| | |
| | | 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 javax.servlet.http.HttpSession; |
| | | import java.util.Date; |
| | | import java.util.LinkedHashSet; |
| | | import java.util.List; |
| | | |
| | | /** |
| | | * <p> |
| | |
| | | |
| | | @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(@RequestParam String data, HttpServletRequest request) { |
| | | HttpSession session = request.getSession(); |
| | | MenuMapping inserted =menuMappingService.create(data, session); |
| | | 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 { |
| | |
| | | } |
| | | |
| | | @RequestMapping(value = "/update", method = RequestMethod.POST) |
| | | public Result<Object> update(@RequestParam String data) throws Exception { |
| | | boolean updated =menuMappingService.update(data); |
| | | 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(); |
| | | |
| | | String themeId = menuMapping.getThemeId(); |
| | | if (!preParentId.equalsIgnoreCase(themeId)) { |
| | | menu.setParentId(themeId); |
| | | menu.updateById(); |
| | | } |
| | | boolean updated = menuMapping.updateById(); |
| | | if (updated) { |
| | | return Result.success("更新成功", null); |
| | | |
| | | |
| | | |
| | | 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); |
| | | } |
| | |
| | | } |
| | | } |
| | | |
| | | |
| | | |
| | | } |