excel导入文件优化

master
RuoYi 6 years ago committed by Limy
parent d7359e3335
commit 80fe171e43

@ -2,6 +2,7 @@ package com.ruoyi.common.utils.poi;
import java.io.FileNotFoundException; import java.io.FileNotFoundException;
import java.io.FileOutputStream; import java.io.FileOutputStream;
import java.io.IOException;
import java.io.InputStream; import java.io.InputStream;
import java.io.OutputStream; import java.io.OutputStream;
import java.lang.reflect.Field; import java.lang.reflect.Field;
@ -53,22 +54,46 @@ public class ExcelUtil<T>
this.clazz = clazz; this.clazz = clazz;
} }
/**
* excellist
*
* @param input
* @return
*/
public List<T> importExcel(InputStream input) throws Exception
{
return importExcel(StringUtils.EMPTY, input);
}
/**
* excellist
*
* @param sheetName
* @param input
* @return
*/
public List<T> importExcel(String sheetName, InputStream input) throws Exception public List<T> importExcel(String sheetName, InputStream input) throws Exception
{ {
List<T> list = new ArrayList<T>(); List<T> list = new ArrayList<T>();
Workbook workbook = WorkbookFactory.create(input); Workbook workbook = WorkbookFactory.create(input);
Sheet sheet = workbook.getSheet(sheetName); Sheet sheet = null;
if (StringUtils.isNotEmpty(sheetName)) if (StringUtils.isNotEmpty(sheetName))
{ {
// 如果指定sheet名,则取指定sheet中的内容. // 如果指定sheet名,则取指定sheet中的内容.
sheet = workbook.getSheet(sheetName); sheet = workbook.getSheet(sheetName);
} }
if (sheet == null) else
{ {
// 如果传入的sheet名不存在则默认指向第1个sheet. // 如果传入的sheet名不存在则默认指向第1个sheet.
sheet = workbook.getSheetAt(0); sheet = workbook.getSheetAt(0);
} }
if (sheet == null)
{
throw new IOException("文件sheet不存在");
}
int rows = sheet.getPhysicalNumberOfRows(); int rows = sheet.getPhysicalNumberOfRows();
if (rows > 0) if (rows > 0)
@ -117,7 +142,7 @@ public class ExcelUtil<T>
// 如果不存在实例则新建. // 如果不存在实例则新建.
entity = (entity == null ? clazz.newInstance() : entity); entity = (entity == null ? clazz.newInstance() : entity);
// 从map中得到对应列的field. // 从map中得到对应列的field.
Field field = fieldsMap.get(j); Field field = fieldsMap.get(j + 1);
// 取得类型,并根据对象类型设置值. // 取得类型,并根据对象类型设置值.
Class<?> fieldType = field.getType(); Class<?> fieldType = field.getType();
if (String.class == fieldType) if (String.class == fieldType)

@ -92,14 +92,15 @@ public class AsyncFactory
public static TimerTask recordLogininfor(final String username, final String status, final String message, final Object... args) public static TimerTask recordLogininfor(final String username, final String status, final String message, final Object... args)
{ {
final UserAgent userAgent = UserAgent.parseUserAgentString(ServletUtils.getRequest().getHeader("User-Agent")); final UserAgent userAgent = UserAgent.parseUserAgentString(ServletUtils.getRequest().getHeader("User-Agent"));
final String ip = ShiroUtils.getIp();
return new TimerTask() return new TimerTask()
{ {
@Override @Override
public void run() public void run()
{ {
StringBuilder s = new StringBuilder(); StringBuilder s = new StringBuilder();
s.append(LogUtils.getBlock(ShiroUtils.getIp())); s.append(LogUtils.getBlock(ip));
s.append(AddressUtils.getRealAddressByIP(ShiroUtils.getIp())); s.append(AddressUtils.getRealAddressByIP(ip));
s.append(LogUtils.getBlock(username)); s.append(LogUtils.getBlock(username));
s.append(LogUtils.getBlock(status)); s.append(LogUtils.getBlock(status));
s.append(LogUtils.getBlock(message)); s.append(LogUtils.getBlock(message));
@ -112,8 +113,8 @@ public class AsyncFactory
// 封装对象 // 封装对象
Logininfor logininfor = new Logininfor(); Logininfor logininfor = new Logininfor();
logininfor.setLoginName(username); logininfor.setLoginName(username);
logininfor.setIpaddr(ShiroUtils.getIp()); logininfor.setIpaddr(ip);
logininfor.setLoginLocation(AddressUtils.getRealAddressByIP(ShiroUtils.getIp())); logininfor.setLoginLocation(AddressUtils.getRealAddressByIP(ip));
logininfor.setBrowser(browser); logininfor.setBrowser(browser);
logininfor.setOs(os); logininfor.setOs(os);
logininfor.setMsg(message); logininfor.setMsg(message);

@ -82,4 +82,10 @@ public class Config extends BaseEntity
this.configType = configType; this.configType = configType;
} }
public String toString()
{
return "Config [configId=" + configId + ", configName=" + configName + ", configKey=" + configKey
+ ", configValue=" + configValue + ", configType=" + configType + "]";
}
} }

@ -32,10 +32,10 @@ PUBLIC "-//mybatis.org//DTD Mapper 3.0//EN"
<if test="methodName != null and methodName != ''"> <if test="methodName != null and methodName != ''">
AND method_name like concat('%', #{methodName}, '%') AND method_name like concat('%', #{methodName}, '%')
</if> </if>
<if test="params != null and params.beginTime != ''"><!-- 开始时间检索 --> <if test="params.beginTime != null and params.beginTime != ''"><!-- 开始时间检索 -->
and date_format(create_time,'%y%m%d') &gt;= date_format(#{params.beginTime},'%y%m%d') and date_format(create_time,'%y%m%d') &gt;= date_format(#{params.beginTime},'%y%m%d')
</if> </if>
<if test="params != null and params.endTime != ''"><!-- 结束时间检索 --> <if test="params.endTime != null and params.endTime != ''"><!-- 结束时间检索 -->
and date_format(create_time,'%y%m%d') &lt;= date_format(#{params.endTime},'%y%m%d') and date_format(create_time,'%y%m%d') &lt;= date_format(#{params.endTime},'%y%m%d')
</if> </if>
</where> </where>

@ -33,10 +33,10 @@ PUBLIC "-//mybatis.org//DTD Mapper 3.0//EN"
<if test="loginName != null and loginName != ''"> <if test="loginName != null and loginName != ''">
AND login_name like concat('%', #{loginName}, '%') AND login_name like concat('%', #{loginName}, '%')
</if> </if>
<if test="params != null and params.beginTime != ''"><!-- 开始时间检索 --> <if test="params.beginTime != null and params.beginTime != ''"><!-- 开始时间检索 -->
and date_format(login_time,'%y%m%d') &gt;= date_format(#{params.beginTime},'%y%m%d') and date_format(login_time,'%y%m%d') &gt;= date_format(#{params.beginTime},'%y%m%d')
</if> </if>
<if test="params != null and params.endTime != ''"><!-- 结束时间检索 --> <if test="params.endTime != null and params.endTime != ''"><!-- 结束时间检索 -->
and date_format(login_time,'%y%m%d') &lt;= date_format(#{params.endTime},'%y%m%d') and date_format(login_time,'%y%m%d') &lt;= date_format(#{params.endTime},'%y%m%d')
</if> </if>
</where> </where>

@ -45,10 +45,10 @@ PUBLIC "-//mybatis.org//DTD Mapper 3.0//EN"
<if test="operName != null and operName != ''"> <if test="operName != null and operName != ''">
AND oper_name like concat('%', #{operName}, '%') AND oper_name like concat('%', #{operName}, '%')
</if> </if>
<if test="params != null and params.beginTime != ''"><!-- 开始时间检索 --> <if test="params.beginTime != null and params.beginTime != ''"><!-- 开始时间检索 -->
and date_format(oper_time,'%y%m%d') &gt;= date_format(#{params.beginTime},'%y%m%d') and date_format(oper_time,'%y%m%d') &gt;= date_format(#{params.beginTime},'%y%m%d')
</if> </if>
<if test="params != null and params.endTime != ''"><!-- 结束时间检索 --> <if test="params.endTime != null and params.endTime != ''"><!-- 结束时间检索 -->
and date_format(oper_time,'%y%m%d') &lt;= date_format(#{params.endTime},'%y%m%d') and date_format(oper_time,'%y%m%d') &lt;= date_format(#{params.endTime},'%y%m%d')
</if> </if>
</where> </where>

@ -49,10 +49,10 @@ PUBLIC "-//mybatis.org//DTD Mapper 3.0//EN"
<if test="configKey != null and configKey != ''"> <if test="configKey != null and configKey != ''">
AND config_key like concat('%', #{configKey}, '%') AND config_key like concat('%', #{configKey}, '%')
</if> </if>
<if test="params != null and params.beginTime != ''"><!-- 开始时间检索 --> <if test="params.beginTime != null and params.beginTime != ''"><!-- 开始时间检索 -->
and date_format(create_time,'%y%m%d') &gt;= date_format(#{params.beginTime},'%y%m%d') and date_format(create_time,'%y%m%d') &gt;= date_format(#{params.beginTime},'%y%m%d')
</if> </if>
<if test="params != null and params.endTime != ''"><!-- 结束时间检索 --> <if test="params.endTime != null and params.endTime != ''"><!-- 结束时间检索 -->
and date_format(create_time,'%y%m%d') &lt;= date_format(#{params.endTime},'%y%m%d') and date_format(create_time,'%y%m%d') &lt;= date_format(#{params.endTime},'%y%m%d')
</if> </if>
</where> </where>

@ -31,10 +31,10 @@ PUBLIC "-//mybatis.org//DTD Mapper 3.0//EN"
<if test="dictType != null and dictType != ''"> <if test="dictType != null and dictType != ''">
AND dict_type like concat('%', #{dictType}, '%') AND dict_type like concat('%', #{dictType}, '%')
</if> </if>
<if test="params != null and params.beginTime != ''"><!-- 开始时间检索 --> <if test="params.beginTime != null and params.beginTime != ''"><!-- 开始时间检索 -->
and date_format(create_time,'%y%m%d') &gt;= date_format(#{params.beginTime},'%y%m%d') and date_format(create_time,'%y%m%d') &gt;= date_format(#{params.beginTime},'%y%m%d')
</if> </if>
<if test="params != null and params.endTime != ''"><!-- 结束时间检索 --> <if test="params.endTime != null and params.endTime != ''"><!-- 结束时间检索 -->
and date_format(create_time,'%y%m%d') &lt;= date_format(#{params.endTime},'%y%m%d') and date_format(create_time,'%y%m%d') &lt;= date_format(#{params.endTime},'%y%m%d')
</if> </if>
</where> </where>

@ -33,10 +33,10 @@ PUBLIC "-//mybatis.org//DTD Mapper 3.0//EN"
<if test="roleKey != null and roleKey != ''"> <if test="roleKey != null and roleKey != ''">
AND role_key like concat('%', #{roleKey}, '%') AND role_key like concat('%', #{roleKey}, '%')
</if> </if>
<if test="params != null and params.beginTime != ''"><!-- 开始时间检索 --> <if test="params.beginTime != null and params.beginTime != ''"><!-- 开始时间检索 -->
and date_format(create_time,'%y%m%d') &gt;= date_format(#{params.beginTime},'%y%m%d') and date_format(create_time,'%y%m%d') &gt;= date_format(#{params.beginTime},'%y%m%d')
</if> </if>
<if test="params != null and params.endTime != ''"><!-- 结束时间检索 --> <if test="params.endTime != null and params.endTime != ''"><!-- 结束时间检索 -->
and date_format(create_time,'%y%m%d') &lt;= date_format(#{params.endTime},'%y%m%d') and date_format(create_time,'%y%m%d') &lt;= date_format(#{params.endTime},'%y%m%d')
</if> </if>
</where> </where>

@ -56,10 +56,10 @@ PUBLIC "-//mybatis.org//DTD Mapper 3.0//EN"
<if test="phonenumber != null and phonenumber != ''"> <if test="phonenumber != null and phonenumber != ''">
AND u.phonenumber like concat('%', #{phonenumber}, '%') AND u.phonenumber like concat('%', #{phonenumber}, '%')
</if> </if>
<if test="params != null and params.beginTime != ''"><!-- 开始时间检索 --> <if test="params.beginTime != null and params.beginTime != ''"><!-- 开始时间检索 -->
AND date_format(u.create_time,'%y%m%d') &gt;= date_format(#{params.beginTime},'%y%m%d') AND date_format(u.create_time,'%y%m%d') &gt;= date_format(#{params.beginTime},'%y%m%d')
</if> </if>
<if test="params != null and params.endTime != ''"><!-- 结束时间检索 --> <if test="params.endTime != null and params.endTime != ''"><!-- 结束时间检索 -->
AND date_format(u.create_time,'%y%m%d') &lt;= date_format(#{params.endTime},'%y%m%d') AND date_format(u.create_time,'%y%m%d') &lt;= date_format(#{params.endTime},'%y%m%d')
</if> </if>
<if test="deptId != null and deptId != 0"> <if test="deptId != null and deptId != 0">

@ -30,10 +30,10 @@ PUBLIC "-//mybatis.org//DTD Mapper 3.0//EN"
<if test="tableComment != null and tableComment != ''"> <if test="tableComment != null and tableComment != ''">
AND table_comment like concat('%', #{tableComment}, '%') AND table_comment like concat('%', #{tableComment}, '%')
</if> </if>
<if test="params != null and params.beginTime != ''"><!-- 开始时间检索 --> <if test="params.beginTime != null and params.beginTime != ''"><!-- 开始时间检索 -->
and date_format(create_time,'%y%m%d') &gt;= date_format(#{params.beginTime},'%y%m%d') and date_format(create_time,'%y%m%d') &gt;= date_format(#{params.beginTime},'%y%m%d')
</if> </if>
<if test="params != null and params.endTime != ''"><!-- 结束时间检索 --> <if test="params.endTime != null and params.endTime != ''"><!-- 结束时间检索 -->
and date_format(create_time,'%y%m%d') &lt;= date_format(#{params.endTime},'%y%m%d') and date_format(create_time,'%y%m%d') &lt;= date_format(#{params.endTime},'%y%m%d')
</if> </if>
</select> </select>

Loading…
Cancel
Save