Browse Source

监听处理

yq 3 năm trước cách đây
mục cha
commit
fcbde55f19

+ 21 - 0
dxcollect-controller/src/main/java/com/usky/controller/web/EntranceLogController.java

@@ -0,0 +1,21 @@
+package com.usky.controller.web;
+
+
+import org.springframework.web.bind.annotation.RequestMapping;
+
+import org.springframework.stereotype.Controller;
+
+/**
+ * <p>
+ *  前端控制器
+ * </p>
+ *
+ * @author ya
+ * @since 2022-04-13
+ */
+@Controller
+@RequestMapping("/entranceLog")
+public class EntranceLogController {
+
+}
+

+ 129 - 0
dxcollect-controller/src/main/java/com/usky/controller/web/MybatisGeneratorUtils.java

@@ -0,0 +1,129 @@
+//package com.usky.controller.web;//package com.usky.dm.controller.web.business;//package com.usky.dm.controller.web;
+//
+//import com.baomidou.mybatisplus.core.toolkit.StringPool;
+//import com.baomidou.mybatisplus.generator.AutoGenerator;
+//import com.baomidou.mybatisplus.generator.InjectionConfig;
+//import com.baomidou.mybatisplus.generator.config.*;
+//import com.baomidou.mybatisplus.generator.config.po.TableInfo;
+//import com.baomidou.mybatisplus.generator.config.rules.NamingStrategy;
+//
+//import java.io.File;
+//import java.util.ArrayList;
+//import java.util.List;
+//
+///**
+// * @author yq
+// * @date 2021/7/6 11:42
+// */
+//public class MybatisGeneratorUtils {
+//    public static void main(String[] args) {
+//        //修改成自己的模块名称
+//        String[] models = {"dxcollect-controller", "dxcollect-service", "dxcollect-model", "dxcollect-persistence"};
+//        for (String model : models) {
+//            shell(model);
+//        }
+//    }
+//
+//    private static void shell(String model) {
+//
+//        AutoGenerator mpg = new AutoGenerator();
+//        //1、全局配置
+//        GlobalConfig gc = new GlobalConfig();
+//        File file = new File(model);
+//        String path = file.getAbsolutePath();
+//        gc.setOutputDir(path + "/src/main/java");  //生成路径(一般都是生成在此项目的src/main/java下面)
+//        //修改为自己的名字
+//        gc.setAuthor("ya"); //设置作者
+//        gc.setOpen(false);
+//        gc.setFileOverride(true); //第二次生成会把第一次生成的覆盖掉
+//        gc.setServiceName("%sService"); //生成的service接口名字首字母是否为I,这样设置就没有
+//        gc.setBaseResultMap(true); //生成resultMap
+//        mpg.setGlobalConfig(gc);
+//
+//        //2、数据源配置
+//        //修改数据源
+//        DataSourceConfig dsc = new DataSourceConfig();
+//        dsc.setUrl("jdbc:mysql://47.111.81.118:3306/dm?useUnicode=true&serverTimezone=GMT&useSSL=false&characterEncoding=utf8");
+//        dsc.setDriverName("com.mysql.jdbc.Driver");
+//        dsc.setUsername("root");
+//        dsc.setPassword("Yt2021");
+//        mpg.setDataSource(dsc);
+//
+//        // 3、包配置
+//        PackageConfig pc = new PackageConfig();
+//        pc.setParent("com.usky.dm");
+//        pc.setController("controller.web");
+//        pc.setEntity("model");
+//        pc.setMapper("persistence.mapper");
+//        pc.setService("service");
+//        pc.setServiceImpl("service.impl");
+//        //pc.setModuleName("test");
+//        mpg.setPackageInfo(pc);
+//
+//        // 4、策略配置
+//        StrategyConfig strategy = new StrategyConfig();
+//        strategy.setNaming(NamingStrategy.underline_to_camel);
+//        strategy.setColumnNaming(NamingStrategy.underline_to_camel);
+//        strategy.setSuperMapperClass("com.usky.dm.common.mvc.base.CrudMapper");
+//        strategy.setSuperServiceClass("com.usky.dm.common.mvc.base.CrudService");
+//        strategy.setSuperServiceImplClass("com.usky.dm.common.mvc.base.AbstractCrudService");
+//        // strategy.setTablePrefix("t_"); // 表名前缀
+//        strategy.setEntityLombokModel(true); //使用lombok
+//        //修改自己想要生成的表
+//        strategy.setInclude("entrance_log");  // 逆向工程使用的表   如果要生成多个,这里可以传入String[]
+//        mpg.setStrategy(strategy);
+//
+//        // 关闭默认 xml 生成,调整生成 至 根目录
+//        //修改对应的模块名称
+//        TemplateConfig tc = new TemplateConfig();
+//        if ("dxcollect-persistence".equals(model)) {
+//            tc.setController(null);
+//            tc.setEntity(null);
+//            tc.setService(null);
+//            tc.setServiceImpl(null);
+//            // 自定义配置
+//            InjectionConfig cfg = new InjectionConfig() {
+//                @Override
+//                public void initMap() {
+//                    // to do nothing
+//                }
+//            };
+//            //如果模板引擎是 velocity
+//            String templatePath = "/templates/mapper.xml.vm";
+//            // 自定义输出配置
+//            List<FileOutConfig> focList = new ArrayList<>();
+//            // 自定义配置会被优先输出
+//            focList.add(new FileOutConfig(templatePath) {
+//                @Override
+//                public String outputFile(TableInfo tableInfo) {
+//                    // 自定义输出文件名 , 如果你 Entity 设置了前后缀、此处注意 xml 的名称会跟着发生变化!!
+//                    return path + "/src/main/resources/mapper/mysql/" + "/"
+//                            + tableInfo.getEntityName() + "Mapper" + StringPool.DOT_XML;
+//                }
+//            });
+//            cfg.setFileOutConfigList(focList);
+//            mpg.setCfg(cfg);
+//            tc.setXml(null);
+//        } else if ("dxcollect-model".equals(model)) {
+//            tc.setController(null);
+//            tc.setService(null);
+//            tc.setServiceImpl(null);
+//            tc.setMapper(null);
+//            tc.setXml(null);
+//        } else if ("dxcollect-service".equals(model)) {
+//            tc.setController(null);
+//            tc.setMapper(null);
+//            tc.setXml(null);
+//            tc.setEntity(null);
+//        } else if ("dxcollect-controller".equals(model)) {
+//            tc.setMapper(null);
+//            tc.setXml(null);
+//            tc.setService(null);
+//            tc.setServiceImpl(null);
+//            tc.setEntity(null);
+//        }
+//        mpg.setTemplate(tc);
+//        //5、执行
+//        mpg.execute();
+//    }
+//}

