Pu Zhibing
昨天 d3efbff8f05d05d90f345f7404f7a848383fa8f4
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
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
package com.stylefeng.guns.modular.system.util.qianyuntong;
 
import com.alibaba.fastjson.JSON;
import com.alibaba.fastjson.JSONObject;
import com.google.gson.Gson;
import com.open.common.util.OpenApiClient;
import com.open.common.util.SystemParameterNames;
import com.stylefeng.guns.modular.system.util.qianyuntong.model.*;
import lombok.extern.slf4j.Slf4j;
 
import java.text.SimpleDateFormat;
import java.util.Date;
import java.util.HashMap;
import java.util.Map;
import java.util.UUID;
 
/**
 * 企业工具类
 *
 * @author zhibing.pu
 * @Date 2025/6/6 17:06
 */
@Slf4j
public class EnterpriseUtil {
    
    
    /**
     * 根据社会信用代码判断企业是否已存在
     *
     * @param uscc
     * @return
     */
    public static CheckEnterExist checkEnterExistByEnterIdCardNo(String uscc) {
        //请求路径
        String url = QianYunTongProperties.apiUrl + "/openapi/rest/1.0/check_enter_exist_by_enterIdCardNo";
        //私钥文件
        String skprivateKeyFile = QianYunTongProperties.privateKeyPath;
        //注意:私钥文件需要开发者手动新建.pem文件,将委办局提供的私钥串复制进文件里用于sign加密
        String appKey = QianYunTongProperties.appkey;//appkey
        Map<String, String> headers = new HashMap<>();
        headers.put("Content-Type", "application/json");
        Map<String, Object> map = new HashMap<>();
        Date nowdate = new Date();
        SimpleDateFormat date = new SimpleDateFormat("yyyyMMddHHmmss");
        
        String timeStamp = date.format(nowdate);
        String messageId = UUID.randomUUID().toString().replaceAll("-", "");
        map.put(SystemParameterNames.getAppKey(), appKey);
        map.put(SystemParameterNames.getMessage_id(), messageId);
        map.put(SystemParameterNames.getUserName(), QianYunTongProperties.userName);
        map.put(SystemParameterNames.getStatus(), QianYunTongProperties.status);
        map.put("content", "{\"uscc\":\"" + uscc + "\"}");
        log.info("【根据社会信用代码判断企业是否已存在】请求地址:" + url);
        log.info("【根据社会信用代码判断企业是否已存在】请求参数:" + JSON.toJSONString(map));
        String result = OpenApiClient.sendCommonHttpRequst(url, headers, "POST", skprivateKeyFile, timeStamp, map);
        log.info("【根据社会信用代码判断企业是否已存在】请求结果:" + result);
        JSONObject jsonObject = JSON.parseObject(result);
        String retCode = jsonObject.getString("retCode");
        if (!"0".equals(retCode)) {
            log.error("【根据社会信用代码判断企业是否已存在】请求失败:" + result);
            throw new RuntimeException("【根据社会信用代码判断企业是否已存在】请求失败:" + result);
        }
        JSONObject object = jsonObject.getJSONObject("object");
        String status = object.getString("status");
        if (!"0".equals(status)) {
            log.error("【根据社会信用代码判断企业是否已存在】失败:" + object.toJSONString());
            throw new RuntimeException("【根据社会信用代码判断企业是否已存在】失败:" + object.toJSONString());
        }
        return jsonObject.getObject("object", CheckEnterExist.class);
    }
    
    
    /**
     * 根据企业名称判断企业是否已存在
     *
     * @param enterName
     * @return
     */
    public static CheckEnterExist checkEnterNameExist(String enterName) {
        //请求路径
        String url = QianYunTongProperties.apiUrl + "/openapi/rest/1.0/checkEnterNameExist";
        //私钥文件
        String skprivateKeyFile = QianYunTongProperties.privateKeyPath;
        //注意:私钥文件需要开发者手动新建.pem文件,将委办局提供的私钥串复制进文件里用于sign加密
        String appKey = QianYunTongProperties.appkey;//appkey
        Map<String, String> headers = new HashMap<>();
        headers.put("Content-Type", "application/json");
        Map<String, Object> map = new HashMap<>();
        Date nowdate = new Date();
        SimpleDateFormat date = new SimpleDateFormat("yyyyMMddHHmmss");
        
        String timeStamp = date.format(nowdate);
        String messageId = UUID.randomUUID().toString().replaceAll("-", "");
        map.put(SystemParameterNames.getAppKey(), appKey);
        map.put(SystemParameterNames.getMessage_id(), messageId);
        map.put(SystemParameterNames.getUserName(), QianYunTongProperties.userName);
        map.put(SystemParameterNames.getStatus(), QianYunTongProperties.status);
        map.put("content", "{\"enterName\":\"" + enterName + "\"}");
        log.info("【根据企业名称判断企业是否已存在】请求地址:" + url);
        log.info("【根据企业名称判断企业是否已存在】请求参数:" + JSON.toJSONString(map));
        String result = OpenApiClient.sendCommonHttpRequst(url, headers, "POST", skprivateKeyFile, timeStamp, map);
        log.info("【根据企业名称判断企业是否已存在】请求结果:" + result);
        JSONObject jsonObject = JSON.parseObject(result);
        String retCode = jsonObject.getString("retCode");
        if (!"0".equals(retCode)) {
            log.error("【根据企业名称判断企业是否已存在】请求失败:" + result);
            throw new RuntimeException("【根据企业名称判断企业是否已存在】请求失败:" + result);
        }
        JSONObject object = jsonObject.getJSONObject("object");
        String status = object.getString("status");
        if (!"0".equals(status)) {
            log.error("【根据企业名称判断企业是否已存在】失败:" + object.toJSONString());
            throw new RuntimeException("【根据企业名称判断企业是否已存在】失败:" + object.toJSONString());
        }
        return jsonObject.getObject("object", CheckEnterExist.class);
    }
    
    
    /**
     * 查询企业详情
     *
     * @param enter_code 企业编号
     * @return
     */
    public static EnterpriseInfo getEnterpriseDetail(String enter_code) {
        //请求路径
        String url = QianYunTongProperties.apiUrl + "/openapi/rest/1.0/getEnterpriseDetail";
        //私钥文件
        String skprivateKeyFile = QianYunTongProperties.privateKeyPath;
        //注意:私钥文件需要开发者手动新建.pem文件,将委办局提供的私钥串复制进文件里用于sign加密
        String appKey = QianYunTongProperties.appkey;//appkey
        Map<String, String> headers = new HashMap<>();
        headers.put("Content-Type", "application/json");
        Map<String, Object> map = new HashMap<>();
        Date nowdate = new Date();
        SimpleDateFormat date = new SimpleDateFormat("yyyyMMddHHmmss");
        
        String timeStamp = date.format(nowdate);
        String messageId = UUID.randomUUID().toString().replaceAll("-", "");
        map.put(SystemParameterNames.getAppKey(), appKey);
        map.put(SystemParameterNames.getMessage_id(), messageId);
        map.put(SystemParameterNames.getUserName(), QianYunTongProperties.userName);
        map.put(SystemParameterNames.getStatus(), QianYunTongProperties.status);
        map.put("content", "{\"enter_code\":\"" + enter_code + "\"}");
        log.info("【查询企业详情】请求地址:" + url);
        log.info("【查询企业详情】请求参数:" + JSON.toJSONString(map));
        String result = OpenApiClient.sendCommonHttpRequst(url, headers, "POST", skprivateKeyFile, timeStamp, map);
        log.info("【查询企业详情】请求结果:" + result);
        JSONObject jsonObject = JSON.parseObject(result);
        String retCode = jsonObject.getString("retCode");
        if (!"0".equals(retCode)) {
            log.error("【查询企业详情】请求失败:" + result);
            throw new RuntimeException("【查询企业详情】请求失败:" + result);
        }
        JSONObject object = jsonObject.getJSONObject("object");
        String status = object.getString("status");
        if (!"0".equals(status)) {
            log.error("【查询企业详情】失败:" + object.toJSONString());
            throw new RuntimeException("【查询企业详情】失败:" + object.toJSONString());
        }
        EnterpriseInfo enterpriseInfo = jsonObject.getObject("object", EnterpriseInfo.class);
        return enterpriseInfo;
    }
    
    
    /**
     * 修改企业基本信息
     *
     * @param request
     * @return
     */
    public static Boolean modifyEnterpriseInfo(ModifyEnterpriseInfoRequest request) {
        //请求路径
        String url = QianYunTongProperties.apiUrl + "/openapi/rest/1.0/modifyEnterpriseInfo";
        //私钥文件
        String skprivateKeyFile = QianYunTongProperties.privateKeyPath;
        //注意:私钥文件需要开发者手动新建.pem文件,将委办局提供的私钥串复制进文件里用于sign加密
        String appKey = QianYunTongProperties.appkey;//appkey
        Map<String, String> headers = new HashMap<>();
        headers.put("Content-Type", "application/json");
        Map<String, Object> map = new HashMap<>();
        Date nowdate = new Date();
        SimpleDateFormat date = new SimpleDateFormat("yyyyMMddHHmmss");
        
        String timeStamp = date.format(nowdate);
        String messageId = UUID.randomUUID().toString().replaceAll("-", "");
        map.put(SystemParameterNames.getAppKey(), appKey);
        map.put(SystemParameterNames.getMessage_id(), messageId);
        map.put(SystemParameterNames.getUserName(), QianYunTongProperties.userName);
        map.put(SystemParameterNames.getStatus(), QianYunTongProperties.status);
        map.put("content", new Gson().toJson(request));
        log.info("【修改企业基本信息】请求地址:" + url);
        log.info("【修改企业基本信息】请求参数:" + JSON.toJSONString(map));
        String result = OpenApiClient.sendCommonHttpRequst(url, headers, "GET", skprivateKeyFile, timeStamp, map);
        log.info("【修改企业基本信息】请求结果:" + result);
        JSONObject jsonObject = JSON.parseObject(result);
        String status = jsonObject.getString("status");
        if (!"0".equals(status)) {
            log.error("【修改企业基本信息】请求失败:" + result);
            return false;
        }
        return true;
    }
    
    
    /**
     * 创建企业
     *
     * @param request
     * @return
     */
    public static CreateEnterprise createEnterprise(CreateEnterpriseRequest request) {
        //请求路径
        String url = QianYunTongProperties.apiUrl + "/openapi/rest/1.0/createEnterprise";
        //私钥文件
        String skprivateKeyFile = QianYunTongProperties.privateKeyPath;
        //注意:私钥文件需要开发者手动新建.pem文件,将委办局提供的私钥串复制进文件里用于sign加密
        String appKey = QianYunTongProperties.appkey;//appkey
        String content = "";//业务参数
        Map<String, String> headers = new HashMap<>();
        headers.put("Content-Type", "application/json");
        Map<String, Object> map = new HashMap<String, Object>();
        Date nowdate = new Date();
        SimpleDateFormat date = new SimpleDateFormat("yyyyMMddHHmmss");
        
        String timeStamp = date.format(nowdate);
        String messageId = UUID.randomUUID().toString().replaceAll("-", "");
        map.put(SystemParameterNames.getAppKey(), appKey);
        map.put(SystemParameterNames.getMessage_id(), messageId);
        map.put(SystemParameterNames.getUserName(), QianYunTongProperties.userName);
        map.put(SystemParameterNames.getStatus(), QianYunTongProperties.status);
        map.put("content", new Gson().toJson(request));
        
        log.info("【创建企业】请求地址:" + url);
        log.info("【创建企业】请求参数:" + JSON.toJSONString(map));
        String result = OpenApiClient.sendCommonHttpRequst(url, headers, "POST", skprivateKeyFile, timeStamp, map);
        log.info("【创建企业】请求结果:" + result);
        JSONObject jsonObject = JSON.parseObject(result);
        String retCode = jsonObject.getString("retCode");
        if (!"0".equals(retCode)) {
            log.error("【创建企业】请求失败:" + result);
            return null;
        }
        JSONObject object = jsonObject.getJSONObject("object");
        String status = object.getString("status");
        if (!"0".equals(status)) {
            log.error("【创建企业】请求失败:" + result);
            return null;
        }
        return object.getObject("data", CreateEnterprise.class);
    }
}