fix
Helius
2021-12-08 2ff788504ed25ed15d75047afb16f058b655eeb6
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
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
package com.xzx.gc.role.service;
 
 
import com.github.pagehelper.PageHelper;
import com.github.pagehelper.PageInfo;
import com.xzx.gc.entity.*;
import com.xzx.gc.model.RoleDataAccessFunction;
import com.xzx.gc.model.admin.CoreFunctionModel;
import com.xzx.gc.model.admin.MoneyModel;
import com.xzx.gc.model.dto.LazyEntity;
import com.xzx.gc.model.query.FunctionQuery;
import com.xzx.gc.role.mapper.CoreMenuMapper;
import com.xzx.gc.role.mapper.CoreRoleMenuMapper;
import com.xzx.gc.role.mapper.RoleFunctionConsoleMapper;
import com.xzx.gc.role.rbac.tree.FunctionItem;
 
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
import org.springframework.transaction.annotation.Transactional;
import tk.mybatis.mapper.entity.Example;
 
import java.util.*;
 
/**
 * @author lijiazhi
 *
 */
@Service
@Transactional
public class FunctionConsoleService{
 
    @Autowired
    RoleFunctionConsoleMapper roleFunctionConsoleDao;
    @Autowired
    CoreRoleMenuMapper sysRoleMenuDao;
    @Autowired
    CorePlatformService platformService;
    /**
     * 得到角色对应的所有功能点
     * @param roleId
     * @return
     */
    public List<Long> getFunctionByRole(Long roleId){
        return roleFunctionConsoleDao.getFunctionIdByRole(roleId);
    }
 
    public void updateSysRoleFunction(Long roleId,List<Long> adds,List<Long> dels){
        for(Long del:dels){
 
            //同时,需要删除与此功能关联的菜单
            CoreRoleMenu sysRoleMenu = querySysRoleMenu(roleId,del);
            if(sysRoleMenu!=null){
                sysRoleMenuDao.deleteByPrimaryKey(sysRoleMenu.getId());
            }
        }
        List<CoreRoleMenu> sysRoleMenuList = querySysRoleMenuList(roleId);
        for (CoreRoleMenu menu:sysRoleMenuList) {
            sysRoleMenuDao.deleteByPrimaryKey(menu.getId());
        }
        for(Long add:adds){
            //同时,需要增加菜单
            CoreRoleMenu roleMenu = new CoreRoleMenu();
            roleMenu.setMenuId(add);
            roleMenu.setRoleId(roleId);
            sysRoleMenuDao.insert(roleMenu);
        }
        //}
 
        //清楚缓存
        platformService.clearFunctionCache();
 
    }
 
    private CoreRoleMenu querySysRoleMenu(Long roleId,Long menuId){
        Example example = new Example(CoreRoleMenu.class);
        Example.Criteria criteria = example.createCriteria();
        criteria.andEqualTo("menuId",menuId);
        criteria.andEqualTo("roleId",roleId);
       /* CoreRoleMenu query= new CoreRoleMenu();
        query.setMenuId(menuId);
        query.setRoleId(roleId);*/
        List<CoreRoleMenu> menus = sysRoleMenuDao.selectByExample(example);
        return menus.isEmpty()?null:menus.get(0);
    }
 
    private List<CoreRoleMenu> querySysRoleMenuList(Long roleId){
        Example example = new Example(CoreRoleMenu.class);
        Example.Criteria criteria = example.createCriteria();
        criteria.andEqualTo("roleId",roleId);
        List<CoreRoleMenu> menus = sysRoleMenuDao.selectByExample(example);
        return menus;
    }
 
    public List<Long> getFunctionByRoleMenu(Long roleId){
        return roleFunctionConsoleDao.getFunctionByRoleMenu(roleId);
    }
 
}