package com.yiqi.task;

import com.yiqi.common.utils.DateUtils;
import com.yiqi.common.utils.StringUtils;
import com.yiqi.core.domain.dto.SettlementBillAddDTO;
import com.yiqi.core.service.ISettlementManageBillService;
import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Component;

import java.text.SimpleDateFormat;
import java.util.Calendar;
import java.util.Date;

/**
 * 定时任务调度测试
 *
 * @author ruoyi
 */
@Component
@Slf4j
public class SettlementTask {

    @Autowired
    private ISettlementManageBillService settlementManageBillService;

    public void run(String date) {
        // 获取上个月的时间范围
        Calendar calendar = Calendar.getInstance();
        calendar.add(Calendar.MONTH, 0);

        SimpleDateFormat monthFormat = new SimpleDateFormat("yyyy-MM");
        String month = monthFormat.format(calendar.getTime());

        // 构建结算标题
        String title = month + "月份结算";

        // 创建结算单
        SettlementBillAddDTO settlementBillAddDTO = new SettlementBillAddDTO();
        settlementBillAddDTO.setTitle(title);
        settlementBillAddDTO.setMonth(month);
        settlementManageBillService.insertSettlementManageBill(settlementBillAddDTO);
    }
}
