package com.wms_main.dao.impl;

import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper;
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import com.wms_main.dao.ITAppStockService;
import com.wms_main.mapper.AppStockMapper;
import com.wms_main.model.po.TAppStock;
import org.springframework.stereotype.Service;

import java.util.List;

/**
 * 库存表服务实现
 */
@Service
public class TAppStockServiceImpl extends ServiceImpl<AppStockMapper, TAppStock> implements ITAppStockService {
    @Override
    public List<TAppStock> getWithEntity(TAppStock entity) {
        if(entity == null) return null;
        try {
            int count = 0;
            LambdaQueryWrapper<TAppStock> queryWrapper = new LambdaQueryWrapper<>();
            if(entity.getStockId() != null) {
                queryWrapper.eq(TAppStock::getStockId, entity.getStockId());
                count++;
            }
            if(entity.getVehicleId() != null) {
                queryWrapper.eq(TAppStock::getVehicleId, entity.getVehicleId());
                count++;
            }
            if(entity.getLocationId() != null) {
                queryWrapper.eq(TAppStock::getLocationId, entity.getLocationId());
                count++;
            }
            if(entity.getStockStatus() != null) {
                queryWrapper.eq(TAppStock::getStockStatus, entity.getStockStatus());
                count++;
            }
            queryWrapper.orderByAsc(TAppStock::getFirstInTime);
            if(count < 1) {
                return null;
            }
            return list(queryWrapper);
        }catch (Exception ex){
            return null;
        }
    }
}
