package com.ruoyi.job.task;



import com.ruoyi.system.api.RemoteMonthSummaryService;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Component;

import java.time.LocalDate;
import java.time.format.DateTimeFormatter;
import java.util.HashMap;
import java.util.Map;

/**
 * 月度汇总定时任务
 *
 * @author lydgt
 */
@Component("financialMonthSummaryTask")
public class FinancialMonthSummaryTask {
    private static final Logger logger = LoggerFactory.getLogger(FinancialMonthSummaryTask.class);
    @Autowired
    RemoteMonthSummaryService remoteMonthSummaryService;
    /**
     * 每个月月初 执行生成上个月的月度账单
     * @author zxf
     */
    public void doTask() {
        logger.info("月度汇总上单定时任务开始");
        LocalDate today = LocalDate.now();
        LocalDate lastMonth = today.minusMonths(1);
        DateTimeFormatter formatter = DateTimeFormatter.ofPattern("yyyy.MM");
        // 格式化上个月日期为字符串
        String formattedDate = lastMonth.format(formatter);
        Map param= new HashMap();
        param.put("monthCode",formattedDate);
        param.put("deptId","");
        remoteMonthSummaryService.creatMontSummary(param);
    }

    /**
     * 每个月月初 执行生成上个月的月度账单
     * @author zxf
     */
    public void doTask(String  deptId,String monthCode) {
        logger.info("月度汇总按照传值月份供应商定时任务开始");
        Map param= new HashMap();
        param.put("monthCode",monthCode);
        param.put("deptId",deptId);
        remoteMonthSummaryService.creatMontSummary(param);
    }

    /**
     * 每天定时回写电子发票
     * @author zxf
     */
    public void updateInvoice() {
        logger.info("已申请电子发票地址查询回写任务开始");
        remoteMonthSummaryService.updateInvoice();
        logger.info("电子发票地址回写完成");
    }





}
