package com.ruoyi.frequency.hosearch.service.impl;

import java.util.List;
import com.ruoyi.common.utils.DateUtils;
import com.ruoyi.controller.req.HotSearchListReq;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import com.ruoyi.code.PublicCommon;
import com.ruoyi.frequency.hosearch.mapper.HotSearchMapper;
import com.ruoyi.frequency.hosearch.entity.HotSearch;
import com.ruoyi.frequency.hosearch.service.HotSearchService;

/**
 * 热门搜索记录Service业务层处理
 *
 * @author liwenlong
 * @date 2024-03-19
 */
@Service
public class HotSearchServiceImpl extends ServiceImpl<HotSearchMapper, HotSearch>  implements HotSearchService
{
    @Autowired
    private HotSearchMapper hotSearchMapper;

    /**
     * 查询热门搜索记录
     *
     * @param id 热门搜索记录主键
     * @return 热门搜索记录
     */
    @Override
    public HotSearch selectHotSearchById(Long id)
    {
        return hotSearchMapper.selectHotSearchById(id);
    }

    /**
     * 查询热门搜索记录列表
     *
     * @param hotSearch 热门搜索记录
     * @return 热门搜索记录
     */
    @Override
    public List<HotSearch> selectHotSearchList(HotSearch hotSearch)
    {
        return hotSearchMapper.selectHotSearchList(hotSearch);
    }

    /**
     * 新增热门搜索记录
     *
     * @param hotSearch 热门搜索记录
     * @return 结果
     */
    @Override
    public int insertHotSearch(HotSearch hotSearch)
    {
        hotSearch.setCreateData();
        return hotSearchMapper.insert(hotSearch);
    }

    /**
     * 修改热门搜索记录
     *
     * @param hotSearch 热门搜索记录
     * @return 结果
     */
    @Override
    public int updateHotSearch(HotSearch hotSearch)
    {
        hotSearch.setUpdateData();
        return hotSearchMapper.updateHotSearch(hotSearch);
    }

    /**
     * 批量删除热门搜索记录
     *
     * @param ids 需要删除的热门搜索记录主键
     * @return 结果
     */
    @Override
    public int deleteHotSearchByIds(Long[] ids,Integer delFlag)
    {
        this.lambdaUpdate().set(HotSearch::getDelFlag,delFlag).in(HotSearch::getId,ids).update();
        return ids.length;
    }

    @Override
    public List<HotSearch> hotSearchList(HotSearchListReq req) {
        return this.baseMapper.hotSearchList(req);
    }

    @Override
    public void addHotSearch(HotSearch hotSearch, Boolean isSuccess) {
        hotSearch.setUpdateData();
        hotSearch.setSuccessTimes(isSuccess?1:0);
        hotSearch.setFailTimes(isSuccess?0:1);
        this.baseMapper.addHotSearch(hotSearch,isSuccess);
    }
}
