Преглед изворни кода

1、箱码关联到已有案件
2、根据案件名称或编号模糊查询案件
3、查询案件涉及箱码列表

zhangzhao пре 3 година
родитељ
комит
07f62d8729

+ 39 - 0
abi-cloud-qr-platform-server/src/main/java/com/abi/qms/platform/controller/console/InspectionCaseController.java

@@ -3,9 +3,12 @@ package com.abi.qms.platform.controller.console;
 import java.util.List;
 import java.util.Arrays;
 
+import cn.hutool.core.util.StrUtil;
 import com.abi.qms.platform.dto.req.*;
+import com.abi.qms.platform.dto.res.GetCaseBoxCodeListRes;
 import com.abi.qms.platform.dto.res.GetInspectionCaseInfoRes;
 import com.abi.qms.platform.dto.res.PageListInspectionCaseRes;
+import com.abi.qms.platform.dto.res.QueryCaseLikeNumOrNameRes;
 import com.abi.qms.platform.service.IInspectionCaseService;
 import com.abi.task.common.api.base.BaseResponse;
 import lombok.RequiredArgsConstructor;
@@ -70,6 +73,17 @@ public class InspectionCaseController {
         return BaseResponse.create(res);
     }
 
+    /**
+     * 获取稽查案件 涉案箱码列表
+     */
+    @ApiOperation("获取稽查案件 涉案箱码列表")
+    @GetMapping("/boxCode/{id}")
+    public BaseResponse<GetCaseBoxCodeListRes> getBoxCodeListByCaseId(@NotNull(message = "主键不能为空")
+                                                                      @PathVariable("id") Long id) {
+        GetCaseBoxCodeListRes res = inspectionCaseService.getBoxCodeListByCaseId(id);
+        return BaseResponse.create(res);
+    }
+
 
     /**
      * 修改稽查案件
@@ -91,4 +105,29 @@ public class InspectionCaseController {
         inspectionCaseService.removeInspectionCase(ids);
         return BaseResponse.create();
     }
+
+    /**
+     * 根据案件编号或名称 模糊查询案件
+     */
+    @ApiOperation("根据案件编号或名称 模糊查询案件 ")
+    @GetMapping("/like/{numOrName}")
+    public BaseResponse<QueryCaseLikeNumOrNameRes> queryCaseLikeNumOrName(@PathVariable("numOrName") String numOrName) {
+        if (StrUtil.isBlank(numOrName)) {
+            return BaseResponse.create();
+        }
+        QueryCaseLikeNumOrNameRes res = inspectionCaseService.queryCaseLikeNumOrName(numOrName);
+        return BaseResponse.create(res);
+    }
+
+    /**
+     * 关联已有案件
+     */
+    @ApiOperation("关联已有案件")
+    @PostMapping("/associate/case")
+    public BaseResponse associatedWithCase(@Validated @RequestBody AssociatedWithCaseReq req) {
+        inspectionCaseService.associatedWithCase(req);
+        return BaseResponse.create();
+    }
+
+
 }

+ 73 - 0
abi-cloud-qr-platform-server/src/main/java/com/abi/qms/platform/dto/req/AssociatedWithCaseReq.java

@@ -0,0 +1,73 @@
+package com.abi.qms.platform.dto.req;
+
+import com.fasterxml.jackson.annotation.JsonFormat;
+import io.swagger.annotations.ApiModel;
+import io.swagger.annotations.ApiModelProperty;
+import io.swagger.v3.oas.annotations.media.Schema;
+import lombok.AllArgsConstructor;
+import lombok.Data;
+import lombok.NoArgsConstructor;
+import lombok.ToString;
+import lombok.experimental.Accessors;
+import org.jetbrains.annotations.NotNull;
+
+import javax.validation.constraints.NotBlank;
+import javax.validation.constraints.NotEmpty;
+import java.io.Serializable;
+import java.time.LocalDateTime;
+import java.util.List;
+
+/**
+ * @author: zhang zhao
+ * @date: 2021/8/510:41
+ * @description: 关联已有案件入参
+ */
+@Data
+@NoArgsConstructor
+@ApiModel
+public class AssociatedWithCaseReq implements Serializable {
+
+    @ApiModelProperty("案件ID")
+    @NotNull
+    private Long caseId;
+
+    @ApiModelProperty("箱码")
+    @NotBlank
+    private String boxCode;
+
+
+    @ApiModelProperty("skuCode")
+    @NotBlank
+    private String skuCode;
+
+    @ApiModelProperty("流向信息列表")
+    @NotEmpty
+    private List<FlowBean> flowList;
+
+    /**
+     * 流向信息
+     */
+    @Data
+    @NoArgsConstructor
+    @AllArgsConstructor
+    @ToString
+    public static class FlowBean implements Serializable {
+        @ApiModelProperty("节点标识")
+        @NotNull
+        private Long nodeId;
+
+        @ApiModelProperty("节点名称")
+        private String nodeName;
+
+
+        @ApiModelProperty("入库时间")
+        @JsonFormat(pattern = "yyyy-MM-dd HH:mm:ss")
+        private LocalDateTime inStorageTime;
+
+        @ApiModelProperty("出库时间")
+        @JsonFormat(pattern = "yyyy-MM-dd HH:mm:ss")
+        private LocalDateTime outStorageTime;
+    }
+
+
+}

