Excel注解新增 dateFormat日期格式/readConverterExp读取内容转表达式
parent
a42c824e92
commit
4d2d5defb9
|
@ -18,6 +18,16 @@ public @interface Excel
|
|||
* 导出到Excel中的名字.
|
||||
*/
|
||||
public abstract String name();
|
||||
|
||||
/**
|
||||
* 日期格式, 如: yyyy-MM-dd
|
||||
*/
|
||||
public abstract String dateFormat() default "";
|
||||
|
||||
/**
|
||||
* 读取内容转表达式 (如: 0=男,1=女,2=未知)
|
||||
*/
|
||||
public abstract String readConverterExp() default "";
|
||||
|
||||
/**
|
||||
* 提示信息
|
||||
|
|
|
@ -6,9 +6,9 @@ import java.io.IOException;
|
|||
import java.io.InputStream;
|
||||
import java.io.OutputStream;
|
||||
import java.lang.reflect.Field;
|
||||
import java.math.BigDecimal;
|
||||
import java.text.SimpleDateFormat;
|
||||
import java.util.ArrayList;
|
||||
import java.util.Date;
|
||||
import java.util.HashMap;
|
||||
import java.util.List;
|
||||
import java.util.Map;
|
||||
|
@ -37,7 +37,6 @@ import org.slf4j.LoggerFactory;
|
|||
import com.ruoyi.common.annotation.Excel;
|
||||
import com.ruoyi.common.base.AjaxResult;
|
||||
import com.ruoyi.common.config.Global;
|
||||
import com.ruoyi.common.utils.StringUtils;
|
||||
|
||||
/**
|
||||
* Excel相关处理
|
||||
|
@ -334,31 +333,28 @@ public class ExcelUtil<T>
|
|||
// 创建cell
|
||||
cell = row.createCell(j);
|
||||
cell.setCellStyle(cs);
|
||||
try
|
||||
if (vo == null)
|
||||
{
|
||||
if (String.valueOf(field.get(vo)).length() > 10)
|
||||
{
|
||||
throw new Exception("长度超过10位就不用转数字了");
|
||||
}
|
||||
// 如果可以转成数字则导出为数字类型
|
||||
BigDecimal bc = new BigDecimal(String.valueOf(field.get(vo)));
|
||||
cell.setCellType(CellType.NUMERIC);
|
||||
cell.setCellValue(bc.doubleValue());
|
||||
// 如果数据存在就填入,不存在填入空格.
|
||||
cell.setCellValue("");
|
||||
continue;
|
||||
}
|
||||
catch (Exception e)
|
||||
|
||||
String dateFormat = attr.dateFormat();
|
||||
String readConverterExp = attr.readConverterExp();
|
||||
if (StringUtils.isNotEmpty(dateFormat))
|
||||
{
|
||||
cell.setCellValue(DateUtils.parseDateToStr(dateFormat, (Date) field.get(vo)));
|
||||
}
|
||||
else if (StringUtils.isNotEmpty(readConverterExp))
|
||||
{
|
||||
cell.setCellValue(convertByExp(String.valueOf(field.get(vo)), readConverterExp));
|
||||
}
|
||||
else
|
||||
{
|
||||
cell.setCellType(CellType.STRING);
|
||||
if (vo == null)
|
||||
{
|
||||
// 如果数据存在就填入,不存在填入空格.
|
||||
cell.setCellValue("");
|
||||
}
|
||||
else
|
||||
{
|
||||
// 如果数据存在就填入,不存在填入空格.
|
||||
cell.setCellValue(field.get(vo) == null ? "" : String.valueOf(field.get(vo)));
|
||||
}
|
||||
|
||||
// 如果数据存在就填入,不存在填入空格.
|
||||
cell.setCellValue(field.get(vo) == null ? "" : String.valueOf(field.get(vo)));
|
||||
}
|
||||
}
|
||||
}
|
||||
|
@ -455,6 +451,35 @@ public class ExcelUtil<T>
|
|||
sheet.addValidationData(dataValidationList);
|
||||
return sheet;
|
||||
}
|
||||
|
||||
/**
|
||||
* 解析导出值 0=男,1=女,2=未知
|
||||
*
|
||||
* @param propertyValue 参数值
|
||||
* @param converterExp 翻译注解
|
||||
* @return 解析后值
|
||||
* @throws Exception
|
||||
*/
|
||||
public static String convertByExp(String propertyValue, String converterExp) throws Exception
|
||||
{
|
||||
try
|
||||
{
|
||||
String[] convertSource = converterExp.split(",");
|
||||
for (String item : convertSource)
|
||||
{
|
||||
String[] itemArray = item.split("=");
|
||||
if (itemArray[0].equals(propertyValue))
|
||||
{
|
||||
return itemArray[1];
|
||||
}
|
||||
}
|
||||
}
|
||||
catch (Exception e)
|
||||
{
|
||||
throw e;
|
||||
}
|
||||
return propertyValue;
|
||||
}
|
||||
|
||||
/**
|
||||
* 编码文件名
|
||||
|
|
|
@ -45,7 +45,7 @@ public class SysJob extends BaseEntity implements Serializable
|
|||
private String misfirePolicy = ScheduleConstants.MISFIRE_DEFAULT;
|
||||
|
||||
/** 任务状态(0正常 1暂停) */
|
||||
@Excel(name = "任务状态")
|
||||
@Excel(name = "任务状态", readConverterExp = "0=正常,1=暂停")
|
||||
private String status;
|
||||
|
||||
public Long getJobId()
|
||||
|
|
|
@ -39,7 +39,7 @@ public class SysJobLog extends BaseEntity
|
|||
private String jobMessage;
|
||||
|
||||
/** 执行状态(0正常 1失败) */
|
||||
@Excel(name = "执行状态")
|
||||
@Excel(name = "执行状态", readConverterExp = "0=正常,1=失败")
|
||||
private String status;
|
||||
|
||||
/** 异常信息 */
|
||||
|
|
|
@ -31,7 +31,7 @@ public class SysConfig extends BaseEntity
|
|||
private String configValue;
|
||||
|
||||
/** 系统内置(Y是 N否) */
|
||||
@Excel(name = "系统内置")
|
||||
@Excel(name = "系统内置", readConverterExp = "Y=是,N=否")
|
||||
private String configType;
|
||||
|
||||
public Long getConfigId()
|
||||
|
|
|
@ -42,11 +42,11 @@ public class SysDictData extends BaseEntity
|
|||
private String listClass;
|
||||
|
||||
/** 是否默认(Y是 N否) */
|
||||
@Excel(name = "是否默认")
|
||||
@Excel(name = "是否默认", readConverterExp = "Y=是,N=否")
|
||||
private String isDefault;
|
||||
|
||||
/** 状态(0正常 1停用) */
|
||||
@Excel(name = "状态")
|
||||
@Excel(name = "状态", readConverterExp = "0=正常,1=停用")
|
||||
private String status;
|
||||
|
||||
public Long getDictCode()
|
||||
|
|
|
@ -27,7 +27,7 @@ public class SysDictType extends BaseEntity
|
|||
private String dictType;
|
||||
|
||||
/** 状态(0正常 1停用) */
|
||||
@Excel(name = "状态")
|
||||
@Excel(name = "状态", readConverterExp = "0=正常,1=停用")
|
||||
private String status;
|
||||
|
||||
public Long getDictId()
|
||||
|
|
|
@ -24,7 +24,7 @@ public class SysLogininfor extends BaseEntity
|
|||
private String loginName;
|
||||
|
||||
/** 登录状态 0成功 1失败 */
|
||||
@Excel(name = "登录状态")
|
||||
@Excel(name = "登录状态", readConverterExp = "0=成功,1=失败")
|
||||
private String status;
|
||||
|
||||
/** 登录IP地址 */
|
||||
|
@ -48,7 +48,7 @@ public class SysLogininfor extends BaseEntity
|
|||
private String msg;
|
||||
|
||||
/** 访问时间 */
|
||||
@Excel(name = "访问时间")
|
||||
@Excel(name = "访问时间", dateFormat = "yyyy-MM-dd HH:mm:ss")
|
||||
private Date loginTime;
|
||||
|
||||
public Long getInfoId()
|
||||
|
|
|
@ -24,7 +24,7 @@ public class SysOperLog extends BaseEntity
|
|||
private String title;
|
||||
|
||||
/** 业务类型(0其它 1新增 2修改 3删除) */
|
||||
@Excel(name = "业务类型")
|
||||
@Excel(name = "业务类型", readConverterExp = "0=其它,1=新增,2=修改,3=删除,4=授权,5=导出,6=导入,7=强退,8=生成代码,9=清空数据")
|
||||
private Integer businessType;
|
||||
|
||||
/** 请求方法 */
|
||||
|
@ -32,7 +32,7 @@ public class SysOperLog extends BaseEntity
|
|||
private String method;
|
||||
|
||||
/** 操作类别(0其它 1后台用户 2手机端用户) */
|
||||
@Excel(name = "操作类别")
|
||||
@Excel(name = "操作类别", readConverterExp = "0=其它,1=后台用户,2=手机端用户")
|
||||
private Integer operatorType;
|
||||
|
||||
/** 操作人员 */
|
||||
|
@ -60,7 +60,7 @@ public class SysOperLog extends BaseEntity
|
|||
private String operParam;
|
||||
|
||||
/** 操作状态(0正常 1异常) */
|
||||
@Excel(name = "状态")
|
||||
@Excel(name = "状态", readConverterExp = "0=正常,1=异常")
|
||||
private Integer status;
|
||||
|
||||
/** 错误消息 */
|
||||
|
@ -68,7 +68,7 @@ public class SysOperLog extends BaseEntity
|
|||
private String errorMsg;
|
||||
|
||||
/** 操作时间 */
|
||||
@Excel(name = "操作时间")
|
||||
@Excel(name = "操作时间", dateFormat = "yyyy-MM-dd HH:mm:ss")
|
||||
private Date operTime;
|
||||
|
||||
public Long getOperId()
|
||||
|
|
|
@ -31,7 +31,7 @@ public class SysPost extends BaseEntity
|
|||
private String postSort;
|
||||
|
||||
/** 状态(0正常 1停用) */
|
||||
@Excel(name = "状态")
|
||||
@Excel(name = "状态", readConverterExp = "0=正常,1=停用")
|
||||
private String status;
|
||||
|
||||
/** 用户是否存在此岗位标识 默认不存在 */
|
||||
|
|
|
@ -31,11 +31,11 @@ public class SysRole extends BaseEntity
|
|||
private String roleSort;
|
||||
|
||||
/** 数据范围(1:所有数据权限;2:自定数据权限) */
|
||||
@Excel(name = "数据范围")
|
||||
@Excel(name = "数据范围", readConverterExp = "1=所有数据权限,2=自定义数据权限")
|
||||
private String dataScope;
|
||||
|
||||
/** 角色状态(0正常 1停用) */
|
||||
@Excel(name = "角色状态")
|
||||
@Excel(name = "角色状态", readConverterExp = "0=正常,1=停用")
|
||||
private String status;
|
||||
|
||||
/** 删除标志(0代表存在 2代表删除) */
|
||||
|
|
|
@ -43,7 +43,7 @@ public class SysUser extends BaseEntity
|
|||
private String phonenumber;
|
||||
|
||||
/** 用户性别 */
|
||||
@Excel(name = "用户性别")
|
||||
@Excel(name = "用户性别", readConverterExp = "0=男,1=女,2=未知")
|
||||
private String sex;
|
||||
|
||||
/** 用户头像 */
|
||||
|
@ -56,7 +56,7 @@ public class SysUser extends BaseEntity
|
|||
private String salt;
|
||||
|
||||
/** 帐号状态(0正常 1停用) */
|
||||
@Excel(name = "帐号状态")
|
||||
@Excel(name = "帐号状态", readConverterExp = "0=正常,1=停用")
|
||||
private String status;
|
||||
|
||||
/** 删除标志(0代表存在 2代表删除) */
|
||||
|
@ -67,7 +67,7 @@ public class SysUser extends BaseEntity
|
|||
private String loginIp;
|
||||
|
||||
/** 最后登陆时间 */
|
||||
@Excel(name = "最后登陆时间")
|
||||
@Excel(name = "最后登陆时间", dateFormat = "yyyy-MM-dd HH:mm:ss")
|
||||
private Date loginDate;
|
||||
|
||||
/** 部门对象 */
|
||||
|
|
Loading…
Reference in New Issue