1.首页"关于我的”和“工单走势图"

main
yitonglei 3 years ago
parent c8080aadbb
commit 3424f6e6b1
  1. 24
      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. 232
      lab-plugin/lab-workflow/src/main/java/org/springblade/plugin/homepage/service/impl/HomePageServiceImpl.java
  4. 14
      lab-plugin/lab-workflow/src/main/java/org/springblade/plugin/operation/task/controller/TaskInfoController.java

@ -8,6 +8,7 @@ import org.springblade.core.boot.ctrl.BladeController;
import org.springblade.core.mp.support.Condition;
import org.springblade.core.tenant.annotation.NonDS;
import org.springblade.core.tool.api.R;
import org.springblade.plugin.homepage.service.IHomePageService;
import org.springblade.plugin.operation.system.entity.ModuleInfo;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.RequestMapping;
@ -27,15 +28,38 @@ import org.springframework.web.bind.annotation.RestController;
@Api(value = "首页", tags = "首页")
public class HomePageController extends BladeController {
private final IHomePageService homePageService;
/**
* 我的相关首页的到期提醒我的待办今日新增今日完成的统计
* 到期提醒我的待办正在运行的节点与当前用户相关的任务数量
* 今日新增今日完成是当前用户所在部门的任务都算
*/
@GetMapping("/aboutMy")
@ApiOperationSupport(order = 1)
@ApiOperation(value = "我的相关", notes = "首页的“到期提醒”、“我的待办”、“今日新增”、“今日完成”的统计")
public R aboutMy() {
return homePageService.aboutMy();
}
/**
* 近一年与当前用户所在部门相关的新增工单和完成工单数量按照月份进行统计
*/
@GetMapping("/flowListMonth")
@ApiOperationSupport(order = 2)
@ApiOperation(value = "近一年与当前用户所在部门相关的新增工单和完成工单数量,按照月份进行统计", notes = "折线图")
public R flowListMonth() {
return homePageService.flowListMonth();
}
/**
* 种类统计,近一个月的
*/
@GetMapping("/flowListType")
@ApiOperationSupport(order = 2)
@ApiOperation(value = "种类统计,近一个月的", notes = "饼图")
public R flowListType(){
return null;
}
}

@ -10,4 +10,8 @@ import org.springblade.core.tool.api.R;
public interface IHomePageService {
R aboutMy();
R flowListMonth();
R flowListType();
}

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

@ -12,29 +12,21 @@ import io.swagger.annotations.ApiOperation;
import io.swagger.annotations.ApiParam;
import lombok.AllArgsConstructor;
import org.springblade.core.boot.ctrl.BladeController;
import org.springblade.core.cache.utils.CacheUtil;
import org.springblade.core.mp.support.Condition;
import org.springblade.core.mp.support.Query;
import org.springblade.core.secure.BladeUser;
import org.springblade.core.secure.utils.AuthUtil;
import org.springblade.core.tenant.annotation.NonDS;
import org.springblade.core.tool.api.R;
import org.springblade.core.tool.utils.Func;
import org.springblade.plugin.operation.database.entity.DataBase;
import org.springblade.plugin.operation.database.service.IDataBaseService;
import org.springblade.plugin.operation.system.entity.ProjectInfo;
import org.springblade.plugin.operation.system.service.IProjectInfoService;
import org.springblade.plugin.operation.task.entity.TaskAndDataBase;
import org.springblade.plugin.operation.task.entity.TaskInfo;
import org.springblade.plugin.operation.task.service.ITaskInfoService;
import org.springframework.web.bind.annotation.*;
import javax.validation.Valid;
import java.util.ArrayList;
import java.util.List;
import static org.springblade.core.cache.constant.CacheConstant.SYS_CACHE;
/**
*

Loading…
Cancel
Save