lizijie
2021-03-17 4c7495d646028e45c14af403e25c785d44e5dbe5
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
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
package com.moral.api.service.impl;
 
import com.moral.api.entity.ManageMenu;
import com.moral.api.entity.ManageRole;
import com.moral.api.mapper.ManageRoleMapper;
import com.moral.api.mapper.ManageRoleMenuMapper;
import com.moral.api.service.ManageRoleService;
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import org.springframework.stereotype.Service;
import org.springframework.transaction.annotation.Transactional;
import org.springframework.util.StringUtils;
 
import javax.annotation.Resource;
import java.util.ArrayList;
import java.util.HashMap;
import java.util.List;
import java.util.Map;
 
/**
 * <p>
 * 后台角色表 服务实现类
 * </p>
 *
 * @author moral
 * @since 2021-03-09
 */
@Service
public class ManageRoleServiceImpl extends ServiceImpl<ManageRoleMapper, ManageRole> implements ManageRoleService {
 
    @Resource
    ManageRoleMapper roleMapper;
 
    public ManageRole getManageRoleByAccountId(String accountId){
        if(StringUtils.isEmpty(accountId))
            return null;
        return null;
    }
 
    @Resource
    private ManageRoleMapper manageRoleMapper;
 
    @Resource
    private ManageRoleMenuMapper manageRoleMenuMapper;
 
    @Override
    @Transactional
    public List<ManageRole> getAll() {
        return manageRoleMapper.getAll();
    }
 
    @Override
    @Transactional
    public Map<String,Object> insertOne(ManageRole manageRole,List list) {
        Map<String,Object> resultMap = new HashMap<>();
        if (manageRole.getName()==null){
            resultMap.put("flag",false);
            resultMap.put("msg","名称为空!");
            return resultMap;
        }
        if (manageRoleMapper.getManageRoleByName(manageRole.getName()) != null){
            resultMap.put("flag",false);
            resultMap.put("msg","该角色已存在!");
        }else {
            manageRoleMapper.insertOne(manageRole);
            resultMap.put("flag",true);
            resultMap.put("msg","添加成功!");
        }
        boolean flag = Boolean.parseBoolean(resultMap.get("flag").toString());
        if (flag){
            ManageRole manageRoleIns = manageRoleMapper.getManageRoleByName(manageRole.getName());
            int role_id = manageRoleIns.getId();
            System.out.println(role_id);
            List insertList = new ArrayList();
            for (Object temp: list) {
                Map<String,Integer> insertMap = new HashMap<>();
                insertMap.put("role_id",role_id);
                insertMap.put("menu_id",Integer.parseInt(temp.toString()));
                insertList.add(insertMap);
            }
            System.out.println(insertList);
            manageRoleMenuMapper.insertBatch(insertList);
        }
        return resultMap;
    }
 
    @Override
    @Transactional
    public Map<String,Object> updateManageRole(Map map) {
        Map<String,Object> resultMap = new HashMap<>();
        if (!map.containsKey("id")){
            resultMap.put("flag",false);
            resultMap.put("msg","未选择更新目标!");
            return resultMap;
        }
        if (manageRoleMapper.getManageRoleById(Integer.parseInt(map.get("id").toString())) == null){
            resultMap.put("flag",false);
            resultMap.put("msg","该角色不存在!");
        }else {
            manageRoleMapper.updateManageRoleById(map);
            resultMap.put("flag",true);
            resultMap.put("msg","更新成功!");
        }
        return resultMap;
    }
 
    @Override
    @Transactional
    public List<ManageRole> getManageRoleByNameFuzzy(ManageRole manageRole) {
        return manageRoleMapper.getManageRoleByNameFuzzy(manageRole);
    }
 
    @Override
    public Map<String, Object> deleteManageRole(Map map) {
        Map<String,Object> resultMap = new HashMap<>();
        if (!map.containsKey("id")){
            resultMap.put("flag",false);
            resultMap.put("msg","未选择删除目标!");
            return resultMap;
        }
        if (manageRoleMapper.getManageRoleById(Integer.parseInt(map.get("id").toString())) == null){
            resultMap.put("flag",false);
            resultMap.put("msg","该角色不存在或已被删除!");
        }else {
            ManageRole manageRole = new ManageRole();
            manageRole.setId(Integer.parseInt(map.get("id").toString()));
            manageRole.setIsDelete("1");
            Map deleteMap = new HashMap();
            deleteMap.put("id",Integer.parseInt(map.get("id").toString()));
            deleteMap.put("is_delete",1);
            manageRoleMapper.updateManageRoleById(deleteMap);
            resultMap.put("flag",true);
            resultMap.put("msg","删除成功!");
        }
        return resultMap;
    }
}