jinlin
2025-04-01 a80b4a7eb099390bb53c967126fa97b30568e1a3
src/main/java/com/example/server/DataSync/service/DataSyncService.java
@@ -1,10 +1,16 @@
package com.example.server.DataSync.service;
import com.example.Application;
import com.example.client.service.DataExportManageService;
import com.example.client.service.DataImportManageService;
import com.example.client.utils.WaitUtil;
import com.example.server.DataSync.dto.IDUpdateDateDto;
import com.example.server.DataSync.dto.FieldTypeDto;
import com.example.server.mysql.dao.SysMysqlDao;
import com.example.server.progressTrack.dao.ExportRecordDao;
import com.example.server.progressTrack.dao.ImportRecordDao;
import com.example.server.progressTrack.model.ExportRecord;
import com.example.server.progressTrack.model.ImportRecord;
import com.example.server.utils.CacheUtils;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.beans.factory.annotation.Value;
@@ -28,6 +34,14 @@
public class DataSyncService {
    @Autowired
    protected SysMysqlDao sysMysqlDao;
    @Autowired
    protected ExportRecordDao exportRecordDao;
    @Autowired
    protected ImportRecordDao importRecordDao;
    @Autowired
    DataExportManageService dataExportManageService;
    @Autowired
    DataImportManageService dataImportManageService;
    @Value("${data.config-path}")
    private String configPath2;
@@ -40,7 +54,9 @@
    @Value("${spring.datasource.url}")
    private String datasource;
    public void export() {
    public void export(JTextArea tips) {
        final String[] massage = {""};
        String[] parts = datasource.split(":", 3);
        // 定义文件路径
        String dbPath = parts[2];
@@ -53,15 +69,16 @@
        String outputZipPath = showSaveFileDialog(mySite + "同步数据包.zip");
        if (outputZipPath == null) {
            System.out.println("用户取消保存,程序退出。");
        }else{
            massage[0] = "用户取消保存,程序退出。"+ new Date();
            tips.setText(tips.getText() + massage[0]);
        } else {
            final WaitUtil waitUtil = new WaitUtil(imgPath, "数据正在导入,请稍候");
            // 开始上传文件的异步任务
            SwingWorker<String, Void> sw = new SwingWorker<String, Void>() {
                @Override
                protected String doInBackground() throws Exception {
                    String flag =  zipData(dbPath,configPath,directoryPath,outputZipPath);
                    String flag = zipData(dbPath, configPath, directoryPath, outputZipPath);
                    return flag;
                }
@@ -74,9 +91,15 @@
                        // 刷新表格数据(如果上传成功)
                        if (uploadSucceeded.equals("true")) {
                            waitUtil.dispose();
                            System.out.println("导出成功时间" + new Date());
                            massage[0] = "导出成功" + new Date();
                            exportRecordDao.insert(new ExportRecord());
                            List<ExportRecord> list = exportRecordDao.getList();
                            dataExportManageService.refresh(list);
                            tips.setText(tips.getText() + massage[0]);
                        } else {
                            waitUtil.dispose();
                            massage[0] = "导出失败" + new Date();
                            tips.setText(tips.getText() + massage[0]);
                            JOptionPane.showMessageDialog(null, uploadSucceeded, "提示", JOptionPane.ERROR_MESSAGE);
                        }
@@ -92,7 +115,7 @@
        }
    }
    public String zipData(String dbPath,String configPath,String directoryPath,String outputZipPath){
    public String zipData(String dbPath, String configPath, String directoryPath, String outputZipPath) {
        // 创建ZIP文件输出流
        FileOutputStream fos = null;
        ZipOutputStream zos = null;
@@ -123,7 +146,8 @@
        return "true";
    }
    public void importData() {
    public void importData(JTextArea tips) {
        String massage = "";
        InputStream inStream = null;
        Properties properties = new Properties();
        try {
@@ -137,8 +161,8 @@
            // 递归复制文件夹
            copyDirectory(sourceDir, targetDir);
            System.out.println("文件夹复制完成,目标路径:" + targetDir);
            massage = "文件夹复制完成,目标路径:" + targetDir;
            tips.setText(tips.getText() + massage);
            //读取配置
            inStream = new FileInputStream(UnzipPath + "config.properties");
            properties.load(inStream);
@@ -155,7 +179,10 @@
            syncTable("dj_jdgz_network_level3_list");
            syncTable("dj_jdgz_track_record");
            syncTable("dj_sys_oss");
            syncTable("dj_sys_teamgroup_class");
            syncTable("sys_user");
            syncTable("dj_jdgz_dismant_track");
            syncTable("dj_jdgz_ship");
        } else if (mySite.equals("TD")) {
            if (otherSite.equals("TD")) {
                syncTable("dj_jdgz_network_level3");
@@ -164,6 +191,9 @@
                syncTable("dj_sys_oss");
                syncTable("dj_jdgz_dismant_track");
                syncTable("dj_jdgz_handover");
                syncTable("dj_sys_teamgroup_class");
                syncTable("sys_user");
                syncTable("dj_jdgz_ship");
            } else if ("工作组".equals(otherSite)) {
                syncTable("dj_jdgz_handover");
                syncTable("dj_jdgz_network_level1");
@@ -175,6 +205,9 @@
                syncTable("dj_jdgz_track_record");
                syncTable("dj_sys_oss");
                syncTable("dj_jdgz_dismant_track");
                syncTable("dj_sys_teamgroup_class");
                syncTable("sys_user");
                syncTable("dj_jdgz_ship");
            }
        } else if ("厂家".equals(mySite)) {
            syncTable("dj_jdgz_handover");
@@ -188,6 +221,11 @@
            syncTable("dj_sys_oss");
            syncTable("dj_jdgz_dismant_track");
        }
        ImportRecord data =new ImportRecord();
        data.setImportSite(otherSite);
        importRecordDao.insert(data);
        List<ImportRecord> list = importRecordDao.getList();
        dataImportManageService.refresh(list);
    }
    public void syncTable(String tableName) {
@@ -250,7 +288,7 @@
                    java.util.Date otherUpdateDate = dateFormat.parse(otherupdateDate);
                    if (otherUpdateDate.after(mysqlUpdateDate)) {
                        isUpdate = true;
                    }else {
                    } else {
                        continue;
                    }
                }