天台山水库获取水质信息
commit
c6de0847fd
|
|
@ -0,0 +1,212 @@
|
|||
<?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 http://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.7.1</version>
|
||||
<relativePath/> <!-- lookup parent from repository -->
|
||||
</parent>
|
||||
|
||||
<groupId>com.whdc</groupId>
|
||||
<artifactId>ttssk-service</artifactId>
|
||||
<version>1.0</version>
|
||||
<description>天台山水库</description>
|
||||
|
||||
<properties>
|
||||
<maven.compiler.source>8</maven.compiler.source>
|
||||
<maven.compiler.target>8</maven.compiler.target>
|
||||
<java.version>1.8</java.version>
|
||||
<copy.jar.directory>target/release</copy.jar.directory>
|
||||
</properties>
|
||||
|
||||
<!-- 使用阿里 maven 库 -->
|
||||
<repositories>
|
||||
<repository>
|
||||
<id>ali-maven</id>
|
||||
<url>https://maven.aliyun.com/nexus/content/groups/public</url>
|
||||
<releases>
|
||||
<enabled>true</enabled>
|
||||
</releases>
|
||||
<snapshots>
|
||||
<enabled>true</enabled>
|
||||
<updatePolicy>always</updatePolicy>
|
||||
<checksumPolicy>fail</checksumPolicy>
|
||||
</snapshots>
|
||||
</repository>
|
||||
</repositories>
|
||||
|
||||
<dependencies>
|
||||
<dependency>
|
||||
<groupId>org.springframework.boot</groupId>
|
||||
<artifactId>spring-boot-starter-web</artifactId>
|
||||
</dependency>
|
||||
<dependency>
|
||||
<groupId>org.springframework.boot</groupId>
|
||||
<artifactId>spring-boot-starter-aop</artifactId>
|
||||
</dependency>
|
||||
<dependency>
|
||||
<groupId>com.baomidou</groupId>
|
||||
<artifactId>mybatis-plus-boot-starter</artifactId>
|
||||
<version>3.5.2</version>
|
||||
</dependency>
|
||||
<dependency>
|
||||
<groupId>org.springframework.boot</groupId>
|
||||
<artifactId>spring-boot-starter-validation</artifactId>
|
||||
</dependency>
|
||||
<dependency>
|
||||
<groupId>org.springframework.boot</groupId>
|
||||
<artifactId>spring-boot-starter-data-redis</artifactId>
|
||||
</dependency>
|
||||
<!-- mysql start-->
|
||||
<dependency>
|
||||
<groupId>mysql</groupId>
|
||||
<artifactId>mysql-connector-java</artifactId>
|
||||
<version>8.0.16</version>
|
||||
</dependency>
|
||||
<!-- mysql end-->
|
||||
|
||||
<!-- Sa-Token 权限认证, 在线文档:http://sa-token.dev33.cn/ -->
|
||||
<dependency>
|
||||
<groupId>cn.dev33</groupId>
|
||||
<artifactId>sa-token-spring-boot-starter</artifactId>
|
||||
<version>1.30.0</version>
|
||||
</dependency><!-- Sa-Token 整合 Redis (使用 jackson 序列化方式) -->
|
||||
<dependency>
|
||||
<groupId>cn.dev33</groupId>
|
||||
<artifactId>sa-token-dao-redis-jackson</artifactId>
|
||||
<version>1.30.0</version>
|
||||
</dependency>
|
||||
<!-- 提供Redis连接池 -->
|
||||
<dependency>
|
||||
<groupId>org.apache.commons</groupId>
|
||||
<artifactId>commons-pool2</artifactId>
|
||||
</dependency>
|
||||
<!-- Sa-Token 权限认证 end -->
|
||||
|
||||
|
||||
<!-- knife4j swagger start-->
|
||||
<dependency>
|
||||
<groupId>com.github.xiaoymin</groupId>
|
||||
<artifactId>knife4j-spring-boot-starter</artifactId>
|
||||
<version>3.0.3</version>
|
||||
</dependency>
|
||||
<!-- knife4j swagger end-->
|
||||
|
||||
<!-- devtools start -->
|
||||
<dependency>
|
||||
<groupId>org.springframework.boot</groupId>
|
||||
<artifactId>spring-boot-devtools</artifactId>
|
||||
<scope>runtime</scope>
|
||||
<optional>true</optional> <!-- 这个需要为 true 热部署才有效 -->
|
||||
</dependency>
|
||||
<!-- devtools end -->
|
||||
|
||||
<!-- lombok start -->
|
||||
<dependency>
|
||||
<groupId>org.projectlombok</groupId>
|
||||
<artifactId>lombok</artifactId>
|
||||
</dependency>
|
||||
<!-- lombok end -->
|
||||
|
||||
<!-- fastjson start -->
|
||||
<dependency>
|
||||
<groupId>com.alibaba</groupId>
|
||||
<artifactId>fastjson</artifactId>
|
||||
<version>1.2.80</version>
|
||||
</dependency>
|
||||
<!-- fastjson end-->
|
||||
|
||||
<dependency>
|
||||
<groupId>org.eclipse.paho</groupId>
|
||||
<artifactId>org.eclipse.paho.client.mqttv3</artifactId>
|
||||
<version>1.2.0</version>
|
||||
</dependency>
|
||||
<!-- druid start -->
|
||||
<dependency>
|
||||
<groupId>com.alibaba</groupId>
|
||||
<artifactId>druid</artifactId>
|
||||
<version>1.2.8</version>
|
||||
</dependency>
|
||||
<!-- druid end -->
|
||||
|
||||
|
||||
<!-- mybatisplus-plus start -->
|
||||
<dependency>
|
||||
<groupId>com.github.jeffreyning</groupId>
|
||||
<artifactId>mybatisplus-plus</artifactId>
|
||||
<version>1.7.0-RELEASE</version>
|
||||
</dependency>
|
||||
<!-- mybatisplus-plus end -->
|
||||
</dependencies>
|
||||
|
||||
<build>
|
||||
<plugins>
|
||||
<!-- 1.生成的jar中,不要包含pom.xml和pom.properties这两个文件 -->
|
||||
<plugin>
|
||||
<groupId>org.apache.maven.plugins</groupId>
|
||||
<artifactId>maven-jar-plugin</artifactId>
|
||||
<configuration>
|
||||
<archive>
|
||||
<addMavenDescriptor>false</addMavenDescriptor>
|
||||
<manifest>
|
||||
<!-- 是否要把第三方jar加入到类构建路径 -->
|
||||
<addClasspath>true</addClasspath>
|
||||
<!-- 外部依赖jar包的最终位置 -->
|
||||
<classpathPrefix>lib/</classpathPrefix>
|
||||
<!-- 项目启动类 -->
|
||||
<mainClass>com.whdc.SpringApplication</mainClass>
|
||||
</manifest>
|
||||
</archive>
|
||||
</configuration>
|
||||
</plugin>
|
||||
|
||||
<!--2.拷贝依赖到jar外面的lib目录-->
|
||||
<plugin>
|
||||
<groupId>org.apache.maven.plugins</groupId>
|
||||
<artifactId>maven-dependency-plugin</artifactId>
|
||||
<executions>
|
||||
<execution>
|
||||
<id>copy-lib</id>
|
||||
<phase>package</phase>
|
||||
<goals>
|
||||
<goal>copy-dependencies</goal>
|
||||
</goals>
|
||||
<configuration>
|
||||
<outputDirectory>${copy.jar.directory}/lib</outputDirectory>
|
||||
<excludeTransitive>false</excludeTransitive>
|
||||
<stripVersion>false</stripVersion>
|
||||
<includeScope>runtime</includeScope>
|
||||
</configuration>
|
||||
</execution>
|
||||
</executions>
|
||||
</plugin>
|
||||
|
||||
<!-- 3.把jar包拷贝到指定目录位置 -->
|
||||
<plugin>
|
||||
<artifactId>maven-antrun-plugin</artifactId>
|
||||
<executions>
|
||||
<execution>
|
||||
<id>copy</id>
|
||||
<phase>package</phase>
|
||||
<configuration>
|
||||
<target>
|
||||
<copy todir="${copy.jar.directory}">
|
||||
<fileset dir="${project.build.directory}">
|
||||
<include name="${project.artifactId}.${project.version}.jar"/>
|
||||
</fileset>
|
||||
</copy>
|
||||
</target>
|
||||
</configuration>
|
||||
<goals>
|
||||
<goal>run</goal>
|
||||
</goals>
|
||||
</execution>
|
||||
</executions>
|
||||
</plugin>
|
||||
</plugins>
|
||||
</build>
|
||||
</project>
|
||||
|
|
@ -0,0 +1,36 @@
|
|||
package com.whdc;
|
||||
|
||||
import com.github.jeffreyning.mybatisplus.conf.EnableMPP;
|
||||
import com.github.xiaoymin.knife4j.spring.annotations.EnableKnife4j;
|
||||
import lombok.extern.slf4j.Slf4j;
|
||||
import org.mybatis.spring.annotation.MapperScan;
|
||||
import org.springframework.beans.BeansException;
|
||||
import org.springframework.boot.SpringApplication;
|
||||
import org.springframework.boot.autoconfigure.SpringBootApplication;
|
||||
import org.springframework.scheduling.annotation.EnableScheduling;
|
||||
import org.springframework.web.servlet.config.annotation.EnableWebMvc;
|
||||
|
||||
/**
|
||||
* @author 李赛
|
||||
* @date 2022-06-26 0:17
|
||||
*/
|
||||
@Slf4j
|
||||
@EnableMPP
|
||||
@EnableWebMvc
|
||||
@EnableKnife4j
|
||||
@EnableScheduling
|
||||
@SpringBootApplication
|
||||
@MapperScan("com.whdc.mapper")
|
||||
public class TtsskApplication {
|
||||
public static void main(String[] args) {
|
||||
try {
|
||||
System.out.println(">>>>>>>>>>>>>>>>>>>>>>>>>>> 启动程序 <<<<<<<<<<<<<<<<<<<<<<<<<<<");
|
||||
|
||||
SpringApplication.run(TtsskApplication.class, args);
|
||||
} catch (BeansException e) {
|
||||
e.printStackTrace();
|
||||
log.error(e.getMessage(), e);
|
||||
}
|
||||
}
|
||||
|
||||
}
|
||||
|
|
@ -0,0 +1,52 @@
|
|||
package com.whdc.entity;
|
||||
|
||||
import com.baomidou.mybatisplus.annotation.IdType;
|
||||
import com.baomidou.mybatisplus.annotation.TableField;
|
||||
import com.baomidou.mybatisplus.annotation.TableId;
|
||||
import com.baomidou.mybatisplus.annotation.TableName;
|
||||
import com.fasterxml.jackson.annotation.JsonFormat;
|
||||
import lombok.Data;
|
||||
import lombok.Getter;
|
||||
import lombok.Setter;
|
||||
|
||||
import java.math.BigDecimal;
|
||||
import java.util.Date;
|
||||
|
||||
/**
|
||||
* <p>
|
||||
* 水质信息表
|
||||
* </p>
|
||||
*
|
||||
* @author wanyan
|
||||
* @since 2023-11-01
|
||||
*/
|
||||
@Getter
|
||||
@Setter
|
||||
@TableName("wq_r")
|
||||
@Data
|
||||
public class WqR {
|
||||
|
||||
@TableId(value = "stcd")
|
||||
private String stcd;
|
||||
|
||||
@JsonFormat(pattern = "yyyy-MM-dd HH:mm:ss", timezone = "GMT+8")
|
||||
@TableField("tm")
|
||||
private Date tm;
|
||||
|
||||
@TableField("chlorophyll")
|
||||
private BigDecimal chlorophyll;
|
||||
|
||||
@TableField("blueAlgae")
|
||||
private BigDecimal blueAlgae;
|
||||
|
||||
@TableField("greenAlgae")
|
||||
private BigDecimal greenAlgae;
|
||||
|
||||
@TableField("diatom")
|
||||
private BigDecimal diatom;
|
||||
|
||||
@TableField("cryptomonas")
|
||||
private BigDecimal cryptomonas;
|
||||
|
||||
|
||||
}
|
||||
|
|
@ -0,0 +1,51 @@
|
|||
package com.whdc.entity;
|
||||
|
||||
import com.baomidou.mybatisplus.annotation.TableField;
|
||||
import com.baomidou.mybatisplus.annotation.TableId;
|
||||
import com.baomidou.mybatisplus.annotation.TableName;
|
||||
import com.fasterxml.jackson.annotation.JsonFormat;
|
||||
import lombok.Data;
|
||||
import lombok.Getter;
|
||||
import lombok.Setter;
|
||||
|
||||
import java.math.BigDecimal;
|
||||
import java.util.Date;
|
||||
|
||||
/**
|
||||
* <p>
|
||||
* 水质实时信息表
|
||||
* </p>
|
||||
*
|
||||
* @author wanyan
|
||||
* @since 2023-11-01
|
||||
*/
|
||||
@Getter
|
||||
@Setter
|
||||
@TableName("wq_real")
|
||||
@Data
|
||||
public class WqReal {
|
||||
|
||||
@TableId(value = "stcd")
|
||||
private String stcd;
|
||||
|
||||
@JsonFormat(pattern = "yyyy-MM-dd HH:mm:ss", timezone = "GMT+8")
|
||||
@TableField("tm")
|
||||
private Date tm;
|
||||
|
||||
@TableField("chlorophyll")
|
||||
private BigDecimal chlorophyll;
|
||||
|
||||
@TableField("blueAlgae")
|
||||
private BigDecimal blueAlgae;
|
||||
|
||||
@TableField("greenAlgae")
|
||||
private BigDecimal greenAlgae;
|
||||
|
||||
@TableField("diatom")
|
||||
private BigDecimal diatom;
|
||||
|
||||
@TableField("cryptomonas")
|
||||
private BigDecimal cryptomonas;
|
||||
|
||||
|
||||
}
|
||||
|
|
@ -0,0 +1,17 @@
|
|||
package com.whdc.mapper;
|
||||
|
||||
import com.baomidou.mybatisplus.core.mapper.BaseMapper;
|
||||
import com.whdc.entity.WqR;
|
||||
import org.apache.ibatis.annotations.Mapper;
|
||||
|
||||
/**
|
||||
* <p>
|
||||
* 水质信息表 Mapper 接口
|
||||
* </p>
|
||||
*
|
||||
* @author wanyan
|
||||
* @since 2023-11-01
|
||||
*/
|
||||
@Mapper
|
||||
public interface WqRMapper extends BaseMapper<WqR> {
|
||||
}
|
||||
|
|
@ -0,0 +1,17 @@
|
|||
package com.whdc.mapper;
|
||||
|
||||
import com.baomidou.mybatisplus.core.mapper.BaseMapper;
|
||||
import com.whdc.entity.WqReal;
|
||||
import org.apache.ibatis.annotations.Mapper;
|
||||
|
||||
/**
|
||||
* <p>
|
||||
* 水质实时信息表 Mapper 接口
|
||||
* </p>
|
||||
*
|
||||
* @author wanyan
|
||||
* @since 2023-11-01
|
||||
*/
|
||||
@Mapper
|
||||
public interface WqRealMapper extends BaseMapper<WqReal> {
|
||||
}
|
||||
|
|
@ -0,0 +1,9 @@
|
|||
package com.whdc.mqtt;
|
||||
|
||||
public class Config {
|
||||
public static final String USERNAME = "wy";
|
||||
public static final char[] PASSWORD = "Gsiot_890".toCharArray();
|
||||
|
||||
public static final String TOPIC_WQ_R = "/Algae/#";
|
||||
|
||||
}
|
||||
|
|
@ -0,0 +1,92 @@
|
|||
package com.whdc.mqtt;
|
||||
|
||||
import com.alibaba.fastjson.JSON;
|
||||
import com.whdc.entity.WqR;
|
||||
import com.whdc.entity.WqReal;
|
||||
import com.whdc.mapper.WqRMapper;
|
||||
import com.whdc.mapper.WqRealMapper;
|
||||
import lombok.extern.slf4j.Slf4j;
|
||||
import org.eclipse.paho.client.mqttv3.MqttException;
|
||||
import org.springframework.beans.factory.annotation.Autowired;
|
||||
import org.springframework.beans.factory.annotation.Value;
|
||||
import org.springframework.context.annotation.Configuration;
|
||||
|
||||
import javax.annotation.PostConstruct;
|
||||
import java.util.Date;
|
||||
|
||||
@Configuration
|
||||
@Slf4j
|
||||
public class MQTTConfig {
|
||||
|
||||
@Autowired
|
||||
private WqRMapper wqRMapper;
|
||||
|
||||
@Autowired
|
||||
private WqRealMapper wqRealMapper;
|
||||
|
||||
@Value("${mqtt.broker}")
|
||||
private String broker;
|
||||
@Value("${mqtt.clientId}")
|
||||
private String clientId;
|
||||
|
||||
@Value("${enableMqttListening}")
|
||||
private Boolean enable;
|
||||
|
||||
private static Sub sub;
|
||||
|
||||
@PostConstruct
|
||||
public void initMQTT() {
|
||||
if (!enable) {
|
||||
log.debug("开发环境,不开启mqtt");
|
||||
return;
|
||||
}
|
||||
log.debug("开启mqtt broker: %s, clientId: %s", broker, clientId);
|
||||
|
||||
Pub.BROKER = broker;
|
||||
sub = new Sub(broker, clientId, Config.TOPIC_WQ_R);
|
||||
sub.setOnMessageListener(new Sub.OnMessageListener() {
|
||||
@Override
|
||||
public void onMessage(String message) {
|
||||
log.debug("mqtt: " + message);
|
||||
System.out.println(message);
|
||||
try {
|
||||
WqR wqr = JSON.parseObject(message, WqR.class);
|
||||
Date now = new Date();
|
||||
wqr.setStcd("WQ");
|
||||
wqr.setTm(now);
|
||||
wqRMapper.insert(wqr);
|
||||
WqReal wqReal = wqRealMapper.selectById("WQ");
|
||||
if(wqReal == null){
|
||||
wqReal = new WqReal();
|
||||
}
|
||||
wqReal.setChlorophyll(wqr.getChlorophyll());
|
||||
wqReal.setBlueAlgae(wqr.getBlueAlgae());
|
||||
wqReal.setGreenAlgae(wqr.getGreenAlgae());
|
||||
wqReal.setDiatom(wqr.getDiatom());
|
||||
wqReal.setCryptomonas(wqr.getCryptomonas());
|
||||
wqReal.setTm(now);
|
||||
if (wqReal.getStcd() == null) {
|
||||
wqReal.setStcd("WQ");
|
||||
wqRealMapper.insert(wqReal);
|
||||
} else {
|
||||
wqRealMapper.updateById(wqReal);
|
||||
}
|
||||
|
||||
} catch (Throwable e) {
|
||||
e.printStackTrace();
|
||||
}
|
||||
}
|
||||
});
|
||||
new Thread(() -> {
|
||||
try {
|
||||
Thread.sleep(10 * 1000);
|
||||
sub.connect(true);
|
||||
} catch (MqttException e) {
|
||||
e.printStackTrace();
|
||||
} catch (InterruptedException e) {
|
||||
throw new RuntimeException(e);
|
||||
}
|
||||
}).start();
|
||||
}
|
||||
|
||||
}
|
||||
|
|
@ -0,0 +1,54 @@
|
|||
package com.whdc.mqtt;
|
||||
|
||||
import org.eclipse.paho.client.mqttv3.MqttClient;
|
||||
import org.eclipse.paho.client.mqttv3.MqttConnectOptions;
|
||||
import org.eclipse.paho.client.mqttv3.MqttException;
|
||||
import org.eclipse.paho.client.mqttv3.MqttMessage;
|
||||
import org.eclipse.paho.client.mqttv3.persist.MemoryPersistence;
|
||||
|
||||
public class Pub {
|
||||
private final String clientId;
|
||||
private final String topic;
|
||||
public static String BROKER;
|
||||
private final int qos;
|
||||
private MqttClient client;
|
||||
|
||||
public Pub(String clientId, String topic) {
|
||||
this.clientId = clientId;
|
||||
this.topic = topic;
|
||||
this.qos = 0;
|
||||
}
|
||||
|
||||
public Pub(String clientId, String topic, int qos) {
|
||||
this.clientId = clientId;
|
||||
this.topic = topic;
|
||||
this.qos = qos;
|
||||
}
|
||||
|
||||
public void connect() throws MqttException {
|
||||
this.client = new MqttClient("tcp://120.24.5.249:3189", "mqttx_2b072a3c", new MemoryPersistence());
|
||||
MqttConnectOptions connOpts = new MqttConnectOptions();
|
||||
connOpts.setUserName(Config.USERNAME);
|
||||
connOpts.setPassword(Config.PASSWORD);
|
||||
connOpts.setCleanSession(true);
|
||||
this.client.connect(connOpts);
|
||||
}
|
||||
|
||||
public void close() {
|
||||
try {
|
||||
this.client.disconnectForcibly(200);
|
||||
this.client.close(true);
|
||||
} catch (MqttException e) {
|
||||
e.printStackTrace();
|
||||
}
|
||||
}
|
||||
|
||||
public void pub(String msg) throws MqttException {
|
||||
MqttMessage message = new MqttMessage(msg.getBytes());
|
||||
message.setQos(qos);
|
||||
this.client.publish(topic, message);
|
||||
}
|
||||
|
||||
|
||||
|
||||
}
|
||||
|
|
@ -0,0 +1,84 @@
|
|||
package com.whdc.mqtt;
|
||||
|
||||
import org.eclipse.paho.client.mqttv3.*;
|
||||
import org.eclipse.paho.client.mqttv3.persist.MemoryPersistence;
|
||||
|
||||
|
||||
public class Sub {
|
||||
private final String clientId;
|
||||
private final String topic;
|
||||
private final String broker;
|
||||
private OnMessageListener onMessageListener;
|
||||
private MqttClient client;
|
||||
|
||||
public Sub(String broker, String clientId, String topic) {
|
||||
this.clientId = clientId;
|
||||
this.topic = topic;
|
||||
this.broker = broker;
|
||||
}
|
||||
|
||||
public void setOnMessageListener(OnMessageListener listener) {
|
||||
this.onMessageListener = listener;
|
||||
}
|
||||
|
||||
public void connect() throws MqttException {
|
||||
connect(true);
|
||||
}
|
||||
|
||||
public void connect(boolean autoReconnect) throws MqttException {
|
||||
this.client = new MqttClient(broker, this.clientId, new MemoryPersistence());
|
||||
MqttConnectOptions connOpts = new MqttConnectOptions();
|
||||
connOpts.setUserName(Config.USERNAME);
|
||||
connOpts.setPassword(Config.PASSWORD);
|
||||
connOpts.setCleanSession(true);
|
||||
connOpts.setAutomaticReconnect(autoReconnect);
|
||||
|
||||
this.client.setCallback(new MqttCallback() {
|
||||
@Override
|
||||
public void connectionLost(Throwable throwable) {
|
||||
throwable.printStackTrace();
|
||||
}
|
||||
|
||||
@Override
|
||||
public void messageArrived(String topic, MqttMessage mqttMessage) {
|
||||
byte[] payload = mqttMessage.getPayload();
|
||||
String msg = new String(payload);
|
||||
try {
|
||||
Sub.this.onMessageListener.onMessage(msg);
|
||||
} catch (Throwable e) {
|
||||
e.printStackTrace();
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
public void deliveryComplete(IMqttDeliveryToken iMqttDeliveryToken) {
|
||||
}
|
||||
});
|
||||
|
||||
this.client.connect(connOpts);
|
||||
this.client.subscribe(this.topic, 0);
|
||||
}
|
||||
|
||||
public void close() {
|
||||
try {
|
||||
this.client.disconnectForcibly(200);
|
||||
this.client.close(true);
|
||||
} catch (MqttException e) {
|
||||
}
|
||||
}
|
||||
|
||||
public interface OnMessageListener {
|
||||
void onMessage(String message);
|
||||
}
|
||||
|
||||
public static void main(String[] args) throws MqttException {
|
||||
Sub sub = new Sub("tcp://120.24.5.249:3189","mqttx_2b072a3c", Config.TOPIC_WQ_R);
|
||||
sub.setOnMessageListener(new OnMessageListener() {
|
||||
@Override
|
||||
public void onMessage(String message) {
|
||||
System.out.println("received msg: " + message);
|
||||
}
|
||||
});
|
||||
sub.connect(true);
|
||||
}
|
||||
}
|
||||
|
|
@ -0,0 +1,16 @@
|
|||
package com.whdc.service;
|
||||
|
||||
import com.baomidou.mybatisplus.extension.service.IService;
|
||||
import com.whdc.entity.WqR;
|
||||
|
||||
/**
|
||||
* <p>
|
||||
* 水质信息表 服务类
|
||||
* </p>
|
||||
*
|
||||
* @author wanyan
|
||||
* @since 2023-11-01
|
||||
*/
|
||||
public interface WqRService extends IService<WqR> {
|
||||
|
||||
}
|
||||
|
|
@ -0,0 +1,20 @@
|
|||
package com.whdc.service.impl;
|
||||
|
||||
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
|
||||
import com.whdc.entity.WqR;
|
||||
import com.whdc.mapper.WqRMapper;
|
||||
import com.whdc.service.WqRService;
|
||||
import org.springframework.stereotype.Service;
|
||||
|
||||
/**
|
||||
* <p>
|
||||
* 水质信息表 服务实现类
|
||||
* </p>
|
||||
*
|
||||
* @author wanyan
|
||||
* @since 2023-11-01
|
||||
*/
|
||||
@Service
|
||||
public class WqRServiceImp extends ServiceImpl<WqRMapper, WqR> implements WqRService {
|
||||
|
||||
}
|
||||
|
|
@ -0,0 +1,67 @@
|
|||
server:
|
||||
port: 12303
|
||||
|
||||
|
||||
spring:
|
||||
#数据库配置
|
||||
datasource:
|
||||
driver-class-name: com.mysql.jdbc.Driver
|
||||
url: jdbc:mysql://rm-wz9n28sq10rz5b0u2o.mysql.rds.aliyuncs.com:3306/ttssk?characterEncoding=utf8&useSSL=false&zeroDateTimeBehavior=convertToNull&useInformationSchema=true&serverTimezone=GMT%2B8&autoReconnect=true
|
||||
username: fxkh
|
||||
password: Fxkh_789_@
|
||||
servlet:
|
||||
multipart:
|
||||
max-file-size: 100MB
|
||||
max-request-size: 100MB
|
||||
|
||||
#jpa配置
|
||||
jpa:
|
||||
properties:
|
||||
hibernate:
|
||||
dialect: org.hibernate.dialect.DmDialect
|
||||
|
||||
knife4j:
|
||||
enable: true
|
||||
setting:
|
||||
enableFooter: false
|
||||
enableFooterCustom: true
|
||||
footerCustomContent: Copyright 2018-[湖北纬皓端成科技有限公司](http://www.wavehorizon.cn)
|
||||
|
||||
documents: # 文档配置,可配置多个分组
|
||||
- group: doc-knife4j-1.0.0
|
||||
name: MarkDown文档
|
||||
locations: classpath:markdown/*
|
||||
- group: v1.0
|
||||
name: v1.0
|
||||
|
||||
|
||||
logging:
|
||||
# level:
|
||||
# org.springframework.boot.autoconfigure: error #spring的自动装配日志只打error,否则debug输出的会打印很多自动装配的log信息到控制台
|
||||
# com.whdc.zhzmkzapi.mapper: error
|
||||
config: classpath:logback-spring.xml
|
||||
mybatis:
|
||||
mapper-locations: classpath:mapper/*.xml
|
||||
# Sa-Token配置
|
||||
sa-token:
|
||||
# token 名称 (同时也是cookie名称)
|
||||
token-name: token
|
||||
# token 有效期, 24小时,单位s, -1代表永不过期
|
||||
timeout: 86400
|
||||
# token 临时有效期 (指定时间内无操作就视为token过期) 单位: 秒
|
||||
activity-timeout: -1
|
||||
# 是否允许同一账号并发登录 (为true时允许一起登录, 为false时新登录挤掉旧登录)
|
||||
is-concurrent: true
|
||||
# 在多人登录同一账号时,是否共用一个token (为true时所有登录共用一个token, 为false时每次登录新建一个token)
|
||||
is-share: true
|
||||
# token风格
|
||||
token-style: simple-uuid
|
||||
# 是否输出操作日志
|
||||
is-log: false
|
||||
|
||||
|
||||
mqtt:
|
||||
broker: tcp://120.24.5.249:3189
|
||||
clientId: mqttx_2b172a3c
|
||||
|
||||
enableMqttListening: true
|
||||
|
|
@ -0,0 +1,206 @@
|
|||
<?xml version="1.0" encoding="UTF-8"?>
|
||||
<!-- 日志级别从低到高分为TRACE < DEBUG < INFO < WARN < ERROR < FATAL,如果设置为WARN,则低于WARN的信息都不会输出 -->
|
||||
<!-- scan:当此属性设置为true时,配置文档如果发生改变,将会被重新加载,默认值为true -->
|
||||
<!-- scanPeriod:设置监测配置文档是否有修改的时间间隔,如果没有给出时间单位,默认单位是毫秒。 当scan为true时,此属性生效。默认的时间间隔为1分钟。 -->
|
||||
<!-- debug:当此属性设置为true时,将打印出logback内部日志信息,实时查看logback运行状态。默认值为false。 -->
|
||||
<configuration scan="true" scanPeriod="10 seconds">
|
||||
<include resource="org/springframework/boot/logging/logback/defaults.xml"/>
|
||||
<contextName>logback</contextName>
|
||||
|
||||
<!-- 文件切割大小 -->
|
||||
<property name="maxFileSize" value="100MB"/>
|
||||
<!-- 文档保留天数 -->
|
||||
<property name="maxHistory" value="3"/>
|
||||
<!-- 文档保留总大小 -->
|
||||
<property name="totalSizeCap" value="1GB"/>
|
||||
|
||||
<!-- name的值是变量的名称,value的值时变量定义的值。通过定义的值会被插入到logger上下文中。定义后,可以使“${}”来使用变量。 -->
|
||||
<property name="log.path" value="./logs"/>
|
||||
|
||||
<!--0. 日志格式和颜色渲染 -->
|
||||
<!-- 彩色日志依赖的渲染类 -->
|
||||
<conversionRule conversionWord="clr" converterClass="org.springframework.boot.logging.logback.ColorConverter"/>
|
||||
<conversionRule conversionWord="wex"
|
||||
converterClass="org.springframework.boot.logging.logback.WhitespaceThrowableProxyConverter"/>
|
||||
<conversionRule conversionWord="wEx"
|
||||
converterClass="org.springframework.boot.logging.logback.ExtendedWhitespaceThrowableProxyConverter"/>
|
||||
<!-- 彩色日志格式 -->
|
||||
<property name="CONSOLE_LOG_PATTERN"
|
||||
value="${CONSOLE_LOG_PATTERN:-%clr(%d{yyyy-MM-dd HH:mm:ss.SSS}){faint} %clr(${LOG_LEVEL_PATTERN:-%5p}) %clr(${PID:- }){magenta} %clr(---){faint} %clr([%15.15t]){faint} %clr(%-40.40logger{39}){cyan} %clr(:){faint} %m%n${LOG_EXCEPTION_CONVERSION_WORD:-%wEx}}"/>
|
||||
|
||||
<!-- <property name="CONSOLE_LOG_PATTERN" value="%-12(%d{yyyy-MM-dd HH:mm:ss.SSS}) |-%-5level [%thread] %c [%L] -| %msg%n"/>-->
|
||||
|
||||
<!--1. 输出到控制台-->
|
||||
<appender name="CONSOLE" class="ch.qos.logback.core.ConsoleAppender">
|
||||
<!--此日志appender是为开发使用,只配置最底级别,控制台输出的日志级别是大于或等于此级别的日志信息-->
|
||||
<filter class="ch.qos.logback.classic.filter.ThresholdFilter">
|
||||
<level>debug</level>
|
||||
</filter>
|
||||
<encoder>
|
||||
<Pattern>${CONSOLE_LOG_PATTERN}</Pattern>
|
||||
<!-- 设置字符集 -->
|
||||
<charset>UTF-8</charset>
|
||||
</encoder>
|
||||
</appender>
|
||||
|
||||
<!--2. 输出到文档-->
|
||||
<!-- 2.1 level为 DEBUG 日志,时间滚动输出 -->
|
||||
<appender name="DEBUG_FILE" class="ch.qos.logback.core.rolling.RollingFileAppender">
|
||||
<!-- 正在记录的日志文档的路径及文档名 -->
|
||||
<file>${log.path}/web_debug.log</file>
|
||||
<!--日志文档输出格式-->
|
||||
<encoder>
|
||||
<pattern>%d{yyyy-MM-dd HH:mm:ss.SSS} [%thread] %-5level %logger{50} - %msg%n</pattern>
|
||||
<charset>UTF-8</charset> <!-- 设置字符集 -->
|
||||
</encoder>
|
||||
<!-- 日志记录器的滚动策略,按日期,按大小记录 -->
|
||||
<rollingPolicy class="ch.qos.logback.core.rolling.TimeBasedRollingPolicy">
|
||||
<!-- 日志归档 -->
|
||||
<fileNamePattern>${log.path}/web-debug-%d{yyyy-MM-dd}.%i.log</fileNamePattern>
|
||||
<timeBasedFileNamingAndTriggeringPolicy class="ch.qos.logback.core.rolling.SizeAndTimeBasedFNATP">
|
||||
<maxFileSize>${maxFileSize}</maxFileSize>
|
||||
</timeBasedFileNamingAndTriggeringPolicy>
|
||||
<!--日志文档保留天数-->
|
||||
<maxHistory>${maxHistory}</maxHistory>
|
||||
</rollingPolicy>
|
||||
<!-- 此日志文档只记录debug级别的 -->
|
||||
<filter class="ch.qos.logback.classic.filter.LevelFilter">
|
||||
<level>debug</level>
|
||||
<onMatch>ACCEPT</onMatch>
|
||||
<onMismatch>DENY</onMismatch>
|
||||
</filter>
|
||||
</appender>
|
||||
|
||||
<!-- 2.2 level为 INFO 日志,时间滚动输出 -->
|
||||
<appender name="INFO_FILE" class="ch.qos.logback.core.rolling.RollingFileAppender">
|
||||
<!-- 正在记录的日志文档的路径及文档名 -->
|
||||
<file>${log.path}/web_info.log</file>
|
||||
<!--日志文档输出格式-->
|
||||
<encoder>
|
||||
<pattern>%d{yyyy-MM-dd HH:mm:ss.SSS} [%thread] %-5level %logger{50} - %msg%n</pattern>
|
||||
<charset>UTF-8</charset>
|
||||
</encoder>
|
||||
<!-- 日志记录器的滚动策略,按日期,按大小记录 -->
|
||||
<rollingPolicy class="ch.qos.logback.core.rolling.TimeBasedRollingPolicy">
|
||||
<!-- 每天日志归档路径以及格式 -->
|
||||
<fileNamePattern>${log.path}/web-info-%d{yyyy-MM-dd}.%i.log</fileNamePattern>
|
||||
<timeBasedFileNamingAndTriggeringPolicy class="ch.qos.logback.core.rolling.SizeAndTimeBasedFNATP">
|
||||
<maxFileSize>${maxFileSize}</maxFileSize>
|
||||
</timeBasedFileNamingAndTriggeringPolicy>
|
||||
<!--日志文档保留天数-->
|
||||
<maxHistory>${maxHistory}</maxHistory>
|
||||
</rollingPolicy>
|
||||
<!-- 此日志文档只记录info级别的 -->
|
||||
<filter class="ch.qos.logback.classic.filter.LevelFilter">
|
||||
<level>info</level>
|
||||
<onMatch>ACCEPT</onMatch>
|
||||
<onMismatch>DENY</onMismatch>
|
||||
</filter>
|
||||
</appender>
|
||||
|
||||
<!-- 2.3 level为 WARN 日志,时间滚动输出 -->
|
||||
<appender name="WARN_FILE" class="ch.qos.logback.core.rolling.RollingFileAppender">
|
||||
<!-- 正在记录的日志文档的路径及文档名 -->
|
||||
<file>${log.path}/web_warn.log</file>
|
||||
<!--日志文档输出格式-->
|
||||
<encoder>
|
||||
<pattern>%d{yyyy-MM-dd HH:mm:ss.SSS} [%thread] %-5level %logger{50} - %msg%n</pattern>
|
||||
<charset>UTF-8</charset> <!-- 此处设置字符集 -->
|
||||
</encoder>
|
||||
<!-- 日志记录器的滚动策略,按日期,按大小记录 -->
|
||||
<rollingPolicy class="ch.qos.logback.core.rolling.TimeBasedRollingPolicy">
|
||||
<fileNamePattern>${log.path}/web-warn-%d{yyyy-MM-dd}.%i.log</fileNamePattern>
|
||||
<timeBasedFileNamingAndTriggeringPolicy class="ch.qos.logback.core.rolling.SizeAndTimeBasedFNATP">
|
||||
<maxFileSize>${maxFileSize}</maxFileSize>
|
||||
</timeBasedFileNamingAndTriggeringPolicy>
|
||||
<!--日志文档保留天数-->
|
||||
<maxHistory>${maxHistory}</maxHistory>
|
||||
</rollingPolicy>
|
||||
<!-- 此日志文档只记录warn级别的 -->
|
||||
<filter class="ch.qos.logback.classic.filter.LevelFilter">
|
||||
<level>warn</level>
|
||||
<onMatch>ACCEPT</onMatch>
|
||||
<onMismatch>DENY</onMismatch>
|
||||
</filter>
|
||||
</appender>
|
||||
|
||||
<!-- 2.4 level为 ERROR 日志,时间滚动输出 -->
|
||||
<appender name="ERROR_FILE" class="ch.qos.logback.core.rolling.RollingFileAppender">
|
||||
<!-- 正在记录的日志文档的路径及文档名 -->
|
||||
<file>${log.path}/web_error.log</file>
|
||||
<!--日志文档输出格式-->
|
||||
<encoder>
|
||||
<pattern>%d{yyyy-MM-dd HH:mm:ss.SSS} [%thread] %-5level %logger{50} - %msg%n</pattern>
|
||||
<charset>UTF-8</charset> <!-- 此处设置字符集 -->
|
||||
</encoder>
|
||||
<!-- 日志记录器的滚动策略,按日期,按大小记录 -->
|
||||
<rollingPolicy class="ch.qos.logback.core.rolling.TimeBasedRollingPolicy">
|
||||
<fileNamePattern>${log.path}/web-error-%d{yyyy-MM-dd}.%i.log</fileNamePattern>
|
||||
<timeBasedFileNamingAndTriggeringPolicy class="ch.qos.logback.core.rolling.SizeAndTimeBasedFNATP">
|
||||
<maxFileSize>${maxFileSize}</maxFileSize>
|
||||
</timeBasedFileNamingAndTriggeringPolicy>
|
||||
<!--日志文档保留天数-->
|
||||
<maxHistory>${maxHistory}</maxHistory>
|
||||
</rollingPolicy>
|
||||
<!-- 此日志文档只记录ERROR级别的 -->
|
||||
<filter class="ch.qos.logback.classic.filter.LevelFilter">
|
||||
<level>ERROR</level>
|
||||
<onMatch>ACCEPT</onMatch>
|
||||
<onMismatch>DENY</onMismatch>
|
||||
</filter>
|
||||
</appender>
|
||||
|
||||
<!--
|
||||
<logger>用来设置某一个包或者具体的某一个类的日志打印级别、以及指定<appender>。<logger>仅有一个name属性, 一个可选的level和一个可选的addtivity属性。
|
||||
name:用来指定受此logger约束的某一个包或者具体的某一个类。
|
||||
level:用来设置打印级别,大小写无关:TRACE, DEBUG, INFO, WARN, ERROR, ALL 和 OFF,
|
||||
还有一个特俗值INHERITED或者同义词NULL,代表强制执行上级的级别。
|
||||
如果未设置此属性,那么当前logger将会继承上级的级别。
|
||||
addtivity:是否向上级logger传递打印信息。默认是true。
|
||||
|
||||
<logger name="org.springframework.web" level="info"/>
|
||||
<logger name="org.springframework.scheduling.annotation.ScheduledAnnotationBeanPostProcessor" level="INFO"/>
|
||||
-->
|
||||
|
||||
<!--
|
||||
使用mybatis的时候,sql语句是debug下才会打印,而这里我们只配置了info,所以想要查看sql语句的话,有以下两种操作:
|
||||
第一种把<root level="info">改成<root level="DEBUG">这样就会打印sql,不过这样日志那边会出现很多其他消息
|
||||
第二种就是单独给dao下目录配置debug模式,代码如下,这样配置sql语句会打印,其他还是正常info级别:
|
||||
|
||||
【logging.level.org.mybatis=debug logging.level.dao=debug】
|
||||
-->
|
||||
<logger name="_org.springframework" level="warn"/>
|
||||
<logger name="org.springframework" level="warn"/>
|
||||
<logger name="com.baomidou" level="warn"/>
|
||||
<logger name="org.mybatis.spring" level="error"/>
|
||||
<logger name="org.apache.ibatis" level="warn"/>
|
||||
<logger name="org.apache.http" level="error"/>
|
||||
<logger name="io.lettuce.core" level="error" additivity="false"/>
|
||||
<logger name="springfox.bean" level="error" additivity="false"/>
|
||||
<logger name="springfox.documentation" level="error" additivity="false"/>
|
||||
<logger name="org.hibernate.validator" level="error" additivity="false"/>
|
||||
<logger name="io.netty" level="error" additivity="false"/>
|
||||
<logger name="com.alibaba.druid" level="error" additivity="false"/>
|
||||
<logger name="com.corundumstudio.socketio" level="error" additivity="false"/>
|
||||
<logger name="org.mongodb.driver" level="error" additivity="false"/>
|
||||
<logger name="org.tio" level="warn"/>
|
||||
<logger name="org.apache.kafka" level="error"/>
|
||||
<logger name="Validator" level="error"/>
|
||||
<logger name="com.whdc.zhzmkzapi.tio" level="warn"/>
|
||||
<logger name="com.whdc.zhzmkzv2.config.MQTTConfig" level="error"/>
|
||||
<logger name="com.whdc.zhzmkzv2.mapper" level="error"/>
|
||||
<logger name="org.apache.poi" level="error"/>
|
||||
<logger name="com.alibaba.excel" level="error"/>
|
||||
<!--
|
||||
root节点是必选节点,用来指定最基础的日志输出级别,只有一个level属性
|
||||
level:用来设置打印级别,大小写无关:TRACE, DEBUG, INFO, WARN, ERROR, ALL 和 OFF,不能设置为INHERITED或者同义词NULL。默认是DEBUG
|
||||
,标识这个appender将会添加到这个logger。
|
||||
-->
|
||||
<root level="debug">
|
||||
<appender-ref ref="CONSOLE"/>
|
||||
<appender-ref ref="DEBUG_FILE"/>
|
||||
<appender-ref ref="INFO_FILE"/>
|
||||
<appender-ref ref="WARN_FILE"/>
|
||||
<appender-ref ref="ERROR_FILE"/>
|
||||
</root>
|
||||
</configuration>
|
||||
Binary file not shown.
Loading…
Reference in New Issue