Просмотр исходного кода

Merge branch 'master' of https://e.coding.net/chuanghaikeji/smartCampus/backend_code

夏文涛 2 лет назад
Родитель
Сommit
cddb0c9d65

+ 5 - 0
SmartNotificationMapper.xml

@@ -0,0 +1,5 @@
+<?xml version="1.0" encoding="UTF-8"?>
+<!DOCTYPE mapper PUBLIC "-//mybatis.org//DTD Mapper 3.0//EN" "http://mybatis.org/dtd/mybatis-3-mapper.dtd">
+<mapper namespace="com.template.mapper.SmartNotificationMapper">
+
+</mapper>

+ 16 - 0
src/main/java/com/template/api/SmartNotificationControllerAPI.java

@@ -0,0 +1,16 @@
+package com.template.api;
+
+import com.template.model.result.CommonResult;
+import io.swagger.annotations.ApiOperation;
+import org.springframework.web.bind.annotation.GetMapping;
+import org.springframework.web.bind.annotation.RequestMapping;
+import org.springframework.web.bind.annotation.RequestParam;
+
+@RequestMapping("/api/smart-notification")
+public interface SmartNotificationControllerAPI {
+
+    @GetMapping(value = "/remindingList")
+    @ApiOperation(value = "消息提醒页面展示", notes = "消息提醒页面展示", httpMethod = "GET")
+    CommonResult remindingList(@RequestParam Integer id, @RequestParam int currentPage, @RequestParam int pageCount, String type);
+
+}

+ 7 - 4
src/main/java/com/template/common/utils/GetCameraPreviewURL.java

