package com.docus.server.synchis.job;

import com.docus.core.util.Func;
import com.docus.server.archive.entity.TBasic;
import com.docus.server.archive.mapper.TBasicMapper;
import com.docus.server.synchis.service.HisService;
import com.xxl.job.core.handler.annotation.XxlJob;
import lombok.extern.slf4j.Slf4j;
import org.springframework.stereotype.Component;

import javax.annotation.Resource;
import java.time.LocalDate;
import java.util.Date;
import java.util.List;

/**
 * @author YongBin Wen
 * @date 2025/1/23 13:21
 */
@Slf4j
@Component
public class CheckHisTaskJob {

    @Resource
    private HisService hisService;
    @Resource
    private TBasicMapper tBasicMapper;

    @XxlJob("hisTaskCheckJob")
    private void hisTaskCheckJob() {
        LocalDate startLocalDate = LocalDate.now().plusMonths(-6);
        String start = startLocalDate + " 00:00:00";
        String end = Func.formatDateTime(new Date());
        try {
            List<TBasic> tbasics = tBasicMapper.getByDisDate(start, end);
            log.info(">>>>>>>>>>>>>>>>>>>>>>>>>>>>>>> HIS视图任务检查开始。出院时间：{} 至 {} 共 {} 条数据！", start, end, tbasics.size());
            for (TBasic tbasic : tbasics) {
                hisService.checkTask(tbasic);
            }
            log.info(">>>>>>>>>>>>>>>>>>>>>>>>>>>>>>> HIS视图任务检查结束。");
        } catch (Exception ex) {
            log.error(">>>>>>>>>>>>>>>>>>>>>>>>>>>>>>> HIS视图任务检查出错了，" + ex.getMessage(), ex);
        }
    }
}
