package com.ruoyi.shipping.service.impl;

import java.util.List;
import java.util.Map;

import com.ruoyi.common.constant.UserConstants;
import com.ruoyi.common.utils.DateUtils;
import com.ruoyi.common.utils.SecurityUtils;
import com.ruoyi.common.utils.SecurityUtils;
import com.ruoyi.common.utils.StringUtils;
import com.ruoyi.shipping.domain.TAddress;
import com.ruoyi.shipping.mapper.TAddressMapper;
import com.ruoyi.shipping.service.ITAddressService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.util.Date;
import java.util.List;
import java.util.Map;

/**
 * 地点基础信息（港口 码头 堆场 航线）Service业务层处理
 * 
 * @author ruoyi
 * @date 2021-03-22
 */
@Service
public class TAddressServiceImpl implements ITAddressService 
{
    @Autowired
    private TAddressMapper tAddressMapper;

    /**
     * 查询地点基础信息（港口 码头 堆场 航线）
     * 
     * @param fId 地点基础信息（港口 码头 堆场 航线）ID
     * @return 地点基础信息（港口 码头 堆场 航线）
     */
    @Override
    public TAddress selectTAddressById(Long fId)
    {
        return tAddressMapper.selectTAddressById(fId);
    }

    /**
     * 查询地点基础信息（港口 码头 堆场 航线）列表
     * 
     * @param tAddress 地点基础信息（港口 码头 堆场 航线）
     * @return 地点基础信息（港口 码头 堆场 航线）
     */
    @Override
    public List<TAddress> selectTAddressList(TAddress tAddress)
    {
        return tAddressMapper.selectTAddressList(tAddress);
    }

    @Override
    public List<TAddress> selectCarriageList(TAddress tAddress) {
        return tAddressMapper.selectCarriageList(tAddress);
    }

    @Override
    public List<Map<String, Object>> selectTAddressListMap(TAddress tAddress) {
        return tAddressMapper.selectTAddressListMap(tAddress);
    }

    /**
     * 新增地点基础信息（港口 码头 堆场 航线）
     * 
     * @param tAddress 地点基础信息（港口 码头 堆场 航线）
     * @return 结果
     */
    @Override
    public int insertTAddress(TAddress tAddress)
    {
        tAddress.setCreateTime(DateUtils.getNowDate());
        tAddress.setCreateBy(SecurityUtils.getUsername());
        return tAddressMapper.insertTAddress(tAddress);
    }

    /**
     * 修改地点基础信息（港口 码头 堆场 航线）
     * 
     * @param tAddress 地点基础信息（港口 码头 堆场 航线）
     * @return 结果
     */
    @Override
    public int updateTAddress(TAddress tAddress)
    {
        tAddress.setUpdateTime(DateUtils.getNowDate());
        tAddress.setUpdateBy(SecurityUtils.getUsername());
        return tAddressMapper.updateTAddress(tAddress);
    }

    /**
     * 批量删除地点基础信息（港口 码头 堆场 航线）
     * 
     * @param fIds 需要删除的地点基础信息（港口 码头 堆场 航线）ID
     * @return 结果
     */
    @Override
    public int deleteTAddressByIds(Long[] fIds)
    {
        return tAddressMapper.deleteTAddressByIds(fIds);
    }

    /**
     * 删除地点基础信息（港口 码头 堆场 航线）信息
     * 
     * @param fId 地点基础信息（港口 码头 堆场 航线）ID
     * @return 结果
     */
    @Override
    public int deleteTAddressById(Long fId)
    {
        return tAddressMapper.deleteTAddressById(fId);
    }

    @Override
    public int updateTAddressStatus(Long[] fIds) {
        return tAddressMapper.updateTAddressStatus(fIds);
    }

    @Override
    public List<TAddress> selectStockDump(TAddress tAddress) {
        return tAddressMapper.selectStockDump(tAddress);
    }

    @Override
    public List<TAddress> selectPortDump(TAddress tAddress) {
        return tAddressMapper.selectPortDump(tAddress);
    }

    @Override
    public List<TAddress> selectWarfDump(TAddress tAddress) {
        return tAddressMapper.selectWarfDump(tAddress);
    }

    @Override
    public List<Map<String, Object>> selectPortName(TAddress tAddress) {
        return tAddressMapper.selectPortName(tAddress);
    }

    @Override
    public List<Map<String, Object>> selectWharfName(TAddress tAddress) {
        return tAddressMapper.selectWharfName(tAddress);
    }

    @Override
    public List<Map<String, Object>> selectStorageName(TAddress tAddress) {
        return tAddressMapper.selectStorageName(tAddress);
    }

    @Override
    public List<Map<String, Object>> selectAirLineName(TAddress tAddress) {
        return tAddressMapper.selectAirLineName(tAddress);
    }

    /**
     *  查询地点基础 下拉信息
     * @param tAddress  条件
     * @return  结果
     */
    @Override
    public List<TAddress> selectTAddressBasicList(TAddress tAddress) {
        return tAddressMapper.selectTAddressBasicList(tAddress);
    }

    @Override
    public String selectAddressFno(TAddress tAddress) {
        TAddress address = tAddressMapper.selectAddressFno(tAddress);
        if (StringUtils.isNotNull(address) && !address.getfId().equals(tAddress.getfId())) {
            return UserConstants.NOT_UNIQUE;
        }
        return UserConstants.UNIQUE;
    }

    @Override
    public String selectAddressFName(TAddress tAddress) {
        TAddress address = tAddressMapper.selectAddressFName(tAddress);
        if (StringUtils.isNotNull(address) && !address.getfId().equals(tAddress.getfId())) {
            return UserConstants.NOT_UNIQUE;
        }
        return UserConstants.UNIQUE;
    }

    @Override
    public List<TAddress> selectadress() {
        return tAddressMapper.selectadress();
    }
}
