代码更新
This commit is contained in:
@@ -1,19 +0,0 @@
|
||||
package org.nl.modules.cache;
|
||||
|
||||
import com.alicp.jetcache.Cache;
|
||||
import com.alicp.jetcache.anno.CacheType;
|
||||
import com.alicp.jetcache.anno.CreateCache;
|
||||
import lombok.Data;
|
||||
|
||||
@Data
|
||||
public class BothCacheManager extends NlCacheManager {
|
||||
/**
|
||||
* 使用 @CreateCache 注解创建Cache实例;
|
||||
* 未定义默认值的参数,将使用yml中指定的全局配置;
|
||||
* 缓存在 Local,也可以配置成 both 开启两级缓存
|
||||
*/
|
||||
@CreateCache(expire = 5 * 60, cacheType = CacheType.BOTH, localLimit = 10)
|
||||
private Cache<Object, Object> defaultCache;
|
||||
@CreateCache(expire = 5 * 60, cacheType = CacheType.BOTH, localLimit = 10)
|
||||
private Cache<Object, Object> systemCache;
|
||||
}
|
||||
@@ -1,23 +0,0 @@
|
||||
package org.nl.modules.cache;
|
||||
|
||||
import com.alicp.jetcache.anno.CacheConsts;
|
||||
import com.alicp.jetcache.anno.CacheType;
|
||||
import org.springframework.beans.factory.annotation.Value;
|
||||
import org.springframework.context.annotation.Bean;
|
||||
import org.springframework.context.annotation.Configuration;
|
||||
|
||||
@Configuration
|
||||
public class CacheConfig {
|
||||
@Value("${jetcache.defaultCacheType}")
|
||||
private String cacheType;
|
||||
|
||||
@Bean(name = "sysCacheManager")
|
||||
public NlCacheManager sysCacheManager() {
|
||||
CacheConsts.isUndefined(2);
|
||||
if (CacheType.BOTH.name().equals(cacheType)) return new BothCacheManager();
|
||||
if (CacheType.LOCAL.name().equals(cacheType)) return new LocalCacheManager();
|
||||
if (CacheType.REMOTE.name().equals(cacheType)) return new RemoteCacheManager();
|
||||
return new LocalCacheManager();
|
||||
}
|
||||
|
||||
}
|
||||
@@ -1,19 +0,0 @@
|
||||
package org.nl.modules.cache;
|
||||
|
||||
import com.alicp.jetcache.Cache;
|
||||
import com.alicp.jetcache.anno.CacheType;
|
||||
import com.alicp.jetcache.anno.CreateCache;
|
||||
import lombok.Data;
|
||||
|
||||
@Data
|
||||
public class LocalCacheManager extends NlCacheManager {
|
||||
/**
|
||||
* 使用 @CreateCache 注解创建Cache实例;
|
||||
* 未定义默认值的参数,将使用yml中指定的全局配置;
|
||||
* 缓存在 Local,也可以配置成 both 开启两级缓存
|
||||
*/
|
||||
@CreateCache(expire = 5 * 60, cacheType = CacheType.LOCAL, localLimit = 10)
|
||||
private Cache<Object, Object> defaultCache;
|
||||
@CreateCache(expire = 5 * 60, cacheType = CacheType.LOCAL, localLimit = 10)
|
||||
private Cache<Object, Object> systemCache;
|
||||
}
|
||||
@@ -1,13 +0,0 @@
|
||||
package org.nl.modules.cache;
|
||||
|
||||
import com.alicp.jetcache.Cache;
|
||||
import lombok.Data;
|
||||
|
||||
@Data
|
||||
public abstract class NlCacheManager {
|
||||
private Cache<Object, Object> defaultCache;
|
||||
private Cache<Object, Object> systemCache;
|
||||
public void test(){
|
||||
System.out.println(this.getClass().getName());
|
||||
}
|
||||
}
|
||||
@@ -1,24 +0,0 @@
|
||||
package org.nl.modules.cache;
|
||||
|
||||
import com.alicp.jetcache.Cache;
|
||||
import com.alicp.jetcache.anno.CacheType;
|
||||
import com.alicp.jetcache.anno.CreateCache;
|
||||
import lombok.Data;
|
||||
|
||||
@Data
|
||||
public class RemoteCacheManager extends NlCacheManager {
|
||||
/**
|
||||
* 使用 @CreateCache 注解创建Cache实例;
|
||||
* 未定义默认值的参数,将使用yml中指定的全局配置;
|
||||
* 缓存在 Local,也可以配置成 both 开启两级缓存
|
||||
*/
|
||||
@CreateCache(expire = 5 * 60, cacheType = CacheType.REMOTE, localLimit = 10)
|
||||
private Cache<Object, Object> defaultCache;
|
||||
@CreateCache(expire = 5 * 60, cacheType = CacheType.REMOTE, localLimit = 10)
|
||||
private Cache<Object, Object> systemCache;
|
||||
|
||||
@Override
|
||||
public void test() {
|
||||
System.out.println(this.getClass().getName());
|
||||
}
|
||||
}
|
||||
@@ -1,54 +0,0 @@
|
||||
package org.nl.modules.log;
|
||||
|
||||
import ch.qos.logback.classic.spi.ILoggingEvent;
|
||||
import ch.qos.logback.core.UnsynchronizedAppenderBase;
|
||||
import cn.hutool.core.util.ObjectUtil;
|
||||
import com.mongodb.BasicDBObject;
|
||||
import lombok.Data;
|
||||
import org.nl.utils.SpringContextHolder;
|
||||
import org.slf4j.Marker;
|
||||
import org.springframework.data.mongodb.core.MongoTemplate;
|
||||
|
||||
import java.net.InetAddress;
|
||||
import java.net.UnknownHostException;
|
||||
|
||||
/**
|
||||
* https://www.cnblogs.com/lzghyh/p/14913230.html
|
||||
* https://juejin.cn/post/6844903488896385037
|
||||
* https://cloud.tencent.com/developer/article/1384035
|
||||
* https://www.freesion.com/article/229560377/
|
||||
* <p>
|
||||
* https://cloud.tencent.com/developer/article/1384035
|
||||
*/
|
||||
@Data
|
||||
public class MongoDBAppenderBase<E> extends UnsynchronizedAppenderBase<ILoggingEvent> {
|
||||
|
||||
@Override
|
||||
protected void append(ILoggingEvent eventObject) {
|
||||
|
||||
MongoTemplate mongoTemplate = SpringContextHolder.getBean(MongoTemplate.class);
|
||||
|
||||
if (mongoTemplate != null) {
|
||||
final BasicDBObject doc = new BasicDBObject();
|
||||
Marker marker = eventObject.getMarker();
|
||||
if (!ObjectUtil.isEmpty(marker)) {
|
||||
doc.append("marker", marker.getName());
|
||||
} else {
|
||||
doc.append("marker", "default");
|
||||
}
|
||||
try {
|
||||
doc.append("ip", InetAddress.getLocalHost().getHostAddress());
|
||||
} catch (UnknownHostException e) {
|
||||
e.printStackTrace();
|
||||
}
|
||||
|
||||
doc.append("level", eventObject.getLevel().toString());
|
||||
doc.append("logger", eventObject.getLoggerName());
|
||||
doc.append("thread", eventObject.getThreadName());
|
||||
doc.append("message", eventObject.getFormattedMessage());
|
||||
mongoTemplate.insert(doc, "log");
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
}
|
||||
@@ -1,42 +0,0 @@
|
||||
|
||||
package org.nl.modules.log.rest;
|
||||
|
||||
|
||||
import io.swagger.annotations.Api;
|
||||
import io.swagger.annotations.ApiOperation;
|
||||
import lombok.RequiredArgsConstructor;
|
||||
import lombok.extern.slf4j.Slf4j;
|
||||
import org.nl.annotation.Log;
|
||||
import org.nl.modules.log.service.RootLogService;
|
||||
import org.springframework.data.domain.Pageable;
|
||||
import org.springframework.http.HttpStatus;
|
||||
import org.springframework.http.ResponseEntity;
|
||||
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 java.util.Map;
|
||||
|
||||
/**
|
||||
* @author ldjun
|
||||
* @date 2021-08-19
|
||||
**/
|
||||
@RestController
|
||||
@RequiredArgsConstructor
|
||||
@Api(tags = "系统日志")
|
||||
@RequestMapping("/api/rootLog")
|
||||
@Slf4j
|
||||
public class RootLogController {
|
||||
|
||||
private final RootLogService rootLogService;
|
||||
|
||||
@GetMapping
|
||||
@Log("查询系统日志")
|
||||
@ApiOperation("查询系统日志")
|
||||
//@PreAuthorize("@el.check('point:list')")
|
||||
public ResponseEntity<Object> query(@RequestParam Map whereJson, Pageable page) {
|
||||
return new ResponseEntity<>(rootLogService.queryAll(whereJson, page), HttpStatus.OK);
|
||||
}
|
||||
|
||||
}
|
||||
@@ -1,18 +0,0 @@
|
||||
package org.nl.modules.log.service;
|
||||
|
||||
import org.springframework.data.domain.Pageable;
|
||||
|
||||
import java.util.Map;
|
||||
|
||||
/**
|
||||
* 系统日志查询
|
||||
*/
|
||||
public interface RootLogService {
|
||||
/**
|
||||
* 查询数据分页
|
||||
* @param whereJson 条件
|
||||
* @param page 分页参数
|
||||
* @return Map<String,Object>
|
||||
*/
|
||||
Map<String,Object> queryAll(Map whereJson, Pageable page);
|
||||
}
|
||||
@@ -1,46 +0,0 @@
|
||||
package org.nl.modules.log.service.impl;
|
||||
|
||||
import com.alibaba.fastjson.JSONObject;
|
||||
import lombok.RequiredArgsConstructor;
|
||||
import lombok.extern.slf4j.Slf4j;
|
||||
import org.nl.modules.log.service.RootLogService;
|
||||
import org.springframework.data.domain.Pageable;
|
||||
import org.springframework.data.mongodb.core.MongoTemplate;
|
||||
import org.springframework.data.mongodb.core.query.Criteria;
|
||||
import org.springframework.data.mongodb.core.query.Query;
|
||||
import org.springframework.stereotype.Service;
|
||||
|
||||
import java.util.List;
|
||||
import java.util.Map;
|
||||
|
||||
/**
|
||||
* @author ldjun
|
||||
* @description 服务实现
|
||||
* @date 2021-08-19
|
||||
**/
|
||||
@Service
|
||||
@RequiredArgsConstructor
|
||||
@Slf4j
|
||||
public class RootLogServiceImpl implements RootLogService {
|
||||
|
||||
private final MongoTemplate mongoTemplate;
|
||||
|
||||
@Override
|
||||
public Map<String, Object> queryAll(Map whereJson, Pageable page) {
|
||||
//查询条件
|
||||
Query query = Query.query(Criteria.where("level").is("INFO"));
|
||||
|
||||
//根据条件得到的总条数
|
||||
long totalSize = mongoTemplate.count(query, Map.class, "log_root");
|
||||
|
||||
//处理分页
|
||||
query.skip(page.getPageNumber()).limit(page.getPageSize());
|
||||
List<Map> list = mongoTemplate.find(query, Map.class, "log_root");
|
||||
|
||||
//封装前端分页查询结果
|
||||
JSONObject result = new JSONObject();
|
||||
result.put("content", list);
|
||||
result.put("totalElements", totalSize);
|
||||
return result;
|
||||
}
|
||||
}
|
||||
@@ -10,7 +10,7 @@ import com.alibaba.fastjson.JSONArray;
|
||||
import com.alibaba.fastjson.JSONObject;
|
||||
import lombok.RequiredArgsConstructor;
|
||||
import lombok.extern.slf4j.Slf4j;
|
||||
import org.apache.commons.collections.MapUtils;
|
||||
import org.apache.commons.collections4.MapUtils;
|
||||
import org.nl.start.auto.initial.ApplicationAutoInitial;
|
||||
import org.nl.wms.ext.bigScreen.service.BigScreenService;
|
||||
import org.nl.wms.ext.bigScreen.service.dto.*;
|
||||
|
||||
@@ -18,11 +18,11 @@ spring:
|
||||
db-type: com.alibaba.druid.pool.DruidDataSource
|
||||
driverClassName: net.sf.log4jdbc.sql.jdbcapi.DriverSpy
|
||||
#url: jdbc:log4jdbc:mysql://${DB_HOST:localhost}:${DB_PORT:3306}/${DB_NAME:hl_one_mes}?serverTimezone=Asia/Shanghai&characterEncoding=utf8&useSSL=false&useOldAliasMetadataBehavior=true&allowPublicKeyRetrieval=true&useSSL=false
|
||||
url: jdbc:log4jdbc:mysql://${DB_HOST:127.0.0.1}:${DB_PORT:3306}/${DB_NAME:hl_one_mes}?serverTimezone=Asia/Shanghai&characterEncoding=utf8&useSSL=false&useOldAliasMetadataBehavior=true&allowPublicKeyRetrieval=true&useSSL=false
|
||||
url: jdbc:log4jdbc:mysql://${DB_HOST:192.168.81.252}:${DB_PORT:3306}/${DB_NAME:hl_one_mes}?serverTimezone=Asia/Shanghai&characterEncoding=utf8&useSSL=false&useOldAliasMetadataBehavior=true&allowPublicKeyRetrieval=true&useSSL=false
|
||||
username: ${DB_USER:root}
|
||||
#password: ${DB_PWD:P@ssw0rd}
|
||||
#password: ${DB_PWD:root}
|
||||
password: ${DB_PWD:password}
|
||||
password: ${DB_PWD:Root.123456}
|
||||
# 初始连接数
|
||||
initial-size: 5
|
||||
# 最小连接数
|
||||
|
||||
@@ -2,7 +2,7 @@ spring:
|
||||
freemarker:
|
||||
check-template-location: false
|
||||
profiles:
|
||||
active: prod
|
||||
active: dev
|
||||
jackson:
|
||||
time-zone: GMT+8
|
||||
data:
|
||||
|
||||
@@ -21,36 +21,8 @@ https://juejin.cn/post/6844903775631572999
|
||||
<appender name="CONSOLE" class="ch.qos.logback.core.ConsoleAppender">
|
||||
<encoder>
|
||||
<pattern>${log.pattern}</pattern>
|
||||
<charset>${log.charset}</charset>
|
||||
<!-- <charset>${log.charset}</charset>-->
|
||||
</encoder>
|
||||
|
||||
<!-- 转为JSON https://www.zoleet.com/details/328.html-->
|
||||
<!-- <encoder class="net.logstash.logback.encoder.LoggingEventCompositeJsonEncoder">
|
||||
<providers>
|
||||
<pattern>
|
||||
<pattern>
|
||||
{
|
||||
"appName": "logistics-core",
|
||||
"time": "%date{yyyy-MM-dd HH:mm:ss.SSS}",
|
||||
"level": "%level",
|
||||
"pid": "${PID:-}",
|
||||
"thread": "%thread",
|
||||
"class": "%logger",
|
||||
"method": "%method",
|
||||
"line": "%line",
|
||||
"message": "%message",
|
||||
"statck_trace": "%xEx"
|
||||
}
|
||||
</pattern>
|
||||
</pattern>
|
||||
</providers>
|
||||
</encoder>-->
|
||||
</appender>
|
||||
|
||||
<appender name="MONGO" class="org.nl.modules.log.MongoDBAppenderBase">
|
||||
<filter class="ch.qos.logback.classic.filter.ThresholdFilter">
|
||||
<level>info</level>
|
||||
</filter>
|
||||
</appender>
|
||||
|
||||
<!--定义日志文件的存储地址 勿在 LogBack 的配置中使用相对路径-->
|
||||
|
||||
Reference in New Issue
Block a user