| | |
| | | import java.util.ArrayList; |
| | | import java.util.List; |
| | | import java.util.Map; |
| | | import java.util.Objects; |
| | | |
| | | import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper; |
| | | import com.baomidou.mybatisplus.core.conditions.update.UpdateWrapper; |
| | | import com.moral.api.entity.UserGroup; |
| | | import com.moral.api.mapper.GroupMapper; |
| | | import com.moral.api.mapper.UserGroupMapper; |
| | | import com.moral.api.mapper.UserMapper; |
| | | import com.moral.api.service.UserGroupService; |
| | | import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl; |
| | | import com.moral.api.utils.OperationLogUtils; |
| | | import com.moral.constant.Constants; |
| | | import com.moral.util.TokenUtils; |
| | | |
| | | import org.springframework.beans.factory.annotation.Autowired; |
| | | import org.springframework.stereotype.Service; |
| | | import org.springframework.transaction.annotation.Transactional; |
| | | import org.springframework.web.context.request.RequestContextHolder; |
| | | import org.springframework.web.context.request.ServletRequestAttributes; |
| | | |
| | | import javax.servlet.http.HttpServletRequest; |
| | | |
| | | /** |
| | | * <p> |
| | |
| | | @Autowired |
| | | private UserGroupMapper userGroupMapper; |
| | | |
| | | @Autowired |
| | | private UserMapper userMapper; |
| | | |
| | | @Autowired |
| | | private GroupMapper groupMapper; |
| | | |
| | | @Override |
| | | public void allotGroups(Map<String, Object> parameters, String token) { |
| | | @Transactional |
| | | public void allotGroups(Map<String, Object> parameters) { |
| | | HttpServletRequest request = ((ServletRequestAttributes) Objects.requireNonNull(RequestContextHolder.getRequestAttributes())).getRequest(); |
| | | String token = request.getHeader("token"); |
| | | |
| | | Integer userId = Integer.parseInt(parameters.get("userId").toString()); |
| | | List<Integer> groupIds = (ArrayList) parameters.get("groupIds"); |
| | | Map<String, Object> currentUserInfo = (Map<String, Object>) TokenUtils.getUserInfoByToken(token); |
| | | Map<String, Object> orgInfo = (Map<String, Object>) currentUserInfo.get("organization"); |
| | | UpdateWrapper<UserGroup> deleteWrapper = new UpdateWrapper<>(); |
| | | deleteWrapper.set("is_delete", Constants.DELETE).eq("user_id", userId); |
| | | userGroupMapper.update(null, deleteWrapper); |
| | | if (!groupIds.isEmpty()) { |
| | | for (Integer groupId : groupIds) { |
| | | deleteWrapper.eq("user_id", userId); |
| | | userGroupMapper.delete(deleteWrapper); |
| | | List<String> groups = new ArrayList<>(); |
| | | if (groupIds != null && !groupIds.isEmpty()) { |
| | | groupIds.forEach(groupId -> { |
| | | groups.add(groupMapper.selectById(groupId).getGroupName()); |
| | | UserGroup userGroup = new UserGroup(); |
| | | userGroup.setUserId(userId); |
| | | userGroup.setGroupId(groupId); |
| | | userGroup.setOrganizationId((Integer) currentUserInfo.get("organizationId")); |
| | | userGroup.setOrganizationId((Integer) orgInfo.get("id")); |
| | | userGroupMapper.insert(userGroup); |
| | | } |
| | | }); |
| | | } |
| | | |
| | | //日志 |
| | | String account = userMapper.selectById((Integer) parameters.get("userId")).getAccount(); |
| | | String content = "给用户:" + account + "分配了组:" + groups.toString(); |
| | | OperationLogUtils.insertLog(request, content, Constants.UPDATE_OPERATE_TYPE); |
| | | } |
| | | |
| | | @Override |
| | |
| | | queryWrapper.eq("user_id", userId).eq("is_delete", Constants.NOT_DELETE); |
| | | List<UserGroup> userGroups = userGroupMapper.selectList(queryWrapper); |
| | | List<Integer> groupIds = new ArrayList<>(); |
| | | for (UserGroup userGroup : userGroups) { |
| | | groupIds.add(userGroup.getGroupId()); |
| | | } |
| | | userGroups.forEach(userGroup -> groupIds.add(userGroup.getGroupId())); |
| | | return groupIds; |
| | | } |
| | | } |