項目經理說這種代碼必須重構,我同意了,這代碼是寫的是有多爛!

来源:https://www.cnblogs.com/MonsterJ/archive/2020/06/11/13094393.html
-Advertisement-
Play Games

摘要 開發已過幾載,閱代碼無數,有人寫的代碼邏輯清晰,bug難以隱藏;依賴最少,易於維護;錯誤處理完全根據一個明確的策略; 性能接近最佳化,避免代碼混亂和無原則的優化;後期閱讀真是賞心悅目,就像是看一篇文章。 但今天我想DIss的是一些CV大佬,那寫的代碼真是慘不忍睹。 來吧,展示 標誌位以及全局變 ...


摘要

開發已過幾載,閱代碼無數,有人寫的代碼邏輯清晰,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


您的分享是我們最大的動力!

-Advertisement-
Play Games
更多相關文章
  • 從小到大玩過很多的游戲,在我小時候,能玩游戲的地方不多,那時玩游戲都是偷摸玩的,只要是個游戲就覺得非常有趣,比較經典的有魂鬥羅,拳皇,超級瑪麗,貪吃蛇,俄羅斯方塊等游戲;發展到現在,玩游戲已經成為生活的一部分了,尤其是現在的很多游戲都已經網路社交化了,游戲種類也更加豐富了,沒事大家一起組隊玩個游戲還 ...
  • 1. 簡單介紹 3DES(或稱為Triple DES)是三重數據加密演算法(TDEA,Triple Data Encryption Algorithm)塊密碼的通稱。它相當於是對每個數據塊應用三次DES加密演算法。由於電腦運算能力的增強,原版DES密碼的密鑰長度變得容易被暴力破解;3DES即是設計用來 ...
  • 作者:程式猿的內心獨白 https://m.toutiaocdn.com/i6685496024770806280 這是一次代碼優化過程中發現的問題,在功能優化後發現部分數據查不到出來了,問題就在於一條sql上的#和$。 下圖為兩條sql: 從圖上可以看出 wwlr.LabelId in($) 和 ...
  • 場景 分流方式 如何分流 使用Filter分流 使用Split分流 使用Side Output分流 場景 獲取流數據的時候,通常需要根據所需把流拆分出其他多個流,根據不同的流再去作相應的處理。 舉個例子:創建一個商品實時流,商品有季節標簽,需要對不同標簽的商品做統計處理,這個時候就需要把商品數據流根 ...
  • 原始go.mod文件 module xxx go 1.14 報錯 i/o timeout go mod init workorder go mod init: go.mod already exists go mod tidy go: finding module for package githu ...
  • 上篇內容我們學習了Stream的大部分終端操作,我們這篇著重瞭解下Stream中重要的終端操作:collect。 ...
  • Django查詢資料庫性能優化 現在有一張記錄用戶信息的UserInfo數據表,表中記錄了10個用戶的姓名,呢稱,年齡,工作等信息. models文件 from django.db import models class Job(models.Model): title=models.CharFie ...
  • 作者:frank909 https://blog.csdn.net/briblue/article/details/76736356 泛型,一個孤獨的守門者。 大家可能會有疑問,我為什麼叫做泛型是一個守門者。這其實是我個人的看法而已,我的意思是說泛型沒有其看起來那麼深不可測,它並不神秘與神奇。泛型是 ...
一周排行
    -Advertisement-
    Play Games
  • 移動開發(一):使用.NET MAUI開發第一個安卓APP 對於工作多年的C#程式員來說,近來想嘗試開發一款安卓APP,考慮了很久最終選擇使用.NET MAUI這個微軟官方的框架來嘗試體驗開發安卓APP,畢竟是使用Visual Studio開發工具,使用起來也比較的順手,結合微軟官方的教程進行了安卓 ...
  • 前言 QuestPDF 是一個開源 .NET 庫,用於生成 PDF 文檔。使用了C# Fluent API方式可簡化開發、減少錯誤並提高工作效率。利用它可以輕鬆生成 PDF 報告、發票、導出文件等。 項目介紹 QuestPDF 是一個革命性的開源 .NET 庫,它徹底改變了我們生成 PDF 文檔的方 ...
  • 項目地址 項目後端地址: https://github.com/ZyPLJ/ZYTteeHole 項目前端頁面地址: ZyPLJ/TreeHoleVue (github.com) https://github.com/ZyPLJ/TreeHoleVue 目前項目測試訪問地址: http://tree ...
  • 話不多說,直接開乾 一.下載 1.官方鏈接下載: https://www.microsoft.com/zh-cn/sql-server/sql-server-downloads 2.在下載目錄中找到下麵這個小的安裝包 SQL2022-SSEI-Dev.exe,運行開始下載SQL server; 二. ...
  • 前言 隨著物聯網(IoT)技術的迅猛發展,MQTT(消息隊列遙測傳輸)協議憑藉其輕量級和高效性,已成為眾多物聯網應用的首選通信標準。 MQTTnet 作為一個高性能的 .NET 開源庫,為 .NET 平臺上的 MQTT 客戶端與伺服器開發提供了強大的支持。 本文將全面介紹 MQTTnet 的核心功能 ...
  • Serilog支持多種接收器用於日誌存儲,增強器用於添加屬性,LogContext管理動態屬性,支持多種輸出格式包括純文本、JSON及ExpressionTemplate。還提供了自定義格式化選項,適用於不同需求。 ...
  • 目錄簡介獲取 HTML 文檔解析 HTML 文檔測試參考文章 簡介 動態內容網站使用 JavaScript 腳本動態檢索和渲染數據,爬取信息時需要模擬瀏覽器行為,否則獲取到的源碼基本是空的。 本文使用的爬取步驟如下: 使用 Selenium 獲取渲染後的 HTML 文檔 使用 HtmlAgility ...
  • 1.前言 什麼是熱更新 游戲或者軟體更新時,無需重新下載客戶端進行安裝,而是在應用程式啟動的情況下,在內部進行資源或者代碼更新 Unity目前常用熱更新解決方案 HybridCLR,Xlua,ILRuntime等 Unity目前常用資源管理解決方案 AssetBundles,Addressable, ...
  • 本文章主要是在C# ASP.NET Core Web API框架實現向手機發送驗證碼簡訊功能。這裡我選擇是一個互億無線簡訊驗證碼平臺,其實像阿裡雲,騰訊雲上面也可以。 首先我們先去 互億無線 https://www.ihuyi.com/api/sms.html 去註冊一個賬號 註冊完成賬號後,它會送 ...
  • 通過以下方式可以高效,並保證數據同步的可靠性 1.API設計 使用RESTful設計,確保API端點明確,並使用適當的HTTP方法(如POST用於創建,PUT用於更新)。 設計清晰的請求和響應模型,以確保客戶端能夠理解預期格式。 2.數據驗證 在伺服器端進行嚴格的數據驗證,確保接收到的數據符合預期格 ...