package com.zehong.system.service.impl;

import java.util.List;

import com.zehong.common.core.domain.entity.SysUser;
import com.zehong.common.utils.DateUtils;
import com.zehong.common.utils.SecurityUtils;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
import com.zehong.system.mapper.TPurchaseMapper;
import com.zehong.system.domain.TPurchase;
import com.zehong.system.service.ITPurchaseService;

/**
 * 外部采购（报销）申请Service业务层处理
 * 
 * @author zehong
 * @date 2023-06-16
 */
@Service
public class TPurchaseServiceImpl implements ITPurchaseService 
{
    @Autowired
    private TPurchaseMapper tPurchaseMapper;

    /**
     * 查询外部采购（报销）申请
     * 
     * @param purchaseId 外部采购（报销）申请ID
     * @return 外部采购（报销）申请
     */
    @Override
    public TPurchase selectTPurchaseById(Long purchaseId)
    {
        return tPurchaseMapper.selectTPurchaseById(purchaseId);
    }

    /**
     * 查询外部采购（报销）申请列表
     * 
     * @param tPurchase 外部采购（报销）申请
     * @return 外部采购（报销）申请
     */
    @Override
    public List<TPurchase> selectTPurchaseList(TPurchase tPurchase)
    {
        return tPurchaseMapper.selectTPurchaseList(tPurchase);
    }

    /**
     * 新增外部采购（报销）申请
     * 
     * @param tPurchase 外部采购（报销）申请
     * @return 结果
     */
    @Override
    public int insertTPurchase(TPurchase tPurchase)
    {
        tPurchase.setCreateTime(DateUtils.getNowDate());
        SysUser user = SecurityUtils.getLoginUser().getUser();
        tPurchase.setPurchaseDeptId(user.getDeptId());
        tPurchase.setHandled_by_user_id(user.getUserId());//经办人
        return tPurchaseMapper.insertTPurchase(tPurchase);
    }

    /**
     * 修改外部采购（报销）申请
     * 
     * @param tPurchase 外部采购（报销）申请
     * @return 结果
     */
    @Override
    public int updateTPurchase(TPurchase tPurchase)
    {
        tPurchase.setUpdateTime(DateUtils.getNowDate());
        return tPurchaseMapper.updateTPurchase(tPurchase);
    }

    /**
     * 批量删除外部采购（报销）申请
     * 
     * @param purchaseIds 需要删除的外部采购（报销）申请ID
     * @return 结果
     */
    @Override
    public int deleteTPurchaseByIds(Long[] purchaseIds)
    {
        return tPurchaseMapper.deleteTPurchaseByIds(purchaseIds);
    }

    /**
     * 删除外部采购（报销）申请信息
     * 
     * @param purchaseId 外部采购（报销）申请ID
     * @return 结果
     */
    @Override
    public int deleteTPurchaseById(Long purchaseId)
    {
        return tPurchaseMapper.deleteTPurchaseById(purchaseId);
    }
}
