| | |
| | | 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.*; |
| | |
| | | |
| | | @Value("${ftp.address}") |
| | | private String ftpAddress; |
| | | @Value("${operatingSystem}") |
| | | private String operatingSystem; |
| | | @Autowired |
| | | private FtpUtil ftpUtil; |
| | | @Autowired |
| | | private IInfluxdbDeployService influxdbDeployService; |
| | | @Autowired |
| | |
| | | @Autowired |
| | | @Lazy |
| | | private IEmptyParameterService emptyParameterService; |
| | | private static final Log logger = LogFactory.getLog(ServerDeployServiceImpl.class); |
| | | |
| | | @Override |
| | | public ServerDeploy findByServerCode(String serverCode) { |
| | |
| | | @Transactional(rollbackFor = Exception.class) |
| | | public Result<?> addDeployDocument(String id) { |
| | | // 验证FTP连接 |
| | | boolean isConnected = FtpUtil.testFtpConnection(); |
| | | boolean isConnected = ftpUtil.testFtpConnection(); |
| | | if (!isConnected) { |
| | | return Result.error("FTP连接失败,请检查配置!"); |
| | | } |
| | |
| | | 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()); |
| | |
| | | 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"); |
| | | // 上传到ftp |
| | | String basePath = "/deploy"; // FTP服务器基础目录 |
| | | String filePath = serverDeploy.getServerCode() + "/deploy/" + formattedDate; // FTP服务器文件存放路径。例如分日期存放:/2015/01/01。文件的路径为basePath+filePath |
| | | String filename = "CollectionConfiguration.lmx";// 上传到FTP服务器上的文件名 |
| | | //创建一个输入流 |
| | | 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(); |
| | | // 上传到ftp |
| | | if (operatingSystem.equals("windows")) { |
| | | String basePath = "/deploy"; // FTP服务器基础目录 |
| | | String filePath = "/" + serverDeploy.getServerCode() + "/deploy/" + formattedDate; // FTP服务器文件存放路径。例如分日期存放:/2015/01/01。文件的路径为basePath+filePath |
| | | String filename = "CollectionConfiguration.lmx";// 上传到FTP服务器上的文件名 |
| | | //创建一个输入流 |
| | | 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。文件的路径为basePath+filePath |
| | | String filename = "CollectionConfiguration.lmx";// 上传到FTP服务器上的文件名 |
| | | //创建一个输入流 |
| | | 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("配置文件生成成功"); |
| | | } |
| | | } |