package com.fdkankan.ucenter.service.impl;

import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper;
import com.fdkankan.ucenter.entity.SceneDownloadLog;
import com.fdkankan.ucenter.mapper.ISceneDownloadLogMapper;
import com.fdkankan.ucenter.service.ISceneDownloadLogService;
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import org.springframework.stereotype.Service;

import java.util.List;

/**
 * <p>
 *  服务实现类
 * </p>
 *
 * @author 
 * @since 2022-07-13
 */
@Service
public class SceneDownloadLogServiceImpl extends ServiceImpl<ISceneDownloadLogMapper, SceneDownloadLog> implements ISceneDownloadLogService {

    @Override
    public SceneDownloadLog getByStatusAndNum(String sceneNum, Integer status, Integer isUpgrade,Integer version) {
        LambdaQueryWrapper<SceneDownloadLog> wrapper = new LambdaQueryWrapper<>();
        wrapper.eq(SceneDownloadLog::getSceneNum,sceneNum);
        wrapper.eq(SceneDownloadLog::getStatus,status);
        String sysVersion = "v3";
        if(isUpgrade == 1){
            sysVersion = "v4";
        }
        wrapper.eq(SceneDownloadLog::getSysVersion,sysVersion);
        wrapper.eq(SceneDownloadLog::getSceneVersion,version);
        wrapper.orderByDesc(SceneDownloadLog::getCreateTime);
        List<SceneDownloadLog> list = this.list(wrapper);
        if(list != null && list.size() >0){
            return list.get(0);
        }
        return null;
    }
}
