From a96fa0ed9bf21343459f2326fcf62932764f3bae Mon Sep 17 00:00:00 2001 From: shusir <497819738@qq.com> Date: Tue, 3 Feb 2026 18:02:09 +0800 Subject: [PATCH] =?UTF-8?q?fix:=E7=89=A9=E6=96=99=E9=AA=8C=E6=94=B6?= =?UTF-8?q?=E6=B5=81=E7=A8=8B?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../admin/MaterialBatchController.java | 7 +- .../vo/MaterialLifecycleDetailRespVO.java | 5 + .../vo/MaterialLifecycleDetailSaveReqVO.java | 3 + .../vo/MaterialLifecycleSaveReqVO.java | 3 +- .../dataobject/MaterialLifecycleDetailDO.java | 5 + .../dal/mapper/MaterialBatchMapper.java | 42 +++- .../mapper/MaterialLifecycleDetailMapper.java | 11 +- .../service/MaterialBatchServiceImpl.java | 50 ++-- .../service/MaterialLifecycleServiceImpl.java | 220 +++++++++++------- 9 files changed, 217 insertions(+), 129 deletions(-) diff --git a/zt-module-qms/zt-module-qms-server/src/main/java/com/zt/plat/module/qms/resource/material/controller/admin/MaterialBatchController.java b/zt-module-qms/zt-module-qms-server/src/main/java/com/zt/plat/module/qms/resource/material/controller/admin/MaterialBatchController.java index 18baad8..6084480 100644 --- a/zt-module-qms/zt-module-qms-server/src/main/java/com/zt/plat/module/qms/resource/material/controller/admin/MaterialBatchController.java +++ b/zt-module-qms/zt-module-qms-server/src/main/java/com/zt/plat/module/qms/resource/material/controller/admin/MaterialBatchController.java @@ -93,7 +93,12 @@ public class MaterialBatchController implements BusinessControllerMarker { @Operation(summary = "获得物料批次分页") // @PreAuthorize("@ss.hasPermission('qms:material-batch:query')") public CommonResult> getMaterialBatchPage(@Valid MaterialBatchPageReqVO pageReqVO) { - PageResult pageResult = materialBatchService.getMaterialBatchPageWithPdtInfo(pageReqVO); + PageResult pageResult; + if (!pageReqVO.getOnlyGong()) { + pageResult = materialBatchService.getMaterialBatchPageWithPdtInfo(pageReqVO); + } else { + pageResult = materialBatchService.getMaterialBatchGongPageWithPdtInfo(pageReqVO); + } return success(pageResult); } diff --git a/zt-module-qms/zt-module-qms-server/src/main/java/com/zt/plat/module/qms/resource/material/controller/vo/MaterialLifecycleDetailRespVO.java b/zt-module-qms/zt-module-qms-server/src/main/java/com/zt/plat/module/qms/resource/material/controller/vo/MaterialLifecycleDetailRespVO.java index 7d34f86..7a29e57 100644 --- a/zt-module-qms/zt-module-qms-server/src/main/java/com/zt/plat/module/qms/resource/material/controller/vo/MaterialLifecycleDetailRespVO.java +++ b/zt-module-qms/zt-module-qms-server/src/main/java/com/zt/plat/module/qms/resource/material/controller/vo/MaterialLifecycleDetailRespVO.java @@ -5,6 +5,7 @@ import com.alibaba.excel.annotation.ExcelProperty; import io.swagger.v3.oas.annotations.media.Schema; import lombok.Data; +import java.math.BigDecimal; import java.time.LocalDateTime; @Schema(description = "管理后台 - 物料通用流程明细 Response VO") @@ -53,6 +54,10 @@ public class MaterialLifecycleDetailRespVO { @ExcelProperty("批次工段-部门名称") private String assignDepartmentName; + @Schema(description = "是否检化验,1-是,0-否") + @ExcelProperty("是否检化验,1-是,0-否") + private Integer assayFlag; + @Schema(description = "物料实例id", example = "968") @ExcelProperty("物料实例id") private Long infomationId; diff --git a/zt-module-qms/zt-module-qms-server/src/main/java/com/zt/plat/module/qms/resource/material/controller/vo/MaterialLifecycleDetailSaveReqVO.java b/zt-module-qms/zt-module-qms-server/src/main/java/com/zt/plat/module/qms/resource/material/controller/vo/MaterialLifecycleDetailSaveReqVO.java index fbf6c06..678217a 100644 --- a/zt-module-qms/zt-module-qms-server/src/main/java/com/zt/plat/module/qms/resource/material/controller/vo/MaterialLifecycleDetailSaveReqVO.java +++ b/zt-module-qms/zt-module-qms-server/src/main/java/com/zt/plat/module/qms/resource/material/controller/vo/MaterialLifecycleDetailSaveReqVO.java @@ -22,6 +22,9 @@ public class MaterialLifecycleDetailSaveReqVO { @Schema(description = "批次工段id", example = "21334") private Long batchGongduanId; + @Schema(description = "是否检化验,1-是,0-否") + private Integer assayFlag; + @Schema(description = "物料实例id", example = "968") private Long infomationId; diff --git a/zt-module-qms/zt-module-qms-server/src/main/java/com/zt/plat/module/qms/resource/material/controller/vo/MaterialLifecycleSaveReqVO.java b/zt-module-qms/zt-module-qms-server/src/main/java/com/zt/plat/module/qms/resource/material/controller/vo/MaterialLifecycleSaveReqVO.java index ba4215f..b709d0e 100644 --- a/zt-module-qms/zt-module-qms-server/src/main/java/com/zt/plat/module/qms/resource/material/controller/vo/MaterialLifecycleSaveReqVO.java +++ b/zt-module-qms/zt-module-qms-server/src/main/java/com/zt/plat/module/qms/resource/material/controller/vo/MaterialLifecycleSaveReqVO.java @@ -42,7 +42,6 @@ public class MaterialLifecycleSaveReqVO { private Long applyDepartmentId; @Schema(description = "申请时间") - @NotNull(groups = AddGroup.class, message = "申请时间不能为空") private LocalDateTime applyTime; @Schema(description = "表单数据,表单数据") @@ -64,6 +63,6 @@ public class MaterialLifecycleSaveReqVO { private String remark; @Schema(description = "工段列表") - private List gongIds; + private List detailList; } \ No newline at end of file diff --git a/zt-module-qms/zt-module-qms-server/src/main/java/com/zt/plat/module/qms/resource/material/dal/dataobject/MaterialLifecycleDetailDO.java b/zt-module-qms/zt-module-qms-server/src/main/java/com/zt/plat/module/qms/resource/material/dal/dataobject/MaterialLifecycleDetailDO.java index d5af1de..0fbc808 100644 --- a/zt-module-qms/zt-module-qms-server/src/main/java/com/zt/plat/module/qms/resource/material/dal/dataobject/MaterialLifecycleDetailDO.java +++ b/zt-module-qms/zt-module-qms-server/src/main/java/com/zt/plat/module/qms/resource/material/dal/dataobject/MaterialLifecycleDetailDO.java @@ -48,6 +48,11 @@ public class MaterialLifecycleDetailDO extends BusinessBaseDO { */ @TableField("BAT_GONG_ID") private Long batchGongduanId; + /** + * 是否检化验,1-是,0-否 + */ + @TableField("ASY_FLG") + private Integer assayFlag; /** * 物料实例id */ diff --git a/zt-module-qms/zt-module-qms-server/src/main/java/com/zt/plat/module/qms/resource/material/dal/mapper/MaterialBatchMapper.java b/zt-module-qms/zt-module-qms-server/src/main/java/com/zt/plat/module/qms/resource/material/dal/mapper/MaterialBatchMapper.java index 072b26f..ddcd184 100644 --- a/zt-module-qms/zt-module-qms-server/src/main/java/com/zt/plat/module/qms/resource/material/dal/mapper/MaterialBatchMapper.java +++ b/zt-module-qms/zt-module-qms-server/src/main/java/com/zt/plat/module/qms/resource/material/dal/mapper/MaterialBatchMapper.java @@ -1,7 +1,6 @@ package com.zt.plat.module.qms.resource.material.dal.mapper; import cn.hutool.core.collection.CollUtil; -import com.github.yulichang.base.MPJBaseMapper; import com.github.yulichang.wrapper.MPJLambdaWrapper; import com.zt.plat.framework.common.pojo.PageResult; import com.zt.plat.framework.mybatis.core.mapper.BaseMapperX; @@ -44,8 +43,38 @@ public interface MaterialBatchMapper extends BaseMapperX { .orderByDesc(MaterialBatchDO::getId)); } - // onlyGong 是否只查询工段 - default PageResult selectPage(MaterialBatchPageReqVO reqVO, List pdtIds, Boolean onlyGong) { + default PageResult selectPageWithPdtInfo(MaterialBatchPageReqVO reqVO, List pdtIds) { + + MPJLambdaWrapper wrapper = new MPJLambdaWrapperX() + .selectAll(MaterialBatchDO.class) + .selectAs(MaterialProductDO::getName, MaterialBatchRespVO::getProductName) + .selectAs(MaterialProductDO::getCode, MaterialBatchRespVO::getProductCode) + .selectAs(MaterialProductDO::getModelNo, MaterialBatchRespVO::getProductModelNo) + .leftJoin(MaterialProductDO.class, MaterialProductDO::getId, MaterialBatchDO::getProductId) + // 只查询批次 + .eq(MaterialBatchDO::getParentId, 0) + .in(CollUtil.isNotEmpty(pdtIds), MaterialBatchDO::getProductId, pdtIds) + .eq(CollUtil.isEmpty(pdtIds) && reqVO.getProductId() != null, MaterialBatchDO::getProductId, reqVO.getProductId()) + .likeIfExists(MaterialBatchDO::getBatchNo, reqVO.getBatchNo()) + .likeIfExists(MaterialBatchDO::getLocation, reqVO.getLocation()) + .likeIfExists(MaterialBatchDO::getSupplierId, reqVO.getSupplierId()) +// .betweenIfPresent(MaterialBatchDO::getManufacturerDate, reqVO.getManufacturerDate()) +// .betweenIfPresent(MaterialBatchDO::getDueDate, reqVO.getDueDate()) + .eqIfExists(MaterialBatchDO::getAssignDepartmentId, reqVO.getAssignDepartmentId()) + .likeIfExists(MaterialBatchDO::getAssignDepartmentName, reqVO.getAssignDepartmentName()) + .eqIfExists(MaterialBatchDO::getAcceptanceStatus, reqVO.getAcceptanceStatus()) + .eqIfExists(MaterialBatchDO::getAssayFlag, reqVO.getAssayFlag()) + .eqIfExists(MaterialBatchDO::getAssayStatus, reqVO.getAssayStatus()) + .eqIfExists(MaterialBatchDO::getSystemDepartmentCode, reqVO.getSystemDepartmentCode()) + .eqIfExists(MaterialBatchDO::getRemark, reqVO.getRemark()) +// .betweenIfPresent(MaterialBatchDO::getCreateTime, reqVO.getCreateTime()) + .orderByDesc(MaterialBatchDO::getId); + return selectJoinPage(reqVO, MaterialBatchRespVO.class, wrapper); + } + + default PageResult selectGongPage(MaterialBatchPageReqVO reqVO, List pdtIds) { + + LoginUser loginUser = SecurityFrameworkUtils.getLoginUser(); Long visitDeptId = null; if (loginUser != null) { @@ -57,11 +86,10 @@ public interface MaterialBatchMapper extends BaseMapperX { .selectAs(MaterialProductDO::getCode, MaterialBatchRespVO::getProductCode) .selectAs(MaterialProductDO::getModelNo, MaterialBatchRespVO::getProductModelNo) .leftJoin(MaterialProductDO.class, MaterialProductDO::getId, MaterialBatchDO::getProductId) - // 只查询批次,不查询工段 - .eq(onlyGong != null && !onlyGong, MaterialBatchDO::getParentId, 0) // 只查询工段 - .ne(onlyGong != null && onlyGong, MaterialBatchDO::getParentId, 0) - .eq(onlyGong != null && onlyGong, MaterialBatchDO::getSubmitStatus, 1) + .ne(MaterialBatchDO::getParentId, 0) + .eq(MaterialBatchDO::getSubmitStatus, 1) + .notExists("SELECT 1 FROM t_mtrl_lfc_dtl ld WHERE ld.BAT_GONG_ID = t.id AND ld.DELETED = 0") // .eq(onlyGong != null && visitDeptId != null && onlyGong, MaterialBatchDO::getAssignDepartmentId, visitDeptId) .in(CollUtil.isNotEmpty(pdtIds), MaterialBatchDO::getProductId, pdtIds) .eq(CollUtil.isEmpty(pdtIds) && reqVO.getProductId() != null, MaterialBatchDO::getProductId, reqVO.getProductId()) diff --git a/zt-module-qms/zt-module-qms-server/src/main/java/com/zt/plat/module/qms/resource/material/dal/mapper/MaterialLifecycleDetailMapper.java b/zt-module-qms/zt-module-qms-server/src/main/java/com/zt/plat/module/qms/resource/material/dal/mapper/MaterialLifecycleDetailMapper.java index 0de7b57..afd8649 100644 --- a/zt-module-qms/zt-module-qms-server/src/main/java/com/zt/plat/module/qms/resource/material/dal/mapper/MaterialLifecycleDetailMapper.java +++ b/zt-module-qms/zt-module-qms-server/src/main/java/com/zt/plat/module/qms/resource/material/dal/mapper/MaterialLifecycleDetailMapper.java @@ -1,5 +1,6 @@ package com.zt.plat.module.qms.resource.material.dal.mapper; +import com.github.yulichang.wrapper.MPJLambdaWrapper; import com.zt.plat.framework.common.pojo.PageResult; import com.zt.plat.framework.mybatis.core.mapper.BaseMapperX; import com.zt.plat.framework.mybatis.core.query.LambdaQueryWrapperX; @@ -39,16 +40,18 @@ public interface MaterialLifecycleDetailMapper extends BaseMapperX selectListWithPdtBatInfo(Long id){ - MPJLambdaWrapperX wrapperX = new MPJLambdaWrapperX() + MPJLambdaWrapper wrapper = new MPJLambdaWrapper() .selectAll(MaterialLifecycleDetailDO.class) .selectAs(MaterialProductDO::getName, MaterialLifecycleDetailRespVO::getProductName) .selectAs(MaterialProductDO::getCode, MaterialLifecycleDetailRespVO::getProductCode) .selectAs(MaterialProductDO::getModelNo, MaterialLifecycleDetailRespVO::getProductModelNo) - .selectAs(MaterialBatchDO::getBatchNo, MaterialLifecycleDetailRespVO::getBatchNo) + .selectAs("batch.BAT_NO", MaterialLifecycleDetailRespVO::getBatchNo) + .selectAs("gongduan.INB_QTY", MaterialLifecycleDetailRespVO::getInfluenceCount) .leftJoin(MaterialProductDO.class, MaterialProductDO::getId, MaterialLifecycleDetailDO::getProductId) - .leftJoin(MaterialBatchDO.class, MaterialBatchDO::getId, MaterialLifecycleDetailDO::getBatchId) + .leftJoin(MaterialBatchDO.class, "batch", MaterialBatchDO::getId, MaterialLifecycleDetailDO::getBatchId) + .leftJoin(MaterialBatchDO.class, "gongduan", MaterialBatchDO::getId, MaterialLifecycleDetailDO::getBatchGongduanId) .eq(MaterialLifecycleDetailDO::getLifecycleId, id); - return selectJoinList(MaterialLifecycleDetailRespVO.class, wrapperX); + return selectJoinList(MaterialLifecycleDetailRespVO.class, wrapper); } } \ No newline at end of file diff --git a/zt-module-qms/zt-module-qms-server/src/main/java/com/zt/plat/module/qms/resource/material/service/MaterialBatchServiceImpl.java b/zt-module-qms/zt-module-qms-server/src/main/java/com/zt/plat/module/qms/resource/material/service/MaterialBatchServiceImpl.java index b13774c..be6ff11 100644 --- a/zt-module-qms/zt-module-qms-server/src/main/java/com/zt/plat/module/qms/resource/material/service/MaterialBatchServiceImpl.java +++ b/zt-module-qms/zt-module-qms-server/src/main/java/com/zt/plat/module/qms/resource/material/service/MaterialBatchServiceImpl.java @@ -1,20 +1,15 @@ package com.zt.plat.module.qms.resource.material.service; import cn.hutool.core.collection.CollUtil; -import cn.hutool.core.util.StrUtil; import com.baomidou.mybatisplus.core.toolkit.Wrappers; -import com.zt.plat.framework.common.exception.ErrorCode; import com.zt.plat.framework.common.exception.ServiceException; import com.zt.plat.framework.common.pojo.PageResult; import com.zt.plat.framework.common.util.object.BeanUtils; import com.zt.plat.module.qms.core.code.SequenceUtil; -import com.zt.plat.module.qms.enums.ErrorCodeConstants; import com.zt.plat.module.qms.resource.material.controller.vo.MaterialBatchPageReqVO; import com.zt.plat.module.qms.resource.material.controller.vo.MaterialBatchRespVO; import com.zt.plat.module.qms.resource.material.controller.vo.MaterialBatchSaveReqVO; -import com.zt.plat.module.qms.resource.material.controller.vo.MaterialProductRespVO; import com.zt.plat.module.qms.resource.material.dal.dataobject.MaterialBatchDO; -import com.zt.plat.module.qms.resource.material.dal.dataobject.MaterialInfomationDO; import com.zt.plat.module.qms.resource.material.dal.dataobject.MaterialProductDO; import com.zt.plat.module.qms.resource.material.dal.mapper.MaterialBatchMapper; import jakarta.annotation.Resource; @@ -24,8 +19,6 @@ import org.springframework.transaction.annotation.Transactional; import org.springframework.validation.annotation.Validated; import java.math.BigDecimal; -import java.util.ArrayList; -import java.util.Calendar; import java.util.List; import java.util.Set; import java.util.stream.Collectors; @@ -71,12 +64,10 @@ public class MaterialBatchServiceImpl implements MaterialBatchService { public void updateMaterialBatch(MaterialBatchSaveReqVO updateReqVO) { // 校验存在 Long reqId = updateReqVO.getId(); - validateMaterialBatchExists(reqId); - - // 已经拆分工段的不可编辑 - List asnDOs = materialBatchMapper.selectList(Wrappers.lambdaQuery(MaterialBatchDO.class) - .eq(MaterialBatchDO::getParentId, reqId)); - if (CollUtil.isNotEmpty(asnDOs)) throw exception(MATERIAL_BATCH_ASSIGN_END); + MaterialBatchDO batchDO = materialBatchMapper.selectById(reqId); + if (batchDO == null) throw exception(MATERIAL_BATCH_NOT_EXISTS); + // 已经提交的不可修改 + if (batchDO.getSubmitStatus() == 1) throw new ServiceException(1_032_160_000, "批次已经提交,不可修改"); // 更新 MaterialBatchDO updateObj = BeanUtils.toBean(updateReqVO, MaterialBatchDO.class); @@ -137,11 +128,19 @@ public class MaterialBatchServiceImpl implements MaterialBatchService { @Override public PageResult getMaterialBatchPageWithPdtInfo(MaterialBatchPageReqVO pageReqVO) { - // 先分页查询批次或工段 - Boolean onlyGong = pageReqVO.getOnlyGong(); - PageResult pageResult = getMaterialBatchRespVOPageWithPdtInfo(pageReqVO, onlyGong); - // 只获取工段 - if (onlyGong) return pageResult; + Long pdtId = pageReqVO.getProductId(); + PageResult pageResult; + if (pdtId == null) { + pageResult = materialBatchMapper.selectPageWithPdtInfo(pageReqVO, List.of()); + } else { + List mtrlDos = materialProductService.getMaterialProductsByLikeIdPath(pdtId); + if (CollUtil.isEmpty(mtrlDos)) { + pageResult = materialBatchMapper.selectPageWithPdtInfo(pageReqVO, List.of()); + } else { + List pdtIds = mtrlDos.stream().map(MaterialProductDO::getId).toList(); + pageResult = materialBatchMapper.selectPageWithPdtInfo(pageReqVO, pdtIds); + } + } // 如果获取是批次分页,再根据批次ids获取工段 List batches = pageResult.getList(); if (CollUtil.isNotEmpty(batches)) { @@ -181,7 +180,7 @@ public class MaterialBatchServiceImpl implements MaterialBatchService { // 2. 拆分后的数量要相等 MaterialBatchDO mtrlBat = materialBatchMapper.selectById(batId); if (mtrlBat == null) throw exception(MATERIAL_BATCH_NOT_EXISTS); - + if (mtrlBat.getSubmitStatus() == 1) throw new ServiceException(1_032_160_000, "批次已经提交,不可修改"); BigDecimal total = BigDecimal.valueOf(0); for (MaterialBatchSaveReqVO batAsn : createReqVOs) { total = total.add(batAsn.getInboundQuantity()); @@ -192,7 +191,6 @@ public class MaterialBatchServiceImpl implements MaterialBatchService { boolean exists = materialBatchMapper.exists(Wrappers.lambdaQuery(MaterialBatchDO.class) .eq(MaterialBatchDO::getParentId, batId)); if (exists) { - if (mtrlBat.getSubmitStatus() == 1) throw new ServiceException(1_032_160_000, "批次已经提交,禁止修改"); // 删除之前的拆分数据 materialBatchMapper.delete(Wrappers.lambdaQuery(MaterialBatchDO.class) .eq(MaterialBatchDO::getParentId, batId)); @@ -267,22 +265,18 @@ public class MaterialBatchServiceImpl implements MaterialBatchService { @Override public PageResult getMaterialBatchGongPageWithPdtInfo(MaterialBatchPageReqVO pageReqVO) { - - return getMaterialBatchRespVOPageWithPdtInfo(pageReqVO, true); - } - - private PageResult getMaterialBatchRespVOPageWithPdtInfo(MaterialBatchPageReqVO pageReqVO, boolean onlyGong) { + // 需要排除已经被选择的工段 Long pdtId = pageReqVO.getProductId(); PageResult pageResult; if (pdtId == null) { - pageResult = materialBatchMapper.selectPage(pageReqVO, List.of(), onlyGong); + pageResult = materialBatchMapper.selectGongPage(pageReqVO, List.of()); } else { List mtrlDos = materialProductService.getMaterialProductsByLikeIdPath(pdtId); if (CollUtil.isEmpty(mtrlDos)) { - pageResult = materialBatchMapper.selectPage(pageReqVO, List.of(), onlyGong); + pageResult = materialBatchMapper.selectGongPage(pageReqVO, List.of()); } else { List pdtIds = mtrlDos.stream().map(MaterialProductDO::getId).toList(); - pageResult = materialBatchMapper.selectPage(pageReqVO, pdtIds, onlyGong); + pageResult = materialBatchMapper.selectGongPage(pageReqVO, pdtIds); } } return pageResult; diff --git a/zt-module-qms/zt-module-qms-server/src/main/java/com/zt/plat/module/qms/resource/material/service/MaterialLifecycleServiceImpl.java b/zt-module-qms/zt-module-qms-server/src/main/java/com/zt/plat/module/qms/resource/material/service/MaterialLifecycleServiceImpl.java index c6e1aef..37d0f3c 100644 --- a/zt-module-qms/zt-module-qms-server/src/main/java/com/zt/plat/module/qms/resource/material/service/MaterialLifecycleServiceImpl.java +++ b/zt-module-qms/zt-module-qms-server/src/main/java/com/zt/plat/module/qms/resource/material/service/MaterialLifecycleServiceImpl.java @@ -2,6 +2,8 @@ package com.zt.plat.module.qms.resource.material.service; import cn.hutool.core.collection.CollUtil; import cn.hutool.core.util.StrUtil; +import cn.hutool.json.JSONUtil; +import com.alibaba.fastjson.JSONObject; import com.zt.plat.framework.common.exception.ServiceException; import com.zt.plat.framework.common.pojo.CommonResult; import com.zt.plat.framework.common.pojo.PageResult; @@ -10,23 +12,28 @@ import com.zt.plat.framework.security.core.LoginUser; import com.zt.plat.framework.security.core.util.SecurityFrameworkUtils; import com.zt.plat.module.bpm.api.task.BpmProcessInstanceApi; import com.zt.plat.module.bpm.api.task.BpmTaskApi; +import com.zt.plat.module.bpm.api.task.dto.BpmProcessInstanceCreateReqDTO; import com.zt.plat.module.bpm.api.task.dto.BpmTaskApproveReqDTO; import com.zt.plat.module.bpm.api.task.dto.BpmTaskRespDTO; +import com.zt.plat.module.qms.api.task.BMPCallbackInterface; +import com.zt.plat.module.qms.api.task.dto.QmsBpmDTO; import com.zt.plat.module.qms.enums.QmsCommonConstant; -import com.zt.plat.module.qms.resource.material.controller.vo.MaterialLifecycleDetailRespVO; -import com.zt.plat.module.qms.resource.material.controller.vo.MaterialLifecyclePageReqVO; -import com.zt.plat.module.qms.resource.material.controller.vo.MaterialLifecycleRespVO; -import com.zt.plat.module.qms.resource.material.controller.vo.MaterialLifecycleSaveReqVO; +import com.zt.plat.module.qms.resource.material.controller.vo.*; import com.zt.plat.module.qms.resource.material.dal.dataobject.MaterialBatchDO; import com.zt.plat.module.qms.resource.material.dal.dataobject.MaterialLifecycleDO; import com.zt.plat.module.qms.resource.material.dal.dataobject.MaterialLifecycleDetailDO; import com.zt.plat.module.qms.resource.material.dal.mapper.MaterialLifecycleMapper; import jakarta.annotation.Resource; +import lombok.extern.slf4j.Slf4j; import org.springframework.beans.factory.annotation.Autowired; import org.springframework.stereotype.Service; import org.springframework.transaction.annotation.Transactional; import org.springframework.validation.annotation.Validated; +import java.text.SimpleDateFormat; +import java.time.LocalDateTime; +import java.util.Date; +import java.util.HashMap; import java.util.List; import java.util.Map; import java.util.function.Function; @@ -36,15 +43,17 @@ import static com.zt.plat.framework.common.exception.util.ServiceExceptionUtil.e import static com.zt.plat.framework.common.exception.util.ServiceExceptionUtil.exception0; import static com.zt.plat.module.qms.enums.ErrorCodeConstants.ERROR_CODE_MODULE_COMMON; import static com.zt.plat.module.qms.enums.ErrorCodeConstants.MATERIAL_LIFECYCLE_NOT_EXISTS; +import static com.zt.plat.module.qms.enums.QmsBpmConstant.BPM_CALLBACK_BEAN_NAME; /** * 物料通用流程,物料验收、退换货 Service 实现类 * * @author 后台管理 */ -@Service +@Slf4j +@Service("materialLifecycleService") @Validated -public class MaterialLifecycleServiceImpl implements MaterialLifecycleService { +public class MaterialLifecycleServiceImpl implements MaterialLifecycleService , BMPCallbackInterface { @Resource private MaterialLifecycleMapper materialLifecycleMapper; @@ -67,14 +76,28 @@ public class MaterialLifecycleServiceImpl implements MaterialLifecycleService { // 插入 MaterialLifecycleDO mtrlLfc = BeanUtils.toBean(createReqVO, MaterialLifecycleDO.class); mtrlLfc.setSubmitStatus(0); + String loginUserNickname = SecurityFrameworkUtils.getLoginUserNickname(); + LoginUser loginUser = SecurityFrameworkUtils.getLoginUser(); + if (loginUser == null) throw new ServiceException(1_032_160_000, "登录用户不存在"); + mtrlLfc.setApplyUser(loginUserNickname) + .setApplyUserId(loginUser.getId()) + .setApplyDepartment(loginUser.getVisitDeptName()) + .setApplyDepartmentId(loginUser.getVisitDeptId()); + mtrlLfc.setFlowStatus(QmsCommonConstant.NOT_START); materialLifecycleMapper.insert(mtrlLfc); - List gongIds = createReqVO.getGongIds(); - if (CollUtil.isEmpty(gongIds)) + List detailList = createReqVO.getDetailList(); + if (CollUtil.isEmpty(detailList)) return BeanUtils.toBean(mtrlLfc, MaterialLifecycleRespVO.class); // 保存工段明细 + List gongIds = detailList.stream().map(MaterialLifecycleDetailSaveReqVO::getBatchGongduanId).toList(); + Map gongAssayMap = detailList.stream().collect(Collectors.toMap( + MaterialLifecycleDetailSaveReqVO::getBatchGongduanId, MaterialLifecycleDetailSaveReqVO::getAssayFlag)); List gongs = materialBatchService.getGongduanListByGongIds(gongIds); if (CollUtil.isEmpty(gongs) || gongs.size() != gongIds.size()) throw new ServiceException(1_032_160_000, "工段不存在或与传入的工段数量不匹配"); + for (MaterialBatchDO gong : gongs) { + gong.setAssayFlag(gongAssayMap.get(gong.getId())); + } List detailDOS = getLifecycleDetailDOsByGongs(gongs, gongIds, mtrlLfc); materialLifecycleDetailService.saveBatch(detailDOS); return BeanUtils.toBean(mtrlLfc, MaterialLifecycleRespVO.class); @@ -92,6 +115,7 @@ public class MaterialLifecycleServiceImpl implements MaterialLifecycleService { detailDO.setLifecycleId(mtrlLfc.getId()) .setProductId(gong.getProductId()).setBatchId(gong.getParentId()) .setBatchGongduanId(gong.getId()) + .setAssayFlag(gong.getAssayFlag()) .setTreatmentStatus(0); return detailDO; }).toList(); @@ -104,21 +128,28 @@ public class MaterialLifecycleServiceImpl implements MaterialLifecycleService { MaterialLifecycleDO lifecycleDO = materialLifecycleMapper.selectById(reqId); if (lifecycleDO == null) throw exception(MATERIAL_LIFECYCLE_NOT_EXISTS); if (lifecycleDO.getSubmitStatus() == 1) throw new ServiceException(1_032_160_000, "流程已提交,不可修改"); - List gongIds = updateReqVO.getGongIds(); + List detailList = updateReqVO.getDetailList(); // 更新 MaterialLifecycleDO mtrlLfc = BeanUtils.toBean(updateReqVO, MaterialLifecycleDO.class); - if (CollUtil.isEmpty(gongIds)) { + if (CollUtil.isEmpty(detailList)) { materialLifecycleMapper.updateById(mtrlLfc); return; } // 删除原来的明细 materialLifecycleDetailService.deleteLifecycleDetailListByLfcId(reqId); + List gongIds = detailList.stream().map(MaterialLifecycleDetailSaveReqVO::getBatchGongduanId).toList(); + Map gongAssayMap = detailList.stream().collect(Collectors.toMap( + MaterialLifecycleDetailSaveReqVO::getBatchGongduanId, MaterialLifecycleDetailSaveReqVO::getAssayFlag)); List gongs = materialBatchService.getGongduanListByGongIds(gongIds); if (CollUtil.isEmpty(gongs) || gongs.size() != gongIds.size()) throw new ServiceException(1_032_160_000, "工段不存在或与传入的工段数量不匹配"); + for (MaterialBatchDO gong : gongs) { + gong.setAssayFlag(gongAssayMap.get(gong.getId())); + } // 保存新的明细 List detailDOS = getLifecycleDetailDOsByGongs(gongs, gongIds, mtrlLfc); materialLifecycleDetailService.saveBatch(detailDOS); + materialLifecycleMapper.updateById(mtrlLfc); } @Transactional @@ -178,7 +209,18 @@ public class MaterialLifecycleServiceImpl implements MaterialLifecycleService { @Override public PageResult getMaterialLifecyclePage(MaterialLifecyclePageReqVO pageReqVO) { - return materialLifecycleMapper.selectPage(pageReqVO); + PageResult pageResult = materialLifecycleMapper.selectPage(pageReqVO); + List list = pageResult.getList(); + if (CollUtil.isEmpty(list)) return pageResult; + list.forEach(mtrlLfc -> { + String formData = mtrlLfc.getFormData(); + if (formData != null) { + String title = (String) JSONUtil.parseObj(formData).get("title"); + mtrlLfc.setTitle(title); + } + }); + pageResult.setList(list); + return pageResult; } @Override @@ -187,7 +229,7 @@ public class MaterialLifecycleServiceImpl implements MaterialLifecycleService { if (lifecycleDO == null) throw exception(MATERIAL_LIFECYCLE_NOT_EXISTS); Integer submitStatus = lifecycleDO.getSubmitStatus(); if (submitStatus == 1) throw new ServiceException(1_032_160_000, "申请已经提交过"); - + lifecycleDO.setApplyTime(LocalDateTime.now()); // 发起流程 this.createProcessInstance(lifecycleDO); @@ -197,73 +239,10 @@ public class MaterialLifecycleServiceImpl implements MaterialLifecycleService { } private void createProcessInstance(MaterialLifecycleDO lifecycleDO) { - /* - LoginUser loginUser = SecurityFrameworkUtils.getLoginUser(); - //当前登录用户昵称 - String nickName = SecurityFrameworkUtils.getLoginUserNickname(); - Long id = param.getId(); - SupplierEvaluationDO entity = getSupplierEvaluation(id); - String flowInsId = entity.getFlowInstanceId(); - if(!ObjectUtils.isEmpty(flowInsId)){ - CommonResult> taskRet = bpmTaskApi.getTaskListByProcessInstanceId(flowInsId); - List taskList = taskRet.getData(); - if(taskList.isEmpty()) - throw exception0(ERROR_CODE_MODULE_COMMON, "流程任务查询失败,请联系管理员处理"); - String taskId = taskList.get(taskList.size() - 1).getId(); - //驳回后重新提交 - BpmTaskApproveReqDTO reqVO = new BpmTaskApproveReqDTO(); - reqVO.setId(taskId); - CommonResult result = bpmProcessInstanceApi.approveTask(reqVO); - if(!result.isSuccess()){ - throw exception0(ERROR_CODE_MODULE_COMMON, result.getMsg()); - } - entity.setFlowStatus(QmsCommonConstant.IN_PROGRESS); - //todo 生成报告编号 documentCode - supplierEvaluationMapper.updateById(entity); - SupplierEvaluationRespVO respVO = BeanUtils.toBean(entity, SupplierEvaluationRespVO.class); - return CommonResult.success(respVO); - } - JSONObject formData = new JSONObject(); - SimpleDateFormat sdf = new SimpleDateFormat("yyyy-MM-dd HH:mm:ss"); - - formData.put("mainId", id); - formData.put("applyUser", nickName); - formData.put("applyUserId", loginUser.getId()); - formData.put("applyDepartment", loginUser.getVisitDeptName()); - formData.put("applyDepartmentId", loginUser.getVisitDeptId()); - formData.put("applyTime", sdf.format(new Date())); - Map variables = formData.toJavaObject(Map.class); - variables.put(BPM_CALLBACK_BEAN_NAME, "supplierEvaluationService"); //流程回调时使用的service - BpmProcessInstanceCreateReqDTO reqDTO = new BpmProcessInstanceCreateReqDTO(); - reqDTO.setBusinessKey(String.valueOf(id)); - reqDTO.setProcessDefinitionKey(QmsSupplierConstant.EVALUATION_FLOW_KEY); - reqDTO.setVariables(variables); - CommonResult result = bpmProcessInstanceApi.createProcessInstance(loginUser.getId(), reqDTO); - if(!result.isSuccess()){ - throw exception0(ERROR_CODE_MODULE_COMMON, result.getMsg()); - } - String wfInsId = result.getData(); - entity.setFlowInstanceId(wfInsId); - entity.setFlowStatus(QmsCommonConstant.IN_PROGRESS); - entity.setEvaluationDate(LocalDateTime.now()); - entity.setEvaluator(nickName); - supplierEvaluationMapper.updateById(entity); - SupplierEvaluationRespVO respVO = BeanUtils.toBean(entity, SupplierEvaluationRespVO.class); - return CommonResult.success(respVO); - */ - // 发起人及其部门 - LoginUser loginUser = SecurityFrameworkUtils.getLoginUser(); - String loginUserNickname = SecurityFrameworkUtils.getLoginUserNickname(); - if (loginUser != null) { - lifecycleDO.setApplyUser(loginUserNickname) - .setApplyUserId(loginUser.getId()) - .setApplyDepartment(loginUser.getVisitDeptName()) - .setApplyDepartmentId(loginUser.getVisitDeptId()); - } String flowInstanceId = lifecycleDO.getFlowInstanceId(); - // 创建流程 - if (StrUtil.isEmpty(flowInstanceId)) { + // 流程已经发起过 + if (StrUtil.isNotEmpty(flowInstanceId)) { CommonResult> taskRet = bpmTaskApi.getTaskListByProcessInstanceId(flowInstanceId); List taskList = taskRet.getData(); if(CollUtil.isEmpty(taskList)) @@ -279,18 +258,85 @@ public class MaterialLifecycleServiceImpl implements MaterialLifecycleService { lifecycleDO.setFlowStatus(QmsCommonConstant.IN_PROGRESS); return; } + // 发起流程 + LoginUser loginUser = SecurityFrameworkUtils.getLoginUser(); + if (loginUser == null) return; + String loginUserNickname = SecurityFrameworkUtils.getLoginUserNickname(); + Long loginUserId = loginUser.getId(); + Map variables = new HashMap<>(); + SimpleDateFormat sdf = new SimpleDateFormat("yyyy-MM-dd HH:mm:ss"); - switch (lifecycleDO.getBusinessType()) { - case "acceptance": - // 发起验收流程 - break; - case "return_exchange": - // 发起退换货流程 - break; - case "config_apply": - // 配置申请 - break; + variables.put("mainId", lifecycleDO.getId()); + variables.put("applyUser", loginUserNickname); + variables.put("applyUserId", loginUserId); + variables.put("applyDepartment", loginUser.getVisitDeptName()); + variables.put("applyDepartmentId", loginUser.getVisitDeptId()); + variables.put("applyTime", sdf.format(new Date())); + variables.put(BPM_CALLBACK_BEAN_NAME, "materialLifecycleService"); + BpmProcessInstanceCreateReqDTO reqDTO = new BpmProcessInstanceCreateReqDTO(); + reqDTO.setBusinessKey(String.valueOf(lifecycleDO.getId())) + .setVariables(variables); + +// switch (lifecycleDO.getBusinessType()) { +// case "验收": +// reqDTO.setProcessDefinitionKey("MATERIAL_ACCEPTANCE_FLOW_KEY"); +// break; +// case "退换货": +// reqDTO.setProcessDefinitionKey("MATERIAL_RETURN_EXCHANGE_FLOW_KEY"); +// break; +// case "配置申请": +// reqDTO.setProcessDefinitionKey("MATERIAL_CONFIG_APPLY_FLOW_KEY"); +// break; +// } + reqDTO.setProcessDefinitionKey("QMS_RESOURCE_MATERIAL_COMMON"); + CommonResult result = bpmProcessInstanceApi.createProcessInstance(loginUserId, reqDTO); + if(!result.isSuccess()){ + throw exception0(ERROR_CODE_MODULE_COMMON, result.getMsg()); } + lifecycleDO.setFlowInstanceId(result.getData()); + lifecycleDO.setFlowStatus(QmsCommonConstant.IN_PROGRESS); + lifecycleDO.setApplyUser(loginUserNickname) + .setApplyUserId(loginUserId) + .setApplyDepartment(loginUser.getVisitDeptName()) + .setApplyDepartmentId(loginUser.getVisitDeptId()); } + /** + * 流程回调处理 + * + */ + @Override + public CommonResult callback(QmsBpmDTO reqDTO) { + log.info("物料流程回调信息:{}", reqDTO.toString()); + /* + QmsBpmDTO( + processInstanceId=042585c1-00e3-11f1-9df0-005056c00001, + businessKey=2018618104343769090, + variables={ + "_FLOWABLE_SKIP_EXPRESSION_ENABLED":true, + "processInstanceId":"042585c1-00e3-11f1-9df0-005056c00001", + "nrOfActiveInstances":1, + "bpmFieldExtensions":[], + "PROCESS_STATUS":1, + "currentActivityInsId":"043c904a-00e3-11f1-9df0-005056c00001", + "bpmCallbackBean":"materialLifecycleService", + "applyDepartment":"检验检测管理中心", + "Activity_0tp833v_assignees":["2008359763063820290"], + "loopCounter":0, + "applyUserId":"2008359763063820290", + "nrOfInstances":1, + "PROCESS_START_USER_ID":"2008359763063820290", + "applyUser":"云铜检验管理员", + "Activity_0tp833v_assignee":"2008359763063820290", + "applyDepartmentId":170, + "applyTime":"2026-02-03 17:30:44", + "mainId":"2018618104343769090", + "bpmCallbackActivityId":"Activity_0tp833v", + "nrOfCompletedInstances":1 + }, + state=) + */ + // 变更流程状态 + return null; + } } \ No newline at end of file