Commit 7c5ad90b by tiger

记录节点执行次数

1 parent b40620a7
package cn.com.glsx.process.modules.entity; package cn.com.glsx.process.modules.entity;
import javax.persistence.*; import javax.persistence.Column;
import javax.persistence.Id;
import javax.persistence.Table;
@Table(name = "sop_tpl_node") @Table(name = "sop_tpl_node")
public class SopTplNode { public class SopTplNode {
...@@ -95,6 +97,18 @@ public class SopTplNode { ...@@ -95,6 +97,18 @@ public class SopTplNode {
@Column(name = "node_async") @Column(name = "node_async")
private Byte nodeAsync; private Byte nodeAsync;
/**
* 节点状态:0,停用;1,启用;
*/
@Column(name = "node_status")
private Integer nodeStatus;
/**
* 每日执行次数限制,0表示不限制。
*/
@Column(name = "daily_limit")
private Integer dailyLimit;
/** /**
* 获取节点id * 获取节点id
* *
...@@ -354,4 +368,21 @@ public class SopTplNode { ...@@ -354,4 +368,21 @@ public class SopTplNode {
public void setNodeAsync(Byte nodeAsync) { public void setNodeAsync(Byte nodeAsync) {
this.nodeAsync = nodeAsync; this.nodeAsync = nodeAsync;
} }
public Integer getNodeStatus() {
return nodeStatus;
}
public void setNodeStatus(Integer nodeStatus) {
this.nodeStatus = nodeStatus;
}
public Integer getDailyLimit() {
return dailyLimit;
}
public void setDailyLimit(Integer dailyLimit) {
this.dailyLimit = dailyLimit;
}
} }
\ No newline at end of file \ No newline at end of file
package cn.com.glsx.process.modules.mapper; package cn.com.glsx.process.modules.mapper;
import cn.com.glsx.process.modules.entity.SopInstNode; import java.util.List;
import com.glsx.plat.mybatis.mapper.CommonBaseMapper;
import org.apache.ibatis.annotations.Mapper; import org.apache.ibatis.annotations.Mapper;
import org.apache.ibatis.annotations.Param; import org.apache.ibatis.annotations.Param;
import java.util.List; import com.glsx.plat.mybatis.mapper.CommonBaseMapper;
import cn.com.glsx.process.modules.entity.SopInstNode;
@Mapper @Mapper
public interface SopInstNodeMapper extends CommonBaseMapper<SopInstNode> { public interface SopInstNodeMapper extends CommonBaseMapper<SopInstNode> {
List<SopInstNode> findByInstId(@Param("instId") String instId); List<SopInstNode> findByInstId(@Param("instId") String instId);
int resetInstNodeDailyCount(@Param("instId") String instId);
} }
\ No newline at end of file \ No newline at end of file
...@@ -34,6 +34,9 @@ public class SopInstExecuteJobHandler { ...@@ -34,6 +34,9 @@ public class SopInstExecuteJobHandler {
SopInstBatch batch = sopService.createBatch(sop.getInst()); SopInstBatch batch = sopService.createBatch(sop.getInst());
sop.setBatch(batch); sop.setBatch(batch);
// 重置节点执行次数
sopService.resetNodeDailyCount(sop);
// 创建所有节点任务 // 创建所有节点任务
SopXxlJobUtil.initSopNodesJob(sop); SopXxlJobUtil.initSopNodesJob(sop);
} }
......
...@@ -25,6 +25,7 @@ import cn.com.glsx.process.modules.sop.execute.SopNodeExecutorFactory; ...@@ -25,6 +25,7 @@ import cn.com.glsx.process.modules.sop.execute.SopNodeExecutorFactory;
import cn.com.glsx.process.modules.sop.execute.SopNodeType; import cn.com.glsx.process.modules.sop.execute.SopNodeType;
import cn.com.glsx.process.util.JacksonUtils; import cn.com.glsx.process.util.JacksonUtils;
import cn.hutool.core.lang.Pair; import cn.hutool.core.lang.Pair;
import cn.hutool.core.util.ObjectUtil;
import cn.hutool.json.JSONUtil; import cn.hutool.json.JSONUtil;
import lombok.extern.slf4j.Slf4j; import lombok.extern.slf4j.Slf4j;
...@@ -111,18 +112,22 @@ public class SopInstNodeExecuteJobHandler { ...@@ -111,18 +112,22 @@ public class SopInstNodeExecuteJobHandler {
if (node.getNodeSkip() != 1) { if (node.getNodeSkip() != 1) {
// 重新加载sop // 重新加载sop
sop = reloadAndCreateNodeBatch(sop, node); sop = reloadAndCreateNodeBatch(sop, node);
node = sop.getInstNodeMap().get(node.getNodeId());
// 预备执行参数 // 没超执行次数限制
SnapshotStruct snapshotStruct = instance.prepare(sop, node); if (node.getDailyLimit() == 0 || node.getDailyCount() < node.getDailyLimit()) {
// 预备执行参数
SnapshotStruct snapshotStruct = instance.prepare(sop, node);
// 执行sop节点 // 执行sop节点
Object result = instance.execute(sop, node, snapshotStruct); Object result = instance.execute(sop, node, snapshotStruct);
// 处理执行结果 // 处理执行结果
snapshotStruct = instance.handleResult(sop, node, snapshotStruct, result); snapshotStruct = instance.handleResult(sop, node, snapshotStruct, result);
// 保存快照 // 保存快照
updateBatch(sop, node, snapshotStruct); updateBatch(sop, node, snapshotStruct);
}
} }
// 更新后续节点状态 // 更新后续节点状态
...@@ -149,6 +154,7 @@ public class SopInstNodeExecuteJobHandler { ...@@ -149,6 +154,7 @@ public class SopInstNodeExecuteJobHandler {
// 刷新实例快照 // 刷新实例快照
SopInst inst = sop.getInst(); SopInst inst = sop.getInst();
inst.setInstSnapshot(snapshot); inst.setInstSnapshot(snapshot);
node.setDailyCount(ObjectUtil.defaultIfNull(node.getDailyCount(), 0) + 1);
// 刷新实例批次快照 // 刷新实例批次快照
SopInstBatch batch = sop.getBatch(); SopInstBatch batch = sop.getBatch();
...@@ -163,7 +169,7 @@ public class SopInstNodeExecuteJobHandler { ...@@ -163,7 +169,7 @@ public class SopInstNodeExecuteJobHandler {
nodeBatch.setSnapshot(snapshot); nodeBatch.setSnapshot(snapshot);
nodeBatch.setUpdateTime(new Date()); nodeBatch.setUpdateTime(new Date());
} }
sopService.updateNodeBatch(inst, batch, nodeBatch); sopService.updateNodeBatch(inst, node, batch, nodeBatch);
} }
private SopStruct reloadAndCreateNodeBatch(SopStruct sop, SopInstNode node) { private SopStruct reloadAndCreateNodeBatch(SopStruct sop, SopInstNode node) {
......
...@@ -182,7 +182,7 @@ public class SopService { ...@@ -182,7 +182,7 @@ public class SopService {
return curBatch; return curBatch;
} }
public void updateNodeBatch(SopInst sopInst, SopInstBatch batch, SopInstNodeBatch nodeBatch) { public void updateNodeBatch(SopInst sopInst, SopInstNode node, SopInstBatch batch, SopInstNodeBatch nodeBatch) {
if (nodeBatch != null) { if (nodeBatch != null) {
instNodeBatchMapper.updateByPrimaryKey(nodeBatch); instNodeBatchMapper.updateByPrimaryKey(nodeBatch);
} }
...@@ -191,7 +191,12 @@ public class SopService { ...@@ -191,7 +191,12 @@ public class SopService {
instBatchMapper.updateByPrimaryKey(batch); instBatchMapper.updateByPrimaryKey(batch);
} }
instMapper.updateByPrimaryKey(sopInst); instMapper.updateByPrimaryKey(sopInst); // 更新快照
instNodeMapper.updateByPrimaryKey(node); // 更新执行次数
}
public void resetNodeDailyCount(SopStruct sop) {
instNodeMapper.resetInstNodeDailyCount(sop.getInst().getInstId());
} }
} }
<?xml version="1.0" encoding="UTF-8"?> <?xml version="1.0" encoding="UTF-8"?>
<!DOCTYPE mapper PUBLIC "-//mybatis.org//DTD Mapper 3.0//EN" "http://mybatis.org/dtd/mybatis-3-mapper.dtd"> <!DOCTYPE mapper PUBLIC "-//mybatis.org//DTD Mapper 3.0//EN" "http://mybatis.org/dtd/mybatis-3-mapper.dtd">
<mapper namespace="cn.com.glsx.process.modules.mapper.SopInstNodeMapper"> <mapper namespace="cn.com.glsx.process.modules.mapper.SopInstNodeMapper">
<resultMap id="BaseResultMap" type="cn.com.glsx.process.modules.entity.SopInstNode"> <resultMap id="BaseResultMap" type="cn.com.glsx.process.modules.entity.SopInstNode">
<!-- <!-- WARNING - @mbg.generated -->
WARNING - @mbg.generated <id column="inst_node_id" jdbcType="INTEGER" property="instNodeId" />
--> <result column="inst_id" jdbcType="VARCHAR" property="instId" />
<id column="inst_node_id" jdbcType="INTEGER" property="instNodeId" /> <result column="node_id" jdbcType="INTEGER" property="nodeId" />
<result column="inst_id" jdbcType="VARCHAR" property="instId" /> <result column="node_name" jdbcType="VARCHAR" property="nodeName" />
<result column="node_id" jdbcType="INTEGER" property="nodeId" /> <result column="node_type" jdbcType="VARCHAR" property="nodeType" />
<result column="node_name" jdbcType="VARCHAR" property="nodeName" /> <result column="node_label" jdbcType="VARCHAR" property="nodeLabel" />
<result column="node_type" jdbcType="VARCHAR" property="nodeType" /> <result column="node_key" jdbcType="VARCHAR" property="nodeKey" />
<result column="node_label" jdbcType="VARCHAR" property="nodeLabel" /> <result column="node_show" jdbcType="VARCHAR" property="nodeShow" />
<result column="node_key" jdbcType="VARCHAR" property="nodeKey" /> <result column="node_param" jdbcType="VARCHAR" property="nodeParam" />
<result column="node_show" jdbcType="VARCHAR" property="nodeShow" /> <result column="node_content" jdbcType="VARCHAR" property="nodeContent" />
<result column="node_param" jdbcType="VARCHAR" property="nodeParam" /> <result column="node_visible" jdbcType="TINYINT" property="nodeVisible" />
<result column="node_content" jdbcType="VARCHAR" property="nodeContent" /> <result column="node_skip" jdbcType="TINYINT" property="nodeSkip" />
<result column="node_visible" jdbcType="TINYINT" property="nodeVisible" /> <result column="node_cron" jdbcType="VARCHAR" property="nodeCron" />
<result column="node_skip" jdbcType="TINYINT" property="nodeSkip" /> <result column="node_expire_cron" jdbcType="VARCHAR" property="nodeExpireCron" />
<result column="node_cron" jdbcType="VARCHAR" property="nodeCron" /> <result column="node_status" jdbcType="INTEGER" property="nodeStatus" />
<result column="node_expire_cron" jdbcType="VARCHAR" property="nodeExpireCron" /> <result column="daily_limit" jdbcType="INTEGER" property="dailyLimit" />
<result column="node_status" jdbcType="INTEGER" property="nodeStatus" /> <result column="daily_count" jdbcType="INTEGER" property="dailyCount" />
</resultMap> </resultMap>
<sql id="Base_Column_List">
<!-- <sql id="Base_Column_List">
WARNING - @mbg.generated <!-- WARNING - @mbg.generated -->
--> inst_node_id, inst_id, node_id, node_name, node_type, node_label, node_key, node_show,
inst_node_id, inst_id, node_id, node_name, node_type, node_label, node_key, node_show, node_param, node_content, node_visible, node_skip, node_cron, node_expire_cron, node_status, daily_limit, daily_count
node_param, node_content, node_visible, node_skip, node_cron, node_expire_cron, node_status </sql>
</sql>
<select id="findByInstId" resultMap="BaseResultMap" <select id="findByInstId" resultMap="BaseResultMap" parameterType="java.lang.String">
parameterType="java.lang.String"> SELECT
node_id, node_name,node_type
FROM sop_inst_node WHERE inst_id=#{instId}
</select>
<update id="resetInstNodeDailyCount">
update sop_inst_node set daily_count=0 where inst_id=#{instId}
</update>
SELECT
node_id, node_name,node_type
FROM sop_inst_node WHERE inst_id=#{instId}
</select>
</mapper> </mapper>
\ No newline at end of file \ No newline at end of file
<?xml version="1.0" encoding="UTF-8"?> <?xml version="1.0" encoding="UTF-8"?>
<!DOCTYPE mapper PUBLIC "-//mybatis.org//DTD Mapper 3.0//EN" "http://mybatis.org/dtd/mybatis-3-mapper.dtd"> <!DOCTYPE mapper PUBLIC "-//mybatis.org//DTD Mapper 3.0//EN" "http://mybatis.org/dtd/mybatis-3-mapper.dtd">
<mapper namespace="cn.com.glsx.process.modules.mapper.SopTplNodeMapper"> <mapper namespace="cn.com.glsx.process.modules.mapper.SopTplNodeMapper">
<resultMap id="BaseResultMap" type="cn.com.glsx.process.modules.entity.SopTplNode"> <resultMap id="BaseResultMap" type="cn.com.glsx.process.modules.entity.SopTplNode">
<!-- <!-- WARNING - @mbg.generated -->
WARNING - @mbg.generated <id column="node_id" jdbcType="INTEGER" property="nodeId" />
--> <result column="tpl_id" jdbcType="VARCHAR" property="tplId" />
<id column="node_id" jdbcType="INTEGER" property="nodeId" /> <result column="node_name" jdbcType="VARCHAR" property="nodeName" />
<result column="tpl_id" jdbcType="VARCHAR" property="tplId" /> <result column="node_type" jdbcType="VARCHAR" property="nodeType" />
<result column="node_name" jdbcType="VARCHAR" property="nodeName" /> <result column="node_label" jdbcType="VARCHAR" property="nodeLabel" />
<result column="node_type" jdbcType="VARCHAR" property="nodeType" /> <result column="node_show" jdbcType="VARCHAR" property="nodeShow" />
<result column="node_label" jdbcType="VARCHAR" property="nodeLabel" /> <result column="node_param_def" jdbcType="VARCHAR" property="nodeParamDef" />
<result column="node_show" jdbcType="VARCHAR" property="nodeShow" /> <result column="node_content_def" jdbcType="VARCHAR" property="nodeContentDef" />
<result column="node_param_def" jdbcType="VARCHAR" property="nodeParamDef" /> <result column="node_key" jdbcType="VARCHAR" property="nodeKey" />
<result column="node_content_def" jdbcType="VARCHAR" property="nodeContentDef" /> <result column="node_result_def" jdbcType="VARCHAR" property="nodeResultDef" />
<result column="node_key" jdbcType="VARCHAR" property="nodeKey" /> <result column="node_visible" jdbcType="TINYINT" property="nodeVisible" />
<result column="node_result_def" jdbcType="VARCHAR" property="nodeResultDef" /> <result column="node_cron" jdbcType="VARCHAR" property="nodeCron" />
<result column="node_visible" jdbcType="TINYINT" property="nodeVisible" /> <result column="node_expire_cron" jdbcType="VARCHAR" property="nodeExpireCron" />
<result column="node_cron" jdbcType="VARCHAR" property="nodeCron" /> <result column="node_skipable" jdbcType="TINYINT" property="nodeSkipable" />
<result column="node_expire_cron" jdbcType="VARCHAR" property="nodeExpireCron" /> <result column="daily_limit" jdbcType="INTEGER" property="dailyLimit" />
<result column="node_skipable" jdbcType="TINYINT" property="nodeSkipable" /> </resultMap>
</resultMap> <sql id="Base_Column_List">
<sql id="Base_Column_List"> <!-- WARNING - @mbg.generated -->
<!-- node_id, tpl_id, node_name, node_type, node_label, node_show, node_param_def, node_content_def,
WARNING - @mbg.generated node_key, node_result_def, node_visible, node_cron, node_expire_cron, node_skipable, daily_limit
--> </sql>
node_id, tpl_id, node_name, node_type, node_label, node_show, node_param_def, node_content_def,
node_key, node_result_def, node_visible, node_cron, node_expire_cron, node_skipable
</sql>
</mapper> </mapper>
\ No newline at end of file \ No newline at end of file
Markdown is supported
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!