package com.yunfeiyun.agmp.fms.service.impl;

import java.util.List;

import com.yunfeiyun.agmp.common.utils.DateUtils;
import com.yunfeiyun.agmp.common.utils.SecurityUtils;
import com.yunfeiyun.agmp.common.utils.StringUtils;
import com.yunfeiyun.agmp.fms.domain.WmsWarehouse;
import com.yunfeiyun.agmp.fms.mapper.WmsWarehouseMapper;
import com.yunfeiyun.agmp.fms.service.IWmsWarehouseService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
import org.springframework.util.ObjectUtils;


/**
 * 仓库Service业务层处理
 *
 * @author 杨晓辉
 * @date 2023-05-25
 */
@Service
public class WmsWarehouseServiceImpl implements IWmsWarehouseService
{
    @Autowired
    private WmsWarehouseMapper wmsWarehouseMapper;

    /**
     * 查询仓库
     *
     * @param warehouseId 仓库主键
     * @return 仓库
     */
    @Override
    public WmsWarehouse selectWmsWarehouseByWarehouseId(String warehouseId)
    {
        return wmsWarehouseMapper.selectWmsWarehouseByWarehouseId(warehouseId);
    }

    /**
     * 查询仓库列表
     *
     * @param wmsWarehouse 仓库
     * @return 仓库
     */
    @Override
    public List<WmsWarehouse> selectWmsWarehouseList(WmsWarehouse wmsWarehouse)
    {
        return wmsWarehouseMapper.selectWmsWarehouseList(wmsWarehouse);
    }

    /**
     * 新增仓库
     *
     * @param wmsWarehouse 仓库
     * @return 结果
     */
    @Override
    public int insertWmsWarehouse(WmsWarehouse wmsWarehouse)
    {
        wmsWarehouse.setWarehouseId(wmsWarehouse.getId());
        wmsWarehouse.setWarehouseCreator(SecurityUtils.getUserId());
        wmsWarehouse.setWarehouseCreatorname(SecurityUtils.getUsername());
        wmsWarehouse.setWarehouseCreateddate(DateUtils.getTime());
        return wmsWarehouseMapper.insertWmsWarehouse(wmsWarehouse);
    }

    /**
     * 修改仓库
     *
     * @param wmsWarehouse 仓库
     * @return 结果
     */
    @Override
    public int updateWmsWarehouse(WmsWarehouse wmsWarehouse)
    {
        if(StringUtils.isEmpty(wmsWarehouse.getWarehouseId()) || ObjectUtils.isEmpty(wmsWarehouseMapper.selectWmsWarehouseByWarehouseId(wmsWarehouse.getWarehouseId())))
        {
            return 0;
        }
        return wmsWarehouseMapper.updateWmsWarehouse(wmsWarehouse);
    }

    /**
     * 批量删除仓库
     *
     * @param warehouseIds 需要删除的仓库主键
     * @return 结果
     */
    @Override
    public int deleteWmsWarehouseByWarehouseIds(String[] warehouseIds)
    {
        return wmsWarehouseMapper.deleteWmsWarehouseByWarehouseIds(warehouseIds);
    }

    /**
     * 删除仓库信息
     *
     * @param warehouseId 仓库主键
     * @return 结果
     */
    @Override
    public int deleteWmsWarehouseByWarehouseId(String warehouseId)
    {
        return wmsWarehouseMapper.deleteWmsWarehouseByWarehouseId(warehouseId);
    }
}
