对比新文件 |
| | |
| | | package com.gk.firework.Controller; |
| | | |
| | | import com.alibaba.fastjson.JSONObject; |
| | | import com.gk.firework.Domain.PermissionInfo; |
| | | import com.gk.firework.Domain.Utils.Msg; |
| | | import com.gk.firework.Domain.Vo.Menu; |
| | | import com.gk.firework.Service.PermissionService; |
| | | import io.swagger.annotations.*; |
| | | import org.springframework.beans.factory.annotation.Autowired; |
| | | import org.springframework.web.bind.annotation.*; |
| | | |
| | | import java.util.Date; |
| | | import java.util.List; |
| | | |
| | | @Api(tags = "菜单接口") |
| | | @RestController |
| | | public class PermissionController { |
| | | @Autowired |
| | | PermissionService permissionService; |
| | | |
| | | @GetMapping("/permissions") |
| | | @ApiOperation(value = "获取菜单数据", notes = "获取菜单数据", response = Msg.class) |
| | | @ApiImplicitParams({ |
| | | @ApiImplicitParam(paramType="query",name = "userId",value = "用户id",required = true)}) |
| | | public Msg getPermission(@RequestParam String userId){ |
| | | Msg msg = new Msg(); |
| | | msg.setCode("200"); |
| | | msg.setMessage("success"); |
| | | List<Menu> menus = permissionService.selectByUserId(userId); |
| | | msg.setResult(menus); |
| | | |
| | | return msg; |
| | | } |
| | | |
| | | @PostMapping("/addpermissions") |
| | | @ApiOperation(value = "添加菜单", notes = "添加菜单", response = Msg.class) |
| | | @ApiImplicitParams({ |
| | | @ApiImplicitParam(paramType="query",name = "component",value = "接口路径"), |
| | | @ApiImplicitParam(paramType="query",name = "icon",value = "图标"), |
| | | @ApiImplicitParam(paramType="query",name = "level",value = "第几级菜单",required = true), |
| | | @ApiImplicitParam(paramType="query",name = "name",value = "名称",required = true), |
| | | @ApiImplicitParam(paramType="query",name = "parentidId",value = "父级id"), |
| | | @ApiImplicitParam(paramType="query",name = "path",value = "路径"), |
| | | @ApiImplicitParam(paramType="query",name = "sortorder",value = "排序",required = true), |
| | | @ApiImplicitParam(paramType="query",name = "status",value = "状态",required = true), |
| | | @ApiImplicitParam(paramType="query",name = "title",value = "标题"), |
| | | @ApiImplicitParam(paramType="query",name = "type",value = "类型",required = true), |
| | | @ApiImplicitParam(paramType="query",name = "operator",value = "操作人"), |
| | | |
| | | }) |
| | | public Msg addPermission(@ApiParam(value = "component,icon,level,name,parentidId,path,sortorder,status,title,type,operator") |
| | | @RequestBody JSONObject jsonObject){ |
| | | Msg msg = new Msg(); |
| | | msg.setCode("200"); |
| | | msg.setMessage("success"); |
| | | PermissionInfo permissionInfo = new PermissionInfo(); |
| | | permissionInfo.setName(jsonObject.getString("name")); |
| | | permissionInfo.setLevel(jsonObject.getInteger("level")); |
| | | permissionInfo.setTitle(jsonObject.getString("title")); |
| | | permissionInfo.setPath(jsonObject.getString("path")); |
| | | permissionInfo.setComponent(jsonObject.getString("component")); |
| | | permissionInfo.setIcon(jsonObject.getString("icon")); |
| | | permissionInfo.setStatus(jsonObject.getInteger("status")); |
| | | permissionInfo.setSortorder(jsonObject.getDouble("sortorder")); |
| | | permissionInfo.setType(jsonObject.getInteger("type")); |
| | | permissionInfo.setExpand(true); |
| | | permissionInfo.setChecked(false); |
| | | permissionInfo.setSelected(false); |
| | | permissionInfo.setCreatedby(jsonObject.getString("operator")); |
| | | permissionInfo.setCreateddate(new Date()); |
| | | permissionInfo.setLastmodifiedby(jsonObject.getString("operator")); |
| | | permissionInfo.setLastmodifieddate(new Date()); |
| | | permissionInfo.setParentid(jsonObject.getInteger("parentid")); |
| | | |
| | | if (permissionInfo.getParentid() != null) { |
| | | PermissionInfo parentPermission = permissionService.getById(permissionInfo.getParentid()); |
| | | permissionInfo.setLevel(parentPermission.getLevel()+1); |
| | | } |
| | | |
| | | permissionService.save(permissionInfo); |
| | | return msg; |
| | | } |
| | | |
| | | @PostMapping("/putpermissions") |
| | | @ApiOperation(value = "修改菜单", notes = "修改菜单", response = Msg.class) |
| | | @ApiImplicitParams({ |
| | | @ApiImplicitParam(paramType="query",name = "id",value = "id",required = true), |
| | | @ApiImplicitParam(paramType="body",name = "component",value = "接口路径"), |
| | | @ApiImplicitParam(paramType="body",name = "icon",value = "图标"), |
| | | @ApiImplicitParam(paramType="body",name = "level",value = "第几级菜单",required = true), |
| | | @ApiImplicitParam(paramType="body",name = "name",value = "名称",required = true), |
| | | @ApiImplicitParam(paramType="body",name = "parentidId",value = "父级id"), |
| | | @ApiImplicitParam(paramType="body",name = "path",value = "路径"), |
| | | @ApiImplicitParam(paramType="body",name = "sortorder",value = "排序",required = true), |
| | | @ApiImplicitParam(paramType="body",name = "status",value = "状态",required = true), |
| | | @ApiImplicitParam(paramType="body",name = "title",value = "标题"), |
| | | @ApiImplicitParam(paramType="body",name = "type",value = "类型",required = true), |
| | | @ApiImplicitParam(paramType="body",name = "operator",value = "操作人"), |
| | | |
| | | }) |
| | | public Msg editPermission(@ApiParam(value = "component,icon,level,name,parentidId,path,sortorder,status,title,type,operator") |
| | | @RequestBody JSONObject jsonObject){ |
| | | Msg msg = new Msg(); |
| | | msg.setCode("200"); |
| | | msg.setMessage("success"); |
| | | PermissionInfo permissionInfo = new PermissionInfo(); |
| | | permissionInfo.setId(jsonObject.getInteger("id")); |
| | | permissionInfo.setName(jsonObject.getString("name")); |
| | | permissionInfo.setLevel(jsonObject.getInteger("level")); |
| | | permissionInfo.setTitle(jsonObject.getString("title")); |
| | | permissionInfo.setPath(jsonObject.getString("path")); |
| | | permissionInfo.setComponent(jsonObject.getString("component")); |
| | | permissionInfo.setIcon(jsonObject.getString("icon")); |
| | | permissionInfo.setStatus(jsonObject.getInteger("status")); |
| | | permissionInfo.setSortorder(jsonObject.getDouble("sortorder")); |
| | | permissionInfo.setType(jsonObject.getInteger("type")); |
| | | permissionInfo.setExpand(true); |
| | | permissionInfo.setChecked(false); |
| | | permissionInfo.setSelected(false); |
| | | permissionInfo.setCreatedby(jsonObject.getString("operator")); |
| | | permissionInfo.setLastmodifiedby(jsonObject.getString("operator")); |
| | | permissionInfo.setLastmodifieddate(new Date()); |
| | | permissionInfo.setParentid(jsonObject.getInteger("parentid")); |
| | | permissionService.updateById(permissionInfo); |
| | | return msg; |
| | | } |
| | | |
| | | @PostMapping("/delpermissions") |
| | | @ApiOperation(value = "删除菜单", notes = "删除菜单", response = Msg.class) |
| | | @ApiImplicitParams({ |
| | | @ApiImplicitParam(paramType="query",name = "id",value = "id",required = true), |
| | | @ApiImplicitParam(paramType="body",name = "operator",value = "操作人"), |
| | | |
| | | }) |
| | | public Msg delPermission(@ApiParam(value = "id,operator") |
| | | @RequestBody JSONObject jsonObject){ |
| | | Msg msg = new Msg(); |
| | | msg.setCode("200"); |
| | | msg.setMessage("success"); |
| | | PermissionInfo permissionInfo = permissionService.getById(jsonObject.getInteger("id")); |
| | | permissionInfo.setStatus(0); |
| | | permissionService.updateById(permissionInfo); |
| | | return msg; |
| | | } |
| | | |
| | | |
| | | } |