package org.ta.pddserver.xxl;

import jakarta.annotation.PostConstruct;
import jakarta.annotation.Resource;
import lombok.extern.slf4j.Slf4j;
import org.springframework.scheduling.annotation.EnableScheduling;
import org.springframework.scheduling.annotation.Scheduled;
import org.springframework.stereotype.Component;
import org.ta.pddserver.entity.GDTicketEntity;
import org.ta.pddserver.model.pddgd.response.GDTicketRepsonse;
import org.ta.pddserver.service.impl.GDTicketImpl;
import org.ta.pddserver.utils.PddGDUtil;

import java.util.Date;
import java.util.List;

@Component
@Slf4j
@EnableScheduling
public class GDOperator {

    @Resource
    GDTicketImpl gdTicketImpl;

    @Scheduled(fixedRate = 1000 * 60 * 5, initialDelay = 1000) // 每5分钟执行一次
    public void getGdTickets() {
        List<GDTicketRepsonse> list = PddGDUtil.getTickets();
        log.info("{} 工单数量：{}", new Date().toLocaleString(), list.size());
        for (GDTicketRepsonse gdTicketRepsonse : list) {
            GDTicketEntity  gdTicketEntity = gdTicketImpl.getByTicketId(gdTicketRepsonse.getTicket_id());
            if (gdTicketEntity == null) {
                // todo 保存
                // 主体、绑定两个表
            }
        }
    }
}
