|
|
@@ -31,6 +31,7 @@ import org.sky.scientific.pojo.entity.SubjectEnterprise;
|
|
|
import org.sky.scientific.pojo.entity.XmCostDetailsEntity;
|
|
|
import org.sky.scientific.pojo.vo.SubjectVO;
|
|
|
import org.sky.scientific.service.ISubjectService;
|
|
|
+import org.sky.scientific.utils.ExportUtil;
|
|
|
import org.springframework.stereotype.Service;
|
|
|
import org.springframework.web.multipart.MultipartFile;
|
|
|
|
|
|
@@ -147,36 +148,37 @@ public class SubjectServiceImpl extends ServiceImpl<SubjectMapper, Subject> impl
|
|
|
public void exportSubject(HttpServletResponse response, SubjectQueryDto dto) {
|
|
|
|
|
|
List<SubjectVO> list = this.lazyList(dto);
|
|
|
- List<JSONObject> resultList = new ArrayList<>();
|
|
|
- traverseSubjectTree(list.get(0), null, null, null, null, 1, resultList);
|
|
|
+ if (Func.isEmpty(list)) {
|
|
|
+ ExportUtil.processWithNoData(response);
|
|
|
+ } else {
|
|
|
+ List<JSONObject> resultList = new ArrayList<>();
|
|
|
+ traverseSubjectTree(list.get(0), null, null, null, null, 1, resultList);
|
|
|
|
|
|
- AtomicInteger index = new AtomicInteger(1);
|
|
|
- for (JSONObject obj : resultList) {
|
|
|
- obj.put("xh", index.getAndIncrement() + "");
|
|
|
- }
|
|
|
+ AtomicInteger index = new AtomicInteger(1);
|
|
|
+ for (JSONObject obj : resultList) {
|
|
|
+ obj.put("xh", index.getAndIncrement() + "");
|
|
|
+ }
|
|
|
|
|
|
- InputStream templateFileName = this.getClass().getClassLoader().getResourceAsStream("export-template/基础资源管理/系统预设会计科目.xls");
|
|
|
- response.setContentType("application/vnd.ms-excel");
|
|
|
- response.setCharacterEncoding("utf-8");
|
|
|
- response.addHeader("Content-Disposition", "attachment;filename=" + URLEncoder.encode("系统预设会计科目.xls", Charsets.UTF_8));
|
|
|
- ExcelWriter excelWriter = EasyExcel.write(response.getOutputStream())
|
|
|
- .withTemplate((templateFileName))
|
|
|
- .excelType(ExcelTypeEnum.XLS)
|
|
|
- .build();
|
|
|
+ InputStream templateFileName = this.getClass().getClassLoader().getResourceAsStream("export-template/基础资源管理/系统预设会计科目.xls");
|
|
|
+ response.setContentType("application/vnd.ms-excel");
|
|
|
+ response.setCharacterEncoding("utf-8");
|
|
|
+ response.addHeader("Content-Disposition", "attachment;filename=" + URLEncoder.encode("系统预设会计科目.xlsx", Charsets.UTF_8));
|
|
|
+ ExcelWriter excelWriter = EasyExcel.write(response.getOutputStream())
|
|
|
+ .withTemplate((templateFileName))
|
|
|
+ .excelType(ExcelTypeEnum.XLS)
|
|
|
+ .build();
|
|
|
|
|
|
- WriteSheet writeSheet = EasyExcel.writerSheet().build();
|
|
|
- //设置list集合数据
|
|
|
- excelWriter.fill(resultList, writeSheet);
|
|
|
- excelWriter.finish();
|
|
|
- if (templateFileName != null) {
|
|
|
- templateFileName.close();
|
|
|
+ WriteSheet writeSheet = EasyExcel.writerSheet().build();
|
|
|
+ //设置list集合数据
|
|
|
+ excelWriter.fill(resultList, writeSheet);
|
|
|
+ excelWriter.finish();
|
|
|
+ if (templateFileName != null) {
|
|
|
+ templateFileName.close();
|
|
|
+ }
|
|
|
}
|
|
|
}
|
|
|
|
|
|
- private static void traverseSubjectTree(SubjectVO currentNode,
|
|
|
- String l1, String l2,
|
|
|
- String l3, String l4,int currentLevel,
|
|
|
- List<JSONObject> result) {
|
|
|
+ private static void traverseSubjectTree(SubjectVO currentNode, String l1, String l2, String l3, String l4, int currentLevel, List<JSONObject> result) {
|
|
|
if (currentNode == null) {
|
|
|
return;
|
|
|
}
|
|
|
@@ -208,15 +210,26 @@ public class SubjectServiceImpl extends ServiceImpl<SubjectMapper, Subject> impl
|
|
|
node.put("l2", newL2);
|
|
|
node.put("l3", newL3);
|
|
|
node.put("l4", newL4);
|
|
|
-
|
|
|
+ List<String> nameList = new ArrayList<>();
|
|
|
+ if (Func.isNotEmpty(newL1)) nameList.add(newL1);
|
|
|
+ if (Func.isNotEmpty(newL2)) nameList.add(newL2);
|
|
|
+ if (Func.isNotEmpty(newL3)) nameList.add(newL3);
|
|
|
+ if (Func.isNotEmpty(newL4)) nameList.add(newL4);
|
|
|
node.put("code", currentNode.getCode());
|
|
|
- node.put("name", currentNode.getName());
|
|
|
+ if (currentLevel == 4 && Func.isNotEmpty(nameList)) {
|
|
|
+ node.put("name", String.join("\\", nameList));
|
|
|
+ } else {
|
|
|
+ node.put("name", null);
|
|
|
+ }
|
|
|
+ node.put("adSubject", currentNode.getAdSubjectEnable() == 1 ? node.get("name") : null);
|
|
|
+ node.put("rdSubject", currentNode.getRdSubjectEnable() == 1 ? node.get("name") : null);
|
|
|
+
|
|
|
result.add(node);
|
|
|
|
|
|
// 递归处理子节点
|
|
|
if (currentNode.getChildren() != null && !currentNode.getChildren().isEmpty()) {
|
|
|
for (SubjectVO child : currentNode.getChildren()) {
|
|
|
- traverseSubjectTree(child, newL1, newL2, newL3, newL4, currentLevel+1, result);
|
|
|
+ traverseSubjectTree(child, newL1, newL2, newL3, newL4, currentLevel + 1, result);
|
|
|
}
|
|
|
}
|
|
|
}
|