Browse Source

feat: 系统月度使用情况统计导出功能

zhangying 9 months ago
parent
commit
2ed08fff67

+ 70 - 2
src/main/java/com/hz/employmentsite/controller/statistics/StatisticsController.java

@@ -43,8 +43,14 @@ public class StatisticsController {
         return RespGenerstor.success(systemDataCount);
     }
 
+    /**
+     * 查询某月的系统使用情况
+     *
+     * @param dateStr
+     * @return
+     */
     @GetMapping("/monthSystemApplyCount")
-    public BaseResponse findMonthSystemDataCount(@RequestParam String dateStr){
+    public BaseResponse findMonthSystemDataCount(@RequestParam String dateStr) {
         Map<String, List<RegionSystemDataCount>> result = statisticsService.findMonthSystemDataCount(dateStr);
         return RespGenerstor.success(result);
     }
@@ -70,7 +76,7 @@ public class StatisticsController {
         }
         titleMap.put(dataStr + "就业驿站系统使用情况表", new CellRangeAddress(0, 0, 0, 5));
         data.setColspanTitles(Arrays.asList(titleMap));
-        data.setTitles(Arrays.asList(new String[]{"行政区划", "驿站名", "驿站人员数量", "录入企业数", "收集岗位数", "登记求职人数"}));
+        data.setTitles(Arrays.asList("行政区划", "驿站名", "驿站人员数量", "录入企业数", "收集岗位数", "登记求职人数"));
         List<List<Object>> rowsData = new ArrayList();
         for (SystemDataCount dataCount : systemDataCount) {
             List<Object> row = new ArrayList();
@@ -112,4 +118,66 @@ public class StatisticsController {
         excelHelper.exportExcel(response, data);
         return null;
     }
+
+    /**
+     * 导出指定时间段的系统使用情况
+     *
+     * @param response 请求响应
+     * @param dateStr  查询月份
+     * @return
+     */
+    @GetMapping("/export/monthSystemApplyCount")
+    public BaseResponse exportMonthSystemApplyCount(HttpServletResponse response, @RequestParam String dateStr) throws Exception {
+        Map<String, List<RegionSystemDataCount>> result = statisticsService.findMonthSystemDataCount(dateStr);
+        ExcelHelper.ExcelData data = excelHelper.new ExcelData();
+        // 设置标题区域
+        Map<String, CellRangeAddress> titleMap = new HashMap<>();
+        titleMap.put("项目", new CellRangeAddress(0, 1, 0, 0));
+        // 子标题
+        List<String> childrenTitle = new ArrayList<>(Arrays.asList(""));
+        // 合并位置
+        int firstCol = 1;
+        // 生成周数标题
+        for (Map.Entry<String, List<RegionSystemDataCount>> entry : result.entrySet()) {
+            String key = entry.getKey();
+            titleMap.put(key, new CellRangeAddress(0, 0, firstCol, firstCol + 3));
+            // 填充子标题
+            childrenTitle.addAll(Arrays.asList("驿站人员数量","录入企业数量","收集岗位数量","登记求职人数"));
+            firstCol += 4;
+        }
+        data.setColspanTitles(Arrays.asList(titleMap));
+        data.setTitles(childrenTitle);
+        // 开始生成数据
+        List<List<Object>> rowsData = new ArrayList();
+        // 遍历原始数据
+        for (List<RegionSystemDataCount> valueList : result.values()) {
+            for (RegionSystemDataCount item : valueList) {
+                boolean found = false;
+                // 判断最终结果中是否已经生成过相同的县区数据,如有则追加,不新建
+                for (List<Object> existingRow : rowsData) {
+                    if (existingRow.get(0).equals(item.getRegionName())) {
+                        existingRow.add(item.getSiteUserCount());
+                        existingRow.add(item.getCompanyCount());
+                        existingRow.add(item.getPostCount());
+                        existingRow.add(item.getJobUserCount());
+                        found = true;
+                        break;
+                    }
+                }
+                // 没有则新建
+                if (!found) {
+                    List<Object> row = new ArrayList<>();
+                    row.add(item.getRegionName());
+                    row.add(item.getSiteUserCount());
+                    row.add(item.getCompanyCount());
+                    row.add(item.getPostCount());
+                    row.add(item.getJobUserCount());
+                    rowsData.add(row);
+                }
+            }
+        }
+        data.setRows(rowsData);
+        excelHelper.exportExcel(response, data);
+        return null;
+    }
 }

+ 2 - 2
vue/src/views/statistics/MonthSystemApplyCount.vue

@@ -30,10 +30,10 @@
           </a-radio-group>
         </div>
         <div>
-          <BExportExcel :filename="'系统使用情况统计'"
+          <BExportExcel :filename="searchParams.dateStr + '系统使用情况统计'"
                         :params="{...exportSearchParams}"
                         :title="'导出'"
-                        :url="'statistics/export/systemApplyCount'"></BExportExcel>
+                        :url="'statistics/export/monthSystemApplyCount'"></BExportExcel>
         </div>
       </a-col>
     </a-row>