Bläddra i källkod

:recycle: 重构代码。 重构代码

冷冷 7 år sedan
förälder
incheckning
9157d784d9

+ 3 - 2
pigx-common/pigx-common-security/src/main/java/com/pig4cloud/pigx/common/security/component/PigxAuth2ExceptionSerializer.java

@@ -20,6 +20,7 @@ package com.pig4cloud.pigx.common.security.component;
 import com.fasterxml.jackson.core.JsonGenerator;
 import com.fasterxml.jackson.databind.SerializerProvider;
 import com.fasterxml.jackson.databind.ser.std.StdSerializer;
+import com.pig4cloud.pigx.common.core.constant.CommonConstant;
 import com.pig4cloud.pigx.common.security.exception.PigxAuth2Exception;
 
 import java.io.IOException;
@@ -38,8 +39,8 @@ public class PigxAuth2ExceptionSerializer extends StdSerializer<PigxAuth2Excepti
 	@Override
 	public void serialize(PigxAuth2Exception value, JsonGenerator gen, SerializerProvider provider) throws IOException {
 		gen.writeStartObject();
-		gen.writeObjectField("code", 1);
-		gen.writeStringField("message", value.getMessage());
+		gen.writeObjectField("code", CommonConstant.FAIL);
+		gen.writeStringField("msg", value.getMessage());
 		gen.writeStringField("data", value.getErrorCode());
 		gen.writeEndObject();
 	}

+ 1 - 3
pigx-config/src/main/resources/config/application-dev.yml

@@ -25,7 +25,7 @@ feign:
     enabled: false
   client:
     config:
-      feignName:
+      default:
         connectTimeout: 10000
         readTimeout: 10000
   compression:
@@ -55,8 +55,6 @@ mybatis-plus:
   # MyBatis Mapper所对应的XML文件位置
   mapper-locations: classpath:/mapper/*Mapper.xml
   global-config:
-    # 自动刷新Mapper对应的XML文件
-    refresh: true
     # 关闭MP3.0自带的banner
     banner: false
     db-config:

+ 10 - 8
pigx-gateway/src/main/java/com/pig4cloud/pigx/gateway/filter/ValidateCodeGatewayFilter.java

@@ -57,14 +57,14 @@ public class ValidateCodeGatewayFilter extends AbstractGatewayFilterFactory {
 
 			// 不是登录请求,直接向下执行
 			if (!StrUtil.containsAnyIgnoreCase(request.getURI().getPath()
-				, SecurityConstants.OAUTH_TOKEN_URL, SecurityConstants.SMS_TOKEN_URL)) {
+					, SecurityConstants.OAUTH_TOKEN_URL, SecurityConstants.SMS_TOKEN_URL)) {
 				return chain.filter(exchange);
 			}
 
 			// 终端设置不校验, 直接向下执行(1. 从请求参数中获取 2.从header取)
 			String clientId = request.getQueryParams().getFirst("client_id");
 			if (StrUtil.isNotBlank(clientId)
-				&& filterIgnorePropertiesConfig.getClients().contains(clientId)) {
+					&& filterIgnorePropertiesConfig.getClients().contains(clientId)) {
 				return chain.filter(exchange);
 			}
 
@@ -81,7 +81,9 @@ public class ValidateCodeGatewayFilter extends AbstractGatewayFilterFactory {
 				response.setStatusCode(HttpStatus.PRECONDITION_REQUIRED);
 				try {
 					return response.writeWith(Mono.just(response.bufferFactory()
-						.wrap(objectMapper.writeValueAsBytes(new R<>(e)))));
+							.wrap(objectMapper.writeValueAsBytes(
+									R.builder().msg(e.getMessage())
+											.code(CommonConstant.FAIL).build()))));
 				} catch (JsonProcessingException e1) {
 					log.error("对象输出异常", e1);
 				}
@@ -101,7 +103,7 @@ public class ValidateCodeGatewayFilter extends AbstractGatewayFilterFactory {
 		String code = request.getQueryParams().getFirst("code");
 
 		if (StrUtil.isBlank(code)) {
-			throw new ValidateCodeException();
+			throw new ValidateCodeException("验证码不能为空");
 		}
 
 		String randomStr = request.getQueryParams().getFirst("randomStr");
@@ -111,24 +113,24 @@ public class ValidateCodeGatewayFilter extends AbstractGatewayFilterFactory {
 
 		String key = CommonConstant.DEFAULT_CODE_KEY + randomStr;
 		if (!redisTemplate.hasKey(key)) {
-			throw new ValidateCodeException();
+			throw new ValidateCodeException("验证码不合法");
 		}
 
 		Object codeObj = redisTemplate.opsForValue().get(key);
 
 		if (codeObj == null) {
-			throw new ValidateCodeException();
+			throw new ValidateCodeException("验证码不合法");
 		}
 
 		String saveCode = codeObj.toString();
 		if (StrUtil.isBlank(saveCode)) {
 			redisTemplate.delete(key);
-			throw new ValidateCodeException();
+			throw new ValidateCodeException("验证码不合法");
 		}
 
 		if (!StrUtil.equals(saveCode, code)) {
 			redisTemplate.delete(key);
-			throw new ValidateCodeException();
+			throw new ValidateCodeException("验证码不合法");
 		}
 
 		redisTemplate.delete(key);

+ 7 - 1
pigx-gateway/src/main/java/com/pig4cloud/pigx/gateway/handler/HystrixFallbackHandler.java

@@ -17,6 +17,8 @@
 
 package com.pig4cloud.pigx.gateway.handler;
 
+import com.pig4cloud.pigx.common.core.constant.CommonConstant;
+import com.pig4cloud.pigx.common.core.util.R;
 import lombok.extern.slf4j.Slf4j;
 import org.springframework.http.HttpStatus;
 import org.springframework.http.MediaType;
@@ -46,6 +48,10 @@ public class HystrixFallbackHandler implements HandlerFunction<ServerResponse> {
 		originalUris.ifPresent(originalUri -> log.error("网关执行请求:{}失败,hystrix服务降级处理", originalUri));
 
 		return ServerResponse.status(HttpStatus.INTERNAL_SERVER_ERROR.value())
-			.contentType(MediaType.TEXT_PLAIN).body(BodyInserters.fromObject("服务异常"));
+				.contentType(MediaType.APPLICATION_JSON_UTF8)
+				.body(BodyInserters.fromObject(R.builder()
+						.msg("服务异常")
+						.code(CommonConstant.FAIL)
+						.build()));
 	}
 }

+ 2 - 2
pigx-visual/pigx-activiti/src/main/java/com/pig4cloud/pigx/act/listener/LeaveProcessTaskListener.java

@@ -50,11 +50,11 @@ public class LeaveProcessTaskListener implements TaskListener {
 		R<List<SysUser>> result = userService.ancestorUsers(SecurityUtils.getUsername());
 
 		if (CollUtil.isEmpty(result.getData())) {
-			log.warn("用户 {} 不存在上级,任务单由当前用户审批", SecurityUtils.getUsername());
+			log.info("用户 {} 不存在上级,任务单由当前用户审批", SecurityUtils.getUsername());
 			delegateTask.addCandidateUser(SecurityUtils.getUsername());
 		} else {
 			List<String> userList = result.getData().stream().map(SysUser::getUsername).collect(Collectors.toList());
-			log.warn("当前任务 {},由 {}处理", delegateTask.getId(), userList);
+			log.info("当前任务 {},由 {}处理", delegateTask.getId(), userList);
 			delegateTask.addCandidateUsers(userList);
 		}