From fdb61533e9e6cf3c1f6597c031f93c359a72bbfa Mon Sep 17 00:00:00 2001 From: PoffyZhang <99775271@qq.com> Date: Mon, 3 Apr 2023 21:52:28 +0800 Subject: [PATCH 1/3] =?UTF-8?q?=E7=AB=8B=E9=A1=B9=E6=89=B9=E5=A4=8D?= =?UTF-8?q?=E6=97=B6=E9=97=B4?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../manage/DefaultDeclaredProjectManage.java | 60 ++++++++++---------- .../pmapi/todocenter/manage/TodoCenterManage.java | 12 +++- .../ningdatech/pmapi/instance/InstanceTest.java | 64 +++++++++++++++++++++- .../java/com/ningdatech/pmapi/stream/stream.java | 35 ++++++++++++ 4 files changed, 140 insertions(+), 31 deletions(-) create mode 100644 pmapi/src/test/java/com/ningdatech/pmapi/stream/stream.java diff --git a/pmapi/src/main/java/com/ningdatech/pmapi/projectdeclared/manage/DefaultDeclaredProjectManage.java b/pmapi/src/main/java/com/ningdatech/pmapi/projectdeclared/manage/DefaultDeclaredProjectManage.java index 22ea593..8bdc2bc 100644 --- a/pmapi/src/main/java/com/ningdatech/pmapi/projectdeclared/manage/DefaultDeclaredProjectManage.java +++ b/pmapi/src/main/java/com/ningdatech/pmapi/projectdeclared/manage/DefaultDeclaredProjectManage.java @@ -80,35 +80,37 @@ public class DefaultDeclaredProjectManage { } public void checkAmount(ProjectDTO projectInfo) { - BigDecimal declareAmount = projectInfo.getDeclareAmount(); - BigDecimal govSuperFinanceAmount = projectInfo.getDeclareGovSuperiorFinanceAmount(); - BigDecimal govOwnFinanceAmount = projectInfo.getDeclareGovOwnFinanceAmount(); - BigDecimal bankLendingAmount = projectInfo.getDeclareBankLendingAmount(); - BigDecimal haveAmount = projectInfo.getDeclareHaveAmount(); - BigDecimal otherAmount = projectInfo.getDeclareOtherAmount(); - BigDecimal totalAmount = govSuperFinanceAmount - .add(govOwnFinanceAmount).add(bankLendingAmount).add(haveAmount).add(otherAmount); - VUtils.isTrue(declareAmount.compareTo(totalAmount) != 0) - .throwMessage(String.format("申报失败! 申报总金额【%s】 不等于其它申报金额 【%s】",declareAmount,totalAmount)); - - //判断 年度计划金额 如果开着的话 - if(projectInfo.getIsAnnualPlanAmount()){ - BigDecimal annualPlanAmount = projectInfo.getAnnualPlanAmount(); - - VUtils.isTrue(annualPlanAmount.compareTo(BigDecimal.ZERO) <= 0) - .throwMessage(String.format("申报失败! 年度支付总金额【%s】 不能小于等于0",annualPlanAmount)); - VUtils.isTrue(annualPlanAmount.compareTo(declareAmount) > 0) - .throwMessage(String.format("申报失败! 年度支付总金额【%s】 不能大于申报金额 【%s】",annualPlanAmount,declareAmount)); - - BigDecimal annualGovSuperAmount = projectInfo.getAnnualPlanGovSuperiorFinanceAmount(); - BigDecimal annualOwnSuperAmount = projectInfo.getAnnualPlanGovOwnFinanceAmount(); - BigDecimal annualBankLendingAmount = projectInfo.getAnnualPlanBankLendingAmount(); - BigDecimal annualHaveAmount = projectInfo.getAnnualPlanHaveAmount(); - BigDecimal anualOtherAmount = projectInfo.getAnnualPlanOtherAmount(); - BigDecimal totalAnnual = annualGovSuperAmount - .add(annualOwnSuperAmount).add(annualBankLendingAmount).add(annualHaveAmount).add(anualOtherAmount); - VUtils.isTrue(annualPlanAmount.compareTo(totalAnnual) != 0) - .throwMessage(String.format("申报失败! 年度支付总金额【%s】 不等于其它年度支付金额 【%s】",annualPlanAmount,totalAnnual)); + if(Objects.nonNull(projectInfo.getDeclareAmount())){ + BigDecimal declareAmount = projectInfo.getDeclareAmount(); + BigDecimal govSuperFinanceAmount = projectInfo.getDeclareGovSuperiorFinanceAmount(); + BigDecimal govOwnFinanceAmount = projectInfo.getDeclareGovOwnFinanceAmount(); + BigDecimal bankLendingAmount = projectInfo.getDeclareBankLendingAmount(); + BigDecimal haveAmount = projectInfo.getDeclareHaveAmount(); + BigDecimal otherAmount = projectInfo.getDeclareOtherAmount(); + BigDecimal totalAmount = govSuperFinanceAmount + .add(govOwnFinanceAmount).add(bankLendingAmount).add(haveAmount).add(otherAmount); + VUtils.isTrue(declareAmount.compareTo(totalAmount) != 0) + .throwMessage(String.format("申报失败! 申报总金额【%s】 不等于其它申报金额 【%s】",declareAmount,totalAmount)); + + //判断 年度计划金额 如果开着的话 + if(projectInfo.getIsAnnualPlanAmount()){ + BigDecimal annualPlanAmount = projectInfo.getAnnualPlanAmount(); + + VUtils.isTrue(annualPlanAmount.compareTo(BigDecimal.ZERO) <= 0) + .throwMessage(String.format("申报失败! 年度支付总金额【%s】 不能小于等于0",annualPlanAmount)); + VUtils.isTrue(annualPlanAmount.compareTo(declareAmount) > 0) + .throwMessage(String.format("申报失败! 年度支付总金额【%s】 不能大于申报金额 【%s】",annualPlanAmount,declareAmount)); + + BigDecimal annualGovSuperAmount = projectInfo.getAnnualPlanGovSuperiorFinanceAmount(); + BigDecimal annualOwnSuperAmount = projectInfo.getAnnualPlanGovOwnFinanceAmount(); + BigDecimal annualBankLendingAmount = projectInfo.getAnnualPlanBankLendingAmount(); + BigDecimal annualHaveAmount = projectInfo.getAnnualPlanHaveAmount(); + BigDecimal anualOtherAmount = projectInfo.getAnnualPlanOtherAmount(); + BigDecimal totalAnnual = annualGovSuperAmount + .add(annualOwnSuperAmount).add(annualBankLendingAmount).add(annualHaveAmount).add(anualOtherAmount); + VUtils.isTrue(annualPlanAmount.compareTo(totalAnnual) != 0) + .throwMessage(String.format("申报失败! 年度支付总金额【%s】 不等于其它年度支付金额 【%s】",annualPlanAmount,totalAnnual)); + } } } diff --git a/pmapi/src/main/java/com/ningdatech/pmapi/todocenter/manage/TodoCenterManage.java b/pmapi/src/main/java/com/ningdatech/pmapi/todocenter/manage/TodoCenterManage.java index a01c057..eb6eba9 100644 --- a/pmapi/src/main/java/com/ningdatech/pmapi/todocenter/manage/TodoCenterManage.java +++ b/pmapi/src/main/java/com/ningdatech/pmapi/todocenter/manage/TodoCenterManage.java @@ -11,10 +11,13 @@ import javax.servlet.http.HttpServletResponse; import com.ningdatech.pmapi.projectdeclared.manage.DeclaredProjectManage; import com.ningdatech.pmapi.todocenter.handle.WithDrawHandle; +import com.wflow.workflow.enums.ProcessHandlerEnum; import org.apache.commons.io.FileUtils; import org.assertj.core.util.Lists; import org.flowable.engine.HistoryService; +import org.flowable.engine.RuntimeService; import org.flowable.engine.history.HistoricProcessInstance; +import org.flowable.variable.api.history.HistoricVariableInstance; import org.springframework.beans.BeanUtils; import org.springframework.mock.web.MockMultipartFile; import org.springframework.stereotype.Component; @@ -107,7 +110,7 @@ public class TodoCenterManage { private final ProcessTaskService processTaskService; private final HistoryService historyService; - private final IUserInfoService userInfoService; + private final RuntimeService runtimeService; private final IProjectService projectService; private final ProjectLibManage projectLibManage; private final StateMachineUtils stateMachineUtils; @@ -870,13 +873,20 @@ public class TodoCenterManage { //项目名称去重 defaultDeclaredProjectManage.checkDuplication(projectDto); + defaultDeclaredProjectManage.checkAmount(projectDto); //修改项目内容 if(!modifyProject(projectDto)){ throw new BusinessException("调整项目失败!"); } + + //设置 节点的状态 为null 代表继续审核 + runtimeService.setVariables(dto.getInstanceId(), + org.assertj.core.util.Maps.newHashMap("approve_" + dto.getTaskId(), "PASS")); + // 更新当前流程状态为审核中 processTaskService.updateProInstStatus(dto.getInstanceId()); + return dto.getInstanceId(); } diff --git a/pmapi/src/test/java/com/ningdatech/pmapi/instance/InstanceTest.java b/pmapi/src/test/java/com/ningdatech/pmapi/instance/InstanceTest.java index 3027063..6273194 100644 --- a/pmapi/src/test/java/com/ningdatech/pmapi/instance/InstanceTest.java +++ b/pmapi/src/test/java/com/ningdatech/pmapi/instance/InstanceTest.java @@ -1,16 +1,30 @@ package com.ningdatech.pmapi.instance; +import cn.hutool.core.collection.CollUtil; import com.alibaba.fastjson.JSON; +import com.baomidou.mybatisplus.core.toolkit.Wrappers; +import com.ningdatech.basic.model.PageVo; import com.ningdatech.pmapi.AppTests; +import com.ningdatech.pmapi.projectlib.manage.ProjectLibManage; +import com.ningdatech.pmapi.projectlib.model.entity.Project; +import com.ningdatech.pmapi.projectlib.model.entity.ProjectInst; +import com.ningdatech.pmapi.projectlib.model.req.ProjectListReq; +import com.ningdatech.pmapi.projectlib.service.IProjectInstService; +import com.wflow.contants.ProcessConstant; import com.wflow.workflow.bean.dto.ProcessInstanceUserDto; +import com.wflow.workflow.bean.dto.TodoCenterListReqDTO; import org.flowable.engine.HistoryService; import org.flowable.engine.RuntimeService; import org.flowable.engine.history.HistoricActivityInstance; import org.flowable.engine.runtime.ActivityInstance; +import org.flowable.task.api.history.HistoricTaskInstance; +import org.flowable.task.service.history.NativeHistoricTaskInstanceQuery; import org.junit.Test; +import org.springframework.beans.BeanUtils; import org.springframework.beans.factory.annotation.Autowired; -import java.util.List; +import java.util.*; +import java.util.stream.Collectors; /** * @Classname InstanceTest @@ -26,6 +40,12 @@ public class InstanceTest extends AppTests { @Autowired private HistoryService historyService; + @Autowired + private ProjectLibManage projectLibManage; + + @Autowired + private IProjectInstService projectInstService; + @Test public void test(){ String instanceId = "896fa188-96d8-11ed-9539-e2d4e8f16b2f"; @@ -54,4 +74,46 @@ public class InstanceTest extends AppTests { .orderByActivityInstanceStartTime().asc().list(); System.out.println(userTask); } + + @Test + public void testTodo(){ + String employeeCode = "GE_e9d5c7917acd4eeea04ff2a9454af62e"; + // 查出项目库项目 + ProjectListReq projectListReq = new ProjectListReq(); + List projects = projectLibManage.projectList(projectListReq); + Map projectsMap = projects.stream().collect(Collectors.toMap(Project::getId, v -> v)); + // 再查出项目关联的流程实例ID + List projectIdList = projects.stream().map(Project::getId).collect(Collectors.toList()); + if (CollUtil.isEmpty(projectIdList)) { + System.out.println("没有项目"); + return; + } + List projectInstList = projectInstService.list(Wrappers.lambdaQuery(ProjectInst.class) + .in(ProjectInst::getProjectId, projectIdList) + .orderByDesc(ProjectInst::getProjectId)); + Map projectInfoMap = projectInstList.stream().collect(Collectors.toMap(ProjectInst::getInstCode, p-> projectsMap.get(p.getProjectId()))); + List instCodes = projectInstList.stream().map(ProjectInst::getInstCode).collect(Collectors.toList()); + + // 查出用户工作流 + TodoCenterListReqDTO req = new TodoCenterListReqDTO(); + req.setEmployeeCode(employeeCode); + req.setInstCodes(instCodes); + + // 自定义sql查询所有已办的任务实例 + String nativeSql = "SELECT ht.* FROM act_hi_taskinst ht WHERE assignee_ = '" + employeeCode + + "' and end_time_ is not NULL"; + NativeHistoricTaskInstanceQuery taskInstanceQuery = + historyService.createNativeHistoricTaskInstanceQuery().sql(nativeSql); + List taskInstances = taskInstanceQuery.list(); + + Set set = new HashSet(); + List taskInstanceList = taskInstances.stream() + .filter(t -> instCodes.contains(t.getProcessInstanceId())) + .sorted(Comparator.comparing(HistoricTaskInstance::getEndTime)).collect(Collectors.toList()) + .stream() + .filter(v -> set.add(v.getProcessInstanceId())) + .collect(Collectors.toList()); + + System.out.println(taskInstanceList.size()); + } } diff --git a/pmapi/src/test/java/com/ningdatech/pmapi/stream/stream.java b/pmapi/src/test/java/com/ningdatech/pmapi/stream/stream.java new file mode 100644 index 0000000..7de6137 --- /dev/null +++ b/pmapi/src/test/java/com/ningdatech/pmapi/stream/stream.java @@ -0,0 +1,35 @@ +package com.ningdatech.pmapi.stream; + +import org.flowable.task.api.history.HistoricTaskInstance; +import org.junit.Test; + +import java.util.ArrayList; +import java.util.List; +import java.util.Set; +import java.util.stream.Collectors; + +/** + * @Classname stream + * @Description + * @Date 2023/4/3 14:52 + * @Author PoffyZhang + */ +public class stream { + + @Test + public void test(){ + List list = new ArrayList<>(); + list.add(1); + list.add(2); + list.add(2); + list.add(3); + list.add(3); + list.add(1); + list.add(1); + list.add(1); + + Set set = list.stream().collect(Collectors.toSet()); + System.out.println(set); + } + +} From 22b035fdb746477c02e5e14c90c429558c6c51b1 Mon Sep 17 00:00:00 2001 From: CMM <2198256324@qq.com> Date: Mon, 3 Apr 2023 22:45:56 +0800 Subject: [PATCH 2/3] =?UTF-8?q?=E6=B5=81=E7=A8=8B=E5=8F=91=E8=B5=B7?= =?UTF-8?q?=E4=BA=BA=E6=92=A4=E5=9B=9E=E5=88=A4=E6=96=AD=E4=BF=AE=E6=94=B9?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../com/ningdatech/pmapi/todocenter/handle/WithDrawHandle.java | 8 ++++++-- 1 file changed, 6 insertions(+), 2 deletions(-) diff --git a/pmapi/src/main/java/com/ningdatech/pmapi/todocenter/handle/WithDrawHandle.java b/pmapi/src/main/java/com/ningdatech/pmapi/todocenter/handle/WithDrawHandle.java index 2a0bc36..3c5316b 100644 --- a/pmapi/src/main/java/com/ningdatech/pmapi/todocenter/handle/WithDrawHandle.java +++ b/pmapi/src/main/java/com/ningdatech/pmapi/todocenter/handle/WithDrawHandle.java @@ -7,6 +7,7 @@ import com.ningdatech.pmapi.todocenter.constant.TodoCenterContant; import com.ningdatech.pmapi.user.security.auth.model.UserFullInfoDTO; import com.ningdatech.pmapi.user.security.auth.model.UserInfoDetails; import com.ningdatech.pmapi.user.util.LoginUserUtil; +import com.wflow.contants.HisProInsEndActId; import com.wflow.workflow.bean.dto.ReqProcessHandlerDTO; import com.wflow.workflow.bean.process.ProgressNode; import com.wflow.workflow.bean.process.enums.NodeTypeEnum; @@ -23,6 +24,7 @@ import org.springframework.stereotype.Component; import java.util.List; import java.util.Objects; +import java.util.stream.Collectors; /** * @Classname WithDrawHandle @@ -212,9 +214,11 @@ public class WithDrawHandle { .processInstanceId(instance.getId()).finished() .activityType(TodoCenterContant.Handler.ACTIVITY_APPROVAL) .orderByHistoricActivityInstanceEndTime().asc().list(); - + List instances = finished.stream() + .filter(a -> !HisProInsEndActId.WITHDRAW.equals(a.getDeleteReason())) + .collect(Collectors.toList()); //如果有已经被审核过的 节点 返回false - if(CollUtil.isNotEmpty(finished)){ + if(CollUtil.isNotEmpty(instances)){ return Boolean.FALSE; } From f1d1818560fe66cd57c727a35486816658019791 Mon Sep 17 00:00:00 2001 From: PoffyZhang <99775271@qq.com> Date: Mon, 3 Apr 2023 23:02:42 +0800 Subject: [PATCH 3/3] =?UTF-8?q?=E7=AB=8B=E9=A1=B9=E6=89=B9=E5=A4=8D?= =?UTF-8?q?=E6=97=B6=E9=97=B4?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../pmapi/todocenter/manage/TodoCenterManage.java | 17 ++++++++++++++--- .../com/ningdatech/pmapi/instance/InstanceTest.java | 14 ++++++++++++++ 2 files changed, 28 insertions(+), 3 deletions(-) diff --git a/pmapi/src/main/java/com/ningdatech/pmapi/todocenter/manage/TodoCenterManage.java b/pmapi/src/main/java/com/ningdatech/pmapi/todocenter/manage/TodoCenterManage.java index eb6eba9..c7436c6 100644 --- a/pmapi/src/main/java/com/ningdatech/pmapi/todocenter/manage/TodoCenterManage.java +++ b/pmapi/src/main/java/com/ningdatech/pmapi/todocenter/manage/TodoCenterManage.java @@ -881,14 +881,25 @@ public class TodoCenterManage { } //设置 节点的状态 为null 代表继续审核 - runtimeService.setVariables(dto.getInstanceId(), - org.assertj.core.util.Maps.newHashMap("approve_" + dto.getTaskId(), "PASS")); + List approves = historyService.createHistoricVariableInstanceQuery() + .processInstanceId(dto.getInstanceId()) + .variableNameLike("approve_%") + .list(); + if(CollUtil.isNotEmpty(approves)){ + for(HistoricVariableInstance approve : approves){ + if(approve.getValue() instanceof ProcessHandlerEnum){ + if(ProcessHandlerEnum.BACK.equals(ProcessHandlerEnum.getEnumByName(String.valueOf(approve.getValue())))){ + runtimeService.removeVariable(approve.getProcessInstanceId(),approve.getVariableName()); + break; + } + } + } + } // 更新当前流程状态为审核中 processTaskService.updateProInstStatus(dto.getInstanceId()); return dto.getInstanceId(); - } private Boolean modifyProject(ProjectDTO projectDto) { diff --git a/pmapi/src/test/java/com/ningdatech/pmapi/instance/InstanceTest.java b/pmapi/src/test/java/com/ningdatech/pmapi/instance/InstanceTest.java index 6273194..c7620b1 100644 --- a/pmapi/src/test/java/com/ningdatech/pmapi/instance/InstanceTest.java +++ b/pmapi/src/test/java/com/ningdatech/pmapi/instance/InstanceTest.java @@ -13,12 +13,14 @@ import com.ningdatech.pmapi.projectlib.service.IProjectInstService; import com.wflow.contants.ProcessConstant; import com.wflow.workflow.bean.dto.ProcessInstanceUserDto; import com.wflow.workflow.bean.dto.TodoCenterListReqDTO; +import com.wflow.workflow.enums.ProcessHandlerEnum; import org.flowable.engine.HistoryService; import org.flowable.engine.RuntimeService; import org.flowable.engine.history.HistoricActivityInstance; import org.flowable.engine.runtime.ActivityInstance; import org.flowable.task.api.history.HistoricTaskInstance; import org.flowable.task.service.history.NativeHistoricTaskInstanceQuery; +import org.flowable.variable.api.history.HistoricVariableInstance; import org.junit.Test; import org.springframework.beans.BeanUtils; import org.springframework.beans.factory.annotation.Autowired; @@ -116,4 +118,16 @@ public class InstanceTest extends AppTests { System.out.println(taskInstanceList.size()); } + + @Test + public void test2(){ + // 获取节点处理结果 +// Map varMap = historyService.createHistoricVariableInstanceQuery() +// .processInstanceId("e99fe24c-d21c-11ed-af5d-02426daa406d") +// .variableNameLike("approve_%") +// .list().stream() +// .collect(Collectors.toMap(HistoricVariableInstance::getVariableName, v -> (ProcessHandlerEnum) v.getValue())); + runtimeService.removeVariable("564102ce-d1ff-11ed-b694-02424b2b849f","approve_7d2a191a-d1ff-11ed-b694-02424b2b849f"); + System.out.println(1); + } }