package com.wms_main.service.controller.serviceImpl;

import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper;
import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import com.wms_main.dao.ITAppVehicleService;
import com.wms_main.model.dto.query.VehicleQuery;
import com.wms_main.model.dto.response.wms.WmsApiResponse;
import com.wms_main.model.po.TAppVehicle;
import com.wms_main.model.vo.wms.PageVo;
import com.wms_main.model.vo.wms.VehicleVo;
import com.wms_main.repository.utils.StringUtils;
import com.wms_main.service.controller.IVehicleControllerService;
import lombok.RequiredArgsConstructor;
import org.springframework.stereotype.Service;

/**
 * 载具服务控制类实现
 */
@Service
@RequiredArgsConstructor
public class VehicleControllerService implements IVehicleControllerService {
    private final ITAppVehicleService appVehicleService;// 载具服务


    /**
     * 查询载具信息（分页）实现
     * @param vehicleQuery 查询参数
     * @return 查询结果
     */
    @Override
    public WmsApiResponse<PageVo<VehicleVo>> queryVehicleInfoByPage(VehicleQuery vehicleQuery) {
        if (vehicleQuery == null) {
            return WmsApiResponse.error("查询参数不能为NULL", null);
        }
        Page<TAppVehicle> page = vehicleQuery.toMpPage();
        LambdaQueryWrapper<TAppVehicle> lambdaQueryWrapper = new LambdaQueryWrapper<TAppVehicle>()
                .like(StringUtils.isNotEmpty(vehicleQuery.getVehicleId()), TAppVehicle::getVehicleId, vehicleQuery.getVehicleId())
                .like(StringUtils.isNotEmpty(vehicleQuery.getLocationId()), TAppVehicle::getLocationId, vehicleQuery.getLocationId())
                .eq(vehicleQuery.getVehicleStatus() != null, TAppVehicle::getVehicleStatus, vehicleQuery.getVehicleStatus())
                .eq(vehicleQuery.getIsLock() != null, TAppVehicle::getIsLock, vehicleQuery.getIsLock())
                .eq(vehicleQuery.getIsEmpty() != null, TAppVehicle::getIsEmpty, vehicleQuery.getIsEmpty());
        Page<TAppVehicle> poPage = appVehicleService.page(page, lambdaQueryWrapper);

        PageVo<VehicleVo> pageVo = PageVo.of(poPage, VehicleVo::of);
        return WmsApiResponse.success("查询料箱成功", pageVo);
    }
}
