package cn.com.ctop.kuaishou.modules.batch.service.impl;

import cn.com.ctop.common.module.utils.Check;
import cn.com.ctop.kuaishou.modules.batch.entity.KuaiShouImageGet;
import cn.com.ctop.kuaishou.modules.batch.mapper.KuaiShouImageGetMapper;
import cn.com.ctop.kuaishou.modules.batch.service.IKuaiShouImageGetService;
import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.util.List;

/**
 * @Description: 快手-获取图片接口
 * @Author: jeecg-boot
 * @Date: 2019-12-03
 * @Version: V1.0
 */
@Service
public class KuaiShouImageGetServiceImpl extends ServiceImpl<KuaiShouImageGetMapper, KuaiShouImageGet> implements IKuaiShouImageGetService {
    @Autowired
    private KuaiShouImageGetMapper imageGetMapper;

    @Override
    public void replaceBatch(List<KuaiShouImageGet> imageGets) {
        imageGetMapper.replaceBatch(imageGets);
    }

    @Override
    public String getUrlByCode(String signature) {
        String url = imageGetMapper.getUrlByCode(signature);
        if (!Check.isNull(url)) {
            return url;
        } else {
            return imageGetMapper.getCutFrameUrlByCode(signature);
        }


    }


    @Override
    public KuaiShouImageGet getOneByParams(String url,String code) {
        QueryWrapper<KuaiShouImageGet> queryWrapper= new QueryWrapper<>();
        if(null!=url&&!"".equals(url.trim())){
            queryWrapper.eq("url",url);
        }
        if(null!=code&&!"".equals(code.trim())){
            queryWrapper.eq("signature",code);
        }
        queryWrapper.orderByDesc("create_time");
        queryWrapper.last("limit 1");
        return this.getOne(queryWrapper);
    }

}
