package com.ruoyi.dezhi.service.impl;

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

import com.ruoyi.mxjb.domain.MxjbContants;
import org.apache.commons.collections4.CollectionUtils;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import com.alibaba.fastjson.JSONObject;
import com.ruoyi.dezhi.domain.BBusiDezhiVideo;
import com.ruoyi.dezhi.mapper.BBusiDezhiVideoMapper;
import com.ruoyi.dezhi.service.IBBusiDezhiVideoService;

/**
 * 视频接口Service业务层处理
 * 
 * @author mingxue
 * @date 2021-07-22
 */
@Service
public class BBusiDezhiVideoServiceImpl implements IBBusiDezhiVideoService 
{
    @Autowired
    private BBusiDezhiVideoMapper bBusiDezhiVideoMapper;

    /**
     * 查询视频接口
     * 
     * @param id 视频接口ID
     * @return 视频接口
     */
    @Override
    public BBusiDezhiVideo selectBBusiDezhiVideoById(Long id)
    {
        return bBusiDezhiVideoMapper.selectBBusiDezhiVideoById(id);
    }

    /**
     * 查询视频接口列表
     * 
     * @param bBusiDezhiVideo 视频接口
     * @return 视频接口
     */
    @Override
    public List<BBusiDezhiVideo> selectBBusiDezhiVideoList(BBusiDezhiVideo bBusiDezhiVideo)
    {
        return bBusiDezhiVideoMapper.selectBBusiDezhiVideoList(bBusiDezhiVideo);
    }

   
    @Override
    public List<JSONObject> selectVideoList(Map<String, Object> params) {
        List<JSONObject> arr = bBusiDezhiVideoMapper.selectVideoList(params);
        arr.stream().forEach(t -> t.put("aliIdType", MxjbContants.Ali_Id_dezhi));
        return arr;
    }

    //单独用来取app首页中名师精讲数据 20210826 莫
    @Override
    public List<JSONObject> selectVideoList2(Map<String, Object> params) {
        List<JSONObject> arr = bBusiDezhiVideoMapper.selectVideoList2(params);
        arr.stream().forEach(t -> t.put("aliIdType", MxjbContants.Ali_Id_dezhi));
        return arr;
    }

    @Override
    public List<JSONObject> searchInfoByPackId(String packId) {
        List<JSONObject> arr = bBusiDezhiVideoMapper.searchInfoByPackId(packId);
        arr.stream().forEach(t -> t.put("aliIdType", MxjbContants.Ali_Id_dezhi));
        return arr;
    }

    /**
     * 新增视频接口
     * 
     * @param bBusiDezhiVideo 视频接口
     * @return 结果
     */
    @Override
    public int insertBBusiDezhiVideo(BBusiDezhiVideo bBusiDezhiVideo)
    {
        return bBusiDezhiVideoMapper.insertBBusiDezhiVideo(bBusiDezhiVideo);
    }

    /**
     * 修改视频接口
     * 
     * @param bBusiDezhiVideo 视频接口
     * @return 结果
     */
    @Override
    public int updateBBusiDezhiVideo(BBusiDezhiVideo bBusiDezhiVideo)
    {
        return bBusiDezhiVideoMapper.updateBBusiDezhiVideo(bBusiDezhiVideo);
    }

    /**
     * 批量删除视频接口
     * 
     * @param ids 需要删除的视频接口ID
     * @return 结果
     */
    @Override
    public int deleteBBusiDezhiVideoByIds(Long[] ids)
    {
        return bBusiDezhiVideoMapper.deleteBBusiDezhiVideoByIds(ids);
    }

    /**
     * 删除视频接口信息
     * 
     * @param id 视频接口ID
     * @return 结果
     */
    @Override
    public int deleteBBusiDezhiVideoById(Long id)
    {
        return bBusiDezhiVideoMapper.deleteBBusiDezhiVideoById(id);
    }

    @Override
    public BBusiDezhiVideo selectBySection(String sectionId) {
        BBusiDezhiVideo query = new BBusiDezhiVideo();
        query.setSectionAliid(sectionId);
        List<BBusiDezhiVideo> list = this.selectBBusiDezhiVideoList(query);
        if(CollectionUtils.isEmpty(list)) {
            query.setSectionAliid(null);
            query.setSectionId(sectionId);
            list = this.selectBBusiDezhiVideoList(query);
        }
        return CollectionUtils.isEmpty(list) ? null : list.get(0);
    }
}
