From b9fb336cac77d4aa2a85c1fa24042cf6bd9b3d72 Mon Sep 17 00:00:00 2001
From: hzj <826100833@qq.com>
Date: Mon, 3 Nov 2025 16:30:58 +0800
Subject: [PATCH] =?UTF-8?q?=E6=9A=82=E6=80=81=E6=96=87=E4=BB=B6=E5=90=8C?=
=?UTF-8?q?=E6=AD=A5=E5=8A=9F=E8=83=BD=E5=BC=80=E5=8F=91?=
MIME-Version: 1.0
Content-Type: text/plain; charset=UTF-8
Content-Transfer-Encoding: 8bit
---
filesync/.gitignore | 38 ++
filesync/pom.xml | 92 +++++
.../java/com/njcn/FileSyncApplication.java | 15 +
.../njcn/device/mapper/PqDeviceMapper.java | 21 ++
.../com/njcn/device/pojo/po/PqDevice.java | 167 +++++++++
.../njcn/device/service/PqDeviceService.java | 22 ++
.../service/impl/PqDeviceServiceImpl.java | 25 ++
.../njcn/filesync/config/FileSyncState.java | 125 +++++++
.../njcn/filesync/config/ServerConfig.java | 34 ++
.../njcn/filesync/config/SourceConfig.java | 35 ++
.../njcn/filesync/config/TargetConfig.java | 35 ++
.../controller/FileSyncController.java | 51 +++
.../filesync/service/FileSyncService.java | 12 +
.../service/impl/FileSyncServiceImpl.java | 50 +++
.../filesync/sftp/IncrementalFileSync.java | 329 ++++++++++++++++++
.../com/njcn/filesync/sftp/SftpClient.java | 110 ++++++
.../main/java/com/njcn/job/FileSyncJob.java | 47 +++
.../main/resources/application-wuxi_dev.yml | 104 ++++++
filesync/src/main/resources/application.yml | 84 +++++
filesync/src/test/resources/.gitkeep | 0
pom.xml | 2 +
21 files changed, 1398 insertions(+)
create mode 100644 filesync/.gitignore
create mode 100644 filesync/pom.xml
create mode 100644 filesync/src/main/java/com/njcn/FileSyncApplication.java
create mode 100644 filesync/src/main/java/com/njcn/device/mapper/PqDeviceMapper.java
create mode 100644 filesync/src/main/java/com/njcn/device/pojo/po/PqDevice.java
create mode 100644 filesync/src/main/java/com/njcn/device/service/PqDeviceService.java
create mode 100644 filesync/src/main/java/com/njcn/device/service/impl/PqDeviceServiceImpl.java
create mode 100644 filesync/src/main/java/com/njcn/filesync/config/FileSyncState.java
create mode 100644 filesync/src/main/java/com/njcn/filesync/config/ServerConfig.java
create mode 100644 filesync/src/main/java/com/njcn/filesync/config/SourceConfig.java
create mode 100644 filesync/src/main/java/com/njcn/filesync/config/TargetConfig.java
create mode 100644 filesync/src/main/java/com/njcn/filesync/controller/FileSyncController.java
create mode 100644 filesync/src/main/java/com/njcn/filesync/service/FileSyncService.java
create mode 100644 filesync/src/main/java/com/njcn/filesync/service/impl/FileSyncServiceImpl.java
create mode 100644 filesync/src/main/java/com/njcn/filesync/sftp/IncrementalFileSync.java
create mode 100644 filesync/src/main/java/com/njcn/filesync/sftp/SftpClient.java
create mode 100644 filesync/src/main/java/com/njcn/job/FileSyncJob.java
create mode 100644 filesync/src/main/resources/application-wuxi_dev.yml
create mode 100644 filesync/src/main/resources/application.yml
create mode 100644 filesync/src/test/resources/.gitkeep
diff --git a/filesync/.gitignore b/filesync/.gitignore
new file mode 100644
index 0000000..5ff6309
--- /dev/null
+++ b/filesync/.gitignore
@@ -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
\ No newline at end of file
diff --git a/filesync/pom.xml b/filesync/pom.xml
new file mode 100644
index 0000000..fd4c5a2
--- /dev/null
+++ b/filesync/pom.xml
@@ -0,0 +1,92 @@
+
+
+ 4.0.0
+
+
+
+
+ com.njcn
+ data-migration
+ 1.0.0
+
+ filesync
+
+
+
+
+ com.njcn
+ njcn-common
+ 0.0.1
+
+
+
+ com.njcn
+ mybatis-plus
+ 0.0.1
+
+
+
+ com.njcn
+ spingboot2.3.12
+ 2.3.12
+
+
+ org.springframework.boot
+ spring-boot
+
+
+
+
+ com.jcraft
+ jsch
+ 0.1.55
+
+
+ com.njcn
+ mybatis-plus
+ 0.0.1
+
+
+
+ mysql
+ mysql-connector-java
+
+
+
+
+ file-sync
+
+
+ org.springframework.boot
+ spring-boot-maven-plugin
+
+
+ package
+
+ repackage
+
+
+
+
+
+
+ org.apache.maven.plugins
+ maven-compiler-plugin
+ 3.8.1
+
+ 1.8
+ 1.8
+
+
+
+
+
+ src/main/resources
+
+ **/*
+
+
+
+
+
diff --git a/filesync/src/main/java/com/njcn/FileSyncApplication.java b/filesync/src/main/java/com/njcn/FileSyncApplication.java
new file mode 100644
index 0000000..38ca3ff
--- /dev/null
+++ b/filesync/src/main/java/com/njcn/FileSyncApplication.java
@@ -0,0 +1,15 @@
+package com.njcn;
+
+import lombok.extern.slf4j.Slf4j;
+import org.mybatis.spring.annotation.MapperScan;
+import org.springframework.boot.SpringApplication;
+import org.springframework.boot.autoconfigure.SpringBootApplication;
+
+@Slf4j
+@MapperScan("com.njcn.**.mapper")
+@SpringBootApplication(scanBasePackages = "com.njcn")
+public class FileSyncApplication {
+ public static void main(String[] args) {
+ SpringApplication.run(FileSyncApplication.class, args);
+ }
+}
\ No newline at end of file
diff --git a/filesync/src/main/java/com/njcn/device/mapper/PqDeviceMapper.java b/filesync/src/main/java/com/njcn/device/mapper/PqDeviceMapper.java
new file mode 100644
index 0000000..e940a66
--- /dev/null
+++ b/filesync/src/main/java/com/njcn/device/mapper/PqDeviceMapper.java
@@ -0,0 +1,21 @@
+package com.njcn.device.mapper;
+
+
+import com.baomidou.mybatisplus.core.mapper.BaseMapper;
+
+import com.njcn.device.pojo.po.PqDevice;
+import org.apache.ibatis.annotations.Param;
+
+import java.util.List;
+
+/**
+ *
+ * Description:
+ * Date: 2025/06/19 下午 1:47【需求编号】
+ *
+ * @author clam
+ * @version V1.0.0
+ */
+public interface PqDeviceMapper extends BaseMapper {
+
+}
diff --git a/filesync/src/main/java/com/njcn/device/pojo/po/PqDevice.java b/filesync/src/main/java/com/njcn/device/pojo/po/PqDevice.java
new file mode 100644
index 0000000..7376a92
--- /dev/null
+++ b/filesync/src/main/java/com/njcn/device/pojo/po/PqDevice.java
@@ -0,0 +1,167 @@
+package com.njcn.device.pojo.po;
+
+import com.baomidou.mybatisplus.annotation.TableId;
+import com.baomidou.mybatisplus.annotation.TableName;
+import lombok.Data;
+
+import java.io.Serializable;
+import java.time.LocalDate;
+import java.time.LocalDateTime;
+
+/**
+ *
+ * Description:
+ * Date: 2025/06/19 下午 1:47【需求编号】
+ *
+ * @author clam
+ * @version V1.0.0
+ */
+/**
+ * 靠靠?
+ */
+@Data
+@TableName("pq_device")
+public class PqDevice implements Serializable {
+
+ private static final long serialVersionUID = 1L;
+
+ /**
+ * 装置序号
+ */
+ @TableId
+ private String id;
+
+ /**
+ * 装置模型(0:虚拟设备;1:实际设备;2:离线设备;)默认是实际设备
+ */
+ private Integer devModel;
+
+ /**
+ * 数据类型(0:暂态系统;1:稳态系统;2:两个系统)
+ */
+ private Integer devDataType;
+
+ /**
+ * 终端运行状态(0:运行;1:检修;2:停运;3:调试;4:退运)
+ */
+ private Integer runFlag;
+
+ /**
+ * 通讯状态(0:中断;1:正常)
+ */
+ private Integer comFlag;
+
+ /**
+ * 设备制造商,字典表
+ */
+ private String manufacturer;
+
+ /**
+ * 定检状态(0:未检 1:已检)
+ */
+ private Integer checkFlag;
+
+ /**
+ * 前置类型(MMS、CLD)字典表
+ */
+ private String frontType;
+
+ /**
+ * 终端型号(570、580……)字典表
+ */
+ private String devType;
+
+ /**
+ * 网络参数
+ */
+ private String ip;
+
+ /**
+ * 召唤标志(0:周期触发;1:变为触发)
+ */
+ private Integer callFlag;
+
+ /**
+ * 端口
+ */
+ private Integer port;
+
+ /**
+ * 装置识别码(3ds加密)
+ */
+ private String series;
+
+ /**
+ * 装置秘钥(3ds加密)
+ */
+ private String devKey;
+
+ /**
+ * 前置序号Id,前置表
+ */
+ private String nodeId;
+
+ /**
+ * 投运时间
+ */
+ private LocalDate loginTime;
+
+ /**
+ * 数据更新时间
+ */
+ private LocalDateTime updateTime;
+
+ /**
+ * 本次定检时间,默认等于投运时间
+ */
+ private LocalDate thisTimeCheck;
+
+ /**
+ * 下次定检时间,默认为投运时间后推3年,假如时间小于3个月则为待检
+ */
+ private LocalDate nextTimeCheck;
+
+ /**
+ * 电度功能 0 关闭 1开启
+ */
+ private Integer electroplate;
+
+ /**
+ * 对时功能 0 关闭, 1开启
+ */
+ private Integer onTime;
+
+ /**
+ * 合同号
+ */
+ private String contract;
+
+ /**
+ * 设备sim卡号
+ */
+ private String sim;
+
+
+ /**
+ * 装置系列
+ */
+ private String devSeries;
+
+
+ /**
+ * 监测装置安装位置
+ */
+ private String devLocation;
+
+
+ /**
+ * 监测厂家设备编号
+ */
+ private String devNo;
+
+
+ /**
+ * 告警功能 0:关闭 null、1:开启
+ */
+ private Integer isAlarm;
+}
\ No newline at end of file
diff --git a/filesync/src/main/java/com/njcn/device/service/PqDeviceService.java b/filesync/src/main/java/com/njcn/device/service/PqDeviceService.java
new file mode 100644
index 0000000..ec4278f
--- /dev/null
+++ b/filesync/src/main/java/com/njcn/device/service/PqDeviceService.java
@@ -0,0 +1,22 @@
+package com.njcn.device.service;
+
+
+
+import com.baomidou.mybatisplus.extension.service.IService;
+
+import com.njcn.device.pojo.po.PqDevice;
+
+import java.util.List;
+
+/**
+ *
+ * Description:
+ * Date: 2025/06/19 下午 1:47【需求编号】
+ *
+ * @author clam
+ * @version V1.0.0
+ */
+public interface PqDeviceService extends IService {
+
+
+}
diff --git a/filesync/src/main/java/com/njcn/device/service/impl/PqDeviceServiceImpl.java b/filesync/src/main/java/com/njcn/device/service/impl/PqDeviceServiceImpl.java
new file mode 100644
index 0000000..77ec175
--- /dev/null
+++ b/filesync/src/main/java/com/njcn/device/service/impl/PqDeviceServiceImpl.java
@@ -0,0 +1,25 @@
+package com.njcn.device.service.impl;
+
+
+import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
+import com.njcn.device.mapper.PqDeviceMapper;
+
+import com.njcn.device.pojo.po.PqDevice;
+import com.njcn.device.service.PqDeviceService;
+import org.springframework.stereotype.Service;
+
+import java.util.List;
+
+/**
+ *
+ * Description:
+ * Date: 2025/06/19 下午 1:47【需求编号】
+ *
+ * @author clam
+ * @version V1.0.0
+ */
+@Service
+public class PqDeviceServiceImpl extends ServiceImpl implements PqDeviceService {
+
+
+}
diff --git a/filesync/src/main/java/com/njcn/filesync/config/FileSyncState.java b/filesync/src/main/java/com/njcn/filesync/config/FileSyncState.java
new file mode 100644
index 0000000..5626b9b
--- /dev/null
+++ b/filesync/src/main/java/com/njcn/filesync/config/FileSyncState.java
@@ -0,0 +1,125 @@
+package com.njcn.filesync.config;
+
+import com.fasterxml.jackson.core.type.TypeReference;
+import com.fasterxml.jackson.databind.ObjectMapper;
+
+import java.io.File;
+import java.io.IOException;
+import java.io.Serializable;
+import java.nio.file.Files;
+import java.nio.file.Path;
+import java.nio.file.Paths;
+import java.nio.file.attribute.BasicFileAttributes;
+import java.util.HashMap;
+import java.util.Map;
+
+/**
+ * Description:
+ * Date: 2025/10/16 下午 2:58【需求编号】文件同步状态管理
+ *
+ * @author clam
+ * @version V1.0.0
+ */
+public class FileSyncState {
+ private static final ObjectMapper objectMapper = new ObjectMapper();
+ private String stateFilePath;
+ private Map fileStates;
+
+ public static class FileMetadata implements Serializable {
+ private long size;
+ private long lastModified;
+ private String checksum;
+
+ public FileMetadata() {}
+
+ public FileMetadata(long size, long lastModified, String checksum) {
+ this.size = size;
+ this.lastModified = lastModified;
+ this.checksum = checksum;
+ }
+
+ // Getters and Setters
+ public long getSize() { return size; }
+ public void setSize(long size) { this.size = size; }
+
+ public long getLastModified() { return lastModified; }
+ public void setLastModified(long lastModified) { this.lastModified = lastModified; }
+
+ public String getChecksum() { return checksum; }
+ public void setChecksum(String checksum) { this.checksum = checksum; }
+ }
+
+ public FileSyncState(String stateFilePath) {
+ this.stateFilePath = stateFilePath;
+ this.fileStates = new HashMap<>();
+ loadState();
+ }
+
+ @SuppressWarnings("unchecked")
+ private void loadState() {
+ File stateFile = new File(stateFilePath);
+ if (stateFile.exists()) {
+ try {
+ fileStates =objectMapper.readValue(stateFile, new TypeReference