+ 43 - 0
abi-cloud-qr-platform-server/src/main/java/com/abi/qms/platform/dto/res/GetCaseBoxCodeListRes.java

@@ -0,0 +1,43 @@
+package com.abi.qms.platform.dto.res;
+
+import io.swagger.annotations.ApiModel;
+import io.swagger.annotations.ApiModelProperty;
+import lombok.AllArgsConstructor;
+import lombok.Data;
+import lombok.NoArgsConstructor;
+import lombok.ToString;
+
+import java.io.Serializable;
+import java.util.List;
+
+/**
+ * @author: zhang zhao
+ * @date: 2021/8/517:49
+ * @description: 稽查案件涉案箱码列表 出参
+ */
+@Data
+@ApiModel
+public class GetCaseBoxCodeListRes implements Serializable {
+
+    @ApiModelProperty(value = "涉案箱码列表")
+    private List<BoxCodeBean> boxCodeList;
+
+    @Data
+    @NoArgsConstructor
+    @AllArgsConstructor
+    @ToString
+    @ApiModel(value = "GetCaseBoxCodeListRes_BoxCodeBean")
+    public static class BoxCodeBean implements Serializable {
+
+        @ApiModelProperty(value = "ID")
+        private Long id;
+
+        @ApiModelProperty(value = "箱码")
+        private String boxCode;
+
+        @ApiModelProperty(value = "标记")
+        private String handMark;
+    }
+
+
+}

+ 41 - 0
abi-cloud-qr-platform-server/src/main/java/com/abi/qms/platform/dto/res/QueryCaseLikeNumOrNameRes.java

@@ -0,0 +1,41 @@
+package com.abi.qms.platform.dto.res;
+
+import io.swagger.annotations.ApiModel;
+import io.swagger.v3.oas.annotations.media.Schema;
+import lombok.AllArgsConstructor;
+import lombok.Data;
+import lombok.NoArgsConstructor;
+import lombok.ToString;
+
+import java.io.Serializable;
+import java.util.List;
+
+/**
+ * @author: zhang zhao
+ * @date: 2021/8/510:14
+ * @description: 根据案件编号或名称 模糊查询案件 出参
+ */
+@Data
+@Schema
+public class QueryCaseLikeNumOrNameRes implements Serializable {
+
+    @Schema(name = "案件信息列表")
+    private List<CaseBean> caseInfoList;
+
+    @Data
+    @NoArgsConstructor
+    @AllArgsConstructor
+    @Schema(name = "QueryCaseLikeNumOrNameRes_Bean")
+    public static class CaseBean implements Serializable{
+        @Schema(name = "案件ID")
+        private Long caseId;
+
+        @Schema(name = "案件编号")
+        private String caseNum;
+
+        @Schema(name = "案件名称")
+        private String caseName;
+    }
+
+
+}

+ 26 - 0
abi-cloud-qr-platform-server/src/main/java/com/abi/qms/platform/service/IInspectionCaseService.java

@@ -2,10 +2,13 @@ package com.abi.qms.platform.service;
 
 
 import com.abi.qms.platform.dto.req.AddInspectionCaseReq;
+import com.abi.qms.platform.dto.req.AssociatedWithCaseReq;
 import com.abi.qms.platform.dto.req.EditInspectionCaseReq;
 import com.abi.qms.platform.dto.req.PageListInspectionCaseReq;
+import com.abi.qms.platform.dto.res.GetCaseBoxCodeListRes;
 import com.abi.qms.platform.dto.res.GetInspectionCaseInfoRes;
 import com.abi.qms.platform.dto.res.PageListInspectionCaseRes;
+import com.abi.qms.platform.dto.res.QueryCaseLikeNumOrNameRes;
 
 import java.util.Collection;
 import java.util.List;
