|
|
|
|
@ -1,26 +1,33 @@ |
|
|
|
|
package org.springblade.plugin.homepage.service.impl; |
|
|
|
|
|
|
|
|
|
import com.alibaba.fastjson.JSONArray; |
|
|
|
|
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.HistoricActivityInstance; |
|
|
|
|
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.flowable.variable.api.history.HistoricVariableInstance; |
|
|
|
|
import org.flowable.variable.api.history.HistoricVariableInstanceQuery; |
|
|
|
|
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.cache.DictBizCache; |
|
|
|
|
import org.springblade.system.entity.DictBiz; |
|
|
|
|
import org.springblade.system.user.cache.UserCache; |
|
|
|
|
import org.springblade.system.user.entity.User; |
|
|
|
|
import org.springframework.stereotype.Service; |
|
|
|
|
|
|
|
|
|
import java.time.Duration; |
|
|
|
|
|
|
|
|
|
import java.time.LocalDate; |
|
|
|
|
import java.util.*; |
|
|
|
|
import java.util.stream.Collectors; |
|
|
|
|
|
|
|
|
|
@ -38,6 +45,7 @@ public class HomePageServiceImpl implements IHomePageService { |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
/** |
|
|
|
|
* 我的相关,首页的“到期提醒”、“我的待办”、“今日新增”、“今日完成”的统计 |
|
|
|
|
* 到期提醒(expireNum),我的待办(needDoNum):正在运行的节点与当前用户相关的任务数量 |
|
|
|
|
@ -87,8 +95,7 @@ public class HomePageServiceImpl implements IHomePageService { |
|
|
|
|
//3.1.获取今日新增的流程
|
|
|
|
|
HistoricProcessInstanceQuery thisDayStartProcessInstanceQuery = historyService.createHistoricProcessInstanceQuery() |
|
|
|
|
.processInstanceTenantId(WfTaskUtil.getTenantId()) |
|
|
|
|
.startedAfter(DateUtil.plusDays(DateUtil.now(), -1)) |
|
|
|
|
.processInstanceTenantId(WfTaskUtil.getTenantId()); |
|
|
|
|
.startedAfter(DateUtil.toDate(LocalDate.now())); |
|
|
|
|
//3.2.遍历流程,得到流程发起人,只要流程发起人的dept在当前用户所属的dept列表中,就计算一次
|
|
|
|
|
int todayAddNum = 0; |
|
|
|
|
List<HistoricProcessInstance> thisDayStartProcessInstanceList = thisDayStartProcessInstanceQuery.list(); |
|
|
|
|
@ -96,14 +103,16 @@ public class HomePageServiceImpl implements IHomePageService { |
|
|
|
|
//获取流程发起人
|
|
|
|
|
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; |
|
|
|
|
if(!Func.isEmpty(user)){ |
|
|
|
|
List<Long> startUserDepts = Func.toLongList(user.getDeptId()); |
|
|
|
|
for(Long startUserDept : startUserDepts){ |
|
|
|
|
if(nowUserDepts.contains(startUserDept)){ |
|
|
|
|
todayAddNum ++; |
|
|
|
|
break; |
|
|
|
|
} |
|
|
|
|
} |
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
} |
|
|
|
|
result.put("todayAddNum" , todayAddNum); |
|
|
|
|
|
|
|
|
|
@ -111,8 +120,7 @@ public class HomePageServiceImpl implements IHomePageService { |
|
|
|
|
//4.1 获取今日完成的流程
|
|
|
|
|
HistoricProcessInstanceQuery thisDayEndProcessInstanceQuery = historyService.createHistoricProcessInstanceQuery() |
|
|
|
|
.processInstanceTenantId(WfTaskUtil.getTenantId()) |
|
|
|
|
.finishedAfter(DateUtil.plusDays(DateUtil.now(), -1)) |
|
|
|
|
.processInstanceTenantId(WfTaskUtil.getTenantId()); |
|
|
|
|
.finishedAfter(DateUtil.toDate(LocalDate.now())); |
|
|
|
|
//4.2 遍历流程,得到流程发起人,只要流程发起人的dept在当前用户所属的dept列表中,就计算一次
|
|
|
|
|
int todayFinishNum = 0; |
|
|
|
|
List<HistoricProcessInstance> thisDayEndProcessInstanceList = thisDayEndProcessInstanceQuery.list(); |
|
|
|
|
@ -120,12 +128,13 @@ public class HomePageServiceImpl implements IHomePageService { |
|
|
|
|
//获取流程发起人
|
|
|
|
|
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; |
|
|
|
|
if(!Func.isEmpty(user)){ |
|
|
|
|
List<Long> startUserDepts = Func.toLongList(user.getDeptId()); |
|
|
|
|
for(Long startUserDept : startUserDepts){ |
|
|
|
|
if(nowUserDepts.contains(startUserDept)){ |
|
|
|
|
todayFinishNum ++; |
|
|
|
|
break; |
|
|
|
|
} |
|
|
|
|
} |
|
|
|
|
} |
|
|
|
|
} |
|
|
|
|
@ -179,7 +188,7 @@ public class HomePageServiceImpl implements IHomePageService { |
|
|
|
|
}).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); |
|
|
|
|
@ -231,6 +240,7 @@ public class HomePageServiceImpl implements IHomePageService { |
|
|
|
|
*/ |
|
|
|
|
@Override |
|
|
|
|
public R flowListType(){ |
|
|
|
|
JSONArray result = new JSONArray(); |
|
|
|
|
//当前获取登录人deptid
|
|
|
|
|
String deptId = AuthUtil.getDeptId(); |
|
|
|
|
List<Long> nowUserDeptList = Func.toLongList(deptId); |
|
|
|
|
@ -239,36 +249,168 @@ public class HomePageServiceImpl implements IHomePageService { |
|
|
|
|
Date lastMonthDate = DateUtil.minusMonths(DateUtil.now(), 1); |
|
|
|
|
List<HistoricProcessInstance> historicProcessInstanceList = historyService.createHistoricProcessInstanceQuery().startedAfter(lastMonthDate) |
|
|
|
|
.processInstanceTenantId(WfTaskUtil.getTenantId()) |
|
|
|
|
.startedAfter(lastMonthDate).list(); |
|
|
|
|
.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; |
|
|
|
|
if(!Func.isEmpty(user)){ |
|
|
|
|
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()); |
|
|
|
|
|
|
|
|
|
LinkedHashMap<String,Integer> map = new LinkedHashMap<>(); |
|
|
|
|
//根据工作流查询任务种类
|
|
|
|
|
collect.stream().forEach(his ->{ |
|
|
|
|
HistoricVariableInstance renwuzhonglei = historyService.createHistoricVariableInstanceQuery().processInstanceId(his.getId()) |
|
|
|
|
.variableName("$renwuzhonglei").singleResult(); |
|
|
|
|
System.out.println("renwu zhonglei--" + renwuzhonglei); |
|
|
|
|
if(!Func.isEmpty(renwuzhonglei)){ |
|
|
|
|
if(renwuzhonglei.getValue() != null){ |
|
|
|
|
Object renwuzhongleiValue = renwuzhonglei.getValue(); |
|
|
|
|
map.put(String.valueOf(renwuzhongleiValue), map.get(String.valueOf(renwuzhongleiValue)) == null ? 1: map.get(String.valueOf(renwuzhongleiValue)) + 1); |
|
|
|
|
} |
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
return null; |
|
|
|
|
}); |
|
|
|
|
|
|
|
|
|
Iterator<Map.Entry<String, Integer>> iterator = map.entrySet().iterator(); |
|
|
|
|
while(iterator.hasNext()){ |
|
|
|
|
Map.Entry<String, Integer> next = iterator.next(); |
|
|
|
|
|
|
|
|
|
JSONObject jsonByDict = new JSONObject(); |
|
|
|
|
jsonByDict.put(next.getKey(),next.getValue()); |
|
|
|
|
|
|
|
|
|
result.add(jsonByDict); |
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
return R.data(result); |
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
/** |
|
|
|
|
* 过滤与当前登录用户部门一致的工作流 |
|
|
|
|
* 流程状态 |
|
|
|
|
* @return |
|
|
|
|
*/ |
|
|
|
|
public List<HistoricProcessInstance> processFilterByUser(List<HistoricProcessInstance> list, String deptId){ |
|
|
|
|
@Override |
|
|
|
|
public R flowStatus(){ |
|
|
|
|
JSONArray result = new JSONArray(); |
|
|
|
|
//当前获取登录人deptid
|
|
|
|
|
String deptId = AuthUtil.getDeptId(); |
|
|
|
|
List<Long> nowUserDeptList = Func.toLongList(deptId); |
|
|
|
|
|
|
|
|
|
return null; |
|
|
|
|
//查询近一个月的
|
|
|
|
|
Date lastMonthDate = DateUtil.minusMonths(DateUtil.now(), 1); |
|
|
|
|
List<HistoricProcessInstance> historicProcessInstanceList = historyService.createHistoricProcessInstanceQuery().startedAfter(lastMonthDate) |
|
|
|
|
.processInstanceTenantId(WfTaskUtil.getTenantId()) |
|
|
|
|
.list(); |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
//过滤出与当前用户所在部门一致的工作流实例
|
|
|
|
|
List<HistoricProcessInstance> collect = historicProcessInstanceList.stream().filter( |
|
|
|
|
process -> { |
|
|
|
|
String startUserId = process.getStartUserId(); |
|
|
|
|
User user = UserCache.getUser(Long.parseLong(startUserId)); |
|
|
|
|
if(!Func.isEmpty(user)){ |
|
|
|
|
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()); |
|
|
|
|
|
|
|
|
|
Map<String,Integer> map = new HashMap<>(); |
|
|
|
|
collect.forEach(hi ->{ |
|
|
|
|
HistoricActivityInstance historicActivityInstance = historyService.createHistoricActivityInstanceQuery().processInstanceId(hi.getSuperProcessInstanceId()).unfinished().singleResult(); |
|
|
|
|
if(historicActivityInstance == null){ |
|
|
|
|
map.put("已结束", map.get("已结束") == null ? 1 : map.get("已结束") + 1); |
|
|
|
|
}else{ |
|
|
|
|
map.put(historicActivityInstance.getActivityName(), map.get(historicActivityInstance.getActivityName()) == null ? 1 : map.get(historicActivityInstance.getActivityName()) + 1); |
|
|
|
|
} |
|
|
|
|
}); |
|
|
|
|
|
|
|
|
|
Iterator<Map.Entry<String, Integer>> iterator = map.entrySet().iterator(); |
|
|
|
|
while(iterator.hasNext()){ |
|
|
|
|
Map.Entry<String, Integer> next = iterator.next(); |
|
|
|
|
JSONObject jsonObject = new JSONObject(); |
|
|
|
|
jsonObject.put(next.getKey(),next.getValue()); |
|
|
|
|
} |
|
|
|
|
return R.data(result); |
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
/** |
|
|
|
|
* 任务耗时 |
|
|
|
|
*/ |
|
|
|
|
@Override |
|
|
|
|
public R flowTakeTime(){ |
|
|
|
|
JSONObject result = new JSONObject(); |
|
|
|
|
//当前获取登录人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()) |
|
|
|
|
.list(); |
|
|
|
|
|
|
|
|
|
//过滤出与当前用户所在部门一致的工作流实例
|
|
|
|
|
List<HistoricProcessInstance> collect = historicProcessInstanceList.stream().filter( |
|
|
|
|
process -> { |
|
|
|
|
String startUserId = process.getStartUserId(); |
|
|
|
|
User user = UserCache.getUser(Long.parseLong(startUserId)); |
|
|
|
|
if(!Func.isEmpty(user)){ |
|
|
|
|
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()); |
|
|
|
|
|
|
|
|
|
HashMap<Integer,Integer> map = new HashMap<>(); |
|
|
|
|
|
|
|
|
|
//获取流程的耗时毫秒数并计算成天数放入到map
|
|
|
|
|
collect.forEach(hi ->{ |
|
|
|
|
if(!Func.isEmpty(hi.getDurationInMillis())){ |
|
|
|
|
Long durationInMillis = hi.getDurationInMillis(); |
|
|
|
|
Integer days = (int)(durationInMillis/(1000 * 60 * 60 * 24) + 1); |
|
|
|
|
|
|
|
|
|
map.put(days, map.get(days) == null ? 1 : map.get(days) + 1); |
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
}); |
|
|
|
|
System.out.println(map.toString()); |
|
|
|
|
Iterator<Map.Entry<Integer, Integer>> iterator = map.entrySet().iterator(); |
|
|
|
|
List<Integer> XData = new ArrayList<>(); |
|
|
|
|
List<Integer> YData = new ArrayList<>(); |
|
|
|
|
|
|
|
|
|
while(iterator.hasNext()){ |
|
|
|
|
Map.Entry<Integer, Integer> next = iterator.next(); |
|
|
|
|
XData.add(next.getKey()); |
|
|
|
|
YData.add(next.getValue()); |
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
result.put("XData", XData); |
|
|
|
|
result.put("YData", YData); |
|
|
|
|
return R.data(result); |
|
|
|
|
} |
|
|
|
|
} |
|
|
|
|
|