Commit 459e363c by zhouhaibao

Merge branch 'v2.0.1' of http://192.168.3.233:8090/platform/platform-process-server into v2.0.1

2 parents 868c1e00 1e49919f
package cn.com.glsx.process.modules.model;
import com.alibaba.fastjson.JSON;
import com.alibaba.fastjson.TypeReference;
import lombok.Data;
import org.springframework.util.StringUtils;
import java.util.Arrays;
import java.util.Map;
import java.util.stream.Collectors;
/**
* 操作符
......@@ -16,4 +23,21 @@ public class SopDataOperatorDTO {
// from SopDataConditionDTO
private String unit;
private String style;
/**
* 一般value存储多值,用,分隔
* desc字段存储value的一些描述数据
*/
public String getDescByValue() {
if (!StringUtils.hasLength(this.getValue()) || !StringUtils.hasLength(this.getDesc())) {
return this.getValue();
}
String[] values = this.getValue().split(",");
if (values.length == 0) {
return this.getValue();
}
Map<String, String> descValueMap = JSON.parseObject(this.getDesc(), new TypeReference<Map<String, String>>() {
});
return Arrays.stream(values).map(p -> descValueMap.getOrDefault(p, p)).collect(Collectors.joining(","));
}
}
\ No newline at end of file
......@@ -126,6 +126,7 @@ public class KeHuLvChengAssembler {
SopTplNode stageNode = PROTO_CONVERTER.proto2tpl(stageProto);
stageNode.setNodeId(tplNodeLastNum++);
stageNode.setNodeName(String.format("%s-%s", stageValue, stageNode.getNodeName()));
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));
......@@ -199,9 +200,9 @@ public class KeHuLvChengAssembler {
* 封装sop触达节点
*
* @param tplNodeProto 触达节点原型
* @param nodeId 节点id
* @param nodeId 节点id
* @param nodeParamDef 页面传参的节点 nodeParamDef 参数
* @param stageid 节点所属阶段的顺序
* @param stageid 节点所属阶段的顺序
* @return
*/
private SopTplNode getNotifyNodeFromProto(SopTplNodeProto tplNodeProto, Integer nodeId, String nodeParamDef, Integer stageid) {
......@@ -209,6 +210,10 @@ public class KeHuLvChengAssembler {
notifyTplNode.setNodeId(nodeId);
notifyTplNode.setNodeKey(String.format("%s%d", tplNodeProto.getNodeKey(), notifyTplNode.getNodeId()));
String stageName = JacksonUtil.getStrValueInJsonStrByPath(nodeParamDef, "stage/defaultValue");
String dayStr = JacksonUtil.getStrValueInJsonStrByPath(nodeParamDef, "day/defaultValue");
notifyTplNode.setNodeName(String.format("%s-第%s天-%s", stageName, dayStr, notifyTplNode.getNodeName()));
nodeParamDef = JacksonUtil.jsonStrDeepSub(notifyTplNode.getNodeParamDef(), nodeParamDef);
nodeParamDef = JacksonUtil.jsonStrDeepSub(nodeParamDef, String.format("{\"stageid\": {\"defaultValue\": %d}}", stageid));
notifyTplNode.setNodeParamDef(nodeParamDef);
......@@ -287,7 +292,7 @@ public class KeHuLvChengAssembler {
// 获取阶段更新的sql
SopInst sopInst = SopInstConverter.INSTANCE.dto2do(instDTO);
Map<String, String> stageSqlMap = sopDataService.parseSQL(sopInst);
String updateSql = String.join("\n", stageSqlMap.values());
String updateSql = String.join(" ", stageSqlMap.values());
String nodeContent = updateStageNode.getNodeContent();
Map<String, Object> nodeContentMap = JSON.parseObject(nodeContent, Map.class);
......
......@@ -8,9 +8,7 @@ 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.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;
import org.springframework.web.bind.annotation.*;
import javax.annotation.Resource;
import java.util.List;
......@@ -30,4 +28,10 @@ public class SopDataController extends BaseController {
public List<SopDataActionDTO> listCondition(SopDataActionSearch search) {
return sopDataService.listCondition(search);
}
@Operation(summary = "根据某一阶段条件获取条件名称", description = "根据某一阶段条件获取条件名称")
@PostMapping("/condition/getConditionTitle")
public String parseParamRemarkTitle(@RequestBody SopDataActionDTO actionDTO) {
return sopDataService.parseParamRemarkTitle(actionDTO);
}
}
......@@ -22,6 +22,7 @@ import org.springframework.stereotype.Service;
import org.springframework.util.CollectionUtils;
import org.springframework.util.StringUtils;
import java.text.MessageFormat;
import java.util.*;
import java.util.stream.Collectors;
......@@ -123,7 +124,7 @@ public class SopDataService {
*
* @param action 所属条件
*/
private String parseParamRemarkTitle(SopDataActionDTO action) {
public String parseParamRemarkTitle(SopDataActionDTO action) {
if (!StringUtils.hasLength(action.getParamRemark())) {
return action.getParamRemark();
}
......@@ -138,26 +139,30 @@ public class SopDataService {
if (CollectionUtils.isEmpty(conditions)) {
return subTitle;
}
List<String> subConditionTitleList = new ArrayList<>();
List<String> conditionTitleList = new ArrayList<>();
for (SopDataConditionDTO condition : conditions) {
String subConditionTitle = StringUtils.hasLength(condition.getParamRemark()) ? JSON.parseObject(condition.getParamRemark()).getString("title") : "";
// 将占位符替换真实数据,占位符采用[]包裹
if (!CollectionUtils.isEmpty(condition.getOperators())) {
Map<String, String> map = condition.getOperators().stream()
.filter(p -> StringUtils.hasLength(p.getValue()))
.collect(Collectors.groupingBy(o -> o.getName(), Collectors.mapping(o -> o.getValue(), Collectors.joining(","))));
for (Map.Entry<String, String> e : map.entrySet()) {
subConditionTitle = subConditionTitle
.replaceFirst("\\[([^\\]]+)\\]", e.getKey())
.replaceFirst("\\[([^\\]]+)\\]", e.getValue());
String conditionTitle = "";
if (StringUtils.hasLength(condition.getParamRemark())) {
conditionTitle = JSON.parseObject(condition.getParamRemark()).getString("title");
// 将占位符替换真实数据,占位符采用[]包裹
if (!CollectionUtils.isEmpty(condition.getOperators())) {
Map<String, String> map = condition.getOperators().stream()
.filter(p -> StringUtils.hasLength(p.getValue()))
.collect(Collectors.groupingBy(o -> o.getName(), Collectors.mapping(o -> o.getDescByValue(), Collectors.joining(","))));
for (Map.Entry<String, String> e : map.entrySet()) {
conditionTitle = conditionTitle
.replaceFirst("\\[([^\\]]+)\\]", e.getKey())
.replaceFirst("\\[([^\\]]+)\\]", e.getValue());
}
}
}
if (!CollectionUtils.isEmpty(condition.getSubConditions())) {
subConditionTitle += parseParamRemarkTitle(condition.getSubConditions());
conditionTitle += parseParamRemarkTitle(condition.getSubConditions());
}
subConditionTitleList.add(subConditionTitle);
conditionTitleList.add(conditionTitle);
}
subTitle += joinWithDelimiter(", 且", subConditionTitleList);
subTitle += joinWithDelimiter(", 且", conditionTitleList);
return subTitle;
}
......@@ -229,17 +234,27 @@ public class SopDataService {
if (CollectionUtils.isEmpty(condition.getOperators())) {
return condStr;
}
// 针对“页面配置”等这种条件(type=1)进行特殊处理,对value值进行拆分,放在sql的占位中
if ("页面配置".equals(condition.getName())) {
SopDataOperatorDTO operator = condition.getOperators().get(0);
String[] vals = operator.getValue().split("\\+");
if (vals.length == 0) {
return "";
}
return MessageFormat.format(condStr, vals);
}
List<String> operatorStrList = new ArrayList<>();
for (SopDataOperatorDTO operator : condition.getOperators()) {
if (StringUtils.hasLength(operator.getValue())) {
String value;
if ("in".equals(operator.getKey()) || "nin".equals(operator.getKey())) {
value = "(" + Arrays.stream(operator.getValue().split(",")).map(p -> "'" + p + "'").collect(Collectors.joining(",")) + ")";
} else {
value = "'" + operator.getValue() + "'";
}
operatorStrList.add(condStr + " " + operator.getKey() + " " + value);
if (!StringUtils.hasLength(operator.getValue())) {
continue;
}
String value;
if ("in".equals(operator.getKey()) || "nin".equals(operator.getKey())) {
value = "(" + Arrays.stream(operator.getValue().split(",")).map(p -> "'" + p + "'").collect(Collectors.joining(",")) + ")";
} else {
value = "'" + operator.getValue() + "'";
}
operatorStrList.add(condStr + " " + operator.getKey() + " " + value);
}
condStr = joinWithDelimiter(" and ", operatorStrList);
return condStr;
......
......@@ -79,9 +79,10 @@ public class TestSopService {
.put("paramRemark", "{\"title\": \"天数[xx][X]天\"}")
.put("operators", Lists.newArrayList(ImmutableMap.builder()
.put("id", "1")
.put("name", "等于")
.put("key", "=")
.put("value", "11")
.put("name", "包含")
.put("key", "in")
.put("value", "a,b,c")
.put("desc", "{\"a\":\"A\", \"b\":\"B\"}")
.build()))
.build()))
.build())).build()).build();
......
Markdown is supported
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!