@@ -55,4 +58,27 @@ public interface IInspectionCaseService {
      * @return 案件详情信息
      */
     GetInspectionCaseInfoRes getInspectionCaseInfo(Long id);
+
+    /**
+     * 根据案件编号 或者名称  模糊查询
+     *
+     * @param numOrName 编号或名称
+     * @return 案件信息
+     */
+    QueryCaseLikeNumOrNameRes queryCaseLikeNumOrName(final String numOrName);
+
+    /**
+     * 关联案件
+     *
+     * @param req 请求
+     */
+    void associatedWithCase(AssociatedWithCaseReq req);
+
+    /**
+     * 查询涉案箱码列表
+     *
+     * @param caseId 案件ID
+     * @return 箱码列表
+     */
+    GetCaseBoxCodeListRes getBoxCodeListByCaseId(final Long caseId);
 }

+ 146 - 14
abi-cloud-qr-platform-server/src/main/java/com/abi/qms/platform/service/impl/InspectionCaseServiceImpl.java

@@ -16,10 +16,7 @@ import com.abi.qms.platform.dao.mapper.InspectionCaseMapper;
 import com.abi.qms.platform.dao.vo.result.InspectionCaseDetailVO;
 import com.abi.qms.platform.dao.vo.result.ListInspectionCaseVO;
 import com.abi.qms.platform.dao.vo.result.ListRoleVO;
-import com.abi.qms.platform.dto.req.AddInspectionCaseReq;
-import com.abi.qms.platform.dto.req.EditInspectionCaseReq;
-import com.abi.qms.platform.dto.req.GetBoxCodeReq;
-import com.abi.qms.platform.dto.req.PageListInspectionCaseReq;
+import com.abi.qms.platform.dto.req.*;
 import com.abi.qms.platform.dto.res.*;
 import com.abi.qms.platform.infrastructure.util.AssertUtil;
 import com.abi.qms.platform.infrastructure.util.PageUtil;
@@ -29,8 +26,10 @@ import com.abi.qms.platform.service.InspectionCaseFlowService;
 import com.abi.qms.platform.service.InspectionCaseNumberService;
 import com.abi.task.common.api.exception.BusinessException;
 import com.abi.task.common.utils.PojoConverterUtils;
+import com.baomidou.mybatisplus.core.conditions.Wrapper;
 import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
 import com.baomidou.mybatisplus.core.metadata.IPage;
+import io.swagger.models.auth.In;
 import jodd.util.StringUtil;
 import org.springframework.beans.factory.annotation.Autowired;
 import org.springframework.stereotype.Service;
