1.首页除了“状态统计"以外的接口

main
yitonglei 3 years ago
parent 2ac5dc6bde
commit 3beae4cbf2
  1. 26
      lab-plugin/lab-workflow/src/main/java/org/springblade/plugin/homepage/controller/HomePageController.java
  2. 4
      lab-plugin/lab-workflow/src/main/java/org/springblade/plugin/homepage/service/IHomePageService.java
  3. 196
      lab-plugin/lab-workflow/src/main/java/org/springblade/plugin/homepage/service/impl/HomePageServiceImpl.java

@ -34,6 +34,7 @@ public class HomePageController extends BladeController {
* 我的相关首页的到期提醒我的待办今日新增今日完成的统计
* 到期提醒我的待办正在运行的节点与当前用户相关的任务数量
* 今日新增今日完成是当前用户所在部门的任务都算
* 考虑用Future异步执行
*/
@GetMapping("/aboutMy")
@ApiOperationSupport(order = 1)
@ -56,10 +57,31 @@ public class HomePageController extends BladeController {
* 种类统计,近一个月的
*/
@GetMapping("/flowListType")
@ApiOperationSupport(order = 2)
@ApiOperationSupport(order = 3)
@ApiOperation(value = "种类统计,近一个月的", notes = "饼图")
public R flowListType(){
return null;
return homePageService.flowListType();
}
/**
* 状态统计,还未完成
*/
@GetMapping("/flowStatus")
@ApiOperationSupport(order = 4)
@ApiOperation(value = "流程状态,近一个月的", notes = "饼图")
public R flowStatus(){
return homePageService.flowStatus();
}
/**
* 耗时统计
*/
@GetMapping("/flowTakeTime")
@ApiOperationSupport(order = 5)
@ApiOperation(value = "耗时统计", notes = "柱状图")
public R flowTakeTime(){
return homePageService.flowTakeTime();
}
}

@ -14,4 +14,8 @@ public interface IHomePageService {
R flowListMonth();
R flowListType();
R flowStatus();
R flowTakeTime();
}

@ -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);
}
}

Loading…
Cancel
Save