From 98e2f637d293788f87f783992d09dc21f9d9954c Mon Sep 17 00:00:00 2001 From: FatttSnake Date: Mon, 22 Jan 2024 18:18:47 +0800 Subject: [PATCH] Optimize ToolBase and ToolTemplate api --- .../api/controller/tool/BaseController.kt | 5 -- .../converter/tool/ToolTemplateConverter.kt | 4 +- .../oxygen/api/entity/tool/ToolTemplate.kt | 24 ++------- .../oxygen/api/mapper/tool/ToolBaseMapper.kt | 2 - .../api/param/tool/ToolTemplateAddParam.kt | 11 +--- .../api/param/tool/ToolTemplateUpdateParam.kt | 6 --- .../api/service/tool/IToolBaseService.kt | 2 - .../service/tool/impl/ToolBaseServiceImpl.kt | 3 +- .../tool/impl/ToolTemplateServiceImpl.kt | 13 +---- .../oxygen/api/vo/tool/ToolTemplateVo.kt | 7 +-- ..._240119__Add_table_'t_b_tool_template'.sql | 2 - .../resources/mapper/tool/ToolBaseMapper.xml | 32 ++--------- .../mapper/tool/ToolTemplateMapper.xml | 53 ++++++------------- 13 files changed, 29 insertions(+), 135 deletions(-) diff --git a/src/main/kotlin/top/fatweb/oxygen/api/controller/tool/BaseController.kt b/src/main/kotlin/top/fatweb/oxygen/api/controller/tool/BaseController.kt index 48d5cb4..5d14167 100644 --- a/src/main/kotlin/top/fatweb/oxygen/api/controller/tool/BaseController.kt +++ b/src/main/kotlin/top/fatweb/oxygen/api/controller/tool/BaseController.kt @@ -25,11 +25,6 @@ class BaseController( fun get(): ResponseResult> = ResponseResult.databaseSuccess(data = toolBaseService.get()) - @Operation(summary = "获取基板列表") - @GetMapping("/list") - fun getList(): ResponseResult> = - ResponseResult.databaseSuccess(data = toolBaseService.getList()) - @Operation(summary = "新增基板") @PostMapping fun add(@RequestBody @Valid toolBaseAddParam: ToolBaseAddParam): ResponseResult = diff --git a/src/main/kotlin/top/fatweb/oxygen/api/converter/tool/ToolTemplateConverter.kt b/src/main/kotlin/top/fatweb/oxygen/api/converter/tool/ToolTemplateConverter.kt index 391a857..3244ed7 100644 --- a/src/main/kotlin/top/fatweb/oxygen/api/converter/tool/ToolTemplateConverter.kt +++ b/src/main/kotlin/top/fatweb/oxygen/api/converter/tool/ToolTemplateConverter.kt @@ -7,10 +7,8 @@ object ToolTemplateConverter { fun toolTemplateToToolTemplateVo(toolTemplate: ToolTemplate) = ToolTemplateVo( id = toolTemplate.id, name = toolTemplate.name, - ver = toolTemplate.ver, - baseId = toolTemplate.baseId, + base = toolTemplate.base?.let(ToolBaseConverter::toolBaseToToolBaseVo), source = toolTemplate.source?.let(ToolDataConverter::toolDataToToolDataVo), - dist = toolTemplate.dist?.let(ToolDataConverter::toolDataToToolDataVo), createTime = toolTemplate.createTime, updateTime = toolTemplate.updateTime, enable = toolTemplate.enable == 1 diff --git a/src/main/kotlin/top/fatweb/oxygen/api/entity/tool/ToolTemplate.kt b/src/main/kotlin/top/fatweb/oxygen/api/entity/tool/ToolTemplate.kt index ad1a41e..1fcbdd4 100644 --- a/src/main/kotlin/top/fatweb/oxygen/api/entity/tool/ToolTemplate.kt +++ b/src/main/kotlin/top/fatweb/oxygen/api/entity/tool/ToolTemplate.kt @@ -29,15 +29,6 @@ class ToolTemplate { @TableField("name") var name: String? = null - /** - * ver - * - * @author FatttSnake, fatttsnake@gmail.com - * @since 1.0.0 - */ - @TableField("ver") - var ver: String? = null - /** * Base ID * @@ -56,15 +47,6 @@ class ToolTemplate { @TableField("source_id") var sourceId: Long? = null - /** - * Dist ID - * - * @author FatttSnake, fatttsnake@gmail.com - * @since 1.0.0 - */ - @TableField("dist_id") - var distId: Long? = null - /** * Enable * @@ -124,15 +106,15 @@ class ToolTemplate { var source: ToolData? = null /** - * Dist + * Base * * @author FatttSnake, fatttsnake@gmail.com * @since 1.0.0 */ @TableField(exist = false) - var dist: ToolData? = null + var base: ToolBase? = null override fun toString(): String { - return "ToolTemplate(id=$id, name=$name, ver=$ver, baseId=$baseId, sourceId=$sourceId, distId=$distId, createTime=$createTime, updateTime=$updateTime, deleted=$deleted, version=$version)" + return "ToolTemplate(id=$id, name=$name, baseId=$baseId, sourceId=$sourceId, enable=$enable, createTime=$createTime, updateTime=$updateTime, deleted=$deleted, version=$version, source=$source, base=$base)" } } \ No newline at end of file diff --git a/src/main/kotlin/top/fatweb/oxygen/api/mapper/tool/ToolBaseMapper.kt b/src/main/kotlin/top/fatweb/oxygen/api/mapper/tool/ToolBaseMapper.kt index d79f84d..51f9d82 100644 --- a/src/main/kotlin/top/fatweb/oxygen/api/mapper/tool/ToolBaseMapper.kt +++ b/src/main/kotlin/top/fatweb/oxygen/api/mapper/tool/ToolBaseMapper.kt @@ -16,6 +16,4 @@ import top.fatweb.oxygen.api.entity.tool.ToolBase @Mapper interface ToolBaseMapper : BaseMapper { fun selectOne(@Param("id") id: Long): ToolBase? - - fun selectList(): List } \ No newline at end of file diff --git a/src/main/kotlin/top/fatweb/oxygen/api/param/tool/ToolTemplateAddParam.kt b/src/main/kotlin/top/fatweb/oxygen/api/param/tool/ToolTemplateAddParam.kt index ad96aec..f1d8a66 100644 --- a/src/main/kotlin/top/fatweb/oxygen/api/param/tool/ToolTemplateAddParam.kt +++ b/src/main/kotlin/top/fatweb/oxygen/api/param/tool/ToolTemplateAddParam.kt @@ -2,24 +2,15 @@ package top.fatweb.oxygen.api.param.tool import jakarta.validation.constraints.NotBlank import jakarta.validation.constraints.NotNull -import jakarta.validation.constraints.Pattern data class ToolTemplateAddParam( @field: NotBlank(message = "Name can not be blank") val name: String?, - @field: NotBlank(message = "Ver can not be blank") - @field: Pattern(regexp = "^\\d+\\.\\d+\\.\\d+\$", message = "Ver can only match '..'") - val ver: String?, - @field: NotNull(message = "BaseId can not be null") val baseId: Long? = null, - @field: NotNull(message = "Source can not be null") - val source: String?, - - @field:NotNull(message = "Dist can not be null") - val dist: String?, + val source: String = "", val enable: Boolean = true ) diff --git a/src/main/kotlin/top/fatweb/oxygen/api/param/tool/ToolTemplateUpdateParam.kt b/src/main/kotlin/top/fatweb/oxygen/api/param/tool/ToolTemplateUpdateParam.kt index 1d90f3f..a158999 100644 --- a/src/main/kotlin/top/fatweb/oxygen/api/param/tool/ToolTemplateUpdateParam.kt +++ b/src/main/kotlin/top/fatweb/oxygen/api/param/tool/ToolTemplateUpdateParam.kt @@ -1,7 +1,6 @@ package top.fatweb.oxygen.api.param.tool import jakarta.validation.constraints.NotNull -import jakarta.validation.constraints.Pattern data class ToolTemplateUpdateParam( @field: NotNull(message = "ID can not be null") @@ -9,14 +8,9 @@ data class ToolTemplateUpdateParam( val name: String?, - @field: Pattern(regexp = "^\\d+\\.\\d+\\.\\d+\$", message = "Ver can only match '..'") - val ver: String?, - val baseId: Long?, val source: String?, - val dist: String?, - val enable: Boolean? ) diff --git a/src/main/kotlin/top/fatweb/oxygen/api/service/tool/IToolBaseService.kt b/src/main/kotlin/top/fatweb/oxygen/api/service/tool/IToolBaseService.kt index 894ad43..f4e9fbb 100644 --- a/src/main/kotlin/top/fatweb/oxygen/api/service/tool/IToolBaseService.kt +++ b/src/main/kotlin/top/fatweb/oxygen/api/service/tool/IToolBaseService.kt @@ -19,8 +19,6 @@ interface IToolBaseService : IService { fun get(): List - fun getList(): List - fun add(toolBaseAddParam: ToolBaseAddParam): ToolBaseVo fun update(toolBaseUpdateParam: ToolBaseUpdateParam): ToolBaseVo diff --git a/src/main/kotlin/top/fatweb/oxygen/api/service/tool/impl/ToolBaseServiceImpl.kt b/src/main/kotlin/top/fatweb/oxygen/api/service/tool/impl/ToolBaseServiceImpl.kt index ea68d32..904dba7 100644 --- a/src/main/kotlin/top/fatweb/oxygen/api/service/tool/impl/ToolBaseServiceImpl.kt +++ b/src/main/kotlin/top/fatweb/oxygen/api/service/tool/impl/ToolBaseServiceImpl.kt @@ -31,8 +31,7 @@ class ToolBaseServiceImpl( override fun getOne(id: Long): ToolBaseVo = baseMapper.selectOne(id)?.let(ToolBaseConverter::toolBaseToToolBaseVo) ?: throw NoRecordFoundException() - override fun get(): List = baseMapper.selectList().map(ToolBaseConverter::toolBaseToToolBaseVo) - override fun getList(): List = this.list().map(ToolBaseConverter::toolBaseToToolBaseVoByGetList) + override fun get(): List = this.list().map(ToolBaseConverter::toolBaseToToolBaseVoByGetList) @Transactional override fun add(toolBaseAddParam: ToolBaseAddParam): ToolBaseVo { diff --git a/src/main/kotlin/top/fatweb/oxygen/api/service/tool/impl/ToolTemplateServiceImpl.kt b/src/main/kotlin/top/fatweb/oxygen/api/service/tool/impl/ToolTemplateServiceImpl.kt index 229a46a..116f9fd 100644 --- a/src/main/kotlin/top/fatweb/oxygen/api/service/tool/impl/ToolTemplateServiceImpl.kt +++ b/src/main/kotlin/top/fatweb/oxygen/api/service/tool/impl/ToolTemplateServiceImpl.kt @@ -42,19 +42,14 @@ class ToolTemplateServiceImpl( toolBaseService.getOne(toolTemplateAddParam.baseId!!) val newSource = ToolData().apply { data = toolTemplateAddParam.source } - val newDist = ToolData().apply { data = toolTemplateAddParam.dist } toolDataService.save(newSource) - toolDataService.save(newDist) val toolTemplate = ToolTemplate().apply { name = toolTemplateAddParam.name - ver = toolTemplateAddParam.ver baseId = toolTemplateAddParam.baseId sourceId = newSource.id - distId = newDist.id source = newSource - dist = newDist enable = if (toolTemplateAddParam.enable) 1 else 0 } @@ -73,15 +68,9 @@ class ToolTemplateServiceImpl( data = toolTemplateUpdateParam.source }) - toolDataService.updateById(ToolData().apply { - id = toolTemplate.distId - data = toolTemplateUpdateParam.dist - }) - this.updateById(ToolTemplate().apply { id = toolTemplateUpdateParam.id name = toolTemplateUpdateParam.name - ver = toolTemplateUpdateParam.ver baseId = toolTemplateUpdateParam.baseId enable = toolTemplateUpdateParam.enable?.let { if (it) 1 else 0 } }) @@ -93,7 +82,7 @@ class ToolTemplateServiceImpl( override fun delete(id: Long): Boolean { val toolTemplate = this.getById(id) - return toolDataService.removeBatchByIds(listOf(toolTemplate.sourceId, toolTemplate.distId)) + return toolDataService.removeById(toolTemplate.sourceId) && this.removeById(id) } } \ No newline at end of file diff --git a/src/main/kotlin/top/fatweb/oxygen/api/vo/tool/ToolTemplateVo.kt b/src/main/kotlin/top/fatweb/oxygen/api/vo/tool/ToolTemplateVo.kt index 235d5ae..ae9c5f9 100644 --- a/src/main/kotlin/top/fatweb/oxygen/api/vo/tool/ToolTemplateVo.kt +++ b/src/main/kotlin/top/fatweb/oxygen/api/vo/tool/ToolTemplateVo.kt @@ -10,15 +10,10 @@ data class ToolTemplateVo( val name: String?, - val ver: String?, - - @JsonSerialize(using = ToStringSerializer::class) - val baseId: Long?, + val base: ToolBaseVo?, val source: ToolDataVo?, - val dist: ToolDataVo?, - val enable: Boolean?, val createTime: LocalDateTime?, diff --git a/src/main/resources/db/migration/master/V1_0_0_240119__Add_table_'t_b_tool_template'.sql b/src/main/resources/db/migration/master/V1_0_0_240119__Add_table_'t_b_tool_template'.sql index b5b6451..8a91504 100644 --- a/src/main/resources/db/migration/master/V1_0_0_240119__Add_table_'t_b_tool_template'.sql +++ b/src/main/resources/db/migration/master/V1_0_0_240119__Add_table_'t_b_tool_template'.sql @@ -4,10 +4,8 @@ create table if not exists t_b_tool_template ( id bigint not null primary key, name varchar(40) not null comment '模板名', - ver varchar(20) not null comment '版本', base_id bigint not null comment '基板 ID', source_id bigint not null comment '源码 ID', - dist_id bigint not null comment '产物 ID', enable int not null default 1 comment '启用', create_time datetime not null default (utc_timestamp()) comment '创建时间', update_time datetime not null default (utc_timestamp()) comment '修改时间', diff --git a/src/main/resources/mapper/tool/ToolBaseMapper.xml b/src/main/resources/mapper/tool/ToolBaseMapper.xml index d6a4a5f..68112da 100644 --- a/src/main/resources/mapper/tool/ToolBaseMapper.xml +++ b/src/main/resources/mapper/tool/ToolBaseMapper.xml @@ -1,7 +1,7 @@ - select t_b_tool_base.id as tool_base_id, t_b_tool_base.name as tool_base_name, t_b_tool_base.source_id as tool_base_source_id, @@ -29,33 +29,6 @@ and t_b_tool_base.id = #{id} - - @@ -66,6 +39,9 @@ + + + diff --git a/src/main/resources/mapper/tool/ToolTemplateMapper.xml b/src/main/resources/mapper/tool/ToolTemplateMapper.xml index 3b7ca5c..be3e29a 100644 --- a/src/main/resources/mapper/tool/ToolTemplateMapper.xml +++ b/src/main/resources/mapper/tool/ToolTemplateMapper.xml @@ -1,13 +1,11 @@ - select t_b_tool_template.id as tool_template_id, t_b_tool_template.name as tool_template_name, - t_b_tool_template.ver as tool_template_ver, t_b_tool_template.base_id as tool_template_base_id, t_b_tool_template.source_id as tool_template_source_id, - t_b_tool_template.dist_id as tool_template_dist_id, t_b_tool_template.enable as tool_template_enable, t_b_tool_template.create_time as tool_template_create_time, t_b_tool_template.update_time as tool_template_update_time, @@ -18,16 +16,13 @@ tbtds.update_time as tool_template_source_update_time, tbtds.deleted as tool_template_source_delete, tbtds.version as tool_template_source_version, - tbtdd.data as tool_template_dist_data, - tbtdd.create_time as tool_template_dist_create_time, - tbtdd.update_time as tool_template_dist_update_time, - tbtdd.deleted as tool_template_dist_delete, - tbtdd.version as tool_template_dist_version + tbtb.name as tool_template_base_name, + tbtb.enable as tool_template_base_enable from t_b_tool_template left join (select * from t_b_tool_data where deleted = 0) as tbtds on tbtds.id = t_b_tool_template.source_id - left join (select * from t_b_tool_data where deleted = 0) as tbtdd - on tbtdd.id = t_b_tool_template.dist_id + left join (select * from t_b_tool_base where deleted = 0) as tbtb + on tbtb.id = t_b_tool_template.base_id where t_b_tool_template.deleted = 0 and t_b_tool_template.id = #{id} @@ -35,45 +30,39 @@ - - + + + + + + + + @@ -82,13 +71,5 @@ - - - - - - - -