Add tool api

This commit is contained in:
2024-01-18 14:14:36 +08:00
parent 0512bab3ca
commit d559fc53dd
52 changed files with 1738 additions and 64 deletions

View File

@@ -1,5 +0,0 @@
package top.fatweb.oxygen.api.controller.common
class ToolController {
}

View File

@@ -25,6 +25,7 @@ import top.fatweb.oxygen.api.vo.system.SensitiveWordVo
* @author FatttSnake, fatttsnake@gmail.com
* @since 1.0.0
* @see ISettingsService
* @see ISensitiveWordService
*/
@BaseController(path = ["/system/settings"], name = "系统设置", description = "系统设置相关接口")
class SettingsController(

View File

@@ -0,0 +1,50 @@
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.ToolBaseAddParam
import top.fatweb.oxygen.api.param.tool.ToolBaseUpdateParam
import top.fatweb.oxygen.api.service.tool.IToolBaseService
import top.fatweb.oxygen.api.vo.tool.ToolBaseVo
@BaseController(path = ["/system/tool/base"], name = "工具基板管理", description = "工具基板管理相关接口")
class BaseController(
private val toolBaseService: IToolBaseService
) {
@Operation(summary = "获取单个基板")
@GetMapping("/{id}")
fun getOne(@PathVariable id: Long): ResponseResult<ToolBaseVo> =
toolBaseService.getOne(id)?.let { ResponseResult.databaseSuccess(data = it) }
?: let { ResponseResult.databaseFail(ResponseCode.DATABASE_NO_RECORD_FOUND) }
@Operation(summary = "获取基板")
@GetMapping
fun get(): ResponseResult<List<ToolBaseVo>> =
ResponseResult.databaseSuccess(data = toolBaseService.get())
@Operation(summary = "新增基板")
@PostMapping
fun add(@RequestBody @Valid toolBaseAddParam: ToolBaseAddParam): ResponseResult<ToolBaseVo> =
ResponseResult.databaseSuccess(
ResponseCode.DATABASE_INSERT_SUCCESS,
data = toolBaseService.add(toolBaseAddParam)
)
@Operation(summary = "更新基板")
@PutMapping
fun update(@RequestBody @Valid toolBaseUpdateParam: ToolBaseUpdateParam): ResponseResult<ToolBaseVo> =
ResponseResult.databaseSuccess(
ResponseCode.DATABASE_UPDATE_SUCCESS,
data = toolBaseService.update(toolBaseUpdateParam)
)
@Operation(summary = "删除基板")
@DeleteMapping("/{id}")
fun delete(@PathVariable id: Long): ResponseResult<Nothing> =
if (toolBaseService.delete(id)) ResponseResult.databaseSuccess(ResponseCode.DATABASE_DELETE_SUCCESS)
else ResponseResult.databaseFail(ResponseCode.DATABASE_DELETE_FILED)
}

View File

@@ -0,0 +1,57 @@
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.ToolCategoryAddParam
import top.fatweb.oxygen.api.param.tool.ToolCategoryUpdateParam
import top.fatweb.oxygen.api.service.tool.IToolCategoryService
import top.fatweb.oxygen.api.vo.tool.ToolCategoryVo
/**
* Tool category management controller
*
* @author FatttSnake, fatttsnake@gmail.com
* @since 1.0.0
*/
@BaseController(path = ["/system/tool/category"], name = "工具类别管理", description = "工具列别管理相关接口")
class CategoryController(
private val toolCategoryService: IToolCategoryService
) {
@Operation(summary = "获取单个类别")
@GetMapping("/{id}")
fun getOne(@PathVariable id: Long): ResponseResult<ToolCategoryVo> =
toolCategoryService.getOne(id)?.let { ResponseResult.databaseSuccess(data = it) }
?: let { ResponseResult.databaseFail(ResponseCode.DATABASE_NO_RECORD_FOUND) }
@Operation(summary = "获取类别")
@GetMapping
fun get(): ResponseResult<List<ToolCategoryVo>> =
ResponseResult.databaseSuccess(data = toolCategoryService.get())
@Operation(summary = "新增类别")
@PostMapping
fun add(@RequestBody @Valid toolCategoryAddParam: ToolCategoryAddParam): ResponseResult<ToolCategoryVo> =
ResponseResult.databaseSuccess(
ResponseCode.DATABASE_INSERT_SUCCESS,
data = toolCategoryService.add(toolCategoryAddParam)
)
@Operation(summary = "更新类别")
@PutMapping
fun update(@RequestBody @Valid toolCategoryUpdateParam: ToolCategoryUpdateParam): ResponseResult<ToolCategoryVo> =
ResponseResult.databaseSuccess(
ResponseCode.DATABASE_UPDATE_SUCCESS,
data = toolCategoryService.update(toolCategoryUpdateParam)
)
@Operation(summary = "删除类别")
@DeleteMapping("/{id}")
fun delete(@PathVariable id: Long): ResponseResult<Nothing> =
if (toolCategoryService.delete(id)) ResponseResult.databaseSuccess(ResponseCode.DATABASE_DELETE_SUCCESS)
else ResponseResult.databaseFail(ResponseCode.DATABASE_DELETE_FILED)
}

View File

@@ -0,0 +1,56 @@
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
/**
* Tool management controller
*
* @author FatttSnake, fatttsnake@gmail.com
* @since 1.0.0
*/
@BaseController(path = ["/tool"], name = "工具管理", description = "工具管理相关接口")
class EditController(
private val toolService: IToolService
) {
@Operation(summary = "获取单个工具")
@GetMapping("/{id}")
fun getOne(@PathVariable id: Long): ResponseResult<ToolVo> =
toolService.getOne(id)?.let { ResponseResult.databaseSuccess(data = it) }
?: let { ResponseResult.databaseFail(ResponseCode.DATABASE_NO_RECORD_FOUND) }
@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 = "删除工具")
@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_FILED)
}

