李天标 5 rokov pred
rodič
commit
e45decf33d

+ 10 - 0
app-api/pom.xml

@@ -28,6 +28,16 @@
             <artifactId>app-service</artifactId>
             <version>1.0-SNAPSHOT</version>
         </dependency>
+        <dependency>
+            <groupId>org.apache.httpcomponents</groupId>
+            <artifactId>httpclient</artifactId>
+            <version>4.4</version>
+        </dependency>
+        <dependency>
+            <groupId>org.apache.httpcomponents</groupId>
+            <artifactId>httpmime</artifactId>
+            <version>4.4</version>
+        </dependency>
     </dependencies>
 
 

+ 15 - 0
app-api/src/main/java/com/hboxs/control/api/equipment/AlarmRecordIndexController.java

@@ -18,6 +18,21 @@ import org.springframework.web.bind.annotation.RequestMapping;
 import org.springframework.web.bind.annotation.RequestMethod;
 import org.springframework.web.bind.annotation.ResponseBody;
 
+
+import java.io.File;
+import java.io.FileOutputStream;
+import java.io.IOException;
+import java.io.InputStream;
+import java.util.List;
+
+import javax.servlet.ServletException;
+import javax.servlet.http.HttpServletRequest;
+import javax.servlet.http.HttpServletResponse;
+
+import org.apache.commons.fileupload.FileItem;
+import org.apache.commons.fileupload.disk.DiskFileItemFactory;
+import org.apache.commons.fileupload.servlet.ServletFileUpload;
+
 import javax.annotation.Resource;
 
 @Controller("appAlarmRecordController")

+ 153 - 5
app-api/src/main/java/com/hboxs/control/api/equipment/IndexController.java

@@ -1,6 +1,7 @@
 package com.hboxs.control.api.equipment;
 
 import com.alibaba.fastjson.JSONArray;
+import com.alibaba.fastjson.JSONObject;
 import com.hboxs.ViewObject.CommonParamVo;
 import com.hboxs.ViewObject.EquipmentVo;
 import com.hboxs.ViewObject.ProductVo;
@@ -14,16 +15,16 @@ import com.hboxs.entity.Equipment;
 import com.hboxs.entity.EquipmentApply;
 import com.hboxs.entity.Proportion;
 import com.hboxs.service.*;
+import org.apache.commons.io.IOUtils;
 import org.apache.commons.lang.StringUtils;
 import org.springframework.stereotype.Controller;
 import org.springframework.web.bind.annotation.*;
-
 import javax.annotation.Resource;
+import javax.servlet.http.HttpServletRequest;
+import javax.servlet.http.HttpServletResponse;
+import java.io.*;
 import java.math.BigDecimal;
-import java.util.ArrayList;
-import java.util.Date;
-import java.util.HashSet;
-import java.util.List;
+import java.util.*;
 
 @Controller("appEquipmentIndexController")
 @RequestMapping("/api/app_equipment/index")
