目前遇到的问题是,自编程序中输入参数和输出参数不在自编程序表中,而是在另外一张单独的表中(中间表)。
在日志记录时,输入参数和输出参数无法记录。
思路:通过虚拟字段,代码如下:
private List<SelfProgramParameter> selfProgramParameterList = Lists.newArrayList(); // 拥有参数列表 @FieldRemark("输入资源池参数") private String improtSelfParamListStr; @FieldRemark("输出资源池参数") private String exprotSelfParamListStr; public String getImprotSelfParamListStr() { return improtSelfParamListStr; } public void setImprotSelfParamListStr() { this.improtSelfParamListStr = SelfParametersUtils.findParametersListByIdAndType(id, 1);//直接将查询到的参数set到对应的格式化后的字符串里面 } public String getExprotSelfParamListStr() { return exprotSelfParamListStr; } public void setExprotSelfParamListStr() { this.exprotSelfParamListStr = SelfParametersUtils.findParametersListByIdAndType(id, 2); }
//自己定义输入参数及输出参数在日志中的显示格式
public class SelfParametersUtils { public static String findParametersListByIdAndType(String selfProgramId,int type) { String result = ""; SelfProgramService selfProgramService = (SelfProgramService) ContextLoader.getCurrentWebApplicationContext() .getBean("selfProgramService"); List<SelfProgramParameter> list = selfProgramService.logFindParametersListByIdAndType(selfProgramId, type); if(list != null && !list.isEmpty() && list.size() >0){ for (SelfProgramParameter selfProgramParameter : list) { if(StringUtils.isNotBlank(selfProgramParameter.getParameters().getName())){ result += selfProgramParameter.getParameters().getName() + "-"; } if(StringUtils.isNotBlank(selfProgramParameter.getParameters().getParameterType())){ result += DictUtils.getDictLabel(selfProgramParameter.getParameters().getParameterType(), "dm_parameter_type", "") + "-"; } result += selfProgramParameter.getSort() + ","; } } if(StringUtils.isNotBlank(result)){ result = StringUtils.getStringDelSymbol(result, ','); } return result; } }
然后在doAround调用get方法时,将格式化后的输入参数和输出参数set到自编程序对象中
if (selfProgram != null && StringUtils.isNotBlank(selfProgram.getId())) { selfProgram.setImprotSelfParamListStr(); selfProgram.setExprotSelfParamListStr(); }
添加后的save方法同样set到对象中,代码略,因为每次添加或修改时,输入参数及输出参数都必须在保存时清空,所以需要在调用service层的save方法时再删除
注意日志记录时执行顺序