kaiyu
2021-03-25 247f19f6c3f17c2ac2f37b55c7d0550731f31ffe
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
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.GroupMenu;
import com.moral.api.mapper.GroupMenuMapper;
import com.moral.api.service.GroupMenuService;
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;
 
/**
 * <p>
 * 用户角色菜单表 服务实现类
 * </p>
 *
 * @author moral
 * @since 2021-03-09
 */
@Service
public class GroupMenuServiceImpl extends ServiceImpl<GroupMenuMapper, GroupMenu> implements GroupMenuService {
 
    @Autowired
    private GroupMenuMapper groupMenuMapper;
 
    @Override
    public void allotMenus(Map<String, Object> parameters, String token) {
        Integer groupId = Integer.parseInt(parameters.get("groupId").toString());
        List<Integer> menuIds = (ArrayList) parameters.get("menuIds");
        Map<String, Object> currentUserInfo = (Map<String, Object>) TokenUtils.getUserInfoByToken(token);
        UpdateWrapper<GroupMenu> deleteWrapper = new UpdateWrapper<>();
        deleteWrapper.set("is_delete", Constants.DELETE)
                .eq("group_id", groupId)
                .eq("channel", Constants.WEB_CHANNEL);
        groupMenuMapper.update(null, deleteWrapper);
        if (!menuIds.isEmpty()) {
            for (Integer menuId : menuIds) {
                GroupMenu groupMenu = new GroupMenu();
                groupMenu.setGroupId(groupId);
                groupMenu.setMenuId(menuId);
                groupMenu.setChannel(Constants.WEB_CHANNEL);
                groupMenu.setOrganizationId((Integer) currentUserInfo.get("organizationId"));
                groupMenuMapper.insert(groupMenu);
            }
        }
    }
}