|
@@ -27,7 +27,7 @@ import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
|
|
|
import org.springframework.transaction.annotation.Transactional;
|
|
|
|
|
|
import javax.annotation.Resource;
|
|
|
-import java.util.List;
|
|
|
+import java.util.*;
|
|
|
import java.util.stream.Collectors;
|
|
|
|
|
|
import static org.jeecg.common.constant.CommonConstant.SC_INTERNAL_SERVER_ERROR_500;
|
|
@@ -64,13 +64,20 @@ public class AppSitePlaceServiceImpl extends ServiceImpl<AppSitePlaceMapper, App
|
|
|
appSitePlace.setSiteId(site.getId());
|
|
|
//时间段提取拼接
|
|
|
List<AppSiteRuleDTO> siteRuleDTOS = placeDTO.getSiteRuleDTOS();
|
|
|
- String teachingDay= "";
|
|
|
- String noTeachingDay= "";
|
|
|
- if (!siteRuleDTOS.isEmpty()) {
|
|
|
|
|
|
+ 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());
|
|
|
+ } else {
|
|
|
+ noTeachingDay.add(dto.getStartTime() + "-"+dto.getEndTime());
|
|
|
+ }
|
|
|
+ });
|
|
|
}
|
|
|
- site.setTeachingDay(teachingDay);
|
|
|
- site.setNoTeachingDay(noTeachingDay);
|
|
|
+ site.setTeachingDay(String.join(",", teachingDay));
|
|
|
+ site.setNoTeachingDay(String.join(",", noTeachingDay));
|
|
|
int updateById = appSiteMapper.updateById(site);
|
|
|
if (updateById < 1) {
|
|
|
throw new JeecgBootException("学校补充信息更新失败");
|
|
@@ -101,6 +108,7 @@ public class AppSitePlaceServiceImpl extends ServiceImpl<AppSitePlaceMapper, App
|
|
|
LoginUser sysUser = (LoginUser) SecurityUtils.getSubject().getPrincipal();
|
|
|
if (null == appSitePlaceCuDTO.getSiteId())
|
|
|
throw new JeecgBootException("商户补充信息id不能为空", SC_INTERNAL_SERVER_ERROR_500);
|
|
|
+ AppSite site = appSiteMapper.selectById(appSitePlaceCuDTO.getSiteId());
|
|
|
AppSitePlace dbPlace = baseMapper.selectById(appSitePlaceCuDTO.getSiteId());
|
|
|
if (null == dbPlace) throw new JeecgBootException("数据不存在", SC_INTERNAL_SERVER_ERROR_500);
|
|
|
//部门校验
|
|
@@ -108,9 +116,9 @@ public class AppSitePlaceServiceImpl extends ServiceImpl<AppSitePlaceMapper, App
|
|
|
AppSitePlace appSitePlace = new AppSitePlace();
|
|
|
BeanUtils.copyProperties(appSitePlaceCuDTO, appSitePlace);
|
|
|
//不许更改项赋值
|
|
|
- appSitePlace.setOrgCode(sysUser.getOrgCode());
|
|
|
- appSitePlace.setTenantId(sysUser.getOrgId());
|
|
|
- appSitePlace.setSiteId(appSitePlaceCuDTO.getSiteId());
|
|
|
+ appSitePlace.setOrgCode(site.getOrgCode());
|
|
|
+ appSitePlace.setTenantId(site.getTenantId());
|
|
|
+ appSitePlace.setSiteId(site.getId());
|
|
|
int update = baseMapper.updateById(appSitePlace);
|
|
|
if (update < 1) {
|
|
|
throw new JeecgBootException("商户场所保存失败");
|
|
@@ -313,20 +321,179 @@ public class AppSitePlaceServiceImpl extends ServiceImpl<AppSitePlaceMapper, App
|
|
|
|
|
|
return appSitePlaceUnfixedDTO;
|
|
|
}
|
|
|
-
|
|
|
+//包场
|
|
|
@Override
|
|
|
+ @Transactional(rollbackFor = Exception.class)
|
|
|
public Boolean savePack(AppSitePlaceDTO placeDTO) {
|
|
|
- return null;
|
|
|
+ AppSitePlaceCuDTO placeCuDTO = placeDTO.getAppSitePlaceCuDTO();
|
|
|
+ List<AppSiteRuleDTO> siteRuleDTOS = placeDTO.getSiteRuleDTOS();
|
|
|
+ AppSite site = appSiteMapper.selectById(placeCuDTO.getSiteId());
|
|
|
+ placeDTO.getSiteCategoryDOTS().forEach(item -> {
|
|
|
+ AppCategory category = appCategoryMapper.selectById(item.getCategoryId());
|
|
|
+ for (int i = 0; i < item.getCount(); i++) {
|
|
|
+ AppSitePlace appSitePlace = new AppSitePlace();
|
|
|
+ BeanUtils.copyProperties(placeCuDTO,appSitePlace);
|
|
|
+ appSitePlace.setType(SitePlaceTypeEnum.PACKAGE.getCode());
|
|
|
+ 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);
|
|
|
+ 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);
|
|
|
+ });
|
|
|
+ }
|
|
|
+
|
|
|
+ });
|
|
|
+ return Boolean.TRUE;
|
|
|
}
|
|
|
|
|
|
@Override
|
|
|
public Boolean editPack(AppSitePlaceDTO placeDTO) {
|
|
|
- return null;
|
|
|
+ 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<AppSiteRuleDTO> rules = ruleMap.getOrDefault(categoryId, Collections.emptyList());
|
|
|
+
|
|
|
+ // 查询该分类已有的场地
|
|
|
+ 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<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());
|
|
|
+
|
|
|
+ // 删除旧的价格规则
|
|
|
+ appSitePriceRulesMapper.delete(Wrappers.<AppSitePriceRules>lambdaQuery()
|
|
|
+ .eq(AppSitePriceRules::getSitePlaceId, appSitePlace.getId()));
|
|
|
+
|
|
|
+ // 插入新的价格规则
|
|
|
+ for (AppSitePriceRules priceRule : priceRules) {
|
|
|
+ int insertResult = appSitePriceRulesMapper.insert(priceRule);
|
|
|
+ if (insertResult < 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);
|
|
|
+ }
|
|
|
+
|
|
|
+ // 删除对应的价格规则
|
|
|
+ appSitePriceRulesMapper.delete(Wrappers.<AppSitePriceRules>lambdaQuery()
|
|
|
+ .eq(AppSitePriceRules::getSitePlaceId, existingPlace.getId()));
|
|
|
+ }
|
|
|
+ }
|
|
|
+
|
|
|
+ return Boolean.TRUE;
|
|
|
}
|
|
|
|
|
|
@Override
|
|
|
public AppSitePlaceDTO queryPackById(String id) {
|
|
|
- return null;
|
|
|
+ AppSitePlace dbPlace = baseMapper.selectById(id);
|
|
|
+ if (null == dbPlace) throw new JeecgBootException("包场数据不存在", SC_INTERNAL_SERVER_ERROR_500);
|
|
|
+ AppSitePlaceCuDTO placeCuDTO = new AppSitePlaceCuDTO();
|
|
|
+ BeanUtils.copyProperties(dbPlace, placeCuDTO);
|
|
|
+ List<AppSiteRuleDTO> collect = appSitePriceRulesMapper.selectList(Wrappers.<AppSitePriceRules>lambdaQuery().eq(AppSitePriceRules::getSitePlaceId, id)).stream().map(rule -> {
|
|
|
+ AppSiteRuleDTO appSiteRuleDTO = new AppSiteRuleDTO();
|
|
|
+ BeanUtils.copyProperties(rule, appSiteRuleDTO);
|
|
|
+ return appSiteRuleDTO;
|
|
|
+ }).collect(Collectors.toList());
|
|
|
+ Map<String, List<AppSiteRuleDTO>> collect1 = collect.stream().collect(Collectors.groupingBy(AppSiteRuleDTO::getCategoryId));
|
|
|
+ List<AppSiteCategoryDOT> appSiteCategoryDOTs = collect1.entrySet().stream().map(entry -> {
|
|
|
+ AppSiteCategoryDOT appSiteCategoryDOT = new AppSiteCategoryDOT();
|
|
|
+ appSiteCategoryDOT.setCategoryId(entry.getKey());
|
|
|
+ appSiteCategoryDOT.setCount(entry.getValue().size());
|
|
|
+ return appSiteCategoryDOT;
|
|
|
+ }).collect(Collectors.toList());
|
|
|
+
|
|
|
+ return new AppSitePlaceDTO(placeCuDTO, collect,appSiteCategoryDOTs);
|
|
|
}
|
|
|
|
|
|
@Override
|