refactor: 优化字典导出数据和格式
This commit is contained in:
parent
9ed63dbd76
commit
8529af8eca
@ -46,13 +46,13 @@ public class BaseDetailVO extends BaseVO {
|
||||
* 修改人
|
||||
*/
|
||||
@Schema(description = "修改人", example = "李四")
|
||||
@ExcelProperty(value = "修改人")
|
||||
@ExcelProperty(value = "修改人", order = Integer.MAX_VALUE - 2)
|
||||
private String updateUserString;
|
||||
|
||||
/**
|
||||
* 修改时间
|
||||
*/
|
||||
@Schema(description = "修改时间", example = "2023-08-08 08:08:08", type = "string")
|
||||
@ExcelProperty(value = "修改时间")
|
||||
@ExcelProperty(value = "修改时间", order = Integer.MAX_VALUE - 1)
|
||||
private LocalDateTime updateTime;
|
||||
}
|
||||
|
@ -236,7 +236,7 @@ public abstract class BaseServiceImpl<M extends BaseMapper<T>, T extends BaseDO,
|
||||
* @param detailObj
|
||||
* 待填充详情信息
|
||||
*/
|
||||
protected void fillDetail(Object detailObj) {
|
||||
public void fillDetail(Object detailObj) {
|
||||
if (detailObj instanceof BaseDetailVO) {
|
||||
BaseDetailVO detailVO = (BaseDetailVO)detailObj;
|
||||
this.fill(detailVO);
|
||||
|
@ -42,7 +42,7 @@ public class BaseVO implements Serializable {
|
||||
* ID
|
||||
*/
|
||||
@Schema(description = "ID", example = "1")
|
||||
@ExcelProperty(value = "ID")
|
||||
@ExcelProperty(value = "ID", order = 1)
|
||||
private Long id;
|
||||
|
||||
/**
|
||||
@ -55,14 +55,14 @@ public class BaseVO implements Serializable {
|
||||
* 创建人
|
||||
*/
|
||||
@Schema(description = "创建人", example = "超级管理员")
|
||||
@ExcelProperty(value = "创建人")
|
||||
@ExcelProperty(value = "创建人", order = Integer.MAX_VALUE - 4)
|
||||
private String createUserString;
|
||||
|
||||
/**
|
||||
* 创建时间
|
||||
*/
|
||||
@Schema(description = "创建时间", example = "2023-08-08 08:08:08", type = "string")
|
||||
@ExcelProperty(value = "创建时间")
|
||||
@ExcelProperty(value = "创建时间", order = Integer.MAX_VALUE - 3)
|
||||
private LocalDateTime createTime;
|
||||
|
||||
/**
|
||||
|
@ -20,9 +20,6 @@ import lombok.Data;
|
||||
|
||||
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;
|
||||
|
||||
/**
|
||||
@ -32,7 +29,6 @@ import top.charles7c.cnadmin.common.base.BaseDetailVO;
|
||||
* @since 2023/9/11 21:29
|
||||
*/
|
||||
@Data
|
||||
@ExcelIgnoreUnannotated
|
||||
@Schema(description = "字典详情信息")
|
||||
public class DictDetailVO extends BaseDetailVO {
|
||||
|
||||
@ -42,20 +38,17 @@ public class DictDetailVO extends BaseDetailVO {
|
||||
* 字典名称
|
||||
*/
|
||||
@Schema(description = "字典名称", example = "公告类型")
|
||||
@ExcelProperty(value = "字典名称")
|
||||
private String name;
|
||||
|
||||
/**
|
||||
* 字典编码
|
||||
*/
|
||||
@Schema(description = "字典编码", example = "announcement_type")
|
||||
@ExcelProperty(value = "字典编码")
|
||||
private String code;
|
||||
|
||||
/**
|
||||
* 描述
|
||||
*/
|
||||
@Schema(description = "描述", example = "公告类型描述信息")
|
||||
@ExcelProperty(value = "描述")
|
||||
private String description;
|
||||
}
|
@ -42,41 +42,54 @@ public class DictItemDetailVO extends BaseDetailVO {
|
||||
* 字典标签
|
||||
*/
|
||||
@Schema(description = "字典标签", example = "通知")
|
||||
@ExcelProperty(value = "字典标签")
|
||||
@ExcelProperty(value = "字典标签", order = 2)
|
||||
private String label;
|
||||
|
||||
/**
|
||||
* 字典值
|
||||
*/
|
||||
@Schema(description = "字典值", example = "1")
|
||||
@ExcelProperty(value = "字典值")
|
||||
@ExcelProperty(value = "字典值", order = 3)
|
||||
private String value;
|
||||
|
||||
/**
|
||||
* 背景颜色
|
||||
*/
|
||||
@Schema(description = "背景颜色", example = "blue")
|
||||
@ExcelProperty(value = "背景颜色")
|
||||
@ExcelProperty(value = "背景颜色", order = 4)
|
||||
private String color;
|
||||
|
||||
/**
|
||||
* 排序
|
||||
*/
|
||||
@Schema(description = "排序", example = "1")
|
||||
@ExcelProperty(value = "排序")
|
||||
@ExcelProperty(value = "排序", order = 5)
|
||||
private Integer sort;
|
||||
|
||||
/**
|
||||
* 描述
|
||||
*/
|
||||
@Schema(description = "描述", example = "通知描述信息")
|
||||
@ExcelProperty(value = "描述")
|
||||
@ExcelProperty(value = "描述", order = 6)
|
||||
private String description;
|
||||
|
||||
/**
|
||||
* 所属字典
|
||||
* 字典 ID
|
||||
*/
|
||||
@Schema(description = "所属字典", example = "1")
|
||||
@ExcelProperty(value = "所属字典")
|
||||
@Schema(description = "字典 ID", example = "1")
|
||||
private Long dictId;
|
||||
|
||||
/**
|
||||
* 字典名称
|
||||
*/
|
||||
@Schema(hidden = true)
|
||||
@ExcelProperty(value = "字典名称", order = 7)
|
||||
private String dictName;
|
||||
|
||||
/**
|
||||
* 字典编码
|
||||
*/
|
||||
@Schema(hidden = true)
|
||||
@ExcelProperty(value = "字典编码", order = 8)
|
||||
private String dictCode;
|
||||
}
|
@ -32,6 +32,15 @@ import top.charles7c.cnadmin.system.model.vo.DictItemVO;
|
||||
*/
|
||||
public interface DictItemService extends BaseService<DictItemVO, DictItemDetailVO, DictItemQuery, DictItemRequest> {
|
||||
|
||||
/**
|
||||
* 根据字典 ID 查询
|
||||
*
|
||||
* @param dictId
|
||||
* 字典 ID
|
||||
* @return 字典项列表
|
||||
*/
|
||||
List<DictItemDetailVO> listByDictId(Long dictId);
|
||||
|
||||
/**
|
||||
* 根据字典 ID 列表删除
|
||||
*
|
||||
|
@ -24,6 +24,7 @@ import org.springframework.stereotype.Service;
|
||||
import org.springframework.transaction.annotation.Transactional;
|
||||
|
||||
import top.charles7c.cnadmin.common.base.BaseServiceImpl;
|
||||
import top.charles7c.cnadmin.common.model.query.SortQuery;
|
||||
import top.charles7c.cnadmin.common.util.validate.CheckUtils;
|
||||
import top.charles7c.cnadmin.system.mapper.DictItemMapper;
|
||||
import top.charles7c.cnadmin.system.model.entity.DictItemDO;
|
||||
@ -61,6 +62,17 @@ public class DictItemServiceImpl
|
||||
super.update(request, id);
|
||||
}
|
||||
|
||||
@Override
|
||||
public List<DictItemDetailVO> listByDictId(Long dictId) {
|
||||
DictItemQuery dictItemQuery = new DictItemQuery();
|
||||
dictItemQuery.setDictId(dictId);
|
||||
SortQuery sortQuery = new SortQuery();
|
||||
sortQuery.setSort(new String[] {"sort,asc"});
|
||||
List<DictItemDetailVO> detailList = super.list(dictItemQuery, sortQuery, DictItemDetailVO.class);
|
||||
detailList.forEach(super::fillDetail);
|
||||
return detailList;
|
||||
}
|
||||
|
||||
@Override
|
||||
public void deleteByDictIds(List<Long> dictIds) {
|
||||
baseMapper.lambdaUpdate().in(DictItemDO::getDictId, dictIds).remove();
|
||||
|
@ -16,21 +16,25 @@
|
||||
|
||||
package top.charles7c.cnadmin.system.service.impl;
|
||||
|
||||
import java.util.ArrayList;
|
||||
import java.util.List;
|
||||
|
||||
import javax.servlet.http.HttpServletResponse;
|
||||
|
||||
import lombok.RequiredArgsConstructor;
|
||||
|
||||
import org.springframework.stereotype.Service;
|
||||
import org.springframework.transaction.annotation.Transactional;
|
||||
|
||||
import top.charles7c.cnadmin.common.base.BaseServiceImpl;
|
||||
import top.charles7c.cnadmin.common.model.query.SortQuery;
|
||||
import top.charles7c.cnadmin.common.util.ExcelUtils;
|
||||
import top.charles7c.cnadmin.common.util.validate.CheckUtils;
|
||||
import top.charles7c.cnadmin.system.mapper.DictMapper;
|
||||
import top.charles7c.cnadmin.system.model.entity.DictDO;
|
||||
import top.charles7c.cnadmin.system.model.query.DictQuery;
|
||||
import top.charles7c.cnadmin.system.model.request.DictRequest;
|
||||
import top.charles7c.cnadmin.system.model.vo.DictDetailVO;
|
||||
import top.charles7c.cnadmin.system.model.vo.DictVO;
|
||||
import top.charles7c.cnadmin.system.model.vo.*;
|
||||
import top.charles7c.cnadmin.system.service.DictItemService;
|
||||
import top.charles7c.cnadmin.system.service.DictService;
|
||||
|
||||
@ -74,6 +78,21 @@ public class DictServiceImpl extends BaseServiceImpl<DictMapper, DictDO, DictVO,
|
||||
super.delete(ids);
|
||||
}
|
||||
|
||||
@Override
|
||||
public void export(DictQuery query, SortQuery sortQuery, HttpServletResponse response) {
|
||||
List<DictVO> dictList = this.list(query, sortQuery);
|
||||
List<DictItemDetailVO> dictItemList = new ArrayList<>();
|
||||
for (DictVO dict : dictList) {
|
||||
List<DictItemDetailVO> tempDictItemList = dictItemService.listByDictId(dict.getId());
|
||||
for (DictItemDetailVO dictItem : tempDictItemList) {
|
||||
dictItem.setDictName(dict.getName());
|
||||
dictItem.setDictCode(dict.getCode());
|
||||
dictItemList.add(dictItem);
|
||||
}
|
||||
}
|
||||
ExcelUtils.export(dictItemList, "导出数据", DictItemDetailVO.class, response);
|
||||
}
|
||||
|
||||
/**
|
||||
* 检查名称是否存在
|
||||
*
|
||||
|
Loading…
Reference in New Issue
Block a user