Commit 8f9edbc6 by 谢海旭

下发门店时,模板以及模板节点初始参数处理

1 parent 7cda6c09
......@@ -16,6 +16,7 @@ import cn.com.glsx.process.modules.rabbitmq.RabbitConfig;
import cn.com.glsx.process.modules.rabbitmq.RabbitMQConstants;
import cn.com.glsx.process.util.FileUploadServerData;
import cn.com.glsx.process.util.FileUploadUtil;
import cn.com.glsx.process.util.SopTplParamHandler;
import com.github.pagehelper.PageHelper;
import com.github.pagehelper.PageInfo;
import com.glsx.plat.core.enums.SysConstants;
......@@ -331,6 +332,8 @@ public class SopInstService {
sopInst.setInstName(String.format("%s-%s", sopTplGrant.getGroupName(), sopTplDTO.getTplName()));
sopInst.setInstId(tplId + grantId);
sopInst.setGrantId(grantId);
// 处理模板定义的初始化参数
sopInst.setInstParam(SopTplParamHandler.addMerchantId(SopTplParamHandler.extract(sopTplDTO.getTplParamDef()), sopTplGrant.getGroupId()) );
sopInst.setCreateTime(date);
sopInst.setUpdateTime(date);
sopInst.setInstStatus(SopInstStatusEnum.UNUSED.getValue());
......@@ -353,6 +356,9 @@ public class SopInstService {
sopInstNode.setInstId(instId);
sopInstNode.setNodeStatus(SopInstNode.NODE_STATUS_NORMAL);
// 处理模板节点定义的初始化参数
sopInstNode.setNodeParam(SopTplParamHandler.extract(sopTplNode.getNodeParamDef()));
//页面选择是否跳过处理
SopInstNode sopInstNodeTemp = customNodesMap.get(sopInstNode.getNodeId());
sopInstNode.setNodeSkip(!Objects.isNull(sopInstNodeTemp) ? sopInstNodeTemp.getNodeSkip() : SopInstNode.NODE_SKIP_FALSE);
......
package cn.com.glsx.process.util;
import com.alibaba.fastjson.JSON;
import com.fasterxml.jackson.databind.JsonNode;
import com.fasterxml.jackson.databind.ObjectMapper;
import com.glsx.plat.exception.ResultException;
import com.glsx.plat.exception.SystemMessage;
import lombok.experimental.UtilityClass;
import org.springframework.util.StringUtils;
import java.util.HashMap;
import java.util.Map;
@UtilityClass
public class SopTplParamHandler {
public ObjectMapper objectMapper = new ObjectMapper();
public String extract(String tplParam) {
if (!StringUtils.hasLength(tplParam)) {
return null;
}
try {
JsonNode rootNode = objectMapper.readTree(tplParam);
return processNode(rootNode);
} catch (Exception e) {
throw ResultException.create(SystemMessage.DATA_HANDLE_ERROR.getCode(), "参数转json对象异常");
}
}
public String addMerchantId(String paramJson, String merchantId) {
HashMap map = JSON.parseObject(paramJson, HashMap.class);
map.put("merchantId", merchantId);
return JSON.toJSONString(map);
}
private String processNode(JsonNode node) {
Map<String, Object> map = new HashMap<>();
for (JsonNode childNode : node) {
String key = childNode.path("paramKey").asText();
String valueType = childNode.path("valueType").asText();
JsonNode defaultValueNode = childNode.path("defaultValue");
switch (valueType) {
case "Number":
int defaultValueInt = defaultValueNode.asInt();
map.put(key, defaultValueInt);
break;
case "String":
String defaultValueString = defaultValueNode.asText();
map.put(key, defaultValueString);
break;
case "Map":
// 解析Map类型的默认值
Map<String, Object> defaultValueMap = objectMapper.convertValue(defaultValueNode, HashMap.class);
map.put(key, defaultValueMap);
break;
// 其他数据类型的解析
default:
break;
}
}
return JSON.toJSONString(map);
}
}
Markdown is supported
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!