Эх сурвалжийг харах

运需、求购草稿状态也校验字段必填,并都支持批量上架操作

yzc 2 жил өмнө
parent
commit
25b1416611

+ 5 - 4
sckw-modules/sckw-order/src/main/java/com/sckw/order/controller/KwoTransportDemandController.java

@@ -129,10 +129,11 @@ public class KwoTransportDemandController {
      * @Param id:
      * @return: com.sckw.core.web.response.HttpResult
      */
-    @GetMapping("/putOnShelves")
-    public HttpResult putOnShelves(@RequestParam Long id) {
-        kwoTransportDemandService.putOnShelves(id);
-        return HttpResult.ok("上架成功");
+    @GetMapping("/batchPutOnShelves")
+    public HttpResult batchPutOnShelves(@RequestParam String ids) {
+        List<Long> list = StringUtils.splitStrToList(ids, ",", Long.class);
+        kwoTransportDemandService.batchPutOnShelves(list);
+        return HttpResult.ok("批量上架成功");
     }
 
     /**

+ 7 - 5
sckw-modules/sckw-order/src/main/java/com/sckw/order/controller/KwpWantBuyController.java

@@ -2,6 +2,7 @@ package com.sckw.order.controller;
 
 import com.sckw.core.exception.BusinessException;
 import com.sckw.core.utils.CollectionUtils;
+import com.sckw.core.utils.StringUtils;
 import com.sckw.core.web.response.HttpResult;
 import com.sckw.excel.utils.ExcelUtil;
 import com.sckw.order.model.dto.WantBuyExport;
@@ -55,7 +56,7 @@ public class KwpWantBuyController {
      * @return: com.sckw.core.web.response.HttpResult
      */
     @PostMapping(value = "/addDraft", produces = MediaType.APPLICATION_JSON_VALUE)
-    public HttpResult addDraft(@RequestBody AddDraftWantBuyParam addDraftWantBuyParam) {
+    public HttpResult addDraft(@RequestBody @Validated AddDraftWantBuyParam addDraftWantBuyParam) {
         kwpWantBuyService.addDraft(addDraftWantBuyParam);
         return HttpResult.ok("新增求购草稿成功");
     }
@@ -78,10 +79,11 @@ public class KwpWantBuyController {
      * @Author: lt
      * @Date: 13:39 2023/7/25 0025
      **/
-    @GetMapping(value = "/putOnShelves", produces = MediaType.APPLICATION_JSON_VALUE)
-    public HttpResult putOnShelves(@RequestParam Long id) {
-        kwpWantBuyService.putOnShelves(id);
-        return HttpResult.ok("求购上架成功");
+    @GetMapping(value = "/batchPutOnShelves", produces = MediaType.APPLICATION_JSON_VALUE)
+    public HttpResult batchPutOnShelves(@RequestParam String ids) {
+        List<Long> list = StringUtils.splitStrToList(ids, Long.class);
+        kwpWantBuyService.batchPutOnShelves(list);
+        return HttpResult.ok("批量求购上架成功");
     }
 
     /**

+ 6 - 0
sckw-modules/sckw-order/src/main/java/com/sckw/order/model/vo/req/AddDraftWantBuyParam.java

@@ -1,6 +1,7 @@
 package com.sckw.order.model.vo.req;
 
 import jakarta.validation.Valid;
+import jakarta.validation.constraints.NotBlank;
 import jakarta.validation.constraints.Pattern;
 import lombok.Getter;
 import lombok.Setter;
@@ -22,6 +23,7 @@ public class AddDraftWantBuyParam {
     /**
      * 商品名称
      */
+    @NotBlank(message = "商品名称不能为空")
     @Length(max = 50, message = "商品名称最多支持50字")
     private String name;
 
@@ -45,24 +47,28 @@ public class AddDraftWantBuyParam {
     /**
      * 求购单价
      */
+    @NotBlank(message = "求购单价不能为空")
     @Length(max = 20, message = "求购单价最多支持20字")
     private String price;
 
     /**
      * 求购总量
      */
+    @NotBlank(message = "求购总量不能为空")
     @Length(max = 20, message = "求购总量最多支持20字")
     private String amount;
 
     /**
      * 联系人姓名
      */
+    @NotBlank(message = "联系人姓名不能为空")
     @Length(max = 32, message = "联系人姓名最多支持32字")
     private String contacts;
 
     /**
      * 联系电话
      */
+    @NotBlank(message = "联系电话不能为空")
     @Pattern(regexp = "^1[3456789]\\d{9}$", message = "非法手机号格式")
     private String phone;
 

+ 11 - 2
sckw-modules/sckw-order/src/main/java/com/sckw/order/model/vo/req/AddTransportDemandDraftParam.java

@@ -1,6 +1,8 @@
 package com.sckw.order.model.vo.req;
 
 import com.fasterxml.jackson.annotation.JsonFormat;
+import jakarta.validation.constraints.NotBlank;
+import jakarta.validation.constraints.NotNull;
 import jakarta.validation.constraints.Pattern;
 import lombok.Getter;
 import lombok.Setter;
@@ -23,6 +25,7 @@ public class AddTransportDemandDraftParam {
      * 商品名称
      */
     @Length(max = 50, message = "商品名称最多支持50字")
+    @NotBlank(message = "商品名称不能为空")
     private String name;
 
     /**
@@ -45,12 +48,14 @@ public class AddTransportDemandDraftParam {
      * 运需单价
      */
     @Length(max = 20, message = "运需单价最多支持20字")
+    @NotBlank(message = "运需单价不能为空")
     private String price;
 
     /**
      * 运输总量
      */
     @Length(max = 20, message = "运输总量最多支持20字")
+    @NotBlank(message = "运输总量不能为空")
     private String amount;
 
     /**
@@ -62,44 +67,48 @@ public class AddTransportDemandDraftParam {
     /**
      * 联系人姓名
      */
+    @NotBlank(message = "联系人姓名不能为空")
     private String contacts;
 
     /**
      * 联系电话
      */
     @Pattern(regexp = "^1[3456789]\\d{9}$", message = "非法手机号格式")
+    @NotBlank(message = "联系人电话不能为空")
     private String phone;
 
     /**
      * 装货区域code
      */
+    @NotNull(message = "装货区域code不能为空")
     private Integer loadAreaCode;
 
     /**
      * 装货区域名称
      */
+    @NotBlank(message = "装货区域名称不能为空")
     private String loadAreaName;
 
     /**
      * 装货详细地址
      */
-    @Length(max = 255, message = "装货详细地址最多支持255字")
     private String loadDetailAddress;
 
     /**
      * 卸货区域code
      */
+    @NotNull(message = "卸货区域code不能为空")
     private Integer unloadAreaCode;
 
     /**
      * 卸货区域名称
      */
+    @NotBlank(message = "卸货区域名称不能为空")
     private String unloadAreaName;
 
     /**
      * 卸货详细地址
      */
-    @Length(max = 255, message = "卸货详细地址最多支持255字")
     private String unloadDetailAddress;
 
     /**

+ 0 - 2
sckw-modules/sckw-order/src/main/java/com/sckw/order/model/vo/req/AddTransportDemandParam.java

@@ -91,7 +91,6 @@ public class AddTransportDemandParam {
     /**
      * 装货详细地址
      */
-    @Length(max = 255, message = "装货详细地址最多支持255字")
     private String loadDetailAddress;
 
     /**
@@ -109,7 +108,6 @@ public class AddTransportDemandParam {
     /**
      * 卸货详细地址
      */
-    @Length(max = 255, message = "卸货详细地址最多支持255字")
     private String unloadDetailAddress;
 
     /**

+ 10 - 3
sckw-modules/sckw-order/src/main/java/com/sckw/order/model/vo/req/UpdateTransportDemandParam.java

@@ -1,6 +1,7 @@
 package com.sckw.order.model.vo.req;
 
 import com.fasterxml.jackson.annotation.JsonFormat;
+import jakarta.validation.constraints.NotBlank;
 import jakarta.validation.constraints.NotNull;
 import jakarta.validation.constraints.Pattern;
 import lombok.Getter;
@@ -27,6 +28,7 @@ public class UpdateTransportDemandParam {
      * 商品名称
      */
     @Length(max = 50, message = "商品名称最多支持50字")
+    @NotBlank(message = "商品名称不能为空")
     private String name;
 
     /**
@@ -49,12 +51,14 @@ public class UpdateTransportDemandParam {
      * 运需单价
      */
     @Length(max = 20, message = "运需单价最多支持20字")
+    @NotBlank(message = "运需单价不能为空")
     private String price;
 
     /**
      * 运输总量
      */
     @Length(max = 20, message = "运输总量最多支持20字")
+    @NotBlank(message = "运输总量不能为空")
     private String amount;
 
     /**
@@ -66,44 +70,48 @@ public class UpdateTransportDemandParam {
     /**
      * 联系人姓名
      */
+    @NotBlank(message = "联系人姓名不能为空")
     private String contacts;
 
     /**
      * 联系电话
      */
     @Pattern(regexp = "^1[3456789]\\d{9}$", message = "非法手机号格式")
+    @NotBlank(message = "联系人电话不能为空")
     private String phone;
 
     /**
      * 装货区域code
      */
+    @NotNull(message = "装货区域code不能为空")
     private Integer loadAreaCode;
 
     /**
      * 装货区域名称
      */
+    @NotBlank(message = "装货区域名称不能为空")
     private String loadAreaName;
 
     /**
      * 装货详细地址
      */
-    @Length(max = 255, message = "装货详细地址最多支持255字")
     private String loadDetailAddress;
 
     /**
      * 卸货区域code
      */
+    @NotNull(message = "卸货区域code不能为空")
     private Integer unloadAreaCode;
 
     /**
      * 卸货区域名称
      */
+    @NotBlank(message = "卸货区域名称不能为空")
     private String unloadAreaName;
 
     /**
      * 卸货详细地址
      */
-    @Length(max = 255, message = "卸货详细地址最多支持255字")
     private String unloadDetailAddress;
 
     /**
@@ -111,5 +119,4 @@ public class UpdateTransportDemandParam {
      */
     @Length(max = 200, message = "备注最多支持200字")
     private String remark;
-
 }

+ 6 - 0
sckw-modules/sckw-order/src/main/java/com/sckw/order/model/vo/req/UpdateWantBuyParam.java

@@ -1,6 +1,7 @@
 package com.sckw.order.model.vo.req;
 
 import jakarta.validation.Valid;
+import jakarta.validation.constraints.NotBlank;
 import jakarta.validation.constraints.NotNull;
 import jakarta.validation.constraints.Pattern;
 import lombok.Getter;
@@ -29,6 +30,7 @@ public class UpdateWantBuyParam {
     /**
      * 商品名称
      */
+    @NotBlank(message = "商品名称不能为空")
     @Length(max = 50, message = "商品名称最多支持50字")
     private String name;
 
@@ -52,24 +54,28 @@ public class UpdateWantBuyParam {
     /**
      * 求购单价
      */
+    @NotBlank(message = "求购单价不能为空")
     @Length(max = 20, message = "求购单价最多支持20字")
     private String price;
 
     /**
      * 求购总量
      */
+    @NotBlank(message = "求购总量不能为空")
     @Length(max = 20, message = "求购总量最多支持20字")
     private String amount;
 
     /**
      * 联系人姓名
      */
+    @NotBlank(message = "联系人姓名不能为空")
     @Length(max = 32, message = "联系人姓名最多支持32字")
     private String contacts;
 
     /**
      * 联系电话
      */
+    @NotBlank(message = "联系电话不能为空")
     @Pattern(regexp = "^1[3456789]\\d{9}$", message = "非法手机号格式")
     private String phone;
 

+ 13 - 22
sckw-modules/sckw-order/src/main/java/com/sckw/order/serivce/KwoTransportDemandService.java

@@ -107,7 +107,8 @@ public class KwoTransportDemandService {
      */
     private KwoTransportDemand getById(Long id) {
         LambdaQueryWrapper<KwoTransportDemand> wrapper = new LambdaQueryWrapper<>();
-        wrapper.eq(KwoTransportDemand::getId, id).eq(KwoTransportDemand::getDelFlag, Global.NO).last("LIMIT 1");
+        wrapper.eq(KwoTransportDemand::getId, id).eq(KwoTransportDemand::getEntId,LoginUserHolder.getEntId())
+                .eq(KwoTransportDemand::getDelFlag, Global.NO).last("LIMIT 1");
         return kwoTransportDemandMapper.selectOne(wrapper);
     }
 
@@ -123,12 +124,6 @@ public class KwoTransportDemandService {
         if (Objects.isNull(demand)) {
             throw new BusinessException("数据不存在!");
         }
-        if (!Objects.equals(demand.getEntId(), LoginUserHolder.getEntId())) {
-            throw new BusinessException("无操作权限!");
-        }
-        if (!Objects.equals(String.valueOf(demand.getStatus()), DictEnum.TRANSPORT_DEMAND_STATUS_0.getValue())) {
-            checkParams(param);
-        }
         BeanUtils.copyProperties(param, demand);
         kwoTransportDemandMapper.updateById(demand);
     }
@@ -313,23 +308,19 @@ public class KwoTransportDemandService {
      * @Param id:
      * @return: void
      */
-    public void putOnShelves(Long id) {
-        KwoTransportDemand demand = getById(id);
-        if (Objects.isNull(demand)) {
-            throw new BusinessException("数据不存在!");
-        }
-        if (!Objects.equals(demand.getEntId(), LoginUserHolder.getEntId())) {
-            throw new BusinessException("无操作权限!");
-        }
-        if (Objects.equals(String.valueOf(demand.getStatus()), DictEnum.TRANSPORT_DEMAND_STATUS_1.getValue())) {
+    public void batchPutOnShelves(List<Long> ids) {
+        LambdaQueryWrapper<KwoTransportDemand> wrapper = new LambdaQueryWrapper<>();
+        wrapper.in(KwoTransportDemand::getId, ids)
+                .ne(KwoTransportDemand::getStatus, Integer.valueOf(DictEnum.TRANSPORT_DEMAND_STATUS_1.getValue()))
+                .eq(KwoTransportDemand::getEntId, LoginUserHolder.getEntId()).eq(KwoTransportDemand::getDelFlag, Global.NO);
+        List<KwoTransportDemand> list = kwoTransportDemandMapper.selectList(wrapper);
+        if (!Objects.equals(ids.size(), list.size())) {
             throw new BusinessException("上架操作仅针对“已下架”“草稿”状态的单据!");
         }
-        if (Objects.equals(String.valueOf(demand.getStatus()), DictEnum.TRANSPORT_DEMAND_STATUS_0.getValue())) {
-            UpdateTransportDemandParam param = BeanUtils.copyProperties(demand, UpdateTransportDemandParam.class);
-            checkParams(param);
-        }
-        demand.setStatus(Integer.valueOf(DictEnum.TRANSPORT_DEMAND_STATUS_1.getValue()));
-        kwoTransportDemandMapper.updateById(demand);
+        LambdaUpdateWrapper<KwoTransportDemand> updateWrapper = new LambdaUpdateWrapper<>();
+        updateWrapper.set(KwoTransportDemand::getStatus, Integer.valueOf(DictEnum.TRANSPORT_DEMAND_STATUS_1.getValue()))
+                .in(KwoTransportDemand::getId, ids);
+        kwoTransportDemandMapper.update(null, updateWrapper);
     }
 
     /**

+ 10 - 17
sckw-modules/sckw-order/src/main/java/com/sckw/order/serivce/KwpWantBuyService.java

@@ -261,22 +261,18 @@ public class KwpWantBuyService {
      * @Author: lt
      * @Date: 13:38 2023/7/25 0025
      **/
-    public void putOnShelves(Long id) {
+    public void batchPutOnShelves(List<Long> ids) {
         LambdaQueryWrapper<KwoWantBuy> wrapper = new LambdaQueryWrapper<>();
-        wrapper.eq(KwoWantBuy::getId, id).eq(KwoWantBuy::getEntId, LoginUserHolder.getEntId())
-                .eq(KwoWantBuy::getDelFlag, Global.NO).last("LIMIT 1");
-        KwoWantBuy kwoWantBuy = kwpWantBuyMapper.selectOne(wrapper);
-        if (Objects.isNull(kwoWantBuy)) {
-            throw new BusinessException("求购信息不存在");
-        }
-        if (Integer.valueOf(DictEnum.WANT_BUY_STATUS_1.getValue()).equals(kwoWantBuy.getStatus())) {
-            throw new BusinessException("求购信息已上架");
-        }
-        if (Integer.valueOf(DictEnum.WANT_BUY_STATUS_0.getValue()).equals(kwoWantBuy.getStatus())) {
-            checkParams(BeanUtils.copyProperties(kwoWantBuy, UpdateWantBuyParam.class));
+        wrapper.in(KwoWantBuy::getId, ids).ne(KwoWantBuy::getStatus, Integer.valueOf(DictEnum.WANT_BUY_STATUS_1.getValue()))
+                .eq(KwoWantBuy::getEntId, LoginUserHolder.getEntId()).eq(KwoWantBuy::getDelFlag, Global.NO);
+        List<KwoWantBuy> list = kwpWantBuyMapper.selectList(wrapper);
+        if (!Objects.equals(ids.size(), list.size())) {
+            throw new BusinessException("上架操作仅针对“已下架”“草稿”状态的单据!");
         }
-        kwoWantBuy.setStatus(Integer.valueOf(DictEnum.WANT_BUY_STATUS_1.getValue()));
-        kwpWantBuyMapper.updateById(kwoWantBuy);
+        LambdaUpdateWrapper<KwoWantBuy> updateWrapper = new LambdaUpdateWrapper<>();
+        updateWrapper.set(KwoWantBuy::getStatus, Integer.valueOf(DictEnum.WANT_BUY_STATUS_1.getValue()))
+                .in(KwoWantBuy::getId, ids);
+        kwpWantBuyMapper.update(null, updateWrapper);
     }
 
     /**
@@ -377,9 +373,6 @@ public class KwpWantBuyService {
         if (Objects.isNull(kwoWantBuy)) {
             throw new BusinessException("求购信息不存在");
         }
-        if (!Objects.equals(String.valueOf(kwoWantBuy.getStatus()), DictEnum.WANT_BUY_STATUS_0.getValue())) {
-            checkParams(param);
-        }
         //1.更新求购信息
         BeanUtils.copyProperties(param, kwoWantBuy);
         kwpWantBuyMapper.updateById(kwoWantBuy);