From f75fac3aaaf1e3783f2edb4d4e3261ffda7f9499 Mon Sep 17 00:00:00 2001
From: Helius <wangdoubleone@gmail.com>
Date: Tue, 16 Aug 2022 16:19:53 +0800
Subject: [PATCH] fix
---
src/main/java/com/xcong/farmer/cms/modules/system/dto/AdminUpdateArticleDto.java | 3 +
src/main/java/com/xcong/farmer/cms/modules/system/dto/AdminAddArticleDto.java | 3 +
src/main/java/com/xcong/farmer/cms/core/template/TemplateConfiguration.java | 32 +++++++++-------
src/main/java/com/xcong/farmer/cms/modules/core/controller/CmsCoreController.java | 10 ++--
src/main/java/com/xcong/farmer/cms/modules/system/service/Impl/ArticleServiceImpl.java | 15 ++++++-
src/main/resources/application-test.yml | 16 +++++--
pom.xml | 7 +++
src/main/java/com/xcong/farmer/cms/FarmerCmsApplication.java | 3 +
src/main/java/com/xcong/farmer/cms/common/contants/AppContants.java | 2
src/main/resources/application.yml | 19 ++++++---
10 files changed, 74 insertions(+), 36 deletions(-)
diff --git a/pom.xml b/pom.xml
index a96d29e..21ddd22 100644
--- a/pom.xml
+++ b/pom.xml
@@ -107,7 +107,6 @@
<dependency>
<groupId>mysql</groupId>
<artifactId>mysql-connector-java</artifactId>
- <version>${mysql-driver.version}</version>
</dependency>
<!-- 参数校验 start -->
@@ -280,6 +279,12 @@
<version>1.9</version>
</dependency>
+ <dependency>
+ <groupId>com.baomidou</groupId>
+ <artifactId>dynamic-datasource-spring-boot-starter</artifactId>
+ <version>3.0.0</version>
+ </dependency>
+
<!-- 控制台 SQL日志打印插件 -->
<dependency>
<groupId>p6spy</groupId>
diff --git a/src/main/java/com/xcong/farmer/cms/FarmerCmsApplication.java b/src/main/java/com/xcong/farmer/cms/FarmerCmsApplication.java
index 1ee1f2f..3019699 100644
--- a/src/main/java/com/xcong/farmer/cms/FarmerCmsApplication.java
+++ b/src/main/java/com/xcong/farmer/cms/FarmerCmsApplication.java
@@ -1,5 +1,6 @@
package com.xcong.farmer.cms;
+import com.alibaba.druid.spring.boot.autoconfigure.DruidDataSourceAutoConfigure;
import com.xcong.farmer.cms.netty.server.WebSocketServer;
import org.mybatis.spring.annotation.MapperScan;
import org.springframework.beans.factory.annotation.Autowired;
@@ -12,7 +13,7 @@
* @author helius
*/
@EnableSwagger2
-@SpringBootApplication
+@SpringBootApplication(exclude = DruidDataSourceAutoConfigure.class)
@MapperScan("com.xcong.farmer.cms.modules.*.mapper")
@MapperScan("com.xcong.farmer.cms.modules.*.dao")
public class FarmerCmsApplication implements CommandLineRunner {
diff --git a/src/main/java/com/xcong/farmer/cms/common/contants/AppContants.java b/src/main/java/com/xcong/farmer/cms/common/contants/AppContants.java
index 52bc8f1..1477fa6 100644
--- a/src/main/java/com/xcong/farmer/cms/common/contants/AppContants.java
+++ b/src/main/java/com/xcong/farmer/cms/common/contants/AppContants.java
@@ -33,7 +33,7 @@
public static final String PICTURE_PATH = "D:\\Tools\\";
- public static final Executor EXECUTOR = new ThreadPoolExecutor(15, 30, 600, TimeUnit.SECONDS, new LinkedBlockingQueue<Runnable>());
+ public static final Executor EXECUTOR = new ThreadPoolExecutor(10, 30, 600, TimeUnit.SECONDS, new LinkedBlockingQueue<Runnable>());
}
diff --git a/src/main/java/com/xcong/farmer/cms/core/template/TemplateConfiguration.java b/src/main/java/com/xcong/farmer/cms/core/template/TemplateConfiguration.java
index 05e363f..e4ca7ce 100644
--- a/src/main/java/com/xcong/farmer/cms/core/template/TemplateConfiguration.java
+++ b/src/main/java/com/xcong/farmer/cms/core/template/TemplateConfiguration.java
@@ -18,7 +18,7 @@
* @date 2022-07-01
**/
@Slf4j
-public class TemplateConfiguration extends Configuration{
+public class TemplateConfiguration extends Configuration {
private TemplateLoader templateLoader;
@@ -36,21 +36,25 @@
}
map.put("apiUrl", API_URL);
- String companyCode = (String) map.get("companyCode");
+ try {
+ String companyCode = (String) map.get("companyCode");
- log.info("解析开始执行--#类型:{}#--#模板名称:{}#--#ID:{}#", map.get("templateType"), templateName, map.get("id"));
- this.templateLoader.data(map);
- Template template = template(FileUtils.path(templatePath, companyCode), templateName);
- template.output(outputPath);
-
- // 判断是否有分页,有则执行。从第二页开始
- int i = 2;
- while(Template.HAS_PAGING) {
- map.put("page", i);
+ log.info("解析开始执行--#类型:{}#--#模板名称:{}#--#ID:{}#", map.get("templateType"), templateName, map.get("id"));
this.templateLoader.data(map);
- Template pageTemplate = template(FileUtils.path(templatePath, companyCode), templateName);
- pageTemplate.output(outputPath);
- i++;
+ Template template = template(FileUtils.path(templatePath, companyCode), templateName);
+ template.output(outputPath);
+
+ // 判断是否有分页,有则执行。从第二页开始
+ int i = 2;
+ while (Template.HAS_PAGING) {
+ map.put("page", i);
+ this.templateLoader.data(map);
+ Template pageTemplate = template(FileUtils.path(templatePath, companyCode), templateName);
+ pageTemplate.output(outputPath);
+ i++;
+ }
+ } catch (Exception e) {
+ log.error("页面编译异常", e);
}
}
diff --git a/src/main/java/com/xcong/farmer/cms/modules/core/controller/CmsCoreController.java b/src/main/java/com/xcong/farmer/cms/modules/core/controller/CmsCoreController.java
index 23f8b67..821ad8a 100644
--- a/src/main/java/com/xcong/farmer/cms/modules/core/controller/CmsCoreController.java
+++ b/src/main/java/com/xcong/farmer/cms/modules/core/controller/CmsCoreController.java
@@ -18,7 +18,7 @@
**/
@Slf4j
@RestController
-@RequestMapping(value = "/api")
+@RequestMapping(value = "/cms")
@Api(value = "CmsCoreController", tags = "CMS核心类")
public class CmsCoreController {
@@ -28,8 +28,8 @@
@ApiOperation(value = "发布文章", notes = "发布文章")
@PostMapping(value = "releaseArticle/{id}")
public Result releaseArticle(@PathVariable("id") Long id) {
- Long companyId = LoginUserUtil.getCompanyId();
-// Long companyId = 24L;
+// Long companyId = LoginUserUtil.getCompanyId();
+ Long companyId = 26L;
releaseService.releaseArticle(id, companyId);
return Result.ok("success");
}
@@ -55,8 +55,8 @@
@ApiOperation(value = "发布全站", notes = "发布全站")
@PostMapping(value = "/releaseAll")
public Result releaseAll() {
- Long companyId = LoginUserUtil.getCompanyId();
-// Long companyId = 24L;
+// Long companyId = LoginUserUtil.getCompanyId();
+ Long companyId = 26L;
releaseService.releaseAll(companyId);
return Result.ok("发布成功");
}
diff --git a/src/main/java/com/xcong/farmer/cms/modules/system/dto/AdminAddArticleDto.java b/src/main/java/com/xcong/farmer/cms/modules/system/dto/AdminAddArticleDto.java
index e0637fe..8113bc8 100644
--- a/src/main/java/com/xcong/farmer/cms/modules/system/dto/AdminAddArticleDto.java
+++ b/src/main/java/com/xcong/farmer/cms/modules/system/dto/AdminAddArticleDto.java
@@ -68,4 +68,7 @@
@ApiModelProperty(value = "内容类型 1:文章 2:图片 3:文件 4:音频")
private Integer contentType;
+
+ @ApiModelProperty(value = "保存状态 1-仅保存 2-保存并发布")
+ private Integer saveState;
}
diff --git a/src/main/java/com/xcong/farmer/cms/modules/system/dto/AdminUpdateArticleDto.java b/src/main/java/com/xcong/farmer/cms/modules/system/dto/AdminUpdateArticleDto.java
index 31ac9bc..fdb75db 100644
--- a/src/main/java/com/xcong/farmer/cms/modules/system/dto/AdminUpdateArticleDto.java
+++ b/src/main/java/com/xcong/farmer/cms/modules/system/dto/AdminUpdateArticleDto.java
@@ -70,4 +70,7 @@
@ApiModelProperty(value = "内容类型 1:文章 2:图片 3:文件 4:音频")
private Integer contentType;
+
+ @ApiModelProperty(value = "保存状态 1-仅保存 2-保存并发布")
+ private Integer saveState;
}
diff --git a/src/main/java/com/xcong/farmer/cms/modules/system/service/Impl/ArticleServiceImpl.java b/src/main/java/com/xcong/farmer/cms/modules/system/service/Impl/ArticleServiceImpl.java
index 13427ba..29928a0 100644
--- a/src/main/java/com/xcong/farmer/cms/modules/system/service/Impl/ArticleServiceImpl.java
+++ b/src/main/java/com/xcong/farmer/cms/modules/system/service/Impl/ArticleServiceImpl.java
@@ -132,6 +132,10 @@
articleEntity.setType(adminAddArticleDto.getType());
articleEntity.setContentType(adminAddArticleDto.getContentType());
this.baseMapper.insert(articleEntity);
+
+ if (adminAddArticleDto.getSaveState() == 2) {
+ releaseService.releaseArticle(articleEntity.getId(), articleEntity.getCompanyId());
+ }
return Result.ok("添加成功");
}
@@ -211,6 +215,10 @@
String authorBelong = adminUpdateArticleDto.getAuthorBelong();
articleEntity.setAuthorBelong(authorBelong);
this.baseMapper.updateById(articleEntity);
+
+ if (adminUpdateArticleDto.getSaveState() == 2) {
+ releaseService.releaseArticle(articleEntity.getId(), articleEntity.getCompanyId());
+ }
return Result.ok("更新成功");
}
@@ -223,8 +231,11 @@
Long articleId = Long.valueOf(articleIdStr);
ArticleEntity articleEntity = this.baseMapper.selectById(articleId);
- articleEntity.setDelStatus(ArticleEntity.DELETE_STATUS_YES);
- this.baseMapper.updateById(articleEntity);
+// articleEntity.setDelStatus(ArticleEntity.DELETE_STATUS_YES);
+// this.baseMapper.updateById(articleEntity);
+ if (articleEntity != null) {
+ this.baseMapper.deleteById(articleId);
+ }
}
}
return Result.ok("删除成功");
diff --git a/src/main/resources/application-test.yml b/src/main/resources/application-test.yml
index e207ce1..9e488dc 100644
--- a/src/main/resources/application-test.yml
+++ b/src/main/resources/application-test.yml
@@ -10,11 +10,17 @@
async:
request-timeout: 20s
datasource:
- url: jdbc:mysql://120.27.238.55:3306/farmer_cms?useUnicode=true&characterEncoding=utf-8&useSSL=false&serverTimezone=GMT%2b8
- username: ct_test
- password: 123456
- driver-class-name: com.mysql.jdbc.Driver
- type: com.alibaba.druid.pool.DruidDataSource
+ dynamic:
+ # 是否开启 SQL日志输出,生产环境建议关闭,有性能损耗
+ p6spy: false
+ # 配置默认数据源
+ primary: base
+ datasource:
+ base:
+ url: jdbc:mysql://120.27.238.55:3306/farmer_cms?useUnicode=true&characterEncoding=utf-8&useSSL=false&serverTimezone=GMT%2b8
+ username: ct_test
+ password: 123456
+ driver-class-name: com.mysql.cj.jdbc.Driver
druid:
initial-size: ${spring_datasource_druid_initial_size:10}
max-active: ${spring_datasource_druid_max_active:20}
diff --git a/src/main/resources/application.yml b/src/main/resources/application.yml
index 4d72940..453c143 100644
--- a/src/main/resources/application.yml
+++ b/src/main/resources/application.yml
@@ -10,13 +10,18 @@
async:
request-timeout: 20s
datasource:
- # 是否开启 SQL日志输出,生产环境建议关闭,有性能损耗
- p6spy: true
- url: jdbc:mysql://120.27.238.55:3306/farmer_cms?useUnicode=true&characterEncoding=utf-8&useSSL=false&serverTimezone=GMT%2b8
- username: ct_test
- password: 123456
- driver-class-name: com.mysql.jdbc.Driver
- type: com.alibaba.druid.pool.DruidDataSource
+ dynamic:
+ # 是否开启 SQL日志输出,生产环境建议关闭,有性能损耗
+ p6spy: true
+ # 配置默认数据源
+ primary: base
+ datasource:
+ base:
+ url: jdbc:mysql://120.27.238.55:3306/farmer_cms?useUnicode=true&characterEncoding=utf-8&useSSL=false&serverTimezone=GMT%2b8
+ username: ct_test
+ password: 123456
+ driver-class-name: com.mysql.jdbc.Driver
+ type: com.alibaba.druid.pool.DruidDataSource
druid:
initial-size: ${spring_datasource_druid_initial_size:10}
max-active: ${spring_datasource_druid_max_active:20}
--
Gitblit v1.9.1