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 96da5e0..78e6449 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 @@ -17,16 +17,16 @@ import top.fatweb.oxygen.api.entity.tool.Tool @Mapper interface StoreMapper : BaseMapper { /** - * Select tool ID in page + * Select author and tool ID in page * * @param page Pagination * @param searchValue Value to search for - * @return Tool ID in page + * @return Author:Tool_ID in page * @author FatttSnake, fatttsnake@gmail.com * @since 1.0.0 * @see IPage */ - fun selectPage(page: IPage, @Param("searchValue") searchValue: String?): IPage + fun selectAuthorToolIdPage(page: IPage, @Param("searchValue") searchValue: String?): IPage /** * Select tool ID by username in page @@ -38,7 +38,7 @@ interface StoreMapper : BaseMapper { * @since 1.0.0 * @see IPage */ - fun selectPageByUsername(page: IPage, @Param("username") username: String): IPage + fun selectAuthorToolIdPageByUsername(page: IPage, @Param("username") username: String): IPage /** * Select tool in list by tool IDs @@ -50,4 +50,15 @@ interface StoreMapper : BaseMapper { * @see Tool */ fun selectListByIds(@Param("ids") ids: List): List + + /** + * Select tool in list by Author:Tool_ID + * + * @param ids List of Author:Tool_ID + * @return List of tool object + * @author FatttSnake, fatttsnake@gmail.com + * @since 1.0.0 + * @see Tool + */ + fun selectListByAuthorToolIds(@Param("ids") ids: List): List } \ 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 index a59d487..7139e56 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 @@ -28,10 +28,10 @@ class StoreServiceImpl : ServiceImpl(), IStoreService { val toolIdsPage = Page(toolStoreGetParam?.currentPage ?: 1, 20) toolIdsPage.setOptimizeCountSql(false) - val toolIdsIPage = baseMapper.selectPage(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.selectListByIds(toolIdsIPage.records)) + toolPage.setRecords(baseMapper.selectListByAuthorToolIds(toolIdsIPage.records)) } return ToolConverter.toolPageToToolPageVo(toolPage) @@ -41,10 +41,10 @@ class StoreServiceImpl : ServiceImpl(), IStoreService { val toolIdsPage = Page(pageSortParam.currentPage, 20) toolIdsPage.setOptimizeCountSql(false) - val toolIdsIPage = baseMapper.selectPageByUsername(toolIdsPage, username) + val toolIdsIPage = baseMapper.selectAuthorToolIdPageByUsername(toolIdsPage, username) val toolPage = Page(toolIdsIPage.current, toolIdsIPage.size, toolIdsIPage.total) if (toolIdsIPage.total > 0) { - toolPage.setRecords(baseMapper.selectListByIds(toolIdsIPage.records)) + toolPage.setRecords(baseMapper.selectListByAuthorToolIds(toolIdsIPage.records)) } return ToolConverter.toolPageToToolPageVo(toolPage) diff --git a/src/main/resources/mapper/tool/StoreMapper.xml b/src/main/resources/mapper/tool/StoreMapper.xml index ef002f7..f4b4e02 100644 --- a/src/main/resources/mapper/tool/StoreMapper.xml +++ b/src/main/resources/mapper/tool/StoreMapper.xml @@ -1,58 +1,60 @@ - + select concat(temp2.author_id, ':', temp2.tool_id) + from (select temp1.tool_id, temp1.author_id, row_number() over (partition by temp1.tool_id, temp1.author_id) as rn2 + from (select temp0.* + from (select *, row_number() over (partition by t_b_tool_main.tool_id, t_b_tool_main.author_id order by t_b_tool_main.id desc) as rn1 + from t_b_tool_main + where t_b_tool_main.deleted = 0 + ) as temp0 + where temp0.rn1 = 1 + ) as temp1 + left join json_table(json_extract(temp1.keywords, '$[*]'), '$[*]' columns (keyword varchar(50) path '$')) as tk on true + + and temp1.publish != 0 and temp1.review = 'PASS' + + and ( + temp1.name like concat('%', #{searchValue}, '%') + or tk.keyword like concat('%', #{searchValue}, '%') + ) + + + + + order by instr(temp1.name, #{searchValue}) = 0, + char_length(temp1.name), + instr(temp1.name, #{searchValue}), + instr(tk.keyword, #{searchValue}) = 0, + char_length(tk.keyword), + instr(tk.keyword, #{searchValue}) + + + order by temp1.publish desc + + + ) as temp2 + where temp2.rn2 = 1 - + select concat(temp2.author_id, ':', temp2.tool_id) + from (select temp1.tool_id, temp1.author_id, row_number() over (partition by temp1.tool_id, temp1.author_id) as rn2 + from (select temp0.* + from (select *, row_number() over (partition by t_b_tool_main.tool_id, t_b_tool_main.author_id order by t_b_tool_main.id desc) as rn1 + from t_b_tool_main + where t_b_tool_main.deleted = 0 + ) as temp0 + where temp0.rn1 = 1 + ) as temp1 + left join (select * from t_s_user where deleted = 0) as tsu on tsu.id = temp1.author_id + where temp1.publish != 0 + and temp1.review = 'PASS' + and tsu.username = #{username} + order by temp1.publish desc + ) as temp2 + where temp2.rn2 = 1 + + \ No newline at end of file