diff --git a/youlai-admin/src/main/java/com/youlai/admin/common/AdminConstant.java b/youlai-admin/src/main/java/com/youlai/admin/common/AdminConstant.java new file mode 100644 index 000000000..ea8eee3f5 --- /dev/null +++ b/youlai-admin/src/main/java/com/youlai/admin/common/AdminConstant.java @@ -0,0 +1,10 @@ +package com.youlai.admin.common; + +/** + * 平台服务常量 + */ +public interface AdminConstant { + + int ROOT_DEPT_ID = 0; + +} diff --git a/youlai-admin/src/main/java/com/youlai/admin/component/ResourceRoleRulesHolder.java b/youlai-admin/src/main/java/com/youlai/admin/component/ResourceRoleRulesHolder.java index 1ccc6200f..41d8d0be1 100644 --- a/youlai-admin/src/main/java/com/youlai/admin/component/ResourceRoleRulesHolder.java +++ b/youlai-admin/src/main/java/com/youlai/admin/component/ResourceRoleRulesHolder.java @@ -23,7 +23,7 @@ public class ResourceRoleRulesHolder { Map> resourceRoleMap = new TreeMap<>(); List roleNames = new ArrayList<>(); roleNames.add(AuthConstant.AUTHORITY_PREFIX + "1_root"); - resourceRoleMap.put("/youlai-admin/users/**", roleNames); + resourceRoleMap.put("/youlai-admin/**", roleNames); redisTemplate.delete(AuthConstant.RESOURCE_ROLES_MAP_KEY); redisTemplate.opsForHash().putAll(AuthConstant.RESOURCE_ROLES_MAP_KEY, resourceRoleMap); } diff --git a/youlai-admin/src/main/java/com/youlai/admin/controller/SysDeptController.java b/youlai-admin/src/main/java/com/youlai/admin/controller/SysDeptController.java index d568d211e..d00d2beab 100644 --- a/youlai-admin/src/main/java/com/youlai/admin/controller/SysDeptController.java +++ b/youlai-admin/src/main/java/com/youlai/admin/controller/SysDeptController.java @@ -2,10 +2,8 @@ package com.youlai.admin.controller; import cn.hutool.core.util.StrUtil; import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper; -import com.baomidou.mybatisplus.extension.plugins.pagination.Page; import com.youlai.admin.entity.SysDept; import com.youlai.admin.service.ISysDeptService; -import com.youlai.common.result.PageResult; import com.youlai.common.result.Result; import io.swagger.annotations.Api; import io.swagger.annotations.ApiImplicitParam; @@ -15,7 +13,6 @@ import lombok.extern.slf4j.Slf4j; import org.springframework.beans.factory.annotation.Autowired; import org.springframework.web.bind.annotation.*; -import java.util.Date; import java.util.List; @Api(tags = "部门接口") @@ -29,32 +26,36 @@ public class SysDeptController { @ApiOperation(value = "列表分页", httpMethod = "GET") @ApiImplicitParams({ - @ApiImplicitParam(name = "page", value = "页码", paramType = "query", dataType = "Integer"), - @ApiImplicitParam(name = "limit", value = "每页数量", paramType = "query", dataType = "Integer"), - @ApiImplicitParam(name = "username", value = "部门名", paramType = "query", dataType = "String"), + @ApiImplicitParam(name = "name", value = "部门名称", paramType = "query", dataType = "String"), + @ApiImplicitParam(name = "mode", value = "查询模式(mode:1-表格数据)", defaultValue = "1", paramType = "query", dataType = "Integer"), }) @GetMapping - public Result list(Integer page, Integer limit, String name) { - LambdaQueryWrapper queryWrapper = new LambdaQueryWrapper() - .like(StrUtil.isNotBlank(name), SysDept::getName, name) + public Result list(@RequestParam(required = false, defaultValue = "1") Integer mode, + Integer status, + String name) { + LambdaQueryWrapper baseQuery = new LambdaQueryWrapper() + .orderByAsc(SysDept::getSort) .orderByDesc(SysDept::getUpdateTime) .orderByDesc(SysDept::getCreateTime); - - if (page != null && limit != null) { - Page result = iSysDeptService.page(new Page<>(page, limit) ,queryWrapper); - - return PageResult.success(result.getRecords(), result.getTotal()); - } else if (limit != null) { - queryWrapper.last("LIMIT " + limit); + List list; + if (mode.equals(1)) { + // 表格数据 + baseQuery = baseQuery.like(StrUtil.isNotBlank(name), SysDept::getName, name) + .eq(status != null, SysDept::getStatus, status); + list = iSysDeptService.listForTableData(baseQuery); + } else if (mode.equals(2)) { + // tree-select 树形下拉数据 + list = iSysDeptService.listForTreeSelect(baseQuery); + } else { + list = iSysDeptService.list(baseQuery); } - List list = iSysDeptService.list(queryWrapper); return Result.success(list); } @ApiOperation(value = "部门详情", httpMethod = "GET") - @ApiImplicitParam(name = "id", value = "部门id", required = true, paramType = "path", dataType = "Long") + @ApiImplicitParam(name = "id", value = "部门id", required = true, paramType = "path", dataType = "Integer") @GetMapping("/{id}") - public Result detail(@PathVariable Long id) { + public Result detail(@PathVariable Integer id) { SysDept sysDept = iSysDeptService.getById(id); return Result.success(sysDept); } @@ -69,24 +70,22 @@ public class SysDeptController { @ApiOperation(value = "修改部门", httpMethod = "PUT") @ApiImplicitParams({ - @ApiImplicitParam(name = "id", value = "部门id", required = true, paramType = "path", dataType = "Long"), + @ApiImplicitParam(name = "id", value = "部门id", required = true, paramType = "path", dataType = "Integer"), @ApiImplicitParam(name = "sysDept", value = "实体JSON对象", required = true, paramType = "body", dataType = "SysDept") }) @PutMapping(value = "/{id}") public Result update( - @PathVariable Long id, + @PathVariable Integer id, @RequestBody SysDept sysDept) { - sysDept.setUpdateTime(new Date()); boolean status = iSysDeptService.updateById(sysDept); return Result.status(status); } @ApiOperation(value = "删除部门", httpMethod = "DELETE") - @ApiImplicitParam(name = "ids[]", value = "id集合", required = true, paramType = "query", allowMultiple = true, dataType = "Long") + @ApiImplicitParam(name = "ids[]", value = "id集合", required = true, paramType = "query", allowMultiple = true, dataType = "Integer") @DeleteMapping - public Result delete(@RequestParam("ids") List ids) { + public Result delete(@RequestParam("ids") List ids) { boolean status = iSysDeptService.removeByIds(ids); return Result.status(status); } - } diff --git a/youlai-admin/src/main/java/com/youlai/admin/entity/SysDept.java b/youlai-admin/src/main/java/com/youlai/admin/entity/SysDept.java index c8b641134..ca143d1d0 100644 --- a/youlai-admin/src/main/java/com/youlai/admin/entity/SysDept.java +++ b/youlai-admin/src/main/java/com/youlai/admin/entity/SysDept.java @@ -23,4 +23,10 @@ public class SysDept extends BaseEntity { private Integer deleted; + private String leader; + + private String mobile; + + private String email; + } diff --git a/youlai-admin/src/main/java/com/youlai/admin/service/ISysDeptService.java b/youlai-admin/src/main/java/com/youlai/admin/service/ISysDeptService.java index 8327fb612..46b3f9637 100644 --- a/youlai-admin/src/main/java/com/youlai/admin/service/ISysDeptService.java +++ b/youlai-admin/src/main/java/com/youlai/admin/service/ISysDeptService.java @@ -1,8 +1,17 @@ package com.youlai.admin.service; +import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper; import com.baomidou.mybatisplus.extension.service.IService; import com.youlai.admin.entity.SysDept; +import com.youlai.admin.vo.DeptVO; +import com.youlai.admin.vo.TreeSelectVO; + +import java.util.List; public interface ISysDeptService extends IService { + + List listForTableData(LambdaQueryWrapper baseQuery); + + List listForTreeSelect(LambdaQueryWrapper baseQuery); } diff --git a/youlai-admin/src/main/java/com/youlai/admin/service/impl/SysDeptServiceImpl.java b/youlai-admin/src/main/java/com/youlai/admin/service/impl/SysDeptServiceImpl.java index 25a912dfa..52c4e9835 100644 --- a/youlai-admin/src/main/java/com/youlai/admin/service/impl/SysDeptServiceImpl.java +++ b/youlai-admin/src/main/java/com/youlai/admin/service/impl/SysDeptServiceImpl.java @@ -1,12 +1,79 @@ package com.youlai.admin.service.impl; +import cn.hutool.core.bean.BeanUtil; +import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper; import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl; +import com.youlai.admin.common.AdminConstant; import com.youlai.admin.entity.SysDept; import com.youlai.admin.mapper.SysDeptMapper; import com.youlai.admin.service.ISysDeptService; +import com.youlai.admin.vo.DeptVO; +import com.youlai.admin.vo.TreeSelectVO; import org.springframework.stereotype.Service; +import java.util.ArrayList; +import java.util.List; +import java.util.Optional; + @Service public class SysDeptServiceImpl extends ServiceImpl implements ISysDeptService { + @Override + public List listForTableData(LambdaQueryWrapper baseQuery) { + List deptList = this.baseMapper.selectList(baseQuery); + List list = recursionForTableData(AdminConstant.ROOT_DEPT_ID, deptList); + return list; + } + + + /** + * 递归生成部门表格数据 + * @param parentId + * @param deptList + * @return + */ + public static List recursionForTableData(int parentId, List deptList) { + List list = new ArrayList<>(); + Optional.ofNullable(deptList).orElse(new ArrayList<>()) + .stream() + .filter(dept -> dept.getParentId().equals(parentId)) + .forEach(dept -> { + DeptVO deptVO = new DeptVO(); + BeanUtil.copyProperties(dept, deptVO); + List children = recursionForTableData(dept.getId(), deptList); + deptVO.setChildren(children); + list.add(deptVO); + }); + return list; + } + + @Override + public List listForTreeSelect(LambdaQueryWrapper baseQuery) { + List deptList = this.baseMapper.selectList(baseQuery); + List list = recursionForTreeSelect(AdminConstant.ROOT_DEPT_ID, deptList); + return list; + } + + /** + * 递归生成部门树形下拉数据 + * @param parentId + * @param deptList + * @return + */ + public static List recursionForTreeSelect(int parentId, List deptList) { + List list = new ArrayList<>(); + Optional.ofNullable(deptList).orElse(new ArrayList<>()) + .stream() + .filter(dept -> dept.getParentId().equals(parentId)) + .forEach(dept -> { + TreeSelectVO treeSelectVO = new TreeSelectVO(); + treeSelectVO.setId(dept.getId().toString()); + treeSelectVO.setLabel(dept.getName()); + List children = recursionForTreeSelect(dept.getId(), deptList); + treeSelectVO.setChildren(children); + list.add(treeSelectVO); + }); + return list; + } + } diff --git a/youlai-admin/src/main/java/com/youlai/admin/vo/DeptVO.java b/youlai-admin/src/main/java/com/youlai/admin/vo/DeptVO.java new file mode 100644 index 000000000..1816d1688 --- /dev/null +++ b/youlai-admin/src/main/java/com/youlai/admin/vo/DeptVO.java @@ -0,0 +1,33 @@ +package com.youlai.admin.vo; + +import com.baomidou.mybatisplus.annotation.IdType; +import com.baomidou.mybatisplus.annotation.TableId; +import lombok.Data; + +import java.util.List; + +@Data +public class DeptVO { + + private Integer id; + + private String name; + + private Integer parentId; + + private String treePath; + + private Integer sort; + + private Integer status; + + private String leader; + + private String mobile; + + private String email; + + + private List children; + +} diff --git a/youlai-admin/src/main/java/com/youlai/admin/vo/TreeSelectVO.java b/youlai-admin/src/main/java/com/youlai/admin/vo/TreeSelectVO.java new file mode 100644 index 000000000..cf354727d --- /dev/null +++ b/youlai-admin/src/main/java/com/youlai/admin/vo/TreeSelectVO.java @@ -0,0 +1,17 @@ +package com.youlai.admin.vo; + + +import lombok.Data; + +import java.util.List; + +@Data +public class TreeSelectVO { + + private String id; + + private String label; + + private List children; + +}