@@ -70,7 +69,6 @@ public class InspectionCaseServiceImpl implements IInspectionCaseService {
     private FlowQueryService flowQueryService;
 
 
-
     /**
      * 新增案件
      *
@@ -99,12 +97,16 @@ public class InspectionCaseServiceImpl implements IInspectionCaseService {
         }
 
         //查看编号是否存在
-        QueryWrapper<InspectionCase> inspectionCaseQueryWrapper = new QueryWrapper<>();
-        inspectionCaseQueryWrapper.eq("case_number", caseNumber);
-        inspectionCaseQueryWrapper.eq("is_delete", 0);
-        List<InspectionCase> inspectionCaseList = inspectionCaseMapper.selectList(inspectionCaseQueryWrapper);
+        QueryWrapper<InspectionCase> inspectionCaseQW = new QueryWrapper<>();
+        inspectionCaseQW.eq("case_number", caseNumber);
+        List<InspectionCase> inspectionCaseList = inspectionCaseMapper.selectList(inspectionCaseQW);
         AssertUtil.isEmpty(inspectionCaseList, "当前编号已存在!");
 
+        //查看案件名称是否存在
+        inspectionCaseQW.clear();
+        inspectionCaseQW.eq("case_name", addReq.getCaseName());
+        inspectionCaseList = inspectionCaseMapper.selectList(inspectionCaseQW);
+        AssertUtil.isEmpty(inspectionCaseList, "当前名称已占用!");
 
         //============保存案件============
 
@@ -153,7 +155,7 @@ public class InspectionCaseServiceImpl implements IInspectionCaseService {
 
         List<InspectionCaseFlow> inspectionCaseFlowList = flowList.stream().map(s -> {
             InspectionCaseFlow inspectionCaseFlow = new InspectionCaseFlow();
-            BeanUtil.copyProperties(s,inspectionCaseFlow);
+            BeanUtil.copyProperties(s, inspectionCaseFlow);
             inspectionCaseFlow.setInspectionCaseId(inspectionCase.getId());
             return inspectionCaseFlow;
         }).collect(Collectors.toList());
@@ -161,7 +163,6 @@ public class InspectionCaseServiceImpl implements IInspectionCaseService {
         inspectionCaseFlowMapper.insertBatch(inspectionCaseFlowList);
 
 
-
     }
 
 
@@ -276,7 +277,7 @@ public class InspectionCaseServiceImpl implements IInspectionCaseService {
         //保存新信息
         List<InspectionCaseFlow> inspectionCaseFlowList = flowList.stream().map(s -> {
             InspectionCaseFlow inspectionCaseFlow = new InspectionCaseFlow();
-            BeanUtil.copyProperties(s,inspectionCaseFlow);
+            BeanUtil.copyProperties(s, inspectionCaseFlow);
             inspectionCaseFlow.setInspectionCaseId(inspectionCase.getId());
             return inspectionCaseFlow;
         }).collect(Collectors.toList());
@@ -333,9 +334,134 @@ public class InspectionCaseServiceImpl implements IInspectionCaseService {
         return getInspectionCaseInfoRes;
     }
 
+    /**
+     * 根据 编号或名称 模糊查询
+     *
+     * @param numOrName 编号或名称
+     * @return 案件信息
+     */
+    @Override
+    public QueryCaseLikeNumOrNameRes queryCaseLikeNumOrName(final String numOrName) {
+        //模糊查询
+        QueryWrapper<InspectionCase> caseQueryWrapper = new QueryWrapper<>();
+        caseQueryWrapper.like("case_number", numOrName).or().like("case_name", numOrName);
+        List<InspectionCase> inspectionCases = inspectionCaseMapper.selectList(caseQueryWrapper);
+        if (CollectionUtil.isEmpty(inspectionCases)) {
+            return null;
+        }
+        QueryCaseLikeNumOrNameRes res = new QueryCaseLikeNumOrNameRes();
+        //类型转换
+        List<QueryCaseLikeNumOrNameRes.CaseBean> caseBeanList = inspectionCases.stream().map(s -> {
+            QueryCaseLikeNumOrNameRes.CaseBean caseBean = new QueryCaseLikeNumOrNameRes.CaseBean();
+            caseBean.setCaseId(s.getId());
+            caseBean.setCaseNum(s.getCaseNumber());
+            caseBean.setCaseName(s.getCaseName());
+            return caseBean;
+        }).collect(Collectors.toList());
+        res.setCaseInfoList(caseBeanList);
+
+        return res;
+    }
+
+
+    /**
+     * 关联到已有案件
+     *
+     * @param req 请求
+     */
+    @Override
+    @Transactional(rollbackFor = Exception.class)
+    public void associatedWithCase(AssociatedWithCaseReq req) {
+
+        Long caseId = req.getCaseId();
+        String boxCode = req.getBoxCode();
+        List<AssociatedWithCaseReq.FlowBean> reqFlowList = req.getFlowList();
+        //验证指定案件是否存在
+        InspectionCase inspectionCase = inspectionCaseMapper.selectById(caseId);
+        AssertUtil.isNull(inspectionCase, "指定案件不存在或已被删除!");
+
+        //验证SKU是否一致
+        String skuCode = inspectionCase.getSkuCode();
+        AssertUtil.isMeets(req.getSkuCode(), s -> StrUtil.equals(s, skuCode), "当前箱码与指定案件SKU不一致!");
+
+        //验证当前箱码是否已经存在
+        QueryWrapper<InspectionCaseBoxCode> boxCodeQW = new QueryWrapper<>();
+        boxCodeQW.eq("inspection_case_id", caseId);
+        List<InspectionCaseBoxCode> caseBoxCodes = inspectionCaseBoxCodeMapper.selectList(boxCodeQW);
+        long count = caseBoxCodes.stream().filter(s -> StrUtil.equals(s.getBoxCode(), boxCode)).count();
+        AssertUtil.isMeets(count, x -> x >= 0L, "指定案件已经关联当前箱码!");
+
+        //验证当前箱码是否与案件流向一致
+        QueryWrapper<InspectionCaseFlow> flowQW = new QueryWrapper<>();
+        flowQW.eq("inspection_case_id", caseId);
+        List<InspectionCaseFlow> flowList = inspectionCaseFlowMapper.selectList(flowQW);
+        //当前案件流向节点
+        List<Long> nodeIds = flowList.stream()
+                .map(InspectionCaseFlow::getNodeId)
+                .collect(Collectors.toList());
+        //请求流向节点
+        List<Long> reqNodeIds = reqFlowList.stream()
+                .map(AssociatedWithCaseReq.FlowBean::getNodeId)
+                .collect(Collectors.toList());
+
+
+        //节点数量是否一致
+        AssertUtil.isMeets(reqNodeIds.size(), size -> size == nodeIds.size(), "当前箱码与案件流向不一致!");
+        //节点是否相同
+        AssertUtil.isMeets(reqNodeIds, s -> CollectionUtil.containsAll(s, nodeIds), "当前箱码与案件流向不一致!");
+
+
+        //当前案件最小出库时间
+        LocalDateTime outStorageTime = flowList.stream()
+                .filter(s -> Objects.nonNull(s.getOutStorageTime()))
+                .min(Comparator.comparing(InspectionCaseFlow::getOutStorageTime))
+                .get()
+                .getOutStorageTime();
+
+        //请求流向最小出库时间
+        LocalDateTime resOutStorageTime = reqFlowList.stream()
+                .filter(s -> Objects.nonNull(s.getOutStorageTime()))
+                .min(Comparator.comparing(AssociatedWithCaseReq.FlowBean::getOutStorageTime))
+                .get()
+                .getOutStorageTime();
+
+        //判断是否为同一批货  出库时间是否一致
+        AssertUtil.isMeets(resOutStorageTime, s -> s.compareTo(outStorageTime) == 0, "当前箱码与案件流向不一致!");
+
+        //修改案件信息
+        Long boxCodeCount = inspectionCase.getBoxCodeCount();
+        inspectionCase.setBoxCodeCount(++boxCodeCount);
+        inspectionCaseMapper.updateById(inspectionCase);
+        //添加箱码
+        InspectionCaseBoxCode entity = new InspectionCaseBoxCode();
+        entity.setBoxCode(boxCode);
+        entity.setInspectionCaseId(caseId);
+        inspectionCaseBoxCodeMapper.insert(entity);
+
+    }
+
+    /**
+     * 查询涉案箱码列表
+     *
+     * @param caseId 案件ID
+     * @return 涉案箱码列表
+     */
+    @Override
+    public GetCaseBoxCodeListRes getBoxCodeListByCaseId(final Long caseId) {
+        QueryWrapper<InspectionCaseBoxCode> queryWrapper = new QueryWrapper<>();
+        queryWrapper.eq("inspection_case_id", caseId);
+        List<InspectionCaseBoxCode> caseBoxCodes = inspectionCaseBoxCodeMapper.selectList(queryWrapper);
+        AssertUtil.isNotEmpty(caseBoxCodes, "未查询到指定案件涉案箱码!");
+        List<GetCaseBoxCodeListRes.BoxCodeBean> boxCodeBeans = PojoConverterUtils.copyList(caseBoxCodes, GetCaseBoxCodeListRes.BoxCodeBean.class);
+        GetCaseBoxCodeListRes res = new GetCaseBoxCodeListRes();
+        res.setBoxCodeList(boxCodeBeans);
+        return res;
+    }
+
 
     /**
      * 查询箱码对应流向信息
+     *
      * @param boxCodeList 箱码列表
      * @return 对应流向信息列表
      */
@@ -381,7 +507,7 @@ public class InspectionCaseServiceImpl implements IInspectionCaseService {
             //判断流向是否一致
             //获取当前流向信息
             List<GetBoxCodeRes.FlowBean> flowList = res.getFlowList();
-            LocalDateTime outStorageTime = flowList.stream().filter(s->Objects.nonNull(s.getOutStorageTime())).min(Comparator.comparing(GetBoxCodeRes.FlowBean::getOutStorageTime)).get().getOutStorageTime();
+            LocalDateTime outStorageTime = flowList.stream().filter(s -> Objects.nonNull(s.getOutStorageTime())).min(Comparator.comparing(GetBoxCodeRes.FlowBean::getOutStorageTime)).get().getOutStorageTime();
             boolean outStorageTimeAdd = outStorageTimeSet.add(outStorageTime);
 
             //获取当前所以流向节点ID
@@ -389,10 +515,16 @@ public class InspectionCaseServiceImpl implements IInspectionCaseService {
             //如果firstFlowNodeIdList 为空 则赋值
             if (CollectionUtil.isEmpty(firstFlowNodeIdList)) {
                 firstFlowNodeIdList.addAll(nodeIds);
+                continue;
+            }
+            //先判断节点数量
+            if (firstFlowNodeIdList.size() != nodeIds.size()) {
+                flowErrBoxCode.add(boxCode);
                 break;
             }
+
             //判断节点信息和时间信息是否一致
-            if (!CollectionUtil.containsAll(firstFlowNodeIdList, nodeIds) || !outStorageTimeAdd) {
+            if (!CollectionUtil.containsAll(firstFlowNodeIdList, nodeIds) || outStorageTimeAdd) {
                 flowErrBoxCode.add(boxCode);
             }
         }