|  | @@ -1,23 +1,29 @@
 | 
	
		
			
				|  |  |  package com.yonge.cooleshow.biz.dal.service.impl;
 | 
	
		
			
				|  |  |  
 | 
	
		
			
				|  |  | +import com.yonge.cooleshow.biz.dal.dao.CourseScheduleDao;
 | 
	
		
			
				|  |  |  import com.yonge.cooleshow.biz.dal.dao.HomeDao;
 | 
	
		
			
				|  |  |  import com.yonge.cooleshow.biz.dal.dto.req.TotalReq;
 | 
	
		
			
				|  |  | -import com.yonge.cooleshow.biz.dal.enums.PeriodEnum;
 | 
	
		
			
				|  |  | +import com.yonge.cooleshow.biz.dal.enums.CourseScheduleEnum;
 | 
	
		
			
				|  |  | +import com.yonge.cooleshow.biz.dal.service.CourseScheduleService;
 | 
	
		
			
				|  |  |  import com.yonge.cooleshow.biz.dal.service.HomeService;
 | 
	
		
			
				|  |  | +import com.yonge.cooleshow.biz.dal.support.WrapperUtil;
 | 
	
		
			
				|  |  | +import com.yonge.cooleshow.biz.dal.vo.CourseHomeVo;
 | 
	
		
			
				|  |  |  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.base.exception.BizException;
 | 
	
		
			
				|  |  | -import io.swagger.annotations.ApiModelProperty;
 | 
	
		
			
				|  |  | +import org.apache.commons.collections.CollectionUtils;
 | 
	
		
			
				|  |  |  import org.springframework.beans.factory.annotation.Autowired;
 | 
	
		
			
				|  |  |  import org.springframework.stereotype.Service;
 | 
	
		
			
				|  |  |  
 | 
	
		
			
				|  |  |  import java.time.LocalDate;
 | 
	
		
			
				|  |  | -import java.time.LocalDateTime;
 | 
	
		
			
				|  |  | -import java.time.LocalTime;
 | 
	
		
			
				|  |  |  import java.time.temporal.TemporalAdjusters;
 | 
	
		
			
				|  |  | +import java.util.ArrayList;
 | 
	
		
			
				|  |  |  import java.util.List;
 | 
	
		
			
				|  |  | +import java.util.Map;
 | 
	
		
			
				|  |  | +import java.util.Objects;
 | 
	
		
			
				|  |  | +import java.util.function.Function;
 | 
	
		
			
				|  |  | +import java.util.stream.Collectors;
 | 
	
		
			
				|  |  |  
 | 
	
		
			
				|  |  |  /**
 | 
	
		
			
				|  |  |   * @Author: liweifan
 | 
	
	
		
			
				|  | @@ -27,6 +33,8 @@ import java.util.List;
 | 
	
		
			
				|  |  |  public class HomeServiceImpl implements HomeService {
 | 
	
		
			
				|  |  |      @Autowired
 | 
	
		
			
				|  |  |      private HomeDao baserMapper;
 | 
	
		
			
				|  |  | +    @Autowired
 | 
	
		
			
				|  |  | +    private CourseScheduleService courseScheduleService;
 | 
	
		
			
				|  |  |  
 | 
	
		
			
				|  |  |      @Override
 | 
	
		
			
				|  |  |      public HomeUserToDoNum getUserToDoNum() {
 | 
	
	
		
			
				|  | @@ -106,4 +114,86 @@ public class HomeServiceImpl implements HomeService {
 | 
	
		
			
				|  |  |          total.setInfoList(totalList);
 | 
	
		
			
				|  |  |          return HttpResponseResult.succeed(total);
 | 
	
		
			
				|  |  |      }
 | 
	
		
			
				|  |  | +
 | 
	
		
			
				|  |  | +    /**
 | 
	
		
			
				|  |  | +     * 获取首页课程数据
 | 
	
		
			
				|  |  | +     * <p>未完成  未开始&进行中
 | 
	
		
			
				|  |  | +     * <p>已完成  已完成课程
 | 
	
		
			
				|  |  | +     *
 | 
	
		
			
				|  |  | +     * @param param 传入参数
 | 
	
		
			
				|  |  | +     *              <p> - year 年
 | 
	
		
			
				|  |  | +     *              <p> - month 月
 | 
	
		
			
				|  |  | +     *              <p> - type 类型  PRACTICE陪练课  LIVE直播课
 | 
	
		
			
				|  |  | +     */
 | 
	
		
			
				|  |  | +    public CourseHomeVo queryCourseHomeData(Map<String, Object> param) {
 | 
	
		
			
				|  |  | +        CourseScheduleEnum.existCourseType(WrapperUtil.toStr(param, "type"), "课程类型参数错误");
 | 
	
		
			
				|  |  | +        Integer year = WrapperUtil.toInt(param, "year", "年份不能为空!");
 | 
	
		
			
				|  |  | +        Integer monthParam = WrapperUtil.toInt(param, "month");
 | 
	
		
			
				|  |  | +        //按月查询true  年查询false
 | 
	
		
			
				|  |  | +        boolean isYear = monthParam == 0;
 | 
	
		
			
				|  |  | +        int month = isYear ? 1 : monthParam;
 | 
	
		
			
				|  |  | +
 | 
	
		
			
				|  |  | +        LocalDate firstDate;
 | 
	
		
			
				|  |  | +        LocalDate endDate;
 | 
	
		
			
				|  |  | +        CourseHomeVo result = new CourseHomeVo();
 | 
	
		
			
				|  |  | +        CourseScheduleDao courseScheduleServiceDao = courseScheduleService.getDao();
 | 
	
		
			
				|  |  | +        firstDate = LocalDate.of(year, month, 1);
 | 
	
		
			
				|  |  | +        //获取开始时间
 | 
	
		
			
				|  |  | +        if (isYear) {
 | 
	
		
			
				|  |  | +            //查询当年最后一天
 | 
	
		
			
				|  |  | +            endDate = firstDate.with(TemporalAdjusters.lastDayOfYear());
 | 
	
		
			
				|  |  | +        } else {
 | 
	
		
			
				|  |  | +            //查询当月最后一天
 | 
	
		
			
				|  |  | +            endDate = firstDate.with(TemporalAdjusters.lastDayOfMonth());
 | 
	
		
			
				|  |  | +        }
 | 
	
		
			
				|  |  | +        param.put("startDate", firstDate);
 | 
	
		
			
				|  |  | +        param.put("endDate", endDate);
 | 
	
		
			
				|  |  | +
 | 
	
		
			
				|  |  | +        //查询数据
 | 
	
		
			
				|  |  | +        List<CourseHomeVo.CourseHomeInfoVo> courseYearInfoList;
 | 
	
		
			
				|  |  | +        if (isYear) {
 | 
	
		
			
				|  |  | +            courseYearInfoList = courseScheduleServiceDao.queryCourseHomeOfYear(param);
 | 
	
		
			
				|  |  | +        } else {
 | 
	
		
			
				|  |  | +            courseYearInfoList = courseScheduleServiceDao.queryCourseHomeOfMonth(param);
 | 
	
		
			
				|  |  | +        }
 | 
	
		
			
				|  |  | +        if (CollectionUtils.isEmpty(courseYearInfoList)) {
 | 
	
		
			
				|  |  | +            courseYearInfoList = new ArrayList<>();
 | 
	
		
			
				|  |  | +        }
 | 
	
		
			
				|  |  | +        Map<String, CourseHomeVo.CourseHomeInfoVo> collect = courseYearInfoList.stream()
 | 
	
		
			
				|  |  | +                .collect(Collectors.toMap(CourseHomeVo.CourseHomeInfoVo::getDate, Function.identity(), (key1, key2) -> key2));
 | 
	
		
			
				|  |  | +        //补全数据
 | 
	
		
			
				|  |  | +        while (firstDate.isBefore(endDate)) {
 | 
	
		
			
				|  |  | +            CourseHomeVo.CourseHomeInfoVo infoVo = collect.get(firstDate.toString());
 | 
	
		
			
				|  |  | +            if (Objects.isNull(infoVo)) {
 | 
	
		
			
				|  |  | +                infoVo = new CourseHomeVo.CourseHomeInfoVo();
 | 
	
		
			
				|  |  | +                if (isYear) {
 | 
	
		
			
				|  |  | +                    infoVo.setDate(firstDate.toString().substring(0, 7));
 | 
	
		
			
				|  |  | +                } else {
 | 
	
		
			
				|  |  | +                    infoVo.setDate(firstDate.toString());
 | 
	
		
			
				|  |  | +                }
 | 
	
		
			
				|  |  | +                infoVo.setDoneCount(0);
 | 
	
		
			
				|  |  | +                infoVo.setUndoneCount(0);
 | 
	
		
			
				|  |  | +                courseYearInfoList.add(infoVo);
 | 
	
		
			
				|  |  | +            } else {
 | 
	
		
			
				|  |  | +                if (isYear) {
 | 
	
		
			
				|  |  | +                    infoVo.setDate(firstDate.toString().substring(0, 7));
 | 
	
		
			
				|  |  | +                }
 | 
	
		
			
				|  |  | +            }
 | 
	
		
			
				|  |  | +            if (isYear) {
 | 
	
		
			
				|  |  | +                firstDate = firstDate.plusMonths(1L);
 | 
	
		
			
				|  |  | +            } else {
 | 
	
		
			
				|  |  | +                firstDate = firstDate.plusDays(1L);
 | 
	
		
			
				|  |  | +            }
 | 
	
		
			
				|  |  | +        }
 | 
	
		
			
				|  |  | +        result.setCourseHomeInfoList(courseYearInfoList);
 | 
	
		
			
				|  |  | +        //计算总数方法
 | 
	
		
			
				|  |  | +        Function<Function<CourseHomeVo.CourseHomeInfoVo, Integer>, Integer> reduceFunc = (c) -> result.getCourseHomeInfoList().stream()
 | 
	
		
			
				|  |  | +                .map(c)
 | 
	
		
			
				|  |  | +                .reduce(0, Integer::sum);
 | 
	
		
			
				|  |  | +        result.setTotalDoneCount(reduceFunc.apply(CourseHomeVo.CourseHomeInfoVo::getDoneCount));
 | 
	
		
			
				|  |  | +        result.setTotalUndoneCount(reduceFunc.apply(CourseHomeVo.CourseHomeInfoVo::getUndoneCount));
 | 
	
		
			
				|  |  | +        result.setTotalCount(result.getTotalDoneCount() + result.getTotalUndoneCount());
 | 
	
		
			
				|  |  | +        return result;
 | 
	
		
			
				|  |  | +    }
 | 
	
		
			
				|  |  | +
 | 
	
		
			
				|  |  |  }
 |