|  |  |  | 
|---|
|  |  |  | package com.moral.api.controller; | 
|---|
|  |  |  |  | 
|---|
|  |  |  | import com.moral.api.pojo.vo.menu.MenuQueryVO; | 
|---|
|  |  |  | import com.moral.api.pojo.vo.menu.MenuVO; | 
|---|
|  |  |  | import com.moral.api.pojo.dto.menu.MenuDTO; | 
|---|
|  |  |  | import com.moral.api.pojo.dto.menu.MenuQueryNamesDTO; | 
|---|
|  |  |  | import com.moral.api.pojo.dto.menu.MenuQueryDTO; | 
|---|
|  |  |  | import com.moral.api.pojo.form.menu.MenuDeleteForm; | 
|---|
|  |  |  | import com.moral.api.pojo.form.menu.MenuInsertForm; | 
|---|
|  |  |  | import com.moral.api.pojo.form.menu.MenuQueryNamesForm; | 
|---|
|  |  |  | import com.moral.api.pojo.form.menu.MenuUpdateForm; | 
|---|
|  |  |  | import com.moral.api.pojo.vo.menu.*; | 
|---|
|  |  |  | import com.moral.api.service.MenuService; | 
|---|
|  |  |  | import com.moral.constant.ResponseCodeEnum; | 
|---|
|  |  |  | import com.moral.constant.ResultMessage; | 
|---|
|  |  |  | import io.swagger.annotations.Api; | 
|---|
|  |  |  | import lombok.extern.slf4j.Slf4j; | 
|---|
|  |  |  | import org.springframework.web.bind.annotation.CrossOrigin; | 
|---|
|  |  |  | import org.springframework.web.bind.annotation.GetMapping; | 
|---|
|  |  |  | import org.springframework.web.bind.annotation.RequestMapping; | 
|---|
|  |  |  | import org.springframework.web.bind.annotation.RestController; | 
|---|
|  |  |  | import org.springframework.beans.factory.annotation.Autowired; | 
|---|
|  |  |  | import org.springframework.util.ObjectUtils; | 
|---|
|  |  |  | import org.springframework.web.bind.annotation.*; | 
|---|
|  |  |  |  | 
|---|
|  |  |  | /** | 
|---|
|  |  |  | * @ClassName MenuController | 
|---|
|  |  |  | 
|---|
|  |  |  | @RestController | 
|---|
|  |  |  | @RequestMapping("/menu") | 
|---|
|  |  |  | public class MenuController { | 
|---|
|  |  |  | @GetMapping("queryMock") | 
|---|
|  |  |  | public ResultMessage queryMock(){ | 
|---|
|  |  |  |  | 
|---|
|  |  |  | return null; | 
|---|
|  |  |  | @Autowired | 
|---|
|  |  |  | MenuService menuService; | 
|---|
|  |  |  |  | 
|---|
|  |  |  | @GetMapping("query") | 
|---|
|  |  |  | public ResultMessage query() { | 
|---|
|  |  |  |  | 
|---|
|  |  |  | //查询组织admin角色的所有菜单,非父子结构 | 
|---|
|  |  |  | MenuQueryDTO dto = menuService.queryAllMenus(); | 
|---|
|  |  |  |  | 
|---|
|  |  |  | //转换为前端所需参数 | 
|---|
|  |  |  | MenuQueryVO vo = MenuQueryVO.convert(dto); | 
|---|
|  |  |  |  | 
|---|
|  |  |  | return new ResultMessage(dto.getCode(), dto.getMsg(), vo); | 
|---|
|  |  |  | } | 
|---|
|  |  |  |  | 
|---|
|  |  |  | @GetMapping("queryAdmin") | 
|---|
|  |  |  | public ResultMessage queryAdmin(@RequestParam Integer organizationId) { | 
|---|
|  |  |  |  | 
|---|
|  |  |  | //执行查询业务 | 
|---|
|  |  |  | MenuQueryDTO dto = menuService.queryAdminGroupMenusByOrganizationId(organizationId); | 
|---|
|  |  |  |  | 
|---|
|  |  |  | //转换为前端所需参数 | 
|---|
|  |  |  | MenuQueryVO vo = MenuQueryVO.convert(dto); | 
|---|
|  |  |  |  | 
|---|
|  |  |  | return new ResultMessage(dto.getCode(), dto.getMsg(), vo); | 
|---|
|  |  |  | } | 
|---|
|  |  |  |  | 
|---|
|  |  |  | @GetMapping("queryNames") | 
|---|
|  |  |  | public ResultMessage queryNames(MenuQueryNamesForm form) { | 
|---|
|  |  |  | //处理查询业务 | 
|---|
|  |  |  | MenuQueryNamesDTO dto = menuService.queryNames(form); | 
|---|
|  |  |  |  | 
|---|
|  |  |  | //转换前端所需参数 | 
|---|
|  |  |  | MenuQueryNamesVO vo = MenuQueryNamesVO.convert(dto); | 
|---|
|  |  |  |  | 
|---|
|  |  |  | return new ResultMessage(dto.getCode(), dto.getMsg(), vo); | 
|---|
|  |  |  | } | 
|---|
|  |  |  |  | 
|---|
|  |  |  | @PostMapping("insert") | 
|---|
|  |  |  | public ResultMessage insert(@RequestBody MenuInsertForm form) { | 
|---|
|  |  |  | //判断是否缺少参数 | 
|---|
|  |  |  | if (!form.valid()) | 
|---|
|  |  |  | return ResultMessage.fail(ResponseCodeEnum.PARAMETERS_IS_MISSING.getCode(), | 
|---|
|  |  |  | ResponseCodeEnum.PARAMETERS_IS_MISSING.getMsg()); | 
|---|
|  |  |  |  | 
|---|
|  |  |  | //处理插入业务 | 
|---|
|  |  |  | MenuDTO dto = menuService.insertMenu(form); | 
|---|
|  |  |  |  | 
|---|
|  |  |  | return new ResultMessage(dto.getCode(), dto.getMsg(),null); | 
|---|
|  |  |  | } | 
|---|
|  |  |  |  | 
|---|
|  |  |  | @PostMapping("delete") | 
|---|
|  |  |  | public ResultMessage delete(@RequestBody MenuDeleteForm form) { | 
|---|
|  |  |  | //判断是否缺少参数 | 
|---|
|  |  |  | if (!form.valid()) | 
|---|
|  |  |  | return ResultMessage.fail(ResponseCodeEnum.PARAMETERS_IS_MISSING.getCode(), | 
|---|
|  |  |  | ResponseCodeEnum.PARAMETERS_IS_MISSING.getMsg()); | 
|---|
|  |  |  |  | 
|---|
|  |  |  | //处理删除业务 | 
|---|
|  |  |  | MenuDTO dto = menuService.deleteMenu(form); | 
|---|
|  |  |  |  | 
|---|
|  |  |  | //转换前端所需参数 | 
|---|
|  |  |  | MenuInsertVO vo = MenuDeleteVO.convert(dto); | 
|---|
|  |  |  |  | 
|---|
|  |  |  | return new ResultMessage(dto.getCode(), dto.getMsg(), vo); | 
|---|
|  |  |  | } | 
|---|
|  |  |  |  | 
|---|
|  |  |  | @PostMapping("update") | 
|---|
|  |  |  | public ResultMessage update(@RequestBody MenuUpdateForm form) { | 
|---|
|  |  |  | //判断是否缺少参数 | 
|---|
|  |  |  | if (!form.valid()) | 
|---|
|  |  |  | return ResultMessage.fail(ResponseCodeEnum.PARAMETERS_IS_MISSING.getCode(), | 
|---|
|  |  |  | ResponseCodeEnum.PARAMETERS_IS_MISSING.getMsg()); | 
|---|
|  |  |  |  | 
|---|
|  |  |  | //处理更新业务 | 
|---|
|  |  |  | MenuDTO dto = menuService.updateMenu(form); | 
|---|
|  |  |  |  | 
|---|
|  |  |  | //转换前端所需参数 | 
|---|
|  |  |  | MenuUpdateVO vo = MenuUpdateVO.convert(dto); | 
|---|
|  |  |  |  | 
|---|
|  |  |  | return new ResultMessage(dto.getCode(), dto.getMsg(), vo); | 
|---|
|  |  |  | } | 
|---|
|  |  |  |  | 
|---|
|  |  |  | } | 
|---|