package com.wms_main.dao.impl;

import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper;
import com.baomidou.mybatisplus.core.conditions.update.LambdaUpdateWrapper;
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import com.wms_main.dao.ITAppLocationService;
import com.wms_main.mapper.AppLocationMapper;
import com.wms_main.model.po.TAppLocation;
import org.springframework.stereotype.Service;

import java.util.List;

/**
 * 库位表服务实现
 */
@Service
public class TAppLocationServiceImpl extends ServiceImpl<AppLocationMapper, TAppLocation> implements ITAppLocationService {
    @Override
    public List<TAppLocation> getAllLocation(Integer equipmentId) {
        if(equipmentId == null) return null;
        try {
            LambdaQueryWrapper<TAppLocation> queryWrapper = new LambdaQueryWrapper<>();
            queryWrapper.eq(TAppLocation::getEquipmentId, equipmentId);
            queryWrapper.orderByDesc(TAppLocation::getLDepth).orderByDesc(TAppLocation::getLCol).orderByAsc(TAppLocation::getLLayer);
            return this.list(queryWrapper);
        } catch (Exception ex) {
            return null;
        }
    }

    @Override
    public boolean updateLocationOccupy(String location, Integer occupy) {
        try {
            LambdaUpdateWrapper<TAppLocation> updateWrapper = new LambdaUpdateWrapper<>();
            updateWrapper.eq(TAppLocation::getLocationId, location);
            updateWrapper.set(TAppLocation::getIsOccupy, occupy);
            return this.update(updateWrapper);
        } catch (Exception ex) {
            return false;
        }
    }
}
