RefreshController.java 2.64 KB
package com.ruoyi.controller;

import com.ruoyi.common.core.domain.ResponseResult;
import com.ruoyi.domain.scheduling.LinggangScheduling;
import com.ruoyi.job.DriverJob;
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 io.swagger.annotations.ApiOperation;
import org.apache.commons.lang3.time.DateUtils;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestParam;
import org.springframework.web.bind.annotation.RestController;

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日 14:37
 */
@RestController
@RequestMapping("/refresh")
public class RefreshController {
    @Autowired
    private DriverJob driverJob;
    @Autowired
    private LinggangKeyWorkLocationService keyWorkLocationService;
    @Autowired
    private NewDriverService newDriverService;
    @Autowired
    private LinggangSchedulingService linggangSchedulingService;

    @GetMapping(value = "/scheduling")
    @ApiOperation("scheduling")
    public ResponseResult<Boolean> test() {
        Date date = new Date();
        for (int i = 0; i < 2; i++) {
            driverJob.runScheduling(DateUtils.addDays(date, i).getTime());
        }

        return ResponseResult.success();
    }

    @GetMapping(value = "/key/info/local")
    @ApiOperation("/key/info/local")
    public ResponseResult<Boolean> testKeyInfoLocal(@RequestParam("dateStr") String dateStr) throws ParseException {
        Date date = DateUtil.YYYY_MM_DD_LINK.parse(dateStr);

        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, idSets);
        return ResponseResult.success();
    }

    @GetMapping(value = "/driver")
    @ApiOperation("driver")
    public ResponseResult<Boolean> insertDriver() {
        newDriverService.insertJob();
        return ResponseResult.success();
    }
}