wuxw
2020-05-31 8954b6c80d6f496baaa9d5a2c3fe5fbbf020bf67
Api/src/main/java/com/java110/api/bmo/ApiBaseBMO.java
@@ -5,9 +5,10 @@
import com.java110.core.context.DataFlowContext;
import com.java110.core.factory.DataFlowFactory;
import com.java110.entity.center.AppService;
import com.java110.event.service.api.ServiceDataFlowEvent;
import com.java110.core.event.service.api.ServiceDataFlowEvent;
import com.java110.utils.constant.CommonConstant;
import com.java110.utils.constant.ServiceCodeConstant;
import com.java110.utils.util.BeanConvertUtil;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.http.*;
import org.springframework.web.client.HttpStatusCodeException;
@@ -34,7 +35,7 @@
     * @param event
     * @return
     */
    protected ResponseEntity<String> callService(ServiceDataFlowEvent event) {
    public ResponseEntity<String> callService(ServiceDataFlowEvent event) {
        DataFlowContext dataFlowContext = event.getDataFlowContext();
        AppService service = event.getAppService();
@@ -50,9 +51,23 @@
     * @return
     */
    public ResponseEntity<String> callService(DataFlowContext context, String serviceCode,JSONArray businesses) {
        context.getRequestCurrentHeaders().put(CommonConstant.HTTP_ORDER_TYPE_CD, "D");
        JSONObject paramInObj = restToCenterProtocol(businesses, context.getRequestCurrentHeaders());
        return callService(context,serviceCode,paramInObj);
    }
    /**
     * 调用下游服务
     *
     * @param context
     * @param serviceCode 下游服务
     * @return
     */
    public ResponseEntity<String> callService(DataFlowContext context, String serviceCode,JSONObject paramInObj) {
        //将 rest header 信息传递到下层服务中去
        HttpHeaders header = new HttpHeaders();
        freshHttpHeader(header, context.getRequestCurrentHeaders());
        ResponseEntity responseEntity = null;
@@ -72,7 +87,7 @@
     * @param appService 下游服务
     * @return
     */
    protected ResponseEntity<String> callService(DataFlowContext context, AppService appService, Map paramIn) {
    public ResponseEntity<String> callService(DataFlowContext context, AppService appService, Map paramIn) {
        context.getRequestCurrentHeaders().put(CommonConstant.HTTP_ORDER_TYPE_CD, "D");
@@ -130,7 +145,7 @@
     * @param headers    订单头信息
     * @return
     */
    protected JSONObject restToCenterProtocol(JSONArray businesses, Map<String, String> headers) {
    public JSONObject restToCenterProtocol(JSONArray businesses, Map<String, String> headers) {
        JSONObject centerProtocol = JSONObject.parseObject("{\"orders\":{},\"business\":[]}");
        freshOrderProtocol(centerProtocol.getJSONObject("orders"), headers);
@@ -145,7 +160,7 @@
     * @param business
     * @return
     */
    protected JSONObject restToCenterProtocol(JSONObject business, Map<String, String> headers) {
    public JSONObject restToCenterProtocol(JSONObject business, Map<String, String> headers) {
        JSONObject centerProtocol = JSONObject.parseObject("{\"orders\":{},\"business\":[]}");
        freshOrderProtocol(centerProtocol.getJSONObject("orders"), headers);
@@ -161,7 +176,7 @@
     * @param orders  订单信息
     * @param headers 头部信息
     */
    protected void freshOrderProtocol(JSONObject orders, Map<String, String> headers) {
    public void freshOrderProtocol(JSONObject orders, Map<String, String> headers) {
        for (String key : headers.keySet()) {
            if (CommonConstant.HTTP_APP_ID.equals(key)) {
@@ -183,6 +198,14 @@
            if (CommonConstant.HTTP_USER_ID.equals(key)) {
                orders.put("userId", headers.get(key));
            }
            if(CommonConstant.ORDER_PROCESS.equals(key)){
                orders.put("orderProcess", headers.get(CommonConstant.ORDER_PROCESS));
            }
            if(CommonConstant.O_ID.equals(key)){
                orders.put("oId", headers.get(CommonConstant.O_ID));
            }
        }
    }
@@ -193,7 +216,7 @@
     * @param httpHeaders http 头信息
     * @param headers     头部信息
     */
    protected void freshHttpHeader(HttpHeaders httpHeaders, Map<String, String> headers) {
    public void freshHttpHeader(HttpHeaders httpHeaders, Map<String, String> headers) {
        for (String key : headers.keySet()) {
            if (CommonConstant.HTTP_APP_ID.equals(key)) {
@@ -210,7 +233,66 @@
            if (CommonConstant.HTTP_USER_ID.equals(key)) {
                httpHeaders.add("user_id", headers.get(key));
            }
        }
    }
    /**
     * 新增数据方法
     *
     * @param context 上下文对象
     * @param param   po对象
     */
    public void insert(DataFlowContext context, Object param, String businessType) {
        JSONObject business = JSONObject.parseObject("{\"datas\":{}}");
        business.put(CommonConstant.HTTP_BUSINESS_TYPE_CD, businessType);
        business.put(CommonConstant.HTTP_SEQ, DEFAULT_SEQ);
        business.put(CommonConstant.HTTP_INVOKE_MODEL, CommonConstant.HTTP_INVOKE_MODEL_S);
        JSONObject businessObj = new JSONObject();
        businessObj = JSONObject.parseObject(JSONObject.toJSONString(BeanConvertUtil.beanCovertMap(param)));
        JSONArray businessArr = new JSONArray();
        businessArr.add(businessObj);
        business.getJSONObject(CommonConstant.HTTP_BUSINESS_DATAS).put(param.getClass().getSimpleName(), businessArr);
        context.addServiceBusiness(business);
    }
    /**
     * 新增数据方法
     *
     * @param context 上下文对象
     * @param param   po对象
     */
    public void update(DataFlowContext context, Object param, String businessType) {
        JSONObject business = JSONObject.parseObject("{\"datas\":{}}");
        business.put(CommonConstant.HTTP_BUSINESS_TYPE_CD, businessType);
        business.put(CommonConstant.HTTP_SEQ, DEFAULT_SEQ);
        business.put(CommonConstant.HTTP_INVOKE_MODEL, CommonConstant.HTTP_INVOKE_MODEL_S);
        JSONObject businessObj = new JSONObject();
        businessObj = JSONObject.parseObject(JSONObject.toJSONString(BeanConvertUtil.beanCovertMap(param)));
        JSONArray businessArr = new JSONArray();
        businessArr.add(businessObj);
        business.getJSONObject(CommonConstant.HTTP_BUSINESS_DATAS).put(param.getClass().getSimpleName(), businessArr);
        context.addServiceBusiness(business);
    }
    /**
     * 新增数据方法
     *
     * @param context 上下文对象
     * @param param   po对象
     */
    public void delete(DataFlowContext context, Object param, String businessType) {
        JSONObject business = JSONObject.parseObject("{\"datas\":{}}");
        business.put(CommonConstant.HTTP_BUSINESS_TYPE_CD, businessType);
        business.put(CommonConstant.HTTP_SEQ, DEFAULT_SEQ);
        business.put(CommonConstant.HTTP_INVOKE_MODEL, CommonConstant.HTTP_INVOKE_MODEL_S);
        JSONObject businessObj = new JSONObject();
        businessObj = JSONObject.parseObject(JSONObject.toJSONString(BeanConvertUtil.beanCovertMap(param)));
        JSONArray businessArr = new JSONArray();
        businessArr.add(businessObj);
        business.getJSONObject(CommonConstant.HTTP_BUSINESS_DATAS).put(param.getClass().getSimpleName(), businessArr);
        context.addServiceBusiness(business);
    }
}