Browse Source

更改数据库引用 更换相对应字段

main
zhaoxianglong 9 months ago
parent
commit
b5557b1a12
  1. 15
      src/main/java/com/example/device/controller/DeviceStatus.java
  2. 61
      src/main/java/com/example/device/entity/Device.java
  3. 6
      src/main/resources/application.yml
  4. 7
      src/main/resources/mapping/DeviceMapper.xml

15
src/main/java/com/example/device/controller/DeviceStatus.java

@ -1,4 +1,5 @@
package com.example.device.controller; package com.example.device.controller;
import com.example.device.entity.Device; import com.example.device.entity.Device;
import com.example.device.entity.Status; import com.example.device.entity.Status;
import com.example.device.service.DeviceService; import com.example.device.service.DeviceService;
@ -8,18 +9,18 @@ import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.scheduling.annotation.EnableScheduling; import org.springframework.scheduling.annotation.EnableScheduling;
import org.springframework.scheduling.annotation.Scheduled; import org.springframework.scheduling.annotation.Scheduled;
import org.springframework.stereotype.Component; import org.springframework.stereotype.Component;
import java.io.IOException; import java.io.IOException;
import java.net.InetAddress; import java.net.InetAddress;
import java.time.LocalDateTime; import java.time.LocalDateTime;
import java.time.format.DateTimeFormatter; import java.time.format.DateTimeFormatter;
import java.time.temporal.ChronoUnit; import java.time.temporal.ChronoUnit;
import java.util.ArrayList; import java.util.*;
import java.util.HashMap;
import java.util.List;
import java.util.Map;
import java.util.stream.Collectors; import java.util.stream.Collectors;
import org.apache.poi.ss.usermodel.Workbook; import org.apache.poi.ss.usermodel.Workbook;
import org.apache.poi.xssf.usermodel.XSSFWorkbook; import org.apache.poi.xssf.usermodel.XSSFWorkbook;
import java.io.FileOutputStream; import java.io.FileOutputStream;
import java.io.BufferedReader; import java.io.BufferedReader;
import java.io.InputStreamReader; import java.io.InputStreamReader;
@ -42,11 +43,12 @@ public class DeviceStatus {
@Scheduled(cron = "0 0 0-23 * * ?") @Scheduled(cron = "0 0 0-23 * * ?")
// @Scheduled(cron = "0 0 1,5,7,8,11,14,17,19,21,23") // @Scheduled(cron = "0 0 1,5,7,8,11,14,17,19,21,23")
public void generateDeviceStatus() { public void generateDeviceStatus() {
System.out.println("开始执行" + new Date());
deviceStatus(); deviceStatus();
System.out.println("执行完毕" + new Date());
} }
// public void deviceStatus() { // public void deviceStatus() {
// Status status = new Status(); // Status status = new Status();
// List<Device> deviceList = deviceService.SelectList(); // List<Device> deviceList = deviceService.SelectList();
@ -77,7 +79,6 @@ public class DeviceStatus {
// } // }
public void deviceStatus() { public void deviceStatus() {
ExecutorService executor = Executors.newFixedThreadPool(100); ExecutorService executor = Executors.newFixedThreadPool(100);
List<Device> deviceList = deviceService.SelectList(); List<Device> deviceList = deviceService.SelectList();
@ -92,7 +93,7 @@ public class DeviceStatus {
String lostRate = getPingPacketLossRate(device.getDeviceIp()); String lostRate = getPingPacketLossRate(device.getDeviceIp());
boolean reachable = address.isReachable(5000); // Timeout: 5 seconds boolean reachable = address.isReachable(5000); // Timeout: 5 seconds
status.setDeviceNo(device.getDeviceNo()); status.setDeviceNo(device.getStakeMark());
status.setDeviceName(device.getDeviceName()); status.setDeviceName(device.getDeviceName());
status.setDeviceIp(device.getDeviceIp()); status.setDeviceIp(device.getDeviceIp());
LocalDateTime localDateTime = LocalDateTime.now(); LocalDateTime localDateTime = LocalDateTime.now();

61
src/main/java/com/example/device/entity/Device.java

@ -5,14 +5,34 @@ package com.example.device.entity;
* @Date 2020/03/03 * @Date 2020/03/03
*/ */
public class Device { public class Device {
private long id; private Long id;
private String stakeMark;
private String deviceName;
private String deviceIp;
private String deviceState;
public Device(Long id, String stakeMark, String deviceName, String deviceIp, String deviceState) {
this.id = id;
this.stakeMark = stakeMark;
this.deviceName = deviceName;
this.deviceIp = deviceIp;
this.deviceState = deviceState;
}
public Long getId() {
return id;
}
public void setId(Long id) {
this.id = id;
}
public String getDeviceNo() { public String getStakeMark() {
return deviceNo; return stakeMark;
} }
public void setDeviceNo(String deviceNo) { public void setStakeMark(String stakeMark) {
this.deviceNo = deviceNo; this.stakeMark = stakeMark;
} }
public String getDeviceName() { public String getDeviceName() {
@ -27,39 +47,16 @@ public class Device {
return deviceIp; return deviceIp;
} }
@Override
public String toString() {
return "Device{" +
"id=" + id +
", deviceNo='" + deviceNo + '\'' +
", deviceName='" + deviceName + '\'' +
", deviceIp='" + deviceIp + '\'' +
'}';
}
public Device(long id, String deviceNo, String deviceName, String deviceIp) {
this.id = id;
this.deviceNo = deviceNo;
this.deviceName = deviceName;
this.deviceIp = deviceIp;
}
public void setDeviceIp(String deviceIp) { public void setDeviceIp(String deviceIp) {
this.deviceIp = deviceIp; this.deviceIp = deviceIp;
} }
public String getType() { public String getDeviceState() {
return type; return deviceState;
} }
public void setType(String type) { public void setDeviceState(String deviceState) {
this.type = type; this.deviceState = deviceState;
} }
private String deviceNo;
private String deviceName;
private String deviceIp;
private String type;
} }

6
src/main/resources/application.yml

@ -4,8 +4,10 @@ server:
spring: spring:
datasource: datasource:
username: root username: root
password: Platform123!@# password: mysql123!@#
url: jdbc:mysql://10.168.56.204:3306/device?useUnicode=true&characterEncoding=utf-8&useSSL=false&serverTimezone=GMT%2B8 # password: Platform123!@#
# url: jdbc:mysql://10.168.56.202:3306/device?useUnicode=true&characterEncoding=utf-8&useSSL=false&serverTimezone=GMT%2B8
url: jdbc:mysql://10.0.81.202:3306/jihe-dc?useUnicode=true&characterEncoding=utf8&zeroDateTimeBehavior=convertToNull&useSSL=false&serverTimezone=GMT%2B8&allowPublicKeyRetrieval=true
driver-class-name: com.mysql.cj.jdbc.Driver driver-class-name: com.mysql.cj.jdbc.Driver
mybatis: mybatis:

7
src/main/resources/mapping/DeviceMapper.xml

@ -4,13 +4,14 @@
<resultMap id="BaseResultMap" type="com.example.device.entity.Device"> <resultMap id="BaseResultMap" type="com.example.device.entity.Device">
<result column="id" jdbcType="BIGINT" property="id"/> <result column="id" jdbcType="BIGINT" property="id"/>
<result column="device_no" jdbcType="VARCHAR" property="deviceNo"/> <result column="stake_mark" jdbcType="VARCHAR" property="stakeMark"/>
<result column="device_name" jdbcType="VARCHAR" property="deviceName"/> <result column="device_name" jdbcType="VARCHAR" property="deviceName"/>
<result column="device_ip" jdbcType="VARCHAR" property="deviceIp"/> <result column="device_ip" jdbcType="VARCHAR" property="deviceIp"/>
</resultMap> </resultMap>
<select id="SelectList" resultType="com.example.device.entity.Device"> <select id="SelectList" parameterType="com.example.device.entity.Device" resultMap="BaseResultMap">
select * from device select *
from dc_device
</select> </select>
</mapper> </mapper>
Loading…
Cancel
Save