DriverSchedulingExpandServiceImpl.java 4.4 KB
package com.ruoyi.expand.service.impl;

import java.util.ArrayList;
import java.util.List;
import java.util.Map;
import java.util.stream.Collectors;

import com.github.pagehelper.PageInfo;
import com.ruoyi.common.constant.HttpStatus;
import com.ruoyi.common.core.controller.BaseController;
import com.ruoyi.common.core.page.TableDataInfo;
import com.ruoyi.common.utils.DateUtils;
import com.ruoyi.common.utils.SecurityUtils;
import com.ruoyi.driver.domain.Driver;
import com.ruoyi.driver.mapper.DriverMapper;
import com.ruoyi.pojo.vo.ExpandResponseViewVo;
import org.springframework.beans.BeanUtils;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
import com.ruoyi.expand.mapper.DriverSchedulingExpandMapper;
import com.ruoyi.expand.domain.DriverSchedulingExpand;
import com.ruoyi.expand.service.IDriverSchedulingExpandService;

/**
 * 跟班设置Service业务层处理
 *
 * @author guzijian
 * @date 2023-09-12
 */
@Service
public class DriverSchedulingExpandServiceImpl implements IDriverSchedulingExpandService {
    @Autowired
    private DriverSchedulingExpandMapper driverSchedulingExpandMapper;

    @Autowired
    private DriverMapper driverMapper;

    /**
     * 查询跟班设置
     *
     * @param id 跟班设置主键
     * @return 跟班设置
     */
    @Override
    public DriverSchedulingExpand selectDriverSchedulingExpandById(Long id) {
        return driverSchedulingExpandMapper.selectDriverSchedulingExpandById(id);
    }

    /**
     * 查询跟班设置列表
     *
     * @param driverSchedulingExpand 跟班设置
     * @return 跟班设置
     */
    @Override
    public TableDataInfo selectDriverSchedulingExpandList(DriverSchedulingExpand driverSchedulingExpand) {
        List<DriverSchedulingExpand> expandList = driverSchedulingExpandMapper.selectDriverSchedulingExpandList(driverSchedulingExpand);
        List<ExpandResponseViewVo> vos = new ArrayList<>(expandList.size());


        List<String> jobCodes = new ArrayList<>();
        for (DriverSchedulingExpand expand : expandList) {
            jobCodes.add(expand.getMasterJobCode());
            jobCodes.add(expand.getSlaveJobCode());
            ExpandResponseViewVo vo = new ExpandResponseViewVo();
            BeanUtils.copyProperties(expand, vo);
            vos.add(vo);
        }

        jobCodes = jobCodes.stream().distinct().collect(Collectors.toList());
        Map<String, Driver> driverMap = driverMapper.getNameByJobCode(jobCodes).stream().collect(Collectors.toMap(Driver::getJobCode,driver -> driver));
        vos = vos.stream().peek(vo->{
            vo.setMaster(vo.getMasterJobCode() + "/" + driverMap.get(vo.getMasterJobCode()).getPersonnelName());
            vo.setSlave( vo.getSlaveJobCode() +"/"+driverMap.get(vo.getSlaveJobCode()).getPersonnelName());
        }).collect(Collectors.toList());

        return BaseController.getDataTable(vos, new PageInfo(expandList).getTotal());
    }


    /**
     * 新增跟班设置
     *
     * @param driverSchedulingExpand 跟班设置
     * @return 结果
     */
    @Override
    public int insertDriverSchedulingExpand(DriverSchedulingExpand driverSchedulingExpand) {
        driverSchedulingExpand.setCreateTime(DateUtils.getNowDate());
        driverSchedulingExpand.setCreateBy(SecurityUtils.getUsername());
        return driverSchedulingExpandMapper.insertDriverSchedulingExpand(driverSchedulingExpand);
    }

    /**
     * 修改跟班设置
     *
     * @param driverSchedulingExpand 跟班设置
     * @return 结果
     */
    @Override
    public int updateDriverSchedulingExpand(DriverSchedulingExpand driverSchedulingExpand) {
        driverSchedulingExpand.setUpdateTime(DateUtils.getNowDate());
        driverSchedulingExpand.setUpdateBy(SecurityUtils.getUsername());
        return driverSchedulingExpandMapper.updateDriverSchedulingExpand(driverSchedulingExpand);
    }

    /**
     * 批量删除跟班设置
     *
     * @param ids 需要删除的跟班设置主键
     * @return 结果
     */
    @Override
    public int deleteDriverSchedulingExpandByIds(Long[] ids) {
        return driverSchedulingExpandMapper.deleteDriverSchedulingExpandByIds(ids);
    }

    /**
     * 删除跟班设置信息
     *
     * @param id 跟班设置主键
     * @return 结果
     */
    @Override
    public int deleteDriverSchedulingExpandById(Long id) {
        return driverSchedulingExpandMapper.deleteDriverSchedulingExpandById(id);
    }
}