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.ITAppEquipmentService;
import com.wms_main.model.dto.query.EquipmentQuery;
import com.wms_main.model.dto.response.wms.WmsApiResponse;
import com.wms_main.model.po.TAppEquipment;
import com.wms_main.model.vo.wms.EquipmentVo;
import com.wms_main.model.vo.wms.PageVo;
import com.wms_main.repository.utils.StringUtils;
import com.wms_main.service.controller.IEquipmentControllerService;
import lombok.RequiredArgsConstructor;
import lombok.extern.slf4j.Slf4j;
import org.springframework.stereotype.Service;

@Service
@RequiredArgsConstructor
@Slf4j
public class EquipmentControllerServiceImpl implements IEquipmentControllerService {
    private final ITAppEquipmentService equipmentService;

    @Override
    public WmsApiResponse<PageVo<EquipmentVo>> queryEquipmentInfoByPage(EquipmentQuery equipmentQuery) {
        if (equipmentQuery == null) {
            return WmsApiResponse.error("查询参数不能为NULL", null);
        }
        Page<TAppEquipment> page = equipmentQuery.toMpPage();
        LambdaQueryWrapper<TAppEquipment> lambdaQueryWrapper = new LambdaQueryWrapper<TAppEquipment>()
                .eq(equipmentQuery.getEquipmentId() != null, TAppEquipment::getEquipmentId, equipmentQuery.getEquipmentId())
                .eq(equipmentQuery.getEquipmentType() != null, TAppEquipment::getEquipmentType, equipmentQuery.getEquipmentType())
                .eq(equipmentQuery.getEquipmentStatus() != null, TAppEquipment::getEquipmentStatus, equipmentQuery.getEquipmentStatus())
                .like(StringUtils.isNotEmpty(equipmentQuery.getEquipmentName()), TAppEquipment::getEquipmentName, equipmentQuery.getEquipmentName())
                .like(StringUtils.isNotEmpty(equipmentQuery.getEquipmentDesc()), TAppEquipment::getEquipmentDesc, equipmentQuery.getEquipmentDesc());
        Page<TAppEquipment> poPage = equipmentService.page(page, lambdaQueryWrapper);

        PageVo<EquipmentVo> pageVo = PageVo.of(poPage, EquipmentVo::of);
        return WmsApiResponse.success("查询堆垛机成功", pageVo);
    }
}