From fa1f4cdd548662fc2619c4675588b9797e0dd9fa Mon Sep 17 00:00:00 2001 From: Lius <Lius2225@163.com> Date: 星期三, 27 八月 2025 16:16:16 +0800 Subject: [PATCH] update --- lxzn-module-system/lxzn-system-biz/src/main/java/org/jeecg/modules/iot/service/impl/ServerDeployServiceImpl.java | 84 ++++++++++++++++++++++++++++------------- 1 files changed, 57 insertions(+), 27 deletions(-) diff --git a/lxzn-module-system/lxzn-system-biz/src/main/java/org/jeecg/modules/iot/service/impl/ServerDeployServiceImpl.java b/lxzn-module-system/lxzn-system-biz/src/main/java/org/jeecg/modules/iot/service/impl/ServerDeployServiceImpl.java index c30890e..2dffd63 100644 --- a/lxzn-module-system/lxzn-system-biz/src/main/java/org/jeecg/modules/iot/service/impl/ServerDeployServiceImpl.java +++ b/lxzn-module-system/lxzn-system-biz/src/main/java/org/jeecg/modules/iot/service/impl/ServerDeployServiceImpl.java @@ -4,6 +4,8 @@ import com.baomidou.mybatisplus.core.toolkit.CollectionUtils; import com.baomidou.mybatisplus.extension.conditions.query.LambdaQueryChainWrapper; import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl; +import org.apache.commons.logging.Log; +import org.apache.commons.logging.LogFactory; import org.jeecg.common.api.vo.Result; import org.jeecg.modules.iot.entity.*; import org.jeecg.modules.iot.service.*; @@ -42,6 +44,10 @@ @Value("${ftp.address}") private String ftpAddress; + @Value("${operatingSystem}") + private String operatingSystem; + @Autowired + private FtpUtil ftpUtil; @Autowired private IInfluxdbDeployService influxdbDeployService; @Autowired @@ -58,6 +64,7 @@ @Autowired @Lazy private IEmptyParameterService emptyParameterService; + private static final Log logger = LogFactory.getLog(ServerDeployServiceImpl.class); @Override public ServerDeploy findByServerCode(String serverCode) { @@ -104,7 +111,7 @@ @Transactional(rollbackFor = Exception.class) public Result<?> addDeployDocument(String id) { // 楠岃瘉FTP杩炴帴 - boolean isConnected = FtpUtil.testFtpConnection(); + boolean isConnected = ftpUtil.testFtpConnection(); if (!isConnected) { return Result.error("FTP杩炴帴澶辫触锛岃妫�鏌ラ厤缃紒"); } @@ -248,9 +255,9 @@ tagInfo.setAttribute("Name", r.getParameterName()); tagInfo.setAttribute("Address", r.getAddress()); tagInfo.setAttribute("DataType", r.getParameterType()); - if (r.getReadWriteType().equals("鍙")){ + if (r.getReadWriteType().equals("鍙")) { tagInfo.setAttribute("ReadOrWrite", "R"); - }else{ + } else { tagInfo.setAttribute("ReadOrWrite", "R/W"); } tagInfo.setAttribute("Describe", r.getParameterDescribe()); @@ -321,42 +328,65 @@ tf.setOutputProperty(OutputKeys.INDENT, "yes"); // 鍒涘缓xml鏂囦欢骞跺啓鍏ュ唴瀹� tf.transform(new DOMSource(document), new StreamResult(new File("/iot/" + serverDeploy.getServerCode() + "/deploy/" + formattedDate + "/CollectionConfiguration.lmx"))); - // 鍒涘缓鍐欏簱琛ㄧ粨鏋勬煡璇㈣櫄璁惧鍒楄〃锛屽鍔犺澶囪〃 - equipmentService.createEmptyEquipmentTable(serverDeploy.getDeployIssueTime(),serverDeploy.getId()); - // 鏌ヨ铏氳澶囧弬鏁帮紝澧炲姞瀛楁 - emptyParameterService.createEmptyEmptyField(serverDeploy.getDeployIssueTime(),serverDeploy.getId()); } catch (Exception e) { e.printStackTrace(); return Result.error("閰嶇疆鏂囦欢鐢熸垚澶辫触"); } - // 鏇存柊鐗堟湰 - serverDeploy.setLatestDeployVersion(formattedDate); - serverDeploy.setDeployIssueTime(new Date()); - baseMapper.updateById(serverDeploy); - // 鐢熸垚鏈湴鏂囦欢澶� -// FileUtil.createDir("D:/iot/" + serverDeploy.getServerCode() + "/deploy/" + formattedDate); - FileUtil.createDir(ftpAddress + serverDeploy.getServerCode() + "/deploy/" + formattedDate + "/script"); - // 涓婁紶鍒癴tp - String basePath = "/deploy"; // FTP鏈嶅姟鍣ㄥ熀纭�鐩綍 - String filePath = serverDeploy.getServerCode() + "/deploy/" + formattedDate; // FTP鏈嶅姟鍣ㄦ枃浠跺瓨鏀捐矾寰勩�備緥濡傚垎鏃ユ湡瀛樻斁锛�/2015/01/01銆傛枃浠剁殑璺緞涓篵asePath+filePath - String filename = "CollectionConfiguration.lmx";// 涓婁紶鍒癋TP鏈嶅姟鍣ㄤ笂鐨勬枃浠跺悕 - //鍒涘缓涓�涓緭鍏ユ祦 try { - FileInputStream fileInputStream = new FileInputStream(ftpAddress + serverDeploy.getServerCode() + "/deploy/" + formattedDate + "/CollectionConfiguration.lmx"); - FtpUtil.uploadFile(basePath, filePath, filename, fileInputStream); - } catch (FileNotFoundException e) { + // 鍒涘缓鍐欏簱琛ㄧ粨鏋勬煡璇㈣櫄璁惧鍒楄〃锛屽鍔犺澶囪〃 + equipmentService.createEmptyEquipmentTable(serverDeploy.getDeployIssueTime(), serverDeploy.getId()); + // 鏌ヨ铏氳澶囧弬鏁帮紝澧炲姞瀛楁 + emptyParameterService.createEmptyEmptyField(serverDeploy.getDeployIssueTime(), serverDeploy.getId()); + } catch (Exception e) { e.printStackTrace(); + return Result.error("璁惧鍗曡〃锛屽弬鏁扮敓鎴愬け璐�"); } - // 瀛樺偍鑴氭湰锛屽鍒舵暣涓枃浠跺す - FtpUtil.uploadFolder(new File(ftpAddress+serverDeploy.getServerCode()+"/script/"), "/deploy/"+serverDeploy.getServerCode()+"/deploy/"+formattedDate+"/script"); - // 鐢熸垚鑴氭湰 - // 鍙戦�侀厤缃枃浠剁増淇″彿 + + // 鐢熸垚鏈湴鏂囦欢澶� + FileUtil.createDir(ftpAddress + serverDeploy.getServerCode() + "/deploy/" + formattedDate); MqttParameter mqttParameter = new MqttParameter(); + // 涓婁紶鍒癴tp + if (operatingSystem.equals("windows")) { + String basePath = "/deploy"; // FTP鏈嶅姟鍣ㄥ熀纭�鐩綍 + String filePath = "/" + serverDeploy.getServerCode() + "/deploy/" + formattedDate; // FTP鏈嶅姟鍣ㄦ枃浠跺瓨鏀捐矾寰勩�備緥濡傚垎鏃ユ湡瀛樻斁锛�/2015/01/01銆傛枃浠剁殑璺緞涓篵asePath+filePath + String filename = "CollectionConfiguration.lmx";// 涓婁紶鍒癋TP鏈嶅姟鍣ㄤ笂鐨勬枃浠跺悕 + //鍒涘缓涓�涓緭鍏ユ祦 + try { + FileInputStream fileInputStream = new FileInputStream(ftpAddress + serverDeploy.getServerCode() + "/deploy/" + formattedDate + "/CollectionConfiguration.lmx"); + ftpUtil.uploadFile(basePath, filePath, filename, fileInputStream); + } catch (FileNotFoundException e) { + e.printStackTrace(); + } + mqttParameter.setParameter4(basePath + filePath); + logger.info("windows閰嶇疆涓嬪彂鐩綍:" + "deploy/" + serverDeploy.getServerCode() + "/deploy/" + formattedDate); + // 瀛樺偍鑴氭湰锛屽鍒舵暣涓枃浠跺す + ftpUtil.uploadFolder(new File(ftpAddress + serverDeploy.getServerCode() + "/script/"), "/deploy/" + serverDeploy.getServerCode() + "/deploy/" + formattedDate + "/script"); + } else { + String basePath = "/iot"; // FTP鏈嶅姟鍣ㄥ熀纭�鐩綍 + String filePath = "/deploy/" + serverDeploy.getServerCode() + "/deploy/" + formattedDate; // FTP鏈嶅姟鍣ㄦ枃浠跺瓨鏀捐矾寰勩�備緥濡傚垎鏃ユ湡瀛樻斁锛�/2015/01/01銆傛枃浠剁殑璺緞涓篵asePath+filePath + String filename = "CollectionConfiguration.lmx";// 涓婁紶鍒癋TP鏈嶅姟鍣ㄤ笂鐨勬枃浠跺悕 + //鍒涘缓涓�涓緭鍏ユ祦 + try { + FileInputStream fileInputStream = new FileInputStream(ftpAddress + serverDeploy.getServerCode() + "/deploy/" + formattedDate + "/CollectionConfiguration.lmx"); + ftpUtil.uploadFileKylin(basePath, filePath, filename, fileInputStream); + } catch (FileNotFoundException e) { + e.printStackTrace(); + } + mqttParameter.setParameter4("deploy/" + serverDeploy.getServerCode() + "/deploy/" + formattedDate); + logger.info("楹掗簾绯荤粺FTP鐩爣鐩綍:" + "deploy/" + serverDeploy.getServerCode() + "/deploy/" + formattedDate); + // 瀛樺偍鑴氭湰锛屽鍒舵暣涓枃浠跺す + ftpUtil.uploadFolderKylin(new File(ftpAddress + serverDeploy.getServerCode() + "/script/"), "/deploy/" + serverDeploy.getServerCode() + "/deploy/" + formattedDate + "/script"); + } + + // 鍙戦�侀厤缃枃浠剁増淇″彿 mqttParameter.setId(serverDeploy.getServerCode()); mqttParameter.setType("version"); mqttParameter.setParameter2(formattedDate); - mqttParameter.setParameter4(basePath +"/" +filePath); mqttCustomerClient.pushlish(2, false, serverDeploy.getServerCode(), mqttParameter); + // 鏇存柊缁堢鐗堟湰 + serverDeploy.setLatestDeployVersion(formattedDate); + serverDeploy.setDeployIssueTime(new Date()); + baseMapper.updateById(serverDeploy); return Result.ok("閰嶇疆鏂囦欢鐢熸垚鎴愬姛"); } } -- Gitblit v1.9.3