|
|
@@ -57,6 +57,16 @@ public class EnterpriseTagController extends JeecgController<EnterpriseTag, IEnt
|
|
|
@Autowired
|
|
|
private EnterpriseTagRelationMapper enterpriseTagRelationMapper;
|
|
|
|
|
|
+ /**
|
|
|
+ * 导出字段与字典编码的映射关系:entity字段名 → 字典编码
|
|
|
+ * 用于导出时自动将字典值翻译为中文标签
|
|
|
+ */
|
|
|
+ private static final Map<String, String> EXPORT_DICT_FIELD_MAP = new LinkedHashMap<>();
|
|
|
+
|
|
|
+ static {
|
|
|
+ EXPORT_DICT_FIELD_MAP.put("dataSource", "DataSource");
|
|
|
+ }
|
|
|
+
|
|
|
/**
|
|
|
* 分页列表查询
|
|
|
*
|
|
|
@@ -158,6 +168,7 @@ public class EnterpriseTagController extends JeecgController<EnterpriseTag, IEnt
|
|
|
|
|
|
/**
|
|
|
* 导出excel
|
|
|
+ * 导出顺序按树形层级展开:一级→二级→三级(非树形,扁平化顺序)
|
|
|
*
|
|
|
* @param request
|
|
|
* @param enterpriseTag
|
|
|
@@ -170,6 +181,21 @@ public class EnterpriseTagController extends JeecgController<EnterpriseTag, IEnt
|
|
|
|
|
|
List<EnterpriseTagVo> exportList = enterpriseTagService.queryListWithRelationCount(queryWrapper, request);
|
|
|
|
|
|
+ // 字典字段值→标签内存映射翻译
|
|
|
+ exportList = enterpriseTagService.translateDictFields(exportList, EXPORT_DICT_FIELD_MAP);
|
|
|
+
|
|
|
+ // 将tagStatus转换为中文显示:1→启用,0→停用
|
|
|
+ for (EnterpriseTagVo tag : exportList) {
|
|
|
+ if ("1".equals(tag.getTagStatus())) {
|
|
|
+ tag.setTagStatus("启用");
|
|
|
+ } else if ("0".equals(tag.getTagStatus())) {
|
|
|
+ tag.setTagStatus("停用");
|
|
|
+ }
|
|
|
+ }
|
|
|
+
|
|
|
+ // 按树形层级排序:一级 → 一级下的二级 → 二级下的三级 → 下一个一级 ...
|
|
|
+ exportList = sortByTreeOrder(exportList);
|
|
|
+
|
|
|
ModelAndView mv = new ModelAndView(new JeecgEntityExcelView());
|
|
|
mv.addObject(NormalExcelConstants.FILE_NAME, "企业标签信息表");
|
|
|
mv.addObject(NormalExcelConstants.CLASS, EnterpriseTagVo.class);
|
|
|
@@ -177,13 +203,68 @@ public class EnterpriseTagController extends JeecgController<EnterpriseTag, IEnt
|
|
|
mv.addObject(NormalExcelConstants.PARAMS, exportParams);
|
|
|
mv.addObject(NormalExcelConstants.DATA_LIST, exportList);
|
|
|
|
|
|
- String exportFields = request.getParameter(NormalExcelConstants.EXPORT_FIELDS);
|
|
|
- if (oConvertUtils.isNotEmpty(exportFields)) {
|
|
|
- mv.addObject(NormalExcelConstants.EXPORT_FIELDS, exportFields);
|
|
|
- }
|
|
|
+ // 指定导出字段,与前端表格列保持一致:标签名称、省标编码、标签编码、标签说明、启用状态、本地关联企业数、数据来源
|
|
|
+ String exportFields = "tagName,provinceStandardCode,tagCode,tagDescription,tagStatus,relationCount,dataSource";
|
|
|
+ mv.addObject(NormalExcelConstants.EXPORT_FIELDS, exportFields);
|
|
|
return mv;
|
|
|
}
|
|
|
|
|
|
+ /**
|
|
|
+ * 将标签列表按树形层级排序:一级 → 该一级的二级 → 该二级的三级 → 下一个一级 ...
|
|
|
+ * 导出时扁平化展平,但保持"1、1.1、1.1.1、2、2.1、2.1.1"的顺序
|
|
|
+ */
|
|
|
+ private List<EnterpriseTagVo> sortByTreeOrder(List<EnterpriseTagVo> tags) {
|
|
|
+ // 构建 id→tag 映射
|
|
|
+ Map<String, EnterpriseTagVo> tagMap = new LinkedHashMap<>();
|
|
|
+ // 构建 parentId→children 映射(二级的parent是一级,三级的parent是二级)
|
|
|
+ Map<String, List<EnterpriseTagVo>> parentChildrenMap = new LinkedHashMap<>();
|
|
|
+
|
|
|
+ for (EnterpriseTagVo tag : tags) {
|
|
|
+ tagMap.put(tag.getId(), tag);
|
|
|
+ String parentId = "2".equals(tag.getTagLevel()) ? tag.getFirstCategory()
|
|
|
+ : "3".equals(tag.getTagLevel()) ? tag.getSecondCategory() : null;
|
|
|
+ if (parentId != null && !parentId.isEmpty()) {
|
|
|
+ parentChildrenMap.computeIfAbsent(parentId, k -> new ArrayList<>()).add(tag);
|
|
|
+ }
|
|
|
+ }
|
|
|
+
|
|
|
+ // 深度优先遍历:一级 → 其二级 → 二级的三级
|
|
|
+ List<EnterpriseTagVo> ordered = new ArrayList<>();
|
|
|
+ Set<String> visited = new HashSet<>();
|
|
|
+
|
|
|
+ for (EnterpriseTagVo tag : tags) {
|
|
|
+ // 只处理根节点:一级且无父分类
|
|
|
+ if ("1".equals(tag.getTagLevel()) && (tag.getFirstCategory() == null || tag.getFirstCategory().isEmpty())) {
|
|
|
+ appendTreeOrder(tag, tagMap, parentChildrenMap, visited, ordered);
|
|
|
+ }
|
|
|
+ }
|
|
|
+
|
|
|
+ // 处理可能遗漏的游离节点(如搜索过滤后父节点不在列表中的子节点)
|
|
|
+ for (EnterpriseTagVo tag : tags) {
|
|
|
+ if (!visited.contains(tag.getId())) {
|
|
|
+ ordered.add(tag);
|
|
|
+ }
|
|
|
+ }
|
|
|
+
|
|
|
+ return ordered;
|
|
|
+ }
|
|
|
+
|
|
|
+ private void appendTreeOrder(EnterpriseTagVo tag, Map<String, EnterpriseTagVo> tagMap,
|
|
|
+ Map<String, List<EnterpriseTagVo>> parentChildrenMap,
|
|
|
+ Set<String> visited, List<EnterpriseTagVo> ordered) {
|
|
|
+ if (!visited.add(tag.getId())) {
|
|
|
+ return;
|
|
|
+ }
|
|
|
+ ordered.add(tag);
|
|
|
+ // 递归添加子节点
|
|
|
+ List<EnterpriseTagVo> children = parentChildrenMap.get(tag.getId());
|
|
|
+ if (children != null) {
|
|
|
+ for (EnterpriseTagVo child : children) {
|
|
|
+ appendTreeOrder(child, tagMap, parentChildrenMap, visited, ordered);
|
|
|
+ }
|
|
|
+ }
|
|
|
+ }
|
|
|
+
|
|
|
/**
|
|
|
* 通过excel导入数据
|
|
|
*
|