Sfoglia il codice sorgente

调整订单调度流程 提供 预提交 和确认提交功能

wuxw 6 anni fa
parent
commit
b8adeace2a

+ 17 - 1
OrderService/src/main/java/com/java110/order/api/OrderApi.java

@@ -1,6 +1,8 @@
 package com.java110.order.api;
 
 import com.alibaba.fastjson.JSONObject;
+import com.java110.entity.order.Orders;
+import com.java110.order.smo.IOrderProcessServiceSMO;
 import com.java110.utils.constant.ResponseConstant;
 import com.java110.utils.exception.BusinessException;
 import com.java110.utils.util.Assert;
@@ -37,6 +39,9 @@ public class OrderApi extends BaseController {
     @Autowired
     private IOrderServiceSMO orderServiceSMOImpl;
 
+    @Autowired
+    private IOrderProcessServiceSMO orderProcessServiceSMOImpl;
+
     /**
      * 订单请求服务
      * @param orderInfo 订单信息
@@ -58,7 +63,18 @@ public class OrderApi extends BaseController {
             DataFlowEventPublishing.receiveRequest(orderInfo, headers);
             //预校验
             preValiateOrderInfo(orderInfo);
-            responseEntity = orderServiceSMOImpl.service(orderInfo, headers);
+            JSONObject order = JSONObject.parseObject(orderInfo).getJSONObject("orders");
+
+            if(!order.containsKey("orderProcess")){
+                responseEntity = orderServiceSMOImpl.service(orderInfo, headers);
+            }else if(Orders.ORDER_PROCESS_ORDER_PRE_SUBMIT.equals(order.getString("orderProcess"))){
+                responseEntity = orderProcessServiceSMOImpl.preService(orderInfo, headers);
+            }else if(Orders.ORDER_PROCESS_ORDER_CONFIRM_SUBMIT.equals(order.getString("orderProcess"))){
+                responseEntity = orderProcessServiceSMOImpl.confirmService(orderInfo, headers);
+            }else{
+                responseEntity = orderServiceSMOImpl.service(orderInfo, headers);
+            }
+
         } catch (Exception e) {
             logger.error("请求订单异常", e);
             responseEntity = new ResponseEntity<String>("请求中心服务发生异常," + e.getMessage(), HttpStatus.INTERNAL_SERVER_ERROR);

+ 28 - 0
OrderService/src/main/java/com/java110/order/smo/IOrderProcessServiceSMO.java

@@ -0,0 +1,28 @@
+package com.java110.order.smo;
+
+import com.java110.utils.exception.SMOException;
+import org.springframework.http.ResponseEntity;
+
+import java.util.Map;
+
+public interface IOrderProcessServiceSMO {
+
+    /**
+     * 预生单
+     * @param reqJson
+     * @param headers
+     * @return
+     * @throws SMOException
+     */
+    public ResponseEntity<String> preService(String reqJson, Map<String, String> headers) throws SMOException;
+
+    /**
+     * 确认提交方法
+     * @param reqJson
+     * @param headers
+     * @return
+     * @throws SMOException
+     */
+    public ResponseEntity confirmService(String reqJson, Map<String, String> headers) throws SMOException;
+
+}

+ 397 - 0
OrderService/src/main/java/com/java110/order/smo/impl/AbstractOrderServiceSMOImpl.java

