Browse Source

:sparkles: 添加新特性。支持jasypt加密,前端错误监控

冷冷 7 years ago
parent
commit
018a625f56

+ 4 - 0
pigx-config/src/main/resources/config/application-dev.yml

@@ -1,3 +1,7 @@
+# 加解密根密码
+jasypt:
+  encryptor:
+    password: pigx #根密码
 # redis 相关
 spring:
   redis:

+ 2 - 2
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

+ 4 - 4
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

+ 5 - 5
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:

+ 4 - 4
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:

+ 1 - 1
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

+ 36 - 0
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;
+}

+ 16 - 3
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<Boolean> save(@RequestBody SysLog sysLog) {
 		return new R<>(sysLogService.insert(sysLog));
 	}
+
+	/**
+	 * 插入前端异常日志
+	 *
+	 * @param preLogVoList 日志实体
+	 * @return success/false
+	 */
+	@PostMapping("/logs")
+	public R<Boolean> saveLogs(@RequestBody List<PreLogVo> preLogVoList) {
+		return new R<>(sysLogService.insertLogs(preLogVoList));
+	}
 }

+ 11 - 0
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;
 
 /**
  * <p>
@@ -39,4 +42,12 @@ public interface SysLogService extends IService<SysLog> {
 	 * @return true/false
 	 */
 	Boolean updateByLogId(Long id);
+
+	/**
+	 * 批量插入前端错误日志
+	 *
+	 * @param preLogVoList 日志信息
+	 * @return true/false
+	 */
+	Boolean insertLogs(List<PreLogVo> preLogVoList);
 }

+ 26 - 0
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;
 
 /**
  * <p>
@@ -48,4 +51,27 @@ public class SysLogServiceImpl extends ServiceImpl<SysLogMapper, SysLog> impleme
 		sysLog.setUpdateTime(LocalDateTime.now());
 		return updateById(sysLog);
 	}
+
+	/**
+	 * 批量插入前端错误日志
+	 *
+	 * @param preLogVoList 日志信息
+	 * @return true/false
+	 */
+	@Override
+	public Boolean insertLogs(List<PreLogVo> preLogVoList) {
+		List<SysLog> 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);
+	}
 }

+ 8 - 2
pom.xml

@@ -37,13 +37,13 @@
 	</parent>
 
 	<properties>
-		<pigx.version>1.5.0</pigx.version>
+		<pigx.version>1.6.0</pigx.version>
 		<spring-boot.version>2.0.4.RELEASE</spring-boot.version>
 		<spring-cloud.version>Finchley.SR1</spring-cloud.version>
 		<project.build.sourceEncoding>UTF-8</project.build.sourceEncoding>
 		<maven.compiler.source>1.8</maven.compiler.source>
 		<maven.compiler.target>1.8</maven.compiler.target>
-		<monitor.version>2.0.1</monitor.version>
+		<monitor.version>2.0.2</monitor.version>
 		<hutool.version>4.1.7</hutool.version>
 		<mbp.boot.version>2.3</mbp.boot.version>
 		<kaptcha.version>0.0.9</kaptcha.version>
@@ -52,6 +52,7 @@
 		<curator.version>2.10.0</curator.version>
 		<velocity.version>1.7</velocity.version>
 		<lcn.version>4.1.0</lcn.version>
+		<jasypt.version>2.1.0</jasypt.version>
 		<elastic-job-lite.version>2.1.5</elastic-job-lite.version>
 		<security.oauth.version>2.3.3.RELEASE</security.oauth.version>
 		<docker.url>http://192.168.0.13:4243</docker.url>
@@ -70,6 +71,11 @@
 			<artifactId>spring-boot-configuration-processor</artifactId>
 			<optional>true</optional>
 		</dependency>
+		<dependency>
+			<groupId>com.github.ulisesbocchio</groupId>
+			<artifactId>jasypt-spring-boot-starter</artifactId>
+			<version>${jasypt.version}</version>
+		</dependency>
 		<!--监控-->
 		<dependency>
 			<groupId>org.springframework.boot</groupId>