Просмотр исходного кода

fix(app): 调整比赛时间状态判断逻辑

- 修改时间比较逻辑,使用DATE_ADD函数处理时区差异
- 确保比赛状态"未开始"、"进行中"、"已结束"的正确判断
- 解决因时区导致的比赛状态显示不准确问题
wzq 1 неделя назад
Родитель
Сommit
e1463e5744

+ 1 - 1
national-motion-module-system/national-motion-system-biz/src/main/java/org/jeecg/modules/quartz/job/OrTeachingJobService.java

@@ -238,7 +238,7 @@ public class OrTeachingJobService {
      * @Param
      * @return
      **/
-    @Scheduled(fixedDelay = 30000)
+    @Scheduled(fixedDelay = 600000)
 //    @Scheduled(cron = "0 0 23 * * ?")
     public void synchronousDoorOpeningAndClosingRecords(){
         try {

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

@@ -507,9 +507,9 @@ public class AppSitePlaceServiceImpl extends ServiceImpl<AppSitePlaceMapper, App
      * @param appSitePlaceParkDTO
      * @return Boolean
      */
-    @Override
+//    @Override
     @Transactional(rollbackFor = Exception.class)
-    public Boolean editPack(AppSitePlaceParkDTO appSitePlaceParkDTO) {
+    public Boolean editPack1(AppSitePlaceParkDTO appSitePlaceParkDTO) {
         AppSitePlaceCuDTO placeCuDTO = appSitePlaceParkDTO.getAppSitePlaceCuDTO();
         List<AppSiteCategoryRuleDTO> appSiteCategoryRuleDTOS = appSitePlaceParkDTO.getAppSiteCategoryRuleDTOS();
         AppSite site = appSiteMapper.selectById(placeCuDTO.getSiteId());
@@ -1012,4 +1012,257 @@ public class AppSitePlaceServiceImpl extends ServiceImpl<AppSitePlaceMapper, App
         if (!sysUser.getOrgCode().equals(place.getOrgCode()))
             throw new JeecgBootException("无权限操作", SC_INTERNAL_SERVER_ERROR_500);
     }
+
+
+    /**
+     * 包场修改
+     *
+     * @param appSitePlaceParkDTO
+     * @return Boolean
+     */
+    @Override
+    @Transactional(rollbackFor = Exception.class)
+    public Boolean editPack(AppSitePlaceParkDTO appSitePlaceParkDTO) {
+        if (appSitePlaceParkDTO == null || appSitePlaceParkDTO.getAppSitePlaceCuDTO() == null) {
+            throw new JeecgBootException("参数不能为空", SC_INTERNAL_SERVER_ERROR_500);
+        }
+
+        AppSitePlaceCuDTO placeCuDTO = appSitePlaceParkDTO.getAppSitePlaceCuDTO();
+
+        List<AppSiteCategoryRuleDTO> appSiteCategoryRuleDTOS = appSitePlaceParkDTO.getAppSiteCategoryRuleDTOS();
+
+        if (CollUtil.isEmpty(appSiteCategoryRuleDTOS)) {
+            return true; // 无配置则无需处理
+        }
+
+        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()) {
+            // 无须对比直接做新增
+            return savePack(appSitePlaceParkDTO);
+        }
+
+        //修改所有的sitePlace的退款,预定限制,温馨提示
+        for (AppSitePlace existingPlace : existingPlaces) {
+            if (!ObjectUtil.equals(existingPlace.getEarlyRefundTime(), placeCuDTO.getEarlyRefundTime()) || !ObjectUtil.equals(existingPlace.getBuyLimit(), placeCuDTO.getBuyLimit()) || !ObjectUtil.equals(existingPlace.getReminder(), placeCuDTO.getReminder())) {
+                if (!ObjectUtil.equals(existingPlace.getEarlyRefundTime(), placeCuDTO.getEarlyRefundTime())) {
+                    existingPlace.setEarlyRefundTime(placeCuDTO.getEarlyRefundTime());
+                }
+                if (!ObjectUtil.equals(existingPlace.getReminder(), placeCuDTO.getReminder())) {
+                    existingPlace.setReminder(placeCuDTO.getReminder());
+                }
+                if (!ObjectUtil.equals(existingPlace.getBuyLimit(), placeCuDTO.getBuyLimit())) {
+                    existingPlace.setBuyLimit(placeCuDTO.getBuyLimit());
+                }
+                baseMapper.updateById(existingPlace);
+            }
+        }
+
+        // 提前收集所有新的分类ID
+        Set<String> newCategoryIds = appSiteCategoryRuleDTOS.stream()
+                .map(AppSiteCategoryRuleDTO::getCategoryId)
+                .collect(Collectors.toSet());
+
+        // 删除不在新分类列表中的现有场地
+        existingPlaces.forEach(place -> {
+            if (!newCategoryIds.contains(place.getCategoryId())) {
+                baseMapper.deleteById(place);
+            }
+        });
+
+        // 预加载所有相关的时间规则
+        Map<String, List<AppSiteRuleTime>> categoryRuleTimeMap = new HashMap<>();
+        for (String categoryId : newCategoryIds) {
+            List<AppSiteRuleTime> rules = appSiteRuleTimeMapper.selectList(
+                    Wrappers.<AppSiteRuleTime>lambdaQuery()
+                            .eq(AppSiteRuleTime::getSiteId, site.getId())
+                            .eq(AppSiteRuleTime::getCategoryId, categoryId));
+            categoryRuleTimeMap.put(categoryId, rules);
+        }
+
+        for (AppSiteCategoryRuleDTO appSiteCategoryRuleDTO : appSiteCategoryRuleDTOS) {
+            String categoryId = appSiteCategoryRuleDTO.getCategoryId();
+            Integer count = appSiteCategoryRuleDTO.getCount();
+
+            AppCategory category = appCategoryMapper.selectById(categoryId);
+            if (category == null) {
+                throw new JeecgBootException("分类不存在", SC_INTERNAL_SERVER_ERROR_500);
+            }
+
+            List<AppSitePlace> sitePlaces = existingPlaces.stream()
+                    .filter(p -> p.getCategoryId() != null && p.getCategoryId().equals(categoryId))
+                    .collect(Collectors.toList());
+
+            if (sitePlaces.isEmpty()) {
+                createNewPlaces(placeCuDTO, site, category, count,appSitePlaceParkDTO.getAppSitePlaceCuDTO());
+                sitePlaces = baseMapper.selectList(Wrappers.<AppSitePlace>lambdaQuery()
+                        .eq(AppSitePlace::getSiteId, site.getId())
+                        .eq(AppSitePlace::getCategoryId, category.getId()));
+            }
+
+            handleRuleTimeChanges(site, category, appSiteCategoryRuleDTO, categoryRuleTimeMap.getOrDefault(categoryId, Collections.emptyList()));
+
+            adjustPlaceCount(site, category, sitePlaces, count,appSitePlaceParkDTO.getAppSitePlaceCuDTO());
+        }
+
+        return Boolean.TRUE;
+    }
+
+    private void createNewPlaces(AppSitePlaceCuDTO placeCuDTO, AppSite site, AppCategory category, Integer count,AppSitePlaceCuDTO appSitePlaceCuDTO) {
+        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.setEarlyRefundTime(appSitePlaceCuDTO.getEarlyRefundTime());
+            appSitePlace.setBuyLimit(appSitePlaceCuDTO.getBuyLimit());
+            appSitePlace.setReminder(appSitePlaceCuDTO.getReminder());
+            baseMapper.insert(appSitePlace);
+        }
+    }
+
+    private void handleRuleTimeChanges(AppSite site, AppCategory category,
+                                       AppSiteCategoryRuleDTO appSiteCategoryRuleDTO,
+                                       List<AppSiteRuleTime> dbRuleTimes) {
+        List<String> formIds = appSiteCategoryRuleDTO.getAppSiteRuleTimeFormDTOList().stream()
+                .map(AppSiteRuleTimeFormDTO::getId)
+                .filter(StrUtil::isNotBlank)
+                .collect(Collectors.toList());
+
+        List<String> dbIds = dbRuleTimes.stream()
+                .map(AppSiteRuleTime::getId)
+                .collect(Collectors.toList());
+
+        // 删除旧规则
+        List<String> toDelete = getDifferListByMap(dbIds, formIds);
+        if (!toDelete.isEmpty()) {
+            toDelete.forEach(id -> {
+                appSitePriceRulesMapper.delete(Wrappers.<AppSitePriceRules>lambdaQuery().eq(AppSitePriceRules::getSiteRuleTimeId, id));
+            });
+            appSiteRuleTimeMapper.deleteBatchIds(toDelete);
+        }
+
+        // 处理新增和修改
+        for (AppSiteRuleTimeFormDTO formDTO : appSiteCategoryRuleDTO.getAppSiteRuleTimeFormDTOList()) {
+            if (StrUtil.isBlank(formDTO.getId())) {
+                insertNewRuleTime(site, category, formDTO);
+            } else {
+                updateExistingRuleTime(site, category, formDTO);
+            }
+        }
+    }
+
+    private void insertNewRuleTime(AppSite site, AppCategory category, AppSiteRuleTimeFormDTO formDTO) {
+        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());
+        });
+
+        // 批量插入价格规则
+        List<AppSitePriceRules> priceRules = buildPriceRulesFromForm(site, category, appSiteRuleTime.getId(), formDTO.getAppSiteRuleDTOList());
+        if (CollUtil.isNotEmpty(priceRules)) {
+            appSitePriceRulesMapper.insertList(priceRules);
+        }
+    }
+
+    private void updateExistingRuleTime(AppSite site, AppCategory category, AppSiteRuleTimeFormDTO formDTO) {
+        AppSiteRuleTime appSiteRuleTime = appSiteRuleTimeMapper.selectById(formDTO.getId());
+        if (appSiteRuleTime == null) return;
+
+        appSiteRuleTime.setSiteId(site.getId())
+                .setCategoryId(category.getId())
+                .setStartTime(formDTO.getStartTime())
+                .setEndTime(formDTO.getEndTime());
+        appSiteRuleTimeMapper.updateById(appSiteRuleTime);
+
+        List<AppSitePriceRules> dbPriceRules = appSitePriceRulesMapper.selectList(
+                Wrappers.<AppSitePriceRules>lambdaQuery().eq(AppSitePriceRules::getSiteRuleTimeId, appSiteRuleTime.getId()));
+
+        for (AppSiteRuleDTO ruleDTO : formDTO.getAppSiteRuleDTOList()) {
+            for (AppSitePriceRules dbRule : dbPriceRules) {
+                if (Objects.equals(dbRule.getDayOfWeek(), ruleDTO.getDayOfWeek())) {
+                    dbRule.setStartTime(ruleDTO.getStartTime())
+                            .setEndTime(ruleDTO.getEndTime())
+                            .setSellingPrice(ruleDTO.getSellingPrice());
+                    appSitePriceRulesMapper.updateById(dbRule);
+                }
+            }
+        }
+    }
+
+    private List<AppSitePriceRules> buildPriceRulesFromForm(AppSite site, AppCategory category, String ruleTimeId, List<AppSiteRuleDTO> ruleDTOs) {
+        List<AppSitePriceRules> result = new ArrayList<>();
+        for (AppSiteRuleDTO dto : ruleDTOs) {
+            AppSitePriceRules rule = new AppSitePriceRules();
+            BeanUtils.copyProperties(dto, rule);
+            rule.setId(null);
+            rule.setSiteRuleTimeId(ruleTimeId);
+            rule.setOrgCode(site.getOrgCode());
+            rule.setTenantId(site.getTenantId());
+            rule.setCategoryId(category.getId());
+            rule.setType(SitePlaceTypeEnum.PACKAGE.getCode());
+            rule.setStatus(CommonConstant.STATUS_0_INT);
+            rule.setDelFlag(CommonConstant.STATUS_0_INT);
+            result.add(rule);
+        }
+        return result;
+    }
+
+    private void adjustPlaceCount(AppSite site, AppCategory category, List<AppSitePlace> sitePlaces, Integer targetCount,AppSitePlaceCuDTO appSitePlaceCuDTO) {
+        long currentCount = sitePlaces.size();
+        if (currentCount < targetCount) {
+            addMorePlaces(site, category, sitePlaces, (int)(targetCount - currentCount),appSitePlaceCuDTO);
+        } else if (currentCount > targetCount) {
+            removeExcessPlaces(site, category, (int)(currentCount - targetCount));
+        }
+    }
+
+    private void addMorePlaces(AppSite site, AppCategory category, List<AppSitePlace> sitePlaces, int numToAdd,AppSitePlaceCuDTO appSitePlaceCuDTO) {
+        for (int i = 1; i <= numToAdd; i++) {
+            AppSitePlace place = new AppSitePlace();
+            BeanUtils.copyProperties(site, place);
+            place.setSiteId(site.getId())
+                    .setCategoryId(category.getId())
+                    .setName(category.getName() + (sitePlaces.size() + i))
+                    .setType(SitePlaceTypeEnum.PACKAGE.getCode())
+                    .setOrgCode(site.getOrgCode())
+                    .setEarlyRefundTime(appSitePlaceCuDTO.getEarlyRefundTime())
+                    .setBuyLimit(appSitePlaceCuDTO.getBuyLimit())
+                    .setReminder(appSitePlaceCuDTO.getReminder())
+                    .setTenantId(site.getTenantId());
+            baseMapper.insert(place);
+        }
+    }
+
+    private void removeExcessPlaces(AppSite site, AppCategory category, int numToRemove) {
+        for (int i = 0; i < numToRemove; i++) {
+            AppSitePlace placeToDelete = baseMapper.selectOne(Wrappers.<AppSitePlace>lambdaQuery()
+                    .eq(AppSitePlace::getSiteId, site.getId())
+                    .eq(AppSitePlace::getCategoryId, category.getId())
+                    .orderByDesc(AppSitePlace::getId)
+                    .last("LIMIT 1"));
+            if (placeToDelete != null) {
+                appSitePriceRulesMapper.delete(Wrappers.<AppSitePriceRules>lambdaQuery().eq(AppSitePriceRules::getSitePlaceId, placeToDelete.getId()));
+                baseMapper.deleteById(placeToDelete);
+            }
+        }
+    }
 }