Commit b6bc4379 by 谢海旭

触达方式查询、圈人方式查询、新增模板 接口

1 parent 08f066f7
Showing 16 changed files with 528 additions and 10 deletions
...@@ -12,6 +12,7 @@ public class SopDataType { ...@@ -12,6 +12,7 @@ public class SopDataType {
/** /**
* 名称 * 名称
*/ */
@Column(name = "`name`")
private String name; private String name;
/** /**
...@@ -27,12 +28,13 @@ public class SopDataType { ...@@ -27,12 +28,13 @@ public class SopDataType {
/** /**
* 圈人方式简介 * 圈人方式简介
*/ */
@Column(name = "`desc`")
private String desc; private String desc;
@Column(name = "updated_time") @Column(name = "updated_time", insertable = false, updatable = false)
private Date updatedTime; private Date updatedTime;
@Column(name = "created_time") @Column(name = "created_time", insertable = false, updatable = false)
private Date createdTime; private Date createdTime;
/** /**
......
...@@ -14,6 +14,12 @@ public class SopTplNode { ...@@ -14,6 +14,12 @@ public class SopTplNode {
@Column(name = "id") @Column(name = "id")
private Integer id; private Integer id;
/**
* 模板节点原型id
*/
@Column(name = "node_proto_id")
private Integer nodeProtoId;
@Column(name = "node_id") @Column(name = "node_id")
private Integer nodeId; private Integer nodeId;
...@@ -115,7 +121,15 @@ public class SopTplNode { ...@@ -115,7 +121,15 @@ public class SopTplNode {
this.id = id; this.id = id;
} }
/** public Integer getNodeProtoId() {
return nodeProtoId;
}
public void setNodeProtoId(Integer nodeProtoId) {
this.nodeProtoId = nodeProtoId;
}
/**
* 获取节点id * 获取节点id
* *
* @return node_id - 节点id * @return node_id - 节点id
......
...@@ -96,18 +96,19 @@ public class SopTplNodeProto { ...@@ -96,18 +96,19 @@ public class SopTplNodeProto {
/** /**
* 节点描述 * 节点描述
*/ */
@Column(name = "`desc`")
private String desc; private String desc;
/** /**
* 更新时间 * 更新时间
*/ */
@Column(name = "updated_time") @Column(name = "updated_time", insertable = false, updatable = false)
private Date updatedTime; private Date updatedTime;
/** /**
* 创建时间 * 创建时间
*/ */
@Column(name = "created_time") @Column(name = "created_time", insertable = false, updatable = false)
private Date createdTime; private Date createdTime;
/** /**
......
...@@ -2,6 +2,8 @@ package cn.com.glsx.process.modules.mapper; ...@@ -2,6 +2,8 @@ package cn.com.glsx.process.modules.mapper;
import cn.com.glsx.process.modules.entity.SopDataType; import cn.com.glsx.process.modules.entity.SopDataType;
import com.glsx.plat.mybatis.mapper.CommonBaseMapper; import com.glsx.plat.mybatis.mapper.CommonBaseMapper;
import org.apache.ibatis.annotations.Mapper;
@Mapper
public interface SopDataTypeMapper extends CommonBaseMapper<SopDataType> { public interface SopDataTypeMapper extends CommonBaseMapper<SopDataType> {
} }
\ No newline at end of file \ No newline at end of file
...@@ -2,6 +2,11 @@ package cn.com.glsx.process.modules.mapper; ...@@ -2,6 +2,11 @@ package cn.com.glsx.process.modules.mapper;
import cn.com.glsx.process.modules.entity.SopTplNodeProto; import cn.com.glsx.process.modules.entity.SopTplNodeProto;
import com.glsx.plat.mybatis.mapper.CommonBaseMapper; import com.glsx.plat.mybatis.mapper.CommonBaseMapper;
import org.apache.ibatis.annotations.Mapper;
import java.util.List;
@Mapper
public interface SopTplNodeProtoMapper extends CommonBaseMapper<SopTplNodeProto> { public interface SopTplNodeProtoMapper extends CommonBaseMapper<SopTplNodeProto> {
List<SopTplNodeProto> list(SopTplNodeProto search);
} }
\ No newline at end of file \ No newline at end of file
package cn.com.glsx.process.modules.model;
import cn.hutool.db.Page;
/**
* @Title:
* @Description:
* @Author xiehx
* @Date 2023/12/21
**/
public class SopTplNodeProtoSearch extends Page {
@Override
public int getPageNumber() {
int pageNumber = super.getPageNumber();
return pageNumber == 0? 1: pageNumber;
}
}
package cn.com.glsx.process.modules.assembler;
import cn.com.glsx.process.common.sysenum.ResultEnum;
import cn.com.glsx.process.exception.AdminException;
import cn.com.glsx.process.modules.converter.SopTplNodeProtoConverter;
import cn.com.glsx.process.modules.entity.SopTplLink;
import cn.com.glsx.process.modules.entity.SopTplNode;
import cn.com.glsx.process.modules.entity.SopTplNodeProto;
import cn.com.glsx.process.modules.mapper.SopTplNodeProtoMapper;
import cn.com.glsx.process.modules.model.SopTplDTO;
import cn.com.glsx.process.util.JacksonUtil;
import cn.com.glsx.process.util.JacksonUtils;
import cn.hutool.core.util.StrUtil;
import com.fasterxml.jackson.core.type.TypeReference;
import com.glsx.plat.common.utils.SnowFlake;
import com.google.common.collect.Lists;
import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Component;
import org.springframework.util.CollectionUtils;
import org.springframework.util.StringUtils;
import tk.mybatis.mapper.entity.Example;
import tk.mybatis.mapper.util.Sqls;
import java.util.*;
import java.util.stream.Collectors;
/**
* @Title:
* @Description:
* @Author xiehx
* @Date 2023/12/21
**/
@Slf4j
@Component
public class KeHuLvChengAssembler {
@Autowired
private SopTplNodeProtoMapper sopTplNodeProtoMapper;
/**
* 客户旅程模板组装
*
* @param sopTplDTO
*/
public void assemble(SopTplDTO sopTplDTO) {
String tplParamDef = sopTplDTO.getTplParamDef();
String dataTypeCode = JacksonUtil.getStrValueInJsonStrByPath(tplParamDef, "dataTypeCode/defaultValue");
String stagesStr = JacksonUtil.getStrValueInJsonStrByPath(tplParamDef, "stages/defaultValue");
sopTplDTO.setTplId(StrUtil.sub(SnowFlake.nextSerialNumber(), 0, 8));
sopTplDTO.setTplCron("10 20 7 * * ?");
sopTplDTO.setTplRemark("运营端新增模板");
sopTplDTO.setTplStatus((byte) 1);
sopTplDTO.setTplSingleton((byte) 1);
sopTplDTO.setTplParamDef(JacksonUtil.jsonStrDeepSub(getTplParamDef(dataTypeCode), tplParamDef));
List<SopTplNodeProto> tplNodeProtos = sopTplNodeProtoMapper.selectByExample(
Example.builder(SopTplNodeProto.class).where(Sqls.custom().andEqualTo("dataTypeCode", dataTypeCode).orIsNull("dataTypeCode")).build());
if (CollectionUtils.isEmpty(tplNodeProtos) || tplNodeProtos.size() < 3) {
log.error("客户旅程 模板node节点原型配置错误,该模板至少三种节点原型");
throw new AdminException(ResultEnum.PARAM_ERROR.getCode(), "模板node节点原型配置错误");
}
//给模板node节点标记位置标识即模板中唯一标识
int tplNodeLastNum = 1;
List<SopTplNode> tplNodes = Lists.newArrayList();
List<SopTplLink> tplNodeLinks = Lists.newArrayList();
//选择对应开始节点
SopTplNodeProto startProto = getGroupFirstProto(tplNodeProtos, dataTypeCode, "start");
SopTplNodeProtoConverter protoConverter = SopTplNodeProtoConverter.INSTANCE;
SopTplNode startTplNode = protoConverter.proto2tpl(startProto);
startTplNode.setNodeId(tplNodeLastNum++);
tplNodes.add(startTplNode);
//选择圈人节点
SopTplNodeProto getDataProto = getGroupFirstProto(tplNodeProtos, dataTypeCode, "get_data");
SopTplNode getDataTplNode = protoConverter.proto2tpl(getDataProto);
getDataTplNode.setNodeId(tplNodeLastNum++);
tplNodes.add(getDataTplNode);
addLink(startTplNode, getDataTplNode, tplNodeLinks);
if (StringUtils.hasLength(stagesStr)) {
//有阶段
SopTplNodeProto stageProto = getGroupFirstProto(tplNodeProtos, dataTypeCode, "stage");
Map<String, Map<String, Object>> stages = JacksonUtils.fromJson(stagesStr, new TypeReference<Map<String, Map<String, Object>>>() {});;
//阶段与其生成的节点的对应关系
HashMap<String, SopTplNode> stageNodeMap = new HashMap<>();
//创建阶段对应的节点
String stageNodeParamDefModel = "{\\\"stage\\\":{\\\"paramKey\\\":\\\"stage\\\",\\\"defaultValue\\\":\\\"潜在客户\\\",\\\"required\\\":true,\\\"paramDesc\\\":\\\"stage\\\",\\\"valueType\\\":\\\"String\\\"}}";
for (String key : stages.keySet()) {
Map<String, Object> stageSettingMap = stages.get(key);
String stageValue = (String) stageSettingMap.get("value");
//TODO 可能需要定义node的key属性
SopTplNode stageNode = protoConverter.proto2tpl(stageProto);
stageNode.setNodeId(tplNodeLastNum++);
stageNode.setNodeParamDef(JacksonUtil.jsonStrDeepSub(stageNodeParamDefModel, String.format("{\\\"stage\\\":{\\\"defaultValue\\\":\\\"%s\\\"}}", stageValue)));
tplNodes.add(stageNode);
addLink(getDataTplNode, stageNode, tplNodeLinks);
stageNodeMap.put(stageValue, stageNode);
}
List<SopTplNode> notifyNodes = sopTplDTO.getNodes();
List<SopTplNode> beforeUpdateStageNodes = new ArrayList<>();
if (!CollectionUtils.isEmpty(notifyNodes)) {
Map<Integer, SopTplNodeProto> nodeProtoMap = tplNodeProtos.stream().filter(nodeProto -> nodeProto.getGroupCode().equals("notify"))
.collect(Collectors.toMap(SopTplNodeProto::getId, nodeProto -> nodeProto));
for (String key : stageNodeMap.keySet()) {
// 阶段下的节点
List<SopTplNode> stageNotifyNodes = notifyNodes.stream().filter(sopTplNode -> {
String nodeStage = JacksonUtil.getStrValueInJsonStrByPath(sopTplNode.getNodeParamDef(), "stage/stages");
return key.equals(nodeStage);
}).collect(Collectors.toList());
if (CollectionUtils.isEmpty(stageNotifyNodes)) {
beforeUpdateStageNodes.add(stageNodeMap.get(key));
} else {
for (SopTplNode sopTplNode : stageNotifyNodes) {
SopTplNodeProto sopTplNodeProto = nodeProtoMap.get(sopTplNode.getNodeProtoId());
SopTplNode notifyTplNode = protoConverter.proto2tpl(sopTplNodeProto);
notifyTplNode.setNodeId(tplNodeLastNum++);
notifyTplNode.setNodeParamDef(JacksonUtil.jsonStrDeepSub(notifyTplNode.getNodeParamDef(), sopTplNode.getNodeParamDef()));
tplNodes.add(notifyTplNode);
addLink(stageNodeMap.get(key), notifyTplNode, tplNodeLinks);
beforeUpdateStageNodes.add(notifyTplNode);
}
}
}
} else {
stageNodeMap.keySet().forEach(key -> beforeUpdateStageNodes.add(stageNodeMap.get(key)));
}
SopTplNodeProto updateStageProto = getGroupFirstProto(tplNodeProtos, dataTypeCode, "update_stage");
SopTplNode updateStageTplNode = protoConverter.proto2tpl(updateStageProto);
updateStageTplNode.setNodeId(tplNodeLastNum++);
tplNodes.add(updateStageTplNode);
beforeUpdateStageNodes.forEach(sopTplNode -> addLink(sopTplNode, updateStageTplNode, tplNodeLinks));
// 添加结束节点
SopTplNodeProto endProto = getGroupFirstProto(tplNodeProtos, dataTypeCode, "end");
SopTplNode endTplNode = protoConverter.proto2tpl(endProto);
endTplNode.setNodeId(tplNodeLastNum++);
tplNodes.add(endTplNode);
addLink(updateStageTplNode, endTplNode, tplNodeLinks);
} else {
// 无阶段
// 添加结束节点
SopTplNodeProto endProto = getGroupFirstProto(tplNodeProtos, dataTypeCode, "end");
SopTplNode endTplNode = protoConverter.proto2tpl(endProto);
endTplNode.setNodeId(tplNodeLastNum++);
tplNodes.add(endTplNode);
addLink(getDataTplNode, endTplNode, tplNodeLinks);
}
}
/**
* 根据圈人方式获取预定义初始化参数 tplParamDef
*
* @param dataTypeCode
* @return
*/
private String getTplParamDef(String 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\\\"}}";
} 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\\\"}}";
}
}
/**
* 获取指定节点原型组第一个节点原型
*
* @param tplNodeProtos
* @param dataTypeCodeStr
* @param groupCode
* @return
*/
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();
if (Objects.isNull(endProto)) {
endProto = tplNodeProtos.stream().filter(sopTplNodeProto -> Objects.isNull(sopTplNodeProto.getDataTypeCode()) && sopTplNodeProto.getGroupCode().equals(groupCode)).findFirst().get();
}
return endProto;
}
/**
* 添加链接
*
* @param sourceTplNode
* @param targetTplNode
* @param tplNodeLinks
*/
private static void addLink(SopTplNode sourceTplNode, SopTplNode targetTplNode, List<SopTplLink> tplNodeLinks) {
SopTplLink sopTplLink = new SopTplLink();
sopTplLink.setSourceId(sourceTplNode.getNodeId());
sopTplLink.setTargetId(targetTplNode.getNodeId());
tplNodeLinks.add(sopTplLink);
}
}
package cn.com.glsx.process.modules.controller;
import cn.com.glsx.process.modules.entity.SopDataType;
import cn.com.glsx.process.modules.service.SopDataTypeService;
import com.glsx.plat.core.annotation.ResponseResultBody;
import io.swagger.v3.oas.annotations.Operation;
import io.swagger.v3.oas.annotations.tags.Tag;
import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;
import java.util.List;
/**
* @Title:
* @Description:
* @Author xiehx
* @Date 2023/12/20
**/
@Slf4j
@Tag(name = "SOP圈人方式开放接口")
@RestController
@RequestMapping(value = "/sop/api/sopDataTypes")
@ResponseResultBody
public class SopDataTypeController {
@Autowired
private SopDataTypeService sopDataTypeService;
@Operation(summary = "圈人方式全部列表", description = "圈人方式全部列表")
@GetMapping("/list")
public List<SopDataType> list() {
return sopDataTypeService.list();
}
}
...@@ -4,10 +4,7 @@ import java.util.List; ...@@ -4,10 +4,7 @@ import java.util.List;
import javax.annotation.Resource; import javax.annotation.Resource;
import org.springframework.web.bind.annotation.GetMapping; import org.springframework.web.bind.annotation.*;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;
import com.github.pagehelper.PageInfo; import com.github.pagehelper.PageInfo;
import com.glsx.plat.core.annotation.ResponseResultBody; import com.glsx.plat.core.annotation.ResponseResultBody;
...@@ -48,4 +45,10 @@ public class SopTplController extends BaseController { ...@@ -48,4 +45,10 @@ public class SopTplController extends BaseController {
public SopTplDTO getById(@PathVariable("tplId") String tplId) { public SopTplDTO getById(@PathVariable("tplId") String tplId) {
return sopTplService.getById(tplId); return sopTplService.getById(tplId);
} }
@Operation(summary = "新增模板", description = "新增模板")
@PostMapping
public SopTpl add(@RequestBody SopTplDTO sopTplDTO) {
return sopTplService.add(sopTplDTO);
}
} }
package cn.com.glsx.process.modules.controller;
import cn.com.glsx.process.modules.entity.SopTplNodeProto;
import cn.com.glsx.process.modules.service.SopTplNodeProtoService;
import com.glsx.plat.core.annotation.ResponseResultBody;
import io.swagger.v3.oas.annotations.Operation;
import io.swagger.v3.oas.annotations.tags.Tag;
import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;
import java.util.List;
/**
* @Title:
* @Description:
* @Author xiehx
* @Date 2023/12/21
**/
@Slf4j
@Tag(name = "SOP触达类型开放接口")
@RestController
@RequestMapping(value = "/sop/api/SopTplNodeProtos")
@ResponseResultBody
public class SopTplNodeProtoController {
@Autowired
private SopTplNodeProtoService sopTplNodeProtoService;
@Operation(summary = "触达类型列表", description = "触达类型列表")
@GetMapping("/list")
public List<SopTplNodeProto> list(SopTplNodeProto search) {
return sopTplNodeProtoService.list(search);
}
}
package cn.com.glsx.process.modules.converter;
import cn.com.glsx.process.modules.entity.SopTplNode;
import cn.com.glsx.process.modules.entity.SopTplNodeProto;
import org.mapstruct.Mapper;
import org.mapstruct.Mapping;
import org.mapstruct.Mappings;
import org.mapstruct.factory.Mappers;
@Mapper
public interface SopTplNodeProtoConverter {
SopTplNodeProtoConverter INSTANCE = Mappers.getMapper(SopTplNodeProtoConverter.class);
//TODO 添加必要的字段映射
// @Mappings({
// @Mapping(source = "nodeAsync", target = "nodeAsync"),
// @Mapping(source = "nodeParamDef", target = "nodeParam"),
// @Mapping(source = "nodeContentDef", target = "nodeContent")})
SopTplNode proto2tpl(SopTplNodeProto nodeProto);
}
package cn.com.glsx.process.modules.service;
import cn.com.glsx.process.modules.entity.SopDataType;
import cn.com.glsx.process.modules.mapper.SopDataTypeMapper;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
import java.util.List;
/**
* @Title:
* @Description:
* @Author xiehx
* @Date 2023/12/21
**/
@Service
public class SopDataTypeService {
@Autowired
private SopDataTypeMapper sopDataTypeMapper;
public List<SopDataType> list() {
return sopDataTypeMapper.selectAll();
}
}
package cn.com.glsx.process.modules.service;
import cn.com.glsx.process.modules.entity.SopTplNodeProto;
import cn.com.glsx.process.modules.mapper.SopTplNodeProtoMapper;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
import java.util.List;
/**
* @Title:
* @Description:
* @Author xiehx
* @Date 2023/12/21
**/
@Service
public class SopTplNodeProtoService {
@Autowired
private SopTplNodeProtoMapper sopTplNodeProtoMapper;
public List<SopTplNodeProto> list(SopTplNodeProto search) {
return sopTplNodeProtoMapper.list(search);
}
}
...@@ -5,7 +5,10 @@ import java.util.Objects; ...@@ -5,7 +5,10 @@ import java.util.Objects;
import javax.annotation.Resource; import javax.annotation.Resource;
import cn.com.glsx.process.modules.assembler.KeHuLvChengAssembler;
import cn.com.glsx.process.modules.converter.SopTplConverter;
import cn.com.glsx.process.modules.entity.SopTpl; import cn.com.glsx.process.modules.entity.SopTpl;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service; import org.springframework.stereotype.Service;
import com.github.pagehelper.PageHelper; import com.github.pagehelper.PageHelper;
...@@ -18,6 +21,7 @@ import cn.com.glsx.process.modules.mapper.SopTplMapper; ...@@ -18,6 +21,7 @@ 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.SopTplDTO; import cn.com.glsx.process.modules.model.SopTplDTO;
import cn.com.glsx.process.modules.model.SopTplSearch; import cn.com.glsx.process.modules.model.SopTplSearch;
import org.springframework.transaction.annotation.Transactional;
@Service @Service
public class SopTplService { public class SopTplService {
...@@ -31,6 +35,9 @@ public class SopTplService { ...@@ -31,6 +35,9 @@ public class SopTplService {
@Resource @Resource
private SopTplLinkMapper sopTplLinkMapper; private SopTplLinkMapper sopTplLinkMapper;
@Autowired
private KeHuLvChengAssembler keHuLvChengAssembler;
public PageInfo<SopTplDTO> page(SopTplSearch search) { public PageInfo<SopTplDTO> page(SopTplSearch search) {
PageHelper.startPage(search.getPageNumber(), search.getPageSize()); PageHelper.startPage(search.getPageNumber(), search.getPageSize());
List<SopTplDTO> list = sopTplMapper.page(search); List<SopTplDTO> list = sopTplMapper.page(search);
...@@ -69,4 +76,23 @@ public class SopTplService { ...@@ -69,4 +76,23 @@ public class SopTplService {
public List<SopTpl> list() { public List<SopTpl> list() {
return sopTplMapper.selectAll(); return sopTplMapper.selectAll();
} }
@Transactional
public SopTpl add(SopTplDTO sopTplDTO) {
keHuLvChengAssembler.assemble(sopTplDTO);
SopTpl sopTpl = SopTplConverter.INSTANCE.dto2do(sopTplDTO);
sopTplMapper.insert(sopTpl);
String tplId = sopTpl.getTplId();
List<SopTplNode> nodes = sopTplDTO.getNodes();
nodes.forEach(sopTplNode -> sopTplNode.setTplId(tplId));
sopTplNodeMapper.insertList(nodes);
List<SopTplLink> links = sopTplDTO.getLinks();
links.forEach(sopTplLink -> sopTplLink.setTplId(tplId));
sopTplLinkMapper.insertList(links);
return sopTpl;
}
} }
...@@ -2,6 +2,9 @@ package cn.com.glsx.process.util; ...@@ -2,6 +2,9 @@ package cn.com.glsx.process.util;
import java.io.IOException; import java.io.IOException;
import com.fasterxml.jackson.core.JsonProcessingException;
import com.fasterxml.jackson.databind.JsonNode;
import com.fasterxml.jackson.databind.node.ObjectNode;
import org.slf4j.Logger; import org.slf4j.Logger;
import org.slf4j.LoggerFactory; import org.slf4j.LoggerFactory;
...@@ -82,4 +85,72 @@ public class JacksonUtil { ...@@ -82,4 +85,72 @@ public class JacksonUtil {
} }
return null; return null;
} }
/**
* 通过路径获取json字符串里对应的值
*
* @param json
* @param path json路径,如 aaa/bbb/ccc
* @return
*/
public static String getStrValueInJsonStrByPath(String json, String path) {
try {
ObjectMapper mapper = new ObjectMapper();
JsonNode rootNode = mapper.readTree(json);
String[] keys = path.split("/");
JsonNode currentNode = rootNode;
for (String key : keys) {
currentNode = currentNode.get(key);
if (currentNode == null) {
return null;
}
}
return currentNode.asText();
} catch (JsonProcessingException e) {
logger.error(e.getMessage(), e);
}
return null;
}
/**
* json字符串深度替换
* 存在就更新,不存在就新增
*
* @param original 原值json字符串
* @param update 新值json字符串
* @return
* @throws Exception
*/
public static String jsonStrDeepSub(String original, String update) {
try {
ObjectMapper mapper = new ObjectMapper();
JsonNode originalNode = mapper.readTree(original);
JsonNode updateNode = mapper.readTree(update);
updateJson((ObjectNode) originalNode, (ObjectNode) updateNode);
return originalNode.toString();
} catch (JsonProcessingException e) {
logger.error(e.getMessage(), e);
}
return null;
}
// 递归更新JSON节点
private static void updateJson(ObjectNode original, ObjectNode update) {
update.fields().forEachRemaining(entry -> {
String key = entry.getKey();
JsonNode value = entry.getValue();
if (original.has(key) && original.get(key).isObject() && value.isObject()) {
updateJson((ObjectNode) original.get(key), (ObjectNode) value);
} else {
original.set(key, value);
}
});
}
} }
...@@ -38,7 +38,7 @@ ...@@ -38,7 +38,7 @@
--> -->
id, node_name, node_type, node_label, node_show, node_key, node_visible, node_cron, id, node_name, node_type, node_label, node_show, node_key, node_visible, node_cron,
node_expire_cron, node_skipable, node_async, daily_limit, data_type_code, group_code, node_expire_cron, node_skipable, node_async, daily_limit, data_type_code, group_code,
action_code, desc, updated_time, created_time action_code, `desc`, updated_time, created_time
</sql> </sql>
<sql id="Blob_Column_List"> <sql id="Blob_Column_List">
<!-- <!--
...@@ -46,4 +46,22 @@ ...@@ -46,4 +46,22 @@
--> -->
node_param_def, node_content_def, node_result_def node_param_def, node_content_def, node_result_def
</sql> </sql>
<select id="list" resultMap="BaseResultMap">
select
<include refid="Base_Column_List"/>
from sop_tpl_node_proto
<where>
<if test="dataTypeCode != null and dataTypeCode != ''">
and data_type_code = #{dataTypeCode}
</if>
<if test="groupCode != null and groupCode != ''">
and group_code = #{groupCode}
</if>
<if test="actionCode != null and actionCode != ''">
and action_code = #{actionCode}
</if>
</where>
</select>
</mapper> </mapper>
\ 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!