广州市综治平台后端
xusd
2025-06-07 36306491396230522fa20585c2621a7fc899849a
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
package cn.huge.module.grid.service;
 
import cn.huge.base.common.bo.R;
import cn.huge.base.common.utils.AesUtils;
import cn.huge.base.common.utils.HttpClientUtils;
import cn.huge.base.common.utils.SpringContextUtil;
import cn.huge.module.grid.domain.dto.GridSysRoleDTO;
import cn.huge.module.grid.domain.vo.*;
import cn.huge.module.sys.dto.GridRoleMenuDTO;
import cn.huge.module.sys.dto.GridUserRoleDTO;
import cn.huge.module.sys.vo.GridOrgUsersVo;
import cn.huge.module.sys.vo.GridRoleMenuVo;
import cn.huge.module.sys.vo.GridUserRoleVo;
import com.alibaba.fastjson.JSON;
import com.alibaba.fastjson.JSONArray;
import com.alibaba.fastjson.JSONObject;
import lombok.extern.slf4j.Slf4j;
import org.apache.commons.codec.DecoderException;
import org.apache.commons.codec.digest.DigestUtils;
import org.springframework.beans.factory.annotation.Value;
import org.springframework.stereotype.Service;
 
import javax.crypto.BadPaddingException;
import javax.crypto.IllegalBlockSizeException;
import javax.crypto.NoSuchPaddingException;
import java.io.UnsupportedEncodingException;
import java.security.InvalidAlgorithmParameterException;
import java.security.InvalidKeyException;
import java.security.NoSuchAlgorithmException;
import java.util.*;
 
@Slf4j
@Service
public class GridUserService {
    @Value("${grid.url:http://219.137.166.84:8061}")
    private String gridUrl;
    @Value("${grid.username:mtxt0011}")
    private String userName;
    @Value("${grid.password:aek8CdcaM}")
    private String passWord;
    @Value("${grid.secret:BZb2hLCx05}")
    private String secret;
    @Value("${grid.passid:b08c0ec0-772d-caf8-5c9b-1f7d86295a95}")
    private String passid;
    private String testUrl = "http://183.2.142.21:9007";
 
    public R<GridUserVo> getUserInfo(GridTokenVo gridTokenVo) {
        String s = null;
        HashMap<String, String> headVo = initHeadVo();
        try {
            // 开发环境
            if (SpringContextUtil.checkDev()) {
                log.info("xsdurl:{},{}", testUrl + "/sys/getUserByToken", headVo);
                s = HttpClientUtils.httpPostRaw(testUrl + "/sys/getUserByToken", gridTokenVo.getToken(), headVo, "utf-8");
            } else {
                log.info("xsdurl:{},{}", gridUrl + "/sys/getUserByToken", JSON.toJSONString(gridTokenVo));
                s = HttpClientUtils.httpPostRaw(gridUrl + "/sys/getUserByToken", JSON.toJSONString(gridTokenVo), headVo, "utf-8");
            }
            log.info("xsd:{}", s);
        } catch (Exception e) {
            log.info("xsderror:{}", e.getLocalizedMessage());
            throw new RuntimeException(e);
        }
        GridUserVo gridUserVo = JSONObject.parseObject(s).getObject("data", GridUserVo.class);
        try {
            gridUserVo.setName(AesUtils.decrypt(gridUserVo.getName(), "W90akz7tA7tyMn5tNTynG69YM2E8jGfF"));
            gridUserVo.setMobile(AesUtils.decrypt(gridUserVo.getMobile(), "W90akz7tA7tyMn5tNTynG69YM2E8jGfF"));
            gridUserVo.setIdNumber(AesUtils.decrypt(gridUserVo.getIdNumber(), "W90akz7tA7tyMn5tNTynG69YM2E8jGfF"));
        } catch (NoSuchPaddingException e) {
            throw new RuntimeException(e);
        } catch (NoSuchAlgorithmException e) {
            throw new RuntimeException(e);
        } catch (UnsupportedEncodingException e) {
            throw new RuntimeException(e);
        } catch (InvalidAlgorithmParameterException e) {
            throw new RuntimeException(e);
        } catch (InvalidKeyException e) {
            throw new RuntimeException(e);
        } catch (DecoderException e) {
            throw new RuntimeException(e);
        } catch (IllegalBlockSizeException e) {
            throw new RuntimeException(e);
        } catch (BadPaddingException e) {
            throw new RuntimeException(e);
        }
        return R.ok(gridUserVo);
    }
 
