|
@@ -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);
|
|
|
}
|