|
@@ -3,15 +3,18 @@ package com.hz.employmentsite.controller.statistics;
|
|
import com.hz.employmentsite.filter.exception.BaseResponse;
|
|
import com.hz.employmentsite.filter.exception.BaseResponse;
|
|
import com.hz.employmentsite.filter.exception.RespGenerstor;
|
|
import com.hz.employmentsite.filter.exception.RespGenerstor;
|
|
import com.hz.employmentsite.services.service.statistics.StatisticsService;
|
|
import com.hz.employmentsite.services.service.statistics.StatisticsService;
|
|
|
|
+import com.hz.employmentsite.util.DateUtils;
|
|
|
|
+import com.hz.employmentsite.util.ExcelHelper;
|
|
import com.hz.employmentsite.vo.statistics.SystemDataCount;
|
|
import com.hz.employmentsite.vo.statistics.SystemDataCount;
|
|
|
|
+import org.apache.poi.ss.util.CellRangeAddress;
|
|
import org.springframework.beans.factory.annotation.Autowired;
|
|
import org.springframework.beans.factory.annotation.Autowired;
|
|
import org.springframework.web.bind.annotation.GetMapping;
|
|
import org.springframework.web.bind.annotation.GetMapping;
|
|
import org.springframework.web.bind.annotation.RequestMapping;
|
|
import org.springframework.web.bind.annotation.RequestMapping;
|
|
import org.springframework.web.bind.annotation.RequestParam;
|
|
import org.springframework.web.bind.annotation.RequestParam;
|
|
import org.springframework.web.bind.annotation.RestController;
|
|
import org.springframework.web.bind.annotation.RestController;
|
|
|
|
|
|
-import java.util.Date;
|
|
|
|
-import java.util.List;
|
|
|
|
|
|
+import javax.servlet.http.HttpServletResponse;
|
|
|
|
+import java.util.*;
|
|
|
|
|
|
@RestController
|
|
@RestController
|
|
@RequestMapping(value = "/api/statistics")
|
|
@RequestMapping(value = "/api/statistics")
|
|
@@ -19,6 +22,12 @@ public class StatisticsController {
|
|
@Autowired
|
|
@Autowired
|
|
private StatisticsService statisticsService;
|
|
private StatisticsService statisticsService;
|
|
|
|
|
|
|
|
+ @Autowired
|
|
|
|
+ private ExcelHelper excelHelper;
|
|
|
|
+
|
|
|
|
+ @Autowired
|
|
|
|
+ private DateUtils dateUtils;
|
|
|
|
+
|
|
/**
|
|
/**
|
|
* 查询指定时间段系统使用情况
|
|
* 查询指定时间段系统使用情况
|
|
*
|
|
*
|
|
@@ -32,4 +41,68 @@ public class StatisticsController {
|
|
List<SystemDataCount> systemDataCount = statisticsService.findSystemDataCount(startDate, endDate);
|
|
List<SystemDataCount> systemDataCount = statisticsService.findSystemDataCount(startDate, endDate);
|
|
return RespGenerstor.success(systemDataCount);
|
|
return RespGenerstor.success(systemDataCount);
|
|
}
|
|
}
|
|
|
|
+
|
|
|
|
+ /**
|
|
|
|
+ * 导出指定时间段的系统使用情况
|
|
|
|
+ *
|
|
|
|
+ * @param response 请求响应
|
|
|
|
+ * @param startDate 开始时间
|
|
|
|
+ * @param endDate 结束时间
|
|
|
|
+ * @return
|
|
|
|
+ */
|
|
|
|
+ @GetMapping("/export/systemApplyCount")
|
|
|
|
+ public BaseResponse exportSystemApplyCount(HttpServletResponse response,
|
|
|
|
+ @RequestParam(value = "startDate", required = false) Date startDate,
|
|
|
|
+ @RequestParam(value = "endDate", required = false) Date endDate) throws Exception {
|
|
|
|
+ List<SystemDataCount> systemDataCount = statisticsService.findSystemDataCount(startDate, endDate);
|
|
|
|
+ ExcelHelper.ExcelData data = excelHelper.new ExcelData();
|
|
|
|
+ Map<String, CellRangeAddress> titleMap = new HashMap<>();
|
|
|
|
+ String dataStr = "";
|
|
|
|
+ if (startDate != null && endDate != null) {
|
|
|
|
+ dataStr = dateUtils.dateToStrFormat(startDate, "yyyy年MM月dd日") + "-" + dateUtils.dateToStrFormat(endDate, "yyyy年MM月dd日");
|
|
|
|
+ }
|
|
|
|
+ titleMap.put(dataStr + "就业驿站系统使用情况表", new CellRangeAddress(0, 0, 0, 5));
|
|
|
|
+ data.setColspanTitles(Arrays.asList(titleMap));
|
|
|
|
+ data.setTitles(Arrays.asList(new String[]{"行政区划", "驿站名", "驿站人员数量", "录入企业数", "收集岗位数", "登记求职人数"}));
|
|
|
|
+ List<List<Object>> rowsData = new ArrayList();
|
|
|
|
+ for (SystemDataCount dataCount : systemDataCount) {
|
|
|
|
+ List<Object> row = new ArrayList();
|
|
|
|
+ row.add(dataCount.getRegionName());
|
|
|
|
+ row.add(dataCount.getSiteName());
|
|
|
|
+ row.add(dataCount.getSiteUserCount());
|
|
|
|
+ row.add(dataCount.getCompanyCount());
|
|
|
|
+ row.add(dataCount.getPostCount());
|
|
|
|
+ row.add(dataCount.getJobUserCount());
|
|
|
|
+ rowsData.add(row);
|
|
|
|
+ }
|
|
|
|
+ data.setRows(rowsData);
|
|
|
|
+ // 设置单元格合并
|
|
|
|
+ List<CellRangeAddress> cellRangeAddressList = new ArrayList<>();
|
|
|
|
+ // 合计行合并
|
|
|
|
+ cellRangeAddressList.add(new CellRangeAddress(2, 2, 0, 1));
|
|
|
|
+ // 计算数据,将相同的县区进行合并
|
|
|
|
+ Map<String, Integer> regionCodeFirstIndex = new HashMap<>();
|
|
|
|
+ Map<String, Integer> regionCodeLastIndex = new HashMap<>();
|
|
|
|
+ for (int i = 0; i < systemDataCount.size(); i++) {
|
|
|
|
+ String regionCode = systemDataCount.get(i).getRegionCode();
|
|
|
|
+ if (!"合计".equals(regionCode)) { // 排除 '合计' 这个 regionCode
|
|
|
|
+ if (!regionCodeFirstIndex.containsKey(regionCode)) {
|
|
|
|
+ regionCodeFirstIndex.put(regionCode, i + 2); // 起始位置加2,避开标题行和合并统计
|
|
|
|
+ }
|
|
|
|
+ regionCodeLastIndex.put(regionCode, i + 2); // 结束位置加2
|
|
|
|
+ }
|
|
|
|
+ }
|
|
|
|
+ // 解析最终坐标
|
|
|
|
+ for (Map.Entry<String, Integer> entry : regionCodeFirstIndex.entrySet()) {
|
|
|
|
+ String regionCode = entry.getKey();
|
|
|
|
+ int firstIndex = entry.getValue();
|
|
|
|
+ int lastIndex = regionCodeLastIndex.get(regionCode);
|
|
|
|
+ // 创建合并区域
|
|
|
|
+ CellRangeAddress newMergedRegion = new CellRangeAddress(firstIndex, lastIndex, 0, 0);
|
|
|
|
+ cellRangeAddressList.add(newMergedRegion);
|
|
|
|
+ }
|
|
|
|
+ data.setCellRangeList(cellRangeAddressList);
|
|
|
|
+ excelHelper.exportExcel(response, data);
|
|
|
|
+ return null;
|
|
|
|
+ }
|
|
}
|
|
}
|