From e3aed650aa4e232f4583a00fc3de088276a2188b Mon Sep 17 00:00:00 2001
From: wuxw <928255095@qq.com>
Date: 星期六, 15 一月 2022 13:41:18 +0800
Subject: [PATCH] 优化代码
---
service-order/src/main/java/com/java110/order/smo/impl/OIdServiceSMOImpl.java | 95 ++++++++++++++++++++++++++++++++++++++++++-----
1 files changed, 85 insertions(+), 10 deletions(-)
diff --git a/service-order/src/main/java/com/java110/order/smo/impl/OIdServiceSMOImpl.java b/service-order/src/main/java/com/java110/order/smo/impl/OIdServiceSMOImpl.java
old mode 100644
new mode 100755
index dea13a2..0786ee2
--- a/service-order/src/main/java/com/java110/order/smo/impl/OIdServiceSMOImpl.java
+++ b/service-order/src/main/java/com/java110/order/smo/impl/OIdServiceSMOImpl.java
@@ -3,11 +3,17 @@
import com.alibaba.fastjson.JSONArray;
import com.alibaba.fastjson.JSONObject;
import com.java110.core.client.RestTemplate;
+import com.java110.core.context.SecureInvocation;
import com.java110.core.factory.GenerateCodeFactory;
+import com.java110.dto.app.AppDto;
+import com.java110.dto.businessTableHis.BusinessTableHisDto;
import com.java110.dto.order.OrderDto;
import com.java110.dto.order.OrderItemDto;
import com.java110.order.dao.ICenterServiceDAO;
+import com.java110.order.smo.IAsynNotifySubService;
import com.java110.order.smo.IOIdServiceSMO;
+import com.java110.utils.cache.BusinessTableHisCache;
+import com.java110.utils.constant.StatusConstant;
import com.java110.utils.util.BeanConvertUtil;
import com.java110.utils.util.DateUtil;
import com.java110.utils.util.StringUtil;
@@ -45,29 +51,33 @@
@Autowired
private RestTemplate restTemplate;
+ @Autowired
+ private IAsynNotifySubService asynNotifySubServiceImpl;
+
@Override
public ResponseEntity<String> createOId(OrderDto orderDto) {
orderDto.setoId(GenerateCodeFactory.getOId());
if (StringUtil.isEmpty(orderDto.getAppId())) {
- throw new IllegalArgumentException("鏈寘鍚玜ppId");
+ orderDto.setAppId(AppDto.WEB_APP_ID);
}
if (StringUtil.isEmpty(orderDto.getExtTransactionId())) {
- throw new IllegalArgumentException("鏈寘鍚氦浜掓棩蹇�");
+ orderDto.setExtTransactionId(GenerateCodeFactory.getTransactionId());
}
if (StringUtil.isEmpty(orderDto.getRequestTime())) {
- throw new IllegalArgumentException("鏈寘鍚姹傛椂闂�");
+ orderDto.setRequestTime(DateUtil.getNow(DateUtil.DATE_FORMATE_STRING_DEFAULT));
}
if (StringUtil.isEmpty(orderDto.getUserId())) {
- throw new IllegalArgumentException("鏈寘鍚敤鎴稩D");
+ orderDto.setUserId("-1");
}
//淇濆瓨璁㈠崟淇℃伅
- centerServiceDAOImpl.saveOrder(BeanConvertUtil.beanCovertMap(orderDto));
+ centerServiceDAOImpl.saveOrder(BeanConvertUtil.beanCovertMap(orderDto));
+
return new ResponseEntity<String>(JSONObject.toJSONString(orderDto), HttpStatus.OK);
}
@@ -156,6 +166,7 @@
return params;
}
+
/**
* 鐢熸垚insert璇彞
*
@@ -174,6 +185,9 @@
sql = "insert into " + orderItemDto.getActionObj() + " ";
param = new JSONObject();
JSONObject keyValue = preValues.getJSONObject(preValueIndex);
+ if (keyValue.isEmpty()) {
+ continue;
+ }
String keySql = "( ";
String valueSql = " values (";
for (String key : keyValue.keySet()) {
@@ -209,13 +223,23 @@
param = new JSONObject();
JSONObject keyValue = preValues.getJSONObject(preValueIndex);
JSONObject afterKeyValue = afterValues.getJSONObject(preValueIndex);
+ if (keyValue.isEmpty() || afterKeyValue.isEmpty()) {
+ continue;
+ }
String whereSql = " where 1=1 ";
for (String key : keyValue.keySet()) {
sql += (key + "=" + keyValue.getString(key) + ",");
+ if ("''".equals(afterKeyValue.getString(key))) { //鏉′欢涓笉鎷煎啓 涓虹┖鐨勭粨鏋�
+ continue;
+ }
whereSql += (" and " + key + " = " + afterKeyValue.getString(key));
}
if (sql.endsWith(",")) {
sql = sql.substring(0, sql.length() - 1);
+ }
+
+ if (sql.endsWith(whereSql)) { // 璇存槑娌℃湁鏉′欢 涓嶅仛鍥為�� 鍥為��鏁翠釜琛ㄦ槸鏈夐棶棰樼殑
+ continue;
}
sql += whereSql;
@@ -240,15 +264,23 @@
JSONObject logTextObj = JSONObject.parseObject(logText);
JSONArray afterValues = logTextObj.getJSONArray("afterValue");
+ String whereSql = " where 1=1 ";
for (int preValueIndex = 0; preValueIndex < afterValues.size(); preValueIndex++) {
- sql = "delete from " + orderItemDto.getActionObj() + " where 1=1 ";
+ sql = "delete from " + orderItemDto.getActionObj() + whereSql;
param = new JSONObject();
JSONObject keyValue = afterValues.getJSONObject(preValueIndex);
+ if (keyValue.isEmpty()) {
+ continue;
+ }
for (String key : keyValue.keySet()) {
- if (StringUtil.isEmpty(keyValue.getString(key))) {
+ if (!StringUtil.isEmpty(keyValue.getString(key))) {
sql += (" and " + key + "=" + keyValue.getString(key));
}
}
+ if (sql.endsWith(whereSql)) { // 璇存槑娌℃湁鏉′欢 涓嶅仛鍥為�� 鍥為��鏁翠釜琛ㄦ槸鏈夐棶棰樼殑
+ continue;
+ }
+ sql += " limit 1";//闃叉绋嬪簭寮傚父鍒犻櫎 灏村艾 鏍规嵁涓氬姟鍦烘櫙 娌℃湁闇�瑕佸垹闄ゅ浣� 1鏉$殑鍦烘櫙
param.put("fallBackSql", sql);
params.add(param);
}
@@ -288,7 +320,32 @@
}
centerServiceDAOImpl.saveOrderItem(BeanConvertUtil.beanCovertMap(orderItemDto));
+ //鍒ゆ柇鏄惁閰嶇疆浜� 杞ㄨ抗
+ BusinessTableHisDto businessTableHisDto = BusinessTableHisCache.getBusinessTableHisDto(orderItemDto.getAction(), orderItemDto.getActionObj());
+ if (businessTableHisDto == null) {
+ return ResultVo.createResponseEntity(ResultVo.CODE_OK, ResultVo.MSG_OK);
+ }
+
+ //琛ュ厖 c_business #{bId},#{oId},#{businessTypeCd},#{remark},#{statusCd}
+ Map business = new HashMap();
+ business.put("oId", orderItemDto.getoId());
+ business.put("businessTypeCd", businessTableHisDto.getBusinessTypeCd());
+ business.put("remark", "");
+ business.put("statusCd", StatusConstant.STATUS_CD_SAVE);
+ business.put("bId", orderItemDto.getbId());
+ centerServiceDAOImpl.saveBusiness(business);
+
+ //閫氱煡瀛愭湇鍔$敓鎴� business 鏁版嵁,濡傛灉閰嶇疆NO 涓嶉�氱煡鐢熸垚 business 鏁版嵁
+ if (BusinessTableHisDto.ACTION_OBJ_HIS_NO.equals(businessTableHisDto.getActionObjHis())) {
+ return ResultVo.createResponseEntity(ResultVo.CODE_OK, ResultVo.MSG_OK);
+ }
+
+ doNoticeServiceGeneratorBusiness(orderItemDto, businessTableHisDto);
return ResultVo.createResponseEntity(ResultVo.CODE_OK, ResultVo.MSG_OK);
+ }
+
+ private void doNoticeServiceGeneratorBusiness(OrderItemDto orderItemDto, BusinessTableHisDto businessTableHisDto) {
+ asynNotifySubServiceImpl.notifySubService(orderItemDto, businessTableHisDto);
}
/**
@@ -310,9 +367,6 @@
info.put("oId", orderDto.getoId());
centerServiceDAOImpl.updateOrderItem(info);
- //鍒犻櫎 浜嬪姟鏃ュ織
- //centerServiceDAOImpl.deleteUnItemLog(info);
-
//瀹屾垚璁㈠崟
info = new HashMap();
info.put("finishTime", DateUtil.getNow(DateUtil.DATE_FORMATE_STRING_A));
@@ -320,6 +374,27 @@
info.put("oId", orderDto.getoId());
centerServiceDAOImpl.updateOrder(info);
+ //灏哻_business 淇敼涓哄畬鎴�
+ //瀹屾垚璁㈠崟椤�
+ info = new HashMap();
+ info.put("finishTime", DateUtil.getNow(DateUtil.DATE_FORMATE_STRING_A));
+ info.put("statusCd", "C");
+ info.put("oId", orderDto.getoId());
+ centerServiceDAOImpl.updateBusiness(info);
+
+ //瑙﹀彂databug
+ //鏌ヨ 浜嬪姟椤�
+ Map orderItem = new HashMap();
+ orderItem.put("oId", orderDto.getoId());
+ List<Map> orderItemMaps = centerServiceDAOImpl.getOrderItems(orderItem);
+
+ //鍒犻櫎 浜嬪姟鏃ュ織
+ //centerServiceDAOImpl.deleteUnItemLog(info);
+
+ asynNotifySubServiceImpl.notifyDatabus(orderItemMaps, orderDto);
+
return ResultVo.createResponseEntity(ResultVo.CODE_OK, ResultVo.MSG_OK);
}
+
+
}
--
Gitblit v1.8.0