Commit 0cf8f2ce by zhouhaibao

refactor(strategy): 优化策略快照缓存服务中的操作符处理逻辑

- 引入 SopOperatorTypeEnum 枚举类来管理操作符类型
- 修改 getOperatorDesc 方法使用枚举替代硬编码的 switch 语句
- 在构建条件描述时增加对值源类型的判断逻辑
- 为条件对象添加变量名称字段的设置
- 更新单元测试中的任务执行参数值
1 parent 8dd6a782
package cn.com.glsx.dj.strategy.service; package cn.com.glsx.dj.strategy.service;
import cn.com.glsx.dj.strategy.enums.SopOperatorTypeEnum;
import cn.com.glsx.dj.strategy.mapper.sop.*; import cn.com.glsx.dj.strategy.mapper.sop.*;
import cn.com.glsx.dj.strategy.model.sop.*; import cn.com.glsx.dj.strategy.model.sop.*;
import com.alibaba.fastjson.JSON; import com.alibaba.fastjson.JSON;
...@@ -412,6 +413,7 @@ public class SopStrategySnapshotCacheService { ...@@ -412,6 +413,7 @@ public class SopStrategySnapshotCacheService {
Collectors.toList()); Collectors.toList());
if (collect.size() > 0) { if (collect.size() > 0) {
conditionMap.put("variableName",collect.get(0).getVariableName()); conditionMap.put("variableName",collect.get(0).getVariableName());
condition.setVariableName(collect.get(0).getVariableName());
} }
conditionMap.put("valueType", condition.getValueType()); conditionMap.put("valueType", condition.getValueType());
conditionMap.put("operator", condition.getOperator()); conditionMap.put("operator", condition.getOperator());
...@@ -458,18 +460,12 @@ public class SopStrategySnapshotCacheService { ...@@ -458,18 +460,12 @@ public class SopStrategySnapshotCacheService {
} }
private String getOperatorDesc(Integer operator) { private String getOperatorDesc(Integer operator) {
if (operator == null) return ""; if (operator == null) {
switch (operator) { return "";
case 1: return "等于";
case 2: return "不等于";
case 3: return "大于";
case 4: return "大于等于";
case 5: return "小于";
case 6: return "小于等于";
case 7: return "包含";
case 8: return "不包含";
default: return "";
} }
SopOperatorTypeEnum operatorEnum = SopOperatorTypeEnum.getEnum(operator);
// 如果找到了对应的枚举,返回描述;否则返回空字符串
return operatorEnum != null ? operatorEnum.getDisplayName() : "";
} }
private String getActionTypeName(Integer actionType) { private String getActionTypeName(Integer actionType) {
...@@ -517,18 +513,32 @@ public class SopStrategySnapshotCacheService { ...@@ -517,18 +513,32 @@ public class SopStrategySnapshotCacheService {
} }
private String buildConditionDesc(SopStrategyCondition condition) { private String buildConditionDesc(SopStrategyCondition condition) {
Integer valueSource = condition.getValueSource();
if (condition.getVariableName() == null || condition.getOperator() == null) { if (condition.getVariableName() == null || condition.getOperator() == null) {
return ""; return "";
} }
String operatorDesc = getOperatorDesc(condition.getOperator()); String operatorDesc = getOperatorDesc(condition.getOperator());
String value = ""; String value = "";
if (condition.getValueType() != null) { if (valueSource != null && valueSource == 1) {
switch (condition.getValueType()) { value = getDateVariableName(condition.getVariableRefCode());
case 1: value = condition.getTextValue(); break; }else {
case 2: value = condition.getNumberValue(); break; if (condition.getValueType() != null) {
case 3: value = condition.getDateValue(); break; switch (condition.getValueType()) {
case 4: value = condition.getEnumValue(); break; case 1:
default: value = ""; value = condition.getTextValue();
break;
case 2:
value = condition.getNumberValue();
break;
case 3:
value = condition.getDateValue();
break;
case 4:
value = condition.getEnumValue();
break;
default:
value = "";
}
} }
} }
return String.format("%s %s %s", condition.getVariableName(), operatorDesc, value); return String.format("%s %s %s", condition.getVariableName(), operatorDesc, value);
......
...@@ -257,6 +257,6 @@ public class StrategyInfoServiceTest extends BaseServiceTest { ...@@ -257,6 +257,6 @@ public class StrategyInfoServiceTest extends BaseServiceTest {
} }
@Test @Test
public void executeTask() { public void executeTask() {
sopStrategyExecutionService.executeTask(21); sopStrategyExecutionService.executeTask(65);
} }
} }
Markdown is supported
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!