@@ -80,19 +80,22 @@ public class GetCameraPreviewURL {
         JSONObject jsonBody = new JSONObject();
 
 //        人脸比对
-        int[] ingArr=new int[]{131659};
-        String url = "http://192.168.161.224:8080/wanzai/eventRcv/faceComparison";
+//        int[] ingArr=new int[]{131659};
+//        String url = "http://192.168.161.224:8080/wanzai/eventRcv/faceComparison";
 //        String url = "https://www.campussmartlife.com/smartApi/wanzai/eventRcv/faceComparison";
+//        String url = "http://122.51.35.116:8080/wanzai/eventRcv/faceComparison";
 
 //        区域入侵,进入区域,离开区域,倒地
-//        int[] ingArr=new int[]{131588,131586,131587,131605};
-//        String url = "http://192.168.161.224:8080/wanzai/eventRcv/subscription";
+        int[] ingArr=new int[]{131588,131586,131587,131605};
+        String url = "http://192.168.161.224:8080/wanzai/eventRcv/subscription";
 //        String url = "https://www.campussmartlife.com/smartApi/wanzai/eventRcv/subscription";
+//        String url = "http://122.51.35.116:8080/wanzai/eventRcv/subscription";
 
 //        重点人员识别事件
 //        int[] ingArr = new int[]{1644175361};
 //        String url = "http://192.168.161.224:8080/wanzai/eventRcv/emphasisFace";
 //        String url = "https://www.campussmartlife.com/smartApi/wanzai/eventRcv/emphasisFace";
+//        String url = "http://122.51.35.116:8080/wanzai/eventRcv/emphasisFace";
 
 
         jsonBody.put("eventTypes", ingArr);

+ 1 - 1
src/main/java/com/template/common/utils/HttpsClient.java

@@ -449,7 +449,7 @@ public class HttpsClient {
             // 读取响应
             is = connection.getInputStream();
             int length = (int) connection.getContentLength();// 获取字节长度
-            System.out.println(length);
+//            System.out.println(length);
             if (length != -1) {
                 byte[] data = new byte[length];
                 byte[] temp = new byte[512];

+ 90 - 55
src/main/java/com/template/common/utils/Message2.java

@@ -1,10 +1,25 @@
 package com.template.common.utils;
 
+import com.alibaba.druid.sql.visitor.SQLASTOutputVisitor;
 import com.alibaba.fastjson.JSONObject;
 import com.google.gson.Gson;
 import com.google.gson.reflect.TypeToken;
+import org.apache.commons.lang3.StringUtils;
+import org.apache.http.HttpEntity;
+import org.apache.http.HttpResponse;
+import org.apache.http.StatusLine;
+import org.apache.http.client.ClientProtocolException;
+import org.apache.http.client.HttpResponseException;
+import org.apache.http.client.methods.HttpPost;
+import org.apache.http.conn.ssl.SSLConnectionSocketFactory;
+import org.apache.http.entity.StringEntity;
+import org.apache.http.impl.client.CloseableHttpClient;
+import org.apache.http.impl.client.HttpClientBuilder;
+import org.apache.http.impl.client.HttpClients;
+import org.apache.http.util.EntityUtils;
 
 
+import java.io.IOException;
 import java.util.HashMap;
 
 /**
@@ -12,67 +27,87 @@ import java.util.HashMap;
  */
 public class Message2 {
 
-    /** 公众号推送消息
-     * openid:用户小程序openid, order_num订单号,
-     *  h_type房型, live_end入住和离店日期:2023-08-02~2023-08-06
-     *  user_name:用户名, hotel_name:酒店名
-     * **/
-    public static String send(String openid,String order_num,
-                              String h_type,String live_end,
-                              String user_name,String hotel_name,String id)
+//小程序
+//    static String appId="wx2fc3f45732fae5d3";
+//    static String secret="7eee4a49a4470a77f9222995e8511547";
+
+//公众号
+    static String appId="wxa46ef222053a1047";
+    static String secret="16f74a1265c314fd79fdf90670173467";
+
+    /**
+     * 公众号推送消息
+     * @param openid 公众号openId
+     * @param type  事件
+     * @param location  地点
+     * @param dateTime  时间
+     * @return
+     * @throws Exception
+     */
+    public static String send(String openid,String type,String location,String dateTime)
             throws Exception {
-        Gson gson = new Gson();
-        String access_token = "";
-        JSONObject json = new JSONObject();
-        json.put("grant_type", "client_credential");
-//        公众号
-        json.put("appid","wxa46ef222053a1047");
-        json.put("secret","16f74a1265c314fd79fdf90670173467");
-        String url = "https://api.weixin.qq.com/cgi-bin/stable_token";
-        access_token = HttpsClient.sendJson(url,json);
-        access_token = gson.fromJson(access_token, AccessToken.class).getAccess_token();
+
+        String url="https://api.weixin.qq.com/cgi-bin/token?grant_type=client_credential&appid="+appId+"&secret="+secret;
+
+        String s = HttpsClient.httpsRequestReturnString(url, "GET", "");
+        JSONObject jsonObject = JSONObject.parseObject(s);
+        String access_token = jsonObject.getString("access_token");
+
+
         JSONObject message = new JSONObject();
         message.put("touser", openid);
-        message.put("template_id", "pQLY-9pKW-lD-6PuOlxieatGmuCHOezubTxI99cs7Zo");
-
-//        JSONObject small = new JSONObject();
-//        small.put("appid", "wx2fc3f45732fae5d3");
-//        small.put("pagepath", "/pages/push/push?id=" + id);
-//        message.put("miniprogram", small);
-        // 订单号
-        JSONObject character_string1_ = new JSONObject();
-        character_string1_.put("value", order_num);
-        character_string1_.put("color", "#173177");
-        // 房型名称
-        JSONObject thing6 = new JSONObject();
-        thing6.put("value", h_type);
-        thing6.put("color", "#0000FF");
-        // 入离时间
-        JSONObject time11 = new JSONObject();
-        time11.put("value", live_end);
-        time11.put("color", "#173177");
-        // 客户名称
-        JSONObject thing10 = new JSONObject();
-        thing10.put("value", user_name);
-        thing10.put("color", "#173177");
-        // 酒店名称
-        JSONObject thing9_ = new JSONObject();
-        thing9_.put("value", hotel_name);
-        thing9_.put("color", "#173177");
+        message.put("template_id", "vPuSS7nivkQHxcGzpZB-NedVKzqJ4ifk0FTiBI7Aa20");
+
+        JSONObject small = new JSONObject();
+        small.put("appid", "wx2fc3f45732fae5d3");
+        small.put("pagepath", "pages/msgWarn/msgWarn");
+        message.put("miniprogram", small);
+        // 报警类型
+        JSONObject const2 = new JSONObject();
+        const2.put("value", type);
+        const2.put("color", "#173177");
+
+        // 报警位置
+        JSONObject thing3 = new JSONObject();
+        thing3.put("value", location);
+        thing3.put("color", "#173177");
+
+        // 报警时间
+        JSONObject time4 = new JSONObject();
+        time4.put("value", dateTime);
+        time4.put("color", "#173177");
+
         // 封装data
         JSONObject data = new JSONObject();
-        // 订单号
-        data.put("character_string1",character_string1_);
-        // 房型名称
-        data.put("thing6",thing6);
-        // 入离时间
-        data.put("time11",time11);
-        // 客户名称
-        data.put("thing10",thing10);
-        // 酒店名称
-        data.put("thing9",thing9_);
+        data.put("const2",const2);
+        data.put("thing3",thing3);
+        data.put("time4",time4);
+
         message.put("data",data);
-        return HttpsClient.sendJson("https://api.weixin.qq.com/cgi-bin/message/template/send?access_token="+access_token, message);
+
+        String s1 = HttpsClient.sendJson("https://api.weixin.qq.com/cgi-bin/message/template/send?access_token=" + access_token, message);
+        System.out.println("s1 = " + s1);
+        return s1;
+    }
+
+
+    public static String getToken() throws Exception {
+        String url="https://api.weixin.qq.com/cgi-bin/token?grant_type=client_credential&appid="+appId+"&secret="+secret;
+
+        String s = HttpsClient.httpsRequestReturnString(url, "GET", "");
+        JSONObject jsonObject = JSONObject.parseObject(s);
+        System.out.println("jsonObject = " + jsonObject);
+        String access_token = jsonObject.getString("access_token");
+//        HttpsClient.httpsRequestReturnString("https://api.weixin.qq.com/cgi-bin/message/template/send?access_token="+access_token, "POST", message.toJSONString());
+        return access_token;
     }
 
+
+
+
+    public static void main(String[] args) throws Exception {
+        String o9MsY67wqvQ__o_pOzF7oeN4MQPM = send("o9MsY67wqvQ__o_pOzF7oeN4MQPM","进入区域","IPCamera 01","2024-01-29 16:16:14");
+//        String token = getToken();
+//        System.out.println("token = " + token);
+    }
 }

+ 101 - 13
src/main/java/com/template/controller/HikvisionController.java

@@ -4,17 +4,27 @@ import com.alibaba.fastjson.JSONArray;
 import com.alibaba.fastjson.JSONObject;
 import com.baomidou.mybatisplus.core.toolkit.ObjectUtils;
 import com.template.api.HikvisionAPI;
+import com.template.api.SmartNotificationControllerAPI;
 import com.template.common.utils.GetCameraPreviewURL;
+import com.template.common.utils.Message2;
 import com.template.model.pojo.SmartFaceDiscern;
+import com.template.model.pojo.SmartNotification;
+import com.template.model.pojo.SmartUser;
 import com.template.model.pojo.SmartWarning;
 import com.template.services.SmartFaceDiscernService;
+import com.template.services.SmartNotificationService;
+import com.template.services.SmartUserService;
 import com.template.services.SmartWarningService;
+import org.aspectj.weaver.ast.Var;
 import org.springframework.beans.factory.annotation.Autowired;
 import org.springframework.web.bind.annotation.RestController;
 
 import javax.servlet.http.HttpServletRequest;
 import java.io.BufferedReader;
 import java.io.InputStreamReader;
+import java.time.LocalDateTime;
+import java.time.format.DateTimeFormatter;
+import java.util.List;
 
 @RestController
 public class HikvisionController implements HikvisionAPI {
@@ -25,9 +35,16 @@ public class HikvisionController implements HikvisionAPI {
     @Autowired
     SmartFaceDiscernService smartFaceDiscernService;
 
+    @Autowired
+    SmartUserService smartUserService;
+
+    @Autowired
+    SmartNotificationService smartNotificationService;
+
 
     /**
      * 事件订阅
+     *
      * @param request
      */
     @Override
@@ -60,9 +77,10 @@ public class HikvisionController implements HikvisionAPI {
 //                地点
             String srcName = jsonObject1.getString("srcName");
             smartWarning.setLocation(srcName);
-
+//            推送的事件
+            String pushType = "";
             if ("131588".equals(eventType)) {
-
+                pushType = "区域入侵";
                 smartWarning.setType("区域入侵");
 
                 JSONArray fielddetection = data.getJSONArray("fielddetection");
@@ -72,7 +90,9 @@ public class HikvisionController implements HikvisionAPI {
                 String imageUrl = jsonObject2.getString("imageUrl");
                 smartWarning.setImage(imageUrl);
 
-            }else if ("131586".equals(eventType)){
+            } else if ("131586".equals(eventType)) {
+                pushType = "进入危险区域";
+
                 smartWarning.setType("进入区域");
 
                 JSONArray regionEntrance = data.getJSONArray("regionEntrance");
@@ -82,7 +102,9 @@ public class HikvisionController implements HikvisionAPI {
                 String imageUrl = jsonObject2.getString("imageUrl");
                 smartWarning.setImage(imageUrl);
 
-            }else if ("131587".equals(eventType)){
+            } else if ("131587".equals(eventType)) {
+                pushType = "离开安全区域";
+
                 smartWarning.setType("离开区域");
 
                 JSONArray regionExiting = data.getJSONArray("regionExiting");
@@ -92,7 +114,9 @@ public class HikvisionController implements HikvisionAPI {
                 String imageUrl = jsonObject2.getString("imageUrl");
                 smartWarning.setImage(imageUrl);
 
-            }else if ("131605".equals(eventType)){
+            } else if ("131605".equals(eventType)) {
+                pushType = "人员倒地";
+
                 smartWarning.setType("倒地");
 
                 JSONArray fallDown = data.getJSONArray("fallDown");
@@ -106,8 +130,38 @@ public class HikvisionController implements HikvisionAPI {
 
             smartWarningService.save(smartWarning);
 
+// 获取推送人
+            List<SmartUser> smartUserList = smartUserService.getListPush();
+
+
+            if (ObjectUtils.isNotEmpty(smartUserList) && smartUserList.size() > 0) {
+                for (SmartUser smartUser : smartUserList) {
+                    SmartNotification smartNotification = new SmartNotification();
+                    smartNotification.setUserId(smartUser.getId());
+                    smartNotification.setTypeName(pushType);
+                    smartNotification.setLocation(smartWarning.getLocation());
+                    smartNotification.setImage(smartWarning.getImage());
+                    smartNotification.setDateTime(smartWarning.getDateTime());
+                    smartNotification.setType(1);
+
+                    String gzhOpenId = smartUser.getGzhOpenId();
+                    if (ObjectUtils.isNotEmpty(gzhOpenId)) {
+
+                        //                        时间格式是 yyyy-MM-dd HH:mm:ss,当前时间格式有问题
+                        DateTimeFormatter dateTimeFormatter1 = DateTimeFormatter.ofPattern("yyyy-MM-dd HH:mm:ss");
+                        LocalDateTime now = LocalDateTime.now();
+                        String format = now.format(dateTimeFormatter1);
+
+//                    公众号信息推送
+                        Message2.send(gzhOpenId, pushType, smartWarning.getLocation(), format);
+
+                        smartNotificationService.save(smartNotification);
+                    }
+
+                }
 
 
+            }
 
         } catch (Exception e) {
             e.printStackTrace();
@@ -116,6 +170,7 @@ public class HikvisionController implements HikvisionAPI {
 
     /**
      * 人脸比对
+     *
      * @param request
      */
     @Override
@@ -167,7 +222,7 @@ public class HikvisionController implements HikvisionAPI {
                 JSONObject jsonObject3 = faces.getJSONObject(0);
 //                对比成功的图片
                 JSONArray identify = jsonObject3.getJSONArray("identify");
-                if (ObjectUtils.isNotEmpty(identify)&&identify.size()>0) {
+                if (ObjectUtils.isNotEmpty(identify) && identify.size() > 0) {
 //                    取对比成功的第一张
                     JSONObject jsonObject4 = identify.getJSONObject(0);
                     JSONArray candidate = jsonObject4.getJSONArray("candidate");
@@ -196,6 +251,7 @@ public class HikvisionController implements HikvisionAPI {
 
     /**
      * 重点人员
+     *
      * @param request
      */
     @Override
@@ -209,7 +265,7 @@ public class HikvisionController implements HikvisionAPI {
             }
             JSONObject jsonObject = JSONObject.parseObject(responseStrBuilder.toString());
 
-            System.out.println("jsonObject = " + jsonObject);
+//            System.out.println("jsonObject = " + jsonObject);
 
             JSONObject params = jsonObject.getJSONObject("params");
 
@@ -255,6 +311,38 @@ public class HikvisionController implements HikvisionAPI {
 
 
                 smartWarningService.save(smartWarning);
+
+
+                // 获取推送人
+                List<SmartUser> smartUserList = smartUserService.getListPush();
+
+                String pushType = "危险人员";
+
+                for (SmartUser smartUser : smartUserList) {
+                    String gzhOpenId = smartUser.getGzhOpenId();
+                    if (ObjectUtils.isNotEmpty(gzhOpenId)) {
+                        SmartNotification smartNotification = new SmartNotification();
+                        smartNotification.setUserId(smartUser.getId());
+                        smartNotification.setUserName(faceInfoName);
+                        smartNotification.setTypeName(pushType);
+                        smartNotification.setLocation(smartWarning.getLocation());
+                        smartNotification.setImage(smartWarning.getImage());
+                        smartNotification.setDateTime(smartWarning.getDateTime());
+                        smartNotification.setType(1);
+
+                        //                        时间格式是 yyyy-MM-dd HH:mm:ss,当前时间格式有问题
+                        DateTimeFormatter dateTimeFormatter1 = DateTimeFormatter.ofPattern("yyyy-MM-dd HH:mm:ss");
+                        LocalDateTime now = LocalDateTime.now();
+                        String format = now.format(dateTimeFormatter1);
+
+//                    公众号信息推送
+                        Message2.send(gzhOpenId, pushType, smartWarning.getLocation(), format);
+
+                        smartNotificationService.save(smartNotification);
+                    }
+                }
+
+
             }
 
 
@@ -265,13 +353,13 @@ public class HikvisionController implements HikvisionAPI {
 
     @Override
     public JSONObject playback() {
-        String url="/api/video/v2/cameras/playbackURLs";
+        String url = "/api/video/v2/cameras/playbackURLs";
         JSONObject jsonBoxdy = new JSONObject();
-        jsonBoxdy.put("cameraIndexCode","ff2a2978a71c4ba0ac43a1a6be97a1a1");
-        jsonBoxdy.put("streamType",0);
-        jsonBoxdy.put("protocol","rtsp");
-        jsonBoxdy.put("transmode",1);
-        String s =GetCameraPreviewURL.CameraPreviewURL(url, jsonBoxdy);
+        jsonBoxdy.put("cameraIndexCode", "ff2a2978a71c4ba0ac43a1a6be97a1a1");
+        jsonBoxdy.put("streamType", 0);
+        jsonBoxdy.put("protocol", "rtsp");
+        jsonBoxdy.put("transmode", 1);
+        String s = GetCameraPreviewURL.CameraPreviewURL(url, jsonBoxdy);
 
         JSONObject jsonObject1 = JSONObject.parseObject(s);
         return jsonObject1;

+ 46 - 0
src/main/java/com/template/controller/SmartNotificationController.java

@@ -0,0 +1,46 @@
+package com.template.controller;
+
+
+import com.baomidou.mybatisplus.core.toolkit.ObjectUtils;
+import com.template.api.SmartNotificationControllerAPI;
+import com.template.model.pojo.SmartNotification;
+import com.template.model.pojo.SmartWarning;
+import com.template.model.result.CommonResult;
+import com.template.model.result.PageUtils;
+import com.template.services.SmartNotificationService;
+import org.springframework.beans.factory.annotation.Autowired;
+import org.springframework.web.bind.annotation.RequestMapping;
+
+import org.springframework.web.bind.annotation.RestController;
+
+/**
+ * <p>
+ * 前端控制器
+ * </p>
+ *
+ * @author ceshi
+ * @since 2024-01-30
+ */
+@RestController
+public class SmartNotificationController implements SmartNotificationControllerAPI {
+
+    @Autowired
+    SmartNotificationService smartNotificationService;
+
+
+    @Override
+    public CommonResult remindingList(Integer id, int currentPage, int pageCount, String type) {
+        if (ObjectUtils.isEmpty(currentPage) && currentPage <= 0) {
+            currentPage = 1;
+        }
+
+        if (ObjectUtils.isEmpty(pageCount) && pageCount <= 0) {
+            currentPage = 10;
+        }
+
+        PageUtils<SmartNotification> result = smartNotificationService.pageRemindingList(id, currentPage, pageCount, type);
+
+        return CommonResult.ok(result);
+    }
+}
+

+ 18 - 0
src/main/java/com/template/mapper/SmartNotificationMapper.java

@@ -0,0 +1,18 @@
+package com.template.mapper;
+
+import com.template.model.pojo.SmartNotification;
+import com.baomidou.mybatisplus.core.mapper.BaseMapper;
+import org.apache.ibatis.annotations.Mapper;
+
+/**
+ * <p>
+ *  Mapper 接口
+ * </p>
+ *
+ * @author ceshi
+ * @since 2024-01-30
+ */
+@Mapper
+public interface SmartNotificationMapper extends BaseMapper<SmartNotification> {
+
+}

+ 1 - 0
src/main/java/com/template/mapper/SmartUserMapper.java

@@ -38,4 +38,5 @@ public interface SmartUserMapper extends BaseMapper<SmartUser> {
 
     List<AffiliateParentVo> queryAffiliateParents(@Param("userId") Integer userId);
 
+    List<SmartUser> getAffiliateList(@Param("id")Integer id);
 }

+ 80 - 0
src/main/java/com/template/model/pojo/SmartNotification.java

@@ -0,0 +1,80 @@
+package com.template.model.pojo;
+
+import com.baomidou.mybatisplus.annotation.IdType;
+import java.util.Date;
+import com.baomidou.mybatisplus.annotation.Version;
+import com.baomidou.mybatisplus.annotation.TableId;
+import com.baomidou.mybatisplus.annotation.FieldFill;
+import com.baomidou.mybatisplus.annotation.TableLogic;
+import com.baomidou.mybatisplus.annotation.TableField;
+import java.io.Serializable;
+import io.swagger.annotations.ApiModel;
+import io.swagger.annotations.ApiModelProperty;
+import lombok.Data;
+import lombok.EqualsAndHashCode;
+import lombok.experimental.Accessors;
+
+/**
+ * <p>
+ * 
+ * </p>
+ *
+ * @author ceshi
+ * @since 2024-01-30
+ */
+@Data
+@EqualsAndHashCode(callSuper = false)
+@Accessors(chain = true)
+@ApiModel(value="SmartNotification对象", description="")
+public class SmartNotification implements Serializable {
+
+    private static final long serialVersionUID = 1L;
+
+    @ApiModelProperty(value = " ")
+    @TableId(value = "id", type = IdType.AUTO)
+    private Integer id;
+
+    @ApiModelProperty(value = "可查看的userId")
+    private Integer userId;
+
+    @ApiModelProperty(value = "名字")
+    private String userName;
+
+    @ApiModelProperty(value = "事件类型名称")
+    private String typeName;
+
+    @ApiModelProperty(value = "地点")
+    private String location;
+
+    @ApiModelProperty(value = "图片")
+    private String image;
+
+    @ApiModelProperty(value = "时间")
+    private String dateTime;
+
+    @ApiModelProperty(value = "类型——1:预警推送,2:学生轨迹")
+    private Integer type;
+
+    @ApiModelProperty(value = "创建时间")
+    @TableField(fill = FieldFill.INSERT)
+    private Date createTime;
+
+    @ApiModelProperty(value = "更新时间")
+    @TableField(fill = FieldFill.INSERT_UPDATE)
+    private Date updateTime;
+
+    @ApiModelProperty(value = "创建人员")
+    @TableField(fill = FieldFill.INSERT)
+    private String createUser;
+
+    @ApiModelProperty(value = "更新人员")
+    @TableField(fill = FieldFill.INSERT_UPDATE)
+    private String updateUser;
+
+    @ApiModelProperty(value = "逻辑删除 未删除:0;删除:1")
+    @TableField(fill = FieldFill.INSERT)
+    @TableLogic
+    private Integer deleted;
+
+
+}

+ 18 - 0
src/main/java/com/template/services/SmartNotificationService.java

@@ -0,0 +1,18 @@
+package com.template.services;
+
+import com.template.model.pojo.SmartNotification;
+import com.baomidou.mybatisplus.extension.service.IService;
+import com.template.model.result.PageUtils;
+
+/**
+ * <p>
+ *  服务类
+ * </p>
+ *
+ * @author ceshi
+ * @since 2024-01-30
+ */
+public interface SmartNotificationService extends IService<SmartNotification> {
+
+    PageUtils<SmartNotification> pageRemindingList(Integer id, int currentPage, int pageCount, String type);
+}

+ 12 - 1
src/main/java/com/template/services/SmartUserService.java

@@ -71,5 +71,16 @@ public interface SmartUserService extends IService<SmartUser> {
 
     List<SmartUser> getSmartUserByxwuids(List<String> xwuids);
 
-    List<SmartUser> querySmartUserByCardNos(List<String> cardNos);
+    /**
+     * 获取可推送的人
+     * @return
+     */
+    List<SmartUser> getListPush();
+
+    /**
+     * 通过id查找所关联的人
+     * @param id
+     * @return
+     */
+    List<SmartUser> getAffiliateList(Integer id);
 }

+ 1 - 0
src/main/java/com/template/services/SmartWarningService.java

@@ -1,5 +1,6 @@
 package com.template.services;
 
+import com.template.model.pojo.SmartUser;
 import com.template.model.pojo.SmartWarning;
 import com.template.model.pojo.SmartWarning;
 import com.baomidou.mybatisplus.extension.service.IService;

+ 90 - 43
src/main/java/com/template/services/impl/SmartFaceDiscernServiceImpl.java

@@ -5,15 +5,14 @@ import com.alibaba.fastjson.JSONObject;
 import com.baomidou.mybatisplus.core.conditions.Wrapper;
 import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper;
 import com.baomidou.mybatisplus.core.toolkit.ObjectUtils;
-import com.template.common.utils.AesTestOne;
-import com.template.common.utils.CommonUtil;
-import com.template.common.utils.RequestUtils;
-import com.template.common.utils.TimeExchange;
+import com.template.common.utils.*;
 import com.template.model.pojo.SmartFaceDiscern;
 import com.template.mapper.SmartFaceDiscernMapper;
+import com.template.model.pojo.SmartNotification;
 import com.template.model.pojo.SmartUser;
 import com.template.services.SmartFaceDiscernService;
 import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
+import com.template.services.SmartNotificationService;
 import com.template.services.SmartUserService;
 import org.springframework.beans.factory.annotation.Autowired;
 import org.springframework.scheduling.annotation.Scheduled;
@@ -40,6 +39,9 @@ public class SmartFaceDiscernServiceImpl extends ServiceImpl<SmartFaceDiscernMap
     @Autowired
     SmartUserService smartUserService;
 
+    @Autowired
+    SmartNotificationService smartNotificationService;
+
 
     //    static String appid = "sc5efc60f2bd373df9";
     static String appid = "sc1eb792c1ea3237e9";
@@ -51,7 +53,7 @@ public class SmartFaceDiscernServiceImpl extends ServiceImpl<SmartFaceDiscernMap
     private Integer page = 1;
     private Integer size = 20;
 
-//    @Scheduled(cron = "0 0/30 * * * ? ")
+    @Scheduled(cron = "0 0/50 * * * ? ")
     public void baiS() {
         try {
             getFaceDiscern(page, size);
@@ -107,73 +109,118 @@ public class SmartFaceDiscernServiceImpl extends ServiceImpl<SmartFaceDiscernMap
         String decodedUrl = URLDecoder.decode(data1, "UTF-8");
 
         String decrypt = decrypt(decodedUrl, appSecret);
-        System.out.println("decrypt = " + decrypt);
-        if (ObjectUtils.isNotEmpty(decrypt)) {
+//        System.out.println("decrypt = " + decrypt);
+        if (ObjectUtils.isNotEmpty(decrypt)&& decrypt!="") {
             JSONObject jsonObject2 = JSONObject.parseObject(decrypt);
+
+            if (ObjectUtils.isNotEmpty(jsonObject2)) {
+
+
 //            获取总数
-            Integer total = Integer.valueOf(jsonObject2.getString("total"));
+                Integer total = Integer.valueOf(jsonObject2.getString("total"));
+ //               System.out.println("total = " + total);
 
-            if (total > pageindex * pagesize) {
-                page = pageindex + 1;
-            } else {
-                page = pageindex - 1;
-            }
+                if (total > pageindex * pagesize) {
+                    page = pageindex + 1;
+                } else {
+                    page = pageindex - 1;
+                }
 
 
-            JSONArray data2 = jsonObject2.getJSONArray("data");
-            for (int i = 0; i < data2.size(); i++) {
-                JSONObject jsonObject3 = data2.getJSONObject(i);
-                SmartFaceDiscern smartFaceDiscern = new SmartFaceDiscern();
+                JSONArray data2 = jsonObject2.getJSONArray("data");
+                for (int i = 0; i < data2.size(); i++) {
+                    JSONObject jsonObject3 = data2.getJSONObject(i);
+                    SmartFaceDiscern smartFaceDiscern = new SmartFaceDiscern();
 
 //                事件
-                String deviceName = jsonObject3.getString("device_name");
-                smartFaceDiscern.setType(deviceName);
+                    String deviceName = jsonObject3.getString("device_name");
+                    smartFaceDiscern.setType(deviceName);
 
 //                地点
-                String deviceArea = jsonObject3.getString("device_area");
-                smartFaceDiscern.setLocation(deviceArea);
+                    String deviceArea = jsonObject3.getString("device_area");
+                    smartFaceDiscern.setLocation(deviceArea);
 
 //                图片
-                String recordPhoto = jsonObject3.getString("record_photo");
-                smartFaceDiscern.setImage(recordPhoto);
+                    String recordPhoto = jsonObject3.getString("record_photo");
+                    smartFaceDiscern.setImage(recordPhoto);
 
 //                时间
-                String recordAddtime = jsonObject3.getString("record_addtime");
-                smartFaceDiscern.setDateTime(recordAddtime);
+                    String recordAddtime = jsonObject3.getString("record_addtime");
+                    smartFaceDiscern.setDateTime(recordAddtime);
 
 //                名字
-                String student_name = jsonObject3.getString("student_name");
-                smartFaceDiscern.setName(student_name);
+                    String student_name = jsonObject3.getString("student_name");
+                    smartFaceDiscern.setName(student_name);
 //                 学号
-                String student_number = jsonObject3.getString("student_number");
+                    String student_number = jsonObject3.getString("student_number");
 //                编号
-                String student_no = jsonObject3.getString("student_no");
+                    String student_no = jsonObject3.getString("student_no");
 
-                LambdaQueryWrapper<SmartUser> wrapper = new LambdaQueryWrapper<>();
-                wrapper.eq(SmartUser::getBsStudentNo, student_no);
-                wrapper.eq(SmartUser::getName, student_name);
-                SmartUser smartUser = smartUserService.getOne(wrapper);
+                    LambdaQueryWrapper<SmartUser> wrapper = new LambdaQueryWrapper<>();
+                    wrapper.eq(SmartUser::getBsStudentNo, student_no);
+                    wrapper.eq(SmartUser::getName, student_name);
+                    SmartUser smartUser = smartUserService.getOne(wrapper);
 
-                if (ObjectUtils.isNotEmpty(smartUser)) {
-                    smartFaceDiscern.setUserId(smartUser.getId());
+                    if (ObjectUtils.isNotEmpty(smartUser)) {
+                        smartFaceDiscern.setUserId(smartUser.getId());
 
 //                    判断是否已经添加
-                    LambdaQueryWrapper<SmartFaceDiscern> wrapperFD = new LambdaQueryWrapper<>();
-                    wrapperFD.eq(SmartFaceDiscern::getDateTime, recordAddtime)
-                            .eq(SmartFaceDiscern::getUserId, smartUser.getId());
-                    SmartFaceDiscern one = this.getOne(wrapperFD);
+                        LambdaQueryWrapper<SmartFaceDiscern> wrapperFD = new LambdaQueryWrapper<>();
+                        wrapperFD.eq(SmartFaceDiscern::getDateTime, recordAddtime)
+                                .eq(SmartFaceDiscern::getUserId, smartUser.getId());
+                        SmartFaceDiscern one = this.getOne(wrapperFD);
+
+                        if (ObjectUtils.isEmpty(one)) {
+                            this.save(smartFaceDiscern);
+
+//                        通过学生id找到关联的家长affiliate,并找到公众号,如果openid为空则不传
+                            List<SmartUser> userList = smartUserService.getAffiliateList(smartUser.getId());
+                            if (ObjectUtils.isNotEmpty(userList) && userList.size() > 0) {
+                                for (SmartUser user : userList) {
+                                    String gzhOpenId = user.getGzhOpenId();
+                                    if (ObjectUtils.isNotEmpty(gzhOpenId)) {
+                                        String pushType = "";
+                                        if (deviceName.contains("进校")) {
+                                            pushType = "进入大门";
+                                        } else if (deviceName.contains("出校")) {
+                                            pushType = "离开大门";
+                                        }
+
+                                        //                        时间格式是 yyyy-MM-dd HH:mm:ss,当前时间格式有问题
+
+                                        LocalDateTime date = LocalDateTime.now();
+                                        String format = date.format(dateTimeFormatter1);
+
+                                        //                    公众号信息推送
+                                        Message2.send(gzhOpenId, pushType, deviceArea, format);
+
+                                        SmartNotification smartNotification = new SmartNotification();
+                                        smartNotification.setUserId(smartUser.getId());
+                                        smartNotification.setUserName(smartUser.getName());
+                                        smartNotification.setTypeName(pushType);
+                                        smartNotification.setLocation(deviceArea);
+                                        smartNotification.setImage(recordPhoto);
+                                        smartNotification.setDateTime(recordAddtime);
+                                        smartNotification.setType(2);
+
+                                        smartNotificationService.save(smartNotification);
+
+                                    }
+
+                                }
+
+                            }
+
+                        }
 
-                    if (ObjectUtils.isEmpty(one)) {
-                        this.save(smartFaceDiscern);
                     }
 
                 }
-
             }
-
         }
     }
 
+
     @Override
     public List<SmartFaceDiscern> track(String stateTime, String endTime, Integer id) {
 

+ 38 - 0
src/main/java/com/template/services/impl/SmartNotificationServiceImpl.java

@@ -0,0 +1,38 @@
+package com.template.services.impl;
+
+import com.baomidou.mybatisplus.core.conditions.Wrapper;
+import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper;
+import com.baomidou.mybatisplus.core.metadata.IPage;
+import com.baomidou.mybatisplus.core.toolkit.ObjectUtils;
+import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
+import com.template.model.pojo.SmartNotification;
+import com.template.mapper.SmartNotificationMapper;
+import com.template.model.result.PageUtils;
+import com.template.services.SmartNotificationService;
+import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
+import org.springframework.stereotype.Service;
+
+/**
+ * <p>
+ *  服务实现类
+ * </p>
+ *
+ * @author ceshi
+ * @since 2024-01-30
+ */
+@Service
+public class SmartNotificationServiceImpl extends ServiceImpl<SmartNotificationMapper, SmartNotification> implements SmartNotificationService {
+
+    @Override
+    public PageUtils<SmartNotification> pageRemindingList(Integer id, int currentPage, int pageCount, String type) {
+
+        LambdaQueryWrapper<SmartNotification> wrapper=new LambdaQueryWrapper<>();
+        wrapper.eq(SmartNotification::getUserId,id)
+                .eq(ObjectUtils.isNotEmpty(type),SmartNotification::getType,type)
+                .orderByDesc(SmartNotification::getDateTime);
+
+        IPage<SmartNotification> page = this.page(new Page<>(currentPage, pageCount), wrapper);
+
+        return new PageUtils<>(page);
+    }
+}

+ 20 - 0
src/main/java/com/template/services/impl/SmartUserServiceImpl.java

@@ -1,5 +1,7 @@
 package com.template.services.impl;
 
+import com.baomidou.mybatisplus.core.conditions.Wrapper;
+import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper;
 import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
 import com.baomidou.mybatisplus.core.metadata.IPage;
 import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
@@ -7,6 +9,7 @@ import com.template.mapper.SmartUserMapper;
 import com.template.model.dto.WarningUserDto;
 import com.template.model.enumModel.eIdentityStatu;
 import com.template.model.pojo.SmartUser;
+import com.template.model.pojo.SmartWarning;
 import com.template.model.result.PageUtils;
 import com.template.model.vo.*;
 import com.template.services.SmartUserService;
@@ -163,6 +166,23 @@ public class SmartUserServiceImpl extends ServiceImpl<SmartUserMapper, SmartUser
     }
 
     @Override
+    public List<SmartUser> getListPush() {
+
+        LambdaQueryWrapper<SmartUser> wrapper=new LambdaQueryWrapper<>();
+        wrapper.eq(SmartUser::getIsCancel,0)
+                .eq(SmartUser::getIsPush,1);
+
+        List<SmartUser> smartUserList = this.list(wrapper);
+
+        return smartUserList;
+    }
+
+    @Override
+    public List<SmartUser> getAffiliateList(Integer id) {
+        return smartUserMapper.getAffiliateList(id);
+    }
+
+    @Override
     public List<AffiliateUserVo> queryAffiliateUserById(Integer id) {
         List<AffiliateUserVo> result = smartUserMapper.queryAffiliateUserById(id);
         return result;

+ 4 - 0
src/main/java/com/template/services/impl/SmartWarningServiceImpl.java

@@ -1,11 +1,13 @@
 package com.template.services.impl;
 
+import com.baomidou.mybatisplus.core.conditions.Wrapper;
 import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper;
 import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
 import com.baomidou.mybatisplus.core.metadata.IPage;
 import com.baomidou.mybatisplus.core.toolkit.ObjectUtils;
 import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
 import com.template.mapper.SmartWarningMapper;
+import com.template.model.pojo.SmartUser;
 import com.template.model.pojo.SmartWarning;
 import com.template.model.pojo.SmartWarning;
 import com.template.mapper.SmartWarningMapper;
@@ -93,4 +95,6 @@ public class SmartWarningServiceImpl extends ServiceImpl<SmartWarningMapper, Sma
     }
 
 
+
+
 }

+ 5 - 0
src/main/resources/mapper/template/SmartNotificationMapper.xml

@@ -0,0 +1,5 @@
+<?xml version="1.0" encoding="UTF-8"?>
+<!DOCTYPE mapper PUBLIC "-//mybatis.org//DTD Mapper 3.0//EN" "http://mybatis.org/dtd/mybatis-3-mapper.dtd">
+<mapper namespace="com.template.mapper.SmartNotificationMapper">
+
+</mapper>

+ 8 - 0
src/main/resources/mapper/template/SmartUserMapper.xml

@@ -159,4 +159,12 @@
         </if>
     </select>
 
+    <select id="getAffiliateList" resultType="com.template.model.pojo.SmartUser">
+        SELECT * FROM `smart_user`
+        where deleted = 0 and is_cancel=0
+        <if test="id != null and id != ''">
+            and FIND_IN_SET(#{id},affiliate)
+        </if>
+    </select>
+
 </mapper>