| | |
| | | import com.java110.common.util.ProtocolUtil; |
| | | import com.java110.config.properties.EventProperties; |
| | | import com.java110.core.base.smo.BaseServiceSMO; |
| | | import com.java110.core.context.AppContext; |
| | | import com.java110.core.event.AppEventPublishing; |
| | | import com.java110.entity.order.BusiOrder; |
| | | import com.java110.entity.order.BusiOrderAttr; |
| | |
| | | import org.springframework.beans.factory.annotation.Autowired; |
| | | import org.springframework.stereotype.Service; |
| | | import org.springframework.transaction.annotation.Transactional; |
| | | import org.springframework.util.Assert; |
| | | import com.java110.common.util.Assert; |
| | | |
| | | import java.util.ArrayList; |
| | | import java.util.HashMap; |
| | | import java.util.List; |
| | | import java.util.Map; |
| | | |
| | |
| | | //获取 订单项 |
| | | JSONArray busiOrderTmps = orderInfo.getJSONArray("busiOrder"); |
| | | |
| | | //存放busiOrder 的data节点 |
| | | |
| | | Map<String,JSONArray> datasTmp = new HashMap<String, JSONArray>(); |
| | | |
| | | for(int busiOrderTmpsIndex = 0 ; busiOrderTmpsIndex < busiOrderTmps.size() ; busiOrderTmpsIndex++){ |
| | | JSONObject busiOrderJson = busiOrderTmps.getJSONObject(busiOrderTmpsIndex); |
| | | if (!busiOrderJson.containsKey("busiObj")){ |
| | | /*if (!busiOrderJson.containsKey("busiObj")){ |
| | | throw new IllegalArgumentException("请求报文中busiOrder 节点中没有对应的 busiObj 节点,请检查"+busiOrderJson); |
| | | } |
| | | }*/ |
| | | |
| | | Assert.isNull(busiOrderJson,"busiObj","请求报文中busiOrder 节点中没有对应的 busiObj 节点,请检查"+busiOrderJson); |
| | | |
| | | BusiOrder busiOrderObj = JSONObject.parseObject(busiOrderJson.getJSONObject("busiObj").toJSONString(),BusiOrder.class); |
| | | |
| | |
| | | } |
| | | } |
| | | //修改data节点下的boId,一般是没有这个值,所以直接新加就行了,不许判断是否已-开头 |
| | | if (!busiOrderJson.containsKey("data")){ |
| | | /* if (!busiOrderJson.containsKey("data")){ |
| | | throw new IllegalArgumentException("请求报文中busiOrder 节点中没有对应的 data 节点,请检查"+busiOrderJson); |
| | | } |
| | | }*/ |
| | | |
| | | Assert.isNull(busiOrderJson,"data","请求报文中busiOrder 节点中没有对应的 data 节点,请检查"+busiOrderJson); |
| | | |
| | | //处理data 节点 |
| | | JSONObject data = busiOrderJson.getJSONObject("data"); |
| | |
| | | //根据busiOrder 的 actionTypeCd 注册那个服务去处理 |
| | | String actionTypeCd = busiOrderObj.getActionTypeCd(); |
| | | |
| | | JSONArray dataJsonTmp = null; |
| | | if(!datasTmp.containsKey(actionTypeCd)){ |
| | | dataJsonTmp = new JSONArray(); |
| | | }else{ |
| | | dataJsonTmp = datasTmp.get(actionTypeCd); |
| | | } |
| | | data.put("actionTypeCd",actionTypeCd); |
| | | dataJsonTmp.add(data); |
| | | |
| | | 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); |
| | | |
| | | //发布事件 |
| | | AppEventPublishing.multicastEvent(context,datasTmp,orderListTmp.getString("asyn")); |
| | | |
| | | return ProtocolUtil.createResultMsg(ProtocolUtil.RETURN_MSG_SUCCESS,"成功",JSONObject.parseObject(JSONObject.toJSONString(orderList))); |
| | | } |
| | |
| | | */ |
| | | @Override |
| | | public String deleteOrder(JSONObject orderInfo) throws Exception { |
| | | //1.0 购物车信息校验处理,走订单受理必须要有购物车信息和订单项信息 |
| | | if(!orderInfo.containsKey("orderList") || !orderInfo.containsKey("busiOrder")){ |
| | | throw new IllegalArgumentException("请求报文中没有购物车相关信息[orderList]或订单项相关信息[busiOrder],请检查报文:"+orderInfo); |
| | | } |
| | | |
| | | JSONObject orderListTmp = orderInfo.getJSONObject("orderList"); |
| | | OrderList orderList = JSONObject.parseObject(orderListTmp.toJSONString(),OrderList.class); |
| | | |
| | | String olId = orderList.getOlId(); |
| | | //生成olId |
| | | if(StringUtils.isBlank(olId) || olId.startsWith("-") ){ |
| | | olId = this.queryPrimaryKey(iPrimaryKeyService,"OL_ID"); |
| | | orderList.setOlId(olId); |
| | | } |
| | | |
| | | //这里保存购物车 |
| | | |
| | | int saveOrderListFlag = iOrderServiceDao.saveDataToBoOrderList(orderList); |
| | | if (saveOrderListFlag < 1){ |
| | | throw new RuntimeException("作废订单时保存购物车信息失败"+orderListTmp); |
| | | } |
| | | |
| | | JSONArray busiOrderTmps = orderInfo.getJSONArray("busiOrder"); |
| | | |
| | | /** |
| | | * 根据actionTypeCd 作废 |
| | | */ |
| | | Assert.isNull(busiOrderTmps,"入参错误,没有busiOrder 节点,或没有子节点"); |
| | | |
| | | if(!busiOrderTmps.getJSONObject(0).containsKey("oldBoId")){ |
| | | String actionTypeCds = busiOrderTmps.getJSONObject(0).getString("actionTypeCd"); |
| | | deleteOrderByActionTypeCd(orderListTmp.getString("oldOlId"),actionTypeCds.split(",")); |
| | | return ProtocolUtil.createResultMsg(ProtocolUtil.RETURN_MSG_SUCCESS,"成功",JSONObject.parseObject(JSONObject.toJSONString(orderList))); |
| | | } |
| | | |
| | | |
| | | |
| | | return null; |
| | | } |
| | | |
| | | /** |
| | | * 根据 订单动作 作废 |
| | | * @param oldOlId 作废的购物车 |
| | | * @param actionTypeCd busi_order action_type_cd 类型来作废订单 |
| | | * @throws Exception |
| | | */ |
| | | private void deleteOrderByActionTypeCd(String oldOlId,String ...actionTypeCd) throws Exception{ |
| | | //根据oldOdId actionTypeCd 获取订单项 |
| | | BusiOrder busiOrderTmp = new BusiOrder(); |
| | | busiOrderTmp.setOlId(oldOlId); |
| | | String actionTypeCds= ""; |
| | | // 'C1','A1','M1', |
| | | for(String ac : actionTypeCd){ |
| | | actionTypeCds += ("'"+ac+"',"); |
| | | } |
| | | |
| | | // 'C1','A1','M1' |
| | | actionTypeCds = actionTypeCds.endsWith(",")?actionTypeCds.substring(0,actionTypeCds.length()-1):actionTypeCds; |
| | | |
| | | busiOrderTmp.setActionTypeCd(actionTypeCds); |
| | | |
| | | List<BusiOrder> busiOrders = iOrderServiceDao.queryBusiOrderAndAttr(busiOrderTmp); |
| | | |
| | | Assert.isNull(busiOrders,"没有找到需要作废的订单,[oldOdId="+oldOlId+",actionTypeCd = "+actionTypeCd+"]"); |
| | | |
| | | |
| | | } |
| | | |
| | | private void prepareContext(AppContext context,Map<String,JSONArray> datasTmp){ |
| | | Assert.isNull(context,"创建上下对象失败"); |
| | | |
| | | //这里将整个订单的data 信息存入 上下文对象中,以防后期使用无法获取 |
| | | |
| | | context.coverData(datasTmp); |
| | | |
| | | } |
| | | |
| | | public IPrimaryKeyService getiPrimaryKeyService() { |
| | | return iPrimaryKeyService; |
| | | } |