| | |
| | | import javax.annotation.Resource; |
| | | import java.io.File; |
| | | import java.net.InetAddress; |
| | | import java.nio.charset.StandardCharsets; |
| | | import java.nio.file.Files; |
| | | import java.nio.file.Paths; |
| | | import java.sql.Connection; |
| | | import java.sql.SQLException; |
| | | import java.util.List; |
| | | import java.util.stream.Collectors; |
| | | import java.util.stream.Stream; |
| | | |
| | | /** |
| | | * @author Lius |
| | |
| | | @Resource |
| | | private IMdcPassLogService mdcPassLogService; |
| | | |
| | | private static final String TYPE = "01"; |
| | | private static final String TYPE = "18"; |
| | | |
| | | @Resource |
| | | private SqlExecutor sqlExecutor; |
| | |
| | | |
| | | // 文件路径 |
| | | String locFilePath = localFilePath + TYPE + today + String.format("%06d", sequenceNumber) + ".xml"; |
| | | FileWriter writer = new FileWriter(locFilePath); |
| | | writer.writeLines(sqlList); |
| | | // FileWriter writer = new FileWriter(locFilePath); |
| | | // writer.writeLines(sqlList); |
| | | String listSql = String.join("\n", sqlList); |
| | | try { |
| | | FileUtils.fileWriterSql(locFilePath, listSql); |
| | | } catch (Exception e) { |
| | | throw new JeecgBootException("数据写入文件失败!"); |
| | | } |
| | | |
| | | // step.4 推送网闸 |
| | | // step.4.1 测试服务器连通性 |
| | | boolean ping = NetUtil.ping(host + ":" + port); |
| | | /* boolean ping = NetUtil.ping(host + ":" + port); |
| | | if (!ping) { |
| | | FileUtil.del(locFilePath); |
| | | throw new JeecgBootException("服务器连接: " + host + ":" + port + " 异常!"); |
| | | } |
| | | }*/ |
| | | |
| | | // step.4.2 获取token |
| | | String token = ""; |
| | |
| | | objectName.setDestination(host); |
| | | objectName.setResult("失败"); |
| | | // 本地文件路径 |
| | | String loFilePath = localFilePath + "\\" + file.getName(); |
| | | String loFilePath = localFilePath + file.getName(); |
| | | // 目标文件路径 |
| | | String servicePathName = servicePath + "\\" + file.getName(); |
| | | String servicePathName = servicePath + file.getName(); |
| | | String result = FileClient.uploadFile(host, port, token, file.getName(), servicePathName, loFilePath, addressUploadFile); |
| | | if ("成功".equals(result)) { |
| | | FileUtil.del(loFilePath); |
| | | if (sequenceNumber == 1) { |
| | | // 删除昨日备份文件夹中历史文件 |
| | | FileUtil.clean(newFilePath); |
| | | } |
| | | // 成功之后将文件备份走 |
| | | FileUtil.move(new File(locFilePath), new File(newFilePath + fileName), true); |
| | | // FileUtil.copy(locFilePath, newFilePath + fileName, true); |
| | | // FileUtil.del(loFilePath); |
| | | objectName.setResult("成功"); |
| | | SyslogClient.sendClient(logIp, Integer.valueOf(logPort), objectName.toString()); |
| | | } else { |
| | |
| | | File[] files = FileUtil.ls(localFilePath); |
| | | for (File file : files) { |
| | | if (file.isFile()) { |
| | | String loFilePath = localFilePath + "\\" + file.getName(); |
| | | String loFilePath = localFilePath + file.getName(); |
| | | FileReader fileReader = new FileReader(loFilePath); |
| | | String sqlList = fileReader.readString(); |
| | | try { |
| | |
| | | } catch (Exception e) { |
| | | throw new JeecgBootException("执行sql失败!"); |
| | | } |
| | | if (Integer.parseInt(file.getName().substring(file.getName().length() - 10, file.getName().length() - 4)) == 1) { |
| | | // 删除历史文件 |
| | | FileUtil.clean(newFilePath); |
| | | } |
| | | |
| | | // 备份 |
| | | FileUtil.move(new File(loFilePath), new File(newFilePath + "\\" + file.getName()), true); |
| | | FileUtil.move(new File(loFilePath), new File(newFilePath + file.getName()), true); |
| | | } |
| | | } |
| | | } |