项目经理说这种代码必须重构,我同意了,这代码…

2020-06-11 16:07:18来源:博客园 阅读 ()

新老客户大回馈,云服务器低至5折

项目经理说这种代码必须重构,我同意了,这代码是写的是有多烂!

摘要

开发已过几载,阅代码无数,有人写的代码逻辑清晰,bug难以隐藏;依赖最少,易于维护;错误处理完全根据一个明确的策略;
性能接近最佳化,避免代码混乱和无原则的优化;后期阅读真是赏心悦目,就像是看一篇文章。

但今天我想DIss的是一些CV大佬,那写的代码真是惨不忍睹。

来吧,展示

在这里插入图片描述

标志位以及全局变量太多,看的头皮发麻,后期一旦有个地方忘了程序就会出错

/*
处理的业务的各种计算
*/
public Result beginBusiness(Map<String, String> requestParmsMap,String myBusinessMessage,String ) throws RuntimeException {
 System.out.println("开始了");
 // 规则方案ID
 String goodbusinessid = requestParmsMap.get("goodbusinessid");
 // 项目GUID
 String myprojectKey = requestParmsMap.get("myprojectKey");
 // 报表类型
 String reportType = requestParmsMap.get("reportType");
 // 数据配置ID
 String dataConfigId = requestParmsMap.get("dataConfigId");
 // 数据配置编号
 String dataConfigCode = requestParmsMap.get("dataConfigCode");
 // 客户端请求ID
 String clientReqId = requestParmsMap.get("clientReqId");
 // 客户端标识
 String clientSymbol = requestParmsMap.get("clientSymbol");
 // 数据期始时间
 String startDateStr = requestParmsMap.get("startDate");
 Date startDate = null;
 // 数据期末时间
 String endDateStr = requestParmsMap.get("endDate");
 Date endDate = null;
 String isCalYesterday = "true";
 try {
 if("false".equalsIgnoreCase(requestParmsMap.get("isCalYesterday"))) {
 isCalYesterday = String.valueOf(Boolean.valueOf(requestParmsMap.get("isCalYesterday")));
 }
 } catch (Exception e) {
 }
 // 判断其时间顺序是否满足四个时间依次递增关系
 String agentTimeCheckEnable = requestParmsMap.get("agentTimeCheckEnable");
 try {
 goodbusinessid = goodbusinessid.trim();
 } catch (Exception e) {
 }
 try {
 myprojectKey = myprojectKey.trim();
 } catch (Exception e) {
 }
 try {
 reportType = reportType.trim();
 } catch (Exception e) {
 }
 try {
 dataConfigId = dataConfigId.trim();
 } catch (Exception e) {
 }
 try {
 dataConfigCode = dataConfigCode.trim();
 } catch (Exception e) {
 }
 try {
 clientReqId = clientReqId.trim();
 } catch (Exception e) {
 }
 try {
 clientSymbol = clientSymbol.trim();
 } catch (Exception e) {
 }
 try {
 agentTimeCheckEnable = String.valueOf(Boolean.valueOf(agentTimeCheckEnable.trim()));
 if("true".equalsIgnoreCase(agentTimeCheckEnable)) {
 agentTimeCheckEnable = "true";
 }else {
 agentTimeCheckEnable = "false";
 }
 } catch (Exception e) {
 agentTimeCheckEnable = "false";
 }
 try {
 startDateStr = startDateStr.trim();
 startDate = new SimpleDateFormat("yyyy-MM-dd HH:mm:ss").parse(startDateStr);
 } catch (Exception e) {
 startDate = null;
 }
 try {
 endDateStr = endDateStr.trim();
 endDate = new SimpleDateFormat("yyyy-MM-dd HH:mm:ss").parse(endDateStr);
 } catch (Exception e) {
 endDate = null;
 }
 if( StringUtils.isBlank(goodbusinessid) && StringUtils.isBlank(myprojectKey)) {
 logger.info("请求参数有误,requestParmsMap:{}", JSON.toJSONString(requestParmsMap));
 throw new RuntimeException("请求参数有误");
 }
 if(StringUtils.isNotBlank(clientReqId) || StringUtils.isNotBlank(clientSymbol) ) {
 if(StringUtils.isBlank(clientReqId)||StringUtils.isBlank(clientSymbol)) {
 logger.info("请求参数有误,requestParmsMap:{}", JSON.toJSONString(requestParmsMap));
 throw new RuntimeException("请求参数有误");
 }
 List<EngineAchieveRequest> engineAchieveRequestList = this.engineAchieveRequestMapper.findByClientId(null, clientReqId, clientSymbol);
 if(CollectionUtils.isNotEmpty(engineAchieveRequestList)) {
 logger.info("请求参数有误,客户请求号有重复,requestParmsMap:{}", JSON.toJSONString(requestParmsMap));
 throw new RuntimeException("请求参数有误:客户请求号有重复");
 }
 }

在这里插入图片描述

// 报表类型
List<String> dataTypes = enginegoodbusinessMapper.findDataTypes();
// 有传goodbusinessid
Enginegoodbusiness oneEnginegoodbusiness = null;
try {
if(StringUtils.isNotBlank(goodbusinessid)) {
oneEnginegoodbusiness = enginegoodbusinessMapper.selectByPrimaryKey(Long.valueOf(goodbusinessid));
// 判断是否有效
if(oneEnginegoodbusiness.getStatus().intValue()!=3 && oneEnginegoodbusiness.getStatus().intValue()!=5) {
throw new Exception("规则方案配置未生效");
}
// 判断是否默认配置
if(StringUtils.isBlank(oneEnginegoodbusiness.getmyprojectKey())) {
throw new Exception("默认规则方案不能直接执行");
}
// 初始化ProjectId
if(StringUtils.isBlank(myprojectKey)) {
myprojectKey = oneEnginegoodbusiness.getmyprojectKey();
}
}
} catch (Exception e) {
logger.info("规则方案配置有误,requestParmsMap:{},ex:{}", JSON.toJSONString(requestParmsMap), e);
throw new RuntimeException("规则方案配置有误");
}
// 传了 myprojectKey
List<Enginegoodbusiness> pidEnginegoodbusinesss = null;
if(oneEnginegoodbusiness==null || oneEnginegoodbusiness.getId()==null) {
if(StringUtils.isNotBlank(myprojectKey)) {
if(StringUtils.isNotBlank(dataConfigId)) {
pidEnginegoodbusinesss = enginegoodbusinessMapper.findByCidIdAndPid(Long.valueOf(dataConfigId), myprojectKey);
}else if(StringUtils.isNotBlank(dataConfigCode)) {
DataConfig dc = dataConfigMapper.findByDataConfigCode(dataConfigCode);
pidEnginegoodbusinesss = enginegoodbusinessMapper.findByCidIdAndPid(Long.valueOf(dc.getId()), myprojectKey);
}else {
pidEnginegoodbusinesss = enginegoodbusinessMapper.findByPid(myprojectKey);
}
if(CollectionUtils.isEmpty(pidEnginegoodbusinesss)) {
if(StringUtils.isNotBlank(reportType)) {
pidEnginegoodbusinesss = enginegoodbusinessMapper.findDefaultCngBygoodbusinessDataType(reportType);
}else {
pidEnginegoodbusinesss = enginegoodbusinessMapper.findDefaultCng();
}
}
}
}
// 是否添加默认的配置
List<Enginegoodbusiness> defaultEnginegoodbusinesss = enginegoodbusinessMapper.findDefaultCngsByDataTypes(dataTypes);
List<Enginegoodbusiness> needDefaultEnginegoodbusinesss = new ArrayList<>();
for(Enginegoodbusiness defaultEnginegoodbusiness:defaultEnginegoodbusinesss) {
boolean isNeedAdd = true;
for(Enginegoodbusiness pidEnginegoodbusiness:pidEnginegoodbusinesss) {
// 默认配置已经包含在内,直接跳过
if(defaultEnginegoodbusiness.getId().equals(pidEnginegoodbusiness.getId())) {
isNeedAdd = false;
break;
}
// 默认配置的时间是否重复
if(defaultEnginegoodbusiness.getgoodbusinessDataType().equals(pidEnginegoodbusiness.getgoodbusinessDataType()) && DateUtil.isInDate(pidEnginegoodbusiness.getStartDate(), pidEnginegoodbusiness.getEndDate(), defaultEnginegoodbusiness.getStartDate(), defaultEnginegoodbusiness.getEndDate())) {
isNeedAdd = false;
break;
}
}
if(isNeedAdd) {
needDefaultEnginegoodbusinesss.add(defaultEnginegoodbusiness);
}
}
if(CollectionUtils.isNotEmpty(needDefaultEnginegoodbusinesss)) {
pidEnginegoodbusinesss.addAll(needDefaultEnginegoodbusinesss);
}
// 基本数据校验
List<Enginegoodbusiness> enginegoodbusinesssNeedCk = new ArrayList<Enginegoodbusiness>();
if(oneEnginegoodbusiness!=null && oneEnginegoodbusiness.getId()!=null) {
if(this.checkEnginegoodbusinessIsSimpleOk(oneEnginegoodbusiness, Arrays.asList(Integer.valueOf(3),Integer.valueOf(5)))) {
enginegoodbusinesssNeedCk.add(oneEnginegoodbusiness);
}
}else {
if(CollectionUtils.isNotEmpty(pidEnginegoodbusinesss)) {
for(Enginegoodbusiness dbEnginegoodbusiness : pidEnginegoodbusinesss) {
if(this.checkEnginegoodbusinessIsSimpleOk(dbEnginegoodbusiness, Arrays.asList(Integer.valueOf(3),Integer.valueOf(5)))) {
enginegoodbusinesssNeedCk.add(dbEnginegoodbusiness);
}
}
}
}
// 方案规则
List<Enginegoodbusiness> enginegoodbusinesss = new ArrayList<Enginegoodbusiness>();
// 数据配置校验
try {
for(Enginegoodbusiness filterEnginegoodbusiness : enginegoodbusinesssNeedCk) {
DataConfig dataConfigCk = dataConfigMapper.selectByPrimaryKey(Long.valueOf(filterEnginegoodbusiness.getDataConfigId()));
// 不符合条件的数据模版过滤
if(this.checkDataConfigIsOk(dataConfigCk, Integer.valueOf(1))==false) {
continue;
}
// 不符合条件的规则方案过滤
if(this.checkEnginegoodbusinessIsOk(filterEnginegoodbusiness, Arrays.asList(Integer.valueOf(3),Integer.valueOf(5)))==false) {
continue;
}
enginegoodbusinesss.add(filterEnginegoodbusiness);
}
} catch (Exception e) {
logger.error("数据配置不正确,requestParmsMap:{},ex:{}", JSON.toJSONString(requestParmsMap), e);
throw new RuntimeException("数据配置不正确");
}
if(CollectionUtils.isEmpty(enginegoodbusinesss)) {
logger.error("找不到适合的方案规则,requestParmsMap:{}", JSON.toJSONString(requestParmsMap));
throw new RuntimeException("找不到适合的方案规则");
}
// 方案规则是否可计算
boolean canCal = false;
for(Enginegoodbusiness enginegoodbusiness : enginegoodbusinesss) {
// 方案为“3:审核通过”、“5:生效”为可计算
if(enginegoodbusiness!=null && (enginegoodbusiness.getStatus().intValue()==3 || enginegoodbusiness.getStatus().intValue()==5)) {
canCal = true;
break;
}
}
if(canCal==false) {
logger.error("找不到适合的方案规则(canCal==false),requestParmsMap:{}", JSON.toJSONString(requestParmsMap));
throw new RuntimeException("找不到适合的方案规则");
}
// 按时间过滤规则
if(startDate!=null || endDate!=null) {
enginegoodbusinesssNeedCk.clear();
enginegoodbusinesssNeedCk.addAll(enginegoodbusinesss);
enginegoodbusinesss.clear();
for(Enginegoodbusiness enginegoodbusinessCk : enginegoodbusinesssNeedCk) {
if( (startDate==null || startDate.compareTo(enginegoodbusinessCk.getStartDate())<=0) && (endDate==null || endDate.compareTo(enginegoodbusinessCk.getEndDate())>=0) ) {
enginegoodbusinesss.add(enginegoodbusinessCk);
}
}
}
// 检查规则是否唯一
if (!checkEnginegoodbusinesssIsUnique(enginegoodbusinesss)) {
logger.error("找不到适合的方案规则,规则不唯一,requestParmsMap:{}", JSON.toJSONString(requestParmsMap));
throw new RuntimeException("找不到适合的方案规则");
}
//判断project是否存在
Proj proj = this.projMapper.getProjIdBymyprojectKey(myprojectKey);
if(proj==null) {
logger.error("项目不存在,requestParmsMap:{}", JSON.toJSONString(requestParmsMap));
throw new RuntimeException("项目不存在");
}
// 根据结束时间从大到小排序
Collections.sort(enginegoodbusinesss, new Comparator<Enginegoodbusiness>() {
@Override
public int compare(Enginegoodbusiness o1, Enginegoodbusiness o2) {
if(o1==null||o1.getEndDate()==null) {
return -1;
}
int dateCom = o2.getEndDate().compareTo(o1.getEndDate());
if(dateCom==0) {
dateCom = o2.getStartDate().compareTo(o1.getStartDate());
}
return dateCom;
}
});
// 再次校验请求号
if(StringUtils.isNotBlank(clientReqId) || StringUtils.isNotBlank(clientSymbol) ) {
if(StringUtils.isBlank(clientReqId)||StringUtils.isBlank(clientSymbol)) {
logger.info("请求参数有误,requestParmsMap:{}", JSON.toJSONString(requestParmsMap));
throw new RuntimeException("请求参数有误");
}
List<EngineAchieveRequest> engineAchieveRequestList = this.engineAchieveRequestMapper.findByClientId(null, clientReqId, clientSymbol);
if(CollectionUtils.isNotEmpty(engineAchieveRequestList)) {
logger.info("请求参数有误,客户请求号有重复,requestParmsMap:{}", JSON.toJSONString(requestParmsMap));
throw new RuntimeException("请求参数有误:客户请求号有重复");
}
}
EngineAchieveRequest engineAchieveRequest = new EngineAchieveRequest();
engineAchieveRequest.setRequestId(CommissionUtil.buildgoodbusinessId("Req"));
engineAchieveRequest.setCaltype(0);
engineAchieveRequest.setStatus(3);
engineAchieveRequest.setMessage("初始化");
engineAchieveRequest.setClientRequestId(clientReqId);
engineAchieveRequest.setClientSymbol(clientSymbol);
this.engineAchieveRequestMapper.insertSelective(engineAchieveRequest);
// 再次校验请求号,防止并发重复的问题
if(StringUtils.isNotBlank(clientReqId) || StringUtils.isNotBlank(clientSymbol) ) {
if(StringUtils.isBlank(clientReqId)||StringUtils.isBlank(clientSymbol)) {
logger.info("请求参数有误,requestParmsMap:{}", JSON.toJSONString(requestParmsMap));
throw new RuntimeException("请求参数有误");
}
List<EngineAchieveRequest> engineAchieveRequestList = this.engineAchieveRequestMapper.findByClientId(null, clientReqId, clientSymbol);
if(CollectionUtils.isNotEmpty(engineAchieveRequestList)&&engineAchieveRequestList.size()>1) {
logger.info("请求参数有误,客户请求号有重复,requestParmsMap:{}", JSON.toJSONString(requestParmsMap));
throw new RuntimeException("请求参数有误:客户请求号有重复");
}
}

在这里插入图片描述

这一大坨是啥,

// 异步执行
final String finalRequestId = engineAchieveRequest.getRequestId();
final Long finalEngineAchieveRequestId = engineAchieveRequest.getId();
final String finalClientRequestId = clientReqId;
final String finalClientSymbol = clientSymbol;
final String finalAgentTimeCheckEnable = agentTimeCheckEnable;
final List<Enginegoodbusiness> finalEnginegoodbusinesss = enginegoodbusinesss;
final String finalmyprojectKey = myprojectKey;
final String finalIsCalYesterday = isCalYesterday;
final Map<String, String> reqMap = new HashMap<String, String>();
reqMap.put("myprojectKey", finalmyprojectKey);
reqMap.put("isCalYesterday", finalIsCalYesterday);
enginegoodbusinessServiceExecutor.execute(() -> {
	StringBuilder sb = new StringBuilder();
	sb.append("1.enginegoodbusinessServiceExecutor-finalmyprojectKey="+finalmyprojectKey+"\r\n");
	sb.append("1.enginegoodbusinessServiceExecutor-finalRequestId="+finalRequestId+"\r\n");
	sb.append("1.enginegoodbusinessServiceExecutor-finalClientRequestId="+finalClientRequestId+"\r\n");
EngineAchieveRequest preEngineAchieveRequest = this.engineAchieveRequestMapper.selectByPrimaryKey(finalEngineAchieveRequestId);
preEngineAchieveRequest.setMessage("运行中");
preEngineAchieveRequest.setStatus(2);
this.engineAchieveRequestMapper.updateByPrimaryKeySelective(preEngineAchieveRequest);
Enginegoodbusiness enginegoodbusinessNow = null;
try {
// 成功
Map<String, EngineAchieveRequestResult> sucessAchieveRequestResults = new HashMap<>();
// 失败
Map<String, EngineAchieveRequestResult> failAchieveRequestResults = new HashMap<>();
// 一次执行一条规则内容
for(Enginegoodbusiness enginegoodbusiness : finalEnginegoodbusinesss) {
	sb.append("2.enginegoodbusinessServiceExecutor-enginegoodbusiness="+enginegoodbusiness.getId()+","+enginegoodbusiness.getgoodbusinessName()+"\r\n");
try {
EngineAchieveRequest eAchieveRequest = new EngineAchieveRequest();
eAchieveRequest.setRequestId(finalRequestId);
eAchieveRequest.setCaltype(0);
eAchieveRequest.setStatus(2);
eAchieveRequest.setMessage("运行中");
eAchieveRequest.setClientRequestId(finalClientRequestId);
eAchieveRequest.setClientSymbol(finalClientSymbol);
eAchieveRequest.setgoodbusinessId(enginegoodbusiness.getId());
this.engineAchieveRequestMapper.insertSelective(eAchieveRequest);
enginegoodbusinessNow = enginegoodbusiness;
String batchNo = null;
// 方案为“3:审核通过”、“5:生效”为可计算
if(enginegoodbusiness!=null && (enginegoodbusiness.getStatus().intValue()==3 || enginegoodbusiness.getStatus().intValue()==5)) {
// 转换对象
ClassUtil<EnginegoodbusinessVo> classUtil = new ClassUtil<EnginegoodbusinessVo>(EnginegoodbusinessVo.class);
EnginegoodbusinessVo enginegoodbusinessVo = classUtil.changeTo(enginegoodbusiness);

// 根据规则配置,组建数据对象EngineFactVo
List<EngineFactVo> engineFactVos = goodbusinessEngineHandler.buildEngineFactVos(enginegoodbusinessVo, reqMap,sb);
// 开始处理数据
if(CollectionUtils.isNotEmpty(engineFactVos)) {
logger.info("EngineFact数据库查询,List<EngineFactVo> engineFactVos,Size:{},enginegoodbusinessVo:{},reqMap:{}", String.valueOf(engineFactVos.size()), enginegoodbusinessVo, reqMap);
List<EngineFactVo> dualEngineFactVos = new ArrayList<EngineFactVo>();
// 需分批处理数据,防止内存使用过大
int engineFactVosIndex = 0;
for (EngineFactVo engineFactVo : engineFactVos) {
engineFactVosIndex++;
dualEngineFactVos.add(engineFactVo);
if(engineFactVosIndex%this.goodbusinessEngineHandler.Batch_Engine_Cal_Size==0||engineFactVos.size()==engineFactVosIndex) {
List<EnginegoodbusinessVo> egoodbusinessVos = new ArrayList<EnginegoodbusinessVo>();
egoodbusinessVos.add(enginegoodbusinessVo);
// 加载引擎规则
KieContainer kieContainer = goodbusinessEngineHandler.getKieContainer(egoodbusinessVos);
goodbusinessEngineHandler.factExcute(kieContainer, dualEngineFactVos);
dualEngineFactVos.clear();
}
sb.append("4.2-for.end engineFactVo.getHitgoodbusinessMessage().getEnginegoodbusinessid()="+engineFactVo.getHitgoodbusinessMessage().getEnginegoodbusinessid()+" \r\n");
}
sb.append("4.3-for循环engineFactVos \r\n");
int mathSize = 0;
for(EngineFactVo engineFactVo : engineFactVos) {
// 设置其时间顺序是否满足四个时间依次递增关系
engineFactVo.getgoodbusinessOtherMessage().setAgentTimeCheckEnable(finalAgentTimeCheckEnable.trim());
// 计算匹配的数目
if(engineFactVo.getHitgoodbusinessMessage()!=null&&StringUtils.isNotBlank(engineFactVo.getHitgoodbusinessMessage().getHitgoodbusinessExpressionPosition())) {
mathSize++;
}
}
// 数据处理引擎的结果
String batchRequestId = String.valueOf(finalRequestId);
DealEngineFactDataResult dualResult = this.dealEngineFactData(enginegoodbusiness, engineFactVos, null, null, batchRequestId,sb);
batchNo = dualResult.getBatchNo();
// 处理结果信息
List<EngineAchieveRequestResult> dualAchieveRequestResults = dualResult.getDualAchieveRequestResults();
if(CollectionUtils.isNotEmpty(dualAchieveRequestResults)) {
for(EngineAchieveRequestResult engineAchieveRequestResult : dualAchieveRequestResults) {
if(engineAchieveRequestResult!=null && engineAchieveRequestResult.getStatus()!=null && StringUtils.isNotBlank(engineAchieveRequestResult.getPk1())) {
	if(engineAchieveRequestResult.getStatus().intValue()==1) { // 处理成功
sucessAchieveRequestResults.put(engineAchieveRequestResult.getPksKey(), engineAchieveRequestResult);
failAchieveRequestResults.remove(engineAchieveRequestResult.getPksKey());
}else { // 处理失败
if(!sucessAchieveRequestResults.keySet().contains(engineAchieveRequestResult.getPksKey())) {
failAchieveRequestResults.put(engineAchieveRequestResult.getPksKey(), engineAchieveRequestResult);
}
}
}
else
{
}
}
}
else
{
}
// 计算报表
goodbusinessReportTypeEnum rrtEnum = goodbusinessReportTypeEnum.getByKey(enginegoodbusiness.getgoodbusinessDataType());
if(goodbusinessReportTypeEnum.Agent.equals(rrtEnum)) {
this.agentCommisionToReportService.ToReport(batchNo, reqMap.get("myprojectKey"));
}
}
else
{
}
}
else
{
	
}
eAchieveRequest.setMessage("成功");
eAchieveRequest.setStatus(1);
eAchieveRequest.setCalcommissionbatchno(batchNo);
this.engineAchieveRequestMapper.updateByPrimaryKeySelective(eAchieveRequest);
} catch (Exception e) {
	
logger.error("计算处理失败,exception:{}", e);
}
}

在这里插入图片描述
被纠结死

List<EngineAchieveRequest> newEegAchieveRequests = this.engineAchieveRequestMapper.findByReqId(finalRequestId);
if(CollectionUtils.isNotEmpty(newEegAchieveRequests)&&newEegAchieveRequests.size()>1) {
this.engineAchieveRequestMapper.deleteByPrimaryKey(preEngineAchieveRequest.getId());
}

if(MapUtils.isNotEmpty(sucessAchieveRequestResults) && CollectionUtils.isNotEmpty(sucessAchieveRequestResults.values())) {
List<EngineAchieveRequestResult> sucessResults = new ArrayList<>();
sucessResults.addAll(sucessAchieveRequestResults.values());
this.engineAchieveRequestResultMapper.insertBatch(sucessResults);
}
if(MapUtils.isNotEmpty(failAchieveRequestResults) && CollectionUtils.isNotEmpty(failAchieveRequestResults.values())) {
List<EngineAchieveRequestResult> failResults = new ArrayList<>();
failResults.addAll(failAchieveRequestResults.values());
this.engineAchieveRequestResultMapper.insertBatch(failResults);
}
sb.append("6.2 计算结束finish \r\n");
logger.info("计算结束,enginegoodbusinessServiceExecutor.execute(),finalEnginegoodbusinesss:{},reqMap:{}", JSON.toJSONString(finalEnginegoodbusinesss), JSON.toJSONString(reqMap));
} catch (Exception e) {
	sb.append("7.1 计算异常"+e.getMessage()+" \r\n");
List<EngineAchieveRequest> errAchieveRequests = this.engineAchieveRequestMapper.findByReqId(finalRequestId);
String errMsg = e.getMessage();
if(errMsg.length()>200) {
errMsg = errMsg.substring(0, 200);
}
if(CollectionUtils.isNotEmpty(errAchieveRequests)) {
for(EngineAchieveRequest errAchieveRequest : errAchieveRequests) {
errAchieveRequest.setMessage(errMsg);
errAchieveRequest.setStatus(0);
this.engineAchieveRequestMapper.updateByPrimaryKeySelective(errAchieveRequest);
}
}
if(CollectionUtils.isNotEmpty(errAchieveRequests)&&errAchieveRequests.size()>1) {
this.engineAchieveRequestMapper.deleteByPrimaryKey(preEngineAchieveRequest.getId());
}
logger.error("计算处理失败,enginegoodbusiness:{},exception:{}", enginegoodbusinessNow, e);
} finally {
	logger.info(sb.toString());
}
});
logger.info("佣金计算请求成功calCommonCommission(),requestParmsMap:{}", JSON.toJSONString(requestParmsMap));
Result result=new Result();
result.setStatus(StatusCode.SUCCESS);
result.setMessage("佣金计算请求成功");
result.setData(engineAchieveRequest.getRequestId());
return result;
//完。大功告成。
}

展示 完毕

这是我在公司接触的真实的代码,列举几点问题

  • 标志位以及全局变量太多
  • 逻辑不够简单
  • 函数设计不合理
  • 可读性差(可能只有自己看得懂)
  • 重复判断没有注释

作为一名合格的程序员,这样的代码不应出现在我们的生产上,严格的项目经理、架构师一定会让你重构,我们要写出规范有自己风格的代码
把你们遇到的奇葩代码也评论出来吧

公众号:程序零世界(C0W1024) 获取更多文章资料

file


原文链接:https://www.cnblogs.com/MonsterJ/p/13094393.html
如有疑问请与原作者联系

标签:

版权申明:本站文章部分自网络,如有侵权,请联系:west999com@outlook.com
特别注意:本站所有转载文章言论不代表本站观点,本站所提供的摄影照片,插画,设计作品,如需使用,请与原作者联系,版权归原作者所有

上一篇:老板让你抗住千万级流量,如何做架构设计?

下一篇:通过与C++程序对比,彻底搞清楚JAVA的对象拷贝