소스 검색

feat(system): 实现包场功能

- 新增包场保存、编辑和查询接口
- 优化场地规则处理逻辑,支持批量插入和更新
- 修复了一些与场地类别和规则相关的潜在问题
lix 2 주 전
부모
커밋
a1990e46aa

+ 79 - 11
national-motion-module-system/national-motion-system-biz/src/main/java/org/jeecg/modules/system/app/service/impl/AppSitePlaceServiceImpl.java

@@ -27,7 +27,9 @@ import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
 import org.springframework.transaction.annotation.Transactional;
 
 import javax.annotation.Resource;
+import java.util.ArrayList;
 import java.util.List;
+import java.util.Map;
 import java.util.stream.Collectors;
 
 import static org.jeecg.common.constant.CommonConstant.SC_INTERNAL_SERVER_ERROR_500;
@@ -64,13 +66,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 +110,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 +118,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 +323,78 @@ 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) {
+        AppSitePlaceCuDTO placeCuDTO = placeDTO.getAppSitePlaceCuDTO();
+        List<AppSiteCategoryDOT> siteCategoryDOTS = placeDTO.getSiteCategoryDOTS();
+        List<AppSiteRuleDTO> siteRuleDTOS = placeDTO.getSiteRuleDTOS();
+        Map<String, List<AppSiteRuleDTO>> collect = siteRuleDTOS.stream().collect(Collectors.groupingBy(AppSiteRuleDTO::getCategoryId));
+        AppSite site = appSiteMapper.selectById(placeCuDTO.getSiteId());
+        List<AppSitePlace> appSitePlaces = baseMapper.selectList(Wrappers.<AppSitePlace>lambdaQuery().eq(AppSitePlace::getSiteId, site.getId()));
+        if (appSitePlaces.isEmpty())throw new JeecgBootException("包场数据不存在", SC_INTERNAL_SERVER_ERROR_500);
+        siteCategoryDOTS.forEach(item -> {
+
+        });
+
+
+
+
         return null;
     }
 
     @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