feat(manuscript): 稿件正文增加 content_format 格式标记
- cms_manuscript 新增 content_format(html/markdown/text),默认 html - Manuscript 实体加 contentFormat;保存与修改时缺省按 html 落库,下游不再靠猜 - 迁移脚本幂等,并把明显是 markdown 的历史行标出来
This commit is contained in:
@@ -0,0 +1,40 @@
|
||||
-- 稿件正文格式标记
|
||||
--
|
||||
-- 背景:cms_manuscript.content 是 longtext,后台 wangEditor 存 HTML,
|
||||
-- 早期从 AI 结果直接粘进来的草稿存的是 markdown(`##`、`**`、`-`)。
|
||||
-- 库里的正文格式没有标记,小程序只能按内容猜,猜错就把标记语言露给用户。
|
||||
-- 加上 content_format 后由写入方声明格式,读取方照标记渲染。
|
||||
--
|
||||
-- 幂等:重复执行只会命中 SELECT 1。
|
||||
|
||||
SET @db = DATABASE();
|
||||
|
||||
SET @sql = IF(
|
||||
EXISTS(
|
||||
SELECT 1 FROM information_schema.COLUMNS
|
||||
WHERE TABLE_SCHEMA = @db AND TABLE_NAME = 'cms_manuscript' AND COLUMN_NAME = 'content_format'
|
||||
),
|
||||
'SELECT 1',
|
||||
'ALTER TABLE cms_manuscript ADD COLUMN content_format VARCHAR(16) NOT NULL DEFAULT ''html'' COMMENT ''正文格式:html/markdown/text'' AFTER content'
|
||||
);
|
||||
PREPARE stmt FROM @sql;
|
||||
EXECUTE stmt;
|
||||
DEALLOCATE PREPARE stmt;
|
||||
|
||||
-- 把明显是 markdown 的历史行标出来(默认 html 不动)。
|
||||
-- 标成 markdown 的行不需要批量改写正文:读取方都以这列为准——
|
||||
-- 小程序用 mp-html 的 markdown 插件渲染,后台编辑弹窗用 bytemd 转成 HTML 再编辑,
|
||||
-- 保存后自然变成 html。这列只是把「猜格式」变成「读声明」。
|
||||
UPDATE cms_manuscript
|
||||
SET content_format = 'markdown'
|
||||
WHERE content_format = 'html'
|
||||
AND content IS NOT NULL
|
||||
AND TRIM(content) <> ''
|
||||
AND content NOT LIKE '<%'
|
||||
AND (
|
||||
content REGEXP '(^|\n)[ \t]{0,3}#{1,6}[ \t]'
|
||||
OR content REGEXP '(^|\n)[ \t]{0,3}[-*+][ \t]'
|
||||
OR content REGEXP '(^|\n)[ \t]{0,3}[0-9]+\\.[ \t]'
|
||||
OR content REGEXP '(^|\n)[ \t]{0,3}>[ \t]'
|
||||
OR content LIKE '%**%'
|
||||
);
|
||||
@@ -19,6 +19,7 @@ import com.gxwebsoft.gxmu.service.ReviewListService;
|
||||
import io.swagger.annotations.Api;
|
||||
import io.swagger.annotations.ApiOperation;
|
||||
import org.springframework.security.access.prepost.PreAuthorize;
|
||||
import org.springframework.util.StringUtils;
|
||||
import org.springframework.web.bind.annotation.*;
|
||||
|
||||
import javax.annotation.Resource;
|
||||
@@ -67,6 +68,7 @@ public class ManuscriptController extends BaseController {
|
||||
@ApiOperation("添加稿件")
|
||||
@PostMapping()
|
||||
public ApiResult<?> save(@RequestBody Manuscript manuscript) {
|
||||
normalizeContentFormat(manuscript);
|
||||
// 记录当前登录用户id
|
||||
User loginUser = getLoginUser();
|
||||
if (loginUser != null) {
|
||||
@@ -98,6 +100,7 @@ public class ManuscriptController extends BaseController {
|
||||
@ApiOperation("修改稿件")
|
||||
@PutMapping()
|
||||
public ApiResult<?> update(@RequestBody Manuscript manuscript) {
|
||||
normalizeContentFormat(manuscript);
|
||||
if (manuscriptService.updateById(manuscript)) {
|
||||
return success("修改成功");
|
||||
}
|
||||
@@ -113,6 +116,17 @@ public class ManuscriptController extends BaseController {
|
||||
return fail("删除失败");
|
||||
}
|
||||
|
||||
/**
|
||||
* 正文格式兜底:客户端没带 contentFormat 时按 html 存,
|
||||
* 避免下游(小程序、后台列表)拿到空值又得靠内容猜格式。
|
||||
* 实际上写库前正文应已统一成 HTML(后台编辑器保存时转换)。
|
||||
*/
|
||||
private void normalizeContentFormat(Manuscript manuscript) {
|
||||
if (!StringUtils.hasText(manuscript.getContentFormat())) {
|
||||
manuscript.setContentFormat("html");
|
||||
}
|
||||
}
|
||||
|
||||
@ApiOperation("批量添加稿件")
|
||||
@PostMapping("/batch")
|
||||
public ApiResult<?> saveBatch(@RequestBody List<Manuscript> list) {
|
||||
|
||||
@@ -32,6 +32,9 @@ public class Manuscript implements Serializable {
|
||||
|
||||
private String content;
|
||||
|
||||
@ApiModelProperty(value = "正文格式:html/markdown/text")
|
||||
private String contentFormat;
|
||||
|
||||
private String cover;
|
||||
|
||||
@ApiModelProperty(value = "是否删除, 0否, 1是")
|
||||
|
||||
Reference in New Issue
Block a user