package com.ruoyi.project.invoice.service.impl;

import java.util.List;

import com.ruoyi.common.utils.StringUtils;
import com.ruoyi.project.ehs.mapper.TJobticketMapper;
import com.ruoyi.project.invoice.mapper.TInvoiceWorkcontentMapper;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
import com.ruoyi.project.invoice.mapper.TInvoiceTagMapper;
import com.ruoyi.project.invoice.domain.TInvoiceTag;
import com.ruoyi.project.invoice.service.ITInvoiceTagService;
import org.springframework.transaction.annotation.Transactional;

import javax.annotation.Resource;

/**
 * 工作票索引Service业务层处理
 *
 * @author ruoyi
 * @date 2022-10-09
 */
@Service
public class TInvoiceTagServiceImpl implements ITInvoiceTagService
{
    @Resource
    private TInvoiceTagMapper tInvoiceTagMapper;
    @Resource
    private TInvoiceWorkcontentMapper tInvoiceWorkcontentMapper;
    @Resource
    private TJobticketMapper tJobticketMapper;
    /**
     * 查询工作票索引
     *
     * @param id 工作票索引ID
     * @return 工作票索引
     */
    @Override
    public TInvoiceTag selectTInvoiceTagById(Long id)
    {
        return tInvoiceTagMapper.selectTInvoiceTagById(id);
    }

    /**
     * 查询工作票索引列表
     *
     * @param tInvoiceTag 工作票索引
     * @return 工作票索引
     */
    @Override
    public List<TInvoiceTag> selectTInvoiceTagList(TInvoiceTag tInvoiceTag)
    {
        return tInvoiceTagMapper.selectTInvoiceTagList(tInvoiceTag);
    }

    /**
     * 新增工作票索引
     *
     * @param tInvoiceTag 工作票索引
     * @return 结果
     */
    @Override
    public int insertTInvoiceTag(TInvoiceTag tInvoiceTag)
    {
        return tInvoiceTagMapper.insertTInvoiceTag(tInvoiceTag);
    }

    /**
     * 修改工作票索引
     *
     * @param tInvoiceTag 工作票索引
     * @return 结果
     */
    @Override
    @Transactional
    public int updateTInvoiceTag(TInvoiceTag tInvoiceTag)
    {
        TInvoiceTag oldTag = tInvoiceTagMapper.selectTInvoiceTagById(tInvoiceTag.getId());
        if (oldTag.getTag().equals(tInvoiceTag.getTag()) || StringUtils.isEmpty(tInvoiceTag.getTag())) {
            return tInvoiceTagMapper.updateTInvoiceTag(tInvoiceTag);
        }else {
            oldTag.setTagNew(tInvoiceTag.getTag());
            tInvoiceWorkcontentMapper.updateTag(oldTag);
            tJobticketMapper.updateTag(oldTag);
        }
        return tInvoiceTagMapper.updateTInvoiceTag(tInvoiceTag);
    }

    /**
     * 批量删除工作票索引
     *
     * @param ids 需要删除的工作票索引ID
     * @return 结果
     */
    @Override
    public int deleteTInvoiceTagByIds(Long[] ids)
    {
        return tInvoiceTagMapper.deleteTInvoiceTagByIds(ids);
    }

    /**
     * 删除工作票索引信息
     *
     * @param id 工作票索引ID
     * @return 结果
     */
    @Override
    public int deleteTInvoiceTagById(Long id)
    {
        return tInvoiceTagMapper.deleteTInvoiceTagById(id);
    }
}
