|
@@ -1,13 +1,21 @@
|
1
|
1
|
package com.huiju.estateagents.drainage.controller;
|
2
|
2
|
|
|
3
|
+import com.alibaba.excel.EasyExcel;
|
|
4
|
+import com.alibaba.excel.ExcelWriter;
|
|
5
|
+import com.alibaba.excel.write.metadata.WriteSheet;
|
|
6
|
+import com.alibaba.fastjson.JSONArray;
|
|
7
|
+import com.alibaba.fastjson.JSONObject;
|
3
|
8
|
import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
|
4
|
9
|
import com.baomidou.mybatisplus.core.metadata.IPage;
|
5
|
10
|
import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
|
|
11
|
+import com.google.gson.JsonObject;
|
6
|
12
|
import com.huiju.estateagents.base.BaseController;
|
7
|
13
|
import com.huiju.estateagents.base.ResponseBean;
|
8
|
14
|
import com.huiju.estateagents.common.StringUtils;
|
9
|
15
|
import com.huiju.estateagents.drainage.entity.TaDrainageRecord;
|
10
|
16
|
import com.huiju.estateagents.drainage.service.ITaDrainageRecordService;
|
|
17
|
+import com.huiju.estateagents.excel.ReporRecommendCustomer;
|
|
18
|
+import com.huiju.estateagents.excel.handler.CustomCellWriteHandler;
|
11
|
19
|
import org.slf4j.Logger;
|
12
|
20
|
import org.slf4j.LoggerFactory;
|
13
|
21
|
import org.springframework.beans.factory.annotation.Autowired;
|
|
@@ -20,6 +28,12 @@ import org.springframework.web.bind.annotation.ResponseBody;
|
20
|
28
|
import org.springframework.web.bind.annotation.RestController;
|
21
|
29
|
|
22
|
30
|
import javax.servlet.http.HttpServletRequest;
|
|
31
|
+import javax.servlet.http.HttpServletResponse;
|
|
32
|
+import java.io.IOException;
|
|
33
|
+import java.time.format.DateTimeFormatter;
|
|
34
|
+import java.util.ArrayList;
|
|
35
|
+import java.util.Arrays;
|
|
36
|
+import java.util.List;
|
23
|
37
|
|
24
|
38
|
/**
|
25
|
39
|
* <p>
|
|
@@ -72,6 +86,68 @@ public class TaDrainageRecordController extends BaseController {
|
72
|
86
|
}
|
73
|
87
|
return responseBean;
|
74
|
88
|
}
|
|
89
|
+
|
|
90
|
+
|
|
91
|
+ /**
|
|
92
|
+ * 导出数据
|
|
93
|
+ * @return
|
|
94
|
+ */
|
|
95
|
+ @RequestMapping(value="/admin/taDrainageRecord/export",method= RequestMethod.GET)
|
|
96
|
+ public void taDrainageRecordList(@RequestParam(value = "drainageId") Integer drainageId,
|
|
97
|
+ @RequestParam(value = "startTime",required = false) String startTime,
|
|
98
|
+ @RequestParam(value = "endTime",required = false) String endTime,
|
|
99
|
+ HttpServletRequest request, HttpServletResponse response) throws IOException {
|
|
100
|
+ //使用分页插件
|
|
101
|
+ QueryWrapper<TaDrainageRecord> queryWrapper = new QueryWrapper<>();
|
|
102
|
+ queryWrapper.eq("drainage_id",drainageId);
|
|
103
|
+ queryWrapper.eq("org_id",getOrgId(request));
|
|
104
|
+ queryWrapper.gt(!StringUtils.isEmpty(startTime),"create_date",startTime);
|
|
105
|
+ queryWrapper.lt(!StringUtils.isEmpty(endTime),"create_date",endTime);
|
|
106
|
+ queryWrapper.orderByDesc("create_date");
|
|
107
|
+
|
|
108
|
+ List<TaDrainageRecord> list = iTaDrainageRecordService.list(queryWrapper);
|
|
109
|
+ List<List<String>> resList = new ArrayList<List<String>>();
|
|
110
|
+
|
|
111
|
+ //构造表头
|
|
112
|
+ if (list.size() > 0) {
|
|
113
|
+ List<String> headerList = new ArrayList<>();
|
|
114
|
+ TaDrainageRecord taDrainageRecord = list.get(0);
|
|
115
|
+ headerList.add("提交时间");
|
|
116
|
+ JSONArray arr= JSONArray.parseArray(taDrainageRecord.getContent());
|
|
117
|
+ arr.forEach(e -> {
|
|
118
|
+ JSONObject jsonObject = JSONObject.parseObject(e.toString());
|
|
119
|
+ headerList.add(jsonObject.getString("label"));
|
|
120
|
+ });
|
|
121
|
+ resList.add(headerList);
|
|
122
|
+ }
|
|
123
|
+
|
|
124
|
+ //构造表数据
|
|
125
|
+ DateTimeFormatter formatter = DateTimeFormatter.ofPattern("yyyy-MM-dd HH:mm");
|
|
126
|
+ list.forEach(e -> {
|
|
127
|
+ List<String> bodyList = new ArrayList<>();
|
|
128
|
+ bodyList.add(e.getCreateDate().format(formatter));
|
|
129
|
+ JSONArray arr= JSONArray.parseArray(e.getContent());
|
|
130
|
+ arr.forEach(json -> {
|
|
131
|
+ JSONObject jsonObject = JSONObject.parseObject(json.toString());
|
|
132
|
+ bodyList.add(jsonObject.getString("value"));
|
|
133
|
+ });
|
|
134
|
+ resList.add(bodyList);
|
|
135
|
+ });
|
|
136
|
+
|
|
137
|
+ response.setContentType("application/octet-stream");
|
|
138
|
+ response.setCharacterEncoding("utf-8");
|
|
139
|
+ response.setHeader("Content-disposition", "attachment;filename=引流详情.xlsx");
|
|
140
|
+ // 设置读取的class
|
|
141
|
+ ExcelWriter excelWriter = EasyExcel.write(response.getOutputStream()).registerWriteHandler(new CustomCellWriteHandler()).build();
|
|
142
|
+ // 设置 sheet, 同一个sheet只需要设置一次
|
|
143
|
+ WriteSheet writeSheet = EasyExcel.writerSheet("引流详情").build();
|
|
144
|
+
|
|
145
|
+
|
|
146
|
+ excelWriter.write(resList, writeSheet);
|
|
147
|
+
|
|
148
|
+ /// finish 会帮忙关闭流
|
|
149
|
+ excelWriter.finish();
|
|
150
|
+ }
|
75
|
151
|
|
76
|
152
|
/**
|
77
|
153
|
* 保存对象
|