|
@@ -62,17 +62,18 @@ public class AppSitePlaceServiceImpl extends ServiceImpl<AppSitePlaceMapper, App
|
|
|
appSitePlace.setOrgCode(site.getOrgCode());
|
|
|
appSitePlace.setTenantId(site.getTenantId());
|
|
|
appSitePlace.setSiteId(site.getId());
|
|
|
+ appSitePlace.setType(SitePlaceTypeEnum.SCHOOL.getCode());
|
|
|
//时间段提取拼接
|
|
|
List<AppSiteRuleDTO> siteRuleDTOS = placeDTO.getSiteRuleDTOS();
|
|
|
|
|
|
- List<String> teachingDay= new ArrayList<>() ;
|
|
|
- List<String> noTeachingDay= new ArrayList<>() ;
|
|
|
+ List<String> teachingDay = new ArrayList<>();
|
|
|
+ List<String> noTeachingDay = new ArrayList<>();
|
|
|
if (!siteRuleDTOS.isEmpty()) {
|
|
|
siteRuleDTOS.forEach(dto -> {
|
|
|
if (dto.getIsTeaching() == 0) {
|
|
|
- teachingDay.add(dto.getStartTime() + "-"+dto.getEndTime());
|
|
|
+ teachingDay.add(dto.getStartTime() + "-" + dto.getEndTime());
|
|
|
} else {
|
|
|
- noTeachingDay.add(dto.getStartTime() + "-"+dto.getEndTime());
|
|
|
+ noTeachingDay.add(dto.getStartTime() + "-" + dto.getEndTime());
|
|
|
}
|
|
|
});
|
|
|
}
|
|
@@ -321,7 +322,8 @@ public class AppSitePlaceServiceImpl extends ServiceImpl<AppSitePlaceMapper, App
|
|
|
|
|
|
return appSitePlaceUnfixedDTO;
|
|
|
}
|
|
|
-//包场
|
|
|
+
|
|
|
+ //包场
|
|
|
@Override
|
|
|
@Transactional(rollbackFor = Exception.class)
|
|
|
public Boolean savePack(AppSitePlaceDTO placeDTO) {
|
|
@@ -332,21 +334,22 @@ public class AppSitePlaceServiceImpl extends ServiceImpl<AppSitePlaceMapper, App
|
|
|
AppCategory category = appCategoryMapper.selectById(item.getCategoryId());
|
|
|
for (int i = 0; i < item.getCount(); i++) {
|
|
|
AppSitePlace appSitePlace = new AppSitePlace();
|
|
|
- BeanUtils.copyProperties(placeCuDTO,appSitePlace);
|
|
|
+ BeanUtils.copyProperties(placeCuDTO, appSitePlace);
|
|
|
appSitePlace.setType(SitePlaceTypeEnum.PACKAGE.getCode());
|
|
|
- appSitePlace.setName(category.getName()+(i+1));
|
|
|
+ appSitePlace.setName(category.getName() + (i + 1));
|
|
|
appSitePlace.setOrgCode(site.getOrgCode());
|
|
|
appSitePlace.setTenantId(site.getTenantId());
|
|
|
int insert = baseMapper.insert(appSitePlace);
|
|
|
if (insert < 1) throw new JeecgBootException("包场保存失败", SC_INTERNAL_SERVER_ERROR_500);
|
|
|
siteRuleDTOS.stream().filter(rule -> rule.getCategoryId().equals(category.getId())).collect(Collectors.toList()).forEach(rule -> {
|
|
|
AppSitePriceRules appSitePriceRules = new AppSitePriceRules();
|
|
|
- BeanUtils.copyProperties(rule,appSitePriceRules);
|
|
|
+ BeanUtils.copyProperties(rule, appSitePriceRules);
|
|
|
appSitePriceRules.setSitePlaceId(appSitePlace.getId());
|
|
|
appSitePriceRules.setOrgCode(appSitePlace.getOrgCode());
|
|
|
appSitePriceRules.setTenantId(appSitePlace.getTenantId());
|
|
|
int savePriceResult = appSitePriceRulesMapper.insert(appSitePriceRules);
|
|
|
- if (savePriceResult < 1) throw new JeecgBootException("包场价格保存失败", SC_INTERNAL_SERVER_ERROR_500);
|
|
|
+ if (savePriceResult < 1)
|
|
|
+ throw new JeecgBootException("包场价格保存失败", SC_INTERNAL_SERVER_ERROR_500);
|
|
|
});
|
|
|
}
|
|
|
|
|
@@ -369,7 +372,7 @@ 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()));
|
|
@@ -385,8 +388,6 @@ public class AppSitePlaceServiceImpl extends ServiceImpl<AppSitePlaceMapper, App
|
|
|
for (AppSiteCategoryDOT item : siteCategoryDOTS) {
|
|
|
String categoryId = item.getCategoryId();
|
|
|
int count = item.getCount();
|
|
|
- List<AppSiteRuleDTO> rules = ruleMap.getOrDefault(categoryId, Collections.emptyList());
|
|
|
-
|
|
|
// 查询该分类已有的场地
|
|
|
List<AppSitePlace> categoryPlaces = existingPlaces.stream()
|
|
|
.filter(p -> p.getCategoryId() != null && p.getCategoryId().equals(categoryId))
|
|
@@ -428,8 +429,9 @@ public class AppSitePlaceServiceImpl extends ServiceImpl<AppSitePlaceMapper, App
|
|
|
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();
|
|
@@ -441,17 +443,60 @@ public class AppSitePlaceServiceImpl extends ServiceImpl<AppSitePlaceMapper, App
|
|
|
})
|
|
|
.collect(Collectors.toList());
|
|
|
|
|
|
- // 删除旧的价格规则
|
|
|
- appSitePriceRulesMapper.delete(Wrappers.<AppSitePriceRules>lambdaQuery()
|
|
|
- .eq(AppSitePriceRules::getSitePlaceId, appSitePlace.getId()));
|
|
|
+ // 获取数据库中已有的价格规则
|
|
|
+ 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());
|
|
|
|
|
|
- // 插入新的价格规则
|
|
|
- for (AppSitePriceRules priceRule : priceRules) {
|
|
|
- int insertResult = appSitePriceRulesMapper.insert(priceRule);
|
|
|
- if (insertResult < 1) {
|
|
|
- throw new JeecgBootException("包场价格规则保存失败", SC_INTERNAL_SERVER_ERROR_500);
|
|
|
- }
|
|
|
- }
|
|
|
+ // 找出要新增的规则(存在于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());
|
|
|
}
|
|
@@ -466,8 +511,11 @@ public class AppSitePlaceServiceImpl extends ServiceImpl<AppSitePlaceMapper, App
|
|
|
}
|
|
|
|
|
|
// 删除对应的价格规则
|
|
|
- appSitePriceRulesMapper.delete(Wrappers.<AppSitePriceRules>lambdaQuery()
|
|
|
+ int delete = appSitePriceRulesMapper.delete(Wrappers.<AppSitePriceRules>lambdaQuery()
|
|
|
.eq(AppSitePriceRules::getSitePlaceId, existingPlace.getId()));
|
|
|
+ if (delete < 1) {
|
|
|
+ throw new JeecgBootException("包场价格规则删除失败", SC_INTERNAL_SERVER_ERROR_500);
|
|
|
+ }
|
|
|
}
|
|
|
}
|
|
|
|
|
@@ -493,12 +541,27 @@ public class AppSitePlaceServiceImpl extends ServiceImpl<AppSitePlaceMapper, App
|
|
|
return appSiteCategoryDOT;
|
|
|
}).collect(Collectors.toList());
|
|
|
|
|
|
- return new AppSitePlaceDTO(placeCuDTO, collect,appSiteCategoryDOTs);
|
|
|
+ return new AppSitePlaceDTO(placeCuDTO, collect, appSiteCategoryDOTs);
|
|
|
}
|
|
|
|
|
|
@Override
|
|
|
+ @Transactional(rollbackFor = Exception.class)
|
|
|
public Boolean deletePackById(String id) {
|
|
|
- return null;
|
|
|
+ AppSitePlace dbPlace = baseMapper.selectById(id);
|
|
|
+ if (null == dbPlace) throw new JeecgBootException("包场数据不存在", SC_INTERNAL_SERVER_ERROR_500);
|
|
|
+ List<AppSitePlace> appSitePlaces = baseMapper.selectList(Wrappers.<AppSitePlace>lambdaQuery().eq(AppSitePlace::getSiteId, id));
|
|
|
+ appSitePlaces.forEach(appSitePlace -> {
|
|
|
+ int deleteResult = baseMapper.deleteById(appSitePlace.getId());
|
|
|
+ if (deleteResult < 1) {
|
|
|
+ throw new JeecgBootException("包场数据删除失败", SC_INTERNAL_SERVER_ERROR_500);
|
|
|
+ }
|
|
|
+ int delete = appSitePriceRulesMapper.delete(Wrappers.<AppSitePriceRules>lambdaQuery().eq(AppSitePriceRules::getSitePlaceId, appSitePlace.getId()));
|
|
|
+ if (delete < 1) {
|
|
|
+ throw new JeecgBootException("包场价格规则删除失败", SC_INTERNAL_SERVER_ERROR_500);
|
|
|
+ }
|
|
|
+ });
|
|
|
+
|
|
|
+ return Boolean.TRUE;
|
|
|
}
|
|
|
|
|
|
/**
|