| | |
| | | import com.highdatas.mdm.entity.TRole;
|
| | | import com.highdatas.mdm.entity.TUser;
|
| | | import com.highdatas.mdm.entity.TUserGroup;
|
| | | import lombok.extern.slf4j.Slf4j;
|
| | | import org.springframework.beans.factory.annotation.Autowired;
|
| | | import org.springframework.beans.factory.annotation.Value;
|
| | | import org.springframework.boot.context.properties.ConfigurationProperties;
|
| | | import org.springframework.http.HttpMethod;
|
| | |
| | | import org.springframework.stereotype.Component;
|
| | | import org.springframework.util.StringUtils;
|
| | |
|
| | | import java.util.HashMap;
|
| | | import java.util.LinkedHashMap;
|
| | | import java.util.List;
|
| | | import java.util.Map;
|
| | | import java.util.*;
|
| | |
|
| | | @ConfigurationProperties(prefix = "user")
|
| | | @Component
|
| | | @Slf4j
|
| | | public class UserRoleClient {
|
| | |
|
| | | @Value("${user.url}")
|
| | | String url;
|
| | |
|
| | | String prefix ;
|
| | | @Autowired
|
| | | RedisClient redisClient;
|
| | |
|
| | | public UserRoleClient() {
|
| | | this.prefix = "/api/datacvg/";
|
| | | }
|
| | |
|
| | | public TUser getTUserById(String userId) {
|
| | | Object redisValObj = redisClient.getRedisValObj(RedisClient.getRealRedisKey(userId));
|
| | | if (redisValObj != null) {
|
| | | JSONObject object = (JSONObject) redisValObj;
|
| | | TUser user = JSONObject.parseObject(object.toJSONString(), TUser.class);
|
| | | return user;
|
| | | }
|
| | | String url = this.url + prefix + "user/selectUser";
|
| | | Map<String, String> params = new LinkedHashMap<>();
|
| | | params.put("userId",userId);
|
| | | String s = HttpUtils.HttpRestClient(url, HttpMethod.POST, params, MediaType.APPLICATION_JSON);
|
| | | log.info(s);
|
| | | 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);
|
| | | data = data.getJSONObject(Constant.userDO);
|
| | | TUser user = JSON.toJavaObject(data, TUser.class);
|
| | | if (user == null){
|
| | | return null;
|
| | | }
|
| | | redisClient.putRedisValObj(RedisClient.getRealRedisKey(userId), user);
|
| | | return user;
|
| | | }
|
| | | }
|
| | |
|
| | | public TRole getRoleByRoleId(String roleId) {
|
| | | Object redisValObj = redisClient.getRedisValObj(RedisClient.getRealRedisKey(roleId));
|
| | | if (redisValObj != null) {
|
| | | JSONObject object = (JSONObject) redisValObj;
|
| | | TRole user = JSONObject.parseObject(object.toJSONString(), TRole.class);
|
| | | return user;
|
| | | }
|
| | | try {
|
| | | String url = this.url + prefix + "role/selectRole";
|
| | | Map<String, String> params = new LinkedHashMap<>();
|
| | |
| | | if (role == null){
|
| | | return null;
|
| | | }
|
| | | redisClient.putRedisValObj(RedisClient.getRealRedisKey(roleId), role);
|
| | | return role;
|
| | | }
|
| | | }catch (Exception e){
|
| | |
| | | }
|
| | |
|
| | | public List<TUserGroup> getUserGroupByUserId(String userId) {
|
| | |
|
| | | String key = RedisClient.getRealRedisKey(userId + "-getUserGroupByUserId");
|
| | | List<Object> redisList = redisClient.getRedisList(key);
|
| | | if (redisList != null && !redisList.isEmpty()) {
|
| | | List<TUserGroup> result = new ArrayList<>();
|
| | | for (Object o : redisList) {
|
| | | JSONObject object = (JSONObject) o;
|
| | | TUserGroup menu = JSONObject.parseObject(object.toJSONString(), TUserGroup.class);
|
| | | result.add(menu);
|
| | | }
|
| | | return result;
|
| | | }
|
| | |
|
| | | String url = this.url + prefix + "group/userGroupInfo";
|
| | | Map<String, Object> params = new LinkedHashMap<>();
|
| | | params.put("userId",userId);
|
| | |
| | | if (tUserGroups == null || tUserGroups.isEmpty()) {
|
| | | return null;
|
| | | }
|
| | | redisClient.putRedisList(key, (tUserGroups));
|
| | | return tUserGroups;
|
| | | }
|
| | | }
|
| | |
|
| | | public List<TRole> getTRoleListByUserId(String userId) {
|
| | |
|
| | | String key = RedisClient.getRealRedisKey(userId + "-getTRoleListByUserId");
|
| | | List<Object> redisList = redisClient.getRedisList(key);
|
| | | if (redisList != null && !redisList.isEmpty()) {
|
| | | List<TRole> result = new ArrayList<>();
|
| | | for (Object o : redisList) {
|
| | | JSONObject object = (JSONObject) o;
|
| | | TRole menu = JSONObject.parseObject(object.toJSONString(), TRole.class);
|
| | | result.add(menu);
|
| | | }
|
| | | return result;
|
| | | }
|
| | | String url = this.url + prefix + "userRole/selectUserRoleList";
|
| | | Map<String, String> params = new LinkedHashMap<>();
|
| | | params.put("userId",userId);
|
| | |
| | | if (tRoles == null || tRoles.isEmpty()) {
|
| | | return null;
|
| | | }
|
| | | redisClient.putRedisList(key, tRoles);
|
| | | return tRoles;
|
| | | }
|
| | | }
|
| | |
|
| | | public List<TRole> getRoleListByGroupId(String groupId) {
|
| | | String key = RedisClient.getRealRedisKey(groupId + "-getTRoleListByUserId");
|
| | | List<Object> redisList = redisClient.getRedisList(key);
|
| | | if (redisList != null && !redisList.isEmpty()) {
|
| | | List<TRole> result = new ArrayList<>();
|
| | | for (Object o : redisList) {
|
| | | JSONObject object = (JSONObject) o;
|
| | | TRole menu = JSONObject.parseObject(object.toJSONString(), TRole.class);
|
| | | result.add(menu);
|
| | | }
|
| | | return result;
|
| | | }
|
| | | try {
|
| | | String url = this.url + prefix + "group/groupRoleInfo";
|
| | | Map<String, Object> params = new LinkedHashMap<>();
|
| | |
| | | if (role == null || role.isEmpty()){
|
| | | return null;
|
| | | }
|
| | | redisClient.putRedisList(key, role);
|
| | | return role;
|
| | | }
|
| | | }catch (Exception e){
|
| | |
| | | }
|
| | | }
|
| | |
|
| | | public List<TUser> listUserRoleGroup() {
|
| | | try {
|
| | | String url = this.url + prefix + "user/listUserRoleGroup";
|
| | | String s = HttpUtils.HttpRestClientByObjectParams(url, HttpMethod.POST, null, 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 null;
|
| | | }
|
| | | JSONArray jsonArray = result.getJSONArray(Constant.Data);
|
| | | List<TUser> tUsers = JSONObject.parseArray(jsonArray.toJSONString(), TUser.class);
|
| | | return tUsers;
|
| | | }catch (Exception e){
|
| | | e.printStackTrace();
|
| | | return null;
|
| | | }
|
| | | }
|
| | |
|
| | |
|
| | | public boolean deleteRoleByGroupId(List<String> roleIds, String groupId) {
|
| | | try {
|
| | |
| | | return false;
|
| | | }
|
| | | }
|
| | |
|
| | | public List<String> getUserListByRole(String roleId) {
|
| | | String key = RedisClient.getRealRedisKey(roleId + "-getUserListByRole");
|
| | | List<Object> redisList = redisClient.getRedisList(key);
|
| | | if (redisList != null && !redisList.isEmpty()) {
|
| | | List<String> result = new ArrayList<>();
|
| | | for (Object o : redisList) {
|
| | | result.add(o.toString());
|
| | | }
|
| | | return result;
|
| | | }
|
| | | try {
|
| | | String url = this.url + prefix + "userRole/selectUserMap";
|
| | | Map<String, Object> params = new LinkedHashMap<>();
|
| | | params.put("roleId", roleId);
|
| | | 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 null;
|
| | | }
|
| | | List<String> array = result.getObject(Constant.Data, List.class);
|
| | |
|
| | | redisClient.putRedisList(key,array);
|
| | | return array;
|
| | | }catch (Exception e){
|
| | | e.printStackTrace();
|
| | | return null;
|
| | | }
|
| | | }
|
| | | }
|