diff --git a/.gitignore b/.gitignore index 5de4c42..02574eb 100644 --- a/.gitignore +++ b/.gitignore @@ -2,3 +2,72 @@ cloud.zip cloud/haikangface/log/2019-11-15/13_文件保存回调.txt cloud/mypulsar/mypulsar-1.0.0/ cloud/mypulsar/mypulsar-1.0.0.jar +cloud/dahua/sdklog/2019-11-22_08-53-36.log +cloud/dahua/sdklog/2019-11-22_08-53-55.log +cloud/dahua/sdklog/2019-11-22_08-54-42.log +cloud/dahua/sdklog/2019-11-22_08-55-16.log +cloud/dahua/sdklog/2019-11-22_08-56-13.log +cloud/dahua/sdklog/2019-12-10_11-22-45.log +cloud/dahua/sdklog/2019-12-25_14-31-48.log +cloud/dahua/sdklog/2019-12-25_14-32-35.log +cloud/dahua/sdklog/2019-12-25_14-36-10.log +cloud/dahua/sdklog/2019-12-25_14-36-57.log +cloud/haikangface/hs_err_pid21508.log +cloud/log/2019-12-25/下发指令.txt +cloud/quartz/src/pom.xml +cloud/sdklog/2019-11-25_17-32-54.log +cloud/sdklog/2019-11-28_13-51-36.log +cloud/sdklog/2019-11-28_13-55-18.log +cloud/sdklog/2019-11-28_14-13-23.log +cloud/sdklog/2019-11-28_14-14-31.log +cloud/sdklog/2019-11-28_14-52-30.log +cloud/sdklog/2019-11-28_14-53-41.log +cloud/sdklog/2019-11-28_14-54-22.log +cloud/sdklog/2019-11-28_14-55-12.log +cloud/sdklog/2019-11-28_15-06-32.log +cloud/sdklog/2019-11-29_13-58-21.log +cloud/sdklog/2019-11-29_14-04-29.log +cloud/sdklog/2019-11-29_16-33-47.log +cloud/sdklog/2019-11-29_17-27-52.log +cloud/sdklog/2019-12-04_14-29-05.log +cloud/sdklog/2019-12-11_16-36-43.log +cloud/sdklog/2019-12-11_16-53-13.log +cloud/sdklog/2019-12-11_16-56-55.log +cloud/sdklog/2019-12-11_17-06-39.log +cloud/sdklog/2019-12-11_17-14-50.log +cloud/sdklog/2019-12-11_17-39-25.log +cloud/sdklog/2019-12-11_17-42-05.log +cloud/sdklog/2019-12-11_17-43-51.log +cloud/sdklog/2019-12-11_17-45-31.log +cloud/sdklog/2019-12-11_17-46-29.log +cloud/sdklog/2019-12-11_17-47-45.log +cloud/sdklog/2019-12-11_17-49-52.log +cloud/sdklog/2019-12-11_17-50-53.log +cloud/sdklog/2019-12-11_17-57-54.log +cloud/sdklog/2019-12-11_18-02-49.log +cloud/sdklog/2019-12-24_17-19-40.log +cloud/sdklog/2019-12-24_17-21-01.log +cloud/sdklog/2019-12-24_17-21-32.log +cloud/sdklog/2019-12-24_17-22-24.log +cloud/sdklog/2019-12-24_17-31-53.log +cloud/sdklog/2019-12-24_17-36-03.log +cloud/sdklog/2019-12-24_17-53-50.log +cloud/sdklog/2019-12-24_18-04-46.log +cloud/sdklog/2019-12-24_18-06-10.log +cloud/sdklog/2019-12-24_18-14-08.log +cloud/sdklog/2019-12-25_10-21-04.log +cloud/sdklog/2019-12-25_10-24-26.log +cloud/sdklog/2019-12-25_10-42-31.log +cloud/sdklog/2019-12-25_10-54-11.log +cloud/sdklog/2019-12-25_12-03-48.log +cloud/sdklog/2019-12-25_12-04-39.log +cloud/sdklog/2019-12-25_12-09-35.log +cloud/sdklog/2019-12-25_12-12-10.log +cloud/sdklog/2019-12-25_12-25-06.log +cloud/sdklog/2019-12-25_12-26-52.log +cloud/sdklog/2019-12-25_13-44-14.log +cloud/sdklog/2019-12-25_13-47-18.log +cloud/sdklog/2019-12-25_13-48-18.log +cloud/sdklog/2019-12-25_13-49-20.log +cloud/sdklog/2019-12-25_14-24-38.log +cloud/sdklog/2019-12-25_14-33-26.log diff --git a/cloud/dahua/pom.xml b/cloud/dahua/pom.xml index e2a3818..cf91588 100644 --- a/cloud/dahua/pom.xml +++ b/cloud/dahua/pom.xml @@ -11,6 +11,7 @@ dahua 1.0.0 dahua + http://maven.apache.org Demo project for Spring Boot @@ -117,7 +118,11 @@ mybatis-spring-boot-starter 2.0.1 - + + com.sincere + common + 1.0.0 + @@ -165,6 +170,12 @@ 4.1.0 compile + + + + + + @@ -185,6 +196,27 @@ + + + org.apache.maven.plugins + maven-dependency-plugin + + + + copy-dependencies + package + + copy-dependencies + + + ${project.build.directory}/libs + true + true + true + + + + diff --git a/cloud/dahua/src/main/java/com/example/dahua/MyTask.java b/cloud/dahua/src/main/java/com/example/dahua/MyTask.java index 169e504..040e028 100644 --- a/cloud/dahua/src/main/java/com/example/dahua/MyTask.java +++ b/cloud/dahua/src/main/java/com/example/dahua/MyTask.java @@ -71,9 +71,9 @@ public class MyTask implements ApplicationRunner { public void run(ApplicationArguments args) throws Exception { // 121.40.109.21 - LoginModule.init(disConnect, haveReConnect); // 打开工程,初始化 +// LoginModule.init(disConnect, haveReConnect); // 打开工程,初始化 - autoRegister();//自注册 +// autoRegister();//自注册 // System.out.println(" sendRecordDao:"+sendRecordDao.getSenSuccess()); } @@ -233,27 +233,19 @@ public class MyTask implements ApplicationRunner { } public synchronized void reloadPic() { - - /* Set set = lLongMap.keySet(); - Iterator iterator = set.iterator(); - - while (iterator.hasNext()){ - String deviceId= iterator.next(); - System.out.println("deviceId:"+deviceId+" llong:"+lLongMap.get(deviceId)); - GateModule.stopRealLoadPic(lLongMap.get(deviceId)); - GateModule.realLoadPic(0,analyzerCallback,lLongMap.get(deviceId)); - }*/ - - if (null!=deviceInfoBeans){ + isHasNewDevice = false; + if (null!=deviceInfoBeans&&deviceInfoBeans.size()>0){ for (DeviceInfoBean dev : deviceInfoBeans) { - FileUtils.getInstance().writeLogs(dev.getDevcieId() + "------" + lLongMap.get(dev.getDevcieId()), FileUtils.device_login); - if (lLongMap.get(dev.getDevcieId()).intValue() > 0) - GateModule.realLoadPic(0, analyzerCallback, lLongMap.get(dev.getDevcieId())); +// FileUtils.getInstance().writeLogs(dev.getDevcieId() + "------" + lLongMap.get(dev.getDevcieId()), FileUtils.device_login); + if (lLongMap.get(dev.getDevcieId()).intValue() > 0){ + NetSDKLib.LLong lLong = GateModule.realLoadPic(0, analyzerCallback, lLongMap.get(dev.getDevcieId())); + if (lLong.intValue()!=-1){ + deviceInfoBeans.remove(dev); + } + } } - - isHasNewDevice = false; } } diff --git a/cloud/dahua/src/main/java/com/example/dahua/Test.java b/cloud/dahua/src/main/java/com/example/dahua/Test.java index b2ee71c..d28cb47 100644 --- a/cloud/dahua/src/main/java/com/example/dahua/Test.java +++ b/cloud/dahua/src/main/java/com/example/dahua/Test.java @@ -1,88 +1,12 @@ package com.example.dahua; -import com.drew.imaging.jpeg.JpegMetadataReader; -import com.drew.imaging.jpeg.JpegProcessingException; -import com.drew.metadata.Directory; -import com.drew.metadata.Metadata; -import com.drew.metadata.Tag; -import com.example.dahua.bean.AttendanceRecords; -import com.example.dahua.bean.UserInfoBean; -import com.example.dahua.dao.UserDao; -import com.example.dahua.xiananDao.SendRecordDao; -import org.springframework.beans.factory.annotation.Autowired; - -import java.io.File; -import java.io.IOException; -import java.text.SimpleDateFormat; -import java.util.ArrayList; -import java.util.Date; -import java.util.List; public class Test { - @Autowired - SendRecordDao sendRecordDao; - - @Autowired - UserDao userDao; - public static void main(String[] args) { -// new Test().getData(); - File file = new File("C:\\TaoHandong\\copy\\School951\\Student\\505766.jpg"); - - try { - Metadata metadata = JpegMetadataReader.readMetadata(file); - for ( Directory directory : metadata.getDirectories() ) { - for (Tag tag : directory.getTags()) { - //格式化输出[directory.getName()] - tag.getTagName() = tag.getDescription() - System.out.format("[%s] - %s = %s\n", - directory.getName(), tag.getTagName(), tag.getDescription()); - if (tag.getTagName().contains("Date")){ - - SimpleDateFormat simpleDateFormat = new SimpleDateFormat("yyyy-MM-dd HH:mm:ss"); - System.out.println(tag.getDescription()); - Date date= new Date(new Test().getData(tag.getDescription())); - System.out.println(simpleDateFormat.format(date)); - - } - } - } - - - } catch (JpegProcessingException e) { - e.printStackTrace(); - } catch (IOException e) { - e.printStackTrace(); - } } - private String getData(String content) { - - content = content.replace("星期一","Mon"); - content = content.replace("星期二","Tues"); - content = content.replace("星期三","Wed"); - content = content.replace("星期四","Thur"); - content = content.replace("星期五","Fri"); - content = content.replace("星期六","Sat"); - content = content.replace("星期日","Sun"); - - - content = content.replace("一月","Jan"); - content = content.replace("二月","Feb"); - content = content.replace("三月","Mar"); - content = content.replace("四月","Apr"); - content = content.replace("五月","May"); - content = content.replace("六月","Jun"); - content = content.replace("七月","Jul"); - content = content.replace("八月","Aug"); - content = content.replace("九月","Sep"); - content = content.replace("十月","Oct"); - content = content.replace("十一月","Nov"); - content = content.replace("十二月","Dec"); - - return content; - } } 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 206e540..c668708 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 @@ -38,6 +38,7 @@ import java.util.List; @EnableScheduling public class MyScheduledTask { + @Autowired SendRecordDao sendRecordDao; @@ -77,7 +78,7 @@ public class MyScheduledTask { SimpleDateFormat simpleDateFormat = new SimpleDateFormat("HH"); int hour = Integer.parseInt(simpleDateFormat.format(new Date())); - if (hour == 7 && !isCloseYT) { + /*if (hour == 7 && !isCloseYT) { isCloseYT = true; close(31, 97); } @@ -85,7 +86,7 @@ public class MyScheduledTask { if (hour == 17 && isCloseYT) { isCloseYT = false; close(30, 97); - } + }*/ /* if (hour == 6 && !isClose) { isClose = true; @@ -101,7 +102,7 @@ public class MyScheduledTask { dealData(); } else if (hour >= 13 && hour < 14) { dealData(); - } else if (hour >= 18 || hour < 5) { + } else if (hour >= 20 || hour < 5) { dealData(); } @@ -121,6 +122,7 @@ public class MyScheduledTask { File file = new File(imgFilPath); File[] files = file.listFiles(); Date currentDate = new Date(); + if (null!=files) for (int i = 0; i < files.length; i++) { File imgFile = files[i]; String name = imgFile.getName().split("\\.")[0]; @@ -171,7 +173,7 @@ public class MyScheduledTask { String ip = new Utils().getHostAddress(); System.out.println("ip:"+ip); - if (ip.startsWith("192")) + if (ip.startsWith("192")||ip.contains("172.16.247.64")) return; /** 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 46b55d1..1a97488 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 @@ -42,7 +42,7 @@ public class SendUserInfoTask { SendRecordDao sendRecordDao; @Async("taskExecutor") - public void doTaskOne(String file, List attendanceBeans, UserInfoBean userInfoBean, String schoolId, int failType,int userType) 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]; //判断是否是副卡 @@ -60,13 +60,13 @@ public class SendUserInfoTask { sendRecordBean.setSchoolId(Integer.parseInt(schoolId)); sendRecordBean.setSchoolName(userDao.getSchoolName(schoolId)); sendRecordBean.setTime(new SimpleDateFormat("yyyy-MM-dd HH:mm:ss").format(new Date())); - sendRecordBean.setUserType(2); + sendRecordBean.setUserType(userType); sendRecordBean.setNum(userInfoBean.getStudent_num()); sendRecordBean.setName(userInfoBean.getName()); sendRecordBean.setImgPath(file); sendRecordBean.setCustomerid(userInfoBean.getStudent_id()); sendRecordBean.setFailType(failType); - sendUserInfoToDev(file, attendanceBeans, userInfoBean, userType+"", sendRecordBean); + sendUserInfoToDev(file, attendanceBeans, userInfoBean, userType + "", sendRecordBean); } @Async("taskExecutor") @@ -153,7 +153,7 @@ public class SendUserInfoTask { if (type == 0 || type == 1) {//学生信息或家长信息 userInfoBean = userDao.getUserInfo(schoolId, studentCode); - HttpUtils.uploadImgs(studentFile,schoolId,studentCode,clint_type,2); + HttpUtils.uploadImgs(studentFile, schoolId, studentCode, clint_type, 2); } else if (type == 2) {//教师信息 TeacherBean teacher = userDao.getTeacher(schoolId, studentCode); if (null != teacher) { @@ -164,7 +164,7 @@ public class SendUserInfoTask { userInfoBean.setStudentcode(teacher.getNum()); userInfoBean.setStudent_id(teacher.getTeacher_id()); } - HttpUtils.uploadImgs(studentFile,schoolId,studentCode,clint_type,1); + HttpUtils.uploadImgs(studentFile, schoolId, studentCode, clint_type, 1); } //判断用户是否存在 @@ -274,6 +274,7 @@ public class SendUserInfoTask { } catch (Exception e) { e.printStackTrace(); } + for (AttendanceBean attendanceBean : attendanceBeans) { pushCardAndFace(attendanceBean, userInfoBean.getUser_id(), userInfoBean.getStudent_num(), userInfoBean.getName(), memory, sendRecordBean); @@ -310,16 +311,19 @@ public class SendUserInfoTask { String cardNum = cardNo(student_num); if (bCardFlags != -1) {//修改卡信息 - GateModule.deleteCard(bCardFlags, loginHandleLong); - userDao.deleteRecordNo(user_id, bCardFlags); - - bCardFlags = GateModule.insertCard(cardNum, user_id, name, "123456" - , Res.string().getCardStatusInt(1), Res.string().getCardTypeInt(1), 0, 0 - , 1, startTime, endTime, loginHandleLong); - - if (bCardFlags != -1) { - int index = userDao.saveRecordNo(user_id, bCardFlags, name, attendanceBean.getClint_id());//存储记录集编号 - } +// GateModule.deleteCard(bCardFlags, loginHandleLong); + GateModule.modifyCard(bCardFlags,cardNum,user_id,name,"123456",Res.string().getCardStatusInt(1),Res.string().getCardTypeInt(1), + 0,0,1,startTime,endTime,loginHandleLong); + userDao.updateRecordNo(user_id,bCardFlags,attendanceBean.getClint_id()); +// userDao.deleteRecordNo(user_id, bCardFlags); + +// bCardFlags = GateModule.insertCard(cardNum, user_id, name, "123456" +// , Res.string().getCardStatusInt(1), Res.string().getCardTypeInt(1), 0, 0 +// , 1, startTime, endTime, loginHandleLong); + +// if (bCardFlags != -1) { +// int index = userDao.saveRecordNo(user_id, bCardFlags, name, attendanceBean.getClint_id());//存储记录集编号 +// } bFaceFalgs = GateModule.modifyFaceInfo(user_id, memory, loginHandleLong); //卡号添加成功,但是人脸不成功的话,就需要新增人脸 if (!bFaceFalgs) @@ -370,7 +374,7 @@ public class SendUserInfoTask { if (bCardFlags == -1 && !bFaceFalgs) { FileUtils.getInstance().writeLogs("下发人脸和卡号失败:" + cardNum + " " + attendanceBean.getClint_id(), FileUtils.sendUserErrTxt); // System.out.println("添加卡信息和人脸失败"); - System.out.println("下发人脸和卡号失败" + "sendRecordBean:" + sendRecordBean); + System.out.println("下发人脸和卡号失败" + "sendRecordBean:" + sendRecordBean.getDeviceID()+" ,"+sendRecordBean.getNum()+","+loginHandleLong+",bCardFlags:"+bCardFlags+"\r\n"); sendRecordBean.setFailContent("下发人脸和卡号失败"); sendRecordDao.updateFace(sendRecordBean.getNum(), sendRecordBean.getDeviceID(), sendRecordBean.getFailType(), 7);//更新下发失败状态 sendRecordBean.setFailType(8); @@ -381,7 +385,7 @@ public class SendUserInfoTask { if (bCardFlags != -1 && !bFaceFalgs) { FileUtils.getInstance().writeLogs("下发卡号成功,人脸失败:" + cardNum + " " + attendanceBean.getClint_id(), FileUtils.sendUserErrTxt); // System.out.println("添加卡信息成功,添加人脸失败"); - System.out.println("customerId:" + sendRecordBean.getCustomerid() + " deviceId:" + sendRecordBean.getDeviceID() + " failType:" + sendRecordBean.getFailType()); + System.out.println("customerId:" + sendRecordBean.getCustomerid() + " deviceId:" + sendRecordBean.getDeviceID() + " failType:" + sendRecordBean.getFailType()+"\r\n"); sendRecordDao.updateFace(sendRecordBean.getNum(), sendRecordBean.getDeviceID(), sendRecordBean.getFailType(), 5);//更新下发失败状态 sendRecordBean.setFailContent("下发卡号成功,人脸失败:照片特征值提取失败"); sendRecordBean.setFailType(5); @@ -391,7 +395,7 @@ public class SendUserInfoTask { // 卡信息已存在,添加人脸成功 if (bCardFlags == -1 && bFaceFalgs) { FileUtils.getInstance().writeLogs("下发人脸成功:" + cardNum + " " + attendanceBean.getClint_id(), FileUtils.sendUserSucTxt); - System.out.println("卡信息已存在,添加人脸成功"); + System.out.println("卡信息已存在,添加人脸成功-----------\n"); } } @@ -412,8 +416,11 @@ public class SendUserInfoTask { if (sendRecordBean.getFailType() == 5) sendRecordBean.setFailType(8); + String imagePath = sendRecordBean.getImgPath().replace("C:/imgCom", + String.format("E:\\wwwhtdocs\\smartcampus\\face17e5\\School%s\\%s", sendRecordBean.getSchoolId(), sendRecordBean.getUserType() == 1 ? "Teacher" : "Student")); + sendRecordDao.addFaceFail(sendRecordBean.getCustomerid(), sendRecordBean.getDeviceID(), sendRecordBean.getNum(), sendRecordBean.getName(), sendRecordBean.getTime(), - sendRecordBean.getSchoolName(), sendRecordBean.getImgPath(), sendRecordBean.getSchoolId(), sendRecordBean.getFailContent(), sendRecordBean.getFailType(), sendRecordBean.getUserType(), 22); + sendRecordBean.getSchoolName(), imagePath , sendRecordBean.getSchoolId(), sendRecordBean.getFailContent(), sendRecordBean.getFailType(), sendRecordBean.getUserType(), 22); // } } @@ -452,15 +459,15 @@ public class SendUserInfoTask { for (int i = 0; i < sendRecordBeanList.size(); i++) { SendRecordBean sendRecordBean = sendRecordBeanList.get(i); - String imgPath = sendRecordBean.getImgPath().replace("face17e50","face17e5"); + String imgPath = sendRecordBean.getImgPath().replace("face17e50", "face17e5"); File file = new File(imgPath); - System.out.println("file:"+file.getAbsolutePath()); + System.out.println("file:" + file.getAbsolutePath()); if (file.exists()) { try { FileInputStream fileInputStream = new FileInputStream(file); String fileName = file.getName(); - fileName = fileName.replace("jpg","png"); - fileName = fileName.replace("jpeg","png"); + fileName = fileName.replace("jpg", "png"); + fileName = fileName.replace("jpeg", "png"); File targetFile = new File(targetrFile, fileName); if (!targetFile.exists()) targetFile.createNewFile(); FileOutputStream fileOutputStream = new FileOutputStream(targetFile); @@ -498,23 +505,30 @@ public class SendUserInfoTask { // int bCardFlags = -1;//记录集编号,存在于设备的 int bCardFlags = userDao.getRecordNo(user_id, deviceId) == null ? -1 : Integer.parseInt(userDao.getRecordNo(user_id, deviceId)); System.out.println("bCardFlags:" + bCardFlags); + if (bCardFlags == -1)bCardFlags = 10; if (bCardFlags != -1) { GateModule.deleteCard(bCardFlags, MyTask.lLongMap.get(deviceId)); } } + @Async("taskExecutor") - public void addWeiGen(){ - List customerIDs = sendRecordDao.getWGFail(); + public void addWeiGen() { + //获取到的设备id集合 + List deviceIds = sendRecordDao.getWGFail(); + String url = "http://121.40.109.21:9000/cleanFail?deviceId="; + RestTemplate restTemplate = new RestTemplate(); - for (int i = 0; i < customerIDs.size(); i++) { - String customerID = customerIDs.get(i); - addKard(customerID, "2");//微耕 + for (int i = 0; i < deviceIds.size(); i++) { + String deviceId = deviceIds.get(i); +// addKard(customerID, "2");//微耕 + String result = restTemplate.getForObject(url + deviceId, String.class); + System.out.println("微耕result:" + result); } MyScheduledTask.isSendWeigeng = false; } - String url = "http://campus.myjxt.com/api/OneCard/UpdateDataBK"; + /* String url = "http://campus.myjxt.com/api/OneCard/UpdateDataBK"; private synchronized void addKard(String customerId, String TerminalType) { StudentBean studentBean = userDao.getStudentUpdate(customerId); if (studentBean != null && studentBean.getStudentCode() != null) { @@ -538,10 +552,10 @@ public class SendUserInfoTask { } else if (studentBean != null && studentBean.getStudentCode() == null) { // System.out.println(studentBean.getName()+"学籍号不存在"); } - } + }*/ @Async("taskExecutor") - public void addHaikangface(){ + public void addHaikangface() { List sendRecordBeanList = sendRecordDao.getSenFailHK("18", "9"); RestTemplate restTemplate = new RestTemplate(); @@ -561,28 +575,29 @@ public class SendUserInfoTask { userTy = "Parent"; break; } - String filePath = String.format("E:\\wwwhtdocs\\SmartCampus\\face17e5\\School%s\\%s\\%s.jpg", sendRecordBean.getSchoolId(), userTy, userDao.getStudentCode(sendRecordBean.getCustomerid())); +// String filePath = String.format("E:\\wwwhtdocs\\SmartCampus\\face17e5\\School%s\\%s\\%s.png", sendRecordBean.getSchoolId(), userTy, userDao.getStudentCode(sendRecordBean.getCustomerid())); + String filePath = sendRecordBean.getImgPath(); String url = "http://114.55.30.100:8089/facereco/sendStuCardAndImg?card={card}&deviceId={deviceId}&endTime={endTime}&" + "filePath={filePath}&name={name}&userType={userType}&validTimeEnabled={validTimeEnabled}&startTime={startTime}"; - Map map = new HashMap<>(); + Map map = new HashMap<>(); - map.put("card",sendRecordBean.getNum()); - map.put("deviceId",sendRecordBean.getDeviceID()); - map.put("endTime","2033-10-01 10:00:00"); - map.put("filePath",filePath); - map.put("name",sendRecordBean.getName()); - map.put("userType",userType); - map.put("validTimeEnabled","1"); - map.put("startTime","2019-10-01 10:00:00"); + map.put("card", sendRecordBean.getNum()); + map.put("deviceId", sendRecordBean.getDeviceID()); + map.put("endTime", "2033-10-01 10:00:00"); + map.put("filePath", filePath); + map.put("name", sendRecordBean.getName()); + map.put("userType", userType); + map.put("validTimeEnabled", "1"); + map.put("startTime", "2019-10-01 10:00:00"); - ResponseEntity responseEntity = restTemplate.getForEntity(url,String.class,map); + ResponseEntity responseEntity = restTemplate.getForEntity(url, String.class, map); - System.out.println("responseEntity:---------------------------"+map.toString()); + System.out.println("responseEntity:---------------------------" + map.toString()); String result = responseEntity.getBody(); - result = result.replace("",""); - result = result.replace("",""); + result = result.replace("", ""); + result = result.replace("", ""); boolean result1 = Boolean.parseBoolean(result); @@ -597,7 +612,7 @@ public class SendUserInfoTask { } @Async("taskExecutor") - public void addDahuaFace(){ + public void addDahuaFace() { List sendRecordBeanList = sendRecordDao.getSenFail("22"); for (int i = 0; i < sendRecordBeanList.size(); i++) { @@ -641,7 +656,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(),sendRecordBean.getUserType()); + , userInfoBean, sendRecordBean.getSchoolId() + "", sendRecordBean.getFailType(), sendRecordBean.getUserType()); } } 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 index 5c2b18d..d7f9f07 100644 --- a/cloud/dahua/src/main/java/com/example/dahua/control/FileControl.java +++ b/cloud/dahua/src/main/java/com/example/dahua/control/FileControl.java @@ -1,9 +1,12 @@ package com.example.dahua.control; +import com.example.dahua.async.SendUserInfoTask; import com.example.dahua.bean.UploadImg; import com.example.dahua.service.UserService; import io.swagger.annotations.Api; +import io.swagger.annotations.ApiOperation; import org.springframework.beans.factory.annotation.Autowired; +import org.springframework.http.MediaType; import org.springframework.web.bind.annotation.*; import org.springframework.web.multipart.MultipartFile; @@ -14,12 +17,15 @@ import java.io.IOException; @RestController @Api("文件管理器") -@RequestMapping("file/*") +@RequestMapping(value = "file/*",produces = MediaType.APPLICATION_JSON_UTF8_VALUE) public class FileControl { @Autowired UserService userService; + @Autowired + SendUserInfoTask sendUserInfoTask; + @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) { @@ -33,7 +39,8 @@ public class FileControl { FileOutputStream fileOutputStream = new FileOutputStream(dest); fileOutputStream.write(file.getBytes()); - userService.uploadImgAndUserInfo(dest.getAbsolutePath(), schoolId, studentCode, clint_type,userType); + fileOutputStream.close(); + userService.uploadImgAndUserInfo(dest.getAbsolutePath(), schoolId, studentCode, clint_type,userType,""); return "1"; } catch (FileNotFoundException e) { e.printStackTrace(); @@ -42,4 +49,40 @@ public class FileControl { } return "0"; } + + + @RequestMapping(method = RequestMethod.POST, value = "uploadImgToDev") + public String uploadImgToDev(@RequestParam("file") MultipartFile file, @RequestParam("schoolId") String schoolId, @RequestParam("studentCode") String studentCode, + @RequestParam("clint_type") String clint_type,@RequestParam("userType") int userType,@RequestParam("devid")String devid) { + 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()); + fileOutputStream.close(); + userService.uploadImgAndUserInfo(dest.getAbsolutePath(), schoolId, studentCode, clint_type,userType,devid); + return "1"; + } catch (FileNotFoundException e) { + e.printStackTrace(); + } catch (IOException e) { + e.printStackTrace(); + } + return "0"; + } + + @RequestMapping(value = "deleteFace", method = RequestMethod.GET) + @ApiOperation("删除人脸") + public void deleteFace(@RequestParam("cardNum") String cardNum, @RequestParam("deviceId") String deviceId) { + + sendUserInfoTask.deleteFace(cardNum, deviceId); + + } + + + + } 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 edb83fd..7136116 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 @@ -6,6 +6,7 @@ import com.example.dahua.async.SendUserInfoTask; import com.example.dahua.lib.CompressPic; import com.example.dahua.service.UserService; import com.example.dahua.utils.*; +import com.sincere.common.util.AuthService; import io.swagger.annotations.Api; import io.swagger.annotations.ApiImplicitParam; import io.swagger.annotations.ApiImplicitParams; @@ -36,11 +37,9 @@ import java.util.*; */ @RestController("/user/") @Api(tags = "下发用户信息") -@RequestMapping("/user/") +@RequestMapping(value = "/user/*",produces = MediaType.APPLICATION_JSON_UTF8_VALUE) public class UserControl { - private int count = 0; - @Autowired UserService userService; @@ -50,14 +49,12 @@ public class UserControl { @Autowired MyTask myTasks; -// @Value("${haikangfaceurl}") -// private String haikangfaceurl; @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) { // return userService.uploadImgAndUserInfo(file, schoolId, studentCode, clint_type); - return HttpUtils.uploadImgs(new File(file),schoolId,studentCode,clint_type,2); + return HttpUtils.uploadImgs(new File(file),schoolId,studentCode,clint_type,file.contains("Teacher")?1:2); } @@ -364,13 +361,13 @@ public class UserControl { } } - @RequestMapping(value = "deleteFace", method = RequestMethod.GET) - @ApiOperation("删除人脸") - public void deleteFace(@RequestParam("cardNum") String cardNum, @RequestParam("deviceId") String deviceId) { - - sendUserInfoTask.deleteFace(cardNum, deviceId); - - } +// @RequestMapping(value = "deleteFace", method = RequestMethod.GET) +// @ApiOperation("删除人脸") +// public void deleteFace(@RequestParam("cardNum") String cardNum, @RequestParam("deviceId") String deviceId) { +// +// sendUserInfoTask.deleteFace(cardNum, deviceId); +// +// } @RequestMapping(value = "movePic", method = RequestMethod.GET) @@ -447,12 +444,12 @@ public class UserControl { } catch (IOException e) { e.printStackTrace(); } -return "解析失败"; + return "解析失败"; } - private String url = "https://aip.baidubce.com/rest/2.0/ocr/v1/general_basic?access_token=24.12f07855bae00621f319d10f00f6aaa2.2592000.1576727813.282335-15990462"; + private String url = "https://aip.baidubce.com/rest/2.0/ocr/v1/general_basic?access_token="+ AuthService.getAuth(); private String getAnswer(String imgUrl, int type) { RestTemplate restTemplate = new RestTemplate(); diff --git a/cloud/dahua/src/main/java/com/example/dahua/dao/UserDao.java b/cloud/dahua/src/main/java/com/example/dahua/dao/UserDao.java index 467ffa3..34f6a1f 100644 --- a/cloud/dahua/src/main/java/com/example/dahua/dao/UserDao.java +++ b/cloud/dahua/src/main/java/com/example/dahua/dao/UserDao.java @@ -17,6 +17,9 @@ public interface UserDao { @Select("select * from SZ_Attendance where school_id = #{school_id} and clint_type = #{clint_type}") List getAttendanceBeans(@Param("school_id")String school_id,@Param("clint_type")String clint_type); + @Select("select * from SZ_Attendance where school_id = #{school_id} and clint_type = #{clint_type} and clint_id = #{clint_id}") + List getAttendanceBeanWithId(@Param("school_id")String school_id,@Param("clint_type")String clint_type,@Param("clint_id")String clint_id); + @Select(" select * from SZ_V_School_Student where school_id = #{school_id} and studentcode = #{studentcode}") UserInfoBean getUserInfo(@Param("school_id")String school_id,@Param("studentcode")String studentcode); @@ -46,6 +49,9 @@ public interface UserDao { @Delete("delete from SZ_Student_RecoderNo where user_id = #{user_id} and recordNo = #{recordNo}") void deleteRecordNo(@Param("user_id") String user_id, @Param("recordNo") int recordNo); + @Update("update SZ_Student_RecoderNo set user_id = #{user_id} where deviceId = #{deviceId} and recordNo = #{recordNo}") + void updateRecordNo(@Param("user_id") String user_id, @Param("recordNo") int recordNo,@Param("deviceId")String deviceId); + @Select("select clint_id from SZ_Attendance where clint_type = #{clint_type} and school_id = #{school_id}") List getDeviceIds(@Param("clint_type")String clint_type ,@Param("school_id") int school_id); 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 bd64086..e671678 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 @@ -16,7 +16,7 @@ public interface UserService { * @param clint_type * @return */ - List getAttendanceBeans(String schoolId,String clint_type); + List getAttendanceBeans(String schoolId,String clint_type,String devid); /** * 获取学生基本信息 @@ -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,int userType); + boolean uploadImgAndUserInfo(String file,String schoolId,String studentCode,String clint_type,int userType,String devid); /** 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 79824d6..bffac7a 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 @@ -5,6 +5,7 @@ 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.apache.commons.lang.StringUtils; import org.springframework.beans.factory.annotation.Autowired; import org.springframework.stereotype.Repository; import org.springframework.stereotype.Service; @@ -22,7 +23,10 @@ public class UserServiceImp implements UserService { SendUserInfoTask myTask; @Override - public List getAttendanceBeans(String schoolId, String clint_type) { + public List getAttendanceBeans(String schoolId, String clint_type,String devid) { + + if (!StringUtils.isEmpty(devid))return userDao.getAttendanceBeanWithId(schoolId,clint_type,devid); + return userDao.getAttendanceBeans(schoolId, clint_type); } @@ -41,9 +45,9 @@ public class UserServiceImp implements UserService { * @return */ @Override - public boolean uploadImgAndUserInfo(String file, String schoolId, String studentCode, String clint_type, int userType) { + public boolean uploadImgAndUserInfo(String file, String schoolId, String studentCode, String clint_type, int userType,String devid) { + List attendanceBeans = getAttendanceBeans(schoolId, clint_type,devid);//获取学校下的大华设备 - List attendanceBeans = getAttendanceBeans(schoolId, clint_type);//获取学校下的大华设备 UserInfoBean userInfoBean = null; try { if (userType == 2) { diff --git a/cloud/dahua/src/main/java/com/example/dahua/xiananDao/SendRecordDao.java b/cloud/dahua/src/main/java/com/example/dahua/xiananDao/SendRecordDao.java index eb754db..42eb332 100644 --- a/cloud/dahua/src/main/java/com/example/dahua/xiananDao/SendRecordDao.java +++ b/cloud/dahua/src/main/java/com/example/dahua/xiananDao/SendRecordDao.java @@ -22,59 +22,62 @@ public interface SendRecordDao { @Insert("insert into Face_SendSuccess values(#{deviceID},#{customerid},#{num},#{name},#{time},#{schoolName},#{imgPath},#{schoolId},#{userType},#{deviceType})") int addFaceSuccess(@Param("customerid") String customerid, @Param("deviceID") String deviceID, @Param("num") String num, @Param("name") String name, - @Param("time") String time, @Param("schoolName") String schoolName, @Param("imgPath") String imgPath, @Param("schoolId") int schoolId, - @Param("userType") int userType,@Param("deviceType")int deviceType); + @Param("time") String time, @Param("schoolName") String schoolName, @Param("imgPath") String imgPath, @Param("schoolId") int schoolId, + @Param("userType") int userType, @Param("deviceType") int deviceType); @Select("select * from Face_SendSuccess where num = #{num} and deviceID = #{deviceID} and schoolId = #{schoolId}") - List getFaceSucceIsexit(@Param("deviceID") String clint_id, @Param("schoolId") String school_id,@Param("num") String num); + List getFaceSucceIsexit(@Param("deviceID") String clint_id, @Param("schoolId") String school_id, @Param("num") String num); @Delete("delete Face_SendSuccess where num = #{num} and deviceID = #{deviceID} ") - void deleteFaceSuccess(@Param("deviceID") String clint_id,@Param("num") String num); + void deleteFaceSuccess(@Param("deviceID") String clint_id, @Param("num") String num); @Update("update Face_SendSuccess set time = #{time} where num = #{num} and deviceID = #{deviceID} ") - void updateFaceSuccess(@Param("time")String time,@Param("deviceID") String clint_id,@Param("num") String num); + void updateFaceSuccess(@Param("time") String time, @Param("deviceID") String clint_id, @Param("num") String num); @Insert("insert into Face_SendFail values(#{deviceID},#{customerid},#{num},#{name},#{time},#{schoolName},#{imgPath},#{schoolId},#{failContent},#{failType},#{userType},#{deviceType})") void addFaceFail(@Param("customerid") String customerid, @Param("deviceID") String deviceID, @Param("num") String num, @Param("name") String name, @Param("time") String time, @Param("schoolName") String schoolName, @Param("imgPath") String imgPath, @Param("schoolId") int schoolId, @Param("failContent") String failContent, - @Param("failType") int failType, @Param("userType") int userType,@Param("deviceType")int deviceType); + @Param("failType") int failType, @Param("userType") int userType, @Param("deviceType") int deviceType); @Select("select * from Face_SendFail where deviceType = #{deviceType}") - List getSenFail(@Param("deviceType")String deviceType); + List getSenFail(@Param("deviceType") String deviceType); @Select("select * from Face_SendFail where deviceType = #{deviceType} and failType = #{failType}") - List getSenFailHK(@Param("deviceType")String deviceType,@Param("failType")String failType); + List getSenFailHK(@Param("deviceType") String deviceType, @Param("failType") String failType); + +// @Select("select a.customerID from [dbo].[WG_SendFail] a inner join DBlan137.smartcampus.dbo.SZ_Attendance b on a.deviceID=b.clint_id and b.isConnection=1 order by createTime desc") +// List getWGFail(); - @Select("select a.customerID from [dbo].[WG_SendFail] a inner join DBlan137.smartcampus.dbo.SZ_Attendance b on a.deviceID=b.clint_id and b.isConnection=1 order by createTime desc") - List getWGFail(); + @Select("select DISTINCT a.deviceId from [dbo].[WG_SendFail] a inner join DBlan137.smartcampus.dbo.SZ_Attendance b on a.deviceID=b.clint_id and b.isConnection=1") + List getWGFail(); @Select("select Top(1) deviceID from Face_SendFail where deviceID = #{deviceID} and schoolId = #{schoolId}") String getFailIsExit(@Param("deviceID") String clint_id, @Param("schoolId") String school_id); @Select("select Top(1) Name from Face_SendFail where deviceID = #{deviceID} and num = #{num} and failType = #{failType}") - String getFailNameIsExit(@Param("deviceID") String deviceID,@Param("num") String num, @Param("failType") int failType); + String getFailNameIsExit(@Param("deviceID") String deviceID, @Param("num") String num, @Param("failType") int failType); @Select("select * from Face_SendFail where deviceID = #{deviceID} and customerid = #{customerid}") - List getFaceFailIsExit(@Param("deviceID") String deviceID,@Param("customerid") String customerid); + List getFaceFailIsExit(@Param("deviceID") String deviceID, @Param("customerid") String customerid); @Delete("delete Face_SendFail where deviceID = #{deviceID} and num = #{num}") void deleteFaceFail(@Param("num") String num, @Param("deviceID") String deviceID); @Update("update Face_SendFail set failType = #{upfailType} where num = #{num} and deviceID = #{deviceID} and failType = #{failType}") - void updateFace(@Param("num") String num, @Param("deviceID") String deviceID, @Param("failType") int failType,@Param("upfailType") int upfailType); + void updateFace(@Param("num") String num, @Param("deviceID") String deviceID, @Param("failType") int failType, @Param("upfailType") int upfailType); @Select("select schoolName from Face_SendFail where schoolId = #{schoolId} and failType = #{failType}") String getSchoolDevice(@Param("schoolId") int schoolId, @Param("failType") int failType); @Select("select * from Face_SendFail where schoolId = #{schoolId} and userType = #{userType} and deviceID = #{deviceID}") - List getFaceFails(@Param("userType")int userType,@Param("schoolId")int schoolId,@Param("deviceID")String deviceID); + List getFaceFails(@Param("userType") int userType, @Param("schoolId") int schoolId, @Param("deviceID") String deviceID); @Insert("insert into Face_Recoder values(#{deviceId},#{user_id},#{name},#{imgurl},#{inOrOut},#{time},#{cardNum})") - void addFaceRecoder(@Param("deviceId") String deviceId, @Param("user_id")String user_id, @Param("name")String name, - @Param("imgurl")String imgurl, @Param("inOrOut")int inOrOut, @Param("time")String time, - @Param("cardNum")String cardNum); + void addFaceRecoder(@Param("deviceId") String deviceId, @Param("user_id") String user_id, @Param("name") String name, + @Param("imgurl") String imgurl, @Param("inOrOut") int inOrOut, @Param("time") String time, + @Param("cardNum") String cardNum); } diff --git a/cloud/dahua/src/test/java/com/example/dahua/DahuaApplicationTests.java b/cloud/dahua/src/test/java/com/example/dahua/DahuaApplicationTests.java index d2db643..19e1d87 100644 --- a/cloud/dahua/src/test/java/com/example/dahua/DahuaApplicationTests.java +++ b/cloud/dahua/src/test/java/com/example/dahua/DahuaApplicationTests.java @@ -311,13 +311,13 @@ public class DahuaApplicationTests { @Test public void test2() { - RestTemplate restTemplate = new RestTemplate(); + /* RestTemplate restTemplate = new RestTemplate(); String url = "http://localhost:8991/user/checkFace?url=C:\\Users\\taohandong\\Pictures\\test.jpg"; - System.out.println("result:"+ restTemplate.getForObject(url,String.class)); + System.out.println("result:"+ restTemplate.getForObject(url,String.class));*/ } @@ -325,6 +325,12 @@ public class DahuaApplicationTests { @Test public void test1() { + + String url = "http://121.40.109.21:9000/cleanFail?deviceId="; + RestTemplate restTemplate = new RestTemplate(); + + String result = restTemplate.getForObject(url+"253164293",String.class); +System.out.println("result:"+result); /* try { BufferedReader bufferedReader = new BufferedReader(new FileReader("C:\\TaoHandong\\copy\\宿舍.txt")); String content = null; diff --git a/cloud/geteway/pom.xml b/cloud/geteway/pom.xml index 81ac48b..184f4e0 100644 --- a/cloud/geteway/pom.xml +++ b/cloud/geteway/pom.xml @@ -7,7 +7,7 @@ cloud 1.0.0 - com.example + com.example.geteway geteway 1.0.0 geteway @@ -19,39 +19,41 @@ - + org.springframework.cloud - spring-cloud-starter-netflix-zuul + spring-cloud-starter-gateway - - io.springfox - springfox-swagger2 - 2.9.2 + org.springframework.boot + spring-boot-starter-data-redis-reactive - io.springfox springfox-swagger-ui 2.9.2 - - - org.springframework.boot - spring-boot-starter-test - test + io.springfox + springfox-swagger2 + 2.9.2 - - - - org.springframework.boot - spring-boot-maven-plugin - - - + + + + + + + + + + + + + + + diff --git a/cloud/geteway/src/main/java/com/example/geteway/DocumentationConfig.java b/cloud/geteway/src/main/java/com/example/geteway/DocumentationConfig.java deleted file mode 100644 index c40afd2..0000000 --- a/cloud/geteway/src/main/java/com/example/geteway/DocumentationConfig.java +++ /dev/null @@ -1,53 +0,0 @@ -package com.example.geteway; - -import org.springframework.cloud.netflix.zuul.filters.Route; -import org.springframework.cloud.netflix.zuul.filters.RouteLocator; -import org.springframework.context.annotation.Primary; -import org.springframework.stereotype.Component; -import springfox.documentation.swagger.web.SwaggerResource; -import springfox.documentation.swagger.web.SwaggerResourcesProvider; - -import java.util.ArrayList; -import java.util.List; - -@Component -@Primary -public class DocumentationConfig implements SwaggerResourcesProvider { - - private RouteLocator routeLocator; - - public DocumentationConfig(RouteLocator routeLocator){ - this.routeLocator = routeLocator; - } - - @Override - public List get() { - - List resources = new ArrayList(); - - List routes = routeLocator.getRoutes(); - - System.out.println("routes:"+routes.toString()); - - for (Route route : - routes) { - resources.add(swaggerResource(route.getId(), route.getFullPath().replace("**", "v2/api-docs"), "1.0")); - } - -// resources.add(swaggerResource("海康指纹接口","/mygateway/haikangserver/v2/api-docs","1.0")); - -// resources.add(swaggerResource("大华人脸接口","","1.0")); - - return resources; - } - - private SwaggerResource swaggerResource(String name,String location,String version){ - - SwaggerResource swaggerResource = new SwaggerResource(); - swaggerResource.setName(name); - swaggerResource.setLocation(location); - swaggerResource.setSwaggerVersion(version); - return swaggerResource; - - } -} diff --git a/cloud/geteway/src/main/java/com/example/geteway/GetewayApplication.java b/cloud/geteway/src/main/java/com/example/geteway/GetewayApplication.java index 575ff56..27b3d08 100644 --- a/cloud/geteway/src/main/java/com/example/geteway/GetewayApplication.java +++ b/cloud/geteway/src/main/java/com/example/geteway/GetewayApplication.java @@ -2,20 +2,12 @@ package com.example.geteway; import org.springframework.boot.SpringApplication; import org.springframework.cloud.client.SpringCloudApplication; -import org.springframework.cloud.client.discovery.EnableDiscoveryClient; -import org.springframework.cloud.netflix.zuul.EnableZuulProxy; -import org.springframework.context.annotation.Bean; -import org.springframework.web.cors.CorsConfiguration; -import org.springframework.web.cors.UrlBasedCorsConfigurationSource; -import org.springframework.web.filter.CorsFilter; /** * 统一网关配置 * 通过服务路由的功能,在对外提供服务的时候,只需要通过暴露Zuul中配置的调用地址就可以让调用方统一的来访问我们的服务; */ @SpringCloudApplication -@EnableDiscoveryClient -@EnableZuulProxy public class GetewayApplication { public static void main(String[] args) { @@ -23,18 +15,4 @@ public class GetewayApplication { } - // 跨域访问 - @Bean - public CorsFilter corsFilter() { - final UrlBasedCorsConfigurationSource source = new UrlBasedCorsConfigurationSource(); - final CorsConfiguration config = new CorsConfiguration(); - config.setAllowCredentials(true); - config.addAllowedOrigin("*"); - config.addAllowedHeader("*"); - config.addAllowedMethod("*"); - config.setMaxAge(3600L); - source.registerCorsConfiguration("/**", config); - return new CorsFilter(source); - } - } diff --git a/cloud/geteway/src/main/java/com/example/geteway/Swagger2.java b/cloud/geteway/src/main/java/com/example/geteway/Swagger2.java deleted file mode 100644 index fbf6960..0000000 --- a/cloud/geteway/src/main/java/com/example/geteway/Swagger2.java +++ /dev/null @@ -1,37 +0,0 @@ -package com.example.geteway; - -import org.springframework.context.annotation.Bean; -import org.springframework.context.annotation.Configuration; -import springfox.documentation.builders.ApiInfoBuilder; -import springfox.documentation.builders.PathSelectors; -import springfox.documentation.builders.RequestHandlerSelectors; -import springfox.documentation.service.ApiInfo; -import springfox.documentation.spi.DocumentationType; -import springfox.documentation.spring.web.plugins.Docket; -import springfox.documentation.swagger2.annotations.EnableSwagger2; - -@Configuration -@EnableSwagger2 -public class Swagger2 { - - @Bean - public Docket createRestApi() { - return new Docket(DocumentationType.SWAGGER_2) - .apiInfo(apiInfo()) - .select() - .apis(RequestHandlerSelectors.basePackage("com.example.geteway.control")) - .paths(PathSelectors.any()) - .build(); - } - - private ApiInfo apiInfo() { - return new ApiInfoBuilder() - .title("网关服务统一接口") - .contact("sincere") - .description("") - .termsOfServiceUrl("") - .version("1.0") - .build(); - } - -} diff --git a/cloud/geteway/src/main/java/com/example/geteway/client/config/SwaggerProvider.java b/cloud/geteway/src/main/java/com/example/geteway/client/config/SwaggerProvider.java new file mode 100644 index 0000000..acceb2b --- /dev/null +++ b/cloud/geteway/src/main/java/com/example/geteway/client/config/SwaggerProvider.java @@ -0,0 +1,48 @@ +package com.example.geteway.client.config; + +import lombok.AllArgsConstructor; +import org.springframework.cloud.gateway.config.GatewayProperties; +import org.springframework.cloud.gateway.route.RouteLocator; +import org.springframework.cloud.gateway.support.NameUtils; +import org.springframework.context.annotation.Primary; +import org.springframework.stereotype.Component; +import springfox.documentation.swagger.web.SwaggerResource; +import springfox.documentation.swagger.web.SwaggerResourcesProvider; + +import java.util.ArrayList; +import java.util.List; + +/** + * @author Sywd + */ +@Component +@Primary +@AllArgsConstructor +public class SwaggerProvider implements SwaggerResourcesProvider { + public static final String API_URI = "/v2/api-docs"; + private final RouteLocator routeLocator; + private final GatewayProperties gatewayProperties; + + + @Override + public List get() { + List resources = new ArrayList<>(); + List routes = new ArrayList<>(); + routeLocator.getRoutes().subscribe(route -> routes.add(route.getId())); + gatewayProperties.getRoutes().stream().filter(routeDefinition -> routes.contains(routeDefinition.getId())) + .forEach(routeDefinition -> routeDefinition.getPredicates().stream() + .filter(predicateDefinition -> ("Path").equalsIgnoreCase(predicateDefinition.getName())) + .forEach(predicateDefinition -> resources.add(swaggerResource(routeDefinition.getId(), + predicateDefinition.getArgs().get(NameUtils.GENERATED_NAME_PREFIX + "0") + .replace("/**", API_URI))))); + return resources; + } + + private SwaggerResource swaggerResource(String name, String location) { + SwaggerResource swaggerResource = new SwaggerResource(); + swaggerResource.setName(name); + swaggerResource.setLocation(location); + swaggerResource.setSwaggerVersion("2.0"); + return swaggerResource; + } +} diff --git a/cloud/geteway/src/main/java/com/example/geteway/client/filter/SwaggerHeaderFilter.java b/cloud/geteway/src/main/java/com/example/geteway/client/filter/SwaggerHeaderFilter.java new file mode 100644 index 0000000..51d2df7 --- /dev/null +++ b/cloud/geteway/src/main/java/com/example/geteway/client/filter/SwaggerHeaderFilter.java @@ -0,0 +1,36 @@ +package com.example.geteway.client.filter; + +import com.example.geteway.client.config.SwaggerProvider; +import org.springframework.cloud.gateway.filter.GatewayFilter; +import org.springframework.cloud.gateway.filter.factory.AbstractGatewayFilterFactory; +import org.springframework.http.server.reactive.ServerHttpRequest; +import org.springframework.stereotype.Component; +import org.springframework.util.StringUtils; +import org.springframework.web.server.ServerWebExchange; + +/** + * Spring 已修复该功能 + */ +@Component +@Deprecated +public class SwaggerHeaderFilter extends AbstractGatewayFilterFactory { + private static final String HEADER_NAME = "X-Forwarded-Prefix"; + + @Override + public GatewayFilter apply(Object config) { + return (exchange, chain) -> { + ServerHttpRequest request = exchange.getRequest(); + String path = request.getURI().getPath(); + if (!StringUtils.endsWithIgnoreCase(path, SwaggerProvider.API_URI)) { + return chain.filter(exchange); + } + + String basePath = path.substring(0, path.lastIndexOf(SwaggerProvider.API_URI)); + + + ServerHttpRequest newRequest = request.mutate().header(HEADER_NAME, basePath).build(); + ServerWebExchange newExchange = exchange.mutate().request(newRequest).build(); + return chain.filter(newExchange); + }; + } +} diff --git a/cloud/geteway/src/main/java/com/example/geteway/client/handler/SwaggerHandler.java b/cloud/geteway/src/main/java/com/example/geteway/client/handler/SwaggerHandler.java new file mode 100644 index 0000000..6192f37 --- /dev/null +++ b/cloud/geteway/src/main/java/com/example/geteway/client/handler/SwaggerHandler.java @@ -0,0 +1,45 @@ +package com.example.geteway.client.handler; + +import org.springframework.beans.factory.annotation.Autowired; +import org.springframework.http.HttpStatus; +import org.springframework.http.ResponseEntity; +import org.springframework.web.bind.annotation.GetMapping; +import org.springframework.web.bind.annotation.RequestMapping; +import org.springframework.web.bind.annotation.RestController; +import reactor.core.publisher.Mono; +import springfox.documentation.swagger.web.*; + +import java.util.Optional; + +@RestController +@RequestMapping("/swagger-resources") +public class SwaggerHandler { + @Autowired(required = false) + private SecurityConfiguration securityConfiguration; + @Autowired(required = false) + private UiConfiguration uiConfiguration; + private final SwaggerResourcesProvider swaggerResources; + + @Autowired + public SwaggerHandler(SwaggerResourcesProvider swaggerResources) { + this.swaggerResources = swaggerResources; + } + + + @GetMapping("/configuration/security") + public Mono> securityConfiguration() { + return Mono.just(new ResponseEntity<>( + Optional.ofNullable(securityConfiguration).orElse(SecurityConfigurationBuilder.builder().build()), HttpStatus.OK)); + } + + @GetMapping("/configuration/ui") + public Mono> uiConfiguration() { + return Mono.just(new ResponseEntity<>( + Optional.ofNullable(uiConfiguration).orElse(UiConfigurationBuilder.builder().build()), HttpStatus.OK)); + } + + @GetMapping("") + public Mono swaggerResources() { + return Mono.just((new ResponseEntity<>(swaggerResources.get(), HttpStatus.OK))); + } +} diff --git a/cloud/geteway/src/main/resources/application.yaml b/cloud/geteway/src/main/resources/application.yaml deleted file mode 100644 index 067da2e..0000000 --- a/cloud/geteway/src/main/resources/application.yaml +++ /dev/null @@ -1,56 +0,0 @@ -server: - port: 8083 - -eureka: - client: - fetch-registry: true - register-with-eureka: true - service-url: -# defaultZone: http://localhost:8761/eureka/ - defaultZone: http://121.40.109.21:8761/eureka/,http://121.40.109.21:8762/eureka/ - instance: - hostname: localhost - lease-expiration-duration-in-seconds: 90 - lease-renewal-interval-in-seconds: 30 - prefer-ip-address: true - -spring: - application: - name: sincere_geteway - - -zuul: - routes: - api-dahua-url: - path: /dahua/** - serviceId: dahuaserver - api-haikang-url: - path: /haikang/** - serviceId: haikangserver - api-iot-url: - path: /iot/** - serviceId: NetCoreService - api-mypulsar-url: - path: /mypulsar/** - serviceId: mypulsar - prefix: /mygateway - - -ribbon: - eureka: - enabled: false - -haikangserver: - ribbon: - listOfServers: http://121.40.109.21:9898 - -dahuaserver: - ribbon: - listOfServers: http://114.55.30.100:8991 - -mypulsar: - ribbon: - listOfServers: http://121.40.109.21:10009 - - - diff --git a/cloud/geteway/src/main/resources/application.yml b/cloud/geteway/src/main/resources/application.yml new file mode 100644 index 0000000..cdf80c1 --- /dev/null +++ b/cloud/geteway/src/main/resources/application.yml @@ -0,0 +1,23 @@ +eureka: + client: + fetch-registry: true + register-with-eureka: true + service-url: +# defaultZone: http://localhost:8761/eureka/ + defaultZone: http://localhost:8761/eureka/,http://localhost:8762/eureka/ + instance: + hostname: localhost + lease-expiration-duration-in-seconds: 90 + lease-renewal-interval-in-seconds: 10 + prefer-ip-address: true + +spring: + cloud: + gateway: + routes: + - id: haikangserver + uri: lb://haikangserver + predicates: + - Path=/haikangserver/** + filters: + - StripPrefix=1 diff --git a/cloud/geteway/src/main/resources/bootstrap.yml b/cloud/geteway/src/main/resources/bootstrap.yml new file mode 100644 index 0000000..3a03a12 --- /dev/null +++ b/cloud/geteway/src/main/resources/bootstrap.yml @@ -0,0 +1,23 @@ +#端口 +server: + port: 8083 + +#服务名称 +spring: + application: + name: sincere_geteway + main: + allow-bean-definition-overriding: true + + +management: + endpoints: + web: + exposure: + include: "*" + endpoint: + health: + show-details: always + + + \ No newline at end of file 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 b2ba3ee..9023699 100644 --- a/cloud/haikangface/src/main/java/com/sincere/haikangface/CMSServer.java +++ b/cloud/haikangface/src/main/java/com/sincere/haikangface/CMSServer.java @@ -115,7 +115,7 @@ public class CMSServer implements ApplicationRunner { public class FRegisterCallBack implements HCEHomeCMS.DEVICE_REGISTER_CB { public boolean invoke(NativeLong lUserID, int dwDataType, Pointer pOutBuffer, int dwOutLen, HCEHomeCMS.NET_EHOME_SERVER_INFO pInBuffer, int dwInLen, Pointer pUser) { String deviceId = ""; -// System.out.println("dwDataType:" + dwDataType); + System.out.println("dwDataType:" + dwDataType); if (dwDataType == 0) { HCEHomeCMS.NET_EHOME_DEV_REG_INFO strDevRegInfo = new HCEHomeCMS.NET_EHOME_DEV_REG_INFO(); strDevRegInfo.write(); @@ -457,6 +457,8 @@ public class CMSServer implements ApplicationRunner { face_recoder.setDeviceId(deviceID); face_recoder.setTime(time); face_recoder.setName(studentBean.getName()); + //114.55.30.100 +// String imgUrl = "http://120.26.116.253:8081/kms/services/rest/dataInfoService/downloadFile?id=" + picDataUrlId; String imgUrl = "http://114.55.30.100:8081/kms/services/rest/dataInfoService/downloadFile?id=" + picDataUrlId; face_recoder.setImgurl(imgUrl); face_recoder.setUser_id(studentBean.getUser_id()); @@ -469,7 +471,6 @@ public class CMSServer implements ApplicationRunner { } - /** * 生成图片服务路径 * @@ -636,6 +637,7 @@ public class CMSServer implements ApplicationRunner { int iErr = hCEhomeCMS.NET_ECMS_GetLastError(); if (validTimeEnabled == 0) System.err.println("删除卡号失败,错误号:" + iErr + "card:" + card); else System.err.println("下发卡号失败,错误号:" + iErr + "card:" + card); + if (iErr==10)map.remove(deviceId); } else { if (validTimeEnabled == 0) System.out.println("删除卡号成功"); else System.out.println("下发卡号成功"); 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 5dfd73b..cd06325 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 @@ -9,7 +9,9 @@ import com.sincere.haikangface.xiananDao.SendRecordDao; import org.json.JSONArray; import org.json.JSONObject; import org.springframework.beans.factory.annotation.Autowired; +import org.springframework.scheduling.annotation.Async; import org.springframework.stereotype.Component; +import org.springframework.web.bind.annotation.RequestParam; import javax.imageio.stream.FileImageInputStream; import java.io.*; @@ -66,4 +68,33 @@ public class SendUserAsync { } + + /** + * 调用传图片接口 + * @param filePath + * @param card + * @param name + * @param deviceId + * @param startTime + * @param endTime + * @param validTimeEnabled + * @param userType + */ + @Async("taskExecutor") + public void uploadImgs(String filePath,String card,String name,String deviceId,String startTime,String endTime,int validTimeEnabled,String userType){ + + HttpUtil.uploadImgs(filePath,card,name,deviceId,startTime,endTime,validTimeEnabled,userType); + } + + @Async("taskExecutor") + public void deleteCard(String deviceId, String card){ + HttpUtil.deleteCard(deviceId,card); + } + + + @Async("taskExecutor") + public boolean IsDeviceOnline( String deviceId){ + return HttpUtil.IsDeviceOnline(deviceId); + } + } diff --git a/cloud/haikangface/src/main/java/com/sincere/haikangface/bean/StudentBean.java b/cloud/haikangface/src/main/java/com/sincere/haikangface/bean/StudentBean.java index 460fba1..ed8d98b 100644 --- a/cloud/haikangface/src/main/java/com/sincere/haikangface/bean/StudentBean.java +++ b/cloud/haikangface/src/main/java/com/sincere/haikangface/bean/StudentBean.java @@ -53,6 +53,26 @@ public class StudentBean implements Serializable { private String photo; + private String teacher_num; + + private String num; + + public String getNum() { + return num; + } + + public void setNum(String num) { + this.num = num; + } + + public String getTeacher_num() { + return teacher_num; + } + + public void setTeacher_num(String teacher_num) { + this.teacher_num = teacher_num; + } + public String getPhoto() { return photo; } @@ -256,12 +276,13 @@ public class StudentBean implements Serializable { @Override public String toString() { return "StudentBean{" + - ", CustomerId='" + CustomerId + '\'' + ", name='" + name + '\'' + + ", ClassName='" + ClassName + '\'' + + ", Card='" + Card + '\'' + ", SchoolId=" + SchoolId + ", school_id=" + school_id + - ", studentcode='" + studentcode + '\'' + - ", student_num='" + student_num + '\'' + + ", teacher_num='" + teacher_num + '\'' + + ", num='" + num + '\'' + '}'; } } 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 index 5d52954..594958f 100644 --- a/cloud/haikangface/src/main/java/com/sincere/haikangface/control/FileControl.java +++ b/cloud/haikangface/src/main/java/com/sincere/haikangface/control/FileControl.java @@ -48,10 +48,11 @@ public class FileControl { File dest = new File(outFile, fileName); FileOutputStream fileOutputStream = new FileOutputStream(dest); fileOutputStream.write(file.getBytes()); + fileOutputStream.close(); 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 (filePath.contains(".jpg")) filePath = filePath.replace(".jpg", ".png"); if (new File(filePath.trim()).exists()) { String targetPath = FileUtils.picPathComp + new File(filePath).getName(); try { @@ -86,7 +87,23 @@ public class FileControl { @RequestMapping(value = "IsDeviceOnline", method = RequestMethod.GET) @ApiOperation("判断设备是否在线") public String IsDeviceOnline(@RequestParam("deviceId") String deviceId) { - return cmsServer.getIsDeviceOnline(deviceId)?"1":"0"; + return cmsServer.getIsDeviceOnline(deviceId) ? "1" : "0"; + } + + + @RequestMapping(value = "DeleteCard", method = RequestMethod.GET) + @ApiOperation("删除人脸") + public String deleteCard(@RequestParam("deviceId") String deviceId, @RequestParam("card") String card) { + cmsServer.deleteCard(deviceId, Long.parseLong(getCard(card), 16) + ""); + return "1"; + } + + @RequestMapping(value = "getCard", method = RequestMethod.GET) + @ApiOperation("获取设备人脸是否存在") + public String getCard(@RequestParam("deviceId") String deviceId, @RequestParam("card") String card) { + if (cmsServer.getFace(deviceId, Long.parseLong(getCard(card), 16) + "") ) + return "1"; + return "0"; } 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 61ec8a8..1084b8a 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 @@ -1,17 +1,22 @@ package com.sincere.haikangface.control; +import com.netflix.ribbon.proxy.annotation.Http; import com.sincere.common.dto.smartCampus.SZ_AttendanceDto; import com.sincere.common.util.BaiduApiUtiols; import com.sincere.haikangface.CMSServer; import com.sincere.haikangface.async.SendUserAsync; +import com.sincere.haikangface.bean.StudentBean; import com.sincere.haikangface.bean.StudentInfo; import com.sincere.haikangface.dao.UserDao; import com.sincere.haikangface.fegin.HaikangfaceFegin; import com.sincere.haikangface.utils.*; import com.sincere.haikangface.xiananDao.SendRecordDao; import io.swagger.annotations.Api; +import io.swagger.annotations.ApiImplicitParam; +import io.swagger.annotations.ApiImplicitParams; import io.swagger.annotations.ApiOperation; import org.springframework.beans.factory.annotation.Autowired; +import org.springframework.http.MediaType; import org.springframework.util.StringUtils; import org.springframework.web.bind.annotation.RequestMapping; import org.springframework.web.bind.annotation.RequestMethod; @@ -22,10 +27,13 @@ import sun.rmi.runtime.Log; import java.io.*; import java.math.BigInteger; +import java.text.SimpleDateFormat; +import java.util.Calendar; +import java.util.Date; import java.util.List; @RestController -@RequestMapping("/facereco/*") +@RequestMapping(value = "/facereco/*", produces = MediaType.APPLICATION_JSON_UTF8_VALUE) @Api("用户控制") public class UserControl { @@ -54,43 +62,127 @@ public class UserControl { @RequestParam("endTime") String endTime, @RequestParam("validTimeEnabled") int validTimeEnabled, @RequestParam("userType") String userType) { try { - 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 (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); - - } catch (Exception e) { - e.printStackTrace(); - return false; - } - } else { + return sendImg(filePath, deviceId, card, name, userType); + + } else { if (null == sendRecoderUtils) sendRecoderUtils = new SendRecoderUtils(); - sendRecoderUtils.sendFail(sendRecordDao, Long.parseLong(getCard(card), 16)+"", filePath, deviceId, userDao, "文件不存在", userType); + sendRecoderUtils.sendFail(sendRecordDao, Long.parseLong(getCard(card), 16) + "", filePath, deviceId, userDao, "文件不存在", userType); System.out.println("文件不存在:" + filePath); } } catch (Exception e) { e.printStackTrace(); } return true; -// return HttpUtil.uploadImgs(filePath,card,name,deviceId,startTime,endTime,validTimeEnabled,userType); } - @RequestMapping(value = "DeleteCard", method = RequestMethod.GET) + private boolean sendImg(String filePath, String deviceId, String card, String name, String userType) { + long time = System.currentTimeMillis(); + String startTime = new SimpleDateFormat("yyyy-MM-dd HH:mm:dd").format(new Date()); + Calendar calendar = Calendar.getInstance(); + calendar.add(Calendar.YEAR, 10); + String endTime = new SimpleDateFormat("yyyy-MM-dd HH:mm:dd").format(calendar.getTime()); + + String targetPath = FileUtils.picPathComp + new File(filePath).getName(); + try { + int isPiliang = 0;//0:批量,1:单张 + if (filePath.contains("face17e50")) {//批量发送 + isPiliang = 0; + } else {//单图发送 + isPiliang = 1; + } + if (cmsServer.getIsDeviceOnline(deviceId)) + sendUserAsync.sendStuToHaiKang(filePath, targetPath, Long.parseLong(getCard(card), 16) + "", startTime, endTime, 1, name, deviceId, userType, isPiliang); + else { + sendUserAsync.uploadImgs(filePath, card, name, deviceId, startTime, endTime, 1, userType); + } + System.out.println("time:" + (System.currentTimeMillis() - time) / 1000); + return true; + } catch (Exception e) { + e.printStackTrace(); + return false; + } + + } + + @RequestMapping(value = "sendFaces", method = RequestMethod.GET) + @ApiOperation(value = "下发学校下所有人脸给指定设备", notes = "下发所有人脸给指定设备") + public void sendFaces(@RequestParam("deviceIds") String deviceIds, @RequestParam("schoolId") String schoolId, @RequestParam("userType") String userType) { + + String typeName = userType.equals("1") ? "Teacher" : "Student"; + + String imgPath = "E:\\wwwhtdocs\\SmartCampus\\face17e50\\School" + schoolId + "\\" + typeName; + + File imgPathFile = new File(imgPath);//目录 + + String[] deviceIdsStr = deviceIds.split(","); + + + if (imgPathFile.exists()) { + File[] imgfiles = imgPathFile.listFiles(); + if (null != imgfiles) { + + for (int i = 0; i < imgfiles.length; i++) { + File file = imgfiles[i];//图片 + if (file.exists()) + for (int j = 0; j < deviceIdsStr.length; j++) { + String deviceId = deviceIdsStr[j]; + + StudentBean studentBean = null; + String card = "", name = ""; + if (userType.equals("1")) { + studentBean = userDao.getTeacherWithstudentcode(file.getName().split("\\.")[0],schoolId); + if (null!=studentBean){ + card = studentBean.getTeacher_num(); + name = studentBean.getName(); + } + } else if (userType.equals("2")) { + studentBean = userDao.getStudentWithstudentcode(file.getName().split("\\.")[0],schoolId); + if (null != studentBean) { + card = studentBean.getStudent_num(); + name = studentBean.getName(); + } + } + + if (!StringUtils.isEmpty(card)) + sendImg(file.getAbsolutePath(), deviceId, card, name, userType); + + } + + } + + } + } + + } + + @RequestMapping(value = "sendFaceToDevices", method = RequestMethod.GET) + @ApiOperation(value = "下发单个用户给指定设备", notes = "下发单个用户给指定设备") + @ApiImplicitParams({@ApiImplicitParam(name = "deviceIds",value = "设备id用逗号,拼接"), + @ApiImplicitParam(name = "file",value = "100服务器上图片绝对路径")}) + public void sendFaceToDevices(@RequestParam("deviceIds") String deviceIds, @RequestParam("userType") String userType,@RequestParam("file") String file, + @RequestParam("card") String card,@RequestParam("name") String name) { + + String[] deviceIdsStr = deviceIds.split(","); + + for (int i = 0; i < deviceIdsStr.length; i++) { + String deviceId = deviceIdsStr[i]; + sendImg(file, deviceId, card, name, userType); + } + + } + + + + @RequestMapping(value = "DeleteCard", method = RequestMethod.GET) @ApiOperation("删除人脸") public boolean deleteCard(@RequestParam("deviceId") String deviceId, @RequestParam("card") String card) { - cmsServer.deleteCard(deviceId, Long.parseLong(getCard(card), 16) + ""); + if (cmsServer.getIsDeviceOnline(deviceId)) + cmsServer.deleteCard(deviceId, Long.parseLong(getCard(card), 16) + ""); + else HttpUtil.deleteCard(deviceId, card); return true; } @@ -98,6 +190,7 @@ public class UserControl { @ApiOperation("获取设备人脸是否存在") public boolean getCard(@RequestParam("deviceId") String deviceId, @RequestParam("card") String card) { cmsServer.getFace(deviceId, Long.parseLong(getCard(card), 16) + ""); +// HttpUtil.getCard(deviceId,card); return true; } @@ -107,13 +200,8 @@ public class UserControl { if (cmsServer.getIsDeviceOnline(deviceId)) { return true; } else { - return false; + return sendUserAsync.IsDeviceOnline(deviceId); } - /*if ( HttpUtil.IsDeviceOnline(deviceId)) { - return true; - } else { - return false; - }*/ } @RequestMapping(value = "FaceUploadFile", method = RequestMethod.POST) @@ -122,7 +210,7 @@ public class UserControl { String targetPath = FileUtils.picPathComp; System.out.println("fileName:" + file.getOriginalFilename()); - return ""; + return "sss"; } @@ -131,7 +219,7 @@ public class UserControl { @ApiOperation("根据设备获取考勤模板") public String getKaoqinTem(@RequestParam("deviceId") String deviceId) { SZ_AttendanceDto attendanceBean = haikangfaceFegin.selectAttendaceWithId(deviceId); - System.out.println("isKaoqin:"+attendanceBean.toString()); + System.out.println("isKaoqin:" + attendanceBean.toString()); int isKaoqin = attendanceBean.getIsKaoqin();//获取考勤模板id List attendanceBeans = haikangfaceFegin.getAttensWithIsKaoqin(isKaoqin);//获取同一模板下的设备 String content = ""; diff --git a/cloud/haikangface/src/main/java/com/sincere/haikangface/control/ZuoYeControl.java b/cloud/haikangface/src/main/java/com/sincere/haikangface/control/ZuoYeControl.java index e1c8e34..0bcf874 100644 --- a/cloud/haikangface/src/main/java/com/sincere/haikangface/control/ZuoYeControl.java +++ b/cloud/haikangface/src/main/java/com/sincere/haikangface/control/ZuoYeControl.java @@ -1,5 +1,6 @@ package com.sincere.haikangface.control; +import com.sincere.common.util.AuthService; import com.sincere.haikangface.admindao.ZuoyeAdminDao; import com.sincere.haikangface.bean.UserBean; import com.sincere.haikangface.bean.homework.AddQuestion; @@ -268,7 +269,7 @@ public class ZuoYeControl { return null; } - private String url = "https://aip.baidubce.com/rest/2.0/ocr/v1/general_basic?access_token=24.26683b650b73b63e0b08afa7ac36e880.2592000.1571310480.282335-15990462"; + private String url = "https://aip.baidubce.com/rest/2.0/ocr/v1/general_basic?access_token="+ AuthService.getAuth(); private String getAnswer(String imgUrl, int type) { RestTemplate restTemplate = new RestTemplate(); diff --git a/cloud/haikangface/src/main/java/com/sincere/haikangface/dao/UserDao.java b/cloud/haikangface/src/main/java/com/sincere/haikangface/dao/UserDao.java index 216c32f..5f6025c 100644 --- a/cloud/haikangface/src/main/java/com/sincere/haikangface/dao/UserDao.java +++ b/cloud/haikangface/src/main/java/com/sincere/haikangface/dao/UserDao.java @@ -2,6 +2,7 @@ package com.sincere.haikangface.dao; import com.sincere.haikangface.bean.*; import org.apache.ibatis.annotations.*; +import org.springframework.security.core.parameters.P; import org.springframework.stereotype.Repository; import java.util.List; @@ -169,7 +170,8 @@ public interface UserDao { @Select(" select * from SZ_V_School_Student where school_id = 562 and student_num is not null and photo is not null and len(photo)>0") List getAllStus(); - @Select("select DISTINCT user_id from SZ_V_School_Teacher where school_id = 885") + @Select("select user_id\n" + + "from SZ_V_School_Student where school_id = 13 and student_type =2 and len(student_num)=0\n") List getUserids(); @Insert("insert into HS_ResRalation (FileId,AddTime,UserId) values (#{FileId},#{AddTime},#{userId})") @@ -192,4 +194,21 @@ public interface UserDao { " from SS_Room\n" + " where SchoolId = 479 and SS_Room.Pid =10284 )") List getStudentIdWithRoom(); + + @Select("select CardNum from Virtual_Card where state =0 and id < 5475 ;") + List getVirCards(); + + @Update("update SZ_V_School_Student set student_num =#{student_num} where school_id = 13 and student_type =2 and len(student_num)=0 and user_id = #{user_id}") + void updateStuCards(@Param("student_num") String card,@Param("user_id")String user_id); + + + @Select("select Top(1)*\n" + + "from SZ_V_School_Student\n" + + "where studentcode = #{studentcode} and school_id = #{schoolId}") + StudentBean getStudentWithstudentcode(@Param("studentcode") String studentcode, @Param("schoolId")String schoolId); + + @Select("select Top(1)*\n" + + "from SZ_V_School_Teacher\n" + + "where num = #{num} and school_id = #{schoolId}") + StudentBean getTeacherWithstudentcode(@Param("num") String num,@Param("schoolId")String schoolId); } diff --git a/cloud/haikangface/src/main/java/com/sincere/haikangface/utils/CompressPic.java b/cloud/haikangface/src/main/java/com/sincere/haikangface/utils/CompressPic.java index 0dd07b7..ef151e2 100644 --- a/cloud/haikangface/src/main/java/com/sincere/haikangface/utils/CompressPic.java +++ b/cloud/haikangface/src/main/java/com/sincere/haikangface/utils/CompressPic.java @@ -16,7 +16,7 @@ import java.io.InputStream; public class CompressPic { public static String CompressPic(String srcPath, String targetPath) throws Exception { - double cutPercent = 0.1; + double cutPercent = 0.4; File file = new File(srcPath.trim()); FileInputStream fileInputStreamSrc = new FileInputStream(file); BufferedImage bufferedImage = ImageIO.read(fileInputStreamSrc); 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 c34625b..210a2b8 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 @@ -95,7 +95,7 @@ public class HttpUtil { return false; } - String url = "http://121.40.109.21:8089/file/uploadImg"; + String url = "http://120.26.116.253:8089/file/uploadImg"; RestTemplate restTemplate = new RestTemplate(); @@ -129,16 +129,37 @@ public class HttpUtil { public static boolean IsDeviceOnline(String deviceId){ - String url = "http://121.40.109.21:8089/file/getCard"; + String url = "http://120.26.116.253:8089/file/IsDeviceOnline?deviceId="+deviceId; RestTemplate restTemplate = new RestTemplate(); - Map map = new HashMap<>(); +// Map map = new HashMap<>(); - map.put("deviceId",deviceId); +// map.put("deviceId",deviceId); - String res = restTemplate.getForObject(url,String.class,map); + String res = restTemplate.getForObject(url,String.class); return res.equals("1"); } + public static boolean deleteCard(String deviceId, String card){ + + String url = "http://120.26.116.253:8089/file/DeleteCard?deviceId="+deviceId+"&card="+card; + + RestTemplate restTemplate = new RestTemplate(); + + String res = restTemplate.getForObject(url,String.class); + + return res.equals("1"); + } + + public static boolean getCard(String deviceId, String card){ + + String url = "http://120.26.116.253:8089/file/getCard?deviceId="+deviceId+"&card="+card; + + RestTemplate restTemplate = new RestTemplate(); + +// String res = restTemplate.getForObject(url,String.class,map); + return restTemplate.getForObject(url,String.class).equals("1"); + } + } diff --git a/cloud/haikangface/src/main/java/com/sincere/haikangface/xiananDao/SendRecordDao.java b/cloud/haikangface/src/main/java/com/sincere/haikangface/xiananDao/SendRecordDao.java index 01eee7d..38df412 100644 --- a/cloud/haikangface/src/main/java/com/sincere/haikangface/xiananDao/SendRecordDao.java +++ b/cloud/haikangface/src/main/java/com/sincere/haikangface/xiananDao/SendRecordDao.java @@ -27,7 +27,7 @@ public interface SendRecordDao { @Param("userType") int userType, @Param("deviceType") int deviceType); - @Select("select * from Face_SendSuccess where schoolId = 1066 ") + @Select("select * from Face_SendSuccess where schoolId = 870 ") List getSenSuccess(); @Select("select * from Face_SendSuccess where deviceID = #{deviceID} and schoolId = #{schoolId}") diff --git a/cloud/haikangface/src/main/resources/application.yaml b/cloud/haikangface/src/main/resources/application.yaml index bf9ab9a..563a49a 100644 --- a/cloud/haikangface/src/main/resources/application.yaml +++ b/cloud/haikangface/src/main/resources/application.yaml @@ -38,8 +38,8 @@ eureka: lease-renewal-interval-in-seconds: 10 client: service-url: - defaultZone: http://121.40.109.21:8761/eureka/,http://121.40.109.21:8762/eureka/ -# defaultZone: http://localhost:8761/eureka/,http://localhost:8762/eureka/ +# defaultZone: http://121.40.109.21:8761/eureka/,http://121.40.109.21:8762/eureka/ + defaultZone: http://localhost:8761/eureka/,http://localhost:8762/eureka/ mybatis: campus: 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 91ea164..f8224c2 100644 --- a/cloud/haikangface/src/test/java/com/sincere/haikangface/HaikangfaceApplicationTests.java +++ b/cloud/haikangface/src/test/java/com/sincere/haikangface/HaikangfaceApplicationTests.java @@ -33,6 +33,8 @@ import org.springframework.util.MultiValueMap; import org.springframework.util.StringUtils; import org.springframework.web.client.RestTemplate; +import javax.imageio.stream.FileImageInputStream; +import javax.imageio.stream.FileImageOutputStream; import javax.ws.rs.core.MultivaluedMap; import java.io.*; import java.math.BigInteger; @@ -70,6 +72,23 @@ public class HaikangfaceApplicationTests { @Test public void send() { +// List virCards = userDao.getVirCards(); +// List userIds = userDao.getUserids(); +// for (int i = 0; i < virCards.size(); i++) { +// String card = virCards.get(i); +// +// userDao.updateStuCards(card,userIds.get(i)); +// } + + /* List sendRecordBeanList = sendRecordDao.getSenSuccess(); + + for (int i = 0; i < sendRecordBeanList.size(); i++) { + SendRecordBean sendRecordBean = sendRecordBeanList.get(i); + + sendRecordDao.deleteFaceFail(sendRecordBean.getNum(),sendRecordBean.getDeviceID()); + }*/ + + //补发失败人脸 /*RestTemplate restTemplate = new RestTemplate(); //失败人脸补发 @@ -242,26 +261,109 @@ public class HaikangfaceApplicationTests { @Test public void fileRes() { -// List questionBeans = zuoYeDao.getQuestionsRecent(); - /* List questionBeans = zuoYeDao.getQuestionsRecent(); - String dateTime = new SimpleDateFormat("yyyy-MM-dd HH:mm:ss").format(new Date()); - - for (QuestionBean ques : - questionBeans) { - zuoyeAdminDao.addQuestionStem("请回答下列问题", "1", dateTime); - int stemId = zuoyeAdminDao.getStemId(); - String intime = new SimpleDateFormat("yyyy-MM-dd HH:mm:ss").format(new Date()); - zuoyeAdminDao.addQuestion(ques.getQuestion(),ques.getQtype(),ques.getAnswer(),ques.getCorrectAnswer(),ques.getAnalysis(), - ques.getState(),intime,stemId+"",ques.getExamineFlag(),ques.getSubjectId(),"10","1",ques.getChapterId(),ques.getGradeId()+"","1","","1"); - }*/ -//List queIds = zuoyeAdminDao.getQueIds(); + File filebianhao = new File("C:\\Users\\Administrator\\Desktop\\中专照片汇总200204\\bianhao.txt"); + File filecard = new File("C:\\Users\\Administrator\\Desktop\\中专照片汇总200204\\card.txt"); + + try { + BufferedReader bufferedReaderBianhao = new BufferedReader(new FileReader(filebianhao)); + BufferedReader bufferedReaderCard = new BufferedReader(new FileReader(filecard)); + + String lineBianhao = null; + + List listBianhao = new ArrayList<>(); + + while ((lineBianhao = bufferedReaderBianhao.readLine()) != null) { + + listBianhao.add(lineBianhao); + + } + + String lineCard = null; + + List listCard = new ArrayList<>(); + + while ((lineCard = bufferedReaderCard.readLine()) != null) { + + listCard.add(lineCard); + + } + + File filePath = new File("C:\\Users\\Administrator\\Desktop\\中专照片汇总200204\\中专照片汇总200204"); + + File[] fileImgs = filePath.listFiles(); + + File fileOut = new File("C:\\Users\\Administrator\\Desktop\\中专照片汇总200204"); -// for (int i = queIds.size()-1; i >=0 ; i--) { -// zuoyeAdminDao.addYYQuestionAndKnowledg(queIds.get(i), Long.parseLong(questionBeans.get(questionBeans.size()-1-i).getKnowledgeId()),0,1); -// } + for (int i = 0; i < fileImgs.length; i++) { + File img = fileImgs[i]; + String bianhao = img.getName().split("\\.")[0]; + + for (int j = 0; j < listBianhao.size(); j++) { + if (bianhao.equals(listBianhao.get(j))) { + StudentBean studentBean = userDao.getTeacherWithCard(listCard.get(j)); + if (studentBean == null) {//学生 + studentBean = userDao.getStudentWithCard(listCard.get(j)); + + if (studentBean == null) { +// System.out.println(listCard.get(j)); + } else { + File fileOutStu = new File(fileOut.getAbsolutePath(), "Student"); + if (!fileOutStu.exists()) fileOutStu.mkdirs(); + File fileOutStu1 = new File(fileOutStu, studentBean.getStudentcode() + ".png"); + if (!fileOutStu1.exists()) fileOutStu1.createNewFile(); + writeImg(fileOutStu1.getAbsolutePath(), img.getAbsolutePath()); + } + + + } else {//老师 + File fileOutTea = new File(fileOut.getAbsolutePath(), "Teacher"); + if (!fileOutTea.exists()) fileOutTea.mkdirs(); + File fileOutStu1 = new File(fileOutTea, studentBean.getNum() + ".png"); + if (!fileOutStu1.exists()) fileOutStu1.createNewFile(); + writeImg(fileOutStu1.getAbsolutePath(), img.getAbsolutePath()); + System.out.println(studentBean==null?listCard.get(j):""); + } + } + } + } + + + } catch (FileNotFoundException e) { + e.printStackTrace(); + } catch (IOException e) { + e.printStackTrace(); + } + + } + + + private void writeImg(String imgPath, String srcPath) { + + try { + FileImageOutputStream fileImageOutputStream = new FileImageOutputStream(new File(imgPath)); + + FileImageInputStream fileImageInputStream = new FileImageInputStream(new File(srcPath)); + + byte[] bytes = new byte[1024]; + + int length = -1; + + while ((length = fileImageInputStream.read(bytes)) != -1) { + fileImageOutputStream.write(bytes, 0, length); + } + + + fileImageInputStream.close(); + fileImageOutputStream.close(); + + + } catch (IOException e) { + e.printStackTrace(); + } } + } diff --git a/cloud/mypulsar/pom.xml b/cloud/mypulsar/pom.xml index 4f6524a..27d642f 100644 --- a/cloud/mypulsar/pom.xml +++ b/cloud/mypulsar/pom.xml @@ -58,34 +58,15 @@ org.springframework.boot spring-boot-starter-web - - - - - - - - - - - - - - - - org.springframework.boot - spring-boot-starter-test - test - + + + + + - org.apache.pulsar - pulsar-client - 2.3.2 - - com.alibaba fastjson 1.2.46 @@ -116,6 +97,17 @@ org.springframework.cloud spring-cloud-starter-netflix-eureka-server + + org.springframework.boot + spring-boot-autoconfigure + + + + org.apache.pulsar + pulsar-client + 2.4.2 + + 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 8f543f7..5be42e7 100644 --- a/cloud/mypulsar/src/main/java/com/example/mypulsar/MyRunnerableInt.java +++ b/cloud/mypulsar/src/main/java/com/example/mypulsar/MyRunnerableInt.java @@ -278,6 +278,9 @@ public class MyRunnerableInt implements ApplicationRunner { // value = value.equals("0")?"0":Integer.parseInt(value) / 10 + "A"; // log(devId + " 当前电流:" + Integer.parseInt(value) / 10 + "A"); break; + case "router_mgr"://网关路由 + + break; } updateDevStatus(deviceBean); } @@ -294,7 +297,7 @@ public class MyRunnerableInt implements ApplicationRunner { if (deviceBean.getValue().equals("有人")) deviceBean.setValue("1"); else deviceBean.setValue("0"); - ControlUtils.getInstance().conTemper(calDevContrls, deviceBean); + ControlUtils.getInstance(deviceDao).conTemper(calDevContrls, deviceBean); } } @@ -308,7 +311,7 @@ public class MyRunnerableInt implements ApplicationRunner { List calDevContrls = deviceDao.getCalDevContrlWidthDevId(deviceBean.getDevId()); if (null != calDevContrls && calDevContrls.size() > 0) - ControlUtils.getInstance().conTemper(calDevContrls, deviceBean); + ControlUtils.getInstance(deviceDao).conTemper(calDevContrls, deviceBean); } diff --git a/cloud/mypulsar/src/main/java/com/example/mypulsar/Test.java b/cloud/mypulsar/src/main/java/com/example/mypulsar/Test.java index 8aa1603..517e3bb 100644 --- a/cloud/mypulsar/src/main/java/com/example/mypulsar/Test.java +++ b/cloud/mypulsar/src/main/java/com/example/mypulsar/Test.java @@ -1,25 +1,33 @@ package com.example.mypulsar; +import com.example.mypulsar.dao.UserDao; import com.example.mypulsar.utils.HttpUtil; +import org.mybatis.spring.annotation.MapperScan; +import org.springframework.beans.factory.annotation.Autowired; +import org.springframework.boot.SpringApplication; +import org.springframework.boot.autoconfigure.SpringBootApplication; +import org.springframework.boot.configurationprocessor.json.JSONArray; +import org.springframework.boot.configurationprocessor.json.JSONException; +import org.springframework.boot.configurationprocessor.json.JSONObject; +import org.springframework.boot.web.servlet.support.SpringBootServletInitializer; +import java.io.*; import java.text.ParseException; import java.text.SimpleDateFormat; +import java.util.ArrayList; +import java.util.Calendar; import java.util.Date; +import java.util.List; + + +public class Test extends SpringBootServletInitializer { + + public static void main(String[] args) { + -public class Test { - public static void main(String[] args){ -// 3307102084f3eb3547e7 -// HttpUtil.controlDev("6cb748ca397c2f03b1nqbh","switch_1","false"); - /*HttpUtil.addAirCode("{\n" + - "\"remote_index\":\"null\",\n" + - "\"remote_id\":\"null\",\n" + - "\"power\":\"1\",\n" + - "\"mode\":\"null\",\n" + - "\"temp\":\"null\",\n" + - "\"wind\":\"null\"\n" + - "}\n","45424060b4e62d2183ec");*/ } + } diff --git a/cloud/mypulsar/src/main/java/com/example/mypulsar/bean/CalDevBeContrl.java b/cloud/mypulsar/src/main/java/com/example/mypulsar/bean/CalDevBeContrl.java new file mode 100644 index 0000000..62dfa0b --- /dev/null +++ b/cloud/mypulsar/src/main/java/com/example/mypulsar/bean/CalDevBeContrl.java @@ -0,0 +1,98 @@ +package com.example.mypulsar.bean; + +public class CalDevBeContrl { + + private int id; + + private String ConDevId; + + private String ConCode; + + private String ConValue; + + private String CreateTime; + + private String CreateUserId; + + private int State; + + private int ModeId; + + public int getId() { + return id; + } + + public void setId(int id) { + this.id = id; + } + + public String getConDevId() { + return ConDevId; + } + + public void setConDevId(String conDevId) { + ConDevId = conDevId; + } + + public String getConCode() { + return ConCode; + } + + public void setConCode(String conCode) { + ConCode = conCode; + } + + public String getConValue() { + return ConValue; + } + + public void setConValue(String conValue) { + ConValue = conValue; + } + + public String getCreateTime() { + return CreateTime; + } + + public void setCreateTime(String createTime) { + CreateTime = createTime; + } + + public String getCreateUserId() { + return CreateUserId; + } + + public void setCreateUserId(String createUserId) { + CreateUserId = createUserId; + } + + public int getState() { + return State; + } + + public void setState(int state) { + State = state; + } + + public int getModeId() { + return ModeId; + } + + public void setModeId(int modeId) { + ModeId = modeId; + } + + @Override + public String toString() { + return "CalDevBeContrl{" + + "id=" + id + + ", ConDevId='" + ConDevId + '\'' + + ", ConCode='" + ConCode + '\'' + + ", ConValue='" + ConValue + '\'' + + ", CreateTime='" + CreateTime + '\'' + + ", CreateUserId='" + CreateUserId + '\'' + + ", State=" + State + + ", ModeId=" + ModeId + + '}'; + } +} diff --git a/cloud/mypulsar/src/main/java/com/example/mypulsar/bean/CalDevContrl.java b/cloud/mypulsar/src/main/java/com/example/mypulsar/bean/CalDevContrl.java index abe953d..8c754f1 100644 --- a/cloud/mypulsar/src/main/java/com/example/mypulsar/bean/CalDevContrl.java +++ b/cloud/mypulsar/src/main/java/com/example/mypulsar/bean/CalDevContrl.java @@ -14,17 +14,19 @@ public class CalDevContrl implements Serializable { private String ThreValue; - private String ConDevId; + private String CreateTime; - private String ConCode; + private String CreateUserId; - private String ConValue; + private String InUserTime; - private String CreateTime; + private int Status ; - private String CreateUserId; + private String DevBeId;//控制的设备id + + private int ModeId;//联动模板id - private String InUseTime; + private String AssDevice;//联动传感器设备 public String getDevid() { return Devid; @@ -42,6 +44,22 @@ public class CalDevContrl implements Serializable { ModelType = modelType; } + public String getInUserTime() { + return InUserTime; + } + + public String getThreValue() { + return ThreValue; + } + + public void setThreValue(String threValue) { + ThreValue = threValue; + } + + public void setInUserTime(String inUserTime) { + InUserTime = inUserTime; + } + public int getComPre() { return ComPre; } @@ -58,63 +76,54 @@ public class CalDevContrl implements Serializable { CompreType = compreType; } - public String getThresholdValue() { - return ThreValue; - } - - public void setThresholdValue(String thresholdValue) { - ThreValue = thresholdValue; - } - - public String getConDevId() { - return ConDevId; + public String getCreateTime() { + return CreateTime; } - public void setConDevId(String conDevId) { - ConDevId = conDevId; + public void setCreateTime(String createTime) { + CreateTime = createTime; } - public String getConCode() { - return ConCode; + public String getCreateUserId() { + return CreateUserId; } - public void setConCode(String conCode) { - ConCode = conCode; + public void setCreateUserId(String createUserId) { + CreateUserId = createUserId; } - public String getConValue() { - return ConValue; + public int getStatus() { + return Status; } - public void setConValue(String conValue) { - ConValue = conValue; + public void setStatus(int status) { + Status = status; } - public String getCreateTime() { - return CreateTime; + public String getDevBeId() { + return DevBeId; } - public void setCreateTime(String createTime) { - CreateTime = createTime; + public void setDevBeId(String devBeId) { + DevBeId = devBeId; } - public String getCreateUserId() { - return CreateUserId; + public int getModeId() { + return ModeId; } - public void setCreateUserId(String createUserId) { - CreateUserId = createUserId; + public void setModeId(int modeId) { + ModeId = modeId; } - public String getInUseTime() { - return InUseTime; + public String getAssDevice() { + return AssDevice; } - public void setInUseTime(String inUseTime) { - InUseTime = inUseTime; + public void setAssDevice(String assDevice) { + AssDevice = assDevice; } - @Override public String toString() { return "CalDevContrl{" + @@ -122,13 +131,14 @@ public class CalDevContrl implements Serializable { ", ModelType=" + ModelType + ", ComPre=" + ComPre + ", CompreType=" + CompreType + - ", ThresholdValue='" + ThreValue + '\'' + - ", ConDevId='" + ConDevId + '\'' + - ", ConCode='" + ConCode + '\'' + - ", ConValue='" + ConValue + '\'' + + ", ThreValue='" + ThreValue + '\'' + ", CreateTime='" + CreateTime + '\'' + ", CreateUserId='" + CreateUserId + '\'' + - ", InUseTime='" + InUseTime + '\'' + + ", InUseTime='" + InUserTime + '\'' + + ", Status=" + Status + + ", DevBeId='" + DevBeId + '\'' + + ", ModeId=" + ModeId + + ", AssDevice='" + AssDevice + '\'' + '}'; } } diff --git a/cloud/mypulsar/src/main/java/com/example/mypulsar/bean/InUserTime.java b/cloud/mypulsar/src/main/java/com/example/mypulsar/bean/InUserTime.java new file mode 100644 index 0000000..4e2b49e --- /dev/null +++ b/cloud/mypulsar/src/main/java/com/example/mypulsar/bean/InUserTime.java @@ -0,0 +1,46 @@ +package com.example.mypulsar.bean; + +import java.io.Serializable; + +public class InUserTime implements Serializable { + +// [{"Week":"5","StartTime":"14:02","EndTime":"14:06"}] + private String Week; + + private String StartTime; + + private String EndTime; + + public String getWeek() { + return Week; + } + + public void setWeek(String week) { + Week = week; + } + + public String getStartTime() { + return StartTime; + } + + public void setStartTime(String startTime) { + StartTime = startTime; + } + + public String getEndTime() { + return EndTime; + } + + public void setEndTime(String endTime) { + EndTime = endTime; + } + + @Override + public String toString() { + return "InUserTime{" + + "Week='" + Week + '\'' + + ", StartTime='" + StartTime + '\'' + + ", EndTime='" + EndTime + '\'' + + '}'; + } +} diff --git a/cloud/mypulsar/src/main/java/com/example/mypulsar/bean/InUserTimeList.java b/cloud/mypulsar/src/main/java/com/example/mypulsar/bean/InUserTimeList.java new file mode 100644 index 0000000..eb7e1b4 --- /dev/null +++ b/cloud/mypulsar/src/main/java/com/example/mypulsar/bean/InUserTimeList.java @@ -0,0 +1,24 @@ +package com.example.mypulsar.bean; + +import java.io.Serializable; +import java.util.List; + +public class InUserTimeList implements Serializable { + +private List inUserTimes; + + public List getInUserTimes() { + return inUserTimes; + } + + public void setInUserTimes(List inUserTimes) { + this.inUserTimes = inUserTimes; + } + + @Override + public String toString() { + return "InUserTimeList{" + + "inUserTimes=" + inUserTimes + + '}'; + } +} 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 bedf9d1..366e7a9 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 @@ -1,5 +1,6 @@ package com.example.mypulsar.dao; +import com.example.mypulsar.bean.CalDevBeContrl; import com.example.mypulsar.bean.CalDevContrl; import com.example.mypulsar.bean.DeviceBean; import org.apache.ibatis.annotations.*; @@ -35,9 +36,13 @@ public interface DeviceDao { List getDevice(@Param("devId") String devId); //获取联动控制模板 - @Select("select * from CalDevContrl") + @Select("select * from CalDevContrl ") List getCalDevContrl(); - @Select("select * from CalDevContrl where Devid = #{Devid}") + + @Select("select * from CalDevContrl where Devid = #{Devid} and Status = 1") List getCalDevContrlWidthDevId(@Param("Devid") String devId); + + @Select("select * from CalDevContrl where State = 1 and Id = #{Id}") + CalDevBeContrl getCalDevBeControl(@Param("Id") String Id); } 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 index bd9298a..c9a4114 100644 --- a/cloud/mypulsar/src/main/java/com/example/mypulsar/utils/ControlUtils.java +++ b/cloud/mypulsar/src/main/java/com/example/mypulsar/utils/ControlUtils.java @@ -1,138 +1,294 @@ package com.example.mypulsar.utils; -import com.example.mypulsar.bean.CalDevContrl; -import com.example.mypulsar.bean.DeviceBean; +import com.example.mypulsar.bean.*; +import com.example.mypulsar.dao.DeviceDao; +import org.apache.pulsar.shade.com.google.gson.Gson; +import org.springframework.boot.configurationprocessor.json.JSONArray; +import org.springframework.boot.configurationprocessor.json.JSONException; +import org.springframework.boot.configurationprocessor.json.JSONObject; import java.text.ParseException; import java.text.SimpleDateFormat; -import java.util.Date; -import java.util.List; +import java.util.*; public class ControlUtils { + private Set deviceSet = new HashSet<>();//保存符合条件的传感器 + private static ControlUtils controlUtils; - public static ControlUtils getInstance(){ - if (null==controlUtils){ - synchronized (ControlUtils.class){ - if (null==controlUtils)controlUtils = new ControlUtils(); + private DeviceDao deviceDao; + + public static ControlUtils getInstance(DeviceDao deviceDao) { + if (null == controlUtils) { + synchronized (ControlUtils.class) { + if (null == controlUtils) controlUtils = new ControlUtils(deviceDao); } } return controlUtils; } + public ControlUtils(DeviceDao deviceDao) { + + this.deviceDao = deviceDao; + + + } + /** * 根据温度变化操纵 + * * @param calDevContrls 联动模板 - * @param deviceBean 温度传感器对象 + * @param deviceBean 温度传感器对象 */ - public void conTemper(List calDevContrls, DeviceBean deviceBean){ + public void conTemper(List calDevContrls, DeviceBean deviceBean) { for (CalDevContrl cal : calDevContrls) { - String inUseTime = cal.getInUseTime();//联动的时间范围,8:00-18:00 + String inUseTime = cal.getInUserTime();//联动的时间范围,[{"Week":"5","StartTime":"14:02","EndTime":"14:06"}] + if (inUseTime == null) break; + try { + JSONArray jsonArray = new JSONArray(inUseTime); - String[] inUseTimes = inUseTime.split("-"); + for (int i = 0; i < jsonArray.length(); i++) { + JSONObject jsonObject = jsonArray.getJSONObject(i); - String startTime = inUseTimes[0]; + int week = jsonObject.getInt("Week"); - String endTime = inUseTimes[1]; + String startTime = jsonObject.getString("StartTime"); - SimpleDateFormat simpleDateFormat = new SimpleDateFormat("HH:mm"); + String endTime = jsonObject.getString("EndTime"); - try { + SimpleDateFormat simpleDateFormat = new SimpleDateFormat("HH:mm"); + SimpleDateFormat simpleDateFormat1 = new SimpleDateFormat("HH:mm:ss"); - Date startDate = simpleDateFormat.parse(startTime); - Date endDate = simpleDateFormat.parse(endTime); - Date date = simpleDateFormat.parse(new Date().getHours()+":"+new Date().getMinutes()); + int indexWeek = Calendar.getInstance().get(Calendar.DAY_OF_WEEK); - long starTime = startDate.getTime(); + if (week == indexWeek) { - if (date.getTime()starTime){ - //比较器类型 - int compreType = cal.getCompreType(); + Date startDate = simpleDateFormat.parse(startTime); + Date endDate = simpleDateFormat.parse(endTime); + Date date = simpleDateFormat1.parse(new Date().getHours() + ":" + new Date().getMinutes() + ":" + new Date().getSeconds()); - switch (compreType){ - case 1://固定值 - calCompre(cal,deviceBean); - break; - case 2://当天日期 + long starTime = startDate.getTime(); + System.out.println("startDate:" + starTime); + System.out.println("endDate:" + endDate.getTime()); + System.out.println("date:" + date.getTime()); + + if (date.getTime() < endDate.getTime() && date.getTime() > starTime) { + //比较器类型 + int compreType = cal.getCompreType(); + + switch (compreType) { + case 1://固定值 + calCompre(cal, deviceBean); + break; + case 2://当天日期 + + break; + } + } - break; } + + System.out.println("jsonObject:" + jsonObject.toString()); } + } catch (JSONException e) { + e.printStackTrace(); } catch (ParseException e) { e.printStackTrace(); } - } } /** - * - * @param cal 联动模板 + * @param cal 联动模板 * @param deviceBean 控制设备 */ private void calCompre(CalDevContrl cal, DeviceBean deviceBean) { - int thrsoldValue = Integer.parseInt(cal.getThresholdValue());//设定的阈值 + + + int thrsoldValue = 0; + + if (cal.getModelType() == 10) {//人体感应 + if (cal.getThreValue().equals("有人")) thrsoldValue = 1; + else thrsoldValue = 0; + } else { + thrsoldValue = Integer.parseInt(cal.getThreValue());//设定的阈值 + } + int value = Integer.parseInt(deviceBean.getValue());//实际的值 - System.out.println("thrsoldValue:"+thrsoldValue+" value:"+value+" cal:"+cal.toString()); - switch (cal.getComPre()){ + System.out.println("thrsoldValue:" + thrsoldValue + " value:" + value + " cal:" + cal.toString()); + switch (cal.getComPre()) { case 1://大于 - if (value>thrsoldValue)//启动触发条件 + if (value > thrsoldValue)//启动触发条件 startDevice(cal);//开启联动的设备 break; case 2://等于 - if(value == thrsoldValue) + if (value == thrsoldValue) startDevice(cal);//开启联动的设备 break; case 3://小于 - if(value < thrsoldValue) + if (value < thrsoldValue) startDevice(cal);//开启联动的设备 break; + default://不触发条件 + + removeSet(cal); + + break; + } + + } + + /** + * 移除设备 + * + * @param calDevContrl + */ + private void removeSet(CalDevContrl calDevContrl) { + + Iterator calDevContrlIterator = deviceSet.iterator(); + + while (calDevContrlIterator.hasNext()) { + + CalDevContrl calDevContrl1 = calDevContrlIterator.next(); + if (calDevContrl1.getDevid().equals(calDevContrl.getDevid()) && calDevContrl.getComPre() == calDevContrl1.getComPre()) { + calDevContrlIterator.remove(); + } } } /** - * 执行计划 + * 执行计划,并判断联动的设备是否满足条件; + * * @param cal */ private void startDevice(CalDevContrl cal) { int modelType = cal.getModelType(); - String conDevId = cal.getConDevId();//被控制的设备id - String conValue =cal.getConValue(); - String conCode = cal.getConCode(); - switch (modelType){ - case 1://开关 - HttpUtil.controlDev(conDevId,conCode,conValue); - break; - case 2://插座 - HttpUtil.controlDev(conDevId,conCode,conValue); - break; - case 3://排插 - HttpUtil.controlDev(conDevId,conCode,conValue); - break; - case 7://空调伴侣 - HttpUtil.addAirCode(conValue,conDevId); - break; - case 10://开关 - HttpUtil.controlDev(conDevId,conCode,conValue); - break; - case 12://万能遥控器 - HttpUtil.addAirCode(conValue,conDevId); - break; + + deviceSet.add(cal); + + String assDevice = cal.getAssDevice();//联动的设备id + + boolean isExit = isExist(assDevice.split(",")); + + System.out.println("是否符合联动条件:" + isExit); + + if (isExit) {//符合联动条件 + + List calDevBeContrlList = getCalDevBeCon(assDevice); + + for (int i = 0; i < calDevBeContrlList.size(); i++) { + CalDevBeContrl calDevBeContrl = calDevBeContrlList.get(i); + System.out.println("控制对象:" + calDevBeContrl.toString()); + String conDevId = calDevBeContrl.getConDevId();//被控制的设备id + String conValue = calDevBeContrl.getConValue(); + String conCodes = calDevBeContrl.getConCode(); + + String[] conCodeStr = conCodes.split(","); + + for (int j = 0; j < conCodeStr.length; j++) { + String conCode = conCodeStr[j]; + switch (modelType) { + case 1://开关 + HttpUtil.controlDev(conDevId, conCode, conValue); + break; + case 2://插座 + HttpUtil.controlDev(conDevId, conCode, conValue); + break; + case 3://排插 + HttpUtil.controlDev(conDevId, conCode, conValue); + break; + case 7://空调伴侣 + HttpUtil.addAirCode(conValue, conDevId); + break; + case 10://开关 + HttpUtil.controlDev(conDevId, conCode, conValue); + break; + case 12://万能遥控器 + HttpUtil.addAirCode(conValue, conDevId); + break; + } + } + + } + } + } + + /** + * 获取被控制的设备 + * + * @param assDevice + * @return + */ + private List getCalDevBeCon(String assDevice) { + + String[] assDeviceIds = assDevice.split(","); + + List devBeContrlList = new ArrayList<>(); + + for (int i = 0; i < assDeviceIds.length; i++) { + String deviceId = assDeviceIds[i]; + + List calDevContrl = deviceDao.getCalDevContrlWidthDevId(deviceId); + + for (int j = 0; j < calDevContrl.size(); j++) { + + CalDevContrl calDevContrl1 = calDevContrl.get(j); + + if (!calDevContrl1.getDevBeId().equals("0")) { + String[] calDevBeIdStr = calDevContrl1.getDevBeId().split(","); + if (calDevBeIdStr != null) { + for (int k = 0; k < calDevBeIdStr.length; k++) { + CalDevBeContrl calDevBeContrl = deviceDao.getCalDevBeControl(calDevBeIdStr[k]); + devBeContrlList.add(calDevBeContrl); + } + } + } + } + + } + + return devBeContrlList; + } + + + /** + * 判断联动设备是否符合条件 + * + * @param deviceIds + * @return + */ + private boolean isExist(String[] deviceIds) { + + for (int i = 0; i < deviceIds.length; i++) { + String deviceId = deviceIds[i]; + Iterator calDevContrlIterator = deviceSet.iterator(); + boolean is = false; + while (calDevContrlIterator.hasNext()) { + + CalDevContrl calDevContrl = calDevContrlIterator.next(); + if (calDevContrl.getDevid().equals(deviceId)) {//存在设备 + is = true; + } + + } + if (!is) return false; + } + return true; } 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 index ac9bb19..2285e49 100644 --- a/cloud/mypulsar/src/main/java/com/example/mypulsar/utils/HttpUtil.java +++ b/cloud/mypulsar/src/main/java/com/example/mypulsar/utils/HttpUtil.java @@ -3,7 +3,6 @@ package com.example.mypulsar.utils; import com.example.mypulsar.bean.Command; import com.example.mypulsar.bean.TuYaAirCondition; import com.example.mypulsar.bean.TuYaCommand; -import org.apache.pulsar.shade.com.google.gson.Gson; import org.springframework.boot.configurationprocessor.json.JSONException; import org.springframework.boot.configurationprocessor.json.JSONObject; import org.springframework.core.io.FileSystemResource; @@ -156,7 +155,6 @@ public class HttpUtil { System.out.println("url-------------------------------:" + url+" conValue:"+tuYaAirCondition.toString()); String response = restTemplate.postForObject(url, tuYaAirCondition, String.class); - System.out.println("response----------------------------------:" + response); return response; diff --git a/cloud/pom.xml b/cloud/pom.xml index 60c2268..e18b4eb 100644 --- a/cloud/pom.xml +++ b/cloud/pom.xml @@ -14,58 +14,81 @@ cloud Demo project for Spring Boot + + 1.8 + Greenwich.SR1 + 4.1 + 2.1.7.RELEASE + 2.3.6.RELEASE + 1.2.60 + Cairo-SR7 + + server1 server2 - common - + + geteway haikang - search_smartCampus - search_xiaoan + + - quartz - zkAttendance + + - - 1.8 - Greenwich.SR1 - - - org.springframework.cloud - spring-cloud-starter-netflix-eureka-server + com.alibaba + fastjson + 1.2.58 + compile - org.springframework.boot - spring-boot-starter-test - test + org.projectlombok + lombok + 1.18.8 - org.springframework.boot - spring-boot-starter-actuator + org.springframework.cloud + spring-cloud-starter-netflix-eureka-client + org.springframework.cloud + spring-cloud-starter-netflix-eureka-client + + org.springframework.boot spring-boot-configuration-processor - + true - com.alibaba - fastjson - 1.2.58 - compile + org.springframework.boot + spring-boot-starter-actuator + + + org.springframework.cloud + spring-cloud-starter-netflix-hystrix + + + org.projectlombok + lombok + 1.16.20 + + + commons-io + commons-io + 2.6 @@ -73,12 +96,26 @@ + org.springframework.boot + spring-boot-dependencies + ${spring-boot.version} + pom + import + + org.springframework.cloud spring-cloud-dependencies ${spring-cloud.version} pom import + + io.spring.platform + platform-bom + ${spring-platform-bom.version} + pom + import + diff --git a/cloud/quartz/src/main/java/com/sincere/quartz/enums/KqTypeEnums.java b/cloud/quartz/src/main/java/com/sincere/quartz/enums/KqTypeEnums.java index 9d946e1..0f2534f 100644 --- a/cloud/quartz/src/main/java/com/sincere/quartz/enums/KqTypeEnums.java +++ b/cloud/quartz/src/main/java/com/sincere/quartz/enums/KqTypeEnums.java @@ -6,21 +6,21 @@ package com.sincere.quartz.enums; * @date 2019/11/29 0029 11:44 */ public enum KqTypeEnums { - morning_to_school(1,"早上到校"), - noon_le_school(2,"中午离校"), - afternoon_to_school(3,"下午到校"), - afternoon_le_school(4,"下午离校"), - night_to_school(5,"晚上到校"), - night_le_school(6,"晚上离校"), - morning_to_chamber(7,"早上离寝"), - noon_to_chamber(8,"中午到寝"), - noon_le_chamber(9,"中午离寝"), - afternoon_to_chamber(10,"下午到寝"), - afternoon_le_chamber(11,"下午离寝"), - night_to_chamber(12,"晚上到寝"); - - private int type ; - private String name ; + morning_to_school(1, "早上到校"), + noon_le_school(2, "中午离校"), + afternoon_to_school(3, "下午到校"), + afternoon_le_school(4, "下午离校"), + night_to_school(5, "晚上到校"), + night_le_school(6, "晚上离校"), + morning_to_chamber(7, "早上离寝"), + noon_to_chamber(8, "中午到寝"), + noon_le_chamber(9, "中午离寝"), + afternoon_to_chamber(10, "下午到寝"), + afternoon_le_chamber(11, "下午离寝"), + night_to_chamber(12, "晚上到寝"); + + private int type; + private String name; public int getType() { return type; @@ -43,12 +43,12 @@ public enum KqTypeEnums { this.name = name; } - public static String getName(int type){ - for(KqTypeEnums enums : KqTypeEnums.values()){ - if(enums.getType() == type){ + public static String getName(int type) { + for (KqTypeEnums enums : KqTypeEnums.values()) { + if (enums.getType() == type) { return enums.getName(); } } - return "" ; + return ""; } } diff --git a/cloud/quartz/src/main/java/com/sincere/quartz/enums/TypeEnums.java b/cloud/quartz/src/main/java/com/sincere/quartz/enums/TypeEnums.java index c52c059..735b751 100644 --- a/cloud/quartz/src/main/java/com/sincere/quartz/enums/TypeEnums.java +++ b/cloud/quartz/src/main/java/com/sincere/quartz/enums/TypeEnums.java @@ -7,15 +7,15 @@ package com.sincere.quartz.enums; */ public enum TypeEnums { - kaoqing(10,"考勤"); + kaoqing(10, "考勤"); TypeEnums(int type, String name) { this.type = type; this.name = name; } - private int type ; - private String name ; + private int type; + private String name; public int getType() { return type; diff --git a/cloud/quartz/src/main/java/com/sincere/quartz/job/KQJob.java b/cloud/quartz/src/main/java/com/sincere/quartz/job/KQJob.java index b95a85d..c9bc173 100644 --- a/cloud/quartz/src/main/java/com/sincere/quartz/job/KQJob.java +++ b/cloud/quartz/src/main/java/com/sincere/quartz/job/KQJob.java @@ -308,8 +308,8 @@ public class KQJob { "整体数据:" + message); String wapUrl = "http://campus.myjxt.com/studentRecord/znxwwebapp/index.html?" + "schoolid="+teacher.getSchoolId()+"&userId="+teacher.getUserId()+"&name="+teacher.getName()+ "&TemplateId=" + templateId+ - "&data="+thirdOpenId+"&type=5&stype=4&mobile="+teacher.getMobile()+"&pass="+teacher.getPass()+ - "&QianDaoId="+times[3]+"&ClassId=0&face=&sourcetype=16&soutype=3×tamp="+ DateUtils.getDate()+"&time="+DateUtils.date2String(new Date(),DateUtils.format1) ; + "&data="+thirdOpenId+"&type=1&stype=4&mobile="+teacher.getMobile()+"&pass="+teacher.getPass()+ + "&face=&sourcetype=16&soutype=3×tamp="+ DateUtils.getDate()+"&time="+DateUtils.date2String(new Date(),DateUtils.format1) ; dingSms.setSchoolId(teacher.getSchoolId()); dingSms.setDingUserId(thirdOpenId); dingSms.setAgentId(appDto.getAgentId()); diff --git a/cloud/quartz/src/main/java/com/sincere/quartz/model/DingSms.java b/cloud/quartz/src/main/java/com/sincere/quartz/model/DingSms.java index 20450f0..3e3a040 100644 --- a/cloud/quartz/src/main/java/com/sincere/quartz/model/DingSms.java +++ b/cloud/quartz/src/main/java/com/sincere/quartz/model/DingSms.java @@ -6,16 +6,16 @@ package com.sincere.quartz.model; * @date 2019/11/28 0028 9:45 */ public class DingSms { - private String tableName ; - - private String msg ; - private int schoolId ; - private String dingUserId ; - private String wapUrl ; - private String agentId ; - private int tdType ; - private String receiveUserId ; - private String name ; + private String tableName; + + private String msg; + private int schoolId; + private String dingUserId; + private String wapUrl; + private String agentId; + private int tdType; + private String receiveUserId; + private String name; public String getTableName() { return tableName; diff --git a/cloud/quartz/src/main/java/com/sincere/quartz/model/ShortMsg.java b/cloud/quartz/src/main/java/com/sincere/quartz/model/ShortMsg.java index 4d30394..01bf377 100644 --- a/cloud/quartz/src/main/java/com/sincere/quartz/model/ShortMsg.java +++ b/cloud/quartz/src/main/java/com/sincere/quartz/model/ShortMsg.java @@ -7,11 +7,11 @@ package com.sincere.quartz.model; */ public class ShortMsg { - private String tableName ; + private String tableName; - private int schoolId ; - private String mobile ; - private String msg ; + private int schoolId; + private String mobile; + private String msg; public String getTableName() { return tableName; diff --git a/cloud/quartz/src/main/java/com/sincere/quartz/model/WeChatSms.java b/cloud/quartz/src/main/java/com/sincere/quartz/model/WeChatSms.java index dc3a1bc..a980c17 100644 --- a/cloud/quartz/src/main/java/com/sincere/quartz/model/WeChatSms.java +++ b/cloud/quartz/src/main/java/com/sincere/quartz/model/WeChatSms.java @@ -7,17 +7,17 @@ package com.sincere.quartz.model; */ public class WeChatSms { - private String tableName ; - - private String receiveUserId ; - private String qiYeHaoUserId ; - private int schoolId ; - private String msgUrl ; - private String name ; - private String appId ; - private String secret ; - private int tdType ; - private String msg ; + private String tableName; + + private String receiveUserId; + private String qiYeHaoUserId; + private int schoolId; + private String msgUrl; + private String name; + private String appId; + private String secret; + private int tdType; + private String msg; public String getAppId() { diff --git a/cloud/quartz/src/main/resources/logback.xml b/cloud/quartz/src/main/resources/logback.xml index 1d0ebec..800e8d5 100644 --- a/cloud/quartz/src/main/resources/logback.xml +++ b/cloud/quartz/src/main/resources/logback.xml @@ -1,60 +1,95 @@     -     +     +     - +     -     -         -         -             -             [%d{yyyy-MM-dd HH:mm:ss.SSS}] [%thread] %highlight([%-5level] %logger{50} - %msg%n) -             UTF-8 -         -     +     + +         +         + +             +             + [%d{yyyy-MM-dd HH:mm:ss.SSS}] [%thread] %highlight([%-5level] %logger{50} - %msg%n) +             + UTF-8 +         + +     +     -     -         -         -             -             ${LOG_HOME}/${PROJECT_NAME}/%d{yyyy-MM-dd}.%i.log -             -             30 -             -             100MB -         - -         -             -             [%d{yyyy-MM-dd HH:mm:ss.SSS}] [%thread] [%-5level] %logger{50} - %msg%n -             UTF-8 -         -     -     -        -    - -    -    -    -    -    -    -    - - -    -    -    -    -    -    -        -        -    +     + +         +         + +             +             + ${LOG_HOME}/${PROJECT_NAME}/%d{yyyy-MM-dd}.%i.log +             +             + 30 +             +             + 100MB +         + + +         + +             +             + [%d{yyyy-MM-dd HH:mm:ss.SSS}] [%thread] [%-5level] %logger{50} - %msg%n +             + UTF-8 +         + +     + +     + +         + +     + + +     +     + +     + +     + +     + +     + +     + + + +     + +     + +     + +     + +     +     + +         + +         + +     + diff --git a/cloud/quartz/src/main/resources/mapper/SmsMapper.xml b/cloud/quartz/src/main/resources/mapper/SmsMapper.xml index 197a699..e65ee1c 100644 --- a/cloud/quartz/src/main/resources/mapper/SmsMapper.xml +++ b/cloud/quartz/src/main/resources/mapper/SmsMapper.xml @@ -3,17 +3,21 @@ - insert into ${tableName} (Msg,MsgID,SchoolID,Type,Status,intime,sendtime,DingUserId,WapUrl,agentid,tdtype,ReceiveUserID,Remark) - values (#{msg},-1,#{schoolId},3,0,GETDATE(),GETDATE(),#{dingUserId},#{wapUrl},#{agentId},#{tdType},#{receiveUserId},#{name}) + insert into ${tableName} (Msg, MsgID, SchoolID, Type, Status, intime, sendtime, DingUserId, WapUrl, agentid, + tdtype, ReceiveUserID, Remark) + values (#{msg}, -1, #{schoolId}, 1, 0, GETDATE(), GETDATE(), #{dingUserId}, #{wapUrl}, #{agentId}, #{tdType}, + #{receiveUserId}, #{name}) - insert into ${tableName} (SchoolID,MsgID,Guid,WapUrl,Status,intime,sendTime,SendUserName,ReceiveUserID,QiYeHaoUserId,AppID,Secret,tdtype,Remark) - values (#{schoolId},-1,#{msg},#{msgUrl},0,GETDATE(),GETDATE(),'智能校卫',#{receiveUserId},#{qiYeHaoUserId},#{appId},#{secret},#{tdType},#{name}) + insert into ${tableName} (SchoolID, MsgID, Guid, WapUrl, Status, intime, sendTime, SendUserName, ReceiveUserID, + QiYeHaoUserId, AppID, Secret, tdtype, Remark) + values (#{schoolId}, -1, #{msg}, #{msgUrl}, 0, GETDATE(), GETDATE(), '智能校卫', #{receiveUserId}, #{qiYeHaoUserId}, + #{appId}, #{secret}, #{tdType}, #{name}) - insert into ${tableName} (SchoolID,Mobile,Msg,tdtype,Status,IsNeedSend,SendTime,intime) - values (#{schoolId},#{mobile},#{msg},1,0,1,GETDATE(),GETDATE()) + insert into ${tableName} (SchoolID, Mobile, Msg, tdtype, Status, IsNeedSend, SendTime, intime) + values (#{schoolId}, #{mobile}, #{msg}, 1, 0, 1, GETDATE(), GETDATE()) 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 deleted file mode 100644 index b4c27d3..0000000 --- a/cloud/search_smartCampus/src/main/java/com/sincere/smartSearch/FileConfiguration.java +++ /dev/null @@ -1,18 +0,0 @@ -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_xiaoan/pom.xml b/cloud/search_xiaoan/pom.xml index 84f0e27..d91193e 100644 --- a/cloud/search_xiaoan/pom.xml +++ b/cloud/search_xiaoan/pom.xml @@ -51,6 +51,7 @@ rapid-core 4.0.5 + org.apache.commons commons-lang3 diff --git a/cloud/server1/pom.xml b/cloud/server1/pom.xml index cf7a20b..de19cd3 100644 --- a/cloud/server1/pom.xml +++ b/cloud/server1/pom.xml @@ -13,6 +13,31 @@ server1 Demo project for Spring Boot + + + + com.aliyun.oss + oss + system + 1 + ${project.basedir}/libs/aliyun-sdk-oss-3.8.0.jar + + + + com.jdom + jdom + system + 1 + ${project.basedir}/libs/jdom-1.1.jar + + + + org.springframework.cloud + spring-cloud-starter-netflix-eureka-server + + + + diff --git a/cloud/server1/src/main/java/com/sincere/server1/Server1Application.java b/cloud/server1/src/main/java/com/sincere/server1/Server1Application.java index ad4e09a..8b451cc 100644 --- a/cloud/server1/src/main/java/com/sincere/server1/Server1Application.java +++ b/cloud/server1/src/main/java/com/sincere/server1/Server1Application.java @@ -4,6 +4,14 @@ import org.springframework.boot.SpringApplication; import org.springframework.boot.autoconfigure.SpringBootApplication; import org.springframework.cloud.netflix.eureka.server.EnableEurekaServer; +import java.io.FileNotFoundException; +import java.io.FileOutputStream; +import java.io.IOException; +import java.io.InputStream; +import java.net.MalformedURLException; +import java.net.URL; +import java.net.URLConnection; + @EnableEurekaServer @SpringBootApplication public class Server1Application { diff --git a/cloud/server1/src/main/java/com/sincere/server1/Test2.java b/cloud/server1/src/main/java/com/sincere/server1/Test2.java new file mode 100644 index 0000000..94d9ed9 --- /dev/null +++ b/cloud/server1/src/main/java/com/sincere/server1/Test2.java @@ -0,0 +1,91 @@ +package com.sincere.server1; + +import com.aliyun.oss.OSS; +import com.aliyun.oss.OSSClientBuilder; + +import java.io.*; +import java.net.URL; + +public class Test2 { + + // Endpoint以杭州为例,其它Region请按实际情况填写。 + public static String endpoint = "http://oss-cn-hangzhou.aliyuncs.com"; + // 云账号AccessKey有所有API访问权限,建议遵循阿里云安全最佳实践,创建并使用RAM子账号进行API访问或日常运维,请登录 https://ram.console.aliyun.com 创建。 + public static String accessKeyId = "QiuM3PwHTnVotcGy"; + public static String accessKeySecret = "Yqs7RlaC1MioZu2YYJ6u0TdeO13VFC"; + + public static void main(String[] args) { + File filePath = new File("D:\\OSS\\video.txt"); + try { + BufferedReader bufferedReader = new BufferedReader(new FileReader(filePath)); + + String cotnent = null; + + int index = 0; + while ((cotnent=bufferedReader.readLine())!=null){ + + upLoadNetStraeam(cotnent,"",cotnent.substring(cotnent.lastIndexOf("/")+1,cotnent.length())); + index++; + System.out.println("index:"+index); + + } + + } catch (FileNotFoundException e) { + e.printStackTrace(); + } catch (IOException e) { + e.printStackTrace(); + } +// File[] files = filePath.listFiles(); +// upLoadNetStraeam("http://0575jyzx.oss-cn-hangzhou.aliyuncs.com/Air/Data/898b208f82574ddcba2d439a1e28bd39.mp4", "test", "898b208f82574ddcba2d439a1e28bd39.mp4"); + /* for (File file: + files) { + + upload(file,"Data"); + + }*/ + } + + /** + * 上传网络流 + * @param url + * @param path + * @param name + */ + public static void upLoadNetStraeam(String url, String path, String name) { + System.out.println("name:"+name+" url --"+url); +// 创建OSSClient实例。 + OSS ossClient = new OSSClientBuilder().build(endpoint, accessKeyId, accessKeySecret); + +// 上传网络流。 + InputStream inputStream = null; + try { + inputStream = new URL(url).openStream(); + } catch (IOException e) { + e.printStackTrace(); + } + ossClient.putObject("szyundisk", "YikeData/" + name, inputStream); + +// 关闭OSSClient。 + ossClient.shutdown(); + + } + + public static void upload(File file, String path) { + +// 创建OSSClient实例。 + OSS ossClient = new OSSClientBuilder().build(endpoint, accessKeyId, accessKeySecret); + +// 上传文件流。 + InputStream inputStream = null; + try { + inputStream = new FileInputStream(file); + ossClient.putObject("szyundisk", "Air/" + path + "/" + file.getName(), inputStream); + +// 关闭OSSClient。 + ossClient.shutdown(); + } catch (FileNotFoundException e) { + e.printStackTrace(); + } + } + +} diff --git a/cloud/server1/src/main/resources/application.yaml b/cloud/server1/src/main/resources/application.yaml index 10d301c..c66ed43 100644 --- a/cloud/server1/src/main/resources/application.yaml +++ b/cloud/server1/src/main/resources/application.yaml @@ -3,7 +3,7 @@ server: spring: application: - name: eureka-server + name: eureka-server1 profiles: active: dev diff --git a/cloud/server2/pom.xml b/cloud/server2/pom.xml index 2ed43ce..56ada0f 100644 --- a/cloud/server2/pom.xml +++ b/cloud/server2/pom.xml @@ -13,6 +13,13 @@ server2 Demo project for Spring Boot + + + org.springframework.cloud + spring-cloud-starter-netflix-eureka-server + + + diff --git a/cloud/server2/src/main/resources/application.yaml b/cloud/server2/src/main/resources/application.yaml index 1a696a9..f4f3a71 100644 --- a/cloud/server2/src/main/resources/application.yaml +++ b/cloud/server2/src/main/resources/application.yaml @@ -3,7 +3,7 @@ server: spring: application: - name: eureka-server + name: eureka-server2 profiles: active: dev diff --git a/cloud/uploadFile/test.jpg b/cloud/uploadFile/test.jpg deleted file mode 100644 index 824229d..0000000 Binary files a/cloud/uploadFile/test.jpg and /dev/null differ -- libgit2 0.21.0