| | |
| | | import com.java110.entity.order.OrderListAttr; |
| | | import com.java110.feign.base.IPrimaryKeyService; |
| | | import com.java110.order.dao.IOrderServiceDao; |
| | | import com.java110.order.mq.DeleteOrderInfoProducer; |
| | | import com.java110.order.smo.IOrderServiceSMO; |
| | | import org.apache.commons.lang.math.NumberUtils; |
| | | import org.apache.commons.lang3.StringUtils; |
| | |
| | | @Autowired |
| | | EventProperties eventProperties; |
| | | |
| | | @Autowired |
| | | DeleteOrderInfoProducer deleteOrderInfoProducer; |
| | | |
| | | /** |
| | | * 根据购物车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){ |
| | |
| | | } |
| | | |
| | | 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); |
| | | } |
| | | |
| | | /** |
| | |
| | | if(StringUtils.isBlank(olId) || olId.startsWith("-") ){ |
| | | olId = this.queryPrimaryKey(iPrimaryKeyService,"OL_ID"); |
| | | orderList.setOlId(olId); |
| | | orderListTmp.put("olId",olId); |
| | | } |
| | | |
| | | //这里保存购物车 |
| | |
| | | |
| | | 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))); |
| | | } |
| | | |
| | |
| | | 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){ |
| | |
| | | AppEventPublishing.multicastEvent(context,datasTmp,orderListTmp.getString("asyn")); |
| | | }catch (Exception e){ |
| | | //这里补偿事物 |
| | | compensateTransactional(datasTmp); |
| | | throw e; |
| | | } |
| | | 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); |
| | | } |
| | | |
| | | /** |
| | |
| | | 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){ |
| | |
| | | } |
| | | dataJsonTmp.add(JSONObject.parseObject(JSONObject.toJSONString(needDeleteBoIdMap))); |
| | | datasTmp.put(actionTypeCd,dataJsonTmp); |
| | | |
| | | //deleteOrderInfoProducer.send(datasTmp.toString()); |
| | | } |
| | | |
| | | |
| | | /** |
| | | * 补偿事物,这里不用手工作废 购物车信息,事物会自动回退掉,这里这需要手工给其他的系统发布事物回退 |
| | | * |
| | | * { 'data': [ |
| | | |
| | | { |
| | | 'boId': '222222', |
| | | 'actionTypeCd': 'C1', |
| | | 'oldBoId':'11111' |
| | | }, |
| | | { |
| | | 'boId': '222222', |
| | | 'actionTypeCd': 'M1', |
| | | 'oldBoId':'11111' |
| | | }, |
| | | { |
| | | 'boId': '222222', |
| | | 'actionTypeCd': 'C1', |
| | | 'oldBoId':'11111' |
| | | } |
| | | ] |
| | | } |
| | | * @param datasTmp {C1={'data':[{}]}} |
| | | */ |
| | | private void compensateTransactional(Map<String,JSONArray> datasTmp){ |
| | | |
| | | Set<String> keys = datasTmp.keySet(); |
| | | |
| | | JSONArray compensateDatas = new JSONArray(); |
| | | |
| | | JSONObject compensateBoId = null; |
| | | for(String key : keys){ |
| | | JSONArray datas = datasTmp.get(key); |
| | | |
| | | for(int dataIndex = 0 ; dataIndex <datas.size() ; dataIndex++){ |
| | | compensateBoId.put("boId",datas.getJSONObject(dataIndex).getString("boId")); |
| | | compensateBoId.put("actionTypeCd",key); |
| | | compensateDatas.add(compensateBoId); |
| | | } |
| | | } |
| | | |
| | | JSONObject compensateData = new JSONObject(); |
| | | |
| | | compensateData.put("data",compensateDatas); |
| | | |
| | | deleteOrderInfoProducer.send(datasTmp.toString()); |
| | | } |
| | | |
| | | public IPrimaryKeyService getiPrimaryKeyService() { |