    public R<List<GridUserRoleDTO>> getUserRoleList(GridUserRoleVo gridUserRoleVo) {
        String s = null;
        HashMap<String, String> headVo = initHeadVo();
        try {
//            log.info("xsdobject:{}",JSON.toJSONString(requestVo));
            log.info("xsdurl:{}", gridUrl + "/sys/getOrgRole");
//            log.info("xsdurl:{}",testUrl + "/sys/getUserByToken");
            s = HttpClientUtils.httpPostRaw(gridUrl + "/sys/getOrgRole", JSON.toJSONString(gridUserRoleVo), headVo, "utf-8");
            log.info("xsd:{}", s);
        } catch (Exception e) {
            log.info("xsderror:{}", e.getLocalizedMessage());
            throw new RuntimeException(e);
        }
        JSONArray data = JSONObject.parseObject(s).getJSONArray("data");
        List<GridUserRoleDTO> gridUserRoleDTOList = data.toJavaList(GridUserRoleDTO.class);
        return R.ok(gridUserRoleDTOList);
    }
 
 
    public HashMap<String, String> initHeadVo() {
        long timestamp = System.currentTimeMillis() / 1000;
        HashMap<String, String> headVo = new HashMap<>();
        headVo.put("x-rio-paasid", passid);
        headVo.put("x-rio-timestamp", timestamp + "");
        headVo.put("x-rio-nonce", "mt");
        headVo.put("x-rio-signature", DigestUtils.sha256Hex(timestamp + secret + "mt" + timestamp));
        return headVo;
    }
 
    public R<GridSysRoleDTO> getSysRoleList(GridOrgVo gridOrgVo) {
        HashMap<String, String> headVo = initHeadVo();
        log.info("xsd:{}", JSON.toJSONString(gridOrgVo));
        log.info("xsd:{}", gridUrl + "/sys/getRoleList");
        String s = null;
        try {
            s = HttpClientUtils.httpPostRaw(gridUrl + "/sys/getRoleList", JSON.toJSONString(gridOrgVo), headVo, "utf-8");
        } catch (Exception e) {
            log.info("xsderror:{}", e);
            throw new RuntimeException(e);
        }
        log.info("xsd:{}", s);
        JSONObject object = JSONObject.parseObject(s);
        if (object.getInteger("code") != null && object.getInteger("code") == 0) {
            GridSysRoleDTO data = object.getObject("data", GridSysRoleDTO.class);
            return R.ok(data);
        } else {
            return R.fail("获取企业信息失败");
        }
    }
 
    public R<List<GridRoleMenuDTO>> getRoleMenu(GridRoleMenuVo gridRoleMenuVo) {
        String s = null;
        HashMap<String, String> headVo = initHeadVo();
        try {
//            log.info("xsdobject:{}",JSON.toJSONString(requestVo));
            log.info("xsdurl:{}", gridUrl + "/sys/getUserMenuRecur");
//            log.info("xsdurl:{}",testUrl + "/sys/getUserByToken");
            s = HttpClientUtils.httpPostRaw(gridUrl + "/sys/getUserMenuRecur", JSON.toJSONString(gridRoleMenuVo), headVo, "utf-8");
            log.info("xsd:{}", s);
        } catch (Exception e) {
            log.info("xsderror:{}", e.getLocalizedMessage());
            throw new RuntimeException(e);
        }
        JSONArray data = JSONObject.parseObject(s).getJSONArray("data");
        List<GridRoleMenuDTO> gridRoleMenuDTOList = data.toJavaList(GridRoleMenuDTO.class);
        return R.ok(gridRoleMenuDTOList);
    }
 
