package org.ta.pddserver.xxl;

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

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

@Component
@Slf4j
public class GDOperator {

    @Resource
    GDTicketImpl gdTicketImpl;

    @PostConstruct
    public void init(){
        getGdTickets();
    }

    @Scheduled(fixedRate = 1000 * 60 * 5) // 每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 保存
                // 主体、绑定两个表
            }
        }
    }
}
