Commit 9163161f by 谢海旭

新增模板 接口调整

1 parent b6bc4379
...@@ -51,10 +51,10 @@ public class SopTpl { ...@@ -51,10 +51,10 @@ public class SopTpl {
@Column(name = "tpl_singleton") @Column(name = "tpl_singleton")
private Byte tplSingleton; private Byte tplSingleton;
@Column(name = "create_time") @Column(name = "create_time", insertable = false, updatable = false)
private Date createTime; private Date createTime;
@Column(name = "update_time") @Column(name = "update_time", insertable = false, updatable = false)
private Date updateTime; private Date updateTime;
/** /**
......
...@@ -33,12 +33,21 @@ public class SopTplNodeProto { ...@@ -33,12 +33,21 @@ public class SopTplNodeProto {
@Column(name = "node_show") @Column(name = "node_show")
private String nodeShow; private String nodeShow;
@Column(name = "node_param_def")
private String nodeParamDef;
@Column(name = "node_content_def")
private String nodeContentDef;
/** /**
* 节点的访问key,复制时不可变 * 节点的访问key,复制时不可变
*/ */
@Column(name = "node_key") @Column(name = "node_key")
private String nodeKey; private String nodeKey;
@Column(name = "node_result_def")
private String nodeResultDef;
/** /**
* 节点可见状态,复制时不可变 * 节点可见状态,复制时不可变
*/ */
...@@ -215,6 +224,30 @@ public class SopTplNodeProto { ...@@ -215,6 +224,30 @@ public class SopTplNodeProto {
this.nodeKey = nodeKey == null ? null : nodeKey.trim(); this.nodeKey = nodeKey == null ? null : nodeKey.trim();
} }
public String getNodeParamDef() {
return nodeParamDef;
}
public void setNodeParamDef(String nodeParamDef) {
this.nodeParamDef = nodeParamDef;
}
public String getNodeContentDef() {
return nodeContentDef;
}
public void setNodeContentDef(String nodeContentDef) {
this.nodeContentDef = nodeContentDef;
}
public String getNodeResultDef() {
return nodeResultDef;
}
public void setNodeResultDef(String nodeResultDef) {
this.nodeResultDef = nodeResultDef;
}
/** /**
* 获取节点可见状态,复制时不可变 * 获取节点可见状态,复制时不可变
* *
......
...@@ -40,6 +40,7 @@ public class KeHuLvChengAssembler { ...@@ -40,6 +40,7 @@ public class KeHuLvChengAssembler {
/** /**
* 客户旅程模板组装 * 客户旅程模板组装
* TODO 需要增加 触发时间转换为cron表达式,保存到对应字段里
* *
* @param sopTplDTO * @param sopTplDTO
*/ */
...@@ -91,7 +92,7 @@ public class KeHuLvChengAssembler { ...@@ -91,7 +92,7 @@ public class KeHuLvChengAssembler {
//阶段与其生成的节点的对应关系 //阶段与其生成的节点的对应关系
HashMap<String, SopTplNode> stageNodeMap = new HashMap<>(); HashMap<String, SopTplNode> stageNodeMap = 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()) { for (String key : stages.keySet()) {
Map<String, Object> stageSettingMap = stages.get(key); Map<String, Object> stageSettingMap = stages.get(key);
String stageValue = (String) stageSettingMap.get("value"); String stageValue = (String) stageSettingMap.get("value");
...@@ -99,7 +100,7 @@ public class KeHuLvChengAssembler { ...@@ -99,7 +100,7 @@ public class KeHuLvChengAssembler {
//TODO 可能需要定义node的key属性 //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)));
tplNodes.add(stageNode); tplNodes.add(stageNode);
addLink(getDataTplNode, stageNode, tplNodeLinks); addLink(getDataTplNode, stageNode, tplNodeLinks);
...@@ -115,7 +116,7 @@ public class KeHuLvChengAssembler { ...@@ -115,7 +116,7 @@ public class KeHuLvChengAssembler {
for (String key : stageNodeMap.keySet()) { for (String key : stageNodeMap.keySet()) {
// 阶段下的节点 // 阶段下的节点
List<SopTplNode> stageNotifyNodes = notifyNodes.stream().filter(sopTplNode -> { List<SopTplNode> stageNotifyNodes = notifyNodes.stream().filter(sopTplNode -> {
String nodeStage = JacksonUtil.getStrValueInJsonStrByPath(sopTplNode.getNodeParamDef(), "stage/stages"); String nodeStage = JacksonUtil.getStrValueInJsonStrByPath(sopTplNode.getNodeParamDef(), "stage/defaultValue");
return key.equals(nodeStage); return key.equals(nodeStage);
}).collect(Collectors.toList()); }).collect(Collectors.toList());
...@@ -164,6 +165,8 @@ public class KeHuLvChengAssembler { ...@@ -164,6 +165,8 @@ public class KeHuLvChengAssembler {
addLink(getDataTplNode, endTplNode, tplNodeLinks); addLink(getDataTplNode, endTplNode, tplNodeLinks);
} }
sopTplDTO.setNodes(tplNodes);
sopTplDTO.setLinks(tplNodeLinks);
} }
/** /**
...@@ -174,14 +177,14 @@ public class KeHuLvChengAssembler { ...@@ -174,14 +177,14 @@ public class KeHuLvChengAssembler {
*/ */
private String getTplParamDef(String dataTypeCode) { private String getTplParamDef(String dataTypeCode) {
if ("xbpzj".equals(dataTypeCode)) { if ("xbpzj".equals(dataTypeCode)) {
return "{\\\"customData\\\":{\\\"paramKey\\\":\\\"customData\\\",\\\"defaultValue\\\":{\\\"textMessage\\\":null,\\\"activityName\\\":null,\\\"activityId\\\":null,\\\"activityUrl\\\":null,\\\"aiSpeech\\\":null},\\\"required\\\":true,\\\"paramDesc\\\":\\\"customData\\\",\\\"valueType\\\":\\\"Map\\\"},\\\"merchantId\\\":{\\\"paramKey\\\":\\\"merchantId\\\",\\\"defaultValue\\\":\\\"\\\",\\\"required\\\":true,\\\"paramDesc\\\":\\\"merchantId\\\",\\\"valueType\\\":\\\"String\\\"},\\\"stages\\\":{\\\"paramKey\\\":\\\"stages\\\",\\\"defaultValue\\\":{},\\\"required\\\":true,\\\"paramDesc\\\":\\\"stages\\\",\\\"valueType\\\":\\\"Map\\\"},\\\"dataTypeCode\\\":{\\\"paramKey\\\":\\\"dataTypeCode\\\",\\\"defaultValue\\\":\\\"圈人方式标识码\\\",\\\"required\\\":true,\\\"paramDesc\\\":\\\"dataTypeCode\\\",\\\"valueType\\\":\\\"String\\\"}}"; return "{\"customData\":{\"paramKey\":\"customData\",\"defaultValue\":{\"textMessage\":null,\"activityName\":null,\"activityId\":null,\"activityUrl\":null,\"aiSpeech\":null},\"required\":true,\"paramDesc\":\"customData\",\"valueType\":\"Map\"},\"merchantId\":{\"paramKey\":\"merchantId\",\"defaultValue\":\"\",\"required\":true,\"paramDesc\":\"merchantId\",\"valueType\":\"String\"},\"stages\":{\"paramKey\":\"stages\",\"defaultValue\":{},\"required\":true,\"paramDesc\":\"stages\",\"valueType\":\"Map\"},\"dataTypeCode\":{\"paramKey\":\"dataTypeCode\",\"defaultValue\":\"圈人方式标识码\",\"required\":true,\"paramDesc\":\"dataTypeCode\",\"valueType\":\"String\"}}";
} else { } else {
return "{\\\"merchantId\\\":{\\\"paramKey\\\":\\\"merchantId\\\",\\\"defaultValue\\\":\\\"\\\",\\\"required\\\":true,\\\"paramDesc\\\":\\\"merchantId\\\",\\\"valueType\\\":\\\"String\\\"},\\\"stages\\\":{\\\"paramKey\\\":\\\"stages\\\",\\\"defaultValue\\\":{},\\\"required\\\":true,\\\"paramDesc\\\":\\\"stages\\\",\\\"valueType\\\":\\\"Map\\\"},\\\"dataTypeCode\\\":{\\\"paramKey\\\":\\\"dataTypeCode\\\",\\\"defaultValue\\\":\\\"圈人方式标识码\\\",\\\"required\\\":true,\\\"paramDesc\\\":\\\"dataTypeCode\\\",\\\"valueType\\\":\\\"String\\\"}}"; return "{\"merchantId\":{\"paramKey\":\"merchantId\",\"defaultValue\":\"\",\"required\":true,\"paramDesc\":\"merchantId\",\"valueType\":\"String\"},\"stages\":{\"paramKey\":\"stages\",\"defaultValue\":{},\"required\":true,\"paramDesc\":\"stages\",\"valueType\":\"Map\"},\"dataTypeCode\":{\"paramKey\":\"dataTypeCode\",\"defaultValue\":\"圈人方式标识码\",\"required\":true,\"paramDesc\":\"dataTypeCode\",\"valueType\":\"String\"}}";
} }
} }
/** /**
* 获取指定节点原型组第一个节点原型 * 获取指定 节点原型组 第一个 节点原型
* *
* @param tplNodeProtos * @param tplNodeProtos
* @param dataTypeCodeStr * @param dataTypeCodeStr
...@@ -189,15 +192,17 @@ public class KeHuLvChengAssembler { ...@@ -189,15 +192,17 @@ public class KeHuLvChengAssembler {
* @return * @return
*/ */
private static SopTplNodeProto getGroupFirstProto(List<SopTplNodeProto> tplNodeProtos, String dataTypeCodeStr, String groupCode) { private static SopTplNodeProto getGroupFirstProto(List<SopTplNodeProto> tplNodeProtos, String dataTypeCodeStr, String groupCode) {
SopTplNodeProto endProto = tplNodeProtos.stream().filter(sopTplNodeProto -> sopTplNodeProto.getDataTypeCode().equals(dataTypeCodeStr) && sopTplNodeProto.getGroupCode().equals(groupCode)).findFirst().get(); SopTplNodeProto nodeProto = tplNodeProtos.stream().filter(sopTplNodeProto -> dataTypeCodeStr.equals(sopTplNodeProto.getDataTypeCode()) && groupCode.equals(sopTplNodeProto.getGroupCode()))
if (Objects.isNull(endProto)) { .findFirst().orElse(null);
endProto = tplNodeProtos.stream().filter(sopTplNodeProto -> Objects.isNull(sopTplNodeProto.getDataTypeCode()) && sopTplNodeProto.getGroupCode().equals(groupCode)).findFirst().get(); if (Objects.isNull(nodeProto)) {
nodeProto = tplNodeProtos.stream().filter(sopTplNodeProto -> Objects.isNull(sopTplNodeProto.getDataTypeCode()) && sopTplNodeProto.getGroupCode().equals(groupCode))
.findFirst().orElse(null);
} }
return endProto; return nodeProto;
} }
/** /**
* 添加链接 * 添加节点链接
* *
* @param sourceTplNode * @param sourceTplNode
* @param targetTplNode * @param targetTplNode
......
...@@ -12,10 +12,11 @@ public interface SopTplNodeProtoConverter { ...@@ -12,10 +12,11 @@ public interface SopTplNodeProtoConverter {
SopTplNodeProtoConverter INSTANCE = Mappers.getMapper(SopTplNodeProtoConverter.class); SopTplNodeProtoConverter INSTANCE = Mappers.getMapper(SopTplNodeProtoConverter.class);
//TODO 添加必要的字段映射 @Mappings({
// @Mappings({ @Mapping(ignore = true, source = "id", target = "id"),
// @Mapping(source = "nodeAsync", target = "nodeAsync"), @Mapping(source = "id", target = "nodeProtoId"),
// @Mapping(source = "nodeParamDef", target = "nodeParam"), @Mapping(source = "nodeParamDef", target = "nodeParamDef"),
// @Mapping(source = "nodeContentDef", target = "nodeContent")}) @Mapping(source = "nodeContentDef", target = "nodeContentDef"),
@Mapping(source = "nodeResultDef", target = "nodeResultDef")})
SopTplNode proto2tpl(SopTplNodeProto nodeProto); SopTplNode proto2tpl(SopTplNodeProto nodeProto);
} }
...@@ -13,6 +13,7 @@ import com.fasterxml.jackson.core.JsonParseException; ...@@ -13,6 +13,7 @@ import com.fasterxml.jackson.core.JsonParseException;
import com.fasterxml.jackson.databind.JavaType; import com.fasterxml.jackson.databind.JavaType;
import com.fasterxml.jackson.databind.JsonMappingException; import com.fasterxml.jackson.databind.JsonMappingException;
import com.fasterxml.jackson.databind.ObjectMapper; import com.fasterxml.jackson.databind.ObjectMapper;
import org.springframework.util.StringUtils;
public class JacksonUtil { public class JacksonUtil {
private static Logger logger = LoggerFactory.getLogger(JacksonUtil.class); private static Logger logger = LoggerFactory.getLogger(JacksonUtil.class);
...@@ -108,7 +109,11 @@ public class JacksonUtil { ...@@ -108,7 +109,11 @@ public class JacksonUtil {
} }
} }
if (currentNode instanceof ObjectNode) {
return currentNode.toString();
} else {
return currentNode.asText(); return currentNode.asText();
}
} catch (JsonProcessingException e) { } catch (JsonProcessingException e) {
logger.error(e.getMessage(), e); logger.error(e.getMessage(), e);
} }
...@@ -127,6 +132,9 @@ public class JacksonUtil { ...@@ -127,6 +132,9 @@ public class JacksonUtil {
*/ */
public static String jsonStrDeepSub(String original, String update) { public static String jsonStrDeepSub(String original, String update) {
try { try {
if (!StringUtils.hasLength(original)) {
original = "{}";
}
ObjectMapper mapper = new ObjectMapper(); ObjectMapper mapper = new ObjectMapper();
JsonNode originalNode = mapper.readTree(original); JsonNode originalNode = mapper.readTree(original);
JsonNode updateNode = mapper.readTree(update); JsonNode updateNode = mapper.readTree(update);
......
Markdown is supported
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!