    public R<String> initNewUsers(GridUserRoleVo gridUserRoleVo) {
        //根据用户id获取用户信息
 
        //拿到用户机构信息
 
        //拿到用户角色菜单权限信息
 
        //如果全部菜单权限,分配管理员角色;如果部分菜单权限,分配纠纷化解员角色
 
 
        //初始化完成用户信息,返回给前端登录
        return R.fail();
    }
 
    public R<List<GridUserVo>> getUserListByOrg(GridOrgUsersVo gridOrgUsersVo) {
        String s = null;
        HashMap<String, String> headVo = initHeadVo();
        List<String> roleIds = new ArrayList<>();
        roleIds.add("43fc22e6-7276-11ef-a6d1-005056820c5f");
        roleIds.add("442be8dd-7276-11ef-a6d1-005056820c5f");
        roleIds.add("679b1846-71c5-11ef-a6d1-005056820c5f");
        roleIds.add("67affc74-71c5-11ef-a6d1-005056820c5f");
        gridOrgUsersVo.setRoleIds(roleIds);
        try {
//            log.info("xsdobject:{}",JSON.toJSONString(requestVo));
            // 开发环境
            if (SpringContextUtil.checkDev()) {
                log.info("xsdurl:{}", testUrl + "/api/thrid/grid/user/get-org-users" + JSON.toJSONString(gridOrgUsersVo));
                s = HttpClientUtils.httpPostRaw(testUrl + "/api/thrid/grid/user/get-org-users", JSON.toJSONString(gridOrgUsersVo), headVo, "utf-8");
            } else {
                log.info("xsdurl:{}", gridUrl + "/sys/user/getUserListByOrg");
                s = HttpClientUtils.httpPostRaw(gridUrl + "/sys/user/getUserListByOrg", JSON.toJSONString(gridOrgUsersVo), headVo, "utf-8");
            }
            log.info("xsd:{}", s);
        } catch (Exception e) {
            log.info("xsderror:{}", e.getLocalizedMessage());
            throw new RuntimeException(e);
        }
        JSONArray data = JSONObject.parseObject(s).getJSONArray("data");
        List<GridUserVo> gridUserVos = data.toJavaList(GridUserVo.class);
        return R.ok(gridUserVos);
 
    }
 
    public R<GridUserVo> getUserByIdNumber(GridUserIdNumberVo gridUserIdNumberVo) {
        String s = null;
        HashMap<String, String> headVo = initHeadVo();
        try {
            gridUserIdNumberVo.setIdNumber(AesUtils.encrypt(gridUserIdNumberVo.getIdNumber(), "W90akz7tA7tyMn5tNTynG69YM2E8jGfF"));
//            log.info("xsdobject:{}",JSON.toJSONString(requestVo));
            // 开发环境
            if (SpringContextUtil.checkDev()) {
                log.info("xsdurl:{}", testUrl + "/api/thrid/grid/user/get-user-idNumber" + JSON.toJSONString(gridUserIdNumberVo));
                s = HttpClientUtils.httpPostRaw(testUrl + "/api/thrid/grid/user/get-user-idNumber", JSON.toJSONString(gridUserIdNumberVo), headVo, "utf-8");
            } else {
                log.info("xsdurl:{}", gridUrl + "/sys/user/getUserByIdNumber");
                s = HttpClientUtils.httpPostRaw(gridUrl + "/sys/user/getUserByIdNumber", JSON.toJSONString(gridUserIdNumberVo), headVo, "utf-8");
            }
            log.info("xsd身份证获取:{}", s);
        } catch (Exception e) {
            log.info("xsderror:{}", e.getLocalizedMessage());
            return R.fail(e.getLocalizedMessage());
        }
        JSONObject object = JSONObject.parseObject(s);
        if (object != null) {
            if (object.getInteger("code") != null && object.getInteger("code") == 0) {
                JSONObject data = JSONObject.parseObject(s).getJSONObject("data");
                if (data != null) {
                    GridUserVo gridUserVo = data.toJavaObject(GridUserVo.class);
                    return R.ok(gridUserVo);
                } else {
                    return R.fail("身份证获取失败");
                }
            } else {
                return R.fail("身份证获取失败");
            }
        } else {
            return R.fail("身份证获取失败");
        }
 
    }
}