From 018a625f5690f368451eb5a1a26851910bc8621c Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=E5=86=B7=E5=86=B7?= Date: Mon, 27 Aug 2018 21:24:17 +0800 Subject: [PATCH] =?UTF-8?q?:sparkles:=20=E6=B7=BB=E5=8A=A0=E6=96=B0?= =?UTF-8?q?=E7=89=B9=E6=80=A7=E3=80=82=E6=94=AF=E6=8C=81jasypt=E5=8A=A0?= =?UTF-8?q?=E5=AF=86=EF=BC=8C=E5=89=8D=E7=AB=AF=E9=94=99=E8=AF=AF=E7=9B=91?= =?UTF-8?q?=E6=8E=A7?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../main/resources/config/application-dev.yml | 4 +++ .../main/resources/config/pigx-auth-dev.yml | 4 +-- .../resources/config/pigx-codegen-dev.yml | 8 ++--- .../main/resources/config/pigx-daemon-dev.yml | 10 +++--- .../main/resources/config/pigx-upms-dev.yml | 8 ++--- pigx-eureka/src/main/resources/bootstrap.yml | 2 +- .../pig4cloud/pigx/admin/api/vo/PreLogVo.java | 36 +++++++++++++++++++ .../pigx/admin/controller/LogController.java | 19 ++++++++-- .../pigx/admin/service/SysLogService.java | 11 ++++++ .../admin/service/impl/SysLogServiceImpl.java | 26 ++++++++++++++ pom.xml | 10 ++++-- 11 files changed, 117 insertions(+), 21 deletions(-) create mode 100644 pigx-upms/pigx-upms-api/src/main/java/com/pig4cloud/pigx/admin/api/vo/PreLogVo.java diff --git a/pigx-config/src/main/resources/config/application-dev.yml b/pigx-config/src/main/resources/config/application-dev.yml index 01bf8a6cb..468da6722 100644 --- a/pigx-config/src/main/resources/config/application-dev.yml +++ b/pigx-config/src/main/resources/config/application-dev.yml @@ -1,3 +1,7 @@ +# 加解密根密码 +jasypt: + encryptor: + password: pigx #根密码 # redis 相关 spring: redis: diff --git a/pigx-config/src/main/resources/config/pigx-auth-dev.yml b/pigx-config/src/main/resources/config/pigx-auth-dev.yml index 8abdbf645..f8a9b6464 100644 --- a/pigx-config/src/main/resources/config/pigx-auth-dev.yml +++ b/pigx-config/src/main/resources/config/pigx-auth-dev.yml @@ -4,5 +4,5 @@ spring: type: com.zaxxer.hikari.HikariDataSource driver-class-name: com.mysql.jdbc.Driver username: root - password: root - url: jdbc:mysql://127.0.0.1:3306/pigx?characterEncoding=utf8&zeroDateTimeBehavior=convertToNull&useSSL=false + password: Bjyjht2017!@# + url: jdbc:mysql://114.116.30.176:3306/pigx?characterEncoding=utf8&zeroDateTimeBehavior=convertToNull&useSSL=false diff --git a/pigx-config/src/main/resources/config/pigx-codegen-dev.yml b/pigx-config/src/main/resources/config/pigx-codegen-dev.yml index 36e4845bb..cbfb4984c 100644 --- a/pigx-config/src/main/resources/config/pigx-codegen-dev.yml +++ b/pigx-config/src/main/resources/config/pigx-codegen-dev.yml @@ -2,8 +2,8 @@ security: oauth2: client: - client-id: gen - client-secret: gen + client-id: ENC(xD1AY92cohwLfefsXett5Q==) + client-secret: ENC(xD1AY92cohwLfefsXett5Q==) scope: server # 数据源配置 @@ -12,8 +12,8 @@ spring: type: com.zaxxer.hikari.HikariDataSource driver-class-name: com.mysql.jdbc.Driver username: root - password: root - url: jdbc:mysql://127.0.0.1:3306/pigx?characterEncoding=utf8&zeroDateTimeBehavior=convertToNull&useSSL=false + password: Bjyjht2017!@# + url: jdbc:mysql://114.116.30.176:3306/pigx?characterEncoding=utf8&zeroDateTimeBehavior=convertToNull&useSSL=false jackson: time-zone: GMT+8 date-format: yyyy-MM-dd HH:mm:ss diff --git a/pigx-config/src/main/resources/config/pigx-daemon-dev.yml b/pigx-config/src/main/resources/config/pigx-daemon-dev.yml index cbca2e16c..fa0c91c7f 100644 --- a/pigx-config/src/main/resources/config/pigx-daemon-dev.yml +++ b/pigx-config/src/main/resources/config/pigx-daemon-dev.yml @@ -2,8 +2,8 @@ security: oauth2: client: - client-id: daemon - client-secret: daemon + client-id: ENC(Y91StLXT8tX5TwpcTSR2kg==) + client-secret: ENC(Y91StLXT8tX5TwpcTSR2kg==) scope: server ## 定时任务 @@ -13,12 +13,12 @@ spring: type: com.zaxxer.hikari.HikariDataSource driver-class-name: com.mysql.jdbc.Driver username: root - password: root - url: jdbc:mysql://127.0.0.1:3306/pigx?characterEncoding=utf8&zeroDateTimeBehavior=convertToNull&useSSL=false + password: Bjyjht2017!@# + url: jdbc:mysql://114.116.30.176:3306/pigx?characterEncoding=utf8&zeroDateTimeBehavior=convertToNull&useSSL=false elasticjob: # 分布式任务协调依赖zookeeper zookeeper: - server-lists: 127.0.0.1:2181 + server-lists: 114.116.45.246:13181 namespace: pigx-daemon # 普通任务 simples: diff --git a/pigx-config/src/main/resources/config/pigx-upms-dev.yml b/pigx-config/src/main/resources/config/pigx-upms-dev.yml index 8cb56ab5d..2529c5085 100644 --- a/pigx-config/src/main/resources/config/pigx-upms-dev.yml +++ b/pigx-config/src/main/resources/config/pigx-upms-dev.yml @@ -2,8 +2,8 @@ security: oauth2: client: - client-id: pig - client-secret: pig + client-id: ENC(iVEZk4Gdt0UXDlX7ZN9J5g==) + client-secret: ENC(iVEZk4Gdt0UXDlX7ZN9J5g==) scope: server # 数据源 @@ -12,8 +12,8 @@ spring: type: com.zaxxer.hikari.HikariDataSource driver-class-name: com.mysql.jdbc.Driver username: root - password: root - url: jdbc:mysql://127.0.0.1:3306/pigx?characterEncoding=utf8&zeroDateTimeBehavior=convertToNull&useSSL=false + password: Bjyjht2017!@# + url: jdbc:mysql://114.116.30.176:3306/pigx?characterEncoding=utf8&zeroDateTimeBehavior=convertToNull&useSSL=false # mybaits 模块配置 mybatis-plus: diff --git a/pigx-eureka/src/main/resources/bootstrap.yml b/pigx-eureka/src/main/resources/bootstrap.yml index 8f1cbe986..2c36ec856 100644 --- a/pigx-eureka/src/main/resources/bootstrap.yml +++ b/pigx-eureka/src/main/resources/bootstrap.yml @@ -13,7 +13,7 @@ spring: # 类似的 redis 使用pigx-redis ,gateway 换成 pigx-gateway eureka: instance: - hostname: pigx-eureka + hostname: localhost prefer-ip-address: true client: register-with-eureka: false diff --git a/pigx-upms/pigx-upms-api/src/main/java/com/pig4cloud/pigx/admin/api/vo/PreLogVo.java b/pigx-upms/pigx-upms-api/src/main/java/com/pig4cloud/pigx/admin/api/vo/PreLogVo.java new file mode 100644 index 000000000..c7bb2dfc9 --- /dev/null +++ b/pigx-upms/pigx-upms-api/src/main/java/com/pig4cloud/pigx/admin/api/vo/PreLogVo.java @@ -0,0 +1,36 @@ +/* + * Copyright (c) 2018-2025, lengleng All rights reserved. + * + * Redistribution and use in source and binary forms, with or without + * modification, are permitted provided that the following conditions are met: + * + * Redistributions of source code must retain the above copyright notice, + * this list of conditions and the following disclaimer. + * Redistributions in binary form must reproduce the above copyright + * notice, this list of conditions and the following disclaimer in the + * documentation and/or other materials provided with the distribution. + * Neither the name of the pig4cloud.com developer nor the names of its + * contributors may be used to endorse or promote products derived from + * this software without specific prior written permission. + * Author: lengleng (wangiegie@gmail.com) + */ + +package com.pig4cloud.pigx.admin.api.vo; + +import lombok.Data; + +/** + * @author lengleng + * @date 2018/8/27 + * 前端日志vo + */ +@Data +public class PreLogVo { + private String url; + private String time; + private String user; + private String type; + private String message; + private String stack; + private String info; +} diff --git a/pigx-upms/pigx-upms-biz/src/main/java/com/pig4cloud/pigx/admin/controller/LogController.java b/pigx-upms/pigx-upms-biz/src/main/java/com/pig4cloud/pigx/admin/controller/LogController.java index 55e4fdae5..ddbf6aa2e 100644 --- a/pigx-upms/pigx-upms-biz/src/main/java/com/pig4cloud/pigx/admin/controller/LogController.java +++ b/pigx-upms/pigx-upms-biz/src/main/java/com/pig4cloud/pigx/admin/controller/LogController.java @@ -23,14 +23,16 @@ package com.pig4cloud.pigx.admin.controller; import com.baomidou.mybatisplus.mapper.EntityWrapper; import com.baomidou.mybatisplus.plugins.Page; import com.pig4cloud.pigx.admin.api.entity.SysLog; +import com.pig4cloud.pigx.admin.api.vo.PreLogVo; import com.pig4cloud.pigx.admin.service.SysLogService; import com.pig4cloud.pigx.common.core.constant.CommonConstant; import com.pig4cloud.pigx.common.core.util.Query; import com.pig4cloud.pigx.common.core.util.R; -import org.springframework.beans.factory.annotation.Autowired; +import lombok.AllArgsConstructor; import org.springframework.security.access.prepost.PreAuthorize; import org.springframework.web.bind.annotation.*; +import java.util.List; import java.util.Map; /** @@ -43,9 +45,9 @@ import java.util.Map; */ @RestController @RequestMapping("/log") +@AllArgsConstructor public class LogController { - @Autowired - private SysLogService sysLogService; + private final SysLogService sysLogService; /** * 分页查询日志信息 @@ -81,4 +83,15 @@ public class LogController { public R save(@RequestBody SysLog sysLog) { return new R<>(sysLogService.insert(sysLog)); } + + /** + * 插入前端异常日志 + * + * @param preLogVoList 日志实体 + * @return success/false + */ + @PostMapping("/logs") + public R saveLogs(@RequestBody List preLogVoList) { + return new R<>(sysLogService.insertLogs(preLogVoList)); + } } diff --git a/pigx-upms/pigx-upms-biz/src/main/java/com/pig4cloud/pigx/admin/service/SysLogService.java b/pigx-upms/pigx-upms-biz/src/main/java/com/pig4cloud/pigx/admin/service/SysLogService.java index 8e0e88f3c..6bbd74251 100644 --- a/pigx-upms/pigx-upms-biz/src/main/java/com/pig4cloud/pigx/admin/service/SysLogService.java +++ b/pigx-upms/pigx-upms-biz/src/main/java/com/pig4cloud/pigx/admin/service/SysLogService.java @@ -21,6 +21,9 @@ package com.pig4cloud.pigx.admin.service; import com.baomidou.mybatisplus.service.IService; import com.pig4cloud.pigx.admin.api.entity.SysLog; +import com.pig4cloud.pigx.admin.api.vo.PreLogVo; + +import java.util.List; /** *

