package com.yonge.cooleshow.biz.dal.service.impl;

import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import com.yonge.cooleshow.biz.dal.dto.search.OrderSearch;
import com.yonge.cooleshow.biz.dal.entity.UserOrder;
import com.yonge.cooleshow.biz.dal.enums.GoodTypeEnum;
import com.yonge.cooleshow.biz.dal.service.UserOrderService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import com.yonge.cooleshow.biz.dal.entity.StudentTime;
import com.yonge.cooleshow.biz.dal.dao.StudentTimeDao;
import com.yonge.cooleshow.biz.dal.service.StudentTimeService;

import java.time.LocalDate;
import java.time.LocalDateTime;
import java.time.LocalTime;
import java.util.Date;
import java.util.List;


@Service
public class StudentTimeServiceImpl extends ServiceImpl<StudentTimeDao, StudentTime> implements StudentTimeService {
    private final static Logger log = LoggerFactory.getLogger(StudentTimeServiceImpl.class);
    @Autowired
    private UserOrderService userOrderService;
    @Override
    public void totalStudentTime() {
        LocalDate toDay = LocalDate.now();
        //查询未记录第一次购买时间的订单
        OrderSearch query = new OrderSearch();
        query.setStartTime(LocalDateTime.of(toDay, LocalTime.MIN));
        query.setEndTime(LocalDateTime.of(toDay, LocalTime.MAX));
        List<UserOrder> orderList = userOrderService.selectUnRecordTimeOrder(query);
        //查询需要统计的用户

    }

    @Override
    public StudentTime setTimeByGoodType(StudentTime studentTime, GoodTypeEnum goodType) {
        if (null == studentTime) {
            studentTime = new StudentTime();
        }
        if (GoodTypeEnum.VIP.equals(goodType) && null == studentTime.getFirstVipTime()) {
            studentTime.setFirstVipTime(new Date());
        }
        if (GoodTypeEnum.PRACTICE.equals(goodType) && null == studentTime.getFirstPracticeTime()) {
            studentTime.setFirstPracticeTime(new Date());
        }
        if (GoodTypeEnum.LIVE.equals(goodType) && null == studentTime.getFirstLiveTime()) {
            studentTime.setFirstLiveTime(new Date());
        }
        if (GoodTypeEnum.VIDEO.equals(goodType) && null == studentTime.getFirstVideoTime()) {
            studentTime.setFirstVideoTime(new Date());
        }
        if (GoodTypeEnum.MUSIC.equals(goodType) && null == studentTime.getFirstMusicTime()) {
            studentTime.setFirstMusicTime(new Date());
        }
        return studentTime;
    }
}