From 6e8c95d31d85b53857e4e3ce12ea303eb0ea42eb Mon Sep 17 00:00:00 2001
From: java110 <928255095@qq.com>
Date: 星期四, 19 八月 2021 00:47:48 +0800
Subject: [PATCH] 优化代码

---
 service-common/src/main/java/com/java110/common/smo/impl/AllocationStorehouseUserInnerServiceSMOImpl.java |  174 +++++++++++++++++++++++++++++++++++++--------------------
 1 files changed, 113 insertions(+), 61 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 2bc83ec..47fe8b6 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
@@ -1,16 +1,21 @@
 package com.java110.common.smo.impl;
 
-
 import com.java110.core.base.smo.BaseServiceSMO;
 import com.java110.dto.PageDto;
-import com.java110.dto.allocationStorehouse.AllocationStorehouseDto;
+import com.java110.dto.allocationStorehouseApply.AllocationStorehouseApplyDto;
+import com.java110.dto.businessDatabus.CustomBusinessDatabusDto;
+import com.java110.dto.purchaseApply.PurchaseApplyDto;
 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.store.IAllocationStorehouseInnerServiceSMO;
-import com.java110.intf.store.IContractInnerServiceSMO;
+import com.java110.intf.job.IDataBusInnerServiceSMO;
+import com.java110.intf.store.IAllocationStorehouseApplyInnerServiceSMO;
+import com.java110.intf.store.IPurchaseApplyInnerServiceSMO;
+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;
@@ -44,36 +49,54 @@
     private RuntimeService runtimeService;
 
     @Autowired
-    private TaskService taskService;
-
-    @Autowired
-    private IAllocationStorehouseInnerServiceSMO allocationStorehouseInnerServiceSMOImpl;
+    private IAllocationStorehouseApplyInnerServiceSMO allocationStorehouseApplyInnerServiceSMOImpl;
 
     @Autowired
     private IWorkflowInnerServiceSMO workflowInnerServiceSMOImpl;
 
+    @Autowired
+    private IPurchaseApplyInnerServiceSMO purchaseApplyInnerServiceSMOImpl;
+
+    @Autowired
+    private IDataBusInnerServiceSMO dataBusInnerServiceSMOImpl;
 
     /**
      * 鍚姩娴佺▼
      *
      * @return
      */
