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

import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
import com.baomidou.mybatisplus.core.metadata.IPage;
import com.baomidou.mybatisplus.core.toolkit.StringUtils;
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import io.renren.common.utils.PageUtils;
import io.renren.common.utils.Query;
import io.renren.datasource.annotation.DataSource;
import io.renren.modules.generator.dao.AlgorithmDao;
import io.renren.modules.generator.entity.AlgorithmEntity;
import io.renren.modules.generator.service.AlgorithmService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.util.Map;


@Service
public class AlgorithmServiceImpl extends ServiceImpl<AlgorithmDao, AlgorithmEntity> implements AlgorithmService {

//    @Autowired
//    AlgorithmDao algorithmDao;
//
//    public boolean updateById(AlgorithmEntity algorithm) {
//        if (algorithmDao.updateById(algorithm) == 1) {
//            return true;
//        }
//        return false;
//    }

    @Override
    /*
          增加了算法种类进行查找
          通过Params传来的参数获取categoryId进行调用
     */
    public PageUtils queryPage(Map<String, Object> params) {
        String categoryId = (String) params.get("categoryId");
        String algorithmName = (String) params.get("search");

        IPage<AlgorithmEntity> page = this.page(
                new Query<AlgorithmEntity>().getPage(params),
                new QueryWrapper<AlgorithmEntity>()
                        .eq(StringUtils.isNotBlank(categoryId), "category_id", categoryId)
                        .like(StringUtils.isNotBlank(algorithmName), "algorithm_name", algorithmName)
        );

        return new PageUtils(page);
    }

}