From 05683f2b2bdbdbe21cf17ad523c21ab338bd1c54 Mon Sep 17 00:00:00 2001
From: wuxw <928255095@qq.com>
Date: 星期二, 19 七月 2022 21:49:55 +0800
Subject: [PATCH] 优化添加设备 功能

---
 service-common/src/main/java/com/java110/common/smo/impl/AllocationStorehouseUserInnerServiceSMOImpl.java |  144 ++++++++++++++++++++++++++++++++++++++++++-----
 1 files changed, 128 insertions(+), 16 deletions(-)

diff --git a/service-common/src/main/java/com/java110/common/smo/impl/AllocationStorehouseUserInnerServiceSMOImpl.java b/service-common/src/main/java/com/java110/common/smo/impl/AllocationStorehouseUserInnerServiceSMOImpl.java
index 91a5729..a1a380e 100644
--- a/service-common/src/main/java/com/java110/common/smo/impl/AllocationStorehouseUserInnerServiceSMOImpl.java
+++ b/service-common/src/main/java/com/java110/common/smo/impl/AllocationStorehouseUserInnerServiceSMOImpl.java
@@ -3,12 +3,21 @@
 import com.java110.core.base.smo.BaseServiceSMO;
 import com.java110.dto.PageDto;
 import com.java110.dto.allocationStorehouseApply.AllocationStorehouseApplyDto;
+import com.java110.dto.businessDatabus.CustomBusinessDatabusDto;
+import com.java110.dto.purchaseApply.PurchaseApplyDto;
+import com.java110.dto.storehouse.StorehouseDto;
 import com.java110.dto.workflow.WorkflowDto;
 import com.java110.entity.audit.AuditUser;
 import com.java110.intf.common.IAllocationStorehouseUserInnerServiceSMO;
 import com.java110.intf.common.IWorkflowInnerServiceSMO;
+import com.java110.intf.job.IDataBusInnerServiceSMO;
 import com.java110.intf.store.IAllocationStorehouseApplyInnerServiceSMO;
+import com.java110.intf.store.IPurchaseApplyInnerServiceSMO;
+import com.java110.intf.store.IStorehouseInnerServiceSMO;
+import com.java110.po.machine.MachineRecordPo;
+import com.java110.utils.constant.BusinessTypeConstant;
 import com.java110.utils.util.Assert;
+import com.java110.utils.util.BeanConvertUtil;
 import com.java110.utils.util.StringUtil;
 import org.activiti.engine.HistoryService;
 import org.activiti.engine.ProcessEngine;
@@ -31,6 +40,8 @@
 import java.util.List;
 import java.util.Map;
 
