kimi
2020-05-23 82fbbf24939e150ee3cef90dc0dd843c9897a7e6
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
package com.highdatas.mdm.controller;
 
 
import com.baomidou.mybatisplus.mapper.EntityWrapper;
import com.highdatas.mdm.entity.MenuMapping;
import com.highdatas.mdm.entity.SysMenu;
import com.highdatas.mdm.entity.TUser;
import com.highdatas.mdm.pojo.CodeMsg;
import com.highdatas.mdm.pojo.Result;
import com.highdatas.mdm.service.IMaintainDetailService;
import com.highdatas.mdm.service.IMaintainService;
import com.highdatas.mdm.service.IMenuMappingService;
import com.highdatas.mdm.service.ISysMenuService;
import com.highdatas.mdm.util.DbUtils;
import com.highdatas.mdm.util.NoticeClient;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;
 
import javax.servlet.http.HttpServletRequest;
import java.util.Date;
import java.util.LinkedHashSet;
import java.util.List;
 
/**
 * <p>
 *  前端控制器
 * </p>
 *
 * @author kimi
 * @since 2019-12-16
 */
@RestController
@RequestMapping("/menuMapping")
public class MenuMappingController {
 
    @Autowired
    IMenuMappingService menuMappingService;
 
    @Autowired
    IMaintainService maintainService;
 
    @Autowired
    IMaintainDetailService maintainDetailService;
    @Autowired
    ISysMenuService menuService;
    @Autowired
    NoticeClient noticeClient;
 
    @RequestMapping(value = "/get/{id}",  method = RequestMethod.GET)
    public Result<MenuMapping> get(@PathVariable String id, HttpServletRequest request) {
        return menuMappingService.getMapping(request.getSession(),id);
    }
 
 
    @RequestMapping(value = "/add", method = RequestMethod.POST)
    public Result<Object> insert(@RequestBody MenuMapping menuMapping, HttpServletRequest request) {
        String menuId = menuMapping.getMenuId();
        int cnt = menuMappingService.selectCount(new EntityWrapper<MenuMapping>().eq("menu_id", menuId));
        if (cnt != 0)  {
           menuMapping.updateById();
        }
        MenuMapping inserted = menuMappingService.create(menuMapping);
        if (inserted != null) {
            return  Result.success(inserted);
        } else {
            return Result.error(CodeMsg.INSERT_ERROR);
        }
 
    }
 
    @RequestMapping(value = "/update", method = RequestMethod.POST)
    public Result<Object> update(@RequestBody MenuMapping menuMapping, HttpServletRequest request) {
        menuMapping.setUpdateTime(new Date());
        String menuId = menuMapping.getMenuId();
        SysMenu menu = menuService.selectById(menuId);
        String preParentId = menu.getParentId();
        menu.setName(menuMapping.getName()).updateById();
        String themeId = menuMapping.getThemeId();
//        if (!preParentId.equalsIgnoreCase(themeId)) {
////            menu.setParentId(themeId);
////            menu.updateById();
////        }
        boolean updated = menuMapping.updateById();
        if (updated) {
            TUser user = DbUtils.getUser(request);
            if (menu != null) {
                LinkedHashSet<String> parentIdSet = new LinkedHashSet<>();
                parentIdSet.add(menuId);
                LinkedHashSet<String> byParentId = menuService.getByParentId(parentIdSet);
                if (byParentId == null) {
                    noticeClient.EditMenuMapping(menu, null, user.getUserId());
                } else {
                    if (!byParentId.isEmpty()) {
                        List<SysMenu> sysMenus = menuService.selectBatchIds(byParentId);
                        SysMenu parentMenu = sysMenus.get(0);
                        noticeClient.EditMenuMapping(menu, parentMenu, user.getUserId());
                    }
 
                }
            }
 
            return  Result.success(menuMapping);
        } else {
            return Result.error(CodeMsg.UPDATE_ERROR);
        }
    }
 
    @RequestMapping(value = "/delete/{menuid}", method = RequestMethod.GET)
    public Result<Object> delete(@PathVariable String menuid) throws Exception {
        boolean deleted = menuMappingService.deleteById(menuid);
        if (deleted) {
            return  Result.success("删除成功", null);
        } else {
            return Result.error(CodeMsg.DELETE_ERROR);
        }
    }
 
 
 
}