feat(mes): 为MES仓储模块添加BPM审批流程支持
- 为杂项出库单、杂项入库单、供应商退货单添加审批流程支持
- 新增APPROVING状态用于标识审批中状态
- 在DO和VO中添加processInstanceId字段存储BPM流程实例编号
- 实现submitApproval方法用于提交审批并创建BPM流程实例
- 添加getApprovalProcessList接口获取可用审批流程定义
- 集成BpmProcessInstanceApi和BpmProcessDefinitionService进行流程管理
- 实现审批状态更新逻辑,根据BPM结果更新单据状态
- 为三个单据类型添加对应的审批分类常量配置
- 更新控制器接口参数,增加processDefinitionKey传入
- 优化流程定义列表获取逻辑,过滤激活状态并保留最新版本
| | |
| | | # WM ä»å¨åæ® BPM å®¡æ¹ + 设å¤èå¨ - 宿½è¿åº¦ |
| | | |
| | | > è®°å½æ¥æï¼2026-09-07 |
| | | > ç¶æï¼é¶æ®µ1 åæå®æï¼å°æªæ¹ç ï¼é¶æ®µ2/3 å°æªå¼å§ |
| | | > ç¶æï¼é¶æ®µ1 æ¹ç å®æä¸ MES 模åç¼è¯éè¿ãæ°æ®åºå段已补ï¼é¶æ®µ2 已宿代ç åæï¼å°æªæ¹ç ï¼é¶æ®µ3 å°æªå¼å§ |
| | | |
| | | ## éæ± |
| | | |
| | |
| | | 2. 设å¤ç®¡çï¼è®¾å¤å°è´¦ï¼å建æ¶èªå¨å
¥åºè®¾å¤ä»ï¼ä¸åºåèå¨ã |
| | | 3. 设å¤**å¤ç¨ç©æä¸»æ°æ®æ¨¡å**ï¼å·²ç¡®è®¤ï¼ã |
| | | |
| | | ## é¶æ®µ1ï¼ä¸å¤§åæ®è¡¥é½ BPM 审æ¹éç¯ ââ åæå®æï¼æªæ¹ç |
| | | ## é¶æ®µ1ï¼ä¸å¤§åæ®è¡¥é½ BPM 审æ¹éç¯ ââ æ¹ç 宿ï¼ç¼è¯éè¿ |
| | | |
| | | ### 已确认ç°ç¶ï¼å¯ç´æ¥éä¿¡ï¼ |
| | | |
| | |
| | | 6. æ°å¢ 3 个çå¬å¨ï¼`MesWmMiscReceiptStatusListener`/`MesWmMiscIssueStatusListener`/`MesWmReturnVendorStatusListener`ï¼åç±» `misc_receipt_approve`/`misc_issue_approve`/`return_vendor_approve`ã |
| | | 7. æ°æ®åºï¼ä¸ä¸ªè¡¨åå `process_instance_id VARCHAR(64)`ï¼éµå® sql-syntax/sql-script è§èï¼ã |
| | | |
| | | ## é¶æ®µ2ï¼è®¾å¤å°è´¦èå¨è®¾å¤ä»ï¼æªå¼å§æ¹ç ï¼ |
| | | ### å·²å®æï¼æ¹ç ï¼ |
| | | |
| | | - æä¸¾ï¼miscreceipt/miscissue å·²å `APPROVING(MesOrderStatusConstants.APPROVING, "审æ¹ä¸")`ã |
| | | - DOï¼ä¸ä¸ª DO åå·²å `processInstanceId` åæ®µã |
| | | - RespVOï¼ä¸ä¸ªåæ® RespVO åå·²å `processInstanceId`ã |
| | | - Service æ¥å£ + Implï¼ä¸ä¸ªåæ®å·²å `submit<Biz>Approval(id, processDefinitionKey)`ã`update<Biz>AuditStatus(id, bpmResult)`ï¼APPROVEâAPPROVED, REJECTâPREPARE, CANCELâCANCELEDï¼ã`get<Biz>ApprovalProcessDefinitionList()`ï¼å¤ç¨ `MesWmItemReceipt` 模å¼ï¼è¿æ»¤æèµ·ãåææ°çæ¬ï¼ãä¸ä¸ªæ°å¢å¸¸éåç±»ï¼`APPROVE_CATEGORY_CODE = misc_receipt_approve / misc_issue_approve / return_vendor_approve`ã |
| | | - Controllerï¼ä¸ä¸ªåæ®å·²å `GET /approval-process-list`ï¼`/submit` æ¹ä¸ºå¸¦ `processDefinitionKey`ï¼è°ç¨å®¡æ¹æäº¤æ¹æ³ã |
| | | - çå¬å¨ï¼å·²æ°å¢ `MesWmMiscReceiptStatusListener`ã`MesWmMiscIssueStatusListener`ã`MesWmReturnVendorStatusListener`ï¼å `MesWmItemReceiptStatusListener` 飿 ¼ã |
| | | - ç¼è¯ï¼`mvn compile -pl yudao-module-mes -am -q` éè¿ã |
| | | - æ°æ®åºï¼å®é
è¿è¡åº mom-xgdlï¼ï¼ |
| | | - `mes_wm_misc_receipt`ã`mes_wm_misc_issue` åå·²æ `process_instance_id`ã |
| | | - `mes_wm_return_vendor` 已补 `process_instance_id VARCHAR(64)`ï¼å·²éªè¯çæï¼ã |
| | | |
| | | ### æªå®æï¼é¶æ®µ1 æ¶å°¾ï¼ |
| | | |
| | | - è¾åºå端èè°æ¹æ¡ææ¡£å° `docs/`ã |
| | | |
| | | ## é¶æ®µ2ï¼è®¾å¤å°è´¦èå¨è®¾å¤ä»ï¼åæå®æï¼æªæ¹ç ï¼ |
| | | |
| | | - å
³é®äºå®ï¼`MdmItemApi.createItem(MdmItemCreateReqDTO)` å¯å»ºç©æï¼å¿
å¡« code/name/categoryId/unitMeasureId/itemTypeï¼ï¼`MesDvMachineryDO` æ item_idï¼å
置设å¤ä» id=5 / åºåº SYS-EQUIP-LOC-01(id=11) / åºä½ SYS-EQUIP-BIN-01(id=10)ã |
| | | - æ¹æ¡ï¼`createMachinery` å äºå¡ â 建 MDM ç©æ â æè®¾å¤å°è´¦(item_id) â èªå¨çææ¡ç â `MesWmTransactionService` å
¥è®¾å¤ä»ï¼IN, qty=1ï¼ãæ´æ°/å é¤/导å
¥è·¯å¾åæ¥ã |
| | | |
| | | ### é¶æ®µ2 ç°ç¶ä¸åæç»è®ºï¼2026-09-07 è¡¥å
ï¼ |
| | | |
| | | - 设å¤å°è´¦å·²å®ä½ï¼`MesDvMachineryServiceImpl.java`ï¼éæ¹å
¥å£æä»¶ï¼ï¼`createMachinery`/`updateMachinery`/`deleteMachinery` å½åå**æ ** `@Transactional`ï¼ä»
æ `importMachineryList` æ `@Transactional`ã |
| | | - ç°æä¾èµï¼`machineryMapper`ã`barcodeService`ï¼èªå¨çææ¡ç â `BarcodeBizTypeEnum.MACHINERY`=DV_MACHINERY=400ï¼ã |
| | | - éè¿½å æ³¨å
¥ï¼`MdmItemApi`ï¼mes 模åå·²ä¾èµ yudao-module-mdmï¼ä¸æç°ææ³¨å
¥å
ä¾ï¼ã`MesWmTransactionService`ã |
| | | -`MdmItemCreateReqDTO` å¿
å¡«ï¼code/name/categoryId/unitMeasureId/itemTypeï¼å¯é warehouseId/warehouseCode/barCode/specification/remarkã**æ 设å¤ä¸ç¨å段**ï¼è®¾å¤-ç©æå
³èä¾èµæ°å¢ `mes_dv_machinery.item_id` ä¿åè¿åç itemIdã |
| | | - `MdmItemCreateReqDTO` ç¼ºå° categoryId/unitMeasureId/itemType çæ¥æºï¼è®¾å¤ SaveReqVO 没æè¿äºå段ï¼**éæç¡®é»è®¤ç©æåç±»ãé»è®¤è®¡éåä½ãç©æç±»åï¼è®¾å¤ï¼**åå®ç°ï¼æ¨ªçº¿çå¾
ç¡®å®ï¼ã |
| | | - åºåäºå¡ DTO `MesWmTransactionSaveReqDTO` å¿
å¡«ï¼type(IN=æ£æ°)/bizType/bizId/bizCode/bizLineId/itemId/quantity/warehouseId/locationId/areaIdã设å¤å°è´¦æ ç¬ç«è¡ IDï¼bizLineId ä¸å¡çº¦å®ç¨**设å¤ä¸»é® id**ã |
| | | - è®¾å¤ StatusEnum é确认ï¼è®¾å¤ç¶æå段 `status` å·²æï¼ä½å
¶æä¸¾å½åä¸åå¼å°æªæ ¸å¯¹ï¼ç©æç¶æç± MDM æ§å¶ï¼ã |
| | | - 设å¤ç©æç±»åï¼å½å MDM ç©æç±»åä¸å¡æ¯å¦å
许设å¤ç±»åé确认ï¼è¥åªå
许 1/2/3ï¼åæ°å¢æ£å¼è®¾å¤ç±»åå¼å¹¶åæ¥åå
¸ï¼ä¸å¨ MES å
é¨ç¡¬ç¼ç æªç¥ç±»åï¼ã |
| | | - 设å¤ãdeleteMachineryãå·²æç¹æ£/ä¿å
»/ç»´ä¿®å
³èæ ¡éªï¼å é¤åºåæ ¡éªå¯å¨åºåäºå¡å卿§æ ¡éªå¤è¡¥å
ã |
| | | |
| | | ï¼é¶æ®µ2 å°æªå¼å§æ¹ç ï¼ |
| | | |
| | | ## é¶æ®µ3ï¼ç¬ç«è®¾å¤å
¥åºåï¼æªå¼å§ï¼ |
| | | |
| | | - æ°å¢ `mes_wm_equipment_receipt` 主表+æç»è¡¨ãDO/Mapper/Service/VO/Controller/æä¸¾/ä¸å¡å¸¸éï¼BPM éç¯ï¼å®æå
¥åºå设å¤ä»ã |
| | |
| | | } |
| | | |
| | | @PutMapping("/submit") |
| | | @Operation(summary = "æäº¤æé¡¹åºåºå") |
| | | @Operation(summary = "æäº¤æé¡¹åºåºå审æ¹") |
| | | @Parameter(name = "id", description = "ç¼å·", required = true) |
| | | @Parameter(name = "processDefinitionKey", description = "æµç¨å®ä¹ Key", required = true) |
| | | @PreAuthorize("@ss.hasPermission('mes:wm-misc-issue:update')") |
| | | public CommonResult<Boolean> submitMiscIssue(@RequestParam("id") Long id) { |
| | | miscIssueService.submitMiscIssue(id); |
| | | public CommonResult<Boolean> submitMiscIssue(@RequestParam("id") Long id, |
| | | @RequestParam("processDefinitionKey") String processDefinitionKey) { |
| | | miscIssueService.submitMiscIssueApproval(id, processDefinitionKey); |
| | | return success(true); |
| | | } |
| | | |
| | | @GetMapping("/approval-process-list") |
| | | @Operation(summary = "è·å¾æé¡¹åºåºå®¡æ¹æµç¨å®ä¹å表") |
| | | @PreAuthorize("@ss.hasPermission('mes:wm-misc-issue:query')") |
| | | public CommonResult<List<java.util.Map<String, Object>>> getApprovalProcessList() { |
| | | return success(miscIssueService.getMiscIssueApprovalProcessDefinitionList()); |
| | | } |
| | | |
| | | @PutMapping("/finish") |
| | | @Operation(summary = "æ§è¡åºåº") |
| | | @Parameter(name = "id", description = "ç¼å·", required = true) |
| | |
| | | @Schema(description = "ç¶æ", requiredMode = Schema.RequiredMode.REQUIRED, example = "0") |
| | | private Integer status; |
| | | |
| | | @Schema(description = "BPM æµç¨å®ä¾ç¼å·", example = "xxx") |
| | | private String processInstanceId; |
| | | |
| | | @Schema(description = "夿³¨", example = "夿³¨") |
| | | private String remark; |
| | | |
| | |
| | | } |
| | | |
| | | @PutMapping("/submit") |
| | | @Operation(summary = "æäº¤å®¡æ¹") |
| | | @Operation(summary = "æäº¤æé¡¹å
¥åºå审æ¹") |
| | | @Parameter(name = "id", description = "ç¼å·", required = true) |
| | | @Parameter(name = "processDefinitionKey", description = "æµç¨å®ä¹ Key", required = true) |
| | | @PreAuthorize("@ss.hasPermission('mes:wm:misc-receipt:submit')") |
| | | public CommonResult<Boolean> submitMiscReceipt(@RequestParam("id") Long id) { |
| | | miscReceiptService.submitMiscReceipt(id); |
| | | public CommonResult<Boolean> submitMiscReceipt(@RequestParam("id") Long id, |
| | | @RequestParam("processDefinitionKey") String processDefinitionKey) { |
| | | miscReceiptService.submitMiscReceiptApproval(id, processDefinitionKey); |
| | | return success(true); |
| | | } |
| | | |
| | | @GetMapping("/approval-process-list") |
| | | @Operation(summary = "è·å¾æé¡¹å
¥åºå®¡æ¹æµç¨å®ä¹å表") |
| | | @PreAuthorize("@ss.hasPermission('mes:wm:misc-receipt:query')") |
| | | public CommonResult<List<java.util.Map<String, Object>>> getApprovalProcessList() { |
| | | return success(miscReceiptService.getMiscReceiptApprovalProcessDefinitionList()); |
| | | } |
| | | |
| | | @PutMapping("/finish") |
| | | @Operation(summary = "æ§è¡å
¥åº") |
| | | @Parameter(name = "id", description = "ç¼å·", required = true) |
| | |
| | | @Schema(description = "ç¶æ", example = "0") |
| | | private Integer status; |
| | | |
| | | @Schema(description = "BPM æµç¨å®ä¾ç¼å·", example = "xxx") |
| | | private String processInstanceId; |
| | | |
| | | @Schema(description = "夿³¨", example = "夿³¨") |
| | | private String remark; |
| | | |
| | |
| | | } |
| | | |
| | | @PutMapping("/submit") |
| | | @Operation(summary = "æäº¤ä¾åºåéè´§å") |
| | | @Operation(summary = "æäº¤ä¾åºåéè´§å审æ¹") |
| | | @Parameter(name = "id", description = "ç¼å·", required = true) |
| | | @Parameter(name = "processDefinitionKey", description = "æµç¨å®ä¹ Key", required = true) |
| | | @PreAuthorize("@ss.hasPermission('mes:wm-return-vendor:update')") |
| | | public CommonResult<Boolean> submitReturnVendor(@RequestParam("id") Long id) { |
| | | returnVendorService.submitReturnVendor(id); |
| | | public CommonResult<Boolean> submitReturnVendor(@RequestParam("id") Long id, |
| | | @RequestParam("processDefinitionKey") String processDefinitionKey) { |
| | | returnVendorService.submitReturnVendorApproval(id, processDefinitionKey); |
| | | return success(true); |
| | | } |
| | | |
| | | @GetMapping("/approval-process-list") |
| | | @Operation(summary = "è·å¾ä¾åºåéè´§å®¡æ¹æµç¨å®ä¹å表") |
| | | @PreAuthorize("@ss.hasPermission('mes:wm-return-vendor:query')") |
| | | public CommonResult<List<java.util.Map<String, Object>>> getApprovalProcessList() { |
| | | return success(returnVendorService.getReturnVendorApprovalProcessDefinitionList()); |
| | | } |
| | | |
| | | @PutMapping("/stock") |
| | | @Operation(summary = "æ§è¡æ£è´§") |
| | | @Parameter(name = "id", description = "ç¼å·", required = true) |
| | |
| | | @Schema(description = "ç¶æ", requiredMode = Schema.RequiredMode.REQUIRED, example = "10") |
| | | private Integer status; |
| | | |
| | | @Schema(description = "BPM æµç¨å®ä¾ç¼å·", example = "xxx") |
| | | private String processInstanceId; |
| | | |
| | | @Schema(description = "夿³¨", example = "夿³¨") |
| | | private String remark; |
| | | |
| | |
| | | */ |
| | | private Integer status; |
| | | /** |
| | | * BPM æµç¨å®ä¾ç¼å· |
| | | */ |
| | | private String processInstanceId; |
| | | /** |
| | | * 夿³¨ |
| | | */ |
| | | private String remark; |
| | |
| | | */ |
| | | private Integer status; |
| | | /** |
| | | * BPM æµç¨å®ä¾ç¼å· |
| | | */ |
| | | private String processInstanceId; |
| | | /** |
| | | * 夿³¨ |
| | | */ |
| | | private String remark; |
| | |
| | | */ |
| | | private Integer status; |
| | | /** |
| | | * BPM æµç¨å®ä¾ç¼å· |
| | | */ |
| | | private String processInstanceId; |
| | | /** |
| | | * 夿³¨ |
| | | */ |
| | | private String remark; |
| | |
| | | */ |
| | | PREPARE(MesOrderStatusConstants.PREPARE, "è稿"), |
| | | /** |
| | | * 审æ¹ä¸ |
| | | * |
| | | * å¯¹åº MesWmMiscIssueService#submitMiscIssueApproval æ¹æ³ |
| | | */ |
| | | APPROVING(MesOrderStatusConstants.APPROVING, "审æ¹ä¸"), |
| | | /** |
| | | * å¾
æ§è¡åºåº |
| | | * |
| | | * å¯¹åº MesWmMiscIssueService#submitMiscIssue æ¹æ³ |
| | | * å¯¹åº MesWmMiscIssueService#updateMiscIssueAuditStatus æ¹æ³ |
| | | */ |
| | | APPROVED(MesOrderStatusConstants.APPROVED, "å¾
æ§è¡åºåº"), |
| | | /** |
| | |
| | | */ |
| | | PREPARE(MesOrderStatusConstants.PREPARE, "è稿"), |
| | | /** |
| | | * 审æ¹ä¸ |
| | | * |
| | | * å¯¹åº MesWmMiscReceiptService#submitMiscReceiptApproval æ¹æ³ |
| | | */ |
| | | APPROVING(MesOrderStatusConstants.APPROVING, "审æ¹ä¸"), |
| | | /** |
| | | * å·²å®¡æ¹ |
| | | * |
| | | * å¯¹åº MesWmMiscReceiptService#submitMiscReceipt æ¹æ³ |
| | | * å¯¹åº MesWmMiscReceiptService#updateMiscReceiptAuditStatus æ¹æ³ |
| | | */ |
| | | APPROVED(MesOrderStatusConstants.APPROVED, "已审æ¹"), |
| | | /** |
| | |
| | | import cn.iocoder.yudao.module.mes.dal.dataobject.wm.miscissue.MesWmMiscIssueDO; |
| | | import jakarta.validation.Valid; |
| | | |
| | | import java.util.List; |
| | | import java.util.Map; |
| | | |
| | | /** |
| | | * MES æé¡¹åºåºå Service æ¥å£ |
| | | */ |
| | | public interface MesWmMiscIssueService { |
| | | |
| | | /** |
| | | * æé¡¹åºåº BPM 审æ¹åç±»ç¼ç |
| | | */ |
| | | String APPROVE_CATEGORY_CODE = "misc_issue_approve"; |
| | | |
| | | /** |
| | | * å建æé¡¹åºåºå |
| | |
| | | PageResult<MesWmMiscIssueDO> getMiscIssuePage(MesWmMiscIssuePageReqVO pageReqVO); |
| | | |
| | | /** |
| | | * æäº¤æé¡¹åºåºåï¼è稿 â å¾
æ§è¡åºåºï¼ |
| | | * æäº¤æé¡¹åºåºå审æ¹ï¼è稿 â 审æ¹ä¸ï¼ï¼å建 BPM æµç¨å®ä¾ |
| | | * |
| | | * @param id ç¼å· |
| | | * @param processDefinitionKey æµç¨å®ä¹ Key |
| | | */ |
| | | void submitMiscIssue(Long id); |
| | | void submitMiscIssueApproval(Long id, String processDefinitionKey); |
| | | |
| | | /** |
| | | * æ´æ°æé¡¹åºåºå审æ¹ç¶æï¼å®¡æ¹ä¸ â å¾
æ§è¡åºåº/è稿/å·²åæ¶ï¼ |
| | | * |
| | | * @param id ç¼å· |
| | | * @param bpmResult BPM 审æ¹ç»æ |
| | | */ |
| | | void updateMiscIssueAuditStatus(Long id, Integer bpmResult); |
| | | |
| | | /** |
| | | * è·åæé¡¹åºåºå®¡æ¹å¯ç¨ç BPM æµç¨å®ä¹å表 |
| | | * |
| | | * @return æµç¨å®ä¹å表ï¼id/key/nameï¼ |
| | | */ |
| | | List<Map<String, Object>> getMiscIssueApprovalProcessDefinitionList(); |
| | | |
| | | /** |
| | | * æ§è¡åºåºï¼å¾
æ§è¡åºåº â 已宿ï¼ï¼æ£ååºå |
| | |
| | | import cn.iocoder.yudao.module.mes.enums.wm.MesWmTransactionTypeEnum; |
| | | import cn.iocoder.yudao.module.mes.service.wm.transaction.MesWmTransactionService; |
| | | import cn.iocoder.yudao.module.mes.service.wm.transaction.dto.MesWmTransactionSaveReqDTO; |
| | | import cn.iocoder.yudao.module.bpm.api.task.BpmProcessInstanceApi; |
| | | import cn.iocoder.yudao.module.bpm.api.task.dto.BpmProcessInstanceCreateReqDTO; |
| | | import cn.iocoder.yudao.module.bpm.dal.dataobject.definition.BpmProcessDefinitionInfoDO; |
| | | import cn.iocoder.yudao.module.bpm.enums.task.BpmTaskStatusEnum; |
| | | import cn.iocoder.yudao.module.bpm.service.definition.BpmProcessDefinitionService; |
| | | import jakarta.annotation.Resource; |
| | | import lombok.extern.slf4j.Slf4j; |
| | | import org.flowable.engine.repository.ProcessDefinition; |
| | | import org.springframework.security.core.Authentication; |
| | | import org.springframework.security.core.context.SecurityContextHolder; |
| | | import org.springframework.stereotype.Service; |
| | | import org.springframework.transaction.annotation.Transactional; |
| | | import org.springframework.validation.annotation.Validated; |
| | | |
| | | import java.util.List; |
| | | import java.util.*; |
| | | |
| | | import static cn.iocoder.yudao.framework.common.exception.util.ServiceExceptionUtil.exception; |
| | | import static cn.iocoder.yudao.framework.common.util.collection.CollectionUtils.convertList; |
| | |
| | | private MesWmMiscIssueLineService miscIssueLineService; |
| | | @Resource |
| | | private MesWmTransactionService wmTransactionService; |
| | | @Resource |
| | | private BpmProcessInstanceApi processInstanceApi; |
| | | @Resource |
| | | private BpmProcessDefinitionService bpmProcessDefinitionService; |
| | | |
| | | @Override |
| | | public Long createMiscIssue(MesWmMiscIssueSaveReqVO createReqVO) { |
| | |
| | | |
| | | @Override |
| | | @Transactional(rollbackFor = Exception.class) |
| | | public void submitMiscIssue(Long id) { |
| | | public void submitMiscIssueApproval(Long id, String processDefinitionKey) { |
| | | // æ ¡éªåå¨ + èç¨¿ç¶æ |
| | | validateMiscIssueExistsAndDraft(id); |
| | | // æ ¡éªè³å°æä¸æ¡è¡ |
| | |
| | | if (CollUtil.isEmpty(lines)) { |
| | | throw exception(WM_MISC_ISSUE_NO_LINE); |
| | | } |
| | | |
| | | // æäº¤ï¼è稿 â å¾
æ§è¡åºåºï¼ |
| | | // å建 BPM æµç¨å®ä¾ |
| | | String processInstanceId = processInstanceApi.createProcessInstance(getCurrentUserId(), |
| | | new BpmProcessInstanceCreateReqDTO() |
| | | .setProcessDefinitionKey(processDefinitionKey) |
| | | .setBusinessKey(String.valueOf(id))); |
| | | // æäº¤å®¡æ¹ï¼è稿 â 审æ¹ä¸ï¼ |
| | | miscIssueMapper.updateById(new MesWmMiscIssueDO() |
| | | .setId(id).setStatus(MesWmMiscIssueStatusEnum.APPROVED.getStatus())); |
| | | .setId(id) |
| | | .setStatus(MesWmMiscIssueStatusEnum.APPROVING.getStatus()) |
| | | .setProcessInstanceId(processInstanceId)); |
| | | } |
| | | |
| | | @Override |
| | | public List<Map<String, Object>> getMiscIssueApprovalProcessDefinitionList() { |
| | | return getProcessDefinitionListByCategory(APPROVE_CATEGORY_CODE); |
| | | } |
| | | |
| | | @Override |
| | | @Transactional(rollbackFor = Exception.class) |
| | | public void updateMiscIssueAuditStatus(Long id, Integer bpmResult) { |
| | | // 1. æ ¡éªåå¨ |
| | | MesWmMiscIssueDO issue = validateMiscIssueExists(id); |
| | | if (!MesWmMiscIssueStatusEnum.APPROVING.getStatus().equals(issue.getStatus())) { |
| | | log.warn("[updateMiscIssueAuditStatus] æé¡¹åºåºå({}) ä¸å¤äºå®¡æ¹ä¸ç¶æ", id); |
| | | return; |
| | | } |
| | | // 2. æ ¹æ®å®¡æ¹ç»ææ´æ°ç¶æ |
| | | Integer newStatus = convertBpmResultToStatus(bpmResult); |
| | | if (newStatus != null) { |
| | | miscIssueMapper.updateById(new MesWmMiscIssueDO().setId(id).setStatus(newStatus)); |
| | | } |
| | | } |
| | | |
| | | private Integer convertBpmResultToStatus(Integer bpmResult) { |
| | | if (BpmTaskStatusEnum.APPROVE.getStatus().equals(bpmResult)) { |
| | | return MesWmMiscIssueStatusEnum.APPROVED.getStatus(); |
| | | } |
| | | if (BpmTaskStatusEnum.REJECT.getStatus().equals(bpmResult)) { |
| | | return MesWmMiscIssueStatusEnum.PREPARE.getStatus(); |
| | | } |
| | | if (BpmTaskStatusEnum.CANCEL.getStatus().equals(bpmResult)) { |
| | | return MesWmMiscIssueStatusEnum.CANCELED.getStatus(); |
| | | } |
| | | return null; |
| | | } |
| | | |
| | | private List<Map<String, Object>> getProcessDefinitionListByCategory(String categoryCode) { |
| | | List<BpmProcessDefinitionInfoDO> definitionInfoList = bpmProcessDefinitionService |
| | | .getProcessDefinitionInfoListByCategory(categoryCode); |
| | | if (CollUtil.isEmpty(definitionInfoList)) { |
| | | return Collections.emptyList(); |
| | | } |
| | | // è¿æ»¤æ¿æ´»ç¶æï¼ä¿çææ°çæ¬ |
| | | Map<String, ProcessDefinition> latestVersionMap = new HashMap<>(); |
| | | for (BpmProcessDefinitionInfoDO info : definitionInfoList) { |
| | | ProcessDefinition pd = bpmProcessDefinitionService.getProcessDefinition(info.getProcessDefinitionId()); |
| | | if (pd == null || pd.isSuspended()) { |
| | | continue; |
| | | } |
| | | ProcessDefinition existing = latestVersionMap.get(pd.getKey()); |
| | | if (existing == null || pd.getVersion() > existing.getVersion()) { |
| | | latestVersionMap.put(pd.getKey(), pd); |
| | | } |
| | | } |
| | | List<Map<String, Object>> result = new ArrayList<>(); |
| | | for (ProcessDefinition pd : latestVersionMap.values()) { |
| | | Map<String, Object> item = new HashMap<>(); |
| | | item.put("id", pd.getId()); |
| | | item.put("key", pd.getKey()); |
| | | item.put("name", pd.getName()); |
| | | result.add(item); |
| | | } |
| | | return result; |
| | | } |
| | | |
| | | private Long getCurrentUserId() { |
| | | Authentication authentication = SecurityContextHolder.getContext().getAuthentication(); |
| | | if (authentication != null && authentication.getPrincipal() instanceof Long) { |
| | | return (Long) authentication.getPrincipal(); |
| | | } |
| | | return 1L; // é»è®¤ç¨æ· |
| | | } |
| | | |
| | | @Override |
| ¶Ô±ÈÐÂÎļþ |
| | |
| | | package cn.iocoder.yudao.module.mes.service.wm.miscissue.listener; |
| | | |
| | | import cn.iocoder.yudao.module.bpm.api.event.BpmProcessInstanceStatusEvent; |
| | | import cn.iocoder.yudao.module.mes.service.wm.miscissue.MesWmMiscIssueService; |
| | | import jakarta.annotation.Resource; |
| | | import lombok.extern.slf4j.Slf4j; |
| | | import org.springframework.stereotype.Component; |
| | | |
| | | /** |
| | | * æé¡¹åºåºå BPM 审æ¹ç¶æçå¬å¨ |
| | | * |
| | | * çå¬ BPM æµç¨å®ä¾ç¶æåæ´äºä»¶ï¼æ´æ°æé¡¹åºåºåç审æ¹ç¶æ |
| | | */ |
| | | @Component |
| | | @Slf4j |
| | | public class MesWmMiscIssueStatusListener |
| | | extends cn.iocoder.yudao.module.bpm.api.event.BpmProcessInstanceStatusEventListener { |
| | | |
| | | @Resource |
| | | private MesWmMiscIssueService miscIssueService; |
| | | |
| | | @Override |
| | | protected String getProcessDefinitionKey() { |
| | | return MesWmMiscIssueService.APPROVE_CATEGORY_CODE; |
| | | } |
| | | |
| | | @Override |
| | | protected void onEvent(BpmProcessInstanceStatusEvent event) { |
| | | Long id; |
| | | try { |
| | | id = Long.parseLong(event.getBusinessKey()); |
| | | } catch (NumberFormatException e) { |
| | | log.warn("[onEvent] businessKey({}) 䏿¯ææçæé¡¹åºåºåç¼å·", event.getBusinessKey()); |
| | | return; |
| | | } |
| | | log.info("[onEvent] æ¶å°BPM审æ¹äºä»¶ï¼miscIssueId={}, status={}", id, event.getStatus()); |
| | | try { |
| | | miscIssueService.updateMiscIssueAuditStatus(id, event.getStatus()); |
| | | log.info("[onEvent] æé¡¹åºåºå({}) 审æ¹ç¶ææ´æ°å®æ", id); |
| | | } catch (Exception e) { |
| | | log.error("[onEvent] æ´æ°æé¡¹åºåºå审æ¹ç¶æå¤±è´¥ï¼miscIssueId={}", id, e); |
| | | } |
| | | } |
| | | |
| | | } |
| | |
| | | import cn.iocoder.yudao.module.mes.dal.dataobject.wm.miscreceipt.MesWmMiscReceiptDO; |
| | | import jakarta.validation.Valid; |
| | | |
| | | import java.util.List; |
| | | import java.util.Map; |
| | | |
| | | /** |
| | | * MES æé¡¹å
¥åºå Service æ¥å£ |
| | | * |
| | | * @author è¶
级管çå |
| | | */ |
| | | public interface MesWmMiscReceiptService { |
| | | |
| | | /** |
| | | * æé¡¹å
¥åº BPM 审æ¹åç±»ç¼ç |
| | | */ |
| | | String APPROVE_CATEGORY_CODE = "misc_receipt_approve"; |
| | | |
| | | /** |
| | | * å建æé¡¹å
¥åºå |
| | |
| | | PageResult<MesWmMiscReceiptDO> getMiscReceiptPage(MesWmMiscReceiptPageReqVO pageReqVO); |
| | | |
| | | /** |
| | | * æäº¤å®¡æ¹ï¼è稿 â 已审æ¹ï¼ |
| | | * æäº¤æé¡¹å
¥åºå审æ¹ï¼è稿 â 审æ¹ä¸ï¼ï¼å建 BPM æµç¨å®ä¾ |
| | | * |
| | | * @param id ç¼å· |
| | | * @param processDefinitionKey æµç¨å®ä¹ Key |
| | | */ |
| | | void submitMiscReceipt(Long id); |
| | | void submitMiscReceiptApproval(Long id, String processDefinitionKey); |
| | | |
| | | /** |
| | | * æ´æ°æé¡¹å
¥åºå审æ¹ç¶æï¼å®¡æ¹ä¸ â 已审æ¹/è稿/å·²åæ¶ï¼ |
| | | * |
| | | * @param id ç¼å· |
| | | * @param bpmResult BPM 审æ¹ç»æ |
| | | */ |
| | | void updateMiscReceiptAuditStatus(Long id, Integer bpmResult); |
| | | |
| | | /** |
| | | * è·åæé¡¹å
¥åºå®¡æ¹å¯ç¨ç BPM æµç¨å®ä¹å表 |
| | | * |
| | | * @return æµç¨å®ä¹å表ï¼id/key/nameï¼ |
| | | */ |
| | | List<Map<String, Object>> getMiscReceiptApprovalProcessDefinitionList(); |
| | | |
| | | /** |
| | | * æ§è¡å
¥åºï¼å·²å®¡æ¹ â 已宿ï¼ï¼æ´æ°åºåå°è´¦ |
| | |
| | | import cn.iocoder.yudao.module.mes.enums.wm.MesWmTransactionTypeEnum; |
| | | import cn.iocoder.yudao.module.mes.service.wm.transaction.MesWmTransactionService; |
| | | import cn.iocoder.yudao.module.mes.service.wm.transaction.dto.MesWmTransactionSaveReqDTO; |
| | | import cn.iocoder.yudao.module.bpm.api.task.BpmProcessInstanceApi; |
| | | import cn.iocoder.yudao.module.bpm.api.task.dto.BpmProcessInstanceCreateReqDTO; |
| | | import cn.iocoder.yudao.module.bpm.dal.dataobject.definition.BpmProcessDefinitionInfoDO; |
| | | import cn.iocoder.yudao.module.bpm.enums.task.BpmTaskStatusEnum; |
| | | import cn.iocoder.yudao.module.bpm.service.definition.BpmProcessDefinitionService; |
| | | import jakarta.annotation.Resource; |
| | | import lombok.extern.slf4j.Slf4j; |
| | | import org.flowable.engine.repository.ProcessDefinition; |
| | | import org.springframework.context.annotation.Lazy; |
| | | import org.springframework.security.core.Authentication; |
| | | import org.springframework.security.core.context.SecurityContextHolder; |
| | | import org.springframework.stereotype.Service; |
| | | import org.springframework.transaction.annotation.Transactional; |
| | | import org.springframework.validation.annotation.Validated; |
| | | |
| | | import java.util.*; |
| | | import java.util.List; |
| | | |
| | | import static cn.iocoder.yudao.framework.common.exception.util.ServiceExceptionUtil.exception; |
| | |
| | | private MesWmMiscReceiptLineService miscReceiptLineService; |
| | | @Resource |
| | | private MesWmTransactionService wmTransactionService; |
| | | @Resource |
| | | private BpmProcessInstanceApi processInstanceApi; |
| | | @Resource |
| | | private BpmProcessDefinitionService bpmProcessDefinitionService; |
| | | |
| | | @Override |
| | | public Long createMiscReceipt(MesWmMiscReceiptSaveReqVO createReqVO) { |
| | |
| | | |
| | | @Override |
| | | @Transactional(rollbackFor = Exception.class) |
| | | public void submitMiscReceipt(Long id) { |
| | | public void submitMiscReceiptApproval(Long id, String processDefinitionKey) { |
| | | // æ ¡éªåå¨ + èç¨¿ç¶æ |
| | | validateMiscReceiptExistsAndPrepare(id); |
| | | // æ ¡éªè³å°æä¸æ¡è¡ |
| | |
| | | if (CollUtil.isEmpty(lines)) { |
| | | throw exception(WM_MISC_RECEIPT_NO_LINE); |
| | | } |
| | | |
| | | // æäº¤å®¡æ¹ï¼è稿 â 已审æ¹ï¼ |
| | | // å建 BPM æµç¨å®ä¾ |
| | | String processInstanceId = processInstanceApi.createProcessInstance(getCurrentUserId(), |
| | | new BpmProcessInstanceCreateReqDTO() |
| | | .setProcessDefinitionKey(processDefinitionKey) |
| | | .setBusinessKey(String.valueOf(id))); |
| | | // æäº¤å®¡æ¹ï¼è稿 â 审æ¹ä¸ï¼ |
| | | miscReceiptMapper.updateById(new MesWmMiscReceiptDO() |
| | | .setId(id).setStatus(MesWmMiscReceiptStatusEnum.APPROVED.getStatus())); |
| | | .setId(id) |
| | | .setStatus(MesWmMiscReceiptStatusEnum.APPROVING.getStatus()) |
| | | .setProcessInstanceId(processInstanceId)); |
| | | } |
| | | |
| | | @Override |
| | | public List<Map<String, Object>> getMiscReceiptApprovalProcessDefinitionList() { |
| | | return getProcessDefinitionListByCategory(APPROVE_CATEGORY_CODE); |
| | | } |
| | | |
| | | @Override |
| | | @Transactional(rollbackFor = Exception.class) |
| | | public void updateMiscReceiptAuditStatus(Long id, Integer bpmResult) { |
| | | // 1. æ ¡éªåå¨ |
| | | MesWmMiscReceiptDO receipt = validateMiscReceiptExists(id); |
| | | if (!MesWmMiscReceiptStatusEnum.APPROVING.getStatus().equals(receipt.getStatus())) { |
| | | log.warn("[updateMiscReceiptAuditStatus] æé¡¹å
¥åºå({}) ä¸å¤äºå®¡æ¹ä¸ç¶æ", id); |
| | | return; |
| | | } |
| | | // 2. æ ¹æ®å®¡æ¹ç»ææ´æ°ç¶æ |
| | | Integer newStatus = convertBpmResultToStatus(bpmResult); |
| | | if (newStatus != null) { |
| | | miscReceiptMapper.updateById(new MesWmMiscReceiptDO().setId(id).setStatus(newStatus)); |
| | | } |
| | | } |
| | | |
| | | private Integer convertBpmResultToStatus(Integer bpmResult) { |
| | | if (BpmTaskStatusEnum.APPROVE.getStatus().equals(bpmResult)) { |
| | | return MesWmMiscReceiptStatusEnum.APPROVED.getStatus(); |
| | | } |
| | | if (BpmTaskStatusEnum.REJECT.getStatus().equals(bpmResult)) { |
| | | return MesWmMiscReceiptStatusEnum.PREPARE.getStatus(); |
| | | } |
| | | if (BpmTaskStatusEnum.CANCEL.getStatus().equals(bpmResult)) { |
| | | return MesWmMiscReceiptStatusEnum.CANCELED.getStatus(); |
| | | } |
| | | return null; |
| | | } |
| | | |
| | | private List<Map<String, Object>> getProcessDefinitionListByCategory(String categoryCode) { |
| | | List<BpmProcessDefinitionInfoDO> definitionInfoList = bpmProcessDefinitionService |
| | | .getProcessDefinitionInfoListByCategory(categoryCode); |
| | | if (CollUtil.isEmpty(definitionInfoList)) { |
| | | return Collections.emptyList(); |
| | | } |
| | | // è¿æ»¤æ¿æ´»ç¶æï¼ä¿çææ°çæ¬ |
| | | Map<String, ProcessDefinition> latestVersionMap = new HashMap<>(); |
| | | for (BpmProcessDefinitionInfoDO info : definitionInfoList) { |
| | | ProcessDefinition pd = bpmProcessDefinitionService.getProcessDefinition(info.getProcessDefinitionId()); |
| | | if (pd == null || pd.isSuspended()) { |
| | | continue; |
| | | } |
| | | ProcessDefinition existing = latestVersionMap.get(pd.getKey()); |
| | | if (existing == null || pd.getVersion() > existing.getVersion()) { |
| | | latestVersionMap.put(pd.getKey(), pd); |
| | | } |
| | | } |
| | | List<Map<String, Object>> result = new ArrayList<>(); |
| | | for (ProcessDefinition pd : latestVersionMap.values()) { |
| | | Map<String, Object> item = new HashMap<>(); |
| | | item.put("id", pd.getId()); |
| | | item.put("key", pd.getKey()); |
| | | item.put("name", pd.getName()); |
| | | result.add(item); |
| | | } |
| | | return result; |
| | | } |
| | | |
| | | private Long getCurrentUserId() { |
| | | Authentication authentication = SecurityContextHolder.getContext().getAuthentication(); |
| | | if (authentication != null && authentication.getPrincipal() instanceof Long) { |
| | | return (Long) authentication.getPrincipal(); |
| | | } |
| | | return 1L; // é»è®¤ç¨æ· |
| | | } |
| | | |
| | | @Override |
| ¶Ô±ÈÐÂÎļþ |
| | |
| | | package cn.iocoder.yudao.module.mes.service.wm.miscreceipt.listener; |
| | | |
| | | import cn.iocoder.yudao.module.bpm.api.event.BpmProcessInstanceStatusEvent; |
| | | import cn.iocoder.yudao.module.mes.service.wm.miscreceipt.MesWmMiscReceiptService; |
| | | import jakarta.annotation.Resource; |
| | | import lombok.extern.slf4j.Slf4j; |
| | | import org.springframework.stereotype.Component; |
| | | |
| | | /** |
| | | * æé¡¹å
¥åºå BPM 审æ¹ç¶æçå¬å¨ |
| | | * |
| | | * çå¬ BPM æµç¨å®ä¾ç¶æåæ´äºä»¶ï¼æ´æ°æé¡¹å
¥åºåç审æ¹ç¶æ |
| | | */ |
| | | @Component |
| | | @Slf4j |
| | | public class MesWmMiscReceiptStatusListener |
| | | extends cn.iocoder.yudao.module.bpm.api.event.BpmProcessInstanceStatusEventListener { |
| | | |
| | | @Resource |
| | | private MesWmMiscReceiptService miscReceiptService; |
| | | |
| | | @Override |
| | | protected String getProcessDefinitionKey() { |
| | | return MesWmMiscReceiptService.APPROVE_CATEGORY_CODE; |
| | | } |
| | | |
| | | @Override |
| | | protected void onEvent(BpmProcessInstanceStatusEvent event) { |
| | | Long id; |
| | | try { |
| | | id = Long.parseLong(event.getBusinessKey()); |
| | | } catch (NumberFormatException e) { |
| | | log.warn("[onEvent] businessKey({}) 䏿¯ææçæé¡¹å
¥åºåç¼å·", event.getBusinessKey()); |
| | | return; |
| | | } |
| | | log.info("[onEvent] æ¶å°BPM审æ¹äºä»¶ï¼miscReceiptId={}, status={}", id, event.getStatus()); |
| | | try { |
| | | miscReceiptService.updateMiscReceiptAuditStatus(id, event.getStatus()); |
| | | log.info("[onEvent] æé¡¹å
¥åºå({}) 审æ¹ç¶ææ´æ°å®æ", id); |
| | | } catch (Exception e) { |
| | | log.error("[onEvent] æ´æ°æé¡¹å
¥åºå审æ¹ç¶æå¤±è´¥ï¼miscReceiptId={}", id, e); |
| | | } |
| | | } |
| | | |
| | | } |
| | |
| | | import cn.iocoder.yudao.module.mes.dal.dataobject.wm.returnvendor.MesWmReturnVendorDO; |
| | | import jakarta.validation.Valid; |
| | | |
| | | import java.util.List; |
| | | import java.util.Map; |
| | | |
| | | /** |
| | | * MES ä¾åºåéè´§å Service æ¥å£ |
| | | */ |
| | | public interface MesWmReturnVendorService { |
| | | |
| | | /** |
| | | * ä¾åºåéè´§ BPM 审æ¹åç±»ç¼ç |
| | | */ |
| | | String APPROVE_CATEGORY_CODE = "return_vendor_approve"; |
| | | |
| | | /** |
| | | * å建ä¾åºåéè´§å |
| | |
| | | MesWmReturnVendorDO validateReturnVendorExists(Long id); |
| | | |
| | | /** |
| | | * æäº¤ä¾åºåéè´§åï¼è稿 -> å¾
æ£è´§ï¼ |
| | | * æäº¤ä¾åºåéè´§å审æ¹ï¼è稿 -> 审æ¹ä¸ï¼ï¼å建 BPM æµç¨å®ä¾ |
| | | * |
| | | * @param id ç¼å· |
| | | * @param processDefinitionKey æµç¨å®ä¹ Key |
| | | */ |
| | | void submitReturnVendor(Long id); |
| | | void submitReturnVendorApproval(Long id, String processDefinitionKey); |
| | | |
| | | /** |
| | | * æ´æ°ä¾åºåéè´§å审æ¹ç¶æï¼å®¡æ¹ä¸ -> å¾
æ§è¡éè´§/è稿/å·²åæ¶ï¼ |
| | | * |
| | | * @param id ç¼å· |
| | | * @param bpmResult BPM 审æ¹ç»æ |
| | | */ |
| | | void updateReturnVendorAuditStatus(Long id, Integer bpmResult); |
| | | |
| | | /** |
| | | * è·åä¾åºåé货审æ¹å¯ç¨ç BPM æµç¨å®ä¹å表 |
| | | * |
| | | * @return æµç¨å®ä¹å表ï¼id/key/nameï¼ |
| | | */ |
| | | List<Map<String, Object>> getReturnVendorApprovalProcessDefinitionList(); |
| | | |
| | | /** |
| | | * æ§è¡æ£è´§ï¼å¾
æ£è´§ -> å¾
æ§è¡éè´§ï¼ |
| | |
| | | import cn.iocoder.yudao.module.srm.api.supplier.SrmSupplierApi; |
| | | import cn.iocoder.yudao.module.mes.service.wm.transaction.MesWmTransactionService; |
| | | import cn.iocoder.yudao.module.mes.service.wm.transaction.dto.MesWmTransactionSaveReqDTO; |
| | | import cn.iocoder.yudao.module.bpm.api.task.BpmProcessInstanceApi; |
| | | import cn.iocoder.yudao.module.bpm.api.task.dto.BpmProcessInstanceCreateReqDTO; |
| | | import cn.iocoder.yudao.module.bpm.dal.dataobject.definition.BpmProcessDefinitionInfoDO; |
| | | import cn.iocoder.yudao.module.bpm.enums.task.BpmTaskStatusEnum; |
| | | import cn.iocoder.yudao.module.bpm.service.definition.BpmProcessDefinitionService; |
| | | import jakarta.annotation.Resource; |
| | | import lombok.extern.slf4j.Slf4j; |
| | | import org.flowable.engine.repository.ProcessDefinition; |
| | | import org.springframework.security.core.Authentication; |
| | | import org.springframework.security.core.context.SecurityContextHolder; |
| | | import org.springframework.stereotype.Service; |
| | | import org.springframework.transaction.annotation.Transactional; |
| | | import org.springframework.validation.annotation.Validated; |
| | | |
| | | import java.math.BigDecimal; |
| | | import java.util.List; |
| | | import java.util.*; |
| | | |
| | | import static cn.iocoder.yudao.framework.common.exception.util.ServiceExceptionUtil.exception; |
| | | import static cn.iocoder.yudao.framework.common.util.collection.CollectionUtils.convertList; |
| | |
| | | */ |
| | | @Service |
| | | @Validated |
| | | @Slf4j |
| | | public class MesWmReturnVendorServiceImpl implements MesWmReturnVendorService { |
| | | |
| | | @Resource |
| | |
| | | private SrmSupplierApi srmSupplierApi; |
| | | @Resource |
| | | private MesWmTransactionService wmTransactionService; |
| | | @Resource |
| | | private BpmProcessInstanceApi processInstanceApi; |
| | | @Resource |
| | | private BpmProcessDefinitionService bpmProcessDefinitionService; |
| | | |
| | | @Override |
| | | @Transactional(rollbackFor = Exception.class) |
| | |
| | | |
| | | @Override |
| | | @Transactional(rollbackFor = Exception.class) |
| | | public void submitReturnVendor(Long id) { |
| | | public void submitReturnVendorApproval(Long id, String processDefinitionKey) { |
| | | // æ ¡éªåå¨ + èç¨¿ç¶æ |
| | | validateReturnVendorExistsAndPrepare(id); |
| | | // æ ¡éªè³å°æä¸æ¡è¡ |
| | |
| | | if (CollUtil.isEmpty(lines)) { |
| | | throw exception(WM_RETURN_VENDOR_NO_LINE); |
| | | } |
| | | |
| | | // æäº¤ï¼è稿 -> å¾
æ£è´§ï¼ |
| | | // å建 BPM æµç¨å®ä¾ |
| | | String processInstanceId = processInstanceApi.createProcessInstance(getCurrentUserId(), |
| | | new BpmProcessInstanceCreateReqDTO() |
| | | .setProcessDefinitionKey(processDefinitionKey) |
| | | .setBusinessKey(String.valueOf(id))); |
| | | // æäº¤å®¡æ¹ï¼è稿 â 审æ¹ä¸ï¼ |
| | | returnVendorMapper.updateById(new MesWmReturnVendorDO() |
| | | .setId(id).setStatus(MesWmReturnVendorStatusEnum.APPROVING.getStatus())); |
| | | .setId(id) |
| | | .setStatus(MesWmReturnVendorStatusEnum.APPROVING.getStatus()) |
| | | .setProcessInstanceId(processInstanceId)); |
| | | } |
| | | |
| | | @Override |
| | | public List<Map<String, Object>> getReturnVendorApprovalProcessDefinitionList() { |
| | | return getProcessDefinitionListByCategory(APPROVE_CATEGORY_CODE); |
| | | } |
| | | |
| | | @Override |
| | | @Transactional(rollbackFor = Exception.class) |
| | | public void updateReturnVendorAuditStatus(Long id, Integer bpmResult) { |
| | | // 1. æ ¡éªåå¨ |
| | | MesWmReturnVendorDO returnVendor = validateReturnVendorExists(id); |
| | | if (!MesWmReturnVendorStatusEnum.APPROVING.getStatus().equals(returnVendor.getStatus())) { |
| | | log.warn("[updateReturnVendorAuditStatus] ä¾åºåéè´§å({}) ä¸å¤äºå®¡æ¹ä¸ç¶æ", id); |
| | | return; |
| | | } |
| | | // 2. æ ¹æ®å®¡æ¹ç»ææ´æ°ç¶æ |
| | | Integer newStatus = convertBpmResultToStatus(bpmResult); |
| | | if (newStatus != null) { |
| | | returnVendorMapper.updateById(new MesWmReturnVendorDO().setId(id).setStatus(newStatus)); |
| | | } |
| | | } |
| | | |
| | | private Integer convertBpmResultToStatus(Integer bpmResult) { |
| | | if (BpmTaskStatusEnum.APPROVE.getStatus().equals(bpmResult)) { |
| | | return MesWmReturnVendorStatusEnum.APPROVED.getStatus(); |
| | | } |
| | | if (BpmTaskStatusEnum.REJECT.getStatus().equals(bpmResult)) { |
| | | return MesWmReturnVendorStatusEnum.PREPARE.getStatus(); |
| | | } |
| | | if (BpmTaskStatusEnum.CANCEL.getStatus().equals(bpmResult)) { |
| | | return MesWmReturnVendorStatusEnum.CANCELED.getStatus(); |
| | | } |
| | | return null; |
| | | } |
| | | |
| | | private List<Map<String, Object>> getProcessDefinitionListByCategory(String categoryCode) { |
| | | List<BpmProcessDefinitionInfoDO> definitionInfoList = bpmProcessDefinitionService |
| | | .getProcessDefinitionInfoListByCategory(categoryCode); |
| | | if (CollUtil.isEmpty(definitionInfoList)) { |
| | | return Collections.emptyList(); |
| | | } |
| | | // è¿æ»¤æ¿æ´»ç¶æï¼ä¿çææ°çæ¬ |
| | | Map<String, ProcessDefinition> latestVersionMap = new HashMap<>(); |
| | | for (BpmProcessDefinitionInfoDO info : definitionInfoList) { |
| | | ProcessDefinition pd = bpmProcessDefinitionService.getProcessDefinition(info.getProcessDefinitionId()); |
| | | if (pd == null || pd.isSuspended()) { |
| | | continue; |
| | | } |
| | | ProcessDefinition existing = latestVersionMap.get(pd.getKey()); |
| | | if (existing == null || pd.getVersion() > existing.getVersion()) { |
| | | latestVersionMap.put(pd.getKey(), pd); |
| | | } |
| | | } |
| | | List<Map<String, Object>> result = new ArrayList<>(); |
| | | for (ProcessDefinition pd : latestVersionMap.values()) { |
| | | Map<String, Object> item = new HashMap<>(); |
| | | item.put("id", pd.getId()); |
| | | item.put("key", pd.getKey()); |
| | | item.put("name", pd.getName()); |
| | | result.add(item); |
| | | } |
| | | return result; |
| | | } |
| | | |
| | | private Long getCurrentUserId() { |
| | | Authentication authentication = SecurityContextHolder.getContext().getAuthentication(); |
| | | if (authentication != null && authentication.getPrincipal() instanceof Long) { |
| | | return (Long) authentication.getPrincipal(); |
| | | } |
| | | return 1L; // é»è®¤ç¨æ· |
| | | } |
| | | |
| | | @Override |
| ¶Ô±ÈÐÂÎļþ |
| | |
| | | package cn.iocoder.yudao.module.mes.service.wm.returnvendor.listener; |
| | | |
| | | import cn.iocoder.yudao.module.bpm.api.event.BpmProcessInstanceStatusEvent; |
| | | import cn.iocoder.yudao.module.mes.service.wm.returnvendor.MesWmReturnVendorService; |
| | | import jakarta.annotation.Resource; |
| | | import lombok.extern.slf4j.Slf4j; |
| | | import org.springframework.stereotype.Component; |
| | | |
| | | /** |
| | | * ä¾åºåéè´§å BPM 审æ¹ç¶æçå¬å¨ |
| | | * |
| | | * çå¬ BPM æµç¨å®ä¾ç¶æåæ´äºä»¶ï¼æ´æ°ä¾åºåéè´§åç审æ¹ç¶æ |
| | | */ |
| | | @Component |
| | | @Slf4j |
| | | public class MesWmReturnVendorStatusListener |
| | | extends cn.iocoder.yudao.module.bpm.api.event.BpmProcessInstanceStatusEventListener { |
| | | |
| | | @Resource |
| | | private MesWmReturnVendorService returnVendorService; |
| | | |
| | | @Override |
| | | protected String getProcessDefinitionKey() { |
| | | return MesWmReturnVendorService.APPROVE_CATEGORY_CODE; |
| | | } |
| | | |
| | | @Override |
| | | protected void onEvent(BpmProcessInstanceStatusEvent event) { |
| | | Long id; |
| | | try { |
| | | id = Long.parseLong(event.getBusinessKey()); |
| | | } catch (NumberFormatException e) { |
| | | log.warn("[onEvent] businessKey({}) 䏿¯ææçä¾åºåéè´§åç¼å·", event.getBusinessKey()); |
| | | return; |
| | | } |
| | | log.info("[onEvent] æ¶å°BPM审æ¹äºä»¶ï¼returnVendorId={}, status={}", id, event.getStatus()); |
| | | try { |
| | | returnVendorService.updateReturnVendorAuditStatus(id, event.getStatus()); |
| | | log.info("[onEvent] ä¾åºåéè´§å({}) 审æ¹ç¶ææ´æ°å®æ", id); |
| | | } catch (Exception e) { |
| | | log.error("[onEvent] æ´æ°ä¾åºåéè´§å审æ¹ç¶æå¤±è´¥ï¼returnVendorId={}", id, e); |
| | | } |
| | | } |
| | | |
| | | } |