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 4dfa78b..4c6b827 100644 --- a/cloud/dahua/src/main/java/com/example/dahua/MyTask.java +++ b/cloud/dahua/src/main/java/com/example/dahua/MyTask.java @@ -1,17 +1,18 @@ package com.example.dahua; -import com.example.dahua.bean.CardBean; -import com.example.dahua.bean.DeviceInfoBean; -import com.example.dahua.bean.TeacherBean; -import com.example.dahua.bean.UserInfoBean; +import com.example.dahua.bean.*; +import com.example.dahua.dao.SearchDao; import com.example.dahua.dao.UserDao; import com.example.dahua.lib.NetSDKLib; import com.example.dahua.lib.ToolKits; import com.example.dahua.lib.Utils; import com.example.dahua.module.AutoRegisterModule; +import com.example.dahua.module.FaceRecognitionModule; import com.example.dahua.module.GateModule; import com.example.dahua.module.LoginModule; import com.example.dahua.service.AttendanceService; +import com.example.dahua.utils.DateUtils; +import com.example.dahua.utils.FileUtils; import com.example.dahua.xiananDao.SendRecordDao; import com.sun.jna.Pointer; import org.springframework.beans.factory.annotation.Autowired; @@ -58,6 +59,9 @@ public class MyTask implements ApplicationRunner { SendRecordDao sendRecordDao; @Autowired + SearchDao searchDao; + + @Autowired UserDao userDao; public boolean isHasNewDevice = false;//判断是否有新设备上线 @@ -65,10 +69,15 @@ public class MyTask implements ApplicationRunner { @Override public void run(ApplicationArguments args) throws Exception { // 121.40.109.21 + // 打开工程,初始化 + LoginModule.init(disConnect, haveReConnect); + //自注册 + autoRegister(); - LoginModule.init(disConnect, haveReConnect); // 打开工程,初始化 - - autoRegister();//自注册 + /** + * 考勤监听 + */ + kaoQinRecord(); // System.out.println(" sendRecordDao:"+sendRecordDao.getSenSuccess()); } @@ -96,6 +105,8 @@ public class MyTask implements ApplicationRunner { if (!StringUtils.isEmpty(deviceId)) { attendanceService.updateConnectStateWithDevid(0, deviceId); GateModule.stopRealLoadPic(lLongMap.get(deviceId)); + //人脸识别、人脸检测事件 + FaceRecognitionModule.stopRealLoadPicture(lLongMap.get(deviceId)); lLongMap.remove(deviceId); // devMap.remove(deviceId); removeDevice(deviceId); @@ -249,6 +260,22 @@ public class MyTask implements ApplicationRunner { } } + /** + * 考勤监听 + */ + public synchronized void kaoQinRecord() { + isHasNewDevice = false; + if (null != deviceInfoBeans && deviceInfoBeans.size() > 0) { + for (DeviceInfoBean dev : + deviceInfoBeans) { + if (lLongMap.get(dev.getDevcieId()).intValue() > 0) { + //人脸识别、人脸检测事件监听 + NetSDKLib.LLong lLong = FaceRecognitionModule.realLoadPicture(0, analyzerCallback); + } + } + } + } + //智能订阅 private AnalyzerDataCB analyzerCallback = new AnalyzerDataCB(); @@ -277,11 +304,14 @@ public class MyTask implements ApplicationRunner { if (dwAlarmType == NetSDKLib.EVENT_IVS_ACCESS_CTL) { NetSDKLib.DEV_EVENT_ACCESS_CTL_INFO msg = new NetSDKLib.DEV_EVENT_ACCESS_CTL_INFO(); ToolKits.GetPointerData(pAlarmInfo, msg); - System.out.println("sda:" + new String(msg.szCardNo) + " 抓拍照片存储地址:"); + //卡号 + String card = new String(msg.szCardNo).trim(); + System.out.println("sda:" + card + " 抓拍照片存储地址:"); + try { - String card = new String(msg.szCardNo).trim(); if (!StringUtils.isEmpty(card)) { // 保存图片,获取图片缓存 + // 图片服务器路径 String snapPicPath = path + "\\" + System.currentTimeMillis() + ".png"; // 保存图片地址 byte[] buffer = pBuffer.getByteArray(0, dwBufSize); ByteArrayInputStream byteArrInputGlobal = new ByteArrayInputStream(buffer); @@ -289,19 +319,32 @@ public class MyTask implements ApplicationRunner { if (gateBufferedImage != null) { ImageIO.write(gateBufferedImage, "png", new File(snapPicPath)); } + //卡号取反(大写) card = cardNo(card); - - CardBean cardBean = userDao.getCards(card);//根据卡号获取身份信息 + //根据卡号获取卡身份信息 + CardBean cardBean = userDao.getCards(card); String time = new SimpleDateFormat("yyyy-MM-dd HH:mm:ss").format(new Date()); snapPicPath = snapPicPath.replaceFirst("\\.", "http://121.40.109.21:8991"); snapPicPath = snapPicPath.replace("FaceRecoder", "image"); - if (null != cardBean && cardBean.getType() == 0) {//老师 + if (null != cardBean && cardBean.getType() == 0) { + //老师人脸信息,保存人脸记录表 TeacherBean teacherBean = userDao.getTeacherWithId(cardBean.getUser_id()); sendRecordDao.addFaceRecoder("", teacherBean.getUser_id(), teacherBean.getName(), snapPicPath, 1, time, card,""); - } else if (null != cardBean && cardBean.getType() == 2) {//学生 + } else if (null != cardBean && cardBean.getType() == 2) { + //学生人脸信息,保存人脸记录表 UserInfoBean userInfoBean = userDao.getStudentWithid(cardBean.getUser_id()); sendRecordDao.addFaceRecoder("", userInfoBean.getUser_id(), userInfoBean.getName(), snapPicPath, 1, time, card,""); } + + // TODO 考勤记录 + //刷卡结果,1表示成功, 0表示失败 + int status = msg.bStatus; + //门禁事件类型:1进2出 + int eventType = msg.emEventType; + //刷卡时间 + String eventTime = msg.UTC.toStringTime(); + //保存考勤记录 + kaoQinRecord(status,eventType,card,"",eventTime,snapPicPath); } } catch (IOException e2) { @@ -321,6 +364,7 @@ public class MyTask implements ApplicationRunner { } } + /** * 卡号两两取反 * @@ -344,4 +388,84 @@ public class MyTask implements ApplicationRunner { } + /** + * 大华设备考勤记录 + * @param status + * @param eventType + * @param cardNo + * @param deviceId + * @param eventTime + * @param imageUrl + */ + public void kaoQinRecord(int status,int eventType,String cardNo,String deviceId,String eventTime,String imageUrl) { + if (status == 1) { + //有效刷卡调考勤存储过程 + CheckIn checkIn = new CheckIn(); + checkIn.setDeviceId(deviceId); + checkIn.setCardNo(cardNo); + checkIn.setFunNo(8); + checkIn.setFlag(eventType == 2 ? 1 : 0); + checkIn.setCheckTime(eventTime); + searchDao.checkIn(checkIn); + if (checkIn.getIsSuccess() == 1) { + //考勤成功 + String content = "考勤成功!,设备:" + deviceId + "卡号:" + cardNo + "方向:" + (eventType == 1 ? "进门" : "出门") + "______" + eventTime; + //记录学生考勤签到记录 + FileUtils.getInstance().writeLogs(content, FileUtils.qiandaoSuccess); + } else { + //考勤失败 + String content = "考勤失败!,设备:" + deviceId + "卡号:" + cardNo + "---" + checkIn.getOut(); + //记录学生考勤签到记录 + FileUtils.getInstance().writeLogs(content, FileUtils.qiandaoErr); + } + } else { + //判断是否请假 + String studentNum = searchDao.checkLeave(cardNo); + if (org.apache.commons.lang.StringUtils.isNotBlank(studentNum)) { + //短信信息 + Message mobileMessage = searchDao.selectByParentMobile(cardNo); + if (mobileMessage.getSchoolId() == 4) { + //才发送短信 + ShortMsg shortMsg = new ShortMsg(); + String tableSuffix = DateUtils.date2String(new Date(), DateUtils.format); + shortMsg.setTableName("smsNew" + tableSuffix); + shortMsg.setSchoolId(mobileMessage.getSchoolId()); + shortMsg.setMobile(mobileMessage.getParentMobile()); + if (eventType == 2) { + //出门 + shortMsg.setMsg(mobileMessage.getName() + "家长您好,你的孩子于" + DateUtils.date2String(new Date(), DateUtils.format2) + "请假后出校,请知晓;"); + } else { + shortMsg.setMsg(mobileMessage.getName() + "家长您好,你的孩子于" + DateUtils.date2String(new Date(), DateUtils.format2) + "请假后进校,请知晓;"); + } + searchDao.insertMessage(shortMsg.getTableName(),shortMsg.getSchoolId()+"",shortMsg.getMobile(),shortMsg.getMsg()); + } + } else { + //若即不成功,也不是请假,则按刷卡异常处理 + User user = searchDao.selectUserByCardNum(cardNo).get(0); + if(user ==null ){ + System.out.println("卡号"+cardNo+"没找到对应学生或老师"); + } + if (deviceId.startsWith("ytj")){ + deviceId = "29"; + }else { + deviceId = "22"; + } + //失败记录 + SendRecordBean sendRecordBean = new SendRecordBean(); + sendRecordBean.setSchoolId(user.getSchoolId()); + sendRecordBean.setSchoolName(userDao.getSchoolName(String.valueOf(user.getSchoolId()))); + sendRecordBean.setTime(new SimpleDateFormat("yyyy-MM-dd HH:mm:ss").format(new Date())); + sendRecordBean.setUserType(2); + sendRecordBean.setNum(cardNo); + sendRecordBean.setName(user.getName()); + sendRecordBean.setImgPath(imageUrl); + sendRecordBean.setCustomerid(String.valueOf(user.getStudentId())); + sendRecordBean.setFailType(8); + sendRecordBean.setFailContent("人脸认证失败"); + sendRecordBean.setDeviceID(deviceId); + 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); + } + } + } } diff --git a/cloud/dahua/src/main/java/com/example/dahua/bean/CheckIn.java b/cloud/dahua/src/main/java/com/example/dahua/bean/CheckIn.java new file mode 100644 index 0000000..114b2cf --- /dev/null +++ b/cloud/dahua/src/main/java/com/example/dahua/bean/CheckIn.java @@ -0,0 +1,74 @@ +package com.example.dahua.bean; + +/** + * @author chen + * @version 1.0 + * @date 2019/10/30 0030 10:26 + */ +public class CheckIn { + + private String deviceId ; + private String cardNo ; + private int funNo ; + private int flag ; + private String checkTime ; + + private String out; + private int isSuccess ; + + public String getDeviceId() { + return deviceId; + } + + public void setDeviceId(String deviceId) { + this.deviceId = deviceId; + } + + public String getCardNo() { + return cardNo; + } + + public void setCardNo(String cardNo) { + this.cardNo = cardNo; + } + + public int getFlag() { + return flag; + } + + public void setFlag(int flag) { + this.flag = flag; + } + + public String getCheckTime() { + return checkTime; + } + + public void setCheckTime(String checkTime) { + this.checkTime = checkTime; + } + + public String getOut() { + return out; + } + + public void setOut(String out) { + this.out = out; + } + + public int getIsSuccess() { + return isSuccess; + } + + public void setIsSuccess(int isSuccess) { + this.isSuccess = isSuccess; + } + + public int getFunNo() { + return funNo; + } + + public void setFunNo(int funNo) { + this.funNo = funNo; + } +} diff --git a/cloud/dahua/src/main/java/com/example/dahua/bean/Message.java b/cloud/dahua/src/main/java/com/example/dahua/bean/Message.java new file mode 100644 index 0000000..e4aac6c --- /dev/null +++ b/cloud/dahua/src/main/java/com/example/dahua/bean/Message.java @@ -0,0 +1,31 @@ +package com.example.dahua.bean; + +public class Message { + private String name ; + private int schoolId ; + private String parentMobile ; + + public String getName() { + return name; + } + + public void setName(String name) { + this.name = name; + } + + public int getSchoolId() { + return schoolId; + } + + public void setSchoolId(int schoolId) { + this.schoolId = schoolId; + } + + public String getParentMobile() { + return parentMobile; + } + + public void setParentMobile(String parentMobile) { + this.parentMobile = parentMobile; + } +} diff --git a/cloud/dahua/src/main/java/com/example/dahua/bean/ShortMsg.java b/cloud/dahua/src/main/java/com/example/dahua/bean/ShortMsg.java new file mode 100644 index 0000000..f080aaf --- /dev/null +++ b/cloud/dahua/src/main/java/com/example/dahua/bean/ShortMsg.java @@ -0,0 +1,42 @@ +package com.example.dahua.bean; + +public class ShortMsg { + + private String tableName ; + + private int schoolId ; + private String mobile ; + private String msg ; + + public String getTableName() { + return tableName; + } + + public void setTableName(String tableName) { + this.tableName = tableName; + } + + public int getSchoolId() { + return schoolId; + } + + public void setSchoolId(int schoolId) { + this.schoolId = schoolId; + } + + public String getMobile() { + return mobile; + } + + public void setMobile(String mobile) { + this.mobile = mobile; + } + + public String getMsg() { + return msg; + } + + public void setMsg(String msg) { + this.msg = msg; + } +} diff --git a/cloud/dahua/src/main/java/com/example/dahua/bean/User.java b/cloud/dahua/src/main/java/com/example/dahua/bean/User.java new file mode 100644 index 0000000..82c03e9 --- /dev/null +++ b/cloud/dahua/src/main/java/com/example/dahua/bean/User.java @@ -0,0 +1,46 @@ +package com.example.dahua.bean; + +/** + * @author chen + * @version 1.0 + * @date 2019/10/14 0014 14:41 + */ +public class User { + + private int schoolId; + private int classId ; + private String name ; + private int studentId ; + + public int getSchoolId() { + return schoolId; + } + + public void setSchoolId(int schoolId) { + this.schoolId = schoolId; + } + + public int getClassId() { + return classId; + } + + public void setClassId(int classId) { + this.classId = classId; + } + + public String getName() { + return name; + } + + public void setName(String name) { + this.name = name; + } + + public int getStudentId() { + return studentId; + } + + public void setStudentId(int studentId) { + this.studentId = studentId; + } +} diff --git a/cloud/dahua/src/main/java/com/example/dahua/dao/SearchDao.java b/cloud/dahua/src/main/java/com/example/dahua/dao/SearchDao.java new file mode 100644 index 0000000..295a4a3 --- /dev/null +++ b/cloud/dahua/src/main/java/com/example/dahua/dao/SearchDao.java @@ -0,0 +1,55 @@ +package com.example.dahua.dao; + +import com.example.dahua.bean.CheckIn; +import com.example.dahua.bean.Message; +import com.example.dahua.bean.User; +import org.apache.ibatis.annotations.Param; +import org.apache.ibatis.annotations.Select; +import org.springframework.stereotype.Repository; + +import java.util.List; + +@Repository +public interface SearchDao { + /** + * 考勤推送存储过程 + * @param checkIn + * @return + */ + int checkIn(CheckIn checkIn); + + /** + * 获取学生信息 + * @param cardNum + * @return + */ + List selectUserByCardNum(String cardNum); + + /** + * 获取卡号 + * @param cardNo + * @return + */ + @Select("select Top(1) StudentNum from HS_LeaveExaminePassList where StudentNum= #{cardNo} and GETDATE() ]]> LeaveTime and GETDATE() ReturnTime") + String checkLeave(@Param("cardNo") String cardNo); + + /** + * 获取学生父母电话 + * @param cardNo + * @return + */ + @Select("select school_id , ParentMobile , name from SZ_V_School_Student where student_num = #{cardNo}") + Message selectByParentMobile(@Param("cardNo") String cardNo); + + /** + * 插入短信发送表 + * @param tableName + * @param schoolId + * @param mobile + * @param msg + */ + @Select("insert into ${tableName} (SchoolID,Mobile,Msg,tdtype,Status,IsNeedSend,SendTime,intime) values (#{schoolId},#{mobile},#{msg},1,0,1,GETDATE(),GETDATE())") + void insertMessage(@Param("tableName") String tableName,@Param("schoolId") String schoolId,@Param("mobile") String mobile,@Param("msg") String msg); + + +} diff --git a/cloud/dahua/src/main/java/com/example/dahua/dbconfig/MessageDataSourceConfig.java b/cloud/dahua/src/main/java/com/example/dahua/dbconfig/MessageDataSourceConfig.java new file mode 100644 index 0000000..ff010b6 --- /dev/null +++ b/cloud/dahua/src/main/java/com/example/dahua/dbconfig/MessageDataSourceConfig.java @@ -0,0 +1,43 @@ +package com.example.dahua.dbconfig; + +import org.apache.ibatis.session.SqlSessionFactory; +import org.mybatis.spring.SqlSessionFactoryBean; +import org.mybatis.spring.annotation.MapperScan; +import org.springframework.beans.factory.annotation.Qualifier; +import org.springframework.boot.context.properties.ConfigurationProperties; +import org.springframework.boot.jdbc.DataSourceBuilder; +import org.springframework.context.annotation.Bean; +import org.springframework.context.annotation.Configuration; +import org.springframework.context.annotation.Primary; +import org.springframework.core.io.support.PathMatchingResourcePatternResolver; +import org.springframework.jdbc.core.JdbcTemplate; + +import javax.sql.DataSource; + +@Configuration +@MapperScan(basePackages = "com.example.dahua.dao", sqlSessionFactoryRef = "messageSessionFactory") +public class MessageDataSourceConfig { + @Primary + @Bean(name = "messageDataSource") + @ConfigurationProperties("spring.datasource.message") + public DataSource masterDataSource() { + return DataSourceBuilder.create().build(); + } + + @Bean(name = "messageSessionFactory") + public SqlSessionFactory sqlSessionFactory(@Qualifier("messageDataSource") DataSource dataSource) throws Exception { + + SqlSessionFactoryBean sessionFactoryBean = new SqlSessionFactoryBean(); + sessionFactoryBean.setDataSource(dataSource); + sessionFactoryBean.setMapperLocations(new PathMatchingResourcePatternResolver() + .getResources("classpath:mapper/*.xml")); + return sessionFactoryBean.getObject(); + + } + + @Bean + public JdbcTemplate campusJdbcTemplate(@Qualifier("messageDataSource") DataSource dataSource) { + return new JdbcTemplate(dataSource); + } + +} diff --git a/cloud/dahua/src/main/java/com/example/dahua/utils/DateUtils.java b/cloud/dahua/src/main/java/com/example/dahua/utils/DateUtils.java new file mode 100644 index 0000000..a495239 --- /dev/null +++ b/cloud/dahua/src/main/java/com/example/dahua/utils/DateUtils.java @@ -0,0 +1,71 @@ +package com.example.dahua.utils; + +import java.text.ParseException; +import java.text.SimpleDateFormat; +import java.util.Date; + +/** + * @author chen + * @version 1.0 + * @date 2019/10/14 0014 14:16 + */ +public class DateUtils { + + public static String format = "yyyy"; + + public static String format1 = "yyyy-MM-dd"; + + public static String format2 = "yyyy-MM-dd HH:mm:ss"; + + public static String format3 = "yyyyMMddHHmm" ; + + public static String format4 = "yyyyMM"; + + public static long getDate(){ + return System.currentTimeMillis(); + } + + public static String date2String(Date date, String format) { + SimpleDateFormat sdf = new SimpleDateFormat(format); + return sdf.format(date); + } + + public static Date string2Date(String date, String format) { + try{ + SimpleDateFormat sdf = new SimpleDateFormat(format); + return sdf.parse(date); + }catch (Exception e){ + + } + return new Date(); + } + + public static Date getToday(){ + return new Date(); + } + + public static String getToday(String format) throws ParseException{ + SimpleDateFormat sdf = new SimpleDateFormat(format); + return sdf.format(new Date()); + } + + public static int getDateDifference(Date date1, Date date2, String timeType) { + int between = (int) (date1.getTime() - date2.getTime()); + int difference = 0; + switch (timeType) { + case "day": + difference = between / (24 * 60 * 60 * 1000); + break; + case "hour": + difference = between / (60 * 60 * 1000); + break; + case "min": + difference = between / (60 * 1000); + break; + case "s": + difference = between / 1000; + } + return difference; + } + +} diff --git a/cloud/dahua/src/main/resources/application.yml b/cloud/dahua/src/main/resources/application.yml index d0aaf6a..33e9be8 100644 --- a/cloud/dahua/src/main/resources/application.yml +++ b/cloud/dahua/src/main/resources/application.yml @@ -27,6 +27,11 @@ spring: # username: SZJXTUSER # password: xst200919 # driver-class-name: com.microsoft.sqlserver.jdbc.SQLServerDriver + message: + username: sa + password: qaz!@#0401 + jdbcUrl: jdbc:sqlserver://60.190.202.38:49469;database=XST + driver-class-name: com.microsoft.sqlserver.jdbc.SQLServerDriver mybatis: diff --git a/cloud/dahua/src/main/resources/xiaoanmapper/SearchMapper.xml b/cloud/dahua/src/main/resources/xiaoanmapper/SearchMapper.xml new file mode 100644 index 0000000..1f59668 --- /dev/null +++ b/cloud/dahua/src/main/resources/xiaoanmapper/SearchMapper.xml @@ -0,0 +1,35 @@ + + + + + + + + + + + {call AttendanceService( + #{deviceId,mode=IN} , #{cardNo,mode=IN} , #{funNo,mode=IN}, #{flag,mode=IN} , #{checkTime,mode=IN}, + #{out,mode=OUT,jdbcType=VARCHAR,resultMap=resultMap},#{isSuccess,mode=OUT,jdbcType=INTEGER,resultMap=resultMap} + )} + + + + + + + + + + + \ No newline at end of file diff --git a/cloud/pom.xml b/cloud/pom.xml index 5543063..58caed6 100644 --- a/cloud/pom.xml +++ b/cloud/pom.xml @@ -31,7 +31,7 @@ common getaway haikang - + dahua haikangface -- libgit2 0.21.0