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.ITAppPickTaskBakService;
import com.wms_main.model.dto.query.PickTaskBakQuery;
import com.wms_main.model.dto.response.wms.WmsApiResponse;
import com.wms_main.model.po.TAppPickTaskBak;
import com.wms_main.model.vo.wms.PageVo;
import com.wms_main.model.vo.wms.PickTaskBakVo;
import com.wms_main.repository.utils.StringUtils;
import com.wms_main.service.controller.IPickTaskBakControllerService;
import lombok.RequiredArgsConstructor;
import lombok.extern.slf4j.Slf4j;
import org.springframework.stereotype.Service;

@Service
@RequiredArgsConstructor
@Slf4j
public class PickTaskBakControllerServiceImpl implements IPickTaskBakControllerService {

    private final ITAppPickTaskBakService appPickTaskBakService;

    /**
     * 查询拣选记录信息（分页）---实现
     *
     * @param pickTaskBakQuery 查询参数
     * @return 查询结果
     */
    @Override
    public WmsApiResponse<PageVo<PickTaskBakVo>> queryPickBakInfoByPage(PickTaskBakQuery pickTaskBakQuery) {
        if (pickTaskBakQuery == null) {
            return WmsApiResponse.error("查询参数不能为NULL", null);
        }
        Page<TAppPickTaskBak> page = pickTaskBakQuery.toMpPage();
        LambdaQueryWrapper<TAppPickTaskBak> lambdaQueryWrapper = new LambdaQueryWrapper<TAppPickTaskBak>()
                .eq(pickTaskBakQuery.getPickStatus() != null, TAppPickTaskBak::getPickStatus, pickTaskBakQuery.getPickStatus())
                .eq(StringUtils.isNotEmpty(pickTaskBakQuery.getVehicleId()), TAppPickTaskBak::getVehicleId, pickTaskBakQuery.getVehicleId())
                .eq(StringUtils.isNotEmpty(pickTaskBakQuery.getPickId()), TAppPickTaskBak::getPickId, pickTaskBakQuery.getPickId());
        Page<TAppPickTaskBak> poPage = appPickTaskBakService.page(page, lambdaQueryWrapper);

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