liuyongxin 9 місяців тому
батько
коміт
6fa8b78890

+ 23 - 0
src/main/java/com/lutao/carlocation/entity/CollectLog.java

@@ -0,0 +1,23 @@
+package com.lutao.carlocation.entity;
+
+import com.baomidou.mybatisplus.annotation.IdType;
+import com.baomidou.mybatisplus.annotation.TableId;
+import com.baomidou.mybatisplus.annotation.TableName;
+import com.baomidou.mybatisplus.extension.activerecord.Model;
+import lombok.Data;
+import lombok.EqualsAndHashCode;
+import lombok.experimental.Accessors;
+
+@Data
+@TableName("collect_log")
+@EqualsAndHashCode(callSuper = true)
+@Accessors(chain = true)
+public class CollectLog extends Model<CollectLog> {
+
+    @TableId(value = "id", type = IdType.ASSIGN_UUID)
+    private String id;
+
+    private String type;
+
+    private String content;
+}

+ 13 - 3
src/main/java/com/lutao/carlocation/kafka/ConsumerCarLoaction.java

@@ -3,6 +3,8 @@ package com.lutao.carlocation.kafka;
 import cn.hutool.json.JSONArray;
 import cn.hutool.json.JSONObject;
 import cn.hutool.json.JSONUtil;
+import com.lutao.carlocation.entity.CollectLog;
+import com.lutao.carlocation.service.CollectLogService;
 import com.lutao.carlocation.service.IsolatedVehicleLocationMonitorService;
 import lombok.extern.slf4j.Slf4j;
 import org.springframework.kafka.annotation.KafkaListener;
@@ -25,6 +27,9 @@ public class ConsumerCarLoaction {
     @Resource
     private IsolatedVehicleLocationMonitorService isolatedVehicleLocationMonitorService;
 
+    @Resource
+    private CollectLogService collectLogService;
+
 
     @KafkaListener(topics = "topic_push_out_jinta", groupId = "topic_push_out_jinta_group", containerFactory = "kafkaListenerContainerFactory")
     public void listen(String message) {
@@ -33,13 +38,15 @@ public class ConsumerCarLoaction {
 
             if (JSONUtil.isJson(decrypt)){
                 log.info("received message:{}", decrypt);
-
+                CollectLog carLocation = new CollectLog().setType("carLocation").setContent(decrypt);
+                collectLogService.save(carLocation);
                 JSONObject receiveMessage = JSONUtil.parseObj(decrypt);
 
                 if (receiveMessage.containsKey("alarmType")){
-
                     //车辆报警
                     kafkaTemplate.send("alarmLog", receiveMessage.toString());
+                    CollectLog alarm = new CollectLog().setType("alarm").setContent(decrypt);
+                    collectLogService.save(alarm);
                     log.info("send-message-alarmLog:{}", receiveMessage);
                 }else {
                     /**
@@ -137,12 +144,15 @@ public class ConsumerCarLoaction {
 
         } catch (Exception e) {
             try {
-                log.error("error:{}", RsaBase64Utils.decrypt(message));
+                String decrypt = RsaBase64Utils.decrypt(message);
+                log.error("error:{}", decrypt);
             } catch (Exception ex) {
                 log.info("error:{}", e.getMessage());
                 e.printStackTrace();
             }
             log.info("error:{}", e.getMessage());
+            CollectLog error = new CollectLog().setType("error").setContent(e.getMessage());
+            collectLogService.save(error);
             e.printStackTrace();
         }
     }

+ 9 - 0
src/main/java/com/lutao/carlocation/mapper/CollectLogMapper.java

@@ -0,0 +1,9 @@
+package com.lutao.carlocation.mapper;
+
+import com.baomidou.mybatisplus.core.mapper.BaseMapper;
+import com.lutao.carlocation.entity.CollectLog;
+import org.apache.ibatis.annotations.Mapper;
+
+@Mapper
+public interface CollectLogMapper extends BaseMapper<CollectLog> {
+}

+ 7 - 0
src/main/java/com/lutao/carlocation/service/CollectLogService.java

@@ -0,0 +1,7 @@
+package com.lutao.carlocation.service;
+
+import com.baomidou.mybatisplus.extension.service.IService;
+import com.lutao.carlocation.entity.CollectLog;
+
+public interface CollectLogService extends IService<CollectLog> {
+}

+ 11 - 0
src/main/java/com/lutao/carlocation/service/impl/CollectLogServiceImpl.java

@@ -0,0 +1,11 @@
+package com.lutao.carlocation.service.impl;
+
+import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
+import com.lutao.carlocation.entity.CollectLog;
+import com.lutao.carlocation.mapper.CollectLogMapper;
+import com.lutao.carlocation.service.CollectLogService;
+import org.springframework.stereotype.Service;
+
+@Service
+public class CollectLogServiceImpl extends ServiceImpl<CollectLogMapper, CollectLog> implements CollectLogService {
+}

+ 4 - 0
src/main/resources/mapper/CollectLogMapper.xml

@@ -0,0 +1,4 @@
+<?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.lutao.carlocation.mapper.CollectLogMapper">
+</mapper>