Commit 7677dd474ae62ea7363d3f898debc54f688d480f
1 parent
46eaf1b0
Exists in
master
海康服务调整,大华服务优化
Showing
30 changed files
with
779 additions
and
138 deletions
Show diff stats
cloud/dahua/src/main/java/com/example/dahua/DahuaApplication.java
@@ -12,6 +12,7 @@ import org.springframework.boot.autoconfigure.EnableAutoConfiguration; | @@ -12,6 +12,7 @@ import org.springframework.boot.autoconfigure.EnableAutoConfiguration; | ||
12 | import org.springframework.boot.autoconfigure.SpringBootApplication; | 12 | import org.springframework.boot.autoconfigure.SpringBootApplication; |
13 | import org.springframework.boot.autoconfigure.jdbc.DataSourceAutoConfiguration; | 13 | import org.springframework.boot.autoconfigure.jdbc.DataSourceAutoConfiguration; |
14 | import org.springframework.boot.autoconfigure.jdbc.DataSourceTransactionManagerAutoConfiguration; | 14 | import org.springframework.boot.autoconfigure.jdbc.DataSourceTransactionManagerAutoConfiguration; |
15 | +import org.springframework.boot.web.servlet.MultipartConfigFactory; | ||
15 | import org.springframework.cloud.client.discovery.EnableDiscoveryClient; | 16 | import org.springframework.cloud.client.discovery.EnableDiscoveryClient; |
16 | import org.springframework.context.annotation.Bean; | 17 | import org.springframework.context.annotation.Bean; |
17 | import org.springframework.context.annotation.Configuration; | 18 | import org.springframework.context.annotation.Configuration; |
@@ -24,6 +25,7 @@ import springfox.documentation.spi.DocumentationType; | @@ -24,6 +25,7 @@ import springfox.documentation.spi.DocumentationType; | ||
24 | import springfox.documentation.spring.web.plugins.Docket; | 25 | import springfox.documentation.spring.web.plugins.Docket; |
25 | import springfox.documentation.swagger2.annotations.EnableSwagger2; | 26 | import springfox.documentation.swagger2.annotations.EnableSwagger2; |
26 | 27 | ||
28 | +import javax.servlet.MultipartConfigElement; | ||
27 | import javax.swing.*; | 29 | import javax.swing.*; |
28 | import java.io.File; | 30 | import java.io.File; |
29 | import java.util.concurrent.Executor; | 31 | import java.util.concurrent.Executor; |
@@ -75,5 +77,15 @@ public class DahuaApplication { | @@ -75,5 +77,15 @@ public class DahuaApplication { | ||
75 | 77 | ||
76 | } | 78 | } |
77 | 79 | ||
80 | + @Bean | ||
81 | + public MultipartConfigElement multipartConfigElement() { | ||
82 | + MultipartConfigFactory factory = new MultipartConfigFactory(); | ||
83 | + //单个文件最大 | ||
84 | + factory.setMaxFileSize("10MB"); | ||
85 | + /// 设置总上传数据总大小 | ||
86 | + factory.setMaxRequestSize("50MB"); | ||
87 | + return factory.createMultipartConfig(); | ||
88 | + } | ||
89 | + | ||
78 | 90 | ||
79 | } | 91 | } |
cloud/dahua/src/main/java/com/example/dahua/async/MyScheduledTask.java
@@ -86,7 +86,7 @@ public class MyScheduledTask { | @@ -86,7 +86,7 @@ public class MyScheduledTask { | ||
86 | close(30, 97); | 86 | close(30, 97); |
87 | } | 87 | } |
88 | 88 | ||
89 | - if (hour == 6 && !isClose) { | 89 | + /* if (hour == 6 && !isClose) { |
90 | isClose = true; | 90 | isClose = true; |
91 | close(31, 479);//打开 | 91 | close(31, 479);//打开 |
92 | } | 92 | } |
@@ -94,7 +94,7 @@ public class MyScheduledTask { | @@ -94,7 +94,7 @@ public class MyScheduledTask { | ||
94 | if (hour == 22 && isClose) { | 94 | if (hour == 22 && isClose) { |
95 | isClose = false; | 95 | isClose = false; |
96 | close(30, 479);//关闭 | 96 | close(30, 479);//关闭 |
97 | - } | 97 | + }*/ |
98 | 98 | ||
99 | if (hour >= 9 && hour < 11) { | 99 | if (hour >= 9 && hour < 11) { |
100 | dealData(); | 100 | dealData(); |
cloud/dahua/src/main/java/com/example/dahua/async/SendUserInfoTask.java
@@ -10,6 +10,7 @@ import com.example.dahua.lib.NetSDKLib; | @@ -10,6 +10,7 @@ import com.example.dahua.lib.NetSDKLib; | ||
10 | import com.example.dahua.lib.ToolKits; | 10 | import com.example.dahua.lib.ToolKits; |
11 | import com.example.dahua.module.GateModule; | 11 | import com.example.dahua.module.GateModule; |
12 | import com.example.dahua.utils.FileUtils; | 12 | import com.example.dahua.utils.FileUtils; |
13 | +import com.example.dahua.utils.HttpUtils; | ||
13 | import com.example.dahua.xiananDao.SendRecordDao; | 14 | import com.example.dahua.xiananDao.SendRecordDao; |
14 | import com.sun.jna.Memory; | 15 | import com.sun.jna.Memory; |
15 | import org.springframework.beans.factory.annotation.Autowired; | 16 | import org.springframework.beans.factory.annotation.Autowired; |
@@ -44,7 +45,7 @@ public class SendUserInfoTask { | @@ -44,7 +45,7 @@ public class SendUserInfoTask { | ||
44 | SendRecordDao sendRecordDao; | 45 | SendRecordDao sendRecordDao; |
45 | 46 | ||
46 | @Async("taskExecutor") | 47 | @Async("taskExecutor") |
47 | - public void doTaskOne(String file, List<AttendanceBean> attendanceBeans, UserInfoBean userInfoBean, String schoolId, int failType) throws Exception { | 48 | + public void doTaskOne(String file, List<AttendanceBean> attendanceBeans, UserInfoBean userInfoBean, String schoolId, int failType,int userType) throws Exception { |
48 | File studentFile = new File(file); | 49 | File studentFile = new File(file); |
49 | String studentCode = studentFile.getName().split("\\.")[0]; | 50 | String studentCode = studentFile.getName().split("\\.")[0]; |
50 | //判断是否是副卡 | 51 | //判断是否是副卡 |
@@ -68,13 +69,12 @@ public class SendUserInfoTask { | @@ -68,13 +69,12 @@ public class SendUserInfoTask { | ||
68 | sendRecordBean.setImgPath(file); | 69 | sendRecordBean.setImgPath(file); |
69 | sendRecordBean.setCustomerid(userInfoBean.getStudent_id()); | 70 | sendRecordBean.setCustomerid(userInfoBean.getStudent_id()); |
70 | sendRecordBean.setFailType(failType); | 71 | sendRecordBean.setFailType(failType); |
71 | - sendUserInfoToDev(file, attendanceBeans, userInfoBean, "2", sendRecordBean); | 72 | + sendUserInfoToDev(file, attendanceBeans, userInfoBean, userType+"", sendRecordBean); |
72 | } | 73 | } |
73 | 74 | ||
74 | @Async("taskExecutor") | 75 | @Async("taskExecutor") |
75 | public void doTaskSendUserInfos(String schoolId, String clint_type, int type, int failtype) { | 76 | public void doTaskSendUserInfos(String schoolId, String clint_type, int type, int failtype) { |
76 | try { | 77 | try { |
77 | - List<AttendanceBean> attendanceBeans = userDao.getAttendanceBeans(schoolId, clint_type); | ||
78 | String filePathStudent = "E:\\wwwhtdocs\\SmartCampus\\face17e50\\School" + schoolId + "\\Student"; | 78 | String filePathStudent = "E:\\wwwhtdocs\\SmartCampus\\face17e50\\School" + schoolId + "\\Student"; |
79 | String filePathParent = "E:\\wwwhtdocs\\SmartCampus\\face17e50\\School" + schoolId + "\\Parent"; | 79 | String filePathParent = "E:\\wwwhtdocs\\SmartCampus\\face17e50\\School" + schoolId + "\\Parent"; |
80 | String filePathTeacher = "E:\\wwwhtdocs\\SmartCampus\\face17e50\\School" + schoolId + "\\Teacher"; | 80 | String filePathTeacher = "E:\\wwwhtdocs\\SmartCampus\\face17e50\\School" + schoolId + "\\Teacher"; |
@@ -156,6 +156,7 @@ public class SendUserInfoTask { | @@ -156,6 +156,7 @@ public class SendUserInfoTask { | ||
156 | 156 | ||
157 | if (type == 0 || type == 1) {//学生信息或家长信息 | 157 | if (type == 0 || type == 1) {//学生信息或家长信息 |
158 | userInfoBean = userDao.getUserInfo(schoolId, studentCode); | 158 | userInfoBean = userDao.getUserInfo(schoolId, studentCode); |
159 | + HttpUtils.uploadImgs(studentFile,schoolId,studentCode,clint_type,2); | ||
159 | } else if (type == 2) {//教师信息 | 160 | } else if (type == 2) {//教师信息 |
160 | TeacherBean teacher = userDao.getTeacher(schoolId, studentCode); | 161 | TeacherBean teacher = userDao.getTeacher(schoolId, studentCode); |
161 | if (null != teacher) { | 162 | if (null != teacher) { |
@@ -166,6 +167,7 @@ public class SendUserInfoTask { | @@ -166,6 +167,7 @@ public class SendUserInfoTask { | ||
166 | userInfoBean.setStudentcode(teacher.getNum()); | 167 | userInfoBean.setStudentcode(teacher.getNum()); |
167 | userInfoBean.setStudent_id(teacher.getTeacher_id()); | 168 | userInfoBean.setStudent_id(teacher.getTeacher_id()); |
168 | } | 169 | } |
170 | + HttpUtils.uploadImgs(studentFile,schoolId,studentCode,clint_type,1); | ||
169 | } | 171 | } |
170 | 172 | ||
171 | //判断用户是否存在 | 173 | //判断用户是否存在 |
@@ -173,7 +175,7 @@ public class SendUserInfoTask { | @@ -173,7 +175,7 @@ public class SendUserInfoTask { | ||
173 | 175 | ||
174 | } | 176 | } |
175 | 177 | ||
176 | - boolean sendResult = sendUserInfoToDev(studentFile.getAbsolutePath(), attendanceBeans, userInfoBean, userType, sendRecordBean); | 178 | +// boolean sendResult = sendUserInfoToDev(studentFile.getAbsolutePath(), attendanceBeans, userInfoBean, userType, sendRecordBean); |
177 | fileList.remove(0); | 179 | fileList.remove(0); |
178 | } | 180 | } |
179 | // System.out.println("全部下发完成:"); | 181 | // System.out.println("全部下发完成:"); |
@@ -593,8 +595,8 @@ public class SendUserInfoTask { | @@ -593,8 +595,8 @@ public class SendUserInfoTask { | ||
593 | senfaceToDahua(sendRecordBean); | 595 | senfaceToDahua(sendRecordBean); |
594 | break; | 596 | break; |
595 | case 5://下发人脸失败 | 597 | case 5://下发人脸失败 |
596 | - if (new File(sendRecordBean.getImgPath()).exists()) | ||
597 | - ImageUtils.rotatePhonePhoto(sendRecordBean.getImgPath(), 90); | 598 | +// if (new File(sendRecordBean.getImgPath()).exists()) |
599 | +// ImageUtils.rotatePhonePhoto(sendRecordBean.getImgPath(), 90); | ||
598 | senfaceToDahua(sendRecordBean); | 600 | senfaceToDahua(sendRecordBean); |
599 | break; | 601 | break; |
600 | case 7://意外失败 | 602 | case 7://意外失败 |
@@ -621,7 +623,7 @@ public class SendUserInfoTask { | @@ -621,7 +623,7 @@ public class SendUserInfoTask { | ||
621 | if (img.startsWith("http")) | 623 | if (img.startsWith("http")) |
622 | img = img.replace("http://campus.myjxt.com//", "E://wwwhtdocs/SmartCampus/"); | 624 | img = img.replace("http://campus.myjxt.com//", "E://wwwhtdocs/SmartCampus/"); |
623 | doTaskOne(img, userDao.getAttendanceBeans(String.valueOf(sendRecordBean.getSchoolId()), "22") | 625 | doTaskOne(img, userDao.getAttendanceBeans(String.valueOf(sendRecordBean.getSchoolId()), "22") |
624 | - , userInfoBean, sendRecordBean.getSchoolId() + "", sendRecordBean.getFailType()); | 626 | + , userInfoBean, sendRecordBean.getSchoolId() + "", sendRecordBean.getFailType(),sendRecordBean.getUserType()); |
625 | } | 627 | } |
626 | 628 | ||
627 | } | 629 | } |
cloud/dahua/src/main/java/com/example/dahua/bean/UploadImg.java
0 → 100644
@@ -0,0 +1,36 @@ | @@ -0,0 +1,36 @@ | ||
1 | +package com.example.dahua.bean; | ||
2 | + | ||
3 | +import org.springframework.web.bind.annotation.RequestParam; | ||
4 | + | ||
5 | +public class UploadImg { | ||
6 | + | ||
7 | +// @RequestParam("schoolId") String schoolId, @RequestParam("studentCode") String studentCode, | ||
8 | + | ||
9 | + private String schoolId; | ||
10 | + | ||
11 | + private String studentCode; | ||
12 | + | ||
13 | + public String getSchoolId() { | ||
14 | + return schoolId; | ||
15 | + } | ||
16 | + | ||
17 | + public void setSchoolId(String schoolId) { | ||
18 | + this.schoolId = schoolId; | ||
19 | + } | ||
20 | + | ||
21 | + public String getStudentCode() { | ||
22 | + return studentCode; | ||
23 | + } | ||
24 | + | ||
25 | + public void setStudentCode(String studentCode) { | ||
26 | + this.studentCode = studentCode; | ||
27 | + } | ||
28 | + | ||
29 | + @Override | ||
30 | + public String toString() { | ||
31 | + return "UploadImg{" + | ||
32 | + "schoolId='" + schoolId + '\'' + | ||
33 | + ", studentCode='" + studentCode + '\'' + | ||
34 | + '}'; | ||
35 | + } | ||
36 | +} |
cloud/dahua/src/main/java/com/example/dahua/control/FileControl.java
0 → 100644
@@ -0,0 +1,45 @@ | @@ -0,0 +1,45 @@ | ||
1 | +package com.example.dahua.control; | ||
2 | + | ||
3 | +import com.example.dahua.bean.UploadImg; | ||
4 | +import com.example.dahua.service.UserService; | ||
5 | +import io.swagger.annotations.Api; | ||
6 | +import org.springframework.beans.factory.annotation.Autowired; | ||
7 | +import org.springframework.web.bind.annotation.*; | ||
8 | +import org.springframework.web.multipart.MultipartFile; | ||
9 | + | ||
10 | +import java.io.File; | ||
11 | +import java.io.FileNotFoundException; | ||
12 | +import java.io.FileOutputStream; | ||
13 | +import java.io.IOException; | ||
14 | + | ||
15 | +@RestController | ||
16 | +@Api("文件管理器") | ||
17 | +@RequestMapping("file/*") | ||
18 | +public class FileControl { | ||
19 | + | ||
20 | + @Autowired | ||
21 | + UserService userService; | ||
22 | + | ||
23 | + @RequestMapping(method = RequestMethod.POST, value = "uploadImg") | ||
24 | + public String uploadImg(@RequestParam("file") MultipartFile file, @RequestParam("schoolId") String schoolId, @RequestParam("studentCode") String studentCode, | ||
25 | + @RequestParam("clint_type") String clint_type,@RequestParam("userType") int userType) { | ||
26 | + System.out.println("schoolId:" + schoolId + " studentCode:" + studentCode); | ||
27 | + String fileName = file.getOriginalFilename();//文件名 | ||
28 | + | ||
29 | + File outFile = new File("C://imgCom"); | ||
30 | + if (!outFile.exists()) outFile.mkdirs(); | ||
31 | + try { | ||
32 | + File dest = new File(outFile, fileName); | ||
33 | + FileOutputStream fileOutputStream = new FileOutputStream(dest); | ||
34 | + | ||
35 | + fileOutputStream.write(file.getBytes()); | ||
36 | + userService.uploadImgAndUserInfo(dest.getAbsolutePath(), schoolId, studentCode, clint_type,userType); | ||
37 | + return "1"; | ||
38 | + } catch (FileNotFoundException e) { | ||
39 | + e.printStackTrace(); | ||
40 | + } catch (IOException e) { | ||
41 | + e.printStackTrace(); | ||
42 | + } | ||
43 | + return "0"; | ||
44 | + } | ||
45 | +} |
cloud/dahua/src/main/java/com/example/dahua/control/UserControl.java
@@ -5,10 +5,7 @@ import com.example.dahua.async.ImageUtils; | @@ -5,10 +5,7 @@ import com.example.dahua.async.ImageUtils; | ||
5 | import com.example.dahua.async.SendUserInfoTask; | 5 | import com.example.dahua.async.SendUserInfoTask; |
6 | import com.example.dahua.lib.CompressPic; | 6 | import com.example.dahua.lib.CompressPic; |
7 | import com.example.dahua.service.UserService; | 7 | import com.example.dahua.service.UserService; |
8 | -import com.example.dahua.utils.Base64Util; | ||
9 | -import com.example.dahua.utils.FileUtils; | ||
10 | -import com.example.dahua.utils.GsonUtils; | ||
11 | -import com.example.dahua.utils.HttpUtil; | 8 | +import com.example.dahua.utils.*; |
12 | import io.swagger.annotations.Api; | 9 | import io.swagger.annotations.Api; |
13 | import io.swagger.annotations.ApiImplicitParam; | 10 | import io.swagger.annotations.ApiImplicitParam; |
14 | import io.swagger.annotations.ApiImplicitParams; | 11 | import io.swagger.annotations.ApiImplicitParams; |
@@ -59,8 +56,8 @@ public class UserControl { | @@ -59,8 +56,8 @@ public class UserControl { | ||
59 | @RequestMapping(value = "uploadImgAndUserInfo", method = RequestMethod.GET) | 56 | @RequestMapping(value = "uploadImgAndUserInfo", method = RequestMethod.GET) |
60 | @ApiOperation(value = "上传用户信息") | 57 | @ApiOperation(value = "上传用户信息") |
61 | public boolean uploadImgAndUserInfo(@RequestParam("file") String file, @RequestParam("schoolId") String schoolId, @RequestParam("studentCode") String studentCode, @RequestParam("clint_type") String clint_type) { | 58 | public boolean uploadImgAndUserInfo(@RequestParam("file") String file, @RequestParam("schoolId") String schoolId, @RequestParam("studentCode") String studentCode, @RequestParam("clint_type") String clint_type) { |
62 | -// System.out.println("count:" + (count++)); | ||
63 | - return userService.uploadImgAndUserInfo(file, schoolId, studentCode, clint_type); | 59 | +// return userService.uploadImgAndUserInfo(file, schoolId, studentCode, clint_type); |
60 | + return HttpUtils.uploadImgs(new File(file),schoolId,studentCode,clint_type,2); | ||
64 | } | 61 | } |
65 | 62 | ||
66 | 63 |
cloud/dahua/src/main/java/com/example/dahua/lib/CompressPic.java
@@ -24,10 +24,10 @@ public class CompressPic { | @@ -24,10 +24,10 @@ public class CompressPic { | ||
24 | int width = bufferedImage.getWidth(null); | 24 | int width = bufferedImage.getWidth(null); |
25 | int height = bufferedImage.getHeight(null); | 25 | int height = bufferedImage.getHeight(null); |
26 | long fileLength = file.length(); | 26 | long fileLength = file.length(); |
27 | - if ((fileLength / 1024) < 128) { | 27 | + if ((fileLength / 1024) < 100) { |
28 | writeImgToFile(bufferedImage, width, height, targetPath); | 28 | writeImgToFile(bufferedImage, width, height, targetPath); |
29 | } else | 29 | } else |
30 | - while ((fileLength / 1024) >= 128) { | 30 | + while ((fileLength / 1024) >= 100) { |
31 | width = (int) (width * (1 - cutPercent)); | 31 | width = (int) (width * (1 - cutPercent)); |
32 | height = (int) (height * (1 - cutPercent)); | 32 | height = (int) (height * (1 - cutPercent)); |
33 | 33 |
cloud/dahua/src/main/java/com/example/dahua/service/UserService.java
@@ -34,7 +34,7 @@ public interface UserService { | @@ -34,7 +34,7 @@ public interface UserService { | ||
34 | * @return | 34 | * @return |
35 | */ | 35 | */ |
36 | // boolean uploadImgAndUserInfo(MultipartFile file,String schoolId,String studentCode,String clint_type); | 36 | // boolean uploadImgAndUserInfo(MultipartFile file,String schoolId,String studentCode,String clint_type); |
37 | - boolean uploadImgAndUserInfo(String file,String schoolId,String studentCode,String clint_type); | 37 | + boolean uploadImgAndUserInfo(String file,String schoolId,String studentCode,String clint_type,int userType); |
38 | 38 | ||
39 | 39 | ||
40 | /** | 40 | /** |
cloud/dahua/src/main/java/com/example/dahua/service/UserServiceImp.java
@@ -2,6 +2,7 @@ package com.example.dahua.service; | @@ -2,6 +2,7 @@ package com.example.dahua.service; | ||
2 | 2 | ||
3 | import com.example.dahua.async.SendUserInfoTask; | 3 | import com.example.dahua.async.SendUserInfoTask; |
4 | import com.example.dahua.bean.AttendanceBean; | 4 | import com.example.dahua.bean.AttendanceBean; |
5 | +import com.example.dahua.bean.TeacherBean; | ||
5 | import com.example.dahua.bean.UserInfoBean; | 6 | import com.example.dahua.bean.UserInfoBean; |
6 | import com.example.dahua.dao.UserDao; | 7 | import com.example.dahua.dao.UserDao; |
7 | import org.springframework.beans.factory.annotation.Autowired; | 8 | import org.springframework.beans.factory.annotation.Autowired; |
@@ -32,6 +33,7 @@ public class UserServiceImp implements UserService { | @@ -32,6 +33,7 @@ public class UserServiceImp implements UserService { | ||
32 | 33 | ||
33 | /** | 34 | /** |
34 | * 单个用户信息下发 | 35 | * 单个用户信息下发 |
36 | + * | ||
35 | * @param file | 37 | * @param file |
36 | * @param schoolId | 38 | * @param schoolId |
37 | * @param studentCode | 39 | * @param studentCode |
@@ -39,45 +41,58 @@ public class UserServiceImp implements UserService { | @@ -39,45 +41,58 @@ public class UserServiceImp implements UserService { | ||
39 | * @return | 41 | * @return |
40 | */ | 42 | */ |
41 | @Override | 43 | @Override |
42 | - public boolean uploadImgAndUserInfo(String file, String schoolId, String studentCode, String clint_type) { | 44 | + public boolean uploadImgAndUserInfo(String file, String schoolId, String studentCode, String clint_type, int userType) { |
43 | 45 | ||
44 | List<AttendanceBean> attendanceBeans = getAttendanceBeans(schoolId, clint_type);//获取学校下的大华设备 | 46 | List<AttendanceBean> attendanceBeans = getAttendanceBeans(schoolId, clint_type);//获取学校下的大华设备 |
45 | UserInfoBean userInfoBean = null; | 47 | UserInfoBean userInfoBean = null; |
46 | - //根据文件命名来判断学籍号 | ||
47 | - String studentCodes = file.split("\\.")[0]; | ||
48 | - String[] studentInfo = studentCodes.split("_"); | ||
49 | try { | 48 | try { |
50 | - | ||
51 | - if (studentInfo.length > 1) {//附属卡 | ||
52 | - | ||
53 | - String studentCodeF = studentInfo[0]; | ||
54 | - String CardType = studentInfo[1]; | ||
55 | - userInfoBean = getUserInfo(schoolId, studentCodeF); | ||
56 | - String cardNum = userDao.getCardNum(userInfoBean.getStudent_id(), CardType); | ||
57 | - userInfoBean.setStudent_num(cardNum); | ||
58 | - | ||
59 | - } else { | ||
60 | - | ||
61 | - userInfoBean = getUserInfo(schoolId, studentCode);//获取用户信息 | ||
62 | - | 49 | + if (userType == 2) { |
50 | + //根据文件命名来判断学籍号 | ||
51 | + String studentCodes = file.split("\\.")[0]; | ||
52 | + String[] studentInfo = studentCodes.split("_"); | ||
53 | + | ||
54 | + if (studentInfo.length > 1) {//附属卡 | ||
55 | + | ||
56 | + String studentCodeF = studentInfo[0]; | ||
57 | + String CardType = studentInfo[1]; | ||
58 | + userInfoBean = getUserInfo(schoolId, studentCodeF); | ||
59 | + String cardNum = userDao.getCardNum(userInfoBean.getStudent_id(), CardType); | ||
60 | + userInfoBean.setStudent_num(cardNum); | ||
61 | + | ||
62 | + } else { | ||
63 | + | ||
64 | + userInfoBean = getUserInfo(schoolId, studentCode);//获取用户信息 | ||
65 | + | ||
66 | + } | ||
67 | + } else if (userType == 1) { | ||
68 | + TeacherBean teacher = userDao.getTeacher(schoolId, studentCode); | ||
69 | + if (null != teacher) { | ||
70 | + userInfoBean = new UserInfoBean(); | ||
71 | + userInfoBean.setStudent_num(teacher.getTeacher_num()); | ||
72 | + userInfoBean.setName(teacher.getName()); | ||
73 | + userInfoBean.setUser_id(teacher.getUser_id()); | ||
74 | + userInfoBean.setStudentcode(teacher.getNum()); | ||
75 | + userInfoBean.setStudent_id(teacher.getTeacher_id()); | ||
76 | + } | ||
63 | } | 77 | } |
64 | - myTask.doTaskOne(file, attendanceBeans, userInfoBean,schoolId, -1); | 78 | + |
79 | + myTask.doTaskOne(file, attendanceBeans, userInfoBean, schoolId, -1, userType); | ||
65 | } catch (Exception e) { | 80 | } catch (Exception e) { |
66 | e.printStackTrace(); | 81 | e.printStackTrace(); |
67 | } | 82 | } |
68 | - | ||
69 | return true; | 83 | return true; |
70 | } | 84 | } |
71 | 85 | ||
72 | /** | 86 | /** |
73 | * 照片下放 | 87 | * 照片下放 |
88 | + * | ||
74 | * @param schoolId | 89 | * @param schoolId |
75 | * @param clint_type | 90 | * @param clint_type |
76 | - * @param type 0:主卡 1:副卡 | 91 | + * @param type 0:主卡 1:副卡 |
77 | */ | 92 | */ |
78 | @Override | 93 | @Override |
79 | - public void sendUserInfos(String schoolId, String clint_type,int type) { | ||
80 | - myTask.doTaskSendUserInfos(schoolId, clint_type,type,-1); | 94 | + public void sendUserInfos(String schoolId, String clint_type, int type) { |
95 | + myTask.doTaskSendUserInfos(schoolId, clint_type, type, -1); | ||
81 | } | 96 | } |
82 | 97 | ||
83 | } | 98 | } |
cloud/dahua/src/main/java/com/example/dahua/utils/HttpUtils.java
0 → 100644
@@ -0,0 +1,52 @@ | @@ -0,0 +1,52 @@ | ||
1 | +package com.example.dahua.utils; | ||
2 | + | ||
3 | +import org.springframework.core.io.FileSystemResource; | ||
4 | +import org.springframework.http.HttpEntity; | ||
5 | +import org.springframework.http.HttpHeaders; | ||
6 | +import org.springframework.http.MediaType; | ||
7 | +import org.springframework.http.ResponseEntity; | ||
8 | +import org.springframework.util.LinkedMultiValueMap; | ||
9 | +import org.springframework.util.MultiValueMap; | ||
10 | +import org.springframework.web.client.RestTemplate; | ||
11 | + | ||
12 | +import java.io.File; | ||
13 | + | ||
14 | +public class HttpUtils { | ||
15 | + | ||
16 | + public static boolean uploadImgs(File file,String schoolId,String studentCode,String clint_type,int userType){ | ||
17 | + | ||
18 | + if (!file.exists()){ | ||
19 | + System.out.println("图片不存在"); | ||
20 | + return false; | ||
21 | + } | ||
22 | + | ||
23 | + String url = "http://121.40.109.21:8991/file/uploadImg"; | ||
24 | +// String url = "http://localhost:8991/file/uploadImg"; | ||
25 | + RestTemplate restTemplate = new RestTemplate(); | ||
26 | + | ||
27 | + HttpHeaders headers = new HttpHeaders(); | ||
28 | + | ||
29 | + MediaType mediaType = MediaType.parseMediaType(MediaType.MULTIPART_FORM_DATA_VALUE); | ||
30 | + | ||
31 | + headers.setContentType(mediaType); | ||
32 | + | ||
33 | + MultiValueMap<String,Object> multivaluedMap = new LinkedMultiValueMap<>(); | ||
34 | + | ||
35 | + FileSystemResource fileSystemResource = new FileSystemResource(file); | ||
36 | + | ||
37 | + multivaluedMap.add("file",fileSystemResource); | ||
38 | + multivaluedMap.add("schoolId",schoolId); | ||
39 | + multivaluedMap.add("studentCode",studentCode); | ||
40 | + multivaluedMap.add("clint_type",clint_type); | ||
41 | + multivaluedMap.add("userType",userType); | ||
42 | + | ||
43 | + HttpEntity<MultiValueMap<String,Object>> httpEntity = new HttpEntity<>(multivaluedMap,headers); | ||
44 | + | ||
45 | + ResponseEntity<String> responseEntity = restTemplate.postForEntity(url,httpEntity, String.class); | ||
46 | + | ||
47 | + System.out.println("responseEntity:"+responseEntity.getBody()); | ||
48 | + return responseEntity.getBody().equals("1"); | ||
49 | + } | ||
50 | + | ||
51 | + | ||
52 | +} |
cloud/haikangface/src/main/java/com/sincere/haikangface/CMSServer.java
@@ -509,7 +509,7 @@ public class CMSServer implements ApplicationRunner { | @@ -509,7 +509,7 @@ public class CMSServer implements ApplicationRunner { | ||
509 | System.out.println("NET_ESS_ClientDoUpload失败,错误号:" + err); | 509 | System.out.println("NET_ESS_ClientDoUpload失败,错误号:" + err); |
510 | } else { | 510 | } else { |
511 | url = "http://" + ip + ":" + 8081 + new String(szUrl).trim(); | 511 | url = "http://" + ip + ":" + 8081 + new String(szUrl).trim(); |
512 | - System.err.println("NET_ESS_ClientDoUpload成功!:" + url); | 512 | +// System.err.println("NET_ESS_ClientDoUpload成功!:" + url); |
513 | } | 513 | } |
514 | hCEhomeSS.NET_ESS_DestroyClient(client);//释放资源 | 514 | hCEhomeSS.NET_ESS_DestroyClient(client);//释放资源 |
515 | } | 515 | } |
@@ -525,7 +525,9 @@ public class CMSServer implements ApplicationRunner { | @@ -525,7 +525,9 @@ public class CMSServer implements ApplicationRunner { | ||
525 | * @Param picUrl 原图 | 525 | * @Param picUrl 原图 |
526 | */ | 526 | */ |
527 | public boolean sendInfo(String srcFile, String url, String card, String startTime, String endTime, int validTimeEnabled, String name, String deviceId, String userType, String employeeNo) { | 527 | public boolean sendInfo(String srcFile, String url, String card, String startTime, String endTime, int validTimeEnabled, String name, String deviceId, String userType, String employeeNo) { |
528 | - editCard(startTime, endTime, validTimeEnabled, name, card, deviceId, employeeNo); | 528 | + deleteCard(deviceId, card); |
529 | + editCard(startTime, endTime, 0, name, card, deviceId, employeeNo); | ||
530 | + editCard(startTime, endTime, 1, name, card, deviceId, employeeNo); | ||
529 | String strRequest = "/ISAPI/AccessControl/SetFaceParamCfg"; | 531 | String strRequest = "/ISAPI/AccessControl/SetFaceParamCfg"; |
530 | String strConfigXML = "<SetFaceParamCfg version=\"2.0\" xmlns=\"http://www.isapi.org/ver20/XMLSchema\">\n" + | 532 | String strConfigXML = "<SetFaceParamCfg version=\"2.0\" xmlns=\"http://www.isapi.org/ver20/XMLSchema\">\n" + |
531 | "<cardNo>" + card + "</cardNo>\n" + | 533 | "<cardNo>" + card + "</cardNo>\n" + |
@@ -534,8 +536,6 @@ public class CMSServer implements ApplicationRunner { | @@ -534,8 +536,6 @@ public class CMSServer implements ApplicationRunner { | ||
534 | "<faceID>1</faceID>\n" + | 536 | "<faceID>1</faceID>\n" + |
535 | "<faceDataType>1</faceDataType>\n" + | 537 | "<faceDataType>1</faceDataType>\n" + |
536 | "</SetFaceParamCfg>"; | 538 | "</SetFaceParamCfg>"; |
537 | -// System.out.println("图片下发参数:" + strConfigXML); | ||
538 | - deleteCard(deviceId,card); | ||
539 | return editFace(srcFile, url, card, strRequest, strConfigXML, "下发人脸", deviceId, 1, userType); | 539 | return editFace(srcFile, url, card, strRequest, strConfigXML, "下发人脸", deviceId, 1, userType); |
540 | } | 540 | } |
541 | 541 | ||
@@ -634,9 +634,11 @@ public class CMSServer implements ApplicationRunner { | @@ -634,9 +634,11 @@ public class CMSServer implements ApplicationRunner { | ||
634 | int i = struXMLCard.size(); | 634 | int i = struXMLCard.size(); |
635 | if (!hCEhomeCMS.NET_ECMS_XMLConfig(map.get(deviceId), struXMLCard, struXMLCard.size())) { | 635 | if (!hCEhomeCMS.NET_ECMS_XMLConfig(map.get(deviceId), struXMLCard, struXMLCard.size())) { |
636 | int iErr = hCEhomeCMS.NET_ECMS_GetLastError(); | 636 | int iErr = hCEhomeCMS.NET_ECMS_GetLastError(); |
637 | - System.err.println("下发卡号失败,错误号:" + iErr + "card:" + card); | 637 | + if (validTimeEnabled == 0) System.err.println("删除卡号失败,错误号:" + iErr + "card:" + card); |
638 | + else System.err.println("下发卡号失败,错误号:" + iErr + "card:" + card); | ||
638 | } else { | 639 | } else { |
639 | - System.out.println("下发卡号成功"); | 640 | + if (validTimeEnabled == 0) System.out.println("删除卡号成功"); |
641 | + else System.out.println("下发卡号成功"); | ||
640 | } | 642 | } |
641 | 643 | ||
642 | } | 644 | } |
@@ -761,7 +763,7 @@ public class CMSServer implements ApplicationRunner { | @@ -761,7 +763,7 @@ public class CMSServer implements ApplicationRunner { | ||
761 | stringXMLOut.read(); | 763 | stringXMLOut.read(); |
762 | String strOutXML = new String(stringXMLOut.byString).trim(); | 764 | String strOutXML = new String(stringXMLOut.byString).trim(); |
763 | sendRecoderUtils.sendSuccess(sendRecordDao, card, faceUrl, deviceId, userDao, userType); | 765 | sendRecoderUtils.sendSuccess(sendRecordDao, card, faceUrl, deviceId, userDao, userType); |
764 | - System.out.println(content + "成功:" + strOutXML); | 766 | + System.out.println(content + "成功:"+card); |
765 | } | 767 | } |
766 | } else if (type == 2) {//删除人脸 | 768 | } else if (type == 2) {//删除人脸 |
767 | if (!hCEhomeCMS.NET_ECMS_PutPTXMLConfig(map.get(deviceId), struISAPXML)) { | 769 | if (!hCEhomeCMS.NET_ECMS_PutPTXMLConfig(map.get(deviceId), struISAPXML)) { |
@@ -771,7 +773,7 @@ public class CMSServer implements ApplicationRunner { | @@ -771,7 +773,7 @@ public class CMSServer implements ApplicationRunner { | ||
771 | } else { | 773 | } else { |
772 | stringXMLOut.read(); | 774 | stringXMLOut.read(); |
773 | String strOutXML = new String(stringXMLOut.byString).trim(); | 775 | String strOutXML = new String(stringXMLOut.byString).trim(); |
774 | - System.out.println(content + "成功:" + strOutXML); | 776 | + System.out.println(content + "成功:"+card); |
775 | return true; | 777 | return true; |
776 | } | 778 | } |
777 | } else if (type == 3) {//获取人脸信息 | 779 | } else if (type == 3) {//获取人脸信息 |
cloud/haikangface/src/main/java/com/sincere/haikangface/async/SendUserAsync.java
@@ -37,7 +37,7 @@ public class SendUserAsync { | @@ -37,7 +37,7 @@ public class SendUserAsync { | ||
37 | 37 | ||
38 | // @Async("taskExecutor") | 38 | // @Async("taskExecutor") |
39 | public void sendStuToHaiKang(String srcFile, String picUrl, String card, String startTime, String endTime, int validTimeEnabled, String name, String deviceId, String userType, int isPiliang) { | 39 | public void sendStuToHaiKang(String srcFile, String picUrl, String card, String startTime, String endTime, int validTimeEnabled, String name, String deviceId, String userType, int isPiliang) { |
40 | - System.out.println("下发时间设置:"+" startTime:"+startTime+" endTime:"+endTime); | 40 | + System.out.println("下发时间设置:"+validTimeEnabled); |
41 | if (null == sendRecoderUtils) sendRecoderUtils = new SendRecoderUtils(); | 41 | if (null == sendRecoderUtils) sendRecoderUtils = new SendRecoderUtils(); |
42 | //1、检测图片是否合格 | 42 | //1、检测图片是否合格 |
43 | boolean check = true; | 43 | boolean check = true; |
cloud/haikangface/src/main/java/com/sincere/haikangface/bean/face/SendFaceBean.java
0 → 100644
@@ -0,0 +1,87 @@ | @@ -0,0 +1,87 @@ | ||
1 | +package com.sincere.haikangface.bean.face; | ||
2 | + | ||
3 | +public class SendFaceBean { | ||
4 | + | ||
5 | + private String card; | ||
6 | + | ||
7 | + private String name; | ||
8 | + | ||
9 | + private String deviceId; | ||
10 | + | ||
11 | + private String startTime; | ||
12 | + | ||
13 | + private String endTime; | ||
14 | + | ||
15 | + private int validTimeEnabled; | ||
16 | + | ||
17 | + private String userType; | ||
18 | + | ||
19 | + public String getCard() { | ||
20 | + return card; | ||
21 | + } | ||
22 | + | ||
23 | + public void setCard(String card) { | ||
24 | + this.card = card; | ||
25 | + } | ||
26 | + | ||
27 | + public String getName() { | ||
28 | + return name; | ||
29 | + } | ||
30 | + | ||
31 | + public void setName(String name) { | ||
32 | + this.name = name; | ||
33 | + } | ||
34 | + | ||
35 | + public String getDeviceId() { | ||
36 | + return deviceId; | ||
37 | + } | ||
38 | + | ||
39 | + public void setDeviceId(String deviceId) { | ||
40 | + this.deviceId = deviceId; | ||
41 | + } | ||
42 | + | ||
43 | + public String getStartTime() { | ||
44 | + return startTime; | ||
45 | + } | ||
46 | + | ||
47 | + public void setStartTime(String startTime) { | ||
48 | + this.startTime = startTime; | ||
49 | + } | ||
50 | + | ||
51 | + public String getEndTime() { | ||
52 | + return endTime; | ||
53 | + } | ||
54 | + | ||
55 | + public void setEndTime(String endTime) { | ||
56 | + this.endTime = endTime; | ||
57 | + } | ||
58 | + | ||
59 | + public int getValidTimeEnabled() { | ||
60 | + return validTimeEnabled; | ||
61 | + } | ||
62 | + | ||
63 | + public void setValidTimeEnabled(int validTimeEnabled) { | ||
64 | + this.validTimeEnabled = validTimeEnabled; | ||
65 | + } | ||
66 | + | ||
67 | + public String getUserType() { | ||
68 | + return userType; | ||
69 | + } | ||
70 | + | ||
71 | + public void setUserType(String userType) { | ||
72 | + this.userType = userType; | ||
73 | + } | ||
74 | + | ||
75 | + @Override | ||
76 | + public String toString() { | ||
77 | + return "SendFaceBean{" + | ||
78 | + "card='" + card + '\'' + | ||
79 | + ", name='" + name + '\'' + | ||
80 | + ", deviceId='" + deviceId + '\'' + | ||
81 | + ", startTime='" + startTime + '\'' + | ||
82 | + ", endTime='" + endTime + '\'' + | ||
83 | + ", validTimeEnabled=" + validTimeEnabled + | ||
84 | + ", userType='" + userType + '\'' + | ||
85 | + '}'; | ||
86 | + } | ||
87 | +} |
cloud/haikangface/src/main/java/com/sincere/haikangface/control/FileControl.java
0 → 100644
@@ -0,0 +1,107 @@ | @@ -0,0 +1,107 @@ | ||
1 | +package com.sincere.haikangface.control; | ||
2 | + | ||
3 | +import com.sincere.haikangface.CMSServer; | ||
4 | +import com.sincere.haikangface.async.SendUserAsync; | ||
5 | +import com.sincere.haikangface.bean.face.SendFaceBean; | ||
6 | +import com.sincere.haikangface.dao.UserDao; | ||
7 | +import com.sincere.haikangface.utils.FileUtils; | ||
8 | +import com.sincere.haikangface.utils.SendRecoderUtils; | ||
9 | +import com.sincere.haikangface.xiananDao.SendRecordDao; | ||
10 | +import io.swagger.annotations.Api; | ||
11 | +import io.swagger.annotations.ApiOperation; | ||
12 | +import org.springframework.beans.factory.annotation.Autowired; | ||
13 | +import org.springframework.web.bind.annotation.*; | ||
14 | +import org.springframework.web.multipart.MultipartFile; | ||
15 | + | ||
16 | +import java.io.File; | ||
17 | +import java.io.FileOutputStream; | ||
18 | + | ||
19 | +@RestController | ||
20 | +@Api("文件管理器") | ||
21 | +@RequestMapping("file/*") | ||
22 | +public class FileControl { | ||
23 | + | ||
24 | + @Autowired | ||
25 | + SendUserAsync sendUserAsync; | ||
26 | + | ||
27 | + @Autowired | ||
28 | + SendRecordDao sendRecordDao; | ||
29 | + | ||
30 | + @Autowired | ||
31 | + UserDao userDao; | ||
32 | + | ||
33 | + @Autowired | ||
34 | + CMSServer cmsServer; | ||
35 | + | ||
36 | + SendRecoderUtils sendRecoderUtils; | ||
37 | + | ||
38 | + @RequestMapping(method = RequestMethod.POST, value = "uploadImg") | ||
39 | + public String uploadImg(@RequestParam("file") MultipartFile file, @RequestParam("card") String card | ||
40 | + , @RequestParam("name") String name, @RequestParam("deviceId") String deviceId, @RequestParam("startTime") String startTime, | ||
41 | + @RequestParam("endTime") String endTime, @RequestParam("validTimeEnabled") int validTimeEnabled, @RequestParam("userType") String userType) { | ||
42 | + | ||
43 | + try { | ||
44 | + String fileName = file.getOriginalFilename();//文件名 | ||
45 | + | ||
46 | + File outFile = new File(".//imgCom"); | ||
47 | + if (!outFile.exists()) outFile.mkdirs(); | ||
48 | + File dest = new File(outFile, fileName); | ||
49 | + FileOutputStream fileOutputStream = new FileOutputStream(dest); | ||
50 | + fileOutputStream.write(file.getBytes()); | ||
51 | + String filePath = dest.getAbsolutePath(); | ||
52 | + FileUtils.getInstance().writeLogs("filePath:" + filePath + " card:" + card + " name:" + name + " deviceId:" + deviceId, FileUtils.sendUserInfo); | ||
53 | + long time = System.currentTimeMillis(); | ||
54 | +// if (filePath.contains(".jpg")) filePath = filePath.replace(".jpg", ".png"); | ||
55 | + if (new File(filePath.trim()).exists()) { | ||
56 | + String targetPath = FileUtils.picPathComp + new File(filePath).getName(); | ||
57 | + try { | ||
58 | + int isPiliang = 0;//0:批量,1:单张 | ||
59 | + if (filePath.contains("face17e50")) {//批量发送 | ||
60 | + isPiliang = 0; | ||
61 | + } else {//单图发送 | ||
62 | + isPiliang = 1; | ||
63 | + } | ||
64 | + sendUserAsync.sendStuToHaiKang(filePath, targetPath, Long.parseLong(getCard(card), 16) + "", startTime, endTime, validTimeEnabled, name, deviceId, userType, isPiliang); | ||
65 | + | ||
66 | + System.out.println("time:" + (System.currentTimeMillis() - time) / 1000); | ||
67 | + return "1"; | ||
68 | + } catch (Exception e) { | ||
69 | + e.printStackTrace(); | ||
70 | + return "0"; | ||
71 | + } | ||
72 | + } else { | ||
73 | + | ||
74 | + if (null == sendRecoderUtils) sendRecoderUtils = new SendRecoderUtils(); | ||
75 | + sendRecoderUtils.sendFail(sendRecordDao, Long.parseLong(getCard(card), 16) + "", filePath, deviceId, userDao, "文件不存在", userType); | ||
76 | + System.out.println("文件不存在:" + filePath); | ||
77 | + } | ||
78 | + } catch (Exception e) { | ||
79 | + e.printStackTrace(); | ||
80 | + } | ||
81 | + | ||
82 | + return "0"; | ||
83 | + } | ||
84 | + | ||
85 | + | ||
86 | + @RequestMapping(value = "IsDeviceOnline", method = RequestMethod.GET) | ||
87 | + @ApiOperation("判断设备是否在线") | ||
88 | + public String IsDeviceOnline(@RequestParam("deviceId") String deviceId) { | ||
89 | + return cmsServer.getIsDeviceOnline(deviceId)?"1":"0"; | ||
90 | + } | ||
91 | + | ||
92 | + | ||
93 | + private String getCard(String card) { | ||
94 | + | ||
95 | + if (card.length() == 8) { | ||
96 | + int length = card.length(); | ||
97 | + String result = card.substring(length - 2, length) + card.substring(length - 4, length - 2) + card.substring(length - 6, length - 4) | ||
98 | + + card.substring(length - 8, length - 6); | ||
99 | + return result; | ||
100 | + | ||
101 | + } else { | ||
102 | + System.out.println("卡号位数不对:" + card); | ||
103 | + return ""; | ||
104 | + } | ||
105 | + | ||
106 | + } | ||
107 | +} |
cloud/haikangface/src/main/java/com/sincere/haikangface/control/UserControl.java
@@ -84,6 +84,7 @@ public class UserControl { | @@ -84,6 +84,7 @@ public class UserControl { | ||
84 | e.printStackTrace(); | 84 | e.printStackTrace(); |
85 | } | 85 | } |
86 | return true; | 86 | return true; |
87 | +// return HttpUtil.uploadImgs(filePath,card,name,deviceId,startTime,endTime,validTimeEnabled,userType); | ||
87 | } | 88 | } |
88 | 89 | ||
89 | @RequestMapping(value = "DeleteCard", method = RequestMethod.GET) | 90 | @RequestMapping(value = "DeleteCard", method = RequestMethod.GET) |
@@ -100,7 +101,6 @@ public class UserControl { | @@ -100,7 +101,6 @@ public class UserControl { | ||
100 | return true; | 101 | return true; |
101 | } | 102 | } |
102 | 103 | ||
103 | - | ||
104 | @RequestMapping(value = "IsDeviceOnline", method = RequestMethod.GET) | 104 | @RequestMapping(value = "IsDeviceOnline", method = RequestMethod.GET) |
105 | @ApiOperation("判断设备是否在线") | 105 | @ApiOperation("判断设备是否在线") |
106 | public boolean IsDeviceOnline(@RequestParam("deviceId") String deviceId) { | 106 | public boolean IsDeviceOnline(@RequestParam("deviceId") String deviceId) { |
@@ -109,6 +109,11 @@ public class UserControl { | @@ -109,6 +109,11 @@ public class UserControl { | ||
109 | } else { | 109 | } else { |
110 | return false; | 110 | return false; |
111 | } | 111 | } |
112 | + /*if ( HttpUtil.IsDeviceOnline(deviceId)) { | ||
113 | + return true; | ||
114 | + } else { | ||
115 | + return false; | ||
116 | + }*/ | ||
112 | } | 117 | } |
113 | 118 | ||
114 | @RequestMapping(value = "FaceUploadFile", method = RequestMethod.POST) | 119 | @RequestMapping(value = "FaceUploadFile", method = RequestMethod.POST) |
cloud/haikangface/src/main/java/com/sincere/haikangface/utils/HttpUtil.java
1 | package com.sincere.haikangface.utils; | 1 | package com.sincere.haikangface.utils; |
2 | 2 | ||
3 | +import org.springframework.core.io.FileSystemResource; | ||
4 | +import org.springframework.http.HttpEntity; | ||
5 | +import org.springframework.http.HttpHeaders; | ||
6 | +import org.springframework.http.MediaType; | ||
7 | +import org.springframework.http.ResponseEntity; | ||
8 | +import org.springframework.util.LinkedMultiValueMap; | ||
9 | +import org.springframework.util.MultiValueMap; | ||
10 | +import org.springframework.web.bind.annotation.RequestParam; | ||
11 | +import org.springframework.web.client.RestTemplate; | ||
12 | + | ||
3 | import java.io.BufferedReader; | 13 | import java.io.BufferedReader; |
4 | import java.io.DataOutputStream; | 14 | import java.io.DataOutputStream; |
15 | +import java.io.File; | ||
5 | import java.io.InputStreamReader; | 16 | import java.io.InputStreamReader; |
6 | import java.net.HttpURLConnection; | 17 | import java.net.HttpURLConnection; |
7 | import java.net.URL; | 18 | import java.net.URL; |
19 | +import java.util.HashMap; | ||
8 | import java.util.List; | 20 | import java.util.List; |
9 | import java.util.Map; | 21 | import java.util.Map; |
10 | 22 | ||
@@ -74,4 +86,59 @@ public class HttpUtil { | @@ -74,4 +86,59 @@ public class HttpUtil { | ||
74 | System.err.println("result:" + result); | 86 | System.err.println("result:" + result); |
75 | return result; | 87 | return result; |
76 | } | 88 | } |
89 | + | ||
90 | + public static boolean uploadImgs(String filePath, String card , String name, String deviceId, String startTime, | ||
91 | + String endTime, int validTimeEnabled, String userType){ | ||
92 | + | ||
93 | + if (!new File(filePath).exists()){ | ||
94 | + System.out.println("图片不存在"); | ||
95 | + return false; | ||
96 | + } | ||
97 | + | ||
98 | + String url = "http://121.40.109.21:8089/file/uploadImg"; | ||
99 | + | ||
100 | + RestTemplate restTemplate = new RestTemplate(); | ||
101 | + | ||
102 | + HttpHeaders headers = new HttpHeaders(); | ||
103 | + | ||
104 | + MediaType mediaType = MediaType.parseMediaType(MediaType.MULTIPART_FORM_DATA_VALUE); | ||
105 | + | ||
106 | + headers.setContentType(mediaType); | ||
107 | + | ||
108 | + MultiValueMap<String,Object> multivaluedMap = new LinkedMultiValueMap<>(); | ||
109 | + | ||
110 | + FileSystemResource fileSystemResource = new FileSystemResource(filePath); | ||
111 | + | ||
112 | + multivaluedMap.add("file",fileSystemResource); | ||
113 | + multivaluedMap.add("deviceId",deviceId); | ||
114 | + multivaluedMap.add("card",card); | ||
115 | + multivaluedMap.add("name",name); | ||
116 | + multivaluedMap.add("startTime",startTime); | ||
117 | + multivaluedMap.add("endTime",endTime); | ||
118 | + multivaluedMap.add("validTimeEnabled",validTimeEnabled); | ||
119 | + multivaluedMap.add("userType",userType); | ||
120 | + | ||
121 | + HttpEntity<MultiValueMap<String,Object>> httpEntity = new HttpEntity<>(multivaluedMap,headers); | ||
122 | + | ||
123 | + ResponseEntity<String> responseEntity = restTemplate.postForEntity(url,httpEntity, String.class); | ||
124 | + | ||
125 | + System.out.println("responseEntity:"+responseEntity.getBody()); | ||
126 | + return responseEntity.getBody().equals("1"); | ||
127 | + } | ||
128 | + | ||
129 | + | ||
130 | + public static boolean IsDeviceOnline(String deviceId){ | ||
131 | + | ||
132 | + String url = "http://121.40.109.21:8089/file/getCard"; | ||
133 | + | ||
134 | + RestTemplate restTemplate = new RestTemplate(); | ||
135 | + | ||
136 | + Map<String,Object> map = new HashMap<>(); | ||
137 | + | ||
138 | + map.put("deviceId",deviceId); | ||
139 | + | ||
140 | + String res = restTemplate.getForObject(url,String.class,map); | ||
141 | + return res.equals("1"); | ||
142 | + } | ||
143 | + | ||
77 | } | 144 | } |
cloud/haikangface/src/main/resources/application.yaml
@@ -27,6 +27,9 @@ spring: | @@ -27,6 +27,9 @@ spring: | ||
27 | # resources: | 27 | # resources: |
28 | # static-locations: classpath:/META-INF/resources/,classpath:/resources/, classpath:/static/, classpath:/public/, file:C:/EhomePicServer/ | 28 | # static-locations: classpath:/META-INF/resources/,classpath:/resources/, classpath:/static/, classpath:/public/, file:C:/EhomePicServer/ |
29 | 29 | ||
30 | +ribbon: | ||
31 | + ReadTimeout: 50000 | ||
32 | + ConnectTimeout: 5000 | ||
30 | 33 | ||
31 | eureka: | 34 | eureka: |
32 | instance: | 35 | instance: |
cloud/haikangface/src/test/java/com/sincere/haikangface/HaikangfaceApplicationTests.java
@@ -21,10 +21,18 @@ import org.junit.Test; | @@ -21,10 +21,18 @@ import org.junit.Test; | ||
21 | import org.junit.runner.RunWith; | 21 | import org.junit.runner.RunWith; |
22 | import org.springframework.beans.factory.annotation.Autowired; | 22 | import org.springframework.beans.factory.annotation.Autowired; |
23 | import org.springframework.boot.test.context.SpringBootTest; | 23 | import org.springframework.boot.test.context.SpringBootTest; |
24 | +import org.springframework.core.io.FileSystemResource; | ||
25 | +import org.springframework.http.HttpEntity; | ||
26 | +import org.springframework.http.HttpHeaders; | ||
27 | +import org.springframework.http.MediaType; | ||
28 | +import org.springframework.http.ResponseEntity; | ||
24 | import org.springframework.test.context.junit4.SpringRunner; | 29 | import org.springframework.test.context.junit4.SpringRunner; |
30 | +import org.springframework.util.LinkedMultiValueMap; | ||
31 | +import org.springframework.util.MultiValueMap; | ||
25 | import org.springframework.util.StringUtils; | 32 | import org.springframework.util.StringUtils; |
26 | import org.springframework.web.client.RestTemplate; | 33 | import org.springframework.web.client.RestTemplate; |
27 | 34 | ||
35 | +import javax.ws.rs.core.MultivaluedMap; | ||
28 | import java.io.*; | 36 | import java.io.*; |
29 | import java.math.BigInteger; | 37 | import java.math.BigInteger; |
30 | import java.text.SimpleDateFormat; | 38 | import java.text.SimpleDateFormat; |
@@ -85,6 +93,7 @@ public class HaikangfaceApplicationTests { | @@ -85,6 +93,7 @@ public class HaikangfaceApplicationTests { | ||
85 | 93 | ||
86 | @Test | 94 | @Test |
87 | public void send() { | 95 | public void send() { |
96 | + | ||
88 | //补发失败人脸 | 97 | //补发失败人脸 |
89 | /*RestTemplate restTemplate = new RestTemplate(); | 98 | /*RestTemplate restTemplate = new RestTemplate(); |
90 | //失败人脸补发 | 99 | //失败人脸补发 |
@@ -220,93 +229,29 @@ public class HaikangfaceApplicationTests { | @@ -220,93 +229,29 @@ public class HaikangfaceApplicationTests { | ||
220 | 229 | ||
221 | @Test | 230 | @Test |
222 | public void getDevice() { | 231 | public void getDevice() { |
223 | - /*File file = new File("C:\\TaoHandong\\copy\\1\\21_指纹签到.txt"); | ||
224 | - | ||
225 | - try { | ||
226 | - BufferedReader bufferedReader = new BufferedReader(new FileReader(file)); | ||
227 | - | ||
228 | - String content = null; | ||
229 | - Set<String> strings = new HashSet<>();//存放studentid | ||
230 | - while ((content = bufferedReader.readLine()) != null) { | ||
231 | - if (content.contains("0x26")) { | ||
232 | - strings.add(content.split("cardNo:")[1]); | ||
233 | - } | ||
234 | - } | ||
235 | - System.out.println("指纹签到数据:" + strings.size()); | ||
236 | - | ||
237 | - | ||
238 | - File fileKQ = new File("C:\\TaoHandong\\copy\\考勤人员.txt"); | ||
239 | - | ||
240 | - BufferedReader bufferedReader1 = new BufferedReader(new FileReader(fileKQ)); | ||
241 | - Set<String> stringsKQ = new HashSet<>();//存放studentid | ||
242 | - String contentKQ=null; | ||
243 | - while ((contentKQ = bufferedReader1.readLine()) != null) { | ||
244 | - stringsKQ.add(contentKQ); | ||
245 | - } | ||
246 | - | ||
247 | - System.out.println("考勤人员:" +stringsKQ.size()); | ||
248 | - | ||
249 | - Set<String> stringsKQ_Fail = new HashSet<>(); | ||
250 | - | ||
251 | - Iterator iteratorstr = strings.iterator(); | ||
252 | - while (iteratorstr.hasNext()){ | ||
253 | - String stKQ = (String) iteratorstr.next(); | ||
254 | - boolean isHas = false; | ||
255 | - | ||
256 | - Iterator iteratorKQ = stringsKQ.iterator(); | ||
257 | - | ||
258 | - while (iteratorKQ.hasNext()){ | ||
259 | 232 | ||
260 | - String KQ = (String) iteratorKQ.next(); | ||
261 | - if (stKQ.equals(KQ))isHas = true; | 233 | + /* String url = "http://localhost:8991/file/uploadImg"; |
234 | + RestTemplate restTemplate = new RestTemplate(); | ||
262 | 235 | ||
263 | - } | 236 | + HttpHeaders headers = new HttpHeaders(); |
264 | 237 | ||
265 | - if (!isHas)stringsKQ_Fail.add("'"+stKQ+"'"); | ||
266 | - } | ||
267 | - System.out.println("考勤失败人员数据:" +stringsKQ_Fail.size()+ stringsKQ_Fail.toString()); | ||
268 | - | ||
269 | - | ||
270 | - File fileQD = new File("C:\\TaoHandong\\copy\\签到人员.txt"); | ||
271 | - | ||
272 | - BufferedReader bufferedReaderQD = new BufferedReader(new FileReader(fileQD)); | ||
273 | - String contentQD = null; | ||
274 | - Set<String> stringsQD = new HashSet<>();//存放studentid | ||
275 | - while ((contentQD = bufferedReaderQD.readLine()) != null) { | ||
276 | - stringsQD.add(contentQD); | ||
277 | - } | ||
278 | - System.out.println("4200签到记录:" + stringsQD.size()); | ||
279 | - | ||
280 | - Iterator iteratorQD = stringsQD.iterator(); | ||
281 | - | ||
282 | - Set<String> resultHas = new HashSet<>(); | 238 | + MediaType mediaType = MediaType.parseMediaType(MediaType.MULTIPART_FORM_DATA_VALUE); |
283 | 239 | ||
284 | - while (iteratorQD.hasNext()){ | 240 | + headers.setContentType(mediaType); |
285 | 241 | ||
286 | - String studentId1 = (String) iteratorQD.next(); | 242 | + MultiValueMap<String,Object> multivaluedMap = new LinkedMultiValueMap<>(); |
287 | 243 | ||
288 | - Iterator iterator = strings.iterator(); | 244 | + FileSystemResource fileSystemResource = new FileSystemResource("C:\\TaoHandong\\copy\\School951\\Student\\505778.png"); |
289 | 245 | ||
290 | - boolean isHas = false; | 246 | + multivaluedMap.add("file",fileSystemResource); |
247 | + multivaluedMap.add("schoolId",1); | ||
248 | + multivaluedMap.add("studentCode",2); | ||
291 | 249 | ||
292 | - while (iterator.hasNext()){ | 250 | + HttpEntity<MultiValueMap<String,Object>> httpEntity = new HttpEntity<>(multivaluedMap,headers); |
293 | 251 | ||
294 | - String studentId2 = (String) iterator.next(); | 252 | + ResponseEntity<String> responseEntity = restTemplate.postForEntity(url,httpEntity, String.class); |
295 | 253 | ||
296 | - if (studentId1.equals(studentId2))isHas=true; | ||
297 | - | ||
298 | - } | ||
299 | - | ||
300 | - if (!isHas){ | ||
301 | - resultHas.add("'"+studentId1+"'"); | ||
302 | - } | ||
303 | - } | ||
304 | - | ||
305 | - System.out.println("没上传的人员:" + resultHas.toString()); | ||
306 | - | ||
307 | - }catch (Exception e){ | ||
308 | - e.printStackTrace(); | ||
309 | - }*/ | 254 | + System.out.println("responseEntity:"+responseEntity.getBody());*/ |
310 | } | 255 | } |
311 | 256 | ||
312 | @Autowired | 257 | @Autowired |
@@ -0,0 +1,24 @@ | @@ -0,0 +1,24 @@ | ||
1 | +2019-12-11 17:00:04 2019-12-11 17:00:04 30 | ||
2 | + | ||
3 | +2019-12-11 17:06:39 2019-12-11 17:06:39 30 | ||
4 | + | ||
5 | +2019-12-11 17:14:49 2019-12-11 17:14:49 30 | ||
6 | + | ||
7 | +2019-12-11 17:39:24 2019-12-11 17:39:24 30 | ||
8 | + | ||
9 | +2019-12-11 17:42:04 2019-12-11 17:42:04 30 | ||
10 | + | ||
11 | +2019-12-11 17:43:50 2019-12-11 17:43:50 30 | ||
12 | + | ||
13 | +2019-12-11 17:45:30 2019-12-11 17:45:30 30 | ||
14 | + | ||
15 | +2019-12-11 17:46:28 2019-12-11 17:46:28 30 | ||
16 | + | ||
17 | +2019-12-11 17:47:44 2019-12-11 17:47:44 30 | ||
18 | + | ||
19 | +2019-12-11 17:49:51 2019-12-11 17:49:51 30 | ||
20 | + | ||
21 | +2019-12-11 17:50:52 2019-12-11 17:50:52 30 | ||
22 | + | ||
23 | +2019-12-11 17:57:53 2019-12-11 17:57:53 30 | ||
24 | + |
cloud/mypulsar/src/main/java/com/example/mypulsar/MyRunnerableInt.java
@@ -66,19 +66,11 @@ public class MyRunnerableInt implements ApplicationRunner { | @@ -66,19 +66,11 @@ public class MyRunnerableInt implements ApplicationRunner { | ||
66 | 66 | ||
67 | MqConsumer mqConsumer = MqConsumer.build().serviceUrl(url).accessId(accessId).accessKey(accessKey) | 67 | MqConsumer mqConsumer = MqConsumer.build().serviceUrl(url).accessId(accessId).accessKey(accessKey) |
68 | .maxRedeliverCount(3).messageListener(message -> { | 68 | .maxRedeliverCount(3).messageListener(message -> { |
69 | -// System.out.println("---------------------------------------------------"); | ||
70 | -// System.out.println("Message received:" + new String(message.getData()) + ",seq=" | ||
71 | -// + message.getSequenceId() + ",time=" + message.getPublishTime() + ",consumed time=" | ||
72 | -// + System.currentTimeMillis() + ",partition=" | ||
73 | -// + ((TopicMessageIdImpl) message.getMessageId()).getTopicPartitionName()); | ||
74 | String jsonMessage = new String(message.getData()); | 69 | String jsonMessage = new String(message.getData()); |
75 | MessageVO vo = JSON.parseObject(jsonMessage, MessageVO.class); | 70 | MessageVO vo = JSON.parseObject(jsonMessage, MessageVO.class); |
76 | -// System.out.println(new SimpleDateFormat("HH:mm:dd").format(new Date())+"--the real message data:" + AESBase64Utils.decrypt(vo.getData(), accessKey.substring(8, 24))); | ||
77 | String data = AESBase64Utils.decrypt(vo.getData(), accessKey.substring(8, 24)); | 71 | String data = AESBase64Utils.decrypt(vo.getData(), accessKey.substring(8, 24)); |
78 | TuYaReceiverBean tuYaReceiverBean = JSON.parseObject(data, TuYaReceiverBean.class); | 72 | TuYaReceiverBean tuYaReceiverBean = JSON.parseObject(data, TuYaReceiverBean.class); |
79 | -// System.out.println(tuYaReceiverBean.toString() + "\r\n"); | ||
80 | detealData(tuYaReceiverBean); | 73 | detealData(tuYaReceiverBean); |
81 | - | ||
82 | } | 74 | } |
83 | 75 | ||
84 | ); | 76 | ); |
@@ -177,7 +169,6 @@ public class MyRunnerableInt implements ApplicationRunner { | @@ -177,7 +169,6 @@ public class MyRunnerableInt implements ApplicationRunner { | ||
177 | int index = deviceDao.addDevice(deviceBean.getDataId(), deviceBean.getDevId(), deviceBean.getProductKey(), deviceBean.getCode(), deviceBean.getValue() | 169 | int index = deviceDao.addDevice(deviceBean.getDataId(), deviceBean.getDevId(), deviceBean.getProductKey(), deviceBean.getCode(), deviceBean.getValue() |
178 | , deviceBean.getBizCode(), deviceBean.getTime(), deviceBean.getName(), deviceBean.getDpId(), deviceBean.getUid(), deviceBean.getDev_status(), deviceBean.getDev_type()); | 170 | , deviceBean.getBizCode(), deviceBean.getTime(), deviceBean.getName(), deviceBean.getDpId(), deviceBean.getUid(), deviceBean.getDev_status(), deviceBean.getDev_type()); |
179 | updateStatus(deviceBean.getDevId(), "1"); | 171 | updateStatus(deviceBean.getDevId(), "1"); |
180 | - System.out.println("插入数据:" + index); | ||
181 | } | 172 | } |
182 | 173 | ||
183 | /** | 174 | /** |
@@ -200,8 +191,10 @@ public class MyRunnerableInt implements ApplicationRunner { | @@ -200,8 +191,10 @@ public class MyRunnerableInt implements ApplicationRunner { | ||
200 | date.setTime(t); | 191 | date.setTime(t); |
201 | deviceBean.setTime(new SimpleDateFormat("yyyy-MM-dd HH:mm:ss").format(date)); | 192 | deviceBean.setTime(new SimpleDateFormat("yyyy-MM-dd HH:mm:ss").format(date)); |
202 | String value = statue.getValue(); | 193 | String value = statue.getValue(); |
194 | + deviceBean.setValue(value); | ||
203 | switch (code) { | 195 | switch (code) { |
204 | case "va_temperature"://温度 | 196 | case "va_temperature"://温度 |
197 | + calOpenOrCloseDevWithtemper(deviceBean);//计算开启或关闭设备 | ||
205 | log("温度:" + value); | 198 | log("温度:" + value); |
206 | break; | 199 | break; |
207 | case "va_humidity"://湿度 | 200 | case "va_humidity"://湿度 |
@@ -260,6 +253,7 @@ public class MyRunnerableInt implements ApplicationRunner { | @@ -260,6 +253,7 @@ public class MyRunnerableInt implements ApplicationRunner { | ||
260 | case "pir"://人体感应 | 253 | case "pir"://人体感应 |
261 | value = (value.equals("pir") ? "有人" : "无人"); | 254 | value = (value.equals("pir") ? "有人" : "无人"); |
262 | log("人体感应:" + (value.equals("pir") ? "有人" : "无人")); | 255 | log("人体感应:" + (value.equals("pir") ? "有人" : "无人")); |
256 | + calOpenOrCloseDevWithPir(deviceBean); | ||
263 | break; | 257 | break; |
264 | case "cur_voltage"://当前电压 | 258 | case "cur_voltage"://当前电压 |
265 | // value = Integer.parseInt(value) / 10 + "V"; | 259 | // value = Integer.parseInt(value) / 10 + "V"; |
@@ -274,11 +268,30 @@ public class MyRunnerableInt implements ApplicationRunner { | @@ -274,11 +268,30 @@ public class MyRunnerableInt implements ApplicationRunner { | ||
274 | // log(devId + " 当前电流:" + Integer.parseInt(value) / 10 + "A"); | 268 | // log(devId + " 当前电流:" + Integer.parseInt(value) / 10 + "A"); |
275 | break; | 269 | break; |
276 | } | 270 | } |
277 | - | ||
278 | - deviceBean.setValue(value); | ||
279 | updateDevStatus(deviceBean); | 271 | updateDevStatus(deviceBean); |
280 | } | 272 | } |
281 | 273 | ||
274 | + /** | ||
275 | + * 根据是否有人控制设备 | ||
276 | + * @param deviceBean | ||
277 | + */ | ||
278 | + private void calOpenOrCloseDevWithPir(DeviceBean deviceBean) { | ||
279 | + | ||
280 | + | ||
281 | + | ||
282 | + } | ||
283 | + | ||
284 | + | ||
285 | + /** | ||
286 | + * 根据温度变化控制设备 | ||
287 | + * @param deviceBean | ||
288 | + */ | ||
289 | + private void calOpenOrCloseDevWithtemper(DeviceBean deviceBean) { | ||
290 | + | ||
291 | + | ||
292 | + | ||
293 | + } | ||
294 | + | ||
282 | private void log(String content) { | 295 | private void log(String content) { |
283 | System.out.println("接收到数据:" + content); | 296 | System.out.println("接收到数据:" + content); |
284 | } | 297 | } |
cloud/mypulsar/src/main/java/com/example/mypulsar/Test.java
0 → 100644
cloud/mypulsar/src/main/java/com/example/mypulsar/bean/Command.java
0 → 100644
@@ -0,0 +1,24 @@ | @@ -0,0 +1,24 @@ | ||
1 | +package com.example.mypulsar.bean; | ||
2 | + | ||
3 | +public class Command{ | ||
4 | + private String code; | ||
5 | + | ||
6 | + public String getCode() { | ||
7 | + return code; | ||
8 | + } | ||
9 | + | ||
10 | + public void setCode(String code) { | ||
11 | + this.code = code; | ||
12 | + } | ||
13 | + | ||
14 | + public String getValue() { | ||
15 | + return value; | ||
16 | + } | ||
17 | + | ||
18 | + public void setValue(String value) { | ||
19 | + this.value = value; | ||
20 | + } | ||
21 | + | ||
22 | + private String value; | ||
23 | + | ||
24 | +} |
cloud/mypulsar/src/main/java/com/example/mypulsar/bean/TuYaCommand.java
0 → 100644
@@ -0,0 +1,21 @@ | @@ -0,0 +1,21 @@ | ||
1 | +package com.example.mypulsar.bean; | ||
2 | + | ||
3 | +import java.util.List; | ||
4 | + | ||
5 | +/** | ||
6 | + * 命令集 | ||
7 | + */ | ||
8 | +public class TuYaCommand { | ||
9 | + | ||
10 | + public List<Command> getCommands() { | ||
11 | + return commands; | ||
12 | + } | ||
13 | + | ||
14 | + public void setCommands(List<Command> commands) { | ||
15 | + this.commands = commands; | ||
16 | + } | ||
17 | + | ||
18 | + private List<Command> commands; | ||
19 | + | ||
20 | +} | ||
21 | + |
cloud/mypulsar/src/main/java/com/example/mypulsar/dao/DeviceDao.java
@@ -32,4 +32,9 @@ public interface DeviceDao { | @@ -32,4 +32,9 @@ public interface DeviceDao { | ||
32 | 32 | ||
33 | @Select("select * from Iot_Device where devId = #{devId}") | 33 | @Select("select * from Iot_Device where devId = #{devId}") |
34 | List<DeviceBean> getDevice(@Param("devId") String devId); | 34 | List<DeviceBean> getDevice(@Param("devId") String devId); |
35 | + | ||
36 | + //获取联动控制模板 | ||
37 | + @Select("select * from CalDevContrl") | ||
38 | + List<String> getCalDevContrl(); | ||
39 | + | ||
35 | } | 40 | } |
cloud/mypulsar/src/main/java/com/example/mypulsar/utils/ControlUtils.java
0 → 100644
cloud/mypulsar/src/main/java/com/example/mypulsar/utils/HttpUtil.java
0 → 100644
@@ -0,0 +1,134 @@ | @@ -0,0 +1,134 @@ | ||
1 | +package com.example.mypulsar.utils; | ||
2 | + | ||
3 | +import com.alibaba.fastjson.JSONArray; | ||
4 | +import com.alibaba.fastjson.JSONObject; | ||
5 | +import com.example.mypulsar.bean.Command; | ||
6 | +import com.example.mypulsar.bean.TuYaCommand; | ||
7 | +import org.apache.pulsar.shade.com.google.gson.Gson; | ||
8 | +import org.springframework.core.io.FileSystemResource; | ||
9 | +import org.springframework.http.HttpEntity; | ||
10 | +import org.springframework.http.HttpHeaders; | ||
11 | +import org.springframework.http.MediaType; | ||
12 | +import org.springframework.http.ResponseEntity; | ||
13 | +import org.springframework.util.LinkedMultiValueMap; | ||
14 | +import org.springframework.util.MultiValueMap; | ||
15 | +import org.springframework.web.client.RestTemplate; | ||
16 | + | ||
17 | +import java.io.BufferedReader; | ||
18 | +import java.io.DataOutputStream; | ||
19 | +import java.io.File; | ||
20 | +import java.io.InputStreamReader; | ||
21 | +import java.net.HttpURLConnection; | ||
22 | +import java.net.URL; | ||
23 | +import java.util.ArrayList; | ||
24 | +import java.util.HashMap; | ||
25 | +import java.util.List; | ||
26 | +import java.util.Map; | ||
27 | + | ||
28 | +/** | ||
29 | + * http 工具类 | ||
30 | + */ | ||
31 | +public class HttpUtil { | ||
32 | + | ||
33 | + public static String post(String requestUrl, String accessToken, String params) | ||
34 | + throws Exception { | ||
35 | + String contentType = "application/json"; | ||
36 | + return HttpUtil.post(requestUrl, accessToken, contentType, params); | ||
37 | + } | ||
38 | + | ||
39 | + public static String post(String requestUrl, String accessToken, String contentType, String params) | ||
40 | + throws Exception { | ||
41 | + String encoding = "UTF-8"; | ||
42 | + if (requestUrl.contains("nlp")) { | ||
43 | + encoding = "GBK"; | ||
44 | + } | ||
45 | + return HttpUtil.post(requestUrl, accessToken, contentType, params, encoding); | ||
46 | + } | ||
47 | + | ||
48 | + public static String post(String requestUrl, String accessToken, String contentType, String params, String encoding) | ||
49 | + throws Exception { | ||
50 | + String url = requestUrl + "?access_token=" + accessToken; | ||
51 | + return HttpUtil.postGeneralUrl(url, contentType, params, encoding); | ||
52 | + } | ||
53 | + | ||
54 | + public static String postGeneralUrl(String generalUrl, String contentType, String params, String encoding) | ||
55 | + throws Exception { | ||
56 | + URL url = new URL(generalUrl); | ||
57 | + // 打开和URL之间的连接 | ||
58 | + HttpURLConnection connection = (HttpURLConnection) url.openConnection(); | ||
59 | + connection.setRequestMethod("POST"); | ||
60 | + // 设置通用的请求属性 | ||
61 | + connection.setRequestProperty("Content-Type", contentType); | ||
62 | + connection.setRequestProperty("Connection", "Keep-Alive"); | ||
63 | + connection.setUseCaches(false); | ||
64 | + connection.setDoOutput(true); | ||
65 | + connection.setDoInput(true); | ||
66 | + | ||
67 | + // 得到请求的输出流对象 | ||
68 | + DataOutputStream out = new DataOutputStream(connection.getOutputStream()); | ||
69 | + out.write(params.getBytes(encoding)); | ||
70 | + out.flush(); | ||
71 | + out.close(); | ||
72 | + | ||
73 | + // 建立实际的连接 | ||
74 | + connection.connect(); | ||
75 | + // 获取所有响应头字段 | ||
76 | + Map<String, List<String>> headers = connection.getHeaderFields(); | ||
77 | + // 遍历所有的响应头字段 | ||
78 | + for (String key : headers.keySet()) { | ||
79 | + System.err.println(key + "--->" + headers.get(key)); | ||
80 | + } | ||
81 | + // 定义 BufferedReader输入流来读取URL的响应 | ||
82 | + BufferedReader in = null; | ||
83 | + in = new BufferedReader( | ||
84 | + new InputStreamReader(connection.getInputStream(), encoding)); | ||
85 | + String result = ""; | ||
86 | + String getLine; | ||
87 | + while ((getLine = in.readLine()) != null) { | ||
88 | + result += getLine; | ||
89 | + } | ||
90 | + in.close(); | ||
91 | + System.err.println("result:" + result); | ||
92 | + return result; | ||
93 | + } | ||
94 | + | ||
95 | + public static boolean controlDev(String deviceId, String code,String value ){ | ||
96 | + | ||
97 | + String url = "http://120.26.116.253:5555/TuYa/sendDeviceCommandsFun?deviceId="+deviceId; | ||
98 | + | ||
99 | + RestTemplate restTemplate = new RestTemplate(); | ||
100 | + | ||
101 | + TuYaCommand tuYaCommand = new TuYaCommand(); | ||
102 | + | ||
103 | + List<Command> commandList = new ArrayList<>(); | ||
104 | + | ||
105 | + Command command = new Command(); | ||
106 | + command.setCode(code); | ||
107 | + command.setValue(value); | ||
108 | + | ||
109 | + commandList.add(command); | ||
110 | + | ||
111 | + tuYaCommand.setCommands(commandList); | ||
112 | + | ||
113 | + String responseEntity = restTemplate.postForObject(url,tuYaCommand, String.class); | ||
114 | + | ||
115 | + System.out.println("responseEntity:"+responseEntity); | ||
116 | + return responseEntity.equals("1"); | ||
117 | + } | ||
118 | + | ||
119 | + | ||
120 | + public static boolean IsDeviceOnline(String deviceId){ | ||
121 | + | ||
122 | + String url = "http://121.40.109.21:8089/file/getCard"; | ||
123 | + | ||
124 | + RestTemplate restTemplate = new RestTemplate(); | ||
125 | + | ||
126 | + Map<String,Object> map = new HashMap<>(); | ||
127 | + | ||
128 | + map.put("deviceId",deviceId); | ||
129 | + | ||
130 | + String res = restTemplate.getForObject(url,String.class,map); | ||
131 | + return res.equals("1"); | ||
132 | + } | ||
133 | + | ||
134 | +} |
cloud/mypulsar/src/test/java/com/example/mypulsar/MypulsarApplicationTests.java
1 | package com.example.mypulsar; | 1 | package com.example.mypulsar; |
2 | 2 | ||
3 | import com.example.mypulsar.dao.DeviceDao; | 3 | import com.example.mypulsar.dao.DeviceDao; |
4 | +import com.example.mypulsar.utils.HttpUtil; | ||
4 | import org.junit.Test; | 5 | import org.junit.Test; |
5 | import org.junit.runner.RunWith; | 6 | import org.junit.runner.RunWith; |
6 | import org.springframework.beans.factory.annotation.Autowired; | 7 | import org.springframework.beans.factory.annotation.Autowired; |
cloud/search_smartCampus/src/main/java/com/sincere/smartSearch/FileConfiguration.java
0 → 100644
@@ -0,0 +1,18 @@ | @@ -0,0 +1,18 @@ | ||
1 | +package com.sincere.smartSearch; | ||
2 | + | ||
3 | +import org.springframework.context.annotation.Configuration; | ||
4 | +import org.springframework.web.servlet.config.annotation.ResourceHandlerRegistry; | ||
5 | +import org.springframework.web.servlet.config.annotation.WebMvcConfigurationSupport; | ||
6 | + | ||
7 | +@Configuration | ||
8 | +public class FileConfiguration extends WebMvcConfigurationSupport { | ||
9 | + | ||
10 | + @Override | ||
11 | + protected void addResourceHandlers(ResourceHandlerRegistry registry) { | ||
12 | + super.addResourceHandlers(registry); | ||
13 | + | ||
14 | + registry.addResourceHandler("/upload/**") | ||
15 | + .addResourceLocations("file:C:/upload/"); | ||
16 | + | ||
17 | + } | ||
18 | +} |
cloud/search_smartCampus/src/main/resources/application.yml
@@ -8,12 +8,18 @@ spring: | @@ -8,12 +8,18 @@ spring: | ||
8 | password: RQminVCJota3H1u8bBYH | 8 | password: RQminVCJota3H1u8bBYH |
9 | url: jdbc:sqlserver://116.62.155.137:33419;database=SmartCampus | 9 | url: jdbc:sqlserver://116.62.155.137:33419;database=SmartCampus |
10 | driver-class-name: com.microsoft.sqlserver.jdbc.SQLServerDriver | 10 | driver-class-name: com.microsoft.sqlserver.jdbc.SQLServerDriver |
11 | + mvc: | ||
12 | + static-path-pattern: /images/** | ||
13 | + resources: | ||
14 | + static-locations: file:C:\upload | ||
11 | ##mybatis | 15 | ##mybatis |
12 | mybatis: | 16 | mybatis: |
13 | mapper-locations: classpath:mapper/*.xml | 17 | mapper-locations: classpath:mapper/*.xml |
14 | type-aliases-package: com.sincere.smartSearch.mapper | 18 | type-aliases-package: com.sincere.smartSearch.mapper |
15 | check-config-location: true | 19 | check-config-location: true |
16 | 20 | ||
21 | + | ||
22 | + | ||
17 | eureka: | 23 | eureka: |
18 | instance: | 24 | instance: |
19 | hostname: localhost | 25 | hostname: localhost |
150 KB