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

import com.alibaba.fastjson.JSONArray;
import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import org.jeecg.modules.bytedance.advertise.entity.BytedanceVideoSlogenInfo;
import org.jeecg.modules.bytedance.advertise.mapper.BytedanceVideoSlogenInfoMapper;
import org.jeecg.modules.bytedance.advertise.service.IBytedanceVideoSlogenInfoService;
import org.jeecg.modules.bytedance.common.utils.Check;
import org.springframework.stereotype.Service;

import java.util.List;

/**
 * 头条视频文案信息
 * @author jeecg-boot
 * 2021-04-19
 * @version V1.0
 */
@Service
public class BytedanceVideoSlogenInfoServiceImpl extends ServiceImpl<BytedanceVideoSlogenInfoMapper, BytedanceVideoSlogenInfo> implements IBytedanceVideoSlogenInfoService {
    @Override
    public void insertSlogans(String videoCode, JSONArray slogans,String userId){
        if(null==slogans||slogans.isEmpty()){
            return;
        }
        for(int i=0;i<slogans.size();i++){
            String slogan = slogans.getString(i);
            BytedanceVideoSlogenInfo slogenInfo = new BytedanceVideoSlogenInfo(videoCode,slogan,userId);
            this.save(slogenInfo);
        }
    }

    @Override
    public List<BytedanceVideoSlogenInfo> listByParams(String code, Integer status) {
        QueryWrapper<BytedanceVideoSlogenInfo>queryWrapper =new QueryWrapper<>();
        if(!Check.isNull(code)){
            queryWrapper.eq("video_code",code);
        }
        if(!Check.isNull(status)){
            queryWrapper.eq("status",status);
        }
        queryWrapper.orderByDesc("id");
        return this.list(queryWrapper);
    }
}
