package com.fs.oms.service.impl;

import java.util.List;
import com.fs.common.utils.DateUtils;
import com.fs.oms.vo.OmsWarehouseVO;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
import com.fs.oms.mapper.OmsWarehouseMapper;
import com.fs.oms.domain.OmsWarehouse;
import com.fs.oms.service.IOmsWarehouseService;

/**
 * 仓库Service业务层处理
 *
 * @author fs
 * @date 2023-05-24
 */
@Service
public class OmsWarehouseServiceImpl implements IOmsWarehouseService
{
    @Autowired
    private OmsWarehouseMapper omsWarehouseMapper;

    /**
     * 查询仓库
     *
     * @param warehouseId 仓库ID
     * @return 仓库
     */
    @Override
    public OmsWarehouse selectOmsWarehouseById(Long warehouseId)
    {
        return omsWarehouseMapper.selectOmsWarehouseById(warehouseId);
    }

    /**
     * 查询仓库列表
     *
     * @param omsWarehouse 仓库
     * @return 仓库
     */
    @Override
    public List<OmsWarehouse> selectOmsWarehouseList(OmsWarehouse omsWarehouse)
    {
        return omsWarehouseMapper.selectOmsWarehouseList(omsWarehouse);
    }

    //查询渠道仓/逻辑仓
//    @Override
//    public List<OmsWarehouseVO> selectOmsStoreList1VO(OmsWarehouse omsWarehouse) {
//        return omsWarehouseMapper.selectOmsStoreList1VO(omsWarehouse);
//    }

    /**
     * 查询仓库列表
     *
     * @param omsWarehouse 仓库
     * @return 仓库
     */
    @Override
    public List<OmsWarehouseVO> selectOmsStoreListVO(OmsWarehouse omsWarehouse)
    {
        return omsWarehouseMapper.selectOmsStoreListVO(omsWarehouse);
    }


    /**
     * 新增仓库
     *
     * @param omsWarehouse 仓库
     * @return 结果
     */
    @Override
    public int insertOmsWarehouse(OmsWarehouse omsWarehouse) {
        omsWarehouse.setCreateTime(DateUtils.getNowDate());
        if(omsWarehouse.getRate()>0){
            double rate=omsWarehouse.getRate()/100.0;
            omsWarehouse.setRate(rate);
        }
        if(omsWarehouseMapper.insertOmsWarehouse(omsWarehouse)>0){
            String warehouseCode="CO"+String.format("%08d",omsWarehouse.getWarehouseId());
            omsWarehouse.setWarehouseCode(warehouseCode);
        }
        return omsWarehouseMapper.updateOmsWarehouse(omsWarehouse);
    }

    /**
     * 修改仓库
     *
     * @param omsWarehouse 仓库
     * @return 结果
     */
    @Override
    public int updateOmsWarehouse(OmsWarehouse omsWarehouse)
    {
        omsWarehouse.setUpdateTime(DateUtils.getNowDate());
        if(omsWarehouse.getRate()>0){
            double rate=omsWarehouse.getRate()/100.0;
            omsWarehouse.setRate(rate);
        }
        return omsWarehouseMapper.updateOmsWarehouse(omsWarehouse);
    }

    /**
     * 批量删除仓库
     *
     * @param warehouseIds 需要删除的仓库ID
     * @return 结果
     */
    @Override
    public int deleteOmsWarehouseByIds(Long[] warehouseIds)
    {
        return omsWarehouseMapper.deleteOmsWarehouseByIds(warehouseIds);
    }

    /**
     * 删除仓库信息
     *
     * @param warehouseId 仓库ID
     * @return 结果
     */
    @Override
    public int deleteOmsWarehouseById(Long warehouseId)
    {
        return omsWarehouseMapper.deleteOmsWarehouseById(warehouseId);
    }

    @Override
    public List<OmsWarehouse> selectOmsWarehouseName(OmsWarehouse omsWarehouse) {
        return omsWarehouseMapper.selectOmsWarehouseName(omsWarehouse);
    }
}