-    public AllocationStorehouseDto startProcess(@RequestBody AllocationStorehouseDto allocationStorehouseDto) {
+    public AllocationStorehouseApplyDto startProcess(@RequestBody AllocationStorehouseApplyDto allocationStorehouseApplyDto) {
         //灏嗕俊鎭姞鍏ap,浠ヤ究浼犲叆娴佺▼涓�
         Map<String, Object> variables = new HashMap<String, Object>();
-        variables.put("allocationStorehouseDto", allocationStorehouseDto);
-        variables.put("userId", allocationStorehouseDto.getCurrentUserId());
-        variables.put("startUserId", allocationStorehouseDto.getCurrentUserId());
+        variables.put("allocationStorehouseApplyDto", allocationStorehouseApplyDto);
+        variables.put("userId", allocationStorehouseApplyDto.getCurrentUserId());
+        variables.put("startUserId", allocationStorehouseApplyDto.getCurrentUserId());
         //寮�鍚祦绋�
-        ProcessInstance processInstance = runtimeService.startProcessInstanceByKey(getWorkflowDto(allocationStorehouseDto.getStoreId()), allocationStorehouseDto.getAsId(), variables);
+        ProcessInstance processInstance = runtimeService.startProcessInstanceByKey(getWorkflowDto(allocationStorehouseApplyDto.getStoreId()), allocationStorehouseApplyDto.getApplyId(), variables);
         //灏嗗緱鍒扮殑瀹炰緥娴佺▼id鍊艰祴缁欎箣鍓嶈缃殑鍙橀噺
         String processInstanceId = processInstance.getId();
         // System.out.println("娴佺▼寮�鍚垚鍔�.......瀹炰緥娴佺▼id:" + processInstanceId);
-
-        allocationStorehouseDto.setProcessInstanceId(processInstanceId);
-
-        return allocationStorehouseDto;
-
+        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;
     }
 
     /**
@@ -94,14 +117,14 @@
      *
      * @param user 鐢ㄦ埛淇℃伅
      */
-    public List<AllocationStorehouseDto> getUserTasks(@RequestBody AuditUser user) {
+    public List<AllocationStorehouseApplyDto> getUserTasks(@RequestBody AuditUser user) {
         TaskService taskService = processEngine.getTaskService();
         TaskQuery query = taskService.createTaskQuery().processDefinitionKey(getWorkflowDto(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());
@@ -109,7 +132,7 @@
             list = query.list();
         }
 
-        List<String> asIds = new ArrayList<>();
+        List<String> appIyIds = new ArrayList<>();
         Map<String, String> taskBusinessKeyMap = new HashMap<>();
         for (Task task : list) {
             String processInstanceId = task.getProcessInstanceId();
@@ -117,52 +140,51 @@
             ProcessInstance pi = runtimeService.createProcessInstanceQuery().processInstanceId(processInstanceId).singleResult();
             //4.浣跨敤娴佺▼瀹炰緥瀵硅薄鑾峰彇BusinessKey
             String business_key = pi.getBusinessKey();
-            asIds.add(business_key);
+            appIyIds.add(business_key);
             taskBusinessKeyMap.put(business_key, task.getId());
         }
 
-        if (asIds == null || asIds.size() == 0) {
+        if (appIyIds == null || appIyIds.size() == 0) {
             return new ArrayList<>();
         }
 
         //鏌ヨ 鎶曡瘔淇℃伅
-        AllocationStorehouseDto allocationStorehouseDto = new AllocationStorehouseDto();
-        allocationStorehouseDto.setStoreId(user.getStoreId());
-        allocationStorehouseDto.setAsIds(asIds.toArray(new String[asIds.size()]));
-        List<AllocationStorehouseDto> tmpAllocationStorehouseDtos = allocationStorehouseInnerServiceSMOImpl.queryAllocationStorehouses(allocationStorehouseDto);
-
-        for (AllocationStorehouseDto tmpAllocationStorehouseDto : tmpAllocationStorehouseDtos) {
-            tmpAllocationStorehouseDto.setTaskId(taskBusinessKeyMap.get(tmpAllocationStorehouseDto.getAsId()));
+        AllocationStorehouseApplyDto allocationStorehouseApplyDto = new AllocationStorehouseApplyDto();
+        allocationStorehouseApplyDto.setStoreId(user.getStoreId());
+        allocationStorehouseApplyDto.setApplyIds(appIyIds.toArray(new String[appIyIds.size()]));
+        List<AllocationStorehouseApplyDto> tmpAllocationStorehouseApplyDtos = allocationStorehouseApplyInnerServiceSMOImpl.queryAllocationStorehouseApplys(allocationStorehouseApplyDto);
+        for (AllocationStorehouseApplyDto tmpAllocationStorehouseApplyDto : tmpAllocationStorehouseApplyDtos) {
+            tmpAllocationStorehouseApplyDto.setTaskId(taskBusinessKeyMap.get(tmpAllocationStorehouseApplyDto.getApplyId()));
         }
-        return tmpAllocationStorehouseDtos;
+        return tmpAllocationStorehouseApplyDtos;
     }
 
-    public boolean agreeCompleteTask(@RequestBody AllocationStorehouseDto allocationStorehouseDto) {
+    public boolean agreeCompleteTask(@RequestBody AllocationStorehouseApplyDto allocationStorehouseApplyDto) {
         TaskService taskService = processEngine.getTaskService();
         Map<String, Object> variables = new HashMap<String, Object>();
-        variables.put("auditCode", allocationStorehouseDto.getAuditCode());
-        taskService.complete(allocationStorehouseDto.getTaskId(), variables);
+        variables.put("auditCode", allocationStorehouseApplyDto.getAuditCode());
+        taskService.complete(allocationStorehouseApplyDto.getTaskId(), variables);
         return true;
     }
 
-    public boolean refuteCompleteTask(@RequestBody AllocationStorehouseDto allocationStorehouseDto) {
+    public boolean refuteCompleteTask(@RequestBody AllocationStorehouseApplyDto allocationStorehouseApplyDto) {
         TaskService taskService = processEngine.getTaskService();
         Map<String, Object> variables = new HashMap<String, Object>();
-        variables.put("auditCode", allocationStorehouseDto.getAuditCode());
-        taskService.complete(allocationStorehouseDto.getTaskId(), variables);
+        variables.put("auditCode", allocationStorehouseApplyDto.getAuditCode());
+        taskService.complete(allocationStorehouseApplyDto.getTaskId(), variables);
         return true;
     }
 
     /**
      * 瀹℃牳 褰撳墠浠诲姟
      *
-     * @param allocationStorehouseDto 璧勬簮璁㈠崟
+     * @param allocationStorehouseApplyDto 璧勬簮璁㈠崟
      * @return
      */
-    public boolean complete(@RequestBody AllocationStorehouseDto allocationStorehouseDto) {
+    public boolean complete(@RequestBody AllocationStorehouseApplyDto allocationStorehouseApplyDto) {
         TaskService taskService = processEngine.getTaskService();
 
-        taskService.complete(allocationStorehouseDto.getTaskId());
+        taskService.complete(allocationStorehouseApplyDto.getTaskId());
 
 
         return true;
@@ -173,7 +195,7 @@
         //寮�鍚祦绋�
         //WorkflowDto.DEFAULT_PROCESS + workflowDto.getFlowId()
         WorkflowDto workflowDto = new WorkflowDto();
-        workflowDto.setFlowType(WorkflowDto.FLOW_TYPE_CONTRACT_APPLY);
+        workflowDto.setFlowType(WorkflowDto.FLOW_TYPE_ALLOCATION_STOREHOUSE);
         workflowDto.setStoreId(storeId);
         List<WorkflowDto> workflowDtos = workflowInnerServiceSMOImpl.queryWorkflows(workflowDto);
         Assert.listOnlyOne(workflowDtos, "鏈壘鍒� 鎶曡瘔寤鸿娴佺▼鎴栨壘鍒板鏉★紝璇峰湪鐗╀笟璐﹀彿绯荤粺绠$悊涓嬫祦绋嬬鐞嗕腑閰嶇疆娴佺▼");
@@ -216,7 +238,7 @@
      *
      * @param user 鐢ㄦ埛淇℃伅
      */
-    public List<AllocationStorehouseDto> getUserHistoryTasks(@RequestBody AuditUser user) {
+    public List<AllocationStorehouseApplyDto> getUserHistoryTasks(@RequestBody AuditUser user) {
         HistoryService historyService = processEngine.getHistoryService();
 
         HistoricTaskInstanceQuery historicTaskInstanceQuery = historyService.createHistoricTaskInstanceQuery()
@@ -238,7 +260,7 @@
             list = query.list();
         }
 
-        List<String> asIds = new ArrayList<>();
+        List<String> appIyIds = new ArrayList<>();
         Map<String, String> taskBusinessKeyMap = new HashMap<>();
 
         for (HistoricTaskInstance task : list) {
@@ -247,40 +269,70 @@
             HistoricProcessInstance pi = historyService.createHistoricProcessInstanceQuery().processInstanceId(processInstanceId).singleResult();
             //4.浣跨敤娴佺▼瀹炰緥瀵硅薄鑾峰彇BusinessKey
             String business_key = pi.getBusinessKey();
-            asIds.add(business_key);
+            appIyIds.add(business_key);
             taskBusinessKeyMap.put(business_key, task.getId());
         }
 
         //鏌ヨ 鎶曡瘔淇℃伅
-        AllocationStorehouseDto allocationStorehouseDto = new AllocationStorehouseDto();
-        allocationStorehouseDto.setStoreId(user.getStoreId());
-        allocationStorehouseDto.setAsIds(asIds.toArray(new String[asIds.size()]));
-        List<AllocationStorehouseDto> tmpAllocationStorehouseDtos = allocationStorehouseInnerServiceSMOImpl.queryAllocationStorehouses(allocationStorehouseDto);
+        AllocationStorehouseApplyDto allocationStorehouseApplyDto = new AllocationStorehouseApplyDto();
+        allocationStorehouseApplyDto.setStoreId(user.getStoreId());
+        allocationStorehouseApplyDto.setApplyIds(appIyIds.toArray(new String[appIyIds.size()]));
+        List<AllocationStorehouseApplyDto> tmpAllocationStorehouseApplyDtos = allocationStorehouseApplyInnerServiceSMOImpl.queryAllocationStorehouseApplys(allocationStorehouseApplyDto);
 
-        for (AllocationStorehouseDto tmpAllocationStorehouseDto : tmpAllocationStorehouseDtos) {
-            tmpAllocationStorehouseDto.setTaskId(taskBusinessKeyMap.get(tmpAllocationStorehouseDto.getAsId()));
+        for (AllocationStorehouseApplyDto tmpAllocationStorehouseApplyDto : tmpAllocationStorehouseApplyDtos) {
+            tmpAllocationStorehouseApplyDto.setTaskId(taskBusinessKeyMap.get(tmpAllocationStorehouseApplyDto.getApplyId()));
         }
-        return tmpAllocationStorehouseDtos;
+        return tmpAllocationStorehouseApplyDtos;
     }
 
 
-    public boolean completeTask(@RequestBody AllocationStorehouseDto allocationStorehouseDto) {
+    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(allocationStorehouseDto.getTaskId()).singleResult();
+        Task task = taskService.createTaskQuery().taskId(allocationStorehouseApplyDto.getTaskId()).singleResult();
         String processInstanceId = task.getProcessInstanceId();
-        Authentication.setAuthenticatedUserId(allocationStorehouseDto.getCurrentUserId());
-        taskService.addComment(allocationStorehouseDto.getTaskId(), processInstanceId, allocationStorehouseDto.getAuditMessage());
+        Authentication.setAuthenticatedUserId(allocationStorehouseApplyDto.getCurrentUserId());
+        taskService.addComment(allocationStorehouseApplyDto.getTaskId(), processInstanceId, allocationStorehouseApplyDto.getAuditMessage());
         Map<String, Object> variables = new HashMap<String, Object>();
-        variables.put("auditCode", allocationStorehouseDto.getAuditCode());
-        variables.put("currentUserId", allocationStorehouseDto.getCurrentUserId());
-        variables.put("flag", "1200".equals(allocationStorehouseDto.getAuditCode()) ? "false" : "true");
-        variables.put("startUserId", allocationStorehouseDto.getStartUserId());
-        taskService.complete(allocationStorehouseDto.getTaskId(), variables);
-
+        variables.put("auditCode", allocationStorehouseApplyDto.getAuditCode());
+        variables.put("currentUserId", allocationStorehouseApplyDto.getCurrentUserId());
+        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