1550076451 лет назад: 2
Родитель
Сommit
441b36a46e

+ 7 - 4
zxkf-api/src/main/java/api/controller/Report/WorkReportController.java

@@ -9,6 +9,7 @@ import api.entity.view.system.CustomerViewExportView;
9 9
 import api.model.AjaxResult;
10 10
 import api.service.order.IReportBaseService;
11 11
 import api.util.annotation.Anonymous;
12
+
12 13
 import api.util.annotation.Log;
13 14
 import api.util.enums.BusinessType;
14 15
 import api.util.helper.ExcelHelper;
@@ -28,6 +29,8 @@ import org.springframework.web.bind.annotation.RestController;
28 29
 
29 30
 import java.text.SimpleDateFormat;
30 31
 import java.util.*;
32
+import java.util.stream.Collectors;
33
+
31 34
 @Api(value = "报表",tags = "报表")
32 35
 @RestController
33 36
 @RequestMapping("/WorkReport")
@@ -44,7 +47,7 @@ public class WorkReportController extends BaseController {
44 47
     }
45 48
     @ApiOperation("在线客服工作报表导出Excel")
46 49
     @Log(title = "在线客服工作报表导出excel", businessType = BusinessType.EXPORT)
47
-    @GetMapping("/OnlineServiceExcel")
50
+    @GetMapping("/OnlineService/exportExcel")
48 51
     public void OnlineServiceExcel(ScreenReport input) {
49 52
         var table= ReportBaseService.selectOnlineServiceReport( input);
50 53
 
@@ -75,7 +78,7 @@ public class WorkReportController extends BaseController {
75 78
     }
76 79
     @ApiOperation("工单分类报表导出Excel")
77 80
     @Log(title = "工单分类报表导出excel", businessType = BusinessType.EXPORT)
78
-    @GetMapping("/WorkOrderTypeExcel")
81
+    @GetMapping("/WorkOrderType/exportExcel")
79 82
     public void WorkOrderTypeExportExcel(ScreenReport input) {
80 83
         var table= ReportBaseService.selectWorkOrderTypeReport( input);
81 84
         if (table != null && table.size() > 0) {
@@ -91,7 +94,6 @@ public class WorkReportController extends BaseController {
91 94
                 }
92 95
             }
93 96
         }
94
-
95 97
         ExcelHelper<WorkOrderTypeReport> excel = new ExcelHelper<>(WorkOrderTypeReport.class);
96 98
         excel.exportExcel("xlsx", table);
97 99
     }
@@ -122,7 +124,7 @@ public class WorkReportController extends BaseController {
122 124
     }
123 125
     @ApiOperation("话务工作报表导出Excel")
124 126
     @Log(title = "话务工作报表导出Excel", businessType = BusinessType.EXPORT)
125
-    @GetMapping("/RecordExcel")
127
+    @GetMapping("/Record/exportExcel")
126 128
     public void RecordExportExcel(ScreenReport input) {
127 129
         var table = ReportBaseService.selectRecordReport(input);
128 130
         if (table != null && table.size() > 0) {
@@ -142,6 +144,7 @@ public class WorkReportController extends BaseController {
142 144
             }
143 145
         }
144 146
         ExcelHelper<RecordReport> excel = new ExcelHelper<>(RecordReport.class);
147
+
145 148
         excel.exportExcel("xlsx", table);
146 149
     }
147 150
 

+ 6 - 0
zxkf-entity/pom.xml

@@ -20,6 +20,12 @@
20 20
             <artifactId>swagger-models</artifactId>
21 21
             <version>1.6.2</version>
22 22
         </dependency>
23
+        <dependency>
24
+            <groupId>api</groupId>
25
+            <artifactId>zxkf-util</artifactId>
26
+            <version>1.0.0</version>
27
+            <scope>compile</scope>
28
+        </dependency>
23 29
 
24 30
     </dependencies>
25 31
 

+ 3 - 0
zxkf-entity/src/main/java/api/entity/database/Report/ScreenReport.java

@@ -3,6 +3,7 @@ package api.entity.database.Report;
3 3
 import io.swagger.annotations.ApiModel;
4 4
 import io.swagger.annotations.ApiModelProperty;
5 5
 import lombok.Data;
6
+import org.springframework.format.annotation.DateTimeFormat;
6 7
 
7 8
 import java.util.Date;
8 9
 
