package com.ruoyi.shipping.service.impl;

import java.util.List;

import com.ruoyi.common.core.domain.AjaxResult;
import com.ruoyi.common.utils.DateUtils;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
import com.ruoyi.shipping.mapper.TFeeInvoiceMapper;
import com.ruoyi.shipping.domain.TFeeInvoice;
import com.ruoyi.shipping.service.ITFeeInvoiceService;

/**
 * 发票从Service业务层处理
 * 
 * @author ruoyi
 * @date 2021-04-22
 */
@Service
public class TFeeInvoiceServiceImpl implements ITFeeInvoiceService 
{
    @Autowired
    private TFeeInvoiceMapper tFeeInvoiceMapper;

    /**
     * 查询发票从
     * 
     * @param fId 发票从ID
     * @return 发票从
     */
    @Override
    public TFeeInvoice selectTFeeInvoiceById(Long fId)
    {
        return tFeeInvoiceMapper.selectTFeeInvoiceById(fId);
    }

    /**
     * 查询发票从列表
     * 
     * @param tFeeInvoice 发票从
     * @return 发票从
     */
    @Override
    public List<TFeeInvoice> selectTFeeInvoiceList(TFeeInvoice tFeeInvoice)
    {
        return tFeeInvoiceMapper.selectTFeeInvoiceList(tFeeInvoice);
    }

    /**
     * 新增发票从
     * 
     * @param tFeeInvoice 发票从
     * @return 结果
     */
    @Override
    public int insertTFeeInvoice(TFeeInvoice tFeeInvoice)
    {
        tFeeInvoice.setCreateTime(DateUtils.getNowDate());
        return tFeeInvoiceMapper.insertTFeeInvoice(tFeeInvoice);
    }

    /**
     * 修改发票从
     * 
     * @param tFeeInvoice 发票从
     * @return 结果
     */
    @Override
    public int updateTFeeInvoice(TFeeInvoice tFeeInvoice)
    {
        tFeeInvoice.setUpdateTime(DateUtils.getNowDate());
        return tFeeInvoiceMapper.updateTFeeInvoice(tFeeInvoice);
    }

    /**
     * 批量删除发票从
     * 
     * @param fIds 需要删除的发票从ID
     * @return 结果
     */
    @Override
    public int deleteTFeeInvoiceByIds(Long[] fIds)
    {
        return tFeeInvoiceMapper.deleteTFeeInvoiceByIds(fIds);
    }

    /**
     * 删除发票从信息
     * 
     * @param fId 发票从ID
     * @return 结果
     */
    @Override
    public AjaxResult deleteTFeeInvoiceById(Long fId)
    {
        TFeeInvoice tFeeInvoice = tFeeInvoiceMapper.selectTFeeInvoiceById(fId);
        if ("4".equals(tFeeInvoice.getfBillstatus())
                || "5".equals(tFeeInvoice.getfBillstatus())
                ||"6".equals(tFeeInvoice.getfBillstatus())){
            return AjaxResult.error("数据已提交审批,暂不能删除");
        }
        Integer i = tFeeInvoiceMapper.deleteTFeeInvoiceById(fId);
        if (i != null && i >0){
            return AjaxResult.success();
        }else {
            return AjaxResult.error("删除失败,请找管理员");
        }

    }
}
