1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
package com.java110.web.smo.addOwner.impl;
 
import com.alibaba.fastjson.JSONObject;
import com.alibaba.fastjson.JSONArray;
import com.java110.utils.constant.PrivilegeCodeConstant;
import com.java110.utils.constant.ServiceConstant;
import com.java110.utils.util.Assert;
import com.java110.entity.component.ComponentValidateResult;
import com.java110.web.smo.addOwner.IAddOwnerRoomBindingSMO;
import org.springframework.web.client.RestTemplate;
import com.java110.core.context.IPageData;
import com.java110.web.core.AbstractComponentSMO;
import org.springframework.stereotype.Service;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.http.HttpMethod;
import org.springframework.http.ResponseEntity;
 
/**
 * 添加小区服务实现类
 * add by wuxw 2019-06-30
 */
@Service("addOwnerRoomBindingSMOImpl")
public class AddOwnerRoomBindingSMOImpl extends AbstractComponentSMO implements IAddOwnerRoomBindingSMO {
 
    @Autowired
    private RestTemplate restTemplate;
 
    @Override
    protected void validate(IPageData pd, JSONObject paramIn) {
 
        //super.validatePageInfo(pd);
        JSONArray infos = paramIn.getJSONArray("data");
        Assert.hasKeyAndValue(paramIn, "communityId", "未包含小区信息");
 
        if (infos.size() != 3) {
            throw new IllegalArgumentException("数据被篡改");
        }
 
        Assert.hasKeyByFlowData(infos, "viewFloorInfo", "floorId", "必填,未选择楼栋");
        Assert.hasKeyByFlowData(infos, "sellRoomSelectRoom", "roomId", "必填,未选择房屋");
        Assert.hasKeyByFlowData(infos, "viewOwnerInfo", "ownerId", "必填,未包含业主信息");
 
 
        super.checkUserHasPrivilege(pd, restTemplate, PrivilegeCodeConstant.ADD_OWNER_ROOM);
 
    }
 
    @Override
    protected ResponseEntity<String> doBusinessProcess(IPageData pd, JSONObject paramIn) {
        ResponseEntity<String> responseEntity = null;
        ComponentValidateResult result = super.validateStoreStaffCommunityRelationship(pd, restTemplate);
 
        JSONArray infos = paramIn.getJSONArray("data");
        //JSONObject viewFloorInfo = getObj(infos, "viewFloorInfo");
        JSONObject sellRoomSelectRoom = getObj(infos, "sellRoomSelectRoom");
        JSONObject viewOwnerInfo = getObj(infos, "viewOwnerInfo");
        JSONObject newParamIn = new JSONObject();
        String communityId = paramIn.getString("communityId");
        newParamIn.put("ownerId", viewOwnerInfo.getString("ownerId"));
        newParamIn.put("roomId", sellRoomSelectRoom.getString("roomId"));
        newParamIn.put("communityId", communityId);
        newParamIn.put("userId", pd.getUserId());
        newParamIn.put("storeId", result.getStoreId());
        newParamIn.put("state", "2002");
        responseEntity = this.callCenterService(restTemplate, pd, newParamIn.toJSONString(),
                ServiceConstant.SERVICE_API_URL + "/api/room.sellRoom",
                HttpMethod.POST);
        return responseEntity;
    }
 
 
    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 + "】数据");
    }
 
 
    @Override
    public ResponseEntity<String> bindingAddOwnerRoom(IPageData pd) {
        return super.businessProcess(pd);
    }
 
    public RestTemplate getRestTemplate() {
        return restTemplate;
    }
 
    public void setRestTemplate(RestTemplate restTemplate) {
        this.restTemplate = restTemplate;
    }
}