package org.jeecg.modules.bytedance.advertise.service.impl;

import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import org.jeecg.common.util.DateUtils;
import org.jeecg.modules.bytedance.advertise.entity.ByteDanceVideoInfo;
import org.jeecg.modules.bytedance.advertise.mapper.ByteDanceVideoInfoMapper;
import org.jeecg.modules.bytedance.advertise.service.IByteDanceVideoInfoService;
import org.springframework.context.annotation.Primary;
import org.springframework.stereotype.Service;

import javax.annotation.Resource;
import java.util.List;

/**
 * @Description: 今日头条视频素材信息
 * @Author: jeecg-boot
 * @Date: 2019-07-29
 * @Version: V1.0
 */
@Service
@Primary
public class ByteDanceVideoInfoServiceImpl extends ServiceImpl<ByteDanceVideoInfoMapper, ByteDanceVideoInfo> implements IByteDanceVideoInfoService {
    @Resource
    private ByteDanceVideoInfoMapper videoInfoMapper;

    @Override
    public void replaceBatch(List<ByteDanceVideoInfo> videoInfoList) {
        videoInfoMapper.replaceBatch(videoInfoList);
    }

    @Override
    public ByteDanceVideoInfo getOneByParams(Long materialId) {
        QueryWrapper<ByteDanceVideoInfo> queryWrapper = new QueryWrapper<>();
        queryWrapper.eq("material_id",materialId);
        queryWrapper.last("limit 1");
        return this.getOne(queryWrapper);
    }

    @Override
    public void updateMaterialType() {
        videoInfoMapper.updateVideoVerticalType();
        videoInfoMapper.updateVideoHorizonType();
    }

    @Override
    public List<ByteDanceVideoInfo> listByParams(Long projectId,Long accountId, String imageMode,String startTime, String endTime, Long videoCnt,long creativeCnt) {
        String now = DateUtils.formatDate();
        return videoInfoMapper.getNewVideoByParams(projectId,accountId,imageMode,startTime,endTime,videoCnt,creativeCnt,now);
    }

    @Override
    public List<ByteDanceVideoInfo> topMatByParams(Long projectId, Long accountId, String imageMode,String startTime, String endTime, Long videoCnt) {
        String now = DateUtils.formatDate();
        return videoInfoMapper.topMatByParams(projectId,accountId,imageMode,startTime,endTime,videoCnt,now);
    }

    @Override
    public List<ByteDanceVideoInfo> historyMatByParams(Long projectId, Long accountId, String imageMode,String startTime, String endTime, Long videoCnt) {
        String now = DateUtils.formatDate();
        return videoInfoMapper.historyMatByParams(projectId,accountId,imageMode,startTime,endTime,videoCnt,now);
    }


    /**
     * 图片 上新 遗漏
     */
    @Override
    public List<ByteDanceVideoInfo> imageListByParams(Long projectId, Long accountId, String imageMode,String startTime, String endTime, Long videoCnt, long creativeCnt) {
        String now = DateUtils.formatDate();
        return videoInfoMapper.imageListByParams(projectId,accountId,imageMode,startTime,endTime,videoCnt,creativeCnt,now);

    }

    /**
     * 图片 跑量
     */
    @Override
    public List<ByteDanceVideoInfo> imageTopMatByParams(Long projectId, Long accountId, String imageMode,String startTime, String endTime, Long videoCnt) {
        String now = DateUtils.formatDate();
        return videoInfoMapper.imageTopMatByParams(projectId,accountId,imageMode,startTime,endTime,videoCnt,now);
    }

    /**
     * 图片 打捞
     */
    @Override
    public List<ByteDanceVideoInfo> imageHistoryMatByParams(Long projectId, Long accountId, String imageMode,String startTime, String endTime, Long videoCnt) {
        String now = DateUtils.formatDate();
        return videoInfoMapper.imageHistoryMatByParams(projectId,accountId,imageMode,startTime,endTime,videoCnt,now);
    }
}
