| 123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112 |
- package com.goafanti.report.controller;
- import java.util.Calendar;
- import java.util.Date;
- import org.apache.commons.lang3.StringUtils;
- import org.springframework.beans.factory.annotation.Autowired;
- import org.springframework.web.bind.annotation.RequestMapping;
- import org.springframework.web.bind.annotation.RequestMethod;
- import org.springframework.web.bind.annotation.RequestParam;
- import org.springframework.web.bind.annotation.RestController;
- import com.goafanti.common.bo.Result;
- import com.goafanti.common.constant.AFTConstants;
- import com.goafanti.common.controller.BaseApiController;
- import com.goafanti.common.utils.DateUtils;
- import com.goafanti.report.enums.OrderBy;
- import com.goafanti.report.enums.SalesReportOrderField;
- import com.goafanti.report.service.SalesReportServiceImpl;
- @RestController
- @RequestMapping(value = "/api/admin/report")
- public class ReportApiController extends BaseApiController {
- @Autowired
- SalesReportServiceImpl reportService;
- @RequestMapping(value = "/sales/personal", method = RequestMethod.GET)
- public Result personal(@RequestParam(required = false) String orderField,
- @RequestParam(required = false) String order, @RequestParam(required = false) String pSize,
- @RequestParam(required = false) String pNo, @RequestParam(required = false) String date,
- @RequestParam(required = false) String depName, @RequestParam(required = false) String name,
- @RequestParam(required = false) String position) {
- Date startTime = null;
- try {
- startTime = StringUtils.isNotBlank(date) ? DateUtils.parseDate(date, AFTConstants.YYYYMMDDHHMMSS)
- : new Date();
- } catch (Exception e) {
- startTime = new Date();
- }
- if (StringUtils.isBlank(depName)) {
- depName = null;
- }
- if (StringUtils.isBlank(name)) {
- name = null;
- }
- if (StringUtils.isBlank(position)) {
- position = null;
- }
- Integer pageSize = StringUtils.isBlank(pSize) ? null : handlePageSize(pSize);
- Integer pageNo = StringUtils.isBlank(pNo) ? null : handlePageNo(pNo);
- if (pageSize != null && pageNo != null) {
- pageNo = (pageNo - 1) * pageSize;
- }
- return res().data(reportService.getPersonSalesReports(SalesReportOrderField.getField(orderField),
- OrderBy.getField(order), pageSize, pageNo, startTime, depName, name, position));
- }
- @RequestMapping(value = "/sales/total", method = RequestMethod.GET)
- public Result total(String date, @RequestParam(required = false) String depName,
- @RequestParam(required = false) String name, @RequestParam(required = false) String position) {
- Date startTime = null;
- try {
- startTime = DateUtils.parseDate(date, AFTConstants.YYYYMMDDHHMMSS);
- } catch (Exception e) {
- startTime = new Date();
- }
- if (StringUtils.isBlank(depName)) {
- depName = null;
- }
- if (StringUtils.isBlank(name)) {
- name = null;
- }
- if (StringUtils.isBlank(position)) {
- position = null;
- }
- return res().data(reportService.getReportTotal(startTime, depName, name, position));
- }
- @RequestMapping(value = "/sales/department", method = RequestMethod.GET)
- public Result department(String date) {
- Date startTime = null;
- try {
- startTime = DateUtils.parseDate(date, AFTConstants.YYYYMMDDHHMMSS);
- } catch (Exception e) {
- startTime = new Date();
- }
- return res().data(reportService.getDepartmentSalesReports(startTime));
- }
- @RequestMapping(value = "/sales/doStatistics", method = RequestMethod.GET)
- public Result doStatistics(String date) {
- Date dateTime = null;
- try {
- dateTime = DateUtils.parseDate(date, AFTConstants.YYYYMMDDHHMMSS);
- } catch (Exception e) {
- dateTime = new Date();
- }
- Calendar now = Calendar.getInstance();
- now.setTime(dateTime);
- now.set(Calendar.MILLISECOND, 0);
- now.set(Calendar.SECOND, 0);
- now.set(Calendar.MINUTE, 0);
- now.set(Calendar.HOUR_OF_DAY, 17);
- Date start = new Calendar.Builder()
- .setDate(now.get(Calendar.YEAR), now.get(Calendar.MONTH), now.get(Calendar.DAY_OF_MONTH) - 1)
- .setTimeOfDay(17, 0, 0, 0).build().getTime();
- // 统计从指定日期前一天的17点到指定日期17点的数据,算作改日期数据
- return res().data(reportService.insertDailyReports(start, now.getTime()));
- }
- }
|