From c5dcb432ef391abeb0b692cbaa42e8054437bd6c Mon Sep 17 00:00:00 2001 From: FatttSnake Date: Sat, 17 Feb 2024 14:24:42 +0800 Subject: [PATCH] Add store get tool api --- .../api/controller/tool/StoreController.kt | 31 +++++++ .../api/mapper/tool/ManagementMapper.kt | 5 +- .../oxygen/api/mapper/tool/StoreMapper.kt | 41 +++++++++ .../api/param/tool/ToolManagementGetParam.kt | 2 +- .../api/param/tool/ToolManagementPassParam.kt | 2 +- .../api/param/tool/ToolStoreGetParam.kt | 16 ++++ .../api/service/tool/IManagementService.kt | 2 +- .../oxygen/api/service/tool/IStoreService.kt | 25 ++++++ .../api/service/tool/impl/StoreServiceImpl.kt | 37 +++++++++ .../resources/mapper/tool/StoreMapper.xml | 83 +++++++++++++++++++ 10 files changed, 239 insertions(+), 5 deletions(-) create mode 100644 src/main/kotlin/top/fatweb/oxygen/api/controller/tool/StoreController.kt create mode 100644 src/main/kotlin/top/fatweb/oxygen/api/mapper/tool/StoreMapper.kt create mode 100644 src/main/kotlin/top/fatweb/oxygen/api/param/tool/ToolStoreGetParam.kt create mode 100644 src/main/kotlin/top/fatweb/oxygen/api/service/tool/IStoreService.kt create mode 100644 src/main/kotlin/top/fatweb/oxygen/api/service/tool/impl/StoreServiceImpl.kt create mode 100644 src/main/resources/mapper/tool/StoreMapper.xml diff --git a/src/main/kotlin/top/fatweb/oxygen/api/controller/tool/StoreController.kt b/src/main/kotlin/top/fatweb/oxygen/api/controller/tool/StoreController.kt new file mode 100644 index 0000000..52d1daa --- /dev/null +++ b/src/main/kotlin/top/fatweb/oxygen/api/controller/tool/StoreController.kt @@ -0,0 +1,31 @@ +package top.fatweb.oxygen.api.controller.tool + +import jakarta.validation.Valid +import org.springframework.web.bind.annotation.GetMapping +import top.fatweb.oxygen.api.annotation.BaseController +import top.fatweb.oxygen.api.entity.common.ResponseResult +import top.fatweb.oxygen.api.param.tool.ToolStoreGetParam +import top.fatweb.oxygen.api.service.tool.IStoreService +import top.fatweb.oxygen.api.vo.PageVo +import top.fatweb.oxygen.api.vo.tool.ToolVo + +/** + * Tool store controller + * + * @author FatttSnake, fatttsnake@gmail.com + * @since 1.0.0 + */ +@BaseController(path = ["/tool/store"], name = "工具商店", description = "工具商店相关接口") +class StoreController( + private val storeService: IStoreService +) { + /** + * Get store tool in page + * + * @author FatttSnake, fatttsnake@gmail.com + * @since 1.0.0 + */ + @GetMapping + fun get(@Valid toolStoreGetParam: ToolStoreGetParam): ResponseResult> = + ResponseResult.databaseSuccess(data = storeService.getPage(toolStoreGetParam)) +} \ No newline at end of file diff --git a/src/main/kotlin/top/fatweb/oxygen/api/mapper/tool/ManagementMapper.kt b/src/main/kotlin/top/fatweb/oxygen/api/mapper/tool/ManagementMapper.kt index f29865b..8ef9eb7 100644 --- a/src/main/kotlin/top/fatweb/oxygen/api/mapper/tool/ManagementMapper.kt +++ b/src/main/kotlin/top/fatweb/oxygen/api/mapper/tool/ManagementMapper.kt @@ -7,7 +7,7 @@ import org.apache.ibatis.annotations.Param import top.fatweb.oxygen.api.entity.tool.Tool /** - * Tool mapper + * Tool management mapper * * @author FatttSnake, fatttsnake@gmail.com * @since 1.0.0 @@ -35,7 +35,7 @@ interface ManagementMapper : BaseMapper { * @param searchType Type of search * @param searchValue Value to search for * @param searchRegex Use regex - * @return Tool object in page + * @return Tool ID in page * @author FatttSnake, fatttsnake@gmail.com * @since 1.0.0 * @see IPage @@ -55,6 +55,7 @@ interface ManagementMapper : BaseMapper { * @return List of tool object * @author FatttSnake, fatttsnake@gmail.com * @since 1.0.0 + * @see Tool */ fun selectListByIds(@Param("ids") ids: List): List } \ No newline at end of file diff --git a/src/main/kotlin/top/fatweb/oxygen/api/mapper/tool/StoreMapper.kt b/src/main/kotlin/top/fatweb/oxygen/api/mapper/tool/StoreMapper.kt new file mode 100644 index 0000000..ec3c0f6 --- /dev/null +++ b/src/main/kotlin/top/fatweb/oxygen/api/mapper/tool/StoreMapper.kt @@ -0,0 +1,41 @@ +package top.fatweb.oxygen.api.mapper.tool + +import com.baomidou.mybatisplus.core.mapper.BaseMapper +import com.baomidou.mybatisplus.core.metadata.IPage +import org.apache.ibatis.annotations.Mapper +import org.apache.ibatis.annotations.Param +import top.fatweb.oxygen.api.entity.tool.Tool + +/** + * Tool store mapper + * + * @author FatttSnake, fatttsnake@gmail.com + * @since 1.0.0 + * @see BaseMapper + * @see Tool + */ +@Mapper +interface StoreMapper : BaseMapper { + /** + * Select tool ID in page + * + * @param page Pagination + * @param searchValue Value to search for + * @return Tool ID in page + * @author FatttSnake, fatttsnake@gmail.com + * @since 1.0.0 + * @see IPage + */ + fun selectPage(page: IPage, @Param("searchValue") searchValue: String?): IPage + + /** + * Select tool in list by tool IDs + * + * @param ids List of tool IDs + * @return List of tool object + * @author FatttSnake, fatttsnake@gmail.com + * @since 1.0.0 + * @see Tool + */ + fun selectListByIds(@Param("ids") ids: List): List +} \ No newline at end of file diff --git a/src/main/kotlin/top/fatweb/oxygen/api/param/tool/ToolManagementGetParam.kt b/src/main/kotlin/top/fatweb/oxygen/api/param/tool/ToolManagementGetParam.kt index 0c8fc83..dd58600 100644 --- a/src/main/kotlin/top/fatweb/oxygen/api/param/tool/ToolManagementGetParam.kt +++ b/src/main/kotlin/top/fatweb/oxygen/api/param/tool/ToolManagementGetParam.kt @@ -4,7 +4,7 @@ import io.swagger.v3.oas.annotations.media.Schema import top.fatweb.oxygen.api.param.PageSortParam /** - * Get tool in management parameters + * Get tool parameters in tool management * * @author FatttSnake, fatttsnake@gmail.com * @since 1.0.0 diff --git a/src/main/kotlin/top/fatweb/oxygen/api/param/tool/ToolManagementPassParam.kt b/src/main/kotlin/top/fatweb/oxygen/api/param/tool/ToolManagementPassParam.kt index 33460d4..bf993c1 100644 --- a/src/main/kotlin/top/fatweb/oxygen/api/param/tool/ToolManagementPassParam.kt +++ b/src/main/kotlin/top/fatweb/oxygen/api/param/tool/ToolManagementPassParam.kt @@ -4,7 +4,7 @@ import io.swagger.v3.oas.annotations.media.Schema import jakarta.validation.constraints.NotBlank /** - * Pass tool in management parameters + * Pass tool parameters in tool management * * @author FatttSnake, fatttsnake@gmail.com * @since 1.0.0 diff --git a/src/main/kotlin/top/fatweb/oxygen/api/param/tool/ToolStoreGetParam.kt b/src/main/kotlin/top/fatweb/oxygen/api/param/tool/ToolStoreGetParam.kt new file mode 100644 index 0000000..a83ae41 --- /dev/null +++ b/src/main/kotlin/top/fatweb/oxygen/api/param/tool/ToolStoreGetParam.kt @@ -0,0 +1,16 @@ +package top.fatweb.oxygen.api.param.tool + +import io.swagger.v3.oas.annotations.media.Schema +import top.fatweb.oxygen.api.param.PageSortParam + +/** + * Get tool parameters in tool store + * + * @author FatttSnake, fatttsnake@gmail.com + * @since 1.0.0 + * @see PageSortParam + */ +data class ToolStoreGetParam( + @Schema(description = "查询内容", example = "ToolName") + val searchValue: String? +) : PageSortParam() diff --git a/src/main/kotlin/top/fatweb/oxygen/api/service/tool/IManagementService.kt b/src/main/kotlin/top/fatweb/oxygen/api/service/tool/IManagementService.kt index 039ad51..2ec08a7 100644 --- a/src/main/kotlin/top/fatweb/oxygen/api/service/tool/IManagementService.kt +++ b/src/main/kotlin/top/fatweb/oxygen/api/service/tool/IManagementService.kt @@ -28,7 +28,7 @@ interface IManagementService : IService { fun getOne(id: Long): ToolVo /** - * Get tool as page + * Get tool in page * * @param toolManagementGetParam Get tool parameters in tool management * @return PageVo object diff --git a/src/main/kotlin/top/fatweb/oxygen/api/service/tool/IStoreService.kt b/src/main/kotlin/top/fatweb/oxygen/api/service/tool/IStoreService.kt new file mode 100644 index 0000000..4ef68cd --- /dev/null +++ b/src/main/kotlin/top/fatweb/oxygen/api/service/tool/IStoreService.kt @@ -0,0 +1,25 @@ +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.ToolStoreGetParam +import top.fatweb.oxygen.api.vo.PageVo +import top.fatweb.oxygen.api.vo.tool.ToolVo + +/** + * Tool store service interface + * + * @author FatttSnake, fatttsnake@gmail.com + * @since 1.0.0 + * @see IService + * @see Tool + */ +interface IStoreService : IService { + /** + * Get tool in page + * + * @author FatttSnake, fatttsnake@gmail.com + * @since 1.0.0 + */ + fun getPage(toolStoreGetParam: ToolStoreGetParam?): PageVo +} \ No newline at end of file diff --git a/src/main/kotlin/top/fatweb/oxygen/api/service/tool/impl/StoreServiceImpl.kt b/src/main/kotlin/top/fatweb/oxygen/api/service/tool/impl/StoreServiceImpl.kt new file mode 100644 index 0000000..e1ba2f0 --- /dev/null +++ b/src/main/kotlin/top/fatweb/oxygen/api/service/tool/impl/StoreServiceImpl.kt @@ -0,0 +1,37 @@ +package top.fatweb.oxygen.api.service.tool.impl + +import com.baomidou.mybatisplus.extension.plugins.pagination.Page +import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl +import org.springframework.stereotype.Service +import top.fatweb.oxygen.api.converter.tool.ToolConverter +import top.fatweb.oxygen.api.entity.tool.Tool +import top.fatweb.oxygen.api.mapper.tool.StoreMapper +import top.fatweb.oxygen.api.param.tool.ToolStoreGetParam +import top.fatweb.oxygen.api.service.tool.IStoreService +import top.fatweb.oxygen.api.vo.PageVo +import top.fatweb.oxygen.api.vo.tool.ToolVo + +/** + * Tool store service implement + * + * @author FatttSnake, fatttsnake@gmail.com + * @since 1.0.0 + * @see ServiceImpl + * @see StoreMapper + * @see Tool + * @see IStoreService + */ +@Service +class StoreServiceImpl : ServiceImpl(), IStoreService { + override fun getPage(toolStoreGetParam: ToolStoreGetParam?): PageVo { + val toolIdsPage = Page(toolStoreGetParam?.currentPage ?: 1, 20) + + val toolIdsIPage = baseMapper.selectPage(toolIdsPage, toolStoreGetParam?.searchValue) + val toolPage = Page(toolIdsIPage.current, toolIdsIPage.size, toolIdsIPage.total) + if (toolIdsIPage.total > 0) { + toolPage.setRecords(baseMapper.selectListByIds(toolIdsIPage.records)) + } + + return ToolConverter.toolPageToToolPageVo(toolPage) + } +} \ No newline at end of file diff --git a/src/main/resources/mapper/tool/StoreMapper.xml b/src/main/resources/mapper/tool/StoreMapper.xml new file mode 100644 index 0000000..6f5f2c9 --- /dev/null +++ b/src/main/resources/mapper/tool/StoreMapper.xml @@ -0,0 +1,83 @@ + + + + + + + \ No newline at end of file