From b6b0cb226fcf184525ee7b36af3a09471e9c0057 Mon Sep 17 00:00:00 2001
From: 13693261870 <252740454@qq.com>
Date: 星期一, 25 三月 2024 11:29:33 +0800
Subject: [PATCH] 修改数据统计的查询条件

---
 src/main/java/com/lf/server/helper/WebHelper.java |  175 +++++++++++++++++++++++++++++++++++++++++++++++++++++-----
 1 files changed, 160 insertions(+), 15 deletions(-)

diff --git a/src/main/java/com/lf/server/helper/WebHelper.java b/src/main/java/com/lf/server/helper/WebHelper.java
index 4014998..2d4c289 100644
--- a/src/main/java/com/lf/server/helper/WebHelper.java
+++ b/src/main/java/com/lf/server/helper/WebHelper.java
@@ -5,20 +5,21 @@
 import com.lf.server.entity.all.ResponseMsg;
 import com.lf.server.entity.all.SettingData;
 import com.lf.server.entity.all.StaticData;
+import org.apache.commons.logging.Log;
+import org.apache.commons.logging.LogFactory;
 import org.springframework.web.context.request.RequestContextHolder;
 import org.springframework.web.context.request.ServletRequestAttributes;
 
 import javax.servlet.ServletContext;
+import javax.servlet.ServletOutputStream;
 import javax.servlet.http.Cookie;
 import javax.servlet.http.HttpServletRequest;
 import javax.servlet.http.HttpServletResponse;
 import javax.servlet.http.HttpSession;
-import java.io.IOException;
-import java.io.PrintWriter;
+import java.io.*;
+import java.net.URLEncoder;
 import java.sql.Timestamp;
-import java.util.Calendar;
-import java.util.Random;
-import java.util.UUID;
+import java.util.*;
 
 /**
  * Web甯姪绫�
@@ -28,6 +29,8 @@
     private final static String UNKNOWN = "unknown";
 
     private final static String COMMA = ",";
+
+    private final static Log log = LogFactory.getLog(WebHelper.class);
 
     /**
      * 鑾峰彇GUID
@@ -249,21 +252,33 @@
     }
 
     /**
-     * 杈撳嚭json鏁版嵁鍒板墠绔�
+     * 杈撳嚭str鑷冲墠绔�
      */
