瀏覽代碼

excel公共导出方法,采用easypoi的方式
黑烟数据导出接口

459242451@qq.com 3 年之前
父節點
當前提交
213a82844a

+ 55 - 7
ruoyi-admin/src/main/java/com/ruoyi/web/controller/gas/BlackGasController.java

@@ -1,26 +1,39 @@
 package com.ruoyi.web.controller.gas;
 
+import cn.afterturn.easypoi.excel.ExcelExportUtil;
+import cn.afterturn.easypoi.excel.entity.ExportParams;
 import cn.hutool.core.convert.Convert;
+import cn.hutool.core.date.DateUtil;
 import cn.hutool.core.util.ObjectUtil;
 import cn.hutool.core.util.StrUtil;
-import com.github.pagehelper.PageInfo;
+import com.ruoyi.common.annotation.Log;
 import com.ruoyi.common.constant.ElasticConstants;
 import com.ruoyi.common.constant.HttpStatus;
 import com.ruoyi.common.core.controller.BaseController;
+import com.ruoyi.common.core.domain.AjaxResult;
 import com.ruoyi.common.core.page.PageDomain;
 import com.ruoyi.common.core.page.TableDataInfo;
 import com.ruoyi.common.core.page.TableSupport;
+import com.ruoyi.common.enums.BusinessType;
+import com.ruoyi.common.utils.StringUtils;
+import com.ruoyi.common.utils.poi.ExcelUtil;
 import com.ruoyi.framework.config.ElasticSearchClient;
 import com.ruoyi.system.domain.ShipRecognition;
 import com.ruoyi.system.domain.SysConfig;
 import io.swagger.annotations.Api;
 import io.swagger.annotations.ApiOperation;
+import lombok.SneakyThrows;
+import org.apache.poi.ss.usermodel.Workbook;
 import org.springframework.beans.factory.annotation.Autowired;
+import org.springframework.security.access.prepost.PreAuthorize;
 import org.springframework.web.bind.annotation.GetMapping;
 import org.springframework.web.bind.annotation.RequestMapping;
-import org.springframework.web.bind.annotation.RequestParam;
 import org.springframework.web.bind.annotation.RestController;
 
+import javax.servlet.ServletOutputStream;
+import javax.servlet.http.HttpServletRequest;
+import javax.servlet.http.HttpServletResponse;
+import java.io.FileOutputStream;
 import java.util.ArrayList;
 import java.util.HashMap;
 import java.util.List;
