hasan преди 3 години
родител
ревизия
df5bbf8e9b

+ 2 - 0
src/main/java/com/szls/nstths/NstthsApplication.java

@@ -3,7 +3,9 @@ package com.szls.nstths;
3 3
 import org.mybatis.spring.annotation.MapperScan;
4 4
 import org.springframework.boot.SpringApplication;
5 5
 import org.springframework.boot.autoconfigure.SpringBootApplication;
6
+import org.springframework.scheduling.annotation.EnableAsync;
6 7
 
8
+@EnableAsync
7 9
 @SpringBootApplication
8 10
 @MapperScan("com.szls.nstths.mapper")
9 11
 public class NstthsApplication {

+ 2 - 4
src/main/java/com/szls/nstths/controller/DataController.java

@@ -29,13 +29,11 @@ public class DataController {
29 29
     @PostMapping("/equipmentTestingEnd")
30 30
     public String equipmentTesting(@RequestBody TeData teData) {
31 31
         logger.info("{}", teData);
32
-        int inum = teDataService.scanTask(teData);
32
+        int inum = teDataService.saveTeData(teData);
33 33
         if (inum < 0) {
34 34
             return "fail";
35 35
         }
36
-        if (inum == 0) { //打点两次完毕 计算体积
37
-            teDataService.calculateVolume(teData.getTaskID());
38
-        }
36
+        teDataService.scanTask(teData);
39 37
         return "success";
40 38
     }
41 39
 

+ 1 - 1
src/main/java/com/szls/nstths/controller/UserController.java

@@ -10,6 +10,7 @@ import org.springframework.web.bind.annotation.RequestParam;
10 10
 import org.springframework.web.bind.annotation.RestController;
11 11
 
12 12
 import java.util.List;
13
+import java.util.concurrent.Callable;
13 14
 
14 15
 @RestController
15 16
 public class UserController {
@@ -30,5 +31,4 @@ public class UserController {
30 31
 
31 32
         return String.format("Hello %s!", name);
32 33
     }
33
-
34 34
 }

+ 2 - 0
src/main/java/com/szls/nstths/entity/TeData.java

@@ -25,4 +25,6 @@ public class TeData {
25 25
     private Date etime;
26 26
     private String rotationxy;
27 27
 
28
+    @TableField(exist = false)
29
+    private Date currenttime;
28 30
 }

+ 4 - 3
src/main/java/com/szls/nstths/service/TeDataService.java

@@ -24,8 +24,9 @@ public interface TeDataService {
24 24
      *
25 25
      * @param high
26 26
      * @param diameter
27
+     * @return 数据库影响条数
27 28
      */
28
-    void scanTask(double diameter, double high);
29
+    int scanTask(double diameter, double high);
29 30
 
30 31
     /**
31 32
      * 第二次待打点
@@ -33,9 +34,9 @@ public interface TeDataService {
33 34
      * @param teData
34 35
      * @return 数据库影响条数
35 36
      */
36
-    int scanTask(TeData teData);
37
-
37
+    void scanTask(TeData teData);
38 38
 
39
+    int  saveTeData(TeData teData);
39 40
     /**
40 41
      * 计算体积
41 42
      *

+ 3 - 3
src/main/java/com/szls/nstths/service/impl/Algorithm.java

@@ -86,7 +86,7 @@ public class Algorithm {
86 86
                 sb.append(Math.round(level_angle));
87 87
                 sb.append(",");
88 88
                 sb.append(Math.round(vertical_angle));
89
-                sb.append("-");
89
+                sb.append(";");
90 90
                 // sb.append("\n");
91 91
             }
92 92
         }
@@ -103,7 +103,7 @@ public class Algorithm {
103 103
         // sb.append("\n");
104 104
         //System.out.println(Math.round(level_step)+","+Math.round(vertical_step)+"");
105 105
         //System.out.println(sb);
106
-        System.out.println(sb);
106
+        //System.out.println(sb);
107 107
         return sb.toString();
108 108
 
109 109
     }
@@ -132,7 +132,7 @@ public class Algorithm {
132 132
 
133 133
 
134 134
         //  "18,7,17.88 - 19,6,28.88 - 17,4,39.88"  水平角度,垂直角度,返回距离 -
135
-        String[] split = rotationxy.split("-");
135
+        String[] split = rotationxy.split(";");
136 136
         for (int i = 0; i < split.length; i++) {
137 137
             String[] split1 = split[i].split(",");
138 138
             levelAngle = Double.parseDouble(split1[0]);

+ 42 - 14
src/main/java/com/szls/nstths/service/impl/TeDataServiceImpl.java

@@ -1,6 +1,7 @@
1 1
 package com.szls.nstths.service.impl;
2 2
 
3 3
 import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
4
+import com.szls.nstths.controller.DataController;
4 5
 import com.szls.nstths.entity.ReMsg;
5 6
 import com.szls.nstths.entity.STask;
6 7
 import com.szls.nstths.entity.TeData;
@@ -8,10 +9,14 @@ import com.szls.nstths.mapper.ReMsgMapper;
8 9
 import com.szls.nstths.mapper.STaskMapper;
9 10
 import com.szls.nstths.mapper.TeDataMapper;
10 11
 import com.szls.nstths.service.TeDataService;
12
+import org.slf4j.Logger;
13
+import org.slf4j.LoggerFactory;
11 14
 import org.springframework.beans.factory.annotation.Autowired;
15
+import org.springframework.scheduling.annotation.Async;
12 16
 import org.springframework.stereotype.Service;
13 17
 import org.springframework.web.client.RestTemplate;
14 18
 
19
+import java.beans.Transient;
15 20
 import java.util.ArrayList;
16 21
 import java.util.Date;
17 22
 import java.util.List;
@@ -19,6 +24,8 @@ import java.util.List;
19 24
 @Service(value = "teDataService")
20 25
 public class TeDataServiceImpl implements TeDataService {
21 26
 
27
+    private static final Logger logger = LoggerFactory.getLogger(TeDataServiceImpl.class);
28
+
22 29
     static String base_url = "http://local.wxlxit.com:61001/";
23 30
     static boolean flag = true;
24 31
     static double diameter = 0; //直径
@@ -57,11 +64,9 @@ public class TeDataServiceImpl implements TeDataService {
57 64
      * 2. equipmentTestingStart
58 65
      * 3. equipmentTestingEnd
59 66
      */
60
-
61 67
     @Override
62
-    public void scanTask(double diameter, double high) {
63
-
64
-
68
+    public int scanTask(double diameter, double high) {
69
+        logger.info("scanTask {},{}",diameter,high);
65 70
         STask task = new STask();
66 71
         Date date = new Date();
67 72
         task.setCtime(date);
@@ -76,19 +81,28 @@ public class TeDataServiceImpl implements TeDataService {
76 81
         //todo 第一次待打点
77 82
         String rotationxy = Algorithm.getAveragePosition(diameter, high);
78 83
         teData.setRotationxy(rotationxy);
79
-        teDataMapper.insert(teData);
84
+        int inum = teDataMapper.insert(teData);
85
+
86
+        logger.info("scanTask sTaskMapper teDataMapper {},{}",task,teData);
80 87
 
81 88
         postHelper(teData);
82 89
         //equipmentTestingEnd
83 90
         flag = true;
84
-    }
85 91
 
92
+        return inum;
93
+    }
94
+    @Async
86 95
     @Override
87
-    public int scanTask(TeData teData) {
96
+    public void scanTask(TeData teData) {
97
+        try {
98
+            Thread.sleep(1000);
99
+        } catch (InterruptedException e) {
100
+            e.printStackTrace();
101
+        }
88 102
         //只运行 发送一次。
89 103
         if (flag) {
90
-            teData.getEquipmentID();
91
-            teData.getTaskID();
104
+            //teData.getEquipmentID();
105
+            //teData.getTaskID();
92 106
 
93 107
             //todo 第二次待打点
94 108
 
@@ -97,28 +111,42 @@ public class TeDataServiceImpl implements TeDataService {
97 111
             //打点
98 112
             String rotationxy = Algorithm.getAveragePosition(diameter, zHeight);
99 113
             teData.setRotationxy(rotationxy);
100
-            int inum = teDataMapper.insert(teData);
101 114
 
102 115
             postHelper(teData);
103
-            flag = false;
104 116
 
105
-            return inum;
117
+            flag = false;
118
+        } else { //打点两次完毕 计算体积
119
+            this.calculateVolume(teData.getTaskID());
106 120
         }
107
-        return 0;
121
+
122
+    }
123
+
124
+    @Override
125
+    public int saveTeData(TeData teData) {
126
+        int inum = teDataMapper.insert(teData);
127
+        return inum;
108 128
     }
109 129
 
110 130
     public ReMsg postHelper(TeData teData) {
131
+
132
+        logger.info("in ...... postHelper teData{}",teData);
133
+
111 134
         RestTemplate restTemplate = new RestTemplate();
135
+        teData.setCurrenttime(new Date());
112 136
         ReMsg reMsg1 = restTemplate.postForObject(base_url + "equipmentTestingIsReady", teData, ReMsg.class);
113 137
         //reMsgMapper.insert(reMsg1);
138
+        logger.info("postHelper reMsg1 {}",reMsg1);
114 139
 
115 140
         if (reMsg1 != null) {
116 141
             if ("0".equals(reMsg1.getCode())) {
117 142
                 ReMsg reMsg2 = restTemplate.postForObject(base_url + "equipmentTestingStart", teData, ReMsg.class);
143
+                logger.info("postHelper reMsg2 {}",reMsg2);
118 144
                 reMsgMapper.insert(reMsg2);
119 145
                 return reMsg2;
120 146
             }
121 147
         }
148
+        logger.info("postHelper post task_ {}",teData);
149
+
122 150
         return null;
123 151
     }
124 152
 
@@ -134,7 +162,7 @@ public class TeDataServiceImpl implements TeDataService {
134 162
         queryWrapper.eq("taskID", taskID);
135 163
         teDataList = teDataMapper.selectList(queryWrapper);
136 164
         for (TeData teData : teDataList) {
137
-            split = teData.getRotationxy().split("-");
165
+            split = teData.getRotationxy().split(";");
138 166
             for (int i = 0; i < split.length; i++) {
139 167
                 String[] split1 = split[i].split(",");
140 168
                 //split1[2]  是返回的距离

+ 4 - 4
src/main/resources/application.yml

@@ -6,13 +6,13 @@ spring:
6 6
     driver-class-name: com.mysql.cj.jdbc.Driver
7 7
     username: root
8 8
     password: 123456
9
-    url: jdbc:mysql://36.134.100.155:3306/nstths?useSSL=false&useUnicode=true&characterEncoding=utf-8&serverTimezone=UTC
10
-    #url: jdbc:mysql://192.168.1.123:3306/nstths?useSSL=false&useUnicode=true&characterEncoding=utf-8&serverTimezone=UTC
9
+    #url: jdbc:mysql://36.134.100.155:3306/nstths?useSSL=false&useUnicode=true&characterEncoding=utf-8&serverTimezone=GMT
10
+    url: jdbc:mysql://192.168.1.123:3306/nstths?useSSL=false&useUnicode=true&characterEncoding=utf-8&serverTimezone=GMT
11 11
     hikari:
12 12
       minimum-idle: 5
13
-      maximum-pool-size: 10
13
+      maximum-pool-size: 20
14 14
       idle-timeout: 30000
15
-      max-lifetime: 0
15
+      max-lifetime: 1800000
16 16
       connection-timeout: 60000
17 17
       validation-timeout: 3000
18 18
       connection-test-query: select 1

+ 17 - 0
src/main/resources/static/nstths.sh

@@ -0,0 +1,17 @@
1
+port=7077
2
+#根据端口号查询对应的pid
3
+pid=$(netstat -nlp | grep :$port | awk '{print $7}' | awk -F"/" '{ print $1 }');
4
+
5
+#杀掉对应的进程,如果pid不存在,则不执行
6
+if [  -n  "$pid"  ];  then
7
+    kill  -9  $pid;
8
+fi
9
+
10
+source /etc/profile
11
+nohup java -jar /home/nstths/nstths-0.0.1-SNAPSHOT.jar >/home/nstths/catalina.out  2>&1 &
12
+
13
+sleep 20
14
+
15
+tail -f /home/nstths/catalina.out
16
+
17
+exit 0