View File

@@ -0,0 +1,50 @@
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> =
toolService.getOne(id)?.let { ResponseResult.databaseSuccess(data = it) }
?: let { ResponseResult.databaseFail(ResponseCode.DATABASE_NO_RECORD_FOUND) }
@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 = "删除工具")
@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_FILED)
}

View File

@@ -0,0 +1,50 @@
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.ToolTemplateAddParam
import top.fatweb.oxygen.api.param.tool.ToolTemplateUpdateParam
import top.fatweb.oxygen.api.service.tool.IToolTemplateService
import top.fatweb.oxygen.api.vo.tool.ToolTemplateVo
@BaseController(path = ["/system/tool/template"], name = "工具模板管理", description = "工具模板管理相关接口")
class TemplateController(
private val toolTemplateService: IToolTemplateService
) {
@Operation(summary = "获取单个模板")
@GetMapping("/{id}")
fun getOne(@PathVariable id: Long): ResponseResult<ToolTemplateVo> =
toolTemplateService.getOne(id)?.let { ResponseResult.databaseSuccess(data = it) }
?: let { ResponseResult.databaseFail(ResponseCode.DATABASE_NO_RECORD_FOUND) }
@Operation(summary = "获取模板")
@GetMapping
fun get(): ResponseResult<List<ToolTemplateVo>> =
ResponseResult.databaseSuccess(data = toolTemplateService.get())
@Operation(summary = "添加模板")
@PostMapping
fun add(@RequestBody @Valid toolTemplateAddParam: ToolTemplateAddParam): ResponseResult<ToolTemplateVo> =
ResponseResult.databaseSuccess(
ResponseCode.DATABASE_INSERT_SUCCESS,
data = toolTemplateService.add(toolTemplateAddParam)
)
@Operation(summary = "更新模板")
@PutMapping
fun update(@RequestBody @Valid toolTemplateUpdateParam: ToolTemplateUpdateParam): ResponseResult<ToolTemplateVo> =
ResponseResult.databaseSuccess(
ResponseCode.DATABASE_UPDATE_SUCCESS,
data = toolTemplateService.update(toolTemplateUpdateParam)
)
@Operation(summary = "删除模板")
@DeleteMapping("/{id}")
fun delete(@PathVariable id: Long): ResponseResult<Nothing> =
if (toolTemplateService.delete(id)) ResponseResult.databaseSuccess(ResponseCode.DATABASE_DELETE_SUCCESS)
else ResponseResult.databaseFail(ResponseCode.DATABASE_DELETE_FILED)
}

View File

@@ -0,0 +1,16 @@
package top.fatweb.oxygen.api.converter.tool
import top.fatweb.oxygen.api.entity.tool.ToolBase
import top.fatweb.oxygen.api.param.tool.ToolBaseAddParam
import top.fatweb.oxygen.api.vo.tool.ToolBaseVo
object ToolBaseConverter {
fun toolBaseToToolBaseVo(toolBase: ToolBase) = ToolBaseVo(
id = toolBase.id,
name = toolBase.name,
source = toolBase.source?.let(ToolDataConverter::toolDataToToolDataVo),
dist = toolBase.dist?.let(ToolDataConverter::toolDataToToolDataVo),
createTime = toolBase.createTime,
updateTime = toolBase.updateTime
)
}

View File

@@ -0,0 +1,27 @@
package top.fatweb.oxygen.api.converter.tool
import top.fatweb.oxygen.api.entity.tool.ToolCategory
import top.fatweb.oxygen.api.param.tool.ToolCategoryAddParam
import top.fatweb.oxygen.api.param.tool.ToolCategoryUpdateParam
import top.fatweb.oxygen.api.vo.tool.ToolCategoryVo
object ToolCategoryConverter {
fun toolCategoryToToolCategoryVo(toolCategory: ToolCategory) = ToolCategoryVo(
id = toolCategory.id,
name = toolCategory.name,
enable = toolCategory.enable == 1,
createTime = toolCategory.createTime,
updateTime = toolCategory.updateTime
)
fun toolCategoryAddParamToToolCategory(toolCategoryAddParam: ToolCategoryAddParam) = ToolCategory().apply {
name = toolCategoryAddParam.name
enable = if (toolCategoryAddParam.enable) 1 else 0
}
fun toolCategoryUpdateParamToToolCategory(toolCategoryUpdateParam: ToolCategoryUpdateParam) = ToolCategory().apply {
id = toolCategoryUpdateParam.id
name = toolCategoryUpdateParam.name
enable = toolCategoryUpdateParam.enable?. let { if (it) 1 else 0 }
}
}

View File

@@ -0,0 +1,26 @@
package top.fatweb.oxygen.api.converter.tool
import top.fatweb.oxygen.api.converter.permission.UserInfoConverter
import top.fatweb.oxygen.api.entity.tool.Tool
import top.fatweb.oxygen.api.vo.tool.ToolVo
object ToolConverter {
fun toolToToolVo(tool: Tool) = ToolVo(
id = tool.id,
name = tool.name,
toolId = tool.toolId,
description = tool.description,
baseId = tool.baseId,
author = tool.author?.let(UserInfoConverter::userInfoToUserInfoVo),
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),
publish = tool.publish == 1,
review = tool.review,
createTime = tool.createTime,
updateTime = tool.updateTime
)
}

View File

@@ -0,0 +1,13 @@
package top.fatweb.oxygen.api.converter.tool
import top.fatweb.oxygen.api.entity.tool.ToolData
import top.fatweb.oxygen.api.vo.tool.ToolDataVo
object ToolDataConverter {
fun toolDataToToolDataVo(toolData: ToolData) = ToolDataVo(
id = toolData.id,
data = toolData.data,
createTime = toolData.createTime,
updateTime = toolData.updateTime
)
}

