package com.ruoyi.mall.service.impl;

import java.util.List;
import com.ruoyi.common.utils.DateUtils;
import com.ruoyi.common.utils.StringUtils;
import com.ruoyi.mall.domain.Vo.ContrastRecordVo;
import com.ruoyi.mall.mapper.MallSchoolTagMapper;
import jdk.nashorn.internal.ir.annotations.Reference;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
import com.ruoyi.mall.mapper.ContrastRecordMapper;
import com.ruoyi.mall.domain.ContrastRecord;
import com.ruoyi.mall.service.IContrastRecordService;

import javax.annotation.Resource;

/**
 * 添加对比记录Service业务层处理
 * 
 * @author ruoyi
 * @date 2023-10-27
 */
@Service
public class ContrastRecordServiceImpl implements IContrastRecordService 
{
    @Resource
    private ContrastRecordMapper contrastRecordMapper;
    @Resource
    private MallSchoolTagMapper mallSchoolTagMapper;
    /**
     * 查询添加对比记录
     * 
     * @param recordId 添加对比记录主键
     * @return 添加对比记录
     */
    @Override
    public ContrastRecord selectContrastRecordByRecordId(Long recordId)
    {
        return contrastRecordMapper.selectContrastRecordByRecordId(recordId);
    }

    /**
     * 查询添加对比记录列表
     * 
     * @param contrastRecord 添加对比记录
     * @return 添加对比记录
     */
    @Override
    public List<ContrastRecord> selectContrastRecordList(ContrastRecord contrastRecord)
    {
        return contrastRecordMapper.selectContrastRecordList(contrastRecord);
    }
    /**
     * 查询已添加对比记录列表 vo 大学对比 已添加学校列表展示
     * @param contrastRecordVo 添加对比记录
     * @return 添加对比记录集合（含学校详细信息）
     */
    @Override
    public List<ContrastRecordVo> selectContrastRecordVoList(ContrastRecordVo contrastRecordVo)
    {
        //查询 记录表和学校表的联合查询
        List<ContrastRecordVo> contrastRecordVos = contrastRecordMapper.selectVoListForContrast(contrastRecordVo);
        //再添加 每个学校的标签组
        for (ContrastRecordVo vo : contrastRecordVos) {
            if (StringUtils.isNotBlank(vo.getTags())) {
                List<String> list = mallSchoolTagMapper.selectTagByTagId(vo.getTags());
                vo.setTagList(list);
            }
        }
        return contrastRecordVos;
    }

    /**
     * 新增添加对比记录
     * 
     * @param contrastRecord 添加对比记录
     * @return 结果
     */
    @Override
    public int insertContrastRecord(ContrastRecord contrastRecord)
    {
        contrastRecord.setCreateTime(DateUtils.getNowDate());
        return contrastRecordMapper.insertContrastRecord(contrastRecord);
    }

    /**
     * 修改添加对比记录
     * 
     * @param contrastRecord 添加对比记录
     * @return 结果
     */
    @Override
    public int updateContrastRecord(ContrastRecord contrastRecord)
    {
        contrastRecord.setUpdateTime(DateUtils.getNowDate());
        return contrastRecordMapper.updateContrastRecord(contrastRecord);
    }

    /**
     * 批量删除添加对比记录
     * 
     * @param recordIds 需要删除的添加对比记录主键
     * @return 结果
     */
    @Override
    public int deleteContrastRecordByRecordIds(Long[] recordIds)
    {
        return contrastRecordMapper.deleteContrastRecordByRecordIds(recordIds);
    }

    /**
     * 删除添加对比记录信息
     * 
     * @param recordId 添加对比记录主键
     * @return 结果
     */
    @Override
    public int deleteContrastRecordByRecordId(Long recordId)
    {
        return contrastRecordMapper.deleteContrastRecordByRecordId(recordId);
    }
}
