KeyWorkLocalJob.java 2.05 KB
package com.ruoyi.job;

import com.ruoyi.domain.scheduling.LinggangScheduling;
import com.ruoyi.service.driver.NewDriverService;
import com.ruoyi.service.key.location.LinggangKeyWorkLocationService;
import com.ruoyi.service.scheduling.LinggangSchedulingService;
import com.ruoyi.utils.DateUtil;
import lombok.extern.slf4j.Slf4j;
import org.apache.commons.lang3.StringUtils;
import org.apache.commons.lang3.time.DateUtils;
import org.springframework.beans.factory.InitializingBean;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Component;

import java.text.ParseException;
import java.util.Date;
import java.util.List;
import java.util.Set;
import java.util.stream.Collectors;

/**
 * @author liujun
 * @date 2024年07月30日 15:12
 */
@Component("KeyWorkLocalJob")
@Slf4j
public class KeyWorkLocalJob implements InitializingBean {
    @Autowired
    private NewDriverService newDriverService;
    @Autowired
    private LinggangSchedulingService linggangSchedulingService;
    @Autowired
    private LinggangKeyWorkLocationService keyWorkLocationService;

    public void insertKeyWorkLocalJob(){
       String  dateStr = DateUtil.YYYY_MM_DD_LINK.format(new Date());
        Date date = null;
        try {
            date = DateUtil.YYYY_MM_DD_LINK.parse(dateStr);
        } catch (ParseException e) {
            throw new RuntimeException(e);
        }

        LinggangScheduling scheduling = new LinggangScheduling();
        scheduling.setStartScheduleDate(DateUtil.shortDate(date));
        scheduling.setEndScheduleDate(DateUtils.addDays(scheduling.getStartScheduleDate(), 1));
        scheduling.setType(100);

        List<LinggangScheduling> linggangSchedulings = linggangSchedulingService.list(scheduling);
        Set<Long> idSets = linggangSchedulings.stream().map(LinggangScheduling::getId).collect(Collectors.toSet());
        keyWorkLocationService.insertJob(dateStr, null, idSets);

        log.info("钥匙存放信息处理完毕");
    }
    @Override
    public void afterPropertiesSet() throws Exception {

    }
}