@@ -0,0 +1,397 @@
+package com.java110.order.smo.impl;
+
+import com.alibaba.fastjson.JSONArray;
+import com.alibaba.fastjson.JSONObject;
+import com.java110.core.client.RestTemplate;
+import com.java110.core.context.IOrderDataFlowContext;
+import com.java110.core.factory.OrderDataFlowContextFactory;
+import com.java110.entity.order.Business;
+import com.java110.entity.order.ServiceBusiness;
+import com.java110.event.center.DataFlowEventPublishing;
+import com.java110.order.dao.ICenterServiceDAO;
+import com.java110.utils.cache.MappingCache;
+import com.java110.utils.constant.MappingConstant;
+import com.java110.utils.constant.ResponseConstant;
+import com.java110.utils.constant.ServiceBusinessConstant;
+import com.java110.utils.constant.StatusConstant;
+import com.java110.utils.exception.BusinessException;
+import com.java110.utils.exception.ConfigDataException;
+import com.java110.utils.exception.OrdersException;
+import com.java110.utils.exception.RuleException;
+import com.java110.utils.util.*;
+import org.slf4j.Logger;
+import org.slf4j.LoggerFactory;
+import org.springframework.beans.factory.annotation.Autowired;
+
+import java.util.*;
+
+public abstract class AbstractOrderServiceSMOImpl {
+
+    private static Logger logger = LoggerFactory.getLogger(AbstractOrderServiceSMOImpl.class);
+
+
+    @Autowired
+    protected ICenterServiceDAO centerServiceDaoImpl;
+
+
+    @Autowired
+    protected RestTemplate restTemplate;
+
+    @Autowired
+    protected RestTemplate restTemplateNoLoadBalanced;
+
+    /**
+     * 4.0规则校验
+     *
+     * @param dataFlow
+     * @throws RuleException
+     */
+    protected 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
+     */
+    protected 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);
+    }
+
+    /**
+     * 刷返回值
+     *
+     * @param dataFlow
+     */
+    protected void refreshOrderDataFlowResJson(IOrderDataFlowContext dataFlow) {
+
+//        if(dataFlow.getResJson() == null || dataFlow.getResJson().isEmpty()){
+//            JSONObject resJson = new JSONObject();
+//            resJson.put("msg","成功");
+//            dataFlow.setResJson(resJson);
+//        }
+
+    }
+
+
+    /**
+     * 6.0 调用下游系统
+     *
+     * @param dataFlow
+     * @throws BusinessException
+     */
+    protected void invokeBusinessSystem(IOrderDataFlowContext dataFlow) throws BusinessException {
+        Date startDate = DateUtil.getCurrentDate();
+        //6.1 先处理同步方式的服务,每一同步后发布事件广播
+
+        doSynchronousBusinesses(dataFlow);
+
+        //6.2 处理异步服务
+        doAsynchronousBusinesses(dataFlow);
+
+
+        OrderDataFlowContextFactory.addCostTime(dataFlow, "invokeBusinessSystem", "调用下游系统耗时", startDate);
+    }
+
+    protected  void doAsynchronousBusinesses(IOrderDataFlowContext dataFlow){
+
+    }
+
+
+    /**
+     * 处理同步业务
+     *
+     * @param dataFlow
+     */
+    protected 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);
+    }
+
+
+    /**
+     * 数据保存到BusinessTable 中
+     *
+     * @param dataFlow
+     * @param synchronousBusinesses
+     * @param responseBusinesses
+     */
+    protected 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, responseJson);
+
+            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());*/
+        }
+    }
+
+
+    /**
+     * 将BusinessTable 中的数据保存到 InstanceTable
+     *
+     * @param dataFlow
+     * @param synchronousBusinesses
+     */
+    protected 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
+     */
+    protected void doDeleteOrderAndInstanceData(IOrderDataFlowContext dataFlow, List<Business> deleteBusinesses) {
+
+        if (deleteBusinesses == null || deleteBusinesses.size() == 0) {
+            return;
+        }
+
+        //1.0 在c_business 表中加入 撤单记录
+        centerServiceDaoImpl.saveBusiness(OrderDataFlowContextFactory.getDeleteOrderBusiness(dataFlow, "业务系统实例失败,发起撤单"));
+        //2.0 作废 c_orders 和 c_business 数据
+        updateOrderAndBusinessDelete(dataFlow,deleteBusinesses);
+        //3.0 发起 撤单业务
+        doDeleteBusinessSystemInstanceData(dataFlow, deleteBusinesses);
+    }
+
+    /**
+     * 修改c_business状态
+     *
+     * @param bId
+     * @param statusCd
+     */
+    protected 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);
+    }
+
+
+    /**
+     * 调用下游系统
+     *
+     * @param dataFlow
+     * @param serviceBusiness
+     * @param requestBusinessJson 请求报文
+     * @return
+     */
+    protected JSONObject doRequestBusinessSystem(IOrderDataFlowContext dataFlow, ServiceBusiness serviceBusiness, JSONObject requestBusinessJson) {
+        String responseMessage;
+
+        Assert.notNull(serviceBusiness, "在表c_service_business中未配置当前业务类型");
+
+        Assert.hasLength(serviceBusiness.getInvokeType(), "c_service_business表配置出错,invoke_type 不能为空" + serviceBusiness.getBusinessTypeCd());
+        String httpUrl = "";
+        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, "配置错误:c_service_business配置url字段错误" + serviceBusiness.getBusinessTypeCd());
+            }
+            httpUrl = MappingCache.getValue(urls[0]);
+            String method = MappingCache.getValue(urls[1]);
+            responseMessage = (String) WebServiceAxisClient.callWebService(httpUrl, method,
+                    new Object[]{requestBusinessJson.toJSONString()},
+                    serviceBusiness.getTimeout());
+        } else if (ServiceBusinessConstant.INVOKE_TYPE_HTTP_POST.equals(serviceBusiness.getInvokeType())) {
+            //http://user-service/test/sayHello
+            httpUrl = MappingCache.getValue(serviceBusiness.getUrl());
+            responseMessage = restTemplate.postForObject(httpUrl, requestBusinessJson.toJSONString(), String.class);
+        } else if (ServiceBusinessConstant.INVOKE_TYPE_OUT_HTTP_POST.equals(serviceBusiness.getInvokeType())) {
+            httpUrl = MappingCache.getValue(serviceBusiness.getUrl());
+            responseMessage = restTemplateNoLoadBalanced.postForObject(httpUrl, requestBusinessJson.toJSONString(), String.class);
+        } else {//post方式
+            throw new ConfigDataException(ResponseConstant.RESULT_CODE_CONFIG_ERROR, "配置错误:c_service_business配置url字段错误,当前无法识别" + serviceBusiness.getBusinessTypeCd());
+        }
+
+
+        logger.debug("调用地址:{}, 订单服务调用下游服务请求报文:{},返回报文:{}", httpUrl, requestBusinessJson, responseMessage);
+
+        if (StringUtil.isNullOrNone(responseMessage) || !Assert.isJsonObject(responseMessage)) {
+            throw new BusinessException(ResponseConstant.RESULT_CODE_INNER_ERROR, "下游系统返回格式不正确,请按协议规范处理");
+        }
+        JSONObject responseJson = JSONObject.parseObject(responseMessage);
+
+        Assert.jsonObjectHaveKey(responseJson, "response", "下游返回报文格式错误,没有包含responseJson节点【" + serviceBusiness.getBusinessTypeCd() + "】");
+
+        JSONObject responseInfo = responseJson.getJSONObject("response");
+
+        Assert.jsonObjectHaveKey(responseInfo, "code", "下游返回报文格式错误,response 节点中没有包含code节点【" + serviceBusiness.getBusinessTypeCd() + "】");
+
+        if (!ResponseConstant.RESULT_CODE_SUCCESS.equals(responseInfo.getString("code"))) {
+            throw new BusinessException(ResponseConstant.RESULT_PARAM_ERROR, "业务系统处理失败," + responseInfo.getString("message"));
+        }
+        return responseJson;
+    }
+
+    /**
+     * 将订单状态改为作废状态。
+     *
+     * @param dataFlow
+     */
+    protected void updateOrderAndBusinessDelete(IOrderDataFlowContext dataFlow,List<Business> deleteBusinesses) {
+
+        Date startDate = DateUtil.getCurrentDate();
+
+        //作废 订单
+        centerServiceDaoImpl.updateOrder(OrderDataFlowContextFactory.getNeedInvalidOrder(dataFlow));
+
+        //作废订单项
+        centerServiceDaoImpl.updateBusiness(OrderDataFlowContextFactory.getNeedDeleteBusiness(dataFlow,deleteBusinesses));
+
+        //加入撤单记录
+        //doAddDeleteOrderBusinessData(dataFlow);
+
+
+        OrderDataFlowContextFactory.addCostTime(dataFlow, "updateOrderAndBusinessError", "订单状态改为失败耗时", startDate);
+
+    }
+
+    /**
+     * 业务系统撤单
+     *
+     * @param dataFlow
+     * @param deleteBusinesses
+     */
+    protected 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());
+        }
+    }
+
+
+}