@@ -11,11 +12,13 @@ import java.util.Date;
11 12
 public class ScreenReport {
12 13
 
13 14
     /**开始时间**/
15
+    @DateTimeFormat(pattern="yyyy-MM-dd HH:mm:ss")
14 16
     @ApiModelProperty("开始时间")
15 17
     private Date startTime;
16 18
 
17 19
 
18 20
     /**结束时间**/
21
+    @DateTimeFormat(pattern="yyyy-MM-dd HH:mm:ss")
19 22
     @ApiModelProperty("结束时间")
20 23
     private Date endTime;
21 24
 

+ 2 - 5
zxkf-entity/src/main/java/api/entity/database/Report/WorkOrderTypeReport.java

@@ -1,8 +1,10 @@
1 1
 package api.entity.database.Report;
2 2
 
3
+
3 4
 import io.swagger.annotations.ApiModel;
4 5
 import io.swagger.annotations.ApiModelProperty;
5 6
 import lombok.Data;
7
+import org.springframework.core.annotation.Order;
6 8
 
7 9
 @ApiModel(value = "WorkOrderTypeReport", description = "工单分类报表")
8 10
 @Data
@@ -10,19 +12,14 @@ public class WorkOrderTypeReport {
10 12
 
11 13
     @ApiModelProperty("工单类型")
12 14
     private String type_name;
13
-
14 15
     @ApiModelProperty("总量")
15 16
     private long type_count;
16
-
17 17
     @ApiModelProperty("已处理量")
18 18
     private long processed;
19
-
20 19
     @ApiModelProperty("完成率")
21 20
     private String processedRate;
22
-
23 21
     @ApiModelProperty("完结量")
24 22
     private long completed;
25
-
26 23
     @ApiModelProperty("完结率")
27 24
     private String completedRate;
28 25
 }

+ 29 - 3
zxkf-util/src/main/java/api/util/helper/ExcelHelper.java

@@ -1,15 +1,19 @@
1 1
 package api.util.helper;
2 2
 
3
+
3 4
 import com.alibaba.fastjson2.JSON;
4 5
 import io.swagger.annotations.ApiModelProperty;
5 6
 import lombok.extern.slf4j.Slf4j;
7
+import org.apache.poi.hpsf.UnicodeString;
6 8
 import org.apache.poi.hssf.usermodel.*;
7 9
 import org.apache.poi.ss.usermodel.*;
8 10
 import org.apache.poi.xssf.usermodel.XSSFWorkbook;
11
+import org.springframework.core.annotation.AnnotationAwareOrderComparator;
9 12
 import org.springframework.stereotype.Component;
10 13
 
11 14
 import javax.servlet.http.HttpServletResponse;
12 15
 import java.io.*;
16
+import java.lang.reflect.AnnotatedArrayType;
13 17
 import java.lang.reflect.Field;
14 18
 import java.math.BigDecimal;
15 19
 import java.text.DecimalFormat;
@@ -260,7 +264,7 @@ public class ExcelHelper<T> {
260 264
     public void exportExcel(String suffix, List<T> list, String title) {
261 265
         HttpServletResponse response=ServletHelper.getResponse();
262 266
         try {
263
-            Map<String, Field> filedMap = new HashMap<>();
267
+            LinkedHashMap<String, Field> filedMap = new LinkedHashMap<>();
264 268
             for (Field field : clazz.getDeclaredFields()) {
265 269
                 if (field.getAnnotation(ApiModelProperty.class) != null) {
266 270
                     filedMap.put(field.getAnnotation(ApiModelProperty.class).value(), field);
@@ -300,6 +304,8 @@ public class ExcelHelper<T> {
300 304
             cellStyle.setBorderBottom(BorderStyle.THIN);
301 305
             cellStyle.setBorderLeft(BorderStyle.THIN);
302 306
             cellStyle.setBorderRight(BorderStyle.THIN);
307
+            cellStyle.setAlignment(HorizontalAlignment.CENTER);
308
+
303 309
 
304 310
             int limit=60000;
305 311
             int rowindex=0;
@@ -317,6 +323,26 @@ public class ExcelHelper<T> {
317 323
                 }
318 324
             }
319 325
 
326
+            for (int columnNum = 0; columnNum <= filedMap.size(); columnNum++)
327
+            {
328
+                int columnWidth = sheet.getColumnWidth(columnNum) / 256;//获取当前列宽
329
+                for (int rowNum = 0; rowNum <= sheet.getLastRowNum(); rowNum++)
330
+                {
331
+                    Row  currentRow = sheet.getRow(rowNum);
332
+                    if (currentRow.getCell(columnNum) != null)
333
+                    {
334
+                        Cell currentCell = currentRow.getCell(columnNum);
335
+                        int length = currentCell.toString().getBytes("UTF-8").length;//获取当前单元格的内容宽度
336
+                        if (columnWidth < length)//若当前单元格内容宽度大于列宽,则调整列宽为当前单元格宽度
337
+                        {
338
+                            columnWidth = length;
339
+                        }
340
+                    }
341
+                }
342
+                sheet.setColumnWidth(columnNum, columnWidth * 256);
343
+            }
344
+
345
+
320 346
             if (StringHelper.isEmpty(title)) {
321 347
                 title = System.currentTimeMillis() + "";
322 348
             }
@@ -347,7 +373,7 @@ public class ExcelHelper<T> {
347 373
      * @param wb
348 374
      * @param filedMap
349 375
      */
350
-    private Sheet createSheet(Workbook wb,Map<String, Field> filedMap,CellStyle style){
376
+    private Sheet createSheet(Workbook wb,LinkedHashMap<String, Field> filedMap,CellStyle style){
351 377
         Sheet sheet = wb.createSheet();
352 378
         Row headerRow = sheet.createRow(0);
353 379
         headerRow.setHeightInPoints(16);
@@ -388,7 +414,7 @@ public class ExcelHelper<T> {
388 414
      * @param t
389 415
      * @param style
390 416
      */
391
-    private void createRow(Sheet sheet,int rowindex,Map<String, Field> filedMap,T t,CellStyle style)
417
+    private void createRow(Sheet sheet,int rowindex,LinkedHashMap<String, Field> filedMap,T t,CellStyle style)
392 418
     {
393 419
         Row row = sheet.createRow(rowindex);
394 420
         row.setHeightInPoints(16);