forked from gzzfw/backEnd/gz-dyh

xusd
2024-10-11 f14df7c0b6aea2dbe393f9ada08b23be3f476e5a
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
package cn.huge.module.grid.service;
 
import cn.huge.base.common.bo.R;
import cn.huge.base.common.utils.HttpClientUtils;
import cn.huge.base.common.utils.SpringContextUtil;
import cn.huge.module.grid.domain.dto.GridOrgDTO;
import cn.huge.module.grid.domain.dto.GridRoleMenuDTO;
import cn.huge.module.grid.domain.dto.GridSysRoleDTO;
import cn.huge.module.grid.domain.dto.GridUserRoleDTO;
import cn.huge.module.grid.domain.vo.*;
import com.alibaba.fastjson.JSON;
import com.alibaba.fastjson.JSONArray;
import com.alibaba.fastjson.JSONObject;
import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.factory.annotation.Value;
import org.springframework.stereotype.Service;
 
import java.util.HashMap;
import java.util.List;
import java.util.UUID;
 
@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;
    private String testUrl = "http://183.2.142.46:9007";
 
    public R<GridUserVo> getUserInfo(GridTokenVo gridTokenVo) {
        String s = null;
        HeadVo headVo = initHeadVo();
        GridUserRequestVo requestVo = new GridUserRequestVo();
        requestVo.setHeadVo(headVo);
        requestVo.setBodyVo(gridTokenVo);
        try {
//            log.info("xsdobject:{}",JSON.toJSONString(requestVo));
            // 开发环境
            if (SpringContextUtil.checkDev()) {
                 log.info("xsdurl:{}",testUrl + "/sys/getUserByToken");
                s = HttpClientUtils.httpPostRaw(testUrl + "/sys/getUserByToken", JSON.toJSONString(requestVo), new HashMap<>(), "utf-8");
            }else {
                log.info("xsdurl:{}",gridUrl + "/sys/getUserByToken");
                s = HttpClientUtils.httpPostRaw(gridUrl + "/sys/getUserByToken", JSON.toJSONString(requestVo), new HashMap<>(), "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);
        return R.ok(gridUserVo);
    }
 
    public R<List<GridUserRoleDTO>> getUserRoleList(GridUserRoleVo gridUserRoleVo) {
        String s = null;
        HeadVo headVo = initHeadVo();
        GridUserRoleRequestVo requestVo = new GridUserRoleRequestVo();
        requestVo.setHeadVo(headVo);
        requestVo.setBodyVo(gridUserRoleVo);
        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(requestVo), new HashMap<>(), "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 HeadVo initHeadVo() {
        HeadVo headVo = new HeadVo();
        headVo.setUsername(userName);
        headVo.setPassword(passWord);
        headVo.setRequestId(UUID.randomUUID().toString());
        headVo.setSource("string");
        return headVo;
    }
 
    public R<GridSysRoleDTO> getSysRoleList(GridOrgVo gridOrgVo) {
        HeadVo headVo = initHeadVo();
        GridOrgRequestVo requestVo = new GridOrgRequestVo();
        requestVo.setHeadVo(headVo);
        requestVo.setBodyVo(gridOrgVo);
        log.info("xsd:{}", JSON.toJSONString(requestVo));
        log.info("xsd:{}", gridUrl + "/sys/getRoleList");
        String s = null;
        try {
            s = HttpClientUtils.httpPostRaw(gridUrl + "/sys/getRoleList", JSON.toJSONString(requestVo), new HashMap<>(), "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;
        HeadVo headVo = initHeadVo();
        GridRoleMenuRequestVo requestVo = new GridRoleMenuRequestVo();
        requestVo.setHeadVo(headVo);
        requestVo.setBodyVo(gridRoleMenuVo);
        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(requestVo), new HashMap<>(), "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);
    }
}