mirror of https://gitee.com/y_project/RuoYi.git
用户导入
parent
5fc9a63231
commit
ca5b4bc852
|
@ -14,7 +14,7 @@ import com.ruoyi.common.annotation.Log;
|
|||
import com.ruoyi.common.base.AjaxResult;
|
||||
import com.ruoyi.common.enums.BusinessType;
|
||||
import com.ruoyi.common.page.TableDataInfo;
|
||||
import com.ruoyi.common.utils.ExcelUtil;
|
||||
import com.ruoyi.common.utils.poi.ExcelUtil;
|
||||
import com.ruoyi.framework.util.ShiroUtils;
|
||||
import com.ruoyi.quartz.domain.SysJob;
|
||||
import com.ruoyi.quartz.service.ISysJobService;
|
||||
|
|
|
@ -14,7 +14,7 @@ import com.ruoyi.common.annotation.Log;
|
|||
import com.ruoyi.common.base.AjaxResult;
|
||||
import com.ruoyi.common.enums.BusinessType;
|
||||
import com.ruoyi.common.page.TableDataInfo;
|
||||
import com.ruoyi.common.utils.ExcelUtil;
|
||||
import com.ruoyi.common.utils.poi.ExcelUtil;
|
||||
import com.ruoyi.framework.web.base.BaseController;
|
||||
import com.ruoyi.quartz.domain.SysJobLog;
|
||||
import com.ruoyi.quartz.service.ISysJobLogService;
|
||||
|
|
|
@ -12,7 +12,7 @@ import com.ruoyi.common.annotation.Log;
|
|||
import com.ruoyi.common.base.AjaxResult;
|
||||
import com.ruoyi.common.enums.BusinessType;
|
||||
import com.ruoyi.common.page.TableDataInfo;
|
||||
import com.ruoyi.common.utils.ExcelUtil;
|
||||
import com.ruoyi.common.utils.poi.ExcelUtil;
|
||||
import com.ruoyi.system.domain.SysLogininfor;
|
||||
import com.ruoyi.system.service.ISysLogininforService;
|
||||
import com.ruoyi.framework.web.base.BaseController;
|
||||
|
|
|
@ -14,7 +14,7 @@ import com.ruoyi.common.annotation.Log;
|
|||
import com.ruoyi.common.base.AjaxResult;
|
||||
import com.ruoyi.common.enums.BusinessType;
|
||||
import com.ruoyi.common.page.TableDataInfo;
|
||||
import com.ruoyi.common.utils.ExcelUtil;
|
||||
import com.ruoyi.common.utils.poi.ExcelUtil;
|
||||
import com.ruoyi.system.domain.SysOperLog;
|
||||
import com.ruoyi.system.service.ISysOperLogService;
|
||||
import com.ruoyi.framework.web.base.BaseController;
|
||||
|
|
|
@ -14,7 +14,7 @@ import com.ruoyi.common.annotation.Log;
|
|||
import com.ruoyi.common.base.AjaxResult;
|
||||
import com.ruoyi.common.enums.BusinessType;
|
||||
import com.ruoyi.common.page.TableDataInfo;
|
||||
import com.ruoyi.common.utils.ExcelUtil;
|
||||
import com.ruoyi.common.utils.poi.ExcelUtil;
|
||||
import com.ruoyi.framework.util.ShiroUtils;
|
||||
import com.ruoyi.system.domain.SysConfig;
|
||||
import com.ruoyi.system.service.ISysConfigService;
|
||||
|
|
|
@ -14,7 +14,7 @@ import com.ruoyi.common.annotation.Log;
|
|||
import com.ruoyi.common.base.AjaxResult;
|
||||
import com.ruoyi.common.enums.BusinessType;
|
||||
import com.ruoyi.common.page.TableDataInfo;
|
||||
import com.ruoyi.common.utils.ExcelUtil;
|
||||
import com.ruoyi.common.utils.poi.ExcelUtil;
|
||||
import com.ruoyi.framework.util.ShiroUtils;
|
||||
import com.ruoyi.system.domain.SysDictData;
|
||||
import com.ruoyi.system.service.ISysDictDataService;
|
||||
|
|
|
@ -14,7 +14,7 @@ import com.ruoyi.common.annotation.Log;
|
|||
import com.ruoyi.common.base.AjaxResult;
|
||||
import com.ruoyi.common.enums.BusinessType;
|
||||
import com.ruoyi.common.page.TableDataInfo;
|
||||
import com.ruoyi.common.utils.ExcelUtil;
|
||||
import com.ruoyi.common.utils.poi.ExcelUtil;
|
||||
import com.ruoyi.framework.util.ShiroUtils;
|
||||
import com.ruoyi.system.domain.SysDictType;
|
||||
import com.ruoyi.system.service.ISysDictTypeService;
|
||||
|
|
|
@ -14,7 +14,7 @@ import com.ruoyi.common.annotation.Log;
|
|||
import com.ruoyi.common.base.AjaxResult;
|
||||
import com.ruoyi.common.enums.BusinessType;
|
||||
import com.ruoyi.common.page.TableDataInfo;
|
||||
import com.ruoyi.common.utils.ExcelUtil;
|
||||
import com.ruoyi.common.utils.poi.ExcelUtil;
|
||||
import com.ruoyi.framework.util.ShiroUtils;
|
||||
import com.ruoyi.system.domain.SysPost;
|
||||
import com.ruoyi.system.service.ISysPostService;
|
||||
|
|
|
@ -15,7 +15,7 @@ import com.ruoyi.common.annotation.Log;
|
|||
import com.ruoyi.common.base.AjaxResult;
|
||||
import com.ruoyi.common.enums.BusinessType;
|
||||
import com.ruoyi.common.page.TableDataInfo;
|
||||
import com.ruoyi.common.utils.ExcelUtil;
|
||||
import com.ruoyi.common.utils.poi.ExcelUtil;
|
||||
import com.ruoyi.framework.util.ShiroUtils;
|
||||
import com.ruoyi.system.domain.SysRole;
|
||||
import com.ruoyi.system.service.ISysRoleService;
|
||||
|
|
|
@ -16,8 +16,8 @@ import com.ruoyi.common.annotation.Log;
|
|||
import com.ruoyi.common.base.AjaxResult;
|
||||
import com.ruoyi.common.enums.BusinessType;
|
||||
import com.ruoyi.common.page.TableDataInfo;
|
||||
import com.ruoyi.common.utils.ExcelUtil;
|
||||
import com.ruoyi.common.utils.StringUtils;
|
||||
import com.ruoyi.common.utils.poi.ExcelUtil;
|
||||
import com.ruoyi.framework.shiro.service.SysPasswordService;
|
||||
import com.ruoyi.framework.util.ShiroUtils;
|
||||
import com.ruoyi.framework.web.base.BaseController;
|
||||
|
|
|
@ -70,13 +70,13 @@ public @interface Excel
|
|||
public String targetAttr() default "";
|
||||
|
||||
/**
|
||||
* 字段类型( 1:仅导出;2:仅导入)
|
||||
* 字段类型(0:导出导入;1:仅导出;2:仅导入)
|
||||
*/
|
||||
Type type() default Type.EXPORT;
|
||||
Type type() default Type.ALL;
|
||||
|
||||
public enum Type
|
||||
{
|
||||
EXPORT(1), IMPORT(2);
|
||||
ALL(0), EXPORT(1), IMPORT(2);
|
||||
private final int value;
|
||||
|
||||
Type(int value)
|
||||
|
|
|
@ -1,4 +1,4 @@
|
|||
package com.ruoyi.common.utils;
|
||||
package com.ruoyi.common.utils.poi;
|
||||
|
||||
import java.io.File;
|
||||
import java.io.FileOutputStream;
|
||||
|
@ -41,6 +41,9 @@ import com.ruoyi.common.base.AjaxResult;
|
|||
import com.ruoyi.common.config.Global;
|
||||
import com.ruoyi.common.exception.BusinessException;
|
||||
import com.ruoyi.common.reflect.ReflectUtils;
|
||||
import com.ruoyi.common.support.Convert;
|
||||
import com.ruoyi.common.utils.DateUtils;
|
||||
import com.ruoyi.common.utils.StringUtils;
|
||||
|
||||
/**
|
||||
* Excel相关处理
|
||||
|
@ -129,6 +132,7 @@ public class ExcelUtil<T>
|
|||
*/
|
||||
public List<T> importExcel(String sheetName, InputStream is) throws Exception
|
||||
{
|
||||
this.type = Type.IMPORT;
|
||||
this.wb = new XSSFWorkbook(is);
|
||||
List<T> list = new ArrayList<T>();
|
||||
Sheet sheet = null;
|
||||
|
@ -161,8 +165,8 @@ public class ExcelUtil<T>
|
|||
for (int col = 0; col < allFields.length; col++)
|
||||
{
|
||||
Field field = allFields[col];
|
||||
// 将有注解的field存放到map中.
|
||||
if (field.isAnnotationPresent(Excel.class))
|
||||
Excel attr = field.getAnnotation(Excel.class);
|
||||
if (attr != null && (attr.type() == Type.ALL || attr.type() == type))
|
||||
{
|
||||
// 设置类的私有字段属性可访问.
|
||||
field.setAccessible(true);
|
||||
|
@ -187,31 +191,31 @@ public class ExcelUtil<T>
|
|||
Class<?> fieldType = field.getType();
|
||||
if (String.class == fieldType)
|
||||
{
|
||||
String s = String.valueOf(val.toString());
|
||||
String s = Convert.toStr(val);
|
||||
if (StringUtils.endsWith(s, ".0"))
|
||||
{
|
||||
val = StringUtils.substringBefore(s, ".0");
|
||||
}
|
||||
else
|
||||
{
|
||||
val = String.valueOf(val.toString());
|
||||
val = Convert.toStr(val);
|
||||
}
|
||||
}
|
||||
else if ((Integer.TYPE == fieldType) || (Integer.class == fieldType))
|
||||
{
|
||||
val = Double.valueOf(val.toString()).intValue();
|
||||
val = Convert.toInt(val);
|
||||
}
|
||||
else if ((Long.TYPE == fieldType) || (Long.class == fieldType))
|
||||
{
|
||||
val = Double.valueOf(val.toString()).longValue();
|
||||
val = Convert.toLong(val);
|
||||
}
|
||||
else if ((Double.TYPE == fieldType) || (Double.class == fieldType))
|
||||
{
|
||||
val = Double.valueOf(val.toString());
|
||||
val = Convert.toDouble(val);
|
||||
}
|
||||
else if ((Float.TYPE == fieldType) || (Float.class == fieldType))
|
||||
{
|
||||
val = Float.valueOf(val.toString());
|
||||
val = Convert.toFloat(val);
|
||||
}
|
||||
else if (Date.class == fieldType)
|
||||
{
|
||||
|
@ -227,20 +231,16 @@ public class ExcelUtil<T>
|
|||
if (StringUtils.isNotNull(fieldType))
|
||||
{
|
||||
Excel attr = field.getAnnotation(Excel.class);
|
||||
String propertyName = field.getName();
|
||||
if (StringUtils.isNotEmpty(attr.targetAttr()))
|
||||
{
|
||||
|
||||
ReflectUtils.invokeSetter(entity, field.getName() + "." + attr.targetAttr(), val);
|
||||
propertyName = field.getName() + "." + attr.targetAttr();
|
||||
}
|
||||
else if (StringUtils.isNotEmpty(attr.readConverterExp()))
|
||||
{
|
||||
String value = reverseByExp(String.valueOf(val), attr.readConverterExp());
|
||||
ReflectUtils.invokeSetter(entity, field.getName() + "." + attr.targetAttr(), value);
|
||||
}
|
||||
else
|
||||
{
|
||||
ReflectUtils.invokeSetter(entity, field.getName(), val);
|
||||
val = reverseByExp(String.valueOf(val), attr.readConverterExp());
|
||||
}
|
||||
ReflectUtils.invokeSetter(entity, propertyName, val);
|
||||
}
|
||||
}
|
||||
list.add(entity);
|
||||
|
@ -653,7 +653,8 @@ public class ExcelUtil<T>
|
|||
// 得到所有field并存放到一个list中.
|
||||
for (Field field : allFields)
|
||||
{
|
||||
if (field.isAnnotationPresent(Excel.class))
|
||||
Excel attr = field.getAnnotation(Excel.class);
|
||||
if (attr != null && (attr.type() == Type.ALL || attr.type() == type))
|
||||
{
|
||||
fields.add(field);
|
||||
}
|
|
@ -1,10 +1,11 @@
|
|||
package com.ruoyi.system.domain;
|
||||
|
||||
import org.apache.commons.lang3.builder.ToStringBuilder;
|
||||
import org.apache.commons.lang3.builder.ToStringStyle;
|
||||
import java.util.Date;
|
||||
import java.util.List;
|
||||
import org.apache.commons.lang3.builder.ToStringBuilder;
|
||||
import org.apache.commons.lang3.builder.ToStringStyle;
|
||||
import com.ruoyi.common.annotation.Excel;
|
||||
import com.ruoyi.common.annotation.Excel.Type;
|
||||
import com.ruoyi.common.base.BaseEntity;
|
||||
|
||||
/**
|
||||
|
@ -21,6 +22,7 @@ public class SysUser extends BaseEntity
|
|||
private Long userId;
|
||||
|
||||
/** 部门ID */
|
||||
@Excel(name = "部门编号", type = Type.IMPORT)
|
||||
private Long deptId;
|
||||
|
||||
/** 部门父ID */
|
||||
|
@ -63,15 +65,15 @@ public class SysUser extends BaseEntity
|
|||
private String delFlag;
|
||||
|
||||
/** 最后登陆IP */
|
||||
@Excel(name = "最后登陆IP")
|
||||
@Excel(name = "最后登陆IP", type = Type.EXPORT)
|
||||
private String loginIp;
|
||||
|
||||
/** 最后登陆时间 */
|
||||
@Excel(name = "最后登陆时间", width = 30, dateFormat = "yyyy-MM-dd HH:mm:ss")
|
||||
@Excel(name = "最后登陆时间", width = 30, dateFormat = "yyyy-MM-dd HH:mm:ss", type = Type.EXPORT)
|
||||
private Date loginDate;
|
||||
|
||||
/** 部门对象 */
|
||||
@Excel(name = "部门名称", targetAttr = "deptName")
|
||||
@Excel(name = "部门名称", targetAttr = "deptName", type = Type.EXPORT)
|
||||
private SysDept dept;
|
||||
|
||||
private List<SysRole> roles;
|
||||
|
|
Loading…
Reference in New Issue