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.StringUtils;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
import com.ruoyi.shipping.mapper.TCntrMapper;
import com.ruoyi.shipping.domain.TCntr;
import com.ruoyi.shipping.service.ITCntrService;

/**
 * 集装箱Service业务层处理
 * 
 * @author ruoyi
 * @date 2021-03-22
 */
@Service
public class TCntrServiceImpl implements ITCntrService 
{
    @Autowired
    private TCntrMapper tCntrMapper;

    /**
     * 查询集装箱
     * 
     * @param fId 集装箱ID
     * @return 集装箱
     */
    @Override
    public TCntr selectTCntrById(Long fId)
    {
        return tCntrMapper.selectTCntrById(fId);
    }

    /**
     * 查询集装箱列表
     * 
     * @param tCntr 集装箱
     * @return 集装箱
     */
    @Override
    public List<TCntr> selectTCntrList(TCntr tCntr)
    {
        return tCntrMapper.selectTCntrList(tCntr);
    }

    /**
     * 新增集装箱
     * 
     * @param tCntr 集装箱
     * @return 结果
     */
    @Override
    public int insertTCntr(TCntr tCntr)
    {
        tCntr.setCreateTime(DateUtils.getNowDate());
        tCntr.setCreateBy(SecurityUtils.getUsername());
        return tCntrMapper.insertTCntr(tCntr);
    }

    /**
     * 修改集装箱
     * 
     * @param tCntr 集装箱
     * @return 结果
     */
    @Override
    public int updateTCntr(TCntr tCntr)
    {
        tCntr.setUpdateTime(DateUtils.getNowDate());
        tCntr.setUpdateBy(SecurityUtils.getUsername());
        return tCntrMapper.updateTCntr(tCntr);
    }

    /**
     * 批量删除集装箱
     * 
     * @param fIds 需要删除的集装箱ID
     * @return 结果
     */
    @Override
    public int deleteTCntrByIds(Long[] fIds)
    {
        return tCntrMapper.deleteTCntrByIds(fIds);
    }

    /**
     * 删除集装箱信息
     * 
     * @param fId 集装箱ID
     * @return 结果
     */
    @Override
    public int deleteTCntrById(Long fId)
    {
        return tCntrMapper.deleteTCntrById(fId);
    }

    @Override
    public List<Map<String, Object>> selectRcntrName(TCntr tCntr) {
        return tCntrMapper.selectRcntrName(tCntr);
    }

    @Override
    public String selectTcnrFno(TCntr tCntr) {
        TCntr cntr = tCntrMapper.selectTcnrFno(tCntr.getfNo());
        if (StringUtils.isNotNull(cntr) && !cntr.getfId().equals(tCntr.getfId())) {
            return UserConstants.NOT_UNIQUE;
        }
        return UserConstants.UNIQUE;
    }

    @Override
    public String selectTcnrFName(TCntr tCntr) {
        TCntr cntr = tCntrMapper.selectTcnrFName(tCntr.getfName());
        if (StringUtils.isNotNull(cntr) && !cntr.getfId().equals(tCntr.getfId())) {
            return UserConstants.NOT_UNIQUE;
        }
        return UserConstants.UNIQUE;

    }
}
