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.ITAppPickPlanService;
import com.wms_main.model.dto.query.PickPlanQuery;
import com.wms_main.model.dto.response.wms.WmsApiResponse;
import com.wms_main.model.po.TAppPickPlan;
import com.wms_main.model.vo.wms.PageVo;
import com.wms_main.model.vo.wms.PickPlanVo;
import com.wms_main.service.controller.IPickPlanControllerService;
import com.wms_main.repository.utils.StringUtils;
import lombok.RequiredArgsConstructor;
import lombok.extern.slf4j.Slf4j;
import org.springframework.stereotype.Service;

@Service
@RequiredArgsConstructor
@Slf4j
public class PickPlanControllerServiceImpl implements IPickPlanControllerService {

    private final ITAppPickPlanService pickPlanService;

    /**
     * 查询拣选计划信息（分页）---实现
     *
     * @param pickPlanQuery 查询参数
     * @return 查询结果
     */
    @Override
    public WmsApiResponse<PageVo<PickPlanVo>> queryPickPlanInfoByPage(PickPlanQuery pickPlanQuery) {
        if (pickPlanQuery == null) {
            return WmsApiResponse.error("查询参数不能为NULL", null);
        }
        Page<TAppPickPlan> page = pickPlanQuery.toMpPage();
        LambdaQueryWrapper<TAppPickPlan> lambdaQueryWrapper = new LambdaQueryWrapper<TAppPickPlan>()
                .eq(StringUtils.isNotEmpty(pickPlanQuery.getVehicleId()), TAppPickPlan::getVehicleId, pickPlanQuery.getVehicleId())
                .eq(StringUtils.isNotEmpty(pickPlanQuery.getStandId()), TAppPickPlan::getStandId, pickPlanQuery.getStandId());
        Page<TAppPickPlan> poPage = pickPlanService.page(page, lambdaQueryWrapper);

        PageVo<PickPlanVo> pageVo = PageVo.of(poPage, PickPlanVo::of);
        return WmsApiResponse.success("查询拣选计划成功", pageVo);
    }
}