View File

@@ -0,0 +1,17 @@
package top.fatweb.oxygen.api.converter.tool
import top.fatweb.oxygen.api.entity.tool.ToolTemplate
import top.fatweb.oxygen.api.vo.tool.ToolTemplateVo
object ToolTemplateConverter {
fun toolTemplateToToolTemplateVo(toolTemplate: ToolTemplate) = ToolTemplateVo(
id = toolTemplate.id,
name = toolTemplate.name,
ver = toolTemplate.ver,
baseId = toolTemplate.baseId,
source = toolTemplate.source?.let(ToolDataConverter::toolDataToToolDataVo),
dist = toolTemplate.dist?.let(ToolDataConverter::toolDataToToolDataVo),
createTime = toolTemplate.createTime,
updateTime = toolTemplate.updateTime
)
}

View File

@@ -2,6 +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 java.time.LocalDateTime
/**
* Tool entity
@@ -48,13 +50,22 @@ class Tool {
var description: String? = null
/**
* Author
* Base ID
*
* @author FatttSnake, fatttsnake@gmail.com
* @since 1.0.0
*/
@TableField("author")
var author: Long? = null
@TableField("base_id")
var baseId: Long? = null
/**
* Author ID
*
* @author FatttSnake, fatttsnake@gmail.com
* @since 1.0.0
*/
@TableField("author_id")
var authorId: Long? = null
/**
* Version of tool
@@ -75,30 +86,31 @@ class Tool {
var privately: Int? = null
/**
* Keyword
* Keywords
*
* @author FatttSnake, fatttsnake@gmail.com
* @since 1.0.0
*/
@TableField("keyword", typeHandler = JacksonTypeHandler::class)
var keyword: List<String>? = null
@TableField("keywords", typeHandler = JacksonTypeHandler::class)
var keywords: List<String>? = null
/**
* Source code
* Source code ID
*
* @author FatttSnake, fatttsnake@gmail.com
* @since 1.0.0
*/
@TableField("source")
var source: Long? = null
@TableField("source_id")
var sourceId: Long? = null
/**
* Compile product
* Compile product ID
*
* @author FatttSnake, fatttsnake@gmail.com
* @since 1.0.0
*/
var dist: Long? = null
@TableField("dist_id")
var distId: Long? = null
/**
* Publish
@@ -106,6 +118,7 @@ class Tool {
* @author FatttSnake, fatttsnake@gmail.com
* @since 1.0.0
*/
@TableField("publish")
var publish: Int? = null
/**
@@ -114,8 +127,29 @@ class Tool {
* @author FatttSnake, fatttsnake@gmail.com
* @since 1.0.0
*/
@TableField("review")
var review: Int? = null
/**
* Create time
*
* @author FatttSnake, fatttsnake@gmail.com
* @since 1.0.0
* @see LocalDateTime
*/
@TableField("create_time", fill = FieldFill.INSERT)
var createTime: LocalDateTime? = null
/**
* Update time
*
* @author FatttSnake, fatttsnake@gmail.com
* @since 1.0.0
* @see LocalDateTime
*/
@TableField("update_time", fill = FieldFill.INSERT_UPDATE)
var updateTime: LocalDateTime? = null
/**
* Deleted
*
@@ -136,7 +170,43 @@ class Tool {
@Version
var version: Int? = null
/**
* Author
*
* @author FatttSnake, fatttsnake@gmail.com
* @since 1.0.0
*/
@TableField(exist = false)
var author: UserInfo? = null
/**
* Categories
*
* @author FatttSnake, fatttsnake@gmail.com
* @since 1.0.0
*/
@TableField(exist = false)
var categories: List<ToolCategory>? = null
/**
* Source
*
* @author FatttSnake, fatttsnake@gmail.com
* @since 1.0.0
*/
@TableField(exist = false)
var source: ToolData? = null
/**
* Dist
*
* @author FatttSnake, fatttsnake@gmail.com
* @since 1.0.0
*/
@TableField(exist = false)
var dist: ToolData? = null
override fun toString(): String {
return "Tool(id=$id, name=$name, toolId=$toolId, description=$description, author=$author, ver=$ver, privately=$privately, keyword=$keyword, source=$source, dist=$dist, publish=$publish, review=$review, deleted=$deleted, version=$version)"
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)"
}
}

View File

@@ -0,0 +1,111 @@
package top.fatweb.oxygen.api.entity.tool
import com.baomidou.mybatisplus.annotation.*
import java.time.LocalDateTime
/**
* Tool base entity
*
* @author FatttSnake, fatttsnake@gmail.com
* @since 1.0.0
*/
@TableName("t_b_tool_base")
class ToolBase {
/**
* ID
*
* @author FatttSnake, fatttsnake@gmail.com
* @since 1.0.0
*/
@TableId("id")
var id: Long? = null
/**
* Name
*
* @author FatttSnake, fatttsnake@gmail.com
* @since 1.0.0
*/
@TableField("name")
var name: String? = null
/**
* Source ID
*
* @author FatttSnake, fatttsnake@gmail.com
* @since 1.0.0
*/
@TableField("source_id")
var sourceId: Long? = null
/**
* Dist ID
*
* @author FatttSnake, fatttsnake@gmail.com
* @since 1.0.0
*/
@TableField("dist_id")
var distId: Long? = null
/**
* Create time
*
* @author FatttSnake, fatttsnake@gmail.com
* @since 1.0.0
* @see LocalDateTime
*/
@TableField("create_time", fill = FieldFill.INSERT)
var createTime: LocalDateTime? = null
/**
* Update time
*
* @author FatttSnake, fatttsnake@gmail.com
* @since 1.0.0
* @see LocalDateTime
*/
@TableField("update_time", fill = FieldFill.INSERT_UPDATE)
var updateTime: LocalDateTime? = null
/**
* Deleted
*
* @author FatttSnake, fatttsnake@gmail.com
* @since 1.0.0
*/
@TableField("deleted")
@TableLogic
var deleted: Long? = null
/**
* Version
*
* @author FatttSnake, fatttsnake@gmail.com
* @since 1.0.0
*/
@TableField("version")
@Version
var version: Int? = null
/**
* Source
*
* @author FatttSnake, fatttsnake@gmail.com
* @since 1.0.0
*/
@TableField(exist = false)
var source: ToolData? = null
/**
* Dist
*
* @author FatttSnake, fatttsnake@gmail.com
* @since 1.0.0
*/
@TableField(exist = false)
var dist: ToolData? = null
override fun toString(): String {
return "ToolBase(id=$id, name=$name, sourceId=$sourceId, distId=$distId, createTime=$createTime, updateTime=$updateTime, deleted=$deleted, version=$version, source=$source, dist=$dist)"
}
}