@@ -39,4 +42,12 @@ public interface SysLogService extends IService { * @return true/false */ Boolean updateByLogId(Long id); + + /** + * 批量插入前端错误日志 + * + * @param preLogVoList 日志信息 + * @return true/false + */ + Boolean insertLogs(List preLogVoList); } diff --git a/pigx-upms/pigx-upms-biz/src/main/java/com/pig4cloud/pigx/admin/service/impl/SysLogServiceImpl.java b/pigx-upms/pigx-upms-biz/src/main/java/com/pig4cloud/pigx/admin/service/impl/SysLogServiceImpl.java index e01c39df5..6a66d2449 100644 --- a/pigx-upms/pigx-upms-biz/src/main/java/com/pig4cloud/pigx/admin/service/impl/SysLogServiceImpl.java +++ b/pigx-upms/pigx-upms-biz/src/main/java/com/pig4cloud/pigx/admin/service/impl/SysLogServiceImpl.java @@ -21,12 +21,15 @@ package com.pig4cloud.pigx.admin.service.impl; import com.baomidou.mybatisplus.service.impl.ServiceImpl; import com.pig4cloud.pigx.admin.api.entity.SysLog; +import com.pig4cloud.pigx.admin.api.vo.PreLogVo; import com.pig4cloud.pigx.admin.mapper.SysLogMapper; import com.pig4cloud.pigx.admin.service.SysLogService; import com.pig4cloud.pigx.common.core.constant.CommonConstant; import org.springframework.stereotype.Service; import java.time.LocalDateTime; +import java.util.ArrayList; +import java.util.List; /** *

@@ -48,4 +51,27 @@ public class SysLogServiceImpl extends ServiceImpl impleme sysLog.setUpdateTime(LocalDateTime.now()); return updateById(sysLog); } + + /** + * 批量插入前端错误日志 + * + * @param preLogVoList 日志信息 + * @return true/false + */ + @Override + public Boolean insertLogs(List preLogVoList) { + List sysLogs = new ArrayList<>(); + preLogVoList.forEach(pre -> { + SysLog log = new SysLog(); + log.setType(CommonConstant.STATUS_LOCK); + log.setTitle(pre.getInfo()); + log.setException(pre.getStack()); + log.setParams(pre.getMessage()); + log.setCreateTime(LocalDateTime.now()); + log.setRequestUri(pre.getUrl()); + log.setCreateBy(pre.getUser()); + sysLogs.add(log); + }); + return this.insertBatch(sysLogs); + } } diff --git a/pom.xml b/pom.xml index 0901705d9..c1b23fc7f 100644 --- a/pom.xml +++ b/pom.xml @@ -37,13 +37,13 @@ - 1.5.0 + 1.6.0 2.0.4.RELEASE Finchley.SR1 UTF-8 1.8 1.8 - 2.0.1 + 2.0.2 4.1.7 2.3 0.0.9 @@ -52,6 +52,7 @@ 2.10.0 1.7 4.1.0 + 2.1.0 2.1.5 2.3.3.RELEASE http://192.168.0.13:4243 @@ -70,6 +71,11 @@ spring-boot-configuration-processor true + + com.github.ulisesbocchio + jasypt-spring-boot-starter + ${jasypt.version} + org.springframework.boot