|
@@ -442,7 +442,6 @@ public class AppSitePlaceServiceImpl extends ServiceImpl<AppSitePlaceMapper, App
|
|
|
|
|
|
item.getAppSiteRuleTimeFormDTOList().forEach(formDTO -> {
|
|
|
formDTO.getAppSiteRuleDTOList().forEach(ruleDTO -> {
|
|
|
- System.out.println();
|
|
|
AppSitePriceRules appSitePriceRules = new AppSitePriceRules();
|
|
|
BeanUtils.copyProperties(formDTO, appSitePriceRules);
|
|
|
appSitePriceRules.setSitePlaceId(appSitePlace.getId());
|
|
@@ -458,9 +457,6 @@ public class AppSitePlaceServiceImpl extends ServiceImpl<AppSitePlaceMapper, App
|
|
|
appSitePriceRulesList.add(appSitePriceRules);
|
|
|
});
|
|
|
});
|
|
|
- appSitePriceRulesList.forEach(appSitePriceRule -> {
|
|
|
- System.out.println(appSitePriceRule.toString());
|
|
|
- });
|
|
|
appSitePriceRulesMapper.insertList(appSitePriceRulesList);
|
|
|
}
|
|
|
});
|
|
@@ -497,22 +493,86 @@ public class AppSitePlaceServiceImpl extends ServiceImpl<AppSitePlaceMapper, App
|
|
|
Integer count = appSiteCategoryRuleDTO.getCount();
|
|
|
|
|
|
// 查询该分类已有的场地
|
|
|
- List<AppSitePlace> categoryPlaces = existingPlaces.stream().filter(p -> p.getCategoryId() != null && p.getCategoryId().equals(categoryId)).sorted(Comparator.comparing(AppSitePlace::getName)).collect(Collectors.toList());
|
|
|
+ List<AppSitePlace> sitePlaces = existingPlaces.stream().filter(p -> p.getCategoryId() != null && p.getCategoryId().equals(categoryId)).collect(Collectors.toList());
|
|
|
|
|
|
AppCategory category = appCategoryMapper.selectById(categoryId);
|
|
|
if (category == null) {
|
|
|
throw new JeecgBootException("分类不存在", SC_INTERNAL_SERVER_ERROR_500);
|
|
|
}
|
|
|
|
|
|
- appSiteCategoryRuleDTO.getAppSiteRuleTimeFormDTOList().forEach(formDTO -> {
|
|
|
+ if (sitePlaces.isEmpty()) {
|
|
|
+ // 创建场地
|
|
|
+ for (int i = 1; i <= count; i++) {
|
|
|
+ AppSitePlace appSitePlace = new AppSitePlace();
|
|
|
+ BeanUtils.copyProperties(placeCuDTO, appSitePlace);
|
|
|
+ appSitePlace.setType(SitePlaceTypeEnum.PACKAGE.getCode());
|
|
|
+ appSitePlace.setName(category.getName() + i);
|
|
|
+ appSitePlace.setSiteId(site.getId());
|
|
|
+ appSitePlace.setOrgCode(site.getOrgCode());
|
|
|
+ appSitePlace.setTenantId(site.getTenantId());
|
|
|
+ appSitePlace.setCategoryId(category.getId());
|
|
|
+ appSitePlace.setType(SitePlaceTypeEnum.PACKAGE.getCode());
|
|
|
+ baseMapper.insert(appSitePlace);
|
|
|
+ }
|
|
|
+ sitePlaces = baseMapper.selectList(Wrappers.<AppSitePlace>lambdaQuery().eq(AppSitePlace::getSiteId, site.getId()).eq(AppSitePlace::getCategoryId, category.getId()));
|
|
|
+ }
|
|
|
+
|
|
|
+ // 表单siteRuleTimeId集合
|
|
|
+ List<String> formIds = appSiteCategoryRuleDTO.getAppSiteRuleTimeFormDTOList().stream().map(AppSiteRuleTimeFormDTO::getId).filter(StrUtil::isNotBlank).collect(Collectors.toList());
|
|
|
+
|
|
|
+ // 查询本地所有的siteRuleTime
|
|
|
+ List<AppSiteRuleTime> appSiteRuleTimeList = appSiteRuleTimeMapper.selectList(Wrappers.<AppSiteRuleTime>lambdaQuery().eq(AppSiteRuleTime::getSiteId, site.getId()).eq(AppSiteRuleTime::getCategoryId, categoryId));
|
|
|
+ // 删除
|
|
|
+ if (CollUtil.isNotEmpty(appSiteRuleTimeList)) {
|
|
|
+ List<String> localIds = appSiteRuleTimeList.stream().map(AppSiteRuleTime::getId).collect(Collectors.toList());
|
|
|
+ // 找出要删除的旧规则(存在于db,不存在于new)
|
|
|
+ List<String> toDelete = getDifferListByMap(localIds, formIds);
|
|
|
+
|
|
|
+ if (!toDelete.isEmpty()) {
|
|
|
+ toDelete.forEach(id -> {
|
|
|
+ appSitePriceRulesMapper.delete(Wrappers.<AppSitePriceRules>lambdaQuery().eq(AppSitePriceRules::getSiteRuleTimeId, id));
|
|
|
+ });
|
|
|
+ appSiteRuleTimeMapper.deleteBatchIds(toDelete);
|
|
|
+ }
|
|
|
+ }
|
|
|
+
|
|
|
+ List<AppSiteRuleTimeFormDTO> appSiteRuleTimeFormDTOList = appSiteCategoryRuleDTO.getAppSiteRuleTimeFormDTOList();
|
|
|
+ for (AppSiteRuleTimeFormDTO formDTO : appSiteRuleTimeFormDTOList) {
|
|
|
+
|
|
|
// 新增
|
|
|
- if (StrUtil.isNotBlank(formDTO.getId())) {
|
|
|
+ if (StrUtil.isBlank(formDTO.getId())) {
|
|
|
AppSiteRuleTime appSiteRuleTime = new AppSiteRuleTime();
|
|
|
appSiteRuleTime.setSiteId(site.getId()).setCategoryId(category.getId()).setStartTime(formDTO.getStartTime()).setEndTime(formDTO.getEndTime());
|
|
|
appSiteRuleTimeMapper.insert(appSiteRuleTime);
|
|
|
formDTO.getAppSiteRuleDTOList().forEach(ruleDTO -> {
|
|
|
ruleDTO.setSiteRuleTimeId(appSiteRuleTime.getId());
|
|
|
});
|
|
|
+
|
|
|
+ if (CollUtil.isNotEmpty(sitePlaces)) {
|
|
|
+ List<AppSitePriceRules> appSitePriceRulesList = new ArrayList<>();
|
|
|
+
|
|
|
+ for (AppSitePlace sitePlace : sitePlaces) {
|
|
|
+ for (AppSiteRuleDTO ruleDTO : formDTO.getAppSiteRuleDTOList()) {
|
|
|
+ AppSitePriceRules appSitePriceRules = new AppSitePriceRules();
|
|
|
+ BeanUtils.copyProperties(formDTO, appSitePriceRules);
|
|
|
+ appSitePriceRules.setId(null);
|
|
|
+ appSitePriceRules.setSitePlaceId(sitePlace.getId());
|
|
|
+ appSitePriceRules.setOrgCode(sitePlace.getOrgCode());
|
|
|
+ appSitePriceRules.setTenantId(sitePlace.getTenantId());
|
|
|
+ appSitePriceRules.setCategoryId(category.getId());
|
|
|
+ appSitePriceRules.setDayOfWeek(ruleDTO.getDayOfWeek());
|
|
|
+ appSitePriceRules.setSellingPrice(ruleDTO.getSellingPrice());
|
|
|
+ appSitePriceRules.setType(sitePlace.getType());
|
|
|
+ appSitePriceRules.setSiteRuleTimeId(ruleDTO.getSiteRuleTimeId());
|
|
|
+ appSitePriceRules.setStatus(CommonConstant.STATUS_0_INT);
|
|
|
+ appSitePriceRules.setDelFlag(CommonConstant.STATUS_0_INT);
|
|
|
+ appSitePriceRulesList.add(appSitePriceRules);
|
|
|
+ }
|
|
|
+ }
|
|
|
+ for (AppSitePriceRules appSitePriceRules : appSitePriceRulesList) {
|
|
|
+ appSitePriceRulesMapper.insert(appSitePriceRules);
|
|
|
+ }
|
|
|
+ }
|
|
|
}
|
|
|
// 修改
|
|
|
else {
|
|
@@ -528,57 +588,43 @@ public class AppSitePlaceServiceImpl extends ServiceImpl<AppSitePlaceMapper, App
|
|
|
}
|
|
|
}
|
|
|
}
|
|
|
-
|
|
|
+ for (AppSitePriceRules appSitePriceRule : appSitePriceRules) {
|
|
|
+ appSitePriceRulesMapper.updateById(appSitePriceRule);
|
|
|
+ }
|
|
|
}
|
|
|
- });
|
|
|
- // 表单siteRuleTimeId集合
|
|
|
- List<String> formIds = appSiteCategoryRuleDTO.getAppSiteRuleTimeFormDTOList().stream().map(AppSiteRuleTimeFormDTO::getId).filter(StrUtil::isNotBlank).collect(Collectors.toList());
|
|
|
-
|
|
|
- // 查询本地所有的siteRuleTime
|
|
|
- List<AppSiteRuleTime> appSiteRuleTimeList = appSiteRuleTimeMapper.selectList(Wrappers.<AppSiteRuleTime>lambdaQuery().eq(AppSiteRuleTime::getSiteId, site.getId()).eq(AppSiteRuleTime::getCategoryId, categoryId));
|
|
|
- // 删除
|
|
|
- if (CollUtil.isNotEmpty(appSiteRuleTimeList)) {
|
|
|
- List<String> localIds = appSiteRuleTimeList.stream().map(AppSiteRuleTime::getId).collect(Collectors.toList());
|
|
|
- // 找出要删除的旧规则(存在于db,不存在于new)
|
|
|
- List<String> toDelete = getDifferListByMap(localIds, formIds);
|
|
|
-
|
|
|
- toDelete.forEach(id -> {
|
|
|
- appSitePriceRulesMapper.delete(Wrappers.<AppSitePriceRules>lambdaQuery().eq(AppSitePriceRules::getSiteRuleTimeId, id));
|
|
|
- });
|
|
|
- appSiteRuleTimeMapper.deleteBatchIds(toDelete);
|
|
|
}
|
|
|
-
|
|
|
Long sitePlaceNum = baseMapper.selectCount(Wrappers.<AppSitePlace>lambdaQuery().eq(AppSitePlace::getSiteId, site.getId()).eq(AppSitePlace::getCategoryId, categoryId));
|
|
|
-
|
|
|
// 数据库场地数量 小于 表单场地数量 -----新增多余场地数量
|
|
|
if (sitePlaceNum < count) {
|
|
|
- // 增加场地 数量
|
|
|
- for (int i = 1; i < count - sitePlaceNum; i++) {
|
|
|
- AppSitePlace appSitePlace = new AppSitePlace();
|
|
|
- BeanUtils.copyProperties(placeCuDTO, appSitePlace);
|
|
|
- appSitePlace.setSiteId(site.getId()).setCategoryId(categoryId).setName(category.getName() + (count + i)).setType(SitePlaceTypeEnum.PACKAGE.getCode()).setOrgCode(site.getOrgCode()).setTenantId(site.getTenantId());
|
|
|
- baseMapper.insert(appSitePlace);
|
|
|
- List<AppSitePriceRules> appSitePriceRulesList = new ArrayList<>();
|
|
|
- appSiteCategoryRuleDTO.getAppSiteRuleTimeFormDTOList().forEach(formDTO -> {
|
|
|
- List<AppSiteRuleDTO> appSiteRuleDTOList = formDTO.getAppSiteRuleDTOList();
|
|
|
- for (AppSiteRuleDTO appSiteRuleDTO : appSiteRuleDTOList) {
|
|
|
- AppSitePriceRules appSitePriceRules = new AppSitePriceRules();
|
|
|
- BeanUtils.copyProperties(appSiteRuleDTO, appSitePriceRules);
|
|
|
- appSitePriceRulesList.add(appSitePriceRules);
|
|
|
- }
|
|
|
- });
|
|
|
- appSitePriceRulesMapper.insertList(appSitePriceRulesList);
|
|
|
- ;
|
|
|
+ if (sitePlaceNum > 0) {
|
|
|
+ // 增加场地 数量
|
|
|
+ for (int i = 1; i < count - sitePlaceNum; i++) {
|
|
|
+ AppSitePlace appSitePlace = new AppSitePlace();
|
|
|
+ BeanUtils.copyProperties(placeCuDTO, appSitePlace);
|
|
|
+ appSitePlace.setSiteId(site.getId()).setCategoryId(categoryId).setName(category.getName() + (count + i)).setType(SitePlaceTypeEnum.PACKAGE.getCode()).setOrgCode(site.getOrgCode()).setTenantId(site.getTenantId());
|
|
|
+ baseMapper.insert(appSitePlace);
|
|
|
+ List<AppSitePriceRules> appSitePriceRulesList = new ArrayList<>();
|
|
|
+ appSiteCategoryRuleDTO.getAppSiteRuleTimeFormDTOList().forEach(formDTO -> {
|
|
|
+ List<AppSiteRuleDTO> appSiteRuleDTOList = formDTO.getAppSiteRuleDTOList();
|
|
|
+ for (AppSiteRuleDTO appSiteRuleDTO : appSiteRuleDTOList) {
|
|
|
+ AppSitePriceRules appSitePriceRules = new AppSitePriceRules();
|
|
|
+ BeanUtils.copyProperties(appSiteRuleDTO, appSitePriceRules);
|
|
|
+ appSitePriceRulesList.add(appSitePriceRules);
|
|
|
+ }
|
|
|
+ });
|
|
|
+ appSitePriceRulesMapper.insertList(appSitePriceRulesList);
|
|
|
+ }
|
|
|
}
|
|
|
+
|
|
|
}
|
|
|
// 数据库场地数量 大于 表单场地数量 -----删除多余场地数量
|
|
|
- else if (sitePlaceNum > count) {
|
|
|
+ if (sitePlaceNum > count) {
|
|
|
// 减少场地 数量
|
|
|
for (int i = 1; i < sitePlaceNum - count; i++) {
|
|
|
// 名称匹配
|
|
|
AppSitePlace appSitePlace = baseMapper.selectOne(Wrappers.<AppSitePlace>lambdaQuery().eq(AppSitePlace::getSiteId, site.getId()).eq(AppSitePlace::getCategoryId, categoryId).eq(AppSitePlace::getName, category.getName() + (sitePlaceNum - i)));
|
|
|
appSitePriceRulesMapper.delete(Wrappers.<AppSitePriceRules>lambdaQuery().eq(AppSitePriceRules::getSitePlaceId, appSitePlace.getId()));
|
|
|
- appSitePriceRulesMapper.deleteById(appSitePlace);
|
|
|
+ baseMapper.deleteById(appSitePlace);
|
|
|
}
|
|
|
}
|
|
|
}
|