lizijie
2021-03-18 0fd4853ab2cf6e8ff6775803f80c4970c484a529
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
package com.moral.api.service.impl;
 
import com.moral.api.entity.ManageMenu;
import com.moral.api.mapper.ManageMenuMapper;
import com.moral.api.mapper.ManageRoleMenuMapper;
import com.moral.api.service.ManageMenuService;
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
import org.springframework.transaction.annotation.Transactional;
 
import javax.annotation.Resource;
import java.util.HashMap;
import java.util.Map;
 
/**
 * <p>
 * 后台菜单 服务实现类
 * </p>
 *
 * @author moral
 * @since 2021-03-09
 */
@Service
public class ManageMenuServiceImpl extends ServiceImpl<ManageMenuMapper, ManageMenu> implements ManageMenuService {
 
    @Autowired(required = false)
    private ManageMenuMapper manageMenuMapper;
 
    @Autowired(required = false)
    private ManageRoleMenuMapper manageRoleMenuMapper;
 
    @Override
    @Transactional
    public Map<String,Object> insertManageMenu(ManageMenu manageMenu) {
        Map<String,Object> resultMap = new HashMap<>();
        if (manageMenu.getName()==null){
            resultMap.put("flag",false);
            resultMap.put("msg","名称为空!");
            return resultMap;
        }
        if (manageMenuMapper.getManageMenuByName(manageMenu.getName()) != null){
            resultMap.put("flag",false);
            resultMap.put("msg","该菜单已存在!");
        }else {
            manageMenuMapper.insertOne(manageMenu);
            resultMap.put("flag",true);
            resultMap.put("msg","添加成功!");
        }
        return resultMap;
    }
 
    @Override
    @Transactional
    public Map<String,Object> updateManageMenu(Map map) {
        Map<String,Object> resultMap = new HashMap<>();
        if (!map.containsKey("id")){
            resultMap.put("flag",false);
            resultMap.put("msg","未选择更新目标!");
            return resultMap;
        }
        if (manageMenuMapper.getManageMenuById(Integer.parseInt(map.get("id").toString())) == null){
            resultMap.put("flag",false);
            resultMap.put("msg","该菜单不存在!");
        }else {
            manageMenuMapper.updateManageMenuById(map);
            resultMap.put("flag",true);
            resultMap.put("msg","更新成功!");
        }
        return resultMap;
    }
 
    @Override
    @Transactional
    public Map<String, Object> deleteManageMenu(Map map) {
        Map<String,Object> resultMap = new HashMap<>();
        if (!map.containsKey("id")){
            resultMap.put("flag",false);
            resultMap.put("msg","未选择删除目标!");
            return resultMap;
        }
        if (manageMenuMapper.getManageMenuById(Integer.parseInt(map.get("id").toString())) == null){
            resultMap.put("flag",false);
            resultMap.put("msg","该角色不存在或已被删除!");
        }else {
            Map deleteMap = new HashMap();
            int id = Integer.parseInt(map.get("id").toString());
            deleteMap.put("id",id);
            deleteMap.put("is_delete",1);
            manageMenuMapper.updateManageMenuById(deleteMap);
            Map role_menuDeleteMap = new HashMap();
            role_menuDeleteMap.put("menu_id",id);
            manageRoleMenuMapper.updateDeleteStateByMenu_id(role_menuDeleteMap);
            resultMap.put("flag",true);
            resultMap.put("msg","删除成功!");
        }
        return resultMap;
    }
}