|
|
@@ -1,5 +1,6 @@
|
|
|
package com.crm.manager.service.impl;
|
|
|
|
|
|
+import com.crm.manager.dao.mapper.MerchantRoleMapper;
|
|
|
import com.crm.manager.service.AuthorityService;
|
|
|
import com.crm.rely.backend.core.constant.ManagerConstant;
|
|
|
import com.crm.manager.dao.repository.SysActionRepository;
|
|
|
@@ -25,8 +26,10 @@ import com.crm.rely.backend.exception.ServiceException;
|
|
|
import com.crm.rely.backend.service.RedisService;
|
|
|
import com.crm.rely.backend.util.FormatPage;
|
|
|
import com.crm.rely.backend.util.GetRandom;
|
|
|
+import com.crm.rely.backend.util.StringUtil;
|
|
|
import com.crm.rely.backend.util.ValidateUtil;
|
|
|
import com.google.common.base.Strings;
|
|
|
+import org.apache.commons.lang3.ObjectUtils;
|
|
|
import org.springframework.beans.BeanUtils;
|
|
|
import org.springframework.beans.factory.annotation.Autowired;
|
|
|
import org.springframework.data.domain.Page;
|
|
|
@@ -74,38 +77,42 @@ public class UserRoleServiceImpl implements UserRoleService {
|
|
|
* @throws ServiceException
|
|
|
*/
|
|
|
@Override
|
|
|
- public List<UserNodeDisplayDto> getUserNodeDisplay(Long roleId) throws ServiceException {
|
|
|
+ public List<UserNodeDisplayDto> getUserNodeDisplay(Long roleId,Long merchantId,Long operatorRoleId) throws ServiceException {
|
|
|
/*
|
|
|
* 查询服务器中是否已存在角色信息
|
|
|
*/
|
|
|
- String key = null;
|
|
|
- String roleUpdateRedisAuthorityIdentificationKey;
|
|
|
- if (roleId == null || roleId == 0) {
|
|
|
- key = RoleConstants.ROLE_USER_NODE + RoleConstants.ROLE_ADMIN;
|
|
|
- roleUpdateRedisAuthorityIdentificationKey = Constants.UPDATE_REDIS_AUTHORITY_IDENTIFICATION + "_" + RoleConstants.ROLE_ADMIN;
|
|
|
- } else {
|
|
|
- key = RoleConstants.ROLE_USER_NODE + roleId;
|
|
|
- roleUpdateRedisAuthorityIdentificationKey = Constants.UPDATE_REDIS_AUTHORITY_IDENTIFICATION + "_" + roleId;
|
|
|
- }
|
|
|
- //获取更新标识
|
|
|
- String updateRedisAuthorityIdentification = redisService.getObject(Constants.UPDATE_REDIS_AUTHORITY_IDENTIFICATION);
|
|
|
- if (Strings.isNullOrEmpty(updateRedisAuthorityIdentification)) {
|
|
|
- updateRedisAuthorityIdentification = authorityService.updateRedisAuthorityIdentification();
|
|
|
- }
|
|
|
- //获取角色更新标识
|
|
|
- String roleUpdateRedisAuthorityIdentification = redisService.getObject(roleUpdateRedisAuthorityIdentificationKey);
|
|
|
- //判断更新标识是否存在 如果不存在或者存在且和角色更新标识相同的话 直接从redis中获取权限
|
|
|
- if (!Strings.isNullOrEmpty(roleUpdateRedisAuthorityIdentification) && updateRedisAuthorityIdentification.equals(roleUpdateRedisAuthorityIdentification)) {
|
|
|
- if (redisService.hasKey(key)) {
|
|
|
- List<UserNodeDisplayDto> userNodeDisplayDtos = redisService.getObject(key);
|
|
|
- if (userNodeDisplayDtos.size() != 0) {
|
|
|
- return userNodeDisplayDtos;
|
|
|
- }
|
|
|
- }
|
|
|
+// String key = null;
|
|
|
+// String roleUpdateRedisAuthorityIdentificationKey;
|
|
|
+// if (roleId == null || roleId == 0) {
|
|
|
+// key = RoleConstants.ROLE_USER_NODE + RoleConstants.ROLE_ADMIN;
|
|
|
+// roleUpdateRedisAuthorityIdentificationKey = Constants.UPDATE_REDIS_AUTHORITY_IDENTIFICATION + "_" + RoleConstants.ROLE_ADMIN;
|
|
|
+// } else {
|
|
|
+// key = RoleConstants.ROLE_USER_NODE + roleId;
|
|
|
+// roleUpdateRedisAuthorityIdentificationKey = Constants.UPDATE_REDIS_AUTHORITY_IDENTIFICATION + "_" + roleId;
|
|
|
+// }
|
|
|
+// //获取更新标识
|
|
|
+// String updateRedisAuthorityIdentification = redisService.getObject(Constants.UPDATE_REDIS_AUTHORITY_IDENTIFICATION);
|
|
|
+// if (Strings.isNullOrEmpty(updateRedisAuthorityIdentification)) {
|
|
|
+// updateRedisAuthorityIdentification = authorityService.updateRedisAuthorityIdentification();
|
|
|
+// }
|
|
|
+// //获取角色更新标识
|
|
|
+// String roleUpdateRedisAuthorityIdentification = redisService.getObject(roleUpdateRedisAuthorityIdentificationKey);
|
|
|
+// //判断更新标识是否存在 如果不存在或者存在且和角色更新标识相同的话 直接从redis中获取权限
|
|
|
+// if (!Strings.isNullOrEmpty(roleUpdateRedisAuthorityIdentification) && updateRedisAuthorityIdentification.equals(roleUpdateRedisAuthorityIdentification)) {
|
|
|
+// if (redisService.hasKey(key)) {
|
|
|
+// List<UserNodeDisplayDto> userNodeDisplayDtos = redisService.getObject(key);
|
|
|
+// if (userNodeDisplayDtos.size() != 0) {
|
|
|
+// return userNodeDisplayDtos;
|
|
|
+// }
|
|
|
+// }
|
|
|
+// }
|
|
|
+ UserRoleTable userRoleTable = userRoleRepository.getFirstById(roleId);
|
|
|
+ if(userRoleTable != null && userRoleTable.getMerchantId() != null){
|
|
|
+ merchantId = userRoleTable.getMerchantId();
|
|
|
}
|
|
|
- List<UserNodeDisplayDto> result = updateUserNode(roleId);
|
|
|
+ List<UserNodeDisplayDto> result = updateUserNode(roleId,merchantId,operatorRoleId);
|
|
|
//更新角色更新标识
|
|
|
- redisService.saveObject(roleUpdateRedisAuthorityIdentificationKey, updateRedisAuthorityIdentification);
|
|
|
+// redisService.saveObject(roleUpdateRedisAuthorityIdentificationKey, updateRedisAuthorityIdentification);
|
|
|
return result;
|
|
|
}
|
|
|
|
|
|
@@ -162,8 +169,9 @@ public class UserRoleServiceImpl implements UserRoleService {
|
|
|
@Override
|
|
|
@Transactional(rollbackFor = Exception.class)
|
|
|
public void updateRoleInfo(UserRoleUpdateEntity userRoleUpdateEntity) throws ServiceException {
|
|
|
+ Long roleId = userRoleUpdateEntity.getId();
|
|
|
// 角色id 查角色信息
|
|
|
- UserRoleTable userRoleTable = userRoleRepository.findOne(userRoleUpdateEntity.getId());
|
|
|
+ UserRoleTable userRoleTable = userRoleRepository.findOne(roleId);
|
|
|
if (userRoleTable == null) {
|
|
|
throw new ServiceException(Constants.INFO_NOT_FOUND);
|
|
|
}
|
|
|
@@ -172,17 +180,19 @@ public class UserRoleServiceImpl implements UserRoleService {
|
|
|
throw new ServiceException("该角色名已存在");
|
|
|
}
|
|
|
}
|
|
|
-
|
|
|
+ Long merchantId = userRoleTable.getMerchantId();
|
|
|
BeanUtils.copyProperties(userRoleUpdateEntity, userRoleTable);
|
|
|
-
|
|
|
+ userRoleTable.setMerchantId(merchantId);
|
|
|
userRoleRepository.save(userRoleTable);
|
|
|
|
|
|
UserRoleOperateListEntity userRoleOperateListEntity = new UserRoleOperateListEntity();
|
|
|
userRoleOperateListEntity.setModifyUser(userRoleUpdateEntity.getModifyUser());
|
|
|
userRoleOperateListEntity.setModifyTime(userRoleUpdateEntity.getModifyTime());
|
|
|
userRoleOperateListEntity.setModifyIp(userRoleUpdateEntity.getModifyIp());
|
|
|
- userRoleOperateListEntity.setRoleId(userRoleTable.getId());
|
|
|
+ userRoleOperateListEntity.setRoleId(roleId);
|
|
|
+ userRoleOperateListEntity.setMerchantId(userRoleTable.getMerchantId());
|
|
|
userRoleOperateListEntity.setData(userRoleUpdateEntity.getData());
|
|
|
+ userRoleOperateListEntity.setIsMerchantAdmin(userRoleUpdateEntity.getIsMerchantAdmin());
|
|
|
updateRoleInfo(userRoleOperateListEntity);
|
|
|
}
|
|
|
|
|
|
@@ -195,7 +205,6 @@ public class UserRoleServiceImpl implements UserRoleService {
|
|
|
@Override
|
|
|
@Transactional(rollbackFor = Exception.class)
|
|
|
public void updateRoleInfo(UserRoleOperateListEntity userRoleOperateListEntity) throws ServiceException {
|
|
|
-
|
|
|
if (userRoleOperateListEntity == null) {
|
|
|
return;
|
|
|
}
|
|
|
@@ -203,6 +212,8 @@ public class UserRoleServiceImpl implements UserRoleService {
|
|
|
throw new ServiceException("当前角色不可修改!!!");
|
|
|
}
|
|
|
Long roleId = userRoleOperateListEntity.getRoleId();
|
|
|
+ Long merchantId = userRoleOperateListEntity.getMerchantId();
|
|
|
+ Integer isMerchantAdmin = userRoleOperateListEntity.getIsMerchantAdmin();
|
|
|
|
|
|
List<UserRoleNodeTable> roleNodeTables = null;
|
|
|
List<UserRoleDetailTable> roleDetailTables = null;
|
|
|
@@ -253,14 +264,14 @@ public class UserRoleServiceImpl implements UserRoleService {
|
|
|
/*
|
|
|
* 修改原有的角色信息
|
|
|
*/
|
|
|
- userRoleNodeService.update(roleNodeTables, roleId);
|
|
|
+ userRoleNodeService.update(roleNodeTables, roleId, isMerchantAdmin, merchantId);
|
|
|
|
|
|
- userRoleDetailService.update(roleDetailTables, roleId);
|
|
|
+ userRoleDetailService.update(roleDetailTables, roleId,isMerchantAdmin,merchantId);
|
|
|
|
|
|
/*
|
|
|
* 更新内存中的角色信息
|
|
|
*/
|
|
|
- updateUserNode(roleId);
|
|
|
+ updateUserNode(roleId,merchantId,null);
|
|
|
}
|
|
|
|
|
|
/**
|
|
|
@@ -467,6 +478,9 @@ public class UserRoleServiceImpl implements UserRoleService {
|
|
|
return shellerRoleDto;
|
|
|
}
|
|
|
|
|
|
+ @Autowired
|
|
|
+ private MerchantRoleMapper merchantRoleMapper;
|
|
|
+
|
|
|
/**
|
|
|
* 修改权限
|
|
|
*
|
|
|
@@ -474,17 +488,22 @@ public class UserRoleServiceImpl implements UserRoleService {
|
|
|
* @return
|
|
|
* @throws ServiceException
|
|
|
*/
|
|
|
- private List<UserNodeDisplayDto> updateUserNode(Long roleId) throws ServiceException {
|
|
|
+ private List<UserNodeDisplayDto> updateUserNode(Long roleId,Long merchantId,Long operatorRoleId) throws ServiceException {
|
|
|
|
|
|
/*
|
|
|
- * 该角色拥有的所有菜单
|
|
|
+ * 返回全量节点信息并标记该角色是否拥有该菜单权限
|
|
|
*/
|
|
|
- List<SysNodeView> sysNodeViews = userRoleNodeService.getSysNodesByRoleId(roleId);
|
|
|
-
|
|
|
+ List<SysNodeView> sysNodeViews = userRoleNodeService.getSysNodesByRoleId(roleId,merchantId,operatorRoleId);
|
|
|
+ List<SysActionTable> sysActionTables;
|
|
|
/*
|
|
|
* 获取按钮信息
|
|
|
*/
|
|
|
- List<SysActionTable> sysActionTables = userActionRepository.getAllByOrderByCode();
|
|
|
+ if(merchantId != null && operatorRoleId != null){
|
|
|
+ // 获取该商户所有节点权限信息
|
|
|
+ sysActionTables = merchantRoleMapper.getAllByMerchantId(merchantId);
|
|
|
+ }else {
|
|
|
+ sysActionTables = userActionRepository.getAllByOrderByCode();
|
|
|
+ }
|
|
|
|
|
|
// if (sysActionTables == null || sysActionTables.size() == 0) {
|
|
|
// throw new RuntimeException("权限信息有误,请联系管理员");
|