Browse Source

门禁接口更新

guq 6 years ago
parent
commit
3bf696ba0c

+ 1 - 1
applications/device/device-client/src/main/resources/application.yml

@@ -4,7 +4,7 @@ device:
     connect-time: 10000
   server:
   # 门禁事件的服务端接口
-    accessControlEvent: https://school-api.ydyhz.com/device/accesscontrol/event
+    accessControlEvent: https://school-api.ydyhz.com/api/device/accesscontrol/event
 server:
   tomcat:
     uri-encoding: UTF-8

+ 6 - 0
applications/device/device-server/pom.xml

@@ -54,6 +54,12 @@
             <groupId>com.usoftchina.smartschool</groupId>
             <artifactId>school-dto</artifactId>
         </dependency>
+        <!--test-->
+        <dependency>
+            <groupId>com.usoftchina.smartschool</groupId>
+            <artifactId>test-starter</artifactId>
+            <scope>test</scope>
+        </dependency>
     </dependencies>
 
     <build>

+ 34 - 0
applications/device/device-server/src/main/java/com/usoftchina/smartschool/device/controller/AccessController.java

@@ -0,0 +1,34 @@
+package com.usoftchina.smartschool.device.controller;
+
+import com.usoftchina.smartschool.base.Result;
+import com.usoftchina.smartschool.device.dto.AccessControlInfo;
+import com.usoftchina.smartschool.device.service.AccessService;
+import org.springframework.beans.factory.annotation.Autowired;
+import org.springframework.web.bind.annotation.*;
+
+/**
+ * @author: guq
+ * @create: 2019-03-12 09:14
+ **/
+@RequestMapping("/accesscontrol")
+@RestController
+public class AccessController {
+
+    @Autowired
+    private AccessService accessService;
+
+    @PostMapping("/event")
+    public Result accessEvent(@RequestBody AccessControlInfo event) {
+        accessService.accessEvent(event);
+        return Result.success();
+    }
+
+   /* @GetMapping("/test")
+    public Result test() {
+        AccessControlInfo info = new AccessControlInfo();
+        info.setCardNo("school");
+        info.setEventType(1);
+        accessService.accessEvent(info);
+        return Result.success();
+    }*/
+}

+ 25 - 11
applications/device/device-server/src/main/java/com/usoftchina/smartschool/device/listener/AccessControlListener.java

