yucheng il y a 4 ans
Parent
commit
5cb5454436

+ 7 - 1
fm-common/src/main/java/com/persagy/fm/common/config/JacksonConfig.java

@@ -4,6 +4,9 @@ import com.fasterxml.jackson.core.JsonGenerator;
 import com.fasterxml.jackson.databind.*;
 import com.fasterxml.jackson.databind.ser.BeanPropertyWriter;
 import com.fasterxml.jackson.databind.ser.BeanSerializerModifier;
+import com.persagy.fm.common.lang.PsDate;
+import com.persagy.fm.common.lang.PsDateTime;
+import com.persagy.fm.common.lang.PsTime;
 import org.springframework.boot.autoconfigure.condition.ConditionalOnMissingBean;
 import org.springframework.context.annotation.Bean;
 import org.springframework.context.annotation.Configuration;
@@ -89,7 +92,10 @@ public class JacksonConfig {
                     clazz.equals(Boolean.class) ||
                     clazz.equals(Byte.class) ||
                     clazz.equals(Date.class) ||
-                    clazz.equals(String.class);
+                    clazz.equals(String.class) ||
+                    clazz.equals(PsDate.class) ||
+                    clazz.equals(PsDateTime.class) ||
+                    clazz.equals(PsTime.class);
         }
     }
 }

+ 6 - 0
fm-common/src/main/java/com/persagy/fm/common/handler/AppContextHandler.java

@@ -4,6 +4,7 @@ import com.alibaba.fastjson.JSONObject;
 import com.persagy.fm.common.constant.AppContextConstants;
 import com.persagy.fm.common.context.AppContext;
 import com.persagy.fm.common.context.DefaultAppContext;
+import com.persagy.fm.common.helper.SpringHelper;
 import com.persagy.fm.common.utils.SecureAES;
 import com.persagy.security.exception.AESDecryptException;
 import org.apache.commons.lang3.StringUtils;
@@ -41,6 +42,11 @@ public class AppContextHandler extends HandlerInterceptorAdapter {
      * @param token
      */
     private void ensureContextInfo(String token){
+        // 是否启用token拦截
+        boolean enabled = SpringHelper.getBoolean("persagy.common.token.enabled", true);
+        if(!enabled) {
+            return;
+        }
         // 从token中解析数据
         SecureAES aes = new SecureAES("63499E35378AE1B0733E3FED7F780B68", "C0E7BD39B52A15C7");
         JSONObject tokenObj = null;

+ 5 - 1
fm-common/src/main/java/com/persagy/fm/common/serializer/PsDateDeserializer.java

@@ -18,6 +18,10 @@ import java.io.IOException;
 public class PsDateDeserializer extends JsonDeserializer<PsDate> {
     @Override
     public PsDate deserialize(JsonParser p, DeserializationContext context) throws IOException, JsonProcessingException {
-        return PsDate.parsePsDate(p.getLongValue());
+        Long millis = p.getValueAsLong();
+        if(millis <= 0) {
+            return null;
+        }
+        return PsDate.parsePsDate(millis);
     }
 }

+ 5 - 1
fm-common/src/main/java/com/persagy/fm/common/serializer/PsDateTimeDeserializer.java

@@ -18,6 +18,10 @@ import java.io.IOException;
 public class PsDateTimeDeserializer extends JsonDeserializer<PsDateTime> {
     @Override
     public PsDateTime deserialize(JsonParser p, DeserializationContext context) throws IOException, JsonProcessingException {
-        return PsDateTime.parsePsDateTime(p.getLongValue());
+        Long millis = p.getValueAsLong();
+        if(millis <= 0) {
+            return null;
+        }
+        return PsDateTime.parsePsDateTime(millis);
     }
 }

+ 5 - 1
fm-common/src/main/java/com/persagy/fm/common/serializer/PsTimeDeserializer.java

@@ -19,6 +19,10 @@ public class PsTimeDeserializer extends JsonDeserializer<PsTime> {
 
     @Override
     public PsTime deserialize(JsonParser p, DeserializationContext context) throws IOException, JsonProcessingException {
-        return PsTime.parsePsTime(p.getLongValue());
+        Long millis = p.getValueAsLong();
+        if(millis <= 0) {
+            return null;
+        }
+        return PsTime.parsePsTime(millis);
     }
 }

+ 14 - 0
fm-common/src/main/java/com/persagy/fm/common/utils/ResultHelper.java

@@ -2,6 +2,7 @@ package com.persagy.fm.common.utils;
 
 import com.baomidou.mybatisplus.core.metadata.IPage;
 import com.persagy.common.enums.ResponseCode;
+import com.persagy.common.exception.BusinessException;
 import com.persagy.fm.common.response.CommonResult;
 import com.persagy.fm.common.response.PageList;
 import org.apache.commons.collections.CollectionUtils;
@@ -94,4 +95,17 @@ public class ResultHelper {
         PageList<T> pageList = new PageList<>(records, total);
         return new CommonResult(ResponseCode.A00000.getCode(), ResponseCode.A00000.getDesc(), pageList);
     }
+
+    /**
+     * 读取结果
+     * @param result
+     * @param <T>
+     * @return 对应的结果
+     */
+    public static <T> T getContent(CommonResult<T> result) {
+        if(!ResponseCode.A00000.getCode().equals(result.getRespCode())) {
+            throw new BusinessException(result.getRespCode(), result.getRespMsg());
+        }
+        return result.getContent();
+    }
 }