Commit 55ba8505 by tiger

sop params

1 parent c66bcbf0
...@@ -3,13 +3,13 @@ package cn.com.glsx.process.modules.mapper; ...@@ -3,13 +3,13 @@ package cn.com.glsx.process.modules.mapper;
import java.util.List; import java.util.List;
import java.util.Map; import java.util.Map;
import cn.com.glsx.process.modules.model.SopInstDTO;
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 com.glsx.plat.mybatis.mapper.CommonBaseMapper; import com.glsx.plat.mybatis.mapper.CommonBaseMapper;
import cn.com.glsx.process.modules.entity.SopInst; import cn.com.glsx.process.modules.entity.SopInst;
import cn.com.glsx.process.modules.model.SopInstDTO;
import cn.com.glsx.process.modules.model.SopInstSearch; import cn.com.glsx.process.modules.model.SopInstSearch;
@Mapper @Mapper
...@@ -41,7 +41,7 @@ public interface SopInstMapper extends CommonBaseMapper<SopInst> { ...@@ -41,7 +41,7 @@ public interface SopInstMapper extends CommonBaseMapper<SopInst> {
*/ */
void updateInstStatus(@Param("instId") String instId, @Param("status") Byte status); void updateInstStatus(@Param("instId") String instId, @Param("status") Byte status);
void updateInstBatchNo(@Param("instId") String instId, @Param("batchNo") String batchNo); void updateInstBatchNo(@Param("instId") String instId, @Param("batchNo") String batchNo, @Param("snapshot") String snapshot);
/** /**
* 分页查询模板实例列表 * 分页查询模板实例列表
......
...@@ -11,25 +11,22 @@ import cn.com.glsx.process.modules.entity.SopInst; ...@@ -11,25 +11,22 @@ import cn.com.glsx.process.modules.entity.SopInst;
import cn.com.glsx.process.modules.entity.SopInstBatch; import cn.com.glsx.process.modules.entity.SopInstBatch;
import cn.com.glsx.process.modules.entity.SopInstNode; import cn.com.glsx.process.modules.entity.SopInstNode;
import cn.com.glsx.process.modules.entity.SopInstNodeBatch; import cn.com.glsx.process.modules.entity.SopInstNodeBatch;
import cn.com.glsx.process.modules.entity.SopTpl;
import cn.com.glsx.process.modules.entity.SopTplGrant;
import cn.com.glsx.process.modules.entity.SopTplNode;
import cn.hutool.core.lang.Pair; import cn.hutool.core.lang.Pair;
import lombok.Data; import lombok.Data;
@Data @Data
public class SopStruct { public class SopStruct {
/** 模板 */ /** 模板,暂时不关注 */
private SopTpl tpl; // private SopTpl tpl;
/** 模板节点表 */ /** 模板节点表,暂时不关注 */
private Map<Integer, SopTplNode> tplNodeMap; // private Map<Integer, SopTplNode> tplNodeMap;
/** 模板节点连接关系: fromSet, toSet,暂时不关注 */ /** 模板节点连接关系: fromSet, toSet,暂时不关注 */
// private Map<Integer, Pair<Set<Integer>, Set<Integer>>> tplLinkMap; // private Map<Integer, Pair<Set<Integer>, Set<Integer>>> tplLinkMap;
/** 模板分配 */ /** 模板分配 */
private SopTplGrant grant; // private SopTplGrant grant;
/** 模板实例 */ /** 模板实例 */
private SopInst inst; private SopInst inst;
......
...@@ -14,6 +14,7 @@ import org.springframework.boot.autoconfigure.SpringBootApplication; ...@@ -14,6 +14,7 @@ import org.springframework.boot.autoconfigure.SpringBootApplication;
import org.springframework.cloud.client.discovery.EnableDiscoveryClient; import org.springframework.cloud.client.discovery.EnableDiscoveryClient;
import org.springframework.cloud.openfeign.EnableFeignClients; import org.springframework.cloud.openfeign.EnableFeignClients;
import org.springframework.context.annotation.EnableAspectJAutoProxy; import org.springframework.context.annotation.EnableAspectJAutoProxy;
import org.springframework.transaction.annotation.EnableTransactionManagement;
import com.glsx.plat.context.EnableRestAdmin; import com.glsx.plat.context.EnableRestAdmin;
...@@ -28,6 +29,7 @@ import cn.com.glsx.process.job.xxljob.core.SopXxlJobUtil; ...@@ -28,6 +29,7 @@ import cn.com.glsx.process.job.xxljob.core.SopXxlJobUtil;
@EnableFeignClients(basePackages = { "cn.com.glsx.*.api", "cn.com.glsx.process.modules.client" }) @EnableFeignClients(basePackages = { "cn.com.glsx.*.api", "cn.com.glsx.process.modules.client" })
@SpringBootApplication @SpringBootApplication
@EnableAspectJAutoProxy @EnableAspectJAutoProxy
@EnableTransactionManagement
public class Application implements CommandLineRunner { public class Application implements CommandLineRunner {
public static void main(String[] args) { public static void main(String[] args) {
......
...@@ -145,6 +145,7 @@ public class SopInstNodeExecuteJobHandler { ...@@ -145,6 +145,7 @@ public class SopInstNodeExecuteJobHandler {
} }
private void updateNextNodes(SopStruct sop, SopInstNode node) { private void updateNextNodes(SopStruct sop, SopInstNode node) {
// TODO 是否需要触发后续任务
SopXxlJobUtil.finishSopNodeJob(sop, node); SopXxlJobUtil.finishSopNodeJob(sop, node);
} }
......
...@@ -45,4 +45,14 @@ public class SopController { ...@@ -45,4 +45,14 @@ public class SopController {
return Result.success("已刷新:" + rs); return Result.success("已刷新:" + rs);
} }
@Operation(summary = "从实例反推模板", description = "注意先把模板清理掉")
@GetMapping(value = "/inst/to/tpl/{instId}")
public Result<String> instToTpl(@PathVariable("instId") String instId) {
SopStruct sop = sopService.loadSop(instId);
sopService.generateTplFromInst(sop);
return Result.success("已生成模板!");
}
} }
...@@ -3,6 +3,7 @@ package cn.com.glsx.process.modules.service; ...@@ -3,6 +3,7 @@ package cn.com.glsx.process.modules.service;
import java.util.Date; import java.util.Date;
import java.util.List; import java.util.List;
import java.util.Map; import java.util.Map;
import java.util.Map.Entry;
import java.util.Set; import java.util.Set;
import java.util.stream.Collectors; import java.util.stream.Collectors;
...@@ -10,10 +11,12 @@ import javax.annotation.Resource; ...@@ -10,10 +11,12 @@ import javax.annotation.Resource;
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 com.alibaba.nacos.shaded.com.google.common.collect.Maps; import com.alibaba.nacos.shaded.com.google.common.collect.Maps;
import com.alibaba.nacos.shaded.com.google.common.collect.Sets; import com.alibaba.nacos.shaded.com.google.common.collect.Sets;
import com.glsx.plat.common.utils.SnowFlake; import com.glsx.plat.common.utils.SnowFlake;
import com.google.common.collect.Lists;
import cn.com.glsx.process.modules.entity.SopInst; import cn.com.glsx.process.modules.entity.SopInst;
import cn.com.glsx.process.modules.entity.SopInstBatch; import cn.com.glsx.process.modules.entity.SopInstBatch;
...@@ -21,7 +24,7 @@ import cn.com.glsx.process.modules.entity.SopInstLink; ...@@ -21,7 +24,7 @@ import cn.com.glsx.process.modules.entity.SopInstLink;
import cn.com.glsx.process.modules.entity.SopInstNode; import cn.com.glsx.process.modules.entity.SopInstNode;
import cn.com.glsx.process.modules.entity.SopInstNodeBatch; import cn.com.glsx.process.modules.entity.SopInstNodeBatch;
import cn.com.glsx.process.modules.entity.SopTpl; import cn.com.glsx.process.modules.entity.SopTpl;
import cn.com.glsx.process.modules.entity.SopTplGrant; import cn.com.glsx.process.modules.entity.SopTplLink;
import cn.com.glsx.process.modules.entity.SopTplNode; import cn.com.glsx.process.modules.entity.SopTplNode;
import cn.com.glsx.process.modules.mapper.SopInstBatchMapper; import cn.com.glsx.process.modules.mapper.SopInstBatchMapper;
import cn.com.glsx.process.modules.mapper.SopInstLinkMapper; import cn.com.glsx.process.modules.mapper.SopInstLinkMapper;
...@@ -33,8 +36,13 @@ import cn.com.glsx.process.modules.mapper.SopTplLinkMapper; ...@@ -33,8 +36,13 @@ import cn.com.glsx.process.modules.mapper.SopTplLinkMapper;
import cn.com.glsx.process.modules.mapper.SopTplMapper; import cn.com.glsx.process.modules.mapper.SopTplMapper;
import cn.com.glsx.process.modules.mapper.SopTplNodeMapper; import cn.com.glsx.process.modules.mapper.SopTplNodeMapper;
import cn.com.glsx.process.modules.model.SopStruct; import cn.com.glsx.process.modules.model.SopStruct;
import cn.com.glsx.process.modules.sop.execute.SnapshotStruct;
import cn.com.glsx.process.util.JacksonUtils;
import cn.hutool.core.lang.Pair; import cn.hutool.core.lang.Pair;
import cn.hutool.core.util.NumberUtil;
import cn.hutool.core.util.StrUtil; import cn.hutool.core.util.StrUtil;
import cn.hutool.json.JSONObject;
import cn.hutool.json.JSONUtil;
import lombok.extern.slf4j.Slf4j; import lombok.extern.slf4j.Slf4j;
import tk.mybatis.mapper.entity.Example; import tk.mybatis.mapper.entity.Example;
import tk.mybatis.mapper.util.Sqls; import tk.mybatis.mapper.util.Sqls;
...@@ -110,16 +118,16 @@ public class SopService { ...@@ -110,16 +118,16 @@ public class SopService {
inst.setInstStatus((byte) -1); inst.setInstStatus((byte) -1);
} }
SopTplGrant grant = grantMapper.selectByPrimaryKey(inst.getGrantId()); // SopTplGrant grant = grantMapper.selectByPrimaryKey(inst.getGrantId());
sop.setGrant(grant); // sop.setGrant(grant);
SopTpl tpl = tplMapper.selectByPrimaryKey(grant.getTplId()); // SopTpl tpl = tplMapper.selectByPrimaryKey(grant.getTplId());
sop.setTpl(tpl); // sop.setTpl(tpl);
List<SopTplNode> tplNodes = tplNodeMapper // List<SopTplNode> tplNodes = tplNodeMapper
.selectByExample(Example.builder(SopTplNode.class).where(Sqls.custom().andEqualTo("tplId", grant.getTplId())).build()); // .selectByExample(Example.builder(SopTplNode.class).where(Sqls.custom().andEqualTo("tplId", grant.getTplId())).build());
Map<Integer, SopTplNode> tplNodeMap = tplNodes.stream().collect(Collectors.toMap(SopTplNode::getNodeId, obj -> obj, (key1, key2) -> key1)); // Map<Integer, SopTplNode> tplNodeMap = tplNodes.stream().collect(Collectors.toMap(SopTplNode::getNodeId, obj -> obj, (key1, key2) -> key1));
sop.setTplNodeMap(tplNodeMap); // sop.setTplNodeMap(tplNodeMap);
List<SopInstNode> instNodes = instNodeMapper List<SopInstNode> instNodes = instNodeMapper
.selectByExample(Example.builder(SopInstNode.class).where(Sqls.custom().andEqualTo("instId", inst.getInstId())).build()); .selectByExample(Example.builder(SopInstNode.class).where(Sqls.custom().andEqualTo("instId", inst.getInstId())).build());
...@@ -159,11 +167,14 @@ public class SopService { ...@@ -159,11 +167,14 @@ public class SopService {
batch.setCreateTime(new Date()); batch.setCreateTime(new Date());
batch.setUpdateTime(new Date()); batch.setUpdateTime(new Date());
batch.setInstId(sopInst.getInstId()); batch.setInstId(sopInst.getInstId());
batch.setSnapshot(StrUtil.blankToDefault(sopInst.getInstSnapshot(), "{}"));
SnapshotStruct ss = JacksonUtils.fromJson(StrUtil.blankToDefault(sopInst.getInstSnapshot(), "{}"), SnapshotStruct.class);
ss.getResultMap().clear();
batch.setSnapshot(JacksonUtils.toJson(ss));
instBatchMapper.insert(batch); instBatchMapper.insert(batch);
instMapper.updateInstBatchNo(sopInst.getInstId(), batch.getBatchNo()); instMapper.updateInstBatchNo(sopInst.getInstId(), batch.getBatchNo(), batch.getSnapshot());
return batch; return batch;
} }
...@@ -199,4 +210,133 @@ public class SopService { ...@@ -199,4 +210,133 @@ public class SopService {
instNodeMapper.resetInstNodeDailyCount(sop.getInst().getInstId()); instNodeMapper.resetInstNodeDailyCount(sop.getInst().getInstId());
} }
/** 从实例倒推出模板,主要用于开发阶段 */
@Transactional
public void generateTplFromInst(SopStruct sop) {
// 预备模板
SopTpl tpl = new SopTpl();
tpl.setCreateTime(new Date());
tpl.setTplCron(sop.getInst().getInstCron());
tpl.setTplId(StrUtil.sub(SnowFlake.nextSerialNumber(), 0, 8)); // 随机生成模板id
tpl.setTplName(sop.getInst().getInstName());
// 生成参数定义
tpl.setTplParamDef(parseDef(sop.getInst().getInstParam()));
tpl.setTplRemark("从实例自动产生模板:" + sop.getInst().getInstName());
tpl.setTplResultDef(sop.getInst().getInstSnapshot());
tpl.setTplSingleton((byte) 1);
tpl.setTplStatus((byte) 1);
tpl.setUpdateTime(new Date());
tplMapper.insert(tpl);
List<SopTplNode> nodes = Lists.newArrayList();
for (SopInstNode node : sop.getInstNodeMap().values()) {
SopTplNode tnode = new SopTplNode();
tnode.setDailyLimit(node.getDailyLimit());
tnode.setNodeAsync(node.getNodeAsync());
tnode.setNodeContentDef(node.getNodeContent());
tnode.setNodeCron(node.getNodeCron());
tnode.setNodeExpireCron(node.getNodeExpireCron());
tnode.setNodeId(node.getNodeId());
tnode.setNodeKey(node.getNodeKey());
tnode.setNodeLabel(node.getNodeLabel());
tnode.setNodeName(node.getNodeName());
tnode.setNodeParamDef(parseDef(node.getNodeParam()));
tnode.setNodeResultDef(node.getNodeContent());
tnode.setNodeShow(node.getNodeShow());
tnode.setNodeSkipable(node.getNodeSkip());
tnode.setNodeType(node.getNodeType());
tnode.setNodeVisible(node.getNodeVisible());
tnode.setTplId(tpl.getTplId());
nodes.add(tnode);
}
tplNodeMapper.insertList(nodes);
List<SopTplLink> links = Lists.newArrayList();
for (Entry<Integer, Pair<Set<Integer>, Set<Integer>>> entry : sop.getInstLinkMap().entrySet()) {
if (entry.getValue().getValue().isEmpty()) {
continue;
}
int sourceId = entry.getKey();
for (int targetId : entry.getValue().getValue()) {
SopTplLink link = new SopTplLink();
link.setSourceId(sourceId);
link.setTargetId(targetId);
link.setTplId(tpl.getTplId());
links.add(link);
}
}
tplLinkMapper.insertList(links);
}
/**
* <code>
{
"day": {
"paramName": "day",
"paramDesc": "有意向第?天",
"valueType": "Integer",
"defaultValue": "2",
"required": true
},
"textContent": {
"paramName": "textContent",
"paramDesc": "营销文案",
"valueType": "String",
"defaultValue": "尊敬的${userName},优惠券领取url.cn/c134dqwe",
"required": true
}
}
* </code>
*
* @param json
* @return
*/
private static String parseDef(String json) {
if (json == null || json.trim().length() < 1) {
return null;
}
JSONObject def = new JSONObject();
try {
JSONObject parse = JSONUtil.parseObj(json);
for (String key : parse.keySet()) {
Map<String, Object> map = Maps.newHashMap();
map.put("paramKey", key);
map.put("paramDesc", key);
Object value = parse.get(key);
String type = detectType(value);
map.put("valueType", type);
map.put("defaultValue", value);
map.put("required", true);
def.set(key, map);
}
} catch (Exception e) {
log.warn("json:{}", json, e);
}
return def.toString();
}
private static String detectType(Object value) {
String v = value.toString().trim();
if (NumberUtil.isNumber(v)) {
return "Number";
}
if (StrUtil.startWith(v, "{")) {
return "Map";
}
if (StrUtil.startWith(v, "[")) {
return "Array";
}
return "String";
}
} }
...@@ -5,23 +5,29 @@ import java.lang.reflect.Field; ...@@ -5,23 +5,29 @@ import java.lang.reflect.Field;
import java.security.GeneralSecurityException; import java.security.GeneralSecurityException;
import java.security.MessageDigest; import java.security.MessageDigest;
import java.text.DateFormat; import java.text.DateFormat;
import java.text.ParseException;
import java.text.SimpleDateFormat; import java.text.SimpleDateFormat;
import java.util.*; import java.util.ArrayList;
import java.util.Collections;
import java.util.Date;
import java.util.HashMap;
import java.util.Iterator;
import java.util.List;
import java.util.Map;
import java.util.stream.Collectors; import java.util.stream.Collectors;
import cn.com.glsx.process.modules.entity.SopInstNode;
import com.alibaba.fastjson.JSON;
import com.alibaba.fastjson.JSONObject;
import com.fasterxml.jackson.databind.JsonNode;
import com.fasterxml.jackson.databind.ObjectMapper;
import org.apache.commons.collections.CollectionUtils; import org.apache.commons.collections.CollectionUtils;
import org.apache.commons.lang.StringUtils; import org.apache.commons.lang.StringUtils;
import org.springframework.util.LinkedMultiValueMap; import org.springframework.util.LinkedMultiValueMap;
import org.springframework.util.MultiValueMap; import org.springframework.util.MultiValueMap;
import org.springframework.web.client.RestTemplate; import org.springframework.web.client.RestTemplate;
import com.alibaba.fastjson.JSON;
import com.alibaba.fastjson.JSONObject;
import com.fasterxml.jackson.databind.JsonNode;
import com.fasterxml.jackson.databind.ObjectMapper;
import cn.com.glsx.process.modules.entity.SopInst; import cn.com.glsx.process.modules.entity.SopInst;
import cn.com.glsx.process.modules.entity.SopInstNode;
import cn.com.glsx.process.redis.DistributedLockUtils; import cn.com.glsx.process.redis.DistributedLockUtils;
/** /**
...@@ -58,7 +64,7 @@ public class SopHelper { ...@@ -58,7 +64,7 @@ public class SopHelper {
int days = 0; int days = 0;
if (Integer.parseInt(star1[0]) < Integer.parseInt(end1[0])) { if (Integer.parseInt(star1[0]) < Integer.parseInt(end1[0])) {
for (int i = Integer.parseInt(star1[0]); i < Integer.parseInt(end1[0]); i++) { for (int i = Integer.parseInt(star1[0]); i < Integer.parseInt(end1[0]); i++) {
//计算是否是瑞年 // 计算是否是瑞年
if (i % 4 == 0 && i % 100 != 0 || i % 400 == 0) { if (i % 4 == 0 && i % 100 != 0 || i % 400 == 0) {
days += 366; days += 366;
} else { } else {
...@@ -66,16 +72,15 @@ public class SopHelper { ...@@ -66,16 +72,15 @@ public class SopHelper {
} }
} }
} }
//得到开始那一年已过去的日期 // 得到开始那一年已过去的日期
int starday = days(star1[0], star1[1], star1[2]); int starday = days(star1[0], star1[1], star1[2]);
//得到结束那一年已过去的日期 // 得到结束那一年已过去的日期
int endday = days(end1[0], end1[1], end1[2]); int endday = days(end1[0], end1[1], end1[2]);
//减去开始那一年已过去的日期,加上结束那一年已过去的日期 // 减去开始那一年已过去的日期,加上结束那一年已过去的日期
days = days - starday + endday; days = days - starday + endday;
return days == diffdays; return days == diffdays;
} }
/** /**
* 获取构建的信息 * 获取构建的信息
* *
...@@ -99,7 +104,7 @@ public class SopHelper { ...@@ -99,7 +104,7 @@ public class SopHelper {
*/ */
public static List<CustomerInfo> getMeetWithCustomer(SopInstNode sopInstNode, Map<String, Object> resultData) { public static List<CustomerInfo> getMeetWithCustomer(SopInstNode sopInstNode, Map<String, Object> resultData) {
String nodeParam = sopInstNode.getNodeParam(); String nodeParam = sopInstNode.getNodeParam();
String key = "user"+getValueFromJsonString(nodeParam, "stageid"); String key = "user" + getValueFromJsonString(nodeParam, "stageid");
// 拿到过滤出阶段的客户 // 拿到过滤出阶段的客户
List<CustomerInfo> customerInfoList = JSON.parseArray(JSON.toJSONString(resultData.get(key)), CustomerInfo.class); List<CustomerInfo> customerInfoList = JSON.parseArray(JSON.toJSONString(resultData.get(key)), CustomerInfo.class);
String diffday = SopHelper.getValueFromJsonString(nodeParam, "day"); String diffday = SopHelper.getValueFromJsonString(nodeParam, "day");
...@@ -108,7 +113,8 @@ public class SopHelper { ...@@ -108,7 +113,8 @@ public class SopHelper {
} }
if (CollectionUtils.isNotEmpty(customerInfoList)) { if (CollectionUtils.isNotEmpty(customerInfoList)) {
// 距离旅程相差天数过滤 // 距离旅程相差天数过滤
return customerInfoList.stream().filter(index -> SopHelper.diffDay(index.getSopJourneyStageEnterTime(), Integer.parseInt(diffday))).collect(Collectors.toList()); return customerInfoList.stream().filter(index -> SopHelper.diffDay(index.getSopJourneyStageEnterTime(), Integer.parseInt(diffday)))
.collect(Collectors.toList());
} }
return null; return null;
} }
...@@ -145,7 +151,8 @@ public class SopHelper { ...@@ -145,7 +151,8 @@ public class SopHelper {
} }
return null; return null;
} }
public static String getValueFromJsonString(String jsonString, String objectName, String objectNameTwo,String fieldName) {
public static String getValueFromJsonString(String jsonString, String objectName, String objectNameTwo, String fieldName) {
try { try {
ObjectMapper objectMapper = new ObjectMapper(); ObjectMapper objectMapper = new ObjectMapper();
JsonNode rootNode = objectMapper.readTree(jsonString); JsonNode rootNode = objectMapper.readTree(jsonString);
...@@ -159,7 +166,6 @@ public class SopHelper { ...@@ -159,7 +166,6 @@ public class SopHelper {
return null; return null;
} }
public static String getValueFromJsonString(String jsonString, String fieldName) { public static String getValueFromJsonString(String jsonString, String fieldName) {
try { try {
ObjectMapper objectMapper = new ObjectMapper(); ObjectMapper objectMapper = new ObjectMapper();
...@@ -176,7 +182,6 @@ public class SopHelper { ...@@ -176,7 +182,6 @@ public class SopHelper {
return null; return null;
} }
public static <T> T post(MultiValueMap<String, String> paramsMap, Class<T> responseType, String baseurl, String method) throws Exception { public static <T> T post(MultiValueMap<String, String> paramsMap, Class<T> responseType, String baseurl, String method) throws Exception {
addBaseParam(paramsMap, method); addBaseParam(paramsMap, method);
MultiValueMap<String, String> params = getSysParams(); MultiValueMap<String, String> params = getSysParams();
...@@ -268,12 +273,11 @@ public class SopHelper { ...@@ -268,12 +273,11 @@ public class SopHelper {
paramsMap.add("name", "zhouhb"); paramsMap.add("name", "zhouhb");
} }
public static int days(String year, String month, String day) { public static int days(String year, String month, String day) {
int days = 0; int days = 0;
int nowyear = Integer.parseInt(year); int nowyear = Integer.parseInt(year);
int[] monthday = {0, 31, 28, 31, 30, 31, 30, 31, 31, 30, 31, 30, 31}; int[] monthday = { 0, 31, 28, 31, 30, 31, 30, 31, 31, 30, 31, 30, 31 };
int[] monthday1 = {0, 31, 29, 31, 30, 31, 30, 31, 31, 30, 31, 30, 31}; int[] monthday1 = { 0, 31, 29, 31, 30, 31, 30, 31, 31, 30, 31, 30, 31 };
boolean flag = true; boolean flag = true;
if (nowyear % 4 == 0 && nowyear % 100 != 0 || nowyear % 400 == 0) { if (nowyear % 4 == 0 && nowyear % 100 != 0 || nowyear % 400 == 0) {
} else { } else {
......
...@@ -39,17 +39,14 @@ public interface SopNodeExecutor { ...@@ -39,17 +39,14 @@ public interface SopNodeExecutor {
* @return * @return
*/ */
default SnapshotStruct prepare(SopStruct sop, SopInstNode node) { default SnapshotStruct prepare(SopStruct sop, SopInstNode node) {
SnapshotStruct es = new SnapshotStruct(); SnapshotStruct es = JacksonUtils.fromJson(sop.getInst().getInstSnapshot(), SnapshotStruct.class);
if (StrUtil.length(sop.getInst().getInstSnapshot()) > 4) {
// 继承参数
es = JacksonUtils.fromJson(sop.getInst().getInstSnapshot(), SnapshotStruct.class);
} else {
// 启动参数 // 启动参数
if (StrUtil.isNotEmpty(sop.getInst().getInstParam())) { if (StrUtil.isNotEmpty(sop.getInst().getInstParam())) {
es.getInitMap().clear();
// 重新生成初始化参数
JSONObject paramObj = JSONUtil.parseObj(sop.getInst().getInstParam()); JSONObject paramObj = JSONUtil.parseObj(sop.getInst().getInstParam());
es.getInitMap().putAll(paramObj); es.getInitMap().putAll(paramObj);
} }
}
es.getInitMap().put("instId", sop.getInst().getInstId()); es.getInitMap().put("instId", sop.getInst().getInstId());
......
...@@ -7,6 +7,7 @@ import org.springframework.stereotype.Service; ...@@ -7,6 +7,7 @@ import org.springframework.stereotype.Service;
import com.alibaba.fastjson.JSON; import com.alibaba.fastjson.JSON;
import com.alibaba.fastjson.JSONObject; import com.alibaba.fastjson.JSONObject;
import cn.com.glsx.process.job.xxljob.core.SopXxlJobUtil;
import cn.com.glsx.process.modules.entity.SopInst; import cn.com.glsx.process.modules.entity.SopInst;
import cn.com.glsx.process.modules.entity.SopInstNode; import cn.com.glsx.process.modules.entity.SopInstNode;
import cn.com.glsx.process.modules.model.SopStruct; import cn.com.glsx.process.modules.model.SopStruct;
...@@ -46,7 +47,7 @@ public class JavaExecutor implements SopNodeExecutor { ...@@ -46,7 +47,7 @@ public class JavaExecutor implements SopNodeExecutor {
// 处理返回结果 // 处理返回结果
return instance; return instance;
} catch (Exception e) { } catch (Exception e) {
e.printStackTrace(); SopXxlJobUtil.log(log, "【{}】{}", getClass().getSimpleName(), e.getMessage(), e);
} }
return null; return null;
......
package cn.com.glsx.process.modules.sop.execute.executor; package cn.com.glsx.process.modules.sop.execute.executor;
import java.util.Map;
import org.springframework.beans.factory.annotation.Autowired; import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service; import org.springframework.stereotype.Service;
import com.alibaba.fastjson.JSON; import com.alibaba.fastjson.JSON;
import com.alibaba.fastjson.JSONObject; import com.alibaba.fastjson.JSONObject;
import cn.com.glsx.process.common.constant.Constants; import cn.com.glsx.process.job.xxljob.core.SopXxlJobUtil;
import cn.com.glsx.process.modules.entity.SopDataSource; import cn.com.glsx.process.modules.entity.SopDataSource;
import cn.com.glsx.process.modules.entity.SopInstNode; import cn.com.glsx.process.modules.entity.SopInstNode;
import cn.com.glsx.process.modules.model.SopStruct; import cn.com.glsx.process.modules.model.SopStruct;
...@@ -29,7 +27,6 @@ public class SqlExecutor implements SopNodeExecutor { ...@@ -29,7 +27,6 @@ public class SqlExecutor implements SopNodeExecutor {
@Override @Override
public Object execute(SopStruct sop, SopInstNode node, SnapshotStruct executeStruct) throws Exception { public Object execute(SopStruct sop, SopInstNode node, SnapshotStruct executeStruct) throws Exception {
Map<String, Object> resultMap = executeStruct.getResultMap();
try { try {
// 获取配置参数信息 // 获取配置参数信息
String nodeContent = node.getNodeContent(); String nodeContent = node.getNodeContent();
...@@ -49,9 +46,7 @@ public class SqlExecutor implements SopNodeExecutor { ...@@ -49,9 +46,7 @@ public class SqlExecutor implements SopNodeExecutor {
return "更新成功条数" + i; return "更新成功条数" + i;
} catch (Exception e) { } catch (Exception e) {
String message = e.getMessage(); SopXxlJobUtil.log(log, "【{}】{}", getClass().getSimpleName(), e.getMessage(), e);
resultMap.put(Constants.RES_FAIL_MESSAGE, message);
resultMap.put(Constants.RES_KEY, Constants.RES_FAIL);
} }
return null; return null;
} }
......
...@@ -10,6 +10,7 @@ import org.springframework.stereotype.Service; ...@@ -10,6 +10,7 @@ import org.springframework.stereotype.Service;
import com.alibaba.fastjson.JSON; import com.alibaba.fastjson.JSON;
import com.alibaba.fastjson.JSONObject; import com.alibaba.fastjson.JSONObject;
import cn.com.glsx.process.job.xxljob.core.SopXxlJobUtil;
import cn.com.glsx.process.modules.entity.SopDataSource; import cn.com.glsx.process.modules.entity.SopDataSource;
import cn.com.glsx.process.modules.entity.SopInstNode; import cn.com.glsx.process.modules.entity.SopInstNode;
import cn.com.glsx.process.modules.model.SopStruct; import cn.com.glsx.process.modules.model.SopStruct;
...@@ -48,7 +49,7 @@ public class SqlQueryExecutor implements SopNodeExecutor { ...@@ -48,7 +49,7 @@ public class SqlQueryExecutor implements SopNodeExecutor {
// 处理执行结果 // 处理执行结果
return maps; return maps;
} catch (Exception e) { } catch (Exception e) {
e.printStackTrace(); SopXxlJobUtil.log(log, "【{}】{}", getClass().getSimpleName(), e.getMessage(), e);
} }
return null; return null;
} }
......
...@@ -38,7 +38,7 @@ ...@@ -38,7 +38,7 @@
</update> </update>
<update id="updateInstBatchNo"> <update id="updateInstBatchNo">
UPDATE sop_inst SET batch_no = #{batchNo} WHERE inst_id = #{instId} UPDATE sop_inst SET batch_no = #{batchNo}, inst_snapshot=#{snapshot} WHERE inst_id = #{instId}
</update> </update>
<select id="selectByGroupId" resultMap="BaseResultMap"> <select id="selectByGroupId" resultMap="BaseResultMap">
......
Markdown is supported
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!