package com.sifang.modules.task;

import com.jfinal.plugin.activerecord.Db;
import com.jfinal.plugin.activerecord.Record;
import com.sifang.modules.sys.util.insurance.InsuranceBizService;
import org.apache.commons.lang3.StringUtils;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.scheduling.annotation.Scheduled;
import org.springframework.stereotype.Component;

import java.util.List;

@Component
public class UpdateInsurancePolicyTask {

    @Autowired
    InsuranceBizService insuranceBizService;

    private static final Logger log = LoggerFactory.getLogger(UpdateInsurancePolicyTask.class);

    // second, minute, hour, day, month, weekday.
    @Scheduled(cron = "0 0 0/1 * * ?") //每隔1小时 整点执行
    public void updatePolicyUrl() {
        long t = System.currentTimeMillis();
        List<Record> records = Db.find("select * from crm_customer_entry_insurance where down_url like 'http%'");
        log.info("exchange size: {}, consumed: {}", records.size(), System.currentTimeMillis() - t);
        for (Record record : records) {
            String insuranceId = record.getStr("id");
            String url = insuranceBizService.uploadInsurancePolicy2OSS(insuranceId, record.getStr("down_url2"));
            insuranceBizService.setDownUrl(insuranceId, url);
        }
    }

}
