|
@@ -29,9 +29,12 @@ import org.ssssssss.magicapi.modules.db.model.PageResult;
|
|
|
import javax.validation.Valid;
|
|
import javax.validation.Valid;
|
|
|
import java.io.ByteArrayOutputStream;
|
|
import java.io.ByteArrayOutputStream;
|
|
|
import java.net.URLEncoder;
|
|
import java.net.URLEncoder;
|
|
|
-import java.util.HashMap;
|
|
|
|
|
-import java.util.List;
|
|
|
|
|
-import java.util.Map;
|
|
|
|
|
|
|
+import java.text.SimpleDateFormat;
|
|
|
|
|
+import java.time.LocalDate;
|
|
|
|
|
+import java.time.LocalDateTime;
|
|
|
|
|
+import java.time.LocalTime;
|
|
|
|
|
+import java.time.format.DateTimeFormatter;
|
|
|
|
|
+import java.util.*;
|
|
|
|
|
|
|
|
/**
|
|
/**
|
|
|
* @title: 台账导出
|
|
* @title: 台账导出
|
|
@@ -79,7 +82,10 @@ public class LedgerExportController {
|
|
|
//构建excel头
|
|
//构建excel头
|
|
|
List<List<String>> headlist = buildExcelHeader(columnConfigs);
|
|
List<List<String>> headlist = buildExcelHeader(columnConfigs);
|
|
|
|
|
|
|
|
- List<List<Object>> dataList = buildExcelDataList(apiInfo, headlist, dto.getQueryParam());
|
|
|
|
|
|
|
+ //构建头对应的key
|
|
|
|
|
+ List<List<String>> keylist = buildEntityKey(columnConfigs);
|
|
|
|
|
+
|
|
|
|
|
+ List<List<Object>> dataList = buildExcelDataList(apiInfo, keylist, dto.getQueryParam());
|
|
|
|
|
|
|
|
ByteArrayOutputStream bot = new ByteArrayOutputStream();
|
|
ByteArrayOutputStream bot = new ByteArrayOutputStream();
|
|
|
EasyExcel.write(bot).head(headlist).automaticMergeHead(false).excelType(ExcelTypeEnum.XLSX).sheet().doWrite(dataList);
|
|
EasyExcel.write(bot).head(headlist).automaticMergeHead(false).excelType(ExcelTypeEnum.XLSX).sheet().doWrite(dataList);
|
|
@@ -101,6 +107,17 @@ public class LedgerExportController {
|
|
|
* @return
|
|
* @return
|
|
|
*/
|
|
*/
|
|
|
private List<List<String>> buildExcelHeader(JsonArray columnConfigs) {
|
|
private List<List<String>> buildExcelHeader(JsonArray columnConfigs) {
|
|
|
|
|
+ List<List<String>> list = ListUtils.newArrayList();
|
|
|
|
|
+ for (JsonElement element : columnConfigs) {
|
|
|
|
|
+ String key = element.getAsJsonObject().get("label").getAsString();
|
|
|
|
|
+ List<String> head = ListUtils.newArrayList();
|
|
|
|
|
+ head.add(key);
|
|
|
|
|
+ list.add(head);
|
|
|
|
|
+ }
|
|
|
|
|
+ return list;
|
|
|
|
|
+ }
|
|
|
|
|
+
|
|
|
|
|
+ private List<List<String>> buildEntityKey(JsonArray columnConfigs) {
|
|
|
List<List<String>> list = ListUtils.newArrayList();
|
|
List<List<String>> list = ListUtils.newArrayList();
|
|
|
for (JsonElement element : columnConfigs) {
|
|
for (JsonElement element : columnConfigs) {
|
|
|
String key = element.getAsJsonObject().get("field").getAsString();
|
|
String key = element.getAsJsonObject().get("field").getAsString();
|
|
@@ -145,13 +162,46 @@ public class LedgerExportController {
|
|
|
|
|
|
|
|
List<List<Object>> list = ListUtils.newArrayList();
|
|
List<List<Object>> list = ListUtils.newArrayList();
|
|
|
|
|
|
|
|
|
|
+ SimpleDateFormat sdf = new SimpleDateFormat("yyyy-MM-dd");
|
|
|
|
|
+
|
|
|
|
|
+ SimpleDateFormat sdfWithTime = new SimpleDateFormat("yyyy-MM-dd HH:mm:ss");
|
|
|
|
|
+
|
|
|
|
|
+ SimpleDateFormat sdfTime = new SimpleDateFormat("HH:mm:ss");
|
|
|
|
|
+
|
|
|
|
|
+
|
|
|
for (Object obj : res.getList()) {
|
|
for (Object obj : res.getList()) {
|
|
|
List<Object> data = ListUtils.newArrayList();
|
|
List<Object> data = ListUtils.newArrayList();
|
|
|
-
|
|
|
|
|
|
|
+ //Map<String, Object> map = (LinkedHashMap)obj;
|
|
|
Entity rowValue = Convert.convert(Entity.class, obj);
|
|
Entity rowValue = Convert.convert(Entity.class, obj);
|
|
|
|
|
|
|
|
for (List<String> head : headlist){
|
|
for (List<String> head : headlist){
|
|
|
- data.add(rowValue.get(head.get(0)));
|
|
|
|
|
|
|
+ Object value = rowValue.get(head.get(0));
|
|
|
|
|
+
|
|
|
|
|
+ if (value instanceof Date) {
|
|
|
|
|
+ String timeStr = sdfTime.format(value);
|
|
|
|
|
+ String dateStr = "";
|
|
|
|
|
+
|
|
|
|
|
+ if (timeStr.equals("00:00:00")) {
|
|
|
|
|
+ dateStr = sdf.format(value);
|
|
|
|
|
+ } else {
|
|
|
|
|
+ dateStr = sdfWithTime.format(value);
|
|
|
|
|
+ }
|
|
|
|
|
+ data.add(dateStr);
|
|
|
|
|
+ }else if(value instanceof LocalDateTime){
|
|
|
|
|
+ DateTimeFormatter formatter = DateTimeFormatter.ofPattern("yyyy-MM-dd HH:mm:ss");
|
|
|
|
|
+ String formattedDateTime = ((LocalDateTime) value).format(formatter);
|
|
|
|
|
+ data.add(formattedDateTime);
|
|
|
|
|
+ }else if(value instanceof LocalDate){
|
|
|
|
|
+ DateTimeFormatter formatter = DateTimeFormatter.ofPattern("yyyy-MM-dd");
|
|
|
|
|
+ String formattedDate = ((LocalDate) value).format(formatter);
|
|
|
|
|
+ data.add(formattedDate);
|
|
|
|
|
+ }else if(value instanceof LocalTime){
|
|
|
|
|
+ DateTimeFormatter formatter = DateTimeFormatter.ofPattern("HH:mm:ss");
|
|
|
|
|
+ String formattedTime = ((LocalTime) value).format(formatter);
|
|
|
|
|
+ data.add(formattedTime);
|
|
|
|
|
+ }else{
|
|
|
|
|
+ data.add(rowValue.get(head.get(0)));
|
|
|
|
|
+ }
|
|
|
}
|
|
}
|
|
|
|
|
|
|
|
list.add(data);
|
|
list.add(data);
|