mirror of
https://github.com/continew-org/continew-admin.git
synced 2025-09-10 20:57:14 +08:00
新增:新增系统管理/部门管理/导出功能(引入 Easy Excel 依赖用于导出 Excel,详情可见 README 介绍。另请注意:测试导出功能时,前端需要关闭 mockjs,否则 responseType 会被 mockjs 设置为 '',导致导出的文件无法打开)
This commit is contained in:
@@ -17,11 +17,14 @@
|
||||
package top.charles7c.cnadmin.system.model.vo;
|
||||
|
||||
import lombok.Data;
|
||||
import lombok.experimental.Accessors;
|
||||
|
||||
import io.swagger.v3.oas.annotations.media.Schema;
|
||||
|
||||
import com.alibaba.excel.annotation.ExcelIgnoreUnannotated;
|
||||
import com.alibaba.excel.annotation.ExcelProperty;
|
||||
|
||||
import top.charles7c.cnadmin.common.base.BaseDetailVO;
|
||||
import top.charles7c.cnadmin.common.config.easyexcel.ExcelBaseEnumConverter;
|
||||
import top.charles7c.cnadmin.common.enums.DisEnableStatusEnum;
|
||||
|
||||
/**
|
||||
@@ -31,7 +34,7 @@ import top.charles7c.cnadmin.common.enums.DisEnableStatusEnum;
|
||||
* @since 2023/2/1 22:19
|
||||
*/
|
||||
@Data
|
||||
@Accessors(chain = true)
|
||||
@ExcelIgnoreUnannotated
|
||||
@Schema(description = "部门详情信息")
|
||||
public class DeptDetailVO extends BaseDetailVO {
|
||||
|
||||
@@ -41,12 +44,14 @@ public class DeptDetailVO extends BaseDetailVO {
|
||||
* 部门 ID
|
||||
*/
|
||||
@Schema(description = "部门 ID")
|
||||
@ExcelProperty(value = "部门ID")
|
||||
private Long deptId;
|
||||
|
||||
/**
|
||||
* 部门名称
|
||||
*/
|
||||
@Schema(description = "部门名称")
|
||||
@ExcelProperty(value = "部门名称")
|
||||
private String deptName;
|
||||
|
||||
/**
|
||||
@@ -65,11 +70,13 @@ public class DeptDetailVO extends BaseDetailVO {
|
||||
* 描述
|
||||
*/
|
||||
@Schema(description = "描述")
|
||||
@ExcelProperty(value = "描述")
|
||||
private String description;
|
||||
|
||||
/**
|
||||
* 状态(1启用 2禁用)
|
||||
*/
|
||||
@Schema(description = "状态(1启用 2禁用)")
|
||||
@ExcelProperty(value = "状态", converter = ExcelBaseEnumConverter.class)
|
||||
private DisEnableStatusEnum status;
|
||||
}
|
||||
|
@@ -18,6 +18,8 @@ package top.charles7c.cnadmin.system.service;
|
||||
|
||||
import java.util.List;
|
||||
|
||||
import javax.servlet.http.HttpServletResponse;
|
||||
|
||||
import cn.hutool.core.lang.tree.Tree;
|
||||
|
||||
import top.charles7c.cnadmin.common.base.BaseService;
|
||||
@@ -64,4 +66,14 @@ public interface DeptService extends BaseService<DeptVO, DeptDetailVO, DeptQuery
|
||||
* @return 是否存在
|
||||
*/
|
||||
boolean checkDeptNameExist(String deptName, Long parentId, Long deptId);
|
||||
|
||||
/**
|
||||
* 导出
|
||||
*
|
||||
* @param query
|
||||
* 查询条件
|
||||
* @param response
|
||||
* 响应对象
|
||||
*/
|
||||
void export(DeptQuery query, HttpServletResponse response);
|
||||
}
|
||||
|
@@ -17,10 +17,13 @@
|
||||
package top.charles7c.cnadmin.system.service.impl;
|
||||
|
||||
import java.util.ArrayList;
|
||||
import java.util.Collections;
|
||||
import java.util.List;
|
||||
import java.util.Objects;
|
||||
import java.util.stream.Collectors;
|
||||
|
||||
import javax.servlet.http.HttpServletResponse;
|
||||
|
||||
import lombok.RequiredArgsConstructor;
|
||||
|
||||
import org.springframework.stereotype.Service;
|
||||
@@ -37,6 +40,7 @@ import top.charles7c.cnadmin.common.base.BaseDetailVO;
|
||||
import top.charles7c.cnadmin.common.base.BaseServiceImpl;
|
||||
import top.charles7c.cnadmin.common.base.BaseVO;
|
||||
import top.charles7c.cnadmin.common.enums.DisEnableStatusEnum;
|
||||
import top.charles7c.cnadmin.common.util.ExcelUtils;
|
||||
import top.charles7c.cnadmin.common.util.ExceptionUtils;
|
||||
import top.charles7c.cnadmin.common.util.TreeUtils;
|
||||
import top.charles7c.cnadmin.common.util.helper.QueryHelper;
|
||||
@@ -65,13 +69,25 @@ public class DeptServiceImpl extends BaseServiceImpl<DeptMapper, DeptDO, DeptVO,
|
||||
|
||||
@Override
|
||||
public List<DeptVO> list(DeptQuery query) {
|
||||
List<DeptDO> deptList = this.listDept(query);
|
||||
List<DeptVO> list = BeanUtil.copyToList(deptList, DeptVO.class);
|
||||
list.forEach(this::fill);
|
||||
return list;
|
||||
}
|
||||
|
||||
/**
|
||||
* 查询列表
|
||||
*
|
||||
* @param query
|
||||
* 查询条件
|
||||
* @return 列表信息
|
||||
*/
|
||||
private List<DeptDO> listDept(DeptQuery query) {
|
||||
QueryWrapper<DeptDO> queryWrapper = QueryHelper.build(query);
|
||||
queryWrapper.lambda().orderByAsc(DeptDO::getParentId).orderByAsc(DeptDO::getDeptSort)
|
||||
.orderByDesc(DeptDO::getCreateTime);
|
||||
List<DeptDO> deptList = baseMapper.selectList(queryWrapper);
|
||||
List<DeptVO> list = BeanUtil.copyToList(deptList, DeptVO.class);
|
||||
list.forEach(this::fill);
|
||||
return list;
|
||||
return CollUtil.isNotEmpty(deptList) ? deptList : Collections.emptyList();
|
||||
}
|
||||
|
||||
@Override
|
||||
@@ -170,6 +186,14 @@ public class DeptServiceImpl extends BaseServiceImpl<DeptMapper, DeptDO, DeptVO,
|
||||
.eq(DeptDO::getParentId, parentId).ne(deptId != null, DeptDO::getDeptId, deptId));
|
||||
}
|
||||
|
||||
@Override
|
||||
public void export(DeptQuery query, HttpServletResponse response) {
|
||||
List<DeptDO> deptList = this.listDept(query);
|
||||
List<DeptDetailVO> list = BeanUtil.copyToList(deptList, DeptDetailVO.class);
|
||||
list.forEach(this::fillDetail);
|
||||
ExcelUtils.export(list, "部门数据", DeptDetailVO.class, response);
|
||||
}
|
||||
|
||||
/**
|
||||
* 填充数据
|
||||
*
|
||||
|
Reference in New Issue
Block a user