+ 409 - 0
OrderService/src/main/java/com/java110/order/smo/impl/OrderProcessServiceSMOImpl.java

@@ -0,0 +1,409 @@
+package com.java110.order.smo.impl;
+
+import com.alibaba.fastjson.JSONArray;
+import com.alibaba.fastjson.JSONObject;
+import com.java110.core.client.RestTemplate;
+import com.java110.core.context.DataFlow;
+import com.java110.core.context.IOrderDataFlowContext;
+import com.java110.core.context.IOrderNotifyDataFlowContext;
+import com.java110.core.context.OrderDataFlow;
+import com.java110.core.factory.OrderDataFlowContextFactory;
+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.IOrderProcessServiceSMO;
+import com.java110.service.smo.IQueryServiceSMO;
+import com.java110.utils.cache.MappingCache;
+import com.java110.utils.constant.*;
+import com.java110.utils.exception.*;
+import com.java110.utils.kafka.KafkaFactory;
+import com.java110.utils.log.LoggerEngine;
+import com.java110.utils.util.*;
+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("orderProcessServiceSMOImpl")
+//@Transactional
+public class OrderProcessServiceSMOImpl extends AbstractOrderServiceSMOImpl implements IOrderProcessServiceSMO {
+
+    private static Logger logger = LoggerFactory.getLogger(OrderProcessServiceSMOImpl.class);
+
+//
+//    @Autowired
+//    ICenterServiceDAO centerServiceDaoImpl;
+//
+//    @Autowired
+//    private RestTemplate restTemplate;
+//
+//    @Autowired
+//    private RestTemplate restTemplateNoLoadBalanced;
+
+    @Autowired
+    private IQueryServiceSMO queryServiceSMOImpl;
+
+
+    /**
+     * 业务统一处理服务方法
+     *
+     * @param reqJson 请求报文json
+     * @return
+     */
+    public ResponseEntity<String> preService(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 {
+            //这里保存耗时,以及日志
+            return responseEntity;
+
+        }
+    }
+
+    /**
+     * 刷返回值
+     *
+     * @param dataFlow
+     */
+    @Override
+    protected void refreshOrderDataFlowResJson(IOrderDataFlowContext dataFlow) {
+        JSONObject resJson = new JSONObject();
+        resJson.put("oId", dataFlow.getOrders().getoId());
+        dataFlow.setResJson(resJson);
+    }
+
+    /**
+     * 6.0 调用下游系统
+     *
+     * @param dataFlow
+     * @throws BusinessException
+     */
+    protected void invokeBusinessSystem(IOrderDataFlowContext dataFlow) throws BusinessException {
+        Date startDate = DateUtil.getCurrentDate();
+        doSynchronousBusinesses(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 表中的字段business_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);
+
+    }
+
+
+    /**
+     * 加入撤单记录
+     *
+     * @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, "订单失败,加入撤单"));
+    }
+
+
+    /**
+     * 确认提交订单
+     * <p>
+     * 请求报文:
+     * {
+     * "orders":{
+     * "transactionId":"576dbed0-117e-451e-b80e-88b2021e4002",
+     * "oId":"",
+     * "requestTime":"20200109114153",
+     * "orderTypeCd":"D",
+     * "orderProcess":"1005001"
+     * }
+     * }
+     *
+     * @param reqJson 接受报文
+     * @throws SMOException
+     */
+
+    public ResponseEntity confirmService(String reqJson, Map<String, String> headers) throws SMOException {
+        IOrderDataFlowContext dataFlow = null;
+        ResponseEntity<String> responseEntity = null;
+        try {
+            DataFlowEventPublishing.preValidateData(reqJson, headers);
+            //1.0 创建数据流
+            dataFlow = OrderDataFlowContextFactory.newInstance(OrderDataFlow.class).builder(reqJson, headers);
+
+            notifyInstanceOrder(dataFlow, headers);
+        } catch (Exception e) {
+            LoggerEngine.error("确认提交订单失败", e);
+            //10.0 成功的情况下通知下游系统失败将状态改为NE,人工处理。
+            responseEntity = new ResponseEntity<>(e.getMessage(), HttpStatus.BAD_REQUEST);
+
+        } finally {
+            responseEntity = new ResponseEntity<>("成功", HttpStatus.OK);
+
+            return responseEntity;
+        }
+    }
+
+    /**
+     * 通知订单 提交到实例中
+     *
+     * @param dataflow
+     * @param headers
+     */
+    private void notifyInstanceOrder(IOrderDataFlowContext dataflow, Map<String, String> headers) {
+
+        //判断 订单状态是否为B
+        Map orderInfo = new HashMap();
+        orderInfo.put("oId", dataflow.getOrders().getoId());
+        orderInfo.put("statusCd", StatusConstant.STATUS_CD_BUSINESS);
+        List<Map> businesses = centerServiceDaoImpl.getBusinessByOId(orderInfo);
+
+        if (businesses == null || businesses.size() < 1) {
+            throw new NoSupportException(1999, "未找到有效订单" + dataflow.getOrders().getoId());
+        }
+
+        doSendInstanceOrder(dataflow, businesses);
+
+    }
+
+    private void doSendInstanceOrder(IOrderDataFlowContext dataFlow, List<Map> businesses) {
+        Date startDate = DateUtil.getCurrentDate();
+
+        List<Business> deleteBusinesses = new ArrayList<Business>();
+
+
+        JSONArray responseBusinesses = new JSONArray();
+        List<Business> synchronousBusinesses = new ArrayList<>();
+
+        Business business = null;
+        for (Map busi : businesses) {
+            business = new Business();
+            business.setbId(busi.get("b_id") + "");
+            business.setBusinessTypeCd(busi.get("business_type_cd") + "");
+            synchronousBusinesses.add(business);
+        }
+
+        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());
+        }
+        OrderDataFlowContextFactory.addCostTime(dataFlow, "doSynchronousBusinesses", "同步调用业务系统总耗时", startDate);
+    }
+
+    /**
+     * 9.0 成功的情况下通知下游系统失败将状态改为NE,人工处理。
+     *
+     * @param dataFlow
+     */
+    private void updateBusinessNotifyError(IOrderNotifyDataFlowContext dataFlow) {
+
+        Date startDate = DateUtil.getCurrentDate();
+        //完成订单项
+        centerServiceDaoImpl.updateBusinessByBId(OrderDataFlowContextFactory.getNeedNotifyErrorBusiness(dataFlow));
+
+        // OrderDataFlowContextFactory.addCostTime(dataFlow, "updateBusinessNotifyError", "订单状态改为失败耗时", startDate);
+
+    }
+
+
+    /**
+     * 处理同步业务
+     *
+     * @param dataFlow
+     */
+    @Override
+    protected void doSynchronousBusinesses(IOrderDataFlowContext dataFlow) throws BusinessException {
+        Date startDate = DateUtil.getCurrentDate();
+        List<Business> synchronousBusinesses = OrderDataFlowContextFactory.getSynchronousBusinesses(dataFlow);
+
+        if (synchronousBusinesses == null || synchronousBusinesses.size() == 0) {
+            return;
+        }
+        JSONArray responseBusinesses = new JSONArray();
+
+        //6.1处理同步服务 发起Business
+        doSaveDataInfoToBusinessTable(dataFlow, synchronousBusinesses, responseBusinesses);
+
+        OrderDataFlowContextFactory.addCostTime(dataFlow, "doSynchronousBusinesses", "同步调用业务系统总耗时", startDate);
+    }
+
+
+    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;
+    }
+}

