1
0

feat: 增加正文处理逻辑

This commit is contained in:
2024-12-22 22:34:48 +08:00
parent f0e4778034
commit 327fa30ab8
4 changed files with 113 additions and 12 deletions

View File

@@ -67,7 +67,6 @@ interface BookRepository : JpaRepository<Book, String>, JpaSpecificationExecutor
@DynamicUpdate
@NamedEntityGraph(
name = "chapter.list", attributeNodes = [
NamedAttributeNode("content"),
]
)
class Chapter(

View File

@@ -0,0 +1,60 @@
package com.lanyuanxiaoyao.bookstore
// @Configuration
// class ProcessorConfiguration {
// @Bean
// fun processors(): Map<String, Processor> = listOf(
// CharWidthProcessor()
// ).associateBy { it.javaClass.name }
// }
interface Slicer {
fun slice(text: String): List<String>
}
open class RegexSlicer(private val regex: Regex) : Slicer {
override fun slice(text: String): List<String> {
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<String>
}
open class AbstractProcessTemplate(
private val slicer: Slicer,
private val optimizations: List<Optimization>,
) : ProcessTemplate {
override fun process(text: String): List<String> {
return slicer.slice(text)
.map { line ->
optimizations.fold(line) { result, optimization -> optimization.handle(result) }
}
}
}
class SexInSexProcessTemplate : AbstractProcessTemplate(
RegexSlicer(Regex("")),
listOf(
CharWidthOptimization(),
),
)

View File

@@ -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,
)
}
}

View File

@@ -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,
},
},
{