| | |
| | | package com.java110.core.factory; |
| | | |
| | | import com.alibaba.fastjson.JSON; |
| | | import com.alibaba.fastjson.JSONArray; |
| | | import com.alibaba.fastjson.JSONObject; |
| | | import com.alibaba.fastjson.JSONPath; |
| | | import com.java110.common.constant.MappingConstant; |
| | | import com.java110.common.constant.OrderTypeCdConstant; |
| | | import com.java110.common.constant.ResponseConstant; |
| | | import com.java110.common.constant.StatusConstant; |
| | | import com.java110.common.util.Assert; |
| | | import com.java110.common.util.DateUtil; |
| | | import com.java110.common.util.SequenceUtil; |
| | | import com.java110.common.util.StringUtil; |
| | | import com.java110.core.context.DataFlow; |
| | | import com.java110.core.context.DataFlowContext; |
| | |
| | | responseInfo.put("business",business); |
| | | } |
| | | return responseInfo; |
| | | } |
| | | |
| | | /** |
| | | * 业务是否都成功了 |
| | | * @param response true 成功 false 失败 |
| | | * @return |
| | | */ |
| | | public static boolean isSuccessBusiness(JSONObject response){ |
| | | Object obj = JSONPath.eval(response,"$.orders.response.code"); |
| | | |
| | | if(obj != null && obj instanceof String && ResponseConstant.RESULT_CODE_SUCCESS.equals(obj.toString())){ |
| | | Object businessObj = JSONPath.eval(response,"$.business"); |
| | | if(businessObj == null){ |
| | | return true; |
| | | } |
| | | |
| | | if(businessObj instanceof JSONObject){ |
| | | JSONObject businessJson = (JSONObject) businessObj; |
| | | if(!businessJson.containsKey("response")){ //这里返回协议错误,我们认为是成功 |
| | | return true; |
| | | } |
| | | if(businessJson.getJSONObject("response").containsKey("code") |
| | | && ResponseConstant.RESULT_CODE_SUCCESS.equals(businessJson.getJSONObject("response").getString("code"))){ |
| | | return true; |
| | | } |
| | | } |
| | | |
| | | if(businessObj instanceof JSONArray){ |
| | | JSONArray businessJsons = (JSONArray) businessObj; |
| | | if(businessJsons == null || businessJsons.size() == 0){ |
| | | return true; |
| | | } |
| | | JSONObject businessJson = null; |
| | | for (int businessIndex = 0;businessIndex < businessJsons.size();businessIndex++) { |
| | | businessJson = businessJsons.getJSONObject(businessIndex); |
| | | if (!businessJson.containsKey("response")) { //这里返回协议错误,我们认为是成功 |
| | | continue; |
| | | } |
| | | if (businessJson.getJSONObject("response").containsKey("code") |
| | | && !ResponseConstant.RESULT_CODE_SUCCESS.equals(businessJson.getJSONObject("response").getString("code"))) { |
| | | return false; |
| | | } |
| | | } |
| | | return true; |
| | | } |
| | | } |
| | | |
| | | return false; |
| | | } |
| | | |
| | | /** |
| | |
| | | |
| | | |
| | | /** |
| | | * 创建请求 center 报文 分装成JSON |
| | | * 创建请求 order 报文 分装成JSON |
| | | * @param appId |
| | | * @return |
| | | */ |
| | |
| | | JSONObject paramIn = JSONObject.parseObject("{\"orders\":{},\"business\":[]}"); |
| | | JSONObject orders = paramIn.getJSONObject("orders"); |
| | | orders.put("appId",appId); |
| | | orders.put("transactionId", SequenceUtil.getTransactionId()); |
| | | orders.put("transactionId", GenerateCodeFactory.getTransactionId()); |
| | | orders.put("userId",userId); |
| | | orders.put("orderTypeCd",orderTypeCd); |
| | | orders.put("requestTime",DateUtil.getNowDefault()); |
| | |
| | | return paramOut; |
| | | } |
| | | |
| | | /** |
| | | * ID生成请求报文 |
| | | * @param transactionId |
| | | * @return |
| | | */ |
| | | public static JSONObject createCodeRequestJson(String transactionId, String prefix,String name){ |
| | | JSONObject paramOut = JSONObject.parseObject("{}"); |
| | | paramOut.put("transactionId",transactionId); |
| | | paramOut.put("prefix",prefix); |
| | | paramOut.put("name",name); |
| | | paramOut.put("requestTime",DateUtil.getNowDefault()); |
| | | return paramOut; |
| | | } |
| | | |
| | | } |