package com.dcsoft.job.task;

import com.dcsoft.common.core.constant.SecurityConstants;
import com.dcsoft.job.domain.HolidayVo;
import com.dcsoft.job.domain.KqHoliday;
import com.dcsoft.job.service.IKqHolidayService;
import com.dcsoft.job.service.ISysJobLogService;
import com.dcsoft.job.util.HolidayUtil;
import com.dcsoft.system.api.RemoteStudentService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Component;
import com.dcsoft.common.core.utils.StringUtils;

import java.io.IOException;
import java.text.ParseException;
import java.text.SimpleDateFormat;
import java.util.ArrayList;
import java.util.Date;

/**
 * 定时任务调度测试
 *
 * @author dcsoft
 */
@Component("ryTask")
public class RyTask
{

    @Autowired
    private IKqHolidayService holidayService;

    @Autowired
    private RemoteStudentService remoteStudentService;

    @Autowired
    private ISysJobLogService sysJobLogService;


    public void ryMultipleParams(String s, Boolean b, Long l, Double d, Integer i)
    {
        System.out.println(StringUtils.format("执行多参方法： 字符串类型{}，布尔类型{}，长整型{}，浮点型{}，整形{}", s, b, l, d, i));
    }

    public void ryParams(String params)
    {
        System.out.println("执行有参方法：" + params);
    }

    public void ryNoParams()
    {
        System.out.println("执行无参方法");
    }

    public void holiday()
    {
        try {
            Date date=new Date();
            SimpleDateFormat sdf1=new SimpleDateFormat("yyyy");
            ArrayList<HolidayVo> list=HolidayUtil.getAllHolidayByYear(sdf1.format(date));
            for(HolidayVo h:list){
                if(!"0".equals(h.getStatus())){
                    //添加到节假日库中
                    KqHoliday kqHoliday=new KqHoliday();
                    kqHoliday.setStatus(h.getStatus());
                    SimpleDateFormat sdf =new SimpleDateFormat("yyyy-MM-dd");
                    try {
                        kqHoliday.setTime(sdf.parse(h.getData()));
                        kqHoliday.setTimeStamp(sdf.parse(h.getData()).getTime());
                    } catch (ParseException e) {
                        throw new RuntimeException(e);
                    }
                    holidayService.insertKqHoliday(kqHoliday);

                }
            }

        } catch (IOException e) {
            throw new RuntimeException(e);
        }
    }

    public void gatherMonth()
    {
        remoteStudentService.gatherMonth(SecurityConstants.INNER);
    }

    public void backUp()
    {
        remoteStudentService.backUp(SecurityConstants.INNER);
    }

    public void gather()
    {
        remoteStudentService.gather(SecurityConstants.INNER);
    }

    public void peopleLeave()
    {
        remoteStudentService.peopleLeave(SecurityConstants.INNER);

    }

    /**
     * 新增请假信息
     */
    public void saveAskForLeave() {
        remoteStudentService.saveAskForLeave(SecurityConstants.INNER);
    }

    /**
     * 新增补卡信息
     */
    public void saveCardReplacement() {
        remoteStudentService.saveCardReplacement(SecurityConstants.INNER);
    }

    /**
     * 定时批量下发
     */
    public void batchDistribute() {
        remoteStudentService.batchDistribute(SecurityConstants.INNER);
    }

    /**
     * 定时部门
     */
    public void saveBranchTree() {
        remoteStudentService.saveBranchTree(SecurityConstants.INNER);
    }

    /**
     * 定时人员
     */
    public void saveUserInfo() {
        remoteStudentService.saveUserInfo(SecurityConstants.INNER);
    }

    /**
     * 定时岗位
     */
    public void saveStation() {
        remoteStudentService.saveStation(SecurityConstants.INNER);
    }

    /**
     * 定时批量下发部门人员
     */
    public void batchDown() {
        remoteStudentService.batchDown(SecurityConstants.INNER);
    }

    /**
     * 梯控刷卡回调接口设置
     */
    public void setDeviceCallBackInfo(String sequence) {
        sysJobLogService.setDeviceCallBackInfo(sequence);
    }

    /**
     * 刷新梯口设备在线离线状态
     */
    public void updateLadderState(String sequence) throws IOException {
        sysJobLogService.updateLadderState(sequence);
    }


    /**
     * 删除宇泛人脸设备访客结束时间的数据
     */
    public void deleteVisitorFaceDevice() {
        sysJobLogService.deleteVisitorFaceDevice();
    }

    public void deleteVisitorHkDevice() {
        sysJobLogService.deleteVisitorHkDevice();
    }

    /**
     * 设置宇泛二维码回调地址
     */
    public void setQRCodeCallback(String sequence) {
        sysJobLogService.setQRCodeCallback(sequence);
    }

    public void amendConsume()
    {
        remoteStudentService.amendConsume(SecurityConstants.INNER);
    }

    public void createConsumeSubsidy()
    {
        remoteStudentService.createConsumeSubsidy(SecurityConstants.INNER);
    }

    public void syncConsume() {
        remoteStudentService.syncConsume(SecurityConstants.INNER);
    }

    public void createConsumeGroup()
    {
        remoteStudentService.createConsumeGroup(SecurityConstants.INNER);
    }

    public void syncHkRecord()
    {
        remoteStudentService.syncHkRecord(SecurityConstants.INNER);
    }


}
