lixing 4 anni fa
parent
commit
134a933e0d

+ 53 - 0
fm-common/src/main/java/com/persagy/fm/common/response/CommonResult.java

@@ -0,0 +1,53 @@
+package com.persagy.fm.common.response;
+
+import com.fasterxml.jackson.annotation.JsonInclude;
+import com.persagy.common.enums.ResponseCode;
+import lombok.Data;
+
+/**
+ * 服务调用消息结果
+ * @author Charlie Yu
+ * @date 2021-03-25
+ */
+@Data
+@JsonInclude(JsonInclude.Include.NON_NULL)
+public class CommonResult<T> {
+
+    /** 不需要提示 */
+    public static final CommonResult SUCCESS = new CommonResult();
+
+    /** 响应码 */
+    private String respCode;
+    /** 响应码 */
+    private String respMsg;
+    /** 响应数据 */
+    private T content;
+
+    /**
+     * 构造方法
+     */
+    public CommonResult(){
+        this(ResponseCode.A00000.getCode(), ResponseCode.A00000.getDesc());
+    }
+
+    /**
+     * 构造方法
+     * @param respCode 响应码
+     * @param respMsg 提示信息
+     */
+    public CommonResult(String respCode, String respMsg) {
+        this(respCode, respMsg,null);
+    }
+
+    /**
+     * 构造方法
+     * @param respCode 响应码
+     * @param respMsg 提示信息
+     * @param content 数据
+     */
+    public CommonResult(String respCode, String respMsg, T content){
+        this.respCode = respCode;
+        this.respMsg = respMsg;
+        this.content = content;
+    }
+}

+ 22 - 0
fm-common/src/main/java/com/persagy/fm/common/response/PageList.java

@@ -0,0 +1,22 @@
+package com.persagy.fm.common.response;
+
+import lombok.Data;
+
+import java.util.List;
+
+/**
+ * 分页列表
+ * @author Charlie Yu
+ * @data 2021-03-25
+ */
+@Data
+public class PageList<T> {
+
+    private List<T> records;
+    private long total;
+
+    public PageList(final List<T> records, final long total) {
+        this.records = records;
+        this.total = total;
+    }
+}

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

@@ -0,0 +1,87 @@
+package com.persagy.fm.common.utils;
+
+import com.baomidou.mybatisplus.core.metadata.IPage;
+import com.persagy.common.enums.ResponseCode;
+import com.persagy.fm.common.response.CommonResult;
+import com.persagy.fm.common.response.PageList;
+import org.apache.commons.collections.CollectionUtils;
+
+import java.util.List;
+
+/**
+ * 响应结果包装助手
+ * @author Charlie Yu
+ * @date 2021-03-25
+ */
+public class ResultHelper {
+
+    /**
+     * 成功消息
+     * @return
+     */
+    public static CommonResult success(){
+        return new CommonResult(ResponseCode.A00000.getCode(), ResponseCode.A00000.getDesc());
+    }
+
+    /**
+     * 成功消息
+     * @return
+     */
+    public static CommonResult success(String respMsg){
+        return new CommonResult(ResponseCode.A00000.getCode(), respMsg);
+    }
+
+    /**
+     * 失败消息
+     * @param respCode
+     * @param respMsg
+     * @return
+     */
+    public static CommonResult failure(String respCode, String respMsg) {
+        return new CommonResult(respCode, respMsg);
+    }
+
+    /**
+     * 单个数据
+     * @param content
+     * @param <T>
+     * @return
+     */
+    public static <T> CommonResult<T> single(T content) {
+        return new CommonResult(ResponseCode.A00000.getCode(), ResponseCode.A00000.getDesc(), content);
+    }
+
+    /**
+     * 多个数据 - 列表
+     * @param records
+     * @param <T>
+     * @return
+     */
+    public static <T> CommonResult<PageList<T>> multi(List<T> records) {
+        return multi(records, CollectionUtils.size(records));
+    }
+
+    /**
+     * 多个数据 - 分页
+     * @param page
+     * @param <T>
+     * @return
+     */
+    public static <T> CommonResult<PageList<T>> multi(IPage<T> page) {
+        List<T> records = page == null ? null : page.getRecords();
+        long total = page == null ? 0 : page.getTotal();
+        return multi(records, total);
+    }
+
+    /**
+     * 多个数据
+     * @param records
+     * @param total
+     * @param <T>
+     * @return
+     */
+    private static <T> CommonResult<PageList<T>> multi(List<T> records, long total) {
+        PageList<T> pageList = new PageList<>(records, total);
+        return new CommonResult(ResponseCode.A00000.getCode(), ResponseCode.A00000.getDesc(), pageList);
+    }
+}

+ 2 - 2
fm-server/src/main/java/com/persagy/ServerApplication.java

@@ -6,7 +6,6 @@ import org.mybatis.spring.annotation.MapperScan;
 import org.springframework.boot.Banner;
 import org.springframework.boot.SpringApplication;
 import org.springframework.boot.autoconfigure.SpringBootApplication;
-import org.springframework.boot.autoconfigure.aop.AopAutoConfiguration;
 import org.springframework.cache.annotation.EnableCaching;
 import org.springframework.cloud.client.discovery.EnableDiscoveryClient;
 import org.springframework.cloud.openfeign.EnableFeignClients;
@@ -25,9 +24,10 @@ import org.springframework.scheduling.annotation.EnableScheduling;
 @EnableDiscoveryClient
 @Configuration
 @EnableScheduling
-@SpringBootApplication
 @MapperScan(value = "com.persagy.fm.*.dao")
 @EnableSpringUtil
+@SpringBootApplication
+@MapperScan(value = "com.persagy.fm.*.dao")
 public class ServerApplication {
 
     public static void main(String[] args) {

+ 5 - 6
fm-translate/src/main/java/com/persagy/fm/translate/aop/TranslateAopAspect.java

@@ -2,7 +2,6 @@ package com.persagy.fm.translate.aop;
 
 import com.google.common.cache.Cache;
 import com.google.common.cache.CacheBuilder;
-import com.persagy.fm.common.helper.SpringHelper;
 import com.persagy.fm.translate.helper.TranslatorHelper;
 import com.persagy.fm.translate.model.ITransable;
 import com.persagy.fm.translate.model.Trans;
@@ -30,17 +29,17 @@ import java.util.List;
 @Slf4j
 public class TranslateAopAspect implements Ordered {
 
-    /**
-     * 翻译描述信息缓存
-     */
+    /** 缓存池大小 */
+    private final int CACHE_COUNT = 100;
+
+    /** 翻译描述信息缓存 */
     private Cache<String,List<TransMeta>> transCach;
 
     /**
      * 构造方法,初始化缓存
      */
     public TranslateAopAspect(){
-        int count = SpringHelper.getInt("translate.cache.size",100);
-        transCach = CacheBuilder.newBuilder().initialCapacity(count/2).maximumSize(count).build();
+        transCach = CacheBuilder.newBuilder().initialCapacity(CACHE_COUNT/2).maximumSize(CACHE_COUNT).build();
     }
 
     @Pointcut("@annotation(com.persagy.fm.translate.model.Transes)||@annotation(com.persagy.fm.translate.model.Trans)")