diff --git a/lab-plugin/lab-workflow/src/main/java/org/springblade/plugin/homepage/controller/HomePageController.java b/lab-plugin/lab-workflow/src/main/java/org/springblade/plugin/homepage/controller/HomePageController.java index c0fe255..78550af 100644 --- a/lab-plugin/lab-workflow/src/main/java/org/springblade/plugin/homepage/controller/HomePageController.java +++ b/lab-plugin/lab-workflow/src/main/java/org/springblade/plugin/homepage/controller/HomePageController.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(); + } } diff --git a/lab-plugin/lab-workflow/src/main/java/org/springblade/plugin/homepage/service/IHomePageService.java b/lab-plugin/lab-workflow/src/main/java/org/springblade/plugin/homepage/service/IHomePageService.java index 4f7a8e4..6541326 100644 --- a/lab-plugin/lab-workflow/src/main/java/org/springblade/plugin/homepage/service/IHomePageService.java +++ b/lab-plugin/lab-workflow/src/main/java/org/springblade/plugin/homepage/service/IHomePageService.java @@ -14,4 +14,8 @@ public interface IHomePageService { R flowListMonth(); R flowListType(); + + R flowStatus(); + + R flowTakeTime(); } diff --git a/lab-plugin/lab-workflow/src/main/java/org/springblade/plugin/homepage/service/impl/HomePageServiceImpl.java b/lab-plugin/lab-workflow/src/main/java/org/springblade/plugin/homepage/service/impl/HomePageServiceImpl.java index abb6185..5c4a3e9 100644 --- a/lab-plugin/lab-workflow/src/main/java/org/springblade/plugin/homepage/service/impl/HomePageServiceImpl.java +++ b/lab-plugin/lab-workflow/src/main/java/org/springblade/plugin/homepage/service/impl/HomePageServiceImpl.java @@ -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 thisDayStartProcessInstanceList = thisDayStartProcessInstanceQuery.list(); @@ -96,14 +103,16 @@ public class HomePageServiceImpl implements IHomePageService { //获取流程发起人 String startUserId = his.getStartUserId(); User user = UserCache.getUser(Long.parseLong(startUserId)); - - List startUserDepts = Func.toLongList(user.getDeptId()); - for(Long startUserDept : startUserDepts){ - if(nowUserDepts.contains(startUserDept)){ - todayAddNum ++; - break; + if(!Func.isEmpty(user)){ + List 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 thisDayEndProcessInstanceList = thisDayEndProcessInstanceQuery.list(); @@ -120,12 +128,13 @@ public class HomePageServiceImpl implements IHomePageService { //获取流程发起人 String startUserId = his.getStartUserId(); User user = UserCache.getUser(Long.parseLong(startUserId)); - - List startUserDepts = Func.toLongList(user.getDeptId()); - for(Long startUserDept : startUserDepts){ - if(nowUserDepts.contains(startUserDept)){ - todayFinishNum ++; - break; + if(!Func.isEmpty(user)){ + List 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 nowUserDeptList = Func.toLongList(deptId); @@ -239,36 +249,168 @@ public class HomePageServiceImpl implements IHomePageService { Date lastMonthDate = DateUtil.minusMonths(DateUtil.now(), 1); List historicProcessInstanceList = historyService.createHistoricProcessInstanceQuery().startedAfter(lastMonthDate) .processInstanceTenantId(WfTaskUtil.getTenantId()) - .startedAfter(lastMonthDate).list(); + .list(); //过滤出与当前用户所在部门一致的工作流实例 List collect = historicProcessInstanceList.stream().filter( process -> { String startUserId = process.getStartUserId(); User user = UserCache.getUser(Long.parseLong(startUserId)); - String userDept = user.getDeptId(); - List userDeptList = Func.toLongList(userDept); - for (Long l : userDeptList) { - if (nowUserDeptList.contains(l)) { - return true; + if(!Func.isEmpty(user)){ + String userDept = user.getDeptId(); + List userDeptList = Func.toLongList(userDept); + for (Long l : userDeptList) { + if (nowUserDeptList.contains(l)) { + return true; + } } } return false; } ).collect(Collectors.toList()); + LinkedHashMap 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> iterator = map.entrySet().iterator(); + while(iterator.hasNext()){ + Map.Entry next = iterator.next(); + + JSONObject jsonByDict = new JSONObject(); + jsonByDict.put(next.getKey(),next.getValue()); + + result.add(jsonByDict); + } + + return R.data(result); } /** - * 过滤与当前登录用户部门一致的工作流 + * 流程状态 + * @return */ - public List processFilterByUser(List list, String deptId){ + @Override + public R flowStatus(){ + JSONArray result = new JSONArray(); + //当前获取登录人deptid + String deptId = AuthUtil.getDeptId(); List nowUserDeptList = Func.toLongList(deptId); - return null; + //查询近一个月的 + Date lastMonthDate = DateUtil.minusMonths(DateUtil.now(), 1); + List historicProcessInstanceList = historyService.createHistoricProcessInstanceQuery().startedAfter(lastMonthDate) + .processInstanceTenantId(WfTaskUtil.getTenantId()) + .list(); + + + //过滤出与当前用户所在部门一致的工作流实例 + List 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 userDeptList = Func.toLongList(userDept); + for (Long l : userDeptList) { + if (nowUserDeptList.contains(l)) { + return true; + } + } + } + return false; + } + ).collect(Collectors.toList()); + + Map 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> iterator = map.entrySet().iterator(); + while(iterator.hasNext()){ + Map.Entry 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 nowUserDeptList = Func.toLongList(deptId); + + //查询近一个月的 + Date lastMonthDate = DateUtil.minusMonths(DateUtil.now(), 1); + List historicProcessInstanceList = historyService.createHistoricProcessInstanceQuery().startedAfter(lastMonthDate) + .processInstanceTenantId(WfTaskUtil.getTenantId()) + .list(); + + //过滤出与当前用户所在部门一致的工作流实例 + List 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 userDeptList = Func.toLongList(userDept); + for (Long l : userDeptList) { + if (nowUserDeptList.contains(l)) { + return true; + } + } + } + return false; + } + ).collect(Collectors.toList()); + + HashMap 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> iterator = map.entrySet().iterator(); + List XData = new ArrayList<>(); + List YData = new ArrayList<>(); + + while(iterator.hasNext()){ + Map.Entry next = iterator.next(); + XData.add(next.getKey()); + YData.add(next.getValue()); + } + + result.put("XData", XData); + result.put("YData", YData); + return R.data(result); + } }