Skip to content

Commit 61b641a

Browse files
committed
fix(convert json): 修复丢失LocalDateTime 秒 (close #920)
1 parent 1c0b517 commit 61b641a

File tree

8 files changed

+122
-82
lines changed

8 files changed

+122
-82
lines changed

configure/etc/conf/i18n/messages_en.properties

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -123,6 +123,7 @@ source.common.erDiagram=ER Diagram
123123
source.common.type=Data Source Type
124124
source.common.configures=Configuration Information
125125
source.common.generateData=Generate Data
126+
source.common.checkConnection=Check Connection
126127
source.tip.selectSource=Please select a data source.
127128
source.tip.deleteSourceSuccess=Data source [ $NAME ] deleted successfully.
128129
source.tip.deleteAlert1=You are about to delete a data source. This operation will permanently delete all data and configurations related to the data source. Please confirm before proceeding.

configure/etc/conf/i18n/messages_zh-cn.properties

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -123,6 +123,7 @@ source.common.erDiagram=ER \u56FE\u5F62
123123
source.common.type=\u6570\u636E\u6E90\u7C7B\u578B
124124
source.common.configures=\u914D\u7F6E\u4FE1\u606F
125125
source.common.generateData=\u751F\u6210\u6570\u636E
126+
source.common.checkConnection=\u68C0\u67E5\u8FDE\u63A5
126127
source.tip.selectSource=\u8BF7\u9009\u62E9\u6570\u636E\u6E90
127128
source.tip.deleteSourceSuccess=\u5220\u9664\u6570\u636E\u6E90 [ $NAME ] \u6210\u529F
128129
source.tip.deleteAlert1=\u60A8\u6B63\u5728\u5220\u9664\u6570\u636E\u6E90\u3002\u6B64\u64CD\u4F5C\u5C06\u6C38\u4E45\u5220\u9664\u6240\u6709\u4E0E\u8BE5\u6570\u636E\u6E90\u76F8\u5173\u7684\u6570\u636E\u548C\u914D\u7F6E\u3002\u8BF7\u52A1\u5FC5\u5728\u7EE7\u7EED\u64CD\u4F5C\u4E4B\u524D\u786E\u8BA4\u60A8\u7684\u64CD\u4F5C\u3002

convert/datacap-convert-json/src/main/kotlin/io/edurt/datacap/convert/json/JsonConvertService.kt

Lines changed: 15 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -46,7 +46,21 @@ class JsonConvertService : ConvertService
4646
val header = request.headers[headerIndex] as String
4747
when (column)
4848
{
49-
is List<*> -> jsonNode.putPOJO(header, column[headerIndex])
49+
is List<*> ->
50+
{
51+
val value = column[headerIndex]
52+
when (value)
53+
{
54+
is LocalDateTime ->
55+
{
56+
val timeString = value.format(DateTimeFormatter.ofPattern("yyyy-MM-dd HH:mm:ss"))
57+
jsonNode.put(header, timeString)
58+
}
59+
60+
else -> jsonNode.putPOJO(header, value)
61+
}
62+
}
63+
5064
else -> jsonNode.putPOJO(header, column)
5165
}
5266
}
Lines changed: 76 additions & 60 deletions
Original file line numberDiff line numberDiff line change
@@ -1,112 +1,128 @@
11
package io.edurt.datacap.convert.json
22

3-
import com.google.inject.Guice.createInjector
4-
import com.google.inject.Injector
5-
import io.edurt.datacap.convert.ConvertFilter
6-
import io.edurt.datacap.convert.ConvertManager
73
import io.edurt.datacap.convert.model.ConvertRequest
8-
import org.junit.Before
4+
import io.edurt.datacap.plugin.PluginConfigure
5+
import io.edurt.datacap.plugin.PluginManager
6+
import io.edurt.datacap.plugin.utils.PluginPathUtils
7+
import org.junit.Assert.assertNotNull
98
import org.junit.Test
109
import org.slf4j.LoggerFactory.getLogger
1110
import java.io.File
1211
import java.io.FileInputStream
12+
import java.nio.file.Path
13+
import java.time.LocalDateTime
14+
import java.time.format.DateTimeFormatter
1315
import kotlin.test.assertTrue
1416

