Commit 8d1d339a by 林永健

fix parse sql bug, add operator type logic

1 parent e8089efb
......@@ -15,16 +15,19 @@ public class SopDataFilterAction {
/**
* 名称
*/
@Column(name = "`name`")
private String name;
/**
* 描述
*/
@Column(name = "`desc`")
private String desc;
/**
* 类型
*/
@Column(name = "`type`")
private String type;
/**
......@@ -36,6 +39,7 @@ public class SopDataFilterAction {
/**
* sql实现
*/
@Column(name = "`sql`")
private String sql;
/**
......
......@@ -19,17 +19,31 @@ public class SopDataFilterCondition {
/**
* 名称
*/
@Column(name = "`name`")
private String name;
@Column(name = "`desc`")
private String desc;
@Column(name = "`type`")
private String type;
@Column(name = "`unit`")
private String unit;
@Column(name = "is_hide")
private Boolean isHide;
@Column(name = "`style`")
private String style;
/**
* sql实现
*/
@Column(name = "`sql`")
private String sql;
@Column(name = "`value`")
private String value;
/**
......
......@@ -3,7 +3,6 @@ package cn.com.glsx.process.modules.entity;
import lombok.Data;
import javax.persistence.*;
import java.util.Date;
@Data
@Table(name = "sop_data_filter_operator")
......@@ -11,12 +10,13 @@ public class SopDataFilterOperator {
@Id
@GeneratedValue(strategy = GenerationType.IDENTITY)
private Integer id;
@Column(name = "`name`")
private String name;
@Column(name = "`desc`")
private String desc;
private String key;
@Column(name = "updated_time")
private Date updatedTime;
@Column(name = "created_time")
private Date createdTime;
@Column(name = "`key`")
private String key;
}
\ No newline at end of file
......@@ -17,6 +17,7 @@ public class SopDataOperatorDTO {
private Integer id;
private String name;
private String desc;
private String type;
private String key;
private String value = "";
......
package cn.com.glsx.process.modules.service;
import cn.com.glsx.process.modules.entity.SopDataFilterAction;
import cn.com.glsx.process.modules.entity.SopDataFilterCondition;
import cn.com.glsx.process.modules.entity.SopDataFilterOperator;
import cn.com.glsx.process.modules.entity.SopInst;
import cn.com.glsx.process.modules.mapper.SopDataFilterActionMapper;
import cn.com.glsx.process.modules.mapper.SopDataFilterConditionMapper;
import cn.com.glsx.process.modules.mapper.SopDataFilterOperatorMapper;
import cn.com.glsx.process.modules.model.*;
import cn.com.glsx.process.util.JacksonUtil;
import cn.com.glsx.process.util.JacksonUtils;
......@@ -33,6 +38,12 @@ public class SopDataService {
@Autowired
private SopDataFilterActionMapper sopDataFilterActionMapper;
@Autowired
private SopDataFilterConditionMapper conditionMapper;
@Autowired
private SopDataFilterOperatorMapper operatorMapper;
public List<SopDataActionDTO> listCondition(SopDataActionSearch search) {
List<SopDataActionDTO> res = sopDataFilterActionMapper.findAll(search);
// 封装子条件,匹配数据源
......@@ -172,7 +183,7 @@ public class SopDataService {
* @return <阶段,SQL>
*/
public Map<String, String> parseSQL(SopInst inst) {
Map<String, String> res = Maps.newHashMap();
Map<String, String> res = Maps.newTreeMap();
if (Objects.isNull(inst) || !StringUtils.hasLength(inst.getInstParam())) {
return res;
}
......@@ -216,6 +227,8 @@ public class SopDataService {
}
public String parseSQL(SopDataActionDTO action) {
mergeActionData(action);
String res = action.getSql();
if (CollectionUtils.isEmpty(action.getConditions())) {
return res;
......@@ -262,11 +275,12 @@ public class SopDataService {
if (!StringUtils.hasLength(operator.getValue())) {
continue;
}
String type = operator.getType();
String value;
if ("in".equals(operator.getKey()) || "nin".equals(operator.getKey())) {
value = "(" + Arrays.stream(operator.getValue().split(",")).map(p -> "'" + p + "'").collect(Collectors.joining(",")) + ")";
value = "(" + Arrays.stream(operator.getValue().split(",")).map(p -> parseOperatorValue(type, p)).collect(Collectors.joining(",")) + ")";
} else {
value = "'" + operator.getValue() + "'";
value = parseOperatorValue(type, operator.getValue());
}
operatorStrList.add(condStr + " " + operator.getKey() + " " + value);
}
......@@ -274,6 +288,17 @@ public class SopDataService {
return condStr;
}
private String parseOperatorValue(String type, String value) {
if (!StringUtils.hasLength(value)) {
return value;
}
type = StringUtils.hasLength(type) ? type : "string";
if ("string".equals(type)) {
value = "'" + value + "'";
}
return value;
}
private String sqlAnd(String s1, String s2) {
return joinWithDelimiter(" and ", Lists.newArrayList(s1, s2));
}
......@@ -284,4 +309,43 @@ public class SopDataService {
}
return parts.stream().filter(Objects::nonNull).filter(p -> StringUtils.hasLength(p.trim())).collect(Collectors.joining(join));
}
/**
* 合并条件和实例条件快照中不变的部分数据
*/
private void mergeActionData(SopDataActionDTO actionDTO) {
SopDataFilterAction actionRaw = sopDataFilterActionMapper.selectByPrimaryKey(actionDTO.getId());
if (Objects.isNull(actionRaw)) {
return;
}
actionDTO.setSql(actionRaw.getSql());
actionDTO.setType(actionRaw.getType());
if (CollectionUtils.isEmpty(actionDTO.getConditions())) {
return;
}
actionDTO.getConditions().forEach(this::mergeConditionData);
}
private void mergeConditionData(SopDataConditionDTO condition) {
SopDataFilterCondition conditionRaw = conditionMapper.selectByPrimaryKey(condition.getId());
if (Objects.isNull(conditionRaw)) {
return;
}
condition.setSql(conditionRaw.getSql());
condition.setType(conditionRaw.getType());
if (!CollectionUtils.isEmpty(condition.getOperators())) {
condition.getOperators().forEach(o -> {
o.setType(condition.getType());
SopDataFilterOperator operatorRaw = operatorMapper.selectByPrimaryKey(o.getId());
if (Objects.isNull(operatorRaw)) {
return;
}
o.setKey(operatorRaw.getKey());
});
}
if (!CollectionUtils.isEmpty(condition.getSubConditions())) {
condition.getSubConditions().forEach(this::mergeConditionData);
}
}
}
......@@ -30,6 +30,7 @@
<result column="operatorName" property="name" />
<result column="operatorDesc" property="desc" />
<result column="operatorKey" property="key" />
<result column="conditionType" property="type" />
<result column="conditionUnit" property="unit" />
<result column="conditionStyle" property="style" />
</resultMap>
......
......@@ -8,20 +8,18 @@
<id column="id" jdbcType="INTEGER" property="id" />
<result column="name" jdbcType="VARCHAR" property="name" />
<result column="desc" jdbcType="VARCHAR" property="desc" />
<result column="value" jdbcType="VARCHAR" property="value" />
<result column="updated_time" jdbcType="TIMESTAMP" property="updatedTime" />
<result column="created_time" jdbcType="TIMESTAMP" property="createdTime" />
<result column="key" jdbcType="VARCHAR" property="key" />
</resultMap>
<sql id="Base_Column_List">
<!--
WARNING - @mbg.generated
-->
id, name, value, desc, updated_time, created_time
id, `name`, `key`, `desc`
</sql>
<select id="findByConditionId" resultType="cn.com.glsx.process.modules.model.SopDataOperatorDTO">
select
op.id as id, op.name as name, op.value as value, op.desc as desc
op.id as id, op.name as `name`, op.key as `key`, op.desc as `desc`, c.type as `type`, c.unit as `unit`, c.style as style
from sop_data_filter_operator op
left join sop_data_filter_condition_operator_rel cop on cop.operator_id = op.id
left join sop_data_filter_condition c on cop.condition_id = c.id
......
Markdown is supported
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!