From ab3d5dc22e2a1b5f0ca9fea04136d0bd825628c8 Mon Sep 17 00:00:00 2001 From: PoffyZhang <99775271@qq.com> Date: Fri, 30 Jun 2023 14:52:01 +0800 Subject: [PATCH] =?UTF-8?q?=E5=88=9D=E5=AE=A1=E4=BA=BA=E5=91=98=20?= =?UTF-8?q?=E5=92=8C=20=E8=87=AA=E5=8A=A8=E4=B8=8B=E4=B8=80=E7=8A=B6?= =?UTF-8?q?=E6=80=81?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../pmapi/projectlib/manage/ProjectLibManage.java | 27 +++++- .../pmapi/scheduler/listener/CcTaskListener.java | 102 +++++++++++++++++++++ .../pmapi/staging/enums/MsgTypeEnum.java | 4 +- .../todocenter/constant/WorkNoticeContant.java | 2 + 4 files changed, 133 insertions(+), 2 deletions(-) create mode 100644 pmapi/src/main/java/com/ningdatech/pmapi/scheduler/listener/CcTaskListener.java diff --git a/pmapi/src/main/java/com/ningdatech/pmapi/projectlib/manage/ProjectLibManage.java b/pmapi/src/main/java/com/ningdatech/pmapi/projectlib/manage/ProjectLibManage.java index 5e992bb..af860b8 100644 --- a/pmapi/src/main/java/com/ningdatech/pmapi/projectlib/manage/ProjectLibManage.java +++ b/pmapi/src/main/java/com/ningdatech/pmapi/projectlib/manage/ProjectLibManage.java @@ -32,12 +32,15 @@ import com.ningdatech.pmapi.organization.model.entity.DingOrganization; import com.ningdatech.pmapi.organization.service.IDingOrganizationService; import com.ningdatech.pmapi.projectdeclared.model.dto.DelayedApplyDTO; import com.ningdatech.pmapi.projectdeclared.model.entity.Contract; +import com.ningdatech.pmapi.projectdeclared.model.entity.PaymentPlan; import com.ningdatech.pmapi.projectdeclared.model.entity.PreInsAcceptancePerson; import com.ningdatech.pmapi.projectdeclared.model.entity.Purchase; import com.ningdatech.pmapi.projectdeclared.model.vo.ContractVO; +import com.ningdatech.pmapi.projectdeclared.model.vo.PaymentPlanVO; import com.ningdatech.pmapi.projectdeclared.model.vo.PreInsAcceptancePersonVO; import com.ningdatech.pmapi.projectdeclared.model.vo.PurchaseVO; import com.ningdatech.pmapi.projectdeclared.service.IContractService; +import com.ningdatech.pmapi.projectdeclared.service.IPaymentPlanService; import com.ningdatech.pmapi.projectdeclared.service.IPreInsAcceptancePersonService; import com.ningdatech.pmapi.projectdeclared.service.IPurchaseService; import com.ningdatech.pmapi.projectdeclared.utils.GenerateProjectCodeUtil; @@ -66,6 +69,7 @@ import org.springframework.beans.BeanUtils; import org.springframework.stereotype.Component; import javax.servlet.http.HttpServletResponse; +import java.math.BigDecimal; import java.time.LocalDateTime; import java.util.*; import java.util.stream.Collectors; @@ -102,6 +106,8 @@ public class ProjectLibManage { private final IPreInsAcceptancePersonService acceptancePersonService; + private final IPaymentPlanService paymentPlanService; + public PageVo projectLibList(ProjectListReq req) { LambdaQueryWrapper query = ProjectHelper.projectQuery(req); query.eq(Project::getNewest,Boolean.TRUE); @@ -540,7 +546,12 @@ public class ProjectLibManage { Contract contract = contractService.getOne(Wrappers.lambdaQuery(Contract.class) .in(Contract::getProjectId, allVersionProjectId) .last(BizConst.LIMIT_1)); - vo.setContract(BeanUtil.copyProperties(contract, ContractVO.class)); + ContractVO contractVO = BeanUtil.copyProperties(contract, ContractVO.class); + vo.setContract(contractVO); + List payments = paymentPlanService.list(Wrappers.lambdaQuery(PaymentPlan.class) + .eq(PaymentPlan::getProjectId, projectId) + .orderByAsc(PaymentPlan::getPaymentTime)); + contractVO.setPayments(convertPayments(payments,contractVO.getTotalAmount())); //查询初验信息 List acceptancePersons = acceptancePersonService.list(Wrappers.lambdaQuery(PreInsAcceptancePerson.class) @@ -788,4 +799,18 @@ public class ProjectLibManage { return acceptancePersons.stream().map(u -> BeanUtil.copyProperties(u,PreInsAcceptancePersonVO.class)).collect(Collectors.toList()); } + + private List convertPayments(List payments, BigDecimal totalAmount) { + if(CollUtil.isEmpty(payments)){ + return Collections.emptyList(); + } + return payments.stream().map(p -> { + PaymentPlanVO vo = BeanUtil.copyProperties(p, PaymentPlanVO.class); + vo.setRatio((Objects.isNull(totalAmount)||totalAmount.compareTo(BigDecimal.ZERO) == 0) ? "0%" + : p.getPaymentAmount().multiply(BigDecimal.valueOf(100)) + .divide(totalAmount,BigDecimal.ROUND_CEILING,BigDecimal.ROUND_CEILING) + "%"); + return vo; + }) + .collect(Collectors.toList()); + } } diff --git a/pmapi/src/main/java/com/ningdatech/pmapi/scheduler/listener/CcTaskListener.java b/pmapi/src/main/java/com/ningdatech/pmapi/scheduler/listener/CcTaskListener.java new file mode 100644 index 0000000..60659b6 --- /dev/null +++ b/pmapi/src/main/java/com/ningdatech/pmapi/scheduler/listener/CcTaskListener.java @@ -0,0 +1,102 @@ +package com.ningdatech.pmapi.scheduler.listener; + +import com.alibaba.fastjson.JSON; +import com.baomidou.mybatisplus.core.toolkit.Wrappers; +import com.ningdatech.cache.model.cache.CacheKey; +import com.ningdatech.cache.repository.CachePlusOps; +import com.ningdatech.pmapi.common.constant.BizConst; +import com.ningdatech.pmapi.projectlib.model.entity.Project; +import com.ningdatech.pmapi.projectlib.model.entity.ProjectInst; +import com.ningdatech.pmapi.projectlib.service.IProjectInstService; +import com.ningdatech.pmapi.projectlib.service.IProjectService; +import com.ningdatech.pmapi.staging.enums.MsgTypeEnum; +import com.ningdatech.pmapi.sys.manage.NoticeManage; +import com.wflow.bean.entity.WflowCcTasks; +import com.wflow.service.WflowCcTasksService; +import com.wflow.workflow.notify.event.CcTaskEvent; +import lombok.RequiredArgsConstructor; +import lombok.extern.slf4j.Slf4j; +import org.flowable.engine.HistoryService; +import org.flowable.engine.history.HistoricProcessInstance; +import org.springframework.context.event.EventListener; +import org.springframework.scheduling.annotation.Async; +import org.springframework.stereotype.Component; +import java.time.Duration; +import java.util.List; +import java.util.Objects; +import static com.ningdatech.pmapi.todocenter.constant.WorkNoticeContant.CC_MSG_TEMPLATE; + +/** + * 工作流开始 事件监听 + * + * @author ZPF + * @return + * @since 2023/04/14 14:19 + */ +@Slf4j +@Component +@RequiredArgsConstructor +public class CcTaskListener { + private final IProjectInstService projectInstService; + + private final HistoryService historyService; + private final IProjectService projectService; + private final NoticeManage noticeManage; + + private final WflowCcTasksService ccTasksService; + + private final CachePlusOps cachePlusOps; + + private static final String DUP_KEY = "ccTasks"; + private static final String NODE = "node:"; + + @Async + @EventListener + public void onApplicationEvent(CcTaskEvent event) { + log.info("进入抄送人任务 事件监听!{}", JSON.toJSONString(event)); + String instCode = event.getInstCode(); + String processDefinitionId = event.getProcessDefinitionId(); + String nodeId = event.getNodeId(); + String taskId = event.getTaskId(); + + //这里 redis 处理一下 1分钟处理同一 nodeId 一次 + if (cachePlusOps.get(NODE + nodeId + DUP_KEY) != null) { + log.info("一分钟只能处理该nodeId一次!{}", nodeId); + return; + } + + //1分钟 + CacheKey key = new CacheKey(); + key.setKey(NODE + nodeId + DUP_KEY); + key.setExpire(Duration.ofMinutes(1)); + cachePlusOps.set(key, nodeId); + + //1.去查找 项目实例关系表 + List tasks = ccTasksService.list(Wrappers.lambdaQuery(WflowCcTasks.class) + .eq(WflowCcTasks::getInstanceId, instCode) + .eq(WflowCcTasks::getNodeId, nodeId)); + + if (Objects.isNull(tasks)) { + return; + } + + tasks.stream().forEach(task -> { + HistoricProcessInstance instance = historyService.createHistoricProcessInstanceQuery() + .processInstanceId(instCode) + .singleResult(); + + ProjectInst projectInst = projectInstService.getOne(Wrappers.lambdaQuery(ProjectInst.class) + .eq(ProjectInst::getInstCode, instCode) + .last(BizConst.LIMIT_1)); + if(Objects.isNull(projectInst) || Objects.isNull(instance)){ + return; + } + Long projectId = projectInst.getProjectId(); + Project project = projectService.getNewProject(projectId); + + //发送消息 + noticeManage.sendNotice(task.getUserId(),93L,project,instance.getProcessDefinitionName(), + CC_MSG_TEMPLATE, MsgTypeEnum.PROJECT_REVIEW_CC); + }); + } +} \ No newline at end of file diff --git a/pmapi/src/main/java/com/ningdatech/pmapi/staging/enums/MsgTypeEnum.java b/pmapi/src/main/java/com/ningdatech/pmapi/staging/enums/MsgTypeEnum.java index fe5c56a..4baa002 100644 --- a/pmapi/src/main/java/com/ningdatech/pmapi/staging/enums/MsgTypeEnum.java +++ b/pmapi/src/main/java/com/ningdatech/pmapi/staging/enums/MsgTypeEnum.java @@ -46,7 +46,9 @@ public enum MsgTypeEnum { /** * 项目审核驳回 */ - PROJECT_REVIEW_REJECT(7,"项目审核"); + PROJECT_REVIEW_REJECT(7,"项目审核"), + + PROJECT_REVIEW_CC(8,"项目抄送"); private Integer code; private String desc; diff --git a/pmapi/src/main/java/com/ningdatech/pmapi/todocenter/constant/WorkNoticeContant.java b/pmapi/src/main/java/com/ningdatech/pmapi/todocenter/constant/WorkNoticeContant.java index fc2db0a..fe12e28 100644 --- a/pmapi/src/main/java/com/ningdatech/pmapi/todocenter/constant/WorkNoticeContant.java +++ b/pmapi/src/main/java/com/ningdatech/pmapi/todocenter/constant/WorkNoticeContant.java @@ -10,6 +10,8 @@ public interface WorkNoticeContant { public final String BACK_MSG_TEMPLATE = "【%s】的【%s】被退回,请及时处理。"; public final String REJECT_MSG_TEMPLATE = "【%s】的【%s】被驳回,请及时处理。"; + public final String CC_MSG_TEMPLATE = "【%s】的【%s】有消息抄送您,请查看详情"; + public final String AUDIT_WORK_TITLE = "审核任务"; public final String EXPERT_REVIEW_TEMPLATE = "【%s】的【%s】待您评审,请及时处理。";