package com.whyc.service; import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper; import com.baomidou.mybatisplus.core.toolkit.Wrappers; import com.whyc.constant.WorkflowEnum; import com.whyc.dto.Response; import com.whyc.mapper.*; import com.whyc.pojo.db_user.User; import com.whyc.pojo.web_site.WorkflowLink; import com.whyc.pojo.web_site.WorkflowMain; import com.whyc.util.CommonUtil; import org.springframework.beans.factory.annotation.Autowired; import org.springframework.context.annotation.Lazy; import org.springframework.stereotype.Service; import org.springframework.transaction.annotation.Transactional; import javax.annotation.Resource; import java.util.*; import java.util.stream.Collectors; @Service public class WorkflowLinkService { @Resource private WorkflowLinkMapper mapper; @Autowired @Lazy private WorkflowMainService mainService; public void addBatch(List links) { mapper.insertBatchSomeColumn(links); } public List getWorkflowInfo(Integer mainId) { QueryWrapper wrapper = Wrappers.query(); wrapper.eq("main_id", mainId); return mapper.selectList(wrapper); } @Transactional public Response updateLink(WorkflowLink link) { //获取当前节点的记录 WorkflowLink linkInDB = mapper.selectById(link.getId()); User user = CommonUtil.getUser(); Date now = new Date(); //根据id.查询关联的主表 WorkflowMain mainInDB = mainService.getById(linkInDB.getMainId()); //查看申请流程类型 switch (mainInDB.getType()) { case 1: { //设备维修申请 //查看主表的状态 //因为是单个链路节点,所以不需要判断是不是待处理,肯定只有1个节点. 审批通过或者驳回 //if(main.getStatus() == WorkflowEnum.MAIN_STATUS_DEALING.getValue().intValue()){ //待处理,下一步是审批通过,待处理 或者驳回 if(link.getStatus() == WorkflowEnum.LINK_STATUS_PASS.getValue().intValue()){ mainInDB.setStatus(WorkflowEnum.MAIN_STATUS_WAIT_FOR_DEALING.getValue()); mainService.updateById(mainInDB); }else if(link.getStatus() == WorkflowEnum.LINK_STATUS_REJECT.getValue().intValue()){ mainInDB.setStatus(WorkflowEnum.MAIN_STATUS_END_REJECT.getValue()); mainInDB.setEndReason(link.getDealRejectReason()); mainInDB.setEndTime(now); mainService.updateById(mainInDB); link.setDealAndClose(1); } } //设备入库申请 case 2: //设备报废申请 case 3:{ if(link.getStatus() == WorkflowEnum.LINK_STATUS_PASS.getValue().intValue()){ mainInDB.setStatus(WorkflowEnum.MAIN_STATUS_WAIT_FOR_DEALING.getValue()); mainService.updateById(mainInDB); }else if(link.getStatus() == WorkflowEnum.LINK_STATUS_REJECT.getValue().intValue()){ mainInDB.setStatus(WorkflowEnum.MAIN_STATUS_END_REJECT.getValue()); mainInDB.setEndReason(link.getDealRejectReason()); mainInDB.setEndTime(now); //检查是否有关联工单.如果有关联工单,关联工单状态重置为完结待处理,完成时间重置为空 if(mainInDB.getRelatedId() != null){ Integer relatedId = mainInDB.getRelatedId(); mainService.resetRepairStatus(relatedId,mainInDB.getQuantity()); } mainService.updateById(mainInDB); link.setDealAndClose(1); } } case 4:{ //TODO 出库申请 if(link.getStatus() == WorkflowEnum.LINK_STATUS_PASS.getValue().intValue()){ mainInDB.setStatus(WorkflowEnum.MAIN_STATUS_WAIT_FOR_DEALING.getValue()); mainService.updateById(mainInDB); }else if(link.getStatus() == WorkflowEnum.LINK_STATUS_REJECT.getValue().intValue()){ mainInDB.setStatus(WorkflowEnum.MAIN_STATUS_END_REJECT.getValue()); mainInDB.setEndReason(link.getDealRejectReason()); mainInDB.setEndTime(now); //检查是否有关联工单.如果有关联工单,关联工单状态重置为完结待处理,完成时间重置为空 if(mainInDB.getRelatedId() != null){ Integer relatedId = mainInDB.getRelatedId(); mainService.resetRepairStatus(relatedId,mainInDB.getQuantity()); } mainService.updateById(mainInDB); link.setDealAndClose(1); } } } link.setId(linkInDB.getId()); link.setDealUserId(user.getId()); link.setDealTime(now); mapper.updateById(link); return new Response().setII(1,"更新完成"); } /** * * @param mainId 特定的单据 * @param processLevel 特定的过程 * @return 特定单据,特定过程,未完成的会签的数量 */ private int getLeftAssignNum(Integer mainId, String processLevel) { QueryWrapper query = Wrappers.query(); query.select("count(*) as id").eq("main_id",mainId).eq("process_level",processLevel).ne("status",WorkflowEnum.LINK_STATUS_PASS.getValue()); return mapper.selectOne(query).getId(); } /** * 更新节点,主节点不完结 * @param link 参数id,status,dealReason或者dealRejectReason */ private void updateLinkField(WorkflowLink link) { Date now = new Date(); link.setDealTime(now); mapper.updateById(link); } public Map getReceivedStatistics(int type, User user) { Map statistics = new HashMap<>(); statistics.put(1,0); statistics.put(6,0); statistics.put(58,0); List links = mapper.getReceivedList(type,user); Map> receivedListMap = links.stream().collect(Collectors.groupingBy(WorkflowLink::getStatus)); Set statusSet = receivedListMap.keySet(); for (Integer status : statusSet) { if (status == 5 || status == 8) { statistics.put(58, statistics.get(58) + receivedListMap.get(status).size()); } else { statistics.put(status, receivedListMap.get(status).size()); } } return statistics; } /** * * 二次核容和隐患故障的统计 * * 增加了全部 0 * 0:全部 * 1:审批中 * 2:通过 * 3:驳回 * * status含义:1-待接单,6-待审核,58-已审核 * @param type * @param user * @return */ public Response getReceivedStatistics2(int type, User user) { Map statistics = new HashMap<>(); statistics.put(0,0); statistics.put(1,0); statistics.put(2,0); statistics.put(3,0); List links = mapper.getReceivedList2(type,user); Map> receivedListMap = links.stream().collect(Collectors.groupingBy(WorkflowLink::getStatus)); Set statusSet = receivedListMap.keySet(); int sum = 0; for (Integer status : statusSet) { int size = receivedListMap.get(status).size(); if (status == 1 || status == 6) { //审批中 statistics.put(1, statistics.get(1) + size); } else if(status == 5){ //通过 statistics.put(2, size); }else if(status == 8){ //驳回 statistics.put(3,size); } sum+=size; } statistics.put(0,sum); return new Response().set(1,statistics); } public void add(WorkflowLink link) { mapper.insert(link); } }