New file |
| | |
| | | package com.highdatas.mdm.util;
|
| | |
|
| | | import com.alibaba.fastjson.JSON;
|
| | | import com.alibaba.fastjson.JSONArray;
|
| | | import com.alibaba.fastjson.JSONObject;
|
| | | import com.highdatas.mdm.entity.TRole;
|
| | | import com.highdatas.mdm.entity.TUser;
|
| | | import com.highdatas.mdm.entity.TUserGroup;
|
| | | import org.springframework.beans.factory.annotation.Value;
|
| | | import org.springframework.boot.context.properties.ConfigurationProperties;
|
| | | import org.springframework.http.HttpMethod;
|
| | | import org.springframework.http.MediaType;
|
| | | import org.springframework.stereotype.Component;
|
| | | import org.springframework.util.LinkedMultiValueMap;
|
| | | import org.springframework.util.MultiValueMap;
|
| | | import org.springframework.util.StringUtils;
|
| | |
|
| | | import java.util.HashMap;
|
| | | import java.util.List;
|
| | |
|
| | | @ConfigurationProperties(prefix = "user")
|
| | | @Component
|
| | | public class UserRoleClient {
|
| | |
|
| | | @Value("${user.url}")
|
| | | String url;
|
| | |
|
| | | String prefix ;
|
| | |
|
| | | private UserRoleClient() {
|
| | | this.prefix = "/api/datacvg/";
|
| | | }
|
| | |
|
| | | public TUser getTUserById(String userId) {
|
| | | String url = this.url + prefix + "user/selectUser";
|
| | | MultiValueMap<String, String> params = new LinkedMultiValueMap<>();
|
| | | params.set("userId",userId);
|
| | | String s = HttpUtils.HttpRestClient(url, HttpMethod.POST, params, MediaType.APPLICATION_JSON);
|
| | | JSONObject result = (JSONObject) JSON.parse(s);
|
| | | String sucess = result.getString(Constant.Success);
|
| | | if (StringUtils.isEmpty(sucess) || !Boolean.valueOf(sucess)) {
|
| | | return null;
|
| | | }else {
|
| | | JSONObject data = result.getJSONObject(Constant.Data);
|
| | | TUser user = JSON.toJavaObject(data, TUser.class);
|
| | | if (user == null){
|
| | | return null;
|
| | | }
|
| | | return user;
|
| | | }
|
| | | }
|
| | |
|
| | | public TRole getRoleByRoleId(String roleId) {
|
| | | try {
|
| | | String url = this.url + prefix + "role/selectRole";
|
| | | MultiValueMap<String, String> params = new LinkedMultiValueMap<>();
|
| | | params.set("roleId", roleId);
|
| | | String s = HttpUtils.HttpRestClient(url, HttpMethod.POST, params, MediaType.APPLICATION_JSON);
|
| | | JSONObject result = (JSONObject) JSON.parse(s);
|
| | | String sucess = result.getString(Constant.Success);
|
| | | if (StringUtils.isEmpty(sucess) || !Boolean.valueOf(sucess)) {
|
| | | return null;
|
| | | }else {
|
| | | JSONObject data = result.getJSONObject(Constant.Data);
|
| | | TRole role = JSON.toJavaObject(data, TRole.class);
|
| | | if (role == null){
|
| | | return null;
|
| | | }
|
| | | return role;
|
| | | }
|
| | | }catch (Exception e){
|
| | | e.printStackTrace();
|
| | | return null;
|
| | | }
|
| | |
|
| | | }
|
| | |
|
| | | public List<TUserGroup> getUserGroupByUserId(String userId) {
|
| | | String url = this.url + prefix + "group/userGroupInfo";
|
| | | MultiValueMap<String, String> params = new LinkedMultiValueMap<>();
|
| | | params.set("userId",userId);
|
| | | String s = HttpUtils.HttpRestClient(url, HttpMethod.POST, params, MediaType.APPLICATION_JSON);
|
| | | JSONObject result = (JSONObject) JSON.parse(s);
|
| | | String sucess = result.getString(Constant.Success);
|
| | | if (StringUtils.isEmpty(sucess) || !Boolean.valueOf(sucess)) {
|
| | | return null;
|
| | | }else {
|
| | | JSONArray groupArray = result.getJSONArray(Constant.Data);
|
| | | List<TUserGroup> tUserGroups = JSONArray.parseArray(groupArray.toJSONString(), TUserGroup.class);
|
| | | if (tUserGroups == null || tUserGroups.isEmpty()) {
|
| | | return null;
|
| | | }
|
| | | return tUserGroups;
|
| | | }
|
| | | }
|
| | |
|
| | | public List<TRole> getTRoleListByUserId(String userId) {
|
| | | String url = this.url + prefix + "userRole/selectUserRole";
|
| | | MultiValueMap<String, String> params = new LinkedMultiValueMap<>();
|
| | | params.set("userId",userId);
|
| | | String s = HttpUtils.HttpRestClient(url, HttpMethod.POST, params, MediaType.APPLICATION_JSON);
|
| | | JSONObject result = (JSONObject) JSON.parse(s);
|
| | | String sucess = result.getString(Constant.Success);
|
| | | if (StringUtils.isEmpty(sucess) || !Boolean.valueOf(sucess)) {
|
| | | return null;
|
| | | }else {
|
| | | JSONObject data = result.getJSONObject(Constant.Data);
|
| | | JSONArray groupArray = data.getJSONArray("Unauthorized");
|
| | | List<TRole> tRoles = JSONArray.parseArray(groupArray.toJSONString(), TRole.class);
|
| | | if (tRoles == null || tRoles.isEmpty()) {
|
| | | return null;
|
| | | }
|
| | | return tRoles;
|
| | | }
|
| | | }
|
| | |
|
| | | public List<TRole> getRoleListByGroupId(String groupId) {
|
| | | try {
|
| | | String url = this.url + prefix + "group/groupRoleInfo";
|
| | | MultiValueMap<String, String> params = new LinkedMultiValueMap<>();
|
| | | params.set("groupId", groupId);
|
| | | String s = HttpUtils.HttpRestClient(url, HttpMethod.POST, params, MediaType.APPLICATION_JSON);
|
| | | JSONObject result = (JSONObject) JSON.parse(s);
|
| | | String sucess = result.getString(Constant.Success);
|
| | | if (StringUtils.isEmpty(sucess) || !Boolean.valueOf(sucess)) {
|
| | | return null;
|
| | | }else {
|
| | | JSONArray data = result.getJSONArray(Constant.Data);
|
| | | List<TRole> role = JSONArray.parseArray(data.toJSONString(), TRole.class);
|
| | | if (role == null || role.isEmpty()){
|
| | | return null;
|
| | | }
|
| | | return role;
|
| | | }
|
| | | }catch (Exception e){
|
| | | e.printStackTrace();
|
| | | return null;
|
| | | }
|
| | |
|
| | | }
|
| | |
|
| | | public boolean addRoleByUser(String userId, List<String> roleIds, String userName) {
|
| | | try {
|
| | | String url = this.url + prefix + "userRole/addRoleUser";
|
| | | MultiValueMap<String, Object> params = new LinkedMultiValueMap<>();
|
| | | params.set("userId", userId);
|
| | | params.set("listRoleId", roleIds);
|
| | | params.set("createUser", userId);
|
| | | String s = HttpUtils.HttpRestClientByObjectParams(url, HttpMethod.POST, params, null, null,MediaType.APPLICATION_JSON);
|
| | | JSONObject result = (JSONObject) JSON.parse(s);
|
| | | String sucess = result.getString(Constant.Success);
|
| | | if (StringUtils.isEmpty(sucess) || !Boolean.valueOf(sucess)) {
|
| | | return false;
|
| | | }else {
|
| | | boolean added = result.getBoolean(Constant.Data);
|
| | | return added;
|
| | | }
|
| | | }catch (Exception e){
|
| | | e.printStackTrace();
|
| | | return false;
|
| | | }
|
| | | }
|
| | |
|
| | | public boolean deleteRoleByUser(String userId, List<String> roleIds, String userName) {
|
| | | try {
|
| | | String url = this.url + prefix + "userRole/deleteRoleUsers";
|
| | | MultiValueMap<String, Object> params = new LinkedMultiValueMap<>();
|
| | | params.set("userId", userId);
|
| | | params.set("listRoleId", roleIds);
|
| | | params.set("createUser", userId);
|
| | | String s = HttpUtils.HttpRestClientByObjectParams(url, HttpMethod.POST, params, null, null,MediaType.APPLICATION_JSON);
|
| | | JSONObject result = (JSONObject) JSON.parse(s);
|
| | | String sucess = result.getString(Constant.Success);
|
| | | if (StringUtils.isEmpty(sucess) || !Boolean.valueOf(sucess)) {
|
| | | return false;
|
| | | }else {
|
| | | boolean added = result.getBoolean(Constant.Data);
|
| | | return added;
|
| | | }
|
| | | }catch (Exception e){
|
| | | e.printStackTrace();
|
| | | return false;
|
| | | }
|
| | |
|
| | | }
|
| | |
|
| | | public boolean addRoleByGroupId(String userId, List<String> roleIds, String groupId) {
|
| | | try {
|
| | | String url = this.url + prefix + "group/addGroupRole";
|
| | | HashMap<String, String> headerMap = new HashMap<>();
|
| | | headerMap.put("userId", userId);
|
| | |
|
| | | MultiValueMap<String, Object> params = new LinkedMultiValueMap<>();
|
| | | params.set("groupId", groupId);
|
| | | params.set("roleIdList", roleIds);
|
| | | String s = HttpUtils.HttpRestClientByObjectParams(url, HttpMethod.POST, params, null,headerMap,MediaType.APPLICATION_JSON);
|
| | | JSONObject result = (JSONObject) JSON.parse(s);
|
| | | String sucess = result.getString(Constant.Success);
|
| | | if (StringUtils.isEmpty(sucess) || !Boolean.valueOf(sucess)) {
|
| | | return false;
|
| | | }
|
| | | return true;
|
| | | }catch (Exception e){
|
| | | e.printStackTrace();
|
| | | return false;
|
| | | }
|
| | | }
|
| | |
|
| | |
|
| | | public boolean deleteRoleByGroupId(List<String> roleIds, String groupId) {
|
| | | try {
|
| | | String url = this.url + prefix + "group/delGroupRole";
|
| | | MultiValueMap<String, Object> params = new LinkedMultiValueMap<>();
|
| | | params.set("groupId", groupId);
|
| | | params.set("roleIdList", roleIds);
|
| | | String s = HttpUtils.HttpRestClientByObjectParams(url, HttpMethod.POST, params, null,null,MediaType.APPLICATION_JSON);
|
| | | JSONObject result = (JSONObject) JSON.parse(s);
|
| | | String sucess = result.getString(Constant.Success);
|
| | | if (StringUtils.isEmpty(sucess) || !Boolean.valueOf(sucess)) {
|
| | | return false;
|
| | | }
|
| | | return true;
|
| | | }catch (Exception e){
|
| | | e.printStackTrace();
|
| | | return false;
|
| | | }
|
| | | }
|
| | | }
|