Search in sources :

Example 6 with EntityInfoCache

use of com.diboot.core.binding.parser.EntityInfoCache in project diboot by dibo-software.

the class ContextHelper method getIServiceByEntity.

/**
 * 根据Entity获取对应的IService实现
 * @param entity
 * @return
 */
public static IService getIServiceByEntity(Class entity) {
    EntityInfoCache entityInfoCache = BindingCacheManager.getEntityInfoByClass(entity);
    IService iService = entityInfoCache != null ? entityInfoCache.getService() : null;
    if (iService == null) {
        log.info("未能识别到Entity: " + entity.getName() + " 的IService实现!");
    }
    return iService;
}
Also used : EntityInfoCache(com.diboot.core.binding.parser.EntityInfoCache) IService(com.baomidou.mybatisplus.extension.service.IService)

Example 7 with EntityInfoCache

use of com.diboot.core.binding.parser.EntityInfoCache in project diboot by dibo-software.

the class ContextHelper method getBaseServiceByEntity.

/**
 * 根据Entity获取对应的BaseService实现
 * @param entity
 * @return
 */
public static BaseService getBaseServiceByEntity(Class entity) {
    EntityInfoCache entityInfoCache = BindingCacheManager.getEntityInfoByClass(entity);
    IService iService = entityInfoCache != null ? entityInfoCache.getService() : null;
    if (iService == null) {
        log.info("未能识别到Entity: " + entity.getName() + " 的Service实现!");
    }
    if (iService instanceof BaseService) {
        return (BaseService) iService;
    }
    return null;
}
Also used : EntityInfoCache(com.diboot.core.binding.parser.EntityInfoCache) IService(com.baomidou.mybatisplus.extension.service.IService) BaseService(com.diboot.core.service.BaseService)

Example 8 with EntityInfoCache

use of com.diboot.core.binding.parser.EntityInfoCache in project diboot by dibo-software.

the class ServiceAdaptor method convertToIPage.

/**
 * 转换为IPage
 * @param pagination 分页
 * @return
 */
public static <E> Page<E> convertToIPage(Pagination pagination, Class entityClass) {
    if (pagination == null) {
        return null;
    }
    // 如果是默认id排序
    if (pagination.isDefaultOrderBy()) {
        // 优化排序
        String pk = ContextHelper.getIdFieldName(entityClass);
        // 主键非有序id字段,需要清空默认排序以免报错
        if (!Cons.FieldName.id.name().equals(pk)) {
            pagination.clearDefaultOrder();
            // 设置时间排序
            EntityInfoCache entityInfoCache = BindingCacheManager.getEntityInfoByClass(entityClass);
            if (entityInfoCache.containsColumn(Cons.COLUMN_CREATE_TIME)) {
                pagination.setDefaultCreateTimeOrderBy();
            }
        }
    }
    return pagination.toPage();
}
Also used : EntityInfoCache(com.diboot.core.binding.parser.EntityInfoCache)

Aggregations

EntityInfoCache (com.diboot.core.binding.parser.EntityInfoCache)8 LambdaQueryWrapper (com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper)3 QueryWrapper (com.baomidou.mybatisplus.core.conditions.query.QueryWrapper)3 IService (com.baomidou.mybatisplus.extension.service.IService)3 BaseMapper (com.baomidou.mybatisplus.core.mapper.BaseMapper)2 DynamicJoinQueryWrapper (com.diboot.core.binding.query.dynamic.DynamicJoinQueryWrapper)2 BaseService (com.diboot.core.service.BaseService)2 LambdaMeta (com.baomidou.mybatisplus.core.toolkit.support.LambdaMeta)1 StaticMemoryCacheManager (com.diboot.core.cache.StaticMemoryCacheManager)1 Dictionary (com.diboot.core.entity.Dictionary)1 BusinessException (com.diboot.core.exception.BusinessException)1 InvalidUsageException (com.diboot.core.exception.InvalidUsageException)1 CcCityInfo (diboot.core.test.binder.entity.CcCityInfo)1 SimpleDictionaryVO (diboot.core.test.binder.vo.SimpleDictionaryVO)1 Serializable (java.io.Serializable)1 ParameterizedType (java.lang.reflect.ParameterizedType)1 Type (java.lang.reflect.Type)1 SqlSessionFactory (org.apache.ibatis.session.SqlSessionFactory)1 Test (org.junit.Test)1 SpringBootTest (org.springframework.boot.test.context.SpringBootTest)1