feat: 增加正文处理逻辑
This commit is contained in:
@@ -67,7 +67,6 @@ interface BookRepository : JpaRepository<Book, String>, JpaSpecificationExecutor
|
||||
@DynamicUpdate
|
||||
@NamedEntityGraph(
|
||||
name = "chapter.list", attributeNodes = [
|
||||
NamedAttributeNode("content"),
|
||||
]
|
||||
)
|
||||
class Chapter(
|
||||
|
||||
60
src/main/kotlin/com/lanyuanxiaoyao/bookstore/Processor.kt
Normal file
60
src/main/kotlin/com/lanyuanxiaoyao/bookstore/Processor.kt
Normal 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(),
|
||||
),
|
||||
)
|
||||
@@ -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,
|
||||
)
|
||||
}
|
||||
}
|
||||
@@ -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,
|
||||
},
|
||||
},
|
||||
{
|
||||
|
||||
Reference in New Issue
Block a user