From a66c5caa600b40bf357402779997483c8c0e3ab5 Mon Sep 17 00:00:00 2001 From: FatttSnake Date: Fri, 26 Jan 2024 14:54:40 +0800 Subject: [PATCH] Add create tool api --- .../api/controller/tool/EditController.kt | 96 +++++++----- .../controller/tool/ManagementController.kt | 61 +++----- .../api/converter/tool/ToolBaseConverter.kt | 6 +- .../api/converter/tool/ToolConverter.kt | 5 +- .../converter/tool/ToolTemplateConverter.kt | 57 ++++++- .../top/fatweb/oxygen/api/entity/tool/Tool.kt | 37 ++++- .../fatweb/oxygen/api/entity/tool/ToolBase.kt | 20 +-- .../oxygen/api/entity/tool/ToolTemplate.kt | 11 +- .../oxygen/api/mapper/tool/EditMapper.kt | 22 +++ .../oxygen/api/mapper/tool/ToolMapper.kt | 7 +- .../oxygen/api/param/tool/ToolAddParam.kt | 44 ------ .../oxygen/api/param/tool/ToolBaseAddParam.kt | 11 +- .../api/param/tool/ToolBaseUpdateParam.kt | 11 +- .../oxygen/api/param/tool/ToolCreateParam.kt | 99 ++++++++++++ .../api/param/tool/ToolTemplateAddParam.kt | 10 ++ .../api/param/tool/ToolTemplateUpdateParam.kt | 9 ++ .../oxygen/api/param/tool/ToolUpdateParam.kt | 84 ++++++++++ .../oxygen/api/service/tool/IEditService.kt | 74 +++++++++ .../oxygen/api/service/tool/IToolService.kt | 15 +- .../api/service/tool/impl/EditServiceImpl.kt | 92 +++++++++++ .../service/tool/impl/ToolBaseServiceImpl.kt | 5 +- .../api/service/tool/impl/ToolServiceImpl.kt | 138 ++++++----------- .../tool/impl/ToolTemplateServiceImpl.kt | 2 + .../fatweb/oxygen/api/vo/tool/ToolBaseVo.kt | 9 -- .../oxygen/api/vo/tool/ToolTemplateVo.kt | 9 ++ .../top/fatweb/oxygen/api/vo/tool/ToolVo.kt | 143 +++++++++++++++++- ..._0_0_240115__Add_table_'t_b_tool_main'.sql | 1 + ..._240119__Add_table_'t_b_tool_template'.sql | 1 + ..._0_0_240120__Add_table_'t_b_tool_base'.sql | 1 - src/main/resources/mapper/tool/EditMapper.xml | 142 +++++++++++++++++ .../resources/mapper/tool/ToolBaseMapper.xml | 2 - .../mapper/tool/ToolCategoryMapper.xml | 13 ++ .../mapper/tool/ToolTemplateMapper.xml | 10 +- 33 files changed, 945 insertions(+), 302 deletions(-) create mode 100644 src/main/kotlin/top/fatweb/oxygen/api/mapper/tool/EditMapper.kt delete mode 100644 src/main/kotlin/top/fatweb/oxygen/api/param/tool/ToolAddParam.kt create mode 100644 src/main/kotlin/top/fatweb/oxygen/api/param/tool/ToolCreateParam.kt create mode 100644 src/main/kotlin/top/fatweb/oxygen/api/service/tool/IEditService.kt create mode 100644 src/main/kotlin/top/fatweb/oxygen/api/service/tool/impl/EditServiceImpl.kt create mode 100644 src/main/resources/mapper/tool/EditMapper.xml create mode 100644 src/main/resources/mapper/tool/ToolCategoryMapper.xml diff --git a/src/main/kotlin/top/fatweb/oxygen/api/controller/tool/EditController.kt b/src/main/kotlin/top/fatweb/oxygen/api/controller/tool/EditController.kt index e69c0c0..1e735e6 100644 --- a/src/main/kotlin/top/fatweb/oxygen/api/controller/tool/EditController.kt +++ b/src/main/kotlin/top/fatweb/oxygen/api/controller/tool/EditController.kt @@ -2,54 +2,80 @@ package top.fatweb.oxygen.api.controller.tool import io.swagger.v3.oas.annotations.Operation import jakarta.validation.Valid -import org.springframework.web.bind.annotation.* +import org.springframework.web.bind.annotation.GetMapping +import org.springframework.web.bind.annotation.PathVariable +import org.springframework.web.bind.annotation.PostMapping +import org.springframework.web.bind.annotation.RequestBody import top.fatweb.oxygen.api.annotation.BaseController import top.fatweb.oxygen.api.entity.common.ResponseCode import top.fatweb.oxygen.api.entity.common.ResponseResult -import top.fatweb.oxygen.api.param.tool.ToolAddParam -import top.fatweb.oxygen.api.param.tool.ToolUpdateParam -import top.fatweb.oxygen.api.service.tool.IToolService +import top.fatweb.oxygen.api.param.tool.ToolCreateParam +import top.fatweb.oxygen.api.service.tool.IEditService +import top.fatweb.oxygen.api.vo.tool.ToolCategoryVo +import top.fatweb.oxygen.api.vo.tool.ToolTemplateVo import top.fatweb.oxygen.api.vo.tool.ToolVo /** - * Tool management controller + * Tool edit controller * * @author FatttSnake, fatttsnake@gmail.com * @since 1.0.0 */ -@BaseController(path = ["/tool"], name = "工具管理", description = "工具管理相关接口") +@BaseController(path = ["/tool"], name = "工具编辑", description = "工具编辑相关接口") class EditController( - private val toolService: IToolService + private val editService: IEditService ) { - @Operation(summary = "获取单个工具") - @GetMapping("/{id}") - fun getOne(@PathVariable id: Long): ResponseResult = - ResponseResult.databaseSuccess(data = toolService.getOne(id)) + /** + * Get tool template list + * + * @return Response object includes tool template list + * @author FatttSnake, fatttsnake@gmail.com + * @since 1.0.0 + * @see ResponseResult + * @see ToolTemplateVo + */ + @Operation(summary = "获取模板") + @GetMapping("/template") + fun getTemplate(): ResponseResult> = + ResponseResult.databaseSuccess(data = editService.getTemplate()) - @Operation(summary = "获取工具") - @GetMapping - fun get(): ResponseResult> = - ResponseResult.databaseSuccess(data = toolService.get()) + /** + * Get tool template by ID + * + * @param id ID + * @return Response object includes tool template information + * @author FatttSnake, fatttsnake@gmail.com + * @since 1.0.0 + * @see ResponseResult + * @see ToolTemplateVo + */ + @Operation(summary = "获取单个模板") + @GetMapping("/template/{id}") + fun getTemplate(@PathVariable id: Long): ResponseResult = + ResponseResult.databaseSuccess(data = editService.getTemplate(id)) - @Operation(summary = "新增工具") + /** + * Get tool category list + * + * @return Response object includes tool category list + * @author FatttSnake, fatttsnake@gmail.com + * @since 1.0.0 + * @see ResponseResult + * @see ToolCategoryVo + */ + @Operation(summary = "获取类别") + @GetMapping("/category") + fun getCategory(): ResponseResult> = + ResponseResult.databaseSuccess(data = editService.getCategory()) + + /** + * Create tool + * + * @author FatttSnake, fatttsnake@gmail.com + * @since 1.0.0 + */ + @Operation(summary = "创建工具") @PostMapping - fun add(@RequestBody @Valid toolAddParam: ToolAddParam): ResponseResult = - ResponseResult.databaseSuccess( - ResponseCode.DATABASE_INSERT_SUCCESS, - data = toolService.add(toolAddParam) - ) - - @Operation(summary = "更新工具") - @PutMapping - fun update(@RequestBody @Valid toolUpdateParam: ToolUpdateParam): ResponseResult = - ResponseResult.databaseSuccess( - ResponseCode.DATABASE_UPDATE_SUCCESS, - data = toolService.update(toolUpdateParam) - ) - - @Operation(summary = "删除工具") - @DeleteMapping("/{id}") - fun delete(@PathVariable id: Long): ResponseResult = - if (toolService.delete(id)) ResponseResult.databaseSuccess(ResponseCode.DATABASE_DELETE_SUCCESS) - else ResponseResult.databaseFail(ResponseCode.DATABASE_DELETE_FAILED) + fun create(@RequestBody @Valid toolCreateParam: ToolCreateParam): ResponseResult = + ResponseResult.databaseSuccess(ResponseCode.DATABASE_INSERT_SUCCESS, data = editService.create(toolCreateParam)) } \ No newline at end of file diff --git a/src/main/kotlin/top/fatweb/oxygen/api/controller/tool/ManagementController.kt b/src/main/kotlin/top/fatweb/oxygen/api/controller/tool/ManagementController.kt index 9e09628..e062586 100644 --- a/src/main/kotlin/top/fatweb/oxygen/api/controller/tool/ManagementController.kt +++ b/src/main/kotlin/top/fatweb/oxygen/api/controller/tool/ManagementController.kt @@ -1,49 +1,30 @@ package top.fatweb.oxygen.api.controller.tool -import io.swagger.v3.oas.annotations.Operation -import jakarta.validation.Valid -import org.springframework.web.bind.annotation.* import top.fatweb.oxygen.api.annotation.BaseController -import top.fatweb.oxygen.api.entity.common.ResponseCode -import top.fatweb.oxygen.api.entity.common.ResponseResult -import top.fatweb.oxygen.api.param.tool.ToolAddParam -import top.fatweb.oxygen.api.param.tool.ToolUpdateParam -import top.fatweb.oxygen.api.service.tool.IToolService -import top.fatweb.oxygen.api.vo.tool.ToolVo @BaseController(path = ["/system/tool"], name = "工具管理", description = "工具管理相关接口") -class ManagementController( - private val toolService: IToolService -) { - @Operation(summary = "获取单个工具") - @GetMapping("/{id}") - fun getOne(@PathVariable id: Long): ResponseResult = - ResponseResult.databaseSuccess(data = toolService.getOne(id)) +class ManagementController { + /* @Operation(summary = "获取单个工具") + @GetMapping("/{id}") + fun getOne(@PathVariable id: Long): ResponseResult = + ResponseResult.databaseSuccess(data = toolService.getOne(id)) - @Operation(summary = "获取工具") - @GetMapping - fun get(): ResponseResult> = - ResponseResult.databaseSuccess(data = toolService.get()) + @Operation(summary = "获取工具") + @GetMapping + fun get(): ResponseResult> = + ResponseResult.databaseSuccess(data = toolService.get()) - @Operation(summary = "新增工具") - @PostMapping - fun add(@RequestBody @Valid toolAddParam: ToolAddParam): ResponseResult = - ResponseResult.databaseSuccess( - ResponseCode.DATABASE_INSERT_SUCCESS, - data = toolService.add(toolAddParam) - ) + @Operation(summary = "更新工具") + @PutMapping + fun update(@RequestBody @Valid toolUpdateParam: ToolUpdateParam): ResponseResult = + ResponseResult.databaseSuccess( + ResponseCode.DATABASE_UPDATE_SUCCESS, + data = toolService.update(toolUpdateParam) + ) - @Operation(summary = "更新工具") - @PutMapping - fun update(@RequestBody @Valid toolUpdateParam: ToolUpdateParam): ResponseResult = - ResponseResult.databaseSuccess( - ResponseCode.DATABASE_UPDATE_SUCCESS, - data = toolService.update(toolUpdateParam) - ) - - @Operation(summary = "删除工具") - @DeleteMapping("/{id}") - fun delete(@PathVariable id: Long): ResponseResult = - if (toolService.delete(id)) ResponseResult.databaseSuccess(ResponseCode.DATABASE_DELETE_SUCCESS) - else ResponseResult.databaseFail(ResponseCode.DATABASE_DELETE_FAILED) + @Operation(summary = "删除工具") + @DeleteMapping("/{id}") + fun delete(@PathVariable id: Long): ResponseResult = + if (toolService.delete(id)) ResponseResult.databaseSuccess(ResponseCode.DATABASE_DELETE_SUCCESS) + else ResponseResult.databaseFail(ResponseCode.DATABASE_DELETE_FAILED)*/ } \ No newline at end of file diff --git a/src/main/kotlin/top/fatweb/oxygen/api/converter/tool/ToolBaseConverter.kt b/src/main/kotlin/top/fatweb/oxygen/api/converter/tool/ToolBaseConverter.kt index 03cada4..1877c39 100644 --- a/src/main/kotlin/top/fatweb/oxygen/api/converter/tool/ToolBaseConverter.kt +++ b/src/main/kotlin/top/fatweb/oxygen/api/converter/tool/ToolBaseConverter.kt @@ -28,8 +28,7 @@ object ToolBaseConverter { dist = toolBase.dist?.let(ToolDataConverter::toolDataToToolDataVo), compiled = toolBase.compiled == 1, createTime = toolBase.createTime, - updateTime = toolBase.updateTime, - enable = toolBase.enable == 1 + updateTime = toolBase.updateTime ) /** @@ -49,7 +48,6 @@ object ToolBaseConverter { dist = ToolDataVo(id = toolBase.distId, data = null, createTime = null, updateTime = null), compiled = toolBase.compiled == 1, createTime = toolBase.createTime, - updateTime = toolBase.updateTime, - enable = toolBase.enable == 1 + updateTime = toolBase.updateTime ) } \ No newline at end of file diff --git a/src/main/kotlin/top/fatweb/oxygen/api/converter/tool/ToolConverter.kt b/src/main/kotlin/top/fatweb/oxygen/api/converter/tool/ToolConverter.kt index d490e11..83f2069 100644 --- a/src/main/kotlin/top/fatweb/oxygen/api/converter/tool/ToolConverter.kt +++ b/src/main/kotlin/top/fatweb/oxygen/api/converter/tool/ToolConverter.kt @@ -1,6 +1,6 @@ package top.fatweb.oxygen.api.converter.tool -import top.fatweb.oxygen.api.converter.permission.UserInfoConverter +import top.fatweb.oxygen.api.converter.permission.UserConverter import top.fatweb.oxygen.api.entity.tool.Tool import top.fatweb.oxygen.api.vo.tool.ToolVo @@ -27,13 +27,14 @@ object ToolConverter { toolId = tool.toolId, description = tool.description, baseId = tool.baseId, - author = tool.author?.let(UserInfoConverter::userInfoToUserInfoVo), + author = tool.author?.let(UserConverter::userToUserWithInfoVo), ver = tool.ver, privately = tool.privately == 1, keywords = tool.keywords, categories = tool.categories?.map(ToolCategoryConverter::toolCategoryToToolCategoryVo), source = tool.source?.let(ToolDataConverter::toolDataToToolDataVo), dist = tool.dist?.let(ToolDataConverter::toolDataToToolDataVo), + entryPoint = tool.entryPoint, publish = tool.publish == 1, review = tool.review, createTime = tool.createTime, 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 37c93fa..e3243ce 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 @@ -1,6 +1,8 @@ package top.fatweb.oxygen.api.converter.tool import top.fatweb.oxygen.api.entity.tool.ToolTemplate +import top.fatweb.oxygen.api.vo.tool.ToolBaseVo +import top.fatweb.oxygen.api.vo.tool.ToolDataVo import top.fatweb.oxygen.api.vo.tool.ToolTemplateVo /** @@ -25,8 +27,59 @@ object ToolTemplateConverter { name = toolTemplate.name, base = toolTemplate.base?.let(ToolBaseConverter::toolBaseToToolBaseVo), source = toolTemplate.source?.let(ToolDataConverter::toolDataToToolDataVo), + entryPoint = toolTemplate.entryPoint, + enable = toolTemplate.enable == 1, createTime = toolTemplate.createTime, - updateTime = toolTemplate.updateTime, - enable = toolTemplate.enable == 1 + updateTime = toolTemplate.updateTime + ) + + /** + * Convert ToolTemplate object into ToolTemplateVo object by list + * + * @author FatttSnake, fatttsnake@gmail.com + * @since 1.0.0 + */ + fun toolTemplateToToolTemplateVoByList(toolTemplate: ToolTemplate) = ToolTemplateVo( + id = toolTemplate.id, + name = toolTemplate.name, + base = ToolBaseVo( + id = toolTemplate.baseId, + name = null, + source = null, + dist = null, + compiled = null, + createTime = null, + updateTime = null + ), + source = ToolDataVo(id = toolTemplate.sourceId, data = null, createTime = null, updateTime = null), + entryPoint = toolTemplate.entryPoint, + enable = toolTemplate.enable == 1, + createTime = toolTemplate.createTime, + updateTime = toolTemplate.updateTime + ) + + /** + * Convert ToolTemplate object into ToolTemplateVo object with base dist + * + * @author FatttSnake, fatttsnake@gmail.com + * @since 1.0.0 + */ + fun toolTemplateToToolTemplateVoWithBaseDist(toolTemplate: ToolTemplate) = ToolTemplateVo( + id = toolTemplate.id, + name = toolTemplate.name, + base = ToolBaseVo( + id = toolTemplate.baseId, + name = toolTemplate.base?.name, + source = null, + dist = ToolDataVo(id = null, data = toolTemplate.base?.distData, createTime = null, updateTime = null), + compiled = null, + createTime = null, + updateTime = null + ), + source = toolTemplate.source?.let(ToolDataConverter::toolDataToToolDataVo), + entryPoint = toolTemplate.entryPoint, + enable = toolTemplate.enable == 1, + createTime = toolTemplate.createTime, + updateTime = toolTemplate.updateTime ) } \ No newline at end of file diff --git a/src/main/kotlin/top/fatweb/oxygen/api/entity/tool/Tool.kt b/src/main/kotlin/top/fatweb/oxygen/api/entity/tool/Tool.kt index 36aa2a6..9c04a29 100644 --- a/src/main/kotlin/top/fatweb/oxygen/api/entity/tool/Tool.kt +++ b/src/main/kotlin/top/fatweb/oxygen/api/entity/tool/Tool.kt @@ -2,7 +2,8 @@ package top.fatweb.oxygen.api.entity.tool import com.baomidou.mybatisplus.annotation.* import com.baomidou.mybatisplus.extension.handlers.JacksonTypeHandler -import top.fatweb.oxygen.api.entity.permission.UserInfo +import com.fasterxml.jackson.annotation.JsonValue +import top.fatweb.oxygen.api.entity.permission.User import java.time.LocalDateTime /** @@ -13,6 +14,16 @@ import java.time.LocalDateTime */ @TableName("t_b_tool_main", autoResultMap = true) class Tool { + /** + * Tool review type enum + * + * @author FatttSnake, fatttsnake@gmail.com + * @since 1.0.0 + */ + enum class ReviewType(@field:EnumValue @field:JsonValue val code: String) { + NONE("NONE"), PASS("PASS"), REJECT("REJECT") + } + /** * ID * @@ -112,6 +123,15 @@ class Tool { @TableField("dist_id") var distId: Long? = null + /** + * Entry point + * + * @author FatttSnake, fatttsnake@gmail.com + * @since 1.0.0 + */ + @TableField("entry_point") + var entryPoint: String? = null + /** * Publish * @@ -128,7 +148,7 @@ class Tool { * @since 1.0.0 */ @TableField("review") - var review: Int? = null + var review: ReviewType? = null /** * Create time @@ -177,7 +197,16 @@ class Tool { * @since 1.0.0 */ @TableField(exist = false) - var author: UserInfo? = null + var author: User? = null + + /** + * Base + * + * @author FatttSnake, fatttsnake@gmail.com + * @since 1.0.0 + */ + @TableField(exist = false) + var base: ToolBase? = null /** * Categories @@ -207,6 +236,6 @@ class Tool { var dist: ToolData? = null override fun toString(): String { - return "Tool(id=$id, name=$name, toolId=$toolId, description=$description, baseId=$baseId, authorId=$authorId, ver=$ver, privately=$privately, keywords=$keywords, sourceId=$sourceId, distId=$distId, publish=$publish, review=$review, createTime=$createTime, updateTime=$updateTime, deleted=$deleted, version=$version, author=$author, categories=$categories, source=$source, dist=$dist)" + return "Tool(id=$id, name=$name, toolId=$toolId, description=$description, baseId=$baseId, authorId=$authorId, ver=$ver, privately=$privately, keywords=$keywords, sourceId=$sourceId, distId=$distId, entryPoint=$entryPoint, publish=$publish, review=$review, createTime=$createTime, updateTime=$updateTime, deleted=$deleted, version=$version, author=$author, categories=$categories, source=$source, dist=$dist)" } } \ No newline at end of file diff --git a/src/main/kotlin/top/fatweb/oxygen/api/entity/tool/ToolBase.kt b/src/main/kotlin/top/fatweb/oxygen/api/entity/tool/ToolBase.kt index 10a591b..9878b57 100644 --- a/src/main/kotlin/top/fatweb/oxygen/api/entity/tool/ToolBase.kt +++ b/src/main/kotlin/top/fatweb/oxygen/api/entity/tool/ToolBase.kt @@ -56,15 +56,6 @@ class ToolBase { @TableField("compiled") var compiled: Int? = null - /** - * Enable - * - * @author FatttSnake, fatttsnake@gmail.com - * @since 1.0.0 - */ - @TableField("enable") - var enable: Int? = null - /** * Create time * @@ -123,7 +114,16 @@ class ToolBase { @TableField(exist = false) var dist: ToolData? = null + /** + * Dist data + * + * @author FatttSnake, fatttsnake@gmail.com + * @since 1.0.0 + */ + @TableField(exist = false) + var distData: String? = null + override fun toString(): String { - return "ToolBase(id=$id, name=$name, sourceId=$sourceId, distId=$distId, compiled=$compiled, enable=$enable, createTime=$createTime, updateTime=$updateTime, deleted=$deleted, version=$version, source=$source, dist=$dist)" + return "ToolBase(id=$id, name=$name, sourceId=$sourceId, distId=$distId, compiled=$compiled, createTime=$createTime, updateTime=$updateTime, deleted=$deleted, version=$version, source=$source, dist=$dist, distData=$distData)" } } \ No newline at end of file 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 1fcbdd4..124995b 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 @@ -47,6 +47,15 @@ class ToolTemplate { @TableField("source_id") var sourceId: Long? = null + /** + * Entry point + * + * @author FatttSnake, fatttsnake@gmail.com + * @since 1.0.0 + */ + @TableField("entry_point") + var entryPoint: String? = null + /** * Enable * @@ -115,6 +124,6 @@ class ToolTemplate { var base: ToolBase? = null override fun toString(): String { - return "ToolTemplate(id=$id, name=$name, baseId=$baseId, sourceId=$sourceId, enable=$enable, createTime=$createTime, updateTime=$updateTime, deleted=$deleted, version=$version, source=$source, base=$base)" + return "ToolTemplate(id=$id, name=$name, baseId=$baseId, sourceId=$sourceId, entryPoint=$entryPoint, 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/EditMapper.kt b/src/main/kotlin/top/fatweb/oxygen/api/mapper/tool/EditMapper.kt new file mode 100644 index 0000000..56f0802 --- /dev/null +++ b/src/main/kotlin/top/fatweb/oxygen/api/mapper/tool/EditMapper.kt @@ -0,0 +1,22 @@ +package top.fatweb.oxygen.api.mapper.tool + +import com.baomidou.mybatisplus.core.mapper.BaseMapper +import org.apache.ibatis.annotations.Mapper +import org.apache.ibatis.annotations.Param +import top.fatweb.oxygen.api.entity.tool.Tool +import top.fatweb.oxygen.api.entity.tool.ToolTemplate + +/** + * Tool edit mapper + * + * @author FatttSnake, fatttsnake@gmail.com + * @since 1.0.0 + * @see BaseMapper + * @see Tool + */ +@Mapper +interface EditMapper : BaseMapper { + fun getTemplate(@Param("id") id: Long): ToolTemplate? + + fun selectOne(@Param("id") id: Long, @Param("userId") userId: Long): Tool? +} \ No newline at end of file diff --git a/src/main/kotlin/top/fatweb/oxygen/api/mapper/tool/ToolMapper.kt b/src/main/kotlin/top/fatweb/oxygen/api/mapper/tool/ToolMapper.kt index ac7caed..77dd30a 100644 --- a/src/main/kotlin/top/fatweb/oxygen/api/mapper/tool/ToolMapper.kt +++ b/src/main/kotlin/top/fatweb/oxygen/api/mapper/tool/ToolMapper.kt @@ -2,7 +2,6 @@ package top.fatweb.oxygen.api.mapper.tool import com.baomidou.mybatisplus.core.mapper.BaseMapper import org.apache.ibatis.annotations.Mapper -import org.apache.ibatis.annotations.Param import top.fatweb.oxygen.api.entity.tool.Tool /** @@ -14,8 +13,4 @@ import top.fatweb.oxygen.api.entity.tool.Tool * @see Tool */ @Mapper -interface ToolMapper : BaseMapper { - fun selectOne(@Param("id") id: Long): Tool? - - fun selectList(): List -} \ No newline at end of file +interface ToolMapper : BaseMapper \ No newline at end of file diff --git a/src/main/kotlin/top/fatweb/oxygen/api/param/tool/ToolAddParam.kt b/src/main/kotlin/top/fatweb/oxygen/api/param/tool/ToolAddParam.kt deleted file mode 100644 index 0cbfcb8..0000000 --- a/src/main/kotlin/top/fatweb/oxygen/api/param/tool/ToolAddParam.kt +++ /dev/null @@ -1,44 +0,0 @@ -package top.fatweb.oxygen.api.param.tool - -import jakarta.validation.constraints.NotBlank -import jakarta.validation.constraints.NotEmpty -import jakarta.validation.constraints.NotNull -import jakarta.validation.constraints.Pattern - -data class ToolAddParam( - @field: NotBlank(message = "Name can not be blank") - val name: String?, - - @field: NotBlank(message = "ToolId can not be blank") - @field: Pattern( - regexp = "^[a-zA-Z-_][0-9a-zA-Z-_]{2,19}\$", - message = "Ver can only match '^[a-zA-Z-_][0-9a-zA-Z-_]{2,19}\$'" - ) - val toolId: String?, - - val description: String?, - - @field: NotNull(message = "BaseId can not be null") - val baseId: Long?, - - @field: NotNull(message = "AuthorId can not be null") - val authorId: Long?, - - @field: NotBlank(message = "Ver can not be blank") - @field: Pattern(regexp = "^\\d+\\.\\d+\\.\\d+\$", message = "Ver can only match '..'") - val ver: String?, - - val privately: Boolean = false, - - @field: NotEmpty(message = "Keywords can not be empty") - val keywords: List, - - @field: NotEmpty(message = "Categories can not be empty") - val categories: List, - - @field: NotNull(message = "Source can not be null") - val source: String?, - - @field:NotNull(message = "Dist can not be null") - val dist: String? -) diff --git a/src/main/kotlin/top/fatweb/oxygen/api/param/tool/ToolBaseAddParam.kt b/src/main/kotlin/top/fatweb/oxygen/api/param/tool/ToolBaseAddParam.kt index 773aa51..582925b 100644 --- a/src/main/kotlin/top/fatweb/oxygen/api/param/tool/ToolBaseAddParam.kt +++ b/src/main/kotlin/top/fatweb/oxygen/api/param/tool/ToolBaseAddParam.kt @@ -18,14 +18,5 @@ data class ToolBaseAddParam( */ @Schema(description = "名称", required = true) @field: NotBlank(message = "Name can not be blank") - val name: String?, - - /** - * Enable - * - * @author FatttSnake, fatttsnake@gmail.com - * @since 1.0.0 - */ - @Schema(description = "启用", allowableValues = ["true", "false"], defaultValue = "true") - val enable: Boolean = true + val name: String? ) diff --git a/src/main/kotlin/top/fatweb/oxygen/api/param/tool/ToolBaseUpdateParam.kt b/src/main/kotlin/top/fatweb/oxygen/api/param/tool/ToolBaseUpdateParam.kt index 83f4cc3..d4da30e 100644 --- a/src/main/kotlin/top/fatweb/oxygen/api/param/tool/ToolBaseUpdateParam.kt +++ b/src/main/kotlin/top/fatweb/oxygen/api/param/tool/ToolBaseUpdateParam.kt @@ -45,14 +45,5 @@ data class ToolBaseUpdateParam( * @since 1.0.0 */ @Schema(description = "产物") - val dist: String?, - - /** - * Enable - * - * @author FatttSnake, fatttsnake@gmail.com - * @since 1.0.0 - */ - @Schema(description = "启用", allowableValues = ["true", "false"]) - val enable: Boolean? + val dist: String? ) diff --git a/src/main/kotlin/top/fatweb/oxygen/api/param/tool/ToolCreateParam.kt b/src/main/kotlin/top/fatweb/oxygen/api/param/tool/ToolCreateParam.kt new file mode 100644 index 0000000..01d1159 --- /dev/null +++ b/src/main/kotlin/top/fatweb/oxygen/api/param/tool/ToolCreateParam.kt @@ -0,0 +1,99 @@ +package top.fatweb.oxygen.api.param.tool + +import io.swagger.v3.oas.annotations.media.Schema +import jakarta.validation.constraints.NotBlank +import jakarta.validation.constraints.NotEmpty +import jakarta.validation.constraints.NotNull +import jakarta.validation.constraints.Pattern + +/** + * Create tool parameters + * + * @author FatttSnake, fatttsnake@gmail.com + * @since 1.0.0 + */ +@Schema(description = "创建工具请求参数") +data class ToolCreateParam( + /** + * Name + * + * @author FatttSnake, fatttsnake@gmail.com + * @since 1.0.0 + */ + @Schema(description = "名称", required = true) + @field: NotBlank(message = "Name can not be blank") + val name: String?, + + /** + * Tool ID + * + * @author FatttSnake, fatttsnake@gmail.com + * @since 1.0.0 + */ + @Schema(description = "工具唯一 ID", required = true, example = "tool_a") + @field: NotBlank(message = "ToolId can not be blank") + @field: Pattern( + regexp = "^[a-zA-Z-_][0-9a-zA-Z-_]{2,19}\$", + message = "Ver can only match '^[a-zA-Z-_][0-9a-zA-Z-_]{2,19}\$'" + ) + val toolId: String?, + + /** + * Description + * + * @author FatttSnake, fatttsnake@gmail.com + * @since 1.0.0 + */ + @Schema(description = "简介") + val description: String?, + + /** + * Version + * + * @author FatttSnake, fatttsnake@gmail.com + * @since 1.0.0 + */ + @Schema(description = "版本", required = true, example = "1.0.3") + @field: NotBlank(message = "Ver can not be blank") + @field: Pattern(regexp = "^\\d+\\.\\d+\\.\\d+\$", message = "Ver can only match '..'") + val ver: String?, + + /** + * Template ID + * + * @author FatttSnake, fatttsnake@gmail.com + * @since 1.0.0 + */ + @Schema(description = "模板 ID", required = true) + @field: NotNull(message = "TemplateId can not be null") + val templateId: Long?, + + /** + * Privately + * + * @author FatttSnake, fatttsnake@gmail.com + * @since 1.0.0 + */ + @Schema(description = "私有", allowableValues = ["true", "false"], defaultValue = "false") + val privately: Boolean = false, + + /** + * Keywords + * + * @author FatttSnake, fatttsnake@gmail.com + * @since 1.0.0 + */ + @Schema(description = "关键词", required = true) + @field: NotEmpty(message = "Keywords can not be empty") + val keywords: List, + + /** + * Categories + * + * @author FatttSnake, fatttsnake@gmail.com + * @since 1.0.0 + */ + @Schema(description = "类别", required = true) + @field: NotEmpty(message = "Categories can not be empty") + val categories: List +) 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 44fa42d..137c554 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 @@ -31,6 +31,16 @@ data class ToolTemplateAddParam( @field: NotNull(message = "BaseId can not be null") val baseId: Long? = null, + /** + * Entry point + * + * @author FatttSnake, fatttsnake@gmail.com + * @since 1.0.0 + */ + @Schema(description = "入口文件", required = true) + @field:NotBlank(message = "EntryPoint can not be null") + val entryPoint: String? = null, + /** * Enable * 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 a06672b..523f74d 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 @@ -47,6 +47,15 @@ data class ToolTemplateUpdateParam( @Schema(description = "源码") val source: String?, + /** + * Entry point + * + * @author FatttSnake, fatttsnake@gmail.com + * @since 1.0.0 + */ + @Schema(description = "入口文件") + val entryPoint: String?, + /** * Enable * diff --git a/src/main/kotlin/top/fatweb/oxygen/api/param/tool/ToolUpdateParam.kt b/src/main/kotlin/top/fatweb/oxygen/api/param/tool/ToolUpdateParam.kt index 94d1d0d..f341be8 100644 --- a/src/main/kotlin/top/fatweb/oxygen/api/param/tool/ToolUpdateParam.kt +++ b/src/main/kotlin/top/fatweb/oxygen/api/param/tool/ToolUpdateParam.kt @@ -1,34 +1,118 @@ package top.fatweb.oxygen.api.param.tool +import io.swagger.v3.oas.annotations.media.Schema import jakarta.validation.constraints.NotNull import jakarta.validation.constraints.Pattern +/** + * Update tool parameters + * + * @author FatttSnake, fatttsnake@gmail.com + * @since 1.0.0 + */ data class ToolUpdateParam( + /** + * ID + * + * @author FatttSnake, fatttsnake@gmail.com + * @since 1.0.0 + */ + @Schema(description = "ID", required = true) @field: NotNull(message = "ID can not be null") val id: Long?, + /** + * Name + * + * @author FatttSnake, fatttsnake@gmail.com + * @since 1.0.0 + */ + @Schema(description = "名称") val name: String?, + /** + * Tool ID + * + * @author FatttSnake, fatttsnake@gmail.com + * @since 1.0.0 + */ + @Schema(description = "工具唯一 ID", example = "tool_a") @field: Pattern( regexp = "^[a-zA-Z-_][0-9a-zA-Z-_]{2,19}\$", message = "Ver can only match '^[a-zA-Z-_][0-9a-zA-Z-_]{2,19}\$'" ) val toolId: String?, + /** + * Description + * + * @author FatttSnake, fatttsnake@gmail.com + * @since 1.0.0 + */ + @Schema(description = "简介") val description: String?, + /** + * Author ID + * + * @author FatttSnake, fatttsnake@gmail.com + * @since 1.0.0 + */ + @Schema(description = "作者 ID") val authorId: Long?, + /** + * Version + * + * @author FatttSnake, fatttsnake@gmail.com + * @since 1.0.0 + */ + @Schema(description = "版本", example = "1.0.3") @field: Pattern(regexp = "^\\d+\\.\\d+\\.\\d+\$", message = "Ver can only match '..'") val ver: String?, + /** + * Privately + * + * @author FatttSnake, fatttsnake@gmail.com + * @since 1.0.0 + */ + @Schema(description = "私有", allowableValues = ["true", "false"]) val privately: Boolean?, + /** + * Keywords + * + * @author FatttSnake, fatttsnake@gmail.com + * @since 1.0.0 + */ + @Schema(description = "关键词") val keywords: List, + /** + * Categories + * + * @author FatttSnake, fatttsnake@gmail.com + * @since 1.0.0 + */ + @Schema(description = "类别") val categories: List, + /** + * Source + * + * @author FatttSnake, fatttsnake@gmail.com + * @since 1.0.0 + */ + @Schema(description = "源码") val source: String?, + /** + * Dist + * + * @author FatttSnake, fatttsnake@gmail.com + * @since 1.0.0 + */ + @Schema(description = "产物") val dist: String? ) diff --git a/src/main/kotlin/top/fatweb/oxygen/api/service/tool/IEditService.kt b/src/main/kotlin/top/fatweb/oxygen/api/service/tool/IEditService.kt new file mode 100644 index 0000000..819fc66 --- /dev/null +++ b/src/main/kotlin/top/fatweb/oxygen/api/service/tool/IEditService.kt @@ -0,0 +1,74 @@ +package top.fatweb.oxygen.api.service.tool + +import com.baomidou.mybatisplus.extension.service.IService +import top.fatweb.oxygen.api.entity.tool.Tool +import top.fatweb.oxygen.api.param.tool.ToolCreateParam +import top.fatweb.oxygen.api.param.tool.ToolUpdateParam +import top.fatweb.oxygen.api.vo.tool.ToolCategoryVo +import top.fatweb.oxygen.api.vo.tool.ToolTemplateVo +import top.fatweb.oxygen.api.vo.tool.ToolVo + +/** + * Tool edit service interface + * + * @author FatttSnake, fatttsnake@gmail.com + * @since 1.0.0 + * @see IService + * @see Tool + */ +interface IEditService : IService { + /** + * Get tool template as list + * + * @return List of ToolTemplateVo object + * @author FatttSnake, fatttsnake@gmail.com + * @since 1.0.0 + * @see ToolTemplateVo + */ + fun getTemplate(): List + + /** + * Get tool template by ID + * + * @param id ID + * @return ToolTemplateVo object + * @author FatttSnake, fatttsnake@gmail.com + * @since 1.0.0 + * @see ToolTemplateVo + */ + fun getTemplate(id: Long): ToolTemplateVo + + /** + * Get tool category as list + * + * @return List of ToolCategoryVo object + * @author FatttSnake, fatttsnake@gmail.com + * @since 1.0.0 + * @see ToolCategoryVo + */ + fun getCategory(): List + + /** + * Get tool by ID + * + * @author FatttSnake, fatttsnake@gmail.com + * @since 1.0.0 + */ + fun getOne(id: Long): ToolVo + + /** + * Create tool + * + * @author FatttSnake, fatttsnake@gmail.com + * @since 1.0.0 + */ + fun create(toolCreateParam: ToolCreateParam): ToolVo + + /** + * Update tool + * + * @author FatttSnake, fatttsnake@gmail.com + * @since 1.0.0 + */ + fun update(toolUpdateParam: ToolUpdateParam): ToolVo +} \ No newline at end of file diff --git a/src/main/kotlin/top/fatweb/oxygen/api/service/tool/IToolService.kt b/src/main/kotlin/top/fatweb/oxygen/api/service/tool/IToolService.kt index 69ef68c..c0df740 100644 --- a/src/main/kotlin/top/fatweb/oxygen/api/service/tool/IToolService.kt +++ b/src/main/kotlin/top/fatweb/oxygen/api/service/tool/IToolService.kt @@ -2,9 +2,6 @@ package top.fatweb.oxygen.api.service.tool import com.baomidou.mybatisplus.extension.service.IService import top.fatweb.oxygen.api.entity.tool.Tool -import top.fatweb.oxygen.api.param.tool.ToolAddParam -import top.fatweb.oxygen.api.param.tool.ToolUpdateParam -import top.fatweb.oxygen.api.vo.tool.ToolVo /** * Tool service interface @@ -14,14 +11,4 @@ import top.fatweb.oxygen.api.vo.tool.ToolVo * @see IService * @see Tool */ -interface IToolService : IService { - fun getOne(id: Long): ToolVo - - fun get(): List - - fun add(toolAddParam: ToolAddParam): ToolVo - - fun update(toolUpdateParam: ToolUpdateParam): ToolVo - - fun delete(id: Long): Boolean -} \ No newline at end of file +interface IToolService : IService \ No newline at end of file diff --git a/src/main/kotlin/top/fatweb/oxygen/api/service/tool/impl/EditServiceImpl.kt b/src/main/kotlin/top/fatweb/oxygen/api/service/tool/impl/EditServiceImpl.kt new file mode 100644 index 0000000..6bfc39a --- /dev/null +++ b/src/main/kotlin/top/fatweb/oxygen/api/service/tool/impl/EditServiceImpl.kt @@ -0,0 +1,92 @@ +package top.fatweb.oxygen.api.service.tool.impl + +import com.baomidou.mybatisplus.extension.kotlin.KtQueryWrapper +import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl +import org.springframework.stereotype.Service +import org.springframework.transaction.annotation.Transactional +import top.fatweb.oxygen.api.converter.tool.ToolCategoryConverter +import top.fatweb.oxygen.api.converter.tool.ToolConverter +import top.fatweb.oxygen.api.converter.tool.ToolTemplateConverter +import top.fatweb.oxygen.api.entity.tool.* +import top.fatweb.oxygen.api.exception.NoRecordFoundException +import top.fatweb.oxygen.api.exception.UserNotFoundException +import top.fatweb.oxygen.api.mapper.tool.EditMapper +import top.fatweb.oxygen.api.param.tool.ToolCreateParam +import top.fatweb.oxygen.api.param.tool.ToolUpdateParam +import top.fatweb.oxygen.api.service.tool.* +import top.fatweb.oxygen.api.util.WebUtil +import top.fatweb.oxygen.api.vo.tool.ToolCategoryVo +import top.fatweb.oxygen.api.vo.tool.ToolTemplateVo +import top.fatweb.oxygen.api.vo.tool.ToolVo + +/** + * Tool edit service implement + * + * @author FatttSnake, fatttsnake@gmail.com + * @since 1.0.0 + * @see ServiceImpl + * @see EditMapper + * @see Tool + * @see IEditService + */ +@Service +class EditServiceImpl( + private val toolTemplateService: IToolTemplateService, + private val toolCategoryService: IToolCategoryService, + private val toolDataService: IToolDataService, + private val rToolCategoryService: IRToolCategoryService +) : ServiceImpl(), IEditService { + override fun getTemplate(): List = + toolTemplateService.list(KtQueryWrapper(ToolTemplate()).eq(ToolTemplate::enable, 1)) + .map(ToolTemplateConverter::toolTemplateToToolTemplateVoByList) + + override fun getTemplate(id: Long): ToolTemplateVo = + baseMapper.getTemplate(id)?.let(ToolTemplateConverter::toolTemplateToToolTemplateVoWithBaseDist) + ?: throw NoRecordFoundException() + + override fun getCategory(): List = + toolCategoryService.list(KtQueryWrapper(ToolCategory()).eq(ToolCategory::enable, 1)) + .map(ToolCategoryConverter::toolCategoryToToolCategoryVo) + + override fun getOne(id: Long): ToolVo = + baseMapper.selectOne(id, WebUtil.getLoginUserId() ?: throw UserNotFoundException()) + ?.let(ToolConverter::toolToToolVo) ?: throw NoRecordFoundException() + + @Transactional + override fun create(toolCreateParam: ToolCreateParam): ToolVo { + val template = this.getTemplate(toolCreateParam.templateId!!) + val newSource = ToolData().apply { data = template.source!!.data } + val newDist = ToolData().apply { data = "" } + toolDataService.saveBatch(listOf(newSource, newDist)) + + val tool = Tool().apply { + name = toolCreateParam.name!!.trim() + toolId = toolCreateParam.toolId + description = toolCreateParam.description + baseId = template.base!!.id + authorId = WebUtil.getLoginUserId() ?: throw UserNotFoundException() + ver = toolCreateParam.ver!!.split(".").map(String::toLong).joinToString(".") + privately = if (toolCreateParam.privately) 1 else 0 + keywords = toolCreateParam.keywords + sourceId = newSource.id + distId = newDist.id + } + + this.save(tool) + + toolCreateParam.categories.forEach { + toolCategoryService.getById(it) ?: throw NoRecordFoundException() + rToolCategoryService.save(RToolCategory().apply { + toolId = tool.id + categoryId = it + }) + } + + return this.getOne(tool.id!!) + } + + @Transactional + override fun update(toolUpdateParam: ToolUpdateParam): ToolVo { + TODO("Not yet implemented") + } +} \ No newline at end of file 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 278dda4..e1070f9 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 @@ -38,8 +38,7 @@ class ToolBaseServiceImpl( val newSource = ToolData().apply { data = "" } val newDist = ToolData().apply { data = "" } - toolDataService.save(newSource) - toolDataService.save(newDist) + toolDataService.saveBatch(listOf(newSource, newDist)) val toolBase = ToolBase().apply { name = toolBaseAddParam.name @@ -47,7 +46,6 @@ class ToolBaseServiceImpl( distId = newDist.id source = newSource dist = newDist - enable = if (toolBaseAddParam.enable) 1 else 0 } this.save(toolBase) @@ -81,7 +79,6 @@ class ToolBaseServiceImpl( id = toolBaseUpdateParam.id name = toolBaseUpdateParam.name compiled = hasCompiled - enable = toolBaseUpdateParam.enable?.let { if (it) 1 else 0 } }) return this.getOne(toolBase.id!!) diff --git a/src/main/kotlin/top/fatweb/oxygen/api/service/tool/impl/ToolServiceImpl.kt b/src/main/kotlin/top/fatweb/oxygen/api/service/tool/impl/ToolServiceImpl.kt index ca982af..1f77089 100644 --- a/src/main/kotlin/top/fatweb/oxygen/api/service/tool/impl/ToolServiceImpl.kt +++ b/src/main/kotlin/top/fatweb/oxygen/api/service/tool/impl/ToolServiceImpl.kt @@ -1,21 +1,10 @@ package top.fatweb.oxygen.api.service.tool.impl -import com.baomidou.mybatisplus.extension.kotlin.KtQueryWrapper import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl import org.springframework.stereotype.Service -import org.springframework.transaction.annotation.Transactional -import top.fatweb.oxygen.api.converter.tool.ToolConverter -import top.fatweb.oxygen.api.entity.tool.RToolCategory import top.fatweb.oxygen.api.entity.tool.Tool -import top.fatweb.oxygen.api.entity.tool.ToolData -import top.fatweb.oxygen.api.exception.NoRecordFoundException -import top.fatweb.oxygen.api.exception.ToolHasPublish import top.fatweb.oxygen.api.mapper.tool.ToolMapper -import top.fatweb.oxygen.api.param.tool.ToolAddParam -import top.fatweb.oxygen.api.param.tool.ToolUpdateParam -import top.fatweb.oxygen.api.service.permission.IUserService -import top.fatweb.oxygen.api.service.tool.* -import top.fatweb.oxygen.api.vo.tool.ToolVo +import top.fatweb.oxygen.api.service.tool.IToolService /** * Tool service implement @@ -28,95 +17,54 @@ import top.fatweb.oxygen.api.vo.tool.ToolVo * @see IToolService */ @Service -class ToolServiceImpl( - private val toolDataService: IToolDataService, - private val toolBaseService: IToolBaseService, - private val toolCategoryService: IToolCategoryService, - private val rToolCategoryService: IRToolCategoryService, - private val userService: IUserService -) : ServiceImpl(), IToolService { - override fun getOne(id: Long): ToolVo = - baseMapper.selectOne(id)?.let(ToolConverter::toolToToolVo) ?: throw NoRecordFoundException() +class ToolServiceImpl : ServiceImpl(), IToolService { + /* + override fun getOne(id: Long): ToolVo = + baseMapper.selectOne(id)?.let(ToolConverter::toolToToolVo) ?: throw NoRecordFoundException() - override fun get(): List = baseMapper.selectList().map(ToolConverter::toolToToolVo) + override fun get(): List = baseMapper.selectList().map(ToolConverter::toolToToolVo) - @Transactional - override fun add(toolAddParam: ToolAddParam): ToolVo { - toolBaseService.getOne(toolAddParam.baseId!!) - userService.getOne(toolAddParam.authorId!!) + @Transactional + override fun update(toolUpdateParam: ToolUpdateParam): ToolVo { + val tool = baseMapper.selectOne(toolUpdateParam.id!!) ?: throw NoRecordFoundException() + if (tool.publish == 1) { + throw ToolHasPublish() + } + userService.getOne(toolUpdateParam.authorId!!) - val newSource = ToolData().apply { data = toolAddParam.source } - val newDist = ToolData().apply { data = toolAddParam.dist } - - toolDataService.save(newSource) - toolDataService.save(newDist) - - val tool = Tool().apply { - name = toolAddParam.name - toolId = toolAddParam.toolId - description = toolAddParam.description - baseId = toolAddParam.baseId - authorId = toolAddParam.authorId - ver = toolAddParam.ver - privately = if (toolAddParam.privately) 1 else 0 - keywords = toolAddParam.keywords - sourceId = newSource.id - distId = newDist.id - } - - this.save(tool) - - toolAddParam.categories.forEach { - toolCategoryService.getById(it) ?: throw NoRecordFoundException() - rToolCategoryService.save(RToolCategory().apply { - toolId = tool.id - categoryId = it + toolDataService.updateById(ToolData().apply { + id = tool.sourceId + data = toolUpdateParam.source }) + + toolDataService.updateById(ToolData().apply { + id = tool.distId + data = toolUpdateParam.dist + }) + + this.updateById(Tool().apply { + id = toolUpdateParam.id + name = toolUpdateParam.name + toolId = toolUpdateParam.toolId + description = toolUpdateParam.description + authorId = toolUpdateParam.authorId + ver = toolUpdateParam.ver + privately = toolUpdateParam.privately?.let { if (it) 1 else 0 } + keywords = toolUpdateParam.keywords + }) + + // TODO Category process + + return this.getOne(tool.id!!) } - return this.getOne(tool.id!!) - } + @Transactional + override fun delete(id: Long): Boolean { + val tool = this.getById(id) - @Transactional - override fun update(toolUpdateParam: ToolUpdateParam): ToolVo { - val tool = baseMapper.selectOne(toolUpdateParam.id!!) ?: throw NoRecordFoundException() - if (tool.publish == 1) { - throw ToolHasPublish() + return toolDataService.removeBatchByIds(listOf(tool.sourceId, tool.distId)) + && rToolCategoryService.remove(KtQueryWrapper(RToolCategory()).eq(RToolCategory::toolId, tool.id)) + && this.removeById(tool.id) } - userService.getOne(toolUpdateParam.authorId!!) - - toolDataService.updateById(ToolData().apply { - id = tool.sourceId - data = toolUpdateParam.source - }) - - toolDataService.updateById(ToolData().apply { - id = tool.distId - data = toolUpdateParam.dist - }) - - this.updateById(Tool().apply { - id = toolUpdateParam.id - name = toolUpdateParam.name - toolId = toolUpdateParam.toolId - description = toolUpdateParam.description - authorId = toolUpdateParam.authorId - ver = toolUpdateParam.ver - privately = toolUpdateParam.privately?.let { if (it) 1 else 0 } - keywords = toolUpdateParam.keywords - }) - - // TODO Category process - - return this.getOne(tool.id!!) - } - - @Transactional - override fun delete(id: Long): Boolean { - val tool = this.getById(id) - - return toolDataService.removeBatchByIds(listOf(tool.sourceId, tool.distId)) - && rToolCategoryService.remove(KtQueryWrapper(RToolCategory()).eq(RToolCategory::toolId, tool.id)) - && this.removeById(tool.id) - } + */ } \ No newline at end of file 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 47706bf..ab9e16a 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 @@ -50,6 +50,7 @@ class ToolTemplateServiceImpl( baseId = toolTemplateAddParam.baseId sourceId = newSource.id source = newSource + entryPoint = toolTemplateAddParam.entryPoint enable = if (toolTemplateAddParam.enable) 1 else 0 } @@ -72,6 +73,7 @@ class ToolTemplateServiceImpl( id = toolTemplateUpdateParam.id name = toolTemplateUpdateParam.name baseId = toolTemplateUpdateParam.baseId + entryPoint = toolTemplateUpdateParam.entryPoint enable = toolTemplateUpdateParam.enable?.let { if (it) 1 else 0 } }) diff --git a/src/main/kotlin/top/fatweb/oxygen/api/vo/tool/ToolBaseVo.kt b/src/main/kotlin/top/fatweb/oxygen/api/vo/tool/ToolBaseVo.kt index 954dcb0..0704766 100644 --- a/src/main/kotlin/top/fatweb/oxygen/api/vo/tool/ToolBaseVo.kt +++ b/src/main/kotlin/top/fatweb/oxygen/api/vo/tool/ToolBaseVo.kt @@ -58,15 +58,6 @@ data class ToolBaseVo( @Schema(description = "已编译") val compiled: Boolean?, - /** - * Enable - * - * @author FatttSnake, fatttsnake@gmail.com - * @since 1.0.0 - */ - @Schema(description = "启用") - val enable: Boolean?, - /** * Create time * 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 90b71d5..fea3b1f 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 @@ -49,6 +49,15 @@ data class ToolTemplateVo( @Schema(description = "源码") val source: ToolDataVo?, + /** + * Entry point + * + * @author FatttSnake, fatttsnake@gmail.com + * @since 1.0.0 + */ + @Schema(description = "入口文件") + val entryPoint: String?, + /** * Enable * diff --git a/src/main/kotlin/top/fatweb/oxygen/api/vo/tool/ToolVo.kt b/src/main/kotlin/top/fatweb/oxygen/api/vo/tool/ToolVo.kt index 3b7fe20..fe30113 100644 --- a/src/main/kotlin/top/fatweb/oxygen/api/vo/tool/ToolVo.kt +++ b/src/main/kotlin/top/fatweb/oxygen/api/vo/tool/ToolVo.kt @@ -2,41 +2,176 @@ package top.fatweb.oxygen.api.vo.tool import com.fasterxml.jackson.databind.annotation.JsonSerialize import com.fasterxml.jackson.databind.ser.std.ToStringSerializer -import top.fatweb.oxygen.api.vo.permission.base.UserInfoVo +import io.swagger.v3.oas.annotations.media.Schema +import top.fatweb.oxygen.api.entity.tool.Tool +import top.fatweb.oxygen.api.vo.permission.UserWithInfoVo import java.time.LocalDateTime -data class ToolVo ( +/** + * Tool value object + * + * @author FatttSnake, fatttsnake@gmail.com + * @since 1.0.0 + */ +data class ToolVo( + /** + * ID + * + * @author FatttSnake, fatttsnake@gmail.com + * @since 1.0.0 + */ @JsonSerialize(using = ToStringSerializer::class) val id: Long?, + /** + * Name + * + * @author FatttSnake, fatttsnake@gmail.com + * @since 1.0.0 + */ + @Schema(description = "名称") val name: String?, + /** + * Tool ID + * + * @author FatttSnake, fatttsnake@gmail.com + * @since 1.0.0 + */ + @Schema(description = "工具 ID") val toolId: String?, + /** + * Description + * + * @author FatttSnake, fatttsnake@gmail.com + * @since 1.0.0 + */ + @Schema(description = "简介") val description: String?, + /** + * Base ID + * + * @author FatttSnake, fatttsnake@gmail.com + * @since 1.0.0 + */ @JsonSerialize(using = ToStringSerializer::class) + @Schema(description = "基板 ID") val baseId: Long?, - val author: UserInfoVo?, + /** + * Author + * + * @author FatttSnake, fatttsnake@gmail.com + * @since 1.0.0 + * @see UserWithInfoVo + */ + @Schema(description = "作者") + val author: UserWithInfoVo?, + /** + * Version + * + * @author FatttSnake, fatttsnake@gmail.com + * @since 1.0.0 + */ + @Schema(description = "版本") val ver: String?, + /** + * Privately + * + * @author FatttSnake, fatttsnake@gmail.com + * @since 1.0.0 + */ + @Schema(description = "私有") val privately: Boolean?, + /** + * Keywords + * + * @author FatttSnake, fatttsnake@gmail.com + * @since 1.0.0 + */ + @Schema(description = "关键字") val keywords: List?, + /** + * Categories + * + * @author FatttSnake, fatttsnake@gmail.com + * @since 1.0.0 + * @see ToolCategoryVo + */ + @Schema(description = "类别") val categories: List?, + /** + * Source + * + * @author FatttSnake, fatttsnake@gmail.com + * @since 1.0.0 + * @see ToolDataVo + */ + @Schema(description = "源码") val source: ToolDataVo?, + /** + * Dist + * + * @author FatttSnake, fatttsnake@gmail.com + * @since 1.0.0 + * @see ToolDataVo + */ + @Schema(description = "产物") val dist: ToolDataVo?, + /** + * Entry point + * + * @author FatttSnake, fatttsnake@gmail.com + * @since 1.0.0 + */ + @Schema(description = "入口文件") + val entryPoint: String?, + + /** + * Publish + * + * @author FatttSnake, fatttsnake@gmail.com + * @since 1.0.0 + */ + @Schema(description = "发布") val publish: Boolean?, - val review: Int?, + /** + * Review + * + * @author FatttSnake, fatttsnake@gmail.com + * @since 1.0.0 + * @see Tool.ReviewType + */ + @Schema(description = "审核") + val review: Tool.ReviewType?, + /** + * Create time + * + * @author FatttSnake, fatttsnake@gmail.com + * @since 1.0.0 + * @see LocalDateTime + */ + @Schema(description = "创建时间", example = "1900-01-01T00:00:00.000Z") val createTime: LocalDateTime?, + /** + * Update time + * + * @author FatttSnake, fatttsnake@gmail.com + * @since 1.0.0 + * @see LocalDateTime + */ + @Schema(description = "修改时间", example = "1900-01-01T00:00:00.000Z") val updateTime: LocalDateTime? ) \ No newline at end of file diff --git a/src/main/resources/db/migration/master/V1_0_0_240115__Add_table_'t_b_tool_main'.sql b/src/main/resources/db/migration/master/V1_0_0_240115__Add_table_'t_b_tool_main'.sql index 45b96e6..9b24ce1 100644 --- a/src/main/resources/db/migration/master/V1_0_0_240115__Add_table_'t_b_tool_main'.sql +++ b/src/main/resources/db/migration/master/V1_0_0_240115__Add_table_'t_b_tool_main'.sql @@ -13,6 +13,7 @@ create table if not exists t_b_tool_main keywords varchar(500) not null comment '关键字', source_id bigint not null comment '源码 ID', dist_id bigint not null comment '产物 ID', + entry_point varchar(64) not null default 'main.tsx' comment '入口文件', publish int not null default 0 comment '发布', review varchar(10) not null default 'NONE' comment '审核', create_time datetime not null default (utc_timestamp()) comment '创建时间', 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 8a91504..0d442a9 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 @@ -6,6 +6,7 @@ create table if not exists t_b_tool_template name varchar(40) not null comment '模板名', base_id bigint not null comment '基板 ID', source_id bigint not null comment '源码 ID', + entry_point varchar(64) not null default 'main.tsx' comment '入口文件', 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/db/migration/master/V1_0_0_240120__Add_table_'t_b_tool_base'.sql b/src/main/resources/db/migration/master/V1_0_0_240120__Add_table_'t_b_tool_base'.sql index deee8b0..9225778 100644 --- a/src/main/resources/db/migration/master/V1_0_0_240120__Add_table_'t_b_tool_base'.sql +++ b/src/main/resources/db/migration/master/V1_0_0_240120__Add_table_'t_b_tool_base'.sql @@ -7,7 +7,6 @@ create table if not exists t_b_tool_base source_id bigint not null comment '源码 ID', dist_id bigint not null comment '产物 ID', compiled int not null default 0 comment '已编译', - 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 '修改时间', deleted bigint not null default 0, diff --git a/src/main/resources/mapper/tool/EditMapper.xml b/src/main/resources/mapper/tool/EditMapper.xml new file mode 100644 index 0000000..f3dd370 --- /dev/null +++ b/src/main/resources/mapper/tool/EditMapper.xml @@ -0,0 +1,142 @@ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + \ No newline at end of file diff --git a/src/main/resources/mapper/tool/ToolBaseMapper.xml b/src/main/resources/mapper/tool/ToolBaseMapper.xml index 26fe0c3..2994493 100644 --- a/src/main/resources/mapper/tool/ToolBaseMapper.xml +++ b/src/main/resources/mapper/tool/ToolBaseMapper.xml @@ -7,7 +7,6 @@ t_b_tool_base.source_id as tool_base_source_id, t_b_tool_base.dist_id as tool_base_dist_id, t_b_tool_base.compiled as tool_base_compiled, - t_b_tool_base.enable as tool_base_enable, t_b_tool_base.create_time as tool_base_create_time, t_b_tool_base.update_time as tool_base_update_time, t_b_tool_base.deleted as tool_base_deleted, @@ -36,7 +35,6 @@ - diff --git a/src/main/resources/mapper/tool/ToolCategoryMapper.xml b/src/main/resources/mapper/tool/ToolCategoryMapper.xml new file mode 100644 index 0000000..5be8646 --- /dev/null +++ b/src/main/resources/mapper/tool/ToolCategoryMapper.xml @@ -0,0 +1,13 @@ + + + + + + + + + + + + + \ No newline at end of file diff --git a/src/main/resources/mapper/tool/ToolTemplateMapper.xml b/src/main/resources/mapper/tool/ToolTemplateMapper.xml index be3e29a..b25a8eb 100644 --- a/src/main/resources/mapper/tool/ToolTemplateMapper.xml +++ b/src/main/resources/mapper/tool/ToolTemplateMapper.xml @@ -6,6 +6,7 @@ t_b_tool_template.name as tool_template_name, 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.entry_point as tool_template_entry_point, 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, @@ -16,8 +17,7 @@ tbtds.update_time as tool_template_source_update_time, tbtds.deleted as tool_template_source_delete, tbtds.version as tool_template_source_version, - tbtb.name as tool_template_base_name, - tbtb.enable as tool_template_base_enable + tbtb.name as tool_template_base_name 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 @@ -32,13 +32,13 @@ t_b_tool_template.name as tool_template_name, 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.entry_point as tool_template_entry_point, 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, t_b_tool_template.deleted as tool_template_deleted, t_b_tool_template.version as tool_template_version, - tbtb.name as tool_template_base_name, - tbtb.enable as tool_template_base_enable + tbtb.name as tool_template_base_name from t_b_tool_template left join (select * from t_b_tool_base where deleted = 0) as tbtb on tbtb.id = t_b_tool_template.base_id @@ -50,6 +50,7 @@ + @@ -58,7 +59,6 @@ -