View File

@@ -1,6 +1,7 @@
package top.fatweb.oxygen.api.entity.tool
import com.baomidou.mybatisplus.annotation.*
import java.time.LocalDateTime
/**
* Tool category entity
@@ -37,6 +38,26 @@ class ToolCategory {
@TableField("enable")
var enable: Int? = null
/**
* Create time
*
* @author FatttSnake, fatttsnake@gmail.com
* @since 1.0.0
* @see LocalDateTime
*/
@TableField("create_time", fill = FieldFill.INSERT)
var createTime: LocalDateTime? = null
/**
* Update time
*
* @author FatttSnake, fatttsnake@gmail.com
* @since 1.0.0
* @see LocalDateTime
*/
@TableField("update_time", fill = FieldFill.INSERT_UPDATE)
var updateTime: LocalDateTime? = null
/**
* Deleted
*
@@ -58,6 +79,6 @@ class ToolCategory {
var version: Int? = null
override fun toString(): String {
return "ToolCategory(id=$id, name=$name, enable=$enable, deleted=$deleted, version=$version)"
return "ToolCategory(id=$id, name=$name, enable=$enable, createTime=$createTime, updateTime=$updateTime, deleted=$deleted, version=$version)"
}
}

View File

@@ -1,8 +1,7 @@
package top.fatweb.oxygen.api.entity.tool
import com.baomidou.mybatisplus.annotation.TableField
import com.baomidou.mybatisplus.annotation.TableId
import com.baomidou.mybatisplus.annotation.TableName
import com.baomidou.mybatisplus.annotation.*
import java.time.LocalDateTime
/**
* Tool data entity
@@ -30,7 +29,47 @@ class ToolData {
@TableField("data")
var data: String? = null
/**
* Create time
*
* @author FatttSnake, fatttsnake@gmail.com
* @since 1.0.0
* @see LocalDateTime
*/
@TableField("create_time", fill = FieldFill.INSERT)
var createTime: LocalDateTime? = null
/**
* Update time
*
* @author FatttSnake, fatttsnake@gmail.com
* @since 1.0.0
* @see LocalDateTime
*/
@TableField("update_time", fill = FieldFill.INSERT_UPDATE)
var updateTime: LocalDateTime? = null
/**
* Deleted
*
* @author FatttSnake, fatttsnake@gmail.com
* @since 1.0.0
*/
@TableField("deleted")
@TableLogic
var deleted: Long? = null
/**
* Version
*
* @author FatttSnake, fatttsnake@gmail.com
* @since 1.0.0
*/
@TableField("version")
@Version
var version: Int? = null
override fun toString(): String {
return "ToolData(id=$id, data=$data)"
return "ToolData(id=$id, data=$data, createTime=$createTime, updateTime=$updateTime, deleted=$deleted, version=$version)"
}
}

View File

@@ -0,0 +1,129 @@
package top.fatweb.oxygen.api.entity.tool
import com.baomidou.mybatisplus.annotation.*
import java.time.LocalDateTime
/**
* Tool template entity
*
* @author FatttSnake, fatttsnake@gmail.com
* @since 1.0.0
*/
@TableName("t_b_tool_template")
class ToolTemplate {
/**
* ID
*
* @author FatttSnake, fatttsnake@gmail.com
* @since 1.0.0
*/
@TableId("id")
var id: Long? = null
/**
* Name
*
* @author FatttSnake, fatttsnake@gmail.com
* @since 1.0.0
*/
@TableField("name")
var name: String? = null
/**
* ver
*
* @author FatttSnake, fatttsnake@gmail.com
* @since 1.0.0
*/
@TableField("ver")
var ver: String? = null
/**
* Base ID
*
* @author FatttSnake, fatttsnake@gmail.com
* @since 1.0.0
*/
@TableField("base_id")
var baseId: Long? = null
/**
* Source ID
*
* @author FatttSnake, fatttsnake@gmail.com
* @since 1.0.0
*/
@TableField("source_id")
var sourceId: Long? = null
/**
* Dist ID
*
* @author FatttSnake, fatttsnake@gmail.com
* @since 1.0.0
*/
@TableField("dist_id")
var distId: Long? = null
/**
* Create time
*
* @author FatttSnake, fatttsnake@gmail.com
* @since 1.0.0
* @see LocalDateTime
*/
@TableField("create_time", fill = FieldFill.INSERT)
var createTime: LocalDateTime? = null
/**
* Update time
*
* @author FatttSnake, fatttsnake@gmail.com
* @since 1.0.0
* @see LocalDateTime
*/
@TableField("update_time", fill = FieldFill.INSERT_UPDATE)
var updateTime: LocalDateTime? = null
/**
* Deleted
*
* @author FatttSnake, fatttsnake@gmail.com
* @since 1.0.0
*/
@TableField("deleted")
@TableLogic
var deleted: Long? = null
/**
* Version
*
* @author FatttSnake, fatttsnake@gmail.com
* @since 1.0.0
*/
@TableField("version")
@Version
var version: Int? = null
/**
* Source
*
* @author FatttSnake, fatttsnake@gmail.com
* @since 1.0.0
*/
@TableField(exist = false)
var source: ToolData? = null
/**
* Dist
*
* @author FatttSnake, fatttsnake@gmail.com
* @since 1.0.0
*/
@TableField(exist = false)
var dist: ToolData? = null
override fun toString(): String {
return "ToolTemplate(id=$id, name=$name, ver=$ver, baseId=$baseId, sourceId=$sourceId, distId=$distId, createTime=$createTime, updateTime=$updateTime, deleted=$deleted, version=$version)"
}
}

