package com.ruoyi.app.service.impl;

import java.util.ArrayList;
import java.util.List;

import com.ruoyi.app.domain.AppVehicle;
import com.ruoyi.app.domain.DAO.AppVehicleInfo;
import com.ruoyi.app.domain.DTO.AppAvailVehicle;
import com.ruoyi.app.mapper.AppVehicleMapper;
import com.ruoyi.app.service.IAppVehicleService;
import com.ruoyi.common.utils.StringUtils;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

/**
 * 【请填写功能名称】Service业务层处理
 *
 * @author ruoyi
 * @date 2025-01-15
 */
@Service
public class AppVehicleServiceImpl implements IAppVehicleService
{
    @Autowired
    private AppVehicleMapper appVehicleMapper;

    /**
     * 查询【请填写功能名称】
     *
     * @param vehicleId 【请填写功能名称】主键
     * @return 【请填写功能名称】
     */
    @Override
    public AppVehicle selectAppVehicleByVehicleId(String vehicleId)
    {
        return appVehicleMapper.selectAppVehicleByVehicleId(vehicleId);
    }

    /**
     * 查询【请填写功能名称】列表
     *
     * @param appVehicle 【请填写功能名称】
     * @return 【请填写功能名称】
     */
    @Override
    public List<AppVehicle> selectAppVehicleList(AppVehicle appVehicle)
    {
        return appVehicleMapper.selectAppVehicleList(appVehicle);
    }

    /**
     * 新增【请填写功能名称】
     *
     * @param appVehicle 【请填写功能名称】
     * @return 结果
     */
    @Override
    public int insertAppVehicle(AppVehicle appVehicle)
    {
        return appVehicleMapper.insertAppVehicle(appVehicle);
    }

    /**
     * 修改【请填写功能名称】
     *
     * @param appVehicle 【请填写功能名称】
     * @return 结果
     */
    @Override
    public int updateAppVehicle(AppVehicle appVehicle)
    {
        return appVehicleMapper.updateAppVehicle(appVehicle);
    }

    /**
     * 批量删除【请填写功能名称】
     *
     * @param vehicleIds 需要删除的【请填写功能名称】主键
     * @return 结果
     */
    @Override
    public int deleteAppVehicleByVehicleIds(String[] vehicleIds)
    {
        return appVehicleMapper.deleteAppVehicleByVehicleIds(vehicleIds);
    }

    /**
     * 删除【请填写功能名称】信息
     *
     * @param vehicleId 【请填写功能名称】主键
     * @return 结果
     */
    @Override
    public int deleteAppVehicleByVehicleId(String vehicleId)
    {
        return appVehicleMapper.deleteAppVehicleByVehicleId(vehicleId);
    }

    /**
     * 获取状态为在库中的所有可用的载具
     * @return 结果
     */
    public List<AppAvailVehicle> selectAppAvailVehicleList() {
        List<AppVehicleInfo> appVehicleInfoList = appVehicleMapper.selectVehicleList();
        List<AppAvailVehicle> response = new ArrayList<AppAvailVehicle>();
        for (AppVehicleInfo appVehicleInfo : appVehicleInfoList) {
            // 1: 在库内
            System.out.println(appVehicleInfo);
            if (appVehicleInfo != null && appVehicleInfo.getVehicleId() != null && !StringUtils.isEmpty(appVehicleInfo.getVehicleId())) {
                if (appVehicleInfo.getVehicleStatus() == 1 && appVehicleInfo.getIsEmpty() != 0 && appVehicleInfo.getIsLock() == 0) {
                    AppAvailVehicle appAvailVehicle = new AppAvailVehicle();
                    appAvailVehicle.setVehicleId(appVehicleInfo.getVehicleId());
                    appAvailVehicle.setVehicleStatus(1);
                    appAvailVehicle.setLocationId(appVehicleInfo.getLocationId());
                    response.add(appAvailVehicle);
                }
            }
        }
        return response;
    }
}
