package org.dromara.service.impl;


import com.google.gson.Gson;
import org.dromara.common.core.utils.DateUtils;
import org.dromara.domain.checkPoint.bo.CheckPointManageBo;
import org.dromara.domain.checkPoint.bo.CheckPointRecordBo;
import org.dromara.domain.checkPoint.vo.CheckPointManageVo;
import org.dromara.service.ICheckPointManageService;
import org.dromara.service.ICheckPointRecordService;
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 ICheckPointManageService checkPointManageService;
    @Autowired
    private ICheckPointRecordService checkPointRecordService;
    private static final Gson GSON = new Gson();
    /***
     *每日巡更记录的定时任务
     * 每天23点执行
     */
    @Async
    @Scheduled(cron = "0 0 23 * * ? ")
    public void popover() throws Exception {
        CheckPointManageBo checkPointManage = new CheckPointManageBo();
        List<CheckPointManageVo> checkPointManages = checkPointManageService.queryList(checkPointManage);
        if (checkPointManages != null && !checkPointManages.isEmpty()){
            for (CheckPointManageVo pointManage : checkPointManages) {
                CheckPointRecordBo checkPointRecord = GSON.fromJson(GSON.toJson(pointManage), CheckPointRecordBo.class);
                checkPointRecord.setCreateTime(DateUtils.getNowDate());
                checkPointRecordService.insertByBo(checkPointRecord);
            }
        }
    }
}
