package com.ym.mec.web.controller;

import com.ym.mec.biz.event.source.CourseEventSource;
import com.ym.mec.biz.service.*;
import com.ym.mec.common.controller.BaseController;
import com.ym.mec.common.redis.service.RedisCache;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

import java.util.ArrayList;
import java.util.Arrays;
import java.util.Date;

@RequestMapping("task")
@RestController
public class TaskController extends BaseController {

	@Autowired
	private MusicGroupStudentFeeService musicGroupStudentFeeService;

	@Autowired
	private VipGroupService vipGroupService;

	@Autowired
	private CourseScheduleService courseScheduleService;

	@Autowired
	private TeacherAttendanceService teacherAttendanceService;

	@Autowired
	private CourseScheduleTeacherSalaryService courseScheduleTeacherSalaryService;

	@Autowired
	private StudentCourseHomeworkService studentCourseHomeworkService;

	@Autowired
	private CourseHomeworkService courseHomeworkService;

	@Autowired
	private StudentPaymentOrderService studentPaymentOrderService;

	@Autowired
	private TenantPaymentOrderService tenantPaymentOrderService;

	@Autowired
	private TeacherCourseStatisticsService teacherCourseStatisticsService;

	@Autowired
	private PracticeGroupService practiceGroupService;

	@Autowired
	private CourseScheduleEvaluateService courseScheduleEvaluateService;

	@Autowired
	private CourseReviewService courseReviewService;

	@Autowired
	private CoursesGroupService coursesGroupService;

	@Autowired
	private ExtracurricularExercisesService extracurricularExercisesService;
	
	@Autowired
	private StudentService studentService;
	
	@Autowired
	private MusicGroupPaymentCalenderService musicGroupPaymentCalenderService;

	@Autowired
	private MusicGroupPaymentCalenderDetailService musicGroupPaymentCalenderDetailService;

	@Autowired
	private StudentServeService studentServeService;

	@Autowired
	private OperatingReportService operatingReportService;

	@Autowired
	private GoodsService goodsService;
	@Autowired
	private StudentGoodsSellService studentGoodsSellService;
	@Autowired
	private SysMessageService sysMessageService;

	@Autowired
	private CourseEventSource courseEventSource;
	@Autowired
	private RedisCache<String, Object> redisCache;
	@Autowired
	private IndexBaseMonthDataService indexBaseMonthDataService;

	@GetMapping(value = "/autoAffirmReceiveTask")
	// 自动确认收货
	public void affirmReceive(){
		studentGoodsSellService.affirmReceive(null);
	}

	@GetMapping(value = "/pushWaitSendMessageTask")
	// 每天9点推送前一天22点之后的推送消息
	public void pushWaitSendMessageTask(){
		sysMessageService.pushWaitSendMessageTask();
	}

	@GetMapping(value = "/repertoryWarn")
	// 商品库存预警
	public void repertoryWarn(){
		goodsService.repertoryWarn();
	}

	@GetMapping(value = "/refreshUserMusicGroupPaymentStatusTask")
	// 刷新学员乐团付费状态
	public void refreshUserMusicGroupPaymentStatusTask(){
		musicGroupPaymentCalenderDetailService.refreshUserMusicGroupPaymentStatusTask();
	}

	@GetMapping("/refreshPaymentFeeStatus")
	// 刷新付费状态
	public void refreshPaymentFeeStatus() {
		musicGroupStudentFeeService.refreshPaymentFeeStatus();
	}

	@GetMapping("/vipGroupAwardedMonthlyRewards")
	// vip课月度奖励
	public void vipGroupAwardedMonthlyRewards() {
		vipGroupService.awardedMonthlyRewards();
	}

	@GetMapping("/vipGroupTeacherSalarySettlement")
	// vip课课酬结算
	public void vipGroupTeacherSalarySettlement() {
		courseScheduleTeacherSalaryService.teacherSalarySettlement();
		redisCache.getRedisTemplate().opsForSet().add(CourseScheduleTeacherSalaryService.TASK_KEY, "VIP");
		courseScheduleTeacherSalaryService.salaryMark();
	}

	@GetMapping("/practiceTeacherSalarySettlement")
	// 陪练课课酬结算
	public void practiceTeacherSalarySettlement() {
		courseScheduleTeacherSalaryService.practiceTeacherSalarySettlement();
		redisCache.getRedisTemplate().opsForSet().add(CourseScheduleTeacherSalaryService.TASK_KEY, "PRACTICE");
		courseScheduleTeacherSalaryService.salaryMark();
	}

	// 乐团课课酬结算
	@GetMapping("/musicGroupTeacherSalarySettlement")
	public void musicGroupTeacherSalarySettlement() {
		courseScheduleTeacherSalaryService.musicGroupTeacherSalarySettlement();
		redisCache.getRedisTemplate().opsForSet().add(CourseScheduleTeacherSalaryService.TASK_KEY, "MUSIC");
		courseScheduleTeacherSalaryService.salaryMark();
	}

	@GetMapping("/updateCourseScheduleToOverStatus")
	// 更新课程状态至已结束
	public void updateCourseScheduleToOverStatus() {
		courseScheduleService.updateCourseScheduleToOverStatus();
		courseScheduleService.updateCourseScheduleToUnderway();
		courseEventSource.courseStatusChange(null);
	}

	@GetMapping("/updateVipGroupToFinishedStatus")
	// 更新VIP课程状态至已结束
	public void updateVipGroupToFinishedStatus() {
		vipGroupService.updateVipGroupStatusToFinished();
	}

