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.AlgorithmTemplateMapper;
import io.renren.modules.sys.dao.algs.CategoryMapper;
import io.renren.modules.sys.entity.SysUserEntity;
import io.renren.modules.sys.entity.algs.AlgorithmTemplate;
import io.renren.modules.sys.entity.algs.CategoryEntity;
import io.renren.modules.sys.service.AlgsTemplsService;
import io.renren.modules.sys.service.CategoryService;
import org.apache.commons.lang.StringUtils;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

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


/**
 * @Author: Ivan Q
 * @Date: 2021/5/31 16:22
 */
@Service("categoryService")
public class CategoryServiceImpl extends ServiceImpl<CategoryMapper, CategoryEntity> implements CategoryService {
    @Autowired
    CategoryMapper categoryMapper;

    @Override
    public PageUtils queryPage(Map<String, Object> params) {
        String categoryName = (String)params.get("categoryName");
            IPage<CategoryEntity> page = this.page(
                    new Query<CategoryEntity>().getPage(params),
                    new QueryWrapper<CategoryEntity>()
                            .like(StringUtils.isNotBlank(categoryName),"name", categoryName)
        );
            return new PageUtils(page);

    }

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

    @Override
    public Long getByName(String classificationtag) {

        return categoryMapper.getByName(classificationtag);
    }


}
