diff --git a/src/main/java/com/zhgd/xmgl/modules/xz/controller/XzFlowController.java b/src/main/java/com/zhgd/xmgl/modules/xz/controller/XzFlowController.java new file mode 100644 index 000000000..9bce0526d --- /dev/null +++ b/src/main/java/com/zhgd/xmgl/modules/xz/controller/XzFlowController.java @@ -0,0 +1,143 @@ +package com.zhgd.xmgl.modules.xz.controller; + +import cn.hutool.core.collection.CollectionUtil; +import cn.hutool.core.util.StrUtil; +import com.baomidou.mybatisplus.core.metadata.IPage; +import com.baomidou.mybatisplus.core.toolkit.Wrappers; +import com.wflow.bean.entity.WflowModelHistorys; +import com.wflow.mapper.WflowModelHistorysMapper; +import com.wflow.mapper.WflowModelsMapper; +import com.wflow.workflow.bean.process.OrgUser; +import com.wflow.workflow.bean.process.enums.ProcessResultEnum; +import com.wflow.workflow.bean.vo.FormAbstractsVo; +import com.wflow.workflow.bean.vo.ProcessInstanceVo; +import com.zhgd.jeecg.common.api.vo.Result; +import com.zhgd.xmgl.modules.xz.entity.XzHikvisionCompareData; +import com.zhgd.xmgl.tenant.TenantContextHolder; +import io.swagger.annotations.Api; +import io.swagger.annotations.ApiImplicitParam; +import io.swagger.annotations.ApiImplicitParams; +import io.swagger.annotations.ApiOperation; +import lombok.extern.slf4j.Slf4j; +import org.apache.commons.collections.MapUtils; +import org.apache.commons.lang3.StringUtils; +import org.flowable.engine.HistoryService; +import org.flowable.engine.RuntimeService; +import org.flowable.engine.history.HistoricProcessInstance; +import org.flowable.engine.history.HistoricProcessInstanceQuery; +import org.flowable.task.api.Task; +import org.flowable.task.api.TaskInfo; +import org.springframework.beans.factory.annotation.Autowired; +import org.springframework.web.bind.annotation.GetMapping; +import org.springframework.web.bind.annotation.RequestMapping; +import org.springframework.web.bind.annotation.RequestParam; +import org.springframework.web.bind.annotation.RestController; +import springfox.documentation.annotations.ApiIgnore; + +import java.math.BigDecimal; +import java.util.*; +import java.util.stream.Collectors; + + +@RestController +@RequestMapping("/xmgl/xzFlow") +@Slf4j +@Api(tags = "星纵-工作流信息") +public class XzFlowController { + + @Autowired + private HistoryService historyService; + + @Autowired + private WflowModelHistorysMapper wflowModelHistorysMapper; + + + @ApiOperation(value = "查询工作流统计信息", notes = "查询工作流统计信息", httpMethod = "GET") + @ApiImplicitParams({ + @ApiImplicitParam(name = "projectSn", value = "项目SN", paramType = "query", required = true, dataType = "String"), + }) + @GetMapping(value = "/getStatByState") + public Result> getStatByState(@ApiIgnore @RequestParam HashMap param) { + HistoricProcessInstanceQuery instanceQuery = historyService.createHistoricProcessInstanceQuery(); + instanceQuery.processInstanceTenantId(MapUtils.getString(param, "projectSn")); + List list = instanceQuery.list(); + List processInstanceVos = getInstances(list); + Map resultMap = new HashMap<>(); + resultMap.put("underApproval", processInstanceVos.stream().filter(l -> l.getResult().toString().equals("RUNNING")).count()); + resultMap.put("rejected", processInstanceVos.stream().filter(l -> l.getResult().toString().equals("REFUSE")).count()); + resultMap.put("passed", processInstanceVos.stream().filter(l -> l.getResult().toString().equals("PASS")).count()); + return Result.success(resultMap); + } + + @ApiOperation(value = "查询工作流统计信息", notes = "查询工作流统计信息", httpMethod = "GET") + @ApiImplicitParams({ + @ApiImplicitParam(name = "projectSn", value = "项目SN", paramType = "query", required = true, dataType = "String"), + @ApiImplicitParam(name = "state", value = "状态(RUNNING, REFUSE, PASS)", paramType = "query", required = true, dataType = "String"), + }) + @GetMapping(value = "/getStatDetailByState") + public Result>> getStatDetailByState(@ApiIgnore @RequestParam HashMap param) { + HistoricProcessInstanceQuery instanceQuery = historyService.createHistoricProcessInstanceQuery(); + instanceQuery.processInstanceTenantId(MapUtils.getString(param, "projectSn")); + String state = MapUtils.getString(param, "state"); + List list = instanceQuery.list(); + List processInstanceVos = getInstances(list); + processInstanceVos = processInstanceVos.stream().filter(p -> p.getResult().toString().equals(state)).collect(Collectors.toList()); + List formIds = processInstanceVos.stream().map(p -> p.getFormId()).collect(Collectors.toList()).stream().distinct().collect(Collectors.toList()); + List wflowModelHistorys = wflowModelHistorysMapper.selectList(null); + List> resultList = new ArrayList<>(); + Map total = new HashMap<>(); + if (state.equals("RUNNING")) { + total.put("name", "进行中"); + } else if (state.equals("REFUSE")) { + total.put("name", "已驳回"); + } else if (state.equals("PASS")) { + total.put("name", "已通过"); + } + total.put("num", processInstanceVos.size()); + resultList.add(total); + for (String formId : formIds) { + Map resultMap = new HashMap<>(); + List collect = wflowModelHistorys.stream().filter(w -> w.getFormId().equals(formId)).collect(Collectors.toList()); + resultMap.put("name", collect.get(collect.size() - 1).getFormName()); + long count = processInstanceVos.stream().filter(p -> p.getFormId().equals(formId)).count(); + int number = (int) count; + resultMap.put("num", number); + resultMap.put("ratio", new BigDecimal(number).divide(new BigDecimal(processInstanceVos.size()), 2, BigDecimal.ROUND_HALF_UP).multiply(new BigDecimal(100))); + resultList.add(resultMap); + } + resultList = resultList.stream().sorted((o1, o2) -> MapUtils.getInteger(o2, "num").compareTo( MapUtils.getInteger(o1, "num"))).collect(Collectors.toList()); + return Result.success(resultList); + } + + /** + * 构造流程实例列表 + * + * @param Instances 流程实例 + * @return 流程实例列表 + */ + private List getInstances(List Instances) { + Set staterUsers = new HashSet<>(); + //构造流程实例列表数据 + List instanceVos = Instances.stream().map(ist -> { + staterUsers.add(ist.getStartUserId()); + ProcessResultEnum processResult = ProcessResultEnum.resolveResult(ist.getEndActivityId()); + ProcessInstanceVo instanceVo = ProcessInstanceVo.builder() + .processDefId(ist.getProcessDefinitionId()) + .instanceId(ist.getId()) + .instanceName(ist.getName()) + .superInstanceId(Optional.ofNullable(ist.getSuperProcessInstanceId()).orElse(ist.getId())) + .formId(ist.getProcessDefinitionKey()) + .staterUserId(ist.getStartUserId()) + .startTime(ist.getStartTime()) + .finishTime(ist.getEndTime()) + .processDefName(ist.getProcessDefinitionName()) + .status(processResult.getDesc()) + .result(processResult) + .version(ist.getProcessDefinitionVersion()) + .build(); + return instanceVo; + }).collect(Collectors.toList()); + return instanceVos; + } + +}