parent
dc25aa9475
commit
1b75633bd6
@ -0,0 +1,38 @@
|
||||
target/
|
||||
!.mvn/wrapper/maven-wrapper.jar
|
||||
!**/src/main/**/target/
|
||||
!**/src/test/**/target/
|
||||
|
||||
### IntelliJ IDEA ###
|
||||
.idea/modules.xml
|
||||
.idea/jarRepositories.xml
|
||||
.idea/compiler.xml
|
||||
.idea/libraries/
|
||||
*.iws
|
||||
*.iml
|
||||
*.ipr
|
||||
|
||||
### Eclipse ###
|
||||
.apt_generated
|
||||
.classpath
|
||||
.factorypath
|
||||
.project
|
||||
.settings
|
||||
.springBeans
|
||||
.sts4-cache
|
||||
|
||||
### NetBeans ###
|
||||
/nbproject/private/
|
||||
/nbbuild/
|
||||
/dist/
|
||||
/nbdist/
|
||||
/.nb-gradle/
|
||||
build/
|
||||
!**/src/main/**/build/
|
||||
!**/src/test/**/build/
|
||||
|
||||
### VS Code ###
|
||||
.vscode/
|
||||
|
||||
### Mac OS ###
|
||||
.DS_Store
|
@ -0,0 +1,2 @@
|
||||
编号 门磁设备IMEI 对应摄像头IP
|
||||
1 866674056947364 192.168.0.68
|
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
@ -1,17 +1,23 @@
|
||||
package com.doormagnet;
|
||||
|
||||
import lombok.extern.slf4j.Slf4j;
|
||||
import org.springframework.boot.SpringApplication;
|
||||
import org.springframework.boot.autoconfigure.SpringBootApplication;
|
||||
import org.springframework.scheduling.annotation.EnableAsync;
|
||||
import org.springframework.scheduling.annotation.EnableScheduling;
|
||||
|
||||
/*
|
||||
* @User $USER
|
||||
* @Time $DATE $TIME
|
||||
*
|
||||
*/
|
||||
@Slf4j
|
||||
@EnableAsync
|
||||
@EnableScheduling
|
||||
@SpringBootApplication
|
||||
public class DoorMagnet {
|
||||
public class DoorMagnetApplication {
|
||||
public static void main(String[] args) {
|
||||
SpringApplication.run(DoorMagnet.class);
|
||||
SpringApplication.run(DoorMagnetApplication.class);
|
||||
System.out.println("门磁对接程序");
|
||||
}
|
||||
}
|
@ -0,0 +1,23 @@
|
||||
package com.doormagnet.config;
|
||||
|
||||
import org.springframework.context.annotation.Configuration;
|
||||
import org.springframework.scheduling.annotation.EnableScheduling;
|
||||
import org.springframework.scheduling.annotation.SchedulingConfigurer;
|
||||
import org.springframework.scheduling.config.ScheduledTaskRegistrar;
|
||||
import org.springframework.stereotype.Component;
|
||||
|
||||
import java.util.concurrent.Executors;
|
||||
|
||||
/**
|
||||
* @Author 杜俊岩
|
||||
* @Date 2023/12/22 17:46
|
||||
* @Version 1.0
|
||||
*/
|
||||
@Configuration
|
||||
@EnableScheduling
|
||||
public class SchuedingConfig implements SchedulingConfigurer {
|
||||
@Override
|
||||
public void configureTasks(ScheduledTaskRegistrar taskRegistrar) {
|
||||
taskRegistrar.setScheduler(Executors.newScheduledThreadPool(30));
|
||||
}
|
||||
}
|
@ -0,0 +1,37 @@
|
||||
package com.doormagnet.controller;
|
||||
|
||||
import cn.hutool.json.JSONObject;
|
||||
import cn.hutool.json.ObjectMapper;
|
||||
import com.alibaba.fastjson.JSON;
|
||||
import com.doormagnet.pojo.EventReport;
|
||||
import com.doormagnet.service.DoorMagnetService;
|
||||
import org.springframework.beans.factory.annotation.Autowired;
|
||||
import org.springframework.validation.support.BindingAwareModelMap;
|
||||
import org.springframework.web.bind.annotation.*;
|
||||
|
||||
import java.io.File;
|
||||
|
||||
/**
|
||||
* @Author 杜俊岩
|
||||
* @Date 2024/4/24 11:36
|
||||
* @Version 1.0
|
||||
*/
|
||||
@RestController
|
||||
@RequestMapping("/doormagnet")
|
||||
public class DoorMagnetController {
|
||||
@Autowired
|
||||
private DoorMagnetService doorMagnetService;
|
||||
|
||||
@PostMapping("/test")
|
||||
public void test(@RequestBody JSONObject jsonObject){
|
||||
EventReport eventReport = JSON.parseObject(String.valueOf(jsonObject), EventReport.class);
|
||||
if (eventReport.getEventContent().getOpenState()== 1 || eventReport.getEventContent().getOpenState()== 0){
|
||||
Boolean flag = doorMagnetService.creatfile(eventReport);
|
||||
System.out.println("eventReport = " + flag);
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
|
||||
|
||||
}
|
@ -0,0 +1,29 @@
|
||||
package com.doormagnet.pojo;
|
||||
|
||||
import com.fasterxml.jackson.annotation.JsonInclude;
|
||||
import com.fasterxml.jackson.annotation.JsonProperty;
|
||||
import lombok.AllArgsConstructor;
|
||||
import lombok.Data;
|
||||
import lombok.NoArgsConstructor;
|
||||
|
||||
/**
|
||||
* @Author 杜俊岩
|
||||
* @Date 2024/4/24 11:33
|
||||
* @Version 1.0
|
||||
*/
|
||||
@Data
|
||||
@NoArgsConstructor
|
||||
@AllArgsConstructor
|
||||
@JsonInclude(JsonInclude.Include.NON_NULL)
|
||||
public class EventContent {
|
||||
@JsonProperty("open_state")
|
||||
private Integer openState = 3;
|
||||
@JsonProperty("battery_voltage")
|
||||
private Double batteryVoltage;
|
||||
@JsonProperty("battery_value")
|
||||
private Integer batteryValue;
|
||||
@JsonProperty("arming_state")
|
||||
private Integer armingState;
|
||||
@JsonProperty("alarm_type")
|
||||
private Integer alarmType;
|
||||
}
|
@ -0,0 +1,56 @@
|
||||
package com.doormagnet.pojo;
|
||||
|
||||
import com.fasterxml.jackson.annotation.JsonInclude;
|
||||
import com.fasterxml.jackson.annotation.JsonProperty;
|
||||
import lombok.AllArgsConstructor;
|
||||
import lombok.Data;
|
||||
import lombok.NoArgsConstructor;
|
||||
|
||||
/**
|
||||
* @Author 杜俊岩
|
||||
* @Date 2024/4/28 11:24
|
||||
* @Version 1.0
|
||||
*/
|
||||
@Data
|
||||
@NoArgsConstructor
|
||||
@AllArgsConstructor
|
||||
@JsonInclude(JsonInclude.Include.NON_NULL)
|
||||
public class EventReport {
|
||||
@JsonProperty("timestamp")
|
||||
private long timestamp;
|
||||
|
||||
@JsonProperty("tenantId")
|
||||
private String tenantId;
|
||||
|
||||
@JsonProperty("serviceId")
|
||||
private Integer serviceId;
|
||||
|
||||
@JsonProperty("protocol")
|
||||
private String protocol;
|
||||
|
||||
@JsonProperty("productId")
|
||||
private String productId;
|
||||
|
||||
@JsonProperty("messageType")
|
||||
private String messageType;
|
||||
|
||||
@JsonProperty("eventType")
|
||||
private Integer eventType;
|
||||
|
||||
@JsonProperty("eventContent")
|
||||
private EventContent eventContent;
|
||||
|
||||
@JsonProperty("deviceSn")
|
||||
private String deviceSn;
|
||||
|
||||
@JsonProperty("deviceId")
|
||||
private String deviceId;
|
||||
|
||||
@JsonProperty("IMSI")
|
||||
private String IMSI;
|
||||
|
||||
@JsonProperty("IMEI")
|
||||
private String IMEI;
|
||||
|
||||
|
||||
}
|
@ -0,0 +1,17 @@
|
||||
package com.doormagnet.task;
|
||||
|
||||
import com.alibaba.excel.annotation.ExcelProperty;
|
||||
import lombok.Data;
|
||||
|
||||
@Data
|
||||
public class ConfigData {
|
||||
|
||||
@ExcelProperty("编号")
|
||||
private String id;
|
||||
@ExcelProperty("门磁设备IMEI")
|
||||
private String doorwayIMEI;
|
||||
@ExcelProperty("对应摄像头IP")
|
||||
private String cameraIP;
|
||||
|
||||
|
||||
}
|
@ -0,0 +1,68 @@
|
||||
package com.doormagnet.task;
|
||||
|
||||
import com.alibaba.excel.EasyExcel;
|
||||
import com.alibaba.excel.context.AnalysisContext;
|
||||
import com.alibaba.excel.event.AnalysisEventListener;
|
||||
import com.github.benmanes.caffeine.cache.Cache;
|
||||
import com.github.benmanes.caffeine.cache.Caffeine;
|
||||
import org.springframework.stereotype.Component;
|
||||
|
||||
import javax.annotation.PostConstruct;
|
||||
import java.io.File;
|
||||
import java.util.ArrayList;
|
||||
import java.util.HashMap;
|
||||
import java.util.List;
|
||||
import java.util.Map;
|
||||
import java.util.stream.Collectors;
|
||||
|
||||
@Component
|
||||
public class ExcelReader {
|
||||
|
||||
private static final Cache<String, String> cache = Caffeine.newBuilder().build();
|
||||
|
||||
@PostConstruct
|
||||
public static void readExcel() {
|
||||
String filePath = "F:\\WT\\config.xlsx";
|
||||
|
||||
// 读取 Excel 文件并映射到对象
|
||||
List<ConfigData> dataList = EasyExcel.read(filePath, ConfigData.class, new ExcelListener()).sheet().doReadSync();
|
||||
Map map = new HashMap();
|
||||
|
||||
cache.putAll(map);
|
||||
Map<String, String> dictMapCode = dataList.stream().collect(Collectors.toMap(
|
||||
e -> e.getDoorwayIMEI(),
|
||||
e -> e.getCameraIP(), (v1, v2) -> v2));
|
||||
cache.putAll(dictMapCode);
|
||||
|
||||
}
|
||||
|
||||
public static class ExcelListener extends AnalysisEventListener<ConfigData> {
|
||||
|
||||
private final List<ConfigData> dataList = new ArrayList<>();
|
||||
|
||||
@Override
|
||||
public void invoke(ConfigData data, AnalysisContext context) {
|
||||
// 处理每一行的数据
|
||||
dataList.add(data);
|
||||
}
|
||||
|
||||
@Override
|
||||
public void doAfterAllAnalysed(AnalysisContext context) {
|
||||
// 数据读取完成后的处理
|
||||
// System.out.println("所有数据处理完毕");
|
||||
}
|
||||
|
||||
public List<ConfigData> getDataList() {
|
||||
return dataList;
|
||||
}
|
||||
}
|
||||
|
||||
public static String get(String key) {
|
||||
return cache.get(key, s -> null);
|
||||
}
|
||||
|
||||
|
||||
public static void main(String[] args) {
|
||||
readExcel();
|
||||
}
|
||||
}
|
@ -0,0 +1,106 @@
|
||||
package com.doormagnet.until;
|
||||
|
||||
import java.io.PrintWriter;
|
||||
import java.io.StringWriter;
|
||||
import java.util.regex.Pattern;
|
||||
|
||||
public class StringKit {
|
||||
|
||||
public StringKit() {
|
||||
}
|
||||
|
||||
public static Boolean isEmpty(Object argObject) {
|
||||
Boolean tbool = false;
|
||||
String tString = toString(argObject);
|
||||
if (tString.equals("")) {
|
||||
tbool = true;
|
||||
}
|
||||
|
||||
return tbool;
|
||||
}
|
||||
|
||||
public static String toString(Object argObject) {
|
||||
String tmpstr = "";
|
||||
try {
|
||||
if (argObject != null) {
|
||||
tmpstr = argObject.toString();
|
||||
tmpstr = tmpstr.replaceAll("\0", "");
|
||||
if( "null".equals(tmpstr) || "underfind".equals(tmpstr) || "undefined".equals(tmpstr) ){
|
||||
tmpstr="";
|
||||
}
|
||||
}
|
||||
} catch (Exception var3) {
|
||||
}
|
||||
|
||||
return tmpstr;
|
||||
}
|
||||
|
||||
public static String toStringNull(Object argObject) {
|
||||
String tmpstr = "";
|
||||
try {
|
||||
if (argObject != null) {
|
||||
tmpstr = argObject.toString();
|
||||
if( "null".equals(tmpstr) || "underfind".equals(tmpstr) || "undefined".equals(tmpstr) ){
|
||||
tmpstr="null";
|
||||
}
|
||||
}
|
||||
} catch (Exception var3) {
|
||||
}
|
||||
|
||||
return tmpstr;
|
||||
}
|
||||
|
||||
@Deprecated
|
||||
public static String toDefaultString(Object argObject) {
|
||||
String tmpstr = "无";
|
||||
try {
|
||||
if (argObject != null) {
|
||||
tmpstr = argObject.toString();
|
||||
if( "null".equals(tmpstr) || "underfind".equals(tmpstr) || "undefined".equals(tmpstr) ){
|
||||
tmpstr="无";
|
||||
}
|
||||
}
|
||||
} catch (Exception var3) {
|
||||
}
|
||||
|
||||
return tmpstr;
|
||||
}
|
||||
|
||||
@Deprecated
|
||||
public static String toDefaultInt(Object argObject) {
|
||||
String tmpstr = "0";
|
||||
try {
|
||||
if (argObject != null) {
|
||||
tmpstr = argObject.toString();
|
||||
if( "null".equals(tmpstr) || "underfind".equals(tmpstr) || "undefined".equals(tmpstr) ){
|
||||
tmpstr="0";
|
||||
}
|
||||
}
|
||||
} catch (Exception var3) {
|
||||
}
|
||||
|
||||
return tmpstr;
|
||||
}
|
||||
|
||||
|
||||
public static boolean isNumeric(String str){
|
||||
Pattern pattern = Pattern.compile("[0-9]*");
|
||||
return pattern.matcher(str).matches();
|
||||
}
|
||||
|
||||
public static boolean isEng(String str){
|
||||
Pattern pattern = Pattern.compile("[a-zA-Z]");
|
||||
return pattern.matcher(str).matches();
|
||||
}
|
||||
|
||||
|
||||
public static String getTrace(Throwable t){
|
||||
|
||||
StringWriter stringWriter = new StringWriter();
|
||||
PrintWriter writer = new PrintWriter(stringWriter);
|
||||
t.printStackTrace(writer);
|
||||
StringBuffer buffer = stringWriter.getBuffer();
|
||||
return buffer.toString();
|
||||
}
|
||||
|
||||
}
|
@ -0,0 +1,71 @@
|
||||
<?xml version="1.0" encoding="UTF-8"?>
|
||||
<configuration scan="true" scanPeriod="60 seconds" debug="false">
|
||||
|
||||
<!--彩色日志解析-->
|
||||
<include resource="org/springframework/boot/logging/logback/defaults.xml"/>
|
||||
<springProperty scope="context" name="LOG_PATH" source="logback.path" defaultValue="/home/project/fileTransfer/log"/>
|
||||
<springProperty scope="context" name="MAX_HISTORY" source="logback.max-history" defaultValue="7"/>
|
||||
|
||||
<!--输出到控制台-->
|
||||
<appender name="CONSOLE" class="ch.qos.logback.core.ConsoleAppender">
|
||||
<encoder>
|
||||
<pattern>${CONSOLE_LOG_PATTERN}</pattern>
|
||||
<!-- 设置字符集 -->
|
||||
<charset>UTF-8</charset>
|
||||
</encoder>
|
||||
</appender>
|
||||
<!--输出到文件-->
|
||||
<appender name="FILE_INFO" class="ch.qos.logback.core.rolling.RollingFileAppender">
|
||||
<rollingPolicy class="ch.qos.logback.core.rolling.TimeBasedRollingPolicy">
|
||||
<fileNamePattern>${LOG_PATH}/info/info.%d{yyyy-MM-dd}.log</fileNamePattern>
|
||||
<MaxHistory>${MAX_HISTORY}</MaxHistory>
|
||||
</rollingPolicy>
|
||||
<encoder>
|
||||
<pattern>${FILE_LOG_PATTERN}</pattern>
|
||||
<charset>UTF-8</charset>
|
||||
</encoder>
|
||||
<filter class="ch.qos.logback.classic.filter.LevelFilter">
|
||||
<level>INFO</level>
|
||||
<onMatch>ACCEPT</onMatch>
|
||||
<onMismatch>DENY</onMismatch>
|
||||
</filter>
|
||||
</appender>
|
||||
<appender name="FILE_ERROR" class="ch.qos.logback.core.rolling.RollingFileAppender">
|
||||
<rollingPolicy class="ch.qos.logback.core.rolling.TimeBasedRollingPolicy">
|
||||
<fileNamePattern>${LOG_PATH}/error/error.%d{yyyy-MM-dd}.log</fileNamePattern>
|
||||
<MaxHistory>${MAX_HISTORY}</MaxHistory>
|
||||
</rollingPolicy>
|
||||
<encoder>
|
||||
<pattern>${FILE_LOG_PATTERN}</pattern>
|
||||
<charset>UTF-8</charset>
|
||||
</encoder>
|
||||
<filter class="ch.qos.logback.classic.filter.LevelFilter">
|
||||
<level>ERROR</level>
|
||||
<onMatch>ACCEPT</onMatch>
|
||||
<onMismatch>DENY</onMismatch>
|
||||
</filter>
|
||||
</appender>
|
||||
|
||||
<logger name="com.watu.filetransfer"/>
|
||||
<logger name="org.springframework" level="warn"/>
|
||||
|
||||
<springProfile name="dev">
|
||||
<root level="DEBUG">
|
||||
<appender-ref ref="CONSOLE"/>
|
||||
</root>
|
||||
</springProfile>
|
||||
<springProfile name="test">
|
||||
<root level="DEBUG">
|
||||
<appender-ref ref="CONSOLE"/>
|
||||
<appender-ref ref="FILE_INFO"/>
|
||||
<appender-ref ref="FILE_ERROR"/>
|
||||
</root>
|
||||
</springProfile>
|
||||
<springProfile name="prod">
|
||||
<root level="INFO">
|
||||
<appender-ref ref="FILE_INFO"/>
|
||||
<appender-ref ref="FILE_ERROR"/>
|
||||
</root>
|
||||
</springProfile>
|
||||
|
||||
</configuration>
|
Loading…
Reference in new issue