View File

@@ -0,0 +1,3 @@
package top.fatweb.oxygen.api.exception
class ToolHasPublish : RuntimeException("The tool has been published and cannot be modified")

View File

@@ -0,0 +1,21 @@
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.ToolBase
/**
* Tool base mapper
*
* @author FatttSnake, fatttsnake@gmail.com
* @since 1.0.0
* @see BaseMapper
* @see ToolBase
*/
@Mapper
interface ToolBaseMapper : BaseMapper<ToolBase> {
fun selectOne(@Param("id") id: Long): ToolBase?
fun selectList(): List<ToolBase>
}

View File

@@ -2,6 +2,7 @@ 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
/**
@@ -13,4 +14,8 @@ import top.fatweb.oxygen.api.entity.tool.Tool
* @see Tool
*/
@Mapper
interface ToolMapper : BaseMapper<Tool>
interface ToolMapper : BaseMapper<Tool> {
fun selectOne(@Param("id") id: Long): Tool?
fun selectList(): List<Tool>
}

View File

@@ -0,0 +1,21 @@
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.ToolTemplate
/**
* Tool template mapper
*
* @author FatttSnake, fatttsnake@gmail.com
* @since 1.0.0
* @see BaseMapper
* @see ToolTemplate
*/
@Mapper
interface ToolTemplateMapper : BaseMapper<ToolTemplate> {
fun selectOne(@Param("id") id: Long): ToolTemplate?
fun selectList(): List<ToolTemplate>
}

View File

@@ -0,0 +1,44 @@
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?
)

View File

@@ -0,0 +1,15 @@
package top.fatweb.oxygen.api.param.tool
import jakarta.validation.constraints.NotBlank
import jakarta.validation.constraints.NotNull
data class ToolBaseAddParam(
@field: NotBlank(message = "Name can not be blank")
val name: String?,
@field: NotNull(message = "Source can not be null")
val source: String?,
@field:NotNull(message = "Dist can not be null")
val dist: String?
)

View File

@@ -0,0 +1,14 @@
package top.fatweb.oxygen.api.param.tool
import jakarta.validation.constraints.NotNull
data class ToolBaseUpdateParam(
@field: NotNull(message = "ID can not be null")
val id: Long?,
val name: String?,
val source: String?,
val dist: String?
)

View File

@@ -0,0 +1,10 @@
package top.fatweb.oxygen.api.param.tool
import jakarta.validation.constraints.NotBlank
data class ToolCategoryAddParam(
@field: NotBlank(message = "Name can not be blank")
val name: String?,
val enable: Boolean = true
)

View File

@@ -0,0 +1,14 @@
package top.fatweb.oxygen.api.param.tool
import jakarta.validation.constraints.NotBlank
import jakarta.validation.constraints.NotNull
data class ToolCategoryUpdateParam(
@field: NotNull(message = "ID can not be null")
val id: Long?,
@field: NotBlank(message = "Name can not be blank")
val name: String?,
val enable: Boolean?
)

View File

@@ -0,0 +1,23 @@
package top.fatweb.oxygen.api.param.tool
import jakarta.validation.constraints.NotBlank
import jakarta.validation.constraints.NotNull
import jakarta.validation.constraints.Pattern
data class ToolTemplateAddParam(
@field: NotBlank(message = "Name can not be blank")
val name: String?,
@field: NotBlank(message = "Ver can not be blank")
@field: Pattern(regexp = "^\\d+\\.\\d+\\.\\d+\$", message = "Ver can only match '<number>.<number>.<number>'")
val ver: String?,
@field: NotNull(message = "BaseId can not be null")
val baseId: Long? = null,
@field: NotNull(message = "Source can not be null")
val source: String?,
@field:NotNull(message = "Dist can not be null")
val dist: String?
)

View File

@@ -0,0 +1,20 @@
package top.fatweb.oxygen.api.param.tool
import jakarta.validation.constraints.NotNull
import jakarta.validation.constraints.Pattern
data class ToolTemplateUpdateParam(
@field: NotNull(message = "ID can not be null")
val id: Long?,
val name: String?,
@field: Pattern(regexp = "^\\d+\\.\\d+\\.\\d+\$", message = "Ver can only match '<number>.<number>.<number>'")
val ver: String?,
val baseId: Long?,
val source: String?,
val dist: String?
)

View File

@@ -0,0 +1,34 @@
package top.fatweb.oxygen.api.param.tool
import jakarta.validation.constraints.NotNull
import jakarta.validation.constraints.Pattern
data class ToolUpdateParam(
@field: NotNull(message = "ID can not be null")
val id: Long?,
val name: String?,
@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?,
val authorId: Long?,
@field: Pattern(regexp = "^\\d+\\.\\d+\\.\\d+\$", message = "Ver can only match '<number>.<number>.<number>'")
val ver: String?,
val privately: Boolean?,
val keywords: List<String>,
val categories: List<Long>,
val source: String?,
val dist: String?
)

View File

