diff --git a/pom.xml b/pom.xml index b9014d4..1856fef 100644 --- a/pom.xml +++ b/pom.xml @@ -10,7 +10,7 @@ com.rymcu forest - 0.0.1 + 0.0.2 war forest forest(森林) —— 一款现代化的知识社区后台项目,使用 SpringBoot + Shiro + MyBatis + JWT + Redis 实现。 @@ -56,14 +56,14 @@ com.fasterxml.jackson.core jackson-databind - 2.13.4.2 + 2.14.0 org.mybatis.spring.boot mybatis-spring-boot-starter - 2.2.2 + 3.0.0 @@ -128,7 +128,7 @@ com.alibaba fastjson - 2.0.16 + 2.0.20 @@ -183,7 +183,7 @@ com.alibaba druid-spring-boot-starter - 1.2.14 + 1.2.15 org.apache.logging.log4j @@ -261,12 +261,12 @@ cn.hutool hutool-core - 5.8.9 + 5.8.10 cn.hutool hutool-http - 5.8.9 + 5.8.10 diff --git a/src/main/java/com/rymcu/forest/answer/AnswerController.java b/src/main/java/com/rymcu/forest/answer/AnswerController.java index 3b4c6f8..910a21a 100644 --- a/src/main/java/com/rymcu/forest/answer/AnswerController.java +++ b/src/main/java/com/rymcu/forest/answer/AnswerController.java @@ -8,6 +8,7 @@ import com.rymcu.forest.entity.User; import com.rymcu.forest.enumerate.TransactionEnum; import com.rymcu.forest.util.HttpUtils; import com.rymcu.forest.util.UserUtils; +import org.springframework.beans.factory.annotation.Value; import org.springframework.web.bind.annotation.*; import java.util.HashMap; @@ -20,7 +21,8 @@ import java.util.Map; @RequestMapping("/api/v1/answer") public class AnswerController { - private final static String ANSWER_API_URL = "http://1.116.175.112:8089/question"; + @Value("${resource.answer-api-url}") + private String ANSWER_API_URL; @GetMapping("/today") public GlobalResult today() { diff --git a/src/main/java/com/rymcu/forest/config/VisitableThreadPoolTaskExecutor.java b/src/main/java/com/rymcu/forest/config/VisitableThreadPoolTaskExecutor.java index 8e47aea..bc12f9a 100644 --- a/src/main/java/com/rymcu/forest/config/VisitableThreadPoolTaskExecutor.java +++ b/src/main/java/com/rymcu/forest/config/VisitableThreadPoolTaskExecutor.java @@ -19,9 +19,8 @@ import java.util.concurrent.ThreadPoolExecutor; public class VisitableThreadPoolTaskExecutor extends ThreadPoolTaskExecutor { private static final Logger logger = LoggerFactory.getLogger(VisitableThreadPoolTaskExecutor.class); - private void showThreadPoolInfo(String prefix){ + private void showThreadPoolInfo(String prefix) { ThreadPoolExecutor threadPoolExecutor = getThreadPoolExecutor(); - logger.info("{}, {},taskCount [{}], completedTaskCount [{}], activeCount [{}], queueSize [{}]", this.getThreadNamePrefix(), prefix, diff --git a/src/main/java/com/rymcu/forest/core/result/GlobalResult.java b/src/main/java/com/rymcu/forest/core/result/GlobalResult.java index 2e52f6f..faab103 100644 --- a/src/main/java/com/rymcu/forest/core/result/GlobalResult.java +++ b/src/main/java/com/rymcu/forest/core/result/GlobalResult.java @@ -21,7 +21,7 @@ public class GlobalResult { } public static GlobalResult newInstance() { - return new GlobalResult(); + return new GlobalResult<>(); } } diff --git a/src/main/java/com/rymcu/forest/core/service/redis/RedisService.java b/src/main/java/com/rymcu/forest/core/service/redis/RedisService.java index c005437..e5f64bf 100644 --- a/src/main/java/com/rymcu/forest/core/service/redis/RedisService.java +++ b/src/main/java/com/rymcu/forest/core/service/redis/RedisService.java @@ -134,7 +134,7 @@ public interface RedisService { * @param expireTime 缓存内容过期时间 (单位:秒) ,若expireTime小于0 则表示该内容不过期 * @return */ - String set(String key, Object obj, int expireTime); + String set(String key, Object obj, long expireTime); /** @@ -145,7 +145,7 @@ public interface RedisService { * @param expireTime 缓存内容过期时间 (单位:秒) ,若expireTime小于0 则表示该内容不过期 * @return */ - String set(String key, String value, int expireTime); + String set(String key, String value, long expireTime); /** * 写入/修改 缓存内容 @@ -212,7 +212,7 @@ public interface RedisService { * @param key * @param seconds */ - void setTTL(String key, int seconds); + void setTTL(String key, long seconds); /** * 根据通配符表达式查询key值的set,通配符仅支持* diff --git a/src/main/java/com/rymcu/forest/core/service/redis/impl/RedisServiceImpl.java b/src/main/java/com/rymcu/forest/core/service/redis/impl/RedisServiceImpl.java index 6c36f11..7cacb08 100644 --- a/src/main/java/com/rymcu/forest/core/service/redis/impl/RedisServiceImpl.java +++ b/src/main/java/com/rymcu/forest/core/service/redis/impl/RedisServiceImpl.java @@ -163,7 +163,7 @@ public class RedisServiceImpl implements RedisService { * @return */ @Override - public String set(String key, Object obj, int expireTime) { + public String set(String key, Object obj, long expireTime) { String value = RedisService.BLANK_CONTENT; if (obj != null) { try { @@ -184,7 +184,7 @@ public class RedisServiceImpl implements RedisService { * @return */ @Override - public String set(String key, String value, int expireTime) { + public String set(String key, String value, long expireTime) { if (StringUtils.isBlank(key)) { logger.warn("Params key is blank!"); return null; @@ -460,7 +460,7 @@ public class RedisServiceImpl implements RedisService { * @param seconds */ @Override - public void setTTL(String key, int seconds) { + public void setTTL(String key, long seconds) { if (seconds < 0) { return; } diff --git a/src/main/java/com/rymcu/forest/lucene/cfg/DefaultConfig.java b/src/main/java/com/rymcu/forest/lucene/cfg/DefaultConfig.java index 92c2312..068143a 100644 --- a/src/main/java/com/rymcu/forest/lucene/cfg/DefaultConfig.java +++ b/src/main/java/com/rymcu/forest/lucene/cfg/DefaultConfig.java @@ -42,7 +42,7 @@ public class DefaultConfig implements Configuration { * 用户自定义字典路径 */ private static final String PATH_USER_DIC = - System.getProperty("user.dir") + "/lucene/userDic/userDic.dic"; + "lucene/userDic/userDic.dic"; /** * 配置属性——扩展字典 */ diff --git a/src/main/java/com/rymcu/forest/lucene/dic/Dictionary.java b/src/main/java/com/rymcu/forest/lucene/dic/Dictionary.java index 51fa7b2..0acb4c8 100644 --- a/src/main/java/com/rymcu/forest/lucene/dic/Dictionary.java +++ b/src/main/java/com/rymcu/forest/lucene/dic/Dictionary.java @@ -53,7 +53,7 @@ public class Dictionary { * 用户自定义词典路径 */ private static final String PATH_USER_DIC = - System.getProperty("user.dir") + "/lucene/userDic/userDic.dic"; + "lucene/userDic/userDic.dic"; /** * 配置对象 */ diff --git a/src/main/java/com/rymcu/forest/lucene/util/ArticleIndexUtil.java b/src/main/java/com/rymcu/forest/lucene/util/ArticleIndexUtil.java index eaeb772..b9b19a4 100644 --- a/src/main/java/com/rymcu/forest/lucene/util/ArticleIndexUtil.java +++ b/src/main/java/com/rymcu/forest/lucene/util/ArticleIndexUtil.java @@ -1,6 +1,7 @@ package com.rymcu.forest.lucene.util; import cn.hutool.core.io.FileUtil; +import cn.hutool.core.util.StrUtil; import com.rymcu.forest.lucene.model.ArticleLucene; import org.apache.lucene.document.Document; import org.apache.lucene.document.Field; @@ -23,8 +24,7 @@ public class ArticleIndexUtil { /** * lucene索引保存目录 */ - private static final String PATH = - System.getProperty("user.dir") + LucenePath.ARTICLE_INDEX_PATH; + private static final String PATH = System.getProperty("user.dir") + StrUtil.SLASH + LucenePath.ARTICLE_INDEX_PATH; /** * 删除所有运行中保存的索引 diff --git a/src/main/java/com/rymcu/forest/lucene/util/LucenePath.java b/src/main/java/com/rymcu/forest/lucene/util/LucenePath.java index d09ba56..4e4414a 100644 --- a/src/main/java/com/rymcu/forest/lucene/util/LucenePath.java +++ b/src/main/java/com/rymcu/forest/lucene/util/LucenePath.java @@ -10,7 +10,7 @@ public final class LucenePath { /** * lucene 目录 */ - public static final String INDEX_PATH = "/lucene/index"; + public static final String INDEX_PATH = "lucene/index"; /** * 文章 lucene 目录 @@ -21,7 +21,7 @@ public final class LucenePath { * 文章增量 lucene 目录 */ public static final String ARTICLE_INCREMENT_INDEX_PATH = - System.getProperty("user.dir") + ARTICLE_INDEX_PATH + "/index777"; + ARTICLE_INDEX_PATH + "/index777"; /** * 用户 lucene 目录 @@ -32,7 +32,7 @@ public final class LucenePath { * 用户增量 lucene 目录 */ public static final String USER_INCREMENT_INDEX_PATH = - System.getProperty("user.dir") + USER_PATH + "/index777"; + USER_PATH + "/index777"; /** * 作品集 lucene 目录 @@ -43,5 +43,5 @@ public final class LucenePath { * 作品集增量 lucene 目录 */ public static final String PORTFOLIO_INCREMENT_INDEX_PATH = - System.getProperty("user.dir") + PORTFOLIO_PATH + "/index777"; + PORTFOLIO_PATH + "/index777"; } diff --git a/src/main/java/com/rymcu/forest/lucene/util/PortfolioIndexUtil.java b/src/main/java/com/rymcu/forest/lucene/util/PortfolioIndexUtil.java index 7b3f84f..7e255e4 100644 --- a/src/main/java/com/rymcu/forest/lucene/util/PortfolioIndexUtil.java +++ b/src/main/java/com/rymcu/forest/lucene/util/PortfolioIndexUtil.java @@ -23,8 +23,7 @@ public class PortfolioIndexUtil { /** * lucene索引保存目录 */ - private static final String PATH = - System.getProperty("user.dir") + StrUtil.SLASH + LucenePath.PORTFOLIO_PATH; + private static final String PATH = System.getProperty("user.dir") + StrUtil.SLASH + LucenePath.PORTFOLIO_PATH; /** * 删除所有运行中保存的索引 @@ -54,7 +53,11 @@ public class PortfolioIndexUtil { System.out.println("创建单个索引"); IndexWriter writer; try { - writer = IndexUtil.getIndexWriter(LucenePath.PORTFOLIO_INCREMENT_INDEX_PATH, false); + boolean create = true; + if (FileUtil.exist(LucenePath.PORTFOLIO_INCREMENT_INDEX_PATH)) { + create = false; + } + writer = IndexUtil.getIndexWriter(LucenePath.PORTFOLIO_INCREMENT_INDEX_PATH, create); Document doc = new Document(); doc.add(new StringField("id", t.getIdPortfolio() + "", Field.Store.YES)); doc.add(new TextField("title", t.getPortfolioTitle(), Field.Store.YES)); @@ -78,6 +81,7 @@ public class PortfolioIndexUtil { try { writer = IndexUtil.getIndexWriter(each.getAbsolutePath(), false); writer.deleteDocuments(new Term("id", String.valueOf(id))); + writer.forceMerge(1); writer.forceMergeDeletes(); // 强制删除 writer.commit(); writer.close(); diff --git a/src/main/java/com/rymcu/forest/lucene/util/UserIndexUtil.java b/src/main/java/com/rymcu/forest/lucene/util/UserIndexUtil.java index 9386324..d876119 100644 --- a/src/main/java/com/rymcu/forest/lucene/util/UserIndexUtil.java +++ b/src/main/java/com/rymcu/forest/lucene/util/UserIndexUtil.java @@ -60,7 +60,11 @@ public class UserIndexUtil { System.out.println("创建单个索引"); IndexWriter writer; try { - writer = IndexUtil.getIndexWriter(INDEX_PATH, false); + boolean create = true; + if (FileUtil.exist(LucenePath.USER_INCREMENT_INDEX_PATH)) { + create = false; + } + writer = IndexUtil.getIndexWriter(INDEX_PATH, create); Document doc = new Document(); doc.add(new StringField("id", t.getIdUser() + "", Field.Store.YES)); doc.add(new TextField("nickname", t.getNickname(), Field.Store.YES)); @@ -85,6 +89,7 @@ public class UserIndexUtil { try { writer = IndexUtil.getIndexWriter(each.getAbsolutePath(), false); writer.deleteDocuments(new Term("id", id)); + writer.forceMerge(1); writer.forceMergeDeletes(); // 强制删除 writer.commit(); writer.close(); diff --git a/src/main/java/com/rymcu/forest/task/BaiDuCronTask.java b/src/main/java/com/rymcu/forest/task/BaiDuCronTask.java deleted file mode 100644 index ce7127f..0000000 --- a/src/main/java/com/rymcu/forest/task/BaiDuCronTask.java +++ /dev/null @@ -1,31 +0,0 @@ -package com.rymcu.forest.task; - -import com.rymcu.forest.core.constant.ProjectConstant; -import com.rymcu.forest.util.BaiDuUtils; -import lombok.extern.slf4j.Slf4j; -import org.springframework.beans.factory.annotation.Value; -import org.springframework.scheduling.annotation.Scheduled; - -/** - * @author ronger - */ -//@Component -@Slf4j -public class BaiDuCronTask { - - @Value("${resource.domain}") - private String domain; - @Value(("${env}")) - private String env; - - /** - * 定时推送首页更新 - */ - @Scheduled(cron = "0 0 10,14,18 * * ?") - public void pushHome() { - if (!ProjectConstant.ENV.equals(env)) { - BaiDuUtils.sendUpdateSEOData(domain); - } - } - -} diff --git a/src/main/resources/application-dev.yml b/src/main/resources/application-dev.yml index 6ab975c..d2f1bea 100644 --- a/src/main/resources/application-dev.yml +++ b/src/main/resources/application-dev.yml @@ -34,7 +34,7 @@ spring: test-while-idle: true test-on-borrow: false test-on-return: false - connection-properties: config.decrypt=true;config.decrypt.key=${publickey} + connection-properties: config.decrypt=true;config.decrypt.key=${publicKey} filters: config,stat max-pool-prepared-statement-per-connection-size: 100 stat-view-servlet: @@ -50,29 +50,6 @@ spring: port: 465 username: service@rymcu.com password: 4W3tCXdyk0Gm -wx: - open: - componentAppId: wx9c4a7dfb3238d5f6 - componentSecret: e32a6f75ab6b746ec3ae38a39a79ba22 - componentToken: rymcu - componentAesKey: NWIwMDQyZjU0YWI2NGFlZThkOWZhZTg3NTg4NzQwN2E - mp: - configs: - - appId: wxf085386aa07c0857 - secret: aabd075d2851764714fd14a0d0b1b8b4 - token: rymcu - aesKey: lvn3mMSnFOvbnIJVNhHQqjWb9swe66L1xIcerJSs0fm - - appId: wxa49093339a5a822b - secret: 29e9390e6d58d57a2b2a2350dbee8754 - token: qwert - aesKey: - miniapp: - configs: - - appid: wxb4fff78a6b878cf7 - secret: c8735d0ccc8497b8509dc2762246cb37 - token: #微信小程序消息服务器配置的token - aesKey: #微信小程序消息服务器配置的EncodingAESKey - msgDataFormat: JSON env: dev logging: file: @@ -85,16 +62,12 @@ server: servlet: context-path: /forest max-http-header-size: 1048576 + shutdown: graceful + tomcat: + reject-illegal-header: false version: 1.0 resource: - domain: http://test.rymcu.com - file-path: http://test.rymcu.com + domain: https://test.rymcu.com + file-path: https://test.rymcu.com pic-path: /opt/nebula/static -baidu: - data: - site: https://rymcu.com - token: 9cdKR6bVCJzxDEJS - ai: - appId: 22891829 - appKey: HKxdO8ioaUmltZh0eaOVMsmW - secretKey: GXOtl3XtiIkVA3CPsc3c29Pqa4V290Yr \ No newline at end of file + answer-api-url: https://test.rymcu.com/subject/question diff --git a/src/main/resources/application.yml b/src/main/resources/application.yml index 99c9014..6c1d560 100644 --- a/src/main/resources/application.yml +++ b/src/main/resources/application.yml @@ -71,12 +71,5 @@ resource: domain: http://yourdomain.com # 网站域名 file-path: http://yourdomain.com # 上传文件前缀域名 pic-path: /yoursrc/xx/nebula/static # 上传文件存储地址 -baidu: - data: - site: https://yourdomain.com # 百度搜索绑定网站域名 - token: xxxx - ai: - appId: xxx # 百度AI-文字识别 应用 appId - appKey: xxxx # 百度AI-文字识别 应用 appKey - secretKey: xxxx # 百度AI-文字识别 应用 secretKey + answer-api-url: https://test.rymcu.com/subject/question