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

import cn.com.ctop.common.module.utils.Check;
import cn.com.ctop.kuaishou.modules.ai.entity.KuaiShouAppMultipleBids;
import cn.com.ctop.kuaishou.modules.ai.mapper.KuaiShouAppMultipleBidsMapper;
import cn.com.ctop.kuaishou.modules.ai.service.IKuaiShouAppMultipleBidsService;
import com.alibaba.fastjson.JSONArray;
import com.alibaba.fastjson.JSONObject;
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;

/**
 * 多应用分别出价
 *
 * @author jeecg-boot
 * 2021-05-18
 * @version V1.0
 */
@Service
public class KuaiShouAppMultipleBidsServiceImpl extends ServiceImpl<KuaiShouAppMultipleBidsMapper, KuaiShouAppMultipleBids> implements IKuaiShouAppMultipleBidsService {
    @Autowired
    private KuaiShouAppMultipleBidsMapper appMultipleBidsMapper;

    @Override
    public List<JSONObject> getAppInfiList(Long accountId, String appIdArray) {
        if (!Check.isNull(appIdArray)) {
            JSONArray jsonArray = JSONArray.parseArray(appIdArray);
            List<JSONObject> appInfoList = appMultipleBidsMapper.getAppInfoList(accountId, jsonArray);
            return appInfoList;

        }
        return null;
    }

    @Override
    public KuaiShouAppMultipleBids getInfoByAccountAndAppId(Long accountId, Long appId) {
        QueryWrapper<KuaiShouAppMultipleBids> queryWrapper = new QueryWrapper<>();
        queryWrapper.eq("account_id", accountId);
        queryWrapper.eq("app_id", appId);
        queryWrapper.orderByDesc("create_time");
        queryWrapper.last("limit 1");
        return this.getOne(queryWrapper);
    }
}
