jinpengyong
2023-10-20 17c774c9c13febdcff654ffd6bbabd313c37a3ee
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
package com.moral.api.service.impl;
 
import java.util.Map;
 
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.util.ObjectUtils;
 
/**
 * <p>
 * 前台用户角色关系表 服务实现类
 * </p>
 *
 * @author moral
 * @since 2021-03-09
 */
@Service
public class UserGroupServiceImpl extends ServiceImpl<UserGroupMapper, UserGroup> implements UserGroupService {
 
    @Autowired
    private UserGroupMapper userGroupMapper;
 
    @Autowired
    private UserMapper userMapper;
 
    @Autowired
    private GroupMapper groupMapper;
 
    @Autowired
    private OperationLogUtils operationLogUtils;
 
    @Override
    @Transactional
    public void allotGroups(Map<String, Object> parameters) {
        Object o = parameters.get("groupId");
        Integer userId = Integer.parseInt(parameters.get("userId").toString());
        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);
 
        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);
        }
    }
}