| | |
| | | package com.moral.api.service.impl; |
| | | |
| | | import java.util.ArrayList; |
| | | import java.util.List; |
| | | import java.util.Map; |
| | | import java.util.Objects; |
| | | |
| | | import com.baomidou.mybatisplus.core.conditions.update.UpdateWrapper; |
| | | import com.moral.api.entity.UserGroup; |
| | |
| | | import org.springframework.stereotype.Service; |
| | | import org.springframework.transaction.annotation.Transactional; |
| | | import org.springframework.util.ObjectUtils; |
| | | import org.springframework.web.context.request.RequestContextHolder; |
| | | import org.springframework.web.context.request.ServletRequestAttributes; |
| | | |
| | | import javax.servlet.http.HttpServletRequest; |
| | | |
| | | /** |
| | | * <p> |
| | |
| | | @Override |
| | | @Transactional |
| | | public void allotGroups(Map<String, Object> parameters) { |
| | | HttpServletRequest request = ((ServletRequestAttributes) Objects.requireNonNull(RequestContextHolder.getRequestAttributes())).getRequest(); |
| | | String token = request.getHeader("token"); |
| | | |
| | | Object o = parameters.get("groupId"); |
| | | 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> currentUserInfo = (Map<String, Object>) TokenUtils.getUserInfo(); |
| | | Map<String, Object> orgInfo = (Map<String, Object>) currentUserInfo.get("organization"); |
| | | |
| | | UpdateWrapper<UserGroup> deleteWrapper = new UpdateWrapper<>(); |
| | | deleteWrapper.eq("user_id", userId); |
| | | userGroupMapper.delete(deleteWrapper); |
| | | List<String> groups = new ArrayList<>(); |
| | | if (!ObjectUtils.isEmpty(groupIds)) { |
| | | groupIds.forEach(groupId -> { |
| | | groups.add(groupMapper.selectById(groupId).getGroupName()); |
| | | UserGroup userGroup = new UserGroup(); |
| | | userGroup.setUserId(userId); |
| | | userGroup.setGroupId(groupId); |
| | | userGroup.setOrganizationId((Integer) orgInfo.get("id")); |
| | | userGroupMapper.insert(userGroup); |
| | | }); |
| | | } |
| | | |
| | | //日志 |
| | | String account = userMapper.selectById((Integer) parameters.get("userId")).getAccount(); |
| | | String content = "给用户:" + account + "分配了组:" + groups; |
| | | operationLogUtils.insertLog(request, content, Constants.UPDATE_OPERATE_TYPE); |
| | | if (!ObjectUtils.isEmpty(o)) { |
| | | int groupId = Integer.parseInt(o.toString()); |
| | | String groupName = groupMapper.selectById(groupId).getGroupName(); |
| | | UserGroup userGroup = new UserGroup(); |
| | | userGroup.setUserId(userId); |
| | | userGroup.setGroupId(groupId); |
| | | userGroup.setOrganizationId((Integer) orgInfo.get("id")); |
| | | //user_group表insert |
| | | userGroupMapper.insert(userGroup); |
| | | //日志 |
| | | String account = userMapper.selectById((Integer) parameters.get("userId")).getAccount(); |
| | | String content = "给用户:" + account + "分配了组:" + groupName; |
| | | operationLogUtils.insertLog(content, Constants.UPDATE_OPERATE_TYPE); |
| | | } |
| | | } |
| | | } |