//package com.cyksj.task;
//
//import cn.hutool.core.date.DateTime;
//import cn.hutool.core.date.DateUtil;
//import com.baomidou.mybatisplus.core.toolkit.Wrappers;
//import com.cyksj.common.constant.Constant;
//import com.cyksj.common.constant.PointsRecordConst;
//import com.cyksj.mapper.manage.statistics.SignStatisticsDataMapper;
//import com.cyksj.mapper.market.sign.SignUserMapper;
//import com.cyksj.mapper.market.sign.UserPointsRecordMapper;
//import com.cyksj.mapper.market.task.TaskFollowPlatVerifyMapper;
//import com.cyksj.mapper.market.task.TaskUserCompleteRecordMapper;
//import com.cyksj.model.entity.SignStatisticsData;
//import com.cyksj.model.entity.SignUser;
//import com.cyksj.model.entity.TaskFollowPlatVerify;
//import com.cyksj.model.entity.TaskUserCompleteRecord;
//import com.cyksj.service.market.MarketFrontService;
//import lombok.RequiredArgsConstructor;
//import lombok.extern.slf4j.Slf4j;
//import org.springframework.scheduling.annotation.Scheduled;
//import org.springframework.stereotype.Component;
//
//import java.util.Date;
//import java.util.List;
//
///*
// *项目名: netflix
// *文件名: SignStatisticsDataScheduler
// *创建者: JavaZou
// *创建时间:2022/12/27 18:27
// */
//@Component
//@Slf4j
//@RequiredArgsConstructor
//public class SignStatisticsDataScheduler {
//	private final SignStatisticsDataMapper signStatisticsDataMapper;
//
//	private final UserPointsRecordMapper userPointsRecordMapper;
//
//	private final SignUserMapper signUserMapper;
//
//	private final TaskFollowPlatVerifyMapper taskFollowPlatVerifyMapper;
//
//	private final TaskUserCompleteRecordMapper taskUserCompleteRecordMapper;
//
//	private final MarketFrontService marketFrontService;
//
//	@Scheduled(cron = "0 0 0 * * ?")
//	public void signStatisticsData() {
//		Date thisZeroDate = DateUtil.beginOfDay(DateTime.now());
//		Date yesZeroDate = DateTime.of(thisZeroDate.getTime() - Constant.DAY_MILLS);
//		SignStatisticsData signStatisticsData = new SignStatisticsData();
//		//今日签到人数
//		Integer todayNumOfSign = signUserMapper.selectCount(Wrappers.lambdaQuery(SignUser.class)
//				.between(SignUser::getUpdateTime, yesZeroDate, thisZeroDate));
//		signStatisticsData.setTodayNumOfSign(todayNumOfSign);
//
//		//今日发放积分
//		Integer todayNumOfPoints = userPointsRecordMapper.getTodayNumOfPoints(yesZeroDate, thisZeroDate);
//
//		signStatisticsData.setTodayNumOfPoints(todayNumOfPoints);
//
//		//累计发放积分
//		Integer sumOfPoints = userPointsRecordMapper.getSumOfPoints();
//
//		signStatisticsData.setSumOfPoints(sumOfPoints);
//
//		//今日使用积分
//		Integer todayUseOfPoints = userPointsRecordMapper.getTodayUseOfPoints(yesZeroDate, thisZeroDate);
//		signStatisticsData.setTodayUseOfPoints(-todayUseOfPoints);
//
//		//累计使用积分
//		Integer sumUseOfPoints = userPointsRecordMapper.getSumUseOfPoints();
//		signStatisticsData.setSumUseOfPoints(-sumUseOfPoints);
//
//		//今日抽奖次数
//		Integer todayNumOfLottery = userPointsRecordMapper.getTodayNumOfLottery(PointsRecordConst.POINTS_LOTTERY, yesZeroDate, thisZeroDate);
//		signStatisticsData.setTodayNumOfLottery(todayNumOfLottery);
//
//		//连签2天
//		Integer sign2Day = userPointsRecordMapper.getSignDayByCondition(2, yesZeroDate, thisZeroDate);
//		signStatisticsData.setT2(sign2Day);
//
//		//连签3天
//		Integer sign3Day = userPointsRecordMapper.getSignDayByCondition(3, yesZeroDate, thisZeroDate);
//		signStatisticsData.setT3(sign3Day);
//
//		//连签4天
//		Integer sign4Day = userPointsRecordMapper.getSignDayByCondition(4, yesZeroDate, thisZeroDate);
//		signStatisticsData.setT4(sign4Day);
//
//		//连签5天
//		Integer sign5Day = userPointsRecordMapper.getSignDayByCondition(5, yesZeroDate, thisZeroDate);
//		signStatisticsData.setT5(sign5Day);
//
//		//连签6天
//		Integer sign6Day = userPointsRecordMapper.getSignDayByCondition(6, yesZeroDate, thisZeroDate);
//		signStatisticsData.setT6(sign6Day);
//
//		//连签7天
//		Integer sign7Day = userPointsRecordMapper.getSignDayByCondition(7, yesZeroDate, thisZeroDate);
//		signStatisticsData.setT7(sign7Day);
//
//		signStatisticsData.setStatisticsDate(yesZeroDate);
//		signStatisticsDataMapper.insert(signStatisticsData);
//	}
//
//	/**
//	 * 关注任务3天未审核 自动审核成功
//	 */
//	@Scheduled(cron = "0 30 0 * * ?")
//	public void autoVerifySuccess() {
//		DateTime now = DateTime.now();
//		DateTime threeBefore = DateUtil.offsetDay(now, -3);
//		List<TaskFollowPlatVerify> taskFollowPlatVerifies = taskFollowPlatVerifyMapper.selectList(Wrappers.lambdaQuery(TaskFollowPlatVerify.class)
//				.le(TaskFollowPlatVerify::getCreatedTime, threeBefore)
//				.eq(TaskFollowPlatVerify::getStatus, TaskFollowPlatVerify.Status.verifying));
//		taskFollowPlatVerifies.forEach(data->{
//			data.setStatus(TaskFollowPlatVerify.Status.success);
//			TaskUserCompleteRecord record = taskUserCompleteRecordMapper.selectOne(Wrappers.lambdaQuery(TaskUserCompleteRecord.class)
//					.eq(TaskUserCompleteRecord::getUserId, data.getUserId())
//					.eq(TaskUserCompleteRecord::getTaskId, data.getTaskId())
//					.last("limit 1"));
//			record.setStatus(TaskUserCompleteRecord.Status.received);
//			taskUserCompleteRecordMapper.updateById(record);
//			taskFollowPlatVerifyMapper.updateById(data);
//			marketFrontService.pointsRecord(record.getUserId(), record.getPoints(), PointsRecordConst.TASK, false);
//		});
//	}
//}
