瀏覽代碼

refactor(national-motion-system):优化场地类别更新逻辑

- 在 AppSiteDTO 中添加了 @NotBlank 注解,用于验证运动类目不能为空
- 优化了 AppSiteServiceImpl 中的 editSite 方法,修复了运动类目更新逻辑
- 移除了不必要的注释和未使用的代码
- 增加了数据验证和异常处理
wangzq 5 天之前
父節點
當前提交
ad97300ac4

+ 3 - 0
national-motion-module-system/national-motion-system-biz/src/main/java/org/jeecg/modules/system/app/dto/AppSiteDTO.java

@@ -3,6 +3,7 @@ package org.jeecg.modules.system.app.dto;
 import com.fasterxml.jackson.annotation.JsonCreator;
 import com.fasterxml.jackson.annotation.JsonFormat;
 import com.fasterxml.jackson.annotation.JsonProperty;
+import com.sun.istack.NotNull;
 import io.swagger.v3.oas.annotations.media.Schema;
 import lombok.AllArgsConstructor;
 import lombok.Data;
@@ -12,6 +13,7 @@ import lombok.experimental.Accessors;
 import org.jeecgframework.poi.excel.annotation.Excel;
 import org.springframework.format.annotation.DateTimeFormat;
 
+import javax.validation.constraints.NotBlank;
 import java.math.BigDecimal;
 import java.util.Date;
 
@@ -87,6 +89,7 @@ public class AppSiteDTO {
     /**运动类目id;多个用逗号分割*/
     @Excel(name = "运动类目id;多个用逗号分割", width = 15)
     @Schema(description = "运动类目id;多个用逗号分割")
+    @NotBlank(message = "运动类目不能为空")
     private String categoryId;
     /**信息/设施*/
     @Excel(name = "信息/设施", width = 15)

+ 18 - 24
national-motion-module-system/national-motion-system-biz/src/main/java/org/jeecg/modules/system/app/service/impl/AppSiteServiceImpl.java

@@ -1,5 +1,7 @@
 package org.jeecg.modules.system.app.service.impl;
 
+import cn.hutool.core.util.ObjectUtil;
+import cn.hutool.core.util.StrUtil;
 import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper;
 import com.baomidou.mybatisplus.core.metadata.IPage;
 import com.baomidou.mybatisplus.core.toolkit.Wrappers;
@@ -13,6 +15,7 @@ import org.jeecg.common.system.vo.LoginUser;
 import org.jeecg.modules.system.app.dto.AppSiteDTO;
 import org.jeecg.modules.system.app.dto.AppSitePageDTO;
 import org.jeecg.modules.system.app.entity.AppSite;
+import org.jeecg.modules.system.app.entity.AppSitePriceRules;
 import org.jeecg.modules.system.app.mapper.AppSiteMapper;
 import org.jeecg.modules.system.app.mapper.AppSitePriceRulesMapper;
 import org.jeecg.modules.system.app.service.IAppSiteService;
@@ -23,10 +26,8 @@ import org.springframework.stereotype.Service;
 import org.springframework.transaction.annotation.Transactional;
 
 import javax.annotation.Resource;
-import java.util.ArrayList;
-import java.util.HashMap;
-import java.util.List;
-import java.util.Map;
+import java.util.*;
+import java.util.stream.Collectors;
 
 import static org.jeecg.common.constant.CommonConstant.SC_INTERNAL_SERVER_ERROR_500;
 
@@ -90,26 +91,19 @@ public class AppSiteServiceImpl extends ServiceImpl<AppSiteMapper, AppSite> impl
     @Override
     @Transactional(rollbackFor = Exception.class)
     public Boolean editSite(AppSiteDTO siteCuDTO) {
-//        String id = siteCuDTO.getId();
-//        if (StrUtil.isNotBlank(id)) {
-//            AppSite oldSite = baseMapper.selectById(id);
-//            //比较运动类目,做新增删除修改
-//            if (!oldSite.getCategoryId().equals(siteCuDTO.getCategoryId())) {
-//                List<String> oldList = Arrays.stream(oldSite.getCategoryId().split(",")).collect(Collectors.toList());
-//                List<String> newList = Arrays.stream(siteCuDTO.getCategoryId().split(",")).collect(Collectors.toList());
-//                List<String> diffList = listCompare(oldList, newList);
-//                if (ObjectUtils.isNotEmpty(diffList)) {
-//                    //删除
-//                    priceRulesMapper.delete(Wrappers.<AppSitePriceRules>lambdaQuery().eq(AppSitePriceRules::getSitePlaceId, id).in(AppSitePriceRules::getCategoryId, diffList));
-//                    //新增
-//                    for (String categoryId : newList) {
-//                        AppSitePriceRules priceRules = new AppSitePriceRules();
-//                        priceRules.setSiteId(id);
-//                        priceRules.setCategoryId(categoryId);
-//                    }
-//                }
-//            }
-//        }
+        String id = siteCuDTO.getId();
+        if (StrUtil.isNotBlank(id)) {
+            AppSite oldSite = baseMapper.selectById(id);
+            //比较运动类目,做新增删除修改
+            if (ObjectUtil.isNotNull(oldSite.getCategoryId()) && !siteCuDTO.getCategoryId().equals(oldSite.getCategoryId())) {
+                List<String> oldList = Arrays.stream(oldSite.getCategoryId().split(",")).collect(Collectors.toList());
+                List<String> newList = Arrays.stream(siteCuDTO.getCategoryId().split(",")).collect(Collectors.toList());
+                List<String> diffList = listCompare(oldList, newList);
+                if (ObjectUtils.isNotEmpty(diffList)) {
+
+                }
+            }
+        }
         AppSite site = new AppSite();
         BeanUtils.copyProperties(siteCuDTO, site);
         LoginUser sysUser = (LoginUser) SecurityUtils.getSubject().getPrincipal();