@@ -0,0 +1,29 @@
package top.fatweb.oxygen.api.service.tool
import com.baomidou.mybatisplus.extension.service.IService
import top.fatweb.oxygen.api.entity.tool.ToolBase
import top.fatweb.oxygen.api.entity.tool.ToolCategory
import top.fatweb.oxygen.api.param.tool.ToolBaseAddParam
import top.fatweb.oxygen.api.param.tool.ToolBaseUpdateParam
import top.fatweb.oxygen.api.vo.tool.ToolBaseVo
import top.fatweb.oxygen.api.vo.tool.ToolCategoryVo
/**
* Tool base service interface
*
* @author FatttSnake, fatttsnake@gmail.com
* @since 1.0.0
* @see IService
* @see ToolBase
*/
interface IToolBaseService : IService<ToolBase> {
fun getOne(id: Long): ToolBaseVo?
fun get(): List<ToolBaseVo>
fun add(toolBaseAddParam: ToolBaseAddParam): ToolBaseVo
fun update(toolBaseUpdateParam: ToolBaseUpdateParam): ToolBaseVo
fun delete(id: Long): Boolean
}

View File

@@ -2,6 +2,9 @@ package top.fatweb.oxygen.api.service.tool
import com.baomidou.mybatisplus.extension.service.IService
import top.fatweb.oxygen.api.entity.tool.ToolCategory
import top.fatweb.oxygen.api.param.tool.ToolCategoryAddParam
import top.fatweb.oxygen.api.param.tool.ToolCategoryUpdateParam
import top.fatweb.oxygen.api.vo.tool.ToolCategoryVo
/**
* Tool category service interface
@@ -11,4 +14,14 @@ import top.fatweb.oxygen.api.entity.tool.ToolCategory
* @see IService
* @see ToolCategory
*/
interface IToolCategoryService : IService<ToolCategory>
interface IToolCategoryService : IService<ToolCategory> {
fun getOne(id: Long): ToolCategoryVo?
fun get(): List<ToolCategoryVo>
fun add(toolCategoryAddParam: ToolCategoryAddParam): ToolCategoryVo
fun update(toolCategoryUpdateParam: ToolCategoryUpdateParam): ToolCategoryVo
fun delete(id: Long): Boolean
}

View File

@@ -2,6 +2,9 @@ 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
@@ -11,4 +14,14 @@ import top.fatweb.oxygen.api.entity.tool.Tool
* @see IService
* @see Tool
*/
interface IToolService : IService<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
}

View File

@@ -0,0 +1,27 @@
package top.fatweb.oxygen.api.service.tool
import com.baomidou.mybatisplus.extension.service.IService
import top.fatweb.oxygen.api.entity.tool.ToolTemplate
import top.fatweb.oxygen.api.param.tool.ToolTemplateAddParam
import top.fatweb.oxygen.api.param.tool.ToolTemplateUpdateParam
import top.fatweb.oxygen.api.vo.tool.ToolTemplateVo
/**
* Tool template service interface
*
* @author FatttSnake, fatttsnake@gmail.com
* @since 1.0.0
* @see IService
* @see ToolTemplate
*/
interface IToolTemplateService : IService<ToolTemplate> {
fun getOne(id: Long): ToolTemplateVo?
fun get(): List<ToolTemplateVo>
fun add(toolTemplateAddParam: ToolTemplateAddParam): ToolTemplateVo
fun update(toolTemplateUpdateParam: ToolTemplateUpdateParam): ToolTemplateVo
fun delete(id: Long): Boolean
}

View File

@@ -1,6 +1,7 @@
package top.fatweb.oxygen.api.service.tool.impl
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl
import org.springframework.stereotype.Service
import top.fatweb.oxygen.api.entity.tool.RToolCategory
import top.fatweb.oxygen.api.mapper.tool.RToolCategoryMapper
import top.fatweb.oxygen.api.service.tool.IRToolCategoryService
@@ -15,4 +16,5 @@ import top.fatweb.oxygen.api.service.tool.IRToolCategoryService
* @see RToolCategory
* @see IRToolCategoryService
*/
@Service
class RToolCategoryServiceImpl : ServiceImpl<RToolCategoryMapper, RToolCategory>(), IRToolCategoryService

View File

@@ -0,0 +1,85 @@
package top.fatweb.oxygen.api.service.tool.impl
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.ToolBaseConverter
import top.fatweb.oxygen.api.entity.tool.ToolBase
import top.fatweb.oxygen.api.entity.tool.ToolData
import top.fatweb.oxygen.api.exception.NoRecordFoundException
import top.fatweb.oxygen.api.mapper.tool.ToolBaseMapper
import top.fatweb.oxygen.api.param.tool.ToolBaseAddParam
import top.fatweb.oxygen.api.param.tool.ToolBaseUpdateParam
import top.fatweb.oxygen.api.service.tool.IToolBaseService
import top.fatweb.oxygen.api.service.tool.IToolDataService
import top.fatweb.oxygen.api.vo.tool.ToolBaseVo
/**
* Tool base service implement
*
* @author FatttSnake, fatttsnake@gmail.com
* @since 1.0.0
* @see ServiceImpl
* @see ToolBaseMapper
* @see ToolBase
* @see IToolBaseService
*/
@Service
class ToolBaseServiceImpl(
private val toolDataService: IToolDataService
) : ServiceImpl<ToolBaseMapper, ToolBase>(), IToolBaseService {
override fun getOne(id: Long): ToolBaseVo? = baseMapper.selectOne(id)?.let(ToolBaseConverter::toolBaseToToolBaseVo)
override fun get(): List<ToolBaseVo> = baseMapper.selectList().map(ToolBaseConverter::toolBaseToToolBaseVo)
@Transactional
override fun add(toolBaseAddParam: ToolBaseAddParam): ToolBaseVo {
val newSource = ToolData().apply { data = toolBaseAddParam.source }
val newDist = ToolData().apply { data = toolBaseAddParam.dist }
toolDataService.save(newSource)
toolDataService.save(newDist)
val toolBase = ToolBase().apply {
name = toolBaseAddParam.name
sourceId = newSource.id
distId = newDist.id
source = newSource
dist = newDist
}
this.save(toolBase)
return ToolBaseConverter.toolBaseToToolBaseVo(toolBase)
}
@Transactional
override fun update(toolBaseUpdateParam: ToolBaseUpdateParam): ToolBaseVo {
val toolBase = baseMapper.selectOne(toolBaseUpdateParam.id!!) ?: throw NoRecordFoundException()
toolDataService.updateById(ToolData().apply {
id = toolBase.sourceId
data = toolBaseUpdateParam.source
})
toolDataService.updateById(ToolData().apply {
id = toolBase.distId
data = toolBaseUpdateParam.dist
})
this.updateById(ToolBase().apply {
id = toolBaseUpdateParam.id
name = toolBaseUpdateParam.name
})
return this.getOne(toolBase.id!!)!!
}
@Transactional
override fun delete(id: Long): Boolean {
val toolBase = this.getById(id)
return toolDataService.removeBatchByIds(listOf(toolBase.sourceId, toolBase.distId))
&& this.removeById(id)
}
}

