New file |
| | |
| | | package com.example.erp.service.userInfo; |
| | | |
| | | import com.baomidou.dynamic.datasource.annotation.DS; |
| | | import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper; |
| | | import com.example.erp.entity.userInfo.UserRole; |
| | | import com.example.erp.mapper.userInfo.UserRoleMapper; |
| | | import org.springframework.beans.factory.annotation.Autowired; |
| | | import org.springframework.stereotype.Service; |
| | | |
| | | import java.util.ArrayList; |
| | | import java.util.List; |
| | | import java.util.Map; |
| | | |
| | | @Service |
| | | @DS("user_info") |
| | | public class UserRoleService { |
| | | private final UserRoleMapper userRoleMapper; |
| | | |
| | | public UserRoleService(UserRoleMapper userRoleMapper) { |
| | | this.userRoleMapper = userRoleMapper; |
| | | } |
| | | |
| | | public Boolean updateUserRole(Map<String, Object> params) { |
| | | Integer userId = (Integer) params.get("userId"); |
| | | List<Integer> list = (List<Integer>) params.get("roles"); |
| | | List<UserRole> userRoleList = new ArrayList<>(); |
| | | if(!list.isEmpty()) { |
| | | for (Integer roleId : list) { |
| | | UserRole userRole = new UserRole(); |
| | | userRole.setUserId(userId); |
| | | userRole.setRoleId(roleId); |
| | | userRoleList.add(userRole); |
| | | } |
| | | } |
| | | userRoleMapper.delete(new QueryWrapper<UserRole>().eq("user_id", userId)); |
| | | userRoleList.forEach(userRole -> { |
| | | userRoleMapper.insert(userRole); |
| | | }); |
| | | return true; |
| | | } |
| | | } |