diff --git a/cloud/dahua/src/main/java/com/example/dahua/DahuaApplication.java b/cloud/dahua/src/main/java/com/example/dahua/DahuaApplication.java index 7137057..905bd76 100644 --- a/cloud/dahua/src/main/java/com/example/dahua/DahuaApplication.java +++ b/cloud/dahua/src/main/java/com/example/dahua/DahuaApplication.java @@ -12,6 +12,7 @@ import org.springframework.boot.autoconfigure.EnableAutoConfiguration; import org.springframework.boot.autoconfigure.SpringBootApplication; import org.springframework.boot.autoconfigure.jdbc.DataSourceAutoConfiguration; import org.springframework.boot.autoconfigure.jdbc.DataSourceTransactionManagerAutoConfiguration; +import org.springframework.boot.web.servlet.MultipartConfigFactory; import org.springframework.cloud.client.discovery.EnableDiscoveryClient; import org.springframework.context.annotation.Bean; import org.springframework.context.annotation.Configuration; @@ -24,6 +25,7 @@ import springfox.documentation.spi.DocumentationType; import springfox.documentation.spring.web.plugins.Docket; import springfox.documentation.swagger2.annotations.EnableSwagger2; +import javax.servlet.MultipartConfigElement; import javax.swing.*; import java.io.File; import java.util.concurrent.Executor; @@ -75,5 +77,15 @@ public class DahuaApplication { } + @Bean + public MultipartConfigElement multipartConfigElement() { + MultipartConfigFactory factory = new MultipartConfigFactory(); + //单个文件最大 + factory.setMaxFileSize("10MB"); + /// 设置总上传数据总大小 + factory.setMaxRequestSize("50MB"); + return factory.createMultipartConfig(); + } + } diff --git a/cloud/dahua/src/main/java/com/example/dahua/async/MyScheduledTask.java b/cloud/dahua/src/main/java/com/example/dahua/async/MyScheduledTask.java index bd6bfc6..5f30f47 100644 --- a/cloud/dahua/src/main/java/com/example/dahua/async/MyScheduledTask.java +++ b/cloud/dahua/src/main/java/com/example/dahua/async/MyScheduledTask.java @@ -86,7 +86,7 @@ public class MyScheduledTask { close(30, 97); } - if (hour == 6 && !isClose) { + /* if (hour == 6 && !isClose) { isClose = true; close(31, 479);//打开 } @@ -94,7 +94,7 @@ public class MyScheduledTask { if (hour == 22 && isClose) { isClose = false; close(30, 479);//关闭 - } + }*/ if (hour >= 9 && hour < 11) { dealData(); diff --git a/cloud/dahua/src/main/java/com/example/dahua/async/SendUserInfoTask.java b/cloud/dahua/src/main/java/com/example/dahua/async/SendUserInfoTask.java index 7dc0b66..1f27d56 100644 --- a/cloud/dahua/src/main/java/com/example/dahua/async/SendUserInfoTask.java +++ b/cloud/dahua/src/main/java/com/example/dahua/async/SendUserInfoTask.java @@ -10,6 +10,7 @@ import com.example.dahua.lib.NetSDKLib; import com.example.dahua.lib.ToolKits; import com.example.dahua.module.GateModule; import com.example.dahua.utils.FileUtils; +import com.example.dahua.utils.HttpUtils; import com.example.dahua.xiananDao.SendRecordDao; import com.sun.jna.Memory; import org.springframework.beans.factory.annotation.Autowired; @@ -44,7 +45,7 @@ public class SendUserInfoTask { SendRecordDao sendRecordDao; @Async("taskExecutor") - public void doTaskOne(String file, List attendanceBeans, UserInfoBean userInfoBean, String schoolId, int failType) throws Exception { + public void doTaskOne(String file, List attendanceBeans, UserInfoBean userInfoBean, String schoolId, int failType,int userType) throws Exception { File studentFile = new File(file); String studentCode = studentFile.getName().split("\\.")[0]; //判断是否是副卡 @@ -68,13 +69,12 @@ public class SendUserInfoTask { sendRecordBean.setImgPath(file); sendRecordBean.setCustomerid(userInfoBean.getStudent_id()); sendRecordBean.setFailType(failType); - sendUserInfoToDev(file, attendanceBeans, userInfoBean, "2", sendRecordBean); + sendUserInfoToDev(file, attendanceBeans, userInfoBean, userType+"", sendRecordBean); } @Async("taskExecutor") public void doTaskSendUserInfos(String schoolId, String clint_type, int type, int failtype) { try { - List attendanceBeans = userDao.getAttendanceBeans(schoolId, clint_type); String filePathStudent = "E:\\wwwhtdocs\\SmartCampus\\face17e50\\School" + schoolId + "\\Student"; String filePathParent = "E:\\wwwhtdocs\\SmartCampus\\face17e50\\School" + schoolId + "\\Parent"; String filePathTeacher = "E:\\wwwhtdocs\\SmartCampus\\face17e50\\School" + schoolId + "\\Teacher"; @@ -156,6 +156,7 @@ public class SendUserInfoTask { if (type == 0 || type == 1) {//学生信息或家长信息 userInfoBean = userDao.getUserInfo(schoolId, studentCode); + HttpUtils.uploadImgs(studentFile,schoolId,studentCode,clint_type,2); } else if (type == 2) {//教师信息 TeacherBean teacher = userDao.getTeacher(schoolId, studentCode); if (null != teacher) { @@ -166,6 +167,7 @@ public class SendUserInfoTask { userInfoBean.setStudentcode(teacher.getNum()); userInfoBean.setStudent_id(teacher.getTeacher_id()); } + HttpUtils.uploadImgs(studentFile,schoolId,studentCode,clint_type,1); } //判断用户是否存在 @@ -173,7 +175,7 @@ public class SendUserInfoTask { } - boolean sendResult = sendUserInfoToDev(studentFile.getAbsolutePath(), attendanceBeans, userInfoBean, userType, sendRecordBean); +// boolean sendResult = sendUserInfoToDev(studentFile.getAbsolutePath(), attendanceBeans, userInfoBean, userType, sendRecordBean); fileList.remove(0); } // System.out.println("全部下发完成:"); @@ -593,8 +595,8 @@ public class SendUserInfoTask { senfaceToDahua(sendRecordBean); break; case 5://下发人脸失败 - if (new File(sendRecordBean.getImgPath()).exists()) - ImageUtils.rotatePhonePhoto(sendRecordBean.getImgPath(), 90); +// if (new File(sendRecordBean.getImgPath()).exists()) +// ImageUtils.rotatePhonePhoto(sendRecordBean.getImgPath(), 90); senfaceToDahua(sendRecordBean); break; case 7://意外失败 @@ -621,7 +623,7 @@ public class SendUserInfoTask { if (img.startsWith("http")) img = img.replace("http://campus.myjxt.com//", "E://wwwhtdocs/SmartCampus/"); doTaskOne(img, userDao.getAttendanceBeans(String.valueOf(sendRecordBean.getSchoolId()), "22") - , userInfoBean, sendRecordBean.getSchoolId() + "", sendRecordBean.getFailType()); + , userInfoBean, sendRecordBean.getSchoolId() + "", sendRecordBean.getFailType(),sendRecordBean.getUserType()); } } diff --git a/cloud/dahua/src/main/java/com/example/dahua/bean/UploadImg.java b/cloud/dahua/src/main/java/com/example/dahua/bean/UploadImg.java new file mode 100644 index 0000000..826405c --- /dev/null +++ b/cloud/dahua/src/main/java/com/example/dahua/bean/UploadImg.java @@ -0,0 +1,36 @@ +package com.example.dahua.bean; + +import org.springframework.web.bind.annotation.RequestParam; + +public class UploadImg { + +// @RequestParam("schoolId") String schoolId, @RequestParam("studentCode") String studentCode, + + private String schoolId; + + private String studentCode; + + public String getSchoolId() { + return schoolId; + } + + public void setSchoolId(String schoolId) { + this.schoolId = schoolId; + } + + public String getStudentCode() { + return studentCode; + } + + public void setStudentCode(String studentCode) { + this.studentCode = studentCode; + } + + @Override + public String toString() { + return "UploadImg{" + + "schoolId='" + schoolId + '\'' + + ", studentCode='" + studentCode + '\'' + + '}'; + } +} diff --git a/cloud/dahua/src/main/java/com/example/dahua/control/FileControl.java b/cloud/dahua/src/main/java/com/example/dahua/control/FileControl.java new file mode 100644 index 0000000..5c2b18d --- /dev/null +++ b/cloud/dahua/src/main/java/com/example/dahua/control/FileControl.java @@ -0,0 +1,45 @@ +package com.example.dahua.control; + +import com.example.dahua.bean.UploadImg; +import com.example.dahua.service.UserService; +import io.swagger.annotations.Api; +import org.springframework.beans.factory.annotation.Autowired; +import org.springframework.web.bind.annotation.*; +import org.springframework.web.multipart.MultipartFile; + +import java.io.File; +import java.io.FileNotFoundException; +import java.io.FileOutputStream; +import java.io.IOException; + +@RestController +@Api("文件管理器") +@RequestMapping("file/*") +public class FileControl { + + @Autowired + UserService userService; + + @RequestMapping(method = RequestMethod.POST, value = "uploadImg") + public String uploadImg(@RequestParam("file") MultipartFile file, @RequestParam("schoolId") String schoolId, @RequestParam("studentCode") String studentCode, + @RequestParam("clint_type") String clint_type,@RequestParam("userType") int userType) { + System.out.println("schoolId:" + schoolId + " studentCode:" + studentCode); + String fileName = file.getOriginalFilename();//文件名 + + File outFile = new File("C://imgCom"); + if (!outFile.exists()) outFile.mkdirs(); + try { + File dest = new File(outFile, fileName); + FileOutputStream fileOutputStream = new FileOutputStream(dest); + + fileOutputStream.write(file.getBytes()); + userService.uploadImgAndUserInfo(dest.getAbsolutePath(), schoolId, studentCode, clint_type,userType); + return "1"; + } catch (FileNotFoundException e) { + e.printStackTrace(); + } catch (IOException e) { + e.printStackTrace(); + } + return "0"; + } +} diff --git a/cloud/dahua/src/main/java/com/example/dahua/control/UserControl.java b/cloud/dahua/src/main/java/com/example/dahua/control/UserControl.java index c6f4b71..edb83fd 100644 --- a/cloud/dahua/src/main/java/com/example/dahua/control/UserControl.java +++ b/cloud/dahua/src/main/java/com/example/dahua/control/UserControl.java @@ -5,10 +5,7 @@ import com.example.dahua.async.ImageUtils; import com.example.dahua.async.SendUserInfoTask; import com.example.dahua.lib.CompressPic; import com.example.dahua.service.UserService; -import com.example.dahua.utils.Base64Util; -import com.example.dahua.utils.FileUtils; -import com.example.dahua.utils.GsonUtils; -import com.example.dahua.utils.HttpUtil; +import com.example.dahua.utils.*; import io.swagger.annotations.Api; import io.swagger.annotations.ApiImplicitParam; import io.swagger.annotations.ApiImplicitParams; @@ -59,8 +56,8 @@ public class UserControl { @RequestMapping(value = "uploadImgAndUserInfo", method = RequestMethod.GET) @ApiOperation(value = "上传用户信息") public boolean uploadImgAndUserInfo(@RequestParam("file") String file, @RequestParam("schoolId") String schoolId, @RequestParam("studentCode") String studentCode, @RequestParam("clint_type") String clint_type) { -// System.out.println("count:" + (count++)); - return userService.uploadImgAndUserInfo(file, schoolId, studentCode, clint_type); +// return userService.uploadImgAndUserInfo(file, schoolId, studentCode, clint_type); + return HttpUtils.uploadImgs(new File(file),schoolId,studentCode,clint_type,2); } diff --git a/cloud/dahua/src/main/java/com/example/dahua/lib/CompressPic.java b/cloud/dahua/src/main/java/com/example/dahua/lib/CompressPic.java index 93fc70c..6b54e23 100644 --- a/cloud/dahua/src/main/java/com/example/dahua/lib/CompressPic.java +++ b/cloud/dahua/src/main/java/com/example/dahua/lib/CompressPic.java @@ -24,10 +24,10 @@ public class CompressPic { int width = bufferedImage.getWidth(null); int height = bufferedImage.getHeight(null); long fileLength = file.length(); - if ((fileLength / 1024) < 128) { + if ((fileLength / 1024) < 100) { writeImgToFile(bufferedImage, width, height, targetPath); } else - while ((fileLength / 1024) >= 128) { + while ((fileLength / 1024) >= 100) { width = (int) (width * (1 - cutPercent)); height = (int) (height * (1 - cutPercent)); diff --git a/cloud/dahua/src/main/java/com/example/dahua/service/UserService.java b/cloud/dahua/src/main/java/com/example/dahua/service/UserService.java index 0761c67..bd64086 100644 --- a/cloud/dahua/src/main/java/com/example/dahua/service/UserService.java +++ b/cloud/dahua/src/main/java/com/example/dahua/service/UserService.java @@ -34,7 +34,7 @@ public interface UserService { * @return */ // boolean uploadImgAndUserInfo(MultipartFile file,String schoolId,String studentCode,String clint_type); - boolean uploadImgAndUserInfo(String file,String schoolId,String studentCode,String clint_type); + boolean uploadImgAndUserInfo(String file,String schoolId,String studentCode,String clint_type,int userType); /** diff --git a/cloud/dahua/src/main/java/com/example/dahua/service/UserServiceImp.java b/cloud/dahua/src/main/java/com/example/dahua/service/UserServiceImp.java index fc96459..79824d6 100644 --- a/cloud/dahua/src/main/java/com/example/dahua/service/UserServiceImp.java +++ b/cloud/dahua/src/main/java/com/example/dahua/service/UserServiceImp.java @@ -2,6 +2,7 @@ package com.example.dahua.service; import com.example.dahua.async.SendUserInfoTask; import com.example.dahua.bean.AttendanceBean; +import com.example.dahua.bean.TeacherBean; import com.example.dahua.bean.UserInfoBean; import com.example.dahua.dao.UserDao; import org.springframework.beans.factory.annotation.Autowired; @@ -32,6 +33,7 @@ public class UserServiceImp implements UserService { /** * 单个用户信息下发 + * * @param file * @param schoolId * @param studentCode @@ -39,45 +41,58 @@ public class UserServiceImp implements UserService { * @return */ @Override - public boolean uploadImgAndUserInfo(String file, String schoolId, String studentCode, String clint_type) { + public boolean uploadImgAndUserInfo(String file, String schoolId, String studentCode, String clint_type, int userType) { List attendanceBeans = getAttendanceBeans(schoolId, clint_type);//获取学校下的大华设备 UserInfoBean userInfoBean = null; - //根据文件命名来判断学籍号 - String studentCodes = file.split("\\.")[0]; - String[] studentInfo = studentCodes.split("_"); try { - - if (studentInfo.length > 1) {//附属卡 - - String studentCodeF = studentInfo[0]; - String CardType = studentInfo[1]; - userInfoBean = getUserInfo(schoolId, studentCodeF); - String cardNum = userDao.getCardNum(userInfoBean.getStudent_id(), CardType); - userInfoBean.setStudent_num(cardNum); - - } else { - - userInfoBean = getUserInfo(schoolId, studentCode);//获取用户信息 - + if (userType == 2) { + //根据文件命名来判断学籍号 + String studentCodes = file.split("\\.")[0]; + String[] studentInfo = studentCodes.split("_"); + + if (studentInfo.length > 1) {//附属卡 + + String studentCodeF = studentInfo[0]; + String CardType = studentInfo[1]; + userInfoBean = getUserInfo(schoolId, studentCodeF); + String cardNum = userDao.getCardNum(userInfoBean.getStudent_id(), CardType); + userInfoBean.setStudent_num(cardNum); + + } else { + + userInfoBean = getUserInfo(schoolId, studentCode);//获取用户信息 + + } + } else if (userType == 1) { + TeacherBean teacher = userDao.getTeacher(schoolId, studentCode); + if (null != teacher) { + userInfoBean = new UserInfoBean(); + userInfoBean.setStudent_num(teacher.getTeacher_num()); + userInfoBean.setName(teacher.getName()); + userInfoBean.setUser_id(teacher.getUser_id()); + userInfoBean.setStudentcode(teacher.getNum()); + userInfoBean.setStudent_id(teacher.getTeacher_id()); + } } - myTask.doTaskOne(file, attendanceBeans, userInfoBean,schoolId, -1); + + myTask.doTaskOne(file, attendanceBeans, userInfoBean, schoolId, -1, userType); } catch (Exception e) { e.printStackTrace(); } - return true; } /** * 照片下放 + * * @param schoolId * @param clint_type - * @param type 0:主卡 1:副卡 + * @param type 0:主卡 1:副卡 */ @Override - public void sendUserInfos(String schoolId, String clint_type,int type) { - myTask.doTaskSendUserInfos(schoolId, clint_type,type,-1); + public void sendUserInfos(String schoolId, String clint_type, int type) { + myTask.doTaskSendUserInfos(schoolId, clint_type, type, -1); } } diff --git a/cloud/dahua/src/main/java/com/example/dahua/utils/HttpUtils.java b/cloud/dahua/src/main/java/com/example/dahua/utils/HttpUtils.java new file mode 100644 index 0000000..1a0d561 --- /dev/null +++ b/cloud/dahua/src/main/java/com/example/dahua/utils/HttpUtils.java @@ -0,0 +1,52 @@ +package com.example.dahua.utils; + +import org.springframework.core.io.FileSystemResource; +import org.springframework.http.HttpEntity; +import org.springframework.http.HttpHeaders; +import org.springframework.http.MediaType; +import org.springframework.http.ResponseEntity; +import org.springframework.util.LinkedMultiValueMap; +import org.springframework.util.MultiValueMap; +import org.springframework.web.client.RestTemplate; + +import java.io.File; + +public class HttpUtils { + + public static boolean uploadImgs(File file,String schoolId,String studentCode,String clint_type,int userType){ + + if (!file.exists()){ + System.out.println("图片不存在"); + return false; + } + + String url = "http://121.40.109.21:8991/file/uploadImg"; +// String url = "http://localhost:8991/file/uploadImg"; + RestTemplate restTemplate = new RestTemplate(); + + HttpHeaders headers = new HttpHeaders(); + + MediaType mediaType = MediaType.parseMediaType(MediaType.MULTIPART_FORM_DATA_VALUE); + + headers.setContentType(mediaType); + + MultiValueMap multivaluedMap = new LinkedMultiValueMap<>(); + + FileSystemResource fileSystemResource = new FileSystemResource(file); + + multivaluedMap.add("file",fileSystemResource); + multivaluedMap.add("schoolId",schoolId); + multivaluedMap.add("studentCode",studentCode); + multivaluedMap.add("clint_type",clint_type); + multivaluedMap.add("userType",userType); + + HttpEntity> httpEntity = new HttpEntity<>(multivaluedMap,headers); + + ResponseEntity responseEntity = restTemplate.postForEntity(url,httpEntity, String.class); + + System.out.println("responseEntity:"+responseEntity.getBody()); + return responseEntity.getBody().equals("1"); + } + + +} diff --git a/cloud/haikangface/src/main/java/com/sincere/haikangface/CMSServer.java b/cloud/haikangface/src/main/java/com/sincere/haikangface/CMSServer.java index f92cc3b..58b4cf9 100644 --- a/cloud/haikangface/src/main/java/com/sincere/haikangface/CMSServer.java +++ b/cloud/haikangface/src/main/java/com/sincere/haikangface/CMSServer.java @@ -509,7 +509,7 @@ public class CMSServer implements ApplicationRunner { System.out.println("NET_ESS_ClientDoUpload失败,错误号:" + err); } else { url = "http://" + ip + ":" + 8081 + new String(szUrl).trim(); - System.err.println("NET_ESS_ClientDoUpload成功!:" + url); +// System.err.println("NET_ESS_ClientDoUpload成功!:" + url); } hCEhomeSS.NET_ESS_DestroyClient(client);//释放资源 } @@ -525,7 +525,9 @@ public class CMSServer implements ApplicationRunner { * @Param picUrl 原图 */ public boolean sendInfo(String srcFile, String url, String card, String startTime, String endTime, int validTimeEnabled, String name, String deviceId, String userType, String employeeNo) { - editCard(startTime, endTime, validTimeEnabled, name, card, deviceId, employeeNo); + deleteCard(deviceId, card); + editCard(startTime, endTime, 0, name, card, deviceId, employeeNo); + editCard(startTime, endTime, 1, name, card, deviceId, employeeNo); String strRequest = "/ISAPI/AccessControl/SetFaceParamCfg"; String strConfigXML = "\n" + "" + card + "\n" + @@ -534,8 +536,6 @@ public class CMSServer implements ApplicationRunner { "1\n" + "1\n" + ""; -// System.out.println("图片下发参数:" + strConfigXML); - deleteCard(deviceId,card); return editFace(srcFile, url, card, strRequest, strConfigXML, "下发人脸", deviceId, 1, userType); } @@ -634,9 +634,11 @@ public class CMSServer implements ApplicationRunner { int i = struXMLCard.size(); if (!hCEhomeCMS.NET_ECMS_XMLConfig(map.get(deviceId), struXMLCard, struXMLCard.size())) { int iErr = hCEhomeCMS.NET_ECMS_GetLastError(); - System.err.println("下发卡号失败,错误号:" + iErr + "card:" + card); + if (validTimeEnabled == 0) System.err.println("删除卡号失败,错误号:" + iErr + "card:" + card); + else System.err.println("下发卡号失败,错误号:" + iErr + "card:" + card); } else { - System.out.println("下发卡号成功"); + if (validTimeEnabled == 0) System.out.println("删除卡号成功"); + else System.out.println("下发卡号成功"); } } @@ -761,7 +763,7 @@ public class CMSServer implements ApplicationRunner { stringXMLOut.read(); String strOutXML = new String(stringXMLOut.byString).trim(); sendRecoderUtils.sendSuccess(sendRecordDao, card, faceUrl, deviceId, userDao, userType); - System.out.println(content + "成功:" + strOutXML); + System.out.println(content + "成功:"+card); } } else if (type == 2) {//删除人脸 if (!hCEhomeCMS.NET_ECMS_PutPTXMLConfig(map.get(deviceId), struISAPXML)) { @@ -771,7 +773,7 @@ public class CMSServer implements ApplicationRunner { } else { stringXMLOut.read(); String strOutXML = new String(stringXMLOut.byString).trim(); - System.out.println(content + "成功:" + strOutXML); + System.out.println(content + "成功:"+card); return true; } } else if (type == 3) {//获取人脸信息 diff --git a/cloud/haikangface/src/main/java/com/sincere/haikangface/async/SendUserAsync.java b/cloud/haikangface/src/main/java/com/sincere/haikangface/async/SendUserAsync.java index 5c6895e..df2d748 100644 --- a/cloud/haikangface/src/main/java/com/sincere/haikangface/async/SendUserAsync.java +++ b/cloud/haikangface/src/main/java/com/sincere/haikangface/async/SendUserAsync.java @@ -37,7 +37,7 @@ public class SendUserAsync { // @Async("taskExecutor") public void sendStuToHaiKang(String srcFile, String picUrl, String card, String startTime, String endTime, int validTimeEnabled, String name, String deviceId, String userType, int isPiliang) { - System.out.println("下发时间设置:"+" startTime:"+startTime+" endTime:"+endTime); + System.out.println("下发时间设置:"+validTimeEnabled); if (null == sendRecoderUtils) sendRecoderUtils = new SendRecoderUtils(); //1、检测图片是否合格 boolean check = true; diff --git a/cloud/haikangface/src/main/java/com/sincere/haikangface/bean/face/SendFaceBean.java b/cloud/haikangface/src/main/java/com/sincere/haikangface/bean/face/SendFaceBean.java new file mode 100644 index 0000000..23d6062 --- /dev/null +++ b/cloud/haikangface/src/main/java/com/sincere/haikangface/bean/face/SendFaceBean.java @@ -0,0 +1,87 @@ +package com.sincere.haikangface.bean.face; + +public class SendFaceBean { + + private String card; + + private String name; + + private String deviceId; + + private String startTime; + + private String endTime; + + private int validTimeEnabled; + + private String userType; + + public String getCard() { + return card; + } + + public void setCard(String card) { + this.card = card; + } + + public String getName() { + return name; + } + + public void setName(String name) { + this.name = name; + } + + public String getDeviceId() { + return deviceId; + } + + public void setDeviceId(String deviceId) { + this.deviceId = deviceId; + } + + public String getStartTime() { + return startTime; + } + + public void setStartTime(String startTime) { + this.startTime = startTime; + } + + public String getEndTime() { + return endTime; + } + + public void setEndTime(String endTime) { + this.endTime = endTime; + } + + public int getValidTimeEnabled() { + return validTimeEnabled; + } + + public void setValidTimeEnabled(int validTimeEnabled) { + this.validTimeEnabled = validTimeEnabled; + } + + public String getUserType() { + return userType; + } + + public void setUserType(String userType) { + this.userType = userType; + } + + @Override + public String toString() { + return "SendFaceBean{" + + "card='" + card + '\'' + + ", name='" + name + '\'' + + ", deviceId='" + deviceId + '\'' + + ", startTime='" + startTime + '\'' + + ", endTime='" + endTime + '\'' + + ", validTimeEnabled=" + validTimeEnabled + + ", userType='" + userType + '\'' + + '}'; + } +} diff --git a/cloud/haikangface/src/main/java/com/sincere/haikangface/control/FileControl.java b/cloud/haikangface/src/main/java/com/sincere/haikangface/control/FileControl.java new file mode 100644 index 0000000..5d52954 --- /dev/null +++ b/cloud/haikangface/src/main/java/com/sincere/haikangface/control/FileControl.java @@ -0,0 +1,107 @@ +package com.sincere.haikangface.control; + +import com.sincere.haikangface.CMSServer; +import com.sincere.haikangface.async.SendUserAsync; +import com.sincere.haikangface.bean.face.SendFaceBean; +import com.sincere.haikangface.dao.UserDao; +import com.sincere.haikangface.utils.FileUtils; +import com.sincere.haikangface.utils.SendRecoderUtils; +import com.sincere.haikangface.xiananDao.SendRecordDao; +import io.swagger.annotations.Api; +import io.swagger.annotations.ApiOperation; +import org.springframework.beans.factory.annotation.Autowired; +import org.springframework.web.bind.annotation.*; +import org.springframework.web.multipart.MultipartFile; + +import java.io.File; +import java.io.FileOutputStream; + +@RestController +@Api("文件管理器") +@RequestMapping("file/*") +public class FileControl { + + @Autowired + SendUserAsync sendUserAsync; + + @Autowired + SendRecordDao sendRecordDao; + + @Autowired + UserDao userDao; + + @Autowired + CMSServer cmsServer; + + SendRecoderUtils sendRecoderUtils; + + @RequestMapping(method = RequestMethod.POST, value = "uploadImg") + public String uploadImg(@RequestParam("file") MultipartFile file, @RequestParam("card") String card + , @RequestParam("name") String name, @RequestParam("deviceId") String deviceId, @RequestParam("startTime") String startTime, + @RequestParam("endTime") String endTime, @RequestParam("validTimeEnabled") int validTimeEnabled, @RequestParam("userType") String userType) { + + try { + String fileName = file.getOriginalFilename();//文件名 + + File outFile = new File(".//imgCom"); + if (!outFile.exists()) outFile.mkdirs(); + File dest = new File(outFile, fileName); + FileOutputStream fileOutputStream = new FileOutputStream(dest); + fileOutputStream.write(file.getBytes()); + String filePath = dest.getAbsolutePath(); + FileUtils.getInstance().writeLogs("filePath:" + filePath + " card:" + card + " name:" + name + " deviceId:" + deviceId, FileUtils.sendUserInfo); + long time = System.currentTimeMillis(); +// if (filePath.contains(".jpg")) filePath = filePath.replace(".jpg", ".png"); + if (new File(filePath.trim()).exists()) { + String targetPath = FileUtils.picPathComp + new File(filePath).getName(); + try { + int isPiliang = 0;//0:批量,1:单张 + if (filePath.contains("face17e50")) {//批量发送 + isPiliang = 0; + } else {//单图发送 + isPiliang = 1; + } + sendUserAsync.sendStuToHaiKang(filePath, targetPath, Long.parseLong(getCard(card), 16) + "", startTime, endTime, validTimeEnabled, name, deviceId, userType, isPiliang); + + System.out.println("time:" + (System.currentTimeMillis() - time) / 1000); + return "1"; + } catch (Exception e) { + e.printStackTrace(); + return "0"; + } + } else { + + if (null == sendRecoderUtils) sendRecoderUtils = new SendRecoderUtils(); + sendRecoderUtils.sendFail(sendRecordDao, Long.parseLong(getCard(card), 16) + "", filePath, deviceId, userDao, "文件不存在", userType); + System.out.println("文件不存在:" + filePath); + } + } catch (Exception e) { + e.printStackTrace(); + } + + return "0"; + } + + + @RequestMapping(value = "IsDeviceOnline", method = RequestMethod.GET) + @ApiOperation("判断设备是否在线") + public String IsDeviceOnline(@RequestParam("deviceId") String deviceId) { + return cmsServer.getIsDeviceOnline(deviceId)?"1":"0"; + } + + + private String getCard(String card) { + + if (card.length() == 8) { + int length = card.length(); + String result = card.substring(length - 2, length) + card.substring(length - 4, length - 2) + card.substring(length - 6, length - 4) + + card.substring(length - 8, length - 6); + return result; + + } else { + System.out.println("卡号位数不对:" + card); + return ""; + } + + } +} diff --git a/cloud/haikangface/src/main/java/com/sincere/haikangface/control/UserControl.java b/cloud/haikangface/src/main/java/com/sincere/haikangface/control/UserControl.java index 309c967..61ec8a8 100644 --- a/cloud/haikangface/src/main/java/com/sincere/haikangface/control/UserControl.java +++ b/cloud/haikangface/src/main/java/com/sincere/haikangface/control/UserControl.java @@ -84,6 +84,7 @@ public class UserControl { e.printStackTrace(); } return true; +// return HttpUtil.uploadImgs(filePath,card,name,deviceId,startTime,endTime,validTimeEnabled,userType); } @RequestMapping(value = "DeleteCard", method = RequestMethod.GET) @@ -100,7 +101,6 @@ public class UserControl { return true; } - @RequestMapping(value = "IsDeviceOnline", method = RequestMethod.GET) @ApiOperation("判断设备是否在线") public boolean IsDeviceOnline(@RequestParam("deviceId") String deviceId) { @@ -109,6 +109,11 @@ public class UserControl { } else { return false; } + /*if ( HttpUtil.IsDeviceOnline(deviceId)) { + return true; + } else { + return false; + }*/ } @RequestMapping(value = "FaceUploadFile", method = RequestMethod.POST) diff --git a/cloud/haikangface/src/main/java/com/sincere/haikangface/utils/HttpUtil.java b/cloud/haikangface/src/main/java/com/sincere/haikangface/utils/HttpUtil.java index 9339a9e..c34625b 100644 --- a/cloud/haikangface/src/main/java/com/sincere/haikangface/utils/HttpUtil.java +++ b/cloud/haikangface/src/main/java/com/sincere/haikangface/utils/HttpUtil.java @@ -1,10 +1,22 @@ package com.sincere.haikangface.utils; +import org.springframework.core.io.FileSystemResource; +import org.springframework.http.HttpEntity; +import org.springframework.http.HttpHeaders; +import org.springframework.http.MediaType; +import org.springframework.http.ResponseEntity; +import org.springframework.util.LinkedMultiValueMap; +import org.springframework.util.MultiValueMap; +import org.springframework.web.bind.annotation.RequestParam; +import org.springframework.web.client.RestTemplate; + import java.io.BufferedReader; import java.io.DataOutputStream; +import java.io.File; import java.io.InputStreamReader; import java.net.HttpURLConnection; import java.net.URL; +import java.util.HashMap; import java.util.List; import java.util.Map; @@ -74,4 +86,59 @@ public class HttpUtil { System.err.println("result:" + result); return result; } + + public static boolean uploadImgs(String filePath, String card , String name, String deviceId, String startTime, + String endTime, int validTimeEnabled, String userType){ + + if (!new File(filePath).exists()){ + System.out.println("图片不存在"); + return false; + } + + String url = "http://121.40.109.21:8089/file/uploadImg"; + + RestTemplate restTemplate = new RestTemplate(); + + HttpHeaders headers = new HttpHeaders(); + + MediaType mediaType = MediaType.parseMediaType(MediaType.MULTIPART_FORM_DATA_VALUE); + + headers.setContentType(mediaType); + + MultiValueMap multivaluedMap = new LinkedMultiValueMap<>(); + + FileSystemResource fileSystemResource = new FileSystemResource(filePath); + + multivaluedMap.add("file",fileSystemResource); + multivaluedMap.add("deviceId",deviceId); + multivaluedMap.add("card",card); + multivaluedMap.add("name",name); + multivaluedMap.add("startTime",startTime); + multivaluedMap.add("endTime",endTime); + multivaluedMap.add("validTimeEnabled",validTimeEnabled); + multivaluedMap.add("userType",userType); + + HttpEntity> httpEntity = new HttpEntity<>(multivaluedMap,headers); + + ResponseEntity responseEntity = restTemplate.postForEntity(url,httpEntity, String.class); + + System.out.println("responseEntity:"+responseEntity.getBody()); + return responseEntity.getBody().equals("1"); + } + + + public static boolean IsDeviceOnline(String deviceId){ + + String url = "http://121.40.109.21:8089/file/getCard"; + + RestTemplate restTemplate = new RestTemplate(); + + Map map = new HashMap<>(); + + map.put("deviceId",deviceId); + + String res = restTemplate.getForObject(url,String.class,map); + return res.equals("1"); + } + } diff --git a/cloud/haikangface/src/main/resources/application.yaml b/cloud/haikangface/src/main/resources/application.yaml index 5b4cde9..bf9ab9a 100644 --- a/cloud/haikangface/src/main/resources/application.yaml +++ b/cloud/haikangface/src/main/resources/application.yaml @@ -27,6 +27,9 @@ spring: # resources: # static-locations: classpath:/META-INF/resources/,classpath:/resources/, classpath:/static/, classpath:/public/, file:C:/EhomePicServer/ +ribbon: + ReadTimeout: 50000 + ConnectTimeout: 5000 eureka: instance: diff --git a/cloud/haikangface/src/test/java/com/sincere/haikangface/HaikangfaceApplicationTests.java b/cloud/haikangface/src/test/java/com/sincere/haikangface/HaikangfaceApplicationTests.java index 122b022..8c8a702 100644 --- a/cloud/haikangface/src/test/java/com/sincere/haikangface/HaikangfaceApplicationTests.java +++ b/cloud/haikangface/src/test/java/com/sincere/haikangface/HaikangfaceApplicationTests.java @@ -21,10 +21,18 @@ import org.junit.Test; import org.junit.runner.RunWith; import org.springframework.beans.factory.annotation.Autowired; import org.springframework.boot.test.context.SpringBootTest; +import org.springframework.core.io.FileSystemResource; +import org.springframework.http.HttpEntity; +import org.springframework.http.HttpHeaders; +import org.springframework.http.MediaType; +import org.springframework.http.ResponseEntity; import org.springframework.test.context.junit4.SpringRunner; +import org.springframework.util.LinkedMultiValueMap; +import org.springframework.util.MultiValueMap; import org.springframework.util.StringUtils; import org.springframework.web.client.RestTemplate; +import javax.ws.rs.core.MultivaluedMap; import java.io.*; import java.math.BigInteger; import java.text.SimpleDateFormat; @@ -85,6 +93,7 @@ public class HaikangfaceApplicationTests { @Test public void send() { + //补发失败人脸 /*RestTemplate restTemplate = new RestTemplate(); //失败人脸补发 @@ -220,93 +229,29 @@ public class HaikangfaceApplicationTests { @Test public void getDevice() { - /*File file = new File("C:\\TaoHandong\\copy\\1\\21_指纹签到.txt"); - - try { - BufferedReader bufferedReader = new BufferedReader(new FileReader(file)); - - String content = null; - Set strings = new HashSet<>();//存放studentid - while ((content = bufferedReader.readLine()) != null) { - if (content.contains("0x26")) { - strings.add(content.split("cardNo:")[1]); - } - } - System.out.println("指纹签到数据:" + strings.size()); - - - File fileKQ = new File("C:\\TaoHandong\\copy\\考勤人员.txt"); - - BufferedReader bufferedReader1 = new BufferedReader(new FileReader(fileKQ)); - Set stringsKQ = new HashSet<>();//存放studentid - String contentKQ=null; - while ((contentKQ = bufferedReader1.readLine()) != null) { - stringsKQ.add(contentKQ); - } - - System.out.println("考勤人员:" +stringsKQ.size()); - - Set stringsKQ_Fail = new HashSet<>(); - - Iterator iteratorstr = strings.iterator(); - while (iteratorstr.hasNext()){ - String stKQ = (String) iteratorstr.next(); - boolean isHas = false; - - Iterator iteratorKQ = stringsKQ.iterator(); - - while (iteratorKQ.hasNext()){ - String KQ = (String) iteratorKQ.next(); - if (stKQ.equals(KQ))isHas = true; + /* String url = "http://localhost:8991/file/uploadImg"; + RestTemplate restTemplate = new RestTemplate(); - } + HttpHeaders headers = new HttpHeaders(); - if (!isHas)stringsKQ_Fail.add("'"+stKQ+"'"); - } - System.out.println("考勤失败人员数据:" +stringsKQ_Fail.size()+ stringsKQ_Fail.toString()); - - - File fileQD = new File("C:\\TaoHandong\\copy\\签到人员.txt"); - - BufferedReader bufferedReaderQD = new BufferedReader(new FileReader(fileQD)); - String contentQD = null; - Set stringsQD = new HashSet<>();//存放studentid - while ((contentQD = bufferedReaderQD.readLine()) != null) { - stringsQD.add(contentQD); - } - System.out.println("4200签到记录:" + stringsQD.size()); - - Iterator iteratorQD = stringsQD.iterator(); - - Set resultHas = new HashSet<>(); + MediaType mediaType = MediaType.parseMediaType(MediaType.MULTIPART_FORM_DATA_VALUE); - while (iteratorQD.hasNext()){ + headers.setContentType(mediaType); - String studentId1 = (String) iteratorQD.next(); + MultiValueMap multivaluedMap = new LinkedMultiValueMap<>(); - Iterator iterator = strings.iterator(); + FileSystemResource fileSystemResource = new FileSystemResource("C:\\TaoHandong\\copy\\School951\\Student\\505778.png"); - boolean isHas = false; + multivaluedMap.add("file",fileSystemResource); + multivaluedMap.add("schoolId",1); + multivaluedMap.add("studentCode",2); - while (iterator.hasNext()){ + HttpEntity> httpEntity = new HttpEntity<>(multivaluedMap,headers); - String studentId2 = (String) iterator.next(); + ResponseEntity responseEntity = restTemplate.postForEntity(url,httpEntity, String.class); - if (studentId1.equals(studentId2))isHas=true; - - } - - if (!isHas){ - resultHas.add("'"+studentId1+"'"); - } - } - - System.out.println("没上传的人员:" + resultHas.toString()); - - }catch (Exception e){ - e.printStackTrace(); - }*/ + System.out.println("responseEntity:"+responseEntity.getBody());*/ } @Autowired diff --git a/cloud/log/2019-12-11/下发指令.txt b/cloud/log/2019-12-11/下发指令.txt new file mode 100644 index 0000000..2632701 --- /dev/null +++ b/cloud/log/2019-12-11/下发指令.txt @@ -0,0 +1,24 @@ +2019-12-11 17:00:04 2019-12-11 17:00:04 30 + +2019-12-11 17:06:39 2019-12-11 17:06:39 30 + +2019-12-11 17:14:49 2019-12-11 17:14:49 30 + +2019-12-11 17:39:24 2019-12-11 17:39:24 30 + +2019-12-11 17:42:04 2019-12-11 17:42:04 30 + +2019-12-11 17:43:50 2019-12-11 17:43:50 30 + +2019-12-11 17:45:30 2019-12-11 17:45:30 30 + +2019-12-11 17:46:28 2019-12-11 17:46:28 30 + +2019-12-11 17:47:44 2019-12-11 17:47:44 30 + +2019-12-11 17:49:51 2019-12-11 17:49:51 30 + +2019-12-11 17:50:52 2019-12-11 17:50:52 30 + +2019-12-11 17:57:53 2019-12-11 17:57:53 30 + diff --git a/cloud/mypulsar/src/main/java/com/example/mypulsar/MyRunnerableInt.java b/cloud/mypulsar/src/main/java/com/example/mypulsar/MyRunnerableInt.java index bc06712..ec9e021 100644 --- a/cloud/mypulsar/src/main/java/com/example/mypulsar/MyRunnerableInt.java +++ b/cloud/mypulsar/src/main/java/com/example/mypulsar/MyRunnerableInt.java @@ -66,19 +66,11 @@ public class MyRunnerableInt implements ApplicationRunner { MqConsumer mqConsumer = MqConsumer.build().serviceUrl(url).accessId(accessId).accessKey(accessKey) .maxRedeliverCount(3).messageListener(message -> { -// System.out.println("---------------------------------------------------"); -// System.out.println("Message received:" + new String(message.getData()) + ",seq=" -// + message.getSequenceId() + ",time=" + message.getPublishTime() + ",consumed time=" -// + System.currentTimeMillis() + ",partition=" -// + ((TopicMessageIdImpl) message.getMessageId()).getTopicPartitionName()); String jsonMessage = new String(message.getData()); MessageVO vo = JSON.parseObject(jsonMessage, MessageVO.class); -// System.out.println(new SimpleDateFormat("HH:mm:dd").format(new Date())+"--the real message data:" + AESBase64Utils.decrypt(vo.getData(), accessKey.substring(8, 24))); String data = AESBase64Utils.decrypt(vo.getData(), accessKey.substring(8, 24)); TuYaReceiverBean tuYaReceiverBean = JSON.parseObject(data, TuYaReceiverBean.class); -// System.out.println(tuYaReceiverBean.toString() + "\r\n"); detealData(tuYaReceiverBean); - } ); @@ -177,7 +169,6 @@ public class MyRunnerableInt implements ApplicationRunner { int index = deviceDao.addDevice(deviceBean.getDataId(), deviceBean.getDevId(), deviceBean.getProductKey(), deviceBean.getCode(), deviceBean.getValue() , deviceBean.getBizCode(), deviceBean.getTime(), deviceBean.getName(), deviceBean.getDpId(), deviceBean.getUid(), deviceBean.getDev_status(), deviceBean.getDev_type()); updateStatus(deviceBean.getDevId(), "1"); - System.out.println("插入数据:" + index); } /** @@ -200,8 +191,10 @@ public class MyRunnerableInt implements ApplicationRunner { date.setTime(t); deviceBean.setTime(new SimpleDateFormat("yyyy-MM-dd HH:mm:ss").format(date)); String value = statue.getValue(); + deviceBean.setValue(value); switch (code) { case "va_temperature"://温度 + calOpenOrCloseDevWithtemper(deviceBean);//计算开启或关闭设备 log("温度:" + value); break; case "va_humidity"://湿度 @@ -260,6 +253,7 @@ public class MyRunnerableInt implements ApplicationRunner { case "pir"://人体感应 value = (value.equals("pir") ? "有人" : "无人"); log("人体感应:" + (value.equals("pir") ? "有人" : "无人")); + calOpenOrCloseDevWithPir(deviceBean); break; case "cur_voltage"://当前电压 // value = Integer.parseInt(value) / 10 + "V"; @@ -274,11 +268,30 @@ public class MyRunnerableInt implements ApplicationRunner { // log(devId + " 当前电流:" + Integer.parseInt(value) / 10 + "A"); break; } - - deviceBean.setValue(value); updateDevStatus(deviceBean); } + /** + * 根据是否有人控制设备 + * @param deviceBean + */ + private void calOpenOrCloseDevWithPir(DeviceBean deviceBean) { + + + + } + + + /** + * 根据温度变化控制设备 + * @param deviceBean + */ + private void calOpenOrCloseDevWithtemper(DeviceBean deviceBean) { + + + + } + private void log(String content) { System.out.println("接收到数据:" + content); } diff --git a/cloud/mypulsar/src/main/java/com/example/mypulsar/Test.java b/cloud/mypulsar/src/main/java/com/example/mypulsar/Test.java new file mode 100644 index 0000000..c53bbb3 --- /dev/null +++ b/cloud/mypulsar/src/main/java/com/example/mypulsar/Test.java @@ -0,0 +1,13 @@ +package com.example.mypulsar; + +import com.example.mypulsar.utils.HttpUtil; + +public class Test { + + public static void main(String[] args){ + + HttpUtil.controlDev("6cb748ca397c2f03b1nqbh","switch_1","false"); + + } + +} diff --git a/cloud/mypulsar/src/main/java/com/example/mypulsar/bean/Command.java b/cloud/mypulsar/src/main/java/com/example/mypulsar/bean/Command.java new file mode 100644 index 0000000..b3da645 --- /dev/null +++ b/cloud/mypulsar/src/main/java/com/example/mypulsar/bean/Command.java @@ -0,0 +1,24 @@ +package com.example.mypulsar.bean; + +public class Command{ + private String code; + + public String getCode() { + return code; + } + + public void setCode(String code) { + this.code = code; + } + + public String getValue() { + return value; + } + + public void setValue(String value) { + this.value = value; + } + + private String value; + +} diff --git a/cloud/mypulsar/src/main/java/com/example/mypulsar/bean/TuYaCommand.java b/cloud/mypulsar/src/main/java/com/example/mypulsar/bean/TuYaCommand.java new file mode 100644 index 0000000..0e0a6f0 --- /dev/null +++ b/cloud/mypulsar/src/main/java/com/example/mypulsar/bean/TuYaCommand.java @@ -0,0 +1,21 @@ +package com.example.mypulsar.bean; + +import java.util.List; + +/** + * 命令集 + */ +public class TuYaCommand { + + public List getCommands() { + return commands; + } + + public void setCommands(List commands) { + this.commands = commands; + } + + private List commands; + +} + diff --git a/cloud/mypulsar/src/main/java/com/example/mypulsar/dao/DeviceDao.java b/cloud/mypulsar/src/main/java/com/example/mypulsar/dao/DeviceDao.java index ebbf8ec..41ac98c 100644 --- a/cloud/mypulsar/src/main/java/com/example/mypulsar/dao/DeviceDao.java +++ b/cloud/mypulsar/src/main/java/com/example/mypulsar/dao/DeviceDao.java @@ -32,4 +32,9 @@ public interface DeviceDao { @Select("select * from Iot_Device where devId = #{devId}") List getDevice(@Param("devId") String devId); + + //获取联动控制模板 + @Select("select * from CalDevContrl") + List getCalDevContrl(); + } diff --git a/cloud/mypulsar/src/main/java/com/example/mypulsar/utils/ControlUtils.java b/cloud/mypulsar/src/main/java/com/example/mypulsar/utils/ControlUtils.java new file mode 100644 index 0000000..8bfadcd --- /dev/null +++ b/cloud/mypulsar/src/main/java/com/example/mypulsar/utils/ControlUtils.java @@ -0,0 +1,7 @@ +package com.example.mypulsar.utils; + +public class ControlUtils { + + + +} diff --git a/cloud/mypulsar/src/main/java/com/example/mypulsar/utils/HttpUtil.java b/cloud/mypulsar/src/main/java/com/example/mypulsar/utils/HttpUtil.java new file mode 100644 index 0000000..7589b5c --- /dev/null +++ b/cloud/mypulsar/src/main/java/com/example/mypulsar/utils/HttpUtil.java @@ -0,0 +1,134 @@ +package com.example.mypulsar.utils; + +import com.alibaba.fastjson.JSONArray; +import com.alibaba.fastjson.JSONObject; +import com.example.mypulsar.bean.Command; +import com.example.mypulsar.bean.TuYaCommand; +import org.apache.pulsar.shade.com.google.gson.Gson; +import org.springframework.core.io.FileSystemResource; +import org.springframework.http.HttpEntity; +import org.springframework.http.HttpHeaders; +import org.springframework.http.MediaType; +import org.springframework.http.ResponseEntity; +import org.springframework.util.LinkedMultiValueMap; +import org.springframework.util.MultiValueMap; +import org.springframework.web.client.RestTemplate; + +import java.io.BufferedReader; +import java.io.DataOutputStream; +import java.io.File; +import java.io.InputStreamReader; +import java.net.HttpURLConnection; +import java.net.URL; +import java.util.ArrayList; +import java.util.HashMap; +import java.util.List; +import java.util.Map; + +/** + * http 工具类 + */ +public class HttpUtil { + + public static String post(String requestUrl, String accessToken, String params) + throws Exception { + String contentType = "application/json"; + return HttpUtil.post(requestUrl, accessToken, contentType, params); + } + + public static String post(String requestUrl, String accessToken, String contentType, String params) + throws Exception { + String encoding = "UTF-8"; + if (requestUrl.contains("nlp")) { + encoding = "GBK"; + } + return HttpUtil.post(requestUrl, accessToken, contentType, params, encoding); + } + + public static String post(String requestUrl, String accessToken, String contentType, String params, String encoding) + throws Exception { + String url = requestUrl + "?access_token=" + accessToken; + return HttpUtil.postGeneralUrl(url, contentType, params, encoding); + } + + public static String postGeneralUrl(String generalUrl, String contentType, String params, String encoding) + throws Exception { + URL url = new URL(generalUrl); + // 打开和URL之间的连接 + HttpURLConnection connection = (HttpURLConnection) url.openConnection(); + connection.setRequestMethod("POST"); + // 设置通用的请求属性 + connection.setRequestProperty("Content-Type", contentType); + connection.setRequestProperty("Connection", "Keep-Alive"); + connection.setUseCaches(false); + connection.setDoOutput(true); + connection.setDoInput(true); + + // 得到请求的输出流对象 + DataOutputStream out = new DataOutputStream(connection.getOutputStream()); + out.write(params.getBytes(encoding)); + out.flush(); + out.close(); + + // 建立实际的连接 + connection.connect(); + // 获取所有响应头字段 + Map> headers = connection.getHeaderFields(); + // 遍历所有的响应头字段 + for (String key : headers.keySet()) { + System.err.println(key + "--->" + headers.get(key)); + } + // 定义 BufferedReader输入流来读取URL的响应 + BufferedReader in = null; + in = new BufferedReader( + new InputStreamReader(connection.getInputStream(), encoding)); + String result = ""; + String getLine; + while ((getLine = in.readLine()) != null) { + result += getLine; + } + in.close(); + System.err.println("result:" + result); + return result; + } + + public static boolean controlDev(String deviceId, String code,String value ){ + + String url = "http://120.26.116.253:5555/TuYa/sendDeviceCommandsFun?deviceId="+deviceId; + + RestTemplate restTemplate = new RestTemplate(); + + TuYaCommand tuYaCommand = new TuYaCommand(); + + List commandList = new ArrayList<>(); + + Command command = new Command(); + command.setCode(code); + command.setValue(value); + + commandList.add(command); + + tuYaCommand.setCommands(commandList); + + String responseEntity = restTemplate.postForObject(url,tuYaCommand, String.class); + + System.out.println("responseEntity:"+responseEntity); + return responseEntity.equals("1"); + } + + + public static boolean IsDeviceOnline(String deviceId){ + + String url = "http://121.40.109.21:8089/file/getCard"; + + RestTemplate restTemplate = new RestTemplate(); + + Map map = new HashMap<>(); + + map.put("deviceId",deviceId); + + String res = restTemplate.getForObject(url,String.class,map); + return res.equals("1"); + } + +} diff --git a/cloud/mypulsar/src/test/java/com/example/mypulsar/MypulsarApplicationTests.java b/cloud/mypulsar/src/test/java/com/example/mypulsar/MypulsarApplicationTests.java index 643961b..89822e7 100644 --- a/cloud/mypulsar/src/test/java/com/example/mypulsar/MypulsarApplicationTests.java +++ b/cloud/mypulsar/src/test/java/com/example/mypulsar/MypulsarApplicationTests.java @@ -1,6 +1,7 @@ package com.example.mypulsar; import com.example.mypulsar.dao.DeviceDao; +import com.example.mypulsar.utils.HttpUtil; import org.junit.Test; import org.junit.runner.RunWith; import org.springframework.beans.factory.annotation.Autowired; diff --git a/cloud/search_smartCampus/src/main/java/com/sincere/smartSearch/FileConfiguration.java b/cloud/search_smartCampus/src/main/java/com/sincere/smartSearch/FileConfiguration.java new file mode 100644 index 0000000..b4c27d3 --- /dev/null +++ b/cloud/search_smartCampus/src/main/java/com/sincere/smartSearch/FileConfiguration.java @@ -0,0 +1,18 @@ +package com.sincere.smartSearch; + +import org.springframework.context.annotation.Configuration; +import org.springframework.web.servlet.config.annotation.ResourceHandlerRegistry; +import org.springframework.web.servlet.config.annotation.WebMvcConfigurationSupport; + +@Configuration +public class FileConfiguration extends WebMvcConfigurationSupport { + + @Override + protected void addResourceHandlers(ResourceHandlerRegistry registry) { + super.addResourceHandlers(registry); + + registry.addResourceHandler("/upload/**") + .addResourceLocations("file:C:/upload/"); + + } +} diff --git a/cloud/search_smartCampus/src/main/resources/application.yml b/cloud/search_smartCampus/src/main/resources/application.yml index 9243d91..1981a18 100644 --- a/cloud/search_smartCampus/src/main/resources/application.yml +++ b/cloud/search_smartCampus/src/main/resources/application.yml @@ -8,12 +8,18 @@ spring: password: RQminVCJota3H1u8bBYH url: jdbc:sqlserver://116.62.155.137:33419;database=SmartCampus driver-class-name: com.microsoft.sqlserver.jdbc.SQLServerDriver + mvc: + static-path-pattern: /images/** + resources: + static-locations: file:C:\upload ##mybatis mybatis: mapper-locations: classpath:mapper/*.xml type-aliases-package: com.sincere.smartSearch.mapper check-config-location: true + + eureka: instance: hostname: localhost diff --git a/cloud/uploadFile/test.jpg b/cloud/uploadFile/test.jpg new file mode 100644 index 0000000..824229d Binary files /dev/null and b/cloud/uploadFile/test.jpg differ -- libgit2 0.21.0