-    public static boolean write2Page(HttpServletResponse response, String jsonPack) throws IOException {
-        response.setContentType("application/json;charset=UTF-8");
-        response.setHeader("Cache-Control", "no-cache");
-        response.setHeader("Pragma", "No-cache");
-        response.setDateHeader("Expires", 0);
+    public static boolean writeStr2Page(HttpServletResponse res, String str) {
+        try {
+            res.setContentType("application/json;charset=UTF-8");
+            res.setHeader("Cache-Control", "no-cache");
+            res.setHeader("Pragma", "No-cache");
+            res.setDateHeader("Expires", 0);
 
-        PrintWriter out = response.getWriter();
-        out.print(jsonPack);
+            PrintWriter out = res.getWriter();
+            out.print(str);
 
-        out.flush();
-        out.close();
+            out.flush();
+            out.close();
+        } catch (Exception ex) {
+            log.error(ex.getMessage(), ex);
+        }
 
         return false;
+    }
+
+    /**
+     * 杈撳嚭json鑷冲墠绔�
+     */
+    public static void writeJson2Page(HttpServletResponse res, String str) {
+        String json = JSON.toJSONString(new ResponseMsg<>(HttpStatus.ERROR, str));
+        writeStr2Page(res, json);
     }
 
     /**
@@ -274,9 +289,139 @@
     }
 
     /**
+     * 鍐欏搷搴斾俊鎭�
+     */
+    public static void writeInfo(HttpStatus status, String info, HttpServletResponse res) {
+        WebHelper.writeStr2Page(res, WebHelper.getErrJson(status, info));
+    }
+
+    /**
      * 鑾峰彇闅忔満鏁存暟
      */
     public static int getRandomInt(int min, int max) {
         return new Random().nextInt(max) % (max - min + 1) + min;
     }
+
+    /**
+     * 涓嬭浇鏂囦欢
+     */
+    public static void download(String file, String fileName, HttpServletResponse res) throws Exception {
+        download(file, fileName, false, res);
+    }
+
+    /**
+     * 涓嬭浇鏂囦欢
+     *
+     * @param file     鏂囦欢
+     * @param fileName 鏂囦欢鍚�
+     * @param res      鍝嶅簲
+     * @throws Exception 寮傚父
+     */
+    public static void download(String file, String fileName, boolean inline, HttpServletResponse res) throws Exception {
+        if (StringHelper.isEmpty(fileName)) {
+            fileName = StringHelper.YMDHMS2_FORMAT.format(new Date());
+        }
+        fileName = URLEncoder.encode(fileName, "UTF-8").replace("+", "%20");
+        String dispose = inline ? "inline" : "attachment";
+
+        // 璁剧疆鍝嶅簲澶翠腑鏂囦欢鐨勪笅杞芥柟寮忎负闄勪欢鏂瑰紡锛屼互鍙婅缃枃浠跺悕
+        res.setHeader("Content-Disposition", dispose + "; filename*=UTF-8''" + fileName);
+        // 璁剧疆鍝嶅簲澶寸殑缂栫爜鏍煎紡涓� UTF-8
+        res.setCharacterEncoding("UTF-8");
+
+        // 閫氳繃response瀵硅薄璁剧疆鍝嶅簲鏁版嵁鏍煎紡(濡傦細"text/plain; charset=utf-8")
+        String ext = FileHelper.getExtension(file);
+        String mime = FileHelper.getMime(ext);
+        res.setContentType(mime);
+
+        // 閫氳繃response瀵硅薄锛岃幏鍙栧埌杈撳嚭娴�
+        ServletOutputStream outputStream = res.getOutputStream();
+        // 瀹氫箟杈撳叆娴侊紝閫氳繃杈撳叆娴佽鍙栨枃浠跺唴瀹�
+        FileInputStream fileInputStream = new FileInputStream(file);
+
+        int len = 0;
+        byte[] bytes = new byte[1024];
+        while ((len = fileInputStream.read(bytes)) != -1) {
+            // 閫氳繃杈撳叆娴佽鍙栨枃浠舵暟鎹紝鐒跺悗閫氳繃涓婅堪鐨勮緭鍑烘祦鍐欏洖娴忚鍣�
+            outputStream.write(bytes, 0, len);
+            outputStream.flush();
+        }
+
+        // 鍏抽棴璧勬簮
+        fileInputStream.close();
+        outputStream.close();
+    }
+
+    /**
+     * 鎵ц鍛戒护
+     *
+     * @param cmd 鍛戒护
+     */
+    public static void exec(String cmd) {
+        try {
+            Runtime.getRuntime().exec(cmd);
+        } catch (Exception ex) {
+            log.error(ex.getMessage(), ex);
+        }
+    }
+
+    /**
+     * 鎵ц鍛戒护
+     *
+     * @param cmd 鍛戒护
+     */
+    public static String exec2(String cmd) {
+        try {
+            StringBuilder sb = new StringBuilder();
+            Process process = Runtime.getRuntime().exec(cmd);
+            BufferedReader reader = new BufferedReader(new InputStreamReader(process.getInputStream()));
+
+            String line;
+            while ((line = reader.readLine()) != null) {
+                sb.append(line).append("\n");
+            }
+            reader.close();
+
+            return sb.toString();
+        } catch (Exception ex) {
+            log.error(ex.getMessage(), ex);
+            return null;
+        }
+    }
+
+    /**
+     * 鑾峰彇璇锋眰鐨勫弬鏁板��
+     *
+     * @param req 璇锋眰
+     * @param key 鍙傛暟鍚�
+     * @return 鍙傛暟鍊�
+     */
+    public static String getReqParamVal(HttpServletRequest req, String key) {
+        Map<String, String[]> maps = req.getParameterMap();
+        for (Map.Entry<String, String[]> entry : maps.entrySet()) {
+            if (entry.getKey().equalsIgnoreCase(key)) {
+                return null == entry.getValue() || 0 == entry.getValue().length ? null : entry.getValue()[0];
+            }
+        }
+
+        return null;
+    }
+
+    /**
+     * 鑾峰彇璇锋眰鐨勫弬鏁板��
+     *
+     * @param req 璇锋眰
+     * @param key 鍙傛暟鍚�
+     * @return 鍙傛暟鍊�
+     */
+    public static String[] getReqParamVals(HttpServletRequest req, String key) {
+        Map<String, String[]> maps = req.getParameterMap();
+        for (Map.Entry<String, String[]> entry : maps.entrySet()) {
+            if (entry.getKey().equalsIgnoreCase(key)) {
+                return entry.getValue();
+            }
+        }
+
+        return null;
+    }
 }

--
Gitblit v1.9.3