Forráskód Böngészése

feat(national-motion-system): 添加设备开门记录功能

- 新增 AppGmtInfo 实体类用于存储开门记录
- 新增 AppGmtInfoMapper 接口用于操作开门记录数据
- 修改 HikiotTool 类,调整查询开门记录的参数
- 重构 OrTeachingJobService 类,实现同步开门记录到数据库
- 移除不必要的 AppIsin、AppOrder等相关代码
- 优化数据提取和处理逻辑,直接保存原始记录到 AppGmtInfo表
SheepHy 3 hete
szülő
commit
2df30ae203

+ 1 - 1
national-motion-module-system/national-motion-system-biz/src/main/java/org/jeecg/modules/hikiot/HikiotTool.java

@@ -558,7 +558,7 @@ public class HikiotTool {
     }
 
     public static void main(String[] args) throws IOException, InterruptedException {
-        queryOpenDoorRecord(1,10000,new Date());
+        queryOpenDoorRecord(1,10000,null);
 //        addUser(new Date(),"FX0889961","Sheep123","10011",null);
 //        addFace("FX0889961","10011","https://national-motion.oss-cn-beijing.aliyuncs.com/opt/upFiles/tmp_81fc8aa195d37dac70fd57221d82845e_1756361097600.jpg");
 //        addUser(new Date(),"FX0889961","Sheep123","10011");

+ 24 - 87
national-motion-module-system/national-motion-system-biz/src/main/java/org/jeecg/modules/quartz/job/OrTeachingJobService.java

@@ -17,9 +17,7 @@ import org.jeecg.modules.quartz.utils.HolidayUtil;
 import org.jeecg.modules.system.app.dto.TeachingDayDTO;
 import org.jeecg.modules.system.app.entity.*;
 import org.jeecg.modules.system.app.mapper.AppDeviceMapper;
-import org.jeecg.modules.system.app.mapper.AppIsinMapper;
-import org.jeecg.modules.system.app.mapper.AppOrderMapper;
-import org.jeecg.modules.system.app.mapper.AppOrderProInfoMapper;
+import org.jeecg.modules.system.app.mapper.AppGmtInfoMapper;
 import org.jeecg.modules.system.app.service.IAppSitePlaceService;
 import org.jeecg.modules.system.app.service.IAppSitePriceRulesService;
 import org.jeecg.modules.system.app.service.IAppSiteService;
@@ -35,7 +33,6 @@ import java.util.ArrayList;
 import java.util.Date;
 import java.util.List;
 import java.util.Map;
-import java.util.stream.Collectors;
 
 import static com.alibaba.dashscope.utils.JsonUtils.gson;
 import static org.jeecg.modules.hikiot.HikiotTool.deleteExpiredVisitors;
@@ -63,11 +60,7 @@ public class OrTeachingJobService {
     private AppDeviceMapper appDeviceMapper;
 
     @Resource
-    private AppIsinMapper appIsinMapper;
-    @Resource
-    private AppOrderProInfoMapper appOrderProInfoMapper;
-    @Resource
-    private AppOrderMapper appOrderMapper;
+    private AppGmtInfoMapper appGmtInfoMapper;
 
     @Scheduled(cron = "0 0 0 1 12 *")
     @Transactional(rollbackFor = Exception.class)
@@ -242,45 +235,26 @@ public class OrTeachingJobService {
      * @Param
      * @return
      **/
-//    @Scheduled(fixedDelay = 30000)
+    @Scheduled(fixedDelay = 300000)
     public void synchronousDoorOpeningAndClosingRecords(){
         try {
             List<DoorRecordDTO> allRecords = fetchAllDoorRecords();
-            List<ExtractedData> extractedData = extractRequiredData(allRecords);
-
-            extractedData.forEach(data -> {
+            allRecords.forEach(data -> {
                 log.info("提取数据: {}", data);
-                AppIsin appIsin = appIsinMapper.selectOne(Wrappers.<AppIsin>lambdaQuery().eq(AppIsin::getOrderProInfoId, data.getEmployeeNo()));
-                if(null != appIsin){
-                    appIsin.setUseTime(DateUtils.str2Date(data.getGmtCreate(), new SimpleDateFormat("yyyy-MM-dd HH:mm:ss")));
-                    appIsin.setUpdateTime(DateUtils.str2Date(data.getGmtCreate(), new SimpleDateFormat("yyyy-MM-dd HH:mm:ss")));
-                    appIsin.setIsinStatus(1);
-                    appIsin.setUseImage(data.getPortraitUrl());
-                    appIsin.setOriginId(data.getOriginId());
-                    appIsinMapper.updateById(appIsin);
-                    AppOrderProInfo orderProInfo = appOrderProInfoMapper.selectById(appIsin.getOrderProInfoId());
-                    orderProInfo.setOrderStatus(2);
-                    appOrderProInfoMapper.updateById(orderProInfo);
-                    // 查询当前订单的所有 AppOrderProInfo 记录
-                    List<AppOrderProInfo> orderProInfoList = appOrderProInfoMapper.selectList(
-                            Wrappers.<AppOrderProInfo>lambdaQuery()
-                                    .eq(AppOrderProInfo::getOrderCode, orderProInfo.getOrderCode())
-                    );
-                    // 判断所有子订单的 orderStatus 是否都为 2
-                    if (orderProInfoList != null && !orderProInfoList.isEmpty() &&
-                            orderProInfoList.stream().allMatch(opi -> opi.getOrderStatus() == 2)) {
-                        // 查询主订单
-                        AppOrder appOrder = appOrderMapper.selectOne(
-                                Wrappers.<AppOrder>lambdaQuery()
-                                        .eq(AppOrder::getOrderCode, orderProInfo.getOrderCode())
-                        );
-                        if (appOrder != null) {
-                            // 更新主订单状态为 2
-                            appOrder.setOrderStatus(2);
-                            appOrderMapper.updateById(appOrder);
-                        }
-                    }
-                }
+                appGmtInfoMapper.insert(new AppGmtInfo()
+                        .setFamilyId(data.getEmployeeNo())
+                        .setSiteId(appDeviceMapper.selectOne(Wrappers.<AppDevice>lambdaQuery()
+                                .eq(AppDevice::getDeviceSerial, data.getDeviceSerial())).getSiteId())
+                        .setAuthResultMsg(data.getAuthResultMsg())
+                        .setGmtCreate(DateUtils.str2Date(data.getGmtCreate(), new SimpleDateFormat("yyyy-MM-dd HH:mm:ss")))
+                        .setPicUrl(data.getPicUrl())
+                        .setSecMsgCode(data.getSecMsgCode())
+                        .setOriginId(data.getOriginId())
+                        .setDeviceSerial(data.getDeviceSerial().split("-")[0])
+                        .setCreateTime(new Date())
+                        .setUpdateTime(new Date())
+                        .setDeviceSerialNo(data.getDeviceSerial()));
+
             });
 
         } catch (Exception e) {
@@ -295,16 +269,14 @@ public class OrTeachingJobService {
         List<DoorRecordDTO> allRecords = new ArrayList<>();
         int pageNum = 1;
         int pageSize = 10000;
-        AppIsin appIsin = appIsinMapper.selectOne(Wrappers.<AppIsin>lambdaQuery()
-                .eq(AppIsin::getIsinStatus, 0)
-                .eq(AppIsin::getOriginId, null)
-                .orderByDesc(AppIsin::getUpdateTime)
+        AppGmtInfo appGmtInfo = appGmtInfoMapper.selectOne(Wrappers.<AppGmtInfo>lambdaQuery()
+                .orderByDesc(AppGmtInfo::getGmtCreate)
                 .last("limit 1"));
         try {
             while (true) {
                 JSONObject response;
-                if(null != appIsin && null != appIsin.getUpdateTime()){
-                    response = gson.fromJson(queryOpenDoorRecord(pageNum, pageSize, appIsin.getUpdateTime()), JSONObject.class);
+                if(null != appGmtInfo && null != appGmtInfo.getGmtCreate()){
+                    response = gson.fromJson(queryOpenDoorRecord(pageNum, pageSize, appGmtInfo.getGmtCreate()), JSONObject.class);
                 }else {
                     response = gson.fromJson(queryOpenDoorRecord(pageNum, pageSize,null), JSONObject.class);
                 }
@@ -337,29 +309,6 @@ public class OrTeachingJobService {
         return allRecords;
     }
 
-    /**
-     * 提取和过滤数据
-     */
-    private List<ExtractedData> extractRequiredData(List<DoorRecordDTO> records) {
-        List<ExtractedData> result = new ArrayList<>();
-        if (records != null && !records.isEmpty()) {
-            result = records.stream()
-                    .filter(record -> "ACE-5-75".equals(record.getSecMsgCode()))
-                    .map(record -> new ExtractedData(
-                            record.getEmployeeNo(),
-                            record.getAuthResultMsg(),
-                            record.getGmtCreate(),
-                            record.getPortraitUrl(),
-                            record.getSecMsgCode(),
-                            record.getOriginId()
-                    ))
-                    .filter(data -> data.getEmployeeNo() != null)  // 可选:排除无效数据
-                    .collect(Collectors.toList());
-        }
-
-        return result;
-    }
-
     /**
      * 验证响应是否有效
      */
@@ -377,22 +326,10 @@ public class OrTeachingJobService {
         private String employeeNo;
         private String authResultMsg;
         private String gmtCreate;
-        private String portraitUrl;
+        private String picUrl;
         private String secMsgCode;
         private String originId;
+        private String deviceSerial;
     }
 
-    /**
-     * DTO类 - 提取结果
-     */
-    @Data
-    @AllArgsConstructor
-    private static class ExtractedData {
-        private String employeeNo;
-        private String authResultMsg;
-        private String gmtCreate;
-        private String portraitUrl;
-        private String secMsgCode;
-        private String originId;
-    }
 }

+ 56 - 0
national-motion-module-system/national-motion-system-biz/src/main/java/org/jeecg/modules/system/app/entity/AppGmtInfo.java

@@ -0,0 +1,56 @@
+package org.jeecg.modules.system.app.entity;
+
+import com.baomidou.mybatisplus.annotation.IdType;
+import com.baomidou.mybatisplus.annotation.TableId;
+import com.baomidou.mybatisplus.annotation.TableName;
+import com.fasterxml.jackson.annotation.JsonFormat;
+import io.swagger.v3.oas.annotations.media.Schema;
+import lombok.Data;
+import lombok.EqualsAndHashCode;
+import lombok.experimental.Accessors;
+import org.jeecgframework.poi.excel.annotation.Excel;
+import org.springframework.format.annotation.DateTimeFormat;
+
+import java.util.Date;
+
+@Data
+@TableName("nm_gmt_info")
+@Accessors(chain = true)
+@EqualsAndHashCode(callSuper = false)
+@Schema(description="设备开门记录表")
+public class AppGmtInfo {
+    /**id*/
+    @TableId(type = IdType.ASSIGN_ID)
+    @Schema(description = "id")
+    private String id;
+    @Schema(description = "familyId")
+    private String familyId;
+    @Schema(description = "siteId")
+    private String siteId;
+    @Schema(description = "认证状态")
+    private String authResultMsg;
+    @Excel(name = "开门时间", width = 20, format = "yyyy-MM-dd HH:mm:ss")
+    @JsonFormat(timezone = "GMT+8",pattern = "yyyy-MM-dd HH:mm:ss")
+    @DateTimeFormat(pattern="yyyy-MM-dd HH:mm:ss")
+    @Schema(description = "开门时间")
+    private Date gmtCreate;
+    @Schema(description = "认证照片")
+    private String picUrl;
+    @Schema(description = "认证编码")
+    private String secMsgCode;
+    @Schema(description = "海康关联ID")
+    private String originId;
+    @Schema(description = "设备编码")
+    private String deviceSerial;
+    @Schema(description = "设备号")
+    private String deviceSerialNo;
+    @JsonFormat(timezone = "GMT+8",pattern = "yyyy-MM-dd HH:mm:ss")
+    @DateTimeFormat(pattern="yyyy-MM-dd HH:mm:ss")
+    @Schema(description = "创建时间;创建时间")
+    private Date createTime;
+    @JsonFormat(timezone = "GMT+8",pattern = "yyyy-MM-dd HH:mm:ss")
+    @DateTimeFormat(pattern="yyyy-MM-dd HH:mm:ss")
+    @Schema(description = "更新时间;更新时间")
+    private Date updateTime;
+
+}

+ 7 - 0
national-motion-module-system/national-motion-system-biz/src/main/java/org/jeecg/modules/system/app/mapper/AppGmtInfoMapper.java

@@ -0,0 +1,7 @@
+package org.jeecg.modules.system.app.mapper;
+
+import com.baomidou.mybatisplus.core.mapper.BaseMapper;
+import org.jeecg.modules.system.app.entity.AppGmtInfo;
+
+public interface AppGmtInfoMapper extends BaseMapper<AppGmtInfo> {
+}