View File

@@ -1,9 +1,15 @@
package top.fatweb.oxygen.api.service.tool.impl
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.entity.tool.ToolCategory
import top.fatweb.oxygen.api.mapper.tool.ToolCategoryMapper
import top.fatweb.oxygen.api.param.tool.ToolCategoryAddParam
import top.fatweb.oxygen.api.param.tool.ToolCategoryUpdateParam
import top.fatweb.oxygen.api.service.tool.IToolCategoryService
import top.fatweb.oxygen.api.vo.tool.ToolCategoryVo
/**
* Tool category service implement
@@ -15,4 +21,29 @@ import top.fatweb.oxygen.api.service.tool.IToolCategoryService
* @see ToolCategory
* @see IToolCategoryService
*/
class ToolCategoryServiceImpl : ServiceImpl<ToolCategoryMapper, ToolCategory>(), IToolCategoryService
@Service
class ToolCategoryServiceImpl : ServiceImpl<ToolCategoryMapper, ToolCategory>(), IToolCategoryService {
override fun getOne(id: Long): ToolCategoryVo? =
this.getById(id)?.let(ToolCategoryConverter::toolCategoryToToolCategoryVo)
override fun get(): List<ToolCategoryVo> =
this.list().map(ToolCategoryConverter::toolCategoryToToolCategoryVo)
override fun add(toolCategoryAddParam: ToolCategoryAddParam): ToolCategoryVo {
val toolCategory = ToolCategoryConverter.toolCategoryAddParamToToolCategory(toolCategoryAddParam)
this.save(toolCategory)
return ToolCategoryConverter.toolCategoryToToolCategoryVo(toolCategory)
}
override fun update(toolCategoryUpdateParam: ToolCategoryUpdateParam): ToolCategoryVo {
val toolCategory = ToolCategoryConverter.toolCategoryUpdateParamToToolCategory(toolCategoryUpdateParam)
this.updateById(toolCategory)
return ToolCategoryConverter.toolCategoryToToolCategoryVo(toolCategory)
}
override fun delete(id: Long): Boolean = this.removeById(id)
}

View File

@@ -1,6 +1,7 @@
package top.fatweb.oxygen.api.service.tool.impl
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl
import org.springframework.stereotype.Service
import top.fatweb.oxygen.api.entity.tool.ToolData
import top.fatweb.oxygen.api.mapper.tool.ToolDataMapper
import top.fatweb.oxygen.api.service.tool.IToolDataService
@@ -15,4 +16,5 @@ import top.fatweb.oxygen.api.service.tool.IToolDataService
* @see ToolData
* @see IToolDataService
*/
@Service
class ToolDataServiceImpl : ServiceImpl<ToolDataMapper, ToolData>(), IToolDataService

View File

@@ -1,9 +1,22 @@
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.exception.UserNotFoundException
import top.fatweb.oxygen.api.mapper.tool.ToolMapper
import top.fatweb.oxygen.api.service.tool.IToolService
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
/**
* Tool service implement
@@ -15,4 +28,95 @@ import top.fatweb.oxygen.api.service.tool.IToolService
* @see Tool
* @see IToolService
*/
class ToolServiceImpl : ServiceImpl<ToolMapper, Tool>(), 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)
override fun get(): List<ToolVo> = baseMapper.selectList().map(ToolConverter::toolToToolVo)
@Transactional
override fun add(toolAddParam: ToolAddParam): ToolVo {
toolBaseService.getOne(toolAddParam.baseId!!) ?: throw NoRecordFoundException()
userService.getOne(toolAddParam.authorId!!) ?: throw UserNotFoundException()
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
})
}
return this.getOne(tool.id!!)!!
}
@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!!) ?: throw UserNotFoundException()
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
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)
}
}

View File

