|
@@ -1,22 +1,14 @@
|
|
|
package com.xjrsoft.module.asset.service.impl;
|
|
|
|
|
|
import com.alibaba.excel.EasyExcel;
|
|
|
-import com.alibaba.excel.ExcelWriter;
|
|
|
import com.alibaba.excel.support.ExcelTypeEnum;
|
|
|
-import com.alibaba.excel.write.metadata.WriteSheet;
|
|
|
-import com.alibaba.excel.write.metadata.WriteTable;
|
|
|
-import com.alibaba.excel.write.metadata.style.WriteCellStyle;
|
|
|
-import com.alibaba.excel.write.metadata.style.WriteFont;
|
|
|
-import com.alibaba.excel.write.style.HorizontalCellStyleStrategy;
|
|
|
-import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper;
|
|
|
+import com.alibaba.excel.util.ListUtils;
|
|
|
import com.baomidou.mybatisplus.core.metadata.IPage;
|
|
|
-import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
|
|
|
+import com.fasterxml.jackson.core.JsonProcessingException;
|
|
|
+import com.fasterxml.jackson.core.type.TypeReference;
|
|
|
+import com.fasterxml.jackson.databind.ObjectMapper;
|
|
|
import com.github.yulichang.base.MPJBaseServiceImpl;
|
|
|
-import com.github.yulichang.wrapper.MPJLambdaWrapper;
|
|
|
import com.xjrsoft.common.page.ConventPage;
|
|
|
-import com.xjrsoft.common.utils.VoToColumnUtil;
|
|
|
-import com.xjrsoft.common.utils.excel.ExcelFillCellMergePrevColUtil;
|
|
|
-import com.xjrsoft.common.utils.excel.ExcelMergeUtil;
|
|
|
import com.xjrsoft.module.asset.dto.WfAssetManageConditionalSearchQueryDto;
|
|
|
import com.xjrsoft.module.asset.dto.WfAssetManagePageDto;
|
|
|
import com.xjrsoft.module.asset.dto.WfAssetManageSelectRecordQueryDto;
|
|
@@ -25,21 +17,16 @@ import com.xjrsoft.module.asset.mapper.WfAssetManageMapper;
|
|
|
import com.xjrsoft.module.asset.service.IWfAssetManageService;
|
|
|
import com.xjrsoft.module.asset.vo.WfAssetManagePageVo;
|
|
|
import com.xjrsoft.module.asset.vo.WfAssetManageQueryVo;
|
|
|
-import com.xjrsoft.module.textbook.vo.TextbookClaimExportQueryVo;
|
|
|
-import com.xjrsoft.module.textbook.vo.TextbookSubscriptionExportQueryVo;
|
|
|
-import com.xjrsoft.module.weekly.vo.WeeklyDutyScheduleListVo;
|
|
|
import lombok.AllArgsConstructor;
|
|
|
-import org.apache.poi.ss.usermodel.BorderStyle;
|
|
|
-import org.apache.poi.ss.usermodel.HorizontalAlignment;
|
|
|
-import org.apache.poi.ss.usermodel.VerticalAlignment;
|
|
|
import org.springframework.stereotype.Service;
|
|
|
-import org.springframework.transaction.annotation.Transactional;
|
|
|
|
|
|
import java.io.ByteArrayOutputStream;
|
|
|
-import java.math.BigDecimal;
|
|
|
-import java.util.*;
|
|
|
-import java.util.stream.Collectors;
|
|
|
-import com.baomidou.mybatisplus.core.toolkit.Wrappers;
|
|
|
+import java.io.IOException;
|
|
|
+import java.lang.reflect.Field;
|
|
|
+import java.util.ArrayList;
|
|
|
+import java.util.HashMap;
|
|
|
+import java.util.List;
|
|
|
+import java.util.Map;
|
|
|
|
|
|
/**
|
|
|
* @title: 资产管理
|
|
@@ -60,21 +47,96 @@ public class WfAssetManageServiceImpl extends MPJBaseServiceImpl<WfAssetManageMa
|
|
|
|
|
|
@Override
|
|
|
public ByteArrayOutputStream listWfAssetManageSelectRecordQuery(WfAssetManageSelectRecordQueryDto dto) {
|
|
|
+ ByteArrayOutputStream bot = new ByteArrayOutputStream();
|
|
|
List<WfAssetManageQueryVo> result = wfAssetManageMapper.listWfAssetManageSelectRecordQuery(dto);
|
|
|
+ if(!result.isEmpty()){
|
|
|
+ //以第一条数据中的其他信息的key作为整个excel的表头,后面的数据根据填充
|
|
|
+ List<List<String>> headList = head(result.get(0));
|
|
|
+ List<List<Object>> dataList = dataList(headList, result);
|
|
|
|
|
|
- ByteArrayOutputStream bot = new ByteArrayOutputStream();
|
|
|
- EasyExcel.write(bot, WfAssetManageQueryVo.class).automaticMergeHead(false).excelType(ExcelTypeEnum.XLSX).sheet().doWrite(result);
|
|
|
+ EasyExcel.write(bot).head(headList).excelType(ExcelTypeEnum.XLSX).sheet().doWrite(dataList);
|
|
|
|
|
|
+ return bot;
|
|
|
+ }
|
|
|
return bot;
|
|
|
+
|
|
|
}
|
|
|
|
|
|
@Override
|
|
|
public ByteArrayOutputStream listWfAssetManageConditionalSearchQuery(WfAssetManageConditionalSearchQueryDto dto) {
|
|
|
+ ByteArrayOutputStream bot = new ByteArrayOutputStream();
|
|
|
List<WfAssetManageQueryVo> result = wfAssetManageMapper.listWfAssetManageConditionalSearchQuery(dto);
|
|
|
+ if(!result.isEmpty()){
|
|
|
+ //以第一条数据中的其他信息的key作为整个excel的表头,后面的数据根据填充
|
|
|
+ List<List<String>> headList = head(result.get(0));
|
|
|
+ List<List<Object>> dataList = dataList(headList, result);
|
|
|
|
|
|
- ByteArrayOutputStream bot = new ByteArrayOutputStream();
|
|
|
- EasyExcel.write(bot, WfAssetManageQueryVo.class).automaticMergeHead(false).excelType(ExcelTypeEnum.XLSX).sheet().doWrite(result);
|
|
|
+ EasyExcel.write(bot).head(headList).excelType(ExcelTypeEnum.XLSX).sheet().doWrite(dataList);
|
|
|
|
|
|
+ return bot;
|
|
|
+ }
|
|
|
return bot;
|
|
|
}
|
|
|
+
|
|
|
+ private List<List<String>> head(WfAssetManageQueryVo firstRecord) {
|
|
|
+ List<List<String>> list = ListUtils.newArrayList();
|
|
|
+
|
|
|
+ ObjectMapper objectMapper = new ObjectMapper();
|
|
|
+ Map<String, Object> extendJsonMap = new HashMap<>();
|
|
|
+ try {
|
|
|
+ extendJsonMap = objectMapper.readValue(firstRecord.getExtendJson(), new TypeReference<Map<String, Object>>(){});
|
|
|
+ } catch (IOException e) {
|
|
|
+ e.printStackTrace();
|
|
|
+ }
|
|
|
+
|
|
|
+ // 获取对象的所有属性
|
|
|
+ String[] fields = {"资产类型", "资产类别", "资产种类", "名称", "所属部门", "使用人", "金额"};
|
|
|
+ for (String field : fields) {
|
|
|
+ list.add(new ArrayList<String>(){{
|
|
|
+ add(field);
|
|
|
+ }});
|
|
|
+ }
|
|
|
+
|
|
|
+ for (Map.Entry<String, Object> entry : extendJsonMap.entrySet()){
|
|
|
+ String key = entry.getKey();
|
|
|
+ list.add(new ArrayList<String>(){{
|
|
|
+ add(key);
|
|
|
+ }});
|
|
|
+ }
|
|
|
+
|
|
|
+ return list;
|
|
|
+ }
|
|
|
+
|
|
|
+ private List<List<Object>> dataList(List<List<String>> headList, List<WfAssetManageQueryVo> result) {
|
|
|
+ List<List<Object>> list = ListUtils.newArrayList();
|
|
|
+ ObjectMapper objectMapper = new ObjectMapper();
|
|
|
+ for (WfAssetManageQueryVo wfAssetManageQueryVo : result) {
|
|
|
+ List<Object> oneRecord = ListUtils.newArrayList();
|
|
|
+
|
|
|
+ //先处理固定字段
|
|
|
+ oneRecord.add(wfAssetManageQueryVo.getAssetTypeCn());
|
|
|
+ oneRecord.add(wfAssetManageQueryVo.getAssetCategoryCn());
|
|
|
+ oneRecord.add(wfAssetManageQueryVo.getAssetSpeciesCn());
|
|
|
+ oneRecord.add(wfAssetManageQueryVo.getName());
|
|
|
+ oneRecord.add(wfAssetManageQueryVo.getDeptIdCn());
|
|
|
+ oneRecord.add(wfAssetManageQueryVo.getUserIdCn());
|
|
|
+ oneRecord.add(wfAssetManageQueryVo.getAmount());
|
|
|
+
|
|
|
+ String extendJson = wfAssetManageQueryVo.getExtendJson();
|
|
|
+ if(!extendJson.isEmpty()){
|
|
|
+ try {
|
|
|
+ Map<String, Object> data = objectMapper.readValue(extendJson, new TypeReference<Map<String, Object>>(){});
|
|
|
+ for (List<String> head : headList){
|
|
|
+ if(data.get(head.get(0)) != null){
|
|
|
+ oneRecord.add(data.get(head.get(0)));
|
|
|
+ }
|
|
|
+ }
|
|
|
+ } catch (JsonProcessingException e) {
|
|
|
+ throw new RuntimeException(e);
|
|
|
+ }
|
|
|
+ }
|
|
|
+ list.add(oneRecord);
|
|
|
+ }
|
|
|
+ return list;
|
|
|
+ }
|
|
|
}
|