package com.yc.ship.module.trade.job;

import com.yc.ship.framework.quartz.core.handler.JobHandler;
import com.yc.ship.framework.tenant.core.util.TenantUtils;
import com.yc.ship.module.trade.dal.dataobject.invoice.InvoiceDO;
import com.yc.ship.module.trade.service.insurance.InsuranceService;
import com.yc.ship.module.trade.service.invoice.InvoiceService;
import com.yc.ship.module.trade.service.order.TradeOrderRepositoryService;
import com.yc.ship.module.trade.service.order.TradeOrderService;
import com.yc.ship.module.trade.service.order.TradeVisitorService;
import lombok.extern.slf4j.Slf4j;
import org.apache.commons.lang3.StringUtils;
import org.springframework.stereotype.Component;

import javax.annotation.Resource;
import java.util.List;

/**
 * 保险购买定时任务
 * 1. 查询需要购买保险的订单，只有确认状态并且开航前一天才可购买保险
 */
@Component
@Slf4j
public class InvoiceQueryJob implements JobHandler {

    @Resource
    private InvoiceService invoiceService;
    /**
     * 执行定时任务
     * 定时购买保险
     */
    @Override
    public String execute(String param) {
        try {
            TenantUtils.execute(1L, () -> {
                List<InvoiceDO> list = invoiceService.getInvoices();
                for (InvoiceDO invoiceDO : list) {
                    invoiceService.queryGroupInvoiceUrl(invoiceDO);
                }
            });
        } catch (Exception e) {
            log.error(">>>>>>>>>>>>>>>>>>>>>> queryGroupInvoiceUrlExecute Error <<<<<<<<<<<<<<<<<<<<<<");
            log.error(e.getMessage(), e);
        }
        log.info(">>>>>>>>>>>>>>>>>>>>>>  queryGroupInvoiceUrlExecute End  <<<<<<<<<<<<<<<<<<<<<<");
        return "success";
    }
}
