Commit 550021ef by 谢海旭

新增模板接口:增加触达节点key处理

1 parent 6f201f61
...@@ -8,11 +8,10 @@ import cn.com.glsx.process.modules.entity.SopTplNode; ...@@ -8,11 +8,10 @@ import cn.com.glsx.process.modules.entity.SopTplNode;
import cn.com.glsx.process.modules.entity.SopTplNodeProto; import cn.com.glsx.process.modules.entity.SopTplNodeProto;
import cn.com.glsx.process.modules.mapper.SopTplNodeProtoMapper; import cn.com.glsx.process.modules.mapper.SopTplNodeProtoMapper;
import cn.com.glsx.process.modules.model.SopTplDTO; import cn.com.glsx.process.modules.model.SopTplDTO;
import cn.com.glsx.process.util.CronUtil;
import cn.com.glsx.process.util.JacksonUtil; import cn.com.glsx.process.util.JacksonUtil;
import cn.com.glsx.process.util.JacksonUtils; import cn.com.glsx.process.util.JacksonUtils;
import cn.hutool.core.util.StrUtil;
import com.fasterxml.jackson.core.type.TypeReference; import com.fasterxml.jackson.core.type.TypeReference;
import com.glsx.plat.common.utils.SnowFlake;
import com.google.common.collect.Lists; import com.google.common.collect.Lists;
import lombok.extern.slf4j.Slf4j; import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.factory.annotation.Autowired; import org.springframework.beans.factory.annotation.Autowired;
...@@ -87,23 +86,34 @@ public class KeHuLvChengAssembler { ...@@ -87,23 +86,34 @@ public class KeHuLvChengAssembler {
//有阶段 //有阶段
SopTplNodeProto stageProto = getGroupFirstProto(tplNodeProtos, dataTypeCode, "stage"); SopTplNodeProto stageProto = getGroupFirstProto(tplNodeProtos, dataTypeCode, "stage");
Map<String, Map<String, Object>> stages = JacksonUtils.fromJson(stagesStr, new TypeReference<Map<String, Map<String, Object>>>() {});; Map<String, Map<String, Object>> stages = JacksonUtils.fromJson(stagesStr, new TypeReference<Map<String, Map<String, Object>>>() {
});
;
//阶段与其生成的节点的对应关系 //阶段与其生成的节点的对应关系
HashMap<String, SopTplNode> stageNodeMap = new HashMap<>(); Map<String, SopTplNode> stageNodeMap = new HashMap<>();
//阶段与其排序后的序号的对应关系
Map<String, Integer> stageOrderMap = new HashMap<>();
//创建阶段对应的节点 //创建阶段对应的节点
String stageNodeParamDefModel = "{\"stage\":{\"paramKey\":\"stage\",\"defaultValue\":\"\",\"required\":true,\"paramDesc\":\"stage\",\"valueType\":\"String\"}}"; String stageNodeParamDefModel = "{\"stage\":{\"paramKey\":\"stage\",\"defaultValue\":\"\",\"required\":true,\"paramDesc\":\"stage\",\"valueType\":\"String\"}}";
for (String key : stages.keySet()) {
Map<String, Object> stageSettingMap = stages.get(key); List<String> stageSortedKeys = new ArrayList<>(stages.keySet());
Collections.sort(stageSortedKeys);
int stageSize = stageSortedKeys.size();
for (int i = 0; i < stageSize; i++) {
int stageOrder = i + 1;
Map<String, Object> stageSettingMap = stages.get(stageSortedKeys.get(i));
String stageValue = (String) stageSettingMap.get("value"); String stageValue = (String) stageSettingMap.get("value");
//TODO 可能需要定义node的key属性
SopTplNode stageNode = protoConverter.proto2tpl(stageProto); SopTplNode stageNode = protoConverter.proto2tpl(stageProto);
stageNode.setNodeId(tplNodeLastNum++); stageNode.setNodeId(tplNodeLastNum++);
stageNode.setNodeParamDef(JacksonUtil.jsonStrDeepSub(stageNodeParamDefModel, String.format("{\"stage\":{\"defaultValue\":\"%s\"}}", stageValue))); stageNode.setNodeParamDef(JacksonUtil.jsonStrDeepSub(stageNodeParamDefModel, String.format("{\"stage\":{\"defaultValue\":\"%s\"}}", stageValue)));
stageNode.setNodeKey(String.format("%s%d", stageProto.getNodeKey(), stageOrder));
tplNodes.add(stageNode); tplNodes.add(stageNode);
addLink(getDataTplNode, stageNode, tplNodeLinks); addLink(getDataTplNode, stageNode, tplNodeLinks);
stageNodeMap.put(stageValue, stageNode); stageNodeMap.put(stageValue, stageNode);
stageOrderMap.put(stageValue, stageOrder);
} }
List<SopTplNode> notifyNodes = sopTplDTO.getNodes(); List<SopTplNode> notifyNodes = sopTplDTO.getNodes();
...@@ -127,7 +137,14 @@ public class KeHuLvChengAssembler { ...@@ -127,7 +137,14 @@ public class KeHuLvChengAssembler {
SopTplNode notifyTplNode = protoConverter.proto2tpl(sopTplNodeProto); SopTplNode notifyTplNode = protoConverter.proto2tpl(sopTplNodeProto);
notifyTplNode.setNodeId(tplNodeLastNum++); notifyTplNode.setNodeId(tplNodeLastNum++);
notifyTplNode.setNodeParamDef(JacksonUtil.jsonStrDeepSub(notifyTplNode.getNodeParamDef(), sopTplNode.getNodeParamDef())); notifyTplNode.setNodeKey(String.format("%s%d", sopTplNodeProto.getNodeKey(), notifyTplNode.getNodeId()));
String nodeParamDef = JacksonUtil.jsonStrDeepSub(notifyTplNode.getNodeParamDef(), sopTplNode.getNodeParamDef());
nodeParamDef = JacksonUtil.jsonStrDeepSub(nodeParamDef, String.format("{\"stageid\": {\"defaultValue\": %d}}", stageOrderMap.get(key)));
notifyTplNode.setNodeParamDef(nodeParamDef);
String timeStr = JacksonUtil.getStrValueInJsonStrByPath(notifyTplNode.getNodeParamDef(), "time/defaultValue");
notifyTplNode.setNodeCron(CronUtil.timeStr2Cron(timeStr, CronUtil.TIME_PATTERN_HM));
tplNodes.add(notifyTplNode); tplNodes.add(notifyTplNode);
addLink(stageNodeMap.get(key), notifyTplNode, tplNodeLinks); addLink(stageNodeMap.get(key), notifyTplNode, tplNodeLinks);
......
package cn.com.glsx.process.util;
import cn.com.glsx.process.common.sysenum.ResultEnum;
import cn.com.glsx.process.exception.AdminException;
import lombok.experimental.UtilityClass;
import lombok.extern.slf4j.Slf4j;
import java.text.ParseException;
import java.text.SimpleDateFormat;
import java.util.Date;
/**
* cron表达式工具
*/
@Slf4j
@UtilityClass
public class CronUtil {
public static final String TIME_PATTERN_HM = "HH:mm";
public static final String TIME_PATTERN_HMS = "HH:mm:ss";
/**
* 时间转cron表达式
*
* @param timeStr 时间字符串
* @param pattern 时间字符串格式 如"HH:mm"或"HH:mm:ss"
* @return
*/
public String timeStr2Cron(String timeStr, String pattern) {
try {
SimpleDateFormat sdf = new SimpleDateFormat(pattern);
Date time = sdf.parse(timeStr);
// 将时间转换成克隆表达式的格式
SimpleDateFormat cronSdf = new SimpleDateFormat("s m H * * ?");
return cronSdf.format(time);
} catch (ParseException e) {
log.error("时间字符串转cron表达式失败 time:{} pattern:{}, msg:{}", timeStr, pattern, e.getMessage());
throw new AdminException(ResultEnum.PARAM_ERROR.getCode(), "时间字符串转cron表达式失败");
}
}
}
\ 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!