java110
2023-08-24 c86174225a4b0a68d32111bf18ac401ff95d90ea
service-common/src/main/java/com/java110/common/smo/impl/AllocationStorehouseUserInnerServiceSMOImpl.java
@@ -1,16 +1,23 @@
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.workflow.WorkflowDto;
import com.java110.entity.audit.AuditUser;
import com.java110.dto.purchase.AllocationStorehouseApplyDto;
import com.java110.dto.data.DatabusDataDto;
import com.java110.dto.purchase.PurchaseApplyDto;
import com.java110.dto.store.StorehouseDto;
import com.java110.dto.oaWorkflow.WorkflowDto;
import com.java110.dto.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.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;
@@ -33,6 +40,8 @@
import java.util.List;
import java.util.Map;
import static com.java110.dto.store.StorehouseDto.SH_TYPE_GROUP;
//@Service("resourceEntryStoreSMOImpl")
@RestController
public class AllocationStorehouseUserInnerServiceSMOImpl extends BaseServiceSMO implements IAllocationStorehouseUserInnerServiceSMO {
@@ -44,13 +53,19 @@
    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;
    @Autowired
    private IStorehouseInnerServiceSMO iStorehouseInnerServiceSMO;
    /**
@@ -58,22 +73,48 @@
     *
     * @return
     */
    public AllocationStorehouseDto startProcess(@RequestBody AllocationStorehouseDto allocationStorehouseDto) {
    public AllocationStorehouseApplyDto startProcess(@RequestBody AllocationStorehouseApplyDto allocationStorehouseApplyDto) {
        //将信息加入map,以便传入流程中
        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());
        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);
        }
        //开启流程
        ProcessInstance processInstance = runtimeService.startProcessInstanceByKey(getWorkflowDto(allocationStorehouseDto.getStoreId()), allocationStorehouseDto.getAsId(), variables);
        ProcessInstance processInstance = runtimeService.startProcessInstanceByKey(getWorkflowDto(allocationStorehouseApplyDto.getStoreId(), communityId), 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();
        //获取下级处理人id
        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);
                //传送databus
                dataBusInnerServiceSMOImpl.databusData(DatabusDataDto.getInstance(
                        BusinessTypeConstant.BUSINESS_TYPE_DATABUS_ALLOCATION_STOREHOUSE_APPLY, BeanConvertUtil.beanCovertJson(machineRecordPo)));
            }
        }
        return allocationStorehouseApplyDto;
    }
    /**
@@ -84,7 +125,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();
    }
@@ -94,14 +137,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()));
        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());
@@ -109,7 +152,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,72 +160,101 @@
            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());
            taskBusinessKeyMap.put(business_key+"_ProcessDefinitionKey", pi.getProcessDefinitionKey());
        }
        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()));
            tmpAllocationStorehouseApplyDto.setProcessDefinitionKey(taskBusinessKeyMap.get(tmpAllocationStorehouseApplyDto.getApplyId()+"_ProcessDefinitionKey"));
        }
        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;
    }
    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;
    }
    /**
@@ -198,7 +270,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())) {
@@ -216,11 +288,11 @@
     *
     * @param user 用户信息
     */
    public List<AllocationStorehouseDto> getUserHistoryTasks(@RequestBody AuditUser user) {
    public List<AllocationStorehouseApplyDto> getUserHistoryTasks(@RequestBody AuditUser user) {
        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())) {
@@ -238,7 +310,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 +319,71 @@
            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());
        variables.put("nextUserId", allocationStorehouseApplyDto.getNextUserId());
        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();
        //获取下级处理人id
        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);
                //传送databus
                dataBusInnerServiceSMOImpl.databusData(DatabusDataDto.getInstance(
                        BusinessTypeConstant.BUSINESS_TYPE_DATABUS_ALLOCATION_STOREHOUSE_APPLY, BeanConvertUtil.beanCovertJson(machineRecordPo)));
            }
        }
        return false;
    }