|
|
@@ -10,6 +10,7 @@ import com.alibaba.xxpt.gateway.shared.api.request.OapiMessageWorkNotificationRe |
|
|
|
import com.alibaba.xxpt.gateway.shared.api.response.OapiMessageWorkNotificationResponse; |
|
|
|
import com.alibaba.xxpt.gateway.shared.client.http.ExecutableClient; |
|
|
|
import com.alibaba.xxpt.gateway.shared.client.http.IntelligentGetClient; |
|
|
|
import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper; |
|
|
|
import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper; |
|
|
|
import com.baomidou.mybatisplus.core.toolkit.Wrappers; |
|
|
|
import com.baomidou.mybatisplus.extension.plugins.pagination.Page; |
|
|
@@ -30,6 +31,7 @@ import com.ningdatech.pmapi.todocenter.enums.ProcessStatusEnum; |
|
|
|
import com.ningdatech.pmapi.todocenter.extension.cmd.BackToHisApprovalNodeCmd; |
|
|
|
import com.ningdatech.pmapi.todocenter.model.dto.req.ReqProcessHandlerDTO; |
|
|
|
import com.ningdatech.pmapi.todocenter.model.dto.req.ReqToBeProcessedDTO; |
|
|
|
import com.ningdatech.pmapi.todocenter.model.dto.res.ResHandledProjectListExportDTO; |
|
|
|
import com.ningdatech.pmapi.todocenter.model.dto.res.ResToBeProcessedDTO; |
|
|
|
import com.ningdatech.pmapi.todocenter.model.dto.res.ResToBeProjectListExportDTO; |
|
|
|
import com.ningdatech.pmapi.todocenter.zwdd.model.MessageContent; |
|
|
@@ -38,13 +40,16 @@ import com.ningdatech.pmapi.user.entity.UserInfo; |
|
|
|
import com.ningdatech.pmapi.user.service.IUserInfoService; |
|
|
|
import com.ningdatech.pmapi.user.util.LoginUserUtil; |
|
|
|
import com.wflow.bean.do_.UserDo; |
|
|
|
import com.wflow.bean.entity.NdDeclaredProject; |
|
|
|
import com.wflow.bean.entity.WflowCcTasks; |
|
|
|
import com.wflow.bean.entity.WflowModelHistorys; |
|
|
|
import com.wflow.bean.entity.WflowModels; |
|
|
|
import com.wflow.exception.BusinessException; |
|
|
|
import com.wflow.mapper.WflowCcTasksMapper; |
|
|
|
import com.wflow.mapper.WflowModelHistorysMapper; |
|
|
|
import com.wflow.service.NdDeclaredProjectService; |
|
|
|
import com.wflow.service.OrgRepositoryService; |
|
|
|
import com.wflow.utils.UserUtil; |
|
|
|
import com.wflow.workflow.bean.dto.ProcessInstanceOwnerDto; |
|
|
|
import com.wflow.workflow.bean.process.OrgUser; |
|
|
|
import com.wflow.workflow.bean.process.ProcessNode; |
|
|
@@ -52,6 +57,7 @@ import com.wflow.workflow.bean.process.enums.ApprovalModeEnum; |
|
|
|
import com.wflow.workflow.bean.process.enums.NodeTypeEnum; |
|
|
|
import com.wflow.workflow.bean.process.form.Form; |
|
|
|
import com.wflow.workflow.bean.process.props.ApprovalProps; |
|
|
|
import com.wflow.workflow.bean.vo.ProcessHandlerParamsVo; |
|
|
|
import com.wflow.workflow.bean.vo.ProcessProgressVo; |
|
|
|
import com.wflow.workflow.bean.vo.ProcessTaskVo; |
|
|
|
import com.wflow.workflow.config.WflowGlobalVarDef; |
|
|
@@ -72,9 +78,13 @@ import org.flowable.engine.runtime.Execution; |
|
|
|
import org.flowable.engine.runtime.ProcessInstance; |
|
|
|
import org.flowable.task.api.Task; |
|
|
|
import org.flowable.task.api.TaskQuery; |
|
|
|
import org.flowable.task.api.history.HistoricTaskInstance; |
|
|
|
import org.flowable.task.service.history.NativeHistoricTaskInstanceQuery; |
|
|
|
import org.flowable.variable.api.history.HistoricVariableInstance; |
|
|
|
import org.springframework.beans.BeanUtils; |
|
|
|
import org.springframework.stereotype.Component; |
|
|
|
|
|
|
|
import javax.annotation.Resource; |
|
|
|
import javax.servlet.http.HttpServletResponse; |
|
|
|
import java.io.IOException; |
|
|
|
import java.util.*; |
|
|
@@ -103,19 +113,21 @@ public class TodoCenterManage { |
|
|
|
private final WflowModelHistorysMapper modelHistorysMapper; |
|
|
|
private final ProcessNodeCatchService nodeCatchService; |
|
|
|
private final OrgRepositoryService orgRepositoryService; |
|
|
|
private final ProcessTaskService processTaskService; |
|
|
|
private final WflowCcTasksMapper ccTasksMapper; |
|
|
|
private final ProcessModelService processModelService; |
|
|
|
private final IUserInfoService userInfoService; |
|
|
|
private final ExecutableClient CLIENT; |
|
|
|
|
|
|
|
private final NdDeclaredProjectService declaredProjectService; |
|
|
|
@Resource(name = "executableClient") |
|
|
|
private ExecutableClient client; |
|
|
|
/** |
|
|
|
* 待办中心项目列表查询 |
|
|
|
* 待办中心待我处理项目列表查询 |
|
|
|
* @param param |
|
|
|
* @return com.ningdatech.basic.model.PageVo<com.ningdatech.pmapi.todocenter.model.dto.res.ResToBeProcessedDTO> |
|
|
|
* @author CMM |
|
|
|
* @since 2023/02/01 17:44 |
|
|
|
*/ |
|
|
|
public PageVo<ResToBeProcessedDTO> queryProjectList(ReqToBeProcessedDTO param) { |
|
|
|
public PageVo<ResToBeProcessedDTO> queryPendingProjectList(ReqToBeProcessedDTO param) { |
|
|
|
// 获取登录用户ID |
|
|
|
// long userId = LoginUserUtil.getUserId(); |
|
|
|
int userId = 381496; |
|
|
@@ -125,68 +137,128 @@ public class TodoCenterManage { |
|
|
|
|
|
|
|
TaskQuery taskQuery = taskService.createTaskQuery(); |
|
|
|
taskQuery.active().taskCandidateOrAssigned(String.valueOf(userId)).orderByTaskCreateTime().desc(); |
|
|
|
Page<ResToBeProcessedDTO> page = param.page(); |
|
|
|
|
|
|
|
List<Task> taskList = taskQuery.listPage(pageSize * (pageNumber - 1), pageSize); |
|
|
|
List<Task> taskList = taskQuery.list(); |
|
|
|
Set<String> staterUsers = new HashSet<>(); |
|
|
|
List<ResToBeProcessedDTO> resVos = taskList.stream().map(task -> { |
|
|
|
String nodeId = task.getTaskDefinitionKey(); |
|
|
|
String instanceId = task.getProcessInstanceId(); |
|
|
|
|
|
|
|
ProcessProgressVo instanceProgress = processService.getInstanceProgress(nodeId, instanceId); |
|
|
|
Map<String, Object> formData = instanceProgress.getFormData(); |
|
|
|
String status = instanceProgress.getStatus(); |
|
|
|
Boolean temporarySupplement = (Boolean) formData.get(ProjectDeclareConstants.BasicInformation.TEMPORARY_SUPPLEMENT); |
|
|
|
Page<NdDeclaredProject> page = param.page(); |
|
|
|
|
|
|
|
// 将待办任务流程实例一次性取出来,减少查询次数 |
|
|
|
Map<String, HistoricProcessInstance> instanceMap = CollectionUtil.isNotEmpty(taskList) ? |
|
|
|
historyService.createHistoricProcessInstanceQuery().processInstanceIds(taskList.stream() |
|
|
|
.map(Task::getProcessInstanceId).collect(Collectors.toSet())) |
|
|
|
.list().stream().collect(Collectors.toMap(HistoricProcessInstance::getId, v -> v)) : new HashMap<>(); |
|
|
|
List<String> processInsIds = taskList.stream().map(Task::getProcessInstanceId).collect(Collectors.toList()); |
|
|
|
|
|
|
|
LambdaQueryWrapper<NdDeclaredProject> wrapper = Wrappers.lambdaQuery(NdDeclaredProject.class); |
|
|
|
wrapper.like(StrUtil.isNotBlank(param.getProjectName()),NdDeclaredProject::getProjectName,param.getProjectName()) |
|
|
|
.like(StrUtil.isNotBlank(param.getOrgName()),NdDeclaredProject::getOrgName,param.getOrgName()) |
|
|
|
.eq(Objects.nonNull(param.getProjectYear()),NdDeclaredProject::getProjectYear,param.getProjectYear()) |
|
|
|
.ge(Objects.nonNull(param.getProcessLaunchStartTime()),NdDeclaredProject::getCreateOn,param.getProcessLaunchStartTime()) |
|
|
|
.le(Objects.nonNull(param.getProcessLaunchEndTime()),NdDeclaredProject::getCreateOn,param.getProcessLaunchEndTime()); |
|
|
|
declaredProjectService.page(page,wrapper); |
|
|
|
|
|
|
|
List<ResToBeProcessedDTO> resVos = page.getRecords().stream().filter(d -> processInsIds.contains(d.getProcInsId())).map(d -> { |
|
|
|
|
|
|
|
ResToBeProcessedDTO res = new ResToBeProcessedDTO(); |
|
|
|
temporarySupplement = true; |
|
|
|
if (temporarySupplement.equals(param.getIsSupplement())) { |
|
|
|
ProcessDefinition processDef = repositoryService.createProcessDefinitionQuery() |
|
|
|
.processDefinitionId(task.getProcessDefinitionId()) |
|
|
|
.singleResult(); |
|
|
|
//从缓存取 |
|
|
|
ProcessInstanceOwnerDto owner = runtimeService.getVariable(task.getExecutionId(), "owner", ProcessInstanceOwnerDto.class); |
|
|
|
ProcessInstance processInstance = runtimeService.createProcessInstanceQuery().processInstanceId(task.getProcessInstanceId()).singleResult(); |
|
|
|
staterUsers.add(owner.getOwner()); |
|
|
|
ProcessTaskVo processTaskVo = ProcessTaskVo.builder() |
|
|
|
.taskId(task.getId()) |
|
|
|
.taskName(task.getName()) |
|
|
|
.taskDefKey(task.getTaskDefinitionKey()) |
|
|
|
.processDefId(task.getProcessDefinitionId()) |
|
|
|
.executionId(task.getExecutionId()) |
|
|
|
.nodeId(nodeId) |
|
|
|
.deployId(processDef.getDeploymentId()) |
|
|
|
.processDefName(processDef.getName()) |
|
|
|
.version(processDef.getVersion()) |
|
|
|
.instanceId(instanceId) |
|
|
|
.ownerId(processInstance.getStartUserId()) |
|
|
|
.ownerDeptId(owner.getOwnerDeptId()) |
|
|
|
.ownerDeptName(owner.getOwnerDeptName()) |
|
|
|
.createTime(processInstance.getStartTime()) |
|
|
|
.taskCreateTime(task.getCreateTime()) |
|
|
|
.build(); |
|
|
|
res.setProcessTaskInfo(processTaskVo); |
|
|
|
String projectName = (String) formData.get(ProjectDeclareConstants.BasicInformation.PROJECT_NAME); |
|
|
|
res.setProjectName(projectName); |
|
|
|
res.setReportUnitId(owner.getOwnerDeptId()); |
|
|
|
res.setReportUnitName(owner.getOwnerDeptName()); |
|
|
|
res.setReportAmount((Integer) formData.get(ProjectDeclareConstants.FundDeclareInfo.DECLARE_AMOUNT)); |
|
|
|
res.setBudgetYear((Integer) formData.get(ProjectDeclareConstants.BasicInformation.BUDGET_YEAR)); |
|
|
|
res.setProcessStatus(ProcessStatusEnum.getCodeByDesc(status)); |
|
|
|
res.setProcessStatusName(status); |
|
|
|
res.setProcessLaunchTime(NdDateUtils.date2LocalDateTime(processInstance.getStartTime())); |
|
|
|
} |
|
|
|
BeanUtils.copyProperties(d, res); |
|
|
|
res.setProcessStatusName(ProcessStatusEnum.getDescByCode(d.getProcessStatus())); |
|
|
|
res.setProcessLaunchTime(d.getCreateOn()); |
|
|
|
|
|
|
|
HistoricTaskInstance task = historyService.createHistoricTaskInstanceQuery().processInstanceId(d.getProcInsId()).singleResult(); |
|
|
|
HistoricProcessInstance instance = instanceMap.get(task.getProcessInstanceId()); |
|
|
|
HistoricVariableInstance variableInstance = historyService.createHistoricVariableInstanceQuery() |
|
|
|
.processInstanceId(instance.getId()).variableName("approve_" + task.getId()).singleResult(); |
|
|
|
//从缓存取 |
|
|
|
staterUsers.add(instance.getStartUserId()); |
|
|
|
ProcessTaskVo processTaskVo = ProcessTaskVo.builder() |
|
|
|
.taskId(task.getId()) |
|
|
|
.taskName(task.getName()) |
|
|
|
.taskDefKey(task.getTaskDefinitionKey()) |
|
|
|
.processDefId(task.getProcessDefinitionId()) |
|
|
|
.executionId(task.getExecutionId()) |
|
|
|
.nodeId(task.getTaskDefinitionKey()) |
|
|
|
.deployId(instance.getDeploymentId()) |
|
|
|
.processDefName(instance.getProcessDefinitionName()) |
|
|
|
.version(instance.getProcessDefinitionVersion()) |
|
|
|
.instanceId(task.getProcessInstanceId()) |
|
|
|
.ownerId(instance.getStartUserId()) |
|
|
|
.createTime(instance.getStartTime()) |
|
|
|
.taskCreateTime(task.getCreateTime()) |
|
|
|
.taskEndTime(task.getEndTime()) |
|
|
|
.taskResult(String.valueOf(Objects.nonNull(variableInstance) ? |
|
|
|
variableInstance.getValue() : ProcessHandlerParamsVo.Action.recall)) |
|
|
|
.build(); |
|
|
|
res.setProcessTaskInfo(processTaskVo); |
|
|
|
return res; |
|
|
|
}).filter(v -> StringUtils.isBlank(param.getProjectName()) || v.getProjectName().contains(param.getProjectName())) |
|
|
|
.filter(v -> StringUtils.isBlank(param.getReportUnitName()) || v.getReportUnitName().contains(param.getReportUnitName())) |
|
|
|
.filter(v -> Objects.isNull(param.getBudgetYear()) || v.getBudgetYear().equals(param.getBudgetYear())) |
|
|
|
.filter(v -> Objects.isNull(param.getProcessLaunchStartTime()) || v.getProcessLaunchTime().isBefore(param.getProcessLaunchStartTime())) |
|
|
|
.filter(v -> Objects.isNull(param.getProcessLaunchEndTime()) || v.getProcessLaunchTime().isAfter(param.getProcessLaunchEndTime())) |
|
|
|
.collect(Collectors.toList()); |
|
|
|
}).collect(Collectors.toList()); |
|
|
|
//取用户信息,减少数据库查询,一次构建 |
|
|
|
List<ResToBeProcessedDTO> result = null; |
|
|
|
if (CollectionUtil.isNotEmpty(staterUsers)) { |
|
|
|
Map<String, OrgUser> userMap = userDeptOrLeaderService.getUserMapByIds(staterUsers); |
|
|
|
page.setRecords(resVos.stream().peek(v -> v.getProcessTaskInfo().setOwner(userMap.get(v.getProcessTaskInfo().getOwnerId()))).collect(Collectors.toList())); |
|
|
|
result = resVos.stream().peek(v -> v.getProcessTaskInfo() |
|
|
|
.setOwner(userMap.get(v.getProcessTaskInfo().getOwnerId()))) |
|
|
|
.collect(Collectors.toList()); |
|
|
|
} |
|
|
|
return PageVo.of(resVos,resVos.size()); |
|
|
|
return PageVo.of(result,page.getTotal()); |
|
|
|
|
|
|
|
//List<ResToBeProcessedDTO> resVos = taskList.stream().map(task -> { |
|
|
|
// String nodeId = task.getTaskDefinitionKey(); |
|
|
|
// String instanceId = task.getProcessInstanceId(); |
|
|
|
// |
|
|
|
// ProcessProgressVo instanceProgress = processService.getInstanceProgress(nodeId, instanceId); |
|
|
|
// Map<String, Object> formData = instanceProgress.getFormData(); |
|
|
|
// String status = instanceProgress.getStatus(); |
|
|
|
// Boolean temporarySupplement = (Boolean) formData.get(ProjectDeclareConstants.BasicInformation.TEMPORARY_SUPPLEMENT); |
|
|
|
// ResToBeProcessedDTO res = new ResToBeProcessedDTO(); |
|
|
|
// temporarySupplement = true; |
|
|
|
// if (temporarySupplement.equals(param.getIsSupplement())) { |
|
|
|
// ProcessDefinition processDef = repositoryService.createProcessDefinitionQuery() |
|
|
|
// .processDefinitionId(task.getProcessDefinitionId()) |
|
|
|
// .singleResult(); |
|
|
|
// //从缓存取 |
|
|
|
// ProcessInstanceOwnerDto owner = runtimeService.getVariable(task.getExecutionId(), "owner", ProcessInstanceOwnerDto.class); |
|
|
|
// ProcessInstance processInstance = runtimeService.createProcessInstanceQuery().processInstanceId(task.getProcessInstanceId()).singleResult(); |
|
|
|
// staterUsers.add(owner.getOwner()); |
|
|
|
// ProcessTaskVo processTaskVo = ProcessTaskVo.builder() |
|
|
|
// .taskId(task.getId()) |
|
|
|
// .taskName(task.getName()) |
|
|
|
// .taskDefKey(task.getTaskDefinitionKey()) |
|
|
|
// .processDefId(task.getProcessDefinitionId()) |
|
|
|
// .executionId(task.getExecutionId()) |
|
|
|
// .nodeId(nodeId) |
|
|
|
// .deployId(processDef.getDeploymentId()) |
|
|
|
// .processDefName(processDef.getName()) |
|
|
|
// .version(processDef.getVersion()) |
|
|
|
// .instanceId(instanceId) |
|
|
|
// .ownerId(processInstance.getStartUserId()) |
|
|
|
// .ownerDeptId(owner.getOwnerDeptId()) |
|
|
|
// .ownerDeptName(owner.getOwnerDeptName()) |
|
|
|
// .createTime(processInstance.getStartTime()) |
|
|
|
// .taskCreateTime(task.getCreateTime()) |
|
|
|
// .build(); |
|
|
|
// res.setProcessTaskInfo(processTaskVo); |
|
|
|
// String projectName = (String) formData.get(ProjectDeclareConstants.BasicInformation.PROJECT_NAME); |
|
|
|
// res.setProjectName(projectName); |
|
|
|
// res.setReportUnitId(owner.getOwnerDeptId()); |
|
|
|
// res.setReportUnitName(owner.getOwnerDeptName()); |
|
|
|
// res.setReportAmount((Integer) formData.get(ProjectDeclareConstants.FundDeclareInfo.DECLARE_AMOUNT)); |
|
|
|
// res.setBudgetYear((Integer) formData.get(ProjectDeclareConstants.BasicInformation.BUDGET_YEAR)); |
|
|
|
// res.setProcessStatus(ProcessStatusEnum.getCodeByDesc(status)); |
|
|
|
// res.setProcessStatusName(status); |
|
|
|
// res.setProcessLaunchTime(NdDateUtils.date2LocalDateTime(processInstance.getStartTime())); |
|
|
|
// } |
|
|
|
// return res; |
|
|
|
//}).filter(v -> StringUtils.isBlank(param.getProjectName()) || v.getProjectName().contains(param.getProjectName())) |
|
|
|
// .filter(v -> StringUtils.isBlank(param.getReportUnitName()) || v.getReportUnitName().contains(param.getReportUnitName())) |
|
|
|
// .filter(v -> Objects.isNull(param.getBudgetYear()) || v.getBudgetYear().equals(param.getBudgetYear())) |
|
|
|
// .filter(v -> Objects.isNull(param.getProcessLaunchStartTime()) || v.getProcessLaunchTime().isBefore(param.getProcessLaunchStartTime())) |
|
|
|
// .filter(v -> Objects.isNull(param.getProcessLaunchEndTime()) || v.getProcessLaunchTime().isAfter(param.getProcessLaunchEndTime())) |
|
|
|
// .collect(Collectors.toList()); |
|
|
|
//if (CollectionUtil.isNotEmpty(staterUsers)) { |
|
|
|
// Map<String, OrgUser> userMap = userDeptOrLeaderService.getUserMapByIds(staterUsers); |
|
|
|
// page.setRecords(resVos.stream().peek(v -> v.getProcessTaskInfo().setOwner(userMap.get(v.getProcessTaskInfo().getOwnerId()))).collect(Collectors.toList())); |
|
|
|
//} |
|
|
|
//return PageVo.of(resVos,resVos.size()); |
|
|
|
} |
|
|
|
/** |
|
|
|
* 待办中心列表导出 |
|
|
@@ -196,15 +268,14 @@ public class TodoCenterManage { |
|
|
|
* @author CMM |
|
|
|
* @since 2023/02/01 17:44 |
|
|
|
*/ |
|
|
|
public void exportProjectList(HttpServletResponse response, ReqToBeProcessedDTO param) { |
|
|
|
PageVo<ResToBeProcessedDTO> page = |
|
|
|
queryProjectList(param); |
|
|
|
public void exportPendingProjectList(HttpServletResponse response, ReqToBeProcessedDTO param) { |
|
|
|
PageVo<ResToBeProcessedDTO> page = queryPendingProjectList(param); |
|
|
|
List<ResToBeProcessedDTO> collect = (List<ResToBeProcessedDTO>) page.getRecords(); |
|
|
|
String fileName = null; |
|
|
|
if (param.getIsSupplement()){ |
|
|
|
fileName = "增补项目列表"; |
|
|
|
fileName = "待办中心_待我处理_增补项目列表"; |
|
|
|
}else { |
|
|
|
fileName = "非增补项目列表"; |
|
|
|
fileName = "待办中心_待我处理_非增补项目列表"; |
|
|
|
} |
|
|
|
ExcelDownUtil.setFileName(fileName,response); |
|
|
|
//数据导出处理函数 |
|
|
@@ -344,7 +415,15 @@ public class TodoCenterManage { |
|
|
|
} |
|
|
|
taskService.complete(param.getTaskId(), var); |
|
|
|
} |
|
|
|
|
|
|
|
/** |
|
|
|
* 给流程发起人发送工作通知 |
|
|
|
* @param task 当前任务 |
|
|
|
* @param projectName 项目名称 |
|
|
|
* @param rootNode 流程发起节点 |
|
|
|
* @return void |
|
|
|
* @author CMM |
|
|
|
* @since 2023/02/03 10:05 |
|
|
|
*/ |
|
|
|
private void sendWorkNoticeToStartUser(Task task, String projectName, FlowNode rootNode) { |
|
|
|
String startUserId = getRootUserId(rootNode); |
|
|
|
UserInfo startUserInfo = userInfoService.getById(Long.valueOf(startUserId)); |
|
|
@@ -444,7 +523,7 @@ public class TodoCenterManage { |
|
|
|
private void sendWorkNotice(UserInfo auditUserInfo, String msg) { |
|
|
|
// TODO 获取浙政钉唯一标识 |
|
|
|
String dingKey = null; |
|
|
|
IntelligentGetClient intelligentGetClient = CLIENT.newIntelligentGetClient(DingConstant.WORKING_NOTICE); |
|
|
|
IntelligentGetClient intelligentGetClient = client.newIntelligentGetClient(DingConstant.WORKING_NOTICE); |
|
|
|
OapiMessageWorkNotificationRequest request = new OapiMessageWorkNotificationRequest(); |
|
|
|
//消息体(参考下文示例消息格式) |
|
|
|
MessageText messageText = new MessageText(); |
|
|
@@ -691,4 +770,109 @@ public class TodoCenterManage { |
|
|
|
//根据流程遍历后续节点,期间要穿越后续包含并行网关和条件网关的节点 |
|
|
|
return Collections.emptyList(); |
|
|
|
} |
|
|
|
/** |
|
|
|
* 待办中心我已处理项目列表查询 |
|
|
|
* @param param |
|
|
|
* @return com.ningdatech.basic.model.PageVo<com.ningdatech.pmapi.todocenter.model.dto.res.ResToBeProcessedDTO> |
|
|
|
* @author CMM |
|
|
|
* @since 2023/02/03 10:07 |
|
|
|
*/ |
|
|
|
public PageVo<ResToBeProcessedDTO> queryHandledProjectList(ReqToBeProcessedDTO param) { |
|
|
|
// 获取登录用户ID |
|
|
|
// long userId = LoginUserUtil.getUserId(); |
|
|
|
int userId = 381496; |
|
|
|
// 获取入参分页信息 |
|
|
|
Integer pageSize = param.getPageSize(); |
|
|
|
Integer pageNumber = param.getPageNumber(); |
|
|
|
Page<NdDeclaredProject> page = param.page(); |
|
|
|
|
|
|
|
//自定义sql查询所有已办的任务 |
|
|
|
String nativeSql = "SELECT aht.* FROM `ACT_HI_TASKINST` AS aht LEFT JOIN `ACT_HI_VARINST` AS ahv ON SUBSTRING(ahv.NAME_, 9) = aht.ID_ \n" + |
|
|
|
"AND ahv.NAME_ LIKE 'approve_%' WHERE aht.ASSIGNEE_ = '" + userId + "' AND ahv.NAME_ IS NOT NULL ORDER BY aht.END_TIME_ DESC"; |
|
|
|
|
|
|
|
NativeHistoricTaskInstanceQuery taskInstanceQuery = historyService.createNativeHistoricTaskInstanceQuery().sql(nativeSql); |
|
|
|
List<HistoricTaskInstance> taskInstances = taskInstanceQuery.list(); |
|
|
|
|
|
|
|
//把已办任务流程实例一次性取出来,减少查询次数 |
|
|
|
Map<String, HistoricProcessInstance> instanceMap = CollectionUtil.isNotEmpty(taskInstances) ? |
|
|
|
historyService.createHistoricProcessInstanceQuery().processInstanceIds(taskInstances.stream() |
|
|
|
.map(HistoricTaskInstance::getProcessInstanceId).collect(Collectors.toSet())) |
|
|
|
.list().stream().collect(Collectors.toMap(HistoricProcessInstance::getId, v -> v)) : new HashMap<>(); |
|
|
|
|
|
|
|
List<String> processInsIds = taskInstances.stream().map(HistoricTaskInstance::getProcessInstanceId).collect(Collectors.toList()); |
|
|
|
LambdaQueryWrapper<NdDeclaredProject> wrapper = Wrappers.lambdaQuery(NdDeclaredProject.class); |
|
|
|
wrapper.like(StrUtil.isNotBlank(param.getProjectName()),NdDeclaredProject::getProjectName,param.getProjectName()) |
|
|
|
.like(StrUtil.isNotBlank(param.getOrgName()),NdDeclaredProject::getOrgName,param.getOrgName()) |
|
|
|
.eq(Objects.nonNull(param.getProjectYear()),NdDeclaredProject::getProjectYear,param.getProjectYear()) |
|
|
|
.ge(Objects.nonNull(param.getProcessLaunchStartTime()),NdDeclaredProject::getCreateOn,param.getProcessLaunchStartTime()) |
|
|
|
.le(Objects.nonNull(param.getProcessLaunchEndTime()),NdDeclaredProject::getCreateOn,param.getProcessLaunchEndTime()); |
|
|
|
declaredProjectService.page(page,wrapper); |
|
|
|
Set<String> staterUsers = new HashSet<>(); |
|
|
|
List<ResToBeProcessedDTO> resVos = page.getRecords().stream().filter(d -> processInsIds.contains(d.getProcInsId())).map(d -> { |
|
|
|
|
|
|
|
ResToBeProcessedDTO res = new ResToBeProcessedDTO(); |
|
|
|
BeanUtils.copyProperties(d, res); |
|
|
|
res.setProcessStatusName(ProcessStatusEnum.getDescByCode(d.getProcessStatus())); |
|
|
|
res.setProcessLaunchTime(d.getCreateOn()); |
|
|
|
res.setProcessHandleTime(d.getUpdateOn()); |
|
|
|
|
|
|
|
HistoricTaskInstance task = historyService.createHistoricTaskInstanceQuery().processInstanceId(d.getProcInsId()).singleResult(); |
|
|
|
HistoricProcessInstance instance = instanceMap.get(task.getProcessInstanceId()); |
|
|
|
HistoricVariableInstance variableInstance = historyService.createHistoricVariableInstanceQuery() |
|
|
|
.processInstanceId(instance.getId()).variableName("approve_" + task.getId()).singleResult(); |
|
|
|
//从缓存取 |
|
|
|
staterUsers.add(instance.getStartUserId()); |
|
|
|
ProcessTaskVo processTaskVo = ProcessTaskVo.builder() |
|
|
|
.taskId(task.getId()) |
|
|
|
.taskName(task.getName()) |
|
|
|
.taskDefKey(task.getTaskDefinitionKey()) |
|
|
|
.processDefId(task.getProcessDefinitionId()) |
|
|
|
.executionId(task.getExecutionId()) |
|
|
|
.nodeId(task.getTaskDefinitionKey()) |
|
|
|
.deployId(instance.getDeploymentId()) |
|
|
|
.processDefName(instance.getProcessDefinitionName()) |
|
|
|
.version(instance.getProcessDefinitionVersion()) |
|
|
|
.instanceId(task.getProcessInstanceId()) |
|
|
|
.ownerId(instance.getStartUserId()) |
|
|
|
.createTime(instance.getStartTime()) |
|
|
|
.taskCreateTime(task.getCreateTime()) |
|
|
|
.taskEndTime(task.getEndTime()) |
|
|
|
.taskResult(String.valueOf(Objects.nonNull(variableInstance) ? |
|
|
|
variableInstance.getValue() : ProcessHandlerParamsVo.Action.recall)) |
|
|
|
.build(); |
|
|
|
res.setProcessTaskInfo(processTaskVo); |
|
|
|
return res; |
|
|
|
}).collect(Collectors.toList()); |
|
|
|
//取用户信息,减少数据库查询,一次构建 |
|
|
|
List<ResToBeProcessedDTO> result = null; |
|
|
|
if (CollectionUtil.isNotEmpty(staterUsers)) { |
|
|
|
Map<String, OrgUser> userMap = userDeptOrLeaderService.getUserMapByIds(staterUsers); |
|
|
|
result = resVos.stream().peek(v -> v.getProcessTaskInfo() |
|
|
|
.setOwner(userMap.get(v.getProcessTaskInfo().getOwnerId()))) |
|
|
|
.collect(Collectors.toList()); |
|
|
|
} |
|
|
|
return PageVo.of(result,page.getTotal()); |
|
|
|
} |
|
|
|
|
|
|
|
public void exportHandledProjectList(HttpServletResponse response, ReqToBeProcessedDTO param) { |
|
|
|
PageVo<ResToBeProcessedDTO> page = queryHandledProjectList(param); |
|
|
|
List<ResToBeProcessedDTO> collect = (List<ResToBeProcessedDTO>) page.getRecords(); |
|
|
|
String fileName = null; |
|
|
|
if (param.getIsSupplement()){ |
|
|
|
fileName = "待办中心_我已处理_增补项目列表"; |
|
|
|
}else { |
|
|
|
fileName = "待办中心_我已处理_非增补项目列表"; |
|
|
|
} |
|
|
|
ExcelDownUtil.setFileName(fileName,response); |
|
|
|
//数据导出处理函数 |
|
|
|
try { |
|
|
|
EasyExcel.write(response.getOutputStream(), ResHandledProjectListExportDTO.class) |
|
|
|
.autoCloseStream(false) |
|
|
|
.registerWriteHandler(ExcelExportStyle.formalStyle()) |
|
|
|
.sheet(fileName) |
|
|
|
.doWrite(collect); |
|
|
|
} catch (IOException e) { |
|
|
|
throw new RuntimeException(e); |
|
|
|
} |
|
|
|
} |
|
|
|
} |