package io.renren.modules.sys.service.impl;

import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
import com.baomidou.mybatisplus.core.metadata.IPage;
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import io.renren.common.utils.PageUtils;
import io.renren.common.utils.Query;
import io.renren.modules.sys.dao.algs.AlgorithmModelMapper;
import io.renren.modules.sys.dao.algs.AlgorithmVoMapper;
import io.renren.modules.sys.dao.algs.VersionMapper;
import io.renren.modules.sys.entity.SysUserEntity;
import io.renren.modules.sys.entity.algs.Algorithm;
import io.renren.modules.sys.entity.algs.AlgorithmModel;
import io.renren.modules.sys.entity.algs.Algorithm_Vo;
import io.renren.modules.sys.entity.algs.Version;
import io.renren.modules.sys.service.AlgsModelsService;
import io.renren.modules.sys.service.CategoryService;
import io.renren.modules.sys.service.VersionService;
import org.apache.commons.lang.StringUtils;
import org.apache.ibatis.annotations.Mapper;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
import org.springframework.transaction.annotation.Transactional;

import java.util.Arrays;
import java.util.List;
import java.util.Map;

/**
 * @Author: Ivan Q
 * @Date: 2021/6/17 10:36
 */
@Service("versionService")
public class VersionServiceImpl extends ServiceImpl<VersionMapper, Version> implements VersionService {

    @Autowired
    VersionMapper versionMapper;


    @Override
    public PageUtils queryPageOnUse(Map<String, Object> params) {
        Long algorithmNameToVersion = (Long) params.get("algorithmNameToVersion");

        IPage<Version> page = this.page(
                new Query<Version>().getPage(params),
                new QueryWrapper<Version>()
                        .eq(algorithmNameToVersion != null,"algorithm_id", algorithmNameToVersion)
                        .eq(true,"delete_status", (byte)0)
        );

        return new PageUtils(page);
    }

    @Override
    public void deleteBatch(Long[] alglIds) {
        this.removeByIds(Arrays.asList(alglIds));
    }

    @Override
    public Long querycategoryId(Long algId) {
        return null;
    }

    @Override
    @Transactional
    public void update(Version version) {
        this.updateById(version);
    }

    @Override
    public Long getMaxId() {
        return versionMapper.getMaxId();
    }


}
