package com.bohuikeji.frame.module.admin.base;

import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
import com.baomidou.mybatisplus.core.conditions.update.UpdateWrapper;
import com.baomidou.mybatisplus.core.toolkit.TableInfoHelper;
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import com.bohuikeji.frame.module.admin.utils.ObjectUtils;
import lombok.extern.slf4j.Slf4j;

import java.util.List;

/**
 * 接口实现类父类
 * @param <M> mapper
 * @param <T> 实体
 * @author 孙劲辉
 */
@Slf4j
public class ServiceImplBase<M extends RanchBaseMapper<T>, T extends EntityBase<T>> extends ServiceImpl<M, T> implements ServiceBase<T>{


    @Override
    public <E> E selectColumnById(Integer id, String clm, Class<E> type) {
        Object obj=baseMapper.selectColumnById(clm,id);
        if(obj==null){
            return null;
        }
        if (type.isInstance(obj)){
            return type.cast(obj);
        }
        return ObjectUtils.convert(obj,type);
    }

    @Override
    public T selectOneByColumn(String clm,Object val) {
        return getOne(new QueryWrapper<T>().eq(clm,val),false);
    }

    @Override
    public List<T> listByColumn(String clm, Object val) {
        return list(new QueryWrapper<T>().eq(clm,val));
    }

    @Override
    public boolean updateColumnById(Integer id, String clm, Object val) {
        /*TableInfoHelper.getTableInfo();
        getById()
        update(new UpdateWrapper<T>().eq())*/
        return false;
    }
}
