Commit e914df27f3b207f095111fd4b9f22b3074656fa3
Exists in
master
Merge remote-tracking branch 'origin/master'
Showing
43 changed files
with
1206 additions
and
230 deletions
Show diff stats
cloud/dahua/src/main/java/com/example/dahua/DahuaApplication.java
@@ -17,6 +17,7 @@ import org.springframework.cloud.client.discovery.EnableDiscoveryClient; | @@ -17,6 +17,7 @@ import org.springframework.cloud.client.discovery.EnableDiscoveryClient; | ||
17 | import org.springframework.context.annotation.Bean; | 17 | import org.springframework.context.annotation.Bean; |
18 | import org.springframework.context.annotation.Configuration; | 18 | import org.springframework.context.annotation.Configuration; |
19 | import org.springframework.scheduling.annotation.EnableAsync; | 19 | import org.springframework.scheduling.annotation.EnableAsync; |
20 | +import org.springframework.scheduling.annotation.EnableScheduling; | ||
20 | import org.springframework.scheduling.concurrent.ThreadPoolTaskExecutor; | 21 | import org.springframework.scheduling.concurrent.ThreadPoolTaskExecutor; |
21 | import springfox.documentation.builders.PathSelectors; | 22 | import springfox.documentation.builders.PathSelectors; |
22 | import springfox.documentation.builders.RequestHandlerSelectors; | 23 | import springfox.documentation.builders.RequestHandlerSelectors; |
@@ -37,6 +38,7 @@ import java.util.concurrent.TimeUnit; | @@ -37,6 +38,7 @@ import java.util.concurrent.TimeUnit; | ||
37 | @SpringBootApplication | 38 | @SpringBootApplication |
38 | @MapperScan("com.example.dahua.dao") | 39 | @MapperScan("com.example.dahua.dao") |
39 | @EnableDiscoveryClient | 40 | @EnableDiscoveryClient |
41 | +@EnableScheduling | ||
40 | public class DahuaApplication { | 42 | public class DahuaApplication { |
41 | 43 | ||
42 | public static void main(String[] args) { | 44 | public static void main(String[] args) { |
cloud/dahua/src/main/java/com/example/dahua/Gate/CardManegerDialog.java
@@ -245,7 +245,7 @@ public class CardManegerDialog extends JDialog{ | @@ -245,7 +245,7 @@ public class CardManegerDialog extends JDialog{ | ||
245 | String userId = v.get(4).toString(); // 用户ID | 245 | String userId = v.get(4).toString(); // 用户ID |
246 | 246 | ||
247 | // 删除人脸和卡信息 | 247 | // 删除人脸和卡信息 |
248 | - if(!GateModule.deleteFaceInfo(userId) || | 248 | + if( |
249 | !GateModule.deleteCard(Integer.parseInt(recordNo))) { | 249 | !GateModule.deleteCard(Integer.parseInt(recordNo))) { |
250 | JOptionPane.showMessageDialog(null, ToolKits.getErrorCodeShow(), Res.string().getErrorMessage(), JOptionPane.ERROR_MESSAGE); | 250 | JOptionPane.showMessageDialog(null, ToolKits.getErrorCodeShow(), Res.string().getErrorMessage(), JOptionPane.ERROR_MESSAGE); |
251 | } else { | 251 | } else { |
@@ -262,8 +262,7 @@ public class CardManegerDialog extends JDialog{ | @@ -262,8 +262,7 @@ public class CardManegerDialog extends JDialog{ | ||
262 | int result = JOptionPane.showConfirmDialog(null, Res.string().getWantClearAllInfo(), Res.string().getPromptMessage(), JOptionPane.YES_NO_OPTION); | 262 | int result = JOptionPane.showConfirmDialog(null, Res.string().getWantClearAllInfo(), Res.string().getPromptMessage(), JOptionPane.YES_NO_OPTION); |
263 | if(result == 0) { // 0-是, 1-否 | 263 | if(result == 0) { // 0-是, 1-否 |
264 | // 清空人脸和卡信息 | 264 | // 清空人脸和卡信息 |
265 | - if(!GateModule.clearFaceInfo() || | ||
266 | - !GateModule.clearCard()) { | 265 | + if(true) { |
267 | JOptionPane.showMessageDialog(null, ToolKits.getErrorCodeShow(), Res.string().getErrorMessage(), JOptionPane.ERROR_MESSAGE); | 266 | JOptionPane.showMessageDialog(null, ToolKits.getErrorCodeShow(), Res.string().getErrorMessage(), JOptionPane.ERROR_MESSAGE); |
268 | } else { | 267 | } else { |
269 | JOptionPane.showMessageDialog(null, Res.string().getSucceed(), Res.string().getPromptMessage(), JOptionPane.INFORMATION_MESSAGE); | 268 | JOptionPane.showMessageDialog(null, Res.string().getSucceed(), Res.string().getPromptMessage(), JOptionPane.INFORMATION_MESSAGE); |
cloud/dahua/src/main/java/com/example/dahua/MyTask.java
@@ -71,9 +71,9 @@ public class MyTask implements ApplicationRunner { | @@ -71,9 +71,9 @@ public class MyTask implements ApplicationRunner { | ||
71 | public void run(ApplicationArguments args) throws Exception { | 71 | public void run(ApplicationArguments args) throws Exception { |
72 | // 121.40.109.21 | 72 | // 121.40.109.21 |
73 | 73 | ||
74 | -// LoginModule.init(disConnect, haveReConnect); // 打开工程,初始化 | 74 | + LoginModule.init(disConnect, haveReConnect); // 打开工程,初始化 |
75 | 75 | ||
76 | -// autoRegister();//自注册 | 76 | + autoRegister();//自注册 |
77 | 77 | ||
78 | // System.out.println(" sendRecordDao:"+sendRecordDao.getSenSuccess()); | 78 | // System.out.println(" sendRecordDao:"+sendRecordDao.getSenSuccess()); |
79 | } | 79 | } |
cloud/dahua/src/main/java/com/example/dahua/Test.java
1 | package com.example.dahua; | 1 | package com.example.dahua; |
2 | 2 | ||
3 | 3 | ||
4 | +import org.springframework.http.ResponseEntity; | ||
5 | +import org.springframework.scheduling.annotation.Async; | ||
6 | +import org.springframework.web.client.RestTemplate; | ||
7 | + | ||
8 | +import java.text.SimpleDateFormat; | ||
9 | +import java.util.Date; | ||
10 | +import java.util.Random; | ||
11 | +import java.util.UUID; | ||
12 | + | ||
4 | public class Test { | 13 | public class Test { |
5 | 14 | ||
6 | public static void main(String[] args) { | 15 | public static void main(String[] args) { |
7 | 16 | ||
8 | 17 | ||
18 | + Test test = new Test(); | ||
19 | + | ||
20 | + | ||
9 | } | 21 | } |
10 | 22 | ||
11 | 23 |
cloud/dahua/src/main/java/com/example/dahua/async/MyScheduledTask.java
@@ -30,12 +30,9 @@ import org.springframework.web.client.RestTemplate; | @@ -30,12 +30,9 @@ import org.springframework.web.client.RestTemplate; | ||
30 | import java.io.*; | 30 | import java.io.*; |
31 | import java.text.ParseException; | 31 | import java.text.ParseException; |
32 | import java.text.SimpleDateFormat; | 32 | import java.text.SimpleDateFormat; |
33 | -import java.util.ArrayList; | ||
34 | -import java.util.Date; | ||
35 | -import java.util.List; | 33 | +import java.util.*; |
36 | 34 | ||
37 | @Component | 35 | @Component |
38 | -@EnableScheduling | ||
39 | public class MyScheduledTask { | 36 | public class MyScheduledTask { |
40 | 37 | ||
41 | 38 | ||
@@ -66,8 +63,9 @@ public class MyScheduledTask { | @@ -66,8 +63,9 @@ public class MyScheduledTask { | ||
66 | 63 | ||
67 | private String imgFilPath = "C:\\EhomePicServer";//抓拍图片路径 | 64 | private String imgFilPath = "C:\\EhomePicServer";//抓拍图片路径 |
68 | 65 | ||
69 | - @Scheduled(fixedRate = 5000) | 66 | +// @Scheduled(fixedRate = 5000) |
70 | private void sendErrorInfo() throws InterruptedException { | 67 | private void sendErrorInfo() throws InterruptedException { |
68 | + System.out.println("---------------------------sendErrorInfo:"); | ||
71 | // System.out.println("定时任务执行中...."); | 69 | // System.out.println("定时任务执行中...."); |
72 | deleteFaceImg(); | 70 | deleteFaceImg(); |
73 | 71 | ||
@@ -78,26 +76,6 @@ public class MyScheduledTask { | @@ -78,26 +76,6 @@ public class MyScheduledTask { | ||
78 | SimpleDateFormat simpleDateFormat = new SimpleDateFormat("HH"); | 76 | SimpleDateFormat simpleDateFormat = new SimpleDateFormat("HH"); |
79 | int hour = Integer.parseInt(simpleDateFormat.format(new Date())); | 77 | int hour = Integer.parseInt(simpleDateFormat.format(new Date())); |
80 | 78 | ||
81 | - /*if (hour == 7 && !isCloseYT) { | ||
82 | - isCloseYT = true; | ||
83 | - close(31, 97); | ||
84 | - } | ||
85 | - | ||
86 | - if (hour == 17 && isCloseYT) { | ||
87 | - isCloseYT = false; | ||
88 | - close(30, 97); | ||
89 | - }*/ | ||
90 | - | ||
91 | - /* if (hour == 6 && !isClose) { | ||
92 | - isClose = true; | ||
93 | - close(31, 479);//打开 | ||
94 | - } | ||
95 | - | ||
96 | - if (hour == 22 && isClose) { | ||
97 | - isClose = false; | ||
98 | - close(30, 479);//关闭 | ||
99 | - }*/ | ||
100 | - | ||
101 | if (hour >= 9 && hour < 11) { | 79 | if (hour >= 9 && hour < 11) { |
102 | dealData(); | 80 | dealData(); |
103 | } else if (hour >= 13 && hour < 14) { | 81 | } else if (hour >= 13 && hour < 14) { |
@@ -106,7 +84,7 @@ public class MyScheduledTask { | @@ -106,7 +84,7 @@ public class MyScheduledTask { | ||
106 | dealData(); | 84 | dealData(); |
107 | } | 85 | } |
108 | 86 | ||
109 | - if (myTasks.isHasNewDevice)myTasks.reloadPic(); | 87 | + if (myTasks.isHasNewDevice) myTasks.reloadPic(); |
110 | 88 | ||
111 | } | 89 | } |
112 | 90 | ||
@@ -122,59 +100,43 @@ public class MyScheduledTask { | @@ -122,59 +100,43 @@ public class MyScheduledTask { | ||
122 | File file = new File(imgFilPath); | 100 | File file = new File(imgFilPath); |
123 | File[] files = file.listFiles(); | 101 | File[] files = file.listFiles(); |
124 | Date currentDate = new Date(); | 102 | Date currentDate = new Date(); |
125 | - if (null!=files) | ||
126 | - for (int i = 0; i < files.length; i++) { | ||
127 | - File imgFile = files[i]; | ||
128 | - String name = imgFile.getName().split("\\.")[0]; | ||
129 | - String time = name.substring(32); | ||
130 | - if(time.length()>8&&!time.contains("-"))time = time.substring(0,8); | ||
131 | - | ||
132 | - SimpleDateFormat simpleDateFormat = new SimpleDateFormat("yyyy-MM-dd"); | ||
133 | - SimpleDateFormat simpleDateFormat1 = new SimpleDateFormat("yyyyMMdd"); | ||
134 | - try { | ||
135 | - Date date1 = null; | ||
136 | - if (time.contains("-"))date1 = simpleDateFormat.parse(time); | ||
137 | - else date1 = simpleDateFormat1.parse(time); | ||
138 | - | ||
139 | - long timecj = currentDate.getTime() - date1.getTime(); | ||
140 | - if (timecj > (7 * 24 * 60 * 60 * 1000)) {//大于七天的删除 | ||
141 | - System.out.println("imgFile:" + imgFile.getAbsolutePath() + imgFile.exists()); | 103 | + if (null != files) |
104 | + for (int i = 0; i < files.length; i++) { | ||
105 | + File imgFile = files[i]; | ||
106 | + String name = imgFile.getName().split("\\.")[0]; | ||
107 | + String time = name.substring(32); | ||
108 | + if (time.length() > 8 && !time.contains("-")) time = time.substring(0, 8); | ||
109 | + | ||
110 | + SimpleDateFormat simpleDateFormat = new SimpleDateFormat("yyyy-MM-dd"); | ||
111 | + SimpleDateFormat simpleDateFormat1 = new SimpleDateFormat("yyyyMMdd"); | ||
112 | + try { | ||
113 | + Date date1 = null; | ||
114 | + if (time.contains("-")) date1 = simpleDateFormat.parse(time); | ||
115 | + else date1 = simpleDateFormat1.parse(time); | ||
116 | + | ||
117 | + long timecj = currentDate.getTime() - date1.getTime(); | ||
118 | + if (timecj > (7 * 24 * 60 * 60 * 1000)) {//大于七天的删除 | ||
119 | + System.out.println("imgFile:" + imgFile.getAbsolutePath() + imgFile.exists()); | ||
120 | + imgFile.delete(); | ||
121 | + } | ||
122 | + | ||
123 | + } catch (ParseException e) { | ||
142 | imgFile.delete(); | 124 | imgFile.delete(); |
125 | +// e.printStackTrace(); | ||
143 | } | 126 | } |
144 | 127 | ||
145 | - } catch (ParseException e) { | ||
146 | - imgFile.delete(); | ||
147 | -// e.printStackTrace(); | ||
148 | } | 128 | } |
149 | 129 | ||
150 | - } | ||
151 | - | ||
152 | } | 130 | } |
153 | 131 | ||
154 | } | 132 | } |
155 | 133 | ||
156 | - private void close(int cmd, int schoolId) { | ||
157 | - SimpleDateFormat simpleDateFormat = new SimpleDateFormat("yyyy-MM-dd HH:mm:ss"); | ||
158 | - String date = simpleDateFormat.format(new Date()); | ||
159 | - FileUtils.getInstance().writeLogs(date + " " + cmd, FileUtils.sendOrder); | ||
160 | - MqttManager mqttManager = new MqttManager(); | 134 | + private synchronized void dealData() { |
161 | 135 | ||
162 | - mqttManager.init(); | ||
163 | - | ||
164 | - List<String> stringList = userDao.getAllDecWithSch(schoolId); | ||
165 | -// System.out.println("stringList:" + stringList); | ||
166 | - for (int i = 0; i < stringList.size(); i++) { | ||
167 | - String devId = stringList.get(i); | ||
168 | - mqttManager.sendMq(devId, cmd); | ||
169 | - } | ||
170 | - } | ||
171 | - | ||
172 | - private synchronized void dealData(){ | ||
173 | - | ||
174 | - String ip = new Utils().getHostAddress(); | ||
175 | - System.out.println("ip:"+ip); | ||
176 | - if (ip.startsWith("192")||ip.contains("172.16.247.64")) | ||
177 | - return; | 136 | + String ip = new Utils().getHostAddress(); |
137 | + System.out.println("ip:" + ip); | ||
138 | + if (ip.startsWith("192") || ip.contains("172.16.247.64")) | ||
139 | + return; | ||
178 | 140 | ||
179 | /** | 141 | /** |
180 | * 微耕 | 142 | * 微耕 |
@@ -203,5 +165,95 @@ public class MyScheduledTask { | @@ -203,5 +165,95 @@ public class MyScheduledTask { | ||
203 | 165 | ||
204 | } | 166 | } |
205 | 167 | ||
168 | + boolean isSendMQ = false; | ||
169 | + | ||
170 | + boolean isInitMQ = false; | ||
171 | + | ||
172 | + int readLineNum = -1; | ||
173 | + | ||
174 | + Map<String, Integer> readLineMap = new HashMap<>(); | ||
175 | + | ||
176 | + MqttManager mqttManager = new MqttManager(); | ||
177 | + | ||
178 | + | ||
179 | + @Scheduled(fixedRate = 1000) | ||
180 | + public void sendMq() { | ||
181 | + SimpleDateFormat simpleDateFormat = new SimpleDateFormat("yyyy-MM-dd HH"); | ||
182 | + | ||
183 | + if (!isInitMQ) initMQ(); | ||
184 | + if (!isSendMQ) { | ||
185 | + isSendMQ = true; | ||
186 | + String fileName = simpleDateFormat.format(new Date()); | ||
187 | +// String filePath = "D:\\wg_log\\info\\kaoInfo\\" + fileName + ".log"; | ||
188 | + String filePath = "C:\\Users\\Administrator\\Desktop\\2020-04-30 08.log"; | ||
189 | + if (!readLineMap.containsKey(fileName)) readLineNum = -1;//更新文件后从头开始 | ||
190 | + File file = new File(filePath); | ||
191 | + try { | ||
192 | + if (!file.exists()){ | ||
193 | + System.out.println("文件不存在:" + filePath); | ||
194 | + return; | ||
195 | + } | ||
196 | + FileInputStream fileInputStream = new FileInputStream(file); | ||
197 | + BufferedReader bufferedReader = new BufferedReader(new InputStreamReader(fileInputStream, "GB2312")); | ||
198 | + | ||
199 | + String content = null; | ||
200 | + | ||
201 | + int indexLineNum = 0;//当前文件的行 | ||
202 | + while ((content = bufferedReader.readLine()) != null) { | ||
203 | + indexLineNum++; | ||
204 | + System.out.println("indexLineNum:"+indexLineNum+" ----------readLineNum:"+readLineNum); | ||
205 | + if (indexLineNum >= readLineNum) { | ||
206 | + readLineNum++; | ||
207 | + sendMQMess(content); | ||
208 | + } | ||
209 | + | ||
210 | + } | ||
211 | + | ||
212 | + readLineMap.put(fileName, readLineNum); | ||
213 | + | ||
214 | + fileInputStream.close(); | ||
215 | + bufferedReader.close(); | ||
216 | + | ||
217 | + } catch (FileNotFoundException e) { | ||
218 | + System.out.println("文件不存在:" + e.toString()); | ||
219 | + e.printStackTrace(); | ||
220 | + } catch (IOException e) { | ||
221 | + System.out.println("IO异常:" + e.toString()); | ||
222 | + e.printStackTrace(); | ||
223 | + } | ||
224 | + } else { | ||
225 | + isSendMQ = false; | ||
226 | + } | ||
227 | + | ||
228 | + | ||
229 | + } | ||
230 | + | ||
231 | + private void initMQ() { | ||
232 | + | ||
233 | + if (null != mqttManager) mqttManager.init(); | ||
234 | + isInitMQ = true; | ||
235 | + | ||
236 | + } | ||
237 | + | ||
238 | + private void sendMQMess(String content) { | ||
239 | + String cardNum = content.substring(content.indexOf("卡号") + 3, content.indexOf("卡号") + 11); | ||
240 | + | ||
241 | + System.out.println("cardNum:" + cardNum); | ||
242 | + | ||
243 | + String inOrOut = content.substring(content.indexOf("方向:") + 3, content.indexOf("方向:") + 5).endsWith("进门") ? "0" : "1"; | ||
244 | + | ||
245 | + System.out.println("inOrOut:" + inOrOut); | ||
246 | + | ||
247 | + | ||
248 | + List<String> clintIds = userDao.getClintIds(); | ||
249 | + for (int i = 0; i < clintIds.size(); i++) { | ||
250 | + String clintId = clintIds.get(i); | ||
251 | + | ||
252 | + String data = "{\"cmd\":\"" + 34 + "\",\"clientId\":\"" + clintId + "\",\"data\":{\"cardNum\":\"" + cardNum + "\",\"inOrOut\":\"" + inOrOut + "\"}}"; | ||
253 | + | ||
254 | + mqttManager.sendMq(clintId, data); | ||
255 | + } | ||
256 | + } | ||
257 | + | ||
206 | 258 | ||
207 | } | 259 | } |
cloud/dahua/src/main/java/com/example/dahua/async/SendUserInfoTask.java
1 | package com.example.dahua.async; | 1 | package com.example.dahua.async; |
2 | 2 | ||
3 | +import com.example.dahua.Gate.Gate; | ||
3 | import com.example.dahua.MyTask; | 4 | import com.example.dahua.MyTask; |
4 | import com.example.dahua.bean.*; | 5 | import com.example.dahua.bean.*; |
5 | import com.example.dahua.common.Res; | 6 | import com.example.dahua.common.Res; |
@@ -41,7 +42,7 @@ public class SendUserInfoTask { | @@ -41,7 +42,7 @@ public class SendUserInfoTask { | ||
41 | @Autowired | 42 | @Autowired |
42 | SendRecordDao sendRecordDao; | 43 | SendRecordDao sendRecordDao; |
43 | 44 | ||
44 | - @Async("taskExecutor") | 45 | +// @Async("taskExecutor") |
45 | public void doTaskOne(String file, List<AttendanceBean> attendanceBeans, UserInfoBean userInfoBean, String schoolId, int failType, int userType) throws Exception { | 46 | public void doTaskOne(String file, List<AttendanceBean> attendanceBeans, UserInfoBean userInfoBean, String schoolId, int failType, int userType) throws Exception { |
46 | File studentFile = new File(file); | 47 | File studentFile = new File(file); |
47 | String studentCode = studentFile.getName().split("\\.")[0]; | 48 | String studentCode = studentFile.getName().split("\\.")[0]; |
@@ -69,7 +70,7 @@ public class SendUserInfoTask { | @@ -69,7 +70,7 @@ public class SendUserInfoTask { | ||
69 | sendUserInfoToDev(file, attendanceBeans, userInfoBean, userType + "", sendRecordBean); | 70 | sendUserInfoToDev(file, attendanceBeans, userInfoBean, userType + "", sendRecordBean); |
70 | } | 71 | } |
71 | 72 | ||
72 | - @Async("taskExecutor") | 73 | +// @Async("taskExecutor") |
73 | public void doTaskSendUserInfos(String schoolId, String clint_type, int type, int failtype) { | 74 | public void doTaskSendUserInfos(String schoolId, String clint_type, int type, int failtype) { |
74 | try { | 75 | try { |
75 | String filePathStudent = "E:\\wwwhtdocs\\SmartCampus\\face17e50\\School" + schoolId + "\\Student"; | 76 | String filePathStudent = "E:\\wwwhtdocs\\SmartCampus\\face17e50\\School" + schoolId + "\\Student"; |
@@ -156,6 +157,7 @@ public class SendUserInfoTask { | @@ -156,6 +157,7 @@ public class SendUserInfoTask { | ||
156 | HttpUtils.uploadImgs(studentFile, schoolId, studentCode, clint_type, 2); | 157 | HttpUtils.uploadImgs(studentFile, schoolId, studentCode, clint_type, 2); |
157 | } else if (type == 2) {//教师信息 | 158 | } else if (type == 2) {//教师信息 |
158 | TeacherBean teacher = userDao.getTeacher(schoolId, studentCode); | 159 | TeacherBean teacher = userDao.getTeacher(schoolId, studentCode); |
160 | + System.out.println("教师信息:" + teacher.toString()); | ||
159 | if (null != teacher) { | 161 | if (null != teacher) { |
160 | userInfoBean = new UserInfoBean(); | 162 | userInfoBean = new UserInfoBean(); |
161 | userInfoBean.setStudent_num(teacher.getTeacher_num()); | 163 | userInfoBean.setStudent_num(teacher.getTeacher_num()); |
@@ -297,6 +299,7 @@ public class SendUserInfoTask { | @@ -297,6 +299,7 @@ public class SendUserInfoTask { | ||
297 | // System.out.println("loginHandleLong:" + loginHandleLong + MyTask.lLongMap.toString() + " 设备ID:" + attendanceBean.getClint_id()); | 299 | // System.out.println("loginHandleLong:" + loginHandleLong + MyTask.lLongMap.toString() + " 设备ID:" + attendanceBean.getClint_id()); |
298 | // System.out.println("loginHandleLong:" +loginHandleLong); | 300 | // System.out.println("loginHandleLong:" +loginHandleLong); |
299 | if (loginHandleLong == null) { | 301 | if (loginHandleLong == null) { |
302 | + | ||
300 | FileUtils.getInstance().writeLogs("设备不在线:" + attendanceBean.getClint_id(), FileUtils.devices); | 303 | FileUtils.getInstance().writeLogs("设备不在线:" + attendanceBean.getClint_id(), FileUtils.devices); |
301 | String deviceId = sendRecordDao.getFailIsExit(attendanceBean.getClint_id(), attendanceBean.getSchool_id()); | 304 | String deviceId = sendRecordDao.getFailIsExit(attendanceBean.getClint_id(), attendanceBean.getSchool_id()); |
302 | sendRecordBean.setFailType(2); | 305 | sendRecordBean.setFailType(2); |
@@ -311,27 +314,18 @@ public class SendUserInfoTask { | @@ -311,27 +314,18 @@ public class SendUserInfoTask { | ||
311 | 314 | ||
312 | String cardNum = cardNo(student_num); | 315 | String cardNum = cardNo(student_num); |
313 | if (bCardFlags != -1) {//修改卡信息 | 316 | if (bCardFlags != -1) {//修改卡信息 |
314 | -// GateModule.deleteCard(bCardFlags, loginHandleLong); | ||
315 | GateModule.modifyCard(bCardFlags,cardNum,user_id,name,"123456",Res.string().getCardStatusInt(1),Res.string().getCardTypeInt(1), | 317 | GateModule.modifyCard(bCardFlags,cardNum,user_id,name,"123456",Res.string().getCardStatusInt(1),Res.string().getCardTypeInt(1), |
316 | 0,0,1,startTime,endTime,loginHandleLong); | 318 | 0,0,1,startTime,endTime,loginHandleLong); |
317 | userDao.updateRecordNo(user_id,bCardFlags,attendanceBean.getClint_id()); | 319 | userDao.updateRecordNo(user_id,bCardFlags,attendanceBean.getClint_id()); |
318 | -// userDao.deleteRecordNo(user_id, bCardFlags); | ||
319 | - | ||
320 | -// bCardFlags = GateModule.insertCard(cardNum, user_id, name, "123456" | ||
321 | -// , Res.string().getCardStatusInt(1), Res.string().getCardTypeInt(1), 0, 0 | ||
322 | -// , 1, startTime, endTime, loginHandleLong); | ||
323 | - | ||
324 | -// if (bCardFlags != -1) { | ||
325 | -// int index = userDao.saveRecordNo(user_id, bCardFlags, name, attendanceBean.getClint_id());//存储记录集编号 | ||
326 | -// } | ||
327 | bFaceFalgs = GateModule.modifyFaceInfo(user_id, memory, loginHandleLong); | 320 | bFaceFalgs = GateModule.modifyFaceInfo(user_id, memory, loginHandleLong); |
328 | //卡号添加成功,但是人脸不成功的话,就需要新增人脸 | 321 | //卡号添加成功,但是人脸不成功的话,就需要新增人脸 |
329 | if (!bFaceFalgs) | 322 | if (!bFaceFalgs) |
330 | bFaceFalgs = GateModule.addFaceInfo(user_id, memory, loginHandleLong); | 323 | bFaceFalgs = GateModule.addFaceInfo(user_id, memory, loginHandleLong); |
331 | 324 | ||
332 | } else {//新增卡信息 | 325 | } else {//新增卡信息 |
326 | + | ||
333 | bCardFlags = GateModule.insertCard(cardNum, user_id, name, "123456" | 327 | bCardFlags = GateModule.insertCard(cardNum, user_id, name, "123456" |
334 | - , Res.string().getCardStatusInt(1), Res.string().getCardTypeInt(1), 0, 0 | 328 | + , Res.string().getCardStatusInt(1), Res.string().getCardTypeInt(1), 0, 1 |
335 | , 1, startTime, endTime, loginHandleLong); | 329 | , 1, startTime, endTime, loginHandleLong); |
336 | 330 | ||
337 | if (bCardFlags != -1) { | 331 | if (bCardFlags != -1) { |
@@ -372,7 +366,7 @@ public class SendUserInfoTask { | @@ -372,7 +366,7 @@ public class SendUserInfoTask { | ||
372 | 366 | ||
373 | // 添加卡信息和人脸失败 | 367 | // 添加卡信息和人脸失败 |
374 | if (bCardFlags == -1 && !bFaceFalgs) { | 368 | if (bCardFlags == -1 && !bFaceFalgs) { |
375 | - FileUtils.getInstance().writeLogs("下发人脸和卡号失败:" + cardNum + " " + attendanceBean.getClint_id(), FileUtils.sendUserErrTxt); | 369 | + FileUtils.getInstance().writeLogs("下发人脸和卡号失败:" + cardNum + " user_id: " + user_id+" loginHandleLong: "+loginHandleLong, FileUtils.sendUserErrTxt); |
376 | // System.out.println("添加卡信息和人脸失败"); | 370 | // System.out.println("添加卡信息和人脸失败"); |
377 | System.out.println("下发人脸和卡号失败" + "sendRecordBean:" + sendRecordBean.getDeviceID()+" ,"+sendRecordBean.getNum()+","+loginHandleLong+",bCardFlags:"+bCardFlags+"\r\n"); | 371 | System.out.println("下发人脸和卡号失败" + "sendRecordBean:" + sendRecordBean.getDeviceID()+" ,"+sendRecordBean.getNum()+","+loginHandleLong+",bCardFlags:"+bCardFlags+"\r\n"); |
378 | sendRecordBean.setFailContent("下发人脸和卡号失败"); | 372 | sendRecordBean.setFailContent("下发人脸和卡号失败"); |
@@ -664,4 +658,39 @@ public class SendUserInfoTask { | @@ -664,4 +658,39 @@ public class SendUserInfoTask { | ||
664 | e.printStackTrace(); | 658 | e.printStackTrace(); |
665 | } | 659 | } |
666 | } | 660 | } |
661 | + | ||
662 | + | ||
663 | +// @Async("taskExecutor") | ||
664 | + public void testSMS(){ | ||
665 | + RestTemplate restTemplate = new RestTemplate(); | ||
666 | + | ||
667 | + String LoginName = "13095656162"; | ||
668 | + String MessageContent ="你好,五一快乐"; | ||
669 | + String MessageType = "2"; | ||
670 | + String Password = "yxt_123456"; | ||
671 | + String ScheduleTime = ""; | ||
672 | + String SerialNumber = ""; | ||
673 | + String SpCode ="13095656162"; | ||
674 | + String UserNumber=""; | ||
675 | + String f= "1"; | ||
676 | + long now = System.currentTimeMillis(); | ||
677 | + String time = new SimpleDateFormat("yyyy").format(new Date()); | ||
678 | + int ran = new Random().nextInt(999)+1; | ||
679 | + SerialNumber = now+time+ran; | ||
680 | + if (SerialNumber.length()<20)SerialNumber=SerialNumber+"0"; | ||
681 | + System.out.println("SerialNumber:"+SerialNumber); | ||
682 | + UserNumber = "130"+(new Random().nextInt(100000000)+1); | ||
683 | + if (UserNumber.length()<11)UserNumber = UserNumber+"0"; | ||
684 | +// SpCode = "130"+(new Random().nextInt(100000000)+1); | ||
685 | + ScheduleTime = new SimpleDateFormat("yyyyMMddHHmmss").format(new Date()); | ||
686 | + | ||
687 | + | ||
688 | + | ||
689 | + String url = String.format("http://121.40.109.21:8083/haikang/sms/sendMsg?LoginName=%s&MessageContent=%s" + | ||
690 | + "&MessageType=%s&Password=%s&ScheduleTime=%s&SerialNumber=%s&SpCode=%s&UserNumber=%s&f=%s",LoginName, | ||
691 | + MessageContent,MessageType,Password,ScheduleTime,SerialNumber,SpCode,UserNumber,f); | ||
692 | + | ||
693 | + ResponseEntity<String> responseEntity = restTemplate.getForEntity(url,String.class); | ||
694 | + System.out.println("responseEntity:"+responseEntity.getBody()+"---url:"+url); | ||
695 | + } | ||
667 | } | 696 | } |
cloud/dahua/src/main/java/com/example/dahua/control/FileControl.java
1 | package com.example.dahua.control; | 1 | package com.example.dahua.control; |
2 | 2 | ||
3 | +import com.example.dahua.MyTask; | ||
3 | import com.example.dahua.async.SendUserInfoTask; | 4 | import com.example.dahua.async.SendUserInfoTask; |
5 | +import com.example.dahua.attendance.Attendance; | ||
6 | +import com.example.dahua.bean.AttendanceBean; | ||
7 | +import com.example.dahua.bean.TeacherBean; | ||
4 | import com.example.dahua.bean.UploadImg; | 8 | import com.example.dahua.bean.UploadImg; |
9 | +import com.example.dahua.dao.UserDao; | ||
10 | +import com.example.dahua.lib.ToolKits; | ||
11 | +import com.example.dahua.module.GateModule; | ||
5 | import com.example.dahua.service.UserService; | 12 | import com.example.dahua.service.UserService; |
13 | +import com.sun.jna.Memory; | ||
6 | import io.swagger.annotations.Api; | 14 | import io.swagger.annotations.Api; |
7 | import io.swagger.annotations.ApiOperation; | 15 | import io.swagger.annotations.ApiOperation; |
8 | import org.springframework.beans.factory.annotation.Autowired; | 16 | import org.springframework.beans.factory.annotation.Autowired; |
@@ -14,10 +22,12 @@ import java.io.File; | @@ -14,10 +22,12 @@ import java.io.File; | ||
14 | import java.io.FileNotFoundException; | 22 | import java.io.FileNotFoundException; |
15 | import java.io.FileOutputStream; | 23 | import java.io.FileOutputStream; |
16 | import java.io.IOException; | 24 | import java.io.IOException; |
25 | +import java.nio.file.Files; | ||
26 | +import java.util.List; | ||
17 | 27 | ||
18 | @RestController | 28 | @RestController |
19 | @Api("文件管理器") | 29 | @Api("文件管理器") |
20 | -@RequestMapping(value = "file/*",produces = MediaType.APPLICATION_JSON_UTF8_VALUE) | 30 | +@RequestMapping(value = "file/*", produces = MediaType.APPLICATION_JSON_UTF8_VALUE) |
21 | public class FileControl { | 31 | public class FileControl { |
22 | 32 | ||
23 | @Autowired | 33 | @Autowired |
@@ -26,9 +36,12 @@ public class FileControl { | @@ -26,9 +36,12 @@ public class FileControl { | ||
26 | @Autowired | 36 | @Autowired |
27 | SendUserInfoTask sendUserInfoTask; | 37 | SendUserInfoTask sendUserInfoTask; |
28 | 38 | ||
39 | + @Autowired | ||
40 | + UserDao userDao; | ||
41 | + | ||
29 | @RequestMapping(method = RequestMethod.POST, value = "uploadImg") | 42 | @RequestMapping(method = RequestMethod.POST, value = "uploadImg") |
30 | public String uploadImg(@RequestParam("file") MultipartFile file, @RequestParam("schoolId") String schoolId, @RequestParam("studentCode") String studentCode, | 43 | public String uploadImg(@RequestParam("file") MultipartFile file, @RequestParam("schoolId") String schoolId, @RequestParam("studentCode") String studentCode, |
31 | - @RequestParam("clint_type") String clint_type,@RequestParam("userType") int userType) { | 44 | + @RequestParam("clint_type") String clint_type, @RequestParam("userType") int userType) { |
32 | System.out.println("schoolId:" + schoolId + " studentCode:" + studentCode); | 45 | System.out.println("schoolId:" + schoolId + " studentCode:" + studentCode); |
33 | String fileName = file.getOriginalFilename();//文件名 | 46 | String fileName = file.getOriginalFilename();//文件名 |
34 | 47 | ||
@@ -40,7 +53,7 @@ public class FileControl { | @@ -40,7 +53,7 @@ public class FileControl { | ||
40 | 53 | ||
41 | fileOutputStream.write(file.getBytes()); | 54 | fileOutputStream.write(file.getBytes()); |
42 | fileOutputStream.close(); | 55 | fileOutputStream.close(); |
43 | - userService.uploadImgAndUserInfo(dest.getAbsolutePath(), schoolId, studentCode, clint_type,userType,""); | 56 | + userService.uploadImgAndUserInfo(dest.getAbsolutePath(), schoolId, studentCode, clint_type, userType, ""); |
44 | return "1"; | 57 | return "1"; |
45 | } catch (FileNotFoundException e) { | 58 | } catch (FileNotFoundException e) { |
46 | e.printStackTrace(); | 59 | e.printStackTrace(); |
@@ -53,7 +66,7 @@ public class FileControl { | @@ -53,7 +66,7 @@ public class FileControl { | ||
53 | 66 | ||
54 | @RequestMapping(method = RequestMethod.POST, value = "uploadImgToDev") | 67 | @RequestMapping(method = RequestMethod.POST, value = "uploadImgToDev") |
55 | public String uploadImgToDev(@RequestParam("file") MultipartFile file, @RequestParam("schoolId") String schoolId, @RequestParam("studentCode") String studentCode, | 68 | public String uploadImgToDev(@RequestParam("file") MultipartFile file, @RequestParam("schoolId") String schoolId, @RequestParam("studentCode") String studentCode, |
56 | - @RequestParam("clint_type") String clint_type,@RequestParam("userType") int userType,@RequestParam("devid")String devid) { | 69 | + @RequestParam("clint_type") String clint_type, @RequestParam("userType") int userType, @RequestParam("devid") String devid) { |
57 | String fileName = file.getOriginalFilename();//文件名 | 70 | String fileName = file.getOriginalFilename();//文件名 |
58 | 71 | ||
59 | File outFile = new File("C://imgCom"); | 72 | File outFile = new File("C://imgCom"); |
@@ -64,7 +77,7 @@ public class FileControl { | @@ -64,7 +77,7 @@ public class FileControl { | ||
64 | 77 | ||
65 | fileOutputStream.write(file.getBytes()); | 78 | fileOutputStream.write(file.getBytes()); |
66 | fileOutputStream.close(); | 79 | fileOutputStream.close(); |
67 | - userService.uploadImgAndUserInfo(dest.getAbsolutePath(), schoolId, studentCode, clint_type,userType,devid); | 80 | + userService.uploadImgAndUserInfo(dest.getAbsolutePath(), schoolId, studentCode, clint_type, userType, devid); |
68 | return "1"; | 81 | return "1"; |
69 | } catch (FileNotFoundException e) { | 82 | } catch (FileNotFoundException e) { |
70 | e.printStackTrace(); | 83 | e.printStackTrace(); |
@@ -91,6 +104,89 @@ public class FileControl { | @@ -91,6 +104,89 @@ public class FileControl { | ||
91 | } | 104 | } |
92 | 105 | ||
93 | 106 | ||
107 | + @RequestMapping(value = "findCard", method = RequestMethod.GET) | ||
108 | + @ApiOperation(value = "查询设备卡信息") | ||
109 | + public boolean findCard(@RequestParam("cardNum") String cardNum, @RequestParam("deviceId") String deviceId) { | ||
110 | + boolean fincard = GateModule.findCard(cardNum, MyTask.lLongMap.get(deviceId)); | ||
111 | + System.out.println("fincard:" + fincard + MyTask.lLongMap.get(deviceId)); | ||
112 | + | ||
113 | + return true; | ||
114 | + } | ||
115 | + | ||
116 | + | ||
117 | + @RequestMapping(value = "addCard", method = RequestMethod.GET) | ||
118 | + @ApiOperation(value = "下发卡信息") | ||
119 | + public int addCard(@RequestParam("schoolId") String schoolId, @RequestParam("targPath") String targPath) { | ||
120 | + | ||
121 | + File file = new File(targPath); | ||
94 | 122 | ||
123 | + File[] files = file.listFiles(); | ||
124 | + | ||
125 | + for (int i = 0; i < files.length; i++) { | ||
126 | + File imgFile = files[i]; | ||
127 | + String num = imgFile.getName().split("\\.")[0]; | ||
128 | + TeacherBean teacherBean = userDao.getTeacher(schoolId, num); | ||
129 | + | ||
130 | + List<AttendanceBean> attendanceBeans = userDao.selectDeviceWithschool_id("22", schoolId); | ||
131 | + for (int j = 0; j < attendanceBeans.size(); j++) { | ||
132 | + AttendanceBean attendanceBean = attendanceBeans.get(j); | ||
133 | + int addCard = GateModule.insertCard(cardNo(teacherBean.getTeacher_num()), teacherBean.getUser_id(), teacherBean.getName(), | ||
134 | + "123456", 1, 1, 1, 1, 1, | ||
135 | + "2020-01-01 00:00:00", "2040-01-01 12:00:00", MyTask.lLongMap.get(attendanceBean.getClint_id())); | ||
136 | + Memory memory = ToolKits.readPictureFile(imgFile.getAbsolutePath()); | ||
137 | + GateModule.addFaceInfo(teacherBean.getUser_id(), memory, MyTask.lLongMap.get(attendanceBean.getClint_id())); | ||
138 | + userDao.saveRecordNo(teacherBean.getUser_id(), addCard, teacherBean.getName(), attendanceBean.getClint_id()); | ||
139 | + System.out.println("teacherBean:" + teacherBean.toString() + " clientid:" + attendanceBean.getClint_id()); | ||
140 | + } | ||
141 | + | ||
142 | + | ||
143 | + } | ||
144 | + | ||
145 | + | ||
146 | + return 1; | ||
147 | + } | ||
95 | 148 | ||
149 | + | ||
150 | + @RequestMapping(value = "deleteCard", method = RequestMethod.GET) | ||
151 | + @ApiOperation(value = "删除卡信息") | ||
152 | + public boolean deleteCard(@RequestParam("recordNum") int recordNum, @RequestParam("deviceId") String deviceId) { | ||
153 | + boolean deleteCard = GateModule.deleteCard(recordNum, MyTask.lLongMap.get(deviceId)); | ||
154 | + System.out.println("addCard:" + deleteCard + "----" + MyTask.lLongMap.get(deviceId)); | ||
155 | + return deleteCard; | ||
156 | + } | ||
157 | + | ||
158 | + | ||
159 | + @RequestMapping(value = "clearCard", method = RequestMethod.GET) | ||
160 | + @ApiOperation(value = "清空卡信息") | ||
161 | + public boolean clearCard(@RequestParam("deviceId") String deviceId) { | ||
162 | + boolean clearCard = GateModule.clearCard(MyTask.lLongMap.get(deviceId)); | ||
163 | + System.out.println("addCard:" + clearCard + "----" + MyTask.lLongMap.get(deviceId)); | ||
164 | + return clearCard; | ||
165 | + } | ||
166 | + | ||
167 | + @RequestMapping(value = "clearFaceInfo", method = RequestMethod.GET) | ||
168 | + @ApiOperation(value = "清空人脸信息") | ||
169 | + public boolean clearFaceInfo(@RequestParam("deviceId") String deviceId) { | ||
170 | + boolean clearCard = GateModule.clearFaceInfo(MyTask.lLongMap.get(deviceId)); | ||
171 | + System.out.println("addCard:" + clearCard + "----" + MyTask.lLongMap.get(deviceId)); | ||
172 | + return clearCard; | ||
173 | + } | ||
174 | + | ||
175 | + | ||
176 | + public String cardNo(String cardDex) { | ||
177 | + | ||
178 | + String cardR = ""; | ||
179 | + int length = cardDex.length(); | ||
180 | + if (length != 8) { | ||
181 | + System.out.println("卡号格式不正确:" + cardDex); | ||
182 | + return cardDex; | ||
183 | + } | ||
184 | + while (length > 0) { | ||
185 | + length -= 2; | ||
186 | + cardR += cardDex.substring(length, length + 2); | ||
187 | + } | ||
188 | + | ||
189 | + return cardR; | ||
190 | + | ||
191 | + } | ||
96 | } | 192 | } |
cloud/dahua/src/main/java/com/example/dahua/dao/TestDao.java
@@ -36,4 +36,7 @@ public interface TestDao { | @@ -36,4 +36,7 @@ public interface TestDao { | ||
36 | 36 | ||
37 | @Update("update TK_Question set Question = #{Question} where ID = #{id}") | 37 | @Update("update TK_Question set Question = #{Question} where ID = #{id}") |
38 | void updateQuestion(@Param("Question") String Question,@Param("id")String id); | 38 | void updateQuestion(@Param("Question") String Question,@Param("id")String id); |
39 | + | ||
40 | + | ||
41 | + | ||
39 | } | 42 | } |
cloud/dahua/src/main/java/com/example/dahua/dao/UserDao.java
@@ -20,10 +20,10 @@ public interface UserDao { | @@ -20,10 +20,10 @@ public interface UserDao { | ||
20 | @Select("select * from SZ_Attendance where school_id = #{school_id} and clint_type = #{clint_type} and clint_id = #{clint_id}") | 20 | @Select("select * from SZ_Attendance where school_id = #{school_id} and clint_type = #{clint_type} and clint_id = #{clint_id}") |
21 | List<AttendanceBean> getAttendanceBeanWithId(@Param("school_id")String school_id,@Param("clint_type")String clint_type,@Param("clint_id")String clint_id); | 21 | List<AttendanceBean> getAttendanceBeanWithId(@Param("school_id")String school_id,@Param("clint_type")String clint_type,@Param("clint_id")String clint_id); |
22 | 22 | ||
23 | - @Select(" select * from SZ_V_School_Student where school_id = #{school_id} and studentcode = #{studentcode}") | 23 | + @Select(" select Top(1)* from SZ_V_School_Student where school_id = #{school_id} and studentcode = #{studentcode}") |
24 | UserInfoBean getUserInfo(@Param("school_id")String school_id,@Param("studentcode")String studentcode); | 24 | UserInfoBean getUserInfo(@Param("school_id")String school_id,@Param("studentcode")String studentcode); |
25 | 25 | ||
26 | - @Select(" select * from SZ_V_School_Teacher where school_id = #{school_id} and num = #{num}") | 26 | + @Select(" select Top(1)* from SZ_V_School_Teacher where school_id = #{school_id} and num = #{num}") |
27 | TeacherBean getTeacher(@Param("school_id")String school_id, @Param("num")String num); | 27 | TeacherBean getTeacher(@Param("school_id")String school_id, @Param("num")String num); |
28 | 28 | ||
29 | @Select(" select Top(1)* from SZ_V_School_Teacher where teacher_id = #{teacher_id}") | 29 | @Select(" select Top(1)* from SZ_V_School_Teacher where teacher_id = #{teacher_id}") |
@@ -100,4 +100,7 @@ public interface UserDao { | @@ -100,4 +100,7 @@ public interface UserDao { | ||
100 | @Select("select * from SZ_V_Card where num=#{num}") | 100 | @Select("select * from SZ_V_Card where num=#{num}") |
101 | CardBean getCards(@Param("num")String num); | 101 | CardBean getCards(@Param("num")String num); |
102 | 102 | ||
103 | + @Select("select clint_id from SZ_Attendance where school_id = 4 and clint_type = 8") | ||
104 | + List<String> getClintIds(); | ||
105 | + | ||
103 | } | 106 | } |
cloud/dahua/src/main/java/com/example/dahua/module/GateModule.java
@@ -494,7 +494,7 @@ public class GateModule { | @@ -494,7 +494,7 @@ public class GateModule { | ||
494 | /** | 494 | /** |
495 | * 清除所有卡信息 | 495 | * 清除所有卡信息 |
496 | */ | 496 | */ |
497 | - public static boolean clearCard() { | 497 | + public static boolean clearCard(LLong lLong) { |
498 | /** | 498 | /** |
499 | * 记录集操作 | 499 | * 记录集操作 |
500 | */ | 500 | */ |
@@ -502,7 +502,7 @@ public class GateModule { | @@ -502,7 +502,7 @@ public class GateModule { | ||
502 | msg.emType = EM_NET_RECORD_TYPE.NET_RECORD_ACCESSCTLCARD; // 门禁卡记录集信息类型 | 502 | msg.emType = EM_NET_RECORD_TYPE.NET_RECORD_ACCESSCTLCARD; // 门禁卡记录集信息类型 |
503 | 503 | ||
504 | msg.write(); | 504 | msg.write(); |
505 | - boolean bRet = LoginModule.netsdk.CLIENT_ControlDevice(LoginModule.m_hLoginHandle, | 505 | + boolean bRet = LoginModule.netsdk.CLIENT_ControlDevice(lLong, |
506 | CtrlType.CTRLTYPE_CTRL_RECORDSET_CLEAR, msg.getPointer(), 5000); | 506 | CtrlType.CTRLTYPE_CTRL_RECORDSET_CLEAR, msg.getPointer(), 5000); |
507 | msg.read(); | 507 | msg.read(); |
508 | if(!bRet){ | 508 | if(!bRet){ |
@@ -727,7 +727,7 @@ public class GateModule { | @@ -727,7 +727,7 @@ public class GateModule { | ||
727 | /** | 727 | /** |
728 | * 清除所有人脸 | 728 | * 清除所有人脸 |
729 | */ | 729 | */ |
730 | - public static boolean clearFaceInfo() { | 730 | + public static boolean clearFaceInfo(LLong lLong) { |
731 | int emType = EM_FACEINFO_OPREATE_TYPE.EM_FACEINFO_OPREATE_CLEAR; // 清除 | 731 | int emType = EM_FACEINFO_OPREATE_TYPE.EM_FACEINFO_OPREATE_CLEAR; // 清除 |
732 | 732 | ||
733 | /** | 733 | /** |
@@ -742,7 +742,7 @@ public class GateModule { | @@ -742,7 +742,7 @@ public class GateModule { | ||
742 | 742 | ||
743 | stIn.write(); | 743 | stIn.write(); |
744 | stOut.write(); | 744 | stOut.write(); |
745 | - boolean bRet = LoginModule.netsdk.CLIENT_FaceInfoOpreate(LoginModule.m_hLoginHandle, emType, | 745 | + boolean bRet = LoginModule.netsdk.CLIENT_FaceInfoOpreate(lLong, emType, |
746 | stIn.getPointer(), stOut.getPointer(), 5000); | 746 | stIn.getPointer(), stOut.getPointer(), 5000); |
747 | stIn.read(); | 747 | stIn.read(); |
748 | stOut.read(); | 748 | stOut.read(); |
@@ -835,6 +835,9 @@ public class GateModule { | @@ -835,6 +835,9 @@ public class GateModule { | ||
835 | findCondition.read(); | 835 | findCondition.read(); |
836 | 836 | ||
837 | m_lFindHandle = stOut.lFindeHandle; | 837 | m_lFindHandle = stOut.lFindeHandle; |
838 | + | ||
839 | + System.err.println("没查到卡信息!" + ToolKits.getErrorCodePrint()); | ||
840 | + | ||
838 | return true; | 841 | return true; |
839 | } | 842 | } |
840 | 843 |
cloud/dahua/src/main/java/com/example/dahua/mqtt/MqttManager.java
@@ -92,10 +92,10 @@ public class MqttManager { | @@ -92,10 +92,10 @@ public class MqttManager { | ||
92 | } | 92 | } |
93 | } | 93 | } |
94 | 94 | ||
95 | - public void sendMq(String deviceId,int cmd) { | 95 | + public void sendMq(String deviceId,String content) { |
96 | String recvClientId = groupId + "@@@"+deviceId; | 96 | String recvClientId = groupId + "@@@"+deviceId; |
97 | final String p2pSendTopic = topic + "/p2p/" + recvClientId; | 97 | final String p2pSendTopic = topic + "/p2p/" + recvClientId; |
98 | - String content = "{\"cmd\":\""+cmd+"\",\"clientId\":\"\",\"data\": \"6:00-19:25\"}"; | 98 | +// String content = "{\"cmd\":\""+cmd+"\",\"clientId\":\"\",\"data\": \"6:00-19:25\"}"; |
99 | MqttMessage message = new MqttMessage(content.getBytes()); | 99 | MqttMessage message = new MqttMessage(content.getBytes()); |
100 | message.setQos(qosLevel); | 100 | message.setQos(qosLevel); |
101 | System.out.println("发送内容:" + p2pSendTopic); | 101 | System.out.println("发送内容:" + p2pSendTopic); |
cloud/dahua/src/main/java/com/example/dahua/service/UserServiceImp.java
@@ -23,9 +23,9 @@ public class UserServiceImp implements UserService { | @@ -23,9 +23,9 @@ public class UserServiceImp implements UserService { | ||
23 | SendUserInfoTask myTask; | 23 | SendUserInfoTask myTask; |
24 | 24 | ||
25 | @Override | 25 | @Override |
26 | - public List<AttendanceBean> getAttendanceBeans(String schoolId, String clint_type,String devid) { | 26 | + public List<AttendanceBean> getAttendanceBeans(String schoolId, String clint_type, String devid) { |
27 | 27 | ||
28 | - if (!StringUtils.isEmpty(devid))return userDao.getAttendanceBeanWithId(schoolId,clint_type,devid); | 28 | + if (!StringUtils.isEmpty(devid)) return userDao.getAttendanceBeanWithId(schoolId, clint_type, devid); |
29 | 29 | ||
30 | return userDao.getAttendanceBeans(schoolId, clint_type); | 30 | return userDao.getAttendanceBeans(schoolId, clint_type); |
31 | } | 31 | } |
@@ -45,9 +45,9 @@ public class UserServiceImp implements UserService { | @@ -45,9 +45,9 @@ public class UserServiceImp implements UserService { | ||
45 | * @return | 45 | * @return |
46 | */ | 46 | */ |
47 | @Override | 47 | @Override |
48 | - public boolean uploadImgAndUserInfo(String file, String schoolId, String studentCode, String clint_type, int userType,String devid) { | ||
49 | - List<AttendanceBean> attendanceBeans = getAttendanceBeans(schoolId, clint_type,devid);//获取学校下的大华设备 | ||
50 | - | 48 | + public boolean uploadImgAndUserInfo(String file, String schoolId, String studentCode, String clint_type, int userType, String devid) { |
49 | + List<AttendanceBean> attendanceBeans = getAttendanceBeans(schoolId, clint_type, devid);//获取学校下的大华设备 | ||
50 | + System.out.println("设备数量:" + attendanceBeans.size()); | ||
51 | UserInfoBean userInfoBean = null; | 51 | UserInfoBean userInfoBean = null; |
52 | try { | 52 | try { |
53 | if (userType == 2) { | 53 | if (userType == 2) { |
cloud/dahua/src/main/java/com/example/dahua/utils/HttpUtils.java
1 | package com.example.dahua.utils; | 1 | package com.example.dahua.utils; |
2 | 2 | ||
3 | +import com.example.dahua.lib.CompressPic; | ||
4 | +import com.example.dahua.lib.FilePath; | ||
3 | import org.springframework.core.io.FileSystemResource; | 5 | import org.springframework.core.io.FileSystemResource; |
4 | import org.springframework.http.HttpEntity; | 6 | import org.springframework.http.HttpEntity; |
5 | import org.springframework.http.HttpHeaders; | 7 | import org.springframework.http.HttpHeaders; |
@@ -22,7 +24,13 @@ public class HttpUtils { | @@ -22,7 +24,13 @@ public class HttpUtils { | ||
22 | System.out.println("图片不存在"); | 24 | System.out.println("图片不存在"); |
23 | return false; | 25 | return false; |
24 | } | 26 | } |
25 | - | 27 | + String targPath = FilePath.picPathComp + studentCode+ ".jpg"; |
28 | +// String targPath = "C:\\Users\\taohandong\\Desktop\\comp\\"+userInfoBean.getStudentcode()+".jpg"; | ||
29 | + try { | ||
30 | + CompressPic.CompressPic(file.getAbsolutePath(), targPath, studentCode);//压缩后的图片 | ||
31 | + } catch (Exception e) { | ||
32 | + e.printStackTrace(); | ||
33 | + } | ||
26 | String url = "http://121.40.109.21:8991/file/uploadImg"; | 34 | String url = "http://121.40.109.21:8991/file/uploadImg"; |
27 | // String url = "http://localhost:8991/file/uploadImg"; | 35 | // String url = "http://localhost:8991/file/uploadImg"; |
28 | RestTemplate restTemplate = new RestTemplate(); | 36 | RestTemplate restTemplate = new RestTemplate(); |
@@ -35,7 +43,7 @@ public class HttpUtils { | @@ -35,7 +43,7 @@ public class HttpUtils { | ||
35 | 43 | ||
36 | MultiValueMap<String,Object> multivaluedMap = new LinkedMultiValueMap<>(); | 44 | MultiValueMap<String,Object> multivaluedMap = new LinkedMultiValueMap<>(); |
37 | 45 | ||
38 | - FileSystemResource fileSystemResource = new FileSystemResource(file); | 46 | + FileSystemResource fileSystemResource = new FileSystemResource(targPath); |
39 | 47 | ||
40 | multivaluedMap.add("file",fileSystemResource); | 48 | multivaluedMap.add("file",fileSystemResource); |
41 | multivaluedMap.add("schoolId",schoolId); | 49 | multivaluedMap.add("schoolId",schoolId); |
cloud/dahua/src/main/java/com/example/dahua/xiananDao/SendRecordDao.java
@@ -79,5 +79,10 @@ public interface SendRecordDao { | @@ -79,5 +79,10 @@ public interface SendRecordDao { | ||
79 | void addFaceRecoder(@Param("deviceId") String deviceId, @Param("user_id") String user_id, @Param("name") String name, | 79 | void addFaceRecoder(@Param("deviceId") String deviceId, @Param("user_id") String user_id, @Param("name") String name, |
80 | @Param("imgurl") String imgurl, @Param("inOrOut") int inOrOut, @Param("time") String time, | 80 | @Param("imgurl") String imgurl, @Param("inOrOut") int inOrOut, @Param("time") String time, |
81 | @Param("cardNum") String cardNum); | 81 | @Param("cardNum") String cardNum); |
82 | + | ||
83 | + | ||
84 | + @Select("select stu.studentcode from DBLan137.smartcampus.dbo.SZ_V_School_Student as stu where stu.student_num in (select distinct NUM from Face_SendFail where schoolId = 1037 and time > '2020-04-13' and userType = 2)") | ||
85 | + List<String> getStudentCode(); | ||
86 | + | ||
82 | } | 87 | } |
83 | 88 |
cloud/dahua/src/main/resources/bootstrap.yml
@@ -6,7 +6,7 @@ server: | @@ -6,7 +6,7 @@ server: | ||
6 | #服务名称 | 6 | #服务名称 |
7 | spring: | 7 | spring: |
8 | application: | 8 | application: |
9 | - name: dahua | 9 | + name: dahuaserver |
10 | 10 | ||
11 | #management: | 11 | #management: |
12 | # endpoints: | 12 | # endpoints: |
@@ -36,5 +36,5 @@ eureka: | @@ -36,5 +36,5 @@ eureka: | ||
36 | lease-renewal-interval-in-seconds: 10 #每隔几秒告诉eureka服务器我还存活,用于心跳检测 | 36 | lease-renewal-interval-in-seconds: 10 #每隔几秒告诉eureka服务器我还存活,用于心跳检测 |
37 | lease-expiration-duration-in-seconds: 10 #如果心跳检测一直没有发送,10秒后会从eureka服务器中将此服务剔除 | 37 | lease-expiration-duration-in-seconds: 10 #如果心跳检测一直没有发送,10秒后会从eureka服务器中将此服务剔除 |
38 | # status-page-url: http://${spring.cloud.client.ip-address}:${server.port}/doc.html # ${server.port}为该服务的端口号 | 38 | # status-page-url: http://${spring.cloud.client.ip-address}:${server.port}/doc.html # ${server.port}为该服务的端口号 |
39 | - hostname: 114.55.30.100 | 39 | + hostname: localhost |
40 | # status-page-url: http://${spring.cloud.client.ip-address}:${randomServerPort.value[5000,5005]}/document.html # ${server.port}为该服务的端口号 | 40 | # status-page-url: http://${spring.cloud.client.ip-address}:${randomServerPort.value[5000,5005]}/document.html # ${server.port}为该服务的端口号 |
41 | \ No newline at end of file | 41 | \ No newline at end of file |
cloud/dahua/src/test/java/com/example/dahua/DahuaApplicationTests.java
@@ -311,13 +311,16 @@ public class DahuaApplicationTests { | @@ -311,13 +311,16 @@ public class DahuaApplicationTests { | ||
311 | @Test | 311 | @Test |
312 | public void test2() { | 312 | public void test2() { |
313 | 313 | ||
314 | - /* RestTemplate restTemplate = new RestTemplate(); | ||
315 | - | ||
316 | - | ||
317 | - String url = "http://localhost:8991/user/checkFace?url=C:\\Users\\taohandong\\Pictures\\test.jpg"; | 314 | + List<String> stuCodes = sendRecordDao.getStudentCode(); |
318 | 315 | ||
316 | + RestTemplate restTemplate = new RestTemplate(); | ||
319 | 317 | ||
320 | - System.out.println("result:"+ restTemplate.getForObject(url,String.class));*/ | 318 | + for (int i = 0; i < stuCodes.size(); i++) { |
319 | + String stuCode = stuCodes.get(i); | ||
320 | + String url = "http://114.55.30.100:8991/user/checkFace?url=E:/wwwhtdocs/SmartCampus/face17e5/School1037/Student/" + stuCode + ".png"; | ||
321 | + ResponseEntity<String> responseEntity = restTemplate.getForEntity(url, String.class); | ||
322 | + System.out.println("responseEntity:" + responseEntity.getBody()); | ||
323 | + } | ||
321 | 324 | ||
322 | 325 | ||
323 | } | 326 | } |
@@ -326,11 +329,11 @@ public class DahuaApplicationTests { | @@ -326,11 +329,11 @@ public class DahuaApplicationTests { | ||
326 | public void test1() { | 329 | public void test1() { |
327 | 330 | ||
328 | 331 | ||
329 | - String url = "http://121.40.109.21:9000/cleanFail?deviceId="; | ||
330 | - RestTemplate restTemplate = new RestTemplate(); | ||
331 | - | ||
332 | - String result = restTemplate.getForObject(url+"253164293",String.class); | ||
333 | -System.out.println("result:"+result); | 332 | +// String url = "http://121.40.109.21:9000/cleanFail?deviceId="; |
333 | +// RestTemplate restTemplate = new RestTemplate(); | ||
334 | +// | ||
335 | +// String result = restTemplate.getForObject(url + "253164293", String.class); | ||
336 | +// System.out.println("result:" + result); | ||
334 | /* try { | 337 | /* try { |
335 | BufferedReader bufferedReader = new BufferedReader(new FileReader("C:\\TaoHandong\\copy\\宿舍.txt")); | 338 | BufferedReader bufferedReader = new BufferedReader(new FileReader("C:\\TaoHandong\\copy\\宿舍.txt")); |
336 | String content = null; | 339 | String content = null; |
@@ -368,20 +371,67 @@ System.out.println("result:"+result); | @@ -368,20 +371,67 @@ System.out.println("result:"+result); | ||
368 | } | 371 | } |
369 | 372 | ||
370 | 373 | ||
374 | + | ||
371 | @Test | 375 | @Test |
372 | public void Mqtt() { | 376 | public void Mqtt() { |
373 | 377 | ||
378 | + | ||
379 | + | ||
380 | + for (int i = 0; i < 2; i++) { | ||
381 | + sendUserInfoTask.testSMS(); | ||
382 | + } | ||
383 | + | ||
384 | + /* File file = new File("C:\\Users\\Administrator\\Desktop\\2020-04-30 08.log"); | ||
385 | + | ||
386 | + try { | ||
387 | + BufferedReader bufferedReader = new BufferedReader(new InputStreamReader(new FileInputStream(file),"GB2312")); | ||
388 | + | ||
389 | + String content = null; | ||
390 | + | ||
391 | + MqttManager mqttManager = new MqttManager(); | ||
392 | + | ||
393 | + mqttManager.init(); | ||
394 | + | ||
395 | + while ((content=bufferedReader.readLine())!=null){ | ||
396 | + | ||
397 | + String cardNum = content.substring(content.indexOf("卡号")+3,content.indexOf("卡号")+11); | ||
398 | + | ||
399 | + System.out.println("cardNum:"+cardNum); | ||
400 | + | ||
401 | + | ||
402 | + String inOrOut = content.substring(content.indexOf("方向:")+3,content.indexOf("方向:")+5).endsWith("进门")?"0":"1"; | ||
403 | + | ||
404 | + System.out.println("inOrOut:"+inOrOut); | ||
405 | + | ||
406 | + | ||
407 | + List<String> clintIds = userDao.getClintIds(); | ||
408 | + for (int i = 0; i < clintIds.size(); i++) { | ||
409 | + String clintId = clintIds.get(i); | ||
410 | + | ||
411 | + String data = "{\"cmd\":\""+34+"\",\"clientId\":\""+clintId+"\",\"data\":{\"cardNum\":\""+cardNum+"\",\"inOrOut\":\""+inOrOut+"\"}}"; | ||
412 | + | ||
413 | + mqttManager.sendMq(clintId, data); | ||
414 | + } | ||
415 | + | ||
416 | + } | ||
417 | + | ||
418 | + } catch (FileNotFoundException e) { | ||
419 | + e.printStackTrace(); | ||
420 | + } catch (IOException e) { | ||
421 | + e.printStackTrace(); | ||
422 | + }*/ | ||
423 | + | ||
374 | /* MqttManager mqttManager = new MqttManager(); | 424 | /* MqttManager mqttManager = new MqttManager(); |
375 | 425 | ||
376 | mqttManager.init(); | 426 | mqttManager.init(); |
377 | 427 | ||
378 | - List<String> stringList = userDao.getAllDecWithSch(479); | 428 | + List<String> stringList = userDao.getAllDecWithSch(27); |
379 | System.out.println("stringList:" + stringList); | 429 | System.out.println("stringList:" + stringList); |
380 | for (int i = 0; i < stringList.size(); i++) { | 430 | for (int i = 0; i < stringList.size(); i++) { |
381 | String devId = stringList.get(i); | 431 | String devId = stringList.get(i); |
382 | //30关闭显示屏 31打开显示屏,9升级客户端 | 432 | //30关闭显示屏 31打开显示屏,9升级客户端 |
383 | 433 | ||
384 | - mqttManager.sendMq(devId, 31); | 434 | + mqttManager.sendMq(devId, 9); |
385 | }*/ | 435 | }*/ |
386 | } | 436 | } |
387 | 437 |
cloud/fIle-center/src/main/java/com/sincere/file/control/FileControl.java
@@ -48,7 +48,6 @@ public class FileControl { | @@ -48,7 +48,6 @@ public class FileControl { | ||
48 | 48 | ||
49 | String ossPath = request.getHeader("ossPath");//oss的二级目录 | 49 | String ossPath = request.getHeader("ossPath");//oss的二级目录 |
50 | 50 | ||
51 | - | ||
52 | FileInfo fileInfo = fileService.upload(file, ossPath); | 51 | FileInfo fileInfo = fileService.upload(file, ossPath); |
53 | 52 | ||
54 | return fileInfo.getUrl(); | 53 | return fileInfo.getUrl(); |
cloud/fIle-center/src/main/java/com/sincere/file/service/impl/AbstractFileService.java
@@ -23,23 +23,9 @@ public abstract class AbstractFileService implements FileService { | @@ -23,23 +23,9 @@ public abstract class AbstractFileService implements FileService { | ||
23 | @Override | 23 | @Override |
24 | public FileInfo upload(MultipartFile file,String filePath) throws Exception { | 24 | public FileInfo upload(MultipartFile file,String filePath) throws Exception { |
25 | FileInfo fileInfo = FileUtil.getFileInfo(file); | 25 | FileInfo fileInfo = FileUtil.getFileInfo(file); |
26 | -// FileInfo oldFileInfo = getFileDao().getById(fileInfo.getId()); | ||
27 | -// if (oldFileInfo != null) { | ||
28 | -// return oldFileInfo; | ||
29 | -// } | ||
30 | -// | ||
31 | -// if (!fileInfo.getName().contains(".")) { | ||
32 | -// throw new IllegalArgumentException("缺少后缀名"); | ||
33 | -// } | ||
34 | 26 | ||
35 | uploadFile(file, fileInfo,filePath); | 27 | uploadFile(file, fileInfo,filePath); |
36 | 28 | ||
37 | -// fileInfo.setSource(fileType().name());// 设置文件来源 | ||
38 | -// getFileDao().save(fileInfo);// 将文件信息保存到数据库 | ||
39 | -// // 本地保存文件 | ||
40 | -// FileUtil.saveFile(file,fileInfo.getPath()); | ||
41 | -// log.info("上传文件:{}", fileInfo); | ||
42 | - | ||
43 | return fileInfo; | 29 | return fileInfo; |
44 | } | 30 | } |
45 | 31 |
cloud/fIle-center/src/main/java/com/sincere/file/service/impl/AliyunOssServiceImpl.java
1 | package com.sincere.file.service.impl; | 1 | package com.sincere.file.service.impl; |
2 | 2 | ||
3 | import com.aliyun.oss.OSSClient; | 3 | import com.aliyun.oss.OSSClient; |
4 | +import com.aliyun.oss.model.OSSObject; | ||
4 | import com.aliyun.oss.model.PutObjectResult; | 5 | import com.aliyun.oss.model.PutObjectResult; |
5 | import com.sincere.file.model.FileInfo; | 6 | import com.sincere.file.model.FileInfo; |
6 | import org.springframework.beans.factory.annotation.Autowired; | 7 | import org.springframework.beans.factory.annotation.Autowired; |
@@ -42,9 +43,19 @@ public class AliyunOssServiceImpl extends AbstractFileService { | @@ -42,9 +43,19 @@ public class AliyunOssServiceImpl extends AbstractFileService { | ||
42 | 43 | ||
43 | @Override | 44 | @Override |
44 | protected void uploadFile(MultipartFile file, FileInfo fileInfo,String filePath) throws Exception { | 45 | protected void uploadFile(MultipartFile file, FileInfo fileInfo,String filePath) throws Exception { |
45 | - String fileName = UUID.randomUUID().toString()+"."+fileInfo.getName().split("\\.")[1]; | ||
46 | - ossClient.putObject(bucketName, filePath+"/"+fileName, file.getInputStream()); | ||
47 | - fileInfo.setUrl(domain+"/" +filePath+ "/" + fileName); | 46 | +// String fileName = UUID.randomUUID().toString()+"."+fileInfo.getName().split("\\.")[1]; |
47 | + String fileName = fileInfo.getName(); | ||
48 | + String keyObjectName = filePath+"/"+fileName; | ||
49 | + | ||
50 | +// boolean isExist = ossClient.doesObjectExist(bucketName, keyObjectName); | ||
51 | +// if (isExist){ | ||
52 | +// OSSObject ossObject = ossClient.getObject(bucketName,keyObjectName); | ||
53 | +// keyObjectName = filePath+"/"+fileName.split("\\.")[0]+; | ||
54 | +// } | ||
55 | + | ||
56 | + ossClient.putObject(bucketName, keyObjectName, file.getInputStream()); | ||
57 | + | ||
58 | + fileInfo.setUrl(domain+"/" +keyObjectName); | ||
48 | } | 59 | } |
49 | 60 | ||
50 | @Override | 61 | @Override |
cloud/getaway/src/main/resources/application.yml
@@ -62,6 +62,13 @@ spring: | @@ -62,6 +62,13 @@ spring: | ||
62 | - Path=/dahua/** | 62 | - Path=/dahua/** |
63 | filters: | 63 | filters: |
64 | - StripPrefix=1 | 64 | - StripPrefix=1 |
65 | + - id: haikangserver | ||
66 | + # uri: lb://dahua | ||
67 | + uri: http://121.40.109.21:9898 | ||
68 | + predicates: | ||
69 | + - Path=/haikang/** | ||
70 | + filters: | ||
71 | + - StripPrefix=1 | ||
65 | # default-filters: | 72 | # default-filters: |
66 | # - DedupeResponseHeader=Access-Control-Allow-Origin, RETAIN_UNIQUE | 73 | # - DedupeResponseHeader=Access-Control-Allow-Origin, RETAIN_UNIQUE |
67 | # discovery: | 74 | # discovery: |
@@ -85,4 +92,4 @@ ribbon: | @@ -85,4 +92,4 @@ ribbon: | ||
85 | 92 | ||
86 | 93 | ||
87 | url: | 94 | url: |
88 | - ignored: /SmartCampusWebApi/**,/authserver/**,/NewSmartCampus/**,/file-center/**,/dahua/** | ||
89 | \ No newline at end of file | 95 | \ No newline at end of file |
96 | + ignored: /SmartCampusWebApi/**,/authserver/**,/NewSmartCampus/**,/file-center/**,/dahua/**,/haikang/** | ||
90 | \ No newline at end of file | 97 | \ No newline at end of file |
cloud/haikang/src/main/java/com/sincere/haikang/SchduleTask.java
@@ -44,7 +44,7 @@ public class SchduleTask { | @@ -44,7 +44,7 @@ public class SchduleTask { | ||
44 | /** | 44 | /** |
45 | * 定时任务,取更新的学生信息 | 45 | * 定时任务,取更新的学生信息 |
46 | */ | 46 | */ |
47 | - @Scheduled(fixedRate = 5000) | 47 | +// @Scheduled(fixedRate = 5000) |
48 | public synchronized void getUpdateStudentInfo() { | 48 | public synchronized void getUpdateStudentInfo() { |
49 | try { | 49 | try { |
50 | 50 |
cloud/haikang/src/main/java/com/sincere/haikang/async/SendUserAsync.java
@@ -8,13 +8,18 @@ import com.sincere.haikang.dao.DeviceDao; | @@ -8,13 +8,18 @@ import com.sincere.haikang.dao.DeviceDao; | ||
8 | import com.sincere.haikang.utils.FileUtils; | 8 | import com.sincere.haikang.utils.FileUtils; |
9 | import org.springframework.beans.factory.annotation.Autowired; | 9 | import org.springframework.beans.factory.annotation.Autowired; |
10 | import org.springframework.beans.factory.annotation.Value; | 10 | import org.springframework.beans.factory.annotation.Value; |
11 | +import org.springframework.http.ResponseEntity; | ||
11 | import org.springframework.scheduling.annotation.Async; | 12 | import org.springframework.scheduling.annotation.Async; |
12 | import org.springframework.stereotype.Component; | 13 | import org.springframework.stereotype.Component; |
13 | import org.springframework.util.StringUtils; | 14 | import org.springframework.util.StringUtils; |
15 | +import org.springframework.web.client.RestTemplate; | ||
14 | 16 | ||
15 | import java.io.File; | 17 | import java.io.File; |
16 | import java.io.FileOutputStream; | 18 | import java.io.FileOutputStream; |
19 | +import java.text.SimpleDateFormat; | ||
20 | +import java.util.Date; | ||
17 | import java.util.List; | 21 | import java.util.List; |
22 | +import java.util.Random; | ||
18 | 23 | ||
19 | @Component | 24 | @Component |
20 | public class SendUserAsync { | 25 | public class SendUserAsync { |
@@ -141,4 +146,6 @@ public class SendUserAsync { | @@ -141,4 +146,6 @@ public class SendUserAsync { | ||
141 | 146 | ||
142 | } | 147 | } |
143 | 148 | ||
149 | + | ||
150 | + | ||
144 | } | 151 | } |
cloud/haikang/src/main/java/com/sincere/haikang/bean/SmsBean.java
0 → 100644
@@ -0,0 +1,105 @@ | @@ -0,0 +1,105 @@ | ||
1 | +package com.sincere.haikang.bean; | ||
2 | + | ||
3 | +import io.swagger.annotations.ApiModel; | ||
4 | + | ||
5 | +@ApiModel | ||
6 | +public class SmsBean { | ||
7 | + | ||
8 | + private String LoginName = "13095656162"; | ||
9 | + private String MessageContent ="你好,五一快乐"; | ||
10 | + private String MessageType = "2"; | ||
11 | + private String Password = "yxt_123456"; | ||
12 | + private String ScheduleTime = ""; | ||
13 | + private String SerialNumber = ""; | ||
14 | + private String SpCode ="13095656162"; | ||
15 | + private String UserNumber=""; | ||
16 | + private String f= "1"; | ||
17 | + | ||
18 | + | ||
19 | + public String getLoginName() { | ||
20 | + return LoginName; | ||
21 | + } | ||
22 | + | ||
23 | + public void setLoginName(String loginName) { | ||
24 | + LoginName = loginName; | ||
25 | + } | ||
26 | + | ||
27 | + public String getMessageContent() { | ||
28 | + return MessageContent; | ||
29 | + } | ||
30 | + | ||
31 | + public void setMessageContent(String messageContent) { | ||
32 | + MessageContent = messageContent; | ||
33 | + } | ||
34 | + | ||
35 | + public String getMessageType() { | ||
36 | + return MessageType; | ||
37 | + } | ||
38 | + | ||
39 | + public void setMessageType(String messageType) { | ||
40 | + MessageType = messageType; | ||
41 | + } | ||
42 | + | ||
43 | + public String getPassword() { | ||
44 | + return Password; | ||
45 | + } | ||
46 | + | ||
47 | + public void setPassword(String password) { | ||
48 | + Password = password; | ||
49 | + } | ||
50 | + | ||
51 | + public String getScheduleTime() { | ||
52 | + return ScheduleTime; | ||
53 | + } | ||
54 | + | ||
55 | + public void setScheduleTime(String scheduleTime) { | ||
56 | + ScheduleTime = scheduleTime; | ||
57 | + } | ||
58 | + | ||
59 | + public String getSerialNumber() { | ||
60 | + return SerialNumber; | ||
61 | + } | ||
62 | + | ||
63 | + public void setSerialNumber(String serialNumber) { | ||
64 | + SerialNumber = serialNumber; | ||
65 | + } | ||
66 | + | ||
67 | + public String getSpCode() { | ||
68 | + return SpCode; | ||
69 | + } | ||
70 | + | ||
71 | + public void setSpCode(String spCode) { | ||
72 | + SpCode = spCode; | ||
73 | + } | ||
74 | + | ||
75 | + public String getUserNumber() { | ||
76 | + return UserNumber; | ||
77 | + } | ||
78 | + | ||
79 | + public void setUserNumber(String userNumber) { | ||
80 | + UserNumber = userNumber; | ||
81 | + } | ||
82 | + | ||
83 | + public String getF() { | ||
84 | + return f; | ||
85 | + } | ||
86 | + | ||
87 | + public void setF(String f) { | ||
88 | + this.f = f; | ||
89 | + } | ||
90 | + | ||
91 | + @Override | ||
92 | + public String toString() { | ||
93 | + return "SmsBean{" + | ||
94 | + "LoginName='" + LoginName + '\'' + | ||
95 | + ", MessageContent='" + MessageContent + '\'' + | ||
96 | + ", MessageType='" + MessageType + '\'' + | ||
97 | + ", Password='" + Password + '\'' + | ||
98 | + ", ScheduleTime='" + ScheduleTime + '\'' + | ||
99 | + ", SerialNumber='" + SerialNumber + '\'' + | ||
100 | + ", SpCode='" + SpCode + '\'' + | ||
101 | + ", UserNumber='" + UserNumber + '\'' + | ||
102 | + ", f='" + f + '\'' + | ||
103 | + '}'; | ||
104 | + } | ||
105 | +} |
cloud/haikang/src/main/java/com/sincere/haikang/control/SmsControl.java
1 | package com.sincere.haikang.control; | 1 | package com.sincere.haikang.control; |
2 | 2 | ||
3 | +import com.sincere.haikang.bean.SmsBean; | ||
3 | import com.sincere.haikang.bean.StudentBean; | 4 | import com.sincere.haikang.bean.StudentBean; |
4 | import com.sincere.haikang.utils.EncodeUtils; | 5 | import com.sincere.haikang.utils.EncodeUtils; |
6 | +import com.sincere.haikang.utils.FileUtils; | ||
5 | import com.sincere.haikang.utils.SmsHttpUtils; | 7 | import com.sincere.haikang.utils.SmsHttpUtils; |
6 | import io.swagger.annotations.Api; | 8 | import io.swagger.annotations.Api; |
7 | import io.swagger.annotations.ApiImplicitParam; | 9 | import io.swagger.annotations.ApiImplicitParam; |
8 | -import org.springframework.web.bind.annotation.RequestMapping; | ||
9 | -import org.springframework.web.bind.annotation.RequestMethod; | ||
10 | -import org.springframework.web.bind.annotation.RequestParam; | ||
11 | -import org.springframework.web.bind.annotation.RestController; | 10 | +import org.springframework.boot.actuate.trace.http.HttpTrace; |
11 | +import org.springframework.util.MultiValueMap; | ||
12 | +import org.springframework.web.bind.annotation.*; | ||
12 | 13 | ||
13 | import java.io.IOException; | 14 | import java.io.IOException; |
14 | import java.io.UnsupportedEncodingException; | 15 | import java.io.UnsupportedEncodingException; |
@@ -20,17 +21,38 @@ import java.util.*; | @@ -20,17 +21,38 @@ import java.util.*; | ||
20 | @RequestMapping(value = "sms/*") | 21 | @RequestMapping(value = "sms/*") |
21 | public class SmsControl { | 22 | public class SmsControl { |
22 | 23 | ||
23 | - @RequestMapping(value = "sendMsg", method = RequestMethod.GET) | 24 | + |
25 | + @RequestMapping(value = "sendMsg", method = RequestMethod.GET,produces="application/json;charset=UTF-8") | ||
26 | + @ResponseBody | ||
24 | @ApiImplicitParam(name = "ExtendAccessNum",required = false) | 27 | @ApiImplicitParam(name = "ExtendAccessNum",required = false) |
25 | public String sendMsg(@RequestParam("SpCode") String SpCode, @RequestParam("LoginName") String LoginName, @RequestParam("Password") String Password | 28 | public String sendMsg(@RequestParam("SpCode") String SpCode, @RequestParam("LoginName") String LoginName, @RequestParam("Password") String Password |
26 | , @RequestParam("MessageContent") String MessageContent, @RequestParam("MessageType") String MessageType | 29 | , @RequestParam("MessageContent") String MessageContent, @RequestParam("MessageType") String MessageType |
27 | , @RequestParam("UserNumber") String UserNumber, @RequestParam("SerialNumber") String SerialNumber | 30 | , @RequestParam("UserNumber") String UserNumber, @RequestParam("SerialNumber") String SerialNumber |
28 | , @RequestParam("ScheduleTime") String ScheduleTime, String ExtendAccessNum | 31 | , @RequestParam("ScheduleTime") String ScheduleTime, String ExtendAccessNum |
29 | , @RequestParam("f") String f) { | 32 | , @RequestParam("f") String f) { |
30 | - | 33 | + System.out.println("接口请求"); |
31 | return sendSms(SpCode, LoginName, Password, MessageContent, MessageType, UserNumber, SerialNumber, ScheduleTime, ExtendAccessNum, f); | 34 | return sendSms(SpCode, LoginName, Password, MessageContent, MessageType, UserNumber, SerialNumber, ScheduleTime, ExtendAccessNum, f); |
35 | +// return "success"; | ||
36 | + } | ||
37 | + | ||
38 | + @PostMapping(value = "sendMsgs") | ||
39 | + public String sendMags(@RequestBody SmsBean smsBean){ | ||
40 | + System.out.println("接口请求POST:"+smsBean.toString()); | ||
41 | + return sendSms(smsBean.getSpCode(), smsBean.getLoginName(), smsBean.getPassword(), | ||
42 | + smsBean.getMessageContent(), smsBean.getMessageType(), smsBean.getUserNumber(), smsBean.getSerialNumber(), | ||
43 | + smsBean.getScheduleTime(), "", smsBean.getF()); | ||
44 | + | ||
32 | } | 45 | } |
33 | 46 | ||
47 | +// @PostMapping(value = "sendMsg") | ||
48 | +// public String sendMsg(@RequestBody MultiValueMap<String,String> multiValueMap){ | ||
49 | +// | ||
50 | +// String SpCode = multiValueMap. | ||
51 | +// | ||
52 | +// | ||
53 | +// } | ||
54 | + | ||
55 | + | ||
34 | private String sendSms(String spCode, String loginName, String password, String messageContent, String messageType, String userNumber, String serialNumber, String scheduleTime, String extendAccessNum, String f) { | 56 | private String sendSms(String spCode, String loginName, String password, String messageContent, String messageType, String userNumber, String serialNumber, String scheduleTime, String extendAccessNum, String f) { |
35 | String url = "http://ytx.zj165.com:9098/api/send"; | 57 | String url = "http://ytx.zj165.com:9098/api/send"; |
36 | Map<String, Object> params = initSmsParams(spCode, loginName, password, messageContent, messageType, userNumber, serialNumber, scheduleTime, extendAccessNum, f); | 58 | Map<String, Object> params = initSmsParams(spCode, loginName, password, messageContent, messageType, userNumber, serialNumber, scheduleTime, extendAccessNum, f); |
@@ -38,9 +60,12 @@ public class SmsControl { | @@ -38,9 +60,12 @@ public class SmsControl { | ||
38 | try { | 60 | try { |
39 | result = SmsHttpUtils.doGet(url, params); | 61 | result = SmsHttpUtils.doGet(url, params); |
40 | } catch (IOException e) { | 62 | } catch (IOException e) { |
63 | + FileUtils.getInstance().writeLogs(String.format("GET短信发送的响应失败【%s】",e.toString()),FileUtils.liantong); | ||
41 | e.printStackTrace(); | 64 | e.printStackTrace(); |
42 | } | 65 | } |
43 | System.out.println(String.format("GET短信发送的响应报文【%s】",result)+" messageContent:"+messageContent); | 66 | System.out.println(String.format("GET短信发送的响应报文【%s】",result)+" messageContent:"+messageContent); |
67 | + | ||
68 | + FileUtils.getInstance().writeLogs(String.format("GET短信发送的响应报文【%s】",result),FileUtils.liantong); | ||
44 | return result; | 69 | return result; |
45 | } | 70 | } |
46 | 71 |
cloud/haikang/src/main/java/com/sincere/haikang/utils/FileUtils.java
@@ -36,6 +36,8 @@ public class FileUtils { | @@ -36,6 +36,8 @@ public class FileUtils { | ||
36 | 36 | ||
37 | public static String yichangtime = "上报异常时间.txt";//学校id记录表 | 37 | public static String yichangtime = "上报异常时间.txt";//学校id记录表 |
38 | 38 | ||
39 | + public static String liantong = "联通短信.txt";//学校id记录表 | ||
40 | + | ||
39 | public static FileUtils getInstance() { | 41 | public static FileUtils getInstance() { |
40 | if (null == fileUtils) { | 42 | if (null == fileUtils) { |
41 | synchronized (FileUtils.class) { | 43 | synchronized (FileUtils.class) { |
cloud/haikang/src/main/resources/application.yaml
cloud/haikangface/src/main/java/com/sincere/haikangface/CMSServer.java
@@ -509,7 +509,8 @@ public class CMSServer implements ApplicationRunner { | @@ -509,7 +509,8 @@ public class CMSServer implements ApplicationRunner { | ||
509 | int err = hCEhomeSS.NET_ESS_GetLastError(); | 509 | int err = hCEhomeSS.NET_ESS_GetLastError(); |
510 | System.out.println("NET_ESS_ClientDoUpload失败,错误号:" + err); | 510 | System.out.println("NET_ESS_ClientDoUpload失败,错误号:" + err); |
511 | } else { | 511 | } else { |
512 | - url = "http://120.26.116.253:" + 8081 + new String(szUrl).trim(); | 512 | +// url = "http://120.26.116.253:" + 8081 + new String(szUrl).trim(); |
513 | + url = "http://114.55.30.100:" + 8081 + new String(szUrl).trim(); | ||
513 | // System.err.println("NET_ESS_ClientDoUpload成功!:" + url); | 514 | // System.err.println("NET_ESS_ClientDoUpload成功!:" + url); |
514 | } | 515 | } |
515 | hCEhomeSS.NET_ESS_DestroyClient(client);//释放资源 | 516 | hCEhomeSS.NET_ESS_DestroyClient(client);//释放资源 |
cloud/haikangface/src/main/java/com/sincere/haikangface/async/SendUserAsync.java
@@ -44,11 +44,6 @@ public class SendUserAsync { | @@ -44,11 +44,6 @@ public class SendUserAsync { | ||
44 | //1、检测图片是否合格 | 44 | //1、检测图片是否合格 |
45 | boolean check = true; | 45 | boolean check = true; |
46 | if (check) {//合格 | 46 | if (check) {//合格 |
47 | - try { | ||
48 | - CompressPic.CompressPic(srcFile, picUrl); | ||
49 | - } catch (Exception e) { | ||
50 | - e.printStackTrace(); | ||
51 | - } | ||
52 | //根据设备是5603 还是新设备 | 47 | //根据设备是5603 还是新设备 |
53 | String employeeNo = ""; | 48 | String employeeNo = ""; |
54 | if (deviceId.contains("ymzx")||deviceId.contains("5607")||deviceId.contains("5671")||deviceId.contains("5604")){ | 49 | if (deviceId.contains("ymzx")||deviceId.contains("5607")||deviceId.contains("5671")||deviceId.contains("5604")){ |
cloud/haikangface/src/main/java/com/sincere/haikangface/control/UserControl.java
@@ -59,6 +59,7 @@ public class UserControl { | @@ -59,6 +59,7 @@ public class UserControl { | ||
59 | @RequestParam("endTime") String endTime, @RequestParam("validTimeEnabled") int validTimeEnabled, @RequestParam("userType") String userType) { | 59 | @RequestParam("endTime") String endTime, @RequestParam("validTimeEnabled") int validTimeEnabled, @RequestParam("userType") String userType) { |
60 | 60 | ||
61 | try { | 61 | try { |
62 | + | ||
62 | if (filePath.contains(".jpg")) filePath = filePath.replace(".jpg", ".png"); | 63 | if (filePath.contains(".jpg")) filePath = filePath.replace(".jpg", ".png"); |
63 | if (new File(filePath.trim()).exists()) { | 64 | if (new File(filePath.trim()).exists()) { |
64 | return sendImg(filePath, deviceId, card, name, userType); | 65 | return sendImg(filePath, deviceId, card, name, userType); |
@@ -74,11 +75,10 @@ public class UserControl { | @@ -74,11 +75,10 @@ public class UserControl { | ||
74 | } | 75 | } |
75 | 76 | ||
76 | private boolean sendImg(String filePath, String deviceId, String card, String name, String userType) { | 77 | private boolean sendImg(String filePath, String deviceId, String card, String name, String userType) { |
77 | - long time = System.currentTimeMillis(); | ||
78 | - String startTime = new SimpleDateFormat("yyyy-MM-dd HH:mm:dd").format(new Date()); | 78 | + String startTime = new SimpleDateFormat("yyyy-MM-dd HH:mm:ss").format(new Date()); |
79 | Calendar calendar = Calendar.getInstance(); | 79 | Calendar calendar = Calendar.getInstance(); |
80 | calendar.add(Calendar.YEAR, 10); | 80 | calendar.add(Calendar.YEAR, 10); |
81 | - String endTime = new SimpleDateFormat("yyyy-MM-dd HH:mm:dd").format(calendar.getTime()); | 81 | + String endTime = new SimpleDateFormat("yyyy-MM-dd HH:mm:ss").format(calendar.getTime()); |
82 | 82 | ||
83 | String targetPath = FileUtils.picPathComp + new File(filePath).getName(); | 83 | String targetPath = FileUtils.picPathComp + new File(filePath).getName(); |
84 | try { | 84 | try { |
@@ -88,10 +88,19 @@ public class UserControl { | @@ -88,10 +88,19 @@ public class UserControl { | ||
88 | } else {//单图发送 | 88 | } else {//单图发送 |
89 | isPiliang = 1; | 89 | isPiliang = 1; |
90 | } | 90 | } |
91 | + | ||
92 | + try { | ||
93 | + CompressPic.CompressPic(filePath, targetPath); | ||
94 | + } catch (Exception e) { | ||
95 | + e.printStackTrace(); | ||
96 | + } | ||
97 | + | ||
98 | + FileUtils.getInstance().writeLogs("startTime:" + startTime + "---endTime:" + endTime, "下发参数"); | ||
91 | if (cmsServer.getIsDeviceOnline(deviceId)) | 99 | if (cmsServer.getIsDeviceOnline(deviceId)) |
100 | + | ||
92 | sendUserAsync.sendStuToHaiKang(filePath, targetPath, Long.parseLong(getCard(card), 16) + "", startTime, endTime, 1, name, deviceId, userType, isPiliang); | 101 | sendUserAsync.sendStuToHaiKang(filePath, targetPath, Long.parseLong(getCard(card), 16) + "", startTime, endTime, 1, name, deviceId, userType, isPiliang); |
93 | else { | 102 | else { |
94 | - sendUserAsync.uploadImgs(filePath, card, name, deviceId, startTime, endTime, 1, userType); | 103 | + sendUserAsync.uploadImgs(targetPath, card, name, deviceId, startTime, endTime, 1, userType); |
95 | } | 104 | } |
96 | // System.out.println("time:" + (System.currentTimeMillis() - time) / 1000); | 105 | // System.out.println("time:" + (System.currentTimeMillis() - time) / 1000); |
97 | return true; | 106 | return true; |
@@ -118,21 +127,57 @@ public class UserControl { | @@ -118,21 +127,57 @@ public class UserControl { | ||
118 | String[] devStrs = devices.split(","); | 127 | String[] devStrs = devices.split(","); |
119 | 128 | ||
120 | File[] imgStrs = new File(imgPath).listFiles(); | 129 | File[] imgStrs = new File(imgPath).listFiles(); |
130 | + String schoolId = null; | ||
131 | + | ||
132 | + logger.error("sendImg2Devices:{}",images2Ddevices.toString()); | ||
121 | 133 | ||
122 | if (null != imgStrs) { | 134 | if (null != imgStrs) { |
123 | for (int i = 0; i < imgStrs.length; i++) { | 135 | for (int i = 0; i < imgStrs.length; i++) { |
124 | 136 | ||
125 | File filePath = imgStrs[i];//图片路径 | 137 | File filePath = imgStrs[i];//图片路径 |
126 | if (filePath.exists()) { | 138 | if (filePath.exists()) { |
139 | + | ||
127 | String studentCode = filePath.getName().split("\\.")[0]; | 140 | String studentCode = filePath.getName().split("\\.")[0]; |
128 | - StudentBean studentBean = userDao.getStudent_NumWitdCode(studentCode); | ||
129 | - if (null != studentBean) { | ||
130 | - for (int j = 0; j < devStrs.length; j++) { | ||
131 | - String devId = devStrs[j]; | ||
132 | - sendUserAsync.uploadImgs(filePath.getAbsolutePath(), studentBean.getStudent_num(), studentBean.getName(), devId, startTime, endTime, 1, images2Ddevices.getUserType()); | 141 | + |
142 | + String targetPath = FileUtils.picPathComp + filePath.getName(); | ||
143 | + | ||
144 | + try { | ||
145 | + CompressPic.CompressPic(filePath.getAbsolutePath(), targetPath); | ||
146 | + } catch (Exception e) { | ||
147 | + e.printStackTrace(); | ||
148 | + } | ||
149 | + /** | ||
150 | + * 下发给不同设备 | ||
151 | + */ | ||
152 | + for (int j = 0; j < devStrs.length; j++) { | ||
153 | + String devId = devStrs[j]; | ||
154 | + if (schoolId == null) schoolId = userDao.getSchoolIdWithDevId(devId); | ||
155 | + | ||
156 | + StudentBean studentBean = null; | ||
157 | + String card = null; | ||
158 | + String name = null; | ||
159 | + | ||
160 | + if (images2Ddevices.getUserType().equals("1")) {//老师 | ||
161 | + studentBean = userDao.getTeacherWithstudentcode(studentCode, schoolId); | ||
162 | + card = studentBean.getTeacher_num(); | ||
163 | + name = studentBean.getName(); | ||
164 | + } else if (images2Ddevices.getUserType().equals("2")) {//学生 | ||
165 | + studentBean = userDao.getStudentWithstudentcode(studentCode, schoolId); | ||
166 | + card = studentBean.getStudent_num(); | ||
167 | + name = studentBean.getName(); | ||
168 | + } | ||
169 | + | ||
170 | + if (null != studentBean) { | ||
171 | + if (cmsServer.getIsDeviceOnline(devId)) { | ||
172 | + | ||
173 | + sendUserAsync.sendStuToHaiKang(filePath.getAbsolutePath(), targetPath, Long.parseLong(getCard(card), 16) + "", startTime, endTime, 1, name, devId, images2Ddevices.getUserType(), 0); | ||
174 | + | ||
175 | + } else { | ||
176 | + sendUserAsync.uploadImgs(targetPath, card, name, devId, startTime, endTime, 1, images2Ddevices.getUserType()); | ||
177 | + } | ||
178 | + } else { | ||
179 | + logger.error("学生对象不存在"); | ||
133 | } | 180 | } |
134 | - } else { | ||
135 | - logger.error("学生对象不存在"); | ||
136 | } | 181 | } |
137 | 182 | ||
138 | } | 183 | } |
cloud/haikangface/src/main/java/com/sincere/haikangface/dao/UserDao.java
@@ -211,6 +211,6 @@ public interface UserDao { | @@ -211,6 +211,6 @@ public interface UserDao { | ||
211 | "where num = #{num} and school_id = #{schoolId}") | 211 | "where num = #{num} and school_id = #{schoolId}") |
212 | StudentBean getTeacherWithstudentcode(@Param("num") String num,@Param("schoolId")String schoolId); | 212 | StudentBean getTeacherWithstudentcode(@Param("num") String num,@Param("schoolId")String schoolId); |
213 | 213 | ||
214 | - @Select("select Top(1) * from SZ_V_School_Student where studentcode = #{studentcode}") | ||
215 | - StudentBean getStudent_NumWitdCode(@Param("studentcode") String studentcode); | 214 | + @Select("select school_id from SZ_Attendance where clint_id = #{devId}") |
215 | + String getSchoolIdWithDevId(@Param("devId") String devId); | ||
216 | } | 216 | } |
cloud/haikangface/src/main/java/com/sincere/haikangface/utils/CompressPic.java
@@ -16,7 +16,7 @@ import java.io.InputStream; | @@ -16,7 +16,7 @@ import java.io.InputStream; | ||
16 | public class CompressPic { | 16 | public class CompressPic { |
17 | 17 | ||
18 | public static String CompressPic(String srcPath, String targetPath) throws Exception { | 18 | public static String CompressPic(String srcPath, String targetPath) throws Exception { |
19 | - double cutPercent = 0.1; | 19 | + double cutPercent = 0.2; |
20 | File file = new File(srcPath.trim()); | 20 | File file = new File(srcPath.trim()); |
21 | FileInputStream fileInputStreamSrc = new FileInputStream(file); | 21 | FileInputStream fileInputStreamSrc = new FileInputStream(file); |
22 | BufferedImage bufferedImage = ImageIO.read(fileInputStreamSrc); | 22 | BufferedImage bufferedImage = ImageIO.read(fileInputStreamSrc); |
cloud/haikangface/src/main/java/com/sincere/haikangface/utils/SendRecoderUtils.java
@@ -23,7 +23,7 @@ public class SendRecoderUtils { | @@ -23,7 +23,7 @@ public class SendRecoderUtils { | ||
23 | * @param userDao | 23 | * @param userDao |
24 | */ | 24 | */ |
25 | 25 | ||
26 | - public void sendSuccess(SendRecordDao sendRecordDao, String card, String faceUrl, String deviceId, UserDao userDao, String userType) { | 26 | + public synchronized void sendSuccess(SendRecordDao sendRecordDao, String card, String faceUrl, String deviceId, UserDao userDao, String userType) { |
27 | // BigInteger bigInteger = new BigInteger(card); | 27 | // BigInteger bigInteger = new BigInteger(card); |
28 | long lon = Long.parseLong(card); | 28 | long lon = Long.parseLong(card); |
29 | String resultCard = getCard(String.format("%08x", lon)).toUpperCase(); | 29 | String resultCard = getCard(String.format("%08x", lon)).toUpperCase(); |
@@ -43,6 +43,7 @@ public class SendRecoderUtils { | @@ -43,6 +43,7 @@ public class SendRecoderUtils { | ||
43 | break; | 43 | break; |
44 | } | 44 | } |
45 | if (null != studentBean) { | 45 | if (null != studentBean) { |
46 | + | ||
46 | String time = new SimpleDateFormat("yyyy-MM-dd HH:mm:ss").format(new Date()); | 47 | String time = new SimpleDateFormat("yyyy-MM-dd HH:mm:ss").format(new Date()); |
47 | String schoolName = userDao.getSchoolName(studentBean.getSchool_id() + ""); | 48 | String schoolName = userDao.getSchoolName(studentBean.getSchool_id() + ""); |
48 | List<SendRecordBean> sendRecordBeans = sendRecordDao.getSuccessIsExitStu(deviceId, resultCard); | 49 | List<SendRecordBean> sendRecordBeans = sendRecordDao.getSuccessIsExitStu(deviceId, resultCard); |
@@ -61,8 +62,9 @@ public class SendRecoderUtils { | @@ -61,8 +62,9 @@ public class SendRecoderUtils { | ||
61 | sendRecordDao.addFaceSuccess(customerId, deviceId, resultCard, studentBean.getName(), time, schoolName, | 62 | sendRecordDao.addFaceSuccess(customerId, deviceId, resultCard, studentBean.getName(), time, schoolName, |
62 | faceUrl, studentBean.getSchool_id(), Integer.parseInt(userType), 18); | 63 | faceUrl, studentBean.getSchool_id(), Integer.parseInt(userType), 18); |
63 | } else { | 64 | } else { |
64 | - sendRecordDao.updateFaceSuccess(deviceId, resultCard, time, faceUrl); | 65 | + sendRecordDao.updateFaceSuccess(deviceId, resultCard, time, faceUrl,studentBean.getName(),customerId); |
65 | } | 66 | } |
67 | + FileUtils.getInstance().writeLogs(studentBean.toString()+"\r\n"+resultCard,"下发成功记录"); | ||
66 | //删除下发失败表中的数据 | 68 | //删除下发失败表中的数据 |
67 | sendRecordDao.deleteFaceFail(resultCard, deviceId); | 69 | sendRecordDao.deleteFaceFail(resultCard, deviceId); |
68 | } else { | 70 | } else { |
@@ -81,7 +83,7 @@ public class SendRecoderUtils { | @@ -81,7 +83,7 @@ public class SendRecoderUtils { | ||
81 | * @param deviceId | 83 | * @param deviceId |
82 | * @param userDao | 84 | * @param userDao |
83 | */ | 85 | */ |
84 | - public void sendFail(SendRecordDao sendRecordDao, String card, String faceUrl, String deviceId, UserDao userDao, String content, String userType) { | 86 | + public synchronized void sendFail(SendRecordDao sendRecordDao, String card, String faceUrl, String deviceId, UserDao userDao, String content, String userType) { |
85 | // BigInteger bigInteger = new BigInteger(card); | 87 | // BigInteger bigInteger = new BigInteger(card); |
86 | long lon = Long.parseLong(card); | 88 | long lon = Long.parseLong(card); |
87 | String resultCard = getCard(String.format("%08x", lon)).toUpperCase(); | 89 | String resultCard = getCard(String.format("%08x", lon)).toUpperCase(); |
cloud/haikangface/src/main/java/com/sincere/haikangface/xiananDao/SendRecordDao.java
@@ -67,8 +67,8 @@ public interface SendRecordDao { | @@ -67,8 +67,8 @@ public interface SendRecordDao { | ||
67 | @Select("select * from Face_SendSuccess where deviceID = #{deviceID} and Num = #{Num}") | 67 | @Select("select * from Face_SendSuccess where deviceID = #{deviceID} and Num = #{Num}") |
68 | List<SendRecordBean> getSuccessIsExitStu(@Param("deviceID") String deviceId, @Param("Num") String card); | 68 | List<SendRecordBean> getSuccessIsExitStu(@Param("deviceID") String deviceId, @Param("Num") String card); |
69 | 69 | ||
70 | - @Update("update Face_SendSuccess set time = #{time},imgPath=#{faceUrl} where deviceID = #{deviceID} and Num =#{Num}") | ||
71 | - void updateFaceSuccess(@Param("deviceID") String deviceId, @Param("Num") String card, @Param("time") String time,@Param("faceUrl")String faceUrl); | 70 | + @Update("update Face_SendSuccess set time = #{time},imgPath= #{faceUrl},Name = #{Name},customerid = #{customerid} where deviceID = #{deviceID} and Num = #{Num}") |
71 | + void updateFaceSuccess(@Param("deviceID") String deviceId, @Param("Num") String card, @Param("time") String time,@Param("faceUrl")String faceUrl,@Param("Name")String name,@Param("customerid")String customerid); | ||
72 | 72 | ||
73 | @Update("update Face_SendFail set time = #{time},failContent = #{content} where deviceID = #{deviceID} and Num =#{Num}") | 73 | @Update("update Face_SendFail set time = #{time},failContent = #{content} where deviceID = #{deviceID} and Num =#{Num}") |
74 | void updateFaceFail(@Param("deviceID") String deviceId, @Param("Num") String card, @Param("time") String time,@Param("content")String content); | 74 | void updateFaceFail(@Param("deviceID") String deviceId, @Param("Num") String card, @Param("time") String time,@Param("content")String content); |
cloud/mypulsar/src/main/java/com/example/mypulsar/MyRunnerableInt.java
@@ -10,6 +10,7 @@ import com.example.mypulsar.message.MessageVO; | @@ -10,6 +10,7 @@ import com.example.mypulsar.message.MessageVO; | ||
10 | import com.example.mypulsar.mq.AESBase64Utils; | 10 | import com.example.mypulsar.mq.AESBase64Utils; |
11 | import com.example.mypulsar.mq.MessageHandlerTask; | 11 | import com.example.mypulsar.mq.MessageHandlerTask; |
12 | import com.example.mypulsar.mq.MqConsumer; | 12 | import com.example.mypulsar.mq.MqConsumer; |
13 | +import com.example.mypulsar.task.SchduledTasks; | ||
13 | import com.example.mypulsar.utils.ControlUtils; | 14 | import com.example.mypulsar.utils.ControlUtils; |
14 | import com.example.mypulsar.utils.PulsarConsumerPoolFactory; | 15 | import com.example.mypulsar.utils.PulsarConsumerPoolFactory; |
15 | import com.example.mypulsar.utils.ThreadPoolFactory; | 16 | import com.example.mypulsar.utils.ThreadPoolFactory; |
@@ -39,14 +40,6 @@ public class MyRunnerableInt implements ApplicationRunner { | @@ -39,14 +40,6 @@ public class MyRunnerableInt implements ApplicationRunner { | ||
39 | 40 | ||
40 | @Override | 41 | @Override |
41 | public void run(ApplicationArguments args) throws Exception { | 42 | public void run(ApplicationArguments args) throws Exception { |
42 | - | ||
43 | -// DeviceBean deviceBean = new DeviceBean(); | ||
44 | -// deviceBean.setValue("30"); | ||
45 | -// deviceBean.setDevId("6c5c38c2e431d01eeei3to"); | ||
46 | -// calOpenOrCloseDevWithtemper(deviceBean); | ||
47 | - | ||
48 | -// System.out.println("running"); | ||
49 | -// initPool(); | ||
50 | initMqConsumer(); | 43 | initMqConsumer(); |
51 | } | 44 | } |
52 | 45 | ||
@@ -306,6 +299,7 @@ public class MyRunnerableInt implements ApplicationRunner { | @@ -306,6 +299,7 @@ public class MyRunnerableInt implements ApplicationRunner { | ||
306 | 299 | ||
307 | ControlUtils.getInstance(deviceDao).conTemper(calDevContrls, deviceBean); | 300 | ControlUtils.getInstance(deviceDao).conTemper(calDevContrls, deviceBean); |
308 | } | 301 | } |
302 | + | ||
309 | } | 303 | } |
310 | 304 | ||
311 | 305 | ||
@@ -316,9 +310,11 @@ public class MyRunnerableInt implements ApplicationRunner { | @@ -316,9 +310,11 @@ public class MyRunnerableInt implements ApplicationRunner { | ||
316 | */ | 310 | */ |
317 | private void calOpenOrCloseDevWithtemper(DeviceBean deviceBean) { | 311 | private void calOpenOrCloseDevWithtemper(DeviceBean deviceBean) { |
318 | 312 | ||
319 | - List<CalDevContrl> calDevContrls = deviceDao.getCalDevContrlWidthDevId(deviceBean.getDevId()); | ||
320 | - if (null != calDevContrls && calDevContrls.size() > 0) | ||
321 | - ControlUtils.getInstance(deviceDao).conTemper(calDevContrls, deviceBean); | 313 | + ControlUtils.tempDevices.put(deviceBean.getDevId(), Integer.valueOf(deviceBean.getValue())); |
314 | + | ||
315 | +// List<CalDevContrl> calDevContrls = deviceDao.getCalDevContrlWidthDevId(deviceBean.getDevId()); | ||
316 | +// if (null != calDevContrls && calDevContrls.size() > 0) | ||
317 | +// ControlUtils.getInstance(deviceDao).conTemper(calDevContrls, deviceBean); | ||
322 | 318 | ||
323 | } | 319 | } |
324 | 320 |
cloud/mypulsar/src/main/java/com/example/mypulsar/MypulsarApplication.java
@@ -9,10 +9,12 @@ import org.springframework.cloud.client.discovery.EnableDiscoveryClient; | @@ -9,10 +9,12 @@ import org.springframework.cloud.client.discovery.EnableDiscoveryClient; | ||
9 | import org.springframework.cloud.netflix.eureka.server.EnableEurekaServer; | 9 | import org.springframework.cloud.netflix.eureka.server.EnableEurekaServer; |
10 | import org.springframework.context.annotation.Bean; | 10 | import org.springframework.context.annotation.Bean; |
11 | import org.springframework.jdbc.core.JdbcTemplate; | 11 | import org.springframework.jdbc.core.JdbcTemplate; |
12 | +import org.springframework.scheduling.annotation.EnableScheduling; | ||
12 | 13 | ||
13 | @SpringBootApplication | 14 | @SpringBootApplication |
14 | @MapperScan("com.example.mypulsar.dao") | 15 | @MapperScan("com.example.mypulsar.dao") |
15 | @EnableDiscoveryClient | 16 | @EnableDiscoveryClient |
17 | +@EnableScheduling | ||
16 | public class MypulsarApplication extends SpringBootServletInitializer { | 18 | public class MypulsarApplication extends SpringBootServletInitializer { |
17 | 19 | ||
18 | 20 |
cloud/mypulsar/src/main/java/com/example/mypulsar/bean/Result.java
0 → 100644
@@ -0,0 +1,23 @@ | @@ -0,0 +1,23 @@ | ||
1 | +package com.example.mypulsar.bean; | ||
2 | + | ||
3 | +import java.io.Serializable; | ||
4 | + | ||
5 | +public class Result implements Serializable { | ||
6 | + | ||
7 | + private ResultData data; | ||
8 | + | ||
9 | + public ResultData getData() { | ||
10 | + return data; | ||
11 | + } | ||
12 | + | ||
13 | + public void setData(ResultData data) { | ||
14 | + this.data = data; | ||
15 | + } | ||
16 | + | ||
17 | + @Override | ||
18 | + public String toString() { | ||
19 | + return "Result{" + | ||
20 | + "data=" + data + | ||
21 | + '}'; | ||
22 | + } | ||
23 | +} |
cloud/mypulsar/src/main/java/com/example/mypulsar/bean/ResultData.java
0 → 100644
@@ -0,0 +1,23 @@ | @@ -0,0 +1,23 @@ | ||
1 | +package com.example.mypulsar.bean; | ||
2 | + | ||
3 | +import java.io.Serializable; | ||
4 | + | ||
5 | +public class ResultData implements Serializable { | ||
6 | + | ||
7 | + private boolean online; | ||
8 | + | ||
9 | + public boolean isOnline() { | ||
10 | + return online; | ||
11 | + } | ||
12 | + | ||
13 | + public void setOnline(boolean online) { | ||
14 | + this.online = online; | ||
15 | + } | ||
16 | + | ||
17 | + @Override | ||
18 | + public String toString() { | ||
19 | + return "ResultData{" + | ||
20 | + "online=" + online + | ||
21 | + '}'; | ||
22 | + } | ||
23 | +} |
cloud/mypulsar/src/main/java/com/example/mypulsar/bean/Wl_Attendace.java
0 → 100644
@@ -0,0 +1,34 @@ | @@ -0,0 +1,34 @@ | ||
1 | +package com.example.mypulsar.bean; | ||
2 | + | ||
3 | +import java.io.Serializable; | ||
4 | + | ||
5 | +public class Wl_Attendace implements Serializable { | ||
6 | + | ||
7 | + private String clint_id; | ||
8 | + | ||
9 | + private String name; | ||
10 | + | ||
11 | + public String getClint_id() { | ||
12 | + return clint_id; | ||
13 | + } | ||
14 | + | ||
15 | + public void setClint_id(String clint_id) { | ||
16 | + this.clint_id = clint_id; | ||
17 | + } | ||
18 | + | ||
19 | + public String getName() { | ||
20 | + return name; | ||
21 | + } | ||
22 | + | ||
23 | + public void setName(String name) { | ||
24 | + this.name = name; | ||
25 | + } | ||
26 | + | ||
27 | + @Override | ||
28 | + public String toString() { | ||
29 | + return "Wl_Attendace{" + | ||
30 | + "clint_id='" + clint_id + '\'' + | ||
31 | + ", name='" + name + '\'' + | ||
32 | + '}'; | ||
33 | + } | ||
34 | +} |
cloud/mypulsar/src/main/java/com/example/mypulsar/dao/DeviceDao.java
@@ -3,6 +3,7 @@ package com.example.mypulsar.dao; | @@ -3,6 +3,7 @@ package com.example.mypulsar.dao; | ||
3 | import com.example.mypulsar.bean.CalDevBeContrl; | 3 | import com.example.mypulsar.bean.CalDevBeContrl; |
4 | import com.example.mypulsar.bean.CalDevContrl; | 4 | import com.example.mypulsar.bean.CalDevContrl; |
5 | import com.example.mypulsar.bean.DeviceBean; | 5 | import com.example.mypulsar.bean.DeviceBean; |
6 | +import com.example.mypulsar.bean.Wl_Attendace; | ||
6 | import org.apache.ibatis.annotations.*; | 7 | import org.apache.ibatis.annotations.*; |
7 | import org.springframework.stereotype.Repository; | 8 | import org.springframework.stereotype.Repository; |
8 | 9 | ||
@@ -45,4 +46,34 @@ public interface DeviceDao { | @@ -45,4 +46,34 @@ public interface DeviceDao { | ||
45 | 46 | ||
46 | @Select("select * from CalDevBeContrl where State = 1 and Id = #{Id}") | 47 | @Select("select * from CalDevBeContrl where State = 1 and Id = #{Id}") |
47 | CalDevBeContrl getCalDevBeControl(@Param("Id") String Id); | 48 | CalDevBeContrl getCalDevBeControl(@Param("Id") String Id); |
49 | + | ||
50 | + @Select("select * from CalDevContrl where Devid = #{Devid} and Status = 1 and ModelType = 9") | ||
51 | + List<CalDevContrl> getTempCalWitdDevid(@Param("Devid") String devId); | ||
52 | + | ||
53 | + | ||
54 | + @Update("update WL_LinkageMode set Field = #{Field} where id = #{id}") | ||
55 | + void updateWL_LinkageModeWithId(@Param("id")int id,@Param("Field")String Field); | ||
56 | + | ||
57 | + @Select("select clint_id\n" + | ||
58 | + "from WL_Attendance where school_id = 1085 and clint_type = 12 and state = 1") | ||
59 | + List<String> getHWDEvices(int i); | ||
60 | + | ||
61 | + @Select("select TOP(1) ConValue from CalDevBeContrl where State = 1 and ConDevId = #{ConDevId}") | ||
62 | + String getConBeValue(@Param("ConDevId")String ConDevId); | ||
63 | + | ||
64 | + | ||
65 | + @Select("select Top(1) InUserTime from CalDevContrl where Status = 1") | ||
66 | + String getInuserTime(); | ||
67 | + | ||
68 | + @Select("select clint_id from WL_Attendance where State = 1 and school_id = 1085 and clint_type = 12") | ||
69 | + List<Wl_Attendace> getHWIds(); | ||
70 | + | ||
71 | + | ||
72 | + @Select("select * from WL_Attendance where state = 1 and school_id = 1085") | ||
73 | + List<Wl_Attendace> getWL_AttendanceIds(); | ||
74 | + | ||
75 | + | ||
76 | + @Select("select Top(1)name from WL_Attendance where State = 1 and school_id = 1085 and clint_type = 12 and clint_id =#{clint_id} order by intime desc") | ||
77 | + String getWLName(@Param("clint_id")String clint_id); | ||
78 | + | ||
48 | } | 79 | } |
cloud/mypulsar/src/main/java/com/example/mypulsar/task/SchduledTasks.java
0 → 100644
@@ -0,0 +1,155 @@ | @@ -0,0 +1,155 @@ | ||
1 | +package com.example.mypulsar.task; | ||
2 | + | ||
3 | +import com.alibaba.fastjson.JSON; | ||
4 | +import com.alibaba.fastjson.JSONArray; | ||
5 | +import com.alibaba.fastjson.JSONObject; | ||
6 | +import com.example.mypulsar.bean.Wl_Attendace; | ||
7 | +import com.example.mypulsar.dao.DeviceDao; | ||
8 | +import com.example.mypulsar.utils.HttpUtil; | ||
9 | +import org.slf4j.Logger; | ||
10 | +import org.slf4j.LoggerFactory; | ||
11 | +import org.springframework.beans.factory.annotation.Autowired; | ||
12 | +import org.springframework.scheduling.annotation.Scheduled; | ||
13 | +import org.springframework.stereotype.Component; | ||
14 | + | ||
15 | +import java.io.*; | ||
16 | +import java.text.ParseException; | ||
17 | +import java.text.SimpleDateFormat; | ||
18 | +import java.util.*; | ||
19 | + | ||
20 | +@Component | ||
21 | +public class SchduledTasks { | ||
22 | + | ||
23 | + @Autowired | ||
24 | + DeviceDao deviceDao; | ||
25 | + | ||
26 | + private Logger logger = LoggerFactory.getLogger(SchduledTasks.class); | ||
27 | + | ||
28 | + public static Map<String, Date> conDevMap = new HashMap<>();//存储被控制的设备 | ||
29 | + | ||
30 | + private SimpleDateFormat simpleDateFormat = new SimpleDateFormat("yyyy-MM-dd HH:mm:ss"); | ||
31 | + | ||
32 | + SimpleDateFormat simpleDateFormat1 = new SimpleDateFormat("HH:mm"); | ||
33 | + SimpleDateFormat simpleDateFormat2 = new SimpleDateFormat("HH:mm"); | ||
34 | + | ||
35 | + private String closeModel = "{\"mode\":\"0\",\"power\":\"0\",\"remote_id\":\"%s\",\"remote_index\":\"11272\",\"temp\":\"26\",\"wind\":\"0\"}"; | ||
36 | + | ||
37 | + boolean isClose = false; | ||
38 | + | ||
39 | + @Scheduled(fixedRate = 15000) | ||
40 | + public void closeAttend() { | ||
41 | + | ||
42 | + logger.error("定时任务执行中......" + conDevMap.size()); | ||
43 | + | ||
44 | + Iterator iterator = conDevMap.entrySet().iterator(); | ||
45 | + | ||
46 | + while (iterator.hasNext()) { | ||
47 | + | ||
48 | + | ||
49 | + Map.Entry entry = (Map.Entry) iterator.next(); | ||
50 | + String conBeDeviceId = (String) entry.getKey(); | ||
51 | + | ||
52 | + logger.error("在线设备:" + conBeDeviceId + "---在线时间:" + simpleDateFormat.format(entry.getValue())); | ||
53 | + | ||
54 | + Date date = (Date) entry.getValue(); | ||
55 | + System.out.println("更新设备时间差值:" + ((new Date().getTime()) - date.getTime())); | ||
56 | + if (((new Date().getTime()) - date.getTime()) > 10 * 60 * 1000) {//大于十分钟后关闭设备 | ||
57 | + | ||
58 | + String conValue = getRemoteId(deviceDao.getConBeValue(conBeDeviceId)); | ||
59 | + String name = deviceDao.getWLName(conBeDeviceId); | ||
60 | + HttpUtil.addAirCode(String.format(closeModel, conValue), conBeDeviceId,name); | ||
61 | + conDevMap.remove(conBeDeviceId); | ||
62 | + } | ||
63 | + | ||
64 | + } | ||
65 | + | ||
66 | + int hour = Calendar.getInstance().get(Calendar.HOUR_OF_DAY); | ||
67 | + | ||
68 | + | ||
69 | + System.out.println("关闭设备:" + hour); | ||
70 | + | ||
71 | + String inuserTime = deviceDao.getInuserTime(); | ||
72 | + JSONArray jsonArray = JSON.parseArray(inuserTime); | ||
73 | + | ||
74 | + if (null==jsonArray)return; | ||
75 | + if (jsonArray!=null&&jsonArray.size()==0)return; | ||
76 | + JSONObject jsonObject = jsonArray.getJSONObject(0); | ||
77 | + | ||
78 | + String startTime = jsonObject.getString("StartTime"); | ||
79 | + String endTime = jsonObject.getString("EndTime"); | ||
80 | + Date startDate = null; | ||
81 | + try { | ||
82 | + startDate = simpleDateFormat1.parse(startTime); | ||
83 | + } catch (ParseException e) { | ||
84 | + e.printStackTrace(); | ||
85 | + } | ||
86 | + Date endDate = null; | ||
87 | + try { | ||
88 | + endDate = simpleDateFormat1.parse(endTime); | ||
89 | + } catch (ParseException e) { | ||
90 | + e.printStackTrace(); | ||
91 | + } | ||
92 | + Date date = null; | ||
93 | + try { | ||
94 | + date = simpleDateFormat2.parse(new Date().getHours() + ":" + new Date().getMinutes()); | ||
95 | + } catch (ParseException e) { | ||
96 | + e.printStackTrace(); | ||
97 | + } | ||
98 | + | ||
99 | + long starTime = startDate.getTime(); | ||
100 | + long indexTime = date.getTime(); | ||
101 | + long entTime = endDate.getTime()+ 10 * 60 * 1000;//延迟十分钟 | ||
102 | + | ||
103 | + if (!isClose) { | ||
104 | + | ||
105 | + if (indexTime < starTime || indexTime >= entTime) { | ||
106 | + closeAllDevice(); | ||
107 | + } | ||
108 | + | ||
109 | + | ||
110 | + } | ||
111 | + | ||
112 | + if (indexTime < entTime && indexTime >= starTime) { | ||
113 | + isClose = false; | ||
114 | + } | ||
115 | + | ||
116 | + | ||
117 | + } | ||
118 | + | ||
119 | + private void closeAllDevice() { | ||
120 | + | ||
121 | + isClose = true; | ||
122 | + List<Wl_Attendace> deviceIds = deviceDao.getHWIds(); | ||
123 | + System.out.println("关闭设备" + deviceIds.toString()); | ||
124 | + for (int i = 0; i < deviceIds.size(); i++) { | ||
125 | + String deviceId = deviceIds.get(i).getClint_id(); | ||
126 | + String conValue = getRemoteId(deviceDao.getConBeValue(deviceId)); | ||
127 | + String devName = deviceIds.get(i).getName(); | ||
128 | + | ||
129 | + HttpUtil.addAirCode(String.format(closeModel, conValue), deviceId,devName); | ||
130 | + } | ||
131 | + | ||
132 | + } | ||
133 | + | ||
134 | + /** | ||
135 | + * 获取遥控器索引 | ||
136 | + * | ||
137 | + * @param conValue | ||
138 | + */ | ||
139 | + private String getRemoteId(String conValue) { | ||
140 | + | ||
141 | + try { | ||
142 | + System.out.println("conValue:"+conValue); | ||
143 | + JSONObject jsonObject = JSON.parseObject(conValue); | ||
144 | + if (null==jsonObject)return ""; | ||
145 | + String remote_id = jsonObject.getString("remote_id"); | ||
146 | + return remote_id; | ||
147 | + } catch (Exception e) { | ||
148 | + e.printStackTrace(); | ||
149 | + } | ||
150 | + return ""; | ||
151 | + } | ||
152 | + | ||
153 | + | ||
154 | + | ||
155 | +} |
cloud/mypulsar/src/main/java/com/example/mypulsar/utils/ControlUtils.java
@@ -2,10 +2,12 @@ package com.example.mypulsar.utils; | @@ -2,10 +2,12 @@ package com.example.mypulsar.utils; | ||
2 | 2 | ||
3 | import com.example.mypulsar.bean.*; | 3 | import com.example.mypulsar.bean.*; |
4 | import com.example.mypulsar.dao.DeviceDao; | 4 | import com.example.mypulsar.dao.DeviceDao; |
5 | +import com.example.mypulsar.task.SchduledTasks; | ||
5 | import org.apache.pulsar.shade.com.google.gson.Gson; | 6 | import org.apache.pulsar.shade.com.google.gson.Gson; |
6 | import org.springframework.boot.configurationprocessor.json.JSONArray; | 7 | import org.springframework.boot.configurationprocessor.json.JSONArray; |
7 | import org.springframework.boot.configurationprocessor.json.JSONException; | 8 | import org.springframework.boot.configurationprocessor.json.JSONException; |
8 | import org.springframework.boot.configurationprocessor.json.JSONObject; | 9 | import org.springframework.boot.configurationprocessor.json.JSONObject; |
10 | +import org.springframework.util.StringUtils; | ||
9 | 11 | ||
10 | import java.text.ParseException; | 12 | import java.text.ParseException; |
11 | import java.text.SimpleDateFormat; | 13 | import java.text.SimpleDateFormat; |
@@ -19,6 +21,11 @@ public class ControlUtils { | @@ -19,6 +21,11 @@ public class ControlUtils { | ||
19 | 21 | ||
20 | private DeviceDao deviceDao; | 22 | private DeviceDao deviceDao; |
21 | 23 | ||
24 | + /** | ||
25 | + * 存储温度感应器和对应温度 | ||
26 | + */ | ||
27 | + public static Map<String, Integer> tempDevices = new HashMap<>(); | ||
28 | + | ||
22 | public static ControlUtils getInstance(DeviceDao deviceDao) { | 29 | public static ControlUtils getInstance(DeviceDao deviceDao) { |
23 | if (null == controlUtils) { | 30 | if (null == controlUtils) { |
24 | synchronized (ControlUtils.class) { | 31 | synchronized (ControlUtils.class) { |
@@ -42,7 +49,8 @@ public class ControlUtils { | @@ -42,7 +49,8 @@ public class ControlUtils { | ||
42 | * @param deviceBean 温度传感器对象 | 49 | * @param deviceBean 温度传感器对象 |
43 | */ | 50 | */ |
44 | public void conTemper(List<CalDevContrl> calDevContrls, DeviceBean deviceBean) { | 51 | public void conTemper(List<CalDevContrl> calDevContrls, DeviceBean deviceBean) { |
45 | - | 52 | + System.out.println("传感器感应设备:deviceBean:" + deviceBean.toString()); |
53 | + FileUtils.getInstance().writeLogs(deviceBean.toString()+"\r\n"+calDevContrls.toString(),FileUtils.mypulsar); | ||
46 | for (CalDevContrl cal : | 54 | for (CalDevContrl cal : |
47 | calDevContrls) { | 55 | calDevContrls) { |
48 | 56 | ||
@@ -52,11 +60,12 @@ public class ControlUtils { | @@ -52,11 +60,12 @@ public class ControlUtils { | ||
52 | // System.out.println("inUseTime:"+inUseTime); | 60 | // System.out.println("inUseTime:"+inUseTime); |
53 | try { | 61 | try { |
54 | JSONArray jsonArray = new JSONArray(inUseTime); | 62 | JSONArray jsonArray = new JSONArray(inUseTime); |
55 | - | 63 | + FileUtils.getInstance().writeLogs(jsonArray.toString(),FileUtils.mypulsar); |
56 | for (int i = 0; i < jsonArray.length(); i++) { | 64 | for (int i = 0; i < jsonArray.length(); i++) { |
57 | JSONObject jsonObject = jsonArray.getJSONObject(i); | 65 | JSONObject jsonObject = jsonArray.getJSONObject(i); |
58 | 66 | ||
59 | - int week = jsonObject.getInt("Week"); | 67 | + String weekStr = jsonObject.getString("Week"); |
68 | + String[] weeks = weekStr.split(","); | ||
60 | 69 | ||
61 | String startTime = jsonObject.getString("StartTime"); | 70 | String startTime = jsonObject.getString("StartTime"); |
62 | 71 | ||
@@ -65,33 +74,36 @@ public class ControlUtils { | @@ -65,33 +74,36 @@ public class ControlUtils { | ||
65 | SimpleDateFormat simpleDateFormat = new SimpleDateFormat("HH:mm"); | 74 | SimpleDateFormat simpleDateFormat = new SimpleDateFormat("HH:mm"); |
66 | SimpleDateFormat simpleDateFormat1 = new SimpleDateFormat("HH:mm:ss"); | 75 | SimpleDateFormat simpleDateFormat1 = new SimpleDateFormat("HH:mm:ss"); |
67 | 76 | ||
68 | - int indexWeek = Calendar.getInstance().get(Calendar.DAY_OF_WEEK); | ||
69 | - | ||
70 | - if (week == indexWeek) { | ||
71 | - | ||
72 | - Date startDate = simpleDateFormat.parse(startTime); | ||
73 | - Date endDate = simpleDateFormat.parse(endTime); | ||
74 | - Date date = simpleDateFormat1.parse(new Date().getHours() + ":" + new Date().getMinutes() + ":" + new Date().getSeconds()); | ||
75 | - | ||
76 | - long starTime = startDate.getTime(); | ||
77 | -// System.out.println("startDate:" + starTime); | ||
78 | -// System.out.println("endDate:" + endDate.getTime()); | ||
79 | -// System.out.println("date:" + date.getTime()); | ||
80 | - | ||
81 | - if (date.getTime() < endDate.getTime() && date.getTime() > starTime) { | ||
82 | - //比较器类型 | ||
83 | - int compreType = cal.getCompreType(); | ||
84 | - | ||
85 | - switch (compreType) { | ||
86 | - case 1://固定值 | ||
87 | - calCompre(cal,deviceBean); | ||
88 | - break; | ||
89 | - case 2://当天日期 | ||
90 | - | ||
91 | - break; | 77 | + int indexWeek = Calendar.getInstance().get(Calendar.DAY_OF_WEEK)-1; |
78 | + FileUtils.getInstance().writeLogs(weekStr.toString()+"当前周:"+indexWeek,FileUtils.mypulsar); | ||
79 | + for (int j = 0; j < weeks.length; j++) { | ||
80 | + int week = Integer.parseInt(weeks[j]); | ||
81 | + if (week == indexWeek) { | ||
82 | + | ||
83 | + Date startDate = simpleDateFormat.parse(startTime); | ||
84 | + Date endDate = simpleDateFormat.parse(endTime); | ||
85 | + Date date = simpleDateFormat1.parse(new Date().getHours() + ":" + new Date().getMinutes() + ":" + new Date().getSeconds()); | ||
86 | + | ||
87 | + long starTime = startDate.getTime(); | ||
88 | + long indexTime = date.getTime(); | ||
89 | + long entTime = endDate.getTime(); | ||
90 | + System.out.println("时间比对:starTime:" + starTime + "-----indexTime:" + indexTime + "----entTime:" + entTime); | ||
91 | + FileUtils.getInstance().writeLogs("开始时间:"+(indexTime < entTime)+"结束时间:"+(indexTime > starTime),FileUtils.mypulsar); | ||
92 | + if (indexTime < entTime && indexTime > starTime) { | ||
93 | + //比较器类型 | ||
94 | + int compreType = cal.getCompreType(); | ||
95 | + | ||
96 | + switch (compreType) { | ||
97 | + case 1://固定值 | ||
98 | + calCompre(cal, deviceBean); | ||
99 | + break; | ||
100 | + case 2://当天日期 | ||
101 | + | ||
102 | + break; | ||
103 | + } | ||
92 | } | 104 | } |
93 | - } | ||
94 | 105 | ||
106 | + } | ||
95 | } | 107 | } |
96 | 108 | ||
97 | // System.out.println("jsonObject:" + jsonObject.toString()); | 109 | // System.out.println("jsonObject:" + jsonObject.toString()); |
@@ -108,19 +120,26 @@ public class ControlUtils { | @@ -108,19 +120,26 @@ public class ControlUtils { | ||
108 | } | 120 | } |
109 | 121 | ||
110 | /** | 122 | /** |
111 | - * @param cal 联动模板 | 123 | + * @param cal 人体感应器 |
112 | * @param deviceBean 控制设备 | 124 | * @param deviceBean 控制设备 |
113 | */ | 125 | */ |
114 | private void calCompre(CalDevContrl cal, DeviceBean deviceBean) { | 126 | private void calCompre(CalDevContrl cal, DeviceBean deviceBean) { |
115 | 127 | ||
116 | - | ||
117 | int thrsoldValue = 0; | 128 | int thrsoldValue = 0; |
118 | 129 | ||
130 | + FileUtils.getInstance().writeLogs(cal.toString(),"caldevCntrol.txt"); | ||
131 | + | ||
119 | if (cal.getModelType() == 10) {//人体感应 | 132 | if (cal.getModelType() == 10) {//人体感应 |
120 | if (cal.getThreValue().equals("有人")) thrsoldValue = 1; | 133 | if (cal.getThreValue().equals("有人")) thrsoldValue = 1; |
121 | - else thrsoldValue = 0; | 134 | + else { |
135 | + thrsoldValue = 0; | ||
136 | + if (cal.getThreValue().equals("无人")) return; | ||
137 | + //无人的时候不做处理 , 在定时服务中处理 | ||
138 | +// return; | ||
139 | + } | ||
122 | } else { | 140 | } else { |
123 | - thrsoldValue = Integer.parseInt(cal.getThreValue());//设定的阈值 | 141 | + //温度传感器 不直接计算 |
142 | +// thrsoldValue = Integer.parseInt(cal.getThreValue());//设定的阈值 | ||
124 | } | 143 | } |
125 | 144 | ||
126 | int value = Integer.parseInt(deviceBean.getValue());//实际的值 | 145 | int value = Integer.parseInt(deviceBean.getValue());//实际的值 |
@@ -132,8 +151,13 @@ public class ControlUtils { | @@ -132,8 +151,13 @@ public class ControlUtils { | ||
132 | break; | 151 | break; |
133 | case 2://等于 | 152 | case 2://等于 |
134 | 153 | ||
135 | - if (value == thrsoldValue) | ||
136 | - startDevice(cal);//开启联动的设备 | 154 | + if (value == thrsoldValue)//有人的时候会执行 |
155 | + { | ||
156 | + boolean temp = calTemp(cal.getAssDevice()); | ||
157 | + System.out.println("--------------------温度是否达标:" + temp + "-------------"); | ||
158 | + if (temp)//温度符合要求 | ||
159 | + startDevice(cal);//开启联动的设备 | ||
160 | + } | ||
137 | 161 | ||
138 | break; | 162 | break; |
139 | case 3://小于 | 163 | case 3://小于 |
@@ -152,6 +176,75 @@ public class ControlUtils { | @@ -152,6 +176,75 @@ public class ControlUtils { | ||
152 | } | 176 | } |
153 | 177 | ||
154 | /** | 178 | /** |
179 | + * 计算温度是否达标 | ||
180 | + * | ||
181 | + * @param assDevice | ||
182 | + */ | ||
183 | + private synchronized boolean calTemp(String assDevice) { | ||
184 | + if (!StringUtils.isEmpty(assDevice)) { | ||
185 | + String[] devices = assDevice.split(","); | ||
186 | + FileUtils.getInstance().writeLogs(assDevice+"设备数量:"+devices.length,"tempisOk.txt"); | ||
187 | + for (int i = 0; i < devices.length; i++) { | ||
188 | + | ||
189 | + String device = devices[i]; | ||
190 | + FileUtils.getInstance().writeLogs(device,"tempisOk.txt"); | ||
191 | + | ||
192 | + List<CalDevContrl> calDevContrls = deviceDao.getTempCalWitdDevid(device); | ||
193 | + | ||
194 | + for (int j = 0; j < calDevContrls.size(); j++) { | ||
195 | + String tempDevId = calDevContrls.get(j).getDevid(); | ||
196 | + if (tempDevices.containsKey(tempDevId)) {//温度记录了 | ||
197 | + | ||
198 | + int tempear = tempDevices.get(tempDevId); | ||
199 | + | ||
200 | + boolean temp = tempIsOk(tempear, calDevContrls.get(j)); | ||
201 | + if (temp)return true; | ||
202 | + | ||
203 | + } else {//沒有記錄溫度按照20度 | ||
204 | + boolean temp = tempIsOk(20, calDevContrls.get(j)); | ||
205 | + if (temp)return true; | ||
206 | + } | ||
207 | + | ||
208 | + } | ||
209 | + | ||
210 | + | ||
211 | + } | ||
212 | + | ||
213 | + } | ||
214 | + | ||
215 | + return false; | ||
216 | + } | ||
217 | + | ||
218 | + private boolean tempIsOk(int tempear, CalDevContrl calDevContrl) { | ||
219 | + | ||
220 | + FileUtils.getInstance().writeLogs(calDevContrl.toString(),"tempisOk.txt"); | ||
221 | + if (calDevContrl.getComPre() != 2) { | ||
222 | + System.out.println("溫度比較:" + tempear + " 比較的值:" + calDevContrl.getThreValue() + " 比较方式:" + calDevContrl.getComPre()); | ||
223 | + | ||
224 | + switch (calDevContrl.getComPre()) { | ||
225 | + case 1://小于 | ||
226 | + | ||
227 | + if (tempear <= Integer.parseInt(calDevContrl.getThreValue())) { | ||
228 | + return true; | ||
229 | + } | ||
230 | + | ||
231 | + break; | ||
232 | + case 3://大于 | ||
233 | + | ||
234 | + if (tempear >= Integer.parseInt(calDevContrl.getThreValue())) { | ||
235 | + return true; | ||
236 | + } | ||
237 | + | ||
238 | + break; | ||
239 | + | ||
240 | + } | ||
241 | + | ||
242 | + } | ||
243 | + | ||
244 | + return false; | ||
245 | + } | ||
246 | + | ||
247 | + /** | ||
155 | * 移除设备 | 248 | * 移除设备 |
156 | * | 249 | * |
157 | * @param calDevContrl | 250 | * @param calDevContrl |
@@ -194,7 +287,7 @@ public class ControlUtils { | @@ -194,7 +287,7 @@ public class ControlUtils { | ||
194 | 287 | ||
195 | for (int i = 0; i < calDevBeContrlList.size(); i++) { | 288 | for (int i = 0; i < calDevBeContrlList.size(); i++) { |
196 | CalDevBeContrl calDevBeContrl = calDevBeContrlList.get(i); | 289 | CalDevBeContrl calDevBeContrl = calDevBeContrlList.get(i); |
197 | - System.out.println("控制对象:" + calDevBeContrl.toString()); | 290 | +// System.out.println("控制对象:" + calDevBeContrl.toString()); |
198 | String conDevId = calDevBeContrl.getConDevId();//被控制的设备id | 291 | String conDevId = calDevBeContrl.getConDevId();//被控制的设备id |
199 | String conValue = calDevBeContrl.getConValue(); | 292 | String conValue = calDevBeContrl.getConValue(); |
200 | String conCodes = calDevBeContrl.getConCode(); | 293 | String conCodes = calDevBeContrl.getConCode(); |
@@ -213,15 +306,19 @@ public class ControlUtils { | @@ -213,15 +306,19 @@ public class ControlUtils { | ||
213 | case 3://排插 | 306 | case 3://排插 |
214 | HttpUtil.controlDev(conDevId, conCode, conValue); | 307 | HttpUtil.controlDev(conDevId, conCode, conValue); |
215 | break; | 308 | break; |
216 | - case 7://空调伴侣 | ||
217 | - HttpUtil.addAirCode(conValue, conDevId); | ||
218 | - break; | ||
219 | - case 10://开关 | ||
220 | -// HttpUtil.controlDev(conDevId, conCode, conValue); | ||
221 | - HttpUtil.addAirCode(conValue, conDevId); | 309 | + case 9://温度传感器 |
222 | break; | 310 | break; |
311 | + case 10://人体感应触发空调开关 | ||
223 | case 12://万能遥控器 | 312 | case 12://万能遥控器 |
224 | - HttpUtil.addAirCode(conValue, conDevId); | 313 | + if (SchduledTasks.conDevMap.containsKey(conDevId)) {//设备已开,更新时间 |
314 | + SchduledTasks.conDevMap.put(conDevId, new Date()); | ||
315 | + System.out.println("更新设备时间"); | ||
316 | + } else {//开启设备 | ||
317 | + SchduledTasks.conDevMap.put(conDevId, new Date()); | ||
318 | + System.out.println("开启设备"); | ||
319 | + String name = deviceDao.getWLName(conDevId); | ||
320 | + HttpUtil.addAirCode(conValue, conDevId,name); | ||
321 | + } | ||
225 | break; | 322 | break; |
226 | } | 323 | } |
227 | } | 324 | } |
cloud/mypulsar/src/main/java/com/example/mypulsar/utils/FileUtils.java
0 → 100644
@@ -0,0 +1,155 @@ | @@ -0,0 +1,155 @@ | ||
1 | +package com.example.mypulsar.utils; | ||
2 | + | ||
3 | +import org.springframework.web.multipart.MultipartFile; | ||
4 | + | ||
5 | +import java.io.*; | ||
6 | +import java.text.SimpleDateFormat; | ||
7 | +import java.util.Date; | ||
8 | + | ||
9 | +/** | ||
10 | + * 日志记录、文件操作工具类 | ||
11 | + */ | ||
12 | +public class FileUtils { | ||
13 | + | ||
14 | + | ||
15 | + public static String studentcode="studentcode.txt"; | ||
16 | + public static String addAirCode = "addAirCode.txt"; | ||
17 | + private static FileUtils fileUtils; | ||
18 | + | ||
19 | + private String filePath = "./log/";//日志记录目录 | ||
20 | + | ||
21 | + public static String picPath = "./picPath/"; | ||
22 | + public static String picPathComp = "./picPath/comp/"; | ||
23 | + | ||
24 | + public static String mypulsar = "mypulsar.txt"; | ||
25 | + | ||
26 | + public static String devices = "devices.txt";//设备记录 | ||
27 | + | ||
28 | + public static String sendUserErrTxt = "senduserErr.txt";//用户下发失败记录 | ||
29 | + | ||
30 | + public static String faceSuccess = "facesuccess.txt";//用户人脸认证成功 | ||
31 | + | ||
32 | + public static String faceFail = "facefail.txt";//用户人脸认证成功 | ||
33 | + | ||
34 | + public static String facerecoder = "人脸识别成功记录.txt";//用户人脸认证成功 | ||
35 | + | ||
36 | + public static String fileName = "文件保存回调.txt";//用户下发失败记录 | ||
37 | + | ||
38 | + public static String sendUserSucTxt = "senduserSuc.txt";//用户下发成功记录 | ||
39 | + | ||
40 | + public static String qiandaoSuccess = "qiandaoSuccess.txt";//用户签到成功记录 | ||
41 | + public static String sms = "短信账号密码.txt";//用户签到成功记录 | ||
42 | + | ||
43 | + public static String qiandaoErr = "qiandaoErr.txt";//用户签到失败记录 | ||
44 | + | ||
45 | + public static String sendNodevice = "没有设备.txt";//设备没有 | ||
46 | + | ||
47 | + public static String schoolId = "学校id记录.txt";//学校id记录表 | ||
48 | + | ||
49 | + public static FileUtils getInstance() { | ||
50 | + if (null == fileUtils) { | ||
51 | + synchronized (FileUtils.class) { | ||
52 | + fileUtils = new FileUtils(); | ||
53 | + } | ||
54 | + } | ||
55 | + return fileUtils; | ||
56 | + } | ||
57 | + | ||
58 | + | ||
59 | + public FileUtils() { | ||
60 | + | ||
61 | + File filePa = new File(filePath); | ||
62 | + if (!filePa.exists()) filePa.mkdirs(); | ||
63 | + | ||
64 | + File picPath = new File(this.picPath); | ||
65 | + if (!picPath.exists())picPath.mkdirs(); | ||
66 | + | ||
67 | + File picPathComp = new File(this.picPathComp); | ||
68 | + if (!picPathComp.exists())picPathComp.mkdirs(); | ||
69 | + | ||
70 | + } | ||
71 | + | ||
72 | + | ||
73 | + /** | ||
74 | + * @param content 日志内容 | ||
75 | + * @param fileName 文件名字 | ||
76 | + */ | ||
77 | + public void writeLogs(String content, String fileName) { | ||
78 | + | ||
79 | + String datePath = new SimpleDateFormat("yyyy-MM-dd").format(new Date()); | ||
80 | + | ||
81 | + File path = new File(filePath+datePath+"/"); | ||
82 | + if (!path.exists())path.mkdirs(); | ||
83 | + | ||
84 | + String time = new SimpleDateFormat("HH").format(new Date()); | ||
85 | + File logPath = new File(path, time+"_"+fileName); | ||
86 | + | ||
87 | + try { | ||
88 | +// System.out.println("logPath:" + logPath.getAbsolutePath()); | ||
89 | + if (!logPath.exists()) logPath.createNewFile(); | ||
90 | + | ||
91 | + FileOutputStream fileOutputStream = new FileOutputStream(logPath, true);//true表示文件后面续写 | ||
92 | + | ||
93 | + String writeContent = new SimpleDateFormat("yyyy-MM-dd HH:mm:ss").format(new Date()) | ||
94 | + + " " + content + "\r\n"; | ||
95 | + | ||
96 | + OutputStreamWriter outputStreamWriter = new OutputStreamWriter(fileOutputStream, "UTF-8"); | ||
97 | + | ||
98 | + outputStreamWriter.write(writeContent); | ||
99 | + | ||
100 | + outputStreamWriter.write("\r\n"); | ||
101 | + | ||
102 | + outputStreamWriter.close(); | ||
103 | + | ||
104 | + } catch (FileNotFoundException e) { | ||
105 | + e.printStackTrace(); | ||
106 | + } catch (UnsupportedEncodingException e) { | ||
107 | + e.printStackTrace(); | ||
108 | + } catch (IOException e) { | ||
109 | + e.printStackTrace(); | ||
110 | + } | ||
111 | + | ||
112 | + | ||
113 | + } | ||
114 | + | ||
115 | + | ||
116 | + /** | ||
117 | + * | ||
118 | + * @param file 文件 | ||
119 | + * @param path 文件存放路径 | ||
120 | + * @param fileName 源文件名 | ||
121 | + * @return | ||
122 | + */ | ||
123 | + public static String upload(MultipartFile file, String path, String fileName){ | ||
124 | + | ||
125 | + // 生成新的文件名 | ||
126 | + //String realPath = path + "/" + FileNameUtils.getFileName(fileName); | ||
127 | + | ||
128 | + //使用原文件名 | ||
129 | + String realPath = path + "/" + fileName; | ||
130 | + | ||
131 | + File dest = new File(realPath); | ||
132 | + | ||
133 | + //判断文件父目录是否存在 | ||
134 | + if(!dest.getParentFile().exists()){ | ||
135 | + dest.getParentFile().mkdir(); | ||
136 | + } | ||
137 | + | ||
138 | + try { | ||
139 | + //保存文件 | ||
140 | + file.transferTo(dest); | ||
141 | + return realPath; | ||
142 | + } catch (IllegalStateException e) { | ||
143 | + // TODO Auto-generated catch block | ||
144 | + e.printStackTrace(); | ||
145 | + return ""; | ||
146 | + } catch (IOException e) { | ||
147 | + // TODO Auto-generated catch block | ||
148 | + e.printStackTrace(); | ||
149 | + return ""; | ||
150 | + } | ||
151 | + | ||
152 | + } | ||
153 | + | ||
154 | + | ||
155 | +} |
cloud/mypulsar/src/main/java/com/example/mypulsar/utils/HttpUtil.java
@@ -112,7 +112,7 @@ public class HttpUtil { | @@ -112,7 +112,7 @@ public class HttpUtil { | ||
112 | 112 | ||
113 | String responseEntity = restTemplate.postForObject(url, tuYaCommand, String.class); | 113 | String responseEntity = restTemplate.postForObject(url, tuYaCommand, String.class); |
114 | 114 | ||
115 | - System.out.println("tuYaCommand:" + tuYaCommand.toString()+"----deviceId:"+deviceId); | 115 | + System.out.println("tuYaCommand:" + tuYaCommand.toString() + "----deviceId:" + deviceId); |
116 | System.out.println("responseEntity:" + responseEntity); | 116 | System.out.println("responseEntity:" + responseEntity); |
117 | return responseEntity.equals("1"); | 117 | return responseEntity.equals("1"); |
118 | } | 118 | } |
@@ -133,17 +133,27 @@ public class HttpUtil { | @@ -133,17 +133,27 @@ public class HttpUtil { | ||
133 | } | 133 | } |
134 | 134 | ||
135 | 135 | ||
136 | - public static String addAirCode(String conValue, String conDevId) { | 136 | + /** |
137 | + * 控制设备 | ||
138 | + * | ||
139 | + * @param conValue 控制指令 | ||
140 | + * @param conDevId 被控制设备id | ||
141 | + * @param conDevName 设备名称 | ||
142 | + * @return | ||
143 | + */ | ||
144 | + public static String addAirCode(String conValue, String conDevId, String conDevName) { | ||
137 | 145 | ||
138 | 146 | ||
139 | String url = String.format("http://120.26.116.253:5555/TuYa/%s/addAirCode", conDevId); | 147 | String url = String.format("http://120.26.116.253:5555/TuYa/%s/addAirCode", conDevId); |
140 | RestTemplate restTemplate = new RestTemplate(); | 148 | RestTemplate restTemplate = new RestTemplate(); |
141 | 149 | ||
142 | TuYaAirCondition tuYaAirCondition = new TuYaAirCondition(); | 150 | TuYaAirCondition tuYaAirCondition = new TuYaAirCondition(); |
151 | + String power = ""; | ||
143 | try { | 152 | try { |
144 | JSONObject jsonObject = new JSONObject(conValue); | 153 | JSONObject jsonObject = new JSONObject(conValue); |
154 | + power = jsonObject.getString("power"); | ||
145 | tuYaAirCondition.setMode(jsonObject.getString("mode")); | 155 | tuYaAirCondition.setMode(jsonObject.getString("mode")); |
146 | - tuYaAirCondition.setPower(jsonObject.getString("power")); | 156 | + tuYaAirCondition.setPower(power); |
147 | tuYaAirCondition.setRemote_id(jsonObject.getString("remote_id")); | 157 | tuYaAirCondition.setRemote_id(jsonObject.getString("remote_id")); |
148 | tuYaAirCondition.setWind(jsonObject.getString("wind")); | 158 | tuYaAirCondition.setWind(jsonObject.getString("wind")); |
149 | tuYaAirCondition.setTemp(jsonObject.getString("temp")); | 159 | tuYaAirCondition.setTemp(jsonObject.getString("temp")); |
@@ -154,8 +164,10 @@ public class HttpUtil { | @@ -154,8 +164,10 @@ public class HttpUtil { | ||
154 | e.printStackTrace(); | 164 | e.printStackTrace(); |
155 | } | 165 | } |
156 | 166 | ||
157 | - System.out.println("url-------------------------------:" + url+" conValue:"+tuYaAirCondition.toString()); | 167 | + |
168 | + System.out.println("url-------------------------------:" + url + " conValue:" + tuYaAirCondition.toString()); | ||
158 | String response = restTemplate.postForObject(url, tuYaAirCondition, String.class); | 169 | String response = restTemplate.postForObject(url, tuYaAirCondition, String.class); |
170 | + FileUtils.getInstance().writeLogs(String.format("%s设备%s--控制%s",power.equals("1")?"成功":"失败",conDevName+"-"+conDevId,response),FileUtils.addAirCode); | ||
159 | System.out.println("response----------------------------------:" + response); | 171 | System.out.println("response----------------------------------:" + response); |
160 | return response; | 172 | return response; |
161 | 173 |