@@ -47,11 +60,11 @@ public class BlackGasController extends BaseController {
         Map<String, Object> params = shipRecognition.getParams();
         Map<String, Object> equalsCondition = new HashMap<>();
         // 组装查询条件
-        equalsCondition.put("aisMmsi", ObjectUtil.isEmpty(shipRecognition.getAismmsi()) ? null : StrUtil.concat(true, "*", Convert.toStr(shipRecognition.getAismmsi()), "*"));
-        equalsCondition.put("aisShipName", StrUtil.isBlank(shipRecognition.getAisshipname()) ? null : StrUtil.concat(true, "*", shipRecognition.getAisshipname(), "*"));
-        equalsCondition.put("snapPos", StrUtil.isBlank(shipRecognition.getSnappos()) ? null : StrUtil.concat(true, "*", shipRecognition.getSnappos(), "*"));
-        equalsCondition.put("aisDst", StrUtil.isBlank(shipRecognition.getAisdst()) ? null : StrUtil.concat(true, "*", shipRecognition.getAisdst(), "*"));
-        equalsCondition.put("aisShipType", shipRecognition.getAisshiptype());
+        equalsCondition.put("aisMmsi", ObjectUtil.isEmpty(shipRecognition.getAisMmsi()) ? null : StrUtil.concat(true, "*", Convert.toStr(shipRecognition.getAisMmsi()), "*"));
+        equalsCondition.put("aisShipName", StrUtil.isBlank(shipRecognition.getAisShipName()) ? null : StrUtil.concat(true, "*", shipRecognition.getAisShipName(), "*"));
+        equalsCondition.put("snapPos", StrUtil.isBlank(shipRecognition.getSnapPos()) ? null : StrUtil.concat(true, "*", shipRecognition.getSnapPos(), "*"));
+        equalsCondition.put("aisDst", StrUtil.isBlank(shipRecognition.getAisDst()) ? null : StrUtil.concat(true, "*", shipRecognition.getAisDst(), "*"));
+        equalsCondition.put("aisShipType", shipRecognition.getAisShipType());
         // 组装范围查询条件
         Map<String, Object> rangeCondition = new HashMap<>();
         if (ObjectUtil.isNotEmpty(params.get("beginTime"))) {
@@ -74,4 +87,39 @@ public class BlackGasController extends BaseController {
         return rspData;
     }
 
+    @SneakyThrows
+    @Log(title = "黑烟记录导出", businessType = BusinessType.EXPORT)
+//    @PreAuthorize("@ss.hasPermi('system:black:export')")
+    @GetMapping("/export")
+    public void export(ShipRecognition shipRecognition, HttpServletRequest request, HttpServletResponse response) {
+        // 传来的参数
+        Map<String, Object> params = shipRecognition.getParams();
+        Map<String, Object> equalsCondition = new HashMap<>();
+        // 组装查询条件
+        equalsCondition.put("aisMmsi", ObjectUtil.isEmpty(shipRecognition.getAisMmsi()) ? null : StrUtil.concat(true, "*", Convert.toStr(shipRecognition.getAisMmsi()), "*"));
+        equalsCondition.put("aisShipName", StrUtil.isBlank(shipRecognition.getAisShipName()) ? null : StrUtil.concat(true, "*", shipRecognition.getAisShipName(), "*"));
+        equalsCondition.put("snapPos", StrUtil.isBlank(shipRecognition.getSnapPos()) ? null : StrUtil.concat(true, "*", shipRecognition.getSnapPos(), "*"));
+        equalsCondition.put("aisDst", StrUtil.isBlank(shipRecognition.getAisDst()) ? null : StrUtil.concat(true, "*", shipRecognition.getAisDst(), "*"));
+        equalsCondition.put("aisShipType", shipRecognition.getAisShipType());
+        // 组装范围查询条件
+        Map<String, Object> rangeCondition = new HashMap<>();
+        if (ObjectUtil.isNotEmpty(params.get("beginTime"))) {
+            params.put("beginTime", params.get("beginTime") + " 00:00:00");
+        }
+        if (ObjectUtil.isNotEmpty(params.get("endTime"))) {
+            params.put("endTime", params.get("endTime") + " 23:59:59");
+        }
+        rangeCondition.put("snapTime", StrUtil.concat(true, "[", Convert.toStr(params.get("beginTime")), ",", Convert.toStr(params.get("endTime")), "]"));
+        List<String> orderBy = new ArrayList<>();
+        orderBy.add("-snapTime");
+        Map<String, Object> maps = client.searchDocument(ElasticConstants.HEIYAN_SHIP_RECOGNITION, equalsCondition, rangeCondition, orderBy, 0, 10000);
+        ExcelUtil<ShipRecognition> util = new ExcelUtil<>(ShipRecognition.class);
+        util.exportExcelByEasyPoi("黑烟违规数据_" + DateUtil.today(),
+                "黑烟违规数据",
+                "黑烟违规数据",
+                ShipRecognition.class,
+                Convert.toList(ShipRecognition.class,maps.get("pageList")),
+                request, response);
+    }
+
 }

+ 7 - 0
ruoyi-common/pom.xml

@@ -125,6 +125,13 @@
             <version>5.3.10</version>
         </dependency>
 
+        <!-- easypoi -->
+        <dependency>
+            <groupId>cn.afterturn</groupId>
+            <artifactId>easypoi-base</artifactId>
+            <version>4.4.0</version>
+        </dependency>
+
     </dependencies>
 
 </project>

+ 121 - 159
ruoyi-common/src/main/java/com/ruoyi/common/utils/StringUtils.java

@@ -6,187 +6,175 @@ import java.util.HashSet;
 import java.util.List;
 import java.util.Map;
 import java.util.Set;
+
 import com.ruoyi.common.constant.Constants;
 import com.ruoyi.common.core.text.StrFormatter;
 
+import javax.servlet.http.HttpServletRequest;
+
 /**
  * 字符串工具类
- * 
+ *
  * @author ruoyi
  */
-public class StringUtils extends org.apache.commons.lang3.StringUtils
-{
-    /** 空字符串 */
+public class StringUtils extends org.apache.commons.lang3.StringUtils {
+    /**
+     * 空字符串
+     */
     private static final String NULLSTR = "";
 
-    /** 下划线 */
+    /**
+     * 下划线
+     */
     private static final char SEPARATOR = '_';
 
     /**
      * 获取参数不为空值
-     * 
+     *
      * @param value defaultValue 要判断的value
      * @return value 返回值
      */
-    public static <T> T nvl(T value, T defaultValue)
-    {
+    public static <T> T nvl(T value, T defaultValue) {
         return value != null ? value : defaultValue;
     }
 
     /**
      * * 判断一个Collection是否为空, 包含List,Set,Queue
-     * 
+     *
      * @param coll 要判断的Collection
      * @return true:为空 false:非空
      */
-    public static boolean isEmpty(Collection<?> coll)
-    {
+    public static boolean isEmpty(Collection<?> coll) {
         return isNull(coll) || coll.isEmpty();
     }
 
     /**
      * * 判断一个Collection是否非空,包含List,Set,Queue
-     * 
+     *
      * @param coll 要判断的Collection
      * @return true:非空 false:空
      */
-    public static boolean isNotEmpty(Collection<?> coll)
-    {
+    public static boolean isNotEmpty(Collection<?> coll) {
         return !isEmpty(coll);
     }
 
     /**
      * * 判断一个对象数组是否为空
-     * 
+     *
      * @param objects 要判断的对象数组
-     ** @return true:为空 false:非空
+     *                * @return true:为空 false:非空
      */
-    public static boolean isEmpty(Object[] objects)
-    {
+    public static boolean isEmpty(Object[] objects) {
         return isNull(objects) || (objects.length == 0);
     }
 
     /**
      * * 判断一个对象数组是否非空
-     * 
+     *
      * @param objects 要判断的对象数组
      * @return true:非空 false:空
      */
-    public static boolean isNotEmpty(Object[] objects)
-    {
+    public static boolean isNotEmpty(Object[] objects) {
         return !isEmpty(objects);
     }
 
     /**
      * * 判断一个Map是否为空
-     * 
+     *
      * @param map 要判断的Map
      * @return true:为空 false:非空
      */
-    public static boolean isEmpty(Map<?, ?> map)
-    {
+    public static boolean isEmpty(Map<?, ?> map) {
         return isNull(map) || map.isEmpty();
     }
 
     /**
      * * 判断一个Map是否为空
-     * 
+     *
      * @param map 要判断的Map
      * @return true:非空 false:空
      */
-    public static boolean isNotEmpty(Map<?, ?> map)
-    {
+    public static boolean isNotEmpty(Map<?, ?> map) {
         return !isEmpty(map);
     }
 
     /**
      * * 判断一个字符串是否为空串
-     * 
+     *
      * @param str String
      * @return true:为空 false:非空
      */
-    public static boolean isEmpty(String str)
-    {
+    public static boolean isEmpty(String str) {
         return isNull(str) || NULLSTR.equals(str.trim());
     }
 
     /**
      * * 判断一个字符串是否为非空串
-     * 
+     *
      * @param str String
      * @return true:非空串 false:空串
      */
-    public static boolean isNotEmpty(String str)
-    {
+    public static boolean isNotEmpty(String str) {
         return !isEmpty(str);
     }
 
     /**
      * * 判断一个对象是否为空
-     * 
+     *
      * @param object Object
      * @return true:为空 false:非空
      */
-    public static boolean isNull(Object object)
-    {
+    public static boolean isNull(Object object) {
         return object == null;
     }
 
     /**
      * * 判断一个对象是否非空
-     * 
+     *
      * @param object Object
      * @return true:非空 false:空
      */
-    public static boolean isNotNull(Object object)
-    {
+    public static boolean isNotNull(Object object) {
         return !isNull(object);
     }
 
     /**
      * * 判断一个对象是否是数组类型(Java基本型别的数组)
-     * 
+     *
      * @param object 对象
      * @return true:是数组 false:不是数组
      */
-    public static boolean isArray(Object object)
-    {
+    public static boolean isArray(Object object) {
         return isNotNull(object) && object.getClass().isArray();
     }
 
     /**
      * 去空格
      */
-    public static String trim(String str)
-    {
+    public static String trim(String str) {
         return (str == null ? "" : str.trim());
     }
 
     /**
      * 截取字符串
-     * 
-     * @param str 字符串
+     *
+     * @param str   字符串
      * @param start 开始
      * @return 结果
      */
-    public static String substring(final String str, int start)
-    {
-        if (str == null)
-        {
+    public static String substring(final String str, int start) {
+        if (str == null) {
             return NULLSTR;
         }
 
-        if (start < 0)
-        {
+        if (start < 0) {
             start = str.length() + start;
         }
 
-        if (start < 0)
-        {
+        if (start < 0) {
             start = 0;
         }
-        if (start > str.length())
-        {
+        if (start > str.length()) {
             return NULLSTR;
         }
 
@@ -195,44 +183,36 @@ public class StringUtils extends org.apache.commons.lang3.StringUtils
 
     /**
      * 截取字符串
-     * 
-     * @param str 字符串
+     *
+     * @param str   字符串
      * @param start 开始
-     * @param end 结束
+     * @param end   结束
      * @return 结果
      */
-    public static String substring(final String str, int start, int end)
-    {
-        if (str == null)
-        {
+    public static String substring(final String str, int start, int end) {
+        if (str == null) {
             return NULLSTR;
         }
 
-        if (end < 0)
-        {
+        if (end < 0) {
             end = str.length() + end;
         }
-        if (start < 0)
-        {
+        if (start < 0) {
             start = str.length() + start;
         }
 
-        if (end > str.length())
-        {
+        if (end > str.length()) {
             end = str.length();
         }
 
-        if (start > end)
-        {
+        if (start > end) {
             return NULLSTR;
         }
 
-        if (start < 0)
-        {
+        if (start < 0) {
             start = 0;
         }
-        if (end < 0)
-        {
+        if (end < 0) {
             end = 0;
         }
 
@@ -247,15 +227,13 @@ public class StringUtils extends org.apache.commons.lang3.StringUtils
      * 通常使用:format("this is {} for {}", "a", "b") -> this is a for b<br>
      * 转义{}: format("this is \\{} for {}", "a", "b") -> this is \{} for a<br>
      * 转义\: format("this is \\\\{} for {}", "a", "b") -> this is \a for b<br>
-     * 
+     *
      * @param template 文本模板,被替换的部分用 {} 表示
-     * @param params 参数值
+     * @param params   参数值
      * @return 格式化后的文本
      */
-    public static String format(String template, Object... params)
-    {
-        if (isEmpty(params) || isEmpty(template))
-        {
+    public static String format(String template, Object... params) {
+        if (isEmpty(params) || isEmpty(template)) {
             return template;
         }
         return StrFormatter.format(template, params);
@@ -263,58 +241,50 @@ public class StringUtils extends org.apache.commons.lang3.StringUtils
 
     /**
      * 是否为http(s)://开头
-     * 
+     *
      * @param link 链接
      * @return 结果
      */
-    public static boolean ishttp(String link)
-    {
+    public static boolean ishttp(String link) {
         return StringUtils.startsWithAny(link, Constants.HTTP, Constants.HTTPS);
     }
 
     /**
      * 字符串转set
-     * 
+     *
      * @param str 字符串
      * @param sep 分隔符
      * @return set集合
      */
-    public static final Set<String> str2Set(String str, String sep)
-    {
+    public static final Set<String> str2Set(String str, String sep) {
         return new HashSet<String>(str2List(str, sep, true, false));
     }
 
     /**
      * 字符串转list
-     * 
-     * @param str 字符串
-     * @param sep 分隔符
+     *
+     * @param str         字符串
+     * @param sep         分隔符
      * @param filterBlank 过滤纯空白
-     * @param trim 去掉首尾空白
+     * @param trim        去掉首尾空白
      * @return list集合
      */
-    public static final List<String> str2List(String str, String sep, boolean filterBlank, boolean trim)
-    {
+    public static final List<String> str2List(String str, String sep, boolean filterBlank, boolean trim) {
         List<String> list = new ArrayList<String>();
-        if (StringUtils.isEmpty(str))
-        {
+        if (StringUtils.isEmpty(str)) {
             return list;
         }
 
         // 过滤空白字符串
-        if (filterBlank && StringUtils.isBlank(str))
-        {
+        if (filterBlank && StringUtils.isBlank(str)) {
             return list;
         }
         String[] split = str.split(sep);
-        for (String string : split)
-        {
-            if (filterBlank && StringUtils.isBlank(string))
-            {
+        for (String string : split) {
+            if (filterBlank && StringUtils.isBlank(string)) {
                 continue;
             }
-            if (trim)
-            {
+            if (trim) {
                 string = string.trim();
             }
             list.add(string);
@@ -326,10 +296,8 @@ public class StringUtils extends org.apache.commons.lang3.StringUtils
     /**
      * 驼峰转下划线命名
      */
-    public static String toUnderScoreCase(String str)
-    {
-        if (str == null)
-        {
+    public static String toUnderScoreCase(String str) {
+        if (str == null) {
             return null;
         }
         StringBuilder sb = new StringBuilder();
@@ -339,31 +307,23 @@ public class StringUtils extends org.apache.commons.lang3.StringUtils
         boolean curreCharIsUpperCase = true;
         // 下一字符是否大写
         boolean nexteCharIsUpperCase = true;
-        for (int i = 0; i < str.length(); i++)
-        {
+        for (int i = 0; i < str.length(); i++) {
             char c = str.charAt(i);
-            if (i > 0)
-            {
+            if (i > 0) {
                 preCharIsUpperCase = Character.isUpperCase(str.charAt(i - 1));
-            }
-            else
-            {
+            } else {
                 preCharIsUpperCase = false;
             }
 
             curreCharIsUpperCase = Character.isUpperCase(c);
 
-            if (i < (str.length() - 1))
-            {
+            if (i < (str.length() - 1)) {
                 nexteCharIsUpperCase = Character.isUpperCase(str.charAt(i + 1));
             }
 
-            if (preCharIsUpperCase && curreCharIsUpperCase && !nexteCharIsUpperCase)
-            {
+            if (preCharIsUpperCase && curreCharIsUpperCase && !nexteCharIsUpperCase) {
                 sb.append(SEPARATOR);
-            }
-            else if ((i != 0 && !preCharIsUpperCase) && curreCharIsUpperCase)
-            {
+            } else if ((i != 0 && !preCharIsUpperCase) && curreCharIsUpperCase) {
                 sb.append(SEPARATOR);
             }
             sb.append(Character.toLowerCase(c));
@@ -374,19 +334,15 @@ public class StringUtils extends org.apache.commons.lang3.StringUtils
 
     /**
      * 是否包含字符串
-     * 
-     * @param str 验证字符串
+     *
+     * @param str  验证字符串
      * @param strs 字符串组
      * @return 包含返回true
      */
-    public static boolean inStringIgnoreCase(String str, String... strs)
-    {
-        if (str != null && strs != null)
-        {
-            for (String s : strs)
-            {
-                if (str.equalsIgnoreCase(trim(s)))
-                {
+    public static boolean inStringIgnoreCase(String str, String... strs) {
+        if (str != null && strs != null) {
+            for (String s : strs) {
+                if (str.equalsIgnoreCase(trim(s))) {
                     return true;
                 }
             }
@@ -396,31 +352,25 @@ public class StringUtils extends org.apache.commons.lang3.StringUtils
 
     /**
      * 将下划线大写方式命名的字符串转换为驼峰式。如果转换前的下划线大写方式命名的字符串为空,则返回空字符串。 例如:HELLO_WORLD->HelloWorld
-     * 
+     *
      * @param name 转换前的下划线大写方式命名的字符串
      * @return 转换后的驼峰式命名的字符串
      */
-    public static String convertToCamelCase(String name)
-    {
+    public static String convertToCamelCase(String name) {
         StringBuilder result = new StringBuilder();
         // 快速检查
-        if (name == null || name.isEmpty())
-        {
+        if (name == null || name.isEmpty()) {
             // 没必要转换
             return "";
-        }
-        else if (!name.contains("_"))
-        {
+        } else if (!name.contains("_")) {
             // 不含下划线,仅将首字母大写
             return name.substring(0, 1).toUpperCase() + name.substring(1);
         }
         // 用下划线将原始字符串分割
         String[] camels = name.split("_");
-        for (String camel : camels)
-        {
+        for (String camel : camels) {
             // 跳过原始字符串中开头、结尾的下换线或双重下划线
-            if (camel.isEmpty())
-            {
+            if (camel.isEmpty()) {
                 continue;
             }
             // 首字母大写
@@ -433,30 +383,22 @@ public class StringUtils extends org.apache.commons.lang3.StringUtils
     /**
      * 驼峰式命名法 例如:user_name->userName
      */
-    public static String toCamelCase(String s)
-    {
-        if (s == null)
-        {
+    public static String toCamelCase(String s) {
+        if (s == null) {
             return null;
         }
         s = s.toLowerCase();
         StringBuilder sb = new StringBuilder(s.length());
         boolean upperCase = false;
-        for (int i = 0; i < s.length(); i++)
-        {
+        for (int i = 0; i < s.length(); i++) {
             char c = s.charAt(i);
 
-            if (c == SEPARATOR)
-            {
+            if (c == SEPARATOR) {
                 upperCase = true;
-            }
-            else if (upperCase)
-            {
+            } else if (upperCase) {
                 sb.append(Character.toUpperCase(c));
                 upperCase = false;
-            }
-            else
-            {
+            } else {
                 sb.append(c);
             }
         }
@@ -464,8 +406,28 @@ public class StringUtils extends org.apache.commons.lang3.StringUtils
     }
 
     @SuppressWarnings("unchecked")
-    public static <T> T cast(Object obj)
-    {
+    public static <T> T cast(Object obj) {
         return (T) obj;
     }
+
+    /**
+     * 对文件流输出下载的中文文件名进行编码 屏蔽各种浏览器版本的差异性
+     *
+     * @throws Exception
+     */
+    public static String encodeChineseDownloadFileName(
+            HttpServletRequest request, String pFileName) throws Exception {
+
+        String filename;
+        String agent = request.getHeader("USER-AGENT").toLowerCase();
+        if (agent.contains("firefox")) {
+            filename = "=?UTF-8?B?" + (new String(org.apache.commons.codec.binary.Base64.encodeBase64(pFileName.getBytes("UTF-8")))) + "?=";
+        } else if (agent.contains("chrome") || agent.contains("safari")) {
+            filename = new String(pFileName.getBytes(), "ISO8859-1");
+        } else {//IE7+
+            filename = java.net.URLEncoder.encode(pFileName, "UTF-8");
+            filename = filename.replace("+", "%20");
+        }
+        return filename;
+    }
 }

+ 63 - 37
ruoyi-common/src/main/java/com/ruoyi/common/utils/poi/ExcelUtil.java

@@ -8,16 +8,11 @@ import java.io.OutputStream;
 import java.lang.reflect.Field;
 import java.math.BigDecimal;
 import java.text.DecimalFormat;
-import java.util.ArrayList;
-import java.util.Arrays;
-import java.util.Comparator;
-import java.util.Date;
-import java.util.HashMap;
-import java.util.List;
-import java.util.Map;
-import java.util.Set;
-import java.util.UUID;
+import java.util.*;
 import java.util.stream.Collectors;
+
+import cn.afterturn.easypoi.excel.ExcelExportUtil;
+import cn.afterturn.easypoi.excel.entity.ExportParams;
 import org.apache.poi.ss.usermodel.BorderStyle;
 import org.apache.poi.ss.usermodel.Cell;
 import org.apache.poi.ss.usermodel.CellStyle;
@@ -58,9 +53,13 @@ import com.ruoyi.common.utils.file.FileTypeUtils;
 import com.ruoyi.common.utils.file.ImageUtils;
 import com.ruoyi.common.utils.reflect.ReflectUtils;
 
+import javax.servlet.ServletOutputStream;
+import javax.servlet.http.HttpServletRequest;
+import javax.servlet.http.HttpServletResponse;
+
 /**
  * Excel相关处理
- * 
+ *
  * @author ruoyi
  */
 public class ExcelUtil<T>
@@ -116,12 +115,12 @@ public class ExcelUtil<T>
      * 统计列表
      */
     private Map<Integer, Double> statistics = new HashMap<Integer, Double>();
-    
+
     /**
      * 数字格式
      */
     private static final DecimalFormat DOUBLE_FORMAT = new DecimalFormat("######0.00");
-    
+
     /**
      * 实体对象
      */
@@ -147,7 +146,7 @@ public class ExcelUtil<T>
 
     /**
      * 对excel表单默认第一个索引名转换成list
-     * 
+     *
      * @param is 输入流
      * @return 转换后集合
      */
@@ -158,7 +157,7 @@ public class ExcelUtil<T>
 
     /**
      * 对excel表单指定表格索引名转换成list
-     * 
+     *
      * @param sheetName 表格索引名
      * @param is 输入流
      * @return 转换后集合
@@ -326,7 +325,7 @@ public class ExcelUtil<T>
 
     /**
      * 对list数据源将其里面的数据导入到excel表单
-     * 
+     *
      * @param list 导出数据集合
      * @param sheetName 工作表的名称
      * @return 结果
@@ -339,7 +338,7 @@ public class ExcelUtil<T>
 
     /**
      * 对list数据源将其里面的数据导入到excel表单
-     * 
+     *
      * @param sheetName 工作表的名称
      * @return 结果
      */
@@ -350,8 +349,35 @@ public class ExcelUtil<T>
     }
 
     /**
+     * 第三方easypoi的方式导出excel
+     * @param fileName
+     * @param title
+     * @param sheetName
+     * @param pojoClass
+     * @param dataSet
+     * @param request
+     * @param response
+     */
+    public void exportExcelByEasyPoi(String fileName,
+                                     String title,
+                                     String sheetName,
+                                     Class<T> pojoClass,
+                                     Collection<T> dataSet,
+                                     HttpServletRequest request,
+                                     HttpServletResponse response) throws Exception {
+        fileName = StringUtils.encodeChineseDownloadFileName(request, fileName);
+        Workbook workbook = ExcelExportUtil.exportExcel(new ExportParams(title, sheetName),
+                pojoClass, dataSet);
+        response.setContentType("application/vnd.ms-excel;chartset=utf-8");
+        response.setHeader("Content-Disposition", "attachment; filename=\"" + fileName + ".xlsx\"");
+        ServletOutputStream out = response.getOutputStream();
+        workbook.write(out);
+        out.flush();
+    }
+
+    /**
      * 对list数据源将其里面的数据导入到excel表单
-     * 
+     *
      * @return 结果
      */
     public AjaxResult exportExcel()
@@ -419,7 +445,7 @@ public class ExcelUtil<T>
 
     /**
      * 填充excel数据
-     * 
+     *
      * @param index 序号
      * @param row 单元格行
      */
@@ -446,7 +472,7 @@ public class ExcelUtil<T>
 
     /**
      * 创建表格样式
-     * 
+     *
      * @param wb 工作薄对象
      * @return 样式列表
      */
@@ -484,7 +510,7 @@ public class ExcelUtil<T>
         headerFont.setColor(IndexedColors.WHITE.getIndex());
         style.setFont(headerFont);
         styles.put("header", style);
-        
+
         style = wb.createCellStyle();
         style.setAlignment(HorizontalAlignment.CENTER);
         style.setVerticalAlignment(VerticalAlignment.CENTER);
@@ -528,7 +554,7 @@ public class ExcelUtil<T>
 
     /**
      * 设置单元格信息
-     * 
+     *
      * @param value 单元格值
      * @param attr 注解相关
      * @param cell 单元格信息
@@ -559,7 +585,7 @@ public class ExcelUtil<T>
             }
         }
     }
-    
+
     /**
      * 获取画布
      */
@@ -674,7 +700,7 @@ public class ExcelUtil<T>
 
     /**
      * 设置 POI XSSFSheet 单元格提示
-     * 
+     *
      * @param sheet 表单
      * @param promptTitle 提示标题
      * @param promptContent 提示内容
@@ -697,7 +723,7 @@ public class ExcelUtil<T>
 
     /**
      * 设置某些列的值只能输入预制的数据,显示下拉框.
-     * 
+     *
      * @param sheet 要设置的sheet.
      * @param textlist 下拉框显示的内容
      * @param firstRow 开始行
@@ -731,7 +757,7 @@ public class ExcelUtil<T>
 
     /**
      * 解析导出值 0=男,1=女,2=未知
-     * 
+     *
      * @param propertyValue 参数值
      * @param converterExp 翻译注解
      * @param separator 分隔符
@@ -768,7 +794,7 @@ public class ExcelUtil<T>
 
     /**
      * 反向解析值 男=0,女=1,未知=2
-     * 
+     *
      * @param propertyValue 参数值
      * @param converterExp 翻译注解
      * @param separator 分隔符
@@ -802,10 +828,10 @@ public class ExcelUtil<T>
         }
         return StringUtils.stripEnd(propertyString.toString(), separator);
     }
-    
+
     /**
      * 解析字典值
-     * 
+     *
      * @param dictValue 字典值
      * @param dictType 字典类型
      * @param separator 分隔符
@@ -818,7 +844,7 @@ public class ExcelUtil<T>
 
     /**
      * 反向解析值字典值
-     * 
+     *
      * @param dictLabel 字典标签
      * @param dictType 字典类型
      * @param separator 分隔符
@@ -828,7 +854,7 @@ public class ExcelUtil<T>
     {
         return DictUtils.getDictValue(dictType, dictLabel, separator);
     }
-    
+
     /**
      * 合计统计信息
      */
@@ -865,7 +891,7 @@ public class ExcelUtil<T>
             cell = row.createCell(0);
             cell.setCellStyle(styles.get("total"));
             cell.setCellValue("合计");
-            
+
             for (Integer key : keys)
             {
                 cell = row.createCell(key);
@@ -887,7 +913,7 @@ public class ExcelUtil<T>
 
     /**
      * 获取下载路径
-     * 
+     *
      * @param filename 文件名称
      */
     public String getAbsoluteFile(String filename)
@@ -903,7 +929,7 @@ public class ExcelUtil<T>
 
     /**
      * 获取bean中的属性值
-     * 
+     *
      * @param vo 实体对象
      * @param field 字段
      * @param excel 注解
@@ -934,7 +960,7 @@ public class ExcelUtil<T>
 
     /**
      * 以类的属性的get方法方法形式获取值
-     * 
+     *
      * @param o
      * @param name
      * @return value
@@ -983,7 +1009,7 @@ public class ExcelUtil<T>
         this.fields = this.fields.stream().sorted(Comparator.comparing(objects -> ((Excel) objects[1]).sort())).collect(Collectors.toList());
         this.maxHeight = getRowHeight();
     }
-    
+
     /**
      * 根据注解获取最大行高
      */
@@ -1019,7 +1045,7 @@ public class ExcelUtil<T>
 
     /**
      * 创建工作表
-     * 
+     *
      * @param sheetNo sheet数量
      * @param index 序号
      */
@@ -1040,7 +1066,7 @@ public class ExcelUtil<T>
 
     /**
      * 获取单元格值
-     * 
+     *
      * @param row 获取的行
      * @param column 获取单元格列号
      * @return 单元格值

+ 1 - 0
ruoyi-framework/src/main/java/com/ruoyi/framework/config/SecurityConfig.java

@@ -114,6 +114,7 @@ public class SecurityConfig extends WebSecurityConfigurerAdapter
                 .antMatchers("/webjars/**").anonymous()
                 .antMatchers("/*/api-docs").anonymous()
                 .antMatchers("/druid/**").anonymous()
+                .antMatchers("/black/**").anonymous()
                 // 除上面外的所有请求全部需要鉴权认证
                 .anyRequest().authenticated()
                 .and()

+ 6 - 0
ruoyi-system/pom.xml

@@ -28,6 +28,12 @@
             <artifactId>lombok</artifactId>
         </dependency>
 
+        <dependency>
+            <groupId>cn.afterturn</groupId>
+            <artifactId>easypoi-annotation</artifactId>
+            <version>4.4.0</version>
+        </dependency>
+
     </dependencies>
 
 </project>

+ 62 - 65
ruoyi-system/src/main/java/com/ruoyi/system/domain/ShipRecognition.java

@@ -1,13 +1,11 @@
 package com.ruoyi.system.domain;
 
-import java.math.BigDecimal;
-
+import cn.afterturn.easypoi.excel.annotation.Excel;
+import com.ruoyi.common.core.domain.BaseEntity;
 import lombok.Data;
 import lombok.EqualsAndHashCode;
-import org.apache.commons.lang3.builder.ToStringBuilder;
-import org.apache.commons.lang3.builder.ToStringStyle;
-import com.ruoyi.common.annotation.Excel;
-import com.ruoyi.common.core.domain.BaseEntity;
+
+import java.math.BigDecimal;
 
 /**
  * 船舶信息对象 ship_recognition
@@ -25,128 +23,127 @@ public class ShipRecognition extends BaseEntity
     private Long id;
 
     /** AIS船舶距离, 单位:m */
-    @Excel(name = "AIS船舶距离, 单位:m")
-    private BigDecimal aisdist;
+    @Excel(name = "船舶距离, 单位:m")
+    private BigDecimal aisDist;
 
     /** AIS吃水, 单位:m */
-    @Excel(name = "AIS吃水, 单位:m")
-    private BigDecimal aisdrt;
+    @Excel(name = "吃水, 单位:m")
+    private BigDecimal aisDrt;
 
     /** AIS目的地 */
-    @Excel(name = "AIS目的地")
-    private String aisdst;
+    @Excel(name = "目的地")
+    private String aisDst;
 
     /** 9位码。例如412119710, 0或null表示AIS未开启 */
-    @Excel(name = "9位码。例如412119710, 0或null表示AIS未开启")
-    private Long aismmsi;
+    @Excel(name = "MMSI")
+    private Long aisMmsi;
 
     /** AIS船长, 单位:m */
-    @Excel(name = "AIS船长, 单位:m")
-    private Long aisshiplen;
+    @Excel(name = "船长, 单位:m")
+    private Long aisShipLen;
 
     /** 可能是中文,AIS船名,为拼音。例如SU SU HUO 009 */
-    @Excel(name = "可能是中文,AIS船名,为拼音。例如SU SU HUO 009")
-    private String aisshipname;
+    @Excel(name = "船名")
+    private String aisShipName;
 
     /** AIS船速, 单位:m/s */
-    @Excel(name = "AIS船速, 单位:m/s")
-    private BigDecimal aisshipspd;
+    @Excel(name = "船速, 单位:m/s")
+    private BigDecimal aisShipSpd;
 
     /** AIS船舶类型 */
-    @Excel(name = "AIS船舶类型")
-    private String aisshiptype;
+    @Excel(name = "船舶类型")
+    private String aisShipType;
 
     /** AIS船宽, 单位:m */
-    @Excel(name = "AIS船宽, 单位:m")
-    private Long aisshipwidth;
+    @Excel(name = "船宽, 单位:m")
+    private Long aisShipWidth;
 
     /** 尺寸异常 */
     @Excel(name = "尺寸异常")
-    private Long isabnormalsize;
+    private Long isAbnormalSize;
 
     /** AIS纬度,单位:度 */
-    @Excel(name = "AIS纬度,单位:度")
+    @Excel(name = "纬度,单位:度")
     private BigDecimal latitude;
 
     /** 黑烟:度数 */
     @Excel(name = "黑烟:度数")
-    private Long rcgsoot;
+    private Long rcgSoot;
 
     /** 船舶过闸闸次 */
     @Excel(name = "船舶过闸闸次")
-    private Long lockseq;
+    private Long lockSeq;
 
     /** AIS经度,单位:度 */
-    @Excel(name = "AIS经度,单位:度")
+    @Excel(name = "经度,单位:度")
     private BigDecimal longitude;
 
     /** 图像识别得到的载货类型。例如:钢筋,砂石。 */
-    @Excel(name = "图像识别得到的载货类型。例如:钢筋,砂石。")
-    private String rcgcargotype;
+    @Excel(name = "图像识别载货类型")
+    private String rcgCargoType;
 
     /** 图像识别得到的船舶载重吨位, 单位:t */
-    @Excel(name = "图像识别得到的船舶载重吨位, 单位:t")
-    private BigDecimal rcgdeadweightton;
+    @Excel(name = "图像识别船舶载重吨位, 单位:t")
+    private BigDecimal rcgDeadweightTon;
 
     /** 图像识别得到的,船舶距离相机直线距离。单位:m */
-    @Excel(name = "图像识别得到的,船舶距离相机直线距离。单位:m")
-    private BigDecimal rcgdist;
+    @Excel(name = "图像识别船舶距离相机直线距离。单位:m")
+    private BigDecimal rcgDist;
 
     /** 图像识别得到的船舶吃水, 单位:m */
-    @Excel(name = "图像识别得到的船舶吃水, 单位:m")
-    private BigDecimal rcgdrt;
+    @Excel(name = "图像识别船舶吃水, 单位:m")
+    private BigDecimal rcgDrt;
 
     /** 是否为船队。0 否,即单机船; 1 是,即为船队 */
     @Excel(name = "是否为船队。0 否,即单机船; 1 是,即为船队")
-    private Long rcgisfleet;
+    private Long rcgIsFleet;
 
     /** UNKNOWN 未知, EMPTY_LOAD 空载, HEAVY_LOAD 重载, OVER_LOAD 超载 */
     @Excel(name = "UNKNOWN 未知, EMPTY_LOAD 空载, HEAVY_LOAD 重载, OVER_LOAD 超载")
-    private String rcgloadsts;
+    private String rcgLoadSts;
 
     /** 图像识别得到的船舶水面上高度,单位:m */
-    @Excel(name = "图像识别得到的船舶水面上高度,单位:m")
-    private BigDecimal rcgshipheightabovewater;
+    @Excel(name = "图像识别船舶水面上高度,单位:m")
+    private BigDecimal rcgShipHeightAboveWater;
 
     /** 图像识别得到的船长,单位:m */
-    @Excel(name = "图像识别得到的船长,单位:m")
-    private BigDecimal rcgshiplen;
+    @Excel(name = "图像识别船长,单位:m")
+    private BigDecimal rcgShipLen;
 
     /** 图像识别得到的船名, 中文, 如: 苏宿货009 */
-    @Excel(name = "图像识别得到的船名, 中文, 如: 苏宿货009")
-    private String rcgshipname;
+    @Excel(name = "图像识别船名")
+    private String rcgShipName;
 
     /** 图像识别得到的速度,带符号,单位m/s */
-    @Excel(name = "图像识别得到的速度,带符号,单位m/s")
-    private BigDecimal rcgshipspd;
+    @Excel(name = "图像识别速度,单位m/s")
+    private BigDecimal rcgShipSpd;
 
     /** 图像识别得到的船舶类型。例如: 货船,集装箱船,危化品船 */
-    @Excel(name = "图像识别得到的船舶类型。例如: 货船,集装箱船,危化品船")
-    private String rcgshiptype;
+    @Excel(name = "图像识别船舶类型")
+    private String rcgShipType;
 
     /** 图像识别得到的船宽,单位:m */
-    @Excel(name = "图像识别得到的船宽,单位:m")
-    private BigDecimal rcgshipwidth;
+    @Excel(name = "图像识别船宽,单位:m")
+    private BigDecimal rcgShipWidth;
 
     /** 船籍港 */
     @Excel(name = "船籍港")
-    private String regportname;
+    private String regportName;
 
     /** 抓拍图片路径 */
     @Excel(name = "抓拍图片路径")
-    private String snapimpath;
+    private String snapImPath;
 
     /** 抓拍地点 */
     @Excel(name = "抓拍地点")
-    private String snappos;
+    private String snapPos;
 
     /** 抓拍时间 */
-    @Excel(name = "抓拍时间")
-    private String snaptime;
+    private String snapTime;
 
     /** 抓拍时间统一格式: 2020-12-12 12:00:11 */
-    @Excel(name = "抓拍时间统一格式: 2020-12-12 12:00:11")
-    private String snaptimefmt;
+    @Excel(name = "抓拍时间")
+    private String snapTimeFmt;
 
     /** 状态 */
     @Excel(name = "状态")
@@ -154,23 +151,23 @@ public class ShipRecognition extends BaseEntity
 
     /** 船名特征信息 */
     @Excel(name = "船名特征信息")
-    private String textfeaturelabel;
+    private String textFeatureLabel;
 
     /** 船名识别原图url */
     @Excel(name = "船名识别原图url")
-    private String textimgurl;
+    private String textImgUrl;
 
     /** 图像识别得到的船舶详细类型 */
     @Excel(name = "图像识别得到的船舶详细类型")
-    private String rcgshiptypedetail;
+    private String rcgShipTypeDetail;
 
     /** useWarn: true, 使用外部输入预警信息 */
-    @Excel(name = "useWarn: true, 使用外部输入预警信息")
-    private Long usewarn;
+    @Excel(name = "使用外部输入预警信息")
+    private Long useWarn;
 
     /** 外部输入报警信息详情 */
     @Excel(name = "外部输入报警信息详情")
-    private String warnlabellist;
+    private String warnLabelList;
 
     /** 二维码识别内容 */
     @Excel(name = "二维码识别内容")
@@ -178,6 +175,6 @@ public class ShipRecognition extends BaseEntity
 
     /** 船名方向 */
     @Excel(name = "船名方向")
-    private String shipnamedirection;
+    private String shipNameDirection;
 
 }