|  | @@ -5,10 +5,7 @@ import com.baomidou.mybatisplus.core.metadata.OrderItem;
 | 
	
		
			
				|  |  |  import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
 | 
	
		
			
				|  |  |  import com.nokia.common.R;
 | 
	
		
			
				|  |  |  import com.nokia.common.exception.BizException;
 | 
	
		
			
				|  |  | -import com.nokia.dao.AreaDao;
 | 
	
		
			
				|  |  | -import com.nokia.dao.UserDao;
 | 
	
		
			
				|  |  | -import com.nokia.dao.UserFunctionDao;
 | 
	
		
			
				|  |  | -import com.nokia.dao.UserRoleCityDao;
 | 
	
		
			
				|  |  | +import com.nokia.dao.*;
 | 
	
		
			
				|  |  |  import com.nokia.pojo.User;
 | 
	
		
			
				|  |  |  import com.nokia.pojo.UserFunction;
 | 
	
		
			
				|  |  |  import com.nokia.pojo.UserRoleCity;
 | 
	
	
		
			
				|  | @@ -29,14 +26,16 @@ public class UserService {
 | 
	
		
			
				|  |  |      private final UserRoleCityDao userRoleCityDao;
 | 
	
		
			
				|  |  |      private final UserFunctionDao userFunctionDao;
 | 
	
		
			
				|  |  |      private final AreaDao areaDao;
 | 
	
		
			
				|  |  | +    private final RoleDao roleDao;
 | 
	
		
			
				|  |  |      private final OperationLogService operationLogService;
 | 
	
		
			
				|  |  |  
 | 
	
		
			
				|  |  |      public UserService(UserDao userDao, UserRoleCityDao userRoleCityDao, UserFunctionDao userFunctionDao,
 | 
	
		
			
				|  |  | -                       AreaDao areaDao, OperationLogService operationLogService) {
 | 
	
		
			
				|  |  | +                       AreaDao areaDao, RoleDao roleDao, OperationLogService operationLogService) {
 | 
	
		
			
				|  |  |          this.userDao = userDao;
 | 
	
		
			
				|  |  |          this.userRoleCityDao = userRoleCityDao;
 | 
	
		
			
				|  |  |          this.userFunctionDao = userFunctionDao;
 | 
	
		
			
				|  |  |          this.areaDao = areaDao;
 | 
	
		
			
				|  |  | +        this.roleDao = roleDao;
 | 
	
		
			
				|  |  |          this.operationLogService = operationLogService;
 | 
	
		
			
				|  |  |      }
 | 
	
		
			
				|  |  |  
 | 
	
	
		
			
				|  | @@ -145,7 +144,7 @@ public class UserService {
 | 
	
		
			
				|  |  |          if (!CollectionUtils.isEmpty(dto.getRoles())) {
 | 
	
		
			
				|  |  |              int userId = user.getUserId();
 | 
	
		
			
				|  |  |              List<UserRoleCity> userRoleCities = new ArrayList<>();
 | 
	
		
			
				|  |  | -            Set<Integer> functionIds = new HashSet<>();
 | 
	
		
			
				|  |  | +            Set<Integer> roleIds = new HashSet<>();
 | 
	
		
			
				|  |  |              sb.append("角色:");
 | 
	
		
			
				|  |  |              for (AddUserRoleDto t : dto.getRoles()) {
 | 
	
		
			
				|  |  |                  sb.append(t.getRoleName()).append("-").append(t.getCityName()).append(",");
 | 
	
	
		
			
				|  | @@ -154,11 +153,10 @@ public class UserService {
 | 
	
		
			
				|  |  |                  userRoleCity.setRoleId(t.getRoleId());
 | 
	
		
			
				|  |  |                  userRoleCity.setCityId(t.getCityId());
 | 
	
		
			
				|  |  |                  userRoleCities.add(userRoleCity);
 | 
	
		
			
				|  |  | -                if (t.getFunctionId() != null) {
 | 
	
		
			
				|  |  | -                    functionIds.add(t.getFunctionId());
 | 
	
		
			
				|  |  | -                }
 | 
	
		
			
				|  |  | +                roleIds.add(t.getRoleId());
 | 
	
		
			
				|  |  |              }
 | 
	
		
			
				|  |  |              userRoleCityDao.insertBatch(userRoleCities);
 | 
	
		
			
				|  |  | +            Set<Integer> functionIds = roleDao.getFunctionIdsByRoleIds(roleIds);
 | 
	
		
			
				|  |  |              if (!CollectionUtils.isEmpty(functionIds)) {
 | 
	
		
			
				|  |  |                  List<UserFunction> userFunctions = functionIds.stream().map(t -> new UserFunction(userId, t))
 | 
	
		
			
				|  |  |                          .collect(Collectors.toList());
 | 
	
	
		
			
				|  | @@ -218,7 +216,7 @@ public class UserService {
 | 
	
		
			
				|  |  |                  sb.append(t.getRoleName()).append("-").append(t.getCityName()).append(",");
 | 
	
		
			
				|  |  |              }
 | 
	
		
			
				|  |  |              List<UserRoleCity> userRoleCities = new ArrayList<>();
 | 
	
		
			
				|  |  | -            Set<Integer> functionIds = new HashSet<>();
 | 
	
		
			
				|  |  | +            Set<Integer> roleIds = new HashSet<>();
 | 
	
		
			
				|  |  |              sb.append(";角色新值:");
 | 
	
		
			
				|  |  |              for (AddUserRoleDto t : dto.getRoles()) {
 | 
	
		
			
				|  |  |                  sb.append(t.getRoleName()).append("-").append(t.getCityName()).append(",");
 | 
	
	
		
			
				|  | @@ -227,14 +225,13 @@ public class UserService {
 | 
	
		
			
				|  |  |                  userRoleCity.setRoleId(t.getRoleId());
 | 
	
		
			
				|  |  |                  userRoleCity.setCityId(t.getCityId());
 | 
	
		
			
				|  |  |                  userRoleCities.add(userRoleCity);
 | 
	
		
			
				|  |  | -                if (t.getFunctionId() != null) {
 | 
	
		
			
				|  |  | -                    functionIds.add(t.getFunctionId());
 | 
	
		
			
				|  |  | -                }
 | 
	
		
			
				|  |  | +                roleIds.add(t.getRoleId());
 | 
	
		
			
				|  |  |              }
 | 
	
		
			
				|  |  |              UpdateWrapper<UserRoleCity> userRoleCityUpdateWrapper = new UpdateWrapper<>();
 | 
	
		
			
				|  |  |              userRoleCityUpdateWrapper.eq("user_id", dto.getUserId());
 | 
	
		
			
				|  |  |              userRoleCityDao.delete(userRoleCityUpdateWrapper);
 | 
	
		
			
				|  |  |              userRoleCityDao.insertBatch(userRoleCities);
 | 
	
		
			
				|  |  | +            Set<Integer> functionIds = roleDao.getFunctionIdsByRoleIds(roleIds);
 | 
	
		
			
				|  |  |              if (!CollectionUtils.isEmpty(functionIds)) {
 | 
	
		
			
				|  |  |                  UpdateWrapper<UserFunction> userFunctionUpdateWrapper = new UpdateWrapper<>();
 | 
	
		
			
				|  |  |                  userFunctionUpdateWrapper.eq("user_id", dto.getUserId());
 | 
	
	
		
			
				|  | @@ -294,14 +291,14 @@ public class UserService {
 | 
	
		
			
				|  |  |          if (role.getCityId() != -1 && !role.getCityId().equals(cityId)) {
 | 
	
		
			
				|  |  |              return R.error("无法修改非本地市用户");
 | 
	
		
			
				|  |  |          }
 | 
	
		
			
				|  |  | +        Set<Integer> roleIds = new HashSet<>();
 | 
	
		
			
				|  |  |          // 检查权限和地市
 | 
	
		
			
				|  |  | -        if (!CollectionUtils.isEmpty(dto.getRoles())) {
 | 
	
		
			
				|  |  | -            for (AddUserRoleDto t : dto.getRoles()) {
 | 
	
		
			
				|  |  | -                // 除工单查询外其他权限地市不匹配
 | 
	
		
			
				|  |  | -                if (!t.getRoleId().equals(3) && !t.getCityId().equals(cityId)) {
 | 
	
		
			
				|  |  | -                    throw new BizException("权限和地市不匹配");
 | 
	
		
			
				|  |  | -                }
 | 
	
		
			
				|  |  | +        for (AddUserRoleDto t : dto.getRoles()) {
 | 
	
		
			
				|  |  | +            // 除工单查询外其他权限地市不匹配
 | 
	
		
			
				|  |  | +            if (!t.getRoleId().equals(3) && !t.getCityId().equals(cityId)) {
 | 
	
		
			
				|  |  | +                throw new BizException("权限和地市不匹配");
 | 
	
		
			
				|  |  |              }
 | 
	
		
			
				|  |  | +            roleIds.add(t.getRoleId());
 | 
	
		
			
				|  |  |          }
 | 
	
		
			
				|  |  |          StringBuilder sb = new StringBuilder();
 | 
	
		
			
				|  |  |          List<User> users = userDao.selectBatchIds(dto.getUserIds());
 | 
	
	
		
			
				|  | @@ -317,12 +314,15 @@ public class UserService {
 | 
	
		
			
				|  |  |                  userRoleCity.setRoleId(t.getRoleId());
 | 
	
		
			
				|  |  |                  userRoleCity.setCityId(t.getCityId());
 | 
	
		
			
				|  |  |                  userRoleCities.add(userRoleCity);
 | 
	
		
			
				|  |  | -                if (t.getFunctionId() != null) {
 | 
	
		
			
				|  |  | -                    UserFunction userFunction = new UserFunction();
 | 
	
		
			
				|  |  | -                    userFunction.setUserId(userId);
 | 
	
		
			
				|  |  | -                    userFunction.setFunctionId(t.getFunctionId());
 | 
	
		
			
				|  |  | -                    userFunctions.add(userFunction);
 | 
	
		
			
				|  |  | -                }
 | 
	
		
			
				|  |  | +            }
 | 
	
		
			
				|  |  | +        }
 | 
	
		
			
				|  |  | +        Set<Integer> functionIds = roleDao.getFunctionIdsByRoleIds(roleIds);
 | 
	
		
			
				|  |  | +        for (Integer t : functionIds) {
 | 
	
		
			
				|  |  | +            for (Integer userId : dto.getUserIds()) {
 | 
	
		
			
				|  |  | +                UserFunction userFunction = new UserFunction();
 | 
	
		
			
				|  |  | +                userFunction.setUserId(userId);
 | 
	
		
			
				|  |  | +                userFunction.setFunctionId(t);
 | 
	
		
			
				|  |  | +                userFunctions.add(userFunction);
 | 
	
		
			
				|  |  |              }
 | 
	
		
			
				|  |  |          }
 | 
	
		
			
				|  |  |          deleteUserRoleCityByUserIds(dto.getUserIds());
 |