新增枚举字典的Excel导入和导出方式
This commit is contained in:
parent
b821142387
commit
6867dce91d
|
|
@ -2,6 +2,7 @@ package com.ruoyi.system.api.domain;
|
||||||
|
|
||||||
import javax.validation.constraints.NotBlank;
|
import javax.validation.constraints.NotBlank;
|
||||||
import javax.validation.constraints.Size;
|
import javax.validation.constraints.Size;
|
||||||
|
import com.ruoyi.system.api.emun.EnableStatusEnum;
|
||||||
import org.apache.commons.lang3.builder.ToStringBuilder;
|
import org.apache.commons.lang3.builder.ToStringBuilder;
|
||||||
import org.apache.commons.lang3.builder.ToStringStyle;
|
import org.apache.commons.lang3.builder.ToStringStyle;
|
||||||
import com.ruoyi.common.core.annotation.Excel;
|
import com.ruoyi.common.core.annotation.Excel;
|
||||||
|
|
@ -11,7 +12,7 @@ import com.ruoyi.common.core.web.domain.BaseEntity;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* 字典数据表 sys_dict_data
|
* 字典数据表 sys_dict_data
|
||||||
*
|
*
|
||||||
* @author ruoyi
|
* @author ruoyi
|
||||||
*/
|
*/
|
||||||
public class SysDictData extends BaseEntity
|
public class SysDictData extends BaseEntity
|
||||||
|
|
@ -48,8 +49,11 @@ public class SysDictData extends BaseEntity
|
||||||
@Excel(name = "是否默认", readConverterExp = "Y=是,N=否")
|
@Excel(name = "是否默认", readConverterExp = "Y=是,N=否")
|
||||||
private String isDefault;
|
private String isDefault;
|
||||||
|
|
||||||
/** 状态(0正常 1停用) */
|
/**
|
||||||
@Excel(name = "状态", readConverterExp = "0=正常,1=停用")
|
* 状态(0正常 1停用)
|
||||||
|
* @see EnableStatusEnum
|
||||||
|
**/
|
||||||
|
@Excel(name = "状态", readConverterEnum = EnableStatusEnum.class)
|
||||||
private String status;
|
private String status;
|
||||||
|
|
||||||
public Long getDictCode()
|
public Long getDictCode()
|
||||||
|
|
@ -153,7 +157,7 @@ public class SysDictData extends BaseEntity
|
||||||
{
|
{
|
||||||
this.status = status;
|
this.status = status;
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public String toString() {
|
public String toString() {
|
||||||
return new ToStringBuilder(this,ToStringStyle.MULTI_LINE_STYLE)
|
return new ToStringBuilder(this,ToStringStyle.MULTI_LINE_STYLE)
|
||||||
|
|
|
||||||
|
|
@ -3,6 +3,7 @@ package com.ruoyi.system.api.domain;
|
||||||
import javax.validation.constraints.NotBlank;
|
import javax.validation.constraints.NotBlank;
|
||||||
import javax.validation.constraints.Pattern;
|
import javax.validation.constraints.Pattern;
|
||||||
import javax.validation.constraints.Size;
|
import javax.validation.constraints.Size;
|
||||||
|
import com.ruoyi.system.api.emun.EnableStatusEnum;
|
||||||
import org.apache.commons.lang3.builder.ToStringBuilder;
|
import org.apache.commons.lang3.builder.ToStringBuilder;
|
||||||
import org.apache.commons.lang3.builder.ToStringStyle;
|
import org.apache.commons.lang3.builder.ToStringStyle;
|
||||||
import com.ruoyi.common.core.annotation.Excel;
|
import com.ruoyi.common.core.annotation.Excel;
|
||||||
|
|
@ -11,7 +12,7 @@ import com.ruoyi.common.core.web.domain.BaseEntity;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* 字典类型表 sys_dict_type
|
* 字典类型表 sys_dict_type
|
||||||
*
|
*
|
||||||
* @author ruoyi
|
* @author ruoyi
|
||||||
*/
|
*/
|
||||||
public class SysDictType extends BaseEntity
|
public class SysDictType extends BaseEntity
|
||||||
|
|
@ -30,8 +31,11 @@ public class SysDictType extends BaseEntity
|
||||||
@Excel(name = "字典类型")
|
@Excel(name = "字典类型")
|
||||||
private String dictType;
|
private String dictType;
|
||||||
|
|
||||||
/** 状态(0正常 1停用) */
|
/**
|
||||||
@Excel(name = "状态", readConverterExp = "0=正常,1=停用")
|
* 状态(0正常 1停用)
|
||||||
|
* @see EnableStatusEnum
|
||||||
|
**/
|
||||||
|
@Excel(name = "状态", readConverterEnum = EnableStatusEnum.class)
|
||||||
private String status;
|
private String status;
|
||||||
|
|
||||||
public Long getDictId()
|
public Long getDictId()
|
||||||
|
|
@ -78,7 +82,7 @@ public class SysDictType extends BaseEntity
|
||||||
{
|
{
|
||||||
this.status = status;
|
this.status = status;
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public String toString() {
|
public String toString() {
|
||||||
return new ToStringBuilder(this,ToStringStyle.MULTI_LINE_STYLE)
|
return new ToStringBuilder(this,ToStringStyle.MULTI_LINE_STYLE)
|
||||||
|
|
|
||||||
|
|
@ -4,6 +4,7 @@ import java.util.Set;
|
||||||
import javax.validation.constraints.NotBlank;
|
import javax.validation.constraints.NotBlank;
|
||||||
import javax.validation.constraints.NotNull;
|
import javax.validation.constraints.NotNull;
|
||||||
import javax.validation.constraints.Size;
|
import javax.validation.constraints.Size;
|
||||||
|
import com.ruoyi.system.api.emun.EnableStatusEnum;
|
||||||
import org.apache.commons.lang3.builder.ToStringBuilder;
|
import org.apache.commons.lang3.builder.ToStringBuilder;
|
||||||
import org.apache.commons.lang3.builder.ToStringStyle;
|
import org.apache.commons.lang3.builder.ToStringStyle;
|
||||||
import com.ruoyi.common.core.annotation.Excel;
|
import com.ruoyi.common.core.annotation.Excel;
|
||||||
|
|
@ -12,7 +13,7 @@ import com.ruoyi.common.core.web.domain.BaseEntity;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* 角色表 sys_role
|
* 角色表 sys_role
|
||||||
*
|
*
|
||||||
* @author ruoyi
|
* @author ruoyi
|
||||||
*/
|
*/
|
||||||
public class SysRole extends BaseEntity
|
public class SysRole extends BaseEntity
|
||||||
|
|
@ -45,8 +46,11 @@ public class SysRole extends BaseEntity
|
||||||
/** 部门树选择项是否关联显示(0:父子不互相关联显示 1:父子互相关联显示 ) */
|
/** 部门树选择项是否关联显示(0:父子不互相关联显示 1:父子互相关联显示 ) */
|
||||||
private boolean deptCheckStrictly;
|
private boolean deptCheckStrictly;
|
||||||
|
|
||||||
/** 角色状态(0正常 1停用) */
|
/**
|
||||||
@Excel(name = "角色状态", readConverterExp = "0=正常,1=停用")
|
* 角色状态(0正常 1停用)
|
||||||
|
* @see EnableStatusEnum
|
||||||
|
**/
|
||||||
|
@Excel(name = "角色状态", readConverterEnum = EnableStatusEnum.class)
|
||||||
private String status;
|
private String status;
|
||||||
|
|
||||||
/** 删除标志(0代表存在 2代表删除) */
|
/** 删除标志(0代表存在 2代表删除) */
|
||||||
|
|
|
||||||
|
|
@ -3,6 +3,7 @@ package com.ruoyi.system.api.domain;
|
||||||
import java.util.Date;
|
import java.util.Date;
|
||||||
import java.util.List;
|
import java.util.List;
|
||||||
import javax.validation.constraints.*;
|
import javax.validation.constraints.*;
|
||||||
|
import com.ruoyi.system.api.emun.EnableStatusEnum;
|
||||||
import org.apache.commons.lang3.builder.ToStringBuilder;
|
import org.apache.commons.lang3.builder.ToStringBuilder;
|
||||||
import org.apache.commons.lang3.builder.ToStringStyle;
|
import org.apache.commons.lang3.builder.ToStringStyle;
|
||||||
import com.ruoyi.common.core.annotation.Excel;
|
import com.ruoyi.common.core.annotation.Excel;
|
||||||
|
|
@ -14,7 +15,7 @@ import com.ruoyi.common.core.xss.Xss;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* 用户对象 sys_user
|
* 用户对象 sys_user
|
||||||
*
|
*
|
||||||
* @author ruoyi
|
* @author ruoyi
|
||||||
*/
|
*/
|
||||||
public class SysUser extends BaseEntity
|
public class SysUser extends BaseEntity
|
||||||
|
|
@ -55,8 +56,11 @@ public class SysUser extends BaseEntity
|
||||||
/** 密码 */
|
/** 密码 */
|
||||||
private String password;
|
private String password;
|
||||||
|
|
||||||
/** 帐号状态(0正常 1停用) */
|
/**
|
||||||
@Excel(name = "帐号状态", readConverterExp = "0=正常,1=停用")
|
* 帐号状态(0正常 1停用)
|
||||||
|
* @see EnableStatusEnum
|
||||||
|
**/
|
||||||
|
@Excel(name = "帐号状态", readConverterEnum = EnableStatusEnum.class)
|
||||||
private String status;
|
private String status;
|
||||||
|
|
||||||
/** 删除标志(0代表存在 2代表删除) */
|
/** 删除标志(0代表存在 2代表删除) */
|
||||||
|
|
|
||||||
|
|
@ -0,0 +1,69 @@
|
||||||
|
package com.ruoyi.system.api.emun;
|
||||||
|
|
||||||
|
import com.ruoyi.common.core.annotation.DictTag;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* ===========================================
|
||||||
|
* Copyright 2024 xiaoyang
|
||||||
|
* All rights reserved
|
||||||
|
* <p>项 目 名 :RuoYi-Cloud</p>
|
||||||
|
* <p>文 件 名 :EnableStatusEnum</p>
|
||||||
|
* <p>描 述 :启用状态枚举</p>
|
||||||
|
*
|
||||||
|
* @author :xiaoyang
|
||||||
|
* @date : 2024/1/12 20:26
|
||||||
|
* ============================================
|
||||||
|
*/
|
||||||
|
public enum EnableStatusEnum implements DictTag
|
||||||
|
{
|
||||||
|
/**
|
||||||
|
* 正常
|
||||||
|
*/
|
||||||
|
enable("0", "正常"),
|
||||||
|
/**
|
||||||
|
* 停用
|
||||||
|
*/
|
||||||
|
disable("1", "停用");
|
||||||
|
|
||||||
|
private String code;
|
||||||
|
|
||||||
|
private String name;
|
||||||
|
;
|
||||||
|
|
||||||
|
EnableStatusEnum(String code, String name)
|
||||||
|
{
|
||||||
|
this.code = code;
|
||||||
|
this.name = name;
|
||||||
|
}
|
||||||
|
@Override
|
||||||
|
public String getKey()
|
||||||
|
{
|
||||||
|
return code;
|
||||||
|
}
|
||||||
|
/**
|
||||||
|
* 获取名称
|
||||||
|
*
|
||||||
|
* @return
|
||||||
|
*/
|
||||||
|
@Override
|
||||||
|
public String getName()
|
||||||
|
{
|
||||||
|
return name;
|
||||||
|
}
|
||||||
|
/**
|
||||||
|
* 获取编码
|
||||||
|
*
|
||||||
|
* @return
|
||||||
|
*/
|
||||||
|
public String getCode()
|
||||||
|
{
|
||||||
|
return code;
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 获取键(集成字典类型)
|
||||||
|
*
|
||||||
|
* @return
|
||||||
|
*/
|
||||||
|
|
||||||
|
}
|
||||||
|
|
@ -0,0 +1,30 @@
|
||||||
|
package com.ruoyi.common.core.annotation;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* ===========================================
|
||||||
|
* Copyright 2024 xiaoyang
|
||||||
|
* All rights reserved
|
||||||
|
* <p>项 目 名 :RuoYi-Cloud</p>
|
||||||
|
* <p>文 件 名 :DictTag</p>
|
||||||
|
* <p>描 述 :字典类型</p>
|
||||||
|
*
|
||||||
|
* @author :xiaoyang
|
||||||
|
* @date : 2024/1/12 20:27
|
||||||
|
* ============================================
|
||||||
|
*/
|
||||||
|
public interface DictTag
|
||||||
|
{
|
||||||
|
/**
|
||||||
|
* 绑定键
|
||||||
|
*
|
||||||
|
* @return 绑定的键值
|
||||||
|
*/
|
||||||
|
String getKey();
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 绑定名称
|
||||||
|
*
|
||||||
|
* @return 绑定的名称
|
||||||
|
*/
|
||||||
|
String getName();
|
||||||
|
}
|
||||||
|
|
@ -11,7 +11,7 @@ import com.ruoyi.common.core.utils.poi.ExcelHandlerAdapter;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* 自定义导出Excel数据注解
|
* 自定义导出Excel数据注解
|
||||||
*
|
*
|
||||||
* @author ruoyi
|
* @author ruoyi
|
||||||
*/
|
*/
|
||||||
@Retention(RetentionPolicy.RUNTIME)
|
@Retention(RetentionPolicy.RUNTIME)
|
||||||
|
|
@ -37,6 +37,14 @@ public @interface Excel
|
||||||
* 读取内容转表达式 (如: 0=男,1=女,2=未知)
|
* 读取内容转表达式 (如: 0=男,1=女,2=未知)
|
||||||
*/
|
*/
|
||||||
public String readConverterExp() default "";
|
public String readConverterExp() default "";
|
||||||
|
/**
|
||||||
|
* 字典转换器的枚举,该枚举需要实现DictTag标签,否则不生效
|
||||||
|
* <p>
|
||||||
|
* 枚举字典有值时,优先取枚举字典
|
||||||
|
*
|
||||||
|
* @return 字典转换枚举
|
||||||
|
*/
|
||||||
|
Class<? extends Enum> readConverterEnum() default Enum.class;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* 分隔符,读取字符串组内容
|
* 分隔符,读取字符串组内容
|
||||||
|
|
@ -179,4 +187,4 @@ public @interface Excel
|
||||||
return this.value;
|
return this.value;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
||||||
|
|
@ -20,6 +20,7 @@ import java.util.Map;
|
||||||
import java.util.Set;
|
import java.util.Set;
|
||||||
import java.util.stream.Collectors;
|
import java.util.stream.Collectors;
|
||||||
import javax.servlet.http.HttpServletResponse;
|
import javax.servlet.http.HttpServletResponse;
|
||||||
|
import com.ruoyi.common.core.annotation.DictTag;
|
||||||
import org.apache.commons.lang3.ArrayUtils;
|
import org.apache.commons.lang3.ArrayUtils;
|
||||||
import org.apache.commons.lang3.RegExUtils;
|
import org.apache.commons.lang3.RegExUtils;
|
||||||
import org.apache.commons.lang3.reflect.FieldUtils;
|
import org.apache.commons.lang3.reflect.FieldUtils;
|
||||||
|
|
@ -298,12 +299,30 @@ public class ExcelUtil<T>
|
||||||
*/
|
*/
|
||||||
public Map<String,String> initValueToFieldConversionMap(Excel attr){
|
public Map<String,String> initValueToFieldConversionMap(Excel attr){
|
||||||
HashMap<String, String> conversionMap = new HashMap<>();
|
HashMap<String, String> conversionMap = new HashMap<>();
|
||||||
String allList = attr.readConverterExp();
|
//如果存在转换exp,提取转换exp
|
||||||
String[] split = allList.split(",");
|
if (StringUtils.isNotEmpty(attr.readConverterExp()))
|
||||||
for (String dictTagItem : split)
|
|
||||||
{
|
{
|
||||||
String[] split1 = dictTagItem.split("=");
|
String allList = attr.readConverterExp();
|
||||||
conversionMap.put(split1[1], split1[0]);
|
String[] split = allList.split(",");
|
||||||
|
for (String dictTagItem : split)
|
||||||
|
{
|
||||||
|
String[] split1 = dictTagItem.split("=");
|
||||||
|
conversionMap.put(split1[1], split1[0]);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
//字段转换初始化(通过枚举字段转换)
|
||||||
|
if (!attr.readConverterEnum().getName().equals(Enum.class.getName()))
|
||||||
|
{
|
||||||
|
Class<? extends Enum> aClass = attr.readConverterEnum();
|
||||||
|
Object[] enumConstants = aClass.getEnumConstants();
|
||||||
|
for (Object enumItem : enumConstants)
|
||||||
|
{
|
||||||
|
if (enumItem instanceof DictTag)
|
||||||
|
{
|
||||||
|
DictTag dictTag = (DictTag) enumItem;
|
||||||
|
conversionMap.put(dictTag.getName(), dictTag.getKey());
|
||||||
|
}
|
||||||
|
}
|
||||||
}
|
}
|
||||||
return conversionMap;
|
return conversionMap;
|
||||||
}
|
}
|
||||||
|
|
@ -361,7 +380,9 @@ public class ExcelUtil<T>
|
||||||
{
|
{
|
||||||
fieldsMap.put(column, objects);
|
fieldsMap.put(column, objects);
|
||||||
//如果存在解析键值映射,则直接初始化
|
//如果存在解析键值映射,则直接初始化
|
||||||
if(StringUtils.isNotEmpty(attr.readConverterExp())){
|
if(StringUtils.isNotEmpty(attr.readConverterExp())
|
||||||
|
|| !attr.readConverterEnum().getName().equals(Enum.class.getName()))
|
||||||
|
{
|
||||||
Map<String, String> fieldConversionMap = initValueToFieldConversionMap(attr);
|
Map<String, String> fieldConversionMap = initValueToFieldConversionMap(attr);
|
||||||
allFieldConversionMap.put(attr.name(),fieldConversionMap);
|
allFieldConversionMap.put(attr.name(),fieldConversionMap);
|
||||||
}
|
}
|
||||||
|
|
@ -815,6 +836,22 @@ public class ExcelUtil<T>
|
||||||
}
|
}
|
||||||
fieldConversionMap.put(column, conversionMap);
|
fieldConversionMap.put(column, conversionMap);
|
||||||
}
|
}
|
||||||
|
//字段转换初始化(通过枚举字段转换)
|
||||||
|
if (!attr.readConverterEnum().getName().equals(Enum.class.getName()))
|
||||||
|
{
|
||||||
|
HashMap<String, String> conversionMap = new HashMap<>();
|
||||||
|
Class<? extends Enum> aClass = attr.readConverterEnum();
|
||||||
|
Object[] enumConstants = aClass.getEnumConstants();
|
||||||
|
for (Object enumItem : enumConstants)
|
||||||
|
{
|
||||||
|
if (enumItem instanceof DictTag)
|
||||||
|
{
|
||||||
|
DictTag dictTag = (DictTag) enumItem;
|
||||||
|
conversionMap.put(dictTag.getKey(), dictTag.getName());
|
||||||
|
}
|
||||||
|
}
|
||||||
|
fieldConversionMap.put(column, conversionMap);
|
||||||
|
}
|
||||||
if (isSubList())
|
if (isSubList())
|
||||||
{
|
{
|
||||||
// 填充默认样式,防止合并单元格样式失效
|
// 填充默认样式,防止合并单元格样式失效
|
||||||
|
|
|
||||||
|
|
@ -3,6 +3,7 @@ package com.ruoyi.system.domain;
|
||||||
import javax.validation.constraints.NotBlank;
|
import javax.validation.constraints.NotBlank;
|
||||||
import javax.validation.constraints.NotNull;
|
import javax.validation.constraints.NotNull;
|
||||||
import javax.validation.constraints.Size;
|
import javax.validation.constraints.Size;
|
||||||
|
import com.ruoyi.system.api.emun.EnableStatusEnum;
|
||||||
import org.apache.commons.lang3.builder.ToStringBuilder;
|
import org.apache.commons.lang3.builder.ToStringBuilder;
|
||||||
import org.apache.commons.lang3.builder.ToStringStyle;
|
import org.apache.commons.lang3.builder.ToStringStyle;
|
||||||
import com.ruoyi.common.core.annotation.Excel;
|
import com.ruoyi.common.core.annotation.Excel;
|
||||||
|
|
@ -11,7 +12,7 @@ import com.ruoyi.common.core.web.domain.BaseEntity;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* 岗位表 sys_post
|
* 岗位表 sys_post
|
||||||
*
|
*
|
||||||
* @author ruoyi
|
* @author ruoyi
|
||||||
*/
|
*/
|
||||||
public class SysPost extends BaseEntity
|
public class SysPost extends BaseEntity
|
||||||
|
|
@ -34,8 +35,11 @@ public class SysPost extends BaseEntity
|
||||||
@Excel(name = "岗位排序")
|
@Excel(name = "岗位排序")
|
||||||
private Integer postSort;
|
private Integer postSort;
|
||||||
|
|
||||||
/** 状态(0正常 1停用) */
|
/**
|
||||||
@Excel(name = "状态", readConverterExp = "0=正常,1=停用")
|
* 状态(0正常 1停用)
|
||||||
|
* @see EnableStatusEnum
|
||||||
|
**/
|
||||||
|
@Excel(name = "状态", readConverterEnum = EnableStatusEnum.class)
|
||||||
private String status;
|
private String status;
|
||||||
|
|
||||||
/** 用户是否存在此岗位标识 默认不存在 */
|
/** 用户是否存在此岗位标识 默认不存在 */
|
||||||
|
|
@ -105,7 +109,7 @@ public class SysPost extends BaseEntity
|
||||||
{
|
{
|
||||||
this.flag = flag;
|
this.flag = flag;
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public String toString() {
|
public String toString() {
|
||||||
return new ToStringBuilder(this,ToStringStyle.MULTI_LINE_STYLE)
|
return new ToStringBuilder(this,ToStringStyle.MULTI_LINE_STYLE)
|
||||||
|
|
|
||||||
Loading…
Reference in New Issue