feat: 增加正文处理逻辑
This commit is contained in:
@@ -67,7 +67,6 @@ interface BookRepository : JpaRepository<Book, String>, JpaSpecificationExecutor
|
|||||||
@DynamicUpdate
|
@DynamicUpdate
|
||||||
@NamedEntityGraph(
|
@NamedEntityGraph(
|
||||||
name = "chapter.list", attributeNodes = [
|
name = "chapter.list", attributeNodes = [
|
||||||
NamedAttributeNode("content"),
|
|
||||||
]
|
]
|
||||||
)
|
)
|
||||||
class Chapter(
|
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
|
@Transactional
|
||||||
@PostMapping("save/{lineId}")
|
@PostMapping("save/{chapterId}")
|
||||||
fun save(@PathVariable("lineId") lineId: String, @RequestBody item: ViewItem) {
|
fun save(@PathVariable("chapterId") chapterId: String, @RequestBody item: ViewItem) {
|
||||||
val chapter = chapterRepository.findById(lineId).orElseThrow()
|
val chapter = chapterRepository.findById(chapterId).orElseThrow()
|
||||||
lineRepository.save(
|
lineRepository.save(
|
||||||
Line(
|
Line(
|
||||||
lineId = item.lineId ?: IdUtil.fastSimpleUUID(),
|
lineId = item.lineId ?: IdUtil.fastSimpleUUID(),
|
||||||
sequence = item.sequence,
|
sequence = item.sequence,
|
||||||
text = item.text,
|
text = item.text,
|
||||||
newText = null,
|
newText = item.newText,
|
||||||
chapter = chapter,
|
chapter = chapter,
|
||||||
)
|
)
|
||||||
)
|
)
|
||||||
@@ -83,11 +83,13 @@ class LineController {
|
|||||||
val lineId: String?,
|
val lineId: String?,
|
||||||
val sequence: Long,
|
val sequence: Long,
|
||||||
val text: String,
|
val text: String,
|
||||||
|
val newText: String?,
|
||||||
) {
|
) {
|
||||||
constructor(line: Line) : this(
|
constructor(line: Line) : this(
|
||||||
line.lineId,
|
line.lineId,
|
||||||
line.sequence,
|
line.sequence,
|
||||||
line.text,
|
line.text,
|
||||||
|
line.newText,
|
||||||
)
|
)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@@ -71,21 +71,19 @@
|
|||||||
name: 'description',
|
name: 'description',
|
||||||
label: '描述',
|
label: '描述',
|
||||||
},
|
},
|
||||||
{
|
|
||||||
name: 'source',
|
|
||||||
label: '来源',
|
|
||||||
width: 200,
|
|
||||||
},
|
|
||||||
{
|
{
|
||||||
type: 'operation',
|
type: 'operation',
|
||||||
label: '操作',
|
label: '操作',
|
||||||
fixed: 'right',
|
fixed: 'right',
|
||||||
className: 'nowrap',
|
className: 'nowrap',
|
||||||
width: 300,
|
width: 250,
|
||||||
buttons: [
|
buttons: [
|
||||||
{
|
{
|
||||||
type: 'action',
|
type: 'action',
|
||||||
label: '跳转',
|
label: '跳转',
|
||||||
|
actionType: 'url',
|
||||||
|
url: '${source}',
|
||||||
|
blank: true,
|
||||||
},
|
},
|
||||||
{
|
{
|
||||||
type: 'action',
|
type: 'action',
|
||||||
@@ -165,6 +163,7 @@
|
|||||||
silentPolling: true,
|
silentPolling: true,
|
||||||
body: {
|
body: {
|
||||||
type: 'tpl',
|
type: 'tpl',
|
||||||
|
className: 'font-serif',
|
||||||
tpl: '${item|raw}'
|
tpl: '${item|raw}'
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@@ -255,6 +254,48 @@
|
|||||||
className: 'nowrap',
|
className: 'nowrap',
|
||||||
width: 100,
|
width: 100,
|
||||||
buttons: [
|
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',
|
type: 'action',
|
||||||
label: '删除',
|
label: '删除',
|
||||||
@@ -307,7 +348,6 @@
|
|||||||
{
|
{
|
||||||
data: {
|
data: {
|
||||||
base: 'http://127.0.0.1:23890',
|
base: 'http://127.0.0.1:23890',
|
||||||
debug: debug,
|
|
||||||
},
|
},
|
||||||
},
|
},
|
||||||
{
|
{
|
||||||
|
|||||||
Reference in New Issue
Block a user