package com.yida.data.attendance.controller.in;

import com.yida.data.attendance.dto.DayReportDataDTO;
import com.yida.data.attendance.service.AttendanceRecordService;
import com.yida.data.attendance.service.AttendanceReportStrategyService;
import com.yida.data.attendance.service.AttendanceResultService;
import com.yida.data.attendance.service.AttendanceRuleService;
import com.yida.data.attendance.service.NoticeService;
import com.yida.data.common.core.entity.attendance.attendance.AttendanceRule;
import java.time.LocalDateTime;
import java.time.format.DateTimeFormatter;
import java.util.ArrayList;
import java.util.List;
import lombok.RequiredArgsConstructor;
import lombok.extern.slf4j.Slf4j;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;
import org.w3c.dom.stylesheets.LinkStyle;

@Slf4j
@RestController
@RequestMapping("in/attendanceResult")
@RequiredArgsConstructor
public class InAttendanceResultController {

    private final AttendanceResultService attendanceResultService;
    private final AttendanceRecordService attendanceRecordService;
    private final AttendanceReportStrategyService attendanceReportStrategyService;
    private final NoticeService noticeService;
    private final AttendanceRuleService attendanceRuleService;

    /**
     * 每日凌晨先初始化考勤结果
     */
    @GetMapping("/initAttendanceResult")
    public void initAttendanceResult() {
        attendanceResultService.initUserAttendance();
    }


    /**
     * 策略推送消息
     */
    @GetMapping("/attendanceNotice")
    public void notice() {
        attendanceReportStrategyService.sendNotice();
    }


    /**
     * 同步老数据
     *
     * @param schoolId
     * @param startDateTime
     */
    @GetMapping("/resetOldData")
    public void resetOldData(Long schoolId, String startDateTime, Integer userType) {
        attendanceRecordService
            .resetOldData(schoolId,
                LocalDateTime.parse(startDateTime, DateTimeFormatter.ofPattern("yyyy-MM-dd HH:mm:ss")), userType);
    }


    /**
     * 同步老数据
     */
    @GetMapping("/testPushDayReport")
    public void testPushDayReport(Long staffId, Long ruleId) {
        List<DayReportDataDTO> dtoList = new ArrayList<>();
        dtoList.add(DayReportDataDTO.builder().deptName("经济管理系").totalNum(1234).abNum(456).requestNum(15).build());
        dtoList.add(DayReportDataDTO.builder().deptName("基础部").totalNum(2563).abNum(652).requestNum(95).build());
        dtoList.add(DayReportDataDTO.builder().deptName("机电工程系").totalNum(859).abNum(15).requestNum(3).build());
        dtoList.add(DayReportDataDTO.builder().deptName("建筑工程系").totalNum(1596).abNum(325).requestNum(35).build());
        dtoList.add(DayReportDataDTO.builder().deptName("计算机信息工程系").totalNum(1846).abNum(15).requestNum(105).build());
        noticeService.sendAttendanceDayReportToStaff(staffId, dtoList, attendanceRuleService.getById(ruleId), 1, true);
    }


    /**
     * 每日/每周/每月考勤数据
     */
    @GetMapping("/initAttendanceReport")
    public void initAttendanceReport() {
        attendanceReportStrategyService.sendNotice();
    }


}