@@ -1,3 +1,4 @@
+/*
 package com.usoftchina.smartschool.device.listener;
 
 import com.usoftchina.smartschool.base.Result;
@@ -35,10 +36,12 @@ import java.util.ArrayList;
 import java.util.Date;
 import java.util.List;
 
+*/
 /**
  * @author yingp
  * @date 2019/3/8
- */
+ *//*
+
 @Component
 public class AccessControlListener implements InitializingBean{
 
@@ -58,11 +61,13 @@ public class AccessControlListener implements InitializingBean{
 
     private Logger logger = LoggerFactory.getLogger(AccessControlListener.class);
 
-    /**
+    */
+/**
      * 门禁事件
      *
      * @param event
-     */
+     *//*
+
     @Async
     @EventListener(AccessControlEvent.class)
     public void onAccessControlEvent(AccessControlEvent event) {
@@ -71,17 +76,21 @@ public class AccessControlListener implements InitializingBean{
         if (StringUtils.isEmpty(cardNo)) {
             return;
         }
-        /**
+        */
+/**
          * 查询人员信息
-         */
+         *//*
+
         List<Information> information = deviceMapper.selectInfoByCardNo(cardNo);
         if (null == information || information.size() == 0) {
             logger.error("学生信息不存在");
             return;
         }
-        /**
+        */
+/**
          * 1、保存图片文件;
-         */
+         *//*
+
         byte[] imageData = event.getAccessControlInfo().getImageData();
         if (null != imageData && imageData.length > 0) {
             MultipartFile file = new ImageFile(imageData, information.get(0).getStuName());
@@ -93,9 +102,11 @@ public class AccessControlListener implements InitializingBean{
                 logger.error(ex.getMessage());
             }
         }
-        /**
+        */
+/**
          * 2、保存门禁出入记录;
-         */
+         *//*
+
         int type = event.getAccessControlInfo().getEventType();
         Information info = information.get(0);
         OutInRecord record = new OutInRecord();
@@ -112,9 +123,11 @@ public class AccessControlListener implements InitializingBean{
         record.setStu_number(info.getStuNumber());
         record.setRecord_name(info.getStuName() + (type == 1 ? "进人" : "出去"));
         deviceMapper.insertRecordSelective(record);
-        /**
+        */
+/**
          * 3、推送消息到消息服务器(微信服务监听此消息发送微信消息)
-         */
+         *//*
+
         MessageInfoDTO msg = new MessageInfoDTO();
         msg.setAppId(info.getAppId());
         msg.setSecret(info.getSecret());
@@ -137,3 +150,4 @@ public class AccessControlListener implements InitializingBean{
         });
     }
 }
+*/

+ 8 - 0
applications/device/device-server/src/main/java/com/usoftchina/smartschool/device/service/AccessService.java

@@ -0,0 +1,8 @@
+package com.usoftchina.smartschool.device.service;
+
+import com.usoftchina.smartschool.device.dto.AccessControlInfo;
+
+public interface AccessService {
+
+    void accessEvent(AccessControlInfo event);
+}

+ 112 - 0
applications/device/device-server/src/main/java/com/usoftchina/smartschool/device/service/impl/AccessServiceImpl.java

@@ -0,0 +1,112 @@
+package com.usoftchina.smartschool.device.service.impl;
+
+import com.usoftchina.smartschool.base.Result;
+import com.usoftchina.smartschool.device.api.DeviceApi;
+import com.usoftchina.smartschool.device.dto.AccessControlInfo;
+import com.usoftchina.smartschool.device.mapper.DeviceMapper;
+import com.usoftchina.smartschool.device.po.ImageFile;
+import com.usoftchina.smartschool.device.po.Information;
+import com.usoftchina.smartschool.device.po.OutInRecord;
+import com.usoftchina.smartschool.device.service.AccessService;
+import com.usoftchina.smartschool.file.api.FileApi;
+import com.usoftchina.smartschool.file.dto.FileInfoDTO;
+import com.usoftchina.smartschool.utils.DateUtils;
+import com.usoftchina.smartschool.utils.StringUtils;
+import com.usoftchina.smartschool.wechat.api.WechatApi;
+import com.usoftchina.smartschool.wechat.dto.MessageInfoDTO;
+import org.slf4j.Logger;
+import org.slf4j.LoggerFactory;
+import org.springframework.beans.factory.annotation.Autowired;
+import org.springframework.stereotype.Service;
+import org.springframework.web.multipart.MultipartFile;
+
+import java.util.Date;
+import java.util.List;
+
+/**
+ * @author: guq
+ * @create: 2019-03-12 09:28
+ **/
+@Service
+public class AccessServiceImpl implements AccessService{
+
+   /* @Autowired
+    private FileApi fileApi;*/
+
+    @Autowired
+    private DeviceApi deviceApi;
+
+    @Autowired
+    private WechatApi wechatApi;
+
+    @Autowired
+    private DeviceMapper deviceMapper;
+
+    final static String TEMPLATEID = "JcWRReMGC1odqcaAgXDfETv9sWwVbWLXc9KLEn_Nve0";
+
+    private Logger logger = LoggerFactory.getLogger(getClass());
+
+    @Override
+    public void accessEvent(AccessControlInfo event) {
+        Long fileId = null;
+        String cardNo = event.getCardNo();
+        if (StringUtils.isEmpty(cardNo)) {
+            return;
+        }
+        /**
+         * 查询人员信息
+         */
+        List<Information> information = deviceMapper.selectInfoByCardNo(cardNo);
+        if (null == information || information.size() == 0) {
+            logger.error("学生信息不存在");
+            return;
+        }
+        /**
+         * 1、保存图片文件;
+         */
+       /* byte[] imageData = event.getImageData();
+        if (null != imageData && imageData.length > 0) {
+            MultipartFile file = new ImageFile(imageData, information.get(0).getStuName());
+            Result<FileInfoDTO> fileInfo = null;
+            try {
+                fileInfo = fileApi.upload(0l, file);
+                fileId = fileInfo.getData().getId();
+            }catch (Exception ex) {
+                logger.error(ex.getMessage());
+            }
+        }*/
+        /**
+         * 2、保存门禁出入记录;
+         */
+        int type = event.getEventType();
+        Information info = information.get(0);
+        OutInRecord record = new OutInRecord();
+        record.setClazz_id(info.getClazz_id());
+        record.setSchool_id(info.getSchoolId());
+        record.setClazz_name(info.getStuClass());
+        record.setSchool_id(info.getSchoolId());
+        record.setGrade_clazz(info.getStuClassnickname());
+        record.setGrade_name(info.getStuGrade());
+        record.setRecord_date(new Date());
+        record.setStu_sex(info.getStuSex());
+        record.setRecord_type(type);
+        record.setStu_id(info.getStuId());
+        record.setStu_number(info.getStuNumber());
+        record.setRecord_name(info.getStuName() + (type == 1 ? "进人" : "出去"));
+        deviceMapper.insertRecordSelective(record);
+        /**
+         * 3、推送消息到消息服务器(微信服务监听此消息发送微信消息)
+         */
+        MessageInfoDTO msg = new MessageInfoDTO();
+        msg.setUserType(0);
+        msg.setAppId(info.getAppId());
+        msg.setSecret(info.getSecret());
+        msg.setTouser(info.getOpenId());
+        msg.setTemplateId(TEMPLATEID);
+        msg.setTitle("出入校提醒");
+        msg.setKeyword1(info.getStuName());
+        msg.setKeyword2(DateUtils.format());
+        msg.setRemark("您好! 你的孩子: " + info.getStuName() + (type == 1 ? " 进人" : " 出去") + "学校");
+        wechatApi.sendMsg(msg);
+    }
+}

+ 50 - 0
applications/device/device-server/src/test/java/com/usoftchina/smartschool/device/test/TestService.java

@@ -0,0 +1,50 @@
+package com.usoftchina.smartschool.device.test;
+
+import com.fasterxml.jackson.annotation.JsonProperty;
+import com.usoftchina.smartschool.device.dto.AccessControlInfo;
+import com.usoftchina.smartschool.device.service.AccessService;
+import com.usoftchina.smartschool.utils.DateUtils;
+import com.usoftchina.smartschool.wechat.api.WechatApi;
+import com.usoftchina.smartschool.wechat.dto.MessageInfoDTO;
+import org.junit.Test;
+import org.junit.runner.RunWith;
+import org.springframework.beans.factory.annotation.Autowired;
+import org.springframework.boot.test.context.SpringBootTest;
+import org.springframework.test.context.junit4.SpringRunner;
+
+/**
+ * @author: guq
+ * @create: 2019-03-12 09:48
+ **/
+@RunWith(SpringRunner.class)
+@SpringBootTest
+public class TestService {
+
+    @Autowired
+    AccessService accessService;
+    @Autowired
+    WechatApi wechatApi;
+
+    @Test
+    public void testa_accessservice() {
+        AccessControlInfo info = new AccessControlInfo();
+        info.setCardNo("school");
+        info.setEventType(1);
+        accessService.accessEvent(info);
+    }
+
+    @Test
+    public void testb_wechatapi() {
+        MessageInfoDTO msg = new MessageInfoDTO();
+        msg.setUserType(0);
+        msg.setAppId("asdf");
+        msg.setSecret("asdf");
+        msg.setTouser("asdf");
+        msg.setTemplateId("JcWRReMGC1odqcaAgXDfETv9sWwVbWLXc9KLEn_Nve0");
+        msg.setTitle("出入校提醒");
+        msg.setKeyword1("asdf");
+        msg.setKeyword2(DateUtils.format());
+        msg.setRemark("您好! 你的孩子: ");
+        wechatApi.sendMsg(msg);
+    }
+}

+ 30 - 0
applications/wechat/wechat-server/src/test/java/com/usoftchina/smartschool/wechat/Test_service.java

@@ -42,6 +42,8 @@ public class Test_service {
         sendService.sendMessage(msg);
     }
 
+
+
     @Test
     public void testb_sendDelayMsg() {
         MessageInfo msg = new MessageInfo();
@@ -60,5 +62,33 @@ public class Test_service {
         sendService.sendDelayMessage(mp);
     }
 
+    @Test
+    public void testc_sendOUtMsg() {
+        MessageInfoDTO msg = new MessageInfoDTO();
+        msg.setAppId("wxbc1f8607137d3b8a");
+        msg.setSecret("cadf13c4e21c2c122cb2341b341e5c22");
+        msg.setTouser("o8lZ9uGFfByUEGOk-xMwmajgmjt4");
+        msg.setTemplateId(TEMPLATEID);
+        msg.setTitle("出入校提醒");
+        msg.setKeyword1("小黄");
+        msg.setKeyword2(DateUtils.format());
+        msg.setRemark("您好! 你的孩子: 小黄已经进入校园");
+       // List
+        //sendService.sendOutMessages(msg);
+    }
+
+    @Test
+    public void testd_wechatapi() {
+        MessageInfoDTO msg = new MessageInfoDTO();
+        msg.setAppId("wxbc1f8607137d3b8a");
+        msg.setSecret("cadf13c4e21c2c122cb2341b341e5c22");
+        msg.setTouser("o8lZ9uGFfByUEGOk-xMwmajgmjt4");
+        msg.setTemplateId(TEMPLATEID);
+        msg.setTitle("出入校提醒");
+        msg.setKeyword1("小黄");
+        msg.setKeyword2(DateUtils.format());
+        msg.setRemark("您好! 你的孩子: 小黄已经进入校园");
+        //sendService.sendOutMessages(msg);
+    }
 
 }