package io.renren.modules.levelManage.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.datasource.annotation.DataSource;
import io.renren.modules.levelManage.dao.ProjectAttributesDao;
import io.renren.modules.levelManage.entity.ProjectAttributesEntity;
import io.renren.modules.levelManage.service.ProjectAttributesService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

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


@Service("projectAttributesService")
@DataSource("heBing")
public class ProjectAttributesServiceImpl extends ServiceImpl<ProjectAttributesDao, ProjectAttributesEntity> implements ProjectAttributesService {

    @Autowired
    ProjectAttributesDao projectAttributesDao;

    @Override
    public PageUtils queryPage(Map<String, Object> params) {
        IPage<ProjectAttributesEntity> page = this.page(
                new Query<ProjectAttributesEntity>().getPage(params),
                new QueryWrapper<ProjectAttributesEntity>()
        );

        return new PageUtils(page);
    }

    public Integer hasProject(String schema){
        return projectAttributesDao.hasProject(schema);
    }

    public Integer createTable(List<Map<String,String>> cols)
    {
        return projectAttributesDao.createTable(cols);
    }

    public List<Map<String,Object>> listAttribute()
    {
        return projectAttributesDao.listAttribute();
    }

    public Integer countProject(){
        return projectAttributesDao.countProject();
    }

    public List<String> listCols(){
        return projectAttributesDao.listCols();
    }

    public List<Map<String,Object>> listData(List<String> tableCols,Integer page,Integer size){
        if (page != null && size != null){
            page = (page - 1) * size;
        }
        return projectAttributesDao.list(tableCols,page,size);
    }

    public List<String> listBoolCols(){
        return projectAttributesDao.listBoolCols();
    }

    public Map<String,Object> selectById(Long id,List<String> tableCols){
        return projectAttributesDao.selectById(id,tableCols);
    }

    public Long saveWithCols(List<Map<String,Object>> cols){
        return projectAttributesDao.saveWithCols(cols);
    }

    public String selectProjectNameById(Long id){
        return projectAttributesDao.selectProjectNameById(id);
    }

    public Integer updateWithCols(List<Map<String,Object>> cols,Long id){
        return projectAttributesDao.updateWithCols(cols,id);
    }

    public List<Map<String,Object>> selectByName(List<String> tableCols,Integer page,Integer size,String name)
    {
        if (page != null && size != null){
            page = (page - 1) * size;
        }
        return projectAttributesDao.selectByName(tableCols,page,size,name);
    }

    public Integer getCountByName(String name){
        return projectAttributesDao.getCountByName(name);
    }

    public Integer removeProjectByIds(List<Long> ids){
        return projectAttributesDao.removeProjectByIds(ids);
    }

    public Integer dropProject(){
        return projectAttributesDao.dropProject() + projectAttributesDao.truncateProjectAttribute();
    }

    public List<Map<String,Object>> listProjectName(){
        return projectAttributesDao.listProjectName();

    }

    public String countProjectLevel(Long id){
        return projectAttributesDao.countProjectLevel(id);
    }

    public Integer selectRootLevel(Long id){
        return projectAttributesDao.selectRootLevel(id);

    }

    public List<Map<String, Object>> listProjectByUid(Long uid){
        return projectAttributesDao.listProjectByUid(uid);
    }


}