diff --git a/renren-admin/src/main/java/io/renren/modules/sys/controller/SysDeptController.java b/renren-admin/src/main/java/io/renren/modules/sys/controller/SysDeptController.java index 9968920a..2748b040 100644 --- a/renren-admin/src/main/java/io/renren/modules/sys/controller/SysDeptController.java +++ b/renren-admin/src/main/java/io/renren/modules/sys/controller/SysDeptController.java @@ -7,113 +7,119 @@ import io.renren.common.validator.ValidatorUtils; import io.renren.common.validator.group.AddGroup; import io.renren.common.validator.group.DefaultGroup; import io.renren.common.validator.group.UpdateGroup; -import io.renren.modules.security.user.SecurityUser; -import io.renren.modules.security.user.UserDetail; import io.renren.modules.sys.dto.SysDeptDTO; import io.renren.modules.sys.service.SysDeptService; import io.swagger.annotations.Api; import io.swagger.annotations.ApiOperation; -import org.apache.commons.lang3.StringUtils; -import org.apache.shiro.authz.annotation.RequiresPermissions; import org.springframework.beans.factory.annotation.Autowired; -import org.springframework.beans.factory.annotation.Value; import org.springframework.jdbc.core.JdbcTemplate; import org.springframework.util.CollectionUtils; import org.springframework.web.bind.annotation.*; -import java.util.*; -import java.util.concurrent.CopyOnWriteArrayList; +import java.util.HashMap; +import java.util.Iterator; +import java.util.List; +import java.util.Map; /** * 部门管理 - * */ @RestController @RequestMapping("/sys/dept") -@Api(tags="部门管理") +@Api(tags = "部门管理") public class SysDeptController { - @Autowired - private SysDeptService sysDeptService; - @Autowired - private JdbcTemplate jdbcTemplate; + @Autowired + private SysDeptService sysDeptService; + @Autowired + private JdbcTemplate jdbcTemplate; - @GetMapping("list") - @ApiOperation("查询部门列表") - @LogOperation("查询部门列表") + @GetMapping("list") + @ApiOperation("查询部门列表") + @LogOperation("查询部门列表") // @RequiresPermissions("sys:dept:list") - public Result> list(){ - List list = sysDeptService.list(new HashMap<>(1)); + public Result> list() { + List list = sysDeptService.list(new HashMap<>(1)); - return new Result>().ok(list); - } + return new Result>().ok(list); + } - @GetMapping("{id}") - @ApiOperation("查询部门详细信息") - @LogOperation("查询部门详细信息") + @GetMapping("all") + @ApiOperation("查询所有部门列表") + @LogOperation("查询所有部门列表") +// @RequiresPermissions("sys:dept:list") + public Result>> all() { + List> list = jdbcTemplate.queryForList("SELECT id,`name` FROM sys_dept;"); + + return new Result>>().ok(list); + } + + @GetMapping("{id}") + @ApiOperation("查询部门详细信息") + @LogOperation("查询部门详细信息") // @RequiresPermissions("sys:dept:info") - public Result get(@PathVariable("id") Long id){ - SysDeptDTO data = sysDeptService.get(id); + public Result get(@PathVariable("id") Long id) { + SysDeptDTO data = sysDeptService.get(id); - return new Result().ok(data); - } + return new Result().ok(data); + } - @PostMapping - @ApiOperation("新增部门") - @LogOperation("新增部门") + @PostMapping + @ApiOperation("新增部门") + @LogOperation("新增部门") // @RequiresPermissions("sys:dept:save") - public Result save(@RequestBody SysDeptDTO dto){ - //效验数据 - ValidatorUtils.validateEntity(dto, AddGroup.class, DefaultGroup.class); + public Result save(@RequestBody SysDeptDTO dto) { + //效验数据 + ValidatorUtils.validateEntity(dto, AddGroup.class, DefaultGroup.class); - sysDeptService.save(dto); + sysDeptService.save(dto); - return new Result(); - } + return new Result(); + } - @PutMapping - @ApiOperation("修改部门信息") - @LogOperation("修改部门信息") + @PutMapping + @ApiOperation("修改部门信息") + @LogOperation("修改部门信息") // @RequiresPermissions("sys:dept:update") - public Result update(@RequestBody SysDeptDTO dto){ - //效验数据 - ValidatorUtils.validateEntity(dto, UpdateGroup.class, DefaultGroup.class); + public Result update(@RequestBody SysDeptDTO dto) { + //效验数据 + ValidatorUtils.validateEntity(dto, UpdateGroup.class, DefaultGroup.class); - sysDeptService.update(dto); + sysDeptService.update(dto); - return new Result(); - } + return new Result(); + } - @DeleteMapping("{id}") - @ApiOperation("删除部门") - @LogOperation("删除部门") + @DeleteMapping("{id}") + @ApiOperation("删除部门") + @LogOperation("删除部门") // @RequiresPermissions("sys:dept:delete") - public Result delete(@PathVariable("id") Long id){ - //效验数据 - AssertUtils.isNull(id, "id"); + public Result delete(@PathVariable("id") Long id) { + //效验数据 + AssertUtils.isNull(id, "id"); - sysDeptService.delete(id); + sysDeptService.delete(id); - return new Result(); - } + return new Result(); + } - private void treeMatch(List anyLevelCategoryList, String keyword) { - Iterator iter = anyLevelCategoryList.iterator(); - while (iter.hasNext()) { - // 获取当前遍历到的目录 - SysDeptDTO category = iter.next(); - // 如果当前目录名称包含关键字,则什么也不做(不移除),否则就看下一级 - if (!category.getName().contains(keyword)) { - // 取出下一级目录集合 - List childrenCategoryList = category.getChildren(); - // 递归 - if (!CollectionUtils.isEmpty(childrenCategoryList)) { - treeMatch(childrenCategoryList, keyword); - } - // 下一级目录看完了,如果下一级目录全部被移除,则移除当前目录 - if (CollectionUtils.isEmpty(category.getChildren())) { - iter.remove(); - } - } - } - } + private void treeMatch(List anyLevelCategoryList, String keyword) { + Iterator iter = anyLevelCategoryList.iterator(); + while (iter.hasNext()) { + // 获取当前遍历到的目录 + SysDeptDTO category = iter.next(); + // 如果当前目录名称包含关键字,则什么也不做(不移除),否则就看下一级 + if (!category.getName().contains(keyword)) { + // 取出下一级目录集合 + List childrenCategoryList = category.getChildren(); + // 递归 + if (!CollectionUtils.isEmpty(childrenCategoryList)) { + treeMatch(childrenCategoryList, keyword); + } + // 下一级目录看完了,如果下一级目录全部被移除,则移除当前目录 + if (CollectionUtils.isEmpty(category.getChildren())) { + iter.remove(); + } + } + } + } } \ No newline at end of file