Browse Source

Merge remote-tracking branch 'origin/master'

Reiskuchen 5 years ago
parent
commit
88bcacd7a5

+ 43 - 0
fhKeeper/formulahousekeeper/management-platform/src/main/java/com/management/platform/constant/Parameter.java

@@ -0,0 +1,43 @@
+package com.management.platform.constant;
+
+/**
+ * Author: 吴涛涛
+ * Date : 2020 - 01 - 06 11:19
+ * Description:<描述> 参数枚举
+ * Version: 1.0
+ */
+public enum Parameter {
+    //百度文字识别apiKey
+    API_KEY("apiKey", "gtImOYhgcFBzwuT29tB7tM0Z"),
+    //百度文字识别secretKey
+    SECRET_KEY("secretKey", "RipT5kfF3Zqp7S2vTXPlNcMiYcA76jfq");//这个后面必须有分号
+
+    private String code;
+    private String name;
+
+    private Parameter(String code, String name) {
+        this.code = code;
+        this.name = name();
+    }
+
+    public String getCode() {
+        return code;
+    }
+
+    public String getName() {
+        return name;
+    }
+
+    public void setCode(String code) {
+        this.code = code;
+    }
+
+    public void setName(String name) {
+        this.name = name;
+    }
+
+//    public static void main(String[] args) {
+//        System.out.println(Parameter.API_KEY.getName());
+//    }
+
+}

+ 2 - 2
fhKeeper/formulahousekeeper/management-platform/src/main/java/com/management/platform/controller/ImageProcessingController.java