+import static com.java110.dto.storehouse.StorehouseDto.SH_TYPE_GROUP;
+
 //@Service("resourceEntryStoreSMOImpl")
 @RestController
 public class AllocationStorehouseUserInnerServiceSMOImpl extends BaseServiceSMO implements IAllocationStorehouseUserInnerServiceSMO {
@@ -47,6 +58,16 @@
     @Autowired
     private IWorkflowInnerServiceSMO workflowInnerServiceSMOImpl;
 
+    @Autowired
+    private IPurchaseApplyInnerServiceSMO purchaseApplyInnerServiceSMOImpl;
+
+    @Autowired
+    private IDataBusInnerServiceSMO dataBusInnerServiceSMOImpl;
+
+    @Autowired
+    private IStorehouseInnerServiceSMO iStorehouseInnerServiceSMO;
+
+
     /**
      * 鍚姩娴佺▼
      *
@@ -58,16 +79,47 @@
         variables.put("allocationStorehouseApplyDto", allocationStorehouseApplyDto);
         variables.put("userId", allocationStorehouseApplyDto.getCurrentUserId());
         variables.put("startUserId", allocationStorehouseApplyDto.getCurrentUserId());
+        variables.put("nextUserId", allocationStorehouseApplyDto.getNextUserId());
+        //鏌ヨ璋冩嫧婧愪粨搴撴槸闆嗗洟浠撳簱杩樻槸灏忓尯浠撳簱锛屽皬鍖轰粨搴撹蛋琚皟鎷ㄦ祦绋嬪鎵�
+        StorehouseDto storehouseDto = new StorehouseDto();
+        storehouseDto.setShId(allocationStorehouseApplyDto.getShId());
+        List<StorehouseDto> storehouseDtoList = iStorehouseInnerServiceSMO.queryStorehouses(storehouseDto);
+        StorehouseDto storehouseDto1 = new StorehouseDto();
+        String communityId = null;
+        if (storehouseDtoList != null && storehouseDtoList.size() > 0) {
+            storehouseDto1 = storehouseDtoList.get(0);
+        }
+        if (SH_TYPE_GROUP.equals(storehouseDto1.getShType())) {//闆嗗洟浠撳簱
+            communityId = "9999";
+        } else {//灏忓尯浠撳簱
+            communityId = storehouseDto1.getShObjId();
+        }
         //寮�鍚祦绋�
-        ProcessInstance processInstance = runtimeService.startProcessInstanceByKey(getWorkflowDto(allocationStorehouseApplyDto.getStoreId()), allocationStorehouseApplyDto.getApplyId(), variables);
+        ProcessInstance processInstance = runtimeService.startProcessInstanceByKey(getWorkflowDto(allocationStorehouseApplyDto.getStoreId(), communityId), allocationStorehouseApplyDto.getApplyId(), variables);
         //灏嗗緱鍒扮殑瀹炰緥娴佺▼id鍊艰祴缁欎箣鍓嶈缃殑鍙橀噺
         String processInstanceId = processInstance.getId();
         // System.out.println("娴佺▼寮�鍚垚鍔�.......瀹炰緥娴佺▼id:" + processInstanceId);
-
+        String processDefinitionId = processInstance.getProcessDefinitionId();
+        String businessKey = processInstance.getBusinessKey();
+        //鑾峰彇涓嬬骇澶勭悊浜篿d
+        PurchaseApplyDto purchaseDto = new PurchaseApplyDto();
+        purchaseDto.setActRuTaskId(processInstanceId);
+        purchaseDto.setProcDefId(processDefinitionId);
+        purchaseDto.setBusinessKey(businessKey);
+        List<PurchaseApplyDto> actRuTaskUserIds = purchaseApplyInnerServiceSMOImpl.getActRuTaskUserId(purchaseDto);
         allocationStorehouseApplyDto.setProcessInstanceId(processInstanceId);
-
+        if (actRuTaskUserIds != null && actRuTaskUserIds.size() > 0) {
+            for (PurchaseApplyDto purchaseApply : actRuTaskUserIds) {
+                String actRuTaskUserId = purchaseApply.getTaskUserId();
+                MachineRecordPo machineRecordPo = new MachineRecordPo();
+                machineRecordPo.setApplyOrderId(businessKey);
+                machineRecordPo.setPurchaseUserId(actRuTaskUserId);
+                //浼犻�乨atabus
+                dataBusInnerServiceSMOImpl.customExchange(CustomBusinessDatabusDto.getInstance(
+                        BusinessTypeConstant.BUSINESS_TYPE_DATABUS_ALLOCATION_STOREHOUSE_APPLY, BeanConvertUtil.beanCovertJson(machineRecordPo)));
+            }
+        }
         return allocationStorehouseApplyDto;
-
     }
 
     /**
@@ -78,7 +130,9 @@
      */
     public long getUserTaskCount(@RequestBody AuditUser user) {
         TaskService taskService = processEngine.getTaskService();
-        TaskQuery query = taskService.createTaskQuery().processDefinitionKey(getWorkflowDto(user.getStoreId()));
+        List<String> workflowlist = getWorkflowDto1(user.getStoreId());
+        TaskQuery query = taskService.createTaskQuery().processDefinitionKeyIn(workflowlist);
+//        TaskQuery query = taskService.createTaskQuery().processDefinitionKey(getWorkflowDto(user.getStoreId(), user.getCommunityId()));
         query.taskAssignee(user.getUserId());
         return query.count();
     }
@@ -90,12 +144,12 @@
      */
     public List<AllocationStorehouseApplyDto> getUserTasks(@RequestBody AuditUser user) {
         TaskService taskService = processEngine.getTaskService();
-        TaskQuery query = taskService.createTaskQuery().processDefinitionKey(getWorkflowDto(user.getStoreId()));
+        TaskQuery query = taskService.createTaskQuery().processDefinitionKeyIn(getWorkflowDto1(user.getStoreId()));
         query.taskAssignee(user.getUserId());
         query.orderByTaskCreateTime().desc();
         List<Task> list = null;
         if (user.getPage() >= 1) {
-            user.setPage(user.getPage() - 1);
+            user.setPage((user.getPage() - 1) * user.getRow());
         }
         if (user.getPage() != PageDto.DEFAULT_PAGE) {
             list = query.listPage(user.getPage(), user.getRow());
@@ -161,21 +215,49 @@
         return true;
     }
 
-
-    private String getWorkflowDto(String storeId) {
+    private String getWorkflowDto(String storeId, String communityId) {
         //寮�鍚祦绋�
         //WorkflowDto.DEFAULT_PROCESS + workflowDto.getFlowId()
         WorkflowDto workflowDto = new WorkflowDto();
-        workflowDto.setFlowType(WorkflowDto.FLOW_TYPE_ALLOCATION_STOREHOUSE);
+        if (!StringUtil.isEmpty(communityId) && "9999".equals(communityId)) {
+            workflowDto.setFlowType(WorkflowDto.FLOW_TYPE_ALLOCATION_STOREHOUSE);
+        } else {
+            workflowDto.setFlowType(WorkflowDto.FLOW_TYPE_ALLOCATION_STOREHOUSE_GO);
+        }
         workflowDto.setStoreId(storeId);
+        workflowDto.setCommunityId(communityId);
         List<WorkflowDto> workflowDtos = workflowInnerServiceSMOImpl.queryWorkflows(workflowDto);
-        Assert.listOnlyOne(workflowDtos, "鏈壘鍒� 鎶曡瘔寤鸿娴佺▼鎴栨壘鍒板鏉★紝璇峰湪鐗╀笟璐﹀彿绯荤粺绠$悊涓嬫祦绋嬬鐞嗕腑閰嶇疆娴佺▼");
-
+        Assert.listOnlyOne(workflowDtos, "鏈壘鍒� 璋冩嫧娴佺▼鎴栨壘鍒板鏉★紝璇峰湪鐗╀笟璐﹀彿绯荤粺绠$悊涓嬫祦绋嬬鐞嗕腑閰嶇疆娴佺▼");
         WorkflowDto tmpWorkflowDto = workflowDtos.get(0);
         if (StringUtil.isEmpty(tmpWorkflowDto.getProcessDefinitionKey())) {
-            throw new IllegalArgumentException("鍚堝悓璧疯崏缁娴佺▼杩樻湭閮ㄧ讲");
+            throw new IllegalArgumentException("璋冩嫧娴佺▼娴佺▼杩樻湭閮ㄧ讲");
         }
         return WorkflowDto.DEFAULT_PROCESS + tmpWorkflowDto.getFlowId();
+    }
+
+    private List<String> getWorkflowDto1(String storeId) {
+
+        //寮�鍚祦绋�
+        //WorkflowDto.DEFAULT_PROCESS + workflowDto.getFlowId()
+        WorkflowDto workflowDto = new WorkflowDto();
+        String[] flowTypes = new String[]{WorkflowDto.FLOW_TYPE_ALLOCATION_STOREHOUSE, WorkflowDto.FLOW_TYPE_ALLOCATION_STOREHOUSE_GO};
+        workflowDto.setFlowTypes(flowTypes);
+        workflowDto.setStoreId(storeId);
+        List<WorkflowDto> workflowDtos = workflowInnerServiceSMOImpl.queryWorkflows(workflowDto);
+        if (workflowDtos != null && workflowDtos.size() == 0) {
+            throw new IllegalArgumentException("鏈壘鍒� 璋冩嫧娴佺▼锛岃鍦ㄧ墿涓氳处鍙风郴缁熺鐞嗕笅娴佺▼绠$悊涓厤缃祦绋�!");
+        }
+        List<String> flowIdList = new ArrayList<String>();
+        for (WorkflowDto workflowDto1 : workflowDtos) {
+            if (StringUtil.isEmpty(workflowDto1.getProcessDefinitionKey()) && WorkflowDto.FLOW_TYPE_ALLOCATION_STOREHOUSE.equals(workflowDto1.getFlowType())) {
+                throw new IllegalArgumentException("灏忓尯缂栫爜=" + workflowDto1.getCommunityId() + "鐨勭墿鍝佽皟鎷ㄦ祦绋嬭繕鏈儴缃�");
+            }
+            if (StringUtil.isEmpty(workflowDto1.getProcessDefinitionKey()) && WorkflowDto.FLOW_TYPE_ALLOCATION_STOREHOUSE_GO.equals(workflowDto1.getFlowType())) {
+                throw new IllegalArgumentException("灏忓尯缂栫爜=" + workflowDto1.getCommunityId() + "鐨勭墿鍝佽璋冩嫧杩樻湭閮ㄧ讲");
+            }
+            flowIdList.add(WorkflowDto.DEFAULT_PROCESS + workflowDto1.getFlowId());
+        }
+        return flowIdList;
     }
 
     /**
@@ -191,7 +273,7 @@
 //                .taskAssignee(user.getUserId());
 
         HistoricTaskInstanceQuery historicTaskInstanceQuery = historyService.createHistoricTaskInstanceQuery()
-                .processDefinitionKey(getWorkflowDto(user.getStoreId()))
+                .processDefinitionKeyIn(getWorkflowDto1(user.getStoreId()))
                 .taskAssignee(user.getUserId())
                 .finished();
         if (!StringUtil.isEmpty(user.getAuditLink()) && "START".equals(user.getAuditLink())) {
@@ -213,7 +295,7 @@
         HistoryService historyService = processEngine.getHistoryService();
 
         HistoricTaskInstanceQuery historicTaskInstanceQuery = historyService.createHistoricTaskInstanceQuery()
-                .processDefinitionKey(getWorkflowDto(user.getStoreId()))
+                .processDefinitionKeyIn(getWorkflowDto1(user.getStoreId()))
                 .taskAssignee(user.getUserId())
                 .finished();
 //        if (!StringUtil.isEmpty(user.getAuditLink()) && "START".equals(user.getAuditLink())) {
@@ -258,6 +340,15 @@
 
 
     public boolean completeTask(@RequestBody AllocationStorehouseApplyDto allocationStorehouseApplyDto) {
+        //鑾峰彇鐘舵�佹爣璇�
+        String noticeState = allocationStorehouseApplyDto.getNoticeState();
+        //鑾峰彇瀹℃壒鐘舵��
+        String auditCode = allocationStorehouseApplyDto.getAuditCode();
+        //鑾峰彇鎷掔粷鐞嗙敱
+        String auditMessage = "";
+        if (!StringUtil.isEmpty(auditCode) && auditCode.equals("1200")) {
+            auditMessage = allocationStorehouseApplyDto.getAuditMessage();
+        }
         TaskService taskService = processEngine.getTaskService();
         Task task = taskService.createTaskQuery().taskId(allocationStorehouseApplyDto.getTaskId()).singleResult();
         String processInstanceId = task.getProcessInstanceId();
@@ -269,11 +360,32 @@
         variables.put("flag", "1200".equals(allocationStorehouseApplyDto.getAuditCode()) ? "false" : "true");
         variables.put("startUserId", allocationStorehouseApplyDto.getStartUserId());
         taskService.complete(allocationStorehouseApplyDto.getTaskId(), variables);
-
         ProcessInstance pi = runtimeService.createProcessInstanceQuery().processInstanceId(processInstanceId).singleResult();
         if (pi == null) {
             return true;
         }
+        String rootProcessInstanceId = pi.getId();
+        String processDefinitionId = pi.getProcessDefinitionId();
+        String businessKey = pi.getBusinessKey();
+        //鑾峰彇涓嬬骇澶勭悊浜篿d
+        PurchaseApplyDto purchaseDto = new PurchaseApplyDto();
+        purchaseDto.setActRuTaskId(rootProcessInstanceId);
+        purchaseDto.setProcDefId(processDefinitionId);
+        purchaseDto.setBusinessKey(businessKey);
+        List<PurchaseApplyDto> actRuTaskUserIds = purchaseApplyInnerServiceSMOImpl.getActRuTaskUserId(purchaseDto);
+        if (actRuTaskUserIds != null && actRuTaskUserIds.size() > 0) {
+            for (PurchaseApplyDto purchaseApply : actRuTaskUserIds) {
+                String actRuTaskUserId = purchaseApply.getTaskUserId();
+                MachineRecordPo machineRecordPo = new MachineRecordPo();
+                machineRecordPo.setApplyOrderId(businessKey);
+                machineRecordPo.setPurchaseUserId(actRuTaskUserId);
+                machineRecordPo.setNoticeState(noticeState);
+                machineRecordPo.setAuditMessage(auditMessage);
+                //浼犻�乨atabus
+                dataBusInnerServiceSMOImpl.customExchange(CustomBusinessDatabusDto.getInstance(
+                        BusinessTypeConstant.BUSINESS_TYPE_DATABUS_ALLOCATION_STOREHOUSE_APPLY, BeanConvertUtil.beanCovertJson(machineRecordPo)));
+            }
+        }
         return false;
     }
 

--
Gitblit v1.8.0