wuxw
2019-10-17 4ff738f377504fe8f2296df18cf7d0123641cdd9
WebService/src/main/java/com/java110/web/smo/impl/CarServiceSMOImpl.java
@@ -1,11 +1,12 @@
package com.java110.web.smo.impl;
import com.alibaba.fastjson.JSONArray;
import com.alibaba.fastjson.JSONObject;
import com.java110.common.constant.PrivilegeCodeConstant;
import com.java110.common.constant.ResponseConstant;
import com.java110.common.constant.ServiceConstant;
import com.java110.common.exception.SMOException;
import com.java110.common.util.Assert;
import com.java110.utils.constant.PrivilegeCodeConstant;
import com.java110.utils.constant.ResponseConstant;
import com.java110.utils.constant.ServiceConstant;
import com.java110.utils.exception.SMOException;
import com.java110.utils.util.Assert;
import com.java110.core.context.IPageData;
import com.java110.web.core.BaseComponentSMO;
import com.java110.web.smo.ICarServiceSMO;
@@ -90,6 +91,8 @@
        super.checkUserHasPrivilege(pd, restTemplate, PrivilegeCodeConstant.PRIVILEGE_CAR);
        JSONObject paramIn = JSONObject.parseObject(pd.getReqData());
        JSONArray infos = paramIn.getJSONArray("data");
        String communityId = paramIn.getString("communityId");
        ResponseEntity responseEntity = super.getStoreInfo(pd, restTemplate);
        if (responseEntity.getStatusCode() != HttpStatus.OK) {
@@ -102,9 +105,25 @@
        String storeTypeCd = JSONObject.parseObject(responseEntity.getBody().toString()).getString("storeTypeCd");
        //数据校验是否 商户是否入驻该小区
        super.checkStoreEnterCommunity(pd, storeId, storeTypeCd, communityId, restTemplate);
        paramIn.put("userId", pd.getUserId());
        paramIn.put("storeId", storeId);
        responseEntity = this.callCenterService(restTemplate, pd, paramIn.toJSONString(),
        JSONObject viewSelectParkingSpace = this.getObj(infos, "viewSelectParkingSpace");
        JSONObject viewOwnerInfo = this.getObj(infos, "viewOwnerInfo");
        JSONObject addCar = this.getObj(infos, "addCar");
        JSONObject parkingSpaceFee = null;
        if(hasThisFlowComponent(infos, "hireParkingSpaceFee")) {
            parkingSpaceFee = this.getObj(infos, "hireParkingSpaceFee");
        }else{
            parkingSpaceFee = this.getObj(infos, "sellParkingSpaceFee");
        }
        JSONObject newParamIn = new JSONObject();
        newParamIn.putAll(addCar);
        newParamIn.putAll(parkingSpaceFee);
        newParamIn.put("communityId", communityId);
        newParamIn.put("ownerId", viewOwnerInfo.getString("ownerId"));
        newParamIn.put("psId", viewSelectParkingSpace.getString("psId"));
        newParamIn.put("userId", pd.getUserId());
        newParamIn.put("storeId", storeId);
        responseEntity = this.callCenterService(restTemplate, pd, newParamIn.toJSONString(),
                ServiceConstant.SERVICE_API_URL + "/api/parkingSpace.sellParkingSpace",
                HttpMethod.POST);
@@ -221,19 +240,52 @@
    private void validateSaveCar(IPageData pd) {
        Assert.jsonObjectHaveKey(pd.getReqData(), "communityId", "未包含小区ID");
        Assert.jsonObjectHaveKey(pd.getReqData(), "ownerId", "请求报文中未包含ownerId");
        Assert.jsonObjectHaveKey(pd.getReqData(), "carNum", "请求报文中未包含carNum");
        Assert.jsonObjectHaveKey(pd.getReqData(), "carBrand", "请求报文中未包含carBrand");
        Assert.jsonObjectHaveKey(pd.getReqData(), "carType", "请求报文中未包含carType");
        Assert.jsonObjectHaveKey(pd.getReqData(), "carColor", "未包含carColor");
        Assert.jsonObjectHaveKey(pd.getReqData(), "psId", "未包含psId");
        Assert.jsonObjectHaveKey(pd.getReqData(), "receivedAmount", "未包含receivedAmount");
        JSONObject paramIn = JSONObject.parseObject(pd.getReqData());
        Assert.hasLength(paramIn.getString("communityId"), "小区ID不能为空");
        Assert.hasLength(paramIn.getString("ownerId"), "ownerId不能为空");
        Assert.hasLength(paramIn.getString("psId"), "psId不能为空");
        Assert.hasLength(paramIn.getString("receivedAmount"), "receivedAmount不能为空");
        JSONObject info = JSONObject.parseObject(pd.getReqData());
        JSONArray infos = info.getJSONArray("data");
        if (infos.size() != 4) {
            throw new IllegalArgumentException("数据被篡改");
        }
        Assert.hasKeyByFlowData(infos, "viewSelectParkingSpace", "psId", "未包含psId");
        Assert.hasKeyByFlowData(infos, "viewOwnerInfo", "ownerId", "必填,未包含业主信息");
        Assert.hasKeyByFlowData(infos, "addCar", "carNum", "请求报文中未包含carNum");
        Assert.hasKeyByFlowData(infos, "addCar", "carBrand", "请求报文中未包含carBrand");
        Assert.hasKeyByFlowData(infos, "addCar", "carType", "请求报文中未包含carType");
        Assert.hasKeyByFlowData(infos, "addCar", "carColor", "未包含carColor");
        JSONObject parkingSpaceFee = null;
        if (hasThisFlowComponent(infos, "hireParkingSpaceFee")) {
            Assert.hasKeyByFlowData(infos, "hireParkingSpaceFee", "receivedAmount", "未包含receivedAmount");
            Assert.hasKeyByFlowData(infos, "hireParkingSpaceFee", "sellOrHire", "未包含sellOrHire");
             parkingSpaceFee = this.getObj(infos, "hireParkingSpaceFee");
        }else{
            Assert.hasKeyByFlowData(infos, "sellParkingSpaceFee", "receivedAmount", "未包含receivedAmount");
            Assert.hasKeyByFlowData(infos, "sellParkingSpaceFee", "sellOrHire", "未包含sellOrHire");
            parkingSpaceFee = this.getObj(infos, "sellParkingSpaceFee");
        }
        JSONObject viewSelectParkingSpace = this.getObj(infos, "viewSelectParkingSpace");
        JSONObject viewOwnerInfo = this.getObj(infos, "viewOwnerInfo");
        JSONObject addCar = this.getObj(infos, "addCar");
        Assert.hasLength(info.getString("communityId"), "小区ID不能为空");
        Assert.hasLength(viewOwnerInfo.getString("ownerId"), "ownerId不能为空");
        Assert.hasLength(viewSelectParkingSpace.getString("psId"), "psId不能为空");
        Assert.hasLength(parkingSpaceFee.getString("receivedAmount"), "receivedAmount不能为空");
        if (!"H".equals(parkingSpaceFee.getString("sellOrHire"))
                && !"S".equals(parkingSpaceFee.getString("sellOrHire"))) {
            throw new IllegalArgumentException("入参错误,无法识别该操作");
        }
        if ("H".equals(parkingSpaceFee.getString("sellOrHire"))) {
            Assert.jsonObjectHaveKey(parkingSpaceFee, "cycles", "未包含cycles");
            Assert.hasLength(parkingSpaceFee.getString("cycles"), "cycles不能为空");
        }
    }
    /**
@@ -258,6 +310,7 @@
        }
    }
    /**
     * 校验查询小区楼信息
     *
@@ -272,6 +325,47 @@
    }
    private JSONObject getObj(JSONArray infos, String flowComponent) {
        JSONObject serviceInfo = null;
        for (int infoIndex = 0; infoIndex < infos.size(); infoIndex++) {
            Assert.hasKeyAndValue(infos.getJSONObject(infoIndex), "flowComponent", "未包含服务流程组件名称");
            if (flowComponent.equals(infos.getJSONObject(infoIndex).getString("flowComponent"))) {
                serviceInfo = infos.getJSONObject(infoIndex);
                Assert.notNull(serviceInfo, "未包含服务信息");
                return serviceInfo;
            }
        }
        throw new IllegalArgumentException("未找到组件编码为【" + flowComponent + "】数据");
    }
    /**
     * 是否有 这个组件
     *
     * @param infos                所有组件信息
     * @param currentFlowComponent 当前组件
     * @return
     */
    private boolean hasThisFlowComponent(JSONArray infos, String currentFlowComponent) {
        JSONObject serviceInfo = null;
        for (int infoIndex = 0; infoIndex < infos.size(); infoIndex++) {
            serviceInfo = infos.getJSONObject(infoIndex);
            if (currentFlowComponent.equals(serviceInfo.getString("flowComponent"))) {
                return true;
            }
        }
        return false;
    }
    public RestTemplate getRestTemplate() {
        return restTemplate;
    }