|
|
|
|
@ -3,22 +3,26 @@ package org.springblade.plugin.homepage.service.impl; |
|
|
|
|
import com.alibaba.fastjson.JSONObject; |
|
|
|
|
import lombok.AllArgsConstructor; |
|
|
|
|
import org.flowable.engine.HistoryService; |
|
|
|
|
import org.flowable.engine.RuntimeService; |
|
|
|
|
import org.flowable.engine.TaskService; |
|
|
|
|
import org.flowable.engine.history.HistoricProcessInstance; |
|
|
|
|
import org.flowable.engine.history.HistoricProcessInstanceQuery; |
|
|
|
|
import org.flowable.task.api.Task; |
|
|
|
|
import org.flowable.task.api.TaskQuery; |
|
|
|
|
import org.springblade.core.secure.utils.AuthUtil; |
|
|
|
|
import org.springblade.core.tool.api.R; |
|
|
|
|
import org.springblade.core.tool.utils.DateUtil; |
|
|
|
|
import org.springblade.core.tool.utils.Func; |
|
|
|
|
import org.springblade.plugin.homepage.service.IHomePageService; |
|
|
|
|
import org.springblade.plugin.workflow.core.utils.WfTaskUtil; |
|
|
|
|
import org.springblade.system.user.cache.UserCache; |
|
|
|
|
import org.springblade.system.user.entity.User; |
|
|
|
|
import org.springframework.stereotype.Service; |
|
|
|
|
|
|
|
|
|
import java.util.ArrayList; |
|
|
|
|
import java.util.HashSet; |
|
|
|
|
import java.util.List; |
|
|
|
|
import java.util.Set; |
|
|
|
|
import java.time.Duration; |
|
|
|
|
|
|
|
|
|
import java.util.*; |
|
|
|
|
import java.util.stream.Collectors; |
|
|
|
|
|
|
|
|
|
/** |
|
|
|
|
* @Description |
|
|
|
|
@ -30,7 +34,15 @@ import java.util.Set; |
|
|
|
|
public class HomePageServiceImpl implements IHomePageService { |
|
|
|
|
private final TaskService taskService; |
|
|
|
|
private final HistoryService historyService; |
|
|
|
|
private final RuntimeService runtimeService; |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
/** |
|
|
|
|
* 我的相关,首页的“到期提醒”、“我的待办”、“今日新增”、“今日完成”的统计 |
|
|
|
|
* 到期提醒(expireNum),我的待办(needDoNum):正在运行的节点与当前用户相关的任务数量 |
|
|
|
|
* 今日新增(todayAddNum),今日完成:是当前用户所在部门的任务都算 |
|
|
|
|
*/ |
|
|
|
|
@Override |
|
|
|
|
public R aboutMy() { |
|
|
|
|
//结果
|
|
|
|
|
@ -38,8 +50,12 @@ public class HomePageServiceImpl implements IHomePageService { |
|
|
|
|
|
|
|
|
|
String taskUser = WfTaskUtil.getTaskUser(); |
|
|
|
|
String taskGroup = WfTaskUtil.getCandidateGroup(); |
|
|
|
|
//当前获取登录人deptid
|
|
|
|
|
String deptId = AuthUtil.getDeptId(); |
|
|
|
|
List<Long> nowUserDepts = Func.toLongList(deptId); |
|
|
|
|
|
|
|
|
|
//我的待办
|
|
|
|
|
|
|
|
|
|
//1.我的待办
|
|
|
|
|
TaskQuery taskQuery = taskService.createTaskQuery() |
|
|
|
|
.orderByTaskCreateTime() |
|
|
|
|
.desc() |
|
|
|
|
@ -49,24 +65,210 @@ public class HomePageServiceImpl implements IHomePageService { |
|
|
|
|
.taskCandidateGroupIn(Func.toStrList(taskGroup)); |
|
|
|
|
|
|
|
|
|
List<Task> listNeedDo = taskQuery.list(); |
|
|
|
|
//我的待办
|
|
|
|
|
result.put("needDoNum", listNeedDo.size()); |
|
|
|
|
|
|
|
|
|
//与我相关的新增
|
|
|
|
|
//1.获取今日新增的流程
|
|
|
|
|
HistoricProcessInstanceQuery thisDayProcessInstanceQuery = historyService.createHistoricProcessInstanceQuery().startedAfter(DateUtil.plusDays(DateUtil.now(), -1)) |
|
|
|
|
//2.我的到期提醒
|
|
|
|
|
int expireNum = 0; |
|
|
|
|
|
|
|
|
|
for(Task task : listNeedDo){ |
|
|
|
|
String executionId = task.getExecutionId(); |
|
|
|
|
System.out.println("executionid--" + executionId); |
|
|
|
|
Map<String, Object> variables = runtimeService.getVariables(task.getExecutionId()); |
|
|
|
|
|
|
|
|
|
Date qiwangwanchengshijian = DateUtil.parse(variables.get("qiwangwanchengshijian").toString(), "yyyy-MM-dd HH:mm:ss"); |
|
|
|
|
Duration between = DateUtil.between(qiwangwanchengshijian, DateUtil.now()); |
|
|
|
|
if(!between.isNegative()){ //between.isNegative() true ,现在时间小于任务结束时间,false消灾时间大于任务结束时间
|
|
|
|
|
expireNum ++; |
|
|
|
|
} |
|
|
|
|
} |
|
|
|
|
result.put("expireNum", expireNum); |
|
|
|
|
|
|
|
|
|
//3.与我相关的新增
|
|
|
|
|
//3.1.获取今日新增的流程
|
|
|
|
|
HistoricProcessInstanceQuery thisDayStartProcessInstanceQuery = historyService.createHistoricProcessInstanceQuery() |
|
|
|
|
.processInstanceTenantId(WfTaskUtil.getTenantId()) |
|
|
|
|
.startedAfter(DateUtil.plusDays(DateUtil.now(), -1)) |
|
|
|
|
.processInstanceTenantId(WfTaskUtil.getTenantId()); |
|
|
|
|
//2.遍历流程通过流程id获取与我相关的task
|
|
|
|
|
//3.2.遍历流程,得到流程发起人,只要流程发起人的dept在当前用户所属的dept列表中,就计算一次
|
|
|
|
|
int todayAddNum = 0; |
|
|
|
|
List<HistoricProcessInstance> list = thisDayProcessInstanceQuery.list(); |
|
|
|
|
for(HistoricProcessInstance his : list){ |
|
|
|
|
TaskQuery taskQuery1 = taskService.createTaskQuery().processInstanceId(his.getId()).taskAssignee(WfTaskUtil.getTenantId()); |
|
|
|
|
if(taskQuery1.list().size() > 0){ |
|
|
|
|
todayAddNum ++; |
|
|
|
|
List<HistoricProcessInstance> thisDayStartProcessInstanceList = thisDayStartProcessInstanceQuery.list(); |
|
|
|
|
for(HistoricProcessInstance his : thisDayStartProcessInstanceList){ |
|
|
|
|
//获取流程发起人
|
|
|
|
|
String startUserId = his.getStartUserId(); |
|
|
|
|
User user = UserCache.getUser(Long.parseLong(startUserId)); |
|
|
|
|
|
|
|
|
|
List<Long> startUserDepts = Func.toLongList(user.getDeptId()); |
|
|
|
|
for(Long startUserDept : startUserDepts){ |
|
|
|
|
if(nowUserDepts.contains(startUserDept)){ |
|
|
|
|
todayAddNum ++; |
|
|
|
|
break; |
|
|
|
|
} |
|
|
|
|
} |
|
|
|
|
} |
|
|
|
|
result.put("todayAddNum" , todayAddNum); |
|
|
|
|
|
|
|
|
|
//4.与我相关的今日完成
|
|
|
|
|
//4.1 获取今日完成的流程
|
|
|
|
|
HistoricProcessInstanceQuery thisDayEndProcessInstanceQuery = historyService.createHistoricProcessInstanceQuery() |
|
|
|
|
.processInstanceTenantId(WfTaskUtil.getTenantId()) |
|
|
|
|
.finishedAfter(DateUtil.plusDays(DateUtil.now(), -1)) |
|
|
|
|
.processInstanceTenantId(WfTaskUtil.getTenantId()); |
|
|
|
|
//4.2 遍历流程,得到流程发起人,只要流程发起人的dept在当前用户所属的dept列表中,就计算一次
|
|
|
|
|
int todayFinishNum = 0; |
|
|
|
|
List<HistoricProcessInstance> thisDayEndProcessInstanceList = thisDayEndProcessInstanceQuery.list(); |
|
|
|
|
for(HistoricProcessInstance his : thisDayEndProcessInstanceList){ |
|
|
|
|
//获取流程发起人
|
|
|
|
|
String startUserId = his.getStartUserId(); |
|
|
|
|
User user = UserCache.getUser(Long.parseLong(startUserId)); |
|
|
|
|
|
|
|
|
|
List<Long> startUserDepts = Func.toLongList(user.getDeptId()); |
|
|
|
|
for(Long startUserDept : startUserDepts){ |
|
|
|
|
if(nowUserDepts.contains(startUserDept)){ |
|
|
|
|
todayFinishNum ++; |
|
|
|
|
break; |
|
|
|
|
} |
|
|
|
|
} |
|
|
|
|
} |
|
|
|
|
result.put("todayFinishNum", todayFinishNum); |
|
|
|
|
|
|
|
|
|
return R.data(result); |
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
/** |
|
|
|
|
* 近一年与当前用户所在部门相关的新增工单和完成工单数量,按照月份进行统计 |
|
|
|
|
* @return |
|
|
|
|
*/ |
|
|
|
|
@Override |
|
|
|
|
public R flowListMonth(){ |
|
|
|
|
JSONObject result = new JSONObject(); |
|
|
|
|
|
|
|
|
|
Date start = DateUtil.minusYears(DateUtil.now(), 1); |
|
|
|
|
String[] xData = new String[12]; |
|
|
|
|
Map<String,Integer> mapMonthAdd = new HashMap<>(); |
|
|
|
|
Map<String,Integer> mapMonthFinish = new HashMap<>(); |
|
|
|
|
for(int i = 0;i < 12; i++){ |
|
|
|
|
Date date = DateUtil.plusMonths(start, i + 1); |
|
|
|
|
String format = DateUtil.format(date, "yyyy-MM"); |
|
|
|
|
xData[i] = format; |
|
|
|
|
mapMonthAdd.put(format,0); |
|
|
|
|
mapMonthFinish.put(format,0); |
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
//当前获取登录人deptid
|
|
|
|
|
String deptId = AuthUtil.getDeptId(); |
|
|
|
|
List<Long> nowUserDeptList = Func.toLongList(deptId); |
|
|
|
|
|
|
|
|
|
//查询近一年开始的工单
|
|
|
|
|
List<HistoricProcessInstance> historicProcessInstanceStartList = historyService.createHistoricProcessInstanceQuery().processInstanceTenantId(WfTaskUtil.getTenantId()) |
|
|
|
|
.startedAfter(DateUtil.plusYears(DateUtil.now(), -1)) |
|
|
|
|
.startedBefore(DateUtil.now()).orderByProcessInstanceStartTime().asc().list(); |
|
|
|
|
|
|
|
|
|
//过滤出发起人所在部门与当前用户所在部门一致的工单
|
|
|
|
|
historicProcessInstanceStartList.stream().filter(process -> { |
|
|
|
|
String startUserId = process.getStartUserId(); |
|
|
|
|
User user = UserCache.getUser(Long.parseLong(startUserId)); |
|
|
|
|
String userDept = user.getDeptId(); |
|
|
|
|
List<Long> userDeptList = Func.toLongList(userDept); |
|
|
|
|
for (Long l : userDeptList) { |
|
|
|
|
if (nowUserDeptList.contains(l)) { |
|
|
|
|
return true; |
|
|
|
|
} |
|
|
|
|
} |
|
|
|
|
return false; |
|
|
|
|
}).forEach(his ->{ |
|
|
|
|
Date startTime = his.getStartTime(); |
|
|
|
|
String format = DateUtil.format(startTime, "yyyy-MM"); |
|
|
|
|
System.out.println("format==" + format); |
|
|
|
|
if (mapMonthAdd.containsKey(format)) { |
|
|
|
|
int num = mapMonthAdd.get(format); |
|
|
|
|
mapMonthAdd.put(format,num + 1); |
|
|
|
|
} |
|
|
|
|
}); |
|
|
|
|
|
|
|
|
|
//查询近一年结束的工单
|
|
|
|
|
List<HistoricProcessInstance> historicProcessInstanceEndList = historyService.createHistoricProcessInstanceQuery().processInstanceTenantId(WfTaskUtil.getTenantId()) |
|
|
|
|
.finishedAfter(DateUtil.plusYears(DateUtil.now(), -1)) |
|
|
|
|
.finishedBefore(DateUtil.now()).orderByProcessInstanceStartTime().asc().list(); |
|
|
|
|
|
|
|
|
|
//过滤出发起人所在部门与当前用户所在部门一致的工单
|
|
|
|
|
historicProcessInstanceEndList.stream().filter(process -> { |
|
|
|
|
String startUserId = process.getStartUserId(); |
|
|
|
|
User user = UserCache.getUser(Long.parseLong(startUserId)); |
|
|
|
|
String userDept = user.getDeptId(); |
|
|
|
|
List<Long> userDeptList = Func.toLongList(userDept); |
|
|
|
|
for (Long l : userDeptList) { |
|
|
|
|
if (nowUserDeptList.contains(l)) { |
|
|
|
|
return true; |
|
|
|
|
} |
|
|
|
|
} |
|
|
|
|
return false; |
|
|
|
|
}).forEach(his ->{ |
|
|
|
|
Date startTime = his.getStartTime(); |
|
|
|
|
String format = DateUtil.format(startTime, "yyyy-MM"); |
|
|
|
|
if (mapMonthFinish.containsKey(format)) { |
|
|
|
|
int num = mapMonthFinish.get(format); |
|
|
|
|
mapMonthFinish.put(format,num + 1); |
|
|
|
|
} |
|
|
|
|
}); |
|
|
|
|
|
|
|
|
|
int[] monthAddNum = new int[12]; |
|
|
|
|
int[] monthFinishNum = new int[12]; |
|
|
|
|
for(int j = 0; j< 12; j++){ |
|
|
|
|
monthAddNum[j] = mapMonthAdd.get(xData[j]); |
|
|
|
|
monthFinishNum[j] = mapMonthAdd.get(xData[j]); |
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
result.put("xData", xData); |
|
|
|
|
result.put("monthAddNum", monthAddNum); |
|
|
|
|
result.put("monthFinishNum", monthFinishNum); |
|
|
|
|
|
|
|
|
|
return R.data(result); |
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
/** |
|
|
|
|
* 种类统计,近一个月的 |
|
|
|
|
*/ |
|
|
|
|
@Override |
|
|
|
|
public R flowListType(){ |
|
|
|
|
//当前获取登录人deptid
|
|
|
|
|
String deptId = AuthUtil.getDeptId(); |
|
|
|
|
List<Long> nowUserDeptList = Func.toLongList(deptId); |
|
|
|
|
|
|
|
|
|
//查询近一个月的
|
|
|
|
|
Date lastMonthDate = DateUtil.minusMonths(DateUtil.now(), 1); |
|
|
|
|
List<HistoricProcessInstance> historicProcessInstanceList = historyService.createHistoricProcessInstanceQuery().startedAfter(lastMonthDate) |
|
|
|
|
.processInstanceTenantId(WfTaskUtil.getTenantId()) |
|
|
|
|
.startedAfter(lastMonthDate).list(); |
|
|
|
|
|
|
|
|
|
//过滤出与当前用户所在部门一致的工作流实例
|
|
|
|
|
List<HistoricProcessInstance> collect = historicProcessInstanceList.stream().filter( |
|
|
|
|
process -> { |
|
|
|
|
String startUserId = process.getStartUserId(); |
|
|
|
|
User user = UserCache.getUser(Long.parseLong(startUserId)); |
|
|
|
|
String userDept = user.getDeptId(); |
|
|
|
|
List<Long> userDeptList = Func.toLongList(userDept); |
|
|
|
|
for (Long l : userDeptList) { |
|
|
|
|
if (nowUserDeptList.contains(l)) { |
|
|
|
|
return true; |
|
|
|
|
} |
|
|
|
|
} |
|
|
|
|
return false; |
|
|
|
|
} |
|
|
|
|
).collect(Collectors.toList()); |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
return null; |
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
/** |
|
|
|
|
* 过滤与当前登录用户部门一致的工作流 |
|
|
|
|
*/ |
|
|
|
|
public List<HistoricProcessInstance> processFilterByUser(List<HistoricProcessInstance> list, String deptId){ |
|
|
|
|
List<Long> nowUserDeptList = Func.toLongList(deptId); |
|
|
|
|
|
|
|
|
|
return null; |
|
|
|
|
|
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
} |
|
|
|
|
|