+ 4 - 377
OrderService/src/main/java/com/java110/order/smo/impl/OrderServiceSMOImpl.java

@@ -70,19 +70,12 @@ import java.util.Map;
  */
 @Service("orderServiceSMOImpl")
 //@Transactional
-public class OrderServiceSMOImpl implements IOrderServiceSMO {
+public class OrderServiceSMOImpl extends AbstractOrderServiceSMOImpl implements IOrderServiceSMO {
 
     private static Logger logger = LoggerFactory.getLogger(OrderServiceSMOImpl.class);
 
 
-    @Autowired
-    ICenterServiceDAO centerServiceDaoImpl;
-
-    @Autowired
-    private RestTemplate restTemplate;
 
-    @Autowired
-    private RestTemplate restTemplateNoLoadBalanced;
 
     @Autowired
     private IQueryServiceSMO queryServiceSMOImpl;
@@ -156,20 +149,6 @@ public class OrderServiceSMOImpl implements IOrderServiceSMO {
         }
     }
 
-    /**
-     * 刷返回值
-     *
-     * @param dataFlow
-     */
-    private void refreshOrderDataFlowResJson(IOrderDataFlowContext dataFlow) {
-
-//        if(dataFlow.getResJson() == null || dataFlow.getResJson().isEmpty()){
-//            JSONObject resJson = new JSONObject();
-//            resJson.put("msg","成功");
-//            dataFlow.setResJson(resJson);
-//        }
-
-    }
 
     /**
      * 抒写返回头信息
@@ -235,87 +214,6 @@ public class OrderServiceSMOImpl implements IOrderServiceSMO {
 
     }
 
-    /**
-     * 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 作废订单和业务项 插入撤单记录 等待撤单
@@ -427,28 +325,7 @@ public class OrderServiceSMOImpl implements IOrderServiceSMO {
 
     }
 
-    /**
-     * 将订单状态改为作废状态。
-     *
-     * @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);
-
-    }
 
     /**
      * 加入撤单记录
@@ -754,214 +631,6 @@ public class OrderServiceSMOImpl implements IOrderServiceSMO {
                 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 在c_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());
-        }
-
-    }*/
-
-    /**
-     * 将BusinessTable 中的数据保存到 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.notNull(serviceBusiness, "在表c_service_business中未配置当前业务类型");
-
-        Assert.hasLength(serviceBusiness.getInvokeType(), "c_service_business表配置出错,invoke_type 不能为空" + serviceBusiness.getBusinessTypeCd());
-        String httpUrl = "";
-        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, "配置错误:c_service_business配置url字段错误" + serviceBusiness.getBusinessTypeCd());
-            }
-            httpUrl = MappingCache.getValue(urls[0]);
-            String method = MappingCache.getValue(urls[1]);
-            responseMessage = (String) WebServiceAxisClient.callWebService(httpUrl, method,
-                    new Object[]{requestBusinessJson.toJSONString()},
-                    serviceBusiness.getTimeout());
-        } else if (ServiceBusinessConstant.INVOKE_TYPE_HTTP_POST.equals(serviceBusiness.getInvokeType())) {
-            //http://user-service/test/sayHello
-            httpUrl = MappingCache.getValue(serviceBusiness.getUrl());
-            responseMessage = restTemplate.postForObject(httpUrl, requestBusinessJson.toJSONString(), String.class);
-        } else if (ServiceBusinessConstant.INVOKE_TYPE_OUT_HTTP_POST.equals(serviceBusiness.getInvokeType())) {
-            httpUrl = MappingCache.getValue(serviceBusiness.getUrl());
-            responseMessage = restTemplateNoLoadBalanced.postForObject(httpUrl, requestBusinessJson.toJSONString(), String.class);
-        } else {//post方式
-            throw new ConfigDataException(ResponseConstant.RESULT_CODE_CONFIG_ERROR, "配置错误:c_service_business配置url字段错误,当前无法识别" + serviceBusiness.getBusinessTypeCd());
-        }
-
-
-        logger.debug("调用地址:{}, 订单服务调用下游服务请求报文:{},返回报文:{}", httpUrl, requestBusinessJson, responseMessage);
-
-        if (StringUtil.isNullOrNone(responseMessage) || !Assert.isJsonObject(responseMessage)) {
-            throw new BusinessException(ResponseConstant.RESULT_CODE_INNER_ERROR, "下游系统返回格式不正确,请按协议规范处理");
-        }
-        JSONObject responseJson = JSONObject.parseObject(responseMessage);
-
-        Assert.jsonObjectHaveKey(responseJson, "response", "下游返回报文格式错误,没有包含responseJson节点【" + serviceBusiness.getBusinessTypeCd() + "】");
-
-        JSONObject responseInfo = responseJson.getJSONObject("response");
-
-        Assert.jsonObjectHaveKey(responseInfo, "code", "下游返回报文格式错误,response 节点中没有包含code节点【" + 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;
@@ -981,45 +650,15 @@ public class OrderServiceSMOImpl implements IOrderServiceSMO {
         return responseMessage;
     }
 
-    /**
-     * 数据保存到BusinessTable 中
-     *
-     * @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, responseJson);
-
-            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 {
+    @Override
+    protected void doAsynchronousBusinesses(IOrderDataFlowContext dataFlow) throws BusinessException {
         Date startDate = DateUtil.getCurrentDate();
         //6.3 处理异步,按消息队里处理
         List<Business> asynchronousBusinesses = OrderDataFlowContextFactory.getAsynchronousBusinesses(dataFlow);
@@ -1108,19 +747,7 @@ public class OrderServiceSMOImpl implements IOrderServiceSMO {
         }
     }
 
-    /**
-     * 修改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;

+ 1 - 1
WebService/src/main/resources/components/pageFramePackage/menu/menu.js

@@ -95,7 +95,7 @@
             },
             miniMenu: function () {
 
-
+                //菜单默认为打开方式
                 if(!vc.notNull(vc.getMenuState())){
                     vc.setMenuState('ON');
                 }

+ 24 - 0
java110-bean/src/main/java/com/java110/entity/order/Orders.java

@@ -10,6 +10,20 @@ import java.util.List;
  **/
 public class Orders extends BaseOrder{
 
+    /**
+     * 一次订单提交
+     */
+    public static final String ORDER_PROCESS_ORDER_ONCE_SUBMIT = "1003001";
+    /**
+     * 订单预生成
+     */
+    public static final String ORDER_PROCESS_ORDER_PRE_SUBMIT = "1004001";
+
+    /**
+     * 订单确认生成
+     */
+    public static final String ORDER_PROCESS_ORDER_CONFIRM_SUBMIT = "1005001";
+
     /**
      * 订单ID
      */
@@ -40,6 +54,8 @@ public class Orders extends BaseOrder{
      */
     private String orderTypeCd;
 
+    private String orderProcess = ORDER_PROCESS_ORDER_ONCE_SUBMIT;
+
 
 
     private List<OrdersAttrs> ordersAttrs;
@@ -102,4 +118,12 @@ public class Orders extends BaseOrder{
     public void setOrdersAttrs(List<OrdersAttrs> ordersAttrs) {
         this.ordersAttrs = ordersAttrs;
     }
+
+    public String getOrderProcess() {
+        return orderProcess;
+    }
+
+    public void setOrderProcess(String orderProcess) {
+        this.orderProcess = orderProcess;
+    }
 }

+ 12 - 0
java110-core/src/main/java/com/java110/core/context/OrderDataFlow.java

@@ -9,6 +9,7 @@ import com.java110.entity.order.Business;
 import com.java110.entity.order.BusinessAttrs;
 import com.java110.entity.order.Orders;
 import com.java110.entity.order.OrdersAttrs;
+import com.java110.utils.util.StringUtil;
 
 import java.util.*;
 
@@ -136,6 +137,14 @@ public class OrderDataFlow extends AbstractOrderDataFlowContext {
         Assert.jsonObjectHaveKey(tmpOrderJson,"orderTypeCd","请求报文错误,未找到orderTypeCd节点");
         this.orders.setOrderTypeCd(tmpOrderJson.getString("orderTypeCd"));
 
+        if(tmpOrderJson.containsKey("orderProcess") && !StringUtil.isEmpty(tmpOrderJson.getString("orderProcess"))){
+            this.orders.setOrderProcess(tmpOrderJson.getString("orderProcess"));
+        }
+
+        if(tmpOrderJson.containsKey("oId") && !StringUtil.isEmpty(tmpOrderJson.getString("oId"))){
+            this.orders.setoId(tmpOrderJson.getString("oId"));
+        }
+
         if(!tmpOrderJson.containsKey("attrs")){
             return ;
         }
@@ -163,6 +172,9 @@ public class OrderDataFlow extends AbstractOrderDataFlowContext {
     private void builderBusiness() {
 
         this.businessList = new ArrayList<Business>();
+        if(!this.getReqJson().containsKey("business")){
+            return;
+        }
 
         JSONArray tmpBusiness = this.getReqJson().getJSONArray("business");
 

+ 2 - 2
java110-core/src/main/java/com/java110/core/factory/OrderDataFlowContextFactory.java

@@ -260,10 +260,10 @@ public class OrderDataFlowContextFactory {
      * @param dataFlow
      * @return
      */
-    public static Map getNeedDeleteBusiness(IOrderDataFlowContext dataFlow){
+    public static Map getNeedDeleteBusiness(IOrderDataFlowContext dataFlow,List<com.java110.entity.order.Business> deleteBusinesses){
         Map business = new HashMap();
         String bId = "";
-        for(com.java110.entity.order.Business busi:dataFlow.getBusinessList()){
+        for(com.java110.entity.order.Business busi:deleteBusinesses){
             bId += busi.getbId()+",";
         }
         business.put("bId",bId.substring(0,bId.length()-1));