Add create tool api
This commit is contained in:
@@ -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<ToolVo> =
|
||||
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<List<ToolTemplateVo>> =
|
||||
ResponseResult.databaseSuccess(data = editService.getTemplate())
|
||||
|
||||
@Operation(summary = "获取工具")
|
||||
@GetMapping
|
||||
fun get(): ResponseResult<List<ToolVo>> =
|
||||
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<ToolTemplateVo> =
|
||||
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<List<ToolCategoryVo>> =
|
||||
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<ToolVo> =
|
||||
ResponseResult.databaseSuccess(
|
||||
ResponseCode.DATABASE_INSERT_SUCCESS,
|
||||
data = toolService.add(toolAddParam)
|
||||
)
|
||||
|
||||
@Operation(summary = "更新工具")
|
||||
@PutMapping
|
||||
fun update(@RequestBody @Valid toolUpdateParam: ToolUpdateParam): ResponseResult<ToolVo> =
|
||||
ResponseResult.databaseSuccess(
|
||||
ResponseCode.DATABASE_UPDATE_SUCCESS,
|
||||
data = toolService.update(toolUpdateParam)
|
||||
)
|
||||
|
||||
@Operation(summary = "删除工具")
|
||||
@DeleteMapping("/{id}")
|
||||
fun delete(@PathVariable id: Long): ResponseResult<Nothing> =
|
||||
if (toolService.delete(id)) ResponseResult.databaseSuccess(ResponseCode.DATABASE_DELETE_SUCCESS)
|
||||
else ResponseResult.databaseFail(ResponseCode.DATABASE_DELETE_FAILED)
|
||||
fun create(@RequestBody @Valid toolCreateParam: ToolCreateParam): ResponseResult<ToolVo> =
|
||||
ResponseResult.databaseSuccess(ResponseCode.DATABASE_INSERT_SUCCESS, data = editService.create(toolCreateParam))
|
||||
}
|
||||
@@ -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<ToolVo> =
|
||||
ResponseResult.databaseSuccess(data = toolService.getOne(id))
|
||||
class ManagementController {
|
||||
/* @Operation(summary = "获取单个工具")
|
||||
@GetMapping("/{id}")
|
||||
fun getOne(@PathVariable id: Long): ResponseResult<ToolVo> =
|
||||
ResponseResult.databaseSuccess(data = toolService.getOne(id))
|
||||
|
||||
@Operation(summary = "获取工具")
|
||||
@GetMapping
|
||||
fun get(): ResponseResult<List<ToolVo>> =
|
||||
ResponseResult.databaseSuccess(data = toolService.get())
|
||||
@Operation(summary = "获取工具")
|
||||
@GetMapping
|
||||
fun get(): ResponseResult<List<ToolVo>> =
|
||||
ResponseResult.databaseSuccess(data = toolService.get())
|
||||
|
||||
@Operation(summary = "新增工具")
|
||||
@PostMapping
|
||||
fun add(@RequestBody @Valid toolAddParam: ToolAddParam): ResponseResult<ToolVo> =
|
||||
ResponseResult.databaseSuccess(
|
||||
ResponseCode.DATABASE_INSERT_SUCCESS,
|
||||
data = toolService.add(toolAddParam)
|
||||
)
|
||||
@Operation(summary = "更新工具")
|
||||
@PutMapping
|
||||
fun update(@RequestBody @Valid toolUpdateParam: ToolUpdateParam): ResponseResult<ToolVo> =
|
||||
ResponseResult.databaseSuccess(
|
||||
ResponseCode.DATABASE_UPDATE_SUCCESS,
|
||||
data = toolService.update(toolUpdateParam)
|
||||
)
|
||||
|
||||
@Operation(summary = "更新工具")
|
||||
@PutMapping
|
||||
fun update(@RequestBody @Valid toolUpdateParam: ToolUpdateParam): ResponseResult<ToolVo> =
|
||||
ResponseResult.databaseSuccess(
|
||||
ResponseCode.DATABASE_UPDATE_SUCCESS,
|
||||
data = toolService.update(toolUpdateParam)
|
||||
)
|
||||
|
||||
@Operation(summary = "删除工具")
|
||||
@DeleteMapping("/{id}")
|
||||
fun delete(@PathVariable id: Long): ResponseResult<Nothing> =
|
||||
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<Nothing> =
|
||||
if (toolService.delete(id)) ResponseResult.databaseSuccess(ResponseCode.DATABASE_DELETE_SUCCESS)
|
||||
else ResponseResult.databaseFail(ResponseCode.DATABASE_DELETE_FAILED)*/
|
||||
}
|
||||
@@ -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
|
||||
)
|
||||
}
|
||||
@@ -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,
|
||||
|
||||
@@ -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
|
||||
)
|
||||
}
|
||||
@@ -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)"
|
||||
}
|
||||
}
|
||||
@@ -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)"
|
||||
}
|
||||
}
|
||||
@@ -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)"
|
||||
}
|
||||
}
|
||||
@@ -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<Tool> {
|
||||
fun getTemplate(@Param("id") id: Long): ToolTemplate?
|
||||
|
||||
fun selectOne(@Param("id") id: Long, @Param("userId") userId: Long): Tool?
|
||||
}
|
||||
@@ -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<Tool> {
|
||||
fun selectOne(@Param("id") id: Long): Tool?
|
||||
|
||||
fun selectList(): List<Tool>
|
||||
}
|
||||
interface ToolMapper : BaseMapper<Tool>
|
||||
@@ -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 '<number>.<number>.<number>'")
|
||||
val ver: String?,
|
||||
|
||||
val privately: Boolean = false,
|
||||
|
||||
@field: NotEmpty(message = "Keywords can not be empty")
|
||||
val keywords: List<String>,
|
||||
|
||||
@field: NotEmpty(message = "Categories can not be empty")
|
||||
val categories: List<Long>,
|
||||
|
||||
@field: NotNull(message = "Source can not be null")
|
||||
val source: String?,
|
||||
|
||||
@field:NotNull(message = "Dist can not be null")
|
||||
val dist: String?
|
||||
)
|
||||
@@ -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?
|
||||
)
|
||||
|
||||
@@ -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?
|
||||
)
|
||||
|
||||
@@ -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 '<number>.<number>.<number>'")
|
||||
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<String>,
|
||||
|
||||
/**
|
||||
* 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<Long>
|
||||
)
|
||||
@@ -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
|
||||
*
|
||||
|
||||
@@ -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
|
||||
*
|
||||
|
||||
@@ -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 '<number>.<number>.<number>'")
|
||||
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<String>,
|
||||
|
||||
/**
|
||||
* Categories
|
||||
*
|
||||
* @author FatttSnake, fatttsnake@gmail.com
|
||||
* @since 1.0.0
|
||||
*/
|
||||
@Schema(description = "类别")
|
||||
val categories: List<Long>,
|
||||
|
||||
/**
|
||||
* 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?
|
||||
)
|
||||
|
||||
@@ -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<Tool> {
|
||||
/**
|
||||
* Get tool template as list
|
||||
*
|
||||
* @return List of ToolTemplateVo object
|
||||
* @author FatttSnake, fatttsnake@gmail.com
|
||||
* @since 1.0.0
|
||||
* @see ToolTemplateVo
|
||||
*/
|
||||
fun getTemplate(): List<ToolTemplateVo>
|
||||
|
||||
/**
|
||||
* 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<ToolCategoryVo>
|
||||
|
||||
/**
|
||||
* 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
|
||||
}
|
||||
@@ -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<Tool> {
|
||||
fun getOne(id: Long): ToolVo
|
||||
|
||||
fun get(): List<ToolVo>
|
||||
|
||||
fun add(toolAddParam: ToolAddParam): ToolVo
|
||||
|
||||
fun update(toolUpdateParam: ToolUpdateParam): ToolVo
|
||||
|
||||
fun delete(id: Long): Boolean
|
||||
}
|
||||
interface IToolService : IService<Tool>
|
||||
@@ -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<EditMapper, Tool>(), IEditService {
|
||||
override fun getTemplate(): List<ToolTemplateVo> =
|
||||
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<ToolCategoryVo> =
|
||||
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")
|
||||
}
|
||||
}
|
||||
@@ -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!!)
|
||||
|
||||
@@ -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<ToolMapper, Tool>(), IToolService {
|
||||
override fun getOne(id: Long): ToolVo =
|
||||
baseMapper.selectOne(id)?.let(ToolConverter::toolToToolVo) ?: throw NoRecordFoundException()
|
||||
class ToolServiceImpl : ServiceImpl<ToolMapper, Tool>(), IToolService {
|
||||
/*
|
||||
override fun getOne(id: Long): ToolVo =
|
||||
baseMapper.selectOne(id)?.let(ToolConverter::toolToToolVo) ?: throw NoRecordFoundException()
|
||||
|
||||
override fun get(): List<ToolVo> = baseMapper.selectList().map(ToolConverter::toolToToolVo)
|
||||
override fun get(): List<ToolVo> = 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)
|
||||
}
|
||||
*/
|
||||
}
|
||||
@@ -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 }
|
||||
})
|
||||
|
||||
|
||||
@@ -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
|
||||
*
|
||||
|
||||
@@ -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
|
||||
*
|
||||
|
||||
@@ -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<String>?,
|
||||
|
||||
/**
|
||||
* Categories
|
||||
*
|
||||
* @author FatttSnake, fatttsnake@gmail.com
|
||||
* @since 1.0.0
|
||||
* @see ToolCategoryVo
|
||||
*/
|
||||
@Schema(description = "类别")
|
||||
val categories: List<ToolCategoryVo>?,
|
||||
|
||||
/**
|
||||
* 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?
|
||||
)
|
||||
Reference in New Issue
Block a user