package com.ruoyi.system.service.impl;


import com.google.gson.Gson;
import com.ruoyi.common.utils.DateUtils;
import com.ruoyi.system.domain.checkPoint.CheckPointManage;
import com.ruoyi.system.domain.checkPoint.CheckPointRecord;
import com.ruoyi.system.mapper.CheckPointManageMapper;
import com.ruoyi.system.mapper.CheckPointRecordMapper;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.scheduling.annotation.Async;
import org.springframework.scheduling.annotation.Scheduled;
import org.springframework.stereotype.Component;

import java.util.List;

/**
 * 定时任务
* @author tang
 */
@Component
public class Task {
    @Autowired
    private CheckPointManageMapper checkPointManageMapper;
    private CheckPointRecordMapper checkPointRecordMapper;
    private static final Gson GSON = new Gson();
    /***
     *每日巡更记录的定时任务
     * 每天23点执行
     */
    @Async
    @Scheduled(cron = "0 0 23 * * ? ")
    public void popover() throws Exception {
        CheckPointManage checkPointManage = new CheckPointManage();
        List<CheckPointManage> checkPointManages = checkPointManageMapper.selectCheckPointManageList(checkPointManage);
        if (checkPointManages != null && checkPointManages.size() > 0){
            for (CheckPointManage pointManage : checkPointManages) {
                CheckPointRecord checkPointRecord = GSON.fromJson(GSON.toJson(pointManage), CheckPointRecord.class);
                checkPointRecord.setCreateTime(DateUtils.getNowDate());
                checkPointRecordMapper.insertCheckPointRecord(checkPointRecord);
            }
        }
    }
}
