From 27881c8635c163296266f8b5df08a87f94ef911f Mon Sep 17 00:00:00 2001
From: RuoYi <yzz_ivy@163.com>
Date: Sun, 26 Aug 2018 23:36:30 +0800
Subject: [PATCH] =?UTF-8?q?excel=E5=AF=BC=E5=85=A5=E6=96=87=E4=BB=B6?=
 =?UTF-8?q?=E4=BC=98=E5=8C=96?=
MIME-Version: 1.0
Content-Type: text/plain; charset=UTF-8
Content-Transfer-Encoding: 8bit

---
 .../com/ruoyi/common/utils/poi/ExcelUtil.java | 31 +++++++++++++++++--
 .../manager/factory/AsyncFactory.java         |  9 +++---
 .../project/system/config/domain/Config.java  |  6 ++++
 .../mybatis/monitor/JobLogMapper.xml          |  4 +--
 .../mybatis/monitor/LogininforMapper.xml      |  4 +--
 .../mybatis/monitor/OperLogMapper.xml         |  4 +--
 .../resources/mybatis/system/ConfigMapper.xml |  4 +--
 .../mybatis/system/DictTypeMapper.xml         |  4 +--
 .../resources/mybatis/system/RoleMapper.xml   |  4 +--
 .../resources/mybatis/system/UserMapper.xml   |  4 +--
 src/main/resources/mybatis/tool/GenMapper.xml |  4 +--
 11 files changed, 55 insertions(+), 23 deletions(-)

diff --git a/src/main/java/com/ruoyi/common/utils/poi/ExcelUtil.java b/src/main/java/com/ruoyi/common/utils/poi/ExcelUtil.java
index d168e9f7..a5e49599 100644
--- a/src/main/java/com/ruoyi/common/utils/poi/ExcelUtil.java
+++ b/src/main/java/com/ruoyi/common/utils/poi/ExcelUtil.java
@@ -2,6 +2,7 @@ package com.ruoyi.common.utils.poi;
 
 import java.io.FileNotFoundException;
 import java.io.FileOutputStream;
+import java.io.IOException;
 import java.io.InputStream;
 import java.io.OutputStream;
 import java.lang.reflect.Field;
@@ -53,22 +54,46 @@ public class ExcelUtil<T>
         this.clazz = clazz;
     }
 
