| | |
| | | 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; |
| | |
| | | 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; |
| | |
| | | @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]; |
| | |
| | | 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; |
| | | } |
| | | |
| | |
| | | // 刷新表格数据(如果上传成功) |
| | | 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); |
| | | } |
| | | |
| | |
| | | } |
| | | } |
| | | |
| | | 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; |
| | |
| | | return "true"; |
| | | } |
| | | |
| | | public void importData() { |
| | | public void importData(JTextArea tips) { |
| | | String massage = ""; |
| | | InputStream inStream = null; |
| | | Properties properties = new Properties(); |
| | | try { |
| | |
| | | |
| | | // 递归复制文件夹 |
| | | copyDirectory(sourceDir, targetDir); |
| | | System.out.println("文件夹复制完成,目标路径:" + targetDir); |
| | | |
| | | massage = "文件夹复制完成,目标路径:" + targetDir; |
| | | tips.setText(tips.getText() + massage); |
| | | //读取配置 |
| | | inStream = new FileInputStream(UnzipPath + "config.properties"); |
| | | properties.load(inStream); |
| | |
| | | syncTable("dj_jdgz_network_level3_list"); |
| | | syncTable("dj_jdgz_track_record"); |
| | | syncTable("dj_sys_oss"); |
| | | } else if ("TD".equals(mySite)) { |
| | | if ("TD".equals(otherSite)) { |
| | | syncTable("dj_jdgz_dismant_track"); |
| | | } else if (mySite.equals("TD")) { |
| | | if (otherSite.equals("TD")) { |
| | | syncTable("dj_jdgz_network_level3"); |
| | | syncTable("dj_jdgz_network_level3_list"); |
| | | syncTable("dj_jdgz_track_record"); |
| | | syncTable("dj_sys_oss"); |
| | | syncTable("dj_jdgz_dismant_track"); |
| | | syncTable("dj_jdgz_handover"); |
| | | } else if ("工作组".equals(otherSite)) { |
| | | syncTable("dj_jdgz_handover"); |
| | | syncTable("dj_jdgz_network_level1"); |
| | |
| | | syncTable("dj_jdgz_network_level3_list"); |
| | | 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"); |
| | |
| | | syncTable("dj_jdgz_network_level3_list"); |
| | | syncTable("dj_jdgz_track_record"); |
| | | 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) { |
| | |
| | | java.util.Date otherUpdateDate = dateFormat.parse(otherupdateDate); |
| | | if (otherUpdateDate.after(mysqlUpdateDate)) { |
| | | isUpdate = true; |
| | | }else { |
| | | } else { |
| | | continue; |
| | | } |
| | | } |
| | |
| | | } |
| | | } |
| | | if (isUpdate) { |
| | | updateSql = "update " + tableName + " set " + updateSql + "where id = " + id; |
| | | updateSql = "update " + tableName + " set " + updateSql + " where id = " + id; |
| | | // 执行update |
| | | sysMysqlDao.execute(updateSql); |
| | | } else { |