+ 1 - 1
dxcollect-controller/src/main/java/com/usky/controller/web/RocketMqController.java

@@ -17,7 +17,7 @@ public class RocketMqController {
     @GetMapping("/pushMessage")
     public String pushMessage(@RequestParam("str") String str) {
 
-        rocketMQTemplate.convertAndSend("first-topic","你好,RocketMq =>" + str);
+        rocketMQTemplate.convertAndSend("entrance-topic","你好,RocketMq =>" + str);
         return "success";
     }
 

+ 1 - 1
dxcollect-controller/src/main/resources/application-dev.properties

@@ -16,7 +16,7 @@ mybatis.refresh.sleep-seconds=20
 # datasource
 spring.autoconfigure.exclude=com.alibaba.druid.spring.boot.autoconfigure.DruidDataSourceAutoConfigure
 spring.datasource.dynamic.primary=mast
-spring.datasource.dynamic.datasource.mast.url=jdbc:mysql://47.111.81.118:3306/dm?useUnicode=true&useJDBCCompliantTimezoneShift=true&useLegacyDatetimeCode=false&serverTimezone=UTC
+spring.datasource.dynamic.datasource.mast.url=jdbc:mysql://47.111.81.118:3306/dm?useUnicode=true&useJDBCCompliantTimezoneShift=true&useLegacyDatetimeCode=false&serverTimezone=Asia/Shanghai&characterEncoding=utf8&allowMultiQueries=true
 spring.datasource.dynamic.datasource.mast.username=root
 spring.datasource.dynamic.datasource.mast.password=Yt2021
 spring.datasource.dynamic.druid.initial-size=5                                                                       

+ 1 - 1
dxcollect-controller/src/main/resources/application-prod.properties

@@ -16,7 +16,7 @@ mybatis.refresh.sleep-seconds=20
 # datasource
 spring.autoconfigure.exclude=com.alibaba.druid.spring.boot.autoconfigure.DruidDataSourceAutoConfigure
 spring.datasource.dynamic.primary=mast
-spring.datasource.dynamic.datasource.mast.url=jdbc:mysql://10.23.39.230:13306/dm?useUnicode=true&useJDBCCompliantTimezoneShift=true&useLegacyDatetimeCode=false&serverTimezone=UTC
+spring.datasource.dynamic.datasource.mast.url=jdbc:mysql://10.23.39.230:13306/dm?useUnicode=true&useJDBCCompliantTimezoneShift=true&useLegacyDatetimeCode=false&serverTimezone=Asia/Shanghai&characterEncoding=utf8&allowMultiQueries=true
 spring.datasource.dynamic.datasource.mast.username=ytloT
 spring.datasource.dynamic.datasource.mast.password=E7c5azRq
 spring.datasource.dynamic.druid.initial-size=5                                                                       

+ 105 - 0
dxcollect-model/src/main/java/com/usky/model/EntranceLog.java

@@ -0,0 +1,105 @@
+package com.usky.model;
+
+import com.baomidou.mybatisplus.annotation.IdType;
+import com.baomidou.mybatisplus.annotation.TableId;
+import com.fasterxml.jackson.annotation.JsonProperty;
+import lombok.Data;
+import lombok.EqualsAndHashCode;
+import lombok.experimental.Accessors;
+
+import java.io.Serializable;
+import java.time.LocalDateTime;
+import java.util.Date;
+
+/**
+ * <p>
+ * 
+ * </p>
+ *
+ * @author ya
+ * @since 2022-04-13
+ */
+@Data
+@EqualsAndHashCode(callSuper = false)
+@Accessors(chain = true)
+public class EntranceLog implements Serializable {
+
+    private static final long serialVersionUID=1L;
+
+    /**
+     * 主键
+     */
+    @TableId(value = "id", type = IdType.AUTO)
+    private Long id;
+
+    /**
+     * 日期
+     */
+    private String date;
+
+    /**
+     * 卡号
+     */
+    @JsonProperty("cardID")
+    private Long cardId;
+
+    /**
+     * 用户名称
+     */
+    private String userName;
+
+    /**
+     * 用户编号
+     */
+    @JsonProperty("userID")
+    private String userId;
+
+    /**
+     * 设备编号
+     */
+    @JsonProperty("deviceID")
+    private String deviceId;
+
+    /**
+     * 设备名称
+     */
+    private String deviceName;
+
+    /**
+     * 设备类型
+     */
+    private Integer deviceType;
+
+    /**
+     * 门编号
+     */
+    @JsonProperty("doorID")
+    private Integer doorId;
+
+    /**
+     * 时间类型编号
+     */
+    private Integer eventType;
+
+    /**
+     * 门名称
+     */
+    private String doorName;
+
+    /**
+     * 同一设备的不同事件来源 1 刷卡 2 二维码 3 人脸
+     */
+    private Integer type;
+
+    /**
+     * 是否通行成功
+     */
+    private Boolean open;
+
+    /**
+     * 创建时间
+     */
+    private Date createTime;
+
+
+}

+ 17 - 0
dxcollect-persistence/src/main/java/com/usky/persistence/mapper/EntranceLogMapper.java

@@ -0,0 +1,17 @@
+package com.usky.persistence.mapper;
+
+
+import com.usky.common.mvc.base.CrudMapper;
+import com.usky.model.EntranceLog;
+
+/**
+ * <p>
+ *  Mapper 接口
+ * </p>
+ *
+ * @author ya
+ * @since 2022-04-13
+ */
+public interface EntranceLogMapper extends CrudMapper<EntranceLog> {
+
+}

+ 23 - 0
dxcollect-persistence/src/main/resources/mapper/mysql/EntranceLogMapper.xml

@@ -0,0 +1,23 @@
+<?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.usky.persistence.mapper.EntranceLogMapper">
+
+    <!-- 通用查询映射结果 -->
+    <resultMap id="BaseResultMap" type="com.usky.model.EntranceLog">
+        <id column="id" property="id" />
+        <result column="date" property="date" />
+        <result column="card_id" property="cardId" />
+        <result column="user_name" property="userName" />
+        <result column="user_id" property="userId" />
+        <result column="device_id" property="deviceId" />
+        <result column="device_name" property="deviceName" />
+        <result column="device_type" property="deviceType" />
+        <result column="door_id" property="doorId" />
+        <result column="envent_type" property="enventType" />
+        <result column="door_name" property="doorName" />
+        <result column="type" property="type" />
+        <result column="open" property="open" />
+        <result column="create_time" property="createTime" />
+    </resultMap>
+
+</mapper>

+ 17 - 0
dxcollect-service/src/main/java/com/usky/service/EntranceLogService.java

@@ -0,0 +1,17 @@
+package com.usky.service;
+
+
+import com.usky.common.mvc.base.CrudService;
+import com.usky.model.EntranceLog;
+
+/**
+ * <p>
+ *  服务类
+ * </p>
+ *
+ * @author ya
+ * @since 2022-04-13
+ */
+public interface EntranceLogService extends CrudService<EntranceLog> {
+
+}

+ 21 - 0
dxcollect-service/src/main/java/com/usky/service/impl/EntranceLogServiceImpl.java

@@ -0,0 +1,21 @@
+package com.usky.service.impl;
+
+
+import com.usky.common.mvc.base.AbstractCrudService;
+import com.usky.persistence.mapper.EntranceLogMapper;
+import com.usky.model.EntranceLog;
+import com.usky.service.EntranceLogService;
+import org.springframework.stereotype.Service;
+
+/**
+ * <p>
+ *  服务实现类
+ * </p>
+ *
+ * @author ya
+ * @since 2022-04-13
+ */
+@Service
+public class EntranceLogServiceImpl extends AbstractCrudService<EntranceLogMapper, EntranceLog> implements EntranceLogService {
+
+}

+ 8 - 1
dxcollect-service/src/main/java/com/usky/service/listener/RocketMqListener.java

@@ -1,19 +1,26 @@
 package com.usky.service.listener;
 
 
+import com.usky.common.spring.util.JsonUtils;
+import com.usky.model.EntranceLog;
+import com.usky.service.EntranceLogService;
 import lombok.extern.slf4j.Slf4j;
 import org.apache.rocketmq.spring.annotation.RocketMQMessageListener;
 import org.apache.rocketmq.spring.core.RocketMQListener;
+import org.springframework.beans.factory.annotation.Autowired;
 import org.springframework.stereotype.Component;
 
 @Slf4j
 @Component
-@RocketMQMessageListener(topic = "first-topic",consumerGroup = "my-consumer-group")
+@RocketMQMessageListener(topic = "entrance-topic",consumerGroup = "my-consumer-group")
 public class RocketMqListener  implements RocketMQListener<String> {
 
+    @Autowired
+    private EntranceLogService entranceLogService;
     @Override
     public void onMessage(String message) {
 
+        entranceLogService.save(JsonUtils.fromJson(message, EntranceLog.class));
         // 打印出消息内容
         log.info("==============================================>");
         System.out.println(message);