mirror of
https://gitee.com/youlaitech/youlai-mall.git
synced 2024-12-23 05:00:25 +08:00
部门管理接口添加
This commit is contained in:
parent
ce0e20431e
commit
76eec829fd
@ -0,0 +1,10 @@
|
||||
package com.youlai.admin.common;
|
||||
|
||||
/**
|
||||
* 平台服务常量
|
||||
*/
|
||||
public interface AdminConstant {
|
||||
|
||||
int ROOT_DEPT_ID = 0;
|
||||
|
||||
}
|
@ -23,7 +23,7 @@ public class ResourceRoleRulesHolder {
|
||||
Map<String, List<String>> resourceRoleMap = new TreeMap<>();
|
||||
List<String> 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);
|
||||
}
|
||||
|
@ -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<SysDept> queryWrapper = new LambdaQueryWrapper<SysDept>()
|
||||
.like(StrUtil.isNotBlank(name), SysDept::getName, name)
|
||||
public Result list(@RequestParam(required = false, defaultValue = "1") Integer mode,
|
||||
Integer status,
|
||||
String name) {
|
||||
LambdaQueryWrapper<SysDept> baseQuery = new LambdaQueryWrapper<SysDept>()
|
||||
.orderByAsc(SysDept::getSort)
|
||||
.orderByDesc(SysDept::getUpdateTime)
|
||||
.orderByDesc(SysDept::getCreateTime);
|
||||
|
||||
if (page != null && limit != null) {
|
||||
Page<SysDept> 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<SysDept> 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<Long> ids) {
|
||||
public Result delete(@RequestParam("ids") List<Integer> ids) {
|
||||
boolean status = iSysDeptService.removeByIds(ids);
|
||||
return Result.status(status);
|
||||
}
|
||||
|
||||
}
|
||||
|
@ -23,4 +23,10 @@ public class SysDept extends BaseEntity {
|
||||
|
||||
private Integer deleted;
|
||||
|
||||
private String leader;
|
||||
|
||||
private String mobile;
|
||||
|
||||
private String email;
|
||||
|
||||
}
|
||||
|
@ -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<SysDept> {
|
||||
|
||||
List<DeptVO> listForTableData(LambdaQueryWrapper<SysDept> baseQuery);
|
||||
|
||||
List<TreeSelectVO> listForTreeSelect(LambdaQueryWrapper<SysDept> baseQuery);
|
||||
}
|
||||
|
@ -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<SysDeptMapper, SysDept> implements ISysDeptService {
|
||||
|
||||
@Override
|
||||
public List<DeptVO> listForTableData(LambdaQueryWrapper<SysDept> baseQuery) {
|
||||
List<SysDept> deptList = this.baseMapper.selectList(baseQuery);
|
||||
List<DeptVO> list = recursionForTableData(AdminConstant.ROOT_DEPT_ID, deptList);
|
||||
return list;
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* 递归生成部门表格数据
|
||||
* @param parentId
|
||||
* @param deptList
|
||||
* @return
|
||||
*/
|
||||
public static List<DeptVO> recursionForTableData(int parentId, List<SysDept> deptList) {
|
||||
List<DeptVO> 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<DeptVO> children = recursionForTableData(dept.getId(), deptList);
|
||||
deptVO.setChildren(children);
|
||||
list.add(deptVO);
|
||||
});
|
||||
return list;
|
||||
}
|
||||
|
||||
@Override
|
||||
public List<TreeSelectVO> listForTreeSelect(LambdaQueryWrapper<SysDept> baseQuery) {
|
||||
List<SysDept> deptList = this.baseMapper.selectList(baseQuery);
|
||||
List<TreeSelectVO> list = recursionForTreeSelect(AdminConstant.ROOT_DEPT_ID, deptList);
|
||||
return list;
|
||||
}
|
||||
|
||||
/**
|
||||
* 递归生成部门树形下拉数据
|
||||
* @param parentId
|
||||
* @param deptList
|
||||
* @return
|
||||
*/
|
||||
public static List<TreeSelectVO> recursionForTreeSelect(int parentId, List<SysDept> deptList) {
|
||||
List<TreeSelectVO> 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<TreeSelectVO> children = recursionForTreeSelect(dept.getId(), deptList);
|
||||
treeSelectVO.setChildren(children);
|
||||
list.add(treeSelectVO);
|
||||
});
|
||||
return list;
|
||||
}
|
||||
|
||||
}
|
||||
|
33
youlai-admin/src/main/java/com/youlai/admin/vo/DeptVO.java
Normal file
33
youlai-admin/src/main/java/com/youlai/admin/vo/DeptVO.java
Normal file
@ -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<DeptVO> children;
|
||||
|
||||
}
|
@ -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<TreeSelectVO> children;
|
||||
|
||||
}
|
Loading…
Reference in New Issue
Block a user