Commit ebf8214a by 林永健

Merge remote-tracking branch 'origin/v1.0.1' into v1.0.1

2 parents a8db5c8f b8a00a76
package cn.com.glsx.process.modules.entity; package cn.com.glsx.process.modules.entity;
import java.util.Date;
import java.util.List; import java.util.List;
import javax.persistence.Column; import javax.persistence.Column;
...@@ -112,13 +113,18 @@ public class SopInstNode { ...@@ -112,13 +113,18 @@ public class SopInstNode {
*/ */
@Column(name = "daily_limit") @Column(name = "daily_limit")
private Integer dailyLimit; private Integer dailyLimit;
/** /**
* 每日执行次数限制,0表示不限制。 * 每日执行次数限制,0表示不限制。
*/ */
@Column(name = "daily_count") @Column(name = "daily_count")
private Integer dailyCount = 0; private Integer dailyCount = 0;
/**
* 每日任务过期时间,创建批次时重置,任务执行时检查。
*/
@Column(name = "daily_expire")
private Date dailyExpire;
@Transient @Transient
private List<SopInstNode> sopInstNodeList; private List<SopInstNode> sopInstNodeList;
...@@ -420,4 +426,12 @@ public class SopInstNode { ...@@ -420,4 +426,12 @@ public class SopInstNode {
this.dailyCount = dailyCount; this.dailyCount = dailyCount;
} }
public Date getDailyExpire() {
return dailyExpire;
}
public void setDailyExpire(Date dailyExpire) {
this.dailyExpire = dailyExpire;
}
} }
\ No newline at end of file \ No newline at end of file
...@@ -48,13 +48,17 @@ public class SopXxlJobUtil { ...@@ -48,13 +48,17 @@ public class SopXxlJobUtil {
// 遍历node,停止任务 // 遍历node,停止任务
for (SopInstNode node : sop.getInstNodeMap().values()) { for (SopInstNode node : sop.getInstNodeMap().values()) {
jobBusId = jobBusId(sop.getInst(), node); pauseSopNode(sop, node);
job = XxlJobUtil.findByBusKey(jobBusId); }
}
if (job != null && job.getTriggerStatus() == 1) { public static void pauseSopNode(SopStruct sop, SopInstNode node) {
String pause = XxlJobUtil.pause(jobBusId); String jobBusId = jobBusId(sop.getInst(), node);
SopXxlJobUtil.log(log, "【{}】Sop任务节点停止:{}", jobBusId, pause); XxlJobInfo job = XxlJobUtil.findByBusKey(jobBusId);
}
if (job != null && job.getTriggerStatus() == 1) {
String pause = XxlJobUtil.pause(jobBusId);
SopXxlJobUtil.log(log, "【{}】Sop任务节点停止:{}", jobBusId, pause);
} }
} }
...@@ -122,6 +126,12 @@ public class SopXxlJobUtil { ...@@ -122,6 +126,12 @@ public class SopXxlJobUtil {
int i = 0; int i = 0;
for (Integer nodeId : sop.getNodeSort()) { for (Integer nodeId : sop.getNodeSort()) {
SopInstNode node = sop.getInstNodeMap().get(nodeId); SopInstNode node = sop.getInstNodeMap().get(nodeId);
if (node.getDailyExpire() != null && node.getDailyExpire().before(new Date())) {
node.setNodeStatus(-1);
continue;
}
initSopNodeJob(sop, node, i++); initSopNodeJob(sop, node, i++);
} }
} }
......
...@@ -8,7 +8,6 @@ import com.xxl.job.core.context.XxlJobHelper; ...@@ -8,7 +8,6 @@ import com.xxl.job.core.context.XxlJobHelper;
import com.xxl.job.core.handler.annotation.XxlJob; import com.xxl.job.core.handler.annotation.XxlJob;
import cn.com.glsx.process.job.xxljob.core.SopXxlJobUtil; import cn.com.glsx.process.job.xxljob.core.SopXxlJobUtil;
import cn.com.glsx.process.modules.entity.SopInstBatch;
import cn.com.glsx.process.modules.model.SopStruct; import cn.com.glsx.process.modules.model.SopStruct;
import cn.com.glsx.process.modules.service.SopService; import cn.com.glsx.process.modules.service.SopService;
import lombok.extern.slf4j.Slf4j; import lombok.extern.slf4j.Slf4j;
...@@ -31,11 +30,9 @@ public class SopInstExecuteJobHandler { ...@@ -31,11 +30,9 @@ public class SopInstExecuteJobHandler {
SopStruct sop = sopService.loadSop(instId); SopStruct sop = sopService.loadSop(instId);
// 创建执行批次 // 创建执行批次
SopInstBatch batch = sopService.createBatch(sop.getInst()); if (sop.getInst().getInstStatus() == 1) {
sop.setBatch(batch); sopService.createBatch(sop);
}
// 重置节点执行次数
sopService.resetNodeDailyCount(sop);
// 创建所有节点任务 // 创建所有节点任务
SopXxlJobUtil.initSopNodesJob(sop); SopXxlJobUtil.initSopNodesJob(sop);
......
...@@ -114,6 +114,16 @@ public class SopInstNodeExecuteJobHandler { ...@@ -114,6 +114,16 @@ public class SopInstNodeExecuteJobHandler {
sop = reloadAndCreateNodeBatch(sop, node); sop = reloadAndCreateNodeBatch(sop, node);
node = sop.getInstNodeMap().get(node.getNodeId()); node = sop.getInstNodeMap().get(node.getNodeId());
// 节点过期
if (node.getDailyExpire() != null && node.getDailyExpire().before(new Date())) {
node.setNodeStatus(-1);
SopXxlJobUtil.pauseSopNode(sop, node);
SopXxlJobUtil.log(log, "【执行Sop节点】【{}:{}】,节点dailyExpire已到期,停止执行!", sop.getInst().getInstId(), sop.getInst().getInstName());
return;
}
// 没超执行次数限制 // 没超执行次数限制
if (node.getDailyLimit() == 0 || node.getDailyCount() < node.getDailyLimit()) { if (node.getDailyLimit() == 0 || node.getDailyCount() < node.getDailyLimit()) {
// 预备执行参数 // 预备执行参数
...@@ -157,6 +167,8 @@ public class SopInstNodeExecuteJobHandler { ...@@ -157,6 +167,8 @@ public class SopInstNodeExecuteJobHandler {
inst.setInstSnapshot(snapshot); inst.setInstSnapshot(snapshot);
node.setDailyCount(ObjectUtil.defaultIfNull(node.getDailyCount(), 0) + 1); node.setDailyCount(ObjectUtil.defaultIfNull(node.getDailyCount(), 0) + 1);
SopXxlJobUtil.log(log, "【执行Sop节点】【{}:{}】,节点已执行次数:{}!", sop.getInst().getInstId(), sop.getInst().getInstName(), node.getDailyCount());
// 刷新实例批次快照 // 刷新实例批次快照
SopInstBatch batch = sop.getBatch(); SopInstBatch batch = sop.getBatch();
if (batch != null) { if (batch != null) {
......
...@@ -2,6 +2,11 @@ package cn.com.glsx.process.modules.api; ...@@ -2,6 +2,11 @@ package cn.com.glsx.process.modules.api;
import javax.annotation.Resource; import javax.annotation.Resource;
import cn.com.glsx.cdp.api.customer.CustomerSopJourneyFeignClient;
import cn.com.glsx.cdp.modules.model.customer.CustomerSopJourneyDTO;
import cn.com.glsx.cdp.modules.model.customer.CustomerSopJourneySearch;
import com.alibaba.fastjson.JSONObject;
import com.github.pagehelper.PageInfo;
import org.springframework.web.bind.annotation.GetMapping; import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PathVariable; import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.RequestMapping; import org.springframework.web.bind.annotation.RequestMapping;
...@@ -39,13 +44,19 @@ public class UserApiController implements UserCenterFeignClient { ...@@ -39,13 +44,19 @@ public class UserApiController implements UserCenterFeignClient {
@Resource @Resource
private EchoCenterFeignClient echoCenterFeignClient; private EchoCenterFeignClient echoCenterFeignClient;
@Resource
private CustomerSopJourneyFeignClient customerSopJourneyFeignClient;
@Operation(summary = "FeignClient调用") @Operation(summary = "FeignClient调用")
@Override @Override
@GetMapping("/echo") @GetMapping("/echo")
public String echo(@RequestParam String message) { public String echo(@RequestParam String message) {
String echo = echoCenterFeignClient.echo(message); CustomerSopJourneySearch customerSopJourneySearch = new CustomerSopJourneySearch();
return echo; customerSopJourneySearch.setPageNum(1);
customerSopJourneySearch.setPageSize(10);
Result<PageInfo<CustomerSopJourneyDTO>> pageInfoResult = customerSopJourneyFeignClient.pageCustomerSopJourney(customerSopJourneySearch);
return JSONObject.toJSONString(pageInfoResult);
} }
@Operation(summary = "本地调用") @Operation(summary = "本地调用")
......
...@@ -19,6 +19,7 @@ import cn.com.glsx.process.modules.rabbitmq.RabbitConfig; ...@@ -19,6 +19,7 @@ import cn.com.glsx.process.modules.rabbitmq.RabbitConfig;
import cn.com.glsx.process.modules.rabbitmq.RabbitMQConstants; import cn.com.glsx.process.modules.rabbitmq.RabbitMQConstants;
import cn.com.glsx.process.util.FileUploadServerData; import cn.com.glsx.process.util.FileUploadServerData;
import cn.com.glsx.process.util.FileUploadUtil; import cn.com.glsx.process.util.FileUploadUtil;
import cn.com.glsx.process.util.SopTplParamHandler;
import com.github.pagehelper.PageHelper; import com.github.pagehelper.PageHelper;
import com.github.pagehelper.PageInfo; import com.github.pagehelper.PageInfo;
import com.glsx.plat.core.enums.SysConstants; import com.glsx.plat.core.enums.SysConstants;
...@@ -306,6 +307,8 @@ public class SopInstService { ...@@ -306,6 +307,8 @@ public class SopInstService {
sopInst.setInstName(String.format("%s-%s", sopTplGrant.getGroupName(), sopTplDTO.getTplName())); sopInst.setInstName(String.format("%s-%s", sopTplGrant.getGroupName(), sopTplDTO.getTplName()));
sopInst.setInstId(tplId + grantId); sopInst.setInstId(tplId + grantId);
sopInst.setGrantId(grantId); sopInst.setGrantId(grantId);
// 处理模板定义的初始化参数
sopInst.setInstParam(SopTplParamHandler.addMerchantId(SopTplParamHandler.extract(sopTplDTO.getTplParamDef()), sopTplGrant.getGroupId()) );
sopInst.setCreateTime(date); sopInst.setCreateTime(date);
sopInst.setUpdateTime(date); sopInst.setUpdateTime(date);
sopInst.setInstStatus(SopInstStatusEnum.UNUSED.getValue()); sopInst.setInstStatus(SopInstStatusEnum.UNUSED.getValue());
...@@ -328,6 +331,9 @@ public class SopInstService { ...@@ -328,6 +331,9 @@ public class SopInstService {
sopInstNode.setInstId(instId); sopInstNode.setInstId(instId);
sopInstNode.setNodeStatus(SopInstNode.NODE_STATUS_NORMAL); sopInstNode.setNodeStatus(SopInstNode.NODE_STATUS_NORMAL);
// 处理模板节点定义的初始化参数
sopInstNode.setNodeParam(SopTplParamHandler.extract(sopTplNode.getNodeParamDef()));
//页面选择是否跳过处理 //页面选择是否跳过处理
SopInstNode sopInstNodeTemp = customNodesMap.get(sopInstNode.getNodeId()); SopInstNode sopInstNodeTemp = customNodesMap.get(sopInstNode.getNodeId());
sopInstNode.setNodeSkip(!Objects.isNull(sopInstNodeTemp) ? sopInstNodeTemp.getNodeSkip() : SopInstNode.NODE_SKIP_FALSE); sopInstNode.setNodeSkip(!Objects.isNull(sopInstNodeTemp) ? sopInstNodeTemp.getNodeSkip() : SopInstNode.NODE_SKIP_FALSE);
......
...@@ -9,6 +9,7 @@ import java.util.stream.Collectors; ...@@ -9,6 +9,7 @@ import java.util.stream.Collectors;
import javax.annotation.Resource; import javax.annotation.Resource;
import org.quartz.CronExpression;
import org.springframework.data.redis.core.StringRedisTemplate; import org.springframework.data.redis.core.StringRedisTemplate;
import org.springframework.stereotype.Service; import org.springframework.stereotype.Service;
import org.springframework.transaction.annotation.Transactional; import org.springframework.transaction.annotation.Transactional;
...@@ -161,7 +162,9 @@ public class SopService { ...@@ -161,7 +162,9 @@ public class SopService {
return sop; return sop;
} }
public SopInstBatch createBatch(SopInst sopInst) { public SopInstBatch createBatch(SopStruct sop) {
SopInst sopInst = sop.getInst();
SopInstBatch batch = new SopInstBatch(); SopInstBatch batch = new SopInstBatch();
batch.setBatchNo(SnowFlake.nextSerialNumber()); batch.setBatchNo(SnowFlake.nextSerialNumber());
batch.setCreateTime(new Date()); batch.setCreateTime(new Date());
...@@ -176,6 +179,24 @@ public class SopService { ...@@ -176,6 +179,24 @@ public class SopService {
instMapper.updateInstBatchNo(sopInst.getInstId(), batch.getBatchNo(), batch.getSnapshot()); instMapper.updateInstBatchNo(sopInst.getInstId(), batch.getBatchNo(), batch.getSnapshot());
// 重置节点执行次数
instNodeMapper.resetInstNodeDailyCount(sopInst.getInstId());
for (SopInstNode node : sop.getInstNodeMap().values()) {
if (StrUtil.isBlank(node.getNodeExpireCron())) {
continue;
}
try {
Date expire = new CronExpression(node.getNodeExpireCron()).getNextValidTimeAfter(new Date());
node.setDailyExpire(expire);
instNodeMapper.updateByPrimaryKey(node);
} catch (Exception e) {
log.info("【{}】过期格式不对:{}", node.getNodeName(), node.getNodeExpireCron(), e);
}
}
sop.setBatch(batch);
return batch; return batch;
} }
...@@ -202,14 +223,15 @@ public class SopService { ...@@ -202,14 +223,15 @@ public class SopService {
instBatchMapper.updateByPrimaryKey(batch); instBatchMapper.updateByPrimaryKey(batch);
} }
// 过期机制
if (sopInst.getExpireTime() != null && sopInst.getExpireTime().before(new Date())) {
sopInst.setInstStatus((byte) -1);
}
instMapper.updateByPrimaryKey(sopInst); // 更新快照 instMapper.updateByPrimaryKey(sopInst); // 更新快照
instNodeMapper.updateByPrimaryKey(node); // 更新执行次数 instNodeMapper.updateByPrimaryKey(node); // 更新执行次数
} }
public void resetNodeDailyCount(SopStruct sop) {
instNodeMapper.resetInstNodeDailyCount(sop.getInst().getInstId());
}
/** 从实例倒推出模板,主要用于开发阶段 */ /** 从实例倒推出模板,主要用于开发阶段 */
@Transactional @Transactional
public void generateTplFromInst(SopStruct sop) { public void generateTplFromInst(SopStruct sop) {
......
package cn.com.glsx.process.util;
import com.alibaba.fastjson.JSON;
import com.fasterxml.jackson.databind.JsonNode;
import com.fasterxml.jackson.databind.ObjectMapper;
import com.glsx.plat.exception.ResultException;
import com.glsx.plat.exception.SystemMessage;
import lombok.experimental.UtilityClass;
import org.springframework.util.StringUtils;
import java.util.HashMap;
import java.util.Map;
@UtilityClass
public class SopTplParamHandler {
public ObjectMapper objectMapper = new ObjectMapper();
public String extract(String tplParam) {
if (!StringUtils.hasLength(tplParam)) {
return null;
}
try {
JsonNode rootNode = objectMapper.readTree(tplParam);
return processNode(rootNode);
} catch (Exception e) {
throw ResultException.create(SystemMessage.DATA_HANDLE_ERROR.getCode(), "参数转json对象异常");
}
}
public String addMerchantId(String paramJson, String merchantId) {
if (!StringUtils.hasLength(paramJson)) {
return null;
}
HashMap map = JSON.parseObject(paramJson, HashMap.class);
map.put("merchantId", merchantId);
return JSON.toJSONString(map);
}
private String processNode(JsonNode node) {
Map<String, Object> map = new HashMap<>();
for (JsonNode childNode : node) {
String key = childNode.path("paramKey").asText();
String valueType = childNode.path("valueType").asText();
JsonNode defaultValueNode = childNode.path("defaultValue");
switch (valueType) {
case "Number":
int defaultValueInt = defaultValueNode.asInt();
map.put(key, defaultValueInt);
break;
case "String":
String defaultValueString = defaultValueNode.asText();
map.put(key, defaultValueString);
break;
case "Map":
// 解析Map类型的默认值
Map<String, Object> defaultValueMap = objectMapper.convertValue(defaultValueNode, HashMap.class);
map.put(key, defaultValueMap);
break;
// 其他数据类型的解析
default:
break;
}
}
return JSON.toJSONString(map);
}
}
...@@ -20,12 +20,13 @@ ...@@ -20,12 +20,13 @@
<result column="node_status" jdbcType="INTEGER" property="nodeStatus" /> <result column="node_status" jdbcType="INTEGER" property="nodeStatus" />
<result column="daily_limit" jdbcType="INTEGER" property="dailyLimit" /> <result column="daily_limit" jdbcType="INTEGER" property="dailyLimit" />
<result column="daily_count" jdbcType="INTEGER" property="dailyCount" /> <result column="daily_count" jdbcType="INTEGER" property="dailyCount" />
<result column="daily_expire" jdbcType="TIMESTAMP" property="dailyExpire" />
</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, daily_limit, daily_count, daily_expire
</sql> </sql>
<select id="findByInstId" resultMap="BaseResultMap" parameterType="java.lang.String"> <select id="findByInstId" resultMap="BaseResultMap" parameterType="java.lang.String">
......
...@@ -7,9 +7,14 @@ import java.util.concurrent.CyclicBarrier; ...@@ -7,9 +7,14 @@ import java.util.concurrent.CyclicBarrier;
import java.util.concurrent.ExecutorService; import java.util.concurrent.ExecutorService;
import java.util.concurrent.Executors; import java.util.concurrent.Executors;
import cn.com.glsx.cdp.api.customer.CustomerSopJourneyFeignClient;
import cn.com.glsx.cdp.modules.model.customer.CustomerSopJourneyDTO;
import cn.com.glsx.cdp.modules.model.customer.CustomerSopJourneySearch;
import cn.com.glsx.process.modules.service.SopInstLinkService; import cn.com.glsx.process.modules.service.SopInstLinkService;
import com.alibaba.fastjson.JSONArray; import com.alibaba.fastjson.JSONArray;
import com.alibaba.fastjson.serializer.SerializerFeature; import com.alibaba.fastjson.serializer.SerializerFeature;
import com.github.pagehelper.PageInfo;
import com.glsx.plat.core.web.Result;
import org.junit.Test; import org.junit.Test;
import org.junit.runner.RunWith; import org.junit.runner.RunWith;
import org.springframework.beans.factory.annotation.Autowired; import org.springframework.beans.factory.annotation.Autowired;
...@@ -32,6 +37,8 @@ import cn.com.glsx.process.modules.sop.execute.plugin.dbconn.SopBizAdapter; ...@@ -32,6 +37,8 @@ import cn.com.glsx.process.modules.sop.execute.plugin.dbconn.SopBizAdapter;
import cn.com.glsx.process.modules.sop.execute.plugin.java.DynamicEngine; import cn.com.glsx.process.modules.sop.execute.plugin.java.DynamicEngine;
import cn.com.glsx.process.modules.sop.java.example.ControllerHttpDemo; import cn.com.glsx.process.modules.sop.java.example.ControllerHttpDemo;
import javax.annotation.Resource;
/** /**
* 测试spring cloud 服务调用方式 * 测试spring cloud 服务调用方式
*/ */
...@@ -51,6 +58,9 @@ public class TestApplication { ...@@ -51,6 +58,9 @@ public class TestApplication {
@Autowired @Autowired
private SopInstLinkService sopInstLinkService; private SopInstLinkService sopInstLinkService;
@Resource
private CustomerSopJourneyFeignClient customerSopJourneyFeignClient;
@Test @Test
public void test() throws SQLException { public void test() throws SQLException {
SopDataSource byId = sopDataSourceService.findByDataSourceId("SOP_CDP"); SopDataSource byId = sopDataSourceService.findByDataSourceId("SOP_CDP");
...@@ -149,5 +159,13 @@ public class TestApplication { ...@@ -149,5 +159,13 @@ public class TestApplication {
String listString = JSON.toJSONString(xblc7, SerializerFeature.DisableCircularReferenceDetect); String listString = JSON.toJSONString(xblc7, SerializerFeature.DisableCircularReferenceDetect);
System.out.println(listString); System.out.println(listString);
} }
@Test
public void pageCustomerSopJourney() {
CustomerSopJourneySearch customerSopJourneySearch=new CustomerSopJourneySearch();
customerSopJourneySearch.setPageNum(1);
customerSopJourneySearch.setPageSize(10);
Result<PageInfo<CustomerSopJourneyDTO>> pageInfoResult = customerSopJourneyFeignClient.pageCustomerSopJourney(customerSopJourneySearch);
System.out.println(pageInfoResult);
}
} }
\ 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!