wuxw7
2017-09-11 ca4e66f00da70b852fc0aae769b6d9b69e627263
OrderService/src/main/java/com/java110/order/smo/impl/OrderServiceSMOImpl.java
@@ -50,14 +50,93 @@
    /**
     * 根据购物车ID 或者 外部系统ID 或者 custId 或者 channelId 查询订单信息
     *
     * 返回报文格式如下:
     *
     * {
     "orderList": [{
     "orderListAttrs": [{···}],
     "busiOrder": [
     {
     "data": {
     "boCust": [{···}],
     "boCustAttr": [ {···}]
     },
     "busiObj": {····},
     "busiOrderAttrs": [{···}]
     }
     ],
     "orderListInfo": {···}
     }]
     }
     * @param orderList
     * @return
     */
    @Override
    public String queryOrderInfo(OrderList orderList) throws Exception{
        return queryOrderInfo(orderList,true);
    }
    /**
     * 根据购物车ID 或者 外部系统ID 或者 custId 或者 channelId 查询订单信息
     *
     * 返回报文格式如下:
     *
     * {
         "orderList": [{
         "orderListAttrs": [{···}],
         "busiOrder": [
             {
                 "data": {
                 "boCust": [{···}],
                 "boCustAttr": [ {···}]
                 },
                 "busiObj": {····},
                 "busiOrderAttrs": [{···}]
             }
         ],
         "orderListInfo": {···}
         }]
     }
     * @param orderList
     * @param isQueryDataInfo 是 查询data节点 否不查询data节点
     * @return
     */
    @Override
    public String queryOrderInfo(OrderList orderList,Boolean isQueryDataInfo) throws Exception{
        List<OrderList> orderLists = iOrderServiceDao.queryOrderListAndAttr(orderList);
        /*List<OrderList> orderLists = iOrderServiceDao.queryOrderListAndAttr(orderList);
        //
        JSONArray orderListsArray = new JSONArray();
        for (OrderList orderListTmp : orderLists){
@@ -75,9 +154,84 @@
        }
        JSONObject orderListTmpO = new JSONObject();
        orderListTmpO.put("orderLists",orderListsArray);
        orderListTmpO.put("orderList",orderListsArray);*/
        return ProtocolUtil.createResultMsg(ProtocolUtil.RETURN_MSG_SUCCESS,"查询成功",orderListTmpO);
        List<OrderList> orderLists = iOrderServiceDao.queryOrderListAndAttr(orderList);
        //多个购物车封装
        JSONArray orderListsArray = new JSONArray();
        JSONObject orderListTmpJson = null;
        for(OrderList orderListTmp : orderLists){
            orderListTmpJson = new JSONObject();
            //封装orderListAttrs
            orderListTmpJson.put("orderListAttrs",JSONArray.parseArray(JSONObject.toJSONString(orderListTmp.getOrderListAttrs())));
            orderListTmpJson.put("orderListInfo",JSONObject.parseObject(JSONObject.toJSONString(orderListTmp)).remove("orderListAttrs"));
            BusiOrder busiOrderTmp = new BusiOrder();
            busiOrderTmp.setBoId(orderListTmp.getOlId());
            List<BusiOrder> busiOrders = iOrderServiceDao.queryBusiOrderAndAttr(busiOrderTmp);
            //封装busiObj
            JSONArray busiOrderTmpArray = new JSONArray();
            /**
             * [
             {
             "data": {
             "boCust": [{···}],
             "boCustAttr": [ {···}]
             },
             "busiObj": {····},
             "busiOrderAttrs": [{···}]
             }
             */
            JSONObject busiOrderTmpJson = null;
            for(BusiOrder busiOrderTmp1 : busiOrders){
                busiOrderTmpJson = new JSONObject();
                //封装busiOrderAttrs
                busiOrderTmpJson.put("busiOrderAttrs",JSONArray.parseArray(JSONObject.toJSONString(busiOrderTmp1.getBusiOrderAttrs())));
                //封装busiObj
                busiOrderTmpJson.put("busiObj",JSONObject.parseObject(JSONObject.toJSONString(busiOrderTmp1)).remove("busiOrderAttrs"));
                //封装data 节点
                if(isQueryDataInfo){
                }
                busiOrderTmpArray.add(busiOrderTmpJson);
            }
            //分装busiOrder
            orderListTmpJson.put("busiOrder",busiOrderTmpArray);
        }
        orderListsArray.add(orderListTmpJson);
        JSONObject orderListJson = new JSONObject();
        orderListJson.put("orderList",orderListsArray);
        return ProtocolUtil.createResultMsg(ProtocolUtil.RETURN_MSG_SUCCESS,"查询成功",orderListJson);
    }
    /**
@@ -105,6 +259,7 @@
        if(StringUtils.isBlank(olId) || olId.startsWith("-") ){
            olId = this.queryPrimaryKey(iPrimaryKeyService,"OL_ID");
            orderList.setOlId(olId);
            orderListTmp.put("olId",olId);
        }
        //这里保存购物车
@@ -215,29 +370,20 @@
            datasTmp.put(actionTypeCd,dataJsonTmp);
            /*
            try {
                //发布事件
                AppEventPublishing.multicastEvent(actionTypeCd,orderInfo.toJSONString(), data.toJSONString(),orderListTmp.getString("asyn"));
            }catch (Exception e){
                //这里补偿事物
                throw e;
            }*/
        }
        //创建上下文对象
        AppContext context = createApplicationContext();
        prepareContext(context, datasTmp);
        try {
       /* try {*/
            //发布事件
            AppEventPublishing.multicastEvent(context,datasTmp,orderListTmp.getString("asyn"));
        }catch (Exception e){
       /* }catch (Exception e){
            //这里补偿事物,这里发布广播
            compensateTransactional(datasTmp);
            throw e;
        }
        }*/
        return ProtocolUtil.createResultMsg(ProtocolUtil.RETURN_MSG_SUCCESS,"成功",JSONObject.parseObject(JSONObject.toJSONString(orderList)));
    }