+    /**
+     * 对excel表单默认第一个索引名转换成list
+     * 
+     * @param input 输入流
+     * @return 转换后集合
+     */
+    public List<T> importExcel(InputStream input) throws Exception
+    {
+        return importExcel(StringUtils.EMPTY, input);
+    }
+
+    /**
+     * 对excel表单指定表格索引名转换成list
+     * 
+     * @param sheetName 表格索引名
+     * @param input 输入流
+     * @return 转换后集合
+     */
     public List<T> importExcel(String sheetName, InputStream input) throws Exception
     {
         List<T> list = new ArrayList<T>();
 
         Workbook workbook = WorkbookFactory.create(input);
-        Sheet sheet = workbook.getSheet(sheetName);
+        Sheet sheet = null;
         if (StringUtils.isNotEmpty(sheetName))
         {
             // 如果指定sheet名,则取指定sheet中的内容.
             sheet = workbook.getSheet(sheetName);
         }
-        if (sheet == null)
+        else
         {
             // 如果传入的sheet名不存在则默认指向第1个sheet.
             sheet = workbook.getSheetAt(0);
         }
+
+        if (sheet == null)
+        {
+            throw new IOException("文件sheet不存在");
+        }
+
         int rows = sheet.getPhysicalNumberOfRows();
 
         if (rows > 0)
@@ -117,7 +142,7 @@ public class ExcelUtil<T>
                     // 如果不存在实例则新建.
                     entity = (entity == null ? clazz.newInstance() : entity);
                     // 从map中得到对应列的field.
-                    Field field = fieldsMap.get(j);
+                    Field field = fieldsMap.get(j + 1);
                     // 取得类型,并根据对象类型设置值.
                     Class<?> fieldType = field.getType();
                     if (String.class == fieldType)
diff --git a/src/main/java/com/ruoyi/framework/manager/factory/AsyncFactory.java b/src/main/java/com/ruoyi/framework/manager/factory/AsyncFactory.java
index 8d507c45..8bac132f 100644
--- a/src/main/java/com/ruoyi/framework/manager/factory/AsyncFactory.java
+++ b/src/main/java/com/ruoyi/framework/manager/factory/AsyncFactory.java
@@ -92,14 +92,15 @@ public class AsyncFactory
     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 String ip = ShiroUtils.getIp();
         return new TimerTask()
         {
             @Override
             public void run()
             {
                 StringBuilder s = new StringBuilder();
-                s.append(LogUtils.getBlock(ShiroUtils.getIp()));
-                s.append(AddressUtils.getRealAddressByIP(ShiroUtils.getIp()));
+                s.append(LogUtils.getBlock(ip));
+                s.append(AddressUtils.getRealAddressByIP(ip));
                 s.append(LogUtils.getBlock(username));
                 s.append(LogUtils.getBlock(status));
                 s.append(LogUtils.getBlock(message));
@@ -112,8 +113,8 @@ public class AsyncFactory
                 // 封装对象
                 Logininfor logininfor = new Logininfor();
                 logininfor.setLoginName(username);
-                logininfor.setIpaddr(ShiroUtils.getIp());
-                logininfor.setLoginLocation(AddressUtils.getRealAddressByIP(ShiroUtils.getIp()));
+                logininfor.setIpaddr(ip);
+                logininfor.setLoginLocation(AddressUtils.getRealAddressByIP(ip));
                 logininfor.setBrowser(browser);
                 logininfor.setOs(os);
                 logininfor.setMsg(message);
diff --git a/src/main/java/com/ruoyi/project/system/config/domain/Config.java b/src/main/java/com/ruoyi/project/system/config/domain/Config.java
index bc7f806e..219b3c79 100644
--- a/src/main/java/com/ruoyi/project/system/config/domain/Config.java
+++ b/src/main/java/com/ruoyi/project/system/config/domain/Config.java
@@ -82,4 +82,10 @@ public class Config extends BaseEntity
         this.configType = configType;
     }
 
+    public String toString()
+    {
+        return "Config [configId=" + configId + ", configName=" + configName + ", configKey=" + configKey
+                + ", configValue=" + configValue + ", configType=" + configType + "]";
+    }
+
 }
diff --git a/src/main/resources/mybatis/monitor/JobLogMapper.xml b/src/main/resources/mybatis/monitor/JobLogMapper.xml
index 64710cca..11b64f6c 100644
--- a/src/main/resources/mybatis/monitor/JobLogMapper.xml
+++ b/src/main/resources/mybatis/monitor/JobLogMapper.xml
@@ -32,10 +32,10 @@ PUBLIC "-//mybatis.org//DTD Mapper 3.0//EN"
 			<if test="methodName != null and methodName != ''">
 				AND method_name like concat('%', #{methodName}, '%')
 			</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')
 			</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')
 			</if>
 		</where>
diff --git a/src/main/resources/mybatis/monitor/LogininforMapper.xml b/src/main/resources/mybatis/monitor/LogininforMapper.xml
index 4ccf013f..c45fcca4 100644
--- a/src/main/resources/mybatis/monitor/LogininforMapper.xml
+++ b/src/main/resources/mybatis/monitor/LogininforMapper.xml
@@ -33,10 +33,10 @@ PUBLIC "-//mybatis.org//DTD Mapper 3.0//EN"
 			<if test="loginName != null and loginName != ''">
 				AND login_name like concat('%', #{loginName}, '%')
 			</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')
 			</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')
 			</if>
 		</where>
diff --git a/src/main/resources/mybatis/monitor/OperLogMapper.xml b/src/main/resources/mybatis/monitor/OperLogMapper.xml
index 16970e3f..4033bd86 100644
--- a/src/main/resources/mybatis/monitor/OperLogMapper.xml
+++ b/src/main/resources/mybatis/monitor/OperLogMapper.xml
@@ -45,10 +45,10 @@ PUBLIC "-//mybatis.org//DTD Mapper 3.0//EN"
 			<if test="operName != null and operName != ''">
 				AND oper_name like concat('%', #{operName}, '%')
 			</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')
 			</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')
 			</if>
 		</where>
diff --git a/src/main/resources/mybatis/system/ConfigMapper.xml b/src/main/resources/mybatis/system/ConfigMapper.xml
index e042f8df..32fdb6f4 100644
--- a/src/main/resources/mybatis/system/ConfigMapper.xml
+++ b/src/main/resources/mybatis/system/ConfigMapper.xml
@@ -49,10 +49,10 @@ PUBLIC "-//mybatis.org//DTD Mapper 3.0//EN"
 			<if test="configKey != null and configKey != ''">
 				AND config_key like concat('%', #{configKey}, '%')
 			</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')
 			</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')
 			</if>
 		</where>
diff --git a/src/main/resources/mybatis/system/DictTypeMapper.xml b/src/main/resources/mybatis/system/DictTypeMapper.xml
index 15862135..60f4cab5 100644
--- a/src/main/resources/mybatis/system/DictTypeMapper.xml
+++ b/src/main/resources/mybatis/system/DictTypeMapper.xml
@@ -31,10 +31,10 @@ PUBLIC "-//mybatis.org//DTD Mapper 3.0//EN"
 			<if test="dictType != null and dictType != ''">
 				AND dict_type like concat('%', #{dictType}, '%')
 			</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')
 			</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')
 			</if>
 	    </where>
diff --git a/src/main/resources/mybatis/system/RoleMapper.xml b/src/main/resources/mybatis/system/RoleMapper.xml
index 3733bd9e..e4c98bbd 100644
--- a/src/main/resources/mybatis/system/RoleMapper.xml
+++ b/src/main/resources/mybatis/system/RoleMapper.xml
@@ -33,10 +33,10 @@ PUBLIC "-//mybatis.org//DTD Mapper 3.0//EN"
 			<if test="roleKey != null and roleKey != ''">
 				AND role_key like concat('%', #{roleKey}, '%')
 			</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')
 			</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')
 			</if>
 		</where>
diff --git a/src/main/resources/mybatis/system/UserMapper.xml b/src/main/resources/mybatis/system/UserMapper.xml
index 9825b5cc..29e33550 100644
--- a/src/main/resources/mybatis/system/UserMapper.xml
+++ b/src/main/resources/mybatis/system/UserMapper.xml
@@ -56,10 +56,10 @@ PUBLIC "-//mybatis.org//DTD Mapper 3.0//EN"
 		<if test="phonenumber != null and phonenumber != ''">
 			AND u.phonenumber like concat('%', #{phonenumber}, '%')
 		</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')
 		</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')
 		</if>
 		<if test="deptId != null and deptId != 0">
diff --git a/src/main/resources/mybatis/tool/GenMapper.xml b/src/main/resources/mybatis/tool/GenMapper.xml
index 5a60835a..bed2e418 100644
--- a/src/main/resources/mybatis/tool/GenMapper.xml
+++ b/src/main/resources/mybatis/tool/GenMapper.xml
@@ -30,10 +30,10 @@ PUBLIC "-//mybatis.org//DTD Mapper 3.0//EN"
 		<if test="tableComment != null and tableComment != ''">
 			AND table_comment like concat('%', #{tableComment}, '%')
 		</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')
 		</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')
 		</if>
 	</select>