@@ -344,6 +345,153 @@ public class IndexController extends BaseController {
     }
 
     /**
+     * 日志上传
+     */
+    @RequestMapping(value = "/sendLog", method = RequestMethod.POST)
+    @ResponseBody
+    public String uploadFile(HttpServletRequest request,HttpServletResponse response, String fileName) throws Exception{
+//        String fileName = request.getParameter("fileName");
+//        log.info("filename:"+fileName);
+//        String fileName ="shafei.xls";
+//        file1.length();
+//        String name = request.getParameter("inputName");
+        String fileFullPath = "/home/hboxs/log/" + fileName+".txt";
+//        String fileFullPath = "/root/uploadfile/apache-tomcat-8.5.42/" + fileName;
+
+        InputStream input = null;
+        FileOutputStream fos = null;
+        try {
+            input = request.getInputStream();
+            File file = new File("/home/hboxs/log/");
+            if(!file.exists()){
+                file.mkdirs();
+            }
+            fos = new FileOutputStream(fileFullPath);
+            int size = 0;
+            byte[] buffer = new byte[1024];
+            while ((size = input.read(buffer,0,1024)) != -1) {
+                fos.write(buffer, 0, size);
+            }
+
+            //响应信息 json字符串格式
+            Map<String,Object> responseMap = new HashMap<String,Object>();
+            responseMap.put("flag", true);
+
+            //生成响应的json字符串
+            String jsonResponse = JSONObject.toJSONString(responseMap);
+            sendResponse(jsonResponse,response);
+        } catch (IOException e) {
+            //响应信息 json字符串格式
+            Map<String,Object> responseMap = new HashMap<String,Object>();
+            responseMap.put("flag", false);
+            responseMap.put("errorMsg", e.getMessage());
+            String jsonResponse = JSONObject.toJSONString(responseMap);
+            sendResponse(jsonResponse,response);
+        } finally{
+            if(input != null){
+                input.close();
+            }
+            if(fos != null){
+                fos.close();
+            }
+        }
+
+        return null;
+    }
+
+    /**
+     * 返回响应
+     *
+     * @throws Exception
+     */
+    private void sendResponse(String responseString,HttpServletResponse response) throws Exception {
+        response.setContentType("application/json;charset=UTF-8");
+        PrintWriter pw = null;
+        try {
+            pw = response.getWriter();
+            pw.write(responseString);
+            pw.flush();
+        } finally {
+            IOUtils.closeQuietly(pw);
+        }
+    }
+//    public JsonMessage sendLog( HttpServletRequest request) throws Exception {
+//        //得到上传文件的保存目录,将上传的文件存放于WEB-INF目录下,不允许外界直接访问,保证上传文件的安全
+//        String savePath = "E:/log";
+//        File file = new File(savePath);
+//        //判断上传文件的保存目录是否存在
+//        if (!file.exists() && !file.isDirectory()) {
+////            System.out.println(savePath+"目录不存在,需要创建");
+//            //创建目录
+//            file.mkdir();
+//        }
+//        //消息提示
+//        String message = "";
+//        try{
+//            //使用Apache文件上传组件处理文件上传步骤:
+//            //1、创建一个DiskFileItemFactory工厂
+//            DiskFileItemFactory factory = new DiskFileItemFactory();
+//            //2、创建一个文件上传解析器
+//            ServletFileUpload upload = new ServletFileUpload(factory);
+//            //解决上传文件名的中文乱码
+//            upload.setHeaderEncoding("UTF-8");
+//            //3、判断提交上来的数据是否是上传表单的数据
+//            if(!ServletFileUpload.isMultipartContent(request)){
+//                //按照传统方式获取数据
+//                System.out.println("没有文件上传");
+//                return JsonMessage.success("没有文件上传");
+////                return "index.html";
+//            }
+//            //4、使用ServletFileUpload解析器解析上传数据,解析结果返回的是一个List<FileItem>集合,每一个FileItem对应一个Form表单的输入项
+//            List<FileItem> list = upload.parseRequest(request);
+//            for(FileItem item : list){
+//                //如果fileitem中封装的是普通输入项的数据
+//                if(item.isFormField()){
+//                    String name = item.getFieldName();
+//                    //解决普通输入项的数据的中文乱码问题
+//                    String value = item.getString("UTF-8");
+//                    //value = new String(value.getBytes("iso8859-1"),"UTF-8");
+//                    System.out.println(name + "=" + value);
+//                }else{//如果fileitem中封装的是上传文件
+//                    //得到上传的文件名称,
+//                    String filename = item.getName();
+//                    System.out.println(filename);
+//                    if(filename==null || filename.trim().equals("")){
+//                        continue;
+//                    }
+//                    //注意:不同的浏览器提交的文件名是不一样的,有些浏览器提交上来的文件名是带有路径的,如:  c:\a\b\1.txt,而有些只是单纯的文件名,如:1.txt
+//                    //处理获取到的上传文件的文件名的路径部分,只保留文件名部分
+//                    filename = filename.substring(filename.lastIndexOf("\\")+1);
+//                    //获取item中的上传文件的输入流
+//                    InputStream in = item.getInputStream();
+//                    //创建一个文件输出流
+//                    FileOutputStream out = new FileOutputStream(savePath + "\\" + filename);
+//                    //创建一个缓冲区
+//                    byte buffer[] = new byte[1024];
+//                    //判断输入流中的数据是否已经读完的标识
+//                    int len = 0;
+//                    //循环将输入流读入到缓冲区当中,(len=in.read(buffer))>0就表示in里面还有数据
+//                    while((len=in.read(buffer))>0){
+//                        //使用FileOutputStream输出流将缓冲区的数据写入到指定的目录(savePath + "\\" + filename)当中
+//                        out.write(buffer, 0, len);
+//                    }
+//                    //关闭输入流
+//                    in.close();
+//                    //关闭输出流
+//                    out.close();
+//                    //删除处理文件上传时生成的临时文件
+//                    item.delete();
+//                    message = "文件上传成功!";
+//                }
+//            }
+//        }catch (Exception e) {
+//            message= "文件上传失败!";
+//            e.printStackTrace();
+//        }
+//        return JsonMessage.success("文件上传成功");
+//    }
+
+    /**
      * 脱离系统
      *
      * @param clientId

+ 20 - 0
app-backend-web/src/main/java/com/hboxs/control/admin/EquipmentController.java

@@ -315,6 +315,26 @@ public class EquipmentController extends BaseController {
         return JsonMessage.success("开门成功");
     }
     /**
+     * 上传日志
+     *
+     * @param clientId
+     * @return
+     */
+    @RequestMapping(value = "/sendLog", method = RequestMethod.POST)
+    @ResponseBody
+    public JsonMessage sendLog(String clientId,String day) {
+        if(day.length()!=8){
+            return JsonMessage.success("日期格式错误");
+        }
+        Equipment equipment = equipmentService.findByClientId(clientId);
+        if (equipment == null) {
+            return JsonMessage.error("该设备不存在");
+        }
+        String kind = day+"-"+clientId;
+        PushUtils.push(equipment.getGtClientId(), "", "", PushUtils.buildJson("log", kind).toString());
+        return JsonMessage.success("发送成功");
+    }
+    /**
      * 修改设备警报发送信息电话
      *
      * @param id

+ 26 - 1
app-backend-web/src/main/webapp/WEB-INF/template/admin/equipment/edit.ftl

@@ -168,6 +168,17 @@
                     <button type="button" id="openDoor" >远程开门</button>
                 </td>
             </tr>
+            [#if type=="管理员"]
+            <tr>
+                <th>
+                    <span class="requiredField"></span>获取日志:
+                </th>
+                <td>
+                    <input type="text" class="text" maxlength="20" id="day" placeholder="20200101" value=""/>
+                    &nbsp &nbsp <button type="button" id="rizhi" >上传</button>
+                </td>
+            </tr>
+            [/#if]
             <tr>
                 <th>
                     <span class="requiredField">*</span>支付方式:
@@ -1147,7 +1158,7 @@
         })
     });
 
-    // 脱离系统管理id
+    // 远程开门
     $('#openDoor').click(function(){
         var id=	document.getElementById("aaaa").value;
         $.ajax({
@@ -1158,6 +1169,20 @@
             }
         })
     });
+    // 上传日志
+    $('#rizhi').click(function(){
+        var id=	document.getElementById("aaaa").value;
+        var day = document.getElementById("day").value;
+        $.ajax({
+            url:"/asl-admin/equipment/sendLog.htm?clientId="+id+"&day="+day,
+            type:"post",
+            success: function(data){
+                debugger;
+                layer.msg(data.data);
+            }
+        })
+    });
+
     var h = '<div id="container" style="width: 1200px;height: 650px"></div>';
     $('.location').click(function () {