	@GetMapping("/stopVipGroupWithNoCreate")
	// 取消达到报名时间未达到报名人数的vip课
	public void stopVipGroupWithNoCreate() {
		vipGroupService.stopVipGroupWithNoCreate();
	}

	@GetMapping("/pushNoSignOutMessage")
	// 推送未签退消息提醒
	public void pushNoSignOutMessage() {
		teacherAttendanceService.pushNoSignOutMessage();
	}

	@GetMapping("/studentCoursesScheduleRemind")
	// 学生有课提醒
	public void studentCoursesScheduleRemind() {
		// courseScheduleService.studentCoursesScheduleRemind();
	}

	@GetMapping("/studentSignInRemind")
	// 学生上课提醒
	public void studentSignInRemind() {
		courseScheduleService.studentSignInRemind();
	}

	@GetMapping("/studentHomeworkRemind")
	// 学生作业提醒
	public void studentHomeworkRemind() {
		studentCourseHomeworkService.homeworkRemind();
	}

	@GetMapping("/teacherCoursesScheduleRemind")
	// 老师有课提醒
	public void teacherCoursesScheduleRemind() {
		courseScheduleService.teacherCoursesScheduleRemind();
	}

	@GetMapping("/teacherSignInRemind")
	// 老师上课提醒
	public void teacherSignInRemind() {
		// courseScheduleService.teacherSignInRemind();
	}

	@GetMapping("/homeworkNoReplyRemind")
	// 老师未回复作业提醒
	public void homeworkNoReplyRemind() {
		courseHomeworkService.homeworkNoReplyRemind();
	}

	// 查询订单状态
	@GetMapping("/queryOrderStatus")
	public void queryOrderStatus() throws Exception {
		try {
			studentPaymentOrderService.queryOrderStatus();
		} catch (Exception e) {
			e.printStackTrace();
		}
		tenantPaymentOrderService.queryOrderStatusFromRemote();
	}

	// 统计老师课酬
	@GetMapping("/teacherCourseStatistic")
	public void teacherCourseStatisticsService() throws Exception {
		teacherCourseStatisticsService.teacherCourseStatistic();
	}

	// 更新历史陪练课至已结束
	@GetMapping("/updateHistoryPracticeGroupStatus")
	public void updateHistoryPracticeGroupStatus() {
		practiceGroupService.updateHistoryPracticeGroupStatus();
	}

	// 练习报告定时推送
	@GetMapping("/pushStudyReport")
	public void pushStudyReport() {
		practiceGroupService.pushStudyReport(null, "JIGUANG");
	}

	// 新增待填写月报定时推送(推送老师)
	@GetMapping("/pushNeedPostReport")
	public void pushNeedPostReport() {
		courseScheduleEvaluateService.pushNeedPostReport();
	}

	// 定时预生成待提交月报
	@GetMapping("/createEvaluate")
	public void createEvaluate() {
		courseScheduleEvaluateService.createEvaluate(new Date());
	}

	// 新增待填写评论定时推送(推送老师)
	@GetMapping("/pushNeedReview2Teacher")
	public void pushNeedReview2Teacher() {
		courseReviewService.pushNeedReview2Teacher();
	}

	//对外无学生课程组提醒
	@GetMapping("/noStudentsCourseGroupRemind")
	public void noStudentsCourseGroupRemind(){
		coursesGroupService.noStudentsCourseGroupRemind();
	}

	//更新对外课程组状态至已结束
	@GetMapping("/finishCourseGroup")
	public void finishCourseGroup(){
		coursesGroupService.finishCourseGroup();
	}

	//学生服务信息统计
	@GetMapping("/exercisesSituationStatistics")
	public void exercisesSituationStatistics(String monday){
		studentServeService.exercisesSituationStatistics2(monday,null);
//		studentServeService.exercisesSituationStatistics2(null,new ArrayList<>(Arrays.asList(1095257)));
//		studentServeService.exercisesSituationStatistics(null);
	}

	//更新学生运营指标
	@GetMapping("/updateStudentOperatingTag")
	public void updateStudentOperatingTag(){
		studentService.updateOperatingTempTag();
	}

	// 更新乐团缴费日历的状态
	@GetMapping("/updateMusicGroupPaymentCalenderStatus")
	public void updateMusicGroupPaymentCalenderStatus() {
		musicGroupPaymentCalenderService.autoUpdateMusicGroupPaymentCalenderStatus();
	}

	// 更新乐团学员缴费状态
	@GetMapping("/updateMusicGroupStudentFeeStatus")
	public void updateMusicGroupStudentFeeStatus() {
		musicGroupPaymentCalenderService.autoUpdateMusicGroupStudentFeeStatus();
	}

	// 推送教师异常考勤
	@GetMapping("/pushTeacherExceptionAttendanceTask")
	public void pushTeacherExceptionAttendanceTask() {
		teacherAttendanceService.pushTeacherExceptionAttendanceTask();
	}

	//应布置课外训练提醒
	@GetMapping("/studentServeRemind")
	public void studentServeRemind(){
		extracurricularExercisesService.studentServeRemind();
	}

	//经营报表
	@GetMapping("/operatingReport")
	public void operatingReport(){
		operatingReportService.statistics();
	}

	@GetMapping("/updateCourseActualPrice")
	public void updateCourseActualPrice(){
		courseEventSource.courseStatusChange(null);
	}

	@GetMapping("/countIndexBaseData")
	public void countIndexBaseData(String month){
		indexBaseMonthDataService.indexBaseDataTask(month);
	}
}
