|
@@ -1,6 +1,7 @@
|
|
|
package org.jeecg.modules.system.app.service.impl;
|
|
|
|
|
|
import cn.hutool.core.collection.CollUtil;
|
|
|
+import cn.hutool.core.util.StrUtil;
|
|
|
import com.alibaba.fastjson.JSONObject;
|
|
|
import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper;
|
|
|
import com.baomidou.mybatisplus.core.metadata.IPage;
|
|
@@ -467,6 +468,12 @@ public class AppSitePlaceServiceImpl extends ServiceImpl<AppSitePlaceMapper, App
|
|
|
return Boolean.TRUE;
|
|
|
}
|
|
|
|
|
|
+ /**
|
|
|
+ * 包场修改
|
|
|
+ *
|
|
|
+ * @param appSitePlaceParkDTO
|
|
|
+ * @return Boolean
|
|
|
+ */
|
|
|
@Override
|
|
|
@Transactional(rollbackFor = Exception.class)
|
|
|
public Boolean editPack(AppSitePlaceParkDTO appSitePlaceParkDTO) {
|
|
@@ -478,226 +485,100 @@ public class AppSitePlaceServiceImpl extends ServiceImpl<AppSitePlaceMapper, App
|
|
|
throw new JeecgBootException("商户门店不存在", SC_INTERNAL_SERVER_ERROR_500);
|
|
|
}
|
|
|
// 查询当前场地的所有包场场所
|
|
|
- List<AppSitePlace> existingPlaces = baseMapper.selectList(Wrappers.<AppSitePlace>lambdaQuery()
|
|
|
- .eq(AppSitePlace::getSiteId, site.getId())
|
|
|
- .eq(AppSitePlace::getType, SitePlaceTypeEnum.PACKAGE.getCode()));
|
|
|
+ List<AppSitePlace> existingPlaces = baseMapper.selectList(Wrappers.<AppSitePlace>lambdaQuery().eq(AppSitePlace::getSiteId, site.getId()).eq(AppSitePlace::getType, SitePlaceTypeEnum.PACKAGE.getCode()));
|
|
|
if (existingPlaces.isEmpty()) {
|
|
|
- //无须对比直接做新增
|
|
|
+ // 无须对比直接做新增
|
|
|
return savePack(appSitePlaceParkDTO);
|
|
|
}
|
|
|
|
|
|
- // 用于存储需要保留的场地ID
|
|
|
- List<String> updatedPlaceIds = new ArrayList<>();
|
|
|
-
|
|
|
- //对比修改
|
|
|
+ // 对比修改
|
|
|
for (AppSiteCategoryRuleDTO appSiteCategoryRuleDTO : appSiteCategoryRuleDTOS) {
|
|
|
String categoryId = appSiteCategoryRuleDTO.getCategoryId();
|
|
|
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> categoryPlaces = existingPlaces.stream().filter(p -> p.getCategoryId() != null && p.getCategoryId().equals(categoryId)).sorted(Comparator.comparing(AppSitePlace::getName)).collect(Collectors.toList());
|
|
|
|
|
|
AppCategory category = appCategoryMapper.selectById(categoryId);
|
|
|
if (category == null) {
|
|
|
throw new JeecgBootException("分类不存在", SC_INTERNAL_SERVER_ERROR_500);
|
|
|
}
|
|
|
|
|
|
- // 扩展或裁剪场地数量
|
|
|
- for (int i = 0; i < count; i++) {
|
|
|
- AppSitePlace appSitePlace;
|
|
|
- if (i < categoryPlaces.size()) {
|
|
|
- // 更新现有场地
|
|
|
- appSitePlace = categoryPlaces.get(i);
|
|
|
- } else {
|
|
|
- // 创建新场地
|
|
|
- appSitePlace = new AppSitePlace();
|
|
|
- BeanUtils.copyProperties(placeCuDTO, appSitePlace);
|
|
|
- appSitePlace.setType(SitePlaceTypeEnum.PACKAGE.getCode());
|
|
|
- appSitePlace.setOrgCode(site.getOrgCode());
|
|
|
- appSitePlace.setTenantId(site.getTenantId());
|
|
|
- appSitePlace.setCategoryId(categoryId);
|
|
|
+ appSiteCategoryRuleDTO.getAppSiteRuleTimeFormDTOList().forEach(formDTO -> {
|
|
|
+ // 新增
|
|
|
+ if (StrUtil.isNotBlank(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());
|
|
|
+ });
|
|
|
}
|
|
|
-
|
|
|
- updatedPlaceIds.add(appSitePlace.getId());
|
|
|
-
|
|
|
- // 设置场地名称
|
|
|
- appSitePlace.setName(category.getName() + (i + 1));
|
|
|
- // 保存或更新场地
|
|
|
- if (appSitePlace.getId() == null) {
|
|
|
- int insertResult = baseMapper.insert(appSitePlace);
|
|
|
- if (insertResult < 1) {
|
|
|
- throw new JeecgBootException("包场场地创建失败", SC_INTERNAL_SERVER_ERROR_500);
|
|
|
- }
|
|
|
- } else {
|
|
|
- int updateResult = baseMapper.updateById(appSitePlace);
|
|
|
- if (updateResult < 1) {
|
|
|
- throw new JeecgBootException("包场场地更新失败", SC_INTERNAL_SERVER_ERROR_500);
|
|
|
+ // 修改
|
|
|
+ else {
|
|
|
+ AppSiteRuleTime appSiteRuleTime = appSiteRuleTimeMapper.selectById(formDTO.getId());
|
|
|
+ appSiteRuleTime.setSiteId(site.getId()).setCategoryId(category.getId()).setStartTime(formDTO.getStartTime()).setEndTime(formDTO.getEndTime());
|
|
|
+ appSiteRuleTimeMapper.updateById(appSiteRuleTime);
|
|
|
+ List<AppSitePriceRules> appSitePriceRules = appSitePriceRulesMapper.selectList(Wrappers.<AppSitePriceRules>lambdaQuery().eq(AppSitePriceRules::getSiteRuleTimeId, appSiteRuleTime.getId()));
|
|
|
+ List<AppSiteRuleDTO> appSiteRuleDTOList = formDTO.getAppSiteRuleDTOList();
|
|
|
+ for (AppSiteRuleDTO appSiteRuleDTO : appSiteRuleDTOList) {
|
|
|
+ for (AppSitePriceRules appSitePriceRule : appSitePriceRules) {
|
|
|
+ if (Objects.equals(appSitePriceRule.getDayOfWeek(), appSiteRuleDTO.getDayOfWeek())) {
|
|
|
+ appSitePriceRule.setStartTime(appSiteRuleDTO.getStartTime()).setEndTime(appSiteRuleDTO.getEndTime()).setSellingPrice(appSiteRuleDTO.getSellingPrice());
|
|
|
+ }
|
|
|
+ }
|
|
|
}
|
|
|
- }
|
|
|
|
|
|
- //定义存在于表单的数据
|
|
|
- List<String> appSiteRuleTimeIds = new ArrayList<>();
|
|
|
-
|
|
|
- //新增或修改
|
|
|
- appSiteCategoryRuleDTO.getAppSiteRuleTimeFormDTOList().forEach(appSiteRuleTimeFormDTO -> {
|
|
|
+ }
|
|
|
+ });
|
|
|
+ // 表单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);
|
|
|
+ }
|
|
|
|
|
|
- //新增
|
|
|
- if (ObjectUtils.isEmpty(appSiteRuleTimeFormDTO.getId())) {
|
|
|
- AppSiteRuleTime appSiteRuleTime = new AppSiteRuleTime();
|
|
|
- appSiteRuleTime.setSiteId(site.getId());
|
|
|
- appSiteRuleTime.setCategoryId(category.getId());
|
|
|
- appSiteRuleTime.setStartTime(appSiteRuleTimeFormDTO.getStartTime());
|
|
|
- appSiteRuleTime.setEndTime(appSiteRuleTimeFormDTO.getEndTime());
|
|
|
- appSiteRuleTimeMapper.insert(appSiteRuleTime);
|
|
|
+ Long sitePlaceNum = baseMapper.selectCount(Wrappers.<AppSitePlace>lambdaQuery().eq(AppSitePlace::getSiteId, site.getId()).eq(AppSitePlace::getCategoryId, categoryId));
|
|
|
|
|
|
- appSiteRuleTimeFormDTO.getAppSiteRuleDTOList().forEach(rule -> {
|
|
|
- AppSitePriceRules appSitePriceRules = new AppSitePriceRules();
|
|
|
- BeanUtils.copyProperties(rule, appSitePriceRules);
|
|
|
- appSitePriceRules.setSitePlaceId(appSitePlace.getId());
|
|
|
- appSitePriceRules.setOrgCode(appSitePlace.getOrgCode());
|
|
|
- appSitePriceRules.setTenantId(appSitePlace.getTenantId());
|
|
|
- appSitePriceRules.setSiteRuleTimeId(appSiteRuleTime.getId());
|
|
|
- int savePriceResult = appSitePriceRulesMapper.insert(appSitePriceRules);
|
|
|
- if (savePriceResult < 1)
|
|
|
- throw new JeecgBootException("包场价格保存失败", SC_INTERNAL_SERVER_ERROR_500);
|
|
|
- });
|
|
|
- }else {
|
|
|
- appSiteRuleTimeIds.add(appSiteRuleTimeFormDTO.getId());
|
|
|
- //修改
|
|
|
- AppSiteRuleTime appSiteRuleTime = new AppSiteRuleTime();
|
|
|
- appSiteRuleTime.setSiteId(site.getId());
|
|
|
-// appSiteRuleTime.setSitePlaceId(appSitePlace.getId());
|
|
|
- appSiteRuleTime.setCategoryId(category.getId());
|
|
|
- appSiteRuleTime.setStartTime(appSiteRuleTimeFormDTO.getStartTime());
|
|
|
- appSiteRuleTime.setEndTime(appSiteRuleTimeFormDTO.getEndTime());
|
|
|
- appSiteRuleTimeMapper.updateById(appSiteRuleTime);
|
|
|
- appSiteRuleTimeFormDTO.getAppSiteRuleDTOList().forEach(rule -> {
|
|
|
+ // 数据库场地数量 小于 表单场地数量 -----新增多余场地数量
|
|
|
+ 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(rule, appSitePriceRules);
|
|
|
- appSitePriceRules.setSitePlaceId(appSitePlace.getId());
|
|
|
- appSitePriceRules.setOrgCode(appSitePlace.getOrgCode());
|
|
|
- appSitePriceRules.setTenantId(appSitePlace.getTenantId());
|
|
|
- appSitePriceRules.setSiteRuleTimeId(appSiteRuleTime.getId());
|
|
|
-
|
|
|
- int updateResult = appSitePriceRulesMapper.updateById(appSitePriceRules);
|
|
|
- if (updateResult < 1)
|
|
|
- throw new JeecgBootException("包场价格保存失败", SC_INTERNAL_SERVER_ERROR_500);
|
|
|
- });
|
|
|
- }
|
|
|
- });
|
|
|
-
|
|
|
- //删除
|
|
|
- //查询本地所有的siteRuleTime
|
|
|
- List<AppSiteRuleTime> appSiteRuleTimeList = appSiteRuleTimeMapper.selectList(Wrappers.<AppSiteRuleTime>lambdaQuery()
|
|
|
- // .eq(AppSiteRuleTime::getSitePlaceId, appSitePlace.getId())
|
|
|
- .eq(AppSiteRuleTime::getCategoryId, categoryId)
|
|
|
- );
|
|
|
- if(ObjectUtils.isEmpty(appSiteRuleTimeList)){
|
|
|
- List<String> localIds = appSiteRuleTimeList.stream().map(AppSiteRuleTime::getId).collect(Collectors.toList());
|
|
|
- // 找出要删除的旧规则(存在于db,不存在于new)
|
|
|
- List<String> toDelete = getDifferListByMap(localIds, appSiteRuleTimeIds);
|
|
|
-
|
|
|
- toDelete.forEach(id -> {
|
|
|
- appSitePriceRulesMapper.delete(Wrappers.<AppSitePriceRules>lambdaQuery().eq(AppSitePriceRules::getSiteRuleTimeId, id));
|
|
|
+ BeanUtils.copyProperties(appSiteRuleDTO, appSitePriceRules);
|
|
|
+ appSitePriceRulesList.add(appSitePriceRules);
|
|
|
+ }
|
|
|
});
|
|
|
- appSiteRuleTimeMapper.deleteBatchIds(toDelete);
|
|
|
+ appSitePriceRulesMapper.insertList(appSitePriceRulesList);
|
|
|
+ ;
|
|
|
}
|
|
|
-// //当前场地的包场价格规则
|
|
|
-// List<AppSiteRuleDTO> rules = appSiteCategoryRuleDTO.getAppSiteRuleDTOList();//表单数据
|
|
|
-// // 当前场地 更新价格规则
|
|
|
-// List<AppSitePriceRules> priceRules = rules.stream()
|
|
|
-// .map(rule -> {
|
|
|
-// AppSitePriceRules priceRule = new AppSitePriceRules();
|
|
|
-// BeanUtils.copyProperties(rule, priceRule);
|
|
|
-// priceRule.setSitePlaceId(appSitePlace.getId());
|
|
|
-// priceRule.setOrgCode(site.getOrgCode());
|
|
|
-// priceRule.setTenantId(site.getTenantId());
|
|
|
-// return priceRule;
|
|
|
-// })
|
|
|
-// .collect(Collectors.toList());//表单数据
|
|
|
-//
|
|
|
-// // 获取数据库中已有的价格规则
|
|
|
-// List<AppSitePriceRules> dbRules = appSitePriceRulesMapper.selectList(
|
|
|
-// Wrappers.<AppSitePriceRules>lambdaQuery()
|
|
|
-// .eq(AppSitePriceRules::getCategoryId, categoryId)
|
|
|
-// .eq(AppSitePriceRules::getSitePlaceId, appSitePlace.getId())
|
|
|
-// );//本地数据,当前的场地的规则数据
|
|
|
-//
|
|
|
-// // 找出要新增的规则(存在于new,不存在于db)
|
|
|
-// List<AppSitePriceRules> toAdd = priceRules.stream()
|
|
|
-// .filter(rule -> rule.getId() == null)
|
|
|
-// .collect(Collectors.toList());
|
|
|
-// toAdd.forEach(rule -> {
|
|
|
-// int insertResult = appSitePriceRulesMapper.insert(rule);
|
|
|
-// if (insertResult < 1)
|
|
|
-// throw new JeecgBootException("包场价格规则新增失败", SC_INTERNAL_SERVER_ERROR_500);
|
|
|
-// });
|
|
|
-//
|
|
|
-// // 找出需要更新的规则(存在ID的数据)
|
|
|
-// List<AppSitePriceRules> toUpdate = priceRules.stream()
|
|
|
-// .filter(rule -> rule.getId() != null)
|
|
|
-// .collect(Collectors.toList());
|
|
|
-//
|
|
|
-// //切换成当前场地的数据
|
|
|
-// for (AppSitePriceRules appSitePriceRules : toUpdate) {
|
|
|
-// AppSitePriceRules sitePriceRules = appSitePriceRulesMapper.selectOne(Wrappers.<AppSitePriceRules>lambdaQuery()
|
|
|
-// .eq(AppSitePriceRules::getCategoryId, categoryId)
|
|
|
-// .eq(AppSitePriceRules::getBatchuuid, appSitePriceRules.getBatchuuid())
|
|
|
-// .eq(AppSitePriceRules::getSitePlaceId, appSitePlace.getId()));
|
|
|
-// appSitePriceRules.setId(sitePriceRules.getId());
|
|
|
-// }
|
|
|
-//
|
|
|
-// toUpdate.forEach(rule -> {
|
|
|
-// int updateResult = appSitePriceRulesMapper.updateById(rule);
|
|
|
-// if (updateResult < 1)
|
|
|
-// throw new JeecgBootException("包场价格规则更新失败", SC_INTERNAL_SERVER_ERROR_500);
|
|
|
-// });
|
|
|
-
|
|
|
- //过滤掉新增数据
|
|
|
-// List<String> filterIds = rules.stream().map(AppSiteRuleDTO::getId).filter(ObjectUtils::isNotEmpty).collect(Collectors.toList());
|
|
|
-// List<String> localIds = dbRules.stream().map(AppSitePriceRules::getId).collect(Collectors.toList());
|
|
|
-// // 找出要删除的旧规则(存在于db,不存在于new)
|
|
|
-// List<String> toDelete = getDifferListByMap(localIds, filterIds);
|
|
|
-//
|
|
|
-// List<AppSitePriceRules> toDeleteList = dbRules.stream().filter(rule -> toDelete.contains(rule.getId())).collect(Collectors.toList());
|
|
|
-//
|
|
|
-// //切换成当前场地的数据
|
|
|
-// for (AppSitePriceRules appSitePriceRules : toDeleteList) {
|
|
|
-// AppSitePriceRules sitePriceRules = appSitePriceRulesMapper.selectOne(Wrappers.<AppSitePriceRules>lambdaQuery()
|
|
|
-// .eq(AppSitePriceRules::getCategoryId, categoryId)
|
|
|
-// .eq(AppSitePriceRules::getBatchuuid, appSitePriceRules.getBatchuuid())
|
|
|
-// .eq(AppSitePriceRules::getSitePlaceId, appSitePlace.getId()));
|
|
|
-// appSitePriceRules.setId(sitePriceRules.getId());
|
|
|
-// }
|
|
|
-//
|
|
|
-// // 执行操作
|
|
|
-// toDeleteList.forEach(rule -> {
|
|
|
-// int deleteResult = appSitePriceRulesMapper.deleteById(rule);
|
|
|
-// if (deleteResult < 1)
|
|
|
-// throw new JeecgBootException("包场价格规则删除失败", SC_INTERNAL_SERVER_ERROR_500);
|
|
|
-// });
|
|
|
}
|
|
|
- }
|
|
|
-
|
|
|
- // 删除不再需要的场地
|
|
|
- for (AppSitePlace existingPlace : existingPlaces) {
|
|
|
- if (!updatedPlaceIds.contains(existingPlace.getId())) {
|
|
|
- int deleteResult = baseMapper.deleteById(existingPlace.getId());
|
|
|
- if (deleteResult < 1) {
|
|
|
- throw new JeecgBootException("包场场地删除失败", SC_INTERNAL_SERVER_ERROR_500);
|
|
|
- }
|
|
|
- // 删除对应的时间规则
|
|
|
- appSiteRuleTimeMapper.deleteById(Wrappers.<AppSiteRuleTime>lambdaQuery()
|
|
|
-// .eq(AppSiteRuleTime::getSitePlaceId, existingPlace.getId())
|
|
|
- );
|
|
|
- // 删除对应的价格规则
|
|
|
- int delete = appSitePriceRulesMapper.delete(Wrappers.<AppSitePriceRules>lambdaQuery()
|
|
|
- .eq(AppSitePriceRules::getSitePlaceId, existingPlace.getId()));
|
|
|
- if (delete < 1) {
|
|
|
- throw new JeecgBootException("包场价格规则删除失败", SC_INTERNAL_SERVER_ERROR_500);
|
|
|
+ // 数据库场地数量 大于 表单场地数量 -----删除多余场地数量
|
|
|
+ else 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);
|
|
|
}
|
|
|
}
|
|
|
}
|
|
@@ -726,170 +607,6 @@ public class AppSitePlaceServiceImpl extends ServiceImpl<AppSitePlaceMapper, App
|
|
|
return differList;
|
|
|
}
|
|
|
|
|
|
-// @Override
|
|
|
-// public Boolean editPack(AppSitePlaceDTO placeDTO) {
|
|
|
-// AppSitePlaceCuDTO placeCuDTO = placeDTO.getAppSitePlaceCuDTO();
|
|
|
-// List<AppSiteCategoryDOT> siteCategoryDOTS = placeDTO.getSiteCategoryDOTS();
|
|
|
-// List<AppSiteRuleDTO> siteRuleDTOS = placeDTO.getSiteRuleDTOS();
|
|
|
-//
|
|
|
-// // 按 categoryId 分组价格规则
|
|
|
-// Map<String, List<AppSiteRuleDTO>> ruleMap = siteRuleDTOS.stream()
|
|
|
-// .collect(Collectors.groupingBy(AppSiteRuleDTO::getCategoryId));
|
|
|
-//
|
|
|
-// AppSite site = appSiteMapper.selectById(placeCuDTO.getSiteId());
|
|
|
-// if (site == null) {
|
|
|
-// throw new JeecgBootException("商户门店不存在", SC_INTERNAL_SERVER_ERROR_500);
|
|
|
-// }
|
|
|
-//
|
|
|
-// // 查询当前场地的所有包场场所
|
|
|
-// List<AppSitePlace> existingPlaces = baseMapper.selectList(Wrappers.<AppSitePlace>lambdaQuery()
|
|
|
-// .eq(AppSitePlace::getSiteId, site.getId())
|
|
|
-// .eq(AppSitePlace::getType, SitePlaceTypeEnum.PACKAGE.getCode()));
|
|
|
-//
|
|
|
-// if (existingPlaces.isEmpty()) {
|
|
|
-// throw new JeecgBootException("包场数据不存在", SC_INTERNAL_SERVER_ERROR_500);
|
|
|
-// }
|
|
|
-//
|
|
|
-// // 用于存储需要保留的场地ID
|
|
|
-// List<String> updatedPlaceIds = new ArrayList<>();
|
|
|
-//
|
|
|
-// // 更新或新增场地
|
|
|
-// for (AppSiteCategoryDOT item : siteCategoryDOTS) {
|
|
|
-// String categoryId = item.getCategoryId();
|
|
|
-// int count = item.getCount();
|
|
|
-// // 查询该分类已有的场地
|
|
|
-// List<AppSitePlace> categoryPlaces = existingPlaces.stream()
|
|
|
-// .filter(p -> p.getCategoryId() != null && p.getCategoryId().equals(categoryId))
|
|
|
-// .sorted(Comparator.comparing(AppSitePlace::getName)) // 按名称排序以确保顺序一致
|
|
|
-// .collect(Collectors.toList());
|
|
|
-//
|
|
|
-// AppCategory category = appCategoryMapper.selectById(categoryId);
|
|
|
-// if (category == null) {
|
|
|
-// throw new JeecgBootException("分类不存在", SC_INTERNAL_SERVER_ERROR_500);
|
|
|
-// }
|
|
|
-//
|
|
|
-// // 扩展或裁剪场地数量
|
|
|
-// for (int i = 0; i < count; i++) {
|
|
|
-// AppSitePlace appSitePlace;
|
|
|
-// if (i < categoryPlaces.size()) {
|
|
|
-// // 更新现有场地
|
|
|
-// appSitePlace = categoryPlaces.get(i);
|
|
|
-// } else {
|
|
|
-// // 创建新场地
|
|
|
-// appSitePlace = new AppSitePlace();
|
|
|
-// BeanUtils.copyProperties(placeCuDTO, appSitePlace);
|
|
|
-// appSitePlace.setType(SitePlaceTypeEnum.PACKAGE.getCode());
|
|
|
-// appSitePlace.setOrgCode(site.getOrgCode());
|
|
|
-// appSitePlace.setTenantId(site.getTenantId());
|
|
|
-// appSitePlace.setCategoryId(categoryId);
|
|
|
-// }
|
|
|
-//
|
|
|
-// // 设置场地名称
|
|
|
-// appSitePlace.setName(category.getName() + (i + 1));
|
|
|
-// // 保存或更新场地
|
|
|
-// if (appSitePlace.getId() == null) {
|
|
|
-// int insertResult = baseMapper.insert(appSitePlace);
|
|
|
-// if (insertResult < 1) {
|
|
|
-// throw new JeecgBootException("包场场地创建失败", SC_INTERNAL_SERVER_ERROR_500);
|
|
|
-// }
|
|
|
-// } else {
|
|
|
-// int updateResult = baseMapper.updateById(appSitePlace);
|
|
|
-// if (updateResult < 1) {
|
|
|
-// throw new JeecgBootException("包场场地更新失败", SC_INTERNAL_SERVER_ERROR_500);
|
|
|
-// }
|
|
|
-// }
|
|
|
-// //传回的当前场地的包场价格规则
|
|
|
-// List<AppSiteRuleDTO> rules = ruleMap.getOrDefault(categoryId, Collections.emptyList());
|
|
|
-// // 当前场地 更新价格规则
|
|
|
-// List<AppSitePriceRules> priceRules = rules.stream()
|
|
|
-// .map(rule -> {
|
|
|
-// AppSitePriceRules priceRule = new AppSitePriceRules();
|
|
|
-// BeanUtils.copyProperties(rule, priceRule);
|
|
|
-// priceRule.setSitePlaceId(appSitePlace.getId());
|
|
|
-// priceRule.setOrgCode(site.getOrgCode());
|
|
|
-// priceRule.setTenantId(site.getTenantId());
|
|
|
-// return priceRule;
|
|
|
-// })
|
|
|
-// .collect(Collectors.toList());
|
|
|
-//
|
|
|
-// // 获取数据库中已有的价格规则
|
|
|
-// List<AppSitePriceRules> dbRules = appSitePriceRulesMapper.selectList(
|
|
|
-// Wrappers.<AppSitePriceRules>lambdaQuery()
|
|
|
-// .eq(AppSitePriceRules::getSitePlaceId, appSitePlace.getId())
|
|
|
-// );
|
|
|
-//
|
|
|
-// // 构建新旧规则的映射(以 startTime + endTime 作为唯一标识)
|
|
|
-// Map<String, AppSitePriceRules> dbRuleMap = dbRules.stream()
|
|
|
-// .collect(Collectors.toMap(
|
|
|
-// rule -> rule.getStartTime() + "-" + rule.getEndTime(),
|
|
|
-// rule -> rule));
|
|
|
-//
|
|
|
-// Map<String, AppSitePriceRules> newRuleMap = priceRules.stream()
|
|
|
-// .collect(Collectors.toMap(
|
|
|
-// rule -> rule.getStartTime() + "-" + rule.getEndTime(),
|
|
|
-// rule -> rule));
|
|
|
-//
|
|
|
-// // 找出要删除的旧规则(存在于db,不存在于new)
|
|
|
-// List<AppSitePriceRules> toDelete = dbRules.stream()
|
|
|
-// .filter(rule -> !newRuleMap.containsKey(rule.getStartTime() + "-" + rule.getEndTime()))
|
|
|
-// .collect(Collectors.toList());
|
|
|
-//
|
|
|
-// // 找出要新增的规则(存在于new,不存在于db)
|
|
|
-// List<AppSitePriceRules> toAdd = priceRules.stream()
|
|
|
-// .filter(rule -> !dbRuleMap.containsKey(rule.getStartTime() + "-" + rule.getEndTime()))
|
|
|
-// .collect(Collectors.toList());
|
|
|
-//
|
|
|
-// // 找出需要更新的规则(存在交集且内容不同)
|
|
|
-// List<AppSitePriceRules> toUpdate = priceRules.stream()
|
|
|
-// .filter(rule -> dbRuleMap.containsKey(rule.getStartTime() + "-" + rule.getEndTime()))
|
|
|
-// .filter(rule -> {
|
|
|
-// AppSitePriceRules dbRule = dbRuleMap.get(rule.getStartTime() + "-" + rule.getEndTime());
|
|
|
-// return !rule.equals(dbRule); // 自定义 equals 或手动比较字段
|
|
|
-// })
|
|
|
-// .collect(Collectors.toList());
|
|
|
-//
|
|
|
-// // 执行操作
|
|
|
-// toDelete.forEach(rule -> {
|
|
|
-// int deleteResult = appSitePriceRulesMapper.deleteById(rule.getId());
|
|
|
-// if (deleteResult < 1)
|
|
|
-// throw new JeecgBootException("包场价格规则删除失败", SC_INTERNAL_SERVER_ERROR_500);
|
|
|
-// });
|
|
|
-//
|
|
|
-// toAdd.forEach(rule -> {
|
|
|
-// int insertResult = appSitePriceRulesMapper.insert(rule);
|
|
|
-// if (insertResult < 1)
|
|
|
-// throw new JeecgBootException("包场价格规则新增失败", SC_INTERNAL_SERVER_ERROR_500);
|
|
|
-// });
|
|
|
-//
|
|
|
-// toUpdate.forEach(rule -> {
|
|
|
-// int updateResult = appSitePriceRulesMapper.updateById(rule);
|
|
|
-// if (updateResult < 1)
|
|
|
-// throw new JeecgBootException("包场价格规则更新失败", SC_INTERNAL_SERVER_ERROR_500);
|
|
|
-// });
|
|
|
-//
|
|
|
-// updatedPlaceIds.add(appSitePlace.getId());
|
|
|
-// }
|
|
|
-// }
|
|
|
-//
|
|
|
-// // 删除不再需要的场地
|
|
|
-// for (AppSitePlace existingPlace : existingPlaces) {
|
|
|
-// if (!updatedPlaceIds.contains(existingPlace.getId())) {
|
|
|
-// int deleteResult = baseMapper.deleteById(existingPlace.getId());
|
|
|
-// if (deleteResult < 1) {
|
|
|
-// throw new JeecgBootException("包场场地删除失败", SC_INTERNAL_SERVER_ERROR_500);
|
|
|
-// }
|
|
|
-//
|
|
|
-// // 删除对应的价格规则
|
|
|
-// int delete = appSitePriceRulesMapper.delete(Wrappers.<AppSitePriceRules>lambdaQuery()
|
|
|
-// .eq(AppSitePriceRules::getSitePlaceId, existingPlace.getId()));
|
|
|
-// if (delete < 1) {
|
|
|
-// throw new JeecgBootException("包场价格规则删除失败", SC_INTERNAL_SERVER_ERROR_500);
|
|
|
-// }
|
|
|
-// }
|
|
|
-// }
|
|
|
-// return Boolean.TRUE;
|
|
|
-// }
|
|
|
-
|
|
|
@Override
|
|
|
public AppSitePlaceDTO queryPackById(String id) {
|
|
|
AppSitePlace dbPlace = baseMapper.selectById(id);
|
|
@@ -1088,8 +805,7 @@ public class AppSitePlaceServiceImpl extends ServiceImpl<AppSitePlaceMapper, App
|
|
|
public AppSitePlaceParkDTO queryPack(String siteId) {
|
|
|
AppSitePlaceParkDTO appSitePlaceParkDTO = new AppSitePlaceParkDTO();
|
|
|
AppSite site = appSiteMapper.selectById(siteId);
|
|
|
- List<AppSitePlace> appSitePlaceList = this.baseMapper.selectList(Wrappers.<AppSitePlace>lambdaQuery()
|
|
|
- .eq(AppSitePlace::getSiteId, site.getId()));
|
|
|
+ List<AppSitePlace> appSitePlaceList = this.baseMapper.selectList(Wrappers.<AppSitePlace>lambdaQuery().eq(AppSitePlace::getSiteId, site.getId()));
|
|
|
if (ObjectUtils.isNotEmpty(appSitePlaceList)) {
|
|
|
List<AppSiteCategoryRuleDTO> appSiteCategoryRuleDTOS = new ArrayList<>();
|
|
|
if (CollUtil.isNotEmpty(appSitePlaceList)) {
|
|
@@ -1104,31 +820,34 @@ public class AppSitePlaceServiceImpl extends ServiceImpl<AppSitePlaceMapper, App
|
|
|
AppSiteCategoryRuleDTO appSiteCategoryRuleDTO = new AppSiteCategoryRuleDTO();
|
|
|
appSiteCategoryRuleDTO.setCategoryId(key);
|
|
|
appSiteCategoryRuleDTO.setCount(placeList.size());
|
|
|
- //查询当前场地的规则时间列表
|
|
|
- List<AppSiteRuleTime> appSiteRuleTimeList = appSiteRuleTimeMapper.selectList(Wrappers.<AppSiteRuleTime>lambdaQuery()
|
|
|
- .eq(AppSiteRuleTime::getSiteId, site.getId())
|
|
|
- .eq(AppSiteRuleTime::getCategoryId,key)
|
|
|
- );
|
|
|
+ // 查询当前场地的规则时间列表
|
|
|
+ List<AppSiteRuleTime> appSiteRuleTimeList = appSiteRuleTimeMapper.selectList(Wrappers.<AppSiteRuleTime>lambdaQuery().eq(AppSiteRuleTime::getSiteId, site.getId()).eq(AppSiteRuleTime::getCategoryId, key));
|
|
|
List<AppSiteRuleTimeFormDTO> formDTOList = new ArrayList<>();
|
|
|
if (ObjectUtils.isNotEmpty(appSiteRuleTimeList)) {
|
|
|
for (AppSiteRuleTime appSiteRuleTime : appSiteRuleTimeList) {
|
|
|
- System.out.println("appsiteTimede id======================="+appSiteRuleTime.getId());
|
|
|
AppSiteRuleTimeFormDTO appSiteRuleTimeFormDTO = new AppSiteRuleTimeFormDTO();
|
|
|
|
|
|
appSiteRuleTimeFormDTO.setId(appSiteRuleTime.getId());
|
|
|
appSiteRuleTimeFormDTO.setStartTime(appSiteRuleTime.getStartTime());
|
|
|
appSiteRuleTimeFormDTO.setEndTime(appSiteRuleTime.getEndTime());
|
|
|
|
|
|
- List<AppSiteRuleDTO> appSiteRuleDTOS = new ArrayList<>();
|
|
|
+ List<AppSiteRuleDTO> appSiteRuleDTOS = new ArrayList<>();
|
|
|
|
|
|
- //todo 去除重的,根据星期,只取一条
|
|
|
- List<AppSitePriceRules> appSitePriceRulesList = appSitePriceRulesMapper.selectList(Wrappers.<AppSitePriceRules>lambdaQuery()
|
|
|
- .eq(AppSitePriceRules::getSiteRuleTimeId, appSiteRuleTime.getId())
|
|
|
+ // 去重,根据星期,只取一条
|
|
|
+ List<AppSitePriceRules> appSitePriceRulesList = appSitePriceRulesMapper.selectList(Wrappers.<AppSitePriceRules>lambdaQuery().eq(AppSitePriceRules::getSiteRuleTimeId, appSiteRuleTime.getId())
|
|
|
// .eq(AppSitePriceRules::getSitePlaceId, appSitePlace.getId())
|
|
|
);
|
|
|
- System.out.println("appSitePriceRulesList的数量为++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++"+appSitePriceRulesList.size());
|
|
|
- if (ObjectUtils.isNotEmpty(appSitePriceRulesList)) {
|
|
|
- for (AppSitePriceRules appSitePriceRules : appSitePriceRulesList) {
|
|
|
+ List<AppSitePriceRules> weekList = new ArrayList<>();
|
|
|
+ Map<String, List<AppSitePriceRules>> siteRuleMap = appSitePriceRulesList.stream().collect(Collectors.groupingBy(AppSitePriceRules::getDayOfWeek));
|
|
|
+ for (String week : siteRuleMap.keySet()) {
|
|
|
+ // 每个week取第一条(共7条)
|
|
|
+ List<AppSitePriceRules> appSitePriceRules = siteRuleMap.get(week);
|
|
|
+ if (ObjectUtils.isNotEmpty(appSitePriceRules)) {
|
|
|
+ weekList.add(appSitePriceRules.get(0));
|
|
|
+ }
|
|
|
+ }
|
|
|
+ if (ObjectUtils.isNotEmpty(weekList)) {
|
|
|
+ for (AppSitePriceRules appSitePriceRules : weekList) {
|
|
|
AppSiteRuleDTO appSiteRuleDTO = new AppSiteRuleDTO();
|
|
|
BeanUtils.copyProperties(appSitePriceRules, appSiteRuleDTO);
|
|
|
appSiteRuleDTOS.add(appSiteRuleDTO);
|
|
@@ -1138,7 +857,6 @@ public class AppSitePlaceServiceImpl extends ServiceImpl<AppSitePlaceMapper, App
|
|
|
appSiteRuleTimeFormDTO.setAppSiteRuleDTOList(appSiteRuleDTOS);
|
|
|
formDTOList.add(appSiteRuleTimeFormDTO);
|
|
|
}
|
|
|
- System.out.println("数量为+++++++++++++++++++++++++++++++"+formDTOList.size());
|
|
|
appSiteCategoryRuleDTO.setAppSiteRuleTimeFormDTOList(formDTOList);
|
|
|
}
|
|
|
appSiteCategoryRuleDTOS.add(appSiteCategoryRuleDTO);
|
|
@@ -1147,7 +865,7 @@ public class AppSitePlaceServiceImpl extends ServiceImpl<AppSitePlaceMapper, App
|
|
|
}
|
|
|
return appSitePlaceParkDTO;
|
|
|
}
|
|
|
- return null;
|
|
|
+ return null;
|
|
|
}
|
|
|
|
|
|
@Override
|