Search in sources :

Example 11 with IService

use of com.baomidou.mybatisplus.extension.service.IService in project jeecg-boot by jeecgboot.

the class ImportExcelUtil method importDateSaveOne.

public static List<String> importDateSaveOne(Object obj, Class serviceClass, List<String> errorMessage, int i, String errorFlag) {
    IService bean = (IService) SpringContextUtils.getBean(serviceClass);
    try {
        boolean save = bean.save(obj);
        if (!save) {
            throw new Exception(errorFlag);
        }
    } catch (Exception e) {
        String message = e.getMessage().toLowerCase();
        int lineNumber = i + 1;
        // 通过索引名判断出错信息
        if (message.contains(CommonConstant.SQL_INDEX_UNIQ_SYS_ROLE_CODE)) {
            errorMessage.add("第 " + lineNumber + " 行:角色编码已经存在,忽略导入。");
        } else if (message.contains(CommonConstant.SQL_INDEX_UNIQ_JOB_CLASS_NAME)) {
            errorMessage.add("第 " + lineNumber + " 行:任务类名已经存在,忽略导入。");
        } else if (message.contains(CommonConstant.SQL_INDEX_UNIQ_CODE)) {
            errorMessage.add("第 " + lineNumber + " 行:职务编码已经存在,忽略导入。");
        } else if (message.contains(CommonConstant.SQL_INDEX_UNIQ_DEPART_ORG_CODE)) {
            errorMessage.add("第 " + lineNumber + " 行:部门编码已经存在,忽略导入。");
        } else {
            errorMessage.add("第 " + lineNumber + " 行:未知错误,忽略导入");
            log.error(e.getMessage(), e);
        }
    }
    return errorMessage;
}
Also used : IService(com.baomidou.mybatisplus.extension.service.IService) IOException(java.io.IOException)

Example 12 with IService

use of com.baomidou.mybatisplus.extension.service.IService in project kykms by mahonelau.

the class ImportExcelUtil method importDateSaveOne.

public static List<String> importDateSaveOne(Object obj, Class serviceClass, List<String> errorMessage, int i, String errorFlag) {
    IService bean = (IService) SpringContextUtils.getBean(serviceClass);
    try {
        boolean save = bean.save(obj);
        if (!save) {
            throw new Exception(errorFlag);
        }
    } catch (Exception e) {
        String message = e.getMessage().toLowerCase();
        int lineNumber = i + 1;
        // 通过索引名判断出错信息
        if (message.contains(CommonConstant.SQL_INDEX_UNIQ_SYS_ROLE_CODE)) {
            errorMessage.add("第 " + lineNumber + " 行:角色编码已经存在,忽略导入。");
        } else if (message.contains(CommonConstant.SQL_INDEX_UNIQ_JOB_CLASS_NAME)) {
            errorMessage.add("第 " + lineNumber + " 行:任务类名已经存在,忽略导入。");
        } else if (message.contains(CommonConstant.SQL_INDEX_UNIQ_CODE)) {
            errorMessage.add("第 " + lineNumber + " 行:职务编码已经存在,忽略导入。");
        } else if (message.contains(CommonConstant.SQL_INDEX_UNIQ_DEPART_ORG_CODE)) {
            errorMessage.add("第 " + lineNumber + " 行:部门编码已经存在,忽略导入。");
        } else {
            errorMessage.add("第 " + lineNumber + " 行:未知错误,忽略导入");
            log.error(e.getMessage(), e);
        }
    }
    return errorMessage;
}
Also used : IService(com.baomidou.mybatisplus.extension.service.IService) IOException(java.io.IOException)

Example 13 with IService

use of com.baomidou.mybatisplus.extension.service.IService in project springboot-learning by lyb-geek.

the class UpdateWapperAspect method updateEntity.

/**
 *重写update(Wrapper<T> updateWrapper), 更新时自动填充不生效问题
 * @param pjp
 * @return
 */
private Object updateEntity(ProceedingJoinPoint pjp) {
    Object[] args = pjp.getArgs();
    if (args != null && args.length == 1) {
        Object arg = args[0];
        if (arg instanceof Wrapper) {
            Wrapper updateWrapper = (Wrapper) arg;
            Object entity = updateWrapper.getEntity();
            IService service = (IService) applicationContext.getBean(pjp.getTarget().getClass());
            if (ObjectUtils.isEmpty(entity)) {
                entity = entityMap.get(pjp.getTarget().getClass().getName());
                if (ObjectUtils.isEmpty(entity)) {
                    Class entityClz = ReflectionKit.getSuperClassGenericType(pjp.getTarget().getClass(), 1);
                    try {
                        entity = entityClz.newInstance();
                    } catch (InstantiationException e) {
                        log.warn("Entity instantiating exception!");
                    } catch (IllegalAccessException e) {
                        log.warn("Entity illegal access exception!");
                    }
                    entityMap.put(pjp.getTarget().getClass().getName(), entity);
                }
            }
            return service.update(entity, updateWrapper);
        }
    }
    return null;
}
Also used : Wrapper(com.baomidou.mybatisplus.core.conditions.Wrapper) IService(com.baomidou.mybatisplus.extension.service.IService)

Aggregations

IService (com.baomidou.mybatisplus.extension.service.IService)13 IOException (java.io.IOException)6 EntityInfoCache (com.diboot.core.binding.parser.EntityInfoCache)3 InvalidUsageException (com.diboot.core.exception.InvalidUsageException)3 Wrapper (com.baomidou.mybatisplus.core.conditions.Wrapper)1 BaseMapper (com.baomidou.mybatisplus.core.mapper.BaseMapper)1 IPage (com.baomidou.mybatisplus.core.metadata.IPage)1 Page (com.baomidou.mybatisplus.extension.plugins.pagination.Page)1 DynamicJoinQueryWrapper (com.diboot.core.binding.query.dynamic.DynamicJoinQueryWrapper)1 StaticMemoryCacheManager (com.diboot.core.cache.StaticMemoryCacheManager)1 BaseService (com.diboot.core.service.BaseService)1 Field (java.lang.reflect.Field)1 ParameterizedType (java.lang.reflect.ParameterizedType)1 Type (java.lang.reflect.Type)1 SqlSessionFactory (org.apache.ibatis.session.SqlSessionFactory)1 Primary (org.springframework.context.annotation.Primary)1