添加设备注册接口

This commit is contained in:
wulin 2023-09-18 16:30:10 +08:00
parent 529cd08917
commit 9667a831df
21 changed files with 3785 additions and 31 deletions

View File

@ -10,33 +10,36 @@ package com.qiuguo.iot.base.enums;
//17闭门器
// 1000秋果box android配置App 1001秋果Box iOS配置App
public enum DeviceTypeEnum {
GUO_BOX(0, "果box"),
ELECTRIC_SOCKET(1, "智能插座"),
BIG_LIGHT(2, "智能大灯"),
CURTAIN_DRIVE(3, "智能窗帘驱动"),
WINDOW_DRIVE(4, "智能窗户关闭"),
DESK_LAMP(5, "智能台灯"),
DESK(6, "智能桌子"),
SEAT(7, "智能椅子"),
ELECTRIC_FAN(8, "智能风扇"),
AIR_CONDITIONING_CONTROL(9, "智能空调(遥控器)"),
ICEBOX(10, "智能冰箱"),
DISHWASHER(11, "智能洗碗机"),
ELECTRIC_WATER(12, "智能电热水器"),
TEMPERATURE_SENSOR(13, "温度传感器"),
AIR_QUALITY_SENSOR(14, "空气质量传感器"),
LIGHT_SENSOR(15, "光线传感器"),
RAIN_SENSOR(16, "雨量传感器"),
DOOR_CLOSER(17, "闭门器"),
BOX_ANDROID_SET_APP(1000, "秋果Android设置App"),
BOX_IOS_SET_APP(1001, "秋果iOS设置App"),
GUO_BOX(0, "果box", "BOX"),
ELECTRIC_SOCKET(1, "智能插座", "SOC"),
BIG_LIGHT(2, "智能大灯", "BIL"),
CURTAIN_DRIVE(3, "智能窗帘驱动", "CUR"),
WINDOW_DRIVE(4, "智能窗户关闭", "WIN"),
DESK_LAMP(5, "智能台灯", "DEL"),
DESK(6, "智能桌子", "DES"),
SEAT(7, "智能椅子", "SEA"),
ELECTRIC_FAN(8, "智能风扇", "FAN"),
AIR_CONDITIONING_CONTROL(9, "智能空调(遥控器)", "CON"),
ICEBOX(10, "智能冰箱", "ICE"),
DISHWASHER(11, "智能洗碗机", "DIS"),
ELECTRIC_WATER(12, "智能电热水器", "EWT"),
TEMPERATURE_SENSOR(13, "温度传感器", "TEP"),
AIR_QUALITY_SENSOR(14, "空气质量传感器", "AIR"),
LIGHT_SENSOR(15, "光线传感器", "LSE"),
RAIN_SENSOR(16, "雨量传感器", "RAI"),
DOOR_CLOSER(17, "闭门器", "DCL"),
BOX_ANDROID_SET_APP(1000, "秋果Android设置App", "AAP"),
BOX_IOS_SET_APP(1001, "秋果iOS设置App", "AIP"),
;
DeviceTypeEnum(Integer c, String n){
DeviceTypeEnum(Integer c, String n, String s){
code = c;
name = n;
sn = s;
}
private Integer code;
private String name;
private String sn;//序列号中间字母QGBOX
public Integer getCode() {
return code;
}
@ -45,6 +48,10 @@ public enum DeviceTypeEnum {
return name;
}
public String getSn() {
return sn;
}
public static DeviceTypeEnum getEnumWithCode(Integer c){
for (DeviceTypeEnum e:values()
) {

View File

@ -1,4 +1,24 @@
package com.qiuguo.iot.base.utils;
public class StringUtils {
import java.util.Random;
public class StringUtils{
private static final String chars = "0123456789abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ";
/**
* 获取随机字符串 0-9, a-z, A-Z
* @param length 个数
* @return String
*/
public static String getRandomStr(int length) {
if (length <= 3) {
length = 3;
}
StringBuilder sb = new StringBuilder();
int charsLen = chars.length();
Random random = new Random();
for (int i = 0; i < length; i++) {
sb.append(chars.charAt(random.nextInt(charsLen)));
}
return sb.toString();
}
}

View File

@ -45,6 +45,14 @@ public class DeviceInfoEntity extends GenericEntity<Long> {
@Column(name = "sn", length = 100, nullable = false)
private String sn;
@Comment("设备密钥")
@Column(name = "key", length = 100, nullable = false)
private String key;
@Comment("设备状态0开启1待机、关闭在线")
@Column(name = "status", length = 5, nullable = false)
private Integer status;
@Comment("蓝牙地址")
@Column(name = "bt_mac", length = 50)
private String btMac;

View File

@ -1,5 +1,8 @@
package com.qiuguo.iot.data.request.device;
import lombok.Data;
import org.hswebframework.ezorm.rdb.mapping.annotation.Comment;
import javax.persistence.Column;
import java.util.Date;
/**
* <p>
@ -42,6 +45,11 @@ public class DeviceInfoRequest implements java.io.Serializable {
private String name;
//设备序列号
private String sn;
//设备密钥
private String key;
//设备状态0开启1待机关闭在线
private Integer status;
//蓝牙地址
private String btMac;
//wifi地址

View File

@ -18,6 +18,11 @@ public class DeviceInfoResp {
private String name;
//设备序列号
private String sn;
//设备密钥
private String key;
//设备状态0开启1待机关闭在线
private Integer status;
//蓝牙地址
private String btMac;
//wifi地址

View File

@ -53,6 +53,12 @@ public class DeviceInfoService extends GenericReactiveCrudService<DeviceInfoEnti
if(StringUtils.isNotEmpty(request.getSn())){
reactiveQuery = reactiveQuery.and(DeviceInfoRequest::getSn, request.getSn());
}
if(StringUtils.isNotEmpty(request.getKey())){
reactiveQuery = reactiveQuery.and(DeviceInfoRequest::getKey, request.getKey());
}
if(request.getStatus() != null){
reactiveQuery = reactiveQuery.and(DeviceInfoRequest::getStatus, request.getStatus());
}
if(StringUtils.isNotEmpty(request.getBtMac())){
reactiveQuery = reactiveQuery.and(DeviceInfoRequest::getBtMac, request.getBtMac());
}

View File

@ -102,12 +102,6 @@ public class DemoController {
return lacNlp.geSingletNlp(value);
}
@GetMapping("/nlp/jieba")
public Mono<Nlp> getJieBaNlp(@RequestParam String value){
JieBaNlp lacNlp = new JieBaNlp();
return lacNlp.geSingletNlp(value);
}
@GetMapping("/nlps")
public Mono<List<Nlp>> getNlp(){
List<String> values = new ArrayList<>();// {"", ""};

View File

@ -54,7 +54,37 @@
<artifactId>commons</artifactId>
<version>1.0.0</version>
</dependency>
<dependency>
<groupId>com.qiuguo.iot</groupId>
<artifactId>iot-data</artifactId>
<version>0.0.1-SNAPSHOT</version>
</dependency>
<dependency>
<groupId>com.qiuguo.iot</groupId>
<artifactId>iot-base</artifactId>
<version>0.0.1-SNAPSHOT</version>
<scope>compile</scope>
</dependency>
<dependency>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-data-r2dbc</artifactId>
<version>${spring.boot.version}</version>
</dependency>
<dependency>
<groupId>dev.miku</groupId>
<artifactId>r2dbc-mysql</artifactId>
<version>0.8.2.RELEASE</version>
</dependency>
<dependency>
<groupId>io.r2dbc</groupId>
<artifactId>r2dbc-bom</artifactId>
<version>${r2dbc.version}</version>
<type>pom</type>
<scope>import</scope>
</dependency>
</dependencies>
<build>

View File

@ -1,9 +1,11 @@
package com.qiuguo.iot.user.api;
import org.hswebframework.web.crud.annotation.EnableEasyormRepository;
import org.springframework.boot.SpringApplication;
import org.springframework.boot.autoconfigure.SpringBootApplication;
@SpringBootApplication
@SpringBootApplication(scanBasePackages = {"com.qiuguo.iot.user.api", "com.qiuguo.iot.data.service"})
@EnableEasyormRepository(value = "com.qiuguo.iot.data.entity.*")
public class IotBoxUserApiApplication {
public static void main(String[] args) {

View File

@ -0,0 +1,91 @@
package com.qiuguo.iot.user.api.controller.device;
import cn.hutool.crypto.digest.MD5;
import com.qiuguo.iot.base.enums.DeviceTypeEnum;
import com.qiuguo.iot.base.utils.StringUtils;
import com.qiuguo.iot.data.entity.device.DeviceInfoEntity;
import com.qiuguo.iot.data.request.device.DeviceInfoRequest;
import com.qiuguo.iot.data.resp.device.DeviceInfoResp;
import com.qiuguo.iot.data.service.device.DeviceBatchService;
import com.qiuguo.iot.data.service.device.DeviceInfoService;
import com.qiuguo.iot.user.api.resp.device.DeviceInitResp;
import lombok.extern.slf4j.Slf4j;
import org.hswebframework.web.exception.BusinessException;
import org.springframework.beans.factory.annotation.Value;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestParam;
import org.springframework.web.bind.annotation.RestController;
import reactor.core.publisher.Mono;
import javax.annotation.Resource;
import java.time.LocalDateTime;
import java.time.format.DateTimeFormatter;
@RestController
@Slf4j
@RequestMapping("/device")
public class DeviceController {
@Value("${device.key}")
private String key;
@Value("${device.checkTimeout}")
private Boolean checkTimeout;
@Resource
private DeviceInfoService deviceInfoService;
@Resource
private DeviceBatchService deviceBatchService;
private static Long timeOut = 120000l;//2分钟
// @GetMapping("/init")
// public Mono<DeviceInitResp> deviceInit(@RequestParam String wifiMac, @RequestParam String btMac,
// @RequestParam Integer type, @RequestParam Long time,
// @RequestParam String signature){
// Long now = System.currentTimeMillis();
// if(checkTimeout && now - time > timeOut){
// //超时
// BusinessException ex = new BusinessException("请求已失效");
// return Mono.error(ex);
// }
// //设备类型是否匹配暂时不做限制
// //验签
// String wifiMd5 = MD5.create().digestHex(wifiMac).toLowerCase();
// String btMd5 = MD5.create().digestHex(btMac).toLowerCase();
// String md5 = MD5.create().digestHex(wifiMd5 + btMd5 + type + time + key).toLowerCase();
// if (md5.equals(signature)) {
// //
// DeviceInfoRequest request = new DeviceInfoRequest();
// request.setWifiMac(wifiMac);
// request.setBtMac(btMac);
// Mono<DeviceInfoEntity> mono = deviceInfoService.selectDeviceInfoByRequest(request);
// return mono.flatMap(d -> {
// Mono o = null;
// if(d == null){
// DeviceTypeEnum entryTypeEnum = DeviceTypeEnum.getEnumWithCode(type);
// d = new DeviceInfoEntity();
// d.setWifiMac(wifiMac);
// d.setBtMac(btMac);
// d.setDeviceType(type);
// d.setKey( com.qiuguo.iot.base.utils.StringUtils.getRandomStr(10));//生成key
// DateTimeFormatter df = DateTimeFormatter.ofPattern("yyMMddHHmmss");
// d.setSn("QG" + entryTypeEnum.getSn() +df.format(LocalDateTime.now()) + StringUtils.getRandomStr(3));
// o = deviceInfoService.insertDeviceInfo(d);
// }else{
// d.setKey( com.qiuguo.iot.base.utils.StringUtils.getRandomStr(10));//重新生成Key
// o = deviceInfoService.updateDeviceInfoById(d);
// }
// final DeviceInfoEntity entity = d;
// DeviceInitResp resp = new DeviceInitResp();
// resp.setSn(entity.getSn());
// resp.setKey(entity.getKey());
// return resp;
//
//
// });
// }
// //验签失败
// BusinessException ex = new BusinessException("验签失败");
// return Mono.error(ex);
//
// }
}

View File

@ -0,0 +1,76 @@
package com.qiuguo.iot.user.api.filter;
import lombok.extern.slf4j.Slf4j;
import org.reactivestreams.Subscription;
import org.slf4j.MDC;
import org.springframework.context.annotation.Configuration;
import reactor.core.CoreSubscriber;
import reactor.core.publisher.Hooks;
import reactor.core.publisher.Operators;
import reactor.util.context.Context;
import javax.annotation.PostConstruct;
import javax.annotation.PreDestroy;
/**
* <p>
* </p>*日志上下文切换配置
* @author wulin
* @since 2023-08-07
*/
@Configuration
@Slf4j
public class LogMdcConfiguration {
public static String PRINT_LOG_ID = "logid";
@PostConstruct
public void contextOperatorHook() {
Hooks.onEachOperator(PRINT_LOG_ID, Operators.lift((r, c) ->{
Context ctx = c.currentContext();
if(ctx.hasKey(PRINT_LOG_ID)){
MDC.put(PRINT_LOG_ID, ctx.get(PRINT_LOG_ID));
}
return new MdcContextSubscriber(c);
}));
}
@PreDestroy
public void cleanupHook() {
Hooks.resetOnEachOperator(PRINT_LOG_ID);
}
class MdcContextSubscriber<T> implements CoreSubscriber<T> {
private CoreSubscriber<T> coreSubscriber;
public MdcContextSubscriber(CoreSubscriber<T> c){
coreSubscriber = c;
}
@Override
public void onComplete() {
coreSubscriber.onComplete();
MDC.remove(PRINT_LOG_ID);
}
@Override
public void onError(Throwable throwable) {
coreSubscriber.onError(throwable);
MDC.remove(PRINT_LOG_ID);
}
@Override
public void onSubscribe(Subscription subscription) {
coreSubscriber.onSubscribe(subscription);
}
@Override
public void onNext(T t) {
coreSubscriber.onNext(t);
}
@Override
public Context currentContext() {
return coreSubscriber.currentContext();
}
}
}

View File

@ -0,0 +1,118 @@
package com.qiuguo.iot.user.api.filter;
import lombok.extern.slf4j.Slf4j;
import org.hswebframework.web.logger.ReactiveLogger;
import org.reactivestreams.Publisher;
import org.slf4j.MDC;
import org.springframework.context.annotation.Configuration;
import org.springframework.core.io.buffer.DataBuffer;
import org.springframework.core.io.buffer.DataBufferFactory;
import org.springframework.core.io.buffer.DataBufferUtils;
import org.springframework.core.io.buffer.DefaultDataBufferFactory;
import org.springframework.http.HttpMethod;
import org.springframework.http.server.reactive.ServerHttpRequest;
import org.springframework.http.server.reactive.ServerHttpRequestDecorator;
import org.springframework.http.server.reactive.ServerHttpResponse;
import org.springframework.http.server.reactive.ServerHttpResponseDecorator;
import org.springframework.web.server.ServerWebExchange;
import org.springframework.web.server.WebFilter;
import org.springframework.web.server.WebFilterChain;
import reactor.core.publisher.Flux;
import reactor.core.publisher.Mono;
import reactor.util.context.Context;
import java.nio.charset.StandardCharsets;
/**
* <p>
* </p>*日志配置
* @author wulin
* @since 2023-08-07
*/
@Configuration
@Slf4j
public class LogWebFilter implements WebFilter {
private static final String CONTEXT_KEY = ReactiveLogger.class.getName();
@Override
public Mono<Void> filter(ServerWebExchange exchange, WebFilterChain chain) {
long startTime = System.currentTimeMillis();
ServerHttpRequest request = exchange.getRequest();
String requestId = request.getId();
MDC.put(LogMdcConfiguration.PRINT_LOG_ID, requestId);
String ip = request.getRemoteAddress().getAddress().getHostAddress();//.getHostName();
String m = request.getMethod().toString();
log.info("api start time:{} ip:{} method:{} url:{} param:{} headers:{}",
startTime,
ip,
m,
request.getPath(),
request.getQueryParams(),
request.getHeaders());
ServerWebExchange.Builder ex = exchange.mutate();
ex.response(getResponse(exchange, requestId));
if(!request.getMethod().equals(HttpMethod.GET) && !request.getMethod().equals(HttpMethod.DELETE)){
ex.request(getRequest(exchange));
}
return chain.filter(ex.build())
.contextWrite(context -> {
Context contextTmp = context.put(LogMdcConfiguration.PRINT_LOG_ID, requestId);
return contextTmp;
})
.doFinally(signalType -> {
long endTime = System.currentTimeMillis();
MDC.put(LogMdcConfiguration.PRINT_LOG_ID, requestId);
log.info("api end time:{}, total time:{}", endTime, endTime - startTime);
MDC.remove(LogMdcConfiguration.PRINT_LOG_ID);
});
}
private ServerHttpRequest getRequest(ServerWebExchange exchange){
ServerHttpRequest request = exchange.getRequest();
return new ServerHttpRequestDecorator(request){
@Override
public Flux<DataBuffer> getBody() {
Flux<DataBuffer> body = this.getDelegate().getBody();
return body.map(dataBuffer -> {
log.info("request:{}", dataBuffer.toString(StandardCharsets.UTF_8));
return dataBuffer;
});
}
};
}
private ServerHttpResponse getResponse(ServerWebExchange exchange, String requestId){
ServerHttpResponse response = exchange.getResponse();
return new ServerHttpResponseDecorator(response){
@Override
public Mono<Void> writeWith(Publisher<? extends DataBuffer> body){
if (body instanceof Flux) {
Flux<? extends DataBuffer> fluxBody = Flux.from(body);
return super.writeWith(fluxBody.buffer().map(dataBuffers -> {
DataBufferFactory dataBufferFactory = new DefaultDataBufferFactory();
DataBuffer joinBuffer = dataBufferFactory.join(dataBuffers);
byte[] returnContent = new byte[joinBuffer.readableByteCount()];
joinBuffer.read(returnContent);
DataBufferUtils.release(joinBuffer);
String returnStr = new String(returnContent, StandardCharsets.UTF_8);
log.info("response:{}", returnStr);
return response.bufferFactory().wrap(returnContent);
}));
}else if(body instanceof Mono){
Mono<DataBuffer> monoBody = Mono.from(body);
return super.writeWith(monoBody.map(dataBuffer -> {
log.info("response:{}", dataBuffer.toString(StandardCharsets.UTF_8));
return response.bufferFactory().wrap(dataBuffer.toString(StandardCharsets.UTF_8).getBytes());
}));
}
return super.writeWith(body);
}
};
}
}

View File

@ -0,0 +1,9 @@
package com.qiuguo.iot.user.api.resp.device;
import lombok.Data;
@Data
public class DeviceInitResp {
String sn;//序列号
String key;//密钥
}

View File

@ -29,7 +29,7 @@ spring:
password: 123456
timeout: 5000
r2dbc:
url: r2dbc:mysql://172.24.218.235:3306/qiuguo-reseller?useUnicode=true&characterEncoding=utf8&zeroDateTimeBehavior=convertToNull&useSSL=true&serverTimezone=GMT%2B8
url: r2dbc:mysql://172.24.218.235:3306/qiuguo_iot?ssl=false&serverZoneId=Asia/Shanghai
username: root
password: '!pHuRvGKIsbiqcX1'
easyorm:
@ -37,15 +37,20 @@ easyorm:
default-schema: qiuguo_iot # 默认使用的schema. mysql时则为数据库名
dialect: mysql # 方言: h2,mysql,postgresql
logging:
config: classpath:logback-${spring.profiles.active}.xml
level:
org.hswebframework: debug
org.hswebframework.expands: error
com.qiuguo.iot.data: debug #可以开启sql的日志打印
hsweb:
webflux:
response-wrapper:
enabled: true # 将响应结果包装为{"status":200,"result":{}}
excludes: #不包装的类
- org.springdoc
device:
key: ZGV2aWNlX2luZm9fdG9rZW5fbWQ1LTNfb2Zpa19xaXVndW8taW90LWJveCY2Mis=
checkTimeout: false
userUrl:
baseUrl: 'https://exper.qiuguojihua.com'
pwdUrl: '/data/api.login/in'

View File

@ -0,0 +1,84 @@
<?xml version="1.0" encoding="UTF-8"?>
<configuration>
<!-- 日志存放路径 -->
<property name="log.path" value="logs/iot-user-api" />
<!-- 日志输出格式 -->
<property name="log.pattern" value="%d{yyyy-HH:mm:ss.SSS} [%thread] %-5level %logger{20} - [%method,%line] [%X{logid}]- %msg%n" />
<!-- 控制台输出 -->
<appender name="STDOUT" class="ch.qos.logback.core.ConsoleAppender">
<encoder>
<pattern>${log.pattern}</pattern>
<charset>UTF-8</charset> <!-- 设置字符集 -->
</encoder>
</appender>
<!-- 系统日志输出 -->
<appender name="file_info" class="ch.qos.logback.core.rolling.RollingFileAppender">
<file>${log.path}/info.log</file>
<!-- 循环政策:基于时间创建日志文件 -->
<rollingPolicy class="ch.qos.logback.core.rolling.TimeBasedRollingPolicy">
<!-- 日志文件名格式 -->
<fileNamePattern>${log.path}/info.%d{yyyy-MM-dd}.log</fileNamePattern>
<!-- 日志最大的历史 60天 -->
<maxHistory>60</maxHistory>
</rollingPolicy>
<encoder>
<pattern>${log.pattern}</pattern>
<charset>UTF-8</charset> <!-- 设置字符集 -->
</encoder>
<filter class="ch.qos.logback.classic.filter.LevelFilter">
<!-- 过滤的级别 -->
<level>INFO</level>
</filter>
</appender>
<!-- 系统日志输出 -->
<appender name="file_warn" class="ch.qos.logback.core.rolling.RollingFileAppender">
<file>${log.path}/warn.log</file>
<!-- 循环政策:基于时间创建日志文件 -->
<rollingPolicy class="ch.qos.logback.core.rolling.TimeBasedRollingPolicy">
<!-- 日志文件名格式 -->
<fileNamePattern>${log.path}/wran.%d{yyyy-MM-dd}.log</fileNamePattern>
<!-- 日志最大的历史 60天 -->
<maxHistory>60</maxHistory>
</rollingPolicy>
<encoder>
<pattern>${log.pattern}</pattern>
<charset>UTF-8</charset> <!-- 设置字符集 -->
</encoder>
<filter class="ch.qos.logback.classic.filter.LevelFilter">
<!-- 过滤的级别 -->
<level>WARN</level>
</filter>
</appender>
<appender name="file_error" class="ch.qos.logback.core.rolling.RollingFileAppender">
<file>${log.path}/error.log</file>
<!-- 循环政策:基于时间创建日志文件 -->
<rollingPolicy class="ch.qos.logback.core.rolling.TimeBasedRollingPolicy">
<!-- 日志文件名格式 -->
<fileNamePattern>${log.path}/error.%d{yyyy-MM-dd}.log</fileNamePattern>
<!-- 日志最大的历史 60天 -->
<maxHistory>60</maxHistory>
</rollingPolicy>
<encoder>
<pattern>${log.pattern}</pattern>
<charset>UTF-8</charset> <!-- 设置字符集 -->
</encoder>
<filter class="ch.qos.logback.classic.filter.LevelFilter">
<!-- 过滤的级别 -->
<level>ERROR</level>
</filter>
</appender>
<!--系统操作日志-->
<root level="info">
<appender-ref ref="file_info" />
<appender-ref ref="file_error" />
<appender-ref ref="file_warn" />
<appender-ref ref="STDOUT" />
</root>
</configuration>

View File

@ -0,0 +1,84 @@
<?xml version="1.0" encoding="UTF-8"?>
<configuration>
<!-- 日志存放路径 -->
<property name="log.path" value="logs/iot-user-api" />
<!-- 日志输出格式 -->
<property name="log.pattern" value="%d{HH:mm:ss.SSS} [%thread] %-5level %logger{20} - [%method,%line] [%X{logid}]- %msg%n" />
<!-- 控制台输出 -->
<appender name="STDOUT" class="ch.qos.logback.core.ConsoleAppender">
<encoder>
<pattern>${log.pattern}</pattern>
<charset>UTF-8</charset> <!-- 设置字符集 -->
</encoder>
</appender>
<!-- 系统日志输出 -->
<appender name="file_info" class="ch.qos.logback.core.rolling.RollingFileAppender">
<file>${log.path}/info.log</file>
<!-- 循环政策:基于时间创建日志文件 -->
<rollingPolicy class="ch.qos.logback.core.rolling.TimeBasedRollingPolicy">
<!-- 日志文件名格式 -->
<fileNamePattern>${log.path}/info.%d{yyyy-MM-dd}.log</fileNamePattern>
<!-- 日志最大的历史 60天 -->
<maxHistory>60</maxHistory>
</rollingPolicy>
<encoder>
<pattern>${log.pattern}</pattern>
<charset>UTF-8</charset> <!-- 设置字符集 -->
</encoder>
<filter class="ch.qos.logback.classic.filter.LevelFilter">
<!-- 过滤的级别 -->
<level>INFO</level>
</filter>
</appender>
<!-- 系统日志输出 -->
<appender name="file_warn" class="ch.qos.logback.core.rolling.RollingFileAppender">
<file>${log.path}/warn.log</file>
<!-- 循环政策:基于时间创建日志文件 -->
<rollingPolicy class="ch.qos.logback.core.rolling.TimeBasedRollingPolicy">
<!-- 日志文件名格式 -->
<fileNamePattern>${log.path}/wran.%d{yyyy-MM-dd}.log</fileNamePattern>
<!-- 日志最大的历史 60天 -->
<maxHistory>60</maxHistory>
</rollingPolicy>
<encoder>
<pattern>${log.pattern}</pattern>
<charset>UTF-8</charset> <!-- 设置字符集 -->
</encoder>
<filter class="ch.qos.logback.classic.filter.LevelFilter">
<!-- 过滤的级别 -->
<level>WARN</level>
</filter>
</appender>
<appender name="file_error" class="ch.qos.logback.core.rolling.RollingFileAppender">
<file>${log.path}/error.log</file>
<!-- 循环政策:基于时间创建日志文件 -->
<rollingPolicy class="ch.qos.logback.core.rolling.TimeBasedRollingPolicy">
<!-- 日志文件名格式 -->
<fileNamePattern>${log.path}/error.%d{yyyy-MM-dd}.log</fileNamePattern>
<!-- 日志最大的历史 60天 -->
<maxHistory>60</maxHistory>
</rollingPolicy>
<encoder>
<pattern>${log.pattern}</pattern>
<charset>UTF-8</charset> <!-- 设置字符集 -->
</encoder>
<filter class="ch.qos.logback.classic.filter.LevelFilter">
<!-- 过滤的级别 -->
<level>ERROR</level>
</filter>
</appender>
<!--系统操作日志-->
<root level="info">
<appender-ref ref="file_info" />
<appender-ref ref="file_error" />
<appender-ref ref="file_warn" />
<appender-ref ref="STDOUT" />
</root>
</configuration>

View File

@ -0,0 +1,84 @@
<?xml version="1.0" encoding="UTF-8"?>
<configuration>
<!-- 日志存放路径 -->
<property name="log.path" value="logs/iot-user-api" />
<!-- 日志输出格式 -->
<property name="log.pattern" value="%d{HH:mm:ss.SSS} [%thread] %-5level %logger{20} - [%method,%line] [%X{logid}]- %msg%n" />
<!-- 控制台输出 -->
<appender name="STDOUT" class="ch.qos.logback.core.ConsoleAppender">
<encoder>
<pattern>${log.pattern}</pattern>
<charset>UTF-8</charset> <!-- 设置字符集 -->
</encoder>
</appender>
<!-- 系统日志输出 -->
<appender name="file_info" class="ch.qos.logback.core.rolling.RollingFileAppender">
<file>${log.path}/info.log</file>
<!-- 循环政策:基于时间创建日志文件 -->
<rollingPolicy class="ch.qos.logback.core.rolling.TimeBasedRollingPolicy">
<!-- 日志文件名格式 -->
<fileNamePattern>${log.path}/info.%d{yyyy-MM-dd}.log</fileNamePattern>
<!-- 日志最大的历史 60天 -->
<maxHistory>60</maxHistory>
</rollingPolicy>
<encoder>
<pattern>${log.pattern}</pattern>
<charset>UTF-8</charset> <!-- 设置字符集 -->
</encoder>
<filter class="ch.qos.logback.classic.filter.LevelFilter">
<!-- 过滤的级别 -->
<level>INFO</level>
</filter>
</appender>
<!-- 系统日志输出 -->
<appender name="file_warn" class="ch.qos.logback.core.rolling.RollingFileAppender">
<file>${log.path}/warn.log</file>
<!-- 循环政策:基于时间创建日志文件 -->
<rollingPolicy class="ch.qos.logback.core.rolling.TimeBasedRollingPolicy">
<!-- 日志文件名格式 -->
<fileNamePattern>${log.path}/wran.%d{yyyy-MM-dd}.log</fileNamePattern>
<!-- 日志最大的历史 60天 -->
<maxHistory>60</maxHistory>
</rollingPolicy>
<encoder>
<pattern>${log.pattern}</pattern>
<charset>UTF-8</charset> <!-- 设置字符集 -->
</encoder>
<filter class="ch.qos.logback.classic.filter.LevelFilter">
<!-- 过滤的级别 -->
<level>WARN</level>
</filter>
</appender>
<appender name="file_error" class="ch.qos.logback.core.rolling.RollingFileAppender">
<file>${log.path}/error.log</file>
<!-- 循环政策:基于时间创建日志文件 -->
<rollingPolicy class="ch.qos.logback.core.rolling.TimeBasedRollingPolicy">
<!-- 日志文件名格式 -->
<fileNamePattern>${log.path}/error.%d{yyyy-MM-dd}.log</fileNamePattern>
<!-- 日志最大的历史 60天 -->
<maxHistory>60</maxHistory>
</rollingPolicy>
<encoder>
<pattern>${log.pattern}</pattern>
<charset>UTF-8</charset> <!-- 设置字符集 -->
</encoder>
<filter class="ch.qos.logback.classic.filter.LevelFilter">
<!-- 过滤的级别 -->
<level>ERROR</level>
</filter>
</appender>
<!--系统操作日志-->
<root level="info">
<appender-ref ref="file_info" />
<appender-ref ref="file_error" />
<appender-ref ref="file_warn" />
<appender-ref ref="STDOUT" />
</root>
</configuration>

View File

@ -46,6 +46,6 @@ logging:
org.hswebframework.expands: error
com.qiuguo.iot.data: debug #可以开启sql的日志打印
device:
tokenkey: ZGV2aWNlX2luZm9fdG9rZW5fbWQ1LTNfb2Zpa19xaXVndW8taW90LWJveCY2Mis=
key: ZGV2aWNlX2luZm9fdG9rZW5fbWQ1LTNfb2Zpa19xaXVndW8taW90LWJveCY2Mis=
lac: #lac服务地址
url: http://127.0.0.1:8866

1041
logs/iot-user-api/error.log Normal file

File diff suppressed because it is too large Load Diff

1041
logs/iot-user-api/info.log Normal file

File diff suppressed because it is too large Load Diff

1041
logs/iot-user-api/warn.log Normal file

File diff suppressed because it is too large Load Diff