优化如下代码:public CommonResult paymentRequest( @ApiParam(name = "params", value = "表单bo") @RequestBody String params) throws Exception { if (org.apache.commons.lang.StringUtils.isBlank(params)) { return new CommonResult(false, "传入参数错误", null); } log.info("-----------"+params); JSONObject json1 = com.alibaba.fastjson.JSON.parseObject(params); // JSONObject bo = com.alibaba.fastjson.JSON.parseObject(json1.getString("boData")); // Map<String,String> map = JSONObject.parseObject(bo.getString("lxcgfksq2"),Map.class); // JSONObject creator = com.alibaba.fastjson.JSON.parseObject(json1.getString("creator")); // 流程申请人 String instId = json1.getString("instId"); // 实例id String flowKey = json1.getString("flowKey"); // 流程实例类型 if ("lxcgfksq".equals(flowKey)){ flowKey = "lxcg"; } else if ("shddfksq".equals(flowKey)){ flowKey = "shdd"; } else if ("ylshhtglysfksq".equals(flowKey)){ flowKey = "htgl"; } String actionName = json1.getString("actionName"); // 审批结果 String sysCode = json1.getString("sysCode"); if (sysCode == null) { BpmResultSapProcess bpmResultSapProcess = new BpmResultSapProcess(); bpmResultSapProcess.setInstId(instId); bpmResultSapProcess.setInstType(flowKey); bpmResultSapProcess.setJsonstr(params); bpmResultSapProcess.setApproveStatus(actionName); bpmResultSapProcess.setCreateTime(new Date()); bpmResultSapProcess.setCreateUser("admin"); piecemealPurchasesManager.create(bpmResultSapProcess); } return new CommonResult(true, "写入成功", null); }
时间: 2024-04-28 16:21:31 浏览: 143
Springboot在有参构造方法类中使用@Value注解取值
public CommonResult paymentRequest(@ApiParam(name = "params", value = "表单bo") @RequestBody String params) throws Exception {
if (StringUtils.isBlank(params)) {
return new CommonResult(false, "传入参数错误", null);
}
log.info("-----------" + params);
JSONObject json1 = JSON.parseObject(params);
String flowKey = json1.getString("flowKey"); // 流程实例类型
if ("lxcgfksq".equals(flowKey)) {
flowKey = "lxcg";
} else if ("shddfksq".equals(flowKey)) {
flowKey = "shdd";
} else if ("ylshhtglysfksq".equals(flowKey)) {
flowKey = "htgl";
}
String sysCode = json1.getString("sysCode");
if (sysCode == null) {
BpmResultSapProcess bpmResultSapProcess = new BpmResultSapProcess();
bpmResultSapProcess.setInstId(json1.getString("instId"));
bpmResultSapProcess.setInstType(flowKey);
bpmResultSapProcess.setJsonstr(params);
bpmResultSapProcess.setApproveStatus(json1.getString("actionName"));
bpmResultSapProcess.setCreateTime(new Date());
bpmResultSapProcess.setCreateUser("admin");
piecemealPurchasesManager.create(bpmResultSapProcess);
}
return new CommonResult(true, "写入成功", null);
}
优化点:
- 引入静态导入,避免频繁写出类名;
- 删除注释代码,减少代码量和维护成本;
- 删除不必要的变量声明,直接使用 JSONObject 获取信息;
- 简化 if-else 判断流程类型,使用字符串替换;
- 简化对象属性赋值,直接使用 JSONObject 获取信息。
阅读全文