diff --git a/src/main/kotlin/top/fatweb/oxygen/api/controller/tool/EditController.kt b/src/main/kotlin/top/fatweb/oxygen/api/controller/tool/EditController.kt index 73720dd..ef150b4 100644 --- a/src/main/kotlin/top/fatweb/oxygen/api/controller/tool/EditController.kt +++ b/src/main/kotlin/top/fatweb/oxygen/api/controller/tool/EditController.kt @@ -8,8 +8,10 @@ import top.fatweb.oxygen.api.annotation.Trim import top.fatweb.oxygen.api.entity.common.ResponseCode import top.fatweb.oxygen.api.entity.common.ResponseResult import top.fatweb.oxygen.api.entity.tool.ToolBase +import top.fatweb.oxygen.api.param.PageSortParam import top.fatweb.oxygen.api.param.tool.* import top.fatweb.oxygen.api.service.tool.IEditService +import top.fatweb.oxygen.api.vo.PageVo import top.fatweb.oxygen.api.vo.tool.ToolCategoryVo import top.fatweb.oxygen.api.vo.tool.ToolTemplateVo import top.fatweb.oxygen.api.vo.tool.ToolVo @@ -111,13 +113,16 @@ class EditController( * @return Response object includes tool list * @author FatttSnake, fatttsnake@gmail.com * @since 1.0.0 + * @see PageSortParam * @see ResponseResult + * @see PageVo * @see ToolVo */ + @Trim @Operation(summary = "获取个人工具") @GetMapping - fun get(): ResponseResult> = - ResponseResult.databaseSuccess(ResponseCode.DATABASE_SELECT_SUCCESS, data = editService.get()) + fun get(@Valid pageSortParam: PageSortParam): ResponseResult> = + ResponseResult.databaseSuccess(ResponseCode.DATABASE_SELECT_SUCCESS, data = editService.getPage(pageSortParam)) /** * Get tool detail diff --git a/src/main/kotlin/top/fatweb/oxygen/api/mapper/tool/EditMapper.kt b/src/main/kotlin/top/fatweb/oxygen/api/mapper/tool/EditMapper.kt index 2fb8321..7cc0da1 100644 --- a/src/main/kotlin/top/fatweb/oxygen/api/mapper/tool/EditMapper.kt +++ b/src/main/kotlin/top/fatweb/oxygen/api/mapper/tool/EditMapper.kt @@ -1,6 +1,7 @@ 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 @@ -41,15 +42,28 @@ interface EditMapper : BaseMapper { fun selectOne(@Param("id") id: Long, @Param("userId") userId: Long): Tool? /** - * Select tool in list by User ID + * Select tool ID by user ID in page * + * @param page Pagination * @param userId User ID - * @return List of tool object + * @return Tool ID in page + * @author FatttSnake, fatttsnake@gmail.com + * @since 1.0.0 + * @see IPage + */ + fun selectPersonalToolIdPage(page: IPage, @Param("userId") userId: Long): IPage + + /** + * Select tool in list by tool IDs and user ID + * + * @param toolIds List of tool Ids + * @param userId User ID + * @return List of Tool object * @author FatttSnake, fatttsnake@gmail.com * @since 1.0.0 * @see Tool */ - fun selectPersonal(@Param("userId") userId: Long): List + fun selectListByToolIds(@Param("toolIds") toolIds: List, @Param("userId") userId: Long): List /** * Select tool detail 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 index 786f58e..e464b45 100644 --- a/src/main/kotlin/top/fatweb/oxygen/api/mapper/tool/StoreMapper.kt +++ b/src/main/kotlin/top/fatweb/oxygen/api/mapper/tool/StoreMapper.kt @@ -29,11 +29,11 @@ interface StoreMapper : BaseMapper { fun selectAuthorToolIdPage(page: IPage, @Param("searchValue") searchValue: String?): IPage /** - * Select tool ID by username in page + * Select author and tool ID by username in page * * @param page Pagination * @param username Username - * @return Tool ID in page + * @return Author:Tool_ID in page * @author FatttSnake, fatttsnake@gmail.com * @since 1.0.0 * @see IPage @@ -44,7 +44,7 @@ interface StoreMapper : BaseMapper { * Select tool in list by tool IDs * * @param ids List of tool IDs - * @return List of tool object + * @return List of Tool object * @author FatttSnake, fatttsnake@gmail.com * @since 1.0.0 * @see Tool diff --git a/src/main/kotlin/top/fatweb/oxygen/api/mapper/tool/ToolFavoriteMapper.kt b/src/main/kotlin/top/fatweb/oxygen/api/mapper/tool/ToolFavoriteMapper.kt index 69d2d9c..213975b 100644 --- a/src/main/kotlin/top/fatweb/oxygen/api/mapper/tool/ToolFavoriteMapper.kt +++ b/src/main/kotlin/top/fatweb/oxygen/api/mapper/tool/ToolFavoriteMapper.kt @@ -4,5 +4,13 @@ import com.baomidou.mybatisplus.core.mapper.BaseMapper import org.apache.ibatis.annotations.Mapper import top.fatweb.oxygen.api.entity.tool.ToolFavorite +/** + * Tool favorite mapper + * + * @author FatttSnake, fatttsnake@gmail.com + * @since 1.0.0 + * @see BaseMapper + * @see ToolFavorite + */ @Mapper interface ToolFavoriteMapper : BaseMapper \ No newline at end of file diff --git a/src/main/kotlin/top/fatweb/oxygen/api/service/tool/IEditService.kt b/src/main/kotlin/top/fatweb/oxygen/api/service/tool/IEditService.kt index 774031c..8d9ba15 100644 --- a/src/main/kotlin/top/fatweb/oxygen/api/service/tool/IEditService.kt +++ b/src/main/kotlin/top/fatweb/oxygen/api/service/tool/IEditService.kt @@ -3,7 +3,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.entity.tool.ToolBase +import top.fatweb.oxygen.api.param.PageSortParam import top.fatweb.oxygen.api.param.tool.* +import top.fatweb.oxygen.api.vo.PageVo import top.fatweb.oxygen.api.vo.tool.ToolCategoryVo import top.fatweb.oxygen.api.vo.tool.ToolTemplateVo import top.fatweb.oxygen.api.vo.tool.ToolVo @@ -98,12 +100,15 @@ interface IEditService : IService { /** * Get personal tools * - * @return List of ToolVo object + * @param pageSortParam Page sort parameters + * @return PageVo object * @author FatttSnake, fatttsnake@gmail.com * @since 1.0.0 + * @see PageSortParam + * @see PageVo * @see ToolVo */ - fun get(): List + fun getPage(pageSortParam: PageSortParam): PageVo /** * Get tool detail 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 index 956d114..d5efaa8 100644 --- a/src/main/kotlin/top/fatweb/oxygen/api/service/tool/IStoreService.kt +++ b/src/main/kotlin/top/fatweb/oxygen/api/service/tool/IStoreService.kt @@ -19,16 +19,27 @@ interface IStoreService : IService { /** * Get tool in page * + * @param toolStoreGetParam Get tool parameters in tool store + * @return PageVo object * @author FatttSnake, fatttsnake@gmail.com * @since 1.0.0 + * @see ToolStoreGetParam + * @see PageVo + * @see ToolVo */ - fun getPage(toolStoreGetParam: ToolStoreGetParam?): PageVo + fun getPage(toolStoreGetParam: ToolStoreGetParam): PageVo /** * Get tool by username in page * + * @param pageSortParam Page sort parameters + * @param username Username + * @return PageVo } \ No newline at end of file diff --git a/src/main/kotlin/top/fatweb/oxygen/api/service/tool/IToolFavoriteService.kt b/src/main/kotlin/top/fatweb/oxygen/api/service/tool/IToolFavoriteService.kt index 59cf54c..108b50c 100644 --- a/src/main/kotlin/top/fatweb/oxygen/api/service/tool/IToolFavoriteService.kt +++ b/src/main/kotlin/top/fatweb/oxygen/api/service/tool/IToolFavoriteService.kt @@ -3,4 +3,12 @@ package top.fatweb.oxygen.api.service.tool import com.baomidou.mybatisplus.extension.service.IService import top.fatweb.oxygen.api.entity.tool.ToolFavorite +/** + * Tool favorite service interface + * + * @author FatttSnake, fatttsnake@gmail.com + * @since 1.0.0 + * @see IService + * @see ToolFavorite + */ interface IToolFavoriteService : IService \ No newline at end of file diff --git a/src/main/kotlin/top/fatweb/oxygen/api/service/tool/impl/EditServiceImpl.kt b/src/main/kotlin/top/fatweb/oxygen/api/service/tool/impl/EditServiceImpl.kt index d7958f9..d879dbe 100644 --- a/src/main/kotlin/top/fatweb/oxygen/api/service/tool/impl/EditServiceImpl.kt +++ b/src/main/kotlin/top/fatweb/oxygen/api/service/tool/impl/EditServiceImpl.kt @@ -2,6 +2,7 @@ package top.fatweb.oxygen.api.service.tool.impl import com.baomidou.mybatisplus.extension.kotlin.KtQueryWrapper import com.baomidou.mybatisplus.extension.kotlin.KtUpdateWrapper +import com.baomidou.mybatisplus.extension.plugins.pagination.Page import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl import org.springframework.dao.DuplicateKeyException import org.springframework.stereotype.Service @@ -12,9 +13,11 @@ import top.fatweb.oxygen.api.converter.tool.ToolTemplateConverter import top.fatweb.oxygen.api.entity.tool.* import top.fatweb.oxygen.api.exception.* import top.fatweb.oxygen.api.mapper.tool.EditMapper +import top.fatweb.oxygen.api.param.PageSortParam import top.fatweb.oxygen.api.param.tool.* import top.fatweb.oxygen.api.service.tool.* import top.fatweb.oxygen.api.util.WebUtil +import top.fatweb.oxygen.api.vo.PageVo import top.fatweb.oxygen.api.vo.tool.ToolCategoryVo import top.fatweb.oxygen.api.vo.tool.ToolTemplateVo import top.fatweb.oxygen.api.vo.tool.ToolVo @@ -210,9 +213,18 @@ class EditServiceImpl( return this.getOne(tool.id!!) } - override fun get(): List = - baseMapper.selectPersonal(WebUtil.getLoginUserId()!!) - .map(ToolConverter::toolToToolVo) + override fun getPage(pageSortParam: PageSortParam): PageVo { + val toolIdsPage = Page(pageSortParam.currentPage, 20) + toolIdsPage.setOptimizeCountSql(false) + + val toolIdsIPage = baseMapper.selectPersonalToolIdPage(toolIdsPage, WebUtil.getLoginUserId()!!) + val toolPage = Page(toolIdsIPage.current, toolIdsIPage.size, toolIdsIPage.total) + if (toolIdsIPage.total > 0) { + toolPage.setRecords(baseMapper.selectListByToolIds(toolIdsIPage.records, WebUtil.getLoginUserId()!!)) + } + + return ToolConverter.toolPageToToolPageVo(toolPage) + } override fun detail(username: String, toolId: String, ver: String, platform: ToolBase.Platform): ToolVo { if (username == "!" && WebUtil.getLoginUserId() == null) { @@ -272,7 +284,12 @@ class EditServiceImpl( throw RecordAlreadyExists() } - this.detail(toolFavoriteAddParam.username!!, toolFavoriteAddParam.toolId!!, "latest", toolFavoriteAddParam.platform!!) + this.detail( + toolFavoriteAddParam.username!!, + toolFavoriteAddParam.toolId!!, + "latest", + toolFavoriteAddParam.platform!! + ) toolFavoriteService.save( ToolFavorite().apply { 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 index 747526f..21e5413 100644 --- 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 @@ -25,11 +25,11 @@ import top.fatweb.oxygen.api.vo.tool.ToolVo */ @Service class StoreServiceImpl : ServiceImpl(), IStoreService { - override fun getPage(toolStoreGetParam: ToolStoreGetParam?): PageVo { - val toolIdsPage = Page(toolStoreGetParam?.currentPage ?: 1, 20) + override fun getPage(toolStoreGetParam: ToolStoreGetParam): PageVo { + val toolIdsPage = Page(toolStoreGetParam.currentPage, 20) toolIdsPage.setOptimizeCountSql(false) - val toolIdsIPage = baseMapper.selectAuthorToolIdPage(toolIdsPage, toolStoreGetParam?.searchValue) + val toolIdsIPage = baseMapper.selectAuthorToolIdPage(toolIdsPage, toolStoreGetParam.searchValue) val toolPage = Page(toolIdsIPage.current, toolIdsIPage.size, toolIdsIPage.total) if (toolIdsIPage.total > 0) { toolPage.setRecords(baseMapper.selectListByAuthorToolIds(toolIdsIPage.records, WebUtil.getLoginUserId())) diff --git a/src/main/kotlin/top/fatweb/oxygen/api/service/tool/impl/ToolFavoriteServiceImpl.kt b/src/main/kotlin/top/fatweb/oxygen/api/service/tool/impl/ToolFavoriteServiceImpl.kt index 7ac062a..8bb5b55 100644 --- a/src/main/kotlin/top/fatweb/oxygen/api/service/tool/impl/ToolFavoriteServiceImpl.kt +++ b/src/main/kotlin/top/fatweb/oxygen/api/service/tool/impl/ToolFavoriteServiceImpl.kt @@ -6,5 +6,15 @@ import top.fatweb.oxygen.api.entity.tool.ToolFavorite import top.fatweb.oxygen.api.mapper.tool.ToolFavoriteMapper import top.fatweb.oxygen.api.service.tool.IToolFavoriteService +/** + * Tool favorite service implement + * + * @author FatttSnake, fatttsnake@gmail.com + * @since 1.0.0 + * @see ServiceImpl + * @see ToolFavoriteMapper + * @see ToolFavorite + * @see IToolFavoriteService + */ @Service class ToolFavoriteServiceImpl : ServiceImpl(), IToolFavoriteService \ No newline at end of file diff --git a/src/main/resources/mapper/tool/EditMapper.xml b/src/main/resources/mapper/tool/EditMapper.xml index c48c967..818ca35 100644 --- a/src/main/resources/mapper/tool/EditMapper.xml +++ b/src/main/resources/mapper/tool/EditMapper.xml @@ -94,7 +94,15 @@ and t_b_tool_main.id = #{id} - + select distinct t_b_tool_main.tool_id + from t_b_tool_main + where t_b_tool_main.deleted = 0 + and t_b_tool_main.author_id = #{userId} + order by t_b_tool_main.id desc + + +