From c5aac73ec29f74904b544a722037b39bbb85ab3e Mon Sep 17 00:00:00 2001
From: wuxw <928255095@qq.com>
Date: 星期四, 07 二月 2019 21:35:35 +0800
Subject: [PATCH] 去serviceCode 改为businessTypeCd 完成
---
OrderService/src/main/java/com/java110/order/smo/impl/OrderServiceSMOImpl.java | 1105 ++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
1 files changed, 1,105 insertions(+), 0 deletions(-)
diff --git a/OrderService/src/main/java/com/java110/order/smo/impl/OrderServiceSMOImpl.java b/OrderService/src/main/java/com/java110/order/smo/impl/OrderServiceSMOImpl.java
new file mode 100644
index 0000000..81fbef4
--- /dev/null
+++ b/OrderService/src/main/java/com/java110/order/smo/impl/OrderServiceSMOImpl.java
@@ -0,0 +1,1105 @@
+package com.java110.order.smo.impl;
+
+import com.alibaba.fastjson.JSONArray;
+import com.alibaba.fastjson.JSONObject;
+import com.java110.common.cache.AppRouteCache;
+import com.java110.common.cache.MappingCache;
+import com.java110.common.constant.*;
+import com.java110.common.exception.*;
+import com.java110.common.factory.ApplicationContextFactory;
+import com.java110.common.kafka.KafkaFactory;
+import com.java110.common.log.LoggerEngine;
+import com.java110.common.util.*;
+import com.java110.core.client.RestTemplate;
+import com.java110.core.context.*;
+import com.java110.core.factory.AuthenticationFactory;
+import com.java110.core.factory.OrderDataFlowContextFactory;
+import com.java110.core.factory.GenerateCodeFactory;
+import com.java110.entity.center.AppRoute;
+import com.java110.entity.center.AppService;
+import com.java110.entity.center.DataFlowLinksCost;
+import com.java110.entity.order.Business;
+import com.java110.entity.order.ServiceBusiness;
+import com.java110.event.center.DataFlowEventPublishing;
+import com.java110.log.agent.LogAgent;
+import com.java110.order.dao.ICenterServiceDAO;
+import com.java110.order.smo.IOrderServiceSMO;
+import com.java110.service.init.ServiceInfoListener;
+import com.java110.service.smo.IQueryServiceSMO;
+import org.apache.commons.lang3.math.NumberUtils;
+import org.slf4j.Logger;
+import org.slf4j.LoggerFactory;
+import org.springframework.beans.factory.annotation.Autowired;
+import org.springframework.http.HttpEntity;
+import org.springframework.http.HttpHeaders;
+import org.springframework.http.HttpStatus;
+import org.springframework.http.ResponseEntity;
+import org.springframework.stereotype.Service;
+
+import java.util.*;
+
+
+/**
+ * 璁㈠崟鏈嶅姟澶勭悊绫�
+ * Created by wuxw on 2018/4/13.
+ */
+@Service("orderServiceSMOImpl")
+//@Transactional
+public class OrderServiceSMOImpl implements IOrderServiceSMO {
+
+ private final static Logger logger = LoggerFactory.getLogger(OrderServiceSMOImpl.class);
+
+
+ @Autowired
+ ICenterServiceDAO centerServiceDaoImpl;
+
+ @Autowired
+ private RestTemplate restTemplate;
+
+ @Autowired
+ private RestTemplate restTemplateNoLoadBalanced;
+
+ @Autowired
+ private IQueryServiceSMO queryServiceSMOImpl;
+
+
+ /**
+ * 涓氬姟缁熶竴澶勭悊鏈嶅姟鏂规硶
+ * @param reqJson 璇锋眰鎶ユ枃json
+ * @return
+ */
+ public ResponseEntity<String> service(String reqJson, Map<String,String> headers) throws SMOException{
+ IOrderDataFlowContext dataFlow = null;
+
+ JSONObject responseJson = null;
+
+ ResponseEntity<String> responseEntity = null;
+
+ try {
+ DataFlowEventPublishing.preValidateData(reqJson,headers);
+ //1.0 鍒涘缓鏁版嵁娴�
+ dataFlow = OrderDataFlowContextFactory.newInstance(OrderDataFlow.class).builder(reqJson, headers);
+ DataFlowEventPublishing.initDataFlowComplete(dataFlow);
+
+ //2.0 璋冪敤瑙勫垯鏍¢獙
+ ruleValidate(dataFlow);
+ DataFlowEventPublishing.ruleValidateComplete(dataFlow);
+
+ //3.0 淇濆瓨璁㈠崟鍜屼笟鍔¢」 c_orders c_order_attrs c_business c_business_attrs
+ saveOrdersAndBusiness(dataFlow);
+
+ //6.0 璋冪敤涓嬫父绯荤粺
+ DataFlowEventPublishing.invokeBusinessSystem(dataFlow);
+ invokeBusinessSystem(dataFlow);
+
+ //鑳藉鎵ц鍒拌繖涓�姝� 璁や负鏄兘鎴愬姛浜�
+ refreshOrderDataFlowResJson(dataFlow);
+
+ }catch (BusinessException e) {
+ responseEntity = new ResponseEntity<String>(e.getMessage() , OrderDataFlowContextFactory.hashMap2MultiValueMap(dataFlow.getResHeaders()),HttpStatus.INTERNAL_SERVER_ERROR);
+ } catch (OrdersException e) {
+ responseEntity = new ResponseEntity<String>(e.getMessage() , OrderDataFlowContextFactory.hashMap2MultiValueMap(dataFlow.getResHeaders()),HttpStatus.INTERNAL_SERVER_ERROR);
+ } catch (RuleException e) {
+ responseEntity = new ResponseEntity<String>(e.getMessage(),OrderDataFlowContextFactory.hashMap2MultiValueMap(dataFlow.getResHeaders()), HttpStatus.NETWORK_AUTHENTICATION_REQUIRED);
+ } catch (NoAuthorityException e) {
+ responseEntity = new ResponseEntity<String>(e.getMessage(), OrderDataFlowContextFactory.hashMap2MultiValueMap(dataFlow.getResHeaders()),HttpStatus.UNAUTHORIZED);
+ } catch (InitConfigDataException e){
+ responseEntity = new ResponseEntity<String>(e.getMessage(), OrderDataFlowContextFactory.hashMap2MultiValueMap(dataFlow.getResHeaders()),HttpStatus.INTERNAL_SERVER_ERROR);
+ }catch (Exception e) {
+ logger.error("鍐呴儴寮傚父浜嗭細",e);
+ responseEntity = new ResponseEntity<String>("鍐呴儴寮傚父浜嗭細"+e.getMessage() + e.getLocalizedMessage(), OrderDataFlowContextFactory.hashMap2MultiValueMap(dataFlow.getResHeaders()),HttpStatus.INTERNAL_SERVER_ERROR);
+ } finally {
+
+ if(responseEntity == null){
+ responseEntity = new ResponseEntity<String>(dataFlow.getResJson().getString("msg"),OrderDataFlowContextFactory.hashMap2MultiValueMap(dataFlow.getResHeaders()),HttpStatus.OK);
+ }
+ if(dataFlow != null) {
+ //娣诲姞鑰楁椂
+ //OrderDataFlowContextFactory.addCostTime(dataFlow, "service", "涓氬姟澶勭悊鎬昏�楁椂", dataFlow.getStartDate(), dataFlow.getEndDate());
+ //淇濆瓨鑰楁椂
+ //saveCostTimeLogMessage(dataFlow);
+// saveLogMessage(dataFlow,LogAgent.createLogMessage(dataFlow.getRequestHeaders(),dataFlow.getReqJson().toJSONString()),
+// LogAgent.createLogMessage(dataFlow.getResponseHeaders(),responseEntity.getBody()),endDate.getTime()-dataFlow.getStartDate().getTime());
+// DataFlowEventPublishing.dataResponse(dataFlow,reqJson,headers);
+ }
+
+
+ //杩欓噷淇濆瓨鑰楁椂锛屼互鍙婃棩蹇�
+ return responseEntity ;
+
+ }
+ }
+
+ /**
+ * 鍒疯繑鍥炲��
+ * @param dataFlow
+ */
+ private void refreshOrderDataFlowResJson(IOrderDataFlowContext dataFlow){
+
+ if(dataFlow.getResJson() == null || dataFlow.getResJson().isEmpty()){
+ JSONObject resJson = new JSONObject();
+ resJson.put("msg","鎴愬姛");
+ dataFlow.setResJson(resJson);
+ }
+
+ }
+
+ /**
+ * 鎶掑啓杩斿洖澶翠俊鎭�
+ * @param dataFlow
+ */
+ private void putResponseHeader(DataFlow dataFlow,Map<String,String> headers) {
+ headers.put("responseTime", DateUtil.getDefaultFormateTimeString(new Date()));
+ headers.put("transactionId",dataFlow.getTransactionId());
+ }
+
+ /**
+ * 瑙e瘑
+ * @param reqJson
+ * @return
+ */
+ private String decrypt(String reqJson,Map<String,String> headers) throws DecryptException{
+ try {
+ if (MappingConstant.VALUE_ON.equals(headers.get(CommonConstant.ENCRYPT))) {
+ logger.debug("瑙e瘑鍓嶅瓧绗︼細" + reqJson);
+ reqJson = new String(AuthenticationFactory.decrypt(reqJson.getBytes("UTF-8"), AuthenticationFactory.loadPrivateKey(MappingConstant.KEY_PRIVATE_STRING)
+ , NumberUtils.isNumber(headers.get(CommonConstant.ENCRYPT_KEY_SIZE)) ? Integer.parseInt(headers.get(CommonConstant.ENCRYPT_KEY_SIZE)) :
+ Integer.parseInt(MappingCache.getValue(MappingConstant.KEY_DEFAULT_DECRYPT_KEY_SIZE))),"UTF-8");
+ logger.debug("瑙e瘑鍚庡瓧绗︼細" + reqJson);
+ }
+ }catch (Exception e){
+ throw new DecryptException(ResponseConstant.RESULT_CODE_NO_AUTHORITY_ERROR,"瑙e瘑澶辫触");
+ }
+
+ return reqJson;
+ }
+
+ /**
+ * 鍔犲瘑
+ * @param resJson
+ * @param headers
+ * @return
+ */
+ private String encrypt(String resJson,Map<String,String> headers){
+ try {
+ if (MappingConstant.VALUE_ON.equals(headers.get(CommonConstant.ENCRYPT))) {
+ logger.debug("鍔犲瘑鍓嶅瓧绗︼細" + resJson);
+ resJson = new String(AuthenticationFactory.encrypt(resJson.getBytes("UTF-8"), AuthenticationFactory.loadPubKey(MappingConstant.KEY_PUBLIC_STRING)
+ , NumberUtils.isNumber(headers.get(CommonConstant.ENCRYPT_KEY_SIZE)) ? Integer.parseInt(headers.get(CommonConstant.ENCRYPT_KEY_SIZE)) :
+ Integer.parseInt(MappingCache.getValue(MappingConstant.KEY_DEFAULT_DECRYPT_KEY_SIZE))),"UTF-8");
+ logger.debug("鍔犲瘑鍚庡瓧绗︼細" + resJson);
+ }
+ }catch (Exception e){
+ logger.error("鍔犲瘑澶辫触锛�",e);
+ }
+ return resJson;
+ }
+
+
+
+ /**
+ * 2.0鍒濆鍖栭厤缃俊鎭�
+ *
+ * @param dataFlow
+ */
+ private void initConfigData(IOrderDataFlowContext dataFlow) {
+
+ }
+
+ /**
+ * 4.0瑙勫垯鏍¢獙
+ *
+ * @param dataFlow
+ * @throws RuleException
+ */
+ private void ruleValidate(IOrderDataFlowContext dataFlow) throws RuleException {
+ Date startDate = DateUtil.getCurrentDate();
+ try {
+
+ if (MappingConstant.VALUE_OFF.equals(MappingCache.getValue(MappingConstant.KEY_RULE_ON_OFF))
+ || (MappingCache.getValue(MappingConstant.KEY_NO_NEED_RULE_VALDATE_ORDER) != null
+ && MappingCache.getValue(MappingConstant.KEY_NO_NEED_RULE_VALDATE_ORDER).contains(dataFlow.getOrders().getOrderTypeCd()))) {
+ //涓嶅仛鏍¢獙
+ //娣诲姞鑰楁椂
+ OrderDataFlowContextFactory.addCostTime(dataFlow, "ruleValidate", "瑙勫垯鏍¢獙鑰楁椂", startDate);
+ return ;
+ }
+
+ //璋冪敤瑙勫垯
+
+ } catch (Exception e) {
+ //娣诲姞鑰楁椂
+ OrderDataFlowContextFactory.addCostTime(dataFlow, "ruleValidate", "瑙勫垯鏍¢獙鑰楁椂", startDate);
+ throw new RuleException(ResponseConstant.RESULT_CODE_RULE_ERROR, "瑙勫垯鏍¢獙寮傚父澶辫触锛�" + e.getMessage());
+ }
+
+ OrderDataFlowContextFactory.addCostTime(dataFlow, "ruleValidate", "瑙勫垯鏍¢獙鑰楁椂", startDate);
+
+ }
+
+ /**
+ * 5.0 淇濆瓨璁㈠崟鍜屼笟鍔¢」 c_orders c_order_attrs c_business c_business_attrs
+ *
+ * @param dataFlow
+ * @throws OrdersException
+ */
+ private void saveOrdersAndBusiness(IOrderDataFlowContext dataFlow) throws OrdersException {
+ Date startDate = DateUtil.getCurrentDate();
+ if(MappingCache.getValue(MappingConstant.KEY_NO_SAVE_ORDER) != null
+ &&MappingCache.getValue(MappingConstant.KEY_NO_SAVE_ORDER).contains(dataFlow.getOrders().getOrderTypeCd())){
+ //涓嶄繚瀛樿鍗曚俊鎭�
+ OrderDataFlowContextFactory.addCostTime(dataFlow, "saveOrdersAndBusiness", "淇濆瓨璁㈠崟鍜屼笟鍔¢」鑰楁椂", startDate);
+ return ;
+ }
+
+
+ //1.0 淇濆瓨 orders淇℃伅
+ centerServiceDaoImpl.saveOrder(OrderDataFlowContextFactory.getOrder(dataFlow.getOrders()));
+
+
+ centerServiceDaoImpl.saveOrderAttrs(OrderDataFlowContextFactory.getOrderAttrs(dataFlow.getOrders()));
+
+ //2.0 淇濆瓨 business淇℃伅
+
+ centerServiceDaoImpl.saveBusiness(OrderDataFlowContextFactory.getBusiness(dataFlow));
+
+ centerServiceDaoImpl.saveBusinessAttrs(OrderDataFlowContextFactory.getBusinessAttrs(dataFlow));
+
+ OrderDataFlowContextFactory.addCostTime(dataFlow, "saveOrdersAndBusiness", "淇濆瓨璁㈠崟鍜屼笟鍔¢」鑰楁椂", startDate);
+ }
+
+ /**
+ * 6.0 璋冪敤涓嬫父绯荤粺
+ *
+ * @param dataFlow
+ * @throws BusinessException
+ */
+ private void invokeBusinessSystem(IOrderDataFlowContext dataFlow) throws BusinessException {
+ Date startDate = DateUtil.getCurrentDate();
+ //6.1 鍏堝鐞嗗悓姝ユ柟寮忕殑鏈嶅姟锛屾瘡涓�鍚屾鍚庡彂甯冧簨浠跺箍鎾�
+
+ doSynchronousBusinesses(dataFlow);
+
+ //6.2 澶勭悊寮傛鏈嶅姟
+ doAsynchronousBusinesses(dataFlow);
+
+
+ OrderDataFlowContextFactory.addCostTime(dataFlow, "invokeBusinessSystem", "璋冪敤涓嬫父绯荤粺鑰楁椂", startDate);
+ }
+
+
+ /**
+ * 7.0 浣滃簾璁㈠崟鍜屼笟鍔¢」 鎻掑叆鎾ゅ崟璁板綍 绛夊緟鎾ゅ崟
+ *
+ * @param dataFlow
+ */
+ private void invalidOrderAndBusiness(IOrderNotifyDataFlowContext dataFlow) {
+ Date startDate = DateUtil.getCurrentDate();
+ if(MappingCache.getValue(MappingConstant.KEY_NO_SAVE_ORDER) != null
+ &&MappingCache.getValue(MappingConstant.KEY_NO_SAVE_ORDER).contains(dataFlow.getOrderTypeCd())){
+ //涓嶇敤浣滃簾璁㈠崟淇℃伅
+ // OrderDataFlowContextFactory.addCostTime(dataFlow, "invalidOrderAndBusiness", "浣滃簾璁㈠崟鍜屼笟鍔¢」鑰楁椂", startDate);
+ return ;
+ }
+
+ //濡傛灉宸茬粡浣滃簾 涓嶅瓨鍦� 鎴栧け璐ワ紝鍒欎笉鍋氬鐞�
+
+ Map order = centerServiceDaoImpl.getOrderInfoByBId(dataFlow.getbId());
+
+ if(order == null || !order.containsKey("status_cd") || StatusConstant.STATUS_CD_DELETE.equals(order.get("status_cd"))
+ || StatusConstant.STATUS_CD_ERROR.equals(order.get("status_cd"))){
+ return ;
+ }
+
+ //浣滃簾 璁㈠崟
+ centerServiceDaoImpl.updateOrder(OrderDataFlowContextFactory.getNeedInvalidOrder(dataFlow));
+
+ //浣滃簾璁㈠崟椤�
+ centerServiceDaoImpl.updateBusiness(OrderDataFlowContextFactory.getNeedInvalidOrder(dataFlow));
+
+ //灏嗗綋鍓嶈鍗曢」鏀逛负 鎾ゅ崟鐘舵��
+ centerServiceDaoImpl.updateBusinessByBId(OrderDataFlowContextFactory.getNeedDeleteBusiness(dataFlow));
+ //鎻掑叆鎾ゅ崟璁板綍
+ doAddDeleteOrderBusinessData(dataFlow);
+
+ //OrderDataFlowContextFactory.addCostTime(dataFlow, "invalidOrderAndBusiness", "浣滃簾璁㈠崟鍜屼笟鍔¢」鑰楁椂", startDate);
+ }
+
+
+ /**
+ * 8.0 骞挎挱浣滃簾宸茬粡瀹屾垚涓氬姟绯荤粺璁㈠崟淇℃伅
+ *
+ * @param dataFlow
+ */
+ private void invalidCompletedBusinessSystem(IOrderNotifyDataFlowContext dataFlow) throws Exception{
+
+ if(!StatusConstant.REQUEST_BUSINESS_TYPE_INSTANCE.equals(dataFlow.getBusinessType())) {
+ return ;
+ }
+
+ //鍒ゆ柇 璁㈠崟instance 鏄惁閮藉彉鎴愪簡鎾ゅ崟鐘舵��
+ if(centerServiceDaoImpl.judgeAllBusinessDeleteOrder(dataFlow.getoId(),StatusConstant.STATUS_CD_DELETE_ORDER) < 1){
+ return ;
+ }
+
+ // 鏍规嵁 c_business 琛ㄤ腑鐨勫瓧娈礲usiness_type_cd 鎵惧埌瀵瑰簲鐨勬秷鎭槦鍒楀悕绉�
+ Map paramIn = new HashMap();
+ paramIn.put("oId",dataFlow.getoId());
+ paramIn.put("statusCd",StatusConstant.STATUS_CD_DELETE_ORDER);
+ List<Map> completedBusinesses = centerServiceDaoImpl.getBusinessByOId(paramIn);
+ for(Map completedBusiness : completedBusinesses){
+ ServiceBusiness serviceBusiness = ServiceBusinessUtil.getServiceBusiness(completedBusiness.get("business_type_cd").toString());
+ long startTime = DateUtil.getCurrentDate().getTime();
+ //鍙戣捣鎾ゅ崟
+ KafkaFactory.sendKafkaMessage(serviceBusiness.getMessageTopic(),"",
+ OrderDataFlowContextFactory.getDeleteInstanceTableJson(dataFlow,completedBusiness).toJSONString());
+ //saveLogMessage(OrderDataFlowContextFactory.getDeleteInstanceTableJson(dataFlow,completedBusiness,appRoute.getAppService()),null);
+ }
+ }
+
+ /**
+ * 9.0 灏嗚鍗曠姸鎬佹敼涓哄け璐ワ紝浜哄伐澶勭悊銆�
+ *
+ * @param dataFlow
+ */
+ private void updateOrderAndBusinessError(IOrderDataFlowContext dataFlow) {
+
+ Date startDate = DateUtil.getCurrentDate();
+
+ //浣滃簾 璁㈠崟
+ centerServiceDaoImpl.updateOrder(OrderDataFlowContextFactory.getNeedErrorOrder(dataFlow));
+
+ //浣滃簾璁㈠崟椤�
+ centerServiceDaoImpl.updateBusiness(OrderDataFlowContextFactory.getNeedErrorOrder(dataFlow));
+
+
+ OrderDataFlowContextFactory.addCostTime(dataFlow, "updateOrderAndBusinessError", "璁㈠崟鐘舵�佹敼涓哄け璐ヨ�楁椂", startDate);
+
+ }
+
+
+ /**
+ * 9.0 灏嗚鍗曠姸鎬佹敼涓哄け璐ワ紝浜哄伐澶勭悊銆�
+ *
+ * @param dataFlow
+ */
+ private void updateOrderAndBusinessError(IOrderNotifyDataFlowContext dataFlow) {
+
+ Date startDate = DateUtil.getCurrentDate();
+
+ //浣滃簾 璁㈠崟
+ centerServiceDaoImpl.updateOrder(OrderDataFlowContextFactory.getNeedErrorOrder(dataFlow));
+
+ //浣滃簾璁㈠崟椤�
+ centerServiceDaoImpl.updateBusiness(OrderDataFlowContextFactory.getNeedErrorOrder(dataFlow));
+
+
+ //OrderDataFlowContextFactory.addCostTime(dataFlow, "updateOrderAndBusinessError", "璁㈠崟鐘舵�佹敼涓哄け璐ヨ�楁椂", startDate);
+
+ }
+ /**
+ * 灏嗚鍗曠姸鎬佹敼涓轰綔搴熺姸鎬併��
+ *
+ * @param dataFlow
+ */
+ private void updateOrderAndBusinessDelete(IOrderDataFlowContext dataFlow) {
+
+ Date startDate = DateUtil.getCurrentDate();
+
+ //浣滃簾 璁㈠崟
+ centerServiceDaoImpl.updateOrder(OrderDataFlowContextFactory.getNeedInvalidOrder(dataFlow));
+
+ //浣滃簾璁㈠崟椤�
+ centerServiceDaoImpl.updateBusiness(OrderDataFlowContextFactory.getNeedDeleteBusiness(dataFlow));
+
+ //鍔犲叆鎾ゅ崟璁板綍
+ //doAddDeleteOrderBusinessData(dataFlow);
+
+
+
+ OrderDataFlowContextFactory.addCostTime(dataFlow, "updateOrderAndBusinessError", "璁㈠崟鐘舵�佹敼涓哄け璐ヨ�楁椂", startDate);
+
+ }
+
+ /**
+ * 鍔犲叆鎾ゅ崟璁板綍
+ * @param dataFlow
+ */
+ private void doAddDeleteOrderBusinessData(IOrderDataFlowContext dataFlow){
+ /* Map business = new HashMap();
+ business.put("bId",SequenceUtil.getBId());
+ business.put("oId",dataFlow.getoId());
+ business.put("businessTypeCd",StatusConstant.REQUEST_BUSINESS_TYPE_DELETE);
+ business.put("remark","鍙戣捣鎾ゅ崟");
+ business.put("statusCd",StatusConstant.STATUS_CD_DELETE_ORDER);*/
+ centerServiceDaoImpl.saveBusiness(OrderDataFlowContextFactory.getDeleteOrderBusiness(dataFlow,"璁㈠崟澶辫触锛屽姞鍏ユ挙鍗�"));
+ }
+
+ /**
+ * 鍔犲叆鎾ゅ崟璁板綍
+ * @param dataFlow
+ */
+ private void doAddDeleteOrderBusinessData(IOrderNotifyDataFlowContext dataFlow){
+ /* Map business = new HashMap();
+ business.put("bId",SequenceUtil.getBId());
+ business.put("oId",dataFlow.getoId());
+ business.put("businessTypeCd",StatusConstant.REQUEST_BUSINESS_TYPE_DELETE);
+ business.put("remark","鍙戣捣鎾ゅ崟");
+ business.put("statusCd",StatusConstant.STATUS_CD_DELETE_ORDER);*/
+ centerServiceDaoImpl.saveBusiness(OrderDataFlowContextFactory.getDeleteOrderBusiness(dataFlow,"璁㈠崟澶辫触锛屽姞鍏ユ挙鍗�"));
+ }
+
+
+
+ /**
+ * 鎺ュ彈涓氬姟绯荤粺閫氱煡娑堟伅
+ * @param receiveJson 鎺ュ彈鎶ユ枃
+ * @throws SMOException
+ */
+ @Override
+ public void receiveBusinessSystemNotifyMessage(String receiveJson) throws SMOException{
+ Date startDate = DateUtil.getCurrentDate();
+ IOrderNotifyDataFlowContext dataFlow = null;
+ try {
+ //1.0 鍒涘缓鏁版嵁娴�
+ dataFlow = OrderDataFlowContextFactory.newInstance(OrderNotifyDataFlow.class).builder(receiveJson,null);
+ //濡傛灉璁㈠崟閮芥病鏈変繚瀛橈紝鍒欏啀涓嶈澶勭悊
+ if(MappingCache.getValue(MappingConstant.KEY_NO_SAVE_ORDER) != null
+ &&MappingCache.getValue(MappingConstant.KEY_NO_SAVE_ORDER).contains(dataFlow.getOrderTypeCd())){
+ //涓嶄繚瀛樿鍗曚俊鎭�
+ return ;
+ }
+
+ //濡傛灉涓嶆槸 business 鍜宨nstance 杩囩▼ 鍒欑洿鎺ヨ烦鍑�
+ judgeBusinessOrInstance(dataFlow);
+
+ //2.0鍔犺浇鏁版嵁锛屾病鏈夋壘鍒癮ppId 鍙婇厤缃俊鎭� 鍒欐姏鍑篒nitConfigDataException
+ reloadOrderInfo(dataFlow);
+
+ //3.0 鍒ゆ柇鏄惁鎴愬姛,澶辫触浼氭姏鍑築usinessStatusException寮傚父
+ judgeBusinessStatusAndCompleteBusiness(dataFlow);
+
+ //4.0 淇敼涓氬姟涓烘垚鍔�,濡傛灉鍙戠幇涓氬姟椤瑰凡缁忔槸浣滃簾鎴栧け璐ョ姸鎬侊紙D鎴朎锛夊垯鎶涘嚭BusinessException寮傚父
+ //completeBusiness(dataFlow);
+
+ //5.0 鍒ゆ柇 鍙戣捣 Instance 鏉′欢鏄惁婊¤冻锛屽鏋滄弧瓒� 鍙戣捣 Instance杩囩▼
+ judgeSendToInstance(dataFlow);
+
+ //7.0 鍒ゆ柇鎾ゅ崟鏉′欢鏄惁婊¤冻锛屽鏋滄弧瓒冲彂璧锋挙鍗�
+ invalidCompletedBusinessSystem(dataFlow);
+
+ }catch (BusinessStatusException e){
+
+ logger.error("璁㈠崟澶辫触:" ,e);
+ //8.0 灏嗚鍗曠姸鎬佹敼涓哄け璐ワ紝浜哄伐澶勭悊銆�
+ updateOrderAndBusinessError(dataFlow);
+
+ }catch (BusinessException e) {
+ //9.0璇存槑杩欎釜璁㈠崟宸茬粡澶辫触浜嗭紝鍐嶄笉闇�瑕�
+ //鎯虫硶锛岃繖閲屽箍鎾綋鍓嶅け璐ヤ笟鍔�
+ logger.error("淇敼涓氬姟鏁版嵁澶辫触",e);
+ }/*catch (InitConfigDataException e){ //杩欑涓�鑸笉浼氬嚭鐜帮紝闄ら潪浜哄伐鏀逛簡鏁版嵁
+ LoggerEngine.error("鍔犺浇閰嶇疆鏁版嵁鍑洪敊", e);
+ try {
+ //6.0 浣滃簾璁㈠崟鍜屾墍鏈変笟鍔¢」
+ invalidOrderAndBusiness(dataFlow);
+ //7.0 骞挎挱浣滃簾涓氬姟绯荤粺璁㈠崟淇℃伅,杩欓噷鍙湁 Instance 澶辫触鍚庢墠鍙戣捣 鎾ゅ崟
+ if(StatusConstant.REQUEST_BUSINESS_TYPE_INSTANCE.equals(dataFlow.getBusinessType())) {
+ invalidCompletedBusinessSystem(dataFlow);
+ }
+ } catch (Exception e1) {
+ LoggerEngine.error("浣滃簾璁㈠崟澶辫触", e1);
+ //8.0 灏嗚鍗曠姸鎬佹敼涓哄け璐ワ紝浜哄伐澶勭悊銆�
+ updateOrderAndBusinessError(dataFlow);
+ }
+
+ }*/catch (NoSupportException e){
+ LoggerEngine.error("褰撳墠涓氬姟涓嶆敮鎸�", e);
+ }catch (Exception e){
+ LoggerEngine.error("浣滃簾璁㈠崟澶辫触", e);
+ //10.0 鎴愬姛鐨勬儏鍐典笅閫氱煡涓嬫父绯荤粺澶辫触灏嗙姸鎬佹敼涓篘E锛屼汉宸ュ鐞嗐��
+ updateBusinessNotifyError(dataFlow);
+ }finally{
+ /*OrderDataFlowContextFactory.addCostTime(dataFlow, "receiveBusinessSystemNotifyMessage", "鎺ュ彈涓氬姟绯荤粺閫氱煡娑堟伅鑰楁椂", startDate);
+ saveLogMessage(dataFlow,LogAgent.createLogMessage(dataFlow.getRequestCurrentHeaders(),dataFlow.getReqJson().toJSONString()),
+ LogAgent.createLogMessage(dataFlow.getResponseCurrentHeaders(),ResponseConstant.RESULT_CODE_SUCCESS),
+ DateUtil.getCurrentDate().getTime() - dataFlow.getStartDate().getTime());*/
+ }
+ }
+
+ /**
+ * Instance杩囩▼
+ * @param dataFlow
+ */
+ private void doSendInstance(IOrderNotifyDataFlowContext dataFlow) {
+ if(dataFlow == null || !StatusConstant.REQUEST_BUSINESS_TYPE_BUSINESS.equals(dataFlow.getBusinessType())){
+ return ;
+ }
+ try {
+ ServiceBusiness serviceBusiness = ServiceBusinessUtil.getServiceBusiness(dataFlow.getBusinessTypeCd());
+ KafkaFactory.sendKafkaMessage(serviceBusiness.getMessageTopic(), "",
+ OrderDataFlowContextFactory.getBusinessTableDataInfoToInstanceTableJson(dataFlow).toJSONString());
+ }catch (Exception e){
+
+ }
+
+ }
+
+ /**
+ * 鍒ゆ柇鏄惁鏄� business 鎴栬�� instance杩囩▼
+ * @param dataFlow
+ * @throws NoSupportException
+ */
+ private void judgeBusinessOrInstance(IOrderNotifyDataFlowContext dataFlow) throws NoSupportException{
+
+ if(dataFlow == null || StatusConstant.REQUEST_BUSINESS_TYPE_BUSINESS.equals(dataFlow.getBusinessType()) ||
+ StatusConstant.REQUEST_BUSINESS_TYPE_INSTANCE.equals(dataFlow.getBusinessType())){
+ return ;
+ }
+
+ throw new NoSupportException(ResponseConstant.RESULT_PARAM_ERROR,"褰撳墠鍙敮鎸� Business 鍜� Instance杩囩▼");
+ }
+
+
+ /**
+ * 2.0閲嶆柊鍔犺浇璁㈠崟淇℃伅鍒癲ataFlow 涓�
+ *
+ * @param dataFlow
+ */
+ private void reloadOrderInfoAndConfigData(DataFlow dataFlow) {
+
+ Map order = centerServiceDaoImpl.getOrderInfoByBId(dataFlow.getBusinesses().get(0).getbId());
+ dataFlow.setoId(order.get("o_id").toString());
+ dataFlow.setAppId(order.get("app_id").toString());
+ if("-1".equals(dataFlow.getDataFlowId()) || StringUtil.isNullOrNone(dataFlow.getDataFlowId())){
+ throw new InitConfigDataException(ResponseConstant.RESULT_CODE_ERROR,"璇锋眰鎶ユ枃涓病鏈夊寘鍚� dataFlowId 鑺傜偣");
+ }
+ //閲嶆柊鍒风鍙d俊鎭�
+ ServiceInfoListener serviceInfoListener = ApplicationContextFactory.getBean("serviceInfoListener",ServiceInfoListener.class);
+ if(serviceInfoListener != null){
+ dataFlow.setPort(serviceInfoListener.getServerPort()+"");
+ }
+ //閲嶆柊鍔犺浇閰嶇疆
+ //initConfigData(dataFlow);
+ }
+
+
+ /**
+ * 2.0閲嶆柊鍔犺浇璁㈠崟淇℃伅鍒癲ataFlow 涓�
+ *
+ * @param dataFlow
+ */
+ private void reloadOrderInfo(IOrderNotifyDataFlowContext dataFlow) {
+
+ Map order = centerServiceDaoImpl.getOrderInfoByBId(dataFlow.getbId());
+ dataFlow.setoId(order.get("o_id").toString());
+ if("-1".equals(dataFlow.getDataFlowId()) || StringUtil.isNullOrNone(dataFlow.getDataFlowId())){
+ throw new InitConfigDataException(ResponseConstant.RESULT_CODE_ERROR,"璇锋眰鎶ユ枃涓病鏈夊寘鍚� dataFlowId 鑺傜偣");
+ }
+ }
+
+ /**
+ * 9.0 鎴愬姛鐨勬儏鍐典笅閫氱煡涓嬫父绯荤粺澶辫触灏嗙姸鎬佹敼涓篘E锛屼汉宸ュ鐞嗐��
+ *
+ * @param dataFlow
+ */
+ private void updateBusinessNotifyError(IOrderNotifyDataFlowContext dataFlow) {
+
+ Date startDate = DateUtil.getCurrentDate();
+ //瀹屾垚璁㈠崟椤�
+ centerServiceDaoImpl.updateBusinessByBId(OrderDataFlowContextFactory.getNeedNotifyErrorBusiness(dataFlow));
+
+ // OrderDataFlowContextFactory.addCostTime(dataFlow, "updateBusinessNotifyError", "璁㈠崟鐘舵�佹敼涓哄け璐ヨ�楁椂", startDate);
+
+ }
+
+ /**
+ * 鍒ゆ柇鏄惁閮芥垚鍔熶簡
+ * @param dataFlow
+ */
+ private void judgeBusinessStatusAndCompleteBusiness(IOrderNotifyDataFlowContext dataFlow) throws BusinessStatusException{
+
+ //List<Business> businesses = dataFlow.getBusinesses();
+
+ //1.0 鍒ゆ柇鏄惁瀛樺湪鎾ゅ崟锛屽鏋滄槸鎾ゅ崟鍒欏皢褰撳墠 bId 鏍囪涓烘挙鍗曠姸鎬�
+ if(StatusConstant.REQUEST_BUSINESS_TYPE_INSTANCE.equals(dataFlow.getBusinessType())) {
+ Map businessMap = centerServiceDaoImpl.getDeleteOrderBusinessByOId(dataFlow.getoId());
+ if(businessMap != null && !businessMap.isEmpty()){
+ centerServiceDaoImpl.updateBusinessByBId(OrderDataFlowContextFactory.getNeedDeleteBusiness(dataFlow));
+ return ;
+ }
+ }
+
+ //Business business = dataFlow.getCurrentBusiness();
+ if(!ResponseConstant.RESULT_CODE_SUCCESS.equals(((IOrderResponse)dataFlow).getCode())){
+ //throw new BusinessStatusException(business.getCode(),"涓氬姟bId= "+business.getbId() + " 澶勭悊澶辫触锛岄渶瑕佷綔搴熻鍗�");
+ //浣滃簾璁㈠崟鍜屼笟鍔¢」 鎻掑叆鎾ゅ崟璁板綍 绛夊緟鎾ゅ崟
+ invalidOrderAndBusiness(dataFlow);
+ }else{
+ completeBusiness(dataFlow);
+ }
+
+ }
+
+ /**
+ * 3.0 淇敼涓氬姟涓烘垚鍔�,濡傛灉鍙戠幇涓氬姟椤瑰凡缁忔槸浣滃簾鎴栧け璐ョ姸鎬侊紙D鎴朎锛夊垯鎶涘嚭BusinessException寮傚父
+ *
+ * @param dataFlow
+ */
+ private void completeBusiness(IOrderNotifyDataFlowContext dataFlow) throws BusinessException{
+ try {
+ if(StatusConstant.REQUEST_BUSINESS_TYPE_INSTANCE.equals(dataFlow.getBusinessType())) {
+ //瀹屾垚璁㈠崟椤�
+ centerServiceDaoImpl.updateBusinessByBId(OrderDataFlowContextFactory.getNeedCompleteBusiness(dataFlow));
+
+ //濡傛灉涓氬姟閮藉畬鎴愶紝鍒欏皢 璁㈠崟鏀逛负瀹屾垚鐘舵��
+ centerServiceDaoImpl.completeOrderByBId(dataFlow.getbId());
+ }else if(StatusConstant.REQUEST_BUSINESS_TYPE_BUSINESS.equals(dataFlow.getBusinessType())) {
+ centerServiceDaoImpl.updateBusinessByBId(OrderDataFlowContextFactory.getNeedBusinessComplete(dataFlow));
+ }else{ //杩欓噷鍒颁笉浜嗭紝鍓嶉潰鍋氫簡鏍¢獙
+ throw new BusinessException(ResponseConstant.RESULT_PARAM_ERROR,"褰撳墠涓嶆敮鎸� 涓氬姟绫诲瀷涓� businessType" +dataFlow.getBusinessType());
+ }
+
+ }catch (DAOException e){
+ throw new BusinessException(e.getResult(),e);
+ }
+ }
+
+ /**
+ * //4.0褰撴墍鏈変笟鍔″姩浣滄槸鍚﹂兘鏄疌锛屽皢璁㈠崟淇℃伅鏀逛负 C 骞朵笖鍙戝竷绔e伐娑堟伅锛岃繖閲屽湪骞挎挱涔嬪墠纭
+ * @param dataFlow
+ */
+ private void judgeSendToInstance(IOrderNotifyDataFlowContext dataFlow) throws Exception{
+ try {
+ if(centerServiceDaoImpl.judgeAllBusinessCompleted(dataFlow.getoId(),StatusConstant.STATUS_CD_BUSINESS_COMPLETE) > 0) {
+ //閫氱煡鎴愬姛娑堟伅
+ doSendInstance(dataFlow);
+ }
+ }catch (DAOException e){
+ //杩欓噷浠�涔堥兘涓嶅仛锛岃鏄庤鍗曟病鏈夊畬鎴�
+ }
+
+
+ }
+
+ /**
+ * 閫氱煡 璁㈠崟宸茬粡瀹屾垚锛屽悗绔渶瑕佸畬鎴愭暟鎹�
+ * @param dataFlow
+ */
+ private void notifyBusinessSystemSuccessMessage(IOrderNotifyDataFlowContext dataFlow) throws Exception{
+
+ long startTime = DateUtil.getCurrentDate().getTime();
+
+ ServiceBusiness serviceBusiness = ServiceBusinessUtil.getServiceBusiness(dataFlow.getBusinessTypeCd());
+ //鎷艰鎶ユ枃閫氱煡涓氬姟绯荤粺
+ KafkaFactory.sendKafkaMessage(serviceBusiness.getMessageTopic(),"",
+ OrderDataFlowContextFactory.getNotifyBusinessSuccessJson(dataFlow).toJSONString());
+
+ /*saveLogMessage(dataFlow,LogAgent.createLogMessage(dataFlow.getRequestCurrentHeaders(),OrderDataFlowContextFactory.getNotifyBusinessSuccessJson(dataFlow).toJSONString()),
+ LogAgent.createLogMessage(dataFlow.getResponseCurrentHeaders(),ResponseConstant.RESULT_CODE_SUCCESS),
+ DateUtil.getCurrentDate().getTime() - startTime);*/
+ }
+
+ /**
+ * 8.0 骞挎挱浣滃簾涓氬姟绯荤粺璁㈠崟淇℃伅
+ *
+ * @param dataFlow
+ */
+ private void notifyBusinessSystemErrorMessage(IOrderNotifyDataFlowContext dataFlow) throws Exception{
+ long startTime = DateUtil.getCurrentDate().getTime();
+
+ ServiceBusiness serviceBusiness = ServiceBusinessUtil.getServiceBusiness(dataFlow.getBusinessTypeCd());
+
+ //鎷艰鎶ユ枃閫氱煡涓氬姟绯荤粺
+ KafkaFactory.sendKafkaMessage(serviceBusiness.getMessageTopic(),"",
+ OrderDataFlowContextFactory.getNotifyBusinessErrorJson(dataFlow).toJSONString());
+ /*saveLogMessage(dataFlow,LogAgent.createLogMessage(dataFlow.getRequestCurrentHeaders(),OrderDataFlowContextFactory.getNotifyBusinessErrorJson(dataFlow).toJSONString()),
+ LogAgent.createLogMessage(dataFlow.getResponseCurrentHeaders(),ResponseConstant.RESULT_CODE_ERROR),
+ DateUtil.getCurrentDate().getTime() - startTime);*/
+ }
+
+ /**
+ * 澶勭悊鍚屾涓氬姟
+ * @param dataFlow
+ */
+ private void doSynchronousBusinesses(IOrderDataFlowContext dataFlow) throws BusinessException{
+ Date startDate = DateUtil.getCurrentDate();
+ List<Business> synchronousBusinesses = OrderDataFlowContextFactory.getSynchronousBusinesses(dataFlow);
+
+ List<Business> deleteBusinesses = new ArrayList<Business>();
+
+ if(synchronousBusinesses == null || synchronousBusinesses.size() == 0){
+ return ;
+ }
+ JSONArray responseBusinesses = new JSONArray();
+
+ //6.1澶勭悊鍚屾鏈嶅姟 鍙戣捣Business
+ doSaveDataInfoToBusinessTable(dataFlow, synchronousBusinesses, responseBusinesses);
+
+ try {
+ //6.2鍙戣捣Instance
+ doBusinessTableDataInfoToInstanceTable(dataFlow, synchronousBusinesses,deleteBusinesses);
+ }catch (Exception e){
+ try {
+ //杩欓噷鍙戣捣鎾ゅ崟閫昏緫
+ doDeleteOrderAndInstanceData(dataFlow, deleteBusinesses);
+ }catch (Exception e1){
+ logger.error("鎾ゅ崟澶辫触",e1);
+ //杩欓噷璁板綍鎾ゅ崟澶辫触鐨勪俊鎭�
+ }
+ throw new BusinessException(ResponseConstant.RESULT_PARAM_ERROR,e.getMessage());
+ }
+ //6.3 c_business 鏁版嵁淇敼涓哄畬鎴�
+ /*List<Business> asynchronousBusinesses = OrderDataFlowContextFactory.getAsynchronousBusinesses(dataFlow);
+ if(asynchronousBusinesses == null || asynchronousBusinesses.size() == 0){
+ doComplateOrderAndBusiness(dataFlow,synchronousBusinesses);
+ }*/
+ OrderDataFlowContextFactory.addCostTime(dataFlow, "doSynchronousBusinesses", "鍚屾璋冪敤涓氬姟绯荤粺鎬昏�楁椂", startDate);
+}
+
+ /**
+ * 鍙戣捣鎾ゅ崟涓氬姟
+ * @param dataFlow
+ * @param deleteBusinesses
+ */
+ private void doDeleteOrderAndInstanceData(IOrderDataFlowContext dataFlow, List<Business> deleteBusinesses) {
+
+ if(deleteBusinesses == null || deleteBusinesses.size() == 0){
+ return ;
+ }
+
+ //1.0 鍦╟_business 琛ㄤ腑鍔犲叆 鎾ゅ崟璁板綍
+ centerServiceDaoImpl.saveBusiness(OrderDataFlowContextFactory.getDeleteOrderBusiness(dataFlow,"涓氬姟绯荤粺瀹炰緥澶辫触锛屽彂璧锋挙鍗�"));
+ //2.0 浣滃簾 c_orders 鍜� c_business 鏁版嵁
+ updateOrderAndBusinessDelete(dataFlow);
+ //3.0 鍙戣捣 鎾ゅ崟涓氬姟
+ doDeleteBusinessSystemInstanceData(dataFlow,deleteBusinesses);
+ }
+
+ /**
+ * 瀹屾垚璁㈠崟鐘舵��
+ * @param synchronousBusinesses
+ */
+ /*private void doComplateOrderAndBusiness(DataFlow dataFlow,List<Business> synchronousBusinesses) {
+
+ //Complete Order and business
+ Map order = new HashMap();
+ order.put("oId",dataFlow.getoId());
+ order.put("statusCd", StatusConstant.STATUS_CD_COMPLETE);
+ order.put("finishTime",DateUtil.getCurrentDate());
+ centerServiceDaoImpl.updateOrder(order);
+ centerServiceDaoImpl.updateBusiness(order);
+ Date businessStartDate;
+ AppService service;
+ JSONObject requestBusinessJson;
+ for(Business business : synchronousBusinesses){
+ businessStartDate = DateUtil.getCurrentDate();
+ service = OrderDataFlowContextFactory.getService(dataFlow,business.getServiceCode());
+ if(!CommonConstant.INSTANCE_Y.equals(service.getIsInstance())){
+ continue;
+ }
+ requestBusinessJson = OrderDataFlowContextFactory.getCompleteInstanceDataJson(dataFlow,business);
+ JSONObject responseJson = doRequestBusinessSystem(dataFlow, service, requestBusinessJson);
+
+ OrderDataFlowContextFactory.addCostTime(dataFlow, business.getServiceCode(), "璋冪敤"+business.getServiceName()+"-doComplete鑰楁椂", businessStartDate);
+ saveLogMessage(dataFlow,LogAgent.createLogMessage(dataFlow.getRequestCurrentHeaders(),requestBusinessJson.toJSONString()),
+ LogAgent.createLogMessage(dataFlow.getResponseCurrentHeaders(),responseJson.toJSONString()),
+ DateUtil.getCurrentDate().getTime() - businessStartDate.getTime());
+ }
+
+ }*/
+
+ /**
+ * 灏咮usinessTable 涓殑鏁版嵁淇濆瓨鍒� InstanceTable
+ * @param dataFlow
+ * @param synchronousBusinesses
+ */
+ private void doBusinessTableDataInfoToInstanceTable(IOrderDataFlowContext dataFlow, List<Business> synchronousBusinesses,List<Business> deleteBusinesses) {
+ Date businessStartDate;
+ ServiceBusiness serviceBusiness;
+ JSONObject requestBusinessJson;
+ for(Business business : synchronousBusinesses){
+ businessStartDate = DateUtil.getCurrentDate();
+ serviceBusiness = ServiceBusinessUtil.getServiceBusiness(business.getBusinessTypeCd());
+ //娣诲姞闇�瑕佹挙鍗曠殑涓氬姟淇℃伅
+ deleteBusinesses.add(business);
+
+ requestBusinessJson = OrderDataFlowContextFactory.getBusinessTableDataInfoToInstanceTableJson(dataFlow,business);
+ JSONObject responseJson = doRequestBusinessSystem(dataFlow, serviceBusiness, requestBusinessJson);
+ //鍙戝竷浜嬩欢
+ DataFlowEventPublishing.invokeBusinessISuccess(dataFlow,business);
+ updateBusinessStatusCdByBId(business.getbId(),StatusConstant.STATUS_CD_COMPLETE);
+ OrderDataFlowContextFactory.addCostTime(dataFlow, business.getBusinessTypeCd(), "璋冪敤"+business.getBusinessTypeCd()+"鑰楁椂", businessStartDate);
+ /* saveLogMessage(dataFlow,LogAgent.createLogMessage(dataFlow.getRequestCurrentHeaders(),requestBusinessJson.toJSONString()),
+ LogAgent.createLogMessage(dataFlow.getResponseCurrentHeaders(),responseJson.toJSONString()),
+ DateUtil.getCurrentDate().getTime() - businessStartDate.getTime());*/
+ }
+
+ /* if(dataFlow.getCurrentBusiness() == null){
+ return ;
+ }*/
+
+ //鍒ゆ柇涓氬姟鍔ㄤ綔鏄惁閮界宸ワ紝涓昏鑰冭檻 璇锋眰鎶ユ枃涓� 鏈夊紓姝ヤ篃鏈夊悓姝ョ殑鎯呭喌
+ //濡傛灉涓氬姟閮藉畬鎴愶紝鍒欏皢 璁㈠崟鏀逛负瀹屾垚鐘舵��
+ centerServiceDaoImpl.completeOrderByOId(dataFlow.getOrders().getoId());
+ }
+
+ /**
+ * 涓氬姟绯荤粺鎾ゅ崟
+ * @param dataFlow
+ * @param deleteBusinesses
+ */
+ private void doDeleteBusinessSystemInstanceData(IOrderDataFlowContext dataFlow, List<Business> deleteBusinesses) {
+ Date businessStartDate;
+ JSONObject requestBusinessJson;
+ ServiceBusiness serviceBusiness;
+ for(Business business : deleteBusinesses){
+ businessStartDate = DateUtil.getCurrentDate();
+ requestBusinessJson = OrderDataFlowContextFactory.getDeleteInstanceTableJson(dataFlow,business);
+ serviceBusiness = ServiceBusinessUtil.getServiceBusiness(business.getBusinessTypeCd());
+ JSONObject responseJson = doRequestBusinessSystem(dataFlow, serviceBusiness, requestBusinessJson);
+ OrderDataFlowContextFactory.addCostTime(dataFlow, business.getBusinessTypeCd(), "璋冪敤"+business.getBusinessTypeCd()+"-鎾ゅ崟 鑰楁椂", businessStartDate);
+// saveLogMessage(dataFlow,LogAgent.createLogMessage(dataFlow.getRequestCurrentHeaders(),requestBusinessJson.toJSONString()),
+// LogAgent.createLogMessage(dataFlow.getResponseCurrentHeaders(),responseJson.toJSONString()),
+// DateUtil.getCurrentDate().getTime() - businessStartDate.getTime());
+ }
+ }
+
+ /**
+ * 璋冪敤涓嬫父绯荤粺
+ * @param dataFlow
+ * @param serviceBusiness
+ * @param requestBusinessJson 璇锋眰鎶ユ枃
+ * @return
+ */
+ private JSONObject doRequestBusinessSystem(IOrderDataFlowContext dataFlow, ServiceBusiness serviceBusiness, JSONObject requestBusinessJson) {
+ String responseMessage;
+
+ Assert.hasLength(serviceBusiness.getInvokeType(),"c_service_business琛ㄩ厤缃嚭閿欙紝invoke_type 涓嶈兘涓虹┖"+ serviceBusiness.getBusinessTypeCd());
+ if(ServiceBusinessConstant.INVOKE_TYPE_WEBSERVICE.equals(serviceBusiness.getInvokeType())) {//webservice鏂瑰紡
+ String url = serviceBusiness.getUrl();
+ String[] urls = url.split("#");
+
+ if(urls.length != 2){
+ throw new ConfigDataException(ResponseConstant.RESULT_CODE_CONFIG_ERROR,"閰嶇疆閿欒锛歝_service_business閰嶇疆url瀛楁閿欒"+serviceBusiness.getBusinessTypeCd());
+ }
+ String webserviceUrl = CodeMapUtil.getDynamicConstantValue(urls[0]);
+ String method = CodeMapUtil.getDynamicConstantValue(urls[1]);
+ responseMessage = (String) WebServiceAxisClient.callWebService(webserviceUrl,method,
+ new Object[]{requestBusinessJson.toJSONString()},
+ serviceBusiness.getTimeout());
+ }else if(ServiceBusinessConstant.INVOKE_TYPE_HTTP_POST.equals(serviceBusiness.getInvokeType())){
+ //http://user-service/test/sayHello
+ String httpPostUrl = CodeMapUtil.getDynamicConstantValue(serviceBusiness.getUrl());
+ responseMessage = restTemplate.postForObject(httpPostUrl,requestBusinessJson.toJSONString(),String.class);
+ }else if(ServiceBusinessConstant.INVOKE_TYPE_OUT_HTTP_POST.equals(serviceBusiness.getInvokeType())){
+ String httpPostUrl = CodeMapUtil.getDynamicConstantValue(serviceBusiness.getUrl());
+ responseMessage = restTemplateNoLoadBalanced.postForObject(httpPostUrl,requestBusinessJson.toJSONString(),String.class);
+ }
+ else {//post鏂瑰紡
+ throw new ConfigDataException(ResponseConstant.RESULT_CODE_CONFIG_ERROR,"閰嶇疆閿欒锛歝_service_business閰嶇疆url瀛楁閿欒,褰撳墠鏃犳硶璇嗗埆"+serviceBusiness.getBusinessTypeCd());
+ }
+
+ if(StringUtil.isNullOrNone(responseMessage) || !Assert.isJsonObject(responseMessage)){
+ throw new BusinessException(ResponseConstant.RESULT_CODE_INNER_ERROR,"涓嬫父绯荤粺杩斿洖鏍煎紡涓嶆纭紝璇锋寜鍗忚瑙勮寖澶勭悊");
+ }
+ JSONObject responseJson = JSONObject.parseObject(responseMessage);
+
+ Assert.jsonObjectHaveKey(responseJson,"response","涓嬫父杩斿洖鎶ユ枃鏍煎紡閿欒锛屾病鏈夊寘鍚玶esponseJson鑺傜偣銆�"+serviceBusiness.getBusinessTypeCd()+"銆�");
+
+ JSONObject responseInfo = responseJson.getJSONObject("response");
+
+ Assert.jsonObjectHaveKey(responseInfo,"code","涓嬫父杩斿洖鎶ユ枃鏍煎紡閿欒锛宺esponse 鑺傜偣涓病鏈夊寘鍚玞ode鑺傜偣銆�"+serviceBusiness.getBusinessTypeCd()+"銆�");
+
+ if(!ResponseConstant.RESULT_CODE_SUCCESS.equals(responseInfo.getString("code"))){
+ throw new BusinessException(ResponseConstant.RESULT_PARAM_ERROR,"涓氬姟绯荤粺澶勭悊澶辫触锛�"+responseInfo.getString("message"));
+ }
+ return responseJson;
+ }
+
+ private String doTransferRequestBusinessSystem(DataFlow dataFlow, AppService service, String reqData) {
+ String responseMessage;
+ if(service.getMethod() == null || "".equals(service.getMethod())) {//post鏂瑰紡
+ //http://user-service/test/sayHello
+ HttpHeaders header = new HttpHeaders();
+ for(String key : dataFlow.getRequestCurrentHeaders().keySet()){
+ header.add(key,dataFlow.getRequestCurrentHeaders().get(key));
+ }
+ HttpEntity<String> httpEntity = new HttpEntity<String>(reqData, header);
+ responseMessage = restTemplateNoLoadBalanced.postForObject(service.getUrl(),httpEntity,String.class);
+ }else{//webservice鏂瑰紡
+ responseMessage = (String) WebServiceAxisClient.callWebService(service.getUrl(),service.getMethod(),
+ new Object[]{dataFlow.getRequestBusinessJson().toJSONString()},
+ service.getTimeOut());
+ }
+ return responseMessage;
+ }
+
+ /**
+ * 鏁版嵁淇濆瓨鍒癇usinessTable 涓�
+ * @param dataFlow
+ * @param synchronousBusinesses
+ * @param responseBusinesses
+ */
+ private void doSaveDataInfoToBusinessTable(IOrderDataFlowContext dataFlow, List<Business> synchronousBusinesses, JSONArray responseBusinesses) {
+ Date businessStartDate;
+ ServiceBusiness serviceBusiness;
+ JSONObject requestBusinessJson;
+ for(Business business : synchronousBusinesses) {
+ businessStartDate = DateUtil.getCurrentDate();
+ //鍙戣捣Business杩囩▼
+ updateBusinessStatusCdByBId(business.getbId(),StatusConstant.STATUS_CD_BUSINESS);
+
+ serviceBusiness = ServiceBusinessUtil.getServiceBusiness(business.getBusinessTypeCd());
+ requestBusinessJson = OrderDataFlowContextFactory.getRequestBusinessJson(dataFlow,business);
+
+ JSONObject responseJson = doRequestBusinessSystem(dataFlow, serviceBusiness, requestBusinessJson);
+
+ //鍙戝竷浜嬩欢
+ DataFlowEventPublishing.invokeBusinessBSuccess(dataFlow,business);
+
+ responseBusinesses.add(responseJson);
+
+ OrderDataFlowContextFactory.addCostTime(dataFlow, business.getBusinessTypeCd(), "璋冪敤"+business.getBusinessTypeCd()+"鑰楁椂", businessStartDate);
+ /* saveLogMessage(null,LogAgent.createLogMessage(dataFlow.getRequestCurrentHeaders(),requestBusinessJson.toJSONString()),
+ LogAgent.createLogMessage(dataFlow.getResponseCurrentHeaders(),responseJson.toJSONString()),
+ DateUtil.getCurrentDate().getTime()-businessStartDate.getTime());*/
+ }
+ }
+
+ /**
+ * 澶勭悊寮傛涓氬姟
+ * @param
+ */
+ private void doAsynchronousBusinesses(IOrderDataFlowContext dataFlow) throws BusinessException{
+ Date startDate = DateUtil.getCurrentDate();
+ //6.3 澶勭悊寮傛锛屾寜娑堟伅闃熼噷澶勭悊
+ List<Business> asynchronousBusinesses = OrderDataFlowContextFactory.getAsynchronousBusinesses(dataFlow);
+
+ if(asynchronousBusinesses == null || asynchronousBusinesses.size() == 0){
+ return ;
+ }
+ ServiceBusiness serviceBusiness;
+ try {
+ for (Business business : asynchronousBusinesses) {
+ serviceBusiness = ServiceBusinessUtil.getServiceBusiness(business.getBusinessTypeCd());
+ KafkaFactory.sendKafkaMessage(serviceBusiness.getMessageTopic(), "",
+ OrderDataFlowContextFactory.getRequestBusinessJson(dataFlow,business).toJSONString());
+ }
+ }catch (Exception e){
+ throw new BusinessException(ResponseConstant.RESULT_CODE_INNER_ERROR,e.getMessage());
+ }
+
+ OrderDataFlowContextFactory.addCostTime(dataFlow, "doSynchronousBusinesses", "寮傛璋冪敤涓氬姟绯荤粺鎬昏�楁椂", startDate);
+// saveLogMessage(dataFlow,LogAgent.createLogMessage(dataFlow.getRequestCurrentHeaders(),dataFlow.getRequestBusinessJson().toJSONString()),
+// LogAgent.createLogMessage(dataFlow.getRequestCurrentHeaders(),dataFlow.getResponseBusinessJson().toJSONString()),
+// DateUtil.getCurrentDate().getTime()-startDate.getTime());
+ }
+
+
+ /**
+ * 淇濆瓨鏃ュ織淇℃伅
+ * @param dataFlow 鏁版嵁娴佸璞� 灏佽鐢ㄦ埛璇锋眰鐨勪俊鎭�
+ *
+ * @param requestJson 璇锋眰鎶ユ枃 鏍煎紡涓�
+ * {"headers":"",
+ * "body":""
+ * }
+ * @param responseJson 璇锋眰鎶ユ枃 鏍煎紡涓�
+ * {"headers":"",
+ * "body":""
+ * }
+ */
+ private void saveLogMessage(DataFlow dataFlow,JSONObject requestJson,JSONObject responseJson,long costTime){
+ LogAgent.sendLog(dataFlow,requestJson,responseJson,costTime);
+ }
+
+ /**
+ * 淇濆瓨鏃ュ織淇℃伅
+ * @param requestJson
+ */
+ private void saveLogMessage(String requestJson,String responseJson){
+
+ try{
+ if(MappingConstant.VALUE_ON.equals(MappingCache.getValue(MappingConstant.KEY_LOG_ON_OFF))){
+ JSONObject log = new JSONObject();
+ log.put("request",requestJson);
+ log.put("response",responseJson);
+ KafkaFactory.sendKafkaMessage(KafkaConstant.TOPIC_LOG_NAME,"",log.toJSONString());
+ }
+ }catch (Exception e){
+ logger.error("鎶ラ敊鏃ュ織鍑洪敊浜嗭紝",e);
+ }
+ }
+
+ /**
+ * 淇濆瓨鑰楁椂淇℃伅
+ * @param dataFlow
+ */
+ private void saveCostTimeLogMessage(DataFlow dataFlow){
+ try{
+ if(MappingConstant.VALUE_ON.equals(MappingCache.getValue(MappingConstant.KEY_COST_TIME_ON_OFF))){
+ List<DataFlowLinksCost> dataFlowLinksCosts = dataFlow.getLinksCostDates();
+ JSONObject costDate = new JSONObject();
+ JSONArray costDates = new JSONArray();
+ JSONObject newObj = null;
+ for(DataFlowLinksCost dataFlowLinksCost : dataFlowLinksCosts){
+ newObj = JSONObject.parseObject(JSONObject.toJSONString(dataFlowLinksCost));
+ newObj.put("dataFlowId",dataFlow.getDataFlowId());
+ newObj.put("transactionId",dataFlow.getTransactionId());
+ costDates.add(newObj);
+ }
+ costDate.put("costDates",costDates);
+
+ KafkaFactory.sendKafkaMessage(KafkaConstant.TOPIC_COST_TIME_LOG_NAME,"",costDate.toJSONString());
+ }
+ }catch (Exception e){
+ logger.error("鎶ラ敊鏃ュ織鍑洪敊浜嗭紝",e);
+ }
+ }
+
+ /**
+ * 淇敼c_business鐘舵��
+ * @param bId
+ * @param statusCd
+ */
+ private void updateBusinessStatusCdByBId(String bId,String statusCd){
+ Map business = new HashMap();
+ business.put("bId",bId);
+ business.put("statusCd",statusCd);
+ business.put("finishTime",DateUtil.getCurrentDate());
+ centerServiceDaoImpl.updateBusinessByBId(business);
+ }
+
+ public ICenterServiceDAO getCenterServiceDaoImpl() {
+ return centerServiceDaoImpl;
+ }
+
+ public void setCenterServiceDaoImpl(ICenterServiceDAO centerServiceDaoImpl) {
+ this.centerServiceDaoImpl = centerServiceDaoImpl;
+ }
+
+ public RestTemplate getRestTemplate() {
+ return restTemplate;
+ }
+
+ public void setRestTemplate(RestTemplate restTemplate) {
+ this.restTemplate = restTemplate;
+ }
+
+ public IQueryServiceSMO getQueryServiceSMOImpl() {
+ return queryServiceSMOImpl;
+ }
+
+ public void setQueryServiceSMOImpl(IQueryServiceSMO queryServiceSMOImpl) {
+ this.queryServiceSMOImpl = queryServiceSMOImpl;
+ }
+
+ public RestTemplate getRestTemplateNoLoadBalanced() {
+ return restTemplateNoLoadBalanced;
+ }
+
+ public void setRestTemplateNoLoadBalanced(RestTemplate restTemplateNoLoadBalanced) {
+ this.restTemplateNoLoadBalanced = restTemplateNoLoadBalanced;
+ }
+}
--
Gitblit v1.8.0