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.modules.bytedance.advertise.entity.BytedanceImageInfo;
import org.jeecg.modules.bytedance.advertise.mapper.BytedanceImageInfoMapper;
import org.jeecg.modules.bytedance.advertise.service.IBytedanceImageInfoService;
import org.jeecg.modules.bytedance.common.utils.Check;
import org.springframework.stereotype.Service;

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

/**
 * 头条图片素材
 * @author jeecg-boot
 * @date   2020-08-01
 * @version V1.0
 */
@Service
public class BytedanceImageInfoServiceImpl extends ServiceImpl<BytedanceImageInfoMapper, BytedanceImageInfo> implements IBytedanceImageInfoService {
    @Resource
    private BytedanceImageInfoMapper imageInfoMapper;
    @Override
    public void replaceBatch(List<BytedanceImageInfo> videoInfoList) {
        imageInfoMapper.replaceBatch(videoInfoList);
    }

    @Override
    public void updateType() {
        imageInfoMapper.updateImageVerticalType();
        imageInfoMapper.updateImageHorizonType();
    }

    @Override
    public BytedanceImageInfo getByParams(String imageCode) {
        QueryWrapper<BytedanceImageInfo> queryWrapper = new QueryWrapper<>();
        if(!Check.isNull(imageCode)){
            queryWrapper.eq("signature",imageCode);
        }
        queryWrapper.orderByDesc("image_create_time").last("limit 1");
        return this.getOne(queryWrapper);
    }
}
