StatisticsController.java 22 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460
  1. package com.hz.employmentsite.controller.statistics;
  2. import com.hz.employmentsite.filter.exception.BaseResponse;
  3. import com.hz.employmentsite.filter.exception.RespGenerstor;
  4. import com.hz.employmentsite.services.service.statistics.StatisticsService;
  5. import com.hz.employmentsite.util.DateUtils;
  6. import com.hz.employmentsite.util.ExcelHelper;
  7. import com.hz.employmentsite.vo.statistics.HourNewAddCount;
  8. import com.hz.employmentsite.vo.statistics.RegionSystemDataCount;
  9. import com.hz.employmentsite.vo.statistics.SiteServiceCount;
  10. import com.hz.employmentsite.vo.statistics.SystemDataCount;
  11. import com.hz.employmentsite.vo.statistics.company.ModelCompanyCount;
  12. import com.hz.employmentsite.vo.statistics.jobUser.*;
  13. import org.apache.poi.ss.util.CellRangeAddress;
  14. import org.springframework.beans.factory.annotation.Autowired;
  15. import org.springframework.web.bind.annotation.GetMapping;
  16. import org.springframework.web.bind.annotation.RequestMapping;
  17. import org.springframework.web.bind.annotation.RequestParam;
  18. import org.springframework.web.bind.annotation.RestController;
  19. import javax.servlet.http.HttpServletResponse;
  20. import java.util.*;
  21. @RestController
  22. @RequestMapping(value = "/api/statistics")
  23. public class StatisticsController {
  24. @Autowired
  25. private StatisticsService statisticsService;
  26. @Autowired
  27. private ExcelHelper excelHelper;
  28. @Autowired
  29. private DateUtils dateUtils;
  30. /**
  31. * 查询指定时间段系统使用情况
  32. *
  33. * @param startDate 开始时间
  34. * @param endDate 结束时间
  35. * @return 数据统计VO类集合
  36. */
  37. @GetMapping("/systemApplyCount")
  38. public BaseResponse getSystemApplyCount(@RequestParam(value = "startDate", required = false) Date startDate,
  39. @RequestParam(value = "endDate", required = false) Date endDate) {
  40. List<SystemDataCount> systemDataCount = statisticsService.findSystemDataCount(startDate, endDate);
  41. return RespGenerstor.success(systemDataCount);
  42. }
  43. /**
  44. * 查询某月的系统使用情况
  45. *
  46. * @param dateStr
  47. * @return
  48. */
  49. @GetMapping("/monthSystemApplyCount")
  50. public BaseResponse findMonthSystemDataCount(@RequestParam String dateStr, @RequestParam(required = false) String regionCode,
  51. @RequestParam(required = false) String institutionID,
  52. @RequestParam(required = false) String siteID) {
  53. Map<String, List<RegionSystemDataCount>> result = statisticsService.findMonthSystemDataCount(dateStr, regionCode, institutionID, siteID);
  54. return RespGenerstor.success(result);
  55. }
  56. /**
  57. * 查询某年的系统使用情况
  58. *
  59. * @param year
  60. * @return
  61. */
  62. @GetMapping("/yearSystemApplyCount")
  63. public BaseResponse findYearSystemDataCount(@RequestParam(required = false) String year, @RequestParam(required = false) String regionCode,
  64. @RequestParam(required = false) String institutionID, @RequestParam(required = false) String siteID,
  65. @RequestParam(required = false) Date startDate, @RequestParam(required = false) Date endDate) {
  66. Map<String, List<RegionSystemDataCount>> result = statisticsService.findYearSystemDataCount(year, regionCode, institutionID, siteID, startDate, endDate);
  67. return RespGenerstor.success(result);
  68. }
  69. /**
  70. * 查询各个年龄段的求职人员数量
  71. */
  72. @GetMapping("/jobUserCountByAgeRange")
  73. public BaseResponse findJobUserCountByAgeRange(@RequestParam(required = false) String year,
  74. @RequestParam(required = false) String month,
  75. @RequestParam(required = false) Boolean isNotCity) {
  76. List<AgeRangeJobUserCount> result = statisticsService.findJobUserCountByAgeRange(year, month, isNotCity);
  77. return RespGenerstor.success(result);
  78. }
  79. /**
  80. * 查询各重点人员类别在各学历的分布情况
  81. */
  82. @GetMapping("/jobUserCountByPersonType")
  83. public BaseResponse findJobUserCountByPersonType(@RequestParam(required = false) String year, @RequestParam(required = false) String month) {
  84. List<PersonTypeJobUserCount> result = statisticsService.findJobUserCountByPersonType(year, month);
  85. return RespGenerstor.success(result);
  86. }
  87. /**
  88. * 查询各区县的普通失业人员与就业困难人员情况
  89. */
  90. @GetMapping("/jobUserByRegionAndDifficulty")
  91. public BaseResponse findJobUserByRegionAndDifficulty(@RequestParam(required = false) String year, @RequestParam(required = false) String month) {
  92. List<RegionJobUserCount> result = statisticsService.findJobUserByRegionAndDifficulty(year, month);
  93. return RespGenerstor.success(result);
  94. }
  95. /**
  96. * 查询各区县的已就业人员
  97. */
  98. @GetMapping("/employedJobUserCount")
  99. public BaseResponse findEmployedJobUserCount() {
  100. List<RegionJobUserCount> result = statisticsService.findEmployedJobUserCount();
  101. return RespGenerstor.success(result);
  102. }
  103. /**
  104. * 查询各区县的失业与已就业人员情况
  105. */
  106. @GetMapping("/empAndUnEmpJobUserCount")
  107. public BaseResponse findEmployedAndUnemployedCount() {
  108. List<RegionJobUserCount> result = statisticsService.findEmployedAndUnemployedCount();
  109. return RespGenerstor.success(result);
  110. }
  111. /**
  112. * 查询各驿站的业务数据情况
  113. */
  114. @GetMapping("/systemApplyCountBySite")
  115. public BaseResponse getSystemApplyCountBySite(@RequestParam(value = "startDate", required = false) Date startDate,
  116. @RequestParam(value = "endDate", required = false) Date endDate) {
  117. List<SystemDataCount> systemDataCount = statisticsService.findSystemDataCountBySite(startDate, endDate);
  118. return RespGenerstor.success(systemDataCount);
  119. }
  120. /**
  121. * 查询各区县的企业与岗位数量-数据大屏
  122. */
  123. @GetMapping("/companyAndPostCountByRegion")
  124. public BaseResponse getCompanyAndPostByRegion(@RequestParam(value = "startDate", required = false) Date startDate,
  125. @RequestParam(value = "endDate", required = false) Date endDate) {
  126. List<RegionSystemDataCount> companyAndPostByRegion = statisticsService.findCompanyAndPostByRegion(startDate, endDate);
  127. return RespGenerstor.success(companyAndPostByRegion);
  128. }
  129. /**
  130. * 查询各区县的企业规模情况-数据大屏
  131. */
  132. @GetMapping("/companyModelCount")
  133. public BaseResponse getCompanyModelCount() {
  134. List<ModelCompanyCount> regionCompanyModel = statisticsService.findRegionCompanyModel();
  135. return RespGenerstor.success(regionCompanyModel);
  136. }
  137. /**
  138. * 查询12种就业困难人员的分布情况
  139. */
  140. @GetMapping("/difficultyPersonTypeCount")
  141. public BaseResponse getDifficultyPersonTypeCount() {
  142. List<PersonTypeJobUserCount> result = statisticsService.findDifficultyPersonTypeCount();
  143. return RespGenerstor.success(result);
  144. }
  145. /**
  146. * 查询各县区的指定时间内求职人员与就业意向新增数量
  147. */
  148. @GetMapping("/jobUserAndJobHuntCount")
  149. public BaseResponse getJobUserAndJobHuntCount(@RequestParam(required = false) Date startDate,
  150. @RequestParam(required = false) Date endDate){
  151. List<RegionJobUserCount> result = statisticsService.findJobUserAndJobHuntCount(startDate, endDate);
  152. return RespGenerstor.success(result);
  153. }
  154. /**
  155. * 查询各区县的驿站与求职人员数量
  156. */
  157. @GetMapping("/siteAndSiteUserCount")
  158. public BaseResponse getSiteAndSiteUserCountByRegion() {
  159. List<RegionSystemDataCount> result = statisticsService.findSiteAndSiteUserCountByRegion();
  160. return RespGenerstor.success(result);
  161. }
  162. /**
  163. * 查询各驿站的求职人员数量
  164. */
  165. @GetMapping("/siteJobUserCount")
  166. public BaseResponse getSiteJobUserCount(@RequestParam(required = false) Integer jobStatus) {
  167. List<SiteJobUserCount> result = statisticsService.findSiteJobUserCount(jobStatus);
  168. return RespGenerstor.success(result);
  169. }
  170. /**
  171. * 查询就业困难人员的服务记录
  172. */
  173. @GetMapping("/difficultyUserServiceCount")
  174. public BaseResponse getDifficultyUserServiceCount() {
  175. DifficultyUserServiceCount result = statisticsService.findDifficultyUserServiceCount();
  176. return RespGenerstor.success(result);
  177. }
  178. /**
  179. * 查询某一天的24小时系统使用情况
  180. */
  181. @GetMapping("/hourSystemDataCount")
  182. public BaseResponse getOneDaySystemDataCount(@RequestParam(required = false) Date day) {
  183. List<HourNewAddCount> result = statisticsService.findOneDaySystemDataCount(day);
  184. return RespGenerstor.success(result);
  185. }
  186. /**
  187. * 查询各驿站的服务数量
  188. */
  189. @GetMapping("/siteServiceCount")
  190. public BaseResponse getSiteServiceCount(@RequestParam(required = false) Date startDate,
  191. @RequestParam(required = false) Date endDate) {
  192. List<SiteServiceCount> siteServiceCount = statisticsService.findSiteServiceCount(startDate, endDate);
  193. return RespGenerstor.success(siteServiceCount);
  194. }
  195. /**
  196. * 查询重点人员在各区县的分布情况
  197. */
  198. @GetMapping("/personTypeCountInRegion")
  199. public BaseResponse getPersonTypeCountInRegion(@RequestParam(required = false) Integer keyPersonTypeID, @RequestParam(required = false) Date startDate,
  200. @RequestParam(required = false) Date endDate, @RequestParam(required = false) String regionCode,
  201. @RequestParam(required = false)String siteID) {
  202. return RespGenerstor.success(statisticsService.findPersonTypeCountInRegion(keyPersonTypeID, startDate, endDate, regionCode, siteID));
  203. }
  204. /**
  205. * 查询重点人员在求职人员的性别,年龄,学历的分布情况
  206. */
  207. @GetMapping("/personTypeCountInJobUserData")
  208. public BaseResponse getPersonTypeCountInJobUserData(@RequestParam(required = false) Integer keyPersonTypeID, @RequestParam(required = false) Date startDate,
  209. @RequestParam(required = false) Date endDate, @RequestParam(required = false) String regionCode,
  210. @RequestParam(required = false)String siteID) {
  211. return RespGenerstor.success(statisticsService.findPersonTypeCountInJobUserData(keyPersonTypeID, startDate, endDate, regionCode, siteID));
  212. }
  213. /**
  214. * 查询各区县的各个规模的企业数量与走访企业次数
  215. */
  216. @GetMapping("/companyModelCompanyCountInRegion")
  217. public BaseResponse getRegionCompanyModelCompanyCount(@RequestParam(required = false) Date startDate, @RequestParam(required = false) Date endDate) {
  218. return RespGenerstor.success(statisticsService.findRegionCompanyModelCompanyCount(startDate, endDate));
  219. }
  220. /**
  221. * 查询各区县的各个规模的企业用工人数与岗位招聘人数
  222. */
  223. @GetMapping("/workSituationCountInRegion")
  224. public BaseResponse getRegionCompanyWorkSituationCount(@RequestParam(required = false) Date startDate, @RequestParam(required = false) Date endDate) {
  225. return RespGenerstor.success(statisticsService.findRegionCompanyWorkSituationCount(startDate, endDate));
  226. }
  227. /**
  228. * 查询各个行业各个规模的企业的岗位招聘人数情况
  229. */
  230. @GetMapping("/workSituationCountInIndustry")
  231. public BaseResponse getIndustryCompanyWorkSituationCount(@RequestParam(required = false) Date startDate, @RequestParam(required = false) Date endDate) {
  232. return RespGenerstor.success(statisticsService.findIndustryCompanyWorkSituationCount(startDate, endDate));
  233. }
  234. /**
  235. * 导出指定时间段的系统使用情况
  236. *
  237. * @param response 请求响应
  238. * @param startDate 开始时间
  239. * @param endDate 结束时间
  240. * @return
  241. */
  242. @GetMapping("/export/systemApplyCount")
  243. public BaseResponse exportSystemApplyCount(HttpServletResponse response,
  244. @RequestParam(value = "startDate", required = false) Date startDate,
  245. @RequestParam(value = "endDate", required = false) Date endDate) throws Exception {
  246. List<SystemDataCount> systemDataCount = statisticsService.findSystemDataCount(startDate, endDate);
  247. ExcelHelper.ExcelData data = excelHelper.new ExcelData();
  248. Map<String, CellRangeAddress> titleMap = new HashMap<>();
  249. String dataStr = "";
  250. if (startDate != null && endDate != null) {
  251. dataStr = dateUtils.dateToStrFormat(startDate, "yyyy年MM月dd日") + "-" + dateUtils.dateToStrFormat(endDate, "yyyy年MM月dd日");
  252. }
  253. titleMap.put(dataStr + "就业驿站系统使用情况表", new CellRangeAddress(0, 0, 0, 6));
  254. data.setColspanTitles(Arrays.asList(titleMap));
  255. data.setTitles(Arrays.asList("行政区划", "驿站名", "驿站人员数量", "录入企业数", "收集岗位条数","收集岗位个数", "登记求职人数"));
  256. List<List<Object>> rowsData = new ArrayList();
  257. for (SystemDataCount dataCount : systemDataCount) {
  258. List<Object> row = new ArrayList();
  259. row.add(dataCount.getRegionName());
  260. row.add(dataCount.getSiteName());
  261. row.add(dataCount.getSiteUserCount());
  262. row.add(dataCount.getCompanyCount());
  263. row.add(dataCount.getPostCount());
  264. row.add(dataCount.getPostRecruitCount());
  265. row.add(dataCount.getJobUserCount());
  266. rowsData.add(row);
  267. }
  268. data.setRows(rowsData);
  269. // 设置单元格合并
  270. List<CellRangeAddress> cellRangeAddressList = new ArrayList<>();
  271. // 合计行合并
  272. cellRangeAddressList.add(new CellRangeAddress(2, 2, 0, 1));
  273. // 计算数据,将相同的县区进行合并
  274. Map<String, Integer> regionCodeFirstIndex = new HashMap<>();
  275. Map<String, Integer> regionCodeLastIndex = new HashMap<>();
  276. for (int i = 0; i < systemDataCount.size(); i++) {
  277. String regionCode = systemDataCount.get(i).getRegionCode();
  278. if (!"合计".equals(regionCode)) { // 排除 '合计' 这个 regionCode
  279. if (!regionCodeFirstIndex.containsKey(regionCode)) {
  280. regionCodeFirstIndex.put(regionCode, i + 2); // 起始位置加2,避开标题行和合并统计
  281. }
  282. regionCodeLastIndex.put(regionCode, i + 2); // 结束位置加2
  283. }
  284. }
  285. // 解析最终坐标
  286. for (Map.Entry<String, Integer> entry : regionCodeFirstIndex.entrySet()) {
  287. String regionCode = entry.getKey();
  288. int firstIndex = entry.getValue();
  289. int lastIndex = regionCodeLastIndex.get(regionCode);
  290. // 创建合并区域
  291. CellRangeAddress newMergedRegion = new CellRangeAddress(firstIndex, lastIndex, 0, 0);
  292. cellRangeAddressList.add(newMergedRegion);
  293. }
  294. data.setCellRangeList(cellRangeAddressList);
  295. excelHelper.exportExcel(response, data);
  296. return null;
  297. }
  298. /**
  299. * 导出指定月份的系统使用情况
  300. *
  301. * @param response 请求响应
  302. * @param dateStr 查询月份
  303. * @return
  304. */
  305. @GetMapping("/export/monthSystemApplyCount")
  306. public BaseResponse exportMonthSystemApplyCount(HttpServletResponse response,
  307. @RequestParam String dateStr,
  308. @RequestParam(required = false) String regionCode,
  309. @RequestParam(required = false) String institutionID,
  310. @RequestParam(required = false) String siteID) throws Exception {
  311. Map<String, List<RegionSystemDataCount>> result = statisticsService.findMonthSystemDataCount(dateStr, regionCode, institutionID, siteID);
  312. ExcelHelper.ExcelData data = excelHelper.new ExcelData();
  313. // 设置标题区域
  314. Map<String, CellRangeAddress> titleMap = new HashMap<>();
  315. titleMap.put("项目", new CellRangeAddress(0, 1, 0, 0));
  316. // 子标题
  317. List<String> childrenTitle = new ArrayList<>(Arrays.asList(""));
  318. // Excel数据
  319. List<List<Object>> rowsData = new ArrayList();
  320. // 初始合并位置
  321. int firstCol = 1;
  322. // 汇总有"驿站人员数量"
  323. titleMap.put("汇总", new CellRangeAddress(0, 0, firstCol, firstCol + 4));
  324. setRSDCExcelData(result.get("汇总"), rowsData, true);
  325. // 填充子标题
  326. childrenTitle.addAll(Arrays.asList("驿站人员数量","录入企业数量","收集岗位条数","收集岗位个数","登记求职人数"));
  327. firstCol += 5;
  328. // 生成周数标题,周数标题没有驿站人员数量
  329. for (Map.Entry<String, List<RegionSystemDataCount>> entry : result.entrySet()) {
  330. String key = entry.getKey();
  331. if (!key.equals("汇总")){
  332. titleMap.put(key, new CellRangeAddress(0, 0, firstCol, firstCol + 3));
  333. // 填充子标题
  334. childrenTitle.addAll(Arrays.asList("录入企业数量","收集岗位条数","收集岗位个数","登记求职人数"));
  335. firstCol += 4;
  336. setRSDCExcelData(result.get(key), rowsData,false);
  337. }
  338. }
  339. data.setColspanTitles(Arrays.asList(titleMap));
  340. data.setTitles(childrenTitle);
  341. data.setRows(rowsData);
  342. excelHelper.exportExcel(response, data);
  343. return null;
  344. }
  345. /**
  346. * 导出指定年份的系统使用情况
  347. *
  348. * @param response 请求响应
  349. * @param year 查询月份
  350. * @return
  351. */
  352. @GetMapping("/export/yearSystemApplyCount")
  353. public BaseResponse exportYearSystemApplyCount(HttpServletResponse response,
  354. @RequestParam String year,
  355. @RequestParam(required = false) String regionCode,
  356. @RequestParam(required = false) String institutionID,
  357. @RequestParam(required = false) String siteID) throws Exception {
  358. Map<String, List<RegionSystemDataCount>> result = statisticsService.findYearSystemDataCount(year, regionCode, institutionID, siteID, null, null);
  359. ExcelHelper.ExcelData data = excelHelper.new ExcelData();
  360. // 设置标题区域
  361. Map<String, CellRangeAddress> titleMap = new HashMap<>();
  362. titleMap.put("项目", new CellRangeAddress(0, 1, 0, 0));
  363. // 子标题
  364. List<String> childrenTitle = new ArrayList<>(Arrays.asList(""));
  365. // Excel数据
  366. List<List<Object>> rowsData = new ArrayList();
  367. // 初始合并位置
  368. int firstCol = 1;
  369. // 汇总有"驿站人员数量"
  370. titleMap.put("汇总", new CellRangeAddress(0, 0, firstCol, firstCol + 4));
  371. setRSDCExcelData(result.get("汇总"), rowsData, true);
  372. // 填充子标题
  373. childrenTitle.addAll(Arrays.asList("驿站人员数量","录入企业数量","收集岗位条数","收集岗位个数","登记求职人数"));
  374. firstCol += 5;
  375. // 生成周数标题,周数标题没有驿站人员数量
  376. for (Map.Entry<String, List<RegionSystemDataCount>> entry : result.entrySet()) {
  377. String key = entry.getKey();
  378. if (!key.equals("汇总")){
  379. titleMap.put(key, new CellRangeAddress(0, 0, firstCol, firstCol + 3));
  380. // 填充子标题
  381. childrenTitle.addAll(Arrays.asList("录入企业数量","收集岗位条数","收集岗位个数","登记求职人数"));
  382. firstCol += 4;
  383. setRSDCExcelData(result.get(key), rowsData,false);
  384. }
  385. }
  386. data.setColspanTitles(Arrays.asList(titleMap));
  387. data.setTitles(childrenTitle);
  388. data.setRows(rowsData);
  389. excelHelper.exportExcel(response, data);
  390. return null;
  391. }
  392. /**
  393. * 系统月度使用情况Excel数据生成
  394. */
  395. public void setRSDCExcelData (List<RegionSystemDataCount> valueList, List<List<Object>> rowsData, Boolean isSiteUserCount){
  396. for (RegionSystemDataCount item : valueList) {
  397. boolean found = false;
  398. // 判断最终结果中是否已经生成过相同的县区数据,如有则追加,不新建
  399. for (List<Object> existingRow : rowsData) {
  400. if (existingRow.get(0).equals(item.getRegionName())) {
  401. if (isSiteUserCount){
  402. existingRow.add(item.getSiteUserCount());
  403. }
  404. existingRow.add(item.getCompanyCount());
  405. existingRow.add(item.getPostCount());
  406. existingRow.add(item.getPostRecruitCount());
  407. existingRow.add(item.getJobUserCount());
  408. found = true;
  409. break;
  410. }
  411. }
  412. // 没有则新建
  413. if (!found) {
  414. List<Object> row = new ArrayList<>();
  415. row.add(item.getRegionName());
  416. if (isSiteUserCount){
  417. row.add(item.getSiteUserCount());
  418. }
  419. row.add(item.getCompanyCount());
  420. row.add(item.getPostCount());
  421. row.add(item.getPostRecruitCount());
  422. row.add(item.getJobUserCount());
  423. rowsData.add(row);
  424. }
  425. }
  426. }
  427. }