package com.landtool.lanbase.modules.sys.controller; import io.swagger.annotations.Api; import io.swagger.annotations.ApiOperation; import io.swagger.annotations.ApiParam; import java.util.Date; import java.util.List; import java.util.Map; import org.apache.shiro.SecurityUtils; import org.apache.shiro.authz.annotation.Logical; import org.apache.shiro.authz.annotation.RequiresPermissions; import org.springframework.beans.factory.annotation.Autowired; import org.springframework.util.StringUtils; import org.springframework.web.bind.annotation.GetMapping; import org.springframework.web.bind.annotation.PathVariable; import org.springframework.web.bind.annotation.PostMapping; import org.springframework.web.bind.annotation.RequestBody; import org.springframework.web.bind.annotation.RequestMapping; import org.springframework.web.bind.annotation.RequestMethod; import org.springframework.web.bind.annotation.RequestParam; import org.springframework.web.bind.annotation.RestController; import com.landtool.lanbase.modules.sys.entity.SysResource; import com.landtool.lanbase.modules.org.entity.OrgUser; import com.landtool.lanbase.modules.sys.service.SysResourceService; import com.landtool.lanbase.common.annotation.LogAction; import com.landtool.lanbase.common.utils.PageUtils; import com.landtool.lanbase.common.utils.Query; import com.landtool.lanbase.common.utils.Result; /** * @author lanbase * @Description: TODO(8系统权限资源管理表) * @date 2018-01-16 08:57:26 */ @RestController @RequestMapping("/sys/resource") @Api(value = "", tags = {"系统权限资源管理"}) public class SysResourceController extends AbstractController{ @Autowired private SysResourceService resourceService; /** * 列表 */ @RequestMapping(value ="/list", method ={RequestMethod.POST, RequestMethod.GET}) // @RequiresPermissions("sys:resource:list") @RequiresPermissions(value = {"sys:resource:list","sys:resource:edit"}, logical = Logical.OR) @ApiOperation( value = "系统权限资源管理列表", notes = "" ) @LogAction("平台管理,权限标识,权限标识查询,查询") public Result list(@ApiParam(name="params",value="系统权限资源管理",required=true)@RequestParam Map params){ //查询列表数据 Query query = new Query(params); List resourceList = resourceService.queryList(query); int total = resourceService.queryTotal(query); PageUtils pageUtil = new PageUtils(resourceList, total, query.getLimit(), query.getPage()); return Result.ok().put("page", pageUtil); } /** * 信息 */ @GetMapping("/info/{resourceid}") // @RequiresPermissions("sys:resource:list") @RequiresPermissions(value = {"sys:resource:list","sys:resource:edit"}, logical = Logical.OR) @ApiOperation( value = "权限资源信息列表", notes = "" ) public Result info(@ApiParam(name="resourceid",value="权限资源Id",required=true)@PathVariable("resourceid") Long resourceid){ SysResource resource = resourceService.queryObject(resourceid); return Result.ok().put("resource", resource); } /** * 保存 */ @LogAction("平台管理,权限标识,权限标识新增,新增") @PostMapping("/save") @RequiresPermissions("sys:resource:edit") @ApiOperation( value = "保存权限资源信息", notes = "" ) public Result save(@ApiParam(name="权限资源信息对象",value="传入json格式",required=true)@RequestBody SysResource resource){ if(resource.getResourcername() == null || resource.getResourcername() .length() == 0 || resource.getResourcercode() == null || resource.getResourcercode().length() == 0){ return Result.error("保存失败,存在特殊字符,请重新输入!"); } //资源名称是否重复 SysResource info = resourceService.queryObjectByName(resource.getAppid(), resource.getResourcername()); if(info != null){ return Result.error("所属系统已存在该资源名称!"); } Long userid =((OrgUser) SecurityUtils.getSubject().getPrincipal()).getUserid(); resource.setRcreateuser(userid); resource.setRcreatedate(new Date()); resourceService.save(resource); //保存后获取自增id int resourceid = resourceService.querySysResourceWithSEQ(); return Result.ok().put("resourceid",resourceid); } /** * 修改 */ @LogAction("平台管理,权限标识,权限标识修改,修改") @PostMapping("/update") @RequiresPermissions("sys:resource:edit") @ApiOperation( value = "修改权限资源信息", notes = "" ) public Result update(@ApiParam(name="权限资源信息对象",value="传入json格式",required=true)@RequestBody SysResource resource){ if(resource.getResourcername() == null || resource.getResourcername() .length() == 0 || resource.getResourcercode() == null || resource.getResourcercode().length() == 0){ return Result.error("保存失败,存在特殊字符,请重新输入!"); } //资源名称是否重复 SysResource info = resourceService.queryObjectByName(resource.getAppid(), resource.getResourcername()); if(info != null && !info.getResourceid().equals(resource.getResourceid())){ return Result.error("所属系统已存在该资源名称!"); } resourceService.update(resource); return Result.ok(); } /** * 删除 */ @LogAction("平台管理,权限标识,权限标识删除,删除") @PostMapping("/delete") @RequiresPermissions("sys:resource:edit") @ApiOperation( value = "删除权限资源信息", notes = "" ) public Result delete(@ApiParam(name="resourceids",value="权限资源信息Id",required=true)@RequestBody Long[] resourceids){ resourceService.deleteBatch(resourceids); return Result.ok(); } }