@@ -45,8 +45,8 @@ public class ImageProcessingController {
      * file 上传的图片文件
      */
     @RequestMapping("/saveAndProcessImage")
-    public HttpRespMsg pictureDetectionTask(ScreenshotVO screenshotvo, String processList) {
-        System.out.println(processList);
+    public HttpRespMsg pictureDetectionTask(ScreenshotVO screenshotvo) {
+        System.out.println(screenshotvo.getProcessList());
         return screenshotService.saveAndProcessImage(screenshotvo);
     }
 

+ 1 - 0
fhKeeper/formulahousekeeper/management-platform/src/main/java/com/management/platform/entity/vo/ScreenshotVO.java

@@ -13,4 +13,5 @@ import org.springframework.web.multipart.MultipartFile;
 @Data
 public class ScreenshotVO extends Screenshot {
     private MultipartFile file;
+    private String processList;
 }

+ 14 - 10
fhKeeper/formulahousekeeper/management-platform/src/main/java/com/management/platform/service/impl/ScreenshotServiceImpl.java

@@ -11,6 +11,7 @@ import com.management.platform.mapper.ScreenshotMapper;
 import com.management.platform.service.ScreenshotService;
 import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
 import com.management.platform.util.*;
+import org.apache.log4j.Logger;
 import org.springframework.beans.BeanUtils;
 import org.springframework.beans.factory.annotation.Autowired;
 import org.springframework.beans.factory.annotation.Value;
@@ -29,7 +30,6 @@ import java.util.Set;
  * <p>
  * 服务实现类
  * </p>
- *
  * @author 吴涛涛
  * @since 2020-01-02
  */
@@ -37,6 +37,8 @@ import java.util.Set;
 @Transactional
 public class ScreenshotServiceImpl extends ServiceImpl<ScreenshotMapper, Screenshot> implements ScreenshotService {
 
+    public static Logger log = Logger.getLogger(ScreenshotServiceImpl.class);
+
     @Value(value = "${upload.path}")
     private String path;
 
@@ -61,6 +63,7 @@ public class ScreenshotServiceImpl extends ServiceImpl<ScreenshotMapper, Screens
             accessToken = (String) map.get("access_token");
             redisUtil.setKeyWithExpireTime("accessToken", accessToken, (Long) map.get("expires_in"));
         }
+        log.info("accessToken-->"+accessToken);
         //利用token去检测
 //        DateTimeFormatter dateTimeFormatter = DateTimeFormatter.ofPattern("yyyy-MM-dd");
 //        LocalDateTime l = LocalDateTime.parse("2019-02-03",dateTimeFormatter);
@@ -68,19 +71,20 @@ public class ScreenshotServiceImpl extends ServiceImpl<ScreenshotMapper, Screens
         List<String> textContents = (List<String>) picResultMap.get("wordsList");
         screenshot.setPicContext((String) picResultMap.get("picContent"));
         Set<Object> members = redisUtil.members(Constant.COMMON_SOFTWARE_KEYWORDS);
+        List<String> exeprocessList = ProcessUtil.getExeprocessListfromProcessStr(screenshotvo.getProcessList());
         for (String textContent : textContents) {
             for (Object member : members) {
                 //由于redis里存储的member是一个PicContentKeywords类型的json字符串,所以取出关键字内容比较
                 JSONObject jsonMember = JSON.parseObject((String) member);
-                System.out.println(jsonMember.getString("content"));
-                System.out.println("textContent----->"+textContent);
-                if (textContent.contains(jsonMember.getString("content"))) {
-                    System.out.println("进来了判断=====");
-                    System.out.println("content=====" + jsonMember.getString("content"));
-                    System.out.println("textContent=====" + textContent);
-                    //包含关键字们可以简单认为是在用常用开发软件
-                    //确定图片是哪个类型的图片
-                    screenshot.setPicType(jsonMember.getInteger("type"));
+                if (textContent.toLowerCase().contains(jsonMember.getString("content").toLowerCase())) {
+                    log.info("图片文字中包含了关键词--->"+jsonMember.getString("content"));
+                    log.info("图片文字识别出的类型--->"+jsonMember.getInteger("type"));
+                    //找到对应关键字,确定图片是哪个类型的图片
+                    //结合进程判断
+                    if(exeprocessList.contains(jsonMember.getString("processName").toLowerCase())){
+                        log.info("图片中关键字对应的进程名--->"+jsonMember.getString("processName"));
+                        screenshot.setPicType(jsonMember.getInteger("type"));
+                    }
                 }
             }
         }

+ 88 - 3
fhKeeper/formulahousekeeper/management-platform/src/main/java/com/management/platform/util/ProcessUtil.java

@@ -14,6 +14,50 @@ public class ProcessUtil {
     private static BufferedReader out;
     private static BufferedReader err;
     public static Logger logger = Logger.getLogger(ProcessUtil.class);
+
+    public static List<String> getExeprocessListfromProcessStr(String processStr) {
+//以下为进程字符串示例
+//        String processStr =
+//                "ӳ������                       PID �Ự��              �Ự#       �ڴ�ʹ�� \n" +
+//                        "========================= ======== ================ =========== ============\n" +
+//                        "System Idle Process              0 Services                   0          8 K\n" +
+//                        "System                           4 Services                   0         20 K\n" +
+//                        "Registry                       144 Services                   0     39,108 K\n" +
+//                        "smss.exe                       568 Services                   0        352 K\n" +
+//                        "csrss.exe                      740 Services                   0      2,148 K\n" +
+//                        "wininit.exe                    948 Services                   0      2,420 K\n" +
+//                        "services.exe                  1020 Services                   0      6,776 K\n" +
+//                        "lsass.exe                      124 Services                   0     12,660 K\n" +
+//                        "svchost.exe                    708 Services                   0      1,140 K\n" +
+//                        "fontdrvhost.exe                732 Services                   0        532 K\n" +
+//                        "svchost.exe                    688 Services                   0     29,176 K\n" +
+//                        "WUDFHost.exe                  1028 Services                   0     10,032 K\n" +
+//                        "svchost.exe                   1096 Services                   0     15,176 K\n" +
+//                        "svchost.exe                   1144 Services                   0      5,140 K\n" +
+//                        "WUDFHost.exe                  1328 Services                   0      2,168 K\n" +
+//                        "svchost.exe                   1500 Services                   0      2,432 K\n" +
+//                        "svchost.exe                   1512 Services                   0      6,704 K\n" +
+//                        "svchost.exe                   1576 Services                   0      8,208 K\n" +
+//                        "svchost.exe                   1628 Services                   0      4,608 K\n" +
+//                        "svchost.exe                   1636 Services                   0      5,604 K\n" +
+//                        "svchost.exe                   1648 Services                   0      4,764 K\n" +
+//                        "svchost.exe                   1776 Services                   0      3,488 K\n" +
+//                        "svchost.exe                   1828 Services                   0      1,536 K\n" +
+//                        "svchost.exe                   1840 Services                   0      4,204 K\n" +
+//                        "svchost.exe                   1848 Services";
+        List<String> exeprocessList = new ArrayList<>();
+        String[] list = processStr.toLowerCase().split("k\n");
+        //从第三行开始才是系统的.exe进程
+        for (int i = 3; i < list.length; i++) {
+            // 必须写死,截取长度,因为是固定的
+            exeprocessList.add(list[i].substring(0, 25).trim()); // 进程名
+//            System.out.println(process);
+        }
+        return exeprocessList;
+
+    }
+
+
     public static void testProcess() {
         // 创建系统进程
         try {
@@ -27,7 +71,7 @@ public class ProcessUtil {
 //            System.out.println(err.readLine());
             // 创建集合 存放 进程+pid
             List<String> list = new ArrayList<>();
-            while (out.readLine()!= null) {
+            while (out.readLine() != null) {
                 System.out.println(out.readLine());
                 list.add(out.readLine());
             }
@@ -71,7 +115,48 @@ public class ProcessUtil {
     }
 
     public static void main(String[] args) {
+//        String processStr =
+//                "ӳ������                       PID �Ự��              �Ự#       �ڴ�ʹ�� \n" +
+//                "========================= ======== ================ =========== ============\n" +
+//                "System Idle Process              0 Services                   0          8 K\n" +
+//                "System                           4 Services                   0         20 K\n" +
+//                "Registry                       144 Services                   0     39,108 K\n" +
+//                "smss.exe                       568 Services                   0        352 K\n" +
+//                "csrss.exe                      740 Services                   0      2,148 K\n" +
+//                "wininit.exe                    948 Services                   0      2,420 K\n" +
+//                "services.exe                  1020 Services                   0      6,776 K\n" +
+//                "lsass.exe                      124 Services                   0     12,660 K\n" +
+//                "svchost.exe                    708 Services                   0      1,140 K\n" +
+//                "fontdrvhost.exe                732 Services                   0        532 K\n" +
+//                "svchost.exe                    688 Services                   0     29,176 K\n" +
+//                "WUDFHost.exe                  1028 Services                   0     10,032 K\n" +
+//                "svchost.exe                   1096 Services                   0     15,176 K\n" +
+//                "svchost.exe                   1144 Services                   0      5,140 K\n" +
+//                "WUDFHost.exe                  1328 Services                   0      2,168 K\n" +
+//                "svchost.exe                   1500 Services                   0      2,432 K\n" +
+//                "svchost.exe                   1512 Services                   0      6,704 K\n" +
+//                "svchost.exe                   1576 Services                   0      8,208 K\n" +
+//                "svchost.exe                   1628 Services                   0      4,608 K\n" +
+//                "svchost.exe                   1636 Services                   0      5,604 K\n" +
+//                "svchost.exe                   1648 Services                   0      4,764 K\n" +
+//                "svchost.exe                   1776 Services                   0      3,488 K\n" +
+//                "svchost.exe                   1828 Services                   0      1,536 K\n" +
+//                "svchost.exe                   1840 Services                   0      4,204 K\n" +
+//                "svchost.exe                   1848 Services";
+//        String[] list = processStr.split("K\n");
+//            for (int i = 3; i < list.length; i++) {
+//                // 必须写死,截取长度,因为是固定的
+//                String process = list[i].substring(0, 25).trim(); // 进程名
+//                System.out.println(process);
+//                String pid = list[i].substring(25, 35).trim();    // 进程号
+        // 匹配指定的进程名,若匹配到,则立即杀死
+//                if (process.startsWith("Thunder")) {
+//                    System.out.println("关闭迅雷");
+//                    Runtime.getRuntime().exec("taskkill /F /PID " + pid);
+//                }
+//            }
+
         testProcess();
-    }
 
-}
+    }
+}