|
@@ -2,17 +2,20 @@ package com.yonge.cooleshow.biz.dal.service.impl;
|
|
|
|
|
|
import com.yonge.cooleshow.biz.dal.dao.HomeDao;
|
|
|
import com.yonge.cooleshow.biz.dal.dto.req.TotalReq;
|
|
|
-import com.yonge.cooleshow.biz.dal.enums.TimeTypeEnum;
|
|
|
+import com.yonge.cooleshow.biz.dal.enums.PeriodEnum;
|
|
|
import com.yonge.cooleshow.biz.dal.service.HomeService;
|
|
|
import com.yonge.cooleshow.biz.dal.vo.res.HomeTotalStudent;
|
|
|
import com.yonge.cooleshow.biz.dal.vo.res.HomeTotalTeacher;
|
|
|
import com.yonge.cooleshow.biz.dal.vo.res.HomeUserToDoNum;
|
|
|
import com.yonge.cooleshow.common.entity.HttpResponseResult;
|
|
|
-import com.yonge.toolset.utils.date.DateUtil;
|
|
|
+import com.yonge.cooleshow.common.exception.BizException;
|
|
|
import org.springframework.beans.factory.annotation.Autowired;
|
|
|
import org.springframework.stereotype.Service;
|
|
|
|
|
|
-import java.util.Calendar;
|
|
|
+import java.time.LocalDate;
|
|
|
+import java.time.LocalDateTime;
|
|
|
+import java.time.LocalTime;
|
|
|
+import java.time.temporal.TemporalAdjusters;
|
|
|
import java.util.List;
|
|
|
|
|
|
/**
|
|
@@ -34,26 +37,30 @@ public class HomeServiceImpl implements HomeService {
|
|
|
}
|
|
|
|
|
|
@Override
|
|
|
- public HttpResponseResult<HomeTotalTeacher> totalTeacher(TotalReq totalReq) {
|
|
|
+ public HttpResponseResult<HomeTotalTeacher> totalTeacher(TotalReq query) {
|
|
|
//参数处理
|
|
|
- Calendar calendar = Calendar.getInstance();
|
|
|
- if (TimeTypeEnum.MONTH.equals(totalReq.getTimeType())) {
|
|
|
- String[] classDateSp = totalReq.getDateTime().split("-");
|
|
|
- calendar.set(Integer.parseInt(classDateSp[0]), Integer.parseInt(classDateSp[1])-1, 1, 0, 0, 0);
|
|
|
- totalReq.setStartTime(calendar.getTime());
|
|
|
- totalReq.setEndTime(DateUtil.dayEnd(DateUtil.getLastDayOfMonth(calendar.getTime())));
|
|
|
- } else if (TimeTypeEnum.YEAR.equals(totalReq.getTimeType())) {
|
|
|
- calendar.set(Integer.parseInt(totalReq.getDateTime()), 1, 1, 0, 0, 0);
|
|
|
- totalReq.setStartTime(calendar.getTime());
|
|
|
+ try {
|
|
|
+ LocalDateTime firstDay;
|
|
|
+ LocalDateTime lastDay;
|
|
|
+ if (PeriodEnum.YEAR.equals(query.getTimeType())) {
|
|
|
+ LocalDate date = LocalDate.of(Integer.parseInt(query.getDateTime()), 1, 1);
|
|
|
+ firstDay = LocalDateTime.of(date.with(TemporalAdjusters.firstDayOfYear()), LocalTime.MIN);
|
|
|
+ lastDay = LocalDateTime.of(date.with(TemporalAdjusters.lastDayOfYear()), LocalTime.MAX);
|
|
|
+ } else {
|
|
|
+ String[] classDateSp = query.getDateTime().split("-");
|
|
|
+ LocalDate date = LocalDate.of(Integer.parseInt(classDateSp[0]), Integer.parseInt(classDateSp[1]), 1);
|
|
|
|
|
|
- calendar.set(Integer.parseInt(totalReq.getDateTime()), 12, 1, 0, 0, 0);
|
|
|
- totalReq.setEndTime(DateUtil.dayEnd(DateUtil.getLastDayOfMonth(calendar.getTime())));
|
|
|
- } else {
|
|
|
- return HttpResponseResult.failed("参数异常");
|
|
|
+ firstDay = LocalDateTime.of(date.with(TemporalAdjusters.firstDayOfMonth()), LocalTime.MIN);
|
|
|
+ lastDay = LocalDateTime.of(date.with(TemporalAdjusters.lastDayOfMonth()), LocalTime.MAX);
|
|
|
+ }
|
|
|
+ query.setStartTime(firstDay);
|
|
|
+ query.setEndTime(lastDay);
|
|
|
+ } catch (Exception e) {
|
|
|
+ throw new BizException("查询时间格式不正确 [" + query.getDateTime() + "]");
|
|
|
}
|
|
|
|
|
|
//统计查询
|
|
|
- List<HomeTotalTeacher> totalList = baserMapper.totalTeacher(totalReq.getTimeType().getCode(), totalReq);
|
|
|
+ List<HomeTotalTeacher> totalList = baserMapper.totalTeacher(query.getTimeType().getCode(), query);
|
|
|
Integer registerNum = 0;
|
|
|
Integer entryNum = 0;
|
|
|
Integer liveNum = 0;
|
|
@@ -79,24 +86,29 @@ public class HomeServiceImpl implements HomeService {
|
|
|
}
|
|
|
|
|
|
@Override
|
|
|
- public HttpResponseResult<HomeTotalStudent> totalStudent(TotalReq totalReq) {
|
|
|
+ public HttpResponseResult<HomeTotalStudent> totalStudent(TotalReq query) {
|
|
|
//参数处理
|
|
|
- Calendar calendar = Calendar.getInstance();
|
|
|
- if (TimeTypeEnum.MONTH.equals(totalReq.getTimeType())) {
|
|
|
- String[] classDateSp = totalReq.getDateTime().split("-");
|
|
|
- calendar.set(Integer.parseInt(classDateSp[0]), Integer.parseInt(classDateSp[1])-1, 1, 0, 0, 0);
|
|
|
- totalReq.setStartTime(calendar.getTime());
|
|
|
- totalReq.setEndTime(DateUtil.dayEnd(DateUtil.getLastDayOfMonth(calendar.getTime())));
|
|
|
- } else if (TimeTypeEnum.YEAR.equals(totalReq.getTimeType())) {
|
|
|
- calendar.set(Integer.parseInt(totalReq.getDateTime()), 1, 1, 0, 0, 0);
|
|
|
- totalReq.setStartTime(calendar.getTime());
|
|
|
+ try {
|
|
|
+ LocalDateTime firstDay;
|
|
|
+ LocalDateTime lastDay;
|
|
|
+ if (PeriodEnum.YEAR.equals(query.getTimeType())) {
|
|
|
+ LocalDate date = LocalDate.of(Integer.parseInt(query.getDateTime()), 1, 1);
|
|
|
+ firstDay = LocalDateTime.of(date.with(TemporalAdjusters.firstDayOfYear()), LocalTime.MIN);
|
|
|
+ lastDay = LocalDateTime.of(date.with(TemporalAdjusters.lastDayOfYear()), LocalTime.MAX);
|
|
|
+ } else {
|
|
|
+ String[] classDateSp = query.getDateTime().split("-");
|
|
|
+ LocalDate date = LocalDate.of(Integer.parseInt(classDateSp[0]), Integer.parseInt(classDateSp[1]), 1);
|
|
|
|
|
|
- calendar.set(Integer.parseInt(totalReq.getDateTime()), 12, 1, 0, 0, 0);
|
|
|
- totalReq.setEndTime(DateUtil.dayEnd(DateUtil.getLastDayOfMonth(calendar.getTime())));
|
|
|
- } else {
|
|
|
- return HttpResponseResult.failed("参数异常");
|
|
|
+ firstDay = LocalDateTime.of(date.with(TemporalAdjusters.firstDayOfMonth()), LocalTime.MIN);
|
|
|
+ lastDay = LocalDateTime.of(date.with(TemporalAdjusters.lastDayOfMonth()), LocalTime.MAX);
|
|
|
+ }
|
|
|
+ query.setStartTime(firstDay);
|
|
|
+ query.setEndTime(lastDay);
|
|
|
+ } catch (Exception e) {
|
|
|
+ throw new BizException("查询时间格式不正确 [" + query.getDateTime() + "]");
|
|
|
}
|
|
|
- List<HomeTotalStudent> totalList = baserMapper.totalStudent(totalReq.getTimeType().getCode(), totalReq);
|
|
|
+
|
|
|
+ List<HomeTotalStudent> totalList = baserMapper.totalStudent(query.getTimeType().getCode(), query);
|
|
|
Integer registerNum = 0;
|
|
|
Integer vipNum = 0;
|
|
|
Integer courseNum = 0;
|
|
@@ -105,7 +117,7 @@ public class HomeServiceImpl implements HomeService {
|
|
|
for (HomeTotalStudent totalStudent : totalList) {
|
|
|
totalStudent.setRegisterNum(null == totalStudent.getRegisterNum() ? 0 : totalStudent.getRegisterNum());
|
|
|
totalStudent.setVipNum(null == totalStudent.getVipNum() ? 0 : totalStudent.getVipNum());
|
|
|
- totalStudent.setCourseNum(null == totalStudent.getCourseNum() ? 0 :totalStudent.getCourseNum());
|
|
|
+ totalStudent.setCourseNum(null == totalStudent.getCourseNum() ? 0 : totalStudent.getCourseNum());
|
|
|
totalStudent.setShoppingNum(null == totalStudent.getShoppingNum() ? 0 : totalStudent.getShoppingNum());
|
|
|
|
|
|
registerNum += totalStudent.getRegisterNum();
|