Browse Source

fix:更改校验位置

qingwudarao 6 tháng trước cách đây
mục cha
commit
7ef4981fe0

+ 1 - 3
ruoyi-modules/ruoyi-commodityManagement/src/main/java/org/dromara/commodityManagement/controller/BrandController.java

@@ -1,6 +1,5 @@
 package org.dromara.commodityManagement.controller;
 
-import cn.dev33.satoken.annotation.SaIgnore;
 import cn.hutool.core.collection.CollUtil;
 import jakarta.servlet.http.HttpServletResponse;
 import lombok.RequiredArgsConstructor;
@@ -53,7 +52,7 @@ public class BrandController extends BaseController {
      * @return 修改结果
      */
     @PutMapping()
-    public R<Void> updateBrand(@RequestBody BrandBo brand) {
+    public R<Void> updateBrand(@Validated @RequestBody BrandBo brand) {
         return toAjax(brandService.updateBrand(brand));
     }
 
@@ -80,7 +79,6 @@ public class BrandController extends BaseController {
      * 通过Excel导出所有品牌数据
      * @param response 响应对象
      */
-    @SaIgnore
     @GetMapping("/exportExcel")
     public void exportDiBuExcel(HttpServletResponse response) {
         ExcelUtil.exportTemplate(CollUtil.newArrayList(new HashMap<>(),brandService.selectBrandList()), "品牌列表","excel/品牌导出模板.xlsx", response);

+ 2 - 1
ruoyi-modules/ruoyi-commodityManagement/src/main/java/org/dromara/commodityManagement/controller/DiBuController.java

@@ -1,5 +1,6 @@
 package org.dromara.commodityManagement.controller;
 
+import cn.dev33.satoken.annotation.SaIgnore;
 import cn.hutool.core.collection.CollUtil;
 import jakarta.servlet.http.HttpServletResponse;
 import lombok.RequiredArgsConstructor;
@@ -53,7 +54,7 @@ public class DiBuController extends BaseController {
      * @return 影响行数
      */
     @PutMapping()
-    public R<Void> updateDiBu(@RequestBody DiBuBo diBuBo) {
+    public R<Void> updateDiBu(@Validated @RequestBody DiBuBo diBuBo) {
         return toAjax(diBuService.updateDiBu(diBuBo));
     }
 

+ 1 - 5
ruoyi-modules/ruoyi-commodityManagement/src/main/java/org/dromara/commodityManagement/service/impl/BrandServiceImpl.java

@@ -108,11 +108,7 @@ public class BrandServiceImpl implements BrandService {
      * @param entity Brand实体对象
      */
     private void validEntityBeforeSave(Brand entity) {
-        if (!StringUtils.isNotEmpty(entity.getName())) {
-            throw new ServiceException("名称不能为空!");
-        } else if (!StringUtils.isNoneBlank(entity.getType())) {
-            throw new ServiceException("类型不能为空!");
-        } else if (!(entity.getType().equals("1") || entity.getType().equals("2"))) {
+        if (!(entity.getType().equals("1") || entity.getType().equals("2"))) {
             throw new ServiceException("类型错误!");
         }
     }

+ 0 - 23
ruoyi-modules/ruoyi-commodityManagement/src/main/java/org/dromara/commodityManagement/service/impl/DiBuServiceImpl.java

@@ -8,7 +8,6 @@ import org.dromara.commodityManagement.domain.bo.DiBuBo;
 import org.dromara.commodityManagement.domain.vo.DiBuVo;
 import org.dromara.commodityManagement.mapper.DiBuMapper;
 import org.dromara.commodityManagement.service.DiBuService;
-import org.dromara.common.core.exception.ServiceException;
 import org.dromara.common.core.utils.MapstructUtils;
 import org.dromara.common.core.utils.StringUtils;
 import org.dromara.common.mybatis.core.page.PageQuery;
@@ -49,7 +48,6 @@ public class DiBuServiceImpl implements DiBuService {
     @Override
     public int insertDiBu(DiBuBo diBuBo) {
         DiBu diBu = MapstructUtils.convert(diBuBo, DiBu.class);
-        validEntityBeforeSave(diBu);
         return diBuMapper.insert(diBu);
     }
 
@@ -61,7 +59,6 @@ public class DiBuServiceImpl implements DiBuService {
     @Override
     public int updateDiBu(DiBuBo diBuBo) {
         DiBu diBu = MapstructUtils.convert(diBuBo, DiBu.class);
-        validEntityBeforeSave(diBu);
         QueryWrapper<DiBu> qw  = new QueryWrapper<>();
         qw.eq("id", diBu.getId());
         return diBuMapper.update(diBu,qw);
@@ -90,24 +87,4 @@ public class DiBuServiceImpl implements DiBuService {
     public List<DiBu> selectDiBuList() {
         return diBuMapper.selectList();
     }
-
-    /**
-     * 保存前校验数据
-     * @param entity 底布对象
-     */
-    private void validEntityBeforeSave(DiBu entity) {
-        if (!StringUtils.isNotEmpty(entity.getName())) {
-            throw new ServiceException("名称不能为空!");
-        } else if (!StringUtils.isNoneBlank(entity.getColor())) {
-            throw new ServiceException("颜色不能为空!");
-        } else if (!StringUtils.isNoneBlank(entity.getMenfu())) {
-            throw new ServiceException("门幅不能为空!");
-        } else if (!StringUtils.isNoneBlank(entity.getWeight())) {
-            throw new ServiceException("克重不能为空!");
-        } else if (!StringUtils.isNoneBlank(entity.getPrice())) {
-            throw new ServiceException("价格不能为空!");
-        } else if (!StringUtils.isNoneBlank(entity.getUnit())) {
-            throw new ServiceException("单位不能为空!");
-        }
-    }
 }