package com.docus.server.synclis.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.synclis.service.LisService;
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/16 16:44
 */
@Slf4j
@Component
public class LisTaskSyncJob {
    @Resource
    private LisService lisService;
    @Resource
    private TBasicMapper tBasicMapper;

    @XxlJob("lisTaskSyncJob")
    private void lisTaskSyncJob() {
        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(">>>>>>>>>>>>>>>>>>>>>>>>>>>>>>> LIS视图任务同步开始。出院时间：{} 至 {} 共 {} 条数据！", start, end, tbasics.size());
            for (TBasic tbasic : tbasics) {
                lisService.syncViewTask(tbasic);
            }
            log.info(">>>>>>>>>>>>>>>>>>>>>>>>>>>>>>> LIS视图任务结束同步。");
        } catch (Exception ex) {
            log.error(">>>>>>>>>>>>>>>>>>>>>>>>>>>>>>> LIS视图任务同步出错了，" + ex.getMessage(), ex);
        }
    }
}
