package com.playlet.system.service.impl;


import java.util.Date;
import java.util.List;

import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
import com.baomidou.mybatisplus.core.metadata.IPage;
import com.baomidou.mybatisplus.core.toolkit.ObjectUtils;
import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import com.playlet.common.utils.DateUtils;
import com.playlet.system.pojo.dto.PlayletItemSearchRequestDTO;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
import com.playlet.system.mapper.PlayletItemMapper;
import com.playlet.system.domain.PlayletItem;
import com.playlet.system.service.IPlayletItemService;
import com.playlet.common.core.text.Convert;
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;

/**
 * @Date: 2024-03-14-22:53
 * @Author: 但星霖
 * @Version: v1.0
 * @Description: 短剧基础Service业务层处理
 */
@Service
public class PlayletItemServiceImpl extends ServiceImpl<PlayletItemMapper, PlayletItem> implements IPlayletItemService {
    @Autowired
    private PlayletItemMapper playletItemMapper;

    /**
     * 查询短剧基础
     *
     * @param id 短剧基础主键
     * @return 短剧基础
     */
    @Override
    public PlayletItem selectPlayletItemById(Long id) {
        return playletItemMapper.selectPlayletItemById(id);
    }

    /**
     * 查询短剧基础列表
     *
     * @param playletItem 短剧基础
     * @return 短剧基础
     */
    @Override
    public List<PlayletItem> selectPlayletItemList(PlayletItem playletItem) {
        return playletItemMapper.selectPlayletItemList(playletItem);
    }

    /**
     * 新增短剧基础
     *
     * @param playletItem 短剧基础
     * @return 结果
     */
    @Override
    public int insertPlayletItem(PlayletItem playletItem) {
        playletItem.setCreateTime(DateUtils.getNowDate());
        return playletItemMapper.insertPlayletItem(playletItem);
    }

    /**
     * 修改短剧基础
     *
     * @param playletItem 短剧基础
     * @return 结果
     */
    @Override
    public int updatePlayletItem(PlayletItem playletItem) {
        playletItem.setUpdateTime(DateUtils.getNowDate());
        return playletItemMapper.updatePlayletItem(playletItem);
    }

    /**
     * 批量删除短剧基础
     *
     * @param ids 需要删除的短剧基础主键
     * @return 结果
     */
    @Override
    public int deletePlayletItemByIds(String ids) {
        return playletItemMapper.deletePlayletItemByIds(Convert.toStrArray(ids));
    }

    /**
     * 删除短剧基础信息
     *
     * @param id 短剧基础主键
     * @return 结果
     */
    @Override
    public int deletePlayletItemById(Long id) {
        return playletItemMapper.deletePlayletItemById(id);
    }

    @Override
    public IPage<PlayletItem> search(PlayletItemSearchRequestDTO requestResp) {
        QueryWrapper<PlayletItem> wrapper = new QueryWrapper<>();
        wrapper.select()
                .lambda()
                // id 精准
                .eq(ObjectUtils.isNotNull(requestResp.getId()), PlayletItem::getId, requestResp.getId())
                // 视频名称
                .like(ObjectUtils.isNotNull(requestResp.getVideoName()), PlayletItem::getVideoName, requestResp.getVideoName())
                // 上映年份
                .eq(ObjectUtils.isNotNull(requestResp.getReleaseDate()), PlayletItem::getReleaseDate, requestResp.getReleaseDate())
                // 地区
                .eq(ObjectUtils.isNotNull(requestResp.getRegion()), PlayletItem::getRegion, requestResp.getRegion())
                // 视频类型1 科幻 2 爱情 3 恐怖 4 悬疑..
                .eq(ObjectUtils.isNotNull(requestResp.getVideoType()), PlayletItem::getVideoType, requestResp.getVideoType())

                // 评分 大于等于
                .ge(ObjectUtils.isNotNull(requestResp.getScore()), PlayletItem::getScore, requestResp.getScore())
                // 集数 大于等于
                .like(ObjectUtils.isNotNull(requestResp.getNumberEpisode()), PlayletItem::getNumberEpisode, requestResp.getNumberEpisode())
                // 上映时间
                .like(ObjectUtils.isNotNull(requestResp.getReleaseTime()), PlayletItem::getReleaseTime, requestResp.getReleaseTime());
        return baseMapper.selectPage(new Page<>(requestResp.getCurrent(), requestResp.getPageSize()), wrapper);
    }
}