17+
1518
class JsonConvertTest
1619
{
1720
private val log = getLogger(this::class.java)
1821
private val name = "JsonConvert"
19-
private var injector: Injector? = null
22+
private val pluginManager: PluginManager
2023
private val request: ConvertRequest = ConvertRequest()
2124

22-
@Before
23-
fun before()
25+
init
2426
{
25-
injector = createInjector(ConvertManager())
27+
val projectRoot: Path = PluginPathUtils.findProjectRoot()
28+
val config: PluginConfigure? = PluginConfigure.builder()
29+
.pluginsDir(projectRoot.resolve("convert/datacap-convert-json"))
30+
.scanDepth(2)
31+
.build()
32+
33+
pluginManager = PluginManager(config)
34+
pluginManager.start()
2635

2736
request.name = "test"
2837
request.path = System.getProperty("user.dir")
29-
request.headers = listOf("name", "age")
38+
request.headers = listOf("name", "age", "datatime")
3039

31-
val l1 = listOf("Test", 12)
32-
val l2 = listOf("Test1", 121)
40+
val timeString = LocalDateTime.parse("2023-12-01T10:30:00").format(DateTimeFormatter.ISO_LOCAL_DATE_TIME)
41+
val l1 = listOf("Test", 12, timeString)
42+
val l2 = listOf("Test1", 121, timeString)
43+
request.columns = listOf(l1, l2)
3344
request.columns = listOf(l1, l2)
3445
}
3546

3647
@Test
3748
fun testFormat()
3849
{
39-
injector?.let { injector ->
40-
ConvertFilter.filter(injector, name)
41-
.ifPresent { file ->
42-
val response = file.format(request)
43-
log.info("headers: [ ${response.headers} ]")
44-
response.columns
45-
.let { columns ->
46-
columns.forEachIndexed { index, line ->
47-
log.info("index: [ $index ], line: [ $line ]")
48-
}
49-
}
50+
pluginManager.getPlugin(name)
51+
.ifPresent { plugin ->
52+
val service = plugin.getService(JsonConvertService::class.java)
53+
assertNotNull(service)
5054

51-
assertTrue {
52-
response.successful == true
55+
val response = service.format(request)
56+
log.info("headers: [ ${response.headers} ]")
57+
response.columns
58+
.let { columns ->
59+
columns.forEachIndexed { index, line ->
60+
log.info("index: [ $index ], line: [ $line ]")
61+
}
5362
}
63+
64+
assertTrue {
65+
response.successful == true
5466
}
55-
}
67+
}
5668
}
5769

5870
@Test
5971
fun testFormatStream()
6072
{
61-
injector?.let { injector ->
62-
ConvertFilter.filter(injector, name)
63-
.ifPresent { file ->
64-
request.stream = FileInputStream(File("${System.getProperty("user.dir")}/${request.name}.json"))
65-
val response = file.formatStream(request)
66-
log.info("headers: [ ${response.headers} ]")
67-
response.columns
68-
.let { columns ->
69-
columns.forEachIndexed { index, line ->
70-
log.info("index: [ $index ], line: [ $line ]")
71-
}
73+
pluginManager.getPlugin(name)
74+
.ifPresent { plugin ->
75+
val service = plugin.getService(JsonConvertService::class.java)
76+
assertNotNull(service)
77+
78+
request.stream = FileInputStream(File("${System.getProperty("user.dir")}/${request.name}.json"))
79+
val response = service.formatStream(request)
80+
log.info("headers: [ ${response.headers} ]")
81+
response.columns
82+
.let { columns ->
83+
columns.forEachIndexed { index, line ->
84+
log.info("index: [ $index ], line: [ $line ]")
7285
}
73-
assertTrue {
74-
response.successful == true
7586
}
87+
assertTrue {
88+
response.successful == true
7689
}
77-
}
90+
}
7891
}
7992

8093
@Test
8194
fun testWriter()
8295
{
83-
injector?.let { injector ->
84-
ConvertFilter.filter(injector, name)
85-
.ifPresent { file ->
86-
assertTrue {
87-
file.writer(request)
88-
.successful == true
89-
}
96+
pluginManager.getPlugin(name)
97+
.ifPresent { plugin ->
98+
val service = plugin.getService(JsonConvertService::class.java)
99+
assertNotNull(service)
100+
101+
assertTrue {
102+
service.writer(request).successful == true
90103
}
91-
}
104+
}
92105
}
93106

94107
@Test
95108
fun testReader()
96109
{
97-
injector?.let { injector ->
98-
ConvertFilter.filter(injector, name)
99-
.ifPresent { file ->
100-
val response = file.reader(request)
101-
log.info("headers: ${response.headers}")
102-
response.columns
103-
.forEach {
104-
log.info("columns: $it")
105-
}
106-
assertTrue {
107-
response.successful == true
110+
pluginManager.getPlugin(name)
111+
.ifPresent { plugin ->
112+
val service = plugin.getService(JsonConvertService::class.java)
113+
assertNotNull(service)
114+
115+
service.writer(request)
116+
117+
val response = service.reader(request)
118+
log.info("headers: ${response.headers}")
119+
response.columns
120+
.forEach {
121+
log.info("columns: $it")
108122
}
123+
assertTrue {
124+
response.successful == true
109125
}
110-
}
126+
}
111127
}
112128
}
Lines changed: 20 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -1,27 +1,31 @@
11
package io.edurt.datacap.convert.json
22

3-
import com.google.inject.Guice.createInjector
4-
import com.google.inject.Injector
5-
import com.google.inject.Key
6-
import com.google.inject.TypeLiteral
7-
import io.edurt.datacap.convert.Convert
8-
import io.edurt.datacap.convert.ConvertManager
9-
import org.junit.Assert.assertEquals
3+
import io.edurt.datacap.plugin.PluginConfigure
4+
import io.edurt.datacap.plugin.PluginManager
5+
import io.edurt.datacap.plugin.utils.PluginPathUtils
6+
import lombok.extern.slf4j.Slf4j
107
import org.junit.Test
118

12-
class JsonModuleTest
9+
@Slf4j
10+
class XmlConvertPluginTest
1311
{
14-
private val injector: Injector = createInjector(ConvertManager())
12+
private val pluginManager: PluginManager
13+
private val pluginName: String = "JsonConvert"
14+
15+
init
16+
{
17+
val projectRoot = PluginPathUtils.findProjectRoot()
18+
val config = PluginConfigure.builder()
19+
.pluginsDir(projectRoot.resolve("convert/datacap-convert-json"))
20+
.scanDepth(2)
21+
.build()
22+
23+
pluginManager = PluginManager(config).apply { start() }
24+
}
1525

1626
@Test
1727
fun test()
1828
{
19-
injector.getInstance(Key.get(object : TypeLiteral<Set<Convert>>()
20-
{}))
21-
.stream()
22-
.findFirst()
23-
.ifPresent {
24-
assertEquals("JsonConvert", it.name())
25-
}
29+
println(pluginManager.getPlugin(pluginName))
2630
}
2731
}

convert/datacap-convert-spi/src/main/kotlin/io/edurt/datacap/convert/ConvertService.kt

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -10,7 +10,7 @@ interface ConvertService : Service
1010
{
1111
return this.javaClass
1212
.simpleName
13-
.removeSuffix("Convert")
13+
.removeSuffix("ConvertService")
1414
}
1515

1616
fun description(): String

core/datacap-ui/src/views/pages/admin/source/SourceHome.vue

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -99,14 +99,16 @@
9999
@on-change="onPageChange"
100100
@on-prev="onPrevChange"
101101
@on-next="onNextChange"
102-
@on-change-size="onSizeChange"/>
102+
@on-change-size="onSizeChange">
103+
</ShadcnPagination>
103104
</div>
104105
</ShadcnCard>
105106

106107
<SourceInfo v-if="dataInfoVisible"
107108
:is-visible="dataInfoVisible"
108109
:info="dataInfo"
109-
@close="visibleInfo(false, null)"/>
110+
@close="visibleInfo(false, null)">
111+
</SourceInfo>
110112

111113
<SourceDelete v-if="dataDeleteVisible"
112114
:is-visible="dataDeleteVisible"

core/datacap-ui/src/views/pages/admin/wofkflow/WorkflowInfo.vue

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -15,7 +15,8 @@
1515
<ShadcnSelectOption v-for="executor in installedExecutors"
1616
:key="executor.name"
1717
:label="executor.name"
18-
:value="executor.name"/>
18+
:value="executor.name">
19+
</ShadcnSelectOption>
1920
</template>
2021
</ShadcnSelect>
2122
</div>
@@ -34,7 +35,8 @@
3435
:categories="configuration.categories"
3536
:nodes="configuration.nodes"
3637
:connections="[]"
37-
:configureWidth="380"/>
38+
:configureWidth="380">
39+
</ShadcnWorkflowEditor>
3840
</div>
3941
</ShadcnCard>
4042
</div>

0 commit comments

Comments
 (0)