Browse Source

学生进出,通知家长

dzx 9 months ago
parent
commit
a62cf2c828

+ 64 - 1
src/main/java/com/xjrsoft/module/hikvision/controller/EventController.java

@@ -1,14 +1,26 @@
 package com.xjrsoft.module.hikvision.controller;
 
 import cn.hutool.db.Db;
+import com.alibaba.fastjson.JSONObject;
+import com.github.yulichang.wrapper.MPJLambdaWrapper;
 import com.google.gson.JsonArray;
+import com.google.gson.JsonElement;
 import com.google.gson.JsonObject;
+import com.google.gson.JsonParser;
 import com.xjrsoft.common.constant.GlobalConstant;
 import com.xjrsoft.common.model.result.RT;
 import com.xjrsoft.common.utils.DatasourceUtil;
 import com.xjrsoft.config.HikvisionConfig;
+import com.xjrsoft.module.base.entity.BaseClass;
+import com.xjrsoft.module.base.service.IBaseClassService;
+import com.xjrsoft.module.concat.service.IXjrUserService;
 import com.xjrsoft.module.hikvision.util.ApiUtil;
 import com.xjrsoft.module.hikvision.util.OutInRecordUtil;
+import com.xjrsoft.module.organization.dto.WeChatSendMessageDto;
+import com.xjrsoft.module.organization.entity.UserStudent;
+import com.xjrsoft.module.organization.service.IWeChatService;
+import com.xjrsoft.module.student.entity.BaseStudentSchoolRoll;
+import com.xjrsoft.module.teacher.entity.XjrUser;
 import com.xjrsoft.module.teacher.mapper.FaceImportMapper;
 import io.swagger.annotations.Api;
 import io.swagger.annotations.ApiOperation;
@@ -23,6 +35,8 @@ import org.springframework.web.bind.annotation.RestController;
 import javax.sql.DataSource;
 import java.sql.SQLException;
 import java.text.ParseException;
+import java.util.List;
+import java.util.Objects;
 
 @RestController
 @RequestMapping("/event")
