diff --git a/cloud/common/src/main/java/com/sincere/common/dto/smartCampus/AppDto.java b/cloud/common/src/main/java/com/sincere/common/dto/smartCampus/AppDto.java index 5a07cba..5999763 100644 --- a/cloud/common/src/main/java/com/sincere/common/dto/smartCampus/AppDto.java +++ b/cloud/common/src/main/java/com/sincere/common/dto/smartCampus/AppDto.java @@ -8,6 +8,8 @@ package com.sincere.common.dto.smartCampus; public class AppDto { private String agentId ; private String agentSecret ; + private String qyhId ; + private String agentKey ; public String getAgentId() { return agentId; @@ -24,4 +26,20 @@ public class AppDto { public void setAgentSecret(String agentSecret) { this.agentSecret = agentSecret; } + + public String getQyhId() { + return qyhId; + } + + public void setQyhId(String qyhId) { + this.qyhId = qyhId; + } + + public String getAgentKey() { + return agentKey; + } + + public void setAgentKey(String agentKey) { + this.agentKey = agentKey; + } } diff --git a/cloud/common/src/main/java/com/sincere/common/dto/smartCampus/BindPushDto.java b/cloud/common/src/main/java/com/sincere/common/dto/smartCampus/BindPushDto.java new file mode 100644 index 0000000..eebd08b --- /dev/null +++ b/cloud/common/src/main/java/com/sincere/common/dto/smartCampus/BindPushDto.java @@ -0,0 +1,73 @@ +package com.sincere.common.dto.smartCampus; + +/** + * @author chen + * @version 1.0 + * @date 2019/12/11 0011 16:56 + */ +public class BindPushDto { + + private int schoolId ; + private int type ; // 0是企业号,1是钉钉 + private String beginDate ; + private String endDate ; + private int intervalDays ; + private String pushTime ; + private String msg ; + + public int getSchoolId() { + return schoolId; + } + + public void setSchoolId(int schoolId) { + this.schoolId = schoolId; + } + + public int getType() { + return type; + } + + public void setType(int type) { + this.type = type; + } + + public String getBeginDate() { + return beginDate; + } + + public void setBeginDate(String beginDate) { + this.beginDate = beginDate; + } + + public String getEndDate() { + return endDate; + } + + public void setEndDate(String endDate) { + this.endDate = endDate; + } + + public int getIntervalDays() { + return intervalDays; + } + + public void setIntervalDays(int intervalDays) { + this.intervalDays = intervalDays; + } + + public String getPushTime() { + return pushTime; + } + + public void setPushTime(String pushTime) { + this.pushTime = pushTime; + } + + public String getMsg() { + return msg; + } + + public void setMsg(String msg) { + this.msg = msg; + } +} diff --git a/cloud/common/src/main/java/com/sincere/common/dto/smartCampus/CensusKqDto.java b/cloud/common/src/main/java/com/sincere/common/dto/smartCampus/CensusKqDto.java index 9754444..e45e062 100644 --- a/cloud/common/src/main/java/com/sincere/common/dto/smartCampus/CensusKqDto.java +++ b/cloud/common/src/main/java/com/sincere/common/dto/smartCampus/CensusKqDto.java @@ -6,49 +6,31 @@ package com.sincere.common.dto.smartCampus; * @date 2019/11/29 0029 14:27 */ public class CensusKqDto { - private int classId ; - private String className ; - private int allT ; - private int kqT ; - private int qjT ; + private String targetName ; + private int leaveCount ; + private int notAttendCount ; - public int getClassId() { - return classId; + public String getTargetName() { + return targetName; } - public void setClassId(int classId) { - this.classId = classId; + public void setTargetName(String targetName) { + this.targetName = targetName; } - public String getClassName() { - return className; + public int getLeaveCount() { + return leaveCount; } - public void setClassName(String className) { - this.className = className; + public void setLeaveCount(int leaveCount) { + this.leaveCount = leaveCount; } - public int getAllT() { - return allT; + public int getNotAttendCount() { + return notAttendCount; } - public void setAllT(int allT) { - this.allT = allT; - } - - public int getKqT() { - return kqT; - } - - public void setKqT(int kqT) { - this.kqT = kqT; - } - - public int getQjT() { - return qjT; - } - - public void setQjT(int qjT) { - this.qjT = qjT; + public void setNotAttendCount(int notAttendCount) { + this.notAttendCount = notAttendCount; } } diff --git a/cloud/common/src/main/java/com/sincere/common/dto/smartCampus/KqTeacherDto.java b/cloud/common/src/main/java/com/sincere/common/dto/smartCampus/KqTeacherDto.java index 94ee788..dfa1b45 100644 --- a/cloud/common/src/main/java/com/sincere/common/dto/smartCampus/KqTeacherDto.java +++ b/cloud/common/src/main/java/com/sincere/common/dto/smartCampus/KqTeacherDto.java @@ -11,11 +11,13 @@ public class KqTeacherDto { private String name ; private String mobile ; private String pass ; - private String DingUserId ; - private String weChatUserId ; private String openId ; private String face ; + private int classId ; + private int roomId ; + private String targetName ; + public String getUserId() { return userId; } @@ -56,22 +58,6 @@ public class KqTeacherDto { this.pass = pass; } - public String getDingUserId() { - return DingUserId; - } - - public void setDingUserId(String dingUserId) { - DingUserId = dingUserId; - } - - public String getWeChatUserId() { - return weChatUserId; - } - - public void setWeChatUserId(String weChatUserId) { - this.weChatUserId = weChatUserId; - } - public String getOpenId() { return openId; } @@ -87,4 +73,28 @@ public class KqTeacherDto { public void setFace(String face) { this.face = face; } + + public int getClassId() { + return classId; + } + + public void setClassId(int classId) { + this.classId = classId; + } + + public int getRoomId() { + return roomId; + } + + public void setRoomId(int roomId) { + this.roomId = roomId; + } + + public String getTargetName() { + return targetName; + } + + public void setTargetName(String targetName) { + this.targetName = targetName; + } } diff --git a/cloud/common/src/main/java/com/sincere/common/dto/smartCampus/ParentDto.java b/cloud/common/src/main/java/com/sincere/common/dto/smartCampus/ParentDto.java new file mode 100644 index 0000000..faef716 --- /dev/null +++ b/cloud/common/src/main/java/com/sincere/common/dto/smartCampus/ParentDto.java @@ -0,0 +1,37 @@ +package com.sincere.common.dto.smartCampus; + +/** + * @author chen + * @version 1.0 + * @date 2019/12/10 0010 11:14 + */ +public class ParentDto { + + private int schoolId ; + private int parentId ; + private String mobile ; + + public int getSchoolId() { + return schoolId; + } + + public void setSchoolId(int schoolId) { + this.schoolId = schoolId; + } + + public int getParentId() { + return parentId; + } + + public void setParentId(int parentId) { + this.parentId = parentId; + } + + public String getMobile() { + return mobile; + } + + public void setMobile(String mobile) { + this.mobile = mobile; + } +} diff --git a/cloud/common/src/main/java/com/sincere/common/dto/smartCampus/TemplateDto.java b/cloud/common/src/main/java/com/sincere/common/dto/smartCampus/TemplateDto.java index 10e4e21..850768e 100644 --- a/cloud/common/src/main/java/com/sincere/common/dto/smartCampus/TemplateDto.java +++ b/cloud/common/src/main/java/com/sincere/common/dto/smartCampus/TemplateDto.java @@ -9,10 +9,19 @@ import java.io.Serializable; */ public class TemplateDto implements Serializable { + private int id ; private String config ; private int schoolId ; private String type ; + public int getId() { + return id; + } + + public void setId(int id) { + this.id = id; + } + public String getConfig() { return config; } diff --git a/cloud/common/src/main/java/com/sincere/common/enums/PushTypeEnums.java b/cloud/common/src/main/java/com/sincere/common/enums/PushTypeEnums.java new file mode 100644 index 0000000..ce66bbf --- /dev/null +++ b/cloud/common/src/main/java/com/sincere/common/enums/PushTypeEnums.java @@ -0,0 +1,40 @@ +package com.sincere.common.enums; + +/** + * @author chen + * @version 1.0 + * @date 2019/12/10 0010 11:30 + */ +public enum PushTypeEnums { + + WEB(0,"站内消息"), + APP(1,"APP消息"), + MESSAGE(2,"短消息"), + WECHAT(3,"微信公众号"), + DING(4,"盯盯消息"), + QIYEHAO(5,"企业号消息"); + + private int type ; + private String name ; + + PushTypeEnums(int type, String name) { + this.type = type; + this.name = name; + } + + public int getType() { + return type; + } + + public void setType(int type) { + this.type = type; + } + + public String getName() { + return name; + } + + public void setName(String name) { + this.name = name; + } +} diff --git a/cloud/common/src/main/java/com/sincere/common/util/DateUtils.java b/cloud/common/src/main/java/com/sincere/common/util/DateUtils.java index 879fd0c..a3fcdf9 100644 --- a/cloud/common/src/main/java/com/sincere/common/util/DateUtils.java +++ b/cloud/common/src/main/java/com/sincere/common/util/DateUtils.java @@ -18,6 +18,10 @@ public class DateUtils { public static String format2 = "yyyy-MM-dd HH:mm:ss"; + public static String format3 = "yyyyMMddHHmm" ; + + public static String format4 = "HH:mm" ; + public static long getDate(){ return System.currentTimeMillis(); } diff --git a/cloud/common/src/main/java/com/sincere/common/util/HttpClientUtils.java b/cloud/common/src/main/java/com/sincere/common/util/HttpClientUtils.java index 14b0124..ad52637 100644 --- a/cloud/common/src/main/java/com/sincere/common/util/HttpClientUtils.java +++ b/cloud/common/src/main/java/com/sincere/common/util/HttpClientUtils.java @@ -1,5 +1,6 @@ package com.sincere.common.util; +import com.alibaba.fastjson.JSONArray; import com.alibaba.fastjson.JSONObject; import org.apache.http.HttpEntity; import org.apache.http.HttpStatus; @@ -17,6 +18,7 @@ import java.io.IOException; import java.io.InputStream; import java.net.HttpURLConnection; import java.net.URL; +import java.util.Date; /** * HttpClient4.3工具类 @@ -28,14 +30,20 @@ public class HttpClientUtils { private static RequestConfig requestConfig = null; - static - { + static { // 设置请求和传输超时时间 requestConfig = RequestConfig.custom().setSocketTimeout(2000).setConnectTimeout(2000).build(); } public static void main(String[] args){ - JSONObject teacherList = HttpClientUtils.httpGet("http://60.190.202.57:1000/api/EasyN/GetSchoolSubject?SchoolId=1"); +// JSONObject object = HttpClientUtils.httpGet("http://60.190.202.57:1000/api/EasyN/GeAttendDetailNew?Id=158&TemplateId=0IZBD9624P&Type=0&time=2019-12-12&UserId=P113111&SchoolId=16"); +// JSONArray data = (JSONArray)object.get("data"); + String msg = "[{\"stuCount\":393,\"stuAttendCount\":341,\"noAttendCount\":52,\"sNoAttendCount\":52,\"leaveCount\":0,\"state\":\"已结束\",\"id\":310,\"templateId\":\"OCQQMV0ZXM\",\"color\":3}]"; + JSONArray data = JSONArray.parseArray(msg); + for(int i = 0 ; i < data.size() ; i++){ + JSONObject object = data.getJSONObject(i); + System.out.println(object.get("stuCount")); + } System.out.println("1"); } @@ -45,7 +53,7 @@ public class HttpClientUtils { * @param jsonParam 参数 * @return */ - public static JSONObject httpPost(String url, JSONObject jsonParam) { + public static JSONObject httpPostJson(String url, String jsonParam) { // post请求返回结果 CloseableHttpClient httpClient = HttpClients.createDefault(); JSONObject jsonResult = null; @@ -55,7 +63,7 @@ public class HttpClientUtils { try { if (null != jsonParam) { // 解决中文乱码问题 - StringEntity entity = new StringEntity(jsonParam.toString(), "utf-8"); + StringEntity entity = new StringEntity(jsonParam, "utf-8"); entity.setContentEncoding("UTF-8"); entity.setContentType("application/json"); httpPost.setEntity(entity); diff --git a/cloud/quartz/lib/taobao-sdk-java-auto_1479188381469-20191205.jar b/cloud/quartz/lib/taobao-sdk-java-auto_1479188381469-20191205.jar new file mode 100644 index 0000000..23bd46b Binary files /dev/null and b/cloud/quartz/lib/taobao-sdk-java-auto_1479188381469-20191205.jar differ diff --git a/cloud/quartz/pom.xml b/cloud/quartz/pom.xml index c8b1d0c..848668b 100644 --- a/cloud/quartz/pom.xml +++ b/cloud/quartz/pom.xml @@ -13,6 +13,13 @@ + taobao-sdk-java-auto + ding + system + 1 + ${project.basedir}/lib/taobao-sdk-java-auto_1479188381469-20191205.jar + + com.sincere common 1.0.0 diff --git a/cloud/quartz/src/main/java/com/sincere/quartz/feign/ScFeign.java b/cloud/quartz/src/main/java/com/sincere/quartz/feign/ScFeign.java index 1aeb285..dfc318c 100644 --- a/cloud/quartz/src/main/java/com/sincere/quartz/feign/ScFeign.java +++ b/cloud/quartz/src/main/java/com/sincere/quartz/feign/ScFeign.java @@ -7,7 +7,9 @@ import org.springframework.web.bind.annotation.RequestMapping; import org.springframework.web.bind.annotation.RequestMethod; import org.springframework.web.bind.annotation.RequestParam; +import java.util.HashMap; import java.util.List; +import java.util.Map; /** * @author chen @@ -17,6 +19,7 @@ import java.util.List; @FeignClient("smartCampusSearch") public interface ScFeign { + //考勤推送 @RequestMapping(value = "/sm/kq/getAllTemplate",method = RequestMethod.GET) List getAllTemplate(); @@ -29,9 +32,17 @@ public interface ScFeign { @RequestMapping(value = "/sm/kq/getApp",method = RequestMethod.GET) AppDto getApp(@RequestParam("schoolId")int schoolId , @RequestParam("type") int type); - @RequestMapping(value = "/sm/kq/getCensusKq",method = RequestMethod.POST) - List getCensusKq(@RequestBody KqDto kqDto); + @RequestMapping(value = "/sm/kq/getThirdId",method = RequestMethod.GET) + String getThirdId(@RequestParam("userId")String userId , @RequestParam("type") int type); - @RequestMapping(value = "/sm/kq/selectCensusChamberKq",method = RequestMethod.POST) - List selectCensusChamberKq(@RequestBody KqDto kqDto); + + //关注绑定推送 + @RequestMapping(value = "/sm/rp/selectBindPushSchool",method = RequestMethod.GET) + List selectBindPushSchool(); + + @RequestMapping(value = "/sm/rp/selectNotFollow",method = RequestMethod.GET) + List selectNotFollow(@RequestParam("schoolId") int schoolId); + + @RequestMapping(value = "/sm/rp/selectNotBind",method = RequestMethod.GET) + List selectNotBind(@RequestParam("schoolId") int schoolId , @RequestParam("type") int type); } diff --git a/cloud/quartz/src/main/java/com/sincere/quartz/job/BindPushJob.java b/cloud/quartz/src/main/java/com/sincere/quartz/job/BindPushJob.java new file mode 100644 index 0000000..9ca20b9 --- /dev/null +++ b/cloud/quartz/src/main/java/com/sincere/quartz/job/BindPushJob.java @@ -0,0 +1,91 @@ +package com.sincere.quartz.job; + +import com.sincere.common.dto.smartCampus.BindPushDto; +import com.sincere.common.dto.smartCampus.ParentDto; +import com.sincere.common.enums.PushTypeEnums; +import com.sincere.common.util.DateUtils; +import com.sincere.quartz.feign.ScFeign; +import org.apache.commons.lang3.StringUtils; +import org.springframework.beans.factory.annotation.Autowired; +import org.springframework.scheduling.annotation.Scheduled; +import org.springframework.stereotype.Service; + +import java.util.*; + +/** + * 用户注册激活提醒 + * @author chen + * @version 1.0 + * @date 2019/12/10 0010 8:31 + */ +@Service +public class BindPushJob { + + @Autowired + ScFeign scFeign; + + private static String date ; + private static List schoolList = new ArrayList<>(); + private static Map intervalDaysMap = new HashMap<>(); + + @Scheduled(cron = "0 0-59 * * * ? ") + public void bindPush(){ + Date nowDate = new Date(); + String now = DateUtils.date2String(nowDate,DateUtils.format1) ; + if(StringUtils.isBlank(date) || !date.equals(now)){ + initMap(now); + } + for(BindPushDto school : schoolList){ + int i =DateUtils.string2Date(school.getBeginDate(),DateUtils.format1).compareTo(nowDate) ; + int j = DateUtils.string2Date(school.getEndDate(),DateUtils.format1).compareTo(nowDate) ; + if(DateUtils.string2Date(school.getBeginDate(),DateUtils.format1).compareTo(nowDate) <= 0 + && DateUtils.string2Date(school.getEndDate(),DateUtils.format1).compareTo(nowDate) >= 0){ + String lastDate = intervalDaysMap.get(school.getSchoolId()); + if(StringUtils.isBlank(lastDate)){ + //下发推送 + bindPush(school,nowDate); + }else { + int day = DateUtils.getDateDifference(nowDate,DateUtils.string2Date(lastDate,DateUtils.format1),"day") ; + if(day == school.getIntervalDays() + 1) { + //下发推送 + bindPush(school,nowDate); + } + } + } + } + } + + private void bindPush(BindPushDto bindPushDto , Date nowDate){ + if(bindPushDto.getPushTime().equals(DateUtils.date2String(nowDate,DateUtils.format4))){ + List unFollowList = scFeign.selectNotFollow(bindPushDto.getSchoolId()); + + List unBindList =scFeign.selectNotBind(bindPushDto.getSchoolId(),getThirdType(bindPushDto.getType())); + + intervalDaysMap.put(bindPushDto.getSchoolId(),DateUtils.date2String(nowDate,DateUtils.format1)); + } + } + + private void initMap(String now){ + date = now ; + //schoolList = scFeign.selectBindPushSchool(); + BindPushDto bindPushDto = new BindPushDto(); + bindPushDto.setSchoolId(16); + bindPushDto.setBeginDate("2019-12-04"); + bindPushDto.setEndDate("2019-12-30"); + bindPushDto.setIntervalDays(1); + bindPushDto.setPushTime("11:04"); + bindPushDto.setType(0); + bindPushDto.setMsg(""); + schoolList = new ArrayList<>(); + schoolList.add(bindPushDto); + } + + private int getThirdType(int type){ + if(type == 0){ + return PushTypeEnums.DING.getType() ; + }else { + return PushTypeEnums.QIYEHAO.getType() ; + } + } + +} 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 282bdff..604788b 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 @@ -1,7 +1,11 @@ package com.sincere.quartz.job; +import com.alibaba.fastjson.JSONArray; +import com.alibaba.fastjson.JSONObject; import com.sincere.common.dto.smartCampus.*; +import com.sincere.common.enums.PushTypeEnums; import com.sincere.common.util.DateUtils; +import com.sincere.common.util.HttpClientUtils; import com.sincere.quartz.enums.KqTypeEnums; import com.sincere.quartz.enums.TypeEnums; import com.sincere.quartz.feign.ScFeign; @@ -38,7 +42,7 @@ public class KQJob { private static String date ; private static Map map = new HashMap<>(); - @Scheduled(cron = "* 0/1 * * * ?") + @Scheduled(cron = "0 0-59 * * * ? ") public void kaoQing() { String now = DateUtils.date2String(new Date(),DateUtils.format1) ; if(StringUtils.isBlank(date)){ @@ -54,14 +58,14 @@ public class KQJob { for(Map.Entry entity : map.entrySet()){ String endTime = entity.getValue().split("_")[1]; if(DateUtils.getDateDifference(new Date(),DateUtils.string2Date(now+" "+endTime+":00",DateUtils.format2),"m")>=2 - && DateUtils.getDateDifference(new Date(),DateUtils.string2Date(now+" "+endTime+":00",DateUtils.format2),"m") < 5){ + ){ String key = entity.getKey(); String[] messageArray = key.split("_"); - if(messageArray[2].contains("5")){ + if(messageArray[2].contains(PushTypeEnums.QIYEHAO.getType()+"")){ logger.info("企业号推送:" + messageArray[0] + "__" + messageArray[1]); - weChatBatchPush(messageArray[0],Integer.valueOf(messageArray[1]),entity.getValue()); + //weChatBatchPush(messageArray[0],Integer.valueOf(messageArray[1]),entity.getValue()); } - if(messageArray[2].contains("4")){ + if(messageArray[2].contains(PushTypeEnums.DING.getType()+"")){ logger.info(("盯盯推送:" + messageArray[0] + "__" + messageArray[1])); dingBatchPush(messageArray[0],Integer.valueOf(messageArray[1]),entity.getValue()); } @@ -73,6 +77,7 @@ public class KQJob { } } + //初始化要推送的模板 private void initMap(){ map = new HashMap<>(); List list = scFeign.getAllTemplate(); @@ -92,7 +97,7 @@ public class KQJob { int nowWeek = DateUtils.getWeek() ; if(Week.contains(nowWeek+"")){ logger.info((templateId+"_"+templateDto.getSchoolId()+"_"+templateDto.getType()+"------"+beginTime+"_"+endTime)); - map.put(templateId+"_"+templateDto.getSchoolId()+"_"+templateDto.getType() , beginTime+"_"+endTime+"_"+type); + map.put(templateId+"_"+templateDto.getSchoolId()+"_"+templateDto.getType() , beginTime+"_"+endTime+"_"+type+"_"+templateDto.getId()); } }catch (Exception e){ e.printStackTrace(); @@ -101,6 +106,7 @@ public class KQJob { } } + //盯盯批量推送 private void dingBatchPush(String templateId , int schoolId , String key){ String[] times = key.split("_"); AppDto appDto = scFeign.getApp(schoolId,1); @@ -116,17 +122,18 @@ public class KQJob { List list = scFeign.getTeacherList(schoolId); for(KqTeacherDto teacher : list){ logger.info("盯盯推送班主任—————" + templateId + "--------" + teacher.getName()); - dingSchoolPush(templateId,teacher, key, appDto); + //dingSchoolPush(templateId,teacher, key, appDto); } //推宿管 List chamberList = scFeign.selectChamberTeacher(schoolId); for(KqTeacherDto teacher : chamberList){ logger.info("盯盯推送宿管—————" + templateId + "--------" + teacher.getName()); - dingChamberPush(templateId,teacher, key, appDto); + //dingChamberPush(templateId,teacher, key, appDto); } } } + //企业号批量推送 private void weChatBatchPush(String templateId , int schoolId , String key){ String[] times = key.split("_"); AppDto appDto = scFeign.getApp(schoolId, 0); @@ -153,22 +160,17 @@ public class KQJob { } } + //盯盯推送班主任 private void dingSchoolPush(String templateId ,KqTeacherDto teacher , String key , AppDto appDto){ String[] times = key.split("_"); String tableSuffix = DateUtils.date2String(new Date(), DateUtils.format); - if(StringUtils.isNotBlank(teacher.getDingUserId())){ - KqDto dto = new KqDto(); - dto.setEndTime(times[1]); - dto.setTemplateId(templateId); - dto.setType(times[2]); - dto.setUserId(teacher.getUserId()); - List censusKqDtos = scFeign.getCensusKq(dto); + String thirdOpenId = scFeign.getThirdId(teacher.getUserId(),0); + if(StringUtils.isNotBlank(thirdOpenId)){ + List censusKqDtos = getCensus(Integer.valueOf(times[3]),templateId,teacher.getSchoolId(),teacher.getUserId(),1); if(censusKqDtos != null &&censusKqDtos.size() > 0){ String message = ""; for(CensusKqDto censusKqDto : censusKqDtos){ - int number = censusKqDto.getAllT() - censusKqDto.getKqT()-censusKqDto.getQjT() ; - number = number < 0?0:number ; - message += "[" + censusKqDto.getClassName() + "]未考勤" + number + "人,请假"+censusKqDto.getQjT()+"人;"; + message += "[" + censusKqDto.getTargetName() + "]未考勤" + censusKqDto.getNotAttendCount() + "人,请假"+censusKqDto.getLeaveCount()+"人;"; } DingSms dingSms = new DingSms(); dingSms.setName(teacher.getName()); @@ -179,36 +181,30 @@ 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="+teacher.getDingUserId()+"&type=1&stype=4&mobile="+teacher.getMobile()+"&pass="+teacher.getPass()+ + "&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(teacher.getDingUserId()); + dingSms.setDingUserId(thirdOpenId); dingSms.setAgentId(appDto.getAgentId()); dingSms.setWapUrl(wapUrl); dingSms.setReceiveUserId(teacher.getUserId()); dingSms.setTdType(TypeEnums.kaoqing.getType()); - smsMapper.insertDing(dingSms); + this.insertDing(dingSms); } } } + //盯盯推送宿管 private void dingChamberPush(String templateId, KqTeacherDto teacher , String key , AppDto appDto){ String[] times = key.split("_"); String tableSuffix = DateUtils.date2String(new Date(), DateUtils.format); - if(StringUtils.isNotBlank(teacher.getDingUserId())){ - List censusKqDtos ; - KqDto dto = new KqDto(); - dto.setEndTime(times[1]); - dto.setTemplateId(templateId); - dto.setType(times[2]); - dto.setUserId(teacher.getUserId()); - censusKqDtos = scFeign.selectCensusChamberKq(dto); + String thirdOpenId = scFeign.getThirdId(teacher.getUserId(),0); + if(StringUtils.isNotBlank(thirdOpenId)){ + List censusKqDtos = getCensus(Integer.valueOf(times[3]),templateId,teacher.getSchoolId(),teacher.getUserId(),1); if(censusKqDtos != null &&censusKqDtos.size() > 0){ String message = ""; for(CensusKqDto censusKqDto : censusKqDtos){ - int number = censusKqDto.getAllT() - censusKqDto.getKqT()-censusKqDto.getQjT() ; - number = number < 0?0:number ; - message += "[" + censusKqDto.getClassName() + "]未考勤" + number + "人,请假"+censusKqDto.getQjT()+"人;"; + message += "[" + censusKqDto.getTargetName() + "]未考勤" + censusKqDto.getNotAttendCount() + "人,请假"+censusKqDto.getLeaveCount()+"人;"; } DingSms dingSms = new DingSms(); dingSms.setName(teacher.getName()); @@ -221,32 +217,27 @@ public class KQJob { "schoolid=" + teacher.getSchoolId() + "&userId=" + teacher.getUserId() + "&name=" + teacher.getName() +"&TemplateId=" + templateId+ "&pass=" + teacher.getPass() + "&type=4&soutype=3&time="+DateUtils.date2String(new Date(),DateUtils.format1); dingSms.setSchoolId(teacher.getSchoolId()); - dingSms.setDingUserId(teacher.getDingUserId()); + dingSms.setDingUserId(thirdOpenId); dingSms.setAgentId(appDto.getAgentId()); dingSms.setWapUrl(msgUrl); dingSms.setReceiveUserId(teacher.getUserId()); dingSms.setTdType(TypeEnums.kaoqing.getType()); - smsMapper.insertDing(dingSms); + this.insertDing(dingSms); } } } + //企业号推送班主任 private void weChatSchoolPush(String templateId, KqTeacherDto teacher , String key , AppDto appDto){ String[] times = key.split("_"); String tableSuffix = DateUtils.date2String(new Date(), DateUtils.format); - if (StringUtils.isNotBlank(teacher.getOpenId())) { - KqDto dto = new KqDto(); - dto.setEndTime(times[1]); - dto.setTemplateId(templateId); - dto.setType(times[2]); - dto.setUserId(teacher.getUserId()); - List censusKqDtos = scFeign.getCensusKq(dto); + String thirdOpenId = scFeign.getThirdId(teacher.getUserId(),1); + if (StringUtils.isNotBlank(thirdOpenId)) { + List censusKqDtos = getCensus(Integer.valueOf(times[3]),templateId,teacher.getSchoolId(),teacher.getUserId(),1); if (censusKqDtos != null && censusKqDtos.size() > 0) { String message = ""; for (CensusKqDto censusKqDto : censusKqDtos) { - int number = censusKqDto.getAllT() - censusKqDto.getKqT()-censusKqDto.getQjT() ; - number = number < 0?0:number ; - message += "[" + censusKqDto.getClassName() + "]未考勤" + number + "人,请假"+censusKqDto.getQjT()+"人;"; + message += "[" + censusKqDto.getTargetName() + "]未考勤" + censusKqDto.getNotAttendCount() + "人,请假"+censusKqDto.getLeaveCount()+"人;"; } WeChatSms weChatSms = new WeChatSms(); weChatSms.setTableName("qyhSmsNew" + tableSuffix); @@ -256,38 +247,32 @@ public class KQJob { "整体数据:" + message); weChatSms.setSchoolId(teacher.getSchoolId()); weChatSms.setName(teacher.getName()); - weChatSms.setQiYeHaoUserId(teacher.getWeChatUserId()); + weChatSms.setQiYeHaoUserId(thirdOpenId); weChatSms.setReceiveUserId(teacher.getUserId()); weChatSms.setAppId(appDto.getAgentId()); weChatSms.setSecret(appDto.getAgentSecret()); String msgUrl = "http://campus.myjxt.com/studentRecord/znxwwebapp/index.html?" + "schoolid=" + teacher.getSchoolId() + "&userId=" + teacher.getUserId() + "&name=" + teacher.getName() +"&TemplateId=" + templateId+ - "&data=" + teacher.getWeChatUserId() + "&type=1&stype=3&mobile=" + teacher.getMobile() + "&pass=" + teacher.getPass() + + "&data=" + thirdOpenId + "&type=1&stype=3&mobile=" + teacher.getMobile() + "&pass=" + teacher.getPass() + "&face=" + teacher.getFace() + "&sourcetype=16&soutype=2×tamp=" + DateUtils.getDate()+"&time="+DateUtils.date2String(new Date(),DateUtils.format1)+"&"; weChatSms.setMsgUrl(msgUrl); weChatSms.setTdType(TypeEnums.kaoqing.getType()); - smsMapper.insertWeChat(weChatSms); + this.insertQYH(weChatSms); } } } + //企业号推送宿管 private void weChatChamberPush(String templateId, KqTeacherDto teacher , String key , AppDto appDto){ String[] times = key.split("_"); String tableSuffix = DateUtils.date2String(new Date(), DateUtils.format); - if (StringUtils.isNotBlank(teacher.getOpenId())) { - List censusKqDtos ; - KqDto dto = new KqDto(); - dto.setEndTime(times[1]); - dto.setTemplateId(templateId); - dto.setType(times[2]); - dto.setUserId(teacher.getUserId()); - censusKqDtos = scFeign.selectCensusChamberKq(dto); + String thirdOpenId = scFeign.getThirdId(teacher.getUserId(),1); + if (StringUtils.isNotBlank(thirdOpenId)) { + List censusKqDtos = getCensus(Integer.valueOf(times[3]),templateId,teacher.getSchoolId(),teacher.getUserId(),1); if (censusKqDtos != null && censusKqDtos.size() > 0) { String message = ""; for (CensusKqDto censusKqDto : censusKqDtos) { - int number = censusKqDto.getAllT() - censusKqDto.getKqT()-censusKqDto.getQjT() ; - number = number < 0?0:number ; - message += "[" + censusKqDto.getClassName() + "]未考勤" + number + "人,请假"+censusKqDto.getQjT()+"人;"; + message += "[" + censusKqDto.getTargetName() + "]未考勤" + censusKqDto.getNotAttendCount() + "人,请假"+censusKqDto.getLeaveCount()+"人;"; } WeChatSms weChatSms = new WeChatSms(); weChatSms.setTableName("qyhSmsNew" + tableSuffix); @@ -297,7 +282,7 @@ public class KQJob { "整体数据:" + message); weChatSms.setSchoolId(teacher.getSchoolId()); weChatSms.setName(teacher.getName()); - weChatSms.setQiYeHaoUserId(teacher.getWeChatUserId()); + weChatSms.setQiYeHaoUserId(thirdOpenId); weChatSms.setReceiveUserId(teacher.getUserId()); weChatSms.setAppId(appDto.getAgentId()); weChatSms.setSecret(appDto.getAgentSecret()); @@ -306,8 +291,46 @@ public class KQJob { "&pass=" + teacher.getPass() + "&type=4&soutype=2&time="+DateUtils.date2String(new Date(),DateUtils.format1)+"&"; weChatSms.setMsgUrl(msgUrl); weChatSms.setTdType(TypeEnums.kaoqing.getType()); - smsMapper.insertWeChat(weChatSms); + this.insertQYH(weChatSms); } } } + + //type 0 出入校 1 出入寝 + private List getCensus(int id , String templateId ,int schoolId , String userId ,int type){ + List list = new ArrayList<>(); + CensusKqDto censusKqDto = new CensusKqDto(); + String url = "http://campus.myjxt.com/api/EasyN/GeAttendDetailNew?schoolId="+schoolId+ + "&id="+id+"&templateID="+templateId+"&type="+type+"&userId="+userId+"&time=" + DateUtils.date2String(new Date(),DateUtils.format1); + JSONObject jsonObject = HttpClientUtils.httpGet(url); + try{ + JSONArray data = (JSONArray)jsonObject.get("data"); + for(int i = 0 ; i < data.size() ; i++){ + JSONObject object = data.getJSONObject(i); + censusKqDto.setLeaveCount((Integer) object.get("leaveCount")); + censusKqDto.setNotAttendCount((Integer) object.get("noAttendCount")); + censusKqDto.setTargetName((String)object.get("name")); + } + list.add(censusKqDto); + }catch (Exception e){ + + } + return list ; + } + + private void insertDing(DingSms dingSms){ + try{ + smsMapper.insertDing(dingSms); + }catch (Exception e){ + logger.info(e.toString()); + } + } + + private void insertQYH(WeChatSms weChatSms){ + try{ + smsMapper.insertWeChat(weChatSms); + }catch (Exception e){ + logger.info(e.toString()); + } + } } diff --git a/cloud/search_smartCampus/src/main/java/com/sincere/smartSearch/controller/KqController.java b/cloud/search_smartCampus/src/main/java/com/sincere/smartSearch/controller/KqController.java index da913d6..24f9ce3 100644 --- a/cloud/search_smartCampus/src/main/java/com/sincere/smartSearch/controller/KqController.java +++ b/cloud/search_smartCampus/src/main/java/com/sincere/smartSearch/controller/KqController.java @@ -27,6 +27,7 @@ public class KqController { List templateDtos = new ArrayList<>(); for(KqTemplate kqTemplate : list){ TemplateDto templateDto = new TemplateDto(); + templateDto.setId(kqTemplate.getId()); templateDto.setConfig(kqTemplate.getConfig()); templateDto.setSchoolId(kqTemplate.getSchoolId()); templateDto.setType(kqTemplate.getType()); @@ -54,13 +55,11 @@ public class KqController { return kqService.selectApp(map); } - @RequestMapping(value = "getCensusKq",method = RequestMethod.POST) - public List getCensusKq(@RequestBody KqDto kqDto){ - return kqService.selectCensusKq(kqDto); - } - - @RequestMapping(value = "selectCensusChamberKq",method = RequestMethod.POST) - public List selectCensusChamberKq(@RequestBody KqDto kqDto){ - return kqService.selectCensusChamberKq(kqDto); + @RequestMapping(value = "getThirdId",method = RequestMethod.GET) + public String getThirdId(@RequestParam("userId")String userId , @RequestParam("type") int type){ + Map map = new HashMap<>(); + map.put("userId",userId); + map.put("type",type+""); + return kqService.selectThirdId(map); } } diff --git a/cloud/search_smartCampus/src/main/java/com/sincere/smartSearch/controller/RegisterPushController.java b/cloud/search_smartCampus/src/main/java/com/sincere/smartSearch/controller/RegisterPushController.java new file mode 100644 index 0000000..20d2fea --- /dev/null +++ b/cloud/search_smartCampus/src/main/java/com/sincere/smartSearch/controller/RegisterPushController.java @@ -0,0 +1,50 @@ +package com.sincere.smartSearch.controller; + +import com.sincere.common.dto.smartCampus.BindPushDto; +import com.sincere.common.dto.smartCampus.ParentDto; +import com.sincere.smartSearch.service.RegisterPushService; +import org.springframework.beans.factory.annotation.Autowired; +import org.springframework.web.bind.annotation.RequestMapping; +import org.springframework.web.bind.annotation.RequestMethod; +import org.springframework.web.bind.annotation.RequestParam; +import org.springframework.web.bind.annotation.RestController; + +import java.util.HashMap; +import java.util.List; +import java.util.Map; + +/** + * @author chen + * @version 1.0 + * @date 2019/12/10 0010 11:20 + */ +@RestController +@RequestMapping("/sm/rp") +public class RegisterPushController { + + @Autowired + RegisterPushService registerPushService ; + + @RequestMapping(value = "selectBindPushSchool",method = RequestMethod.GET) + List selectBindPushSchool(){ + return registerPushService.selectBindPushSchool(); + } + + @RequestMapping(value = "selectNotFollow",method = RequestMethod.GET) + List selectNotFollow(@RequestParam("schoolId") int schoolId){ + return registerPushService.selectNotFollow(schoolId); + } + + @RequestMapping(value = "selectFollow",method = RequestMethod.GET) + List selectFollow(@RequestParam("schoolId") int schoolId){ + return registerPushService.selectFollow(schoolId); + } + + @RequestMapping(value = "selectNotBind",method = RequestMethod.GET) + List selectNotBind(@RequestParam("schoolId") int schoolId , @RequestParam("type") int type){ + Map map = new HashMap<>(); + map.put("schoolId",schoolId); + map.put("type",type); + return registerPushService.selectNotBind(map); + } +} diff --git a/cloud/search_smartCampus/src/main/java/com/sincere/smartSearch/mapper/KqTemplateMapper.java b/cloud/search_smartCampus/src/main/java/com/sincere/smartSearch/mapper/KqTemplateMapper.java index 3121ce7..4a00d7d 100644 --- a/cloud/search_smartCampus/src/main/java/com/sincere/smartSearch/mapper/KqTemplateMapper.java +++ b/cloud/search_smartCampus/src/main/java/com/sincere/smartSearch/mapper/KqTemplateMapper.java @@ -24,25 +24,6 @@ public interface KqTemplateMapper { AppDto selectApp(Map map); - List selectCensusKq(Map map); + String selectThirdId(Map map); - List selectChamberName(String userId); - - int selectChamberAllKq(Map map); - - int selectChamberTrueKq(Map map); - - int selectClassDealDateCHUQIN(Map map); - - int selectClassDealDateQINGJIA(Map map); - - int selectClassLeave(Map map); - - int selectChamberDealDateCHUQIN(Map map); - - int selectChamberDealDateQINGJIA(Map map); - - int selectChamberLeave(Map map); - - int selectClassChamberNumber(int classId); } diff --git a/cloud/search_smartCampus/src/main/java/com/sincere/smartSearch/mapper/RegisterPushMapper.java b/cloud/search_smartCampus/src/main/java/com/sincere/smartSearch/mapper/RegisterPushMapper.java new file mode 100644 index 0000000..5d6004f --- /dev/null +++ b/cloud/search_smartCampus/src/main/java/com/sincere/smartSearch/mapper/RegisterPushMapper.java @@ -0,0 +1,23 @@ +package com.sincere.smartSearch.mapper; + +import com.sincere.common.dto.smartCampus.BindPushDto; +import com.sincere.common.dto.smartCampus.ParentDto; + +import java.util.List; +import java.util.Map; + +/** + * @author chen + * @version 1.0 + * @date 2019/12/10 0010 10:26 + */ +public interface RegisterPushMapper { + + List selectBindPushSchool(); + + List selectNotFollow(int schoolId) ; + + List selectFollow(int schoolId) ; + + List selectNotBind(Map map); +} diff --git a/cloud/search_smartCampus/src/main/java/com/sincere/smartSearch/model/KqTemplate.java b/cloud/search_smartCampus/src/main/java/com/sincere/smartSearch/model/KqTemplate.java index ff7f76e..f61713d 100644 --- a/cloud/search_smartCampus/src/main/java/com/sincere/smartSearch/model/KqTemplate.java +++ b/cloud/search_smartCampus/src/main/java/com/sincere/smartSearch/model/KqTemplate.java @@ -7,10 +7,19 @@ package com.sincere.smartSearch.model; */ public class KqTemplate { + private int id ; private String config ; private int schoolId ; private String type ; + public int getId() { + return id; + } + + public void setId(int id) { + this.id = id; + } + public String getConfig() { return config; } diff --git a/cloud/search_smartCampus/src/main/java/com/sincere/smartSearch/service/KqService.java b/cloud/search_smartCampus/src/main/java/com/sincere/smartSearch/service/KqService.java index 002219d..47f6690 100644 --- a/cloud/search_smartCampus/src/main/java/com/sincere/smartSearch/service/KqService.java +++ b/cloud/search_smartCampus/src/main/java/com/sincere/smartSearch/service/KqService.java @@ -24,7 +24,5 @@ public interface KqService { AppDto selectApp(Map map); - List selectCensusKq(KqDto kqDto); - - List selectCensusChamberKq(KqDto kqDto); + String selectThirdId(Map map); } diff --git a/cloud/search_smartCampus/src/main/java/com/sincere/smartSearch/service/RegisterPushService.java b/cloud/search_smartCampus/src/main/java/com/sincere/smartSearch/service/RegisterPushService.java new file mode 100644 index 0000000..85f411e --- /dev/null +++ b/cloud/search_smartCampus/src/main/java/com/sincere/smartSearch/service/RegisterPushService.java @@ -0,0 +1,23 @@ +package com.sincere.smartSearch.service; + +import com.sincere.common.dto.smartCampus.BindPushDto; +import com.sincere.common.dto.smartCampus.ParentDto; + +import java.util.List; +import java.util.Map; + +/** + * @author chen + * @version 1.0 + * @date 2019/12/10 0010 11:17 + */ +public interface RegisterPushService { + + List selectBindPushSchool(); + + List selectNotFollow(int schoolId) ; + + List selectFollow(int schoolId) ; + + List selectNotBind(Map map); +} diff --git a/cloud/search_smartCampus/src/main/java/com/sincere/smartSearch/service/impl/KqServiceImpl.java b/cloud/search_smartCampus/src/main/java/com/sincere/smartSearch/service/impl/KqServiceImpl.java index 122ccdf..119e5db 100644 --- a/cloud/search_smartCampus/src/main/java/com/sincere/smartSearch/service/impl/KqServiceImpl.java +++ b/cloud/search_smartCampus/src/main/java/com/sincere/smartSearch/service/impl/KqServiceImpl.java @@ -46,62 +46,7 @@ public class KqServiceImpl implements KqService { } @Override - public List selectCensusKq(KqDto kqDto) { - String tableSuffix = DateUtils.date2String(new Date(), DateUtils.format); - Map map = new HashMap<>(); - map.put("userId",kqDto.getUserId()); - map.put("tableName","SZ_AttendanceRecords"+tableSuffix); - map.put("type",kqDto.getType()); - List list = kqTemplateMapper.selectCensusKq(map); - for(CensusKqDto censusKqDto : list){ - if(Integer.valueOf(kqDto.getType()) >= 7){ - //出入寝 - int classNumber = kqTemplateMapper.selectClassChamberNumber(censusKqDto.getClassId()); - censusKqDto.setAllT(classNumber); - } - Map sqlMap = new HashMap<>(); - sqlMap.put("templateId",kqDto.getTemplateId()); - sqlMap.put("classId",censusKqDto.getClassId()+""); - int chuqin = kqTemplateMapper.selectClassDealDateCHUQIN(sqlMap); - int qingjia = kqTemplateMapper.selectClassDealDateQINGJIA(sqlMap); - String date = DateUtils.date2String(new Date(),DateUtils.format1); - sqlMap.put("endTime",date+" " + kqDto.getEndTime() +":00"); - qingjia = qingjia + kqTemplateMapper.selectClassLeave(sqlMap); - censusKqDto.setKqT(censusKqDto.getKqT()+chuqin); - censusKqDto.setQjT(qingjia); - } - return list ; - } - - @Override - public List selectCensusChamberKq(KqDto kqDto) { - String tableSuffix = DateUtils.date2String(new Date(), DateUtils.format); - Map map = new HashMap<>(); - map.put("userId",kqDto.getUserId()); - map.put("tableName","SZ_AttendanceRecords"+tableSuffix); - map.put("type",kqDto.getType()); - List list = new ArrayList<>(); - List chambers = kqTemplateMapper.selectChamberName(map.get("userId")); - for(KqChamber chamber :chambers){ - CensusKqDto censusKqDto = new CensusKqDto(); - map.put("id",chamber.getId()+""); - int allKq = kqTemplateMapper.selectChamberAllKq(map); - int trueKq = kqTemplateMapper.selectChamberTrueKq(map); - censusKqDto.setClassName(chamber.getName()); - censusKqDto.setAllT(allKq); - Map sqlMap = new HashMap<>(); - sqlMap.put("templateId",kqDto.getTemplateId()); - sqlMap.put("userId",kqDto.getUserId()); - sqlMap.put("id",chamber.getId()+""); - int chuqin = kqTemplateMapper.selectChamberDealDateCHUQIN(sqlMap); - int qingjia = kqTemplateMapper.selectChamberDealDateQINGJIA(sqlMap); - String date = DateUtils.date2String(new Date(),DateUtils.format1); - sqlMap.put("endTime",date+" " + kqDto.getEndTime() +":00"); - qingjia = qingjia + kqTemplateMapper.selectChamberLeave(sqlMap); - censusKqDto.setKqT(trueKq+chuqin); - censusKqDto.setKqT(qingjia); - list.add(censusKqDto); - } - return list; + public String selectThirdId(Map map) { + return kqTemplateMapper.selectThirdId(map); } } diff --git a/cloud/search_smartCampus/src/main/java/com/sincere/smartSearch/service/impl/RegisterPushServiceImpl.java b/cloud/search_smartCampus/src/main/java/com/sincere/smartSearch/service/impl/RegisterPushServiceImpl.java new file mode 100644 index 0000000..579a290 --- /dev/null +++ b/cloud/search_smartCampus/src/main/java/com/sincere/smartSearch/service/impl/RegisterPushServiceImpl.java @@ -0,0 +1,43 @@ +package com.sincere.smartSearch.service.impl; + +import com.sincere.common.dto.smartCampus.BindPushDto; +import com.sincere.common.dto.smartCampus.ParentDto; +import com.sincere.smartSearch.mapper.RegisterPushMapper; +import com.sincere.smartSearch.service.RegisterPushService; +import org.springframework.beans.factory.annotation.Autowired; +import org.springframework.stereotype.Service; + +import java.util.List; +import java.util.Map; + +/** + * @author chen + * @version 1.0 + * @date 2019/12/10 0010 11:18 + */ +@Service +public class RegisterPushServiceImpl implements RegisterPushService { + + @Autowired + RegisterPushMapper registerPushMapper ; + + @Override + public List selectBindPushSchool() { + return registerPushMapper.selectBindPushSchool(); + } + + @Override + public List selectNotFollow(int schoolId) { + return registerPushMapper.selectNotFollow(schoolId); + } + + @Override + public List selectFollow(int schoolId) { + return registerPushMapper.selectFollow(schoolId); + } + + @Override + public List selectNotBind(Map map) { + return registerPushMapper.selectNotBind(map); + } +} diff --git a/cloud/search_smartCampus/src/main/resources/mapper/KqTemplateMapper.xml b/cloud/search_smartCampus/src/main/resources/mapper/KqTemplateMapper.xml index 27c21ea..0ea3b64 100644 --- a/cloud/search_smartCampus/src/main/resources/mapper/KqTemplateMapper.xml +++ b/cloud/search_smartCampus/src/main/resources/mapper/KqTemplateMapper.xml @@ -3,13 +3,14 @@ + - select distinct a.user_id,a.school_id,a.name,a.mobile,a.face,a.pass, a.OpenId,a.QiYeHaoUserId,a.DingUserId + select distinct a.user_id,a.school_id,a.name,a.mobile,a.face,a.pass, a.OpenId from SZ_V_School_Teacher a inner join SZ_Class b on a.class_id=b.class_id and b.state=1 and b.is_finish=0 join SZ_UserRole on a.user_id = SZ_UserRole.user_id @@ -37,7 +36,7 @@ - - - - - - - - - - - - - - - - - - - - + select DQuserId from EM_QyDingUser where HxyUserId = #{userId} and State = 1 and QyType = #{type} - - - - - - - - - - - - diff --git a/cloud/search_smartCampus/src/main/resources/mapper/RegisterPushMapper.xml b/cloud/search_smartCampus/src/main/resources/mapper/RegisterPushMapper.xml new file mode 100644 index 0000000..3faa5b1 --- /dev/null +++ b/cloud/search_smartCampus/src/main/resources/mapper/RegisterPushMapper.xml @@ -0,0 +1,61 @@ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + \ No newline at end of file diff --git a/cloud/weigeng/pom.xml b/cloud/weigeng/pom.xml index 170adb1..e18ef3c 100644 --- a/cloud/weigeng/pom.xml +++ b/cloud/weigeng/pom.xml @@ -20,16 +20,16 @@ + io.netty + netty-all + 4.1.33.Final + + com.sincere common 1.0.0 - org.apache.mina - mina-core - 2.1.3 - - org.apache.poi poi 4.1.0 diff --git a/cloud/weigeng/src/main/java/com/sincere/weigeng/Watch1200.java b/cloud/weigeng/src/main/java/com/sincere/weigeng/Watch1200.java new file mode 100644 index 0000000..821ee25 --- /dev/null +++ b/cloud/weigeng/src/main/java/com/sincere/weigeng/Watch1200.java @@ -0,0 +1,61 @@ +package com.sincere.weigeng; + +import com.sincere.weigeng.feign.SmFeign; +import com.sincere.weigeng.feign.XaFeign; +import com.sincere.weigeng.utils.WatchServer; +import org.springframework.beans.factory.annotation.Autowired; +import org.springframework.boot.ApplicationArguments; +import org.springframework.boot.ApplicationRunner; +import org.springframework.stereotype.Component; + +/** + * @author chen + * @version 1.0 + * @date 2019/12/3 0003 11:42 + */ +@Component +public class Watch1200 extends WatchServer implements ApplicationRunner { + + @Autowired + SmFeign smFeign ; + + @Autowired + XaFeign xaFeign; + + @Override + public void run(ApplicationArguments args) throws Exception { + watchPort(1200); + Listen1200 listen1200 = new Listen1200(this); + listen1200.start(); + } + + class Listen1200 extends Thread{ + + private Watch1200 watch1200 ; + + public Watch1200 getWatch1200() { + return watch1200; + } + + public void setWatch1200(Watch1200 watch1200) { + this.watch1200 = watch1200; + } + + + public Listen1200(Watch1200 watch1200) { + this.watch1200 = watch1200; + } + + @Override + public synchronized void start() { + super.start(); + } + + @Override + public void run() { + super.run(); + this.watch1200.listen(smFeign,xaFeign); + } + } + +} diff --git a/cloud/weigeng/src/main/java/com/sincere/weigeng/Watch1300.java b/cloud/weigeng/src/main/java/com/sincere/weigeng/Watch1300.java new file mode 100644 index 0000000..2c61f46 --- /dev/null +++ b/cloud/weigeng/src/main/java/com/sincere/weigeng/Watch1300.java @@ -0,0 +1,61 @@ +package com.sincere.weigeng; + +import com.sincere.weigeng.feign.SmFeign; +import com.sincere.weigeng.feign.XaFeign; +import com.sincere.weigeng.utils.WatchServer; +import org.springframework.beans.factory.annotation.Autowired; +import org.springframework.boot.ApplicationArguments; +import org.springframework.boot.ApplicationRunner; +import org.springframework.stereotype.Component; + +/** + * @author chen + * @version 1.0 + * @date 2019/12/3 0003 11:42 + */ +@Component +public class Watch1300 extends WatchServer implements ApplicationRunner { + + @Autowired + SmFeign smFeign ; + + @Autowired + XaFeign xaFeign; + + @Override + public void run(ApplicationArguments args) throws Exception { + watchPort(1300); + Listen1300 listen1300 = new Listen1300(this); + listen1300.start(); + } + + class Listen1300 extends Thread{ + + private Watch1300 watch1300 ; + + public Watch1300 getWatch1300() { + return watch1300; + } + + public void setWatch1300(Watch1300 watch1300) { + this.watch1300 = watch1300; + } + + + public Listen1300(Watch1300 watch1300) { + this.watch1300 = watch1300; + } + + @Override + public synchronized void start() { + super.start(); + } + + @Override + public void run() { + super.run(); + this.watch1300.listen(smFeign,xaFeign); + } + } + +} diff --git a/cloud/weigeng/src/main/java/com/sincere/weigeng/WeigengApplication.java b/cloud/weigeng/src/main/java/com/sincere/weigeng/WeigengApplication.java index d831577..1539ad5 100644 --- a/cloud/weigeng/src/main/java/com/sincere/weigeng/WeigengApplication.java +++ b/cloud/weigeng/src/main/java/com/sincere/weigeng/WeigengApplication.java @@ -1,6 +1,5 @@ package com.sincere.weigeng; -import com.sincere.weigeng.utils.WatchServer; import org.springframework.boot.SpringApplication; import org.springframework.boot.autoconfigure.SpringBootApplication; import org.springframework.cloud.netflix.eureka.EnableEurekaClient; @@ -11,12 +10,8 @@ import org.springframework.cloud.openfeign.EnableFeignClients; @SpringBootApplication public class WeigengApplication { - private static String ip = "172.16.3.175"; - private static int port = 1200; - public static void main(String[] args) { SpringApplication.run(WeigengApplication.class, args); - //WatchServer.WatchingServerRunning(ip,port); } } diff --git a/cloud/weigeng/src/main/java/com/sincere/weigeng/controller/WgController.java b/cloud/weigeng/src/main/java/com/sincere/weigeng/controller/WgController.java index 6386ddc..153ba6c 100644 --- a/cloud/weigeng/src/main/java/com/sincere/weigeng/controller/WgController.java +++ b/cloud/weigeng/src/main/java/com/sincere/weigeng/controller/WgController.java @@ -7,12 +7,16 @@ import com.sincere.common.dto.smartCampus.UserDto; import com.sincere.common.dto.xiaoan.SendFailDto; import com.sincere.common.dto.xiaoan.SendMessageDto; import com.sincere.common.dto.xiaoan.SendSuccessDto; +import com.sincere.weigeng.Watch1200; +import com.sincere.weigeng.Watch1300; import com.sincere.weigeng.feign.SmFeign; import com.sincere.weigeng.feign.XaFeign; import com.sincere.weigeng.logs.LogName; import com.sincere.weigeng.logs.LoggerUtils; import com.sincere.weigeng.utils.WatchServer; import com.sincere.weigeng.vo.*; +import io.netty.channel.ChannelHandlerContext; +import io.netty.channel.socket.DatagramPacket; import io.swagger.annotations.Api; import io.swagger.annotations.ApiOperation; import org.slf4j.Logger; @@ -42,39 +46,76 @@ public class WgController { @Autowired XaFeign xaFeign; - private static String ip = "172.16.3.175"; - private static int port = 1200; + @Autowired + Watch1200 watch1200 ; + + @Autowired + Watch1300 watch1300 ; - @RequestMapping(value = "watching" , method = RequestMethod.GET) - public void watching(){ - WatchServer.WatchingServerRunning(ip,port,smFeign,xaFeign); + public ChannelHandlerContext getContext(long sno){ + ChannelHandlerContext context1200 = watch1200.getContext(sno) ; + ChannelHandlerContext context1300 = watch1300.getContext(sno) ; + if(context1200 == null){ + return context1300; + }else { + return context1200 ; + } + } + + public DatagramPacket getPacket(long sno){ + DatagramPacket packet1200 = watch1200.getPacket(sno); + DatagramPacket packet1300 = watch1300.getPacket(sno); + if(packet1200 == null){ + return packet1300 ; + }else { + return packet1200 ; + } + } + + @RequestMapping(value = "openDoor1" , method = RequestMethod.GET) + public void openDoor1(){ + OpenDoorVo openDoorVo = new OpenDoorVo(); + openDoorVo.setId(1); + openDoorVo.setSn(253163272); + openDoorVo.setType(1); + openDoorVo.setDoorNo(1); + this.openDoor(openDoorVo); + } + + @RequestMapping(value = "openDoor2" , method = RequestMethod.GET) + public void openDoor2(){ + OpenDoorVo openDoorVo = new OpenDoorVo(); + openDoorVo.setId(1); + openDoorVo.setSn(253160793); + openDoorVo.setType(1); + openDoorVo.setDoorNo(1); + this.openDoor(openDoorVo); } @RequestMapping(value = "setTime" , method = RequestMethod.GET) public void setTime(long sn){ - WatchServer.setTime(xaFeign,sn,"48"); + WatchServer.setTime(xaFeign,getContext(sn),getPacket(sn),sn,"48"); } @ApiOperation("远程开门") @RequestMapping(value = "openDoor" , method = RequestMethod.POST) public boolean openDoor(@RequestBody OpenDoorVo openDoorVo) { String functionId = smFeign.selectOutOrderId(openDoorVo.getType(),openDoorVo.getId()); - long messageId = WatchServer.openDoor(xaFeign,openDoorVo.getSn(),functionId,openDoorVo.getDoorNo(),null); + long messageId = WatchServer.openDoor(xaFeign,getContext(openDoorVo.getSn()),getPacket(openDoorVo.getSn()),openDoorVo.getSn(),functionId,openDoorVo.getDoorNo(),null); SendMessageDto message = getResult(messageId); if(message.getCorrect() == 1){ - Log_orderSuccess.info("web端远程开门成功!"); + Log_orderSuccess.info("web端远程开门成功!") ; }else { - Log_orderFail.info("远程开门失败"); + Log_orderFail.info("远程开门失败") ; } return message.getCorrect() == 1 ; } - @ApiOperation("设置考勤时段") @RequestMapping(value = "setAttendanceTime" , method = RequestMethod.POST) public boolean setAttendanceTime(@RequestBody AttendanceTimeVo attendanceTimeVo){ String functionId = smFeign.selectOutOrderId(attendanceTimeVo.getType(),attendanceTimeVo.getId()); - List result = WatchServer.SetAttendanceTime(xaFeign,attendanceTimeVo.getSn(),functionId,attendanceTimeVo.getShiduan(), + List result = WatchServer.SetAttendanceTime(xaFeign,getContext(attendanceTimeVo.getSn()),getPacket(attendanceTimeVo.getSn()),attendanceTimeVo.getSn(),functionId,attendanceTimeVo.getShiduan(), attendanceTimeVo.getStart(),attendanceTimeVo.getEnd(),attendanceTimeVo.getIsMonday(),attendanceTimeVo.getIsTuesday(), attendanceTimeVo.getIsWednesday(),attendanceTimeVo.getIsThursday(),attendanceTimeVo.getIsFriday(), attendanceTimeVo.getIsSaturday(),attendanceTimeVo.getIsWeekend(),attendanceTimeVo.getShiqu()); @@ -91,13 +132,12 @@ public class WgController { return isSuccess; } - @ApiOperation("单个卡号的权限添加或修改") @RequestMapping(value = "setSignalCardInfo" , method = RequestMethod.POST) public boolean setSignalCardInfo(@RequestBody SignalCardInfoVo signalCardInfoVo){ String functionId = smFeign.selectOutOrderId(signalCardInfoVo.getType(),signalCardInfoVo.getId()); String cardNo = initCardNo(signalCardInfoVo.getCardNo()); - long messageId = WatchServer.SetSignalCardInfo(xaFeign,signalCardInfoVo.getSn(),functionId,cardNo, + long messageId = WatchServer.SetSignalCardInfo(xaFeign,getContext(signalCardInfoVo.getSn()),getPacket(signalCardInfoVo.getSn()),signalCardInfoVo.getSn(),functionId,cardNo, signalCardInfoVo.getShiduan(),signalCardInfoVo.getStartTime(),signalCardInfoVo.getEndTime()); SendMessageDto message = getResult(messageId); UserDto user = smFeign.selectUserByCardNum(cardNo); @@ -136,7 +176,7 @@ public class WgController { public boolean clearSinglePower(@RequestBody CardInfo cardInfo){ String functionId = smFeign.selectOutOrderId(cardInfo.getType(),cardInfo.getId()); String cardNo = initCardNo(cardInfo.getCardNo()); - long messageId = WatchServer.clearSinglePower(xaFeign,cardInfo.getSn(),functionId,cardNo); + long messageId = WatchServer.clearSinglePower(xaFeign,getContext(cardInfo.getSn()),getPacket(cardInfo.getSn()),cardInfo.getSn(),functionId,cardNo); SendMessageDto message = getResult(messageId); if(message.getCorrect() == 1){ Log_orderSuccess.info("卡号"+cardNo+"清除权限成功"); @@ -154,7 +194,7 @@ public class WgController { @RequestMapping(value = "clearAllPower" , method = RequestMethod.POST) public boolean clearAllPower(@RequestBody CleanShiDuanVo cleanShiDuanVo){ String functionId = smFeign.selectOutOrderId(cleanShiDuanVo.getType(),cleanShiDuanVo.getId()); - long messageId = WatchServer.clearAllPower(xaFeign,cleanShiDuanVo.getSn(),functionId); + long messageId = WatchServer.clearAllPower(xaFeign,getContext(cleanShiDuanVo.getSn()),getPacket(cleanShiDuanVo.getSn()),cleanShiDuanVo.getSn(),functionId); SendMessageDto message = getResult(messageId); if(message.getCorrect() == 1){ Log_orderSuccess.info("设备"+cleanShiDuanVo.getSn()+"清除权限成功"); @@ -172,7 +212,7 @@ public class WgController { @RequestMapping(value = "clearShiDuan" , method = RequestMethod.POST) public boolean clearShiDuan(@RequestBody CleanShiDuanVo cleanShiDuanVo){ String functionId = smFeign.selectOutOrderId(cleanShiDuanVo.getType(),cleanShiDuanVo.getId()); - long messageId = WatchServer.clearShiDuan(xaFeign,cleanShiDuanVo.getSn(),functionId); + long messageId = WatchServer.clearShiDuan(xaFeign,getContext(cleanShiDuanVo.getSn()),getPacket(cleanShiDuanVo.getSn()),cleanShiDuanVo.getSn(),functionId); SendMessageDto sendMessage = getResult(messageId); if(sendMessage.getCorrect() == 1){ Log_orderSuccess.info("设备"+cleanShiDuanVo.getSn()+"时段清除成功"); @@ -187,7 +227,7 @@ public class WgController { public boolean searchPower(@RequestBody CardInfo cardInfo){ String functionId = smFeign.selectOutOrderId(cardInfo.getType(),cardInfo.getId()); String cardNo = initCardNo(cardInfo.getCardNo()); - long messageId = WatchServer.searchPower(xaFeign,cardInfo.getSn(),functionId,cardNo); + long messageId = WatchServer.searchPower(xaFeign,getContext(cardInfo.getSn()),getPacket(cardInfo.getSn()),cardInfo.getSn(),functionId,cardNo); SendMessageDto sendMessage = getResult(messageId); if(sendMessage.getCorrect() == 1){ Log_orderSuccess.info("设备"+cardInfo.getSn()+"卡号"+cardNo+"查询权限成功"); diff --git a/cloud/weigeng/src/main/java/com/sincere/weigeng/utils/UdpServerHandler.java b/cloud/weigeng/src/main/java/com/sincere/weigeng/utils/UdpServerHandler.java new file mode 100644 index 0000000..17afb5c --- /dev/null +++ b/cloud/weigeng/src/main/java/com/sincere/weigeng/utils/UdpServerHandler.java @@ -0,0 +1,68 @@ +package com.sincere.weigeng.utils; + +import com.sincere.common.util.DateUtils; +import com.sincere.weigeng.logs.LogName; +import com.sincere.weigeng.logs.LoggerUtils; +import io.netty.buffer.ByteBuf; +import io.netty.channel.ChannelHandlerContext; +import io.netty.channel.SimpleChannelInboundHandler; +import io.netty.channel.socket.DatagramPacket; +import io.netty.util.ReferenceCountUtil; +import org.slf4j.Logger; + +import java.util.Date; +import java.util.Map; +import java.util.Queue; + +/** + * @author chen + * @version 1.0 + * @date 2019/11/21 0021 9:18 + */ +public class UdpServerHandler extends SimpleChannelInboundHandler { + + private static Logger Log_error = LoggerUtils.Logger(LogName.error); + private static Logger Log_heartBeat = LoggerUtils.Logger(LogName.heartBeat); + + private String dateTime = "" ; + private int i = 0 ; + + private Queue queue; + private Map channelMap ; + private Map packetMap ; + + public UdpServerHandler(Queue queue , Map channelMap , Map packetMap) { + super(); + this.queue = queue; + this.channelMap = channelMap; + this.packetMap = packetMap ; + } + + + @Override + protected void channelRead0(ChannelHandlerContext ctx, DatagramPacket packet){ + try{ + i++ ; + String time = DateUtils.date2String(new Date() , DateUtils.format3); + if(!dateTime.equals(time)){ + Log_heartBeat.info("------------------------"+packet.recipient().getPort()+"访问次数" + i); + dateTime = time ; + i = 1 ; + } + ByteBuf buf = packet.copy().content(); + byte[] validBytes = new byte[buf.readableBytes()]; + buf.readBytes(validBytes); + if (validBytes.length == WgUdpCommShort.WGPacketSize) { + synchronized (queue) { + long sn = WgUdpCommShort.getLongByByte(validBytes, 4, 4); + channelMap.put(sn,ctx); + packetMap.put(sn,packet); + queue.offer(validBytes); + } + } + ReferenceCountUtil.release(buf); + }catch (Exception e){ + Log_error.info(e.toString()); + } + } +} diff --git a/cloud/weigeng/src/main/java/com/sincere/weigeng/utils/WatchServer.java b/cloud/weigeng/src/main/java/com/sincere/weigeng/utils/WatchServer.java index b358ad3..d382d43 100644 --- a/cloud/weigeng/src/main/java/com/sincere/weigeng/utils/WatchServer.java +++ b/cloud/weigeng/src/main/java/com/sincere/weigeng/utils/WatchServer.java @@ -1,6 +1,5 @@ package com.sincere.weigeng.utils; - import com.sincere.common.dto.smartCampus.UserDto; import com.sincere.common.dto.xiaoan.CheckInDto; import com.sincere.common.dto.xiaoan.CheckOutDto; @@ -11,14 +10,16 @@ import com.sincere.weigeng.feign.SmFeign; import com.sincere.weigeng.feign.XaFeign; import com.sincere.weigeng.logs.LogName; import com.sincere.weigeng.logs.LoggerUtils; +import io.netty.bootstrap.Bootstrap; +import io.netty.channel.ChannelHandlerContext; +import io.netty.channel.ChannelOption; +import io.netty.channel.EventLoopGroup; +import io.netty.channel.nio.NioEventLoopGroup; +import io.netty.channel.socket.DatagramPacket; +import io.netty.channel.socket.nio.NioDatagramChannel; import org.apache.commons.lang3.StringUtils; -import org.apache.mina.core.session.IoSession; -import org.apache.mina.transport.socket.DatagramSessionConfig; -import org.apache.mina.transport.socket.nio.NioDatagramAcceptor; import org.slf4j.Logger; -import java.io.IOException; -import java.net.InetSocketAddress; import java.util.*; import java.util.concurrent.ConcurrentHashMap; @@ -29,39 +30,36 @@ import java.util.concurrent.ConcurrentHashMap; */ public class WatchServer { - private static final Logger Log_orderSuccess = LoggerUtils.Logger(LogName.orderSuccess); - private static final Logger Log_orderFail = LoggerUtils.Logger(LogName.orderFail); - private static final Logger Log_kaoInfo = LoggerUtils.Logger(LogName.kaoInfo); - private static final Logger Log_heartBeat = LoggerUtils.Logger(LogName.heartBeat); - private static final Logger Log_error = LoggerUtils.Logger(LogName.error); - - private static List snoList = new ArrayList<>(); - private static List indexList = new ArrayList<>(); - private static WatchingShortHandler watchingShortHandler ; - private static Queue queue = new LinkedList<>(); - private static Map sessionMap = new ConcurrentHashMap<>(); - - // 进入服务器监控状态 - public static int WatchingServerRunning(String watchServerIP,int watchServerPort, - SmFeign smFeign ,XaFeign xaFeign) { - watchingShortHandler = new WatchingShortHandler(queue,sessionMap); - // 创建UDP数据包NIO - NioDatagramAcceptor acceptor = new NioDatagramAcceptor(); - // NIO设置底层IOHandler - acceptor.setHandler(watchingShortHandler); - - // 设置是否重用地址? 也就是每个发过来的udp信息都是一个地址? - DatagramSessionConfig dcfg = acceptor.getSessionConfig(); - dcfg.setReuseAddress(false); - // 绑定端口地址 + private static Logger Log_error = LoggerUtils.Logger(LogName.error); + private static Logger Log_orderSuccess = LoggerUtils.Logger(LogName.orderSuccess); + private static Logger Log_orderFail = LoggerUtils.Logger(LogName.orderFail); + private static Logger Log_kaoInfo = LoggerUtils.Logger(LogName.kaoInfo); + private static Logger Log_heartBeat = LoggerUtils.Logger(LogName.heartBeat); + + private List snoList = new ArrayList<>(); + private List indexList = new ArrayList<>(); + private Queue queue = new LinkedList<>(); + private Map channelMap = new ConcurrentHashMap<>() ; + private Map packetMap = new ConcurrentHashMap<>(); + + public void watchPort(int port){ try { - acceptor.bind(new InetSocketAddress(watchServerIP, watchServerPort)); - } catch (IOException e) { + Bootstrap b = new Bootstrap(); + EventLoopGroup group = new NioEventLoopGroup(); + b.group(group) + .channel(NioDatagramChannel.class) + .option(ChannelOption.SO_BROADCAST, true) + .handler(new UdpServerHandler(queue,channelMap,packetMap)); + + b.bind(port).sync().channel(); + } catch (InterruptedException e) { Log_orderSuccess.info("绑定接收服务器失败...."); e.printStackTrace(); - return 0; } - Log_orderSuccess.info("绑定接收服务器成功...."); + Log_orderSuccess.info("绑定接收服务器成功....:"+port); + } + + public void listen(SmFeign smFeign, XaFeign xaFeign){ long recordIndex = 0; while(true) { if (!queue.isEmpty()) { @@ -69,30 +67,34 @@ public class WatchServer { synchronized (queue) { recvBuff= queue.poll(); } - if (recvBuff[1]== 0x20) { - long sn = WgUdpCommShort.getLongByByte(recvBuff, 4, 4); - smFeign.updateLinkTime(sn+""); - Log_heartBeat.info("设备"+sn); - boolean isExist = true ; - long recordIndexGet = WgUdpCommShort.getLongByByte(recvBuff, 8, 4); - if(snoList.indexOf(sn) >= 0){ - int number = snoList.indexOf(sn); - recordIndex = indexList.get(number); - indexList.set(number,recordIndexGet); - }else { - snoList.add(sn); - recordIndex = 0 ; - indexList.add(recordIndexGet); - System.out.println("设备"+sn+"上线"); - isExist = false ; - } - if(isExist){ - if (recordIndex < recordIndexGet || (recordIndexGet - recordIndex) < -5) { - watching(recvBuff,smFeign,xaFeign); + try { + if (recvBuff[1]== 0x20) { + long sn = WgUdpCommShort.getLongByByte(recvBuff, 4, 4); + smFeign.updateLinkTime(sn+""); + Log_heartBeat.info("设备"+sn); + boolean isExist = true ; + long recordIndexGet = WgUdpCommShort.getLongByByte(recvBuff, 8, 4); + if(snoList.indexOf(sn) >= 0){ + int number = snoList.indexOf(sn); + recordIndex = indexList.get(number); + indexList.set(number,recordIndexGet); + }else { + snoList.add(sn); + recordIndex = 0 ; + indexList.add(recordIndexGet); + System.out.println("设备"+sn+"上线"); + isExist = false ; + } + if(isExist){ + if (recordIndex < recordIndexGet || (recordIndexGet - recordIndex) < -5) { + watching(recvBuff,xaFeign,smFeign); + } } + }else { + push(recvBuff,xaFeign); } - }else { - push(recvBuff,xaFeign); + }catch (Exception e){ + } } else { long times = 100; @@ -105,7 +107,7 @@ public class WatchServer { } } - private static void watching(byte[] recv,SmFeign smFeign ,XaFeign xaFeign){ + private void watching(byte[] recv , XaFeign xaFeign , SmFeign smFeign){ long res = 0; //8-11 记录的索引号 //(=0表示没有记录) 4 0x00000000 @@ -177,7 +179,7 @@ public class WatchServer { if (StringUtils.isNotBlank(studentNum)) { int outOf = recordDoorNO == 1 ? 1 : 0; //远程开门 - openDoor(xaFeign,sno,"64",recordDoorNO,cardNo); + WatchServer.openDoor(xaFeign,channelMap.get(sno),packetMap.get(sno),sno,"64",recordDoorNO,cardNo); Log_orderSuccess.info("请假开门成功"+cardNo); } else { //没有请假不做任何处理,则是刷卡异常,入库 @@ -196,7 +198,7 @@ public class WatchServer { } } - private static void push(byte[] recv,XaFeign xaFeign){ + private void push(byte[] recv , XaFeign xaFeign){ long index = WgUdpCommShort.getXidOfCommand(recv); long sno = WgUdpCommShort.getLongByByte(recv, 4, 4); String functionId = WGUtils.byte2Hex(recv[1]); @@ -216,8 +218,17 @@ public class WatchServer { } } + public ChannelHandlerContext getContext(long sno){ + return channelMap.get(sno) ; + } + + public DatagramPacket getPacket(long sno){ + return packetMap.get(sno); + } + //远程开门 - public static long openDoor(XaFeign xaFeign,long sno , String outsideOrderId,int doorNo , String cardNo){ + public static long openDoor(XaFeign xaFeign , ChannelHandlerContext context , DatagramPacket packet , + long sno , String outsideOrderId, int doorNo , String cardNo){ WgUdpCommShort pkt = new WgUdpCommShort(); pkt.iDevSn = sno; try{ @@ -234,7 +245,7 @@ public class WatchServer { byte[] bytes = pkt.toByte(); long index = WgUdpCommShort.getXidOfCommand(bytes); long result = insert(xaFeign,sno+"",outsideOrderId,cardNo,index,bytes); - pkt.run(watchingShortHandler.getSessionMap().get(sno),bytes); + pkt.run(context,packet,bytes); return result ; }catch (Exception e){ Log_error.error(e.toString()); @@ -243,7 +254,7 @@ public class WatchServer { } //重置控制板时间 - public static long setTime(XaFeign xaFeign,long sno , String outsideOrderId){ + public static long setTime(XaFeign xaFeign , ChannelHandlerContext context , DatagramPacket packet , long sno , String outsideOrderId){ WgUdpCommShort pkt = new WgUdpCommShort(); pkt.iDevSn = sno; try{ @@ -253,14 +264,14 @@ public class WatchServer { pkt.data[0] = WGUtils.toHex(String.valueOf(cal.get(Calendar.YEAR)).substring(0,2)); pkt.data[1] = WGUtils.toHex(String.valueOf(cal.get(Calendar.YEAR)).substring(2,4)); pkt.data[2] = WGUtils.toHex(String.valueOf(cal.get(Calendar.MONTH)+1)); - pkt.data[3] = WGUtils.toHex(String.valueOf(cal.get(Calendar.DATE))); + pkt.data[3] = WGUtils.toHex(String.valueOf(cal.get(Calendar.DATE)-1)); pkt.data[4] =WGUtils.toHex(String.valueOf(cal.get(Calendar.HOUR_OF_DAY))); pkt.data[5] =WGUtils.toHex(String.valueOf(cal.get(Calendar.MINUTE))); pkt.data[6] = WGUtils.toHex(String.valueOf(cal.get(Calendar.SECOND))); byte[] bytes = pkt.toByte(); long index = WgUdpCommShort.getXidOfCommand(bytes); long result = insert(xaFeign,sno+"",outsideOrderId,null,index,bytes); - pkt.run(watchingShortHandler.getSessionMap().get(sno),bytes); + pkt.run(context,packet,bytes); return result ; }catch (Exception e){ Log_error.error(e.toString()); @@ -269,11 +280,10 @@ public class WatchServer { } - //设置考勤时段 - public static List SetAttendanceTime(XaFeign xaFeign,long sno ,String outsideOrderId, int shiduan , Date begin ,Date end , - int isMonDay ,int isTuesDay , int isWednesDay ,int isThursDay , int isFriday , - int isSaturDay , int isWeekend , String shiqu){ + public static List SetAttendanceTime(XaFeign xaFeign , ChannelHandlerContext context , DatagramPacket packet , long sno ,String outsideOrderId, int shiduan , Date begin ,Date end , + int isMonDay ,int isTuesDay , int isWednesDay ,int isThursDay , int isFriday , + int isSaturDay , int isWeekend , String shiqu){ List resultList = new ArrayList<>(); WgUdpCommShort pkt = new WgUdpCommShort(); pkt.iDevSn = sno; @@ -341,7 +351,7 @@ public class WatchServer { byte[] bytes = pkt.toByte(); long index = WgUdpCommShort.getXidOfCommand(bytes); long result = insert(xaFeign,sno+"",outsideOrderId,null,index,bytes); - pkt.run(watchingShortHandler.getSessionMap().get(sno),bytes); + pkt.run(context,packet,bytes); resultList.add(result); } return resultList ; @@ -351,9 +361,8 @@ public class WatchServer { return resultList; } - //设置权限 - public static long SetSignalCardInfo(XaFeign xaFeign,long sno , String outsideOrderId, String cardNo , int shiduan , Date begin , Date end){ + public static long SetSignalCardInfo(XaFeign xaFeign , ChannelHandlerContext context , DatagramPacket packet , long sno , String outsideOrderId, String cardNo , int shiduan , Date begin , Date end){ WgUdpCommShort pkt = new WgUdpCommShort(); pkt.iDevSn = sno; try{ @@ -390,7 +399,7 @@ public class WatchServer { byte[] bytes = pkt.toByte(); long index = WgUdpCommShort.getXidOfCommand(bytes); long result = insert(xaFeign,sno+"",outsideOrderId,cardNo,index,bytes); - pkt.run(watchingShortHandler.getSessionMap().get(sno),bytes); + pkt.run(context,packet,bytes); return result ; }catch (Exception e){ Log_error.error(e.toString()); @@ -399,7 +408,7 @@ public class WatchServer { } //删除单张卡权限 - public static long clearSinglePower(XaFeign xaFeign,long sno ,String outsideOrderId, String cardNo){ + public static long clearSinglePower(XaFeign xaFeign , ChannelHandlerContext context , DatagramPacket packet , long sno ,String outsideOrderId, String cardNo){ WgUdpCommShort pkt = new WgUdpCommShort(); pkt.iDevSn = sno; try{ @@ -413,7 +422,7 @@ public class WatchServer { byte[] bytes = pkt.toByte(); long index = WgUdpCommShort.getXidOfCommand(bytes); long result = insert(xaFeign,sno+"",outsideOrderId,cardNo,index,bytes); - pkt.run(watchingShortHandler.getSessionMap().get(sno),bytes); + pkt.run(context,packet,bytes); return result ; }catch (Exception e){ Log_error.error(e.toString()); @@ -422,7 +431,7 @@ public class WatchServer { } //删除全部权限 - public static long clearAllPower(XaFeign xaFeign,long sno ,String outsideOrderId){ + public static long clearAllPower(XaFeign xaFeign , ChannelHandlerContext context , DatagramPacket packet , long sno ,String outsideOrderId){ WgUdpCommShort pkt = new WgUdpCommShort(); pkt.iDevSn = sno; try{ @@ -436,7 +445,7 @@ public class WatchServer { byte[] bytes = pkt.toByte(); long index = WgUdpCommShort.getXidOfCommand(bytes); long result = insert(xaFeign,sno+"",outsideOrderId,null,index,bytes); - pkt.run(watchingShortHandler.getSessionMap().get(sno),bytes); + pkt.run(context,packet,bytes); return result ; }catch (Exception e){ Log_error.error(e.toString()); @@ -445,7 +454,7 @@ public class WatchServer { } //查询卡权限 - public static long searchPower(XaFeign xaFeign,long sno ,String outsideOrderId, String cardNo){ + public static long searchPower(XaFeign xaFeign , ChannelHandlerContext context , DatagramPacket packet , long sno ,String outsideOrderId, String cardNo){ WgUdpCommShort pkt = new WgUdpCommShort(); pkt.iDevSn = sno; try{ @@ -459,7 +468,7 @@ public class WatchServer { byte[] bytes = pkt.toByte(); long index = WgUdpCommShort.getXidOfCommand(bytes); long result = insert(xaFeign,sno+"",outsideOrderId,cardNo,index,bytes); - pkt.run(watchingShortHandler.getSessionMap().get(sno),bytes); + pkt.run(context,packet,bytes); return result ; }catch (Exception e){ Log_error.error(e.toString()); @@ -468,7 +477,7 @@ public class WatchServer { } //删除时段 - public static long clearShiDuan(XaFeign xaFeign,long sno , String outsideOrderId){ + public static long clearShiDuan(XaFeign xaFeign , ChannelHandlerContext context , DatagramPacket packet , long sno , String outsideOrderId){ WgUdpCommShort pkt = new WgUdpCommShort(); pkt.iDevSn = sno; try{ @@ -482,7 +491,7 @@ public class WatchServer { byte[] bytes = pkt.toByte(); long index = WgUdpCommShort.getXidOfCommand(bytes); long result = insert(xaFeign,sno+"",outsideOrderId,null,index,bytes); - pkt.run(watchingShortHandler.getSessionMap().get(sno),bytes); + pkt.run(context,packet,bytes); return result ; }catch (Exception e){ Log_error.error(e.toString()); @@ -490,7 +499,7 @@ public class WatchServer { return 0l; } - private static long insert(XaFeign xaFeign ,String sn ,String functionId , String cardNo , long index , byte[] recv){ + private static long insert(XaFeign xaFeign , String sn ,String functionId , String cardNo , long index , byte[] recv){ StringBuffer send = new StringBuffer(); for(byte b : recv){ diff --git a/cloud/weigeng/src/main/java/com/sincere/weigeng/utils/WatchingShortHandler.java b/cloud/weigeng/src/main/java/com/sincere/weigeng/utils/WatchingShortHandler.java deleted file mode 100644 index 32fcea8..0000000 --- a/cloud/weigeng/src/main/java/com/sincere/weigeng/utils/WatchingShortHandler.java +++ /dev/null @@ -1,90 +0,0 @@ -package com.sincere.weigeng.utils; - -import org.apache.mina.core.buffer.IoBuffer; -import org.apache.mina.core.service.IoHandlerAdapter; -import org.apache.mina.core.session.IdleStatus; -import org.apache.mina.core.session.IoSession; - -import java.util.Map; -import java.util.Queue; - - -/** - * Class the extends IoHandlerAdapter in order to properly handle - * connections and the data the connections send - * - * @author Apache MINA Project - */ -public class WatchingShortHandler extends IoHandlerAdapter { - - private Queue queue; - private Map sessionMap ; - public WatchingShortHandler(Queue queue , Map sessionMap) { - super(); - this.queue = queue; - this.sessionMap = sessionMap; - } - - /** - * 异常来关闭session - */ - @Override - public void exceptionCaught(IoSession session, Throwable cause) - throws Exception { - cause.printStackTrace(); - session.close(true); - } - - /** - * 服务器端收到一个消息 - */ - @Override - public void messageReceived(IoSession session, Object message) throws Exception { - IoBuffer io = (IoBuffer) message; - if (io.hasRemaining()) { - byte[] validBytes = new byte[io.remaining()]; - io.get(validBytes,0,io.remaining()); - if (validBytes.length == WgUdpCommShort.WGPacketSize) { - synchronized (queue) { - long sn = WgUdpCommShort.getLongByByte(validBytes, 4, 4); - sessionMap.put(sn,session); - queue.offer(validBytes); - } - } else { - } - } - } - - @Override - public void sessionClosed(IoSession session) throws Exception { - } - - @Override - public void sessionCreated(IoSession session) throws Exception { - } - - @Override - public void sessionIdle(IoSession session, IdleStatus status) - throws Exception { - } - - @Override - public void sessionOpened(IoSession session) throws Exception { - } - - public Queue getQueue() { - return queue; - } - - public void setQueue(Queue queue) { - this.queue = queue; - } - - public Map getSessionMap() { - return sessionMap; - } - - public void setSessionMap(Map sessionMap) { - this.sessionMap = sessionMap; - } -} diff --git a/cloud/weigeng/src/main/java/com/sincere/weigeng/utils/WgUdpCommShort.java b/cloud/weigeng/src/main/java/com/sincere/weigeng/utils/WgUdpCommShort.java index 30234cf..4f076c2 100644 --- a/cloud/weigeng/src/main/java/com/sincere/weigeng/utils/WgUdpCommShort.java +++ b/cloud/weigeng/src/main/java/com/sincere/weigeng/utils/WgUdpCommShort.java @@ -1,7 +1,8 @@ package com.sincere.weigeng.utils; -import org.apache.mina.core.buffer.IoBuffer; -import org.apache.mina.core.session.IoSession; +import io.netty.buffer.Unpooled; +import io.netty.channel.ChannelHandlerContext; +import io.netty.channel.socket.DatagramPacket; public class WgUdpCommShort { //短报文协议 @@ -99,22 +100,9 @@ public class WgUdpCommShort { //短报文协议 return buff; } - public void run(IoSession ioSession , byte[] command){ - byte[] bytCommand = command; - IoBuffer b; - Boolean bSent =false; - //ioSession = connFuture.getSession(); - if (ioSession !=null) - { - if (ioSession.isConnected()) - { - b = IoBuffer.allocate(bytCommand.length); - b.put(bytCommand); - b.flip(); - ioSession.write(b); - bSent = true; - } - } - } + public void run(ChannelHandlerContext ctx, DatagramPacket packet , byte[] command ){ + DatagramPacket data = new DatagramPacket(Unpooled.copiedBuffer(command), packet.sender()); + ctx.writeAndFlush(data);//向客户端发送消息 + } } diff --git a/cloud/weigeng/src/main/resources/application.yaml b/cloud/weigeng/src/main/resources/application.yaml index 486b3c3..5152597 100644 --- a/cloud/weigeng/src/main/resources/application.yaml +++ b/cloud/weigeng/src/main/resources/application.yaml @@ -4,17 +4,13 @@ server: spring: application: name: weigeng-server - profiles: - active: dev - eureka: - instance: + instance:2 hostname: localhost lease-expiration-duration-in-seconds: 60 lease-renewal-interval-in-seconds: 10 client: service-url: - # defaultZone: http://localhost:8761/eureka/ defaultZone: http://localhost:8761/eureka/,http://localhost:8762/eureka/ -- libgit2 0.21.0