Commit 4f4f4d42 by 谢海旭

优化

1 parent 00143b0d
...@@ -16,6 +16,7 @@ import com.google.common.collect.Lists; ...@@ -16,6 +16,7 @@ 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;
import org.springframework.stereotype.Component; import org.springframework.stereotype.Component;
import org.springframework.util.Assert;
import org.springframework.util.CollectionUtils; import org.springframework.util.CollectionUtils;
import org.springframework.util.StringUtils; import org.springframework.util.StringUtils;
import tk.mybatis.mapper.entity.Example; import tk.mybatis.mapper.entity.Example;
...@@ -43,6 +44,8 @@ public class KeHuLvChengAssembler { ...@@ -43,6 +44,8 @@ public class KeHuLvChengAssembler {
*/ */
private static final String STAGE_TPL_NODE_PARAM_DEF_TPL = "{\"stage\":{\"paramKey\":\"stage\",\"defaultValue\":\"\",\"required\":true,\"paramDesc\":\"stage\",\"valueType\":\"String\"}}"; private static final String STAGE_TPL_NODE_PARAM_DEF_TPL = "{\"stage\":{\"paramKey\":\"stage\",\"defaultValue\":\"\",\"required\":true,\"paramDesc\":\"stage\",\"valueType\":\"String\"}}";
private static final SopTplNodeProtoConverter PROTO_CONVERTER = SopTplNodeProtoConverter.INSTANCE;
@Autowired @Autowired
private SopTplNodeProtoMapper sopTplNodeProtoMapper; private SopTplNodeProtoMapper sopTplNodeProtoMapper;
...@@ -78,14 +81,13 @@ public class KeHuLvChengAssembler { ...@@ -78,14 +81,13 @@ public class KeHuLvChengAssembler {
//选择对应开始节点 //选择对应开始节点
SopTplNodeProto startProto = getGroupFirstProto(tplNodeProtos, dataTypeCode, "start"); SopTplNodeProto startProto = getGroupFirstProto(tplNodeProtos, dataTypeCode, "start");
SopTplNodeProtoConverter protoConverter = SopTplNodeProtoConverter.INSTANCE; SopTplNode startTplNode = PROTO_CONVERTER.proto2tpl(startProto);
SopTplNode startTplNode = protoConverter.proto2tpl(startProto);
startTplNode.setNodeId(tplNodeLastNum++); startTplNode.setNodeId(tplNodeLastNum++);
tplNodes.add(startTplNode); tplNodes.add(startTplNode);
//选择圈人节点 //选择圈人节点
SopTplNodeProto getDataProto = getGroupFirstProto(tplNodeProtos, dataTypeCode, "get_data"); SopTplNodeProto getDataProto = getGroupFirstProto(tplNodeProtos, dataTypeCode, "get_data");
SopTplNode getDataTplNode = protoConverter.proto2tpl(getDataProto); SopTplNode getDataTplNode = PROTO_CONVERTER.proto2tpl(getDataProto);
getDataTplNode.setNodeId(tplNodeLastNum++); getDataTplNode.setNodeId(tplNodeLastNum++);
tplNodes.add(getDataTplNode); tplNodes.add(getDataTplNode);
...@@ -112,7 +114,7 @@ public class KeHuLvChengAssembler { ...@@ -112,7 +114,7 @@ public class KeHuLvChengAssembler {
Map<String, Object> stageSettingMap = stages.get(stageSortedKeys.get(i)); Map<String, Object> stageSettingMap = stages.get(stageSortedKeys.get(i));
String stageValue = (String) stageSettingMap.get("value"); String stageValue = (String) stageSettingMap.get("value");
SopTplNode stageNode = protoConverter.proto2tpl(stageProto); SopTplNode stageNode = PROTO_CONVERTER.proto2tpl(stageProto);
stageNode.setNodeId(tplNodeLastNum++); stageNode.setNodeId(tplNodeLastNum++);
stageNode.setNodeParamDef(JacksonUtil.jsonStrDeepSub(STAGE_TPL_NODE_PARAM_DEF_TPL, String.format("{\"stage\":{\"defaultValue\":\"%s\"}}", stageValue))); stageNode.setNodeParamDef(JacksonUtil.jsonStrDeepSub(STAGE_TPL_NODE_PARAM_DEF_TPL, String.format("{\"stage\":{\"defaultValue\":\"%s\"}}", stageValue)));
stageNode.setNodeKey(String.format("%s%d", stageProto.getNodeKey(), stageOrder)); stageNode.setNodeKey(String.format("%s%d", stageProto.getNodeKey(), stageOrder));
...@@ -141,22 +143,9 @@ public class KeHuLvChengAssembler { ...@@ -141,22 +143,9 @@ public class KeHuLvChengAssembler {
} else { } else {
for (SopTplNode sopTplNode : stageNotifyNodes) { for (SopTplNode sopTplNode : stageNotifyNodes) {
SopTplNodeProto sopTplNodeProto = nodeProtoMap.get(sopTplNode.getNodeProtoId()); SopTplNodeProto sopTplNodeProto = nodeProtoMap.get(sopTplNode.getNodeProtoId());
Assert.state(Objects.nonNull(sopTplNodeProto), "触达类型和圈人方式不匹配!");
SopTplNode notifyTplNode = protoConverter.proto2tpl(sopTplNodeProto); SopTplNode notifyTplNode = getNotifyNodeFromProto(sopTplNodeProto, tplNodeLastNum++, sopTplNode.getNodeParamDef(), stageOrderMap.get(key));
notifyTplNode.setNodeId(tplNodeLastNum++);
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");
if (!StringUtils.hasLength(timeStr)) {
throw new AdminException(ResultEnum.PARAM_ERROR.getCode(), "sop任务发送时间必传!");
}
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);
beforeUpdateStageNodes.add(notifyTplNode); beforeUpdateStageNodes.add(notifyTplNode);
...@@ -168,7 +157,7 @@ public class KeHuLvChengAssembler { ...@@ -168,7 +157,7 @@ public class KeHuLvChengAssembler {
} }
SopTplNodeProto updateStageProto = getGroupFirstProto(tplNodeProtos, dataTypeCode, "update_stage"); SopTplNodeProto updateStageProto = getGroupFirstProto(tplNodeProtos, dataTypeCode, "update_stage");
SopTplNode updateStageTplNode = protoConverter.proto2tpl(updateStageProto); SopTplNode updateStageTplNode = PROTO_CONVERTER.proto2tpl(updateStageProto);
updateStageTplNode.setNodeId(tplNodeLastNum++); updateStageTplNode.setNodeId(tplNodeLastNum++);
tplNodes.add(updateStageTplNode); tplNodes.add(updateStageTplNode);
...@@ -176,7 +165,7 @@ public class KeHuLvChengAssembler { ...@@ -176,7 +165,7 @@ public class KeHuLvChengAssembler {
// 添加结束节点 // 添加结束节点
SopTplNodeProto endProto = getGroupFirstProto(tplNodeProtos, dataTypeCode, "end"); SopTplNodeProto endProto = getGroupFirstProto(tplNodeProtos, dataTypeCode, "end");
SopTplNode endTplNode = protoConverter.proto2tpl(endProto); SopTplNode endTplNode = PROTO_CONVERTER.proto2tpl(endProto);
endTplNode.setNodeId(tplNodeLastNum++); endTplNode.setNodeId(tplNodeLastNum++);
tplNodes.add(endTplNode); tplNodes.add(endTplNode);
...@@ -185,7 +174,7 @@ public class KeHuLvChengAssembler { ...@@ -185,7 +174,7 @@ public class KeHuLvChengAssembler {
// 无阶段 // 无阶段
// 添加结束节点 // 添加结束节点
SopTplNodeProto endProto = getGroupFirstProto(tplNodeProtos, dataTypeCode, "end"); SopTplNodeProto endProto = getGroupFirstProto(tplNodeProtos, dataTypeCode, "end");
SopTplNode endTplNode = protoConverter.proto2tpl(endProto); SopTplNode endTplNode = PROTO_CONVERTER.proto2tpl(endProto);
endTplNode.setNodeId(tplNodeLastNum++); endTplNode.setNodeId(tplNodeLastNum++);
tplNodes.add(endTplNode); tplNodes.add(endTplNode);
...@@ -197,6 +186,34 @@ public class KeHuLvChengAssembler { ...@@ -197,6 +186,34 @@ public class KeHuLvChengAssembler {
} }
/** /**
* 封装sop触达节点
*
* @param tplNodeProto 触达节点原型
* @param nodeId 节点id
* @param nodeParamDef 页面传参的节点 nodeParamDef 参数
* @param stageid 节点所属阶段的顺序
* @return
*/
private SopTplNode getNotifyNodeFromProto(SopTplNodeProto tplNodeProto, Integer nodeId, String nodeParamDef, Integer stageid) {
SopTplNode notifyTplNode = PROTO_CONVERTER.proto2tpl(tplNodeProto);
notifyTplNode.setNodeId(nodeId);
notifyTplNode.setNodeKey(String.format("%s%d", tplNodeProto.getNodeKey(), notifyTplNode.getNodeId()));
nodeParamDef = JacksonUtil.jsonStrDeepSub(notifyTplNode.getNodeParamDef(), nodeParamDef);
nodeParamDef = JacksonUtil.jsonStrDeepSub(nodeParamDef, String.format("{\"stageid\": {\"defaultValue\": %d}}", stageid));
notifyTplNode.setNodeParamDef(nodeParamDef);
String timeStr = JacksonUtil.getStrValueInJsonStrByPath(notifyTplNode.getNodeParamDef(), "time/defaultValue");
if (!StringUtils.hasLength(timeStr)) {
throw new AdminException(ResultEnum.PARAM_ERROR.getCode(), "sop任务发送时间必传!");
}
notifyTplNode.setNodeCron(CronUtil.timeStr2Cron(timeStr, CronUtil.TIME_PATTERN_HM));
return notifyTplNode;
}
/**
* 获取指定 节点原型组 第一个 节点原型 * 获取指定 节点原型组 第一个 节点原型
* *
* @param tplNodeProtos * @param tplNodeProtos
......
Markdown is supported
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!