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<WorkflowLink> links) {
|
mapper.insertBatchSomeColumn(links);
|
}
|
|
public List<WorkflowLink> getWorkflowInfo(Integer mainId) {
|
QueryWrapper<WorkflowLink> 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 main = mainService.getById(linkInDB.getMainId());
|
//查看申请流程类型
|
switch (main.getType()) {
|
case 1: { //设备维修申请
|
//查看主表的状态
|
if(main.getStatus() == WorkflowEnum.MAIN_STATUS_DEALING.getValue().intValue()){ //待处理,下一步是审批通过,待处理 或者驳回
|
if(link.getStatus() == WorkflowEnum.LINK_STATUS_PASS.getValue().intValue()){
|
main.setStatus(WorkflowEnum.MAIN_STATUS_WAIT_FOR_DEALING.getValue());
|
mainService.updateStatus(main);
|
}else if(link.getStatus() == WorkflowEnum.LINK_STATUS_REJECT.getValue().intValue()){
|
main.setStatus(WorkflowEnum.MAIN_STATUS_END_REJECT.getValue());
|
main.setEndReason(link.getDealRejectReason());
|
main.setEndTime(now);
|
mainService.updateStatus(main);
|
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<WorkflowLink> 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<Integer, Integer> getReceivedStatistics(int type, User user) {
|
Map<Integer,Integer> statistics = new HashMap<>();
|
statistics.put(1,0);
|
statistics.put(6,0);
|
statistics.put(58,0);
|
List<WorkflowLink> links = mapper.getReceivedList(type,user);
|
Map<Integer, List<WorkflowLink>> receivedListMap = links.stream().collect(Collectors.groupingBy(WorkflowLink::getStatus));
|
Set<Integer> 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<Integer,Integer> statistics = new HashMap<>();
|
statistics.put(0,0);
|
statistics.put(1,0);
|
statistics.put(2,0);
|
statistics.put(3,0);
|
List<WorkflowLink> links = mapper.getReceivedList2(type,user);
|
Map<Integer, List<WorkflowLink>> receivedListMap = links.stream().collect(Collectors.groupingBy(WorkflowLink::getStatus));
|
Set<Integer> 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);
|
}
|
|
|
}
|