package com.dk.mdm.infrastructure.xxljob;

import com.dk.mdm.mapper.xxljob.XxlJobMapper;
import com.xxl.job.core.handler.annotation.XxlJob;
import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

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

@Slf4j
@Service
public class XxlJobService {

    @Autowired
    private XxlJobMapper xxlJobMapper;

    /**
     * @desc : 定时任务执行
     * @author : 洪旭东
     * @date : 2023-08-02 09:56
     */
    @XxlJob("mes-mdm-scheduled")
    public void mdmScheduled() throws Exception {
        log.info("mes-mdm-scheduled start");

        SimpleDateFormat format = new SimpleDateFormat("yyyy-MM-dd");
        Date date = new Date();
        Calendar calendar = Calendar.getInstance();
        calendar.setTime(date);
        calendar.add(Calendar.DATE, -1);
        String beforeDay = format.format(calendar .getTime());

        xxlJobMapper.sumProductOutput(beforeDay);

        log.info("mes-mdm-scheduled end");
    }

}