Commit adc50046 by zhouhaibao

fix(strategy): 修复消息变量日期格式化问题

- 添加日期格式标准化方法,将YYYY/DD转换为yyyy/dd
- 增强日期解析逻辑,支持Date/Long/Integer类型输入
- 添加日期格式化解析异常处理和警告日志
- 优化日期格式化流程,避免空指针异常
1 parent ee47326f
...@@ -144,7 +144,7 @@ public class SopMessageVariableResolverService { ...@@ -144,7 +144,7 @@ public class SopMessageVariableResolverService {
return null; return null;
} }
String dateFormat = variable.getDateFormat(); String dateFormat = normalizeDateFormat(variable.getDateFormat());
String valueType = variable.getValueType(); String valueType = variable.getValueType();
if (value instanceof Date) { if (value instanceof Date) {
...@@ -171,19 +171,42 @@ public class SopMessageVariableResolverService { ...@@ -171,19 +171,42 @@ public class SopMessageVariableResolverService {
if ("DATE".equals(valueType)) { if ("DATE".equals(valueType)) {
try { try {
Date date = DateUtil.parse(String.valueOf(value)); Date date = parseDateValue(value);
if (StrUtil.isNotBlank(dateFormat)) { if (date != null) {
return DateUtil.format(date, dateFormat); if (StrUtil.isNotBlank(dateFormat)) {
return DateUtil.format(date, dateFormat);
}
return DateUtil.format(date, "yyyy-MM-dd");
} }
return DateUtil.format(date, "yyyy-MM-dd");
} catch (Exception e) { } catch (Exception e) {
return value; log.warn("日期格式化失败, value:{}, error:{}", value, e.getMessage());
} }
return value;
} }
return String.valueOf(value); return String.valueOf(value);
} }
private String normalizeDateFormat(String dateFormat) {
if (StrUtil.isBlank(dateFormat)) {
return null;
}
return dateFormat.replace("YYYY", "yyyy").replace("DD", "dd");
}
private Date parseDateValue(Object value) {
if (value instanceof Date) {
return (Date) value;
}
if (value instanceof Long) {
return new Date((Long) value);
}
if (value instanceof Integer) {
return new Date(((Integer) value).longValue() * 1000);
}
return DateUtil.parse(String.valueOf(value));
}
public List<SopStrategyMetaMessageVariable> getAllMessageVariables() { public List<SopStrategyMetaMessageVariable> getAllMessageVariables() {
return metaMessageVariableMapper.selectByStatus(1); 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!