@@ -369,6 +515,7 @@
            busiOrderAttr.setBoId(newBoId);
            busiOrderAttr.setAttrCd(AttrCdConstant.BUSI_ORDER_ATTR_10000001);
            busiOrderAttr.setValue(needDeleteBoIdMap.get("boId"));
            needDeleteBoIdMap.put("newBoId",newBoId);
            saveBusiOrderFlag =  iOrderServiceDao.saveDataToBusiOrderAttr(busiOrderAttr);
            if(saveBusiOrderFlag < 1){
@@ -415,6 +562,39 @@
        }
        return ProtocolUtil.createResultMsg(ProtocolUtil.RETURN_MSG_SUCCESS,"成功",JSONObject.parseObject(JSONObject.toJSONString(orderList)));
    }
    /**
     * 撤单处理 add by wuxw 2017-09-10 22:35
     * 修改以前逻辑,根据olId 去目标系统查询需要查询撤单订单组装报文
     * @param orderInfo
     * @throws Exception
     */
    public void soDeleteOrder(JSONObject orderInfo) throws Exception{
        //1.0 购物车信息校验处理,走订单受理必须要有购物车信息和订单项信息
        if(!orderInfo.containsKey("orderListInfo") || !orderInfo.containsKey("busiOrder")){
            return;
        }
        JSONObject orderListTmp = orderInfo.getJSONObject("orderListInfo");
        OrderList orderList = JSONObject.parseObject(orderListTmp.toJSONString(),OrderList.class);
        String olId = orderList.getOlId();
        //生成olId
        if(StringUtils.isBlank(olId) || olId.startsWith("-") ){
           return ;
        }
        // 查询购物车信息,订单项信息
        String oldOrderInfo = this.queryOrderInfo(orderList,false);
        JSONObject oldOrderInfoJson = ProtocolUtil.getObject(oldOrderInfo,JSONObject.class);
        oldOrderInfoJson.getJSONArray("orderLists");
        //重新发起撤单订单
        orderDispatch(null);
    }
    /**
@@ -486,10 +666,10 @@
        Assert.isNull(datasTmp,"processDeleteOrderByActionTypeCd 方法的参数 datasTmp 为空,");
        // 如果这两个中有一个为空,则从库中查询
        if(StringUtils.isBlank(needDeleteBoIdMap.get("olId")) || StringUtils.isBlank(needDeleteBoIdMap.get("actionTypeCd"))){
        if(StringUtils.isBlank(needDeleteBoIdMap.get("newBoId")) || StringUtils.isBlank(needDeleteBoIdMap.get("actionTypeCd"))){
            BusiOrder busiOrderTmp = new BusiOrder();
            busiOrderTmp.setBoId(needDeleteBoIdMap.get("boId"));
            //这里只有一条其他,则抛出异常
            //这里只有一条其他,否则抛出异常
            List<BusiOrder> oldBusiOrders =  iOrderServiceDao.queryBusiOrderAndAttr(busiOrderTmp);
            if(oldBusiOrders == null || oldBusiOrders.size() != 1){
@@ -513,7 +693,7 @@
        dataJsonTmp.add(JSONObject.parseObject(JSONObject.toJSONString(needDeleteBoIdMap)));
        datasTmp.put(actionTypeCd,dataJsonTmp);
        deleteOrderInfoProducer.send(datasTmp.toString());
        //deleteOrderInfoProducer.send(datasTmp.toString());
    }
@@ -561,6 +741,8 @@
        JSONObject compensateData = new JSONObject();
        compensateData.put("data",compensateDatas);
        deleteOrderInfoProducer.send(datasTmp.toString());
    }
    public IPrimaryKeyService getiPrimaryKeyService() {