package com.ruoyi.system.service.impl;

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

import com.ruoyi.common.utils.DateUtils;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
import com.ruoyi.system.mapper.TGoodsMapper;
import com.ruoyi.system.domain.TGoods;
import com.ruoyi.system.service.ITGoodsService;

/**
 * 物品Service业务层处理
 * 
 * @author ruoyi
 * @date 2024-02-20
 */
@Service
public class TGoodsServiceImpl implements ITGoodsService 
{
    @Autowired
    private TGoodsMapper tGoodsMapper;

    /**
     * 查询物品
     * 
     * @param id 物品主键
     * @return 物品
     */
    @Override
    public TGoods selectTGoodsById(Long id)
    {
        return tGoodsMapper.selectTGoodsById(id);
    }

    /**
     * 查询物品列表
     * 
     * @param tGoods 物品
     * @return 物品
     */
    @Override
    public List<TGoods> selectTGoodsList(TGoods tGoods)
    {
        if (tGoods.getLoginUserId() != null) {
            tGoods.setRoleId(tGoodsMapper.getRoleIdByUser(tGoods.getLoginUserId()));
        }
        return tGoodsMapper.selectTGoodsList(tGoods);
    }

    /**
     * 新增物品
     * 
     * @param tGoods 物品
     * @return 结果
     */
    @Override
    public int insertTGoods(TGoods tGoods)
    {
        tGoods.setCreateTime(DateUtils.getNowDate());
        return tGoodsMapper.insertTGoods(tGoods);
    }

    /**
     * 修改物品
     * 
     * @param tGoods 物品
     * @return 结果
     */
    @Override
    public int updateTGoods(TGoods tGoods)
    {
        tGoods.setUpdateTime(DateUtils.getNowDate());
        return tGoodsMapper.updateTGoods(tGoods);
    }

    /**
     * 批量删除物品
     * 
     * @param ids 需要删除的物品主键
     * @return 结果
     */
    @Override
    public int deleteTGoodsByIds(Long[] ids)
    {
        return tGoodsMapper.deleteTGoodsByIds(ids);
    }

    /**
     * 删除物品信息
     * 
     * @param id 物品主键
     * @return 结果
     */
    @Override
    public int deleteTGoodsById(Long id)
    {
        return tGoodsMapper.deleteTGoodsById(id);
    }

    @Override
    public List<Map<String, Object>> getKuFangList(Long userId) {
        Long roleId = tGoodsMapper.getRoleIdByUser(userId);
        return tGoodsMapper.getKuFangList(userId, roleId);
    }
}
