From eece39f06e8afbf85e1d815d9746aec97d1b0bc5 Mon Sep 17 00:00:00 2001 From: daiqy88 Date: Mon, 3 Nov 2025 18:40:31 +0800 Subject: [PATCH] =?UTF-8?q?=E9=9B=86=E6=88=90CID=E4=BB=BF=E7=9C=9F?= =?UTF-8?q?=E8=AF=84=E5=AE=A1=E6=B5=81?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../com/sdm/approve/ApproveApplication.java | 1 - .../com/sdm/common/utils/SystemOperate.java | 71 ++--- .../com/sdm/pbs/dao/SimulationFlowMapper.java | 59 +++++ .../com/sdm/pbs/flow/AbstractFlowNode.java | 118 +++++++++ .../com/sdm/pbs/flow/CloudAppFlowNode.java | 40 +++ .../com/sdm/pbs/flow/ConditionFlowNode.java | 41 +++ .../java/com/sdm/pbs/flow/EndFlowNode.java | 44 ++++ .../java/com/sdm/pbs/flow/FlowNodeBean.java | 25 ++ .../java/com/sdm/pbs/flow/HpcFlowNode.java | 41 +++ .../main/java/com/sdm/pbs/flow/IFlowNode.java | 44 ++++ .../com/sdm/pbs/flow/LocalAppFlowNode.java | 41 +++ .../com/sdm/pbs/flow/LogicAndFlowNode.java | 41 +++ .../com/sdm/pbs/flow/LogicOrFlowNode.java | 41 +++ .../java/com/sdm/pbs/flow/LoopFlowNode.java | 42 +++ .../java/com/sdm/pbs/flow/StartFlowNode.java | 41 +++ .../model/entity/SimulationFlowInstance.java | 45 ++++ .../model/entity/SimulationFlowMember.java | 26 ++ .../pbs/model/entity/SimulationFlowNode.java | 45 ++++ .../model/entity/SimulationFlowTemplate.java | 33 +++ .../sdm/grpc/server/CidApproveFlowServer.java | 39 +++ .../ReceiveCidApproveFlowNoticeService.java | 20 ++ .../controller/SystemApproveController.java | 26 +- .../system/dao/SimulationApproveMapper.java | 5 +- .../system/model/entity/ApproveFlowBean.java | 12 + .../model/entity/ApproveTemplateBean.java | 6 + .../service/ISimulatinoApprovalService.java | 11 +- .../impl/SimulationApproveServiceImpl.java | 242 ++++++++++++++++-- system/src/main/proto/approve.proto | 52 ++++ system/src/main/resources/application-dev.yml | 9 +- .../src/main/resources/application-prod.yml | 9 +- 30 files changed, 1196 insertions(+), 74 deletions(-) create mode 100644 pbs/src/main/java/com/sdm/pbs/dao/SimulationFlowMapper.java create mode 100644 pbs/src/main/java/com/sdm/pbs/flow/AbstractFlowNode.java create mode 100644 pbs/src/main/java/com/sdm/pbs/flow/CloudAppFlowNode.java create mode 100644 pbs/src/main/java/com/sdm/pbs/flow/ConditionFlowNode.java create mode 100644 pbs/src/main/java/com/sdm/pbs/flow/EndFlowNode.java create mode 100644 pbs/src/main/java/com/sdm/pbs/flow/FlowNodeBean.java create mode 100644 pbs/src/main/java/com/sdm/pbs/flow/HpcFlowNode.java create mode 100644 pbs/src/main/java/com/sdm/pbs/flow/IFlowNode.java create mode 100644 pbs/src/main/java/com/sdm/pbs/flow/LocalAppFlowNode.java create mode 100644 pbs/src/main/java/com/sdm/pbs/flow/LogicAndFlowNode.java create mode 100644 pbs/src/main/java/com/sdm/pbs/flow/LogicOrFlowNode.java create mode 100644 pbs/src/main/java/com/sdm/pbs/flow/LoopFlowNode.java create mode 100644 pbs/src/main/java/com/sdm/pbs/flow/StartFlowNode.java create mode 100644 pbs/src/main/java/com/sdm/pbs/model/entity/SimulationFlowInstance.java create mode 100644 pbs/src/main/java/com/sdm/pbs/model/entity/SimulationFlowMember.java create mode 100644 pbs/src/main/java/com/sdm/pbs/model/entity/SimulationFlowNode.java create mode 100644 pbs/src/main/java/com/sdm/pbs/model/entity/SimulationFlowTemplate.java create mode 100644 system/src/main/java/com/sdm/grpc/server/CidApproveFlowServer.java create mode 100644 system/src/main/java/com/sdm/grpc/server/ReceiveCidApproveFlowNoticeService.java create mode 100644 system/src/main/java/com/sdm/system/model/entity/ApproveTemplateBean.java create mode 100644 system/src/main/proto/approve.proto diff --git a/approve/src/main/java/com/sdm/approve/ApproveApplication.java b/approve/src/main/java/com/sdm/approve/ApproveApplication.java index 1b705ac0..d099807a 100644 --- a/approve/src/main/java/com/sdm/approve/ApproveApplication.java +++ b/approve/src/main/java/com/sdm/approve/ApproveApplication.java @@ -13,5 +13,4 @@ public class ApproveApplication { public static void main(String[] args) { SpringApplication.run(ApproveApplication.class, args); } - } diff --git a/common/src/main/java/com/sdm/common/utils/SystemOperate.java b/common/src/main/java/com/sdm/common/utils/SystemOperate.java index a4c56087..ccc7c592 100644 --- a/common/src/main/java/com/sdm/common/utils/SystemOperate.java +++ b/common/src/main/java/com/sdm/common/utils/SystemOperate.java @@ -8,7 +8,9 @@ import java.io.*; import java.net.URLEncoder; import java.nio.file.Files; import java.nio.file.Paths; +import java.text.SimpleDateFormat; import java.util.Base64; +import java.util.Date; @Slf4j public class SystemOperate { @@ -19,11 +21,10 @@ public class SystemOperate { String osName = System.getProperty("os.name"); osName = osName.toLowerCase(); String[] shCmd = null; - if(osName.contains("linux")) { + if (osName.contains("linux")) { String[] linuxCmd = {"/bin/sh", "-c", command}; shCmd = linuxCmd; - } - else { + } else { String[] winCmd = {"cmd", "/c", command}; shCmd = winCmd; } @@ -110,41 +111,39 @@ public class SystemOperate { /** * 向http response中输出文件流 + * * @param * @param inputFileName * @param outputFileName */ - public static void outputHttpFileStream(HttpServletResponse httpServletResponse,String inputFileName,String outputFileName) - { - try { + public static void outputHttpFileStream(HttpServletResponse httpServletResponse, String inputFileName, String outputFileName) { + try { - File file = new File(inputFileName); - if (!file.exists()) { - return; - } else { - String encodeFileName = URLEncoder.encode(outputFileName, "UTF-8"); - encodeFileName = encodeFileName.replaceAll("\\+", "%20"); - httpServletResponse.reset(); - httpServletResponse.setCharacterEncoding("UTF-8"); - String contentType = Files.probeContentType(Paths.get(inputFileName)); - if (contentType == null) { - contentType = MediaType.APPLICATION_OCTET_STREAM_VALUE; - } - httpServletResponse.addHeader("Content-Disposition", "attachment;filename=\"" + encodeFileName + "\";filename*=utf-8"); - httpServletResponse.addHeader("Content-Length", "" + file.length()); - httpServletResponse.addHeader("Content-Type", contentType); - OutputStream outputStream = new BufferedOutputStream(httpServletResponse.getOutputStream()); - InputStream inputStream = new FileInputStream(file); - outputStream.write(inputStream.readAllBytes()); - outputStream.flush(); - outputStream.close(); - inputStream.close(); - } - } - catch (Exception ex) - { - ex.printStackTrace(); - } + File file = new File(inputFileName); + if (!file.exists()) { + return; + } else { + String encodeFileName = URLEncoder.encode(outputFileName, "UTF-8"); + encodeFileName = encodeFileName.replaceAll("\\+", "%20"); + httpServletResponse.reset(); + httpServletResponse.setCharacterEncoding("UTF-8"); + String contentType = Files.probeContentType(Paths.get(inputFileName)); + if (contentType == null) { + contentType = MediaType.APPLICATION_OCTET_STREAM_VALUE; + } + httpServletResponse.addHeader("Content-Disposition", "attachment;filename=\"" + encodeFileName + "\";filename*=utf-8"); + httpServletResponse.addHeader("Content-Length", "" + file.length()); + httpServletResponse.addHeader("Content-Type", contentType); + OutputStream outputStream = new BufferedOutputStream(httpServletResponse.getOutputStream()); + InputStream inputStream = new FileInputStream(file); + outputStream.write(inputStream.readAllBytes()); + outputStream.flush(); + outputStream.close(); + inputStream.close(); + } + } catch (Exception ex) { + ex.printStackTrace(); + } } @@ -152,4 +151,10 @@ public class SystemOperate { process.destroy(); } + public static String getCurrentTime() + { + SimpleDateFormat sdf = new SimpleDateFormat("yyyy-MM-dd HH:mm:ss"); + return sdf.format(new Date()); + } + } diff --git a/pbs/src/main/java/com/sdm/pbs/dao/SimulationFlowMapper.java b/pbs/src/main/java/com/sdm/pbs/dao/SimulationFlowMapper.java new file mode 100644 index 00000000..ed41c3dd --- /dev/null +++ b/pbs/src/main/java/com/sdm/pbs/dao/SimulationFlowMapper.java @@ -0,0 +1,59 @@ +package com.sdm.pbs.dao; + + +import com.sdm.pbs.model.entity.SimulationFlowInstance; +import com.sdm.pbs.model.entity.SimulationFlowTemplate; +import com.sdm.pbs.model.entity.SimulationFlowMember; +import org.apache.ibatis.annotations.*; + +import java.util.List; + +@Mapper +public interface SimulationFlowMapper { + + @Insert("INSERT INTO simulation_flow_template(uuid,templateName,version,template,templateStatus,templateType,approveStatus,comment,tenantId,creator) VALUES(#{template.uuid},#{template.templateName},#{template.version},#{template.template},#{template.templateStatus},#{template.templateType},#{template.approveStatus},#{template.comment},#{template.tenantId},#{template.creator})") + int addSimulationFlowTemplate(@Param("template") SimulationFlowTemplate template); + + @Update("UPDATE simulation_flow_template SET templateName=#{template.templateName},templateType=#{template.templateType},approveStatus=#{template.approveStatus},version=#{template.version},template=#{template.template},templateStatus=#{template.templateStatus},comment=#{template.comment},tenantId=#{template.tenantId} WHERE uuid=#{template.uuid}") + int updateSimulationFlowTemplate(@Param("template") SimulationFlowTemplate template); + + @Select("SELECT * FROM simulation_flow_template WHERE approveStatus=1") + List querySimulationAllFlowTemplate(); + + @Select("SELECT templateName FROM simulation_flow_template") + List querySimulateAllTemplateName(); + + @Select("SELECT DISTINCT(version) FROM simulation_flow_template WHERE uuid=#{templateId}") + List querySimulationFlowTemplateVersion(@Param("templateId") String templateId); + + @Update("UPDATE simulation_flow_template SET approveStatus=#{approveStatus} WHERE uuid=#{templateId}") + int updateSimulationFlowTemplateApproveStatus(@Param("approveStatus") int approveStatus, @Param("templateId") String templateId); + + @Delete("DELETE FROM simulation_flow_template WHERE uuid=#{templateId}") + int deleteSimulationFlowTemplate(@Param("templateId") String templateId); + + @Insert("INSERT INTO simulation_flow_instance(uuid,flowName,templateName,templateId,nodeId,nodeName,taskId,taskName,runId,runName,flowStatus,workPath,currentPhase,planEndTime,beginTime,endTime,tenantId,creator) VALUES (#{instance.uuid},#{instance.flowName},#{instance.templateName},#{instance.templateId},#{instance.nodeId},#{instance.nodeName},#{instance.taskId},#{instance.taskName},#{instance.runId},#{instance.runName},#{instance.flowStatus},#{instance.workPath},#{instance.currentPhase},#{instance.planEndTime},#{instance.beginTime},#{instance.endTime},#{instance.tenantId},#{instance.creator})") + int addSimulationFlowTemplateInstance(@Param("instance")SimulationFlowInstance instance); + + @Update("UPDATE simulation_flow_instance SET nodeId=#{instance.nodeId},nodeName=#{instance.nodeName},taskId=#{instance.taskId},taskName=#{instance.taskName},runId=#{instance.runId},runName=#{instance.runName},flowStatus=#{instance.flowStatus},workPath=#{instance.workPath},currentPath=#{instance.currentPath},planEndTime=#{instance.planEndTime},beginTime=#{instance.beginTime},endTime=#{instance.endTime} WHERE uuid=#{instance.uuid}") + int updateSimulationFlowInstance(@Param("instance")SimulationFlowInstance instance); + + @Delete("DELETE FROM simulation_flow_instance WHERE uuid=#{instanceId}") + int deleteSimulationFlowInstance(@Param("instanceId") int instanceId); + + @Select("SELECT * FROM simulation_flow_instance WHERE ${condition}") + List querySimulationFlowInstanceByCondition(@Param("condition") String condition); + + @Insert("INSERT INTO simulation_flow_member(flowId,flowName,memberName,memberId,role,creator) VALUES (#{member.flowId},#{member.flowName},#{member.memberName},#{member.memberId},#{member.role},#{member.creator})") + int addSimulationFlowInstanceMember(@Param("member") SimulationFlowMember member); + + @Update("UPDATE simulation_flow_member SET memberName=#{member.memberName},memberId=#{member.memberId} role=#{member.role} WHERE id=#{member.id}") + int updateSimulationFlowInstanceMember(@Param("member") SimulationFlowMember member); + + @Delete("DELETE FROM simulation_flow_member WHERE id=#{id}") + int deleteSimulationFlowInstanceMember(@Param("id") int id); + + @Select("SELECT * FROM simulation_flow_member WHERE flowId=#{flowId}") + List querySimulationFlowMember(@Param("flowId") String flowId); + +} diff --git a/pbs/src/main/java/com/sdm/pbs/flow/AbstractFlowNode.java b/pbs/src/main/java/com/sdm/pbs/flow/AbstractFlowNode.java new file mode 100644 index 00000000..aaee4fe6 --- /dev/null +++ b/pbs/src/main/java/com/sdm/pbs/flow/AbstractFlowNode.java @@ -0,0 +1,118 @@ +package com.sdm.pbs.flow; + +import com.sdm.common.utils.SystemOperate; + +import java.util.ArrayList; +import java.util.List; + +public abstract class AbstractFlowNode extends FlowNodeBean implements IFlowNode{ + + public AbstractFlowNode(FlowNodeBean nodeBean) + { + this.nodeName = nodeBean.nodeName; + this.nodeId = nodeBean.nodeId; + this.flowId = nodeBean.flowId; + this.beginTime = nodeBean.beginTime; + this.endTime = nodeBean.endTime; + this.exeCmd = nodeBean.exeCmd; + this.nodeParams = nodeBean.nodeParams; + this.nodeStatus = nodeBean.nodeStatus; + this.nodeType = nodeBean.nodeType; + this.description = nodeBean.description; + this.preProcessCmd = nodeBean.preProcessCmd; + this.postProcessCmd = nodeBean.postProcessCmd; + } + protected List children = new ArrayList<>(); + @Override + public String getNodeName() { + return nodeName; + } + + @Override + public String getFlowId() { + return flowId; + } + + @Override + public int getNodeType() { + return nodeType; + } + + @Override + public int getNodeStatus() { + return nodeStatus; + } + + @Override + public int setNodeStatus(int status) { + return 0; + } + + @Override + public void stop() { + + } + + @Override + public void start() { + + } + + @Override + public String getNodeParams() { + return nodeParams; + } + + @Override + public void setNodeParams(String params) { + + } + + @Override + public void setNodeExeCmd(String cmd) { + + } + + @Override + public String getNodeExeCmd() { + return exeCmd; + } + + @Override + public String getBeginTime() { + return beginTime; + } + + @Override + public void setBeginTime(String beginTime) { + + } + + @Override + public String getEndTime() { + return endTime; + } + + @Override + public void setEndTime(String endTime) { + + } + + @Override + public void execute() + { + setBeginTime(SystemOperate.getCurrentTime()); + //执行前处理 + preProcess(); + //执行节点命令或脚本 + handle(); + //执行后处理 + postProcess(); + //执行下一步节点 + setEndTime(SystemOperate.getCurrentTime()); + succeed(); + } + + + +} diff --git a/pbs/src/main/java/com/sdm/pbs/flow/CloudAppFlowNode.java b/pbs/src/main/java/com/sdm/pbs/flow/CloudAppFlowNode.java new file mode 100644 index 00000000..0126e9e1 --- /dev/null +++ b/pbs/src/main/java/com/sdm/pbs/flow/CloudAppFlowNode.java @@ -0,0 +1,40 @@ +package com.sdm.pbs.flow; + +import lombok.extern.slf4j.Slf4j; + +@Slf4j +public class CloudAppFlowNode extends AbstractFlowNode{ + public CloudAppFlowNode(FlowNodeBean nodeBean) + { + super(nodeBean); + nodeType = 3; + } + + @Override + public void preProcess() { + setNodeStatus(1); + //为流程新建工作空间 + } + + @Override + public void postProcess() { + + setNodeStatus(2); + } + + @Override + public void handle() { + log.info("流程开始"); + } + + @Override + public void succeed() { + if(nodeStatus == 2) + { + for(AbstractFlowNode flowNode : children) + { + flowNode.execute(); + } + } + } +} diff --git a/pbs/src/main/java/com/sdm/pbs/flow/ConditionFlowNode.java b/pbs/src/main/java/com/sdm/pbs/flow/ConditionFlowNode.java new file mode 100644 index 00000000..48b3ca8f --- /dev/null +++ b/pbs/src/main/java/com/sdm/pbs/flow/ConditionFlowNode.java @@ -0,0 +1,41 @@ +package com.sdm.pbs.flow; + +import lombok.extern.slf4j.Slf4j; + +@Slf4j +public class ConditionFlowNode extends AbstractFlowNode{ + public ConditionFlowNode(FlowNodeBean nodeBean) + { + super(nodeBean); + nodeType = 8; + } + + + @Override + public void preProcess() { + setNodeStatus(1); + //为流程新建工作空间 + } + + @Override + public void postProcess() { + + setNodeStatus(2); + } + + @Override + public void handle() { + log.info("流程开始"); + } + + @Override + public void succeed() { + if(nodeStatus == 2) + { + for(AbstractFlowNode flowNode : children) + { + flowNode.execute(); + } + } + } +} diff --git a/pbs/src/main/java/com/sdm/pbs/flow/EndFlowNode.java b/pbs/src/main/java/com/sdm/pbs/flow/EndFlowNode.java new file mode 100644 index 00000000..a10c7217 --- /dev/null +++ b/pbs/src/main/java/com/sdm/pbs/flow/EndFlowNode.java @@ -0,0 +1,44 @@ +package com.sdm.pbs.flow; + +import com.sdm.common.utils.SystemOperate; +import lombok.extern.slf4j.Slf4j; + +@Slf4j +public class EndFlowNode extends AbstractFlowNode{ + public EndFlowNode(FlowNodeBean nodeBean) + { + super(nodeBean); + nodeType = 9; + } + + + @Override + public void preProcess() { + setNodeStatus(1); + } + + @Override + public void postProcess() { + setNodeStatus(2); + } + + @Override + public void handle() { + log.info("流程结束"); + if(exeCmd != null && exeCmd.length() > 0) + { + try { + SystemOperate.exeShellCmd(exeCmd); + } + catch (Exception ex) + { + ex.printStackTrace(); + } + } + } + + @Override + public void succeed() { + + } +} diff --git a/pbs/src/main/java/com/sdm/pbs/flow/FlowNodeBean.java b/pbs/src/main/java/com/sdm/pbs/flow/FlowNodeBean.java new file mode 100644 index 00000000..61d340e7 --- /dev/null +++ b/pbs/src/main/java/com/sdm/pbs/flow/FlowNodeBean.java @@ -0,0 +1,25 @@ +package com.sdm.pbs.flow; + +import com.sdm.common.entity.bo.BaseBean; + + +public class FlowNodeBean extends BaseBean { + + public FlowNodeBean() + { + init(); + } + protected String nodeId; + protected String nodeName;//节点名称 + protected String workPath;//节点工作路径 + protected int nodeType;//节点类型 0:启动节点 1:配置节点 2:本地应用 3:云应用 4:执行节点 5:逻辑与 6:逻辑或 7:逻辑循环 8:条件节点 9:结束节点 + protected int nodeStatus;//节点状态 0:未执行 1:执行中 2:完成 3:失败 4:停止 + protected String flowId;//节点所属流程Id + protected String nodeParams;//节点参数 + protected String exeCmd;//节点执行命令 + protected String preProcessCmd;//前处理 + protected String postProcessCmd;//后处理 + protected String beginTime;//节点开始时间 + protected String endTime;//节点结束时间 + protected String description;//节点描述 +} diff --git a/pbs/src/main/java/com/sdm/pbs/flow/HpcFlowNode.java b/pbs/src/main/java/com/sdm/pbs/flow/HpcFlowNode.java new file mode 100644 index 00000000..bd3f4158 --- /dev/null +++ b/pbs/src/main/java/com/sdm/pbs/flow/HpcFlowNode.java @@ -0,0 +1,41 @@ +package com.sdm.pbs.flow; + +import lombok.extern.slf4j.Slf4j; + +@Slf4j +public class HpcFlowNode extends AbstractFlowNode{ + public HpcFlowNode(FlowNodeBean nodeBean) + { + super(nodeBean); + nodeType = 4; + } + + + @Override + public void preProcess() { + setNodeStatus(1); + //为流程新建工作空间 + } + + @Override + public void postProcess() { + + setNodeStatus(2); + } + + @Override + public void handle() { + log.info("流程开始"); + } + + @Override + public void succeed() { + if(nodeStatus == 2) + { + for(AbstractFlowNode flowNode : children) + { + flowNode.execute(); + } + } + } +} diff --git a/pbs/src/main/java/com/sdm/pbs/flow/IFlowNode.java b/pbs/src/main/java/com/sdm/pbs/flow/IFlowNode.java new file mode 100644 index 00000000..307e0ce4 --- /dev/null +++ b/pbs/src/main/java/com/sdm/pbs/flow/IFlowNode.java @@ -0,0 +1,44 @@ +package com.sdm.pbs.flow; + +public interface IFlowNode { + + String getNodeName(); + + String getFlowId(); + + int getNodeType(); + + int getNodeStatus(); + + int setNodeStatus(int status); + + void stop(); + + void start(); + + String getNodeParams(); + + void setNodeParams(String params); + + void setNodeExeCmd(String cmd); + + String getNodeExeCmd(); + + void execute(); + + void preProcess(); + + void postProcess(); + + void handle(); + + void succeed(); + + String getBeginTime(); + + void setBeginTime(String beginTime); + + String getEndTime(); + + void setEndTime(String endTime); +} diff --git a/pbs/src/main/java/com/sdm/pbs/flow/LocalAppFlowNode.java b/pbs/src/main/java/com/sdm/pbs/flow/LocalAppFlowNode.java new file mode 100644 index 00000000..9b0232eb --- /dev/null +++ b/pbs/src/main/java/com/sdm/pbs/flow/LocalAppFlowNode.java @@ -0,0 +1,41 @@ +package com.sdm.pbs.flow; + +import lombok.extern.slf4j.Slf4j; + +@Slf4j +public class LocalAppFlowNode extends AbstractFlowNode{ + public LocalAppFlowNode(FlowNodeBean nodeBean) + { + super(nodeBean); + nodeType = 2; + } + + + @Override + public void preProcess() { + setNodeStatus(1); + //为流程新建工作空间 + } + + @Override + public void postProcess() { + + setNodeStatus(2); + } + + @Override + public void handle() { + log.info("流程开始"); + } + + @Override + public void succeed() { + if(nodeStatus == 2) + { + for(AbstractFlowNode flowNode : children) + { + flowNode.execute(); + } + } + } +} diff --git a/pbs/src/main/java/com/sdm/pbs/flow/LogicAndFlowNode.java b/pbs/src/main/java/com/sdm/pbs/flow/LogicAndFlowNode.java new file mode 100644 index 00000000..134ee866 --- /dev/null +++ b/pbs/src/main/java/com/sdm/pbs/flow/LogicAndFlowNode.java @@ -0,0 +1,41 @@ +package com.sdm.pbs.flow; + +import lombok.extern.slf4j.Slf4j; + +@Slf4j +public class LogicAndFlowNode extends AbstractFlowNode{ + public LogicAndFlowNode(FlowNodeBean nodeBean) + { + super(nodeBean); + nodeType = 5; + } + + + @Override + public void preProcess() { + setNodeStatus(1); + //为流程新建工作空间 + } + + @Override + public void postProcess() { + + setNodeStatus(2); + } + + @Override + public void handle() { + log.info("流程开始"); + } + + @Override + public void succeed() { + if(nodeStatus == 2) + { + for(AbstractFlowNode flowNode : children) + { + flowNode.execute(); + } + } + } +} diff --git a/pbs/src/main/java/com/sdm/pbs/flow/LogicOrFlowNode.java b/pbs/src/main/java/com/sdm/pbs/flow/LogicOrFlowNode.java new file mode 100644 index 00000000..ec9a1760 --- /dev/null +++ b/pbs/src/main/java/com/sdm/pbs/flow/LogicOrFlowNode.java @@ -0,0 +1,41 @@ +package com.sdm.pbs.flow; + +import lombok.extern.slf4j.Slf4j; + +@Slf4j +public class LogicOrFlowNode extends AbstractFlowNode{ + public LogicOrFlowNode(FlowNodeBean nodeBean) + { + super(nodeBean); + nodeType = 6; + } + + + @Override + public void preProcess() { + setNodeStatus(1); + //为流程新建工作空间 + } + + @Override + public void postProcess() { + + setNodeStatus(2); + } + + @Override + public void handle() { + log.info("流程开始"); + } + + @Override + public void succeed() { + if(nodeStatus == 2) + { + for(AbstractFlowNode flowNode : children) + { + flowNode.execute(); + } + } + } +} diff --git a/pbs/src/main/java/com/sdm/pbs/flow/LoopFlowNode.java b/pbs/src/main/java/com/sdm/pbs/flow/LoopFlowNode.java new file mode 100644 index 00000000..6f641222 --- /dev/null +++ b/pbs/src/main/java/com/sdm/pbs/flow/LoopFlowNode.java @@ -0,0 +1,42 @@ +package com.sdm.pbs.flow; + +import lombok.extern.slf4j.Slf4j; + +@Slf4j +public class LoopFlowNode extends AbstractFlowNode{ + + public LoopFlowNode(FlowNodeBean nodeBean) + { + super(nodeBean); + nodeType = 7; + } + + + @Override + public void preProcess() { + setNodeStatus(1); + //为流程新建工作空间 + } + + @Override + public void postProcess() { + + setNodeStatus(2); + } + + @Override + public void handle() { + + } + + @Override + public void succeed() { + if(nodeStatus == 2) + { + for(AbstractFlowNode flowNode : children) + { + flowNode.execute(); + } + } + } +} diff --git a/pbs/src/main/java/com/sdm/pbs/flow/StartFlowNode.java b/pbs/src/main/java/com/sdm/pbs/flow/StartFlowNode.java new file mode 100644 index 00000000..c7c11124 --- /dev/null +++ b/pbs/src/main/java/com/sdm/pbs/flow/StartFlowNode.java @@ -0,0 +1,41 @@ +package com.sdm.pbs.flow; + +import lombok.extern.slf4j.Slf4j; + +@Slf4j +public class StartFlowNode extends AbstractFlowNode{ + public StartFlowNode(FlowNodeBean nodeBean) + { + super(nodeBean); + nodeType = 0; + } + + + @Override + public void preProcess() { + setNodeStatus(1); + //为流程新建工作空间 + } + + @Override + public void postProcess() { + + setNodeStatus(2); + } + + @Override + public void handle() { + log.info("流程开始"); + } + + @Override + public void succeed() { + if(nodeStatus == 2) + { + for(AbstractFlowNode flowNode : children) + { + flowNode.execute(); + } + } + } +} diff --git a/pbs/src/main/java/com/sdm/pbs/model/entity/SimulationFlowInstance.java b/pbs/src/main/java/com/sdm/pbs/model/entity/SimulationFlowInstance.java new file mode 100644 index 00000000..ca5309b8 --- /dev/null +++ b/pbs/src/main/java/com/sdm/pbs/model/entity/SimulationFlowInstance.java @@ -0,0 +1,45 @@ +package com.sdm.pbs.model.entity; + +import com.sdm.common.entity.bo.BaseBean; + +public class SimulationFlowInstance extends BaseBean { + + public SimulationFlowInstance(){ + init(); + } + public int id; + + public String uuid; //流程实例唯一ID + + public String flowName; //流程实例名称 + + public String nodeId; //流程实例所属节点UUID + + public String nodeName; //流程实例所属节点名称 + + public String taskId; //流程实例所属任务UUID + + public String taskName; //流程实例所属任务名称 + + public String runId; //流程实例所属Run UUID + + public String runName; //流程实例所属Run名称 + + public int flowStatus; //流程实例状态 0:未开始 1:进行中 2:已完成 3:失败 4:停止 + + public String workPath; //流程实例工作路径 + + public String currentPhase; //流程实例当前阶段 + + public String planEndTime; //路程实例计划完成时间 + + public String beginTime; //流程实例开始时间 + + public String endTime; //流程实例结束时间 + + public String tenantId; //租户ID + + public String creator; //实例创建者 + + public String createTime; //实例创建时间 +} diff --git a/pbs/src/main/java/com/sdm/pbs/model/entity/SimulationFlowMember.java b/pbs/src/main/java/com/sdm/pbs/model/entity/SimulationFlowMember.java new file mode 100644 index 00000000..49f373da --- /dev/null +++ b/pbs/src/main/java/com/sdm/pbs/model/entity/SimulationFlowMember.java @@ -0,0 +1,26 @@ +package com.sdm.pbs.model.entity; + +import com.sdm.common.entity.bo.BaseBean; + +public class SimulationFlowMember extends BaseBean { + + public SimulationFlowMember() { + init(); + } + + public int id; + + public String flowId; //流程UUID + + public String flowName; //流程名称 + + public String memberName; //成员名称 + + public String memberId; //成员ID + + public int role; //成员在流程中的角色 + + public String creator; //创建者 + + public String createTime; //创建时间 +} diff --git a/pbs/src/main/java/com/sdm/pbs/model/entity/SimulationFlowNode.java b/pbs/src/main/java/com/sdm/pbs/model/entity/SimulationFlowNode.java new file mode 100644 index 00000000..3e392d9f --- /dev/null +++ b/pbs/src/main/java/com/sdm/pbs/model/entity/SimulationFlowNode.java @@ -0,0 +1,45 @@ +package com.sdm.pbs.model.entity; + +import com.sdm.common.entity.bo.BaseBean; + +public class SimulationFlowNode extends BaseBean { + + public SimulationFlowNode(){ + init(); + } + + public int id; + + public String uuid; //节点唯一ID + + public String nodeName; //节点名称 + + public String parentId; //所属父节点UUID + + public String flowId; //所属流程UUID + + public String flowName; //所属流程名称 + + public String templateId; //所属模版UUID + + public String templateName; //所属模版名称 + + public int nodeType; //节点类型 + + public String workPath; //节点工作路径 + + public String exeCmd; //节点执行命令 + + public String preProcessCmd; //节点前处理命令 + + public String postProcessCmd; //节点后处理命令 + + public int nodeStatus; //节点状态 0:未开始 1:进行中 2:已完成 3:失败 4:停止 + + public String nodeParam; //节点参数 + + public String beginTime; //节点开始时间 + + public String endTime; //节点结束时间 + +} diff --git a/pbs/src/main/java/com/sdm/pbs/model/entity/SimulationFlowTemplate.java b/pbs/src/main/java/com/sdm/pbs/model/entity/SimulationFlowTemplate.java new file mode 100644 index 00000000..cb632d7d --- /dev/null +++ b/pbs/src/main/java/com/sdm/pbs/model/entity/SimulationFlowTemplate.java @@ -0,0 +1,33 @@ +package com.sdm.pbs.model.entity; + +import com.sdm.common.entity.bo.BaseBean; + +public class SimulationFlowTemplate extends BaseBean { + + public SimulationFlowTemplate() { + init(); + } + public int id; + + public String uuid; //流程模版唯一ID + + public String templateName; //流程模版名称 + + public String version; //流程模版版本号 + + public String template; //流程模版内容 + + public int templateStatus; //流程模版状态 0: 禁用 1:启用 + + public int approveStatus; //流程模版评审状态 0:未评审 1:已评审 + + public int templateType; //流程模版类型 + + public String comment; //流程模版描述信息 + + public String tenantId; //租户ID + + public String creator; //模版创建者 + + public String createTime; //模版创建时间 +} diff --git a/system/src/main/java/com/sdm/grpc/server/CidApproveFlowServer.java b/system/src/main/java/com/sdm/grpc/server/CidApproveFlowServer.java new file mode 100644 index 00000000..fb84adee --- /dev/null +++ b/system/src/main/java/com/sdm/grpc/server/CidApproveFlowServer.java @@ -0,0 +1,39 @@ +package com.sdm.grpc.server; + +import com.sdm.common.common.SdmResponse; +import com.sdm.grpc.lib.ApproveFlowReply; +import com.sdm.grpc.lib.ApproveFlowRequest; +import com.sdm.grpc.lib.ApproveFlowServiceGrpc; +import com.sdm.system.service.ISimulatinoApprovalService; +import com.sdm.system.service.impl.SimulationApproveServiceImpl; +import io.grpc.stub.StreamObserver; +import lombok.extern.slf4j.Slf4j; +import net.devh.boot.grpc.server.service.GrpcService; +import org.springframework.beans.factory.annotation.Autowired; +import org.springframework.context.ApplicationContext; + +@Slf4j +@GrpcService +public class CidApproveFlowServer extends ApproveFlowServiceGrpc.ApproveFlowServiceImplBase{ + + public CidApproveFlowServer(){ + log.info("CidApproveFlowServer init"); + } + @Autowired + ISimulatinoApprovalService approvalService ; + @Override + public void launchApproveFlow(ApproveFlowRequest request, StreamObserver responseObserver) { + String approveTitle = request.getApproveTitle(); + int innerFlowId = request.getInnerFlowId(); + String comment = request.getComment(); + int approveType = request.getApproveType(); + String tenantId = request.getTenantId(); + String user = request.getUser(); + String replayUrl = request.getReplayUrl(); + + + + //responseObserver.onNext(reply.build()); + //responseObserver.onCompleted(); + } +} diff --git a/system/src/main/java/com/sdm/grpc/server/ReceiveCidApproveFlowNoticeService.java b/system/src/main/java/com/sdm/grpc/server/ReceiveCidApproveFlowNoticeService.java new file mode 100644 index 00000000..ef954571 --- /dev/null +++ b/system/src/main/java/com/sdm/grpc/server/ReceiveCidApproveFlowNoticeService.java @@ -0,0 +1,20 @@ +package com.sdm.grpc.server; + +import com.sdm.grpc.lib.ApproveFlowServiceGrpc; +import com.sdm.grpc.lib.ApproveNoticeReply; +import com.sdm.grpc.lib.ApproveResultRequest; +import io.grpc.stub.StreamObserver; +import net.devh.boot.grpc.server.service.GrpcService; + +public class ReceiveCidApproveFlowNoticeService{// extends ApproveFlowServiceGrpc.ApproveFlowServiceImplBase { + //@Override + public void approveFlowResultNotice(ApproveResultRequest request, StreamObserver responseObserver) { + int approveStatus = request.getApproveStatus(); + int innerApproveId = request.getInnerFlowId(); + /******* ToDo ********/ + /*********************/ + ApproveNoticeReply.Builder reply = ApproveNoticeReply.newBuilder(); + reply.setInnerFlowId(innerApproveId); + reply.setSuccess(true); + } +} diff --git a/system/src/main/java/com/sdm/system/controller/SystemApproveController.java b/system/src/main/java/com/sdm/system/controller/SystemApproveController.java index 6cfc9a44..97ee0e3e 100644 --- a/system/src/main/java/com/sdm/system/controller/SystemApproveController.java +++ b/system/src/main/java/com/sdm/system/controller/SystemApproveController.java @@ -4,7 +4,6 @@ import com.sdm.common.common.SdmResponse; import com.sdm.system.model.entity.ApproveFlowBean; import com.sdm.system.service.ISimulatinoApprovalService; import io.swagger.v3.oas.annotations.tags.Tag; -import org.apache.ibatis.annotations.Param; import org.springframework.beans.factory.annotation.Autowired; import org.springframework.web.bind.annotation.*; @@ -26,7 +25,7 @@ public class SystemApproveController { @PostMapping("/launchApprove") public SdmResponse launchApproval(@RequestBody ApproveFlowBean flowBean){ - return approveServer.launchApproval(flowBean.approveTitle,flowBean.approveType,flowBean.innerFlowId,flowBean.comment); + return approveServer.launchApproval(flowBean.approveTitle,flowBean.templateName,flowBean.templateId,flowBean.approveType,flowBean.innerFlowId,flowBean.comment,flowBean.replyUrl); } /** @@ -39,11 +38,26 @@ public class SystemApproveController { return approveServer.receiveApprovalResult(flowBean.cidFlowId,flowBean.approveStatus); } - /*@PostMapping("/stopApprove") - public SdmResponse stopApproval(@Param("flowId") String flowId, @Param("userId") String userId) { - approveServer.stopCidApprovalFlow(flowId,userId); + @GetMapping("queryApproveFlowStatus") + public SdmResponse queryApproveFlowStatus(@RequestParam("flowId") String flowId) { + return approveServer.queryApproveFlowStatus(flowId); + } + + @PostMapping("/stopApprove") + public SdmResponse stopApproval(@RequestParam ("flowId") String flowId) { + return approveServer.stopCidApprovalFlow(flowId); + } + + @PostMapping("/approveInnerNotice") + public SdmResponse systemApproveInnerNotice(@RequestBody ApproveFlowBean flowBean) { return SdmResponse.success(); - }*/ + } + + @GetMapping("/queryApproveFlowTempalte") + public SdmResponse queryApproveFlowTemplate() + { + return approveServer.queryApprovalTemplates(); + } diff --git a/system/src/main/java/com/sdm/system/dao/SimulationApproveMapper.java b/system/src/main/java/com/sdm/system/dao/SimulationApproveMapper.java index f79d4256..f822825e 100644 --- a/system/src/main/java/com/sdm/system/dao/SimulationApproveMapper.java +++ b/system/src/main/java/com/sdm/system/dao/SimulationApproveMapper.java @@ -13,12 +13,15 @@ import java.util.List; public interface SimulationApproveMapper { - @Insert("INSERT INTO simulation_approve_flow(innerFlowId,cidFlowId,approveTitle,approveStatus,approveType,comment,creator) VALUES (#{flowBean.innerFlowId},#{flowBean.cidFlowId},#{flowBean.approveTitle},#{flowBean.approveStatus},#{flowBean.approveType},#{flowBean.comment},#{flowBean.creator})") + @Insert("INSERT INTO simulation_approve_flow(innerFlowId,cidFlowId,templateName,templateId,approveTitle,approveStatus,approveType,comment,tenantId,userId,replyUrl,creator) VALUES (#{flowBean.innerFlowId},#{flowBean.cidFlowId},#{flowBean.templateName},#{flowBean.templateId},#{flowBean.approveTitle},#{flowBean.approveStatus},#{flowBean.approveType},#{flowBean.comment},#{flowBean.tenantId},#{flowBean.userId},#{flowBean.replyUrl},#{flowBean.creator})") int addSimulationApproveFlow(@Param("flowBean") ApproveFlowBean flowBean); @Update("UPDATE simulation_approve_flow SET approveStatus=#{status} WHERE cidFlowId=#{cidFlowId}") int updateSimulationApproveFlowStatus(@Param("cidFlowId") String cidFlowId,@Param("status") int status); + @Update("UPDATE simulation_approve_flow SET replyStatus=#{replyStatus} WHERE cidFlowid=#{cidFlowId}") + int updateSimulationApproveFlowReplyStatus(@Param("cidFlowId") String cidFlowId,@Param("replyStatus") int replyStatus); + @Select("SELECT * FROM simulation_approve_flow WHERE innerFlowId=#{flowId}") ApproveFlowBean querySimulationApproveFlowByInnerFlowId(@Param("flowId") int flowId); diff --git a/system/src/main/java/com/sdm/system/model/entity/ApproveFlowBean.java b/system/src/main/java/com/sdm/system/model/entity/ApproveFlowBean.java index 6b9ad19a..4cafde30 100644 --- a/system/src/main/java/com/sdm/system/model/entity/ApproveFlowBean.java +++ b/system/src/main/java/com/sdm/system/model/entity/ApproveFlowBean.java @@ -21,6 +21,18 @@ public class ApproveFlowBean extends BaseBean { public String comment; //审批描述 + public long tenantId; //租户ID + + public String replyUrl; //审批回复URL + + public String templateName; //模版名称 + + public String templateId; //评审流程模版ID + + public int replyStatus; //审批回复状态 0:未回复 1:已回复 + + public long userId; //用户ID + public String creator; //审批创建者 public String createTime; //审批创建时间 diff --git a/system/src/main/java/com/sdm/system/model/entity/ApproveTemplateBean.java b/system/src/main/java/com/sdm/system/model/entity/ApproveTemplateBean.java new file mode 100644 index 00000000..79c29edf --- /dev/null +++ b/system/src/main/java/com/sdm/system/model/entity/ApproveTemplateBean.java @@ -0,0 +1,6 @@ +package com.sdm.system.model.entity; + +public class ApproveTemplateBean { + public String templateId; + public String templateName; +} diff --git a/system/src/main/java/com/sdm/system/service/ISimulatinoApprovalService.java b/system/src/main/java/com/sdm/system/service/ISimulatinoApprovalService.java index a430a899..6c93fd6b 100644 --- a/system/src/main/java/com/sdm/system/service/ISimulatinoApprovalService.java +++ b/system/src/main/java/com/sdm/system/service/ISimulatinoApprovalService.java @@ -2,9 +2,6 @@ package com.sdm.system.service; import com.sdm.common.common.SdmResponse; -import com.sdm.common.utils.SystemOperate; -import com.sdm.system.model.entity.AppCenterItemBean; -import com.sdm.system.model.entity.AppConfigureBean; import com.sdm.system.model.entity.ApproveFlowBean; /** @@ -18,14 +15,16 @@ import com.sdm.system.model.entity.ApproveFlowBean; public interface ISimulatinoApprovalService { - SdmResponse queryApprovalTemplates(String group,String tenantId); + SdmResponse queryApprovalTemplates(); - boolean stopCidApprovalFlow(String flowId,String userId,String url); + SdmResponse stopCidApprovalFlow(String flowId); - SdmResponse launchApproval(String approveTitle,int approveType,int innerFlowId,String comment); + SdmResponse launchApproval(String approveTitle,String templateName,String templateId,int approveType,int innerFlowId,String comment,String replayUrl); SdmResponse receiveApprovalResult(String cidFlowId,int status); SdmResponse approvalResultNotice(ApproveFlowBean flowBean); + SdmResponse queryApproveFlowStatus(String flowId); + } diff --git a/system/src/main/java/com/sdm/system/service/impl/SimulationApproveServiceImpl.java b/system/src/main/java/com/sdm/system/service/impl/SimulationApproveServiceImpl.java index a0c65930..899dbbcd 100644 --- a/system/src/main/java/com/sdm/system/service/impl/SimulationApproveServiceImpl.java +++ b/system/src/main/java/com/sdm/system/service/impl/SimulationApproveServiceImpl.java @@ -1,17 +1,24 @@ package com.sdm.system.service.impl; +import com.alibaba.fastjson2.JSONArray; import com.alibaba.fastjson2.JSONObject; import com.sdm.common.common.SdmResponse; +import com.sdm.common.common.ThreadLocalContext; import com.sdm.common.utils.HttpClientUtil; import com.sdm.system.dao.SimulationApproveMapper; import com.sdm.system.model.entity.ApproveConfigBean; import com.sdm.system.model.entity.ApproveFlowBean; +import com.sdm.system.model.entity.ApproveTemplateBean; import com.sdm.system.service.ISimulatinoApprovalService; import lombok.extern.slf4j.Slf4j; import org.springframework.beans.factory.annotation.Autowired; +import org.springframework.beans.factory.annotation.Value; import org.springframework.stereotype.Service; -import java.util.HashMap; -import java.util.Map; + +import java.io.IOException; +import java.util.ArrayList; +import java.util.List; + @Slf4j @Service @@ -20,12 +27,27 @@ public class SimulationApproveServiceImpl implements ISimulatinoApprovalService @Autowired private HttpClientUtil httpClientUtil; + @Autowired private SimulationApproveMapper approveMapper; - @Override - public SdmResponse queryApprovalTemplates(String group, String tenantId) { - return null; - } + + @Value("${cid.url}") + private String cidUrl; + + @Value("${cid.flow.queryFlowTemplate}") + private String queryFlowTemplatePath; + + @Value("${cid.flow.launchApprove}") + private String launchApprovePath; + + @Value("${cid.flow.queryApproveDetail}") + private String queryFlowDetailPath; + + @Value("${cid.flow.stopApproveFlow}") + private String stopFlowPath; + + @Value("${cid.flow.group}") + private String groupName; /** * 向CID发起审批流程 @@ -33,7 +55,7 @@ public class SimulationApproveServiceImpl implements ISimulatinoApprovalService * @param userId * @return string 返回审批流ID */ - private String launchCidApprovalFlow(String flowId,String userId,String tenantId,String url) + private String launchCidApprovalFlow(String flowId,long userId,long tenantId,String url) { JSONObject paramJson = new JSONObject(); paramJson.put("flowId",flowId); @@ -41,7 +63,7 @@ public class SimulationApproveServiceImpl implements ISimulatinoApprovalService paramJson.put("tenantId",tenantId); String cidFlowId = ""; try { - String resultString = httpClientUtil.doPostJson(url+"/startFlow", paramJson.toJSONString()); + String resultString = httpClientUtil.doPostJson(url, paramJson.toJSONString()); if (resultString != null && !resultString.isEmpty()) { JSONObject resultJson = JSONObject.parseObject(resultString); if (resultJson != null && resultJson.containsKey("success")) { @@ -60,22 +82,59 @@ public class SimulationApproveServiceImpl implements ISimulatinoApprovalService } /** - * 停止cid评审流程 + * 获取Cid评审流程状态 * @param flowId - * @param userId + * @param tenantId * @return */ - public boolean stopCidApprovalFlow(String flowId,String userId,String url) + private JSONArray queryCidApproveFlowStatus(String flowId, String templateId, long tenantId, String url) { JSONObject paramJson = new JSONObject(); + paramJson.put("flowId",templateId); paramJson.put("processInstanceId",flowId); - paramJson.put("userId",userId); + paramJson.put("tenantId",tenantId); + JSONArray array = null; try { - String resultString = httpClientUtil.doPostJson(url+"/stopFlow", paramJson.toJSONString()); + String resultString = httpClientUtil.doPostJson(url, paramJson.toJSONString()); if (resultString != null && !resultString.isEmpty()) { JSONObject resultJson = JSONObject.parseObject(resultString); if (resultJson != null && resultJson.containsKey("success")) { - return resultJson.getBoolean("success"); + boolean success = resultJson.getBoolean("success"); + if (success) { + array = resultJson.getJSONArray("data"); + } + } + } + } + catch (Exception e) + { + e.printStackTrace(); + } + return array; + } + + /** + * 停止CID评审流程 + * @param cidFlowId + * @param userId + * @return + */ + private boolean stopCidApprovalFlow(String cidFlowId,long userId) + { + JSONObject paramJson = new JSONObject(); + paramJson.put("processInstanceId", cidFlowId); + paramJson.put("userId", userId); + try + { + String url = cidUrl + stopFlowPath; + String resultString = httpClientUtil.doPostJson(url, paramJson.toJSONString()); + if (resultString != null && !resultString.isEmpty()) { + JSONObject resultJson = JSONObject.parseObject(resultString); + if (resultJson != null && resultJson.containsKey("success")) { + if(resultJson.getBoolean("success")) + { + return true; + } } } } @@ -86,6 +145,40 @@ public class SimulationApproveServiceImpl implements ISimulatinoApprovalService return false; } + /** + * 停止cid评审流程 + * @param flowId + * @return + */ + public SdmResponse stopCidApprovalFlow(String flowId) + { + SdmResponse response = SdmResponse.success(); + ApproveFlowBean flowBean = approveMapper.querySimulationApproveFlowByCidFlowId(flowId); + if (flowBean == null) { + response = SdmResponse.failed("评审流程不存在"); + } + else { + JSONObject paramJson = new JSONObject(); + paramJson.put("processInstanceId", flowBean.cidFlowId); + paramJson.put("userId", flowBean.creator); + try + { + String url = cidUrl+stopFlowPath; + String resultString = httpClientUtil.doPostJson(url, paramJson.toJSONString()); + if (resultString != null && !resultString.isEmpty()) { + JSONObject resultJson = JSONObject.parseObject(resultString); + if (resultJson == null || !resultJson.containsKey("success")) { + response = SdmResponse.failed("停止评审失败"); + } + } + + } catch (Exception e) { + e.printStackTrace(); + } + } + return response; + } + /** * 发起审批流 @@ -96,15 +189,16 @@ public class SimulationApproveServiceImpl implements ISimulatinoApprovalService * @return */ @Override - public SdmResponse launchApproval(String approveTitle, int approveType, int approveId,String comment) { + public SdmResponse launchApproval(String approveTitle,String templateName,String templateId, int approveType, int approveId,String comment,String replayUrl) { + SdmResponse sdmResponse = SdmResponse.success(); - ApproveConfigBean configBean = approveMapper.querySimulationApproveConfig(approveType); - if(configBean == null){ - sdmResponse = SdmResponse.failed("评审配置信息不存在"); - return sdmResponse; - } - String cidFlowId = launchCidApprovalFlow(configBean.cidFlowTemplate, "1979078323595476993","1979091834410176514",configBean.url); + long userId = ThreadLocalContext.getUserId(); + long tenantId = ThreadLocalContext.getTenantId(); + String userName = ThreadLocalContext.getUserName(); + String url = cidUrl+launchApprovePath; + + String cidFlowId = launchCidApprovalFlow(templateId, userId,tenantId,url); if (cidFlowId.isEmpty()) { sdmResponse = SdmResponse.failed("发起Cid审批流程失败"); } else { @@ -114,9 +208,16 @@ public class SimulationApproveServiceImpl implements ISimulatinoApprovalService approveFlowBean.approveType = approveType; approveFlowBean.comment = comment; approveFlowBean.innerFlowId = approveId; + approveFlowBean.creator = userName; + approveFlowBean.tenantId = tenantId; + approveFlowBean.replyUrl = replayUrl; + approveFlowBean.userId = userId; + approveFlowBean.creator = userName; + approveFlowBean.templateId = templateId; + approveFlowBean.templateName = templateName; if (approveMapper.addSimulationApproveFlow(approveFlowBean) <= 0) { sdmResponse = SdmResponse.failed("保存审批流程失败"); - if(!stopCidApprovalFlow(cidFlowId,"1979078323595476993",configBean.url)) + if(!stopCidApprovalFlow(cidFlowId,userId)) { log.error("删除CID审批流["+cidFlowId+"]失败"); } @@ -129,6 +230,33 @@ public class SimulationApproveServiceImpl implements ISimulatinoApprovalService return sdmResponse; } + /** + * 查询当前评审流程的状态详情 + * @param flowId + * @return + */ + @Override + public SdmResponse queryApproveFlowStatus( String flowId) + { + SdmResponse sdmResponse = SdmResponse.success(); + ApproveFlowBean flowBean = approveMapper.querySimulationApproveFlowByCidFlowId(flowId); + if(flowBean == null){ + sdmResponse = SdmResponse.failed("评审流程不存在"); + } + else + { + String url = cidUrl+queryFlowDetailPath; + JSONArray array = queryCidApproveFlowStatus(flowBean.cidFlowId, flowBean.templateId,flowBean.tenantId,url); + if(array != null){ + sdmResponse.setData(array); + } + else{ + sdmResponse = SdmResponse.failed("获取评审流程状态信息失败"); + } + } + return sdmResponse; + } + /** * 接收CID审批流状态 * @param cidFlowId @@ -153,7 +281,10 @@ public class SimulationApproveServiceImpl implements ISimulatinoApprovalService else { if(status > 1) { //评审结束后通知评审发起模块 - approvalResultNotice(flowBean); + if(approvalResultNotice(flowBean).isSuccess()) + { + approveMapper.updateSimulationApproveFlowReplyStatus(cidFlowId,1); + } } } } @@ -167,8 +298,69 @@ public class SimulationApproveServiceImpl implements ISimulatinoApprovalService */ @Override public SdmResponse approvalResultNotice(ApproveFlowBean flowBean) { - return null; + SdmResponse sdmResponse = SdmResponse.success(); + JSONObject param = new JSONObject(); + param.put("flowId", flowBean.innerFlowId); + param.put("approveType", flowBean.approveType); + try { + String result = httpClientUtil.doPostJson(flowBean.replyUrl, param.toJSONString()); + if(result == null) { + sdmResponse = SdmResponse.failed("发送评审状态通知失败"); + } + else + { + JSONObject resultJson = JSONObject.parseObject(result); + if(!resultJson.containsKey("success")) { + sdmResponse = SdmResponse.failed(); + } + } + } + catch (Exception e) { + e.printStackTrace(); + } + return sdmResponse; } - + /** + * 查询评审流程模版 + * @return + */ + @Override + public SdmResponse queryApprovalTemplates() + { + SdmResponse sdmResponse = SdmResponse.success(); + long tenantId = ThreadLocalContext.getTenantId(); + String url = cidUrl+queryFlowTemplatePath+"?groupName="+groupName+"&tenantId="+tenantId; + try + { + String result = httpClientUtil.doGet(url); + if(result == null) { + sdmResponse = SdmResponse.failed("获取评审流程模版失败"); + } + else { + JSONObject resultJson = JSONObject.parseObject(result); + if(!resultJson.containsKey("success")) { + sdmResponse = SdmResponse.failed(); + } + else + { + List templateBeanList = new ArrayList<>(); + JSONArray dataArray = resultJson.getJSONArray("data"); + for(int i=0;i