DriverServiceImpl.java 3.21 KB
package com.ruoyi.driver.service.impl;

import java.util.ArrayList;
import java.util.Collection;
import java.util.List;
import java.util.Map;

import com.ruoyi.common.core.domain.AjaxResult;
import com.ruoyi.common.core.redis.RedisCache;
import com.ruoyi.common.utils.SecurityUtils;
import com.ruoyi.pojo.response.ResponseScheduling;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
import com.ruoyi.driver.mapper.DriverMapper;
import com.ruoyi.driver.domain.Driver;
import com.ruoyi.driver.service.IDriverService;

import static com.ruoyi.redispre.GlobalRedisPreName.DRIVER_SCHEDULING_PRE;

/**
 * 驾驶员信息Service业务层处理
 *
 * @author 古自健
 * @date 2023-07-04
 */
@Service
public class DriverServiceImpl implements IDriverService {
    @Autowired
    private DriverMapper driverMapper;

    @Autowired
    private RedisCache redisCache;

    /**
     * 查询驾驶员信息
     *
     * @param id 驾驶员信息主键
     * @return 驾驶员信息
     */
    @Override
    public Driver selectDriverById(Long id) {
        return driverMapper.selectDriverById(id);
    }

    /**
     * 查询驾驶员信息列表
     *
     * @param driver 驾驶员信息
     * @return 驾驶员信息
     */
    @Override
    public List<Driver> selectDriverList(Driver driver) {
        return driverMapper.selectDriverList(driver);
    }

    /**
     * 新增驾驶员信息
     *
     * @param driver 驾驶员信息
     * @return 结果
     */
    @Override
    public int insertDriver(Driver driver) {
        return driverMapper.insertDriver(driver);
    }

    /**
     * 修改驾驶员信息
     *
     * @param driver 驾驶员信息
     * @return 结果
     */
    @Override
    public int updateDriver(Driver driver) {
        return driverMapper.updateDriver(driver);
    }

    /**
     * 批量删除驾驶员信息
     *
     * @param ids 需要删除的驾驶员信息主键
     * @return 结果
     */
    @Override
    public int deleteDriverByIds(Long[] ids) {
        return driverMapper.deleteDriverByIds(ids);
    }

    /**
     * 删除驾驶员信息信息
     *
     * @param id 驾驶员信息主键
     * @return 结果
     */
    @Override
    public int deleteDriverById(Long id) {
        return driverMapper.deleteDriverById(id);
    }

    @Override
    public void insertDrivers(List<Driver> driverList) {
        driverMapper.saveDrivers(driverList);
    }

    @Override
    public AjaxResult getDriverSchedulingInfo(String date, String jobCode) {
        List<ResponseScheduling> cacheMapValue = redisCache.getCacheMapValue(DRIVER_SCHEDULING_PRE + date, jobCode);
        Boolean aBoolean = redisCache.redisTemplate.opsForHash().hasKey(DRIVER_SCHEDULING_PRE + date, jobCode);
        return AjaxResult.success(redisCache.getCacheMapValue(DRIVER_SCHEDULING_PRE + date, jobCode));
    }

    @Override
    public void saveDriverScheduling(Map<String, List<ResponseScheduling>> driverSchedulingMap) {
        Collection<List<ResponseScheduling>> listCollection = driverSchedulingMap.values();
        for (List<ResponseScheduling> responseSchedulings : listCollection) {
            driverMapper.saveDriverScheduling(responseSchedulings);
        }

    }
}