@@ -0,0 +1,96 @@
package top.fatweb.oxygen.api.service.tool.impl
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.ToolTemplateConverter
import top.fatweb.oxygen.api.entity.tool.ToolData
import top.fatweb.oxygen.api.entity.tool.ToolTemplate
import top.fatweb.oxygen.api.exception.NoRecordFoundException
import top.fatweb.oxygen.api.mapper.tool.ToolTemplateMapper
import top.fatweb.oxygen.api.param.tool.ToolTemplateAddParam
import top.fatweb.oxygen.api.param.tool.ToolTemplateUpdateParam
import top.fatweb.oxygen.api.service.tool.IToolBaseService
import top.fatweb.oxygen.api.service.tool.IToolDataService
import top.fatweb.oxygen.api.service.tool.IToolTemplateService
import top.fatweb.oxygen.api.vo.tool.ToolTemplateVo
/**
* Tool template service implement
*
* @author FatttSnake, fatttsnake@gmail.com
* @since 1.0.0
* @see ServiceImpl
* @see ToolTemplateMapper
* @see ToolTemplate
* @see IToolTemplateService
*/
@Service
class ToolTemplateServiceImpl(
private val toolDataService: IToolDataService,
private val toolBaseService: IToolBaseService
) : ServiceImpl<ToolTemplateMapper, ToolTemplate>(), IToolTemplateService {
override fun getOne(id: Long): ToolTemplateVo? =
baseMapper.selectOne(id)?.let(ToolTemplateConverter::toolTemplateToToolTemplateVo)
override fun get(): List<ToolTemplateVo> =
baseMapper.selectList().map(ToolTemplateConverter::toolTemplateToToolTemplateVo)
@Transactional
override fun add(toolTemplateAddParam: ToolTemplateAddParam): ToolTemplateVo {
toolBaseService.getOne(toolTemplateAddParam.baseId!!) ?: throw NoRecordFoundException()
val newSource = ToolData().apply { data = toolTemplateAddParam.source }
val newDist = ToolData().apply { data = toolTemplateAddParam.dist }
toolDataService.save(newSource)
toolDataService.save(newDist)
val toolTemplate = ToolTemplate().apply {
name = toolTemplateAddParam.name
ver = toolTemplateAddParam.ver
baseId = toolTemplateAddParam.baseId
sourceId = newSource.id
distId = newDist.id
source = newSource
dist = newDist
}
this.save(toolTemplate)
return ToolTemplateConverter.toolTemplateToToolTemplateVo(toolTemplate)
}
@Transactional
override fun update(toolTemplateUpdateParam: ToolTemplateUpdateParam): ToolTemplateVo {
val toolTemplate = baseMapper.selectOne(toolTemplateUpdateParam.id!!) ?: throw NoRecordFoundException()
toolTemplateUpdateParam.baseId?.let { toolBaseService.getOne(it) ?: throw NoRecordFoundException() }
toolDataService.updateById(ToolData().apply {
id = toolTemplate.sourceId
data = toolTemplateUpdateParam.source
})
toolDataService.updateById(ToolData().apply {
id = toolTemplate.distId
data = toolTemplateUpdateParam.dist
})
this.updateById(ToolTemplate().apply {
id = toolTemplateUpdateParam.id
name = toolTemplateUpdateParam.name
ver = toolTemplateUpdateParam.ver
baseId = toolTemplateUpdateParam.baseId
})
return this.getOne(toolTemplate.id!!)!!
}
@Transactional
override fun delete(id: Long): Boolean {
val toolTemplate = this.getById(id)
return toolDataService.removeBatchByIds(listOf(toolTemplate.sourceId, toolTemplate.distId))
&& this.removeById(id)
}
}

View File

@@ -0,0 +1,20 @@
package top.fatweb.oxygen.api.vo.tool
import com.fasterxml.jackson.databind.annotation.JsonSerialize
import com.fasterxml.jackson.databind.ser.std.ToStringSerializer
import java.time.LocalDateTime
data class ToolBaseVo(
@JsonSerialize(using = ToStringSerializer::class)
val id: Long?,
val name: String?,
val source: ToolDataVo?,
val dist: ToolDataVo?,
val createTime: LocalDateTime?,
val updateTime: LocalDateTime?
)

View File

@@ -0,0 +1,18 @@
package top.fatweb.oxygen.api.vo.tool
import com.fasterxml.jackson.databind.annotation.JsonSerialize
import com.fasterxml.jackson.databind.ser.std.ToStringSerializer
import java.time.LocalDateTime
data class ToolCategoryVo(
@JsonSerialize(using = ToStringSerializer::class)
val id: Long?,
val name: String?,
val enable: Boolean?,
val createTime: LocalDateTime?,
val updateTime: LocalDateTime?
)

View File

@@ -0,0 +1,16 @@
package top.fatweb.oxygen.api.vo.tool
import com.fasterxml.jackson.databind.annotation.JsonSerialize
import com.fasterxml.jackson.databind.ser.std.ToStringSerializer
import java.time.LocalDateTime
data class ToolDataVo(
@JsonSerialize(using = ToStringSerializer::class)
val id: Long?,
val data: String?,
val createTime: LocalDateTime?,
val updateTime: LocalDateTime?
)

View File

@@ -0,0 +1,25 @@
package top.fatweb.oxygen.api.vo.tool
import com.fasterxml.jackson.databind.annotation.JsonSerialize
import com.fasterxml.jackson.databind.ser.std.ToStringSerializer
import java.time.LocalDateTime
data class ToolTemplateVo(
@JsonSerialize(using = ToStringSerializer::class)
val id: Long?,
val name: String?,
val ver: String?,
@JsonSerialize(using = ToStringSerializer::class)
val baseId: Long?,
val source: ToolDataVo?,
val dist: ToolDataVo?,
val createTime: LocalDateTime?,
val updateTime: LocalDateTime?
)

View File

@@ -0,0 +1,42 @@
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 java.time.LocalDateTime
data class ToolVo (
@JsonSerialize(using = ToStringSerializer::class)
val id: Long?,
val name: String?,
val toolId: String?,
val description: String?,
@JsonSerialize(using = ToStringSerializer::class)
val baseId: Long?,
val author: UserInfoVo?,
val ver: String?,
val privately: Boolean?,
val keywords: List<String>?,
val categories: List<ToolCategoryVo>?,
val source: ToolDataVo?,
val dist: ToolDataVo?,
val publish: Boolean?,
val review: Int?,
val createTime: LocalDateTime?,
val updateTime: LocalDateTime?
)