From 327fa30ab826ae582459c60aba68a842d4f9401b Mon Sep 17 00:00:00 2001 From: lanyuanxiaoyao Date: Sun, 22 Dec 2024 22:34:48 +0800 Subject: [PATCH] =?UTF-8?q?feat:=20=E5=A2=9E=E5=8A=A0=E6=AD=A3=E6=96=87?= =?UTF-8?q?=E5=A4=84=E7=90=86=E9=80=BB=E8=BE=91?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../com/lanyuanxiaoyao/bookstore/Entity.kt | 1 - .../com/lanyuanxiaoyao/bookstore/Processor.kt | 60 +++++++++++++++++++ .../bookstore/controller/LineController.kt | 10 ++-- src/main/resources/static/index.html | 54 ++++++++++++++--- 4 files changed, 113 insertions(+), 12 deletions(-) create mode 100644 src/main/kotlin/com/lanyuanxiaoyao/bookstore/Processor.kt diff --git a/src/main/kotlin/com/lanyuanxiaoyao/bookstore/Entity.kt b/src/main/kotlin/com/lanyuanxiaoyao/bookstore/Entity.kt index 828c416..8c76a07 100644 --- a/src/main/kotlin/com/lanyuanxiaoyao/bookstore/Entity.kt +++ b/src/main/kotlin/com/lanyuanxiaoyao/bookstore/Entity.kt @@ -67,7 +67,6 @@ interface BookRepository : JpaRepository, JpaSpecificationExecutor @DynamicUpdate @NamedEntityGraph( name = "chapter.list", attributeNodes = [ - NamedAttributeNode("content"), ] ) class Chapter( diff --git a/src/main/kotlin/com/lanyuanxiaoyao/bookstore/Processor.kt b/src/main/kotlin/com/lanyuanxiaoyao/bookstore/Processor.kt new file mode 100644 index 0000000..e76b0fd --- /dev/null +++ b/src/main/kotlin/com/lanyuanxiaoyao/bookstore/Processor.kt @@ -0,0 +1,60 @@ +package com.lanyuanxiaoyao.bookstore + +// @Configuration +// class ProcessorConfiguration { +// @Bean +// fun processors(): Map = listOf( +// CharWidthProcessor() +// ).associateBy { it.javaClass.name } +// } + +interface Slicer { + fun slice(text: String): List +} + +open class RegexSlicer(private val regex: Regex) : Slicer { + override fun slice(text: String): List { + return text.split(regex) + } +} + +interface Optimization { + fun handle(line: String): String +} + +class CharWidthOptimization : Optimization { + override fun handle(line: String): String { + if (line.isBlank()) return line + return line + .map { char -> + if (char in '!'..'~') + char.code - 65248 + else + char + } + .joinToString("") + } +} + +interface ProcessTemplate { + fun process(text: String): List +} + +open class AbstractProcessTemplate( + private val slicer: Slicer, + private val optimizations: List, +) : ProcessTemplate { + override fun process(text: String): List { + return slicer.slice(text) + .map { line -> + optimizations.fold(line) { result, optimization -> optimization.handle(result) } + } + } +} + +class SexInSexProcessTemplate : AbstractProcessTemplate( + RegexSlicer(Regex("")), + listOf( + CharWidthOptimization(), + ), +) diff --git a/src/main/kotlin/com/lanyuanxiaoyao/bookstore/controller/LineController.kt b/src/main/kotlin/com/lanyuanxiaoyao/bookstore/controller/LineController.kt index 10eac0c..4e8bed9 100644 --- a/src/main/kotlin/com/lanyuanxiaoyao/bookstore/controller/LineController.kt +++ b/src/main/kotlin/com/lanyuanxiaoyao/bookstore/controller/LineController.kt @@ -46,15 +46,15 @@ class LineController { } @Transactional - @PostMapping("save/{lineId}") - fun save(@PathVariable("lineId") lineId: String, @RequestBody item: ViewItem) { - val chapter = chapterRepository.findById(lineId).orElseThrow() + @PostMapping("save/{chapterId}") + fun save(@PathVariable("chapterId") chapterId: String, @RequestBody item: ViewItem) { + val chapter = chapterRepository.findById(chapterId).orElseThrow() lineRepository.save( Line( lineId = item.lineId ?: IdUtil.fastSimpleUUID(), sequence = item.sequence, text = item.text, - newText = null, + newText = item.newText, chapter = chapter, ) ) @@ -83,11 +83,13 @@ class LineController { val lineId: String?, val sequence: Long, val text: String, + val newText: String?, ) { constructor(line: Line) : this( line.lineId, line.sequence, line.text, + line.newText, ) } } \ No newline at end of file diff --git a/src/main/resources/static/index.html b/src/main/resources/static/index.html index ad00eeb..cc4e8b6 100644 --- a/src/main/resources/static/index.html +++ b/src/main/resources/static/index.html @@ -71,21 +71,19 @@ name: 'description', label: '描述', }, - { - name: 'source', - label: '来源', - width: 200, - }, { type: 'operation', label: '操作', fixed: 'right', className: 'nowrap', - width: 300, + width: 250, buttons: [ { type: 'action', label: '跳转', + actionType: 'url', + url: '${source}', + blank: true, }, { type: 'action', @@ -165,6 +163,7 @@ silentPolling: true, body: { type: 'tpl', + className: 'font-serif', tpl: '${item|raw}' } } @@ -255,6 +254,48 @@ className: 'nowrap', width: 100, buttons: [ + { + type: 'action', + label: '处理', + actionType: 'dialog', + dialog: { + title: '文本处理', + size: 'lg', + body: { + debug: true, + type: 'form', + canAccessSuperData: false, + initApi: '${base}/line/detail/${lineId}', + api: '${base}/line/save/${chapterId}', + body: [ + { + type: 'hidden', + name: 'lineId', + }, + { + type: 'textarea', + name: 'text', + label: '正文', + ...formInputClearable(), + showCounter: true, + trimContents: true, + minRows: 5, + maxRows: 5, + }, + { + type: 'textarea', + name: 'newText', + label: '优化后正文', + ...formInputClearable(), + showCounter: true, + trimContents: true, + minRows: 5, + maxRows: 5, + }, + ] + } + } + }, { type: 'action', label: '删除', @@ -307,7 +348,6 @@ { data: { base: 'http://127.0.0.1:23890', - debug: debug, }, }, {