ReportApiController.java 4.1 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112
  1. package com.goafanti.report.controller;
  2. import java.util.Calendar;
  3. import java.util.Date;
  4. import org.apache.commons.lang3.StringUtils;
  5. import org.springframework.beans.factory.annotation.Autowired;
  6. import org.springframework.web.bind.annotation.RequestMapping;
  7. import org.springframework.web.bind.annotation.RequestMethod;
  8. import org.springframework.web.bind.annotation.RequestParam;
  9. import org.springframework.web.bind.annotation.RestController;
  10. import com.goafanti.common.bo.Result;
  11. import com.goafanti.common.constant.AFTConstants;
  12. import com.goafanti.common.controller.BaseApiController;
  13. import com.goafanti.common.utils.DateUtils;
  14. import com.goafanti.report.enums.OrderBy;
  15. import com.goafanti.report.enums.SalesReportOrderField;
  16. import com.goafanti.report.service.SalesReportServiceImpl;
  17. @RestController
  18. @RequestMapping(value = "/api/admin/report")
  19. public class ReportApiController extends BaseApiController {
  20. @Autowired
  21. SalesReportServiceImpl reportService;
  22. @RequestMapping(value = "/sales/personal", method = RequestMethod.GET)
  23. public Result personal(@RequestParam(required = false) String orderField,
  24. @RequestParam(required = false) String order, @RequestParam(required = false) String pSize,
  25. @RequestParam(required = false) String pNo, @RequestParam(required = false) String date,
  26. @RequestParam(required = false) String depName, @RequestParam(required = false) String name,
  27. @RequestParam(required = false) String position) {
  28. Date startTime = null;
  29. try {
  30. startTime = StringUtils.isNotBlank(date) ? DateUtils.parseDate(date, AFTConstants.YYYYMMDDHHMMSS)
  31. : new Date();
  32. } catch (Exception e) {
  33. startTime = new Date();
  34. }
  35. if (StringUtils.isBlank(depName)) {
  36. depName = null;
  37. }
  38. if (StringUtils.isBlank(name)) {
  39. name = null;
  40. }
  41. if (StringUtils.isBlank(position)) {
  42. position = null;
  43. }
  44. Integer pageSize = StringUtils.isBlank(pSize) ? null : handlePageSize(pSize);
  45. Integer pageNo = StringUtils.isBlank(pNo) ? null : handlePageNo(pNo);
  46. if (pageSize != null && pageNo != null) {
  47. pageNo = (pageNo - 1) * pageSize;
  48. }
  49. return res().data(reportService.getPersonSalesReports(SalesReportOrderField.getField(orderField),
  50. OrderBy.getField(order), pageSize, pageNo, startTime, depName, name, position));
  51. }
  52. @RequestMapping(value = "/sales/total", method = RequestMethod.GET)
  53. public Result total(String date, @RequestParam(required = false) String depName,
  54. @RequestParam(required = false) String name, @RequestParam(required = false) String position) {
  55. Date startTime = null;
  56. try {
  57. startTime = DateUtils.parseDate(date, AFTConstants.YYYYMMDDHHMMSS);
  58. } catch (Exception e) {
  59. startTime = new Date();
  60. }
  61. if (StringUtils.isBlank(depName)) {
  62. depName = null;
  63. }
  64. if (StringUtils.isBlank(name)) {
  65. name = null;
  66. }
  67. if (StringUtils.isBlank(position)) {
  68. position = null;
  69. }
  70. return res().data(reportService.getReportTotal(startTime, depName, name, position));
  71. }
  72. @RequestMapping(value = "/sales/department", method = RequestMethod.GET)
  73. public Result department(String date) {
  74. Date startTime = null;
  75. try {
  76. startTime = DateUtils.parseDate(date, AFTConstants.YYYYMMDDHHMMSS);
  77. } catch (Exception e) {
  78. startTime = new Date();
  79. }
  80. return res().data(reportService.getDepartmentSalesReports(startTime));
  81. }
  82. @RequestMapping(value = "/sales/doStatistics", method = RequestMethod.GET)
  83. public Result doStatistics(String date) {
  84. Date dateTime = null;
  85. try {
  86. dateTime = DateUtils.parseDate(date, AFTConstants.YYYYMMDDHHMMSS);
  87. } catch (Exception e) {
  88. dateTime = new Date();
  89. }
  90. Calendar now = Calendar.getInstance();
  91. now.setTime(dateTime);
  92. now.set(Calendar.MILLISECOND, 0);
  93. now.set(Calendar.SECOND, 0);
  94. now.set(Calendar.MINUTE, 0);
  95. now.set(Calendar.HOUR_OF_DAY, 17);
  96. Date start = new Calendar.Builder()
  97. .setDate(now.get(Calendar.YEAR), now.get(Calendar.MONTH), now.get(Calendar.DAY_OF_MONTH) - 1)
  98. .setTimeOfDay(17, 0, 0, 0).build().getTime();
  99. // 统计从指定日期前一天的17点到指定日期17点的数据,算作改日期数据
  100. return res().data(reportService.insertDailyReports(start, now.getTime()));
  101. }
  102. }