package hw.tagApi.service.service.impl;

import java.util.ArrayList;
import java.util.List;
import hw.tagApi.common.utils.DateUtils;
import hw.tagApi.common.utils.uuid.IdGenerator;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
import hw.tagApi.service.mapper.HwTagRecordMapper;
import hw.tagApi.service.domain.HwTagRecord;
import hw.tagApi.service.service.IHwTagRecordService;

/**
 * 标签记录Service业务层处理
 * 
 * @author Yinq
 * @date 2025-04-15
 */
@Service
public class HwTagRecordServiceImpl implements IHwTagRecordService 
{
    @Autowired
    private HwTagRecordMapper hwTagRecordMapper;

    /**
     * 查询标签记录
     * 
     * @param rId 标签记录主键
     * @return 标签记录
     */
    @Override
    public HwTagRecord selectHwTagRecordByRId(Long rId)
    {
        return hwTagRecordMapper.selectHwTagRecordByRId(rId);
    }

    /**
     * 查询标签记录列表
     * 
     * @param hwTagRecord 标签记录
     * @return 标签记录
     */
    @Override
    public List<HwTagRecord> selectHwTagRecordList(HwTagRecord hwTagRecord)
    {
        return hwTagRecordMapper.selectHwTagRecordList(hwTagRecord);
    }

    /**
     * 新增标签记录
     * 
     * @param hwTagRecord 标签记录
     * @return 结果
     */
    @Override
    public int insertHwTagRecord(HwTagRecord hwTagRecord)
    {
        hwTagRecord.setCreateTime(DateUtils.getNowDate());
        return hwTagRecordMapper.insertHwTagRecord(hwTagRecord);
    }

    /**
     * 修改标签记录
     * 
     * @param hwTagRecord 标签记录
     * @return 结果
     */
    @Override
    public int updateHwTagRecord(HwTagRecord hwTagRecord)
    {
        initTagRecord(hwTagRecord);
        return hwTagRecordMapper.updateHwTagRecord(hwTagRecord);
    }

    /**
     * 批量删除标签记录
     * 
     * @param rIds 需要删除的标签记录主键
     * @return 结果
     */
    @Override
    public int deleteHwTagRecordByRIds(Long[] rIds)
    {
        return hwTagRecordMapper.deleteHwTagRecordByRIds(rIds);
    }

    /**
     * 删除标签记录信息
     * 
     * @param rId 标签记录主键
     * @return 结果
     */
    @Override
    public int deleteHwTagRecordByRId(Long rId)
    {
        return hwTagRecordMapper.deleteHwTagRecordByRId(rId);
    }

    /**
     * 根据TID更新标签记录
     * 
     * @param record 标签记录
     */
    @Override
    public void updateHwTagRecordByTID(HwTagRecord record) {
        hwTagRecordMapper.updateHwTagRecordByTID(record);
    }

    /**
     * 批量插入标签记录
     * 
     * @param batchList 标签记录列表
     */
    @Override
    public void batchInsertHwTagRecord(List<HwTagRecord> batchList) {
        hwTagRecordMapper.batchInsertHwTagRecord(batchList);
    }


    @Override
    public HwTagRecord selectHwTagRecordData(HwTagRecord selectTagRecord) {
        List<HwTagRecord> tagRecordList = hwTagRecordMapper.selectHwTagRecordList(selectTagRecord);
        if (!tagRecordList.isEmpty()){
            return tagRecordList.get(0);
        }
        return null;
    }

    /**
     * 根据TID查询标签记录
     *
     * @param tId TID
     */
    @Override
    public HwTagRecord selectHwTagRecordByTID(String tId) {
        return hwTagRecordMapper.selectHwTagRecordByTxId(tId);
    }

    /**
     * 初始化hwTagRecord
     * @param hwTagRecord hwTagRecord
     */
    public void initTagRecord(HwTagRecord hwTagRecord){
        hwTagRecord.setRId(IdGenerator.nextId());
        hwTagRecord.setCreateTime(DateUtils.getNowDate());
    }
}