@@ -36,6 +50,9 @@ public class EventController {
     private final Db use = Db.use(datasource);
     private final FaceImportMapper faceImportMapper;
     private final HikvisionConfig hikvisionConfig;
+    private final IBaseClassService classService;
+    private final IWeChatService weChatService;
+    private final IXjrUserService xjrUserService;
 
     @PostMapping("/receiveCar")
     @ApiOperation(value = "接收车辆事件")
@@ -59,7 +76,53 @@ public class EventController {
         log.info("Received event data: {}", eventData);
         new Thread(() -> {
             try {
-                outInRecordUtil.GetTeacherAndStudentRecordsTest(use, faceImportMapper, eventData);
+                JsonObject data = new JsonParser().parse(eventData).getAsJsonObject();
+                outInRecordUtil.GetTeacherAndStudentRecordsTest(use, faceImportMapper, data);
+
+                JsonObject paramsObject = data.getAsJsonObject("params");
+                JsonArray eventsArray = paramsObject.getAsJsonArray("events");
+                for (JsonElement eventElement : eventsArray) {
+                    JsonObject eventObject = eventElement.getAsJsonObject();
+                    JsonObject dataObject = eventObject.getAsJsonObject("data");
+
+                    String idNum = null;
+                    if (dataObject.has("ExtEventPersonNo")) {
+                        idNum = dataObject.get("ExtEventPersonNo").getAsString();
+                    }
+                    String happenTime = eventObject.get("happenTime").getAsString();
+                    String recordTimeStr = outInRecordUtil.ChangeTime(happenTime);
+                    if (idNum == null) continue;
+                    if (!Objects.equals(faceImportMapper.IsStudentTypeByPersonId(Long.valueOf(idNum)), "学生")) {
+                        continue;
+                    }
+
+                    List<XjrUser> userList = xjrUserService.list(
+                        new MPJLambdaWrapper<XjrUser>()
+                        .leftJoin(UserStudent.class, UserStudent::getUserId, XjrUser::getId)
+                        .eq(UserStudent::getStudentId, idNum)
+                    );
+
+                    for (XjrUser member : userList) {
+                        XjrUser student = xjrUserService.getById(idNum);
+                        BaseClass baseClass = classService.getOne(
+                            new MPJLambdaWrapper<BaseClass>()
+                            .leftJoin(BaseStudentSchoolRoll.class, BaseStudentSchoolRoll::getClassId, BaseClass::getId)
+                            .eq(BaseStudentSchoolRoll::getUserId, student.getId())
+                        );
+
+                        WeChatSendMessageDto weChatSendMessageDto = new WeChatSendMessageDto();
+                        weChatSendMessageDto.setUserId(member.getOpenId());
+                        weChatSendMessageDto.setTemplateId("ERkMebHjsziZO6WBrlzsbENiEuRR4vrlhJw5LR4aDr8");
+                        weChatSendMessageDto.setMsgId(member.getId().toString());
+                        JSONObject paramJson = new JSONObject();
+
+                        paramJson.put("thing1", student.getName());
+                        paramJson.put("time3", recordTimeStr);
+                        paramJson.put("thing2", baseClass.getName());
+                        weChatSendMessageDto.setContent(paramJson);
+                        weChatService.sendTemplateMessage(weChatSendMessageDto);
+                    }
+                }
             } catch (SQLException | ParseException e) {
                 log.error("Error processing event data", e);
             }

+ 3 - 4
src/main/java/com/xjrsoft/module/hikvision/util/OutInRecordUtil.java

@@ -443,21 +443,20 @@ public class OutInRecordUtil {
         return apiUtil.doPost(apiPath, String.valueOf(paramJson), null);
     }
 
-    private String ChangeTime(String recordTime) throws ParseException {
+    public String ChangeTime(String recordTime) throws ParseException {
         SimpleDateFormat isoFormat = new SimpleDateFormat("yyyy-MM-dd'T'HH:mm:ss");
         SimpleDateFormat mysqlFormat = new SimpleDateFormat("yyyy-MM-dd HH:mm:ss");
         Date date = isoFormat.parse(recordTime);
         return mysqlFormat.format(date);
     }
 
-    public void GetTeacherAndStudentRecordsTest(Db use, FaceImportMapper faceImportMapper, String data) throws SQLException, ParseException {
+    public void GetTeacherAndStudentRecordsTest(Db use, FaceImportMapper faceImportMapper, JsonObject data) throws SQLException, ParseException {
         try {
             List<String> teacherEventIdList = faceImportMapper.GetTeacherUrlList();
             List<String> studentEventIdList = faceImportMapper.GetStudentUrlList();
             DateTimeFormatter formatter = DateTimeFormatter.ofPattern("yyyy-MM-dd HH:mm:ss");
 
-            JsonObject jsonObject = new Gson().fromJson(data, JsonObject.class);
-            JsonObject paramsObject = jsonObject.getAsJsonObject("params");
+            JsonObject paramsObject = data.getAsJsonObject("params");
             JsonArray eventsArray = paramsObject.getAsJsonArray("events");
 
             for (JsonElement eventElement : eventsArray) {

+ 2 - 0
src/main/java/com/xjrsoft/module/student/entity/BaseStudentFamilyMember.java

@@ -179,4 +179,6 @@ public class BaseStudentFamilyMember implements Serializable {
     private String wechat;
 
 
+    @ApiModelProperty("微信openId")
+    private String openId;
 }

+ 15 - 0
src/main/java/com/xjrsoft/module/student/service/IBaseStudentFamilyMemberService.java

@@ -0,0 +1,15 @@
+package com.xjrsoft.module.student.service;
+
+import com.github.yulichang.base.MPJBaseService;
+import com.xjrsoft.module.student.entity.BaseStudentFamilyMember;
+
+/**
+* @title: 学生家长
+* @Author dzx
+* @Date: 2024年6月4日
+* @Version 1.0
+*/
+
+public interface IBaseStudentFamilyMemberService extends MPJBaseService<BaseStudentFamilyMember> {
+
+}

+ 23 - 0
src/main/java/com/xjrsoft/module/student/service/impl/BaseStudentFamilyMemberServiceImpl.java

@@ -0,0 +1,23 @@
+package com.xjrsoft.module.student.service.impl;
+
+import com.github.yulichang.base.MPJBaseServiceImpl;
+import com.xjrsoft.module.student.entity.BaseStudentFamily;
+import com.xjrsoft.module.student.entity.BaseStudentFamilyMember;
+import com.xjrsoft.module.student.mapper.BaseStudentFamilyMapper;
+import com.xjrsoft.module.student.mapper.BaseStudentFamilyMemberMapper;
+import com.xjrsoft.module.student.service.IBaseStudentFamilyMemberService;
+import com.xjrsoft.module.student.service.IBaseStudentFamilyService;
+import lombok.AllArgsConstructor;
+import org.springframework.stereotype.Service;
+
+/**
+ * @title: 学生家长
+ * @Author dzx
+ * @Date: 2024年6月4日
+ * @Version 1.0
+*/
+@Service
+@AllArgsConstructor
+public class BaseStudentFamilyMemberServiceImpl extends MPJBaseServiceImpl<BaseStudentFamilyMemberMapper, BaseStudentFamilyMember> implements IBaseStudentFamilyMemberService {
+
+}