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
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
package com.java110.web.smo.impl;
 
import com.alibaba.fastjson.JSONArray;
import com.alibaba.fastjson.JSONObject;
import com.java110.utils.constant.AttrCdConstant;
import com.java110.utils.constant.CredentialsConstant;
import com.java110.utils.constant.ServiceConstant;
import com.java110.utils.util.Assert;
import com.java110.core.context.IPageData;
import com.java110.web.core.BaseComponentSMO;
import com.java110.web.smo.ICompanyServiceSMO;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.http.HttpMethod;
import org.springframework.http.HttpStatus;
import org.springframework.http.ResponseEntity;
import org.springframework.stereotype.Service;
import org.springframework.web.client.RestTemplate;
 
/**
 * 初始化公司实现类
 * Created by Administrator on 2019/3/28.
 */
@Service("companyServiceSMOImpl")
public class CompanyServiceSMOImpl extends BaseComponentSMO implements ICompanyServiceSMO {
 
    @Autowired
    private RestTemplate restTemplate;
 
    /**
     * 查询 商户类别
     * @param pd
     * @return
     */
    @Override
    public ResponseEntity<String> getStoreType(IPageData pd) {
        ResponseEntity<String> responseEntity = null;
        Assert.hasLength(pd.getUserId(),"用户还未登录请先登录");
 
        responseEntity = this.callCenterService(restTemplate,pd,"", ServiceConstant.SERVICE_API_URL+"/api/query.store.type?type=all", HttpMethod.GET);
 
        if(responseEntity.getStatusCode() == HttpStatus.OK){
            Assert.jsonObjectHaveKey(responseEntity.getBody(),"storeType","查询中心服务异常,不是有效json或未包含storeType节点");
            //将storeType 返回出去
            responseEntity = new ResponseEntity<String>(JSONObject.parseObject(responseEntity.getBody()).getJSONArray("storeType").toJSONString(),HttpStatus.OK);
        }
        return responseEntity;
    }
 
    /**
     * 保存公司信息
     * @param pd
     * @return
     */
    public ResponseEntity<String> saveCompanyInfo(IPageData pd){
        ResponseEntity<String> responseEntity = null;
        Assert.hasLength(pd.getUserId(),"用户还未登录请先登录");
 
        validateCompanyInfo(pd.getReqData());
 
 
        JSONObject reqJson = JSONObject.parseObject("{\"businessStore\":{}}");
 
        JSONObject paramJson = JSONObject.parseObject(pd.getReqData());
 
        //基本信息
        JSONObject businessStore = reqJson.getJSONObject("businessStore");
        businessStore.put("userId",pd.getUserId());
        businessStore.put("name",paramJson.getString("name"));
        businessStore.put("address",paramJson.getString("address"));
        businessStore.put("tel",paramJson.getString("tel"));
        businessStore.put("storeTypeCd",paramJson.getString("storeTypeCd"));
        businessStore.put("nearbyLandmarks",paramJson.getString("nearbyLandmarks"));
 
        JSONArray businessStoreAttr = new JSONArray();
 
        JSONObject attr = new JSONObject();
        attr.put("specCd", AttrCdConstant.SPEC_CD_STORE_CORPORATION);
        attr.put("value",paramJson.getString("corporation"));
        businessStoreAttr.add(attr);
 
         attr = new JSONObject();
        attr.put("specCd", AttrCdConstant.SPEC_CD_STORE_REGISTEREDCAPITAL);
        attr.put("value",paramJson.getString("registeredCapital"));
        businessStoreAttr.add(attr);
 
         attr = new JSONObject();
        attr.put("specCd", AttrCdConstant.SPEC_CD_STORE_FOUNDINGTIME);
        attr.put("value",paramJson.getString("foundingTime"));
        businessStoreAttr.add(attr);
 
        attr = new JSONObject();
        attr.put("specCd", AttrCdConstant.SPEC_CD_STORE_REGISTRATIONAUTHORITY);
        attr.put("value",paramJson.getString("registrationAuthority"));
        businessStoreAttr.add(attr);
 
        attr = new JSONObject();
        attr.put("specCd", AttrCdConstant.SPEC_CD_STORE_SCOPE);
        attr.put("value",paramJson.getString("scope"));
        businessStoreAttr.add(attr);
        reqJson.put("businessStoreAttr",businessStoreAttr);
 
        JSONArray businessStoreCerdentials = new JSONArray();
        JSONObject cerdentials = new JSONObject();
 
        cerdentials.put("credentialsCd", CredentialsConstant.LICENCE);
        cerdentials.put("value",paramJson.getString("value"));
        cerdentials.put("validityPeriod",paramJson.getString("validityPeriod"));
        cerdentials.put("positivePhoto","");
        cerdentials.put("negativePhoto","");
        businessStoreCerdentials.add(cerdentials);
 
        reqJson.put("businessStoreCerdentials",businessStoreCerdentials);
 
 
 
        responseEntity = this.callCenterService(restTemplate,pd,reqJson.toJSONString(), ServiceConstant.SERVICE_API_URL+"/api/save.store.info", HttpMethod.POST);
 
       /* if(responseEntity.getStatusCode() != HttpStatus.OK){
            return responseEntity;
        }
 
        JSONObject resStoreInfo = JSONObject.parseObject(responseEntity.getBody().toString());
        //将现用户添加为商户管理员
        JSONObject staffInfo = new JSONObject();
        staffInfo.put("userId",pd.getUserId());
        staffInfo.put("storeId",resStoreInfo.getString("storeId"));
        responseEntity = this.callCenterService(restTemplate,pd,staffInfo.toJSONString(), ServiceConstant.SERVICE_API_URL+"/api/user.staff.add", HttpMethod.POST);
*/
 
        return responseEntity;
    }
 
 
    /**
     * 校验公司信息
     * @param param
     */
    private void validateCompanyInfo(String param){
 
    }
 
 
    public RestTemplate getRestTemplate() {
        return restTemplate;
    }
 
    public void setRestTemplate(RestTemplate restTemplate) {
        this.restTemplate = restTemplate;
    }
}