提交 6c622901 authored 作者: wangqiang's avatar wangqiang

install service

上级 73d2dcb6
<?xml version="1.0" encoding="UTF-8"?>
<project xmlns="http://maven.apache.org/POM/4.0.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 https://maven.apache.org/xsd/maven-4.0.0.xsd">
<modelVersion>4.0.0</modelVersion>
<parent>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-parent</artifactId>
<version>2.4.10</version>
<relativePath/> <!-- lookup parent from repository -->
</parent>
<groupId>com.priusis</groupId>
<artifactId>apq-pc-client</artifactId>
<version>0.0.1-SNAPSHOT</version>
<name>apq-pc-client</name>
<description>apq-pc-client</description>
<properties>
<java.version>1.8</java.version>
<!-- Eclipse Paho 1.1.0 contains major issue with persistence of buffered messages. Using 1.1.1-SNAPSHOT for now. Need to remove this after Paho 1.1.1 release -->
<paho.client.version>1.2.0</paho.client.version>
<milo.client.version>0.1.0</milo.client.version>
<moquette.version>0.10</moquette.version>
<netty.version>4.1.22.Final</netty.version>
<commons-lang3.version>3.4</commons-lang3.version>
<jackson.version>2.10.2</jackson.version>
<spring.version>4.3.4.RELEASE</spring.version>
<spring-boot.version>2.4.10</spring-boot.version>
<slf4j.version>1.7.7</slf4j.version>
<winsw.version>2.0.1</winsw.version>
<pkg.name>apq-pc-client</pkg.name>
<pkg.user>priusis-iot</pkg.user>
<pkg.unixLogFolder>/var/log/${pkg.name}</pkg.unixLogFolder>
<pkg.installFolder>/usr/share/${pkg.name}</pkg.installFolder>
<pkg.win.dist>${project.build.directory}/windows</pkg.win.dist>
<priusis-iot.version>1.0.0-SNAPSHOT</priusis-iot.version>
</properties>
<dependencies>
<dependency>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-web</artifactId>
</dependency>
<dependency>
<groupId>org.hibernate.validator</groupId>
<artifactId>hibernate-validator</artifactId>
</dependency>
<dependency>
<groupId>mysql</groupId>
<artifactId>mysql-connector-java</artifactId>
<scope>runtime</scope>
</dependency>
<dependency>
<groupId>org.projectlombok</groupId>
<artifactId>lombok</artifactId>
<optional>true</optional>
</dependency>
<dependency>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-test</artifactId>
<scope>test</scope>
</dependency>
<dependency>
<groupId>com.priusis</groupId>
<artifactId>netty-mqtt</artifactId>
<version>${priusis-iot.version}</version>
<exclusions>
<exclusion>
<groupId>io.netty</groupId>
<artifactId>netty-all</artifactId>
</exclusion>
</exclusions>
</dependency>
<dependency>
<groupId>org.eclipse.paho</groupId>
<artifactId>org.eclipse.paho.client.mqttv3</artifactId>
<version>${paho.client.version}</version>
</dependency>
<dependency>
<groupId>com.sun.winsw</groupId>
<artifactId>winsw</artifactId>
<version>${winsw.version}</version>
<classifier>bin</classifier>
<type>exe</type>
<scope>provided</scope>
</dependency>
<dependency>
<groupId>org.apache.commons</groupId>
<artifactId>commons-lang3</artifactId>
<version>${commons-lang3.version}</version>
</dependency>
<dependency>
<groupId>io.netty</groupId>
<artifactId>netty-common</artifactId>
<version>${netty.version}</version>
</dependency>
<dependency>
<groupId>io.netty</groupId>
<artifactId>netty-transport</artifactId>
<version>${netty.version}</version>
</dependency>
<dependency>
<groupId>org.slf4j</groupId>
<artifactId>slf4j-api</artifactId>
<version>${slf4j.version}</version>
</dependency>
<dependency>
<groupId>com.fasterxml.jackson.core</groupId>
<artifactId>jackson-databind</artifactId>
<version>${jackson.version}</version>
</dependency>
<dependency>
<groupId>io.moquette</groupId>
<artifactId>moquette-broker</artifactId>
<version>${moquette.version}</version>
<scope>test</scope>
</dependency>
<dependency>
<groupId>com.baomidou</groupId>
<artifactId>mybatis-plus-boot-starter</artifactId>
<version>3.4.3.2</version>
</dependency>
<dependency>
<groupId>cn.hutool</groupId>
<artifactId>hutool-all</artifactId>
<version>5.7.11</version>
</dependency>
<dependency>
<groupId>com.github.oshi</groupId>
<artifactId>oshi-core</artifactId>
<version>3.5.0</version>
</dependency>
<dependency>
<groupId>org.ini4j</groupId>
<artifactId>ini4j</artifactId>
<version>0.5.2</version>
</dependency>
<dependency>
<groupId>junit</groupId>
<artifactId>junit</artifactId>
<scope>test</scope>
</dependency>
</dependencies>
<build>
<finalName>${pkg.name}-${project.version}</finalName>
<resources>
<resource>
<directory>${project.basedir}/src/main/resources</directory>
</resource>
</resources>
<pluginManagement>
<plugins>
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-compiler-plugin</artifactId>
<version>2.5.1</version>
<configuration>
<source>${java.version}</source>
<target>${java.version}</target>
</configuration>
</plugin>
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-resources-plugin</artifactId>
<version>2.7</version>
</plugin>
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-source-plugin</artifactId>
<version>2.2.1</version>
</plugin>
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-jar-plugin</artifactId>
<version>3.0.2</version>
</plugin>
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-assembly-plugin</artifactId>
<version>3.0.0</version>
</plugin>
<plugin>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-maven-plugin</artifactId>
<version>${spring-boot.version}</version>
<configuration>
<excludes>
<exclude>
<groupId>org.projectlombok</groupId>
<artifactId>lombok</artifactId>
</exclude>
</excludes>
</configuration>
</plugin>
</plugins>
</pluginManagement>
<plugins>
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-dependency-plugin</artifactId>
<executions>
<execution>
<id>copy</id>
<phase>package</phase>
<goals>
<goal>copy</goal>
</goals>
<configuration>
<artifactItems>
<artifactItem>
<groupId>com.sun.winsw</groupId>
<artifactId>winsw</artifactId>
<classifier>bin</classifier>
<type>exe</type>
<destFileName>service.exe</destFileName>
</artifactItem>
</artifactItems>
<outputDirectory>${pkg.win.dist}</outputDirectory>
</configuration>
</execution>
</executions>
</plugin>
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-resources-plugin</artifactId>
<executions>
<execution>
<id>copy-service-conf</id>
<phase>process-resources</phase>
<goals>
<goal>copy-resources</goal>
</goals>
<configuration>
<outputDirectory>${project.build.directory}/conf</outputDirectory>
<resources>
<resource>
<directory>src/main/resources</directory>
<excludes>
<exclude>logback.xml</exclude>
</excludes>
<filtering>false</filtering>
</resource>
<resource>
<directory>src/main/conf</directory>
<filtering>true</filtering>
</resource>
</resources>
<filters>
<filter>src/main/filters/unix.properties</filter>
</filters>
</configuration>
</execution>
<execution>
<id>copy-win-conf</id>
<phase>process-resources</phase>
<goals>
<goal>copy-resources</goal>
</goals>
<configuration>
<outputDirectory>${pkg.win.dist}/conf</outputDirectory>
<resources>
<resource>
<directory>src/main/resources</directory>
<excludes>
<exclude>logback.xml</exclude>
</excludes>
<filtering>false</filtering>
</resource>
<resource>
<directory>src/main/conf</directory>
<excludes>
<exclude>pi-gateway.conf</exclude>
</excludes>
<filtering>true</filtering>
</resource>
</resources>
<filters>
<filter>src/main/filters/windows.properties</filter>
</filters>
</configuration>
</execution>
<execution>
<id>copy-control</id>
<phase>process-resources</phase>
<goals>
<goal>copy-resources</goal>
</goals>
<configuration>
<outputDirectory>${project.build.directory}/control</outputDirectory>
<resources>
<resource>
<directory>src/main/scripts/control</directory>
<filtering>true</filtering>
</resource>
</resources>
<filters>
<filter>src/main/filters/unix.properties</filter>
</filters>
</configuration>
</execution>
<execution>
<id>copy-windows-control</id>
<phase>process-resources</phase>
<goals>
<goal>copy-resources</goal>
</goals>
<configuration>
<outputDirectory>${pkg.win.dist}</outputDirectory>
<resources>
<resource>
<directory>src/main/scripts/windows</directory>
<filtering>true</filtering>
</resource>
</resources>
<filters>
<filter>src/main/filters/windows.properties</filter>
</filters>
</configuration>
</execution>
</executions>
</plugin>
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-jar-plugin</artifactId>
<configuration>
<archive>
<manifestEntries>
<Implementation-Title>apq-pc-client</Implementation-Title>
<Implementation-Version>${project.version}</Implementation-Version>
</manifestEntries>
</archive>
</configuration>
</plugin>
<plugin>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-maven-plugin</artifactId>
<configuration>
<classifier>boot</classifier>
<layout>ZIP</layout>
<executable>true</executable>
<excludeDevtools>true</excludeDevtools>
<embeddedLaunchScriptProperties>
<confFolder>${pkg.installFolder}/conf</confFolder>
<logFolder>${pkg.unixLogFolder}</logFolder>
<logFilename>${pkg.name}.out</logFilename>
<initInfoProvides>${pkg.name}</initInfoProvides>
</embeddedLaunchScriptProperties>
</configuration>
<executions>
<execution>
<goals>
<goal>repackage</goal>
</goals>
</execution>
</executions>
</plugin>
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-assembly-plugin</artifactId>
<configuration>
<finalName>${pkg.name}</finalName>
<descriptors>
<descriptor>src/main/assembly/windows.xml</descriptor>
</descriptors>
</configuration>
<executions>
<execution>
<id>assembly</id>
<phase>package</phase>
<goals>
<goal>single</goal>
</goals>
</execution>
</executions>
</plugin>
</plugins>
</build>
</project>
<?xml version="1.0" encoding="UTF-8"?>
<project xmlns="http://maven.apache.org/POM/4.0.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 https://maven.apache.org/xsd/maven-4.0.0.xsd">
<modelVersion>4.0.0</modelVersion>
<parent>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-parent</artifactId>
<version>2.4.10</version>
<relativePath/> <!-- lookup parent from repository -->
</parent>
<groupId>com.priusis</groupId>
<artifactId>apq-pc-client</artifactId>
<version>0.0.1-SNAPSHOT</version>
<name>apq-pc-client</name>
<description>apq-pc-client</description>
<properties>
<java.version>1.8</java.version>
<!-- Eclipse Paho 1.1.0 contains major issue with persistence of buffered messages. Using 1.1.1-SNAPSHOT for now. Need to remove this after Paho 1.1.1 release -->
<paho.client.version>1.2.0</paho.client.version>
<milo.client.version>0.1.0</milo.client.version>
<moquette.version>0.10</moquette.version>
<netty.version>4.1.22.Final</netty.version>
<commons-lang3.version>3.4</commons-lang3.version>
<jackson.version>2.10.2</jackson.version>
<spring.version>4.3.4.RELEASE</spring.version>
<spring-boot.version>2.4.10</spring-boot.version>
<slf4j.version>1.7.7</slf4j.version>
<winsw.version>2.0.1</winsw.version>
<pkg.name>apq-pc-client</pkg.name>
<pkg.user>priusis-iot</pkg.user>
<pkg.unixLogFolder>/var/log/${pkg.name}</pkg.unixLogFolder>
<pkg.installFolder>/usr/share/${pkg.name}</pkg.installFolder>
<pkg.win.dist>${project.build.directory}/windows</pkg.win.dist>
<priusis-iot.version>1.0.0-SNAPSHOT</priusis-iot.version>
</properties>
<dependencies>
<dependency>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-web</artifactId>
</dependency>
<dependency>
<groupId>org.hibernate.validator</groupId>
<artifactId>hibernate-validator</artifactId>
</dependency>
<dependency>
<groupId>mysql</groupId>
<artifactId>mysql-connector-java</artifactId>
<scope>runtime</scope>
</dependency>
<dependency>
<groupId>org.projectlombok</groupId>
<artifactId>lombok</artifactId>
<optional>true</optional>
</dependency>
<dependency>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-test</artifactId>
<scope>test</scope>
</dependency>
<dependency>
<groupId>com.priusis</groupId>
<artifactId>netty-mqtt</artifactId>
<version>${priusis-iot.version}</version>
<exclusions>
<exclusion>
<groupId>io.netty</groupId>
<artifactId>netty-all</artifactId>
</exclusion>
</exclusions>
</dependency>
<dependency>
<groupId>org.eclipse.paho</groupId>
<artifactId>org.eclipse.paho.client.mqttv3</artifactId>
<version>${paho.client.version}</version>
</dependency>
<dependency>
<groupId>com.sun.winsw</groupId>
<artifactId>winsw</artifactId>
<version>${winsw.version}</version>
<classifier>bin</classifier>
<type>exe</type>
<scope>provided</scope>
</dependency>
<dependency>
<groupId>org.apache.commons</groupId>
<artifactId>commons-lang3</artifactId>
<version>${commons-lang3.version}</version>
</dependency>
<dependency>
<groupId>io.netty</groupId>
<artifactId>netty-common</artifactId>
<version>${netty.version}</version>
</dependency>
<dependency>
<groupId>io.netty</groupId>
<artifactId>netty-transport</artifactId>
<version>${netty.version}</version>
</dependency>
<dependency>
<groupId>org.slf4j</groupId>
<artifactId>slf4j-api</artifactId>
<version>${slf4j.version}</version>
</dependency>
<dependency>
<groupId>com.fasterxml.jackson.core</groupId>
<artifactId>jackson-databind</artifactId>
<version>${jackson.version}</version>
</dependency>
<dependency>
<groupId>io.moquette</groupId>
<artifactId>moquette-broker</artifactId>
<version>${moquette.version}</version>
<scope>test</scope>
</dependency>
<dependency>
<groupId>com.baomidou</groupId>
<artifactId>mybatis-plus-boot-starter</artifactId>
<version>3.4.3.2</version>
</dependency>
<dependency>
<groupId>cn.hutool</groupId>
<artifactId>hutool-all</artifactId>
<version>5.7.11</version>
</dependency>
<dependency>
<groupId>com.github.oshi</groupId>
<artifactId>oshi-core</artifactId>
<version>3.5.0</version>
</dependency>
<dependency>
<groupId>org.ini4j</groupId>
<artifactId>ini4j</artifactId>
<version>0.5.2</version>
</dependency>
<dependency>
<groupId>junit</groupId>
<artifactId>junit</artifactId>
<scope>test</scope>
</dependency>
</dependencies>
<build>
<finalName>${pkg.name}-${project.version}</finalName>
<resources>
<resource>
<directory>${project.basedir}/src/main/resources</directory>
</resource>
</resources>
<pluginManagement>
<plugins>
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-compiler-plugin</artifactId>
<version>2.5.1</version>
<configuration>
<source>${java.version}</source>
<target>${java.version}</target>
</configuration>
</plugin>
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-resources-plugin</artifactId>
<version>2.7</version>
</plugin>
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-source-plugin</artifactId>
<version>2.2.1</version>
</plugin>
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-jar-plugin</artifactId>
<version>3.0.2</version>
</plugin>
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-assembly-plugin</artifactId>
<version>3.0.0</version>
</plugin>
<plugin>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-maven-plugin</artifactId>
<version>${spring-boot.version}</version>
<configuration>
<excludes>
<exclude>
<groupId>org.projectlombok</groupId>
<artifactId>lombok</artifactId>
</exclude>
</excludes>
</configuration>
</plugin>
</plugins>
</pluginManagement>
<plugins>
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-dependency-plugin</artifactId>
<executions>
<execution>
<id>copy</id>
<phase>package</phase>
<goals>
<goal>copy</goal>
</goals>
<configuration>
<artifactItems>
<artifactItem>
<groupId>com.sun.winsw</groupId>
<artifactId>winsw</artifactId>
<classifier>bin</classifier>
<type>exe</type>
<destFileName>service.exe</destFileName>
</artifactItem>
</artifactItems>
<outputDirectory>${pkg.win.dist}</outputDirectory>
</configuration>
</execution>
</executions>
</plugin>
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-resources-plugin</artifactId>
<executions>
<execution>
<id>copy-service-conf</id>
<phase>process-resources</phase>
<goals>
<goal>copy-resources</goal>
</goals>
<configuration>
<outputDirectory>${project.build.directory}/conf</outputDirectory>
<resources>
<resource>
<directory>src/main/resources</directory>
<excludes>
<exclude>logback.xml</exclude>
</excludes>
<filtering>false</filtering>
</resource>
<resource>
<directory>src/main/conf</directory>
<filtering>true</filtering>
</resource>
</resources>
<filters>
<filter>src/main/filters/unix.properties</filter>
</filters>
</configuration>
</execution>
<execution>
<id>copy-win-conf</id>
<phase>process-resources</phase>
<goals>
<goal>copy-resources</goal>
</goals>
<configuration>
<outputDirectory>${pkg.win.dist}/conf</outputDirectory>
<resources>
<resource>
<directory>src/main/resources</directory>
<excludes>
<exclude>logback.xml</exclude>
</excludes>
<filtering>false</filtering>
</resource>
<resource>
<directory>src/main/conf</directory>
<excludes>
<exclude>pi-gateway.conf</exclude>
</excludes>
<filtering>true</filtering>
</resource>
</resources>
<filters>
<filter>src/main/filters/windows.properties</filter>
</filters>
</configuration>
</execution>
<execution>
<id>copy-control</id>
<phase>process-resources</phase>
<goals>
<goal>copy-resources</goal>
</goals>
<configuration>
<outputDirectory>${project.build.directory}/control</outputDirectory>
<resources>
<resource>
<directory>src/main/scripts/control</directory>
<filtering>true</filtering>
</resource>
</resources>
<filters>
<filter>src/main/filters/unix.properties</filter>
</filters>
</configuration>
</execution>
<execution>
<id>copy-windows-control</id>
<phase>process-resources</phase>
<goals>
<goal>copy-resources</goal>
</goals>
<configuration>
<outputDirectory>${pkg.win.dist}</outputDirectory>
<resources>
<resource>
<directory>src/main/scripts/windows</directory>
<filtering>true</filtering>
</resource>
</resources>
<filters>
<filter>src/main/filters/windows.properties</filter>
</filters>
</configuration>
</execution>
</executions>
</plugin>
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-jar-plugin</artifactId>
<configuration>
<archive>
<manifestEntries>
<Implementation-Title>apq-pc-client</Implementation-Title>
<Implementation-Version>${project.version}</Implementation-Version>
</manifestEntries>
</archive>
</configuration>
</plugin>
<plugin>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-maven-plugin</artifactId>
<configuration>
<classifier>boot</classifier>
<layout>ZIP</layout>
<executable>true</executable>
<excludeDevtools>true</excludeDevtools>
<embeddedLaunchScriptProperties>
<confFolder>${pkg.installFolder}/conf</confFolder>
<logFolder>${pkg.unixLogFolder}</logFolder>
<logFilename>${pkg.name}.out</logFilename>
<initInfoProvides>${pkg.name}</initInfoProvides>
</embeddedLaunchScriptProperties>
</configuration>
<executions>
<execution>
<goals>
<goal>repackage</goal>
</goals>
</execution>
</executions>
</plugin>
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-assembly-plugin</artifactId>
<configuration>
<finalName>${pkg.name}</finalName>
<descriptors>
<descriptor>src/main/assembly/windows.xml</descriptor>
</descriptors>
</configuration>
<executions>
<execution>
<id>assembly</id>
<phase>package</phase>
<goals>
<goal>single</goal>
</goals>
</execution>
</executions>
</plugin>
</plugins>
</build>
</project>
package com.priusis;
import org.springframework.boot.SpringApplication;
import org.springframework.boot.autoconfigure.SpringBootApplication;
import org.springframework.boot.autoconfigure.jdbc.DataSourceAutoConfiguration;
import org.springframework.boot.autoconfigure.security.servlet.SecurityAutoConfiguration;
import org.springframework.scheduling.annotation.EnableScheduling;
@EnableScheduling
@SpringBootApplication(exclude = {DataSourceAutoConfiguration.class, SecurityAutoConfiguration.class})
public class ApqClientApplication {
public static void main(String[] args) {
SpringApplication.run(ApqClientApplication.class, args);
}
}
package com.priusis;
import org.springframework.boot.SpringApplication;
import org.springframework.boot.autoconfigure.SpringBootApplication;
import org.springframework.boot.autoconfigure.jdbc.DataSourceAutoConfiguration;
import org.springframework.boot.autoconfigure.security.servlet.SecurityAutoConfiguration;
import org.springframework.scheduling.annotation.EnableScheduling;
@EnableScheduling
@SpringBootApplication(exclude = {DataSourceAutoConfiguration.class, SecurityAutoConfiguration.class})
public class ApqClientApplication {
public static void main(String[] args) {
SpringApplication.run(ApqClientApplication.class, args);
}
}
package com.priusis.controller;
import cn.hutool.core.io.unit.DataSizeUtil;
import cn.hutool.core.map.MapUtil;
import cn.hutool.core.util.StrUtil;
import cn.hutool.json.JSONObject;
import cn.hutool.json.JSONUtil;
import cn.hutool.system.oshi.OshiUtil;
import com.priusis.lib.R;
import com.priusis.util.MacAddrUtil;
import lombok.extern.slf4j.Slf4j;
import org.springframework.scheduling.annotation.Scheduled;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;
import oshi.hardware.HWDiskStore;
import oshi.hardware.HWPartition;
import javax.annotation.PostConstruct;
import java.io.File;
import java.net.InetAddress;
import java.net.SocketException;
import java.net.UnknownHostException;
import java.text.DecimalFormat;
import java.util.Arrays;
import java.util.Map;
import java.util.stream.Collectors;
/**
* @author yangli
* @since 2021/09/06
*/
@Slf4j
@RestController
@RequestMapping(value = "device_info")
public class DeviceInfoController {
private Map<String, Object> info;
@GetMapping(value = "get")
public R<Map<String, Object>> get() throws UnknownHostException, SocketException {
if (info == null) refresh();
return R.success(info);
}
@Scheduled(fixedDelay = 5000)
protected void refresh() throws UnknownHostException {
JSONObject diskModel = null;
JSONObject diskCap = null;
JSONObject diskFree = null;
try {
diskModel = JSONUtil.parseObj(Arrays.stream(OshiUtil.getHardware().getDiskStores())
.map(store -> Arrays.stream(store.getPartitions())
.map(HWPartition::getMountPoint)
.filter(StrUtil::isNotBlank)
.map(s -> "\"" + StrUtil.removeSuffix(s, ":\\") + "盘\":\"" +
StrUtil.removeSuffix(store.getModel(), " (标准磁盘驱动器)") + "\"")
.collect(Collectors.joining(",")))
.filter(StrUtil::isNotBlank)
.collect(Collectors.joining(",", "{", "}")));
diskCap = JSONUtil.parseObj(Arrays.stream(OshiUtil.getHardware().getDiskStores())
.map(HWDiskStore::getPartitions)
.flatMap(Arrays::stream)
.filter(partition -> StrUtil.isNotBlank(partition.getMountPoint()))
.map(partition -> "\"" + StrUtil.removeSuffix(partition.getMountPoint(), ":\\") + "盘\":\"" +
DataSizeUtil.format(partition.getSize()) + "\"")
.collect(Collectors.joining(",", "{", "}")));
diskFree = JSONUtil.parseObj(Arrays.stream(OshiUtil.getHardware().getDiskStores())
.map(HWDiskStore::getPartitions)
.flatMap(Arrays::stream)
.filter(partition -> StrUtil.isNotBlank(partition.getMountPoint()))
.map(partition -> "\"" + StrUtil.removeSuffix(partition.getMountPoint(), ":\\") + "盘\":\"" +
new DecimalFormat("#.00").format(100d * new File(partition.getMountPoint()).getFreeSpace() / partition.getSize()) + "%\"")
.collect(Collectors.joining(",", "{", "}")));
} catch (Exception e) {
log.error("硬盘数据获取失败", e);
}
info = MapUtil.<String, Object>builder()
.put("operatingSystem", OshiUtil.getOs().toString())
.put("mac", MacAddrUtil.get())
.put("baseboard", OshiUtil.getSystem().getBaseboard().getManufacturer() + " " + OshiUtil.getSystem().getBaseboard().getVersion())
.put("ip", InetAddress.getLocalHost().getHostAddress())
.put("cpuModel", OshiUtil.getCpuInfo(0).getCpuModel())
.put("cpuTemp", Double.parseDouble(new DecimalFormat("#.00").format(OshiUtil.getSensors().getCpuTemperature())))
.put("memoryCap", DataSizeUtil.format(OshiUtil.getMemory().getTotal()))
.put("diskModel", diskModel)
.put("diskCap", diskCap)
.put("diskFree", diskFree)
.build();
}
@PostConstruct
public void init() {
try {
refresh();
} catch (Exception e) {
log.error("初始化失败", e);
}
}
public static void main(String[] args) throws UnknownHostException {
System.out.println("操作系统");
System.out.println(OshiUtil.getOs().toString());
System.out.println("MAC地址");
System.out.println(MacAddrUtil.get());
System.out.println("主板");
System.out.println(OshiUtil.getSystem().getBaseboard().getManufacturer() + " " + OshiUtil.getSystem().getBaseboard().getVersion());
System.out.println("IP");
System.out.println(InetAddress.getLocalHost().getHostAddress());
System.out.println("CPU型号");
System.out.println(OshiUtil.getCpuInfo(0).getCpuModel());
System.out.println("CPU温度");
System.out.println(Double.parseDouble(new DecimalFormat("#.00").format(OshiUtil.getSensors().getCpuTemperature())));
System.out.println("内存容量");
System.out.println(DataSizeUtil.format(OshiUtil.getMemory().getTotal()));
System.out.println("硬盘型号");
System.out.println(Arrays.stream(OshiUtil.getHardware().getDiskStores())
.map(store -> Arrays.stream(store.getPartitions())
.map(HWPartition::getMountPoint)
.filter(StrUtil::isNotBlank)
.map(s -> "\"" + StrUtil.removeSuffix(s, ":\\") + "盘\":\"" +
StrUtil.removeSuffix(store.getModel(), " (标准磁盘驱动器)") + "\"")
.collect(Collectors.joining(",")))
.filter(StrUtil::isNotBlank)
.collect(Collectors.joining(",", "{", "}")));
System.out.println("硬盘容量");
System.out.println(Arrays.stream(OshiUtil.getHardware().getDiskStores())
.map(HWDiskStore::getPartitions)
.flatMap(Arrays::stream)
.filter(partition -> StrUtil.isNotBlank(partition.getMountPoint()))
.map(partition -> "\"" + StrUtil.removeSuffix(partition.getMountPoint(), ":\\") + "盘\":\"" +
DataSizeUtil.format(partition.getSize()) + "\"")
.collect(Collectors.joining(",", "{", "}")));
System.out.println("硬盘剩余");
DecimalFormat formatter = new DecimalFormat("#.00");
System.out.println(Arrays.stream(OshiUtil.getHardware().getDiskStores())
.map(HWDiskStore::getPartitions)
.flatMap(Arrays::stream)
.filter(partition -> StrUtil.isNotBlank(partition.getMountPoint()))
.map(partition -> "\"" + StrUtil.removeSuffix(partition.getMountPoint(), ":\\") + "盘\":\"" +
formatter.format(100d * new File(partition.getMountPoint()).getFreeSpace() / partition.getSize()) + "%\"")
.collect(Collectors.joining(",", "{", "}")));
}
}
package com.priusis.controller;
import cn.hutool.core.io.unit.DataSizeUtil;
import cn.hutool.core.map.MapUtil;
import cn.hutool.core.util.StrUtil;
import cn.hutool.json.JSONObject;
import cn.hutool.json.JSONUtil;
import cn.hutool.system.oshi.OshiUtil;
import com.priusis.lib.R;
import com.priusis.util.MacAddrUtil;
import lombok.extern.slf4j.Slf4j;
import org.springframework.scheduling.annotation.Scheduled;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;
import oshi.hardware.HWDiskStore;
import oshi.hardware.HWPartition;
import javax.annotation.PostConstruct;
import java.io.File;
import java.net.InetAddress;
import java.net.SocketException;
import java.net.UnknownHostException;
import java.text.DecimalFormat;
import java.util.Arrays;
import java.util.Map;
import java.util.stream.Collectors;
/**
* @author yangli
* @since 2021/09/06
*/
@Slf4j
@RestController
@RequestMapping(value = "device_info")
public class DeviceInfoController {
private Map<String, Object> info;
@GetMapping(value = "get")
public R<Map<String, Object>> get() throws UnknownHostException, SocketException {
if (info == null) refresh();
return R.success(info);
}
@Scheduled(fixedDelay = 5000)
protected void refresh() throws UnknownHostException {
JSONObject diskModel = null;
JSONObject diskCap = null;
JSONObject diskFree = null;
HWDiskStore[] diskStores = null;
try {
diskStores = OshiUtil.getHardware().getDiskStores();
diskModel = JSONUtil.parseObj(Arrays.stream(diskStores)
.map(store -> Arrays.stream(store.getPartitions())
.map(HWPartition::getMountPoint)
.filter(StrUtil::isNotBlank)
.map(s -> "\"" + StrUtil.removeSuffix(s, ":\\") + "盘\":\"" +
StrUtil.removeSuffix(store.getModel(), " (标准磁盘驱动器)") + "\"")
.collect(Collectors.joining(",")))
.filter(StrUtil::isNotBlank)
.collect(Collectors.joining(",", "{", "}")));
diskCap = JSONUtil.parseObj(Arrays.stream(diskStores)
.map(HWDiskStore::getPartitions)
.flatMap(Arrays::stream)
.filter(partition -> StrUtil.isNotBlank(partition.getMountPoint()))
.map(partition -> "\"" + StrUtil.removeSuffix(partition.getMountPoint(), ":\\") + "盘\":\"" +
DataSizeUtil.format(partition.getSize()) + "\"")
.collect(Collectors.joining(",", "{", "}")));
diskFree = JSONUtil.parseObj(Arrays.stream(diskStores)
.map(HWDiskStore::getPartitions)
.flatMap(Arrays::stream)
.filter(partition -> StrUtil.isNotBlank(partition.getMountPoint()))
.map(partition -> "\"" + StrUtil.removeSuffix(partition.getMountPoint(), ":\\") + "盘\":\"" +
new DecimalFormat("#.00").format(100d * new File(partition.getMountPoint()).getFreeSpace() / partition.getSize()) + "%\"")
.collect(Collectors.joining(",", "{", "}")));
} catch (Exception e) {
log.error("硬盘数据获取失败", e);
if (null != diskStores) {
for (HWDiskStore diskStore : diskStores) {
HWPartition[] partitions = diskStore.getPartitions();
if (null != partitions) {
for (HWPartition partition : partitions) {
log.error("硬盘数据获取失败: {}", partition.getMountPoint());
}
}
}
}
}
info = MapUtil.<String, Object>builder()
.put("operatingSystem", OshiUtil.getOs().toString())
.put("mac", MacAddrUtil.get())
.put("baseboard", OshiUtil.getSystem().getBaseboard().getManufacturer() + " " + OshiUtil.getSystem().getBaseboard().getVersion())
.put("ip", InetAddress.getLocalHost().getHostAddress())
.put("cpuModel", OshiUtil.getCpuInfo(0).getCpuModel())
.put("cpuTemp", Double.parseDouble(new DecimalFormat("#.00").format(OshiUtil.getSensors().getCpuTemperature())))
.put("memoryCap", DataSizeUtil.format(OshiUtil.getMemory().getTotal()))
.put("diskModel", diskModel)
.put("diskCap", diskCap)
.put("diskFree", diskFree)
.build();
}
@PostConstruct
public void init() {
try {
refresh();
} catch (Exception e) {
log.error("初始化失败", e);
}
}
public static void main(String[] args) throws UnknownHostException {
System.out.println("操作系统");
System.out.println(OshiUtil.getOs().toString());
System.out.println("MAC地址");
System.out.println(MacAddrUtil.get());
System.out.println("主板");
System.out.println(OshiUtil.getSystem().getBaseboard().getManufacturer() + " " + OshiUtil.getSystem().getBaseboard().getVersion());
System.out.println("IP");
System.out.println(InetAddress.getLocalHost().getHostAddress());
System.out.println("CPU型号");
System.out.println(OshiUtil.getCpuInfo(0).getCpuModel());
System.out.println("CPU温度");
System.out.println(Double.parseDouble(new DecimalFormat("#.00").format(OshiUtil.getSensors().getCpuTemperature())));
System.out.println("内存容量");
System.out.println(DataSizeUtil.format(OshiUtil.getMemory().getTotal()));
System.out.println("硬盘型号");
System.out.println(Arrays.stream(OshiUtil.getHardware().getDiskStores())
.map(store -> Arrays.stream(store.getPartitions())
.map(HWPartition::getMountPoint)
.filter(StrUtil::isNotBlank)
.map(s -> "\"" + StrUtil.removeSuffix(s, ":\\") + "盘\":\"" +
StrUtil.removeSuffix(store.getModel(), " (标准磁盘驱动器)") + "\"")
.collect(Collectors.joining(",")))
.filter(StrUtil::isNotBlank)
.collect(Collectors.joining(",", "{", "}")));
System.out.println("硬盘容量");
System.out.println(Arrays.stream(OshiUtil.getHardware().getDiskStores())
.map(HWDiskStore::getPartitions)
.flatMap(Arrays::stream)
.filter(partition -> StrUtil.isNotBlank(partition.getMountPoint()))
.map(partition -> "\"" + StrUtil.removeSuffix(partition.getMountPoint(), ":\\") + "盘\":\"" +
DataSizeUtil.format(partition.getSize()) + "\"")
.collect(Collectors.joining(",", "{", "}")));
System.out.println("硬盘剩余");
DecimalFormat formatter = new DecimalFormat("#.00");
System.out.println(Arrays.stream(OshiUtil.getHardware().getDiskStores())
.map(HWDiskStore::getPartitions)
.flatMap(Arrays::stream)
.filter(partition -> StrUtil.isNotBlank(partition.getMountPoint()))
.map(partition -> "\"" + StrUtil.removeSuffix(partition.getMountPoint(), ":\\") + "盘\":\"" +
formatter.format(100d * new File(partition.getMountPoint()).getFreeSpace() / partition.getSize()) + "%\"")
.collect(Collectors.joining(",", "{", "}")));
}
}
package com.priusis.vo;
import lombok.Data;
import java.io.Serializable;
@Data
public class ApqInfoDataVo implements Serializable {
private String code;
private String name;
private int frequency;
}
package com.priusis.vo;
import lombok.Data;
import java.io.Serializable;
@Data
public class MqttRpcDataMessage implements Serializable {
private static final long serialVersionUID = -3133461476074777891L;
private int requestId;
private String method;
private String params;
@Override
public String toString() {
return "{requestId=" + requestId +
", method=" + method +
", params=" + params +
'}';
}
}
@ECHO OFF
setlocal ENABLEEXTENSIONS
@ECHO Detecting Java version installed.
:CHECK_JAVA_64
@ECHO Detecting if it is 64 bit machine
set KEY_NAME="HKEY_LOCAL_MACHINE\Software\Wow6432Node\JavaSoft\Java Runtime Environment"
set VALUE_NAME=CurrentVersion
FOR /F "usebackq skip=2 tokens=1-3" %%A IN (`REG QUERY %KEY_NAME% /v %VALUE_NAME% 2^>nul`) DO (
set ValueName=%%A
set ValueType=%%B
set ValueValue=%%C
)
@ECHO CurrentVersion %ValueValue%
SET KEY_NAME="%KEY_NAME:~1,-1%\%ValueValue%"
SET VALUE_NAME=JavaHome
if defined ValueName (
FOR /F "usebackq skip=2 tokens=1,2*" %%A IN (`REG QUERY %KEY_NAME% /v %VALUE_NAME% 2^>nul`) DO (
set ValueName2=%%A
set ValueType2=%%B
set JRE_PATH2=%%C
if defined ValueName2 (
set ValueName = %ValueName2%
set ValueType = %ValueType2%
set ValueValue = %JRE_PATH2%
)
)
)
IF NOT "%JRE_PATH2%" == "" GOTO JAVA_INSTALLED
:CHECK_JAVA_32
@ECHO Detecting if it is 32 bit machine
set KEY_NAME="HKEY_LOCAL_MACHINE\Software\JavaSoft\Java Runtime Environment"
set VALUE_NAME=CurrentVersion
FOR /F "usebackq skip=2 tokens=1-3" %%A IN (`REG QUERY %KEY_NAME% /v %VALUE_NAME% 2^>nul`) DO (
set ValueName=%%A
set ValueType=%%B
set ValueValue=%%C
)
@ECHO CurrentVersion %ValueValue%
SET KEY_NAME="%KEY_NAME:~1,-1%\%ValueValue%"
SET VALUE_NAME=JavaHome
if defined ValueName (
FOR /F "usebackq skip=2 tokens=1,2*" %%A IN (`REG QUERY %KEY_NAME% /v %VALUE_NAME% 2^>nul`) DO (
set ValueName2=%%A
set ValueType2=%%B
set JRE_PATH2=%%C
if defined ValueName2 (
set ValueName = %ValueName2%
set ValueType = %ValueType2%
set ValueValue = %JRE_PATH2%
)
)
)
IF "%JRE_PATH2%" == "" GOTO JAVA_NOT_INSTALLED
:JAVA_INSTALLED
@ECHO Java 1.8 found!
@ECHO Installing apq-pc-client ...
%~dp0apq-pc-client.exe install
@ECHO runing apq-pc-client ...
%~dp0apq-pc-client.exe start
@ECHO DONE.
GOTO END
:JAVA_NOT_INSTALLED
@ECHO Java 1.8 or above is not installed
@ECHO Please go to https://java.com/ and install Java. Then retry installation.
PAUSE
GOTO END
:END
@ECHO OFF
setlocal ENABLEEXTENSIONS
@ECHO Detecting Java version installed.
:CHECK_JAVA_64
@ECHO Detecting if it is 64 bit machine
set KEY_NAME="HKEY_LOCAL_MACHINE\Software\Wow6432Node\JavaSoft\Java Runtime Environment"
set VALUE_NAME=CurrentVersion
FOR /F "usebackq skip=2 tokens=1-3" %%A IN (`REG QUERY %KEY_NAME% /v %VALUE_NAME% 2^>nul`) DO (
set ValueName=%%A
set ValueType=%%B
set ValueValue=%%C
)
@ECHO CurrentVersion %ValueValue%
SET KEY_NAME="%KEY_NAME:~1,-1%\%ValueValue%"
SET VALUE_NAME=JavaHome
if defined ValueName (
FOR /F "usebackq skip=2 tokens=1,2*" %%A IN (`REG QUERY %KEY_NAME% /v %VALUE_NAME% 2^>nul`) DO (
set ValueName2=%%A
set ValueType2=%%B
set JRE_PATH2=%%C
if defined ValueName2 (
set ValueName = %ValueName2%
set ValueType = %ValueType2%
set ValueValue = %JRE_PATH2%
)
)
)
IF NOT "%JRE_PATH2%" == "" GOTO JAVA_INSTALLED
:CHECK_JAVA_32
@ECHO Detecting if it is 32 bit machine
set KEY_NAME="HKEY_LOCAL_MACHINE\Software\JavaSoft\Java Runtime Environment"
set VALUE_NAME=CurrentVersion
FOR /F "usebackq skip=2 tokens=1-3" %%A IN (`REG QUERY %KEY_NAME% /v %VALUE_NAME% 2^>nul`) DO (
set ValueName=%%A
set ValueType=%%B
set ValueValue=%%C
)
@ECHO CurrentVersion %ValueValue%
SET KEY_NAME="%KEY_NAME:~1,-1%\%ValueValue%"
SET VALUE_NAME=JavaHome
if defined ValueName (
FOR /F "usebackq skip=2 tokens=1,2*" %%A IN (`REG QUERY %KEY_NAME% /v %VALUE_NAME% 2^>nul`) DO (
set ValueName2=%%A
set ValueType2=%%B
set JRE_PATH2=%%C
if defined ValueName2 (
set ValueName = %ValueName2%
set ValueType = %ValueType2%
set ValueValue = %JRE_PATH2%
)
)
)
IF "%JRE_PATH2%" == "" GOTO JAVA_NOT_INSTALLED
:JAVA_INSTALLED
@ECHO Java 1.8 found!
@ECHO Installing apq-pc-client ...
%~dp0apq-pc-client.exe install
@ECHO running apq-pc-client ...
%~dp0apq-pc-client.exe start
@ECHO DONE.
GOTO END
:JAVA_NOT_INSTALLED
@ECHO Java 1.8 or above is not installed
@ECHO Please go to https://java.com/ and install Java. Then retry installation.
PAUSE
GOTO END
:END
@ECHO OFF
setlocal ENABLEEXTENSIONS
@ECHO Detecting Java version installed.
:CHECK_JAVA_64
@ECHO Detecting if it is 64 bit machine
set KEY_NAME="HKEY_LOCAL_MACHINE\Software\Wow6432Node\JavaSoft\Java Runtime Environment"
set VALUE_NAME=CurrentVersion
FOR /F "usebackq skip=2 tokens=1-3" %%A IN (`REG QUERY %KEY_NAME% /v %VALUE_NAME% 2^>nul`) DO (
set ValueName=%%A
set ValueType=%%B
set ValueValue=%%C
)
@ECHO CurrentVersion %ValueValue%
SET KEY_NAME="%KEY_NAME:~1,-1%\%ValueValue%"
SET VALUE_NAME=JavaHome
if defined ValueName (
FOR /F "usebackq skip=2 tokens=1,2*" %%A IN (`REG QUERY %KEY_NAME% /v %VALUE_NAME% 2^>nul`) DO (
set ValueName2=%%A
set ValueType2=%%B
set JRE_PATH2=%%C
if defined ValueName2 (
set ValueName = %ValueName2%
set ValueType = %ValueType2%
set ValueValue = %JRE_PATH2%
)
)
)
IF NOT "%JRE_PATH2%" == "" GOTO JAVA_INSTALLED
:CHECK_JAVA_32
@ECHO Detecting if it is 32 bit machine
set KEY_NAME="HKEY_LOCAL_MACHINE\Software\JavaSoft\Java Runtime Environment"
set VALUE_NAME=CurrentVersion
FOR /F "usebackq skip=2 tokens=1-3" %%A IN (`REG QUERY %KEY_NAME% /v %VALUE_NAME% 2^>nul`) DO (
set ValueName=%%A
set ValueType=%%B
set ValueValue=%%C
)
@ECHO CurrentVersion %ValueValue%
SET KEY_NAME="%KEY_NAME:~1,-1%\%ValueValue%"
SET VALUE_NAME=JavaHome
if defined ValueName (
FOR /F "usebackq skip=2 tokens=1,2*" %%A IN (`REG QUERY %KEY_NAME% /v %VALUE_NAME% 2^>nul`) DO (
set ValueName2=%%A
set ValueType2=%%B
set JRE_PATH2=%%C
if defined ValueName2 (
set ValueName = %ValueName2%
set ValueType = %ValueType2%
set ValueValue = %JRE_PATH2%
)
)
)
IF "%JRE_PATH2%" == "" GOTO JAVA_NOT_INSTALLED
:JAVA_INSTALLED
@ECHO Java 1.8 found!
@ECHO Installing apq-pc-client ...
%~dp0apq-pc-client.exe install
@ECHO runing apq-pc-client ...
%~dp0apq-pc-client.exe start
@ECHO DONE.
GOTO END
:JAVA_NOT_INSTALLED
@ECHO Java 1.8 or above is not installed
@ECHO Please go to https://java.com/ and install Java. Then retry installation.
PAUSE
GOTO END
:END
@ECHO OFF
setlocal ENABLEEXTENSIONS
@ECHO Detecting Java version installed.
:CHECK_JAVA_64
@ECHO Detecting if it is 64 bit machine
set KEY_NAME="HKEY_LOCAL_MACHINE\Software\Wow6432Node\JavaSoft\Java Runtime Environment"
set VALUE_NAME=CurrentVersion
FOR /F "usebackq skip=2 tokens=1-3" %%A IN (`REG QUERY %KEY_NAME% /v %VALUE_NAME% 2^>nul`) DO (
set ValueName=%%A
set ValueType=%%B
set ValueValue=%%C
)
@ECHO CurrentVersion %ValueValue%
SET KEY_NAME="%KEY_NAME:~1,-1%\%ValueValue%"
SET VALUE_NAME=JavaHome
if defined ValueName (
FOR /F "usebackq skip=2 tokens=1,2*" %%A IN (`REG QUERY %KEY_NAME% /v %VALUE_NAME% 2^>nul`) DO (
set ValueName2=%%A
set ValueType2=%%B
set JRE_PATH2=%%C
if defined ValueName2 (
set ValueName = %ValueName2%
set ValueType = %ValueType2%
set ValueValue = %JRE_PATH2%
)
)
)
IF NOT "%JRE_PATH2%" == "" GOTO JAVA_INSTALLED
:CHECK_JAVA_32
@ECHO Detecting if it is 32 bit machine
set KEY_NAME="HKEY_LOCAL_MACHINE\Software\JavaSoft\Java Runtime Environment"
set VALUE_NAME=CurrentVersion
FOR /F "usebackq skip=2 tokens=1-3" %%A IN (`REG QUERY %KEY_NAME% /v %VALUE_NAME% 2^>nul`) DO (
set ValueName=%%A
set ValueType=%%B
set ValueValue=%%C
)
@ECHO CurrentVersion %ValueValue%
SET KEY_NAME="%KEY_NAME:~1,-1%\%ValueValue%"
SET VALUE_NAME=JavaHome
if defined ValueName (
FOR /F "usebackq skip=2 tokens=1,2*" %%A IN (`REG QUERY %KEY_NAME% /v %VALUE_NAME% 2^>nul`) DO (
set ValueName2=%%A
set ValueType2=%%B
set JRE_PATH2=%%C
if defined ValueName2 (
set ValueName = %ValueName2%
set ValueType = %ValueType2%
set ValueValue = %JRE_PATH2%
)
)
)
IF "%JRE_PATH2%" == "" GOTO JAVA_NOT_INSTALLED
:JAVA_INSTALLED
@ECHO Java 1.8 found!
@ECHO Installing apq-pc-client ...
%~dp0apq-pc-client.exe install
@ECHO running apq-pc-client ...
%~dp0apq-pc-client.exe start
@ECHO DONE.
GOTO END
:JAVA_NOT_INSTALLED
@ECHO Java 1.8 or above is not installed
@ECHO Please go to https://java.com/ and install Java. Then retry installation.
PAUSE
GOTO END
:END
package com.priusis;
import cn.hutool.core.collection.CollUtil;
import cn.hutool.core.util.StrUtil;
import cn.hutool.json.JSONUtil;
import com.priusis.dto.HwPortControllerDto;
import com.priusis.utils.IHwPortController;
import com.priusis.vo.MqttRpcDataMessage;
import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.beans.factory.annotation.Value;
import org.springframework.boot.SpringApplication;
import org.springframework.boot.autoconfigure.SpringBootApplication;
import org.springframework.boot.autoconfigure.jdbc.DataSourceAutoConfiguration;
import org.springframework.boot.autoconfigure.security.servlet.SecurityAutoConfiguration;
import org.springframework.http.ResponseEntity;
import org.springframework.scheduling.annotation.EnableScheduling;
import org.springframework.scheduling.annotation.Scheduled;
import org.springframework.web.client.RestClientException;
import org.springframework.web.client.RestTemplate;
import java.util.HashMap;
import java.util.List;
import java.util.Map;
import java.util.Objects;
@Slf4j
@EnableScheduling
@SpringBootApplication(exclude = {DataSourceAutoConfiguration.class, SecurityAutoConfiguration.class})
public class ApqControlApplication {
// 一分钟一次上报
private final Long FIXED_DELAY = 60000L;
@Autowired
private RestTemplate restTemplate;
public static void main(String[] args) {
SpringApplication.run(ApqControlApplication.class, args);
}
@Scheduled(fixedDelay = 60000L)
protected void controlProgramTask() {
log.info("硬件监控上报=================");
// 获取硬件监控配置 params == data
ResponseEntity<MqttRpcDataMessage> forEntity = null;
try {
forEntity = restTemplate.getForEntity("http://localhost:8765/rpc_cmd/controll", MqttRpcDataMessage.class);
} catch (Exception e) {
log.error("硬件监控上报异常", e.getMessage());
}
if (null != forEntity) {
MqttRpcDataMessage body = forEntity.getBody();
String params = body.getParams();
if (StrUtil.isNotBlank(params)) {
Long sendTime = body.getSendTime();
long current = System.currentTimeMillis();
List<HwPortControllerDto> hwPortControllerDtos = JSONUtil.toList(params, HwPortControllerDto.class);
// 初始化硬件接口管理模块
int result = IHwPortController.instanceDll.APQ_HWPORT_Initialize();
log.info("APQ_HWPORT_Initialize ret:{}", result);
if (current - sendTime <= FIXED_DELAY && CollUtil.isNotEmpty(hwPortControllerDtos)) {
// 收到硬件策略下发请求
log.info("收到硬件策略下发请求, sendTime:{}, params:{}", sendTime, params);
for (HwPortControllerDto hwPortControllerDto : hwPortControllerDtos) {
HwPortControllerDto.DeviceHardwareEnum deviceHardwareEnum = hwPortControllerDto.getKey();
int doType = hwPortControllerDto.getDoType();
int limitType = hwPortControllerDto.getLimitType();
int value = hwPortControllerDto.getValue();
List<Integer> hwDeviceIds = deviceHardwareEnum.getHwDeviceIds();
String hwDeviceName = deviceHardwareEnum.getName();
// 设置普通设备权限
if (Objects.equals(deviceHardwareEnum.getHwGroup(), "Normal")) {
// 1F/2T
for (Integer hwDeviceId : hwDeviceIds) {
int perm = (doType == 1 ? 2 : 1);
int result32 = IHwPortController.instanceDll.APQ_HWPORT_set_normal_device_permit(hwDeviceId, perm, null);
log.info("APQ_HWPORT_set_normal_device_permit doType:{}, limitType;{},value:{}, hwDeviceId:{}, name;{}, perm:{}, ret:{}",
doType, limitType, value, hwDeviceId, hwDeviceName, perm, result32);
}
} else if (Objects.equals(deviceHardwareEnum.getHwGroup(), "Storage")) { // 设置存储设备权限
// 1F/2T/3T-ALL/4T-R/5T-CI/6T-CO 拷出目前无用!! Storage移动硬盘,TYPEC 无效 !!
for (Integer hwDeviceId : hwDeviceIds) {
int perm = (doType == 1 ? 2 : 1);
if (perm == 2) {
// limitType 1读写 2只读 3拷入 4拷出 5不限速 6限速
perm = (limitType == 1 ? 3 : limitType == 2 ? 4 : limitType == 3 ? 5 : limitType == 4 ? 6 : 3);
}
int result32 = IHwPortController.instanceDll.APQ_HWPORT_set_storage_device_permit(hwDeviceId, perm, null);
log.info("APQ_HWPORT_set_storage_device_permit doType:{}, limitType;{},value:{}, hwDeviceId:{}, name;{}, perm:{}, ret:{}",
doType, limitType, value, hwDeviceId, hwDeviceName, perm, result32);
}
} else if (Objects.equals(deviceHardwareEnum.getHwGroup(), "NET")) { // 设置网络设备权限
// 1F/2T/3T-NS/4T-S-200 网口,4G/5G模块,无线WIFI区分不了 !!
for (Integer hwDeviceId : hwDeviceIds) {
int perm = (doType == 1 ? 2 : 1);
if (perm == 2) {
// limitType 1读写 2只读 3拷入 4拷出 5不限速 6限速
perm = (limitType == 5 ? 3 : limitType == 6 ? 4 : 2);
}
int result32 = IHwPortController.instanceDll.APQ_HWPORT_set_net_device_permit(hwDeviceId, perm, value, null);
log.info("APQ_HWPORT_set_net_device_permit doType:{}, limitType;{},value:{}, hwDeviceId:{}, name;{}, perm:{}, ret:{}",
doType, limitType, value, hwDeviceId, hwDeviceName, perm, result32);
}
}
// 应用硬件接口管理模块的配置内容
int result5 = IHwPortController.instanceDll.APQ_HWPORT_Apply();
log.info("APQ_HWPORT_Apply ret:{}", result5);
}
} else {
log.info("执行硬件监控, sendTime:{}, params:{}", sendTime, params);
// 上报硬件监控数据
Map mapRequest = new HashMap();
for (HwPortControllerDto hwPortControllerDto : hwPortControllerDtos) {
HwPortControllerDto.DeviceHardwareEnum deviceHardwareEnum = hwPortControllerDto.getKey();
int doType = hwPortControllerDto.getDoType();
int limitType = hwPortControllerDto.getLimitType();
int value = hwPortControllerDto.getValue();
List<Integer> hwDeviceIds = deviceHardwareEnum.getHwDeviceIds();
String hwDeviceName = deviceHardwareEnum.getName();
// 设置普通设备权限
if (Objects.equals(deviceHardwareEnum.getHwGroup(), "Normal")) {
// 1F/2T
for (Integer hwDeviceId : hwDeviceIds) {
int perm = (doType == 1 ? 2 : 1);
if (perm == 1) {
// 获取普通设备权限
int result31 = IHwPortController.instanceDll.APQ_HWPORT_get_normal_device_permit(hwDeviceId);
log.debug("APQ_HWPORT_get_normal_device_permit doType:{}, limitType;{},value:{}, hwDeviceId:{}, name;{}, perm:{}, ret:{}",
doType, limitType, value, hwDeviceId, hwDeviceName, perm, result31);
if (result31 == 2) {
mapRequest.put(deviceHardwareEnum.name(), perm);
}
}
}
} else if (Objects.equals(deviceHardwareEnum.getHwGroup(), "Storage")) { // 设置存储设备权限
// 1F/2T/3T-ALL/4T-R/5T-CI/6T-CO 拷出目前无用!! Storage移动硬盘,TYPEC 无效 !!
for (Integer hwDeviceId : hwDeviceIds) {
int perm = (doType == 1 ? 2 : 1);
if (perm == 2) {
// limitType 1读写 2只读 3拷入 4拷出 5不限速 6限速
perm = (limitType == 1 ? 3 : limitType == 2 ? 4 : limitType == 3 ? 5 : limitType == 4 ? 6 : 3);
}
int result32 = IHwPortController.instanceDll.APQ_HWPORT_get_storage_device_permit(hwDeviceId);
log.info("APQ_HWPORT_get_storage_device_permit doType:{}, limitType;{},value:{}, hwDeviceId:{}, name;{}, perm:{}, ret:{}",
doType, limitType, value, hwDeviceId, hwDeviceName, perm, result32);
if (perm != result32) {
mapRequest.put(deviceHardwareEnum.name(), perm);
}
}
} else if (Objects.equals(deviceHardwareEnum.getHwGroup(), "NET")) { // 设置网络设备权限
// 1F/2T/3T-NS/4T-S-200 网口,4G/5G模块,无线WIFI区分不了 !!
for (Integer hwDeviceId : hwDeviceIds) {
int perm = (doType == 1 ? 2 : 1);
if (perm == 2) {
// limitType 1读写 2只读 3拷入 4拷出 5不限速 6限速
perm = (limitType == 5 ? 3 : limitType == 6 ? 4 : 2);
}
int result32 = IHwPortController.instanceDll.APQ_HWPORT_get_net_device_permit(hwDeviceId, 0);
log.info("APQ_HWPORT_get_net_device_permit doType:{}, limitType;{},value:{}, hwDeviceId:{}, name;{}, perm:{}, ret:{}",
doType, limitType, value, hwDeviceId, hwDeviceName, perm, result32);
if (perm != result32) {
mapRequest.put(deviceHardwareEnum.name(), perm);
}
}
}
}
if (mapRequest.size() > 0) {
Map eventMapRequest = new HashMap();
eventMapRequest.put("methodName", "control_warning");
eventMapRequest.put("params", mapRequest);
Map map = restTemplate.postForObject("http://localhost:8765/uplink_event/oc-client", eventMapRequest, Map.class);
log.info("存在硬件接口扫码告警,上报告警事件: mapData:{}, ret:{}", mapRequest, map);
}
}
// 清理硬件接口管理模块
int result2 = IHwPortController.instanceDll.APQ_HWPORT_Uninitialize();
log.info("APQ_HWPORT_Uninitialize ret:{}", result2);
} else {
log.info("未获取到获取硬件监控配置");
}
} else {
log.info("未获取到获取硬件监控配置");
//int result = IHwPortController.instanceDll.APQ_HWPORT_Initialize();
//log.info("APQ_HWPORT_Initialize ret:{}", result);
//int result2 = IHwPortController.instanceDll.APQ_HWPORT_Uninitialize();
//log.info("APQ_HWPORT_Uninitialize ret:{}", result2);
}
}
}
package com.priusis;
import cn.hutool.core.collection.CollUtil;
import cn.hutool.core.util.StrUtil;
import cn.hutool.json.JSONUtil;
import com.priusis.dto.HwPortControllerDto;
import com.priusis.utils.IHwPortController;
import com.priusis.vo.MqttRpcDataMessage;
import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.boot.SpringApplication;
import org.springframework.boot.autoconfigure.SpringBootApplication;
import org.springframework.boot.autoconfigure.jdbc.DataSourceAutoConfiguration;
import org.springframework.boot.autoconfigure.security.servlet.SecurityAutoConfiguration;
import org.springframework.http.ResponseEntity;
import org.springframework.scheduling.annotation.EnableScheduling;
import org.springframework.scheduling.annotation.Scheduled;
import org.springframework.web.client.RestTemplate;
import java.util.HashMap;
import java.util.List;
import java.util.Map;
import java.util.Objects;
@Slf4j
@EnableScheduling
@SpringBootApplication(exclude = {DataSourceAutoConfiguration.class, SecurityAutoConfiguration.class})
public class ApqControlApplication {
// 一分钟一次上报
private final Long FIXED_DELAY = 60000L;
@Autowired
private RestTemplate restTemplate;
public static void main(String[] args) {
SpringApplication.run(ApqControlApplication.class, args);
}
@Scheduled(fixedDelay = 60000L)
protected void controlProgramTask() {
log.info("硬件监控上报=================");
// todo
//testUsb();
// 获取硬件监控配置 params == data
ResponseEntity<MqttRpcDataMessage> forEntity = null;
try {
forEntity = restTemplate.getForEntity("http://localhost:8765/rpc_cmd/controll", MqttRpcDataMessage.class);
} catch (Exception e) {
log.error("硬件监控上报异常", e.getMessage());
}
if (null != forEntity) {
MqttRpcDataMessage body = forEntity.getBody();
String params = body.getParams();
if (StrUtil.isNotBlank(params)) {
Long sendTime = body.getSendTime();
long current = System.currentTimeMillis();
List<HwPortControllerDto> hwPortControllerDtos = JSONUtil.toList(params, HwPortControllerDto.class);
// 初始化硬件接口管理模块
int result = IHwPortController.instanceDll.APQ_HWPORT_Initialize();
log.info("APQ_HWPORT_Initialize ret:{}", result);
if (current - sendTime <= FIXED_DELAY && CollUtil.isNotEmpty(hwPortControllerDtos)) {
// 收到硬件策略下发请求
log.info("收到硬件策略下发请求, sendTime:{}, params:{}", sendTime, params);
for (HwPortControllerDto hwPortControllerDto : hwPortControllerDtos) {
HwPortControllerDto.DeviceHardwareEnum deviceHardwareEnum = hwPortControllerDto.getKey();
int doType = hwPortControllerDto.getDoType();
int limitType = hwPortControllerDto.getLimitType();
int value = hwPortControllerDto.getValue();
List<Integer> hwDeviceIds = deviceHardwareEnum.getHwDeviceIds();
String hwDeviceName = deviceHardwareEnum.getName();
// 设置普通设备权限
if (Objects.equals(deviceHardwareEnum.getHwGroup(), "Normal")) {
// 1F/2T
for (Integer hwDeviceId : hwDeviceIds) {
int perm = (doType == 1 ? 2 : 1);
int result32 = IHwPortController.instanceDll.APQ_HWPORT_set_normal_device_permit(hwDeviceId, perm, null);
log.info("APQ_HWPORT_set_normal_device_permit doType:{}, limitType;{},value:{}, hwDeviceId:{}, name;{}, perm:{}, ret:{}",
doType, limitType, value, hwDeviceId, hwDeviceName, perm, result32);
}
} else if (Objects.equals(deviceHardwareEnum.getHwGroup(), "Storage")) { // 设置存储设备权限
// 1F/2T/3T-ALL/4T-R/5T-CI/6T-CO 拷出目前无用!! Storage移动硬盘,TYPEC 无效 !!
for (Integer hwDeviceId : hwDeviceIds) {
int perm = (doType == 1 ? 2 : 1);
if (perm == 2) {
// limitType 1读写 2只读 3拷入 4拷出 5不限速 6限速
perm = (limitType == 1 ? 3 : limitType == 2 ? 4 : limitType == 3 ? 5 : limitType == 4 ? 6 : 3);
}
int result32 = IHwPortController.instanceDll.APQ_HWPORT_set_storage_device_permit(hwDeviceId, perm, null);
log.info("APQ_HWPORT_set_storage_device_permit doType:{}, limitType;{},value:{}, hwDeviceId:{}, name;{}, perm:{}, ret:{}",
doType, limitType, value, hwDeviceId, hwDeviceName, perm, result32);
}
} else if (Objects.equals(deviceHardwareEnum.getHwGroup(), "NET")) { // 设置网络设备权限
// 1F/2T/3T-NS/4T-S-200 网口,4G/5G模块,无线WIFI区分不了 !!
for (Integer hwDeviceId : hwDeviceIds) {
int perm = (doType == 1 ? 2 : 1);
if (perm == 2) {
// limitType 1读写 2只读 3拷入 4拷出 5不限速 6限速
perm = (limitType == 5 ? 3 : limitType == 6 ? 4 : 2);
}
int result32 = IHwPortController.instanceDll.APQ_HWPORT_set_net_device_permit(hwDeviceId, perm, value, null);
log.info("APQ_HWPORT_set_net_device_permit doType:{}, limitType;{},value:{}, hwDeviceId:{}, name;{}, perm:{}, ret:{}",
doType, limitType, value, hwDeviceId, hwDeviceName, perm, result32);
}
}
// 应用硬件接口管理模块的配置内容
int result5 = IHwPortController.instanceDll.APQ_HWPORT_Apply();
log.info("APQ_HWPORT_Apply ret:{}", result5);
}
} else {
log.info("执行硬件监控, sendTime:{}, params:{}", sendTime, params);
// 上报硬件监控数据
Map mapRequest = new HashMap();
for (HwPortControllerDto hwPortControllerDto : hwPortControllerDtos) {
HwPortControllerDto.DeviceHardwareEnum deviceHardwareEnum = hwPortControllerDto.getKey();
int doType = hwPortControllerDto.getDoType();
int limitType = hwPortControllerDto.getLimitType();
int value = hwPortControllerDto.getValue();
List<Integer> hwDeviceIds = deviceHardwareEnum.getHwDeviceIds();
String hwDeviceName = deviceHardwareEnum.getName();
// 设置普通设备权限
if (Objects.equals(deviceHardwareEnum.getHwGroup(), "Normal")) {
// 1F/2T
for (Integer hwDeviceId : hwDeviceIds) {
int perm = (doType == 1 ? 2 : 1);
if (perm == 1) {
// 获取普通设备权限
int result31 = IHwPortController.instanceDll.APQ_HWPORT_get_normal_device_permit(hwDeviceId);
log.debug("APQ_HWPORT_get_normal_device_permit doType:{}, limitType;{},value:{}, hwDeviceId:{}, name;{}, perm:{}, ret:{}",
doType, limitType, value, hwDeviceId, hwDeviceName, perm, result31);
if (result31 == 2) {
mapRequest.put(deviceHardwareEnum.name(), perm);
}
}
}
} else if (Objects.equals(deviceHardwareEnum.getHwGroup(), "Storage")) { // 设置存储设备权限
// 1F/2T/3T-ALL/4T-R/5T-CI/6T-CO 拷出目前无用!! Storage移动硬盘,TYPEC 无效 !!
for (Integer hwDeviceId : hwDeviceIds) {
int perm = (doType == 1 ? 2 : 1);
if (perm == 2) {
// limitType 1读写 2只读 3拷入 4拷出 5不限速 6限速
perm = (limitType == 1 ? 3 : limitType == 2 ? 4 : limitType == 3 ? 5 : limitType == 4 ? 6 : 3);
}
int result32 = IHwPortController.instanceDll.APQ_HWPORT_get_storage_device_permit(hwDeviceId);
log.info("APQ_HWPORT_get_storage_device_permit doType:{}, limitType;{},value:{}, hwDeviceId:{}, name;{}, perm:{}, ret:{}",
doType, limitType, value, hwDeviceId, hwDeviceName, perm, result32);
if (perm != result32) {
mapRequest.put(deviceHardwareEnum.name(), perm);
}
}
} else if (Objects.equals(deviceHardwareEnum.getHwGroup(), "NET")) { // 设置网络设备权限
// 1F/2T/3T-NS/4T-S-200 网口,4G/5G模块,无线WIFI区分不了 !!
for (Integer hwDeviceId : hwDeviceIds) {
int perm = (doType == 1 ? 2 : 1);
if (perm == 2) {
// limitType 1读写 2只读 3拷入 4拷出 5不限速 6限速
perm = (limitType == 5 ? 3 : limitType == 6 ? 4 : 2);
}
int result32 = IHwPortController.instanceDll.APQ_HWPORT_get_net_device_permit(hwDeviceId, 0);
log.info("APQ_HWPORT_get_net_device_permit doType:{}, limitType;{},value:{}, hwDeviceId:{}, name;{}, perm:{}, ret:{}",
doType, limitType, value, hwDeviceId, hwDeviceName, perm, result32);
if (perm != result32) {
mapRequest.put(deviceHardwareEnum.name(), perm);
}
}
}
}
if (mapRequest.size() > 0) {
Map eventMapRequest = new HashMap();
eventMapRequest.put("methodName", "control_warning");
eventMapRequest.put("params", mapRequest);
Map map = restTemplate.postForObject("http://localhost:8765/uplink_event/oc-client", eventMapRequest, Map.class);
log.info("存在硬件接口扫码告警,上报告警事件: mapData:{}, ret:{}", mapRequest, map);
}
}
// 清理硬件接口管理模块
int result2 = IHwPortController.instanceDll.APQ_HWPORT_Uninitialize();
log.info("APQ_HWPORT_Uninitialize ret:{}", result2);
} else {
log.info("未获取到获取硬件监控配置");
}
} else {
log.info("未获取到获取硬件监控配置");
//int result = IHwPortController.instanceDll.APQ_HWPORT_Initialize();
//log.info("APQ_HWPORT_Initialize ret:{}", result);
//int result2 = IHwPortController.instanceDll.APQ_HWPORT_Uninitialize();
//log.info("APQ_HWPORT_Uninitialize ret:{}", result2);
}
}
public void testUsb() {
// 初始化硬件接口管理模块
int result = IHwPortController.instanceDll.APQ_HWPORT_Initialize();
log.info("APQ_HWPORT_Initialize ret:{}", result);
// APQ_HWPORT_STORAGE_PERM_ALLOW APQ_HWPORT_STORAGE_PERM_DENY
int result32 = IHwPortController.instanceDll.APQ_HWPORT_set_storage_device_permit(IHwPortController.HwportStorageDevidEnum.APQ_HWPORT_STORAGE_DEVID_UDISK.getCode(), IHwPortController.HwportStoragePermEnum.APQ_HWPORT_STORAGE_PERM_ALLOW.getCode(), null);
log.info("APQ_HWPORT_set_storage_device_permit ret:{}", result32);
//应用硬件接口管理模块的配置内容
int result5 = IHwPortController.instanceDll.APQ_HWPORT_Apply();
log.info("APQ_HWPORT_Apply ret:{}", result5);
int result2 = IHwPortController.instanceDll.APQ_HWPORT_Uninitialize();
log.info("APQ_HWPORT_Uninitialize ret:{}", result2);
}
}
spring:
application:
name: apq-pc-control
server:
# Server bind address
address: "0.0.0.0"
port: ${random.int[10000,19999]}
spring:
application:
name: apq-pc-control
server:
# Server bind address
address: "0.0.0.0"
# port: ${random.int[10000,19999]}
port: 8762
\ No newline at end of file
package com.priusis.controller;
import cn.hutool.core.io.unit.DataSizeUtil;
import cn.hutool.core.map.MapUtil;
import cn.hutool.core.util.StrUtil;
import cn.hutool.json.JSONUtil;
import cn.hutool.system.oshi.CpuInfo;
import cn.hutool.system.oshi.OshiUtil;
import com.priusis.lib.R;
import com.priusis.util.MacAddrUtil;
import com.priusis.vo.ApqInfoDataVo;
import com.priusis.vo.MqttRpcDataMessage;
import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.http.ResponseEntity;
import org.springframework.validation.annotation.Validated;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;
import org.springframework.web.client.RestTemplate;
import oshi.hardware.HWDiskStore;
import oshi.hardware.HWPartition;
import java.io.File;
import java.io.IOException;
import java.net.InetAddress;
import java.text.DecimalFormat;
import java.util.Arrays;
import java.util.HashMap;
import java.util.List;
import java.util.Map;
import java.util.stream.Collectors;
/**
* @author yangli
* @since 2021/09/10
*/
@Slf4j
@Validated
@RestController
@RequestMapping(value = "info")
public class InfoController {
@Autowired
private RestTemplate restTemplate;
@GetMapping(value = "read_post")
public R<Map<String, Object>> getDownloadPath() throws IOException {
boolean isNoneEven = false;
// 获取采集配置,数据上报频率 params == data
ResponseEntity<MqttRpcDataMessage> forEntity = null;
Map<String, Integer> mapParams = null;
try {
forEntity = restTemplate.getForEntity("http://localhost:8765/rpc_cmd/info", MqttRpcDataMessage.class);
if (null != forEntity) {
MqttRpcDataMessage body = forEntity.getBody();
String params = body.getParams();
if (StrUtil.isNotBlank(params)) {
List<ApqInfoDataVo> apqInfoDataVos = JSONUtil.toList(params, ApqInfoDataVo.class);
mapParams = new HashMap<>();
for (ApqInfoDataVo apqInfoDataVo : apqInfoDataVos) {
mapParams.put(apqInfoDataVo.getCode(), apqInfoDataVo.getFrequency());
}
}
}
} catch (Exception e) {
log.error("采集数据异常", e);
}
String operatingSystem = "operatingSystem";
String mac = "mac";
String baseboard = "baseboard";
String ip = "ip";
String cpuModel = "cpuModel";
String cpuLoad = "cpuLoad";
String cpuTemp = "cpuTemp";
String memoryCap = "memoryCap";
String memoryAvailable = "memoryAvailable";
String diskModel = "diskModel";
String diskCap = "diskCap";
String diskFree = "diskFree";
Map<String, Object> data = null;
try {
// 上报PC实时信息
String collect = null;
String collect1 = null;
String collect2 = null;
try {
collect = Arrays.stream(OshiUtil.getHardware().getDiskStores())
.map(HWDiskStore::getPartitions)
.flatMap(Arrays::stream)
.filter(partition -> StrUtil.isNotBlank(partition.getMountPoint()))
.map(partition -> "\"" + StrUtil.removeSuffix(partition.getMountPoint(), ":\\") + "盘\":\"" +
DataSizeUtil.format(partition.getSize()) + "\"")
.collect(Collectors.joining(",", "{", "}"));
collect1 = Arrays.stream(OshiUtil.getHardware().getDiskStores())
.map(store -> Arrays.stream(store.getPartitions())
.map(HWPartition::getMountPoint)
.filter(StrUtil::isNotBlank)
.map(s -> "\"" + StrUtil.removeSuffix(s, ":\\") + "盘\":\"" +
StrUtil.removeSuffix(store.getModel(), " (标准磁盘驱动器)") + "\"")
.collect(Collectors.joining(",")))
.filter(StrUtil::isNotBlank)
.collect(Collectors.joining(",", "{", "}"));
collect2 = Arrays.stream(OshiUtil.getHardware().getDiskStores())
.map(HWDiskStore::getPartitions)
.flatMap(Arrays::stream)
.filter(partition -> StrUtil.isNotBlank(partition.getMountPoint()))
.map(partition -> "\"" + StrUtil.removeSuffix(partition.getMountPoint(), ":\\") + "盘\":\"" +
new DecimalFormat("#.00").format(100d * new File(partition.getMountPoint()).getFreeSpace() / partition.getSize()) + "%\"")
.collect(Collectors.joining(",", "{", "}"));
} catch (Exception e) {
log.error("硬盘数据获取失败", e);
}
data = MapUtil.<String, Object>builder()
.put(isNeedCollection(isNoneEven, operatingSystem, mapParams), operatingSystem, OshiUtil.getOs().toString())
.put(isNeedCollection(isNoneEven, mac, mapParams), mac, MacAddrUtil.get())
.put(isNeedCollection(isNoneEven, baseboard, mapParams), baseboard, OshiUtil.getSystem().getBaseboard().getManufacturer() + " " + OshiUtil.getSystem().getBaseboard().getVersion())
.put(isNeedCollection(isNoneEven, ip, mapParams), ip, InetAddress.getLocalHost().getHostAddress())
.put(isNeedCollection(isNoneEven, cpuModel, mapParams), cpuModel, OshiUtil.getCpuInfo(0).getCpuModel())
.put(isNeedCollection(isNoneEven, cpuTemp, mapParams), cpuTemp, Double.parseDouble(new DecimalFormat("#.00").format(OshiUtil.getSensors().getCpuTemperature())))
.put(isNeedCollection(isNoneEven, cpuLoad, mapParams), cpuLoad, getCpuUsed())
.put(isNeedCollection(isNoneEven, memoryCap, mapParams), memoryCap, DataSizeUtil.format(OshiUtil.getMemory().getTotal()))
.put(isNeedCollection(isNoneEven, memoryAvailable, mapParams), memoryAvailable, DataSizeUtil.format(OshiUtil.getMemory().getAvailable()))
.put(isNeedCollection(isNoneEven, diskModel, mapParams), diskModel, collect1)
.put(isNeedCollection(isNoneEven, diskCap, mapParams), diskCap, collect)
.put(isNeedCollection(isNoneEven, diskFree, mapParams), diskFree, collect2)
.build();
log.info("采集数据,上报属性: mapData:{}", data);
Map mapR = restTemplate.postForObject("http://localhost:8765/uplink/oc-client", data, Map.class);
log.info("采集数据,上报属性: ret:{}", mapR);
} catch (Exception e) {
log.error("采集数据异常", e);
data = MapUtil.<String, Object>builder().put("ERROR", e.getMessage()).build();
}
return R.success(data);
}
private boolean isNeedCollection(boolean isNoneEven, String key, Map<String, Integer> mapParams) {
if (null != mapParams && mapParams.containsKey(key)) {
return (!isNoneEven || mapParams.get(key) != 30);
} else {
return isNoneEven;
}
}
public static double getCpuUsed() {
CpuInfo cpuInfo = OshiUtil.getCpuInfo(100);
double used = Double.parseDouble(new DecimalFormat("#.00").format(100 - cpuInfo.getFree()));
return Math.min(Math.max(used, 0), 100);
}
}
package com.priusis.lib;
import lombok.Getter;
@Getter
public class R<T> {
private final int code;
private final String msg;
private final T data;
private R(int code, String msg, T data) {
this.code = code;
this.msg = msg;
this.data = data;
}
public static <T> R<T> success(T data) {
return new R<>(0, "SUCCESS", data);
}
public static <T> R<T> success() {
return success(null);
}
public static <T> R<T> error(int code, String msg, T data) {
return new R<>(code, msg, data);
}
public static <T> R<T> error(int code, String msg) {
return error(code, msg, null);
}
public static <T> R<T> error(String msg) {
return error(500, msg);
}
public static <T> R<T> error() {
return error("系统异常");
}
}
spring:
application:
name: apq-pc-info
server:
# Server bind address
address: "0.0.0.0"
port: ${random.int[10000,19999]}
spring:
application:
name: apq-pc-info
server:
# Server bind address
address: "0.0.0.0"
# port: ${random.int[10000,19999]}
port: 8764
package com.priusis;
import cn.hutool.core.util.StrUtil;
import cn.hutool.json.JSONUtil;
import com.priusis.dto.RegisterParamDto;
import com.priusis.util.WinExecuteUtils;
import com.priusis.vo.MqttRpcDataMessage;
import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.boot.SpringApplication;
import org.springframework.boot.autoconfigure.SpringBootApplication;
import org.springframework.boot.autoconfigure.jdbc.DataSourceAutoConfiguration;
import org.springframework.boot.autoconfigure.security.servlet.SecurityAutoConfiguration;
import org.springframework.http.ResponseEntity;
import org.springframework.scheduling.annotation.EnableScheduling;
import org.springframework.scheduling.annotation.Scheduled;
import org.springframework.web.client.RestClientException;
import org.springframework.web.client.RestTemplate;
import java.util.HashMap;
import java.util.List;
import java.util.Map;
@Slf4j
@EnableScheduling
@SpringBootApplication(exclude = {DataSourceAutoConfiguration.class, SecurityAutoConfiguration.class})
public class ApqRegisterApplication {
public static void main(String[] args) {
SpringApplication.run(ApqRegisterApplication.class, args);
}
// "params":
// {
// "type":1
// "programs": [
// {
// "name":"qq"
// }
// ]
// }
@Autowired
private RestTemplate restTemplate;
@Scheduled(fixedDelay = 30000L)
protected void registerProgramTask() {
log.info("软件检测上报=================");
/*
log.info("===================");
try {
WinExecuteUtils.killProc("Postman.exe");
} catch (Exception e) {
log.error("杀进程异常", e);
}*/
// 获取软件检测监控配置 params == data
ResponseEntity<MqttRpcDataMessage> forEntity = null;
try {
forEntity = restTemplate.getForEntity("http://localhost:8765/rpc_cmd/register", MqttRpcDataMessage.class);
} catch (RestClientException e) {
log.error("软件检测上报异常", e.getMessage());
}
if (null != forEntity) {
MqttRpcDataMessage body = forEntity.getBody();
String params = body.getParams();
if (StrUtil.isNotBlank(params)) {
Long sendTime = body.getSendTime();
//long current = System.currentTimeMillis();
RegisterParamDto registerParamDto = JSONUtil.toBean(params, RegisterParamDto.class);
// 收到软件检测下发请求
log.info("收到软件检测下发请求, sendTime:{}, params:{}", sendTime, params);
int type = registerParamDto.getType();
if (type == 1) {
List<RegisterParamDto.RegisterDetailParamDto> programs = registerParamDto.getPrograms();
// 上报软件检测监控数据
Map mapRequest = new HashMap();
for (RegisterParamDto.RegisterDetailParamDto program : programs) {
String name = program.getName().trim();
log.info("软件检测软件: {}", name);
boolean isE = WinExecuteUtils.findProcess(name);
if (isE) {
// 杀进程
log.info("存在黑名单软件, 进行进程查杀: {}", name);
try {
WinExecuteUtils.killProc(name);
} catch (Exception e) {
log.error("杀进程异常", e);
}
// 上报黑名单异常
mapRequest.put(name, "1");
}
}
// 上报黑名单异常
if (mapRequest.size() > 0) {
Map eventMapRequest = new HashMap();
eventMapRequest.put("requestId", 1);
eventMapRequest.put("methodName", "BlackList");
eventMapRequest.put("params", mapRequest);
Map map = restTemplate.postForObject("http://localhost:8765/uplink_event/oc-client", eventMapRequest, Map.class);
log.info("存在软件检测接口扫码告警,上报告警事件: mapData:{}, ret:{}", mapRequest, map);
}
// 上报黑名单属性 todo
}
} else {
log.info("未获取到获取软件检测监控配置");
}
} else {
log.info("未获取到获取软件检测监控配置");
}
}
}
package com.priusis;
import cn.hutool.core.util.StrUtil;
import cn.hutool.json.JSONUtil;
import com.priusis.dto.RegisterParamDto;
import com.priusis.util.WinExecuteUtils;
import com.priusis.vo.MqttRpcDataMessage;
import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.boot.SpringApplication;
import org.springframework.boot.autoconfigure.SpringBootApplication;
import org.springframework.boot.autoconfigure.jdbc.DataSourceAutoConfiguration;
import org.springframework.boot.autoconfigure.security.servlet.SecurityAutoConfiguration;
import org.springframework.http.ResponseEntity;
import org.springframework.scheduling.annotation.EnableScheduling;
import org.springframework.scheduling.annotation.Scheduled;
import org.springframework.web.client.RestClientException;
import org.springframework.web.client.RestTemplate;
import java.util.HashMap;
import java.util.List;
import java.util.Map;
@Slf4j
@EnableScheduling
@SpringBootApplication(exclude = {DataSourceAutoConfiguration.class, SecurityAutoConfiguration.class})
public class ApqRegisterApplication {
public static void main(String[] args) {
SpringApplication.run(ApqRegisterApplication.class, args);
}
// "params":
// {
// "type":1
// "programs": [
// {
// "name":"qq"
// }
// ]
// }
@Autowired
private RestTemplate restTemplate;
@Scheduled(fixedDelay = 30000L)
protected void registerProgramTask() {
log.info("软件检测上报=================");
/* try {
WinExecuteUtils.killProc("TIM.exe");
} catch (IOException e) {
log.error("杀进程异常", e);
}*/
// 获取软件检测监控配置 params == data
ResponseEntity<MqttRpcDataMessage> forEntity = null;
try {
forEntity = restTemplate.getForEntity("http://localhost:8765/rpc_cmd/register", MqttRpcDataMessage.class);
} catch (RestClientException e) {
log.error("软件检测上报异常", e.getMessage());
}
if (null != forEntity) {
MqttRpcDataMessage body = forEntity.getBody();
String params = body.getParams();
if (StrUtil.isNotBlank(params)) {
Long sendTime = body.getSendTime();
//long current = System.currentTimeMillis();
RegisterParamDto registerParamDto = JSONUtil.toBean(params, RegisterParamDto.class);
// 收到软件检测下发请求
log.info("收到软件检测下发请求, sendTime:{}, params:{}", sendTime, params);
int type = registerParamDto.getType();
if (type == 1) {
List<RegisterParamDto.RegisterDetailParamDto> programs = registerParamDto.getPrograms();
// 上报软件检测监控数据
Map mapRequest = new HashMap();
for (RegisterParamDto.RegisterDetailParamDto program : programs) {
String name = program.getName().trim();
log.info("软件检测软件: {}", name);
boolean isE = WinExecuteUtils.findProcess(name);
if (isE) {
// 杀进程
log.info("存在黑名单软件, 进行进程查杀: {}", name);
try {
WinExecuteUtils.killProc(name);
} catch (Exception e) {
log.error("杀进程异常", e);
}
// 上报黑名单异常
mapRequest.put(name, "1");
}
}
// 上报黑名单异常
if (mapRequest.size() > 0) {
Map eventMapRequest = new HashMap();
eventMapRequest.put("requestId", 1);
eventMapRequest.put("methodName", "BlackList");
eventMapRequest.put("params", mapRequest);
Map map = restTemplate.postForObject("http://localhost:8765/uplink_event/oc-client", eventMapRequest, Map.class);
log.info("存在软件检测接口扫码告警,上报告警事件: mapData:{}, ret:{}", mapRequest, map);
}
// 上报黑名单属性 todo
}
} else {
log.info("未获取到获取软件检测监控配置");
}
} else {
log.info("未获取到获取软件检测监控配置");
}
}
}
spring:
application:
name: apq-pc-register
server:
# Server bind address
address: "0.0.0.0"
port: ${random.int[30000,39999]}
spring:
application:
name: apq-pc-register
server:
# Server bind address
address: "0.0.0.0"
# port: ${random.int[30000,39999]}
port: 8763
\ No newline at end of file
; Script generated by the Inno Setup Script Wizard.
; SEE THE DOCUMENTATION FOR DETAILS ON CREATING INNO SETUP SCRIPT FILES!
#define MyAppName "阿普奇检测客户端"
#define MyAppVersion "V1.0"
#define MyAppPublisher "阿普奇"
#define MyAppURL "https://www.apq.com/"
#define MyAppDirName "apq-client"
#define MyAppEnName "apq-client"
#define MyAppExeName "apq-client.exe"
#define MyAppReBootName "service\启动服务R.bat"
[Setup]
; 注: AppId的值为单独标识该应用程序。
; 不要为其他安装程序使用相同的AppId值。
; (生成新的GUID,点击 工具|在IDE中生成GUID。)
; Tell Windows Explorer to reload the environment
ChangesEnvironment=yes
DisableDirPage=no
AlwaysRestart=yes
AppId={{1394783A-5D3C-48CD-0000-E2DFBB844E42}
AppName={#MyAppName}
AppVersion={#MyAppVersion}
AppVerName={#MyAppName}
AppPublisher={#MyAppPublisher}
AppPublisherURL={#MyAppURL}
AppSupportURL={#MyAppURL}
AppUpdatesURL={#MyAppURL}
DefaultDirName={pf}\{#MyAppDirName}
DefaultGroupName={#MyAppName}
SetupIconFile=logo.ico
;安装包文件输出目录
OutputDir=..\dist\
;安装包文件名
OutputBaseFilename={#MyAppName}
;压缩文件
Compression=lzma
SolidCompression=yes
;以管理员权限运行
PrivilegesRequired=admin
UninstallDisplayIcon={app}/{#MyAppExeName}
//CreateUninstallRegKey=no
//UpdateUninstallLogAppName=no
VersionInfoVersion=1.0.0.1
[Languages]
Name: "chinese"; MessagesFile: "compiler:Languages/Chinese.isl"
[Files]
Source: "../apq-client/*"; DestDir: "{app}"; Flags: ignoreversion recursesubdirs createallsubdirs;
Source: "../../java/jre/jre/*"; DestDir: "{app}/jre"; Flags: ignoreversion recursesubdirs createallsubdirs;
Source: "../../client/*"; DestDir: "{app}"; Flags: ignoreversion recursesubdirs createallsubdirs;
; NOTE: Don't use "Flags: ignoreversion" on any shared system files
[Icons]
Name: "{group}\{cm:UninstallProgram,{#MyAppName}}"; Filename: "{uninstallexe}"
Name: "{commondesktop}\{#MyAppName}"; Filename: "{app}\client-soft\apq.exe";
[Run]
Filename: "{app}\Set_Env.bat"; Flags: runhidden;
Filename: "{app}\service\启动服务.bat"; Flags: runhidden runascurrentuser waituntilterminated;
;卸载后执行的操作(停止、删除各种服务)
[UninstallRun]
Filename: "{app}\service\删除服务.bat"; Flags: runhidden;
;卸载后删除目录所有文件,删除空目录
[UninstallDelete]
Type: filesandordirs; Name: "{app}\*"
Type: dirifempty; Name: "{app}"
;操作注册表
[Registry]
Root: HKLM; Subkey: "Software\{#MyAppEnName}"; Flags: uninsdeletekey;
Root: HKCU; Subkey: "SOFTWARE\Microsoft\Windows\CurrentVersion\Run"; ValueType: string; ValueName: "{#MyAppEnName}"; ValueData: "{app}\{#MyAppReBootName}"; Flags: uninsdeletevalue;
; set JAVA_HOME
Root: HKLM; Subkey: "SYSTEM\CurrentControlSet\Control\Session Manager\Environment"; ValueType:string; ValueName:"JAVA_HOME"; ValueData:"{app}\jre"; Flags: preservestringtype
; set PATH
Root: HKLM; Subkey: "SYSTEM\CurrentControlSet\Control\Session Manager\Environment"; ValueType:string; ValueName:"PATH"; ValueData:"{olddata};{app}\jre\bin"; Flags: preservestringtype
[Code]
function CheckProcessRunning( aProcName,
aProcDesc: string ): boolean;
var
ShellResult: boolean;
ResultCode: integer;
cmd: string;
sl: TStringList;
f: string;
d: string;
cmd2: string;
f2: string;
sl2: TStringList;
begin
cmd := 'for /f "delims=," %%i ' +
'in (''tasklist /FI "IMAGENAME eq ' + aProcName + '" /FO CSV'') ' +
'do if "%%~i"=="' + aProcName + '" exit 1';
f := 'CheckProc.cmd';
cmd2 := 'taskkill -f -t -im ' + aProcName;
f2 := 'KillProc.cmd';
d := AddBackSlash( ExpandConstant( '{tmp}' ));
sl := TStringList.Create;
sl.Add( cmd );
sl.Add( 'exit /0' );
sl.SaveToFile( d + f );
sl.Free;
sl2 := TStringList.Create;
sl2.Add( cmd2 );
sl2.Add( 'exit /0' );
sl2.SaveToFile( d + f2 );
sl2.Free;
Result := true;
while ( Result ) do
begin
ResultCode := 1;
ShellResult := Exec( f,
'',
d,
SW_HIDE,
ewWaitUntilTerminated,
ResultCode );
Result := ResultCode > 0;
if Result then
begin
// Msgbox('已关闭正在运行' + aProcDesc + '客户端!', mbInformation, MB_OK);
ShellResult := Exec( f2,
'',
d,
SW_HIDE,
ewWaitUntilTerminated,
ResultCode );
end;
end;
DeleteFile( d + f );
DeleteFile( d + f2 );
end;
// Perform some initializations. Return False to abort setup
function InitializeSetup: Boolean;
begin
// Do not use any user defined vars in here such as {app}
// Result := not ( CheckProcessRunning( 'apq-client-service.exe', 'apq-client-service' ));
CheckProcessRunning( 'apq-control.exe', 'apq客户端插件' )
CheckProcessRunning( 'apq-info.exe', 'apq客户端插件' )
CheckProcessRunning( 'apq-register.exe', 'apq客户端插件' )
CheckProcessRunning( 'apq.exe', 'apq客户端桌面' )
Result := not ( CheckProcessRunning( 'apq-client.exe', 'apq-client客户端' ));
; Script generated by the Inno Setup Script Wizard.
; SEE THE DOCUMENTATION FOR DETAILS ON CREATING INNO SETUP SCRIPT FILES!
#define MyAppName "阿普奇检测客户端"
#define MyAppVersion "V1.0"
#define MyAppPublisher "阿普奇"
#define MyAppURL "https://www.apq.com/"
#define MyAppDirName "apq-client"
#define MyAppEnName "apq-client"
#define MyAppExeName "apq-client.exe"
#define MyAppReBootName "service\启动服务R.bat"
[Setup]
; 注: AppId的值为单独标识该应用程序。
; 不要为其他安装程序使用相同的AppId值。
; (生成新的GUID,点击 工具|在IDE中生成GUID。)
; Tell Windows Explorer to reload the environment
ChangesEnvironment=yes
DisableDirPage=no
; AlwaysRestart=yes
AppId={{1394783A-5D3C-48CD-0000-E2DFBB844E42}
AppName={#MyAppName}
AppVersion={#MyAppVersion}
AppVerName={#MyAppName}
AppPublisher={#MyAppPublisher}
AppPublisherURL={#MyAppURL}
AppSupportURL={#MyAppURL}
AppUpdatesURL={#MyAppURL}
DefaultDirName={pf}\{#MyAppDirName}
DefaultGroupName={#MyAppName}
SetupIconFile=logo.ico
;安装包文件输出目录
OutputDir=..\dist\
;安装包文件名
OutputBaseFilename={#MyAppName}
;压缩文件
Compression=lzma
SolidCompression=yes
;以管理员权限运行
PrivilegesRequired=admin
UninstallDisplayIcon={app}/{#MyAppExeName}
//CreateUninstallRegKey=no
//UpdateUninstallLogAppName=no
VersionInfoVersion=1.0.0.1
[Languages]
Name: "chinese"; MessagesFile: "compiler:Languages/Chinese.isl"
[Files]
Source: "../apq-client/*"; DestDir: "{app}"; Flags: ignoreversion recursesubdirs createallsubdirs;
Source: "../../java/jre/jre/*"; DestDir: "{app}/jre"; Flags: ignoreversion recursesubdirs createallsubdirs;
Source: "../../client/*"; DestDir: "{app}"; Flags: ignoreversion recursesubdirs createallsubdirs;
; NOTE: Don't use "Flags: ignoreversion" on any shared system files
[Icons]
Name: "{group}\{cm:UninstallProgram,{#MyAppName}}"; Filename: "{uninstallexe}"
Name: "{commondesktop}\{#MyAppName}"; Filename: "{app}\client-soft\apq.exe";
[Run]
Filename: "{app}\Set_Env.bat"; Flags: runhidden;
Filename: "{app}\service\启动服务.bat"; Flags: runhidden runascurrentuser waituntilterminated;
;卸载后执行的操作(停止、删除各种服务)
[UninstallRun]
Filename: "{app}\service\删除服务.bat"; Flags: runhidden;
;卸载后删除目录所有文件,删除空目录
[UninstallDelete]
Type: filesandordirs; Name: "{app}\*"
Type: dirifempty; Name: "{app}"
;操作注册表
[Registry]
Root: HKLM; Subkey: "Software\{#MyAppEnName}"; Flags: uninsdeletekey;
Root: HKCU; Subkey: "SOFTWARE\Microsoft\Windows\CurrentVersion\Run"; ValueType: string; ValueName: "{#MyAppEnName}"; ValueData: "{app}\{#MyAppReBootName}"; Flags: uninsdeletevalue;
; set JAVA_HOME
Root: HKLM; Subkey: "SYSTEM\CurrentControlSet\Control\Session Manager\Environment"; ValueType:string; ValueName:"JAVA_HOME"; ValueData:"{app}\jre"; Flags: preservestringtype
; set PATH
Root: HKLM; Subkey: "SYSTEM\CurrentControlSet\Control\Session Manager\Environment"; ValueType:string; ValueName:"PATH"; ValueData:"{olddata};{app}\jre\bin"; Flags: preservestringtype
[Code]
function CheckProcessRunning( aProcName,
aProcDesc: string ): boolean;
var
ShellResult: boolean;
ResultCode: integer;
cmd: string;
sl: TStringList;
f: string;
d: string;
cmd2: string;
f2: string;
sl2: TStringList;
begin
cmd := 'for /f "delims=," %%i ' +
'in (''tasklist /FI "IMAGENAME eq ' + aProcName + '" /FO CSV'') ' +
'do if "%%~i"=="' + aProcName + '" exit 1';
f := 'CheckProc.cmd';
cmd2 := 'taskkill -f -t -im ' + aProcName;
f2 := 'KillProc.cmd';
d := AddBackSlash( ExpandConstant( '{tmp}' ));
sl := TStringList.Create;
sl.Add( cmd );
sl.Add( 'exit /0' );
sl.SaveToFile( d + f );
sl.Free;
sl2 := TStringList.Create;
sl2.Add( cmd2 );
sl2.Add( 'exit /0' );
sl2.SaveToFile( d + f2 );
sl2.Free;
Result := true;
while ( Result ) do
begin
ResultCode := 1;
ShellResult := Exec( f,
'',
d,
SW_HIDE,
ewWaitUntilTerminated,
ResultCode );
Result := ResultCode > 0;
if Result then
begin
// Msgbox('已关闭正在运行' + aProcDesc + '客户端!', mbInformation, MB_OK);
ShellResult := Exec( f2,
'',
d,
SW_HIDE,
ewWaitUntilTerminated,
ResultCode );
end;
end;
DeleteFile( d + f );
DeleteFile( d + f2 );
end;
// Perform some initializations. Return False to abort setup
function InitializeSetup: Boolean;
begin
// Do not use any user defined vars in here such as {app}
// Result := not ( CheckProcessRunning( 'apq-client-service.exe', 'apq-client-service' ));
CheckProcessRunning( 'apq-control.exe', 'apq客户端插件' )
CheckProcessRunning( 'apq-info.exe', 'apq客户端插件' )
CheckProcessRunning( 'apq-register.exe', 'apq客户端插件' )
CheckProcessRunning( 'apq.exe', 'apq客户端桌面' )
Result := not ( CheckProcessRunning( 'apq-client.exe', 'apq-client客户端' ));
end;
\ No newline at end of file
@ECHO OFF
setlocal ENABLEEXTENSIONS
@ECHO Installing apq-client ...
"%~dp0apq-client-service.exe" install
@ECHO runing apq-client ...
"%~dp0apq-client-service.exe" start
@ECHO DONE.
@ECHO OFF
setlocal ENABLEEXTENSIONS
@ECHO Installing apq-client ...
"%~dp0apq-client-service.exe" install
@ECHO running apq-client ...
"%~dp0apq-client-service.exe" start
@ECHO DONE.
:END
\ No newline at end of file
No preview for this file type
Markdown 格式
0%
您添加了 0 到此讨论。请谨慎行事。
请先完成此评论的编辑!
注册 或者 后发表评论