package com.tax.file.service.async.report;

import com.tax.file.model.TkTaxUser;
import com.tax.file.service.api.TkTaxUserService;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Component;

import java.util.List;
import java.util.concurrent.CountDownLatch;

@Component
public class FileDayReportTask {

    private static final Logger logger = LoggerFactory.getLogger(FileDayReportTask.class);
    @Autowired
    private TkTaxUserService tkTaxUserService;
    @Autowired
    private FileDayReportService fileDayReportService;

    public void createDayReport(String uuidFlag){

        List<TkTaxUser> taxUserList = tkTaxUserService.queryDayReportTaxnoList();
        logger.info(uuidFlag + " createDayReport taxno number:" + taxUserList.size());
        try {
            if(taxUserList!=null && taxUserList.size()>0){
                CountDownLatch latch = new CountDownLatch(taxUserList.size());
                for(TkTaxUser taxUser: taxUserList){
                    fileDayReportService.saveFileDayReport(uuidFlag, latch, taxUser);
                }
                latch.await();
            }
        } catch (Exception e) {
            e.printStackTrace();
            logger.info(uuidFlag + " createDayReport is error:" + e.getMessage());
        }
    }

}
