| | |
| | | package com.moral.api.service.impl; |
| | | |
| | | import java.util.ArrayList; |
| | | import java.util.List; |
| | | import java.util.Map; |
| | | |
| | | import com.baomidou.mybatisplus.core.conditions.update.UpdateWrapper; |
| | | import com.moral.api.entity.UserGroup; |
| | | import com.moral.api.mapper.UserGroupMapper; |
| | | import com.moral.api.service.UserGroupService; |
| | | import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl; |
| | | import com.moral.constant.Constants; |
| | | import com.moral.util.TokenUtils; |
| | | |
| | | import org.springframework.beans.factory.annotation.Autowired; |
| | | import org.springframework.stereotype.Service; |
| | | |
| | | /** |
| | |
| | | @Service |
| | | public class UserGroupServiceImpl extends ServiceImpl<UserGroupMapper, UserGroup> implements UserGroupService { |
| | | |
| | | @Autowired |
| | | private UserGroupMapper userGroupMapper; |
| | | |
| | | @Override |
| | | public void allotGroups(Map<String, Object> parameters, String 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); |
| | | 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) { |
| | | UserGroup userGroup = new UserGroup(); |
| | | userGroup.setUserId(userId); |
| | | userGroup.setGroupId(groupId); |
| | | userGroup.setOrganizationId((Integer) currentUserInfo.get("organizationId")); |
| | | userGroupMapper.insert(userGroup); |
| | | } |
| | | } |
| | | } |
| | | } |