Commit 016d5eaa by zhouhaibao

refactor(strategy): 移除客户快照依赖并优化变量解析逻辑

- 删除了 SopStrategyCustomerSnapshot 相关代码和 BeanUtil 依赖
- 修改 resolveVariable 方法移除快照参数传递
- 简化 resolveFromSnapshot 方法实现,直接从上下文获取值
- 优化 SQL 占位符替换逻辑,支持字符串、日期等类型值的正确转义
- 移除客户快照查询数据库相关方法代码
1 parent 97c8c5d7
package cn.com.glsx.dj.strategy.service;
import cn.com.glsx.dj.strategy.mapper.sop.SopStrategyMetaMessageVariableMapper;
import cn.com.glsx.dj.strategy.model.sop.SopStrategyCustomerSnapshot;
import cn.com.glsx.dj.strategy.model.sop.SopStrategyMetaMessageVariable;
import cn.hutool.core.bean.BeanUtil;
import cn.hutool.core.date.DateUtil;
import cn.hutool.core.util.StrUtil;
import lombok.RequiredArgsConstructor;
......@@ -33,12 +31,10 @@ public class SopMessageVariableResolverService {
return result;
}
SopStrategyCustomerSnapshot snapshot = getCustomerSnapshot(taskId, customerInstanceId);
for (SopStrategyMetaMessageVariable variable : variables) {
String variableCode = variable.getVariableCode();
try {
Object value = resolveVariable(variable, snapshot, context);
Object value = resolveVariable(variable, context);
if (value != null) {
result.put(variableCode, value);
} else if (StrUtil.isNotBlank(variable.getDefaultValue())) {
......@@ -59,13 +55,12 @@ public class SopMessageVariableResolverService {
return result;
}
private Object resolveVariable(SopStrategyMetaMessageVariable variable,
SopStrategyCustomerSnapshot snapshot, Map<String, Object> context) {
private Object resolveVariable(SopStrategyMetaMessageVariable variable, Map<String, Object> context) {
String dataSource = variable.getDataSource();
if (DATA_SOURCE_SNAPSHOT.equals(dataSource)) {
return resolveFromSnapshot(variable, snapshot, context);
return resolveFromSnapshot(variable, context);
} else if (DATA_SOURCE_SQL.equals(dataSource)) {
return resolveFromSql(variable, context);
} else {
......@@ -74,8 +69,7 @@ public class SopMessageVariableResolverService {
}
}
private Object resolveFromSnapshot(SopStrategyMetaMessageVariable variable,
SopStrategyCustomerSnapshot snapshot, Map<String, Object> context) {
private Object resolveFromSnapshot(SopStrategyMetaMessageVariable variable, Map<String, Object> context) {
String snapshotField = variable.getSnapshotField();
if (StrUtil.isBlank(snapshotField)) {
......@@ -83,15 +77,9 @@ public class SopMessageVariableResolverService {
return null;
}
Object value;
Object value = null;
if (snapshot != null) {
value = BeanUtil.getFieldValue(snapshot, snapshotField);
} else {
value = null;
}
if (value == null && context != null) {
if (context != null) {
value = context.get(snapshotField);
}
......@@ -114,7 +102,18 @@ public class SopMessageVariableResolverService {
if (context != null) {
for (Map.Entry<String, Object> entry : context.entrySet()) {
String placeholder = "${" + entry.getKey() + "}";
resolvedSql = resolvedSql.replace(placeholder, String.valueOf(entry.getValue()));
Object value = entry.getValue();
String valueStr;
if (value instanceof String) {
valueStr = "'" + value + "'";
} else if (value instanceof Date) {
valueStr = "'" + DateUtil.format((Date) value, "yyyy-MM-dd HH:mm:ss") + "'";
} else {
valueStr = String.valueOf(value);
}
resolvedSql = resolvedSql.replace(placeholder, valueStr);
}
}
......@@ -182,49 +181,6 @@ public class SopMessageVariableResolverService {
return String.valueOf(value);
}
private SopStrategyCustomerSnapshot getCustomerSnapshot(Integer taskId, Long customerInstanceId) {
if (taskId == null || customerInstanceId == null) {
return null;
}
try {
String sql = "SELECT * FROM sop_strategy_customer_snapshot " +
"WHERE task_id = ? AND customer_instance_id = ? AND deleted_flag = 'N'";
List<SopStrategyCustomerSnapshot> snapshots = jdbcTemplate.query(sql,
new Object[]{taskId, customerInstanceId},
(rs, rowNum) -> {
SopStrategyCustomerSnapshot snapshot = new SopStrategyCustomerSnapshot();
snapshot.setId(rs.getInt("id"));
snapshot.setStrategyId(rs.getInt("strategy_id"));
snapshot.setTaskId(rs.getInt("task_id"));
snapshot.setCustomerInstanceId(rs.getLong("customer_instance_id"));
snapshot.setCustomerName(rs.getString("customer_name"));
snapshot.setCustomerPhone(rs.getString("customer_phone"));
snapshot.setStoreId(rs.getLong("store_id"));
snapshot.setStoreCode(rs.getString("store_code"));
snapshot.setStoreName(rs.getString("store_name"));
snapshot.setStaffUuid(rs.getString("staff_uuid"));
snapshot.setStaffName(rs.getString("staff_name"));
snapshot.setDepositDate(rs.getDate("deposit_date"));
snapshot.setDeliveryDate(rs.getDate("delivery_date"));
snapshot.setCustomerCategory(rs.getString("customer_category"));
snapshot.setCarBrand(rs.getString("car_brand"));
snapshot.setCarSeries(rs.getString("car_series"));
snapshot.setCarSeriesLevel(rs.getString("car_series_level"));
snapshot.setGroupId(rs.getString("group_id"));
snapshot.setSnapshotData(rs.getString("snapshot_data"));
snapshot.setSnapshotTime(rs.getDate("snapshot_time"));
snapshot.setDeletedFlag(rs.getString("deleted_flag"));
return snapshot;
});
return snapshots.isEmpty() ? null : snapshots.get(0);
} catch (Exception e) {
log.error("查询客户快照失败, taskId:{}, customerInstanceId:{}, error:{}",
taskId, customerInstanceId, e.getMessage(), e);
return null;
}
}
public List<SopStrategyMetaMessageVariable> getAllMessageVariables() {
return metaMessageVariableMapper.selectByStatus(1);
}
......
Markdown is supported
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!