Feat(PersonalTool): Add pagination
Add pagination to personal tool management
This commit is contained in:
@@ -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.ResponseCode
|
||||||
import top.fatweb.oxygen.api.entity.common.ResponseResult
|
import top.fatweb.oxygen.api.entity.common.ResponseResult
|
||||||
import top.fatweb.oxygen.api.entity.tool.ToolBase
|
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.param.tool.*
|
||||||
import top.fatweb.oxygen.api.service.tool.IEditService
|
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.ToolCategoryVo
|
||||||
import top.fatweb.oxygen.api.vo.tool.ToolTemplateVo
|
import top.fatweb.oxygen.api.vo.tool.ToolTemplateVo
|
||||||
import top.fatweb.oxygen.api.vo.tool.ToolVo
|
import top.fatweb.oxygen.api.vo.tool.ToolVo
|
||||||
@@ -111,13 +113,16 @@ class EditController(
|
|||||||
* @return Response object includes tool list
|
* @return Response object includes tool list
|
||||||
* @author FatttSnake, fatttsnake@gmail.com
|
* @author FatttSnake, fatttsnake@gmail.com
|
||||||
* @since 1.0.0
|
* @since 1.0.0
|
||||||
|
* @see PageSortParam
|
||||||
* @see ResponseResult
|
* @see ResponseResult
|
||||||
|
* @see PageVo
|
||||||
* @see ToolVo
|
* @see ToolVo
|
||||||
*/
|
*/
|
||||||
|
@Trim
|
||||||
@Operation(summary = "获取个人工具")
|
@Operation(summary = "获取个人工具")
|
||||||
@GetMapping
|
@GetMapping
|
||||||
fun get(): ResponseResult<List<ToolVo>> =
|
fun get(@Valid pageSortParam: PageSortParam): ResponseResult<PageVo<ToolVo>> =
|
||||||
ResponseResult.databaseSuccess(ResponseCode.DATABASE_SELECT_SUCCESS, data = editService.get())
|
ResponseResult.databaseSuccess(ResponseCode.DATABASE_SELECT_SUCCESS, data = editService.getPage(pageSortParam))
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Get tool detail
|
* Get tool detail
|
||||||
|
|||||||
@@ -1,6 +1,7 @@
|
|||||||
package top.fatweb.oxygen.api.mapper.tool
|
package top.fatweb.oxygen.api.mapper.tool
|
||||||
|
|
||||||
import com.baomidou.mybatisplus.core.mapper.BaseMapper
|
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.Mapper
|
||||||
import org.apache.ibatis.annotations.Param
|
import org.apache.ibatis.annotations.Param
|
||||||
import top.fatweb.oxygen.api.entity.tool.Tool
|
import top.fatweb.oxygen.api.entity.tool.Tool
|
||||||
@@ -41,15 +42,28 @@ interface EditMapper : BaseMapper<Tool> {
|
|||||||
fun selectOne(@Param("id") id: Long, @Param("userId") userId: Long): Tool?
|
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
|
* @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<String>, @Param("userId") userId: Long): IPage<String>
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 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
|
* @author FatttSnake, fatttsnake@gmail.com
|
||||||
* @since 1.0.0
|
* @since 1.0.0
|
||||||
* @see Tool
|
* @see Tool
|
||||||
*/
|
*/
|
||||||
fun selectPersonal(@Param("userId") userId: Long): List<Tool>
|
fun selectListByToolIds(@Param("toolIds") toolIds: List<String>, @Param("userId") userId: Long): List<Tool>
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Select tool detail
|
* Select tool detail
|
||||||
|
|||||||
@@ -29,11 +29,11 @@ interface StoreMapper : BaseMapper<Tool> {
|
|||||||
fun selectAuthorToolIdPage(page: IPage<Long>, @Param("searchValue") searchValue: String?): IPage<String>
|
fun selectAuthorToolIdPage(page: IPage<Long>, @Param("searchValue") searchValue: String?): IPage<String>
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Select tool ID by username in page
|
* Select author and tool ID by username in page
|
||||||
*
|
*
|
||||||
* @param page Pagination
|
* @param page Pagination
|
||||||
* @param username Username
|
* @param username Username
|
||||||
* @return Tool ID in page
|
* @return Author:Tool_ID in page
|
||||||
* @author FatttSnake, fatttsnake@gmail.com
|
* @author FatttSnake, fatttsnake@gmail.com
|
||||||
* @since 1.0.0
|
* @since 1.0.0
|
||||||
* @see IPage
|
* @see IPage
|
||||||
@@ -44,7 +44,7 @@ interface StoreMapper : BaseMapper<Tool> {
|
|||||||
* Select tool in list by tool IDs
|
* Select tool in list by tool IDs
|
||||||
*
|
*
|
||||||
* @param ids List of tool IDs
|
* @param ids List of tool IDs
|
||||||
* @return List of tool object
|
* @return List of Tool object
|
||||||
* @author FatttSnake, fatttsnake@gmail.com
|
* @author FatttSnake, fatttsnake@gmail.com
|
||||||
* @since 1.0.0
|
* @since 1.0.0
|
||||||
* @see Tool
|
* @see Tool
|
||||||
|
|||||||
@@ -4,5 +4,13 @@ import com.baomidou.mybatisplus.core.mapper.BaseMapper
|
|||||||
import org.apache.ibatis.annotations.Mapper
|
import org.apache.ibatis.annotations.Mapper
|
||||||
import top.fatweb.oxygen.api.entity.tool.ToolFavorite
|
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
|
@Mapper
|
||||||
interface ToolFavoriteMapper : BaseMapper<ToolFavorite>
|
interface ToolFavoriteMapper : BaseMapper<ToolFavorite>
|
||||||
@@ -3,7 +3,9 @@ package top.fatweb.oxygen.api.service.tool
|
|||||||
import com.baomidou.mybatisplus.extension.service.IService
|
import com.baomidou.mybatisplus.extension.service.IService
|
||||||
import top.fatweb.oxygen.api.entity.tool.Tool
|
import top.fatweb.oxygen.api.entity.tool.Tool
|
||||||
import top.fatweb.oxygen.api.entity.tool.ToolBase
|
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.param.tool.*
|
||||||
|
import top.fatweb.oxygen.api.vo.PageVo
|
||||||
import top.fatweb.oxygen.api.vo.tool.ToolCategoryVo
|
import top.fatweb.oxygen.api.vo.tool.ToolCategoryVo
|
||||||
import top.fatweb.oxygen.api.vo.tool.ToolTemplateVo
|
import top.fatweb.oxygen.api.vo.tool.ToolTemplateVo
|
||||||
import top.fatweb.oxygen.api.vo.tool.ToolVo
|
import top.fatweb.oxygen.api.vo.tool.ToolVo
|
||||||
@@ -98,12 +100,15 @@ interface IEditService : IService<Tool> {
|
|||||||
/**
|
/**
|
||||||
* Get personal tools
|
* Get personal tools
|
||||||
*
|
*
|
||||||
* @return List of ToolVo object
|
* @param pageSortParam Page sort parameters
|
||||||
|
* @return PageVo<ToolVo> object
|
||||||
* @author FatttSnake, fatttsnake@gmail.com
|
* @author FatttSnake, fatttsnake@gmail.com
|
||||||
* @since 1.0.0
|
* @since 1.0.0
|
||||||
|
* @see PageSortParam
|
||||||
|
* @see PageVo
|
||||||
* @see ToolVo
|
* @see ToolVo
|
||||||
*/
|
*/
|
||||||
fun get(): List<ToolVo>
|
fun getPage(pageSortParam: PageSortParam): PageVo<ToolVo>
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Get tool detail
|
* Get tool detail
|
||||||
|
|||||||
@@ -19,16 +19,27 @@ interface IStoreService : IService<Tool> {
|
|||||||
/**
|
/**
|
||||||
* Get tool in page
|
* Get tool in page
|
||||||
*
|
*
|
||||||
|
* @param toolStoreGetParam Get tool parameters in tool store
|
||||||
|
* @return PageVo<ToolVo> object
|
||||||
* @author FatttSnake, fatttsnake@gmail.com
|
* @author FatttSnake, fatttsnake@gmail.com
|
||||||
* @since 1.0.0
|
* @since 1.0.0
|
||||||
|
* @see ToolStoreGetParam
|
||||||
|
* @see PageVo
|
||||||
|
* @see ToolVo
|
||||||
*/
|
*/
|
||||||
fun getPage(toolStoreGetParam: ToolStoreGetParam?): PageVo<ToolVo>
|
fun getPage(toolStoreGetParam: ToolStoreGetParam): PageVo<ToolVo>
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Get tool by username in page
|
* Get tool by username in page
|
||||||
*
|
*
|
||||||
|
* @param pageSortParam Page sort parameters
|
||||||
|
* @param username Username
|
||||||
|
* @return PageVo<ToolVo< object
|
||||||
* @author FatttSnake, fatttsnake@gmail.com
|
* @author FatttSnake, fatttsnake@gmail.com
|
||||||
* @since 1.0.0
|
* @since 1.0.0
|
||||||
|
* @see PageSortParam
|
||||||
|
* @see PageVo
|
||||||
|
* @see ToolVo
|
||||||
*/
|
*/
|
||||||
fun getPage(pageSortParam: PageSortParam, username: String): PageVo<ToolVo>
|
fun getPage(pageSortParam: PageSortParam, username: String): PageVo<ToolVo>
|
||||||
}
|
}
|
||||||
@@ -3,4 +3,12 @@ package top.fatweb.oxygen.api.service.tool
|
|||||||
import com.baomidou.mybatisplus.extension.service.IService
|
import com.baomidou.mybatisplus.extension.service.IService
|
||||||
import top.fatweb.oxygen.api.entity.tool.ToolFavorite
|
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<ToolFavorite>
|
interface IToolFavoriteService : IService<ToolFavorite>
|
||||||
@@ -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.KtQueryWrapper
|
||||||
import com.baomidou.mybatisplus.extension.kotlin.KtUpdateWrapper
|
import com.baomidou.mybatisplus.extension.kotlin.KtUpdateWrapper
|
||||||
|
import com.baomidou.mybatisplus.extension.plugins.pagination.Page
|
||||||
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl
|
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl
|
||||||
import org.springframework.dao.DuplicateKeyException
|
import org.springframework.dao.DuplicateKeyException
|
||||||
import org.springframework.stereotype.Service
|
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.entity.tool.*
|
||||||
import top.fatweb.oxygen.api.exception.*
|
import top.fatweb.oxygen.api.exception.*
|
||||||
import top.fatweb.oxygen.api.mapper.tool.EditMapper
|
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.param.tool.*
|
||||||
import top.fatweb.oxygen.api.service.tool.*
|
import top.fatweb.oxygen.api.service.tool.*
|
||||||
import top.fatweb.oxygen.api.util.WebUtil
|
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.ToolCategoryVo
|
||||||
import top.fatweb.oxygen.api.vo.tool.ToolTemplateVo
|
import top.fatweb.oxygen.api.vo.tool.ToolTemplateVo
|
||||||
import top.fatweb.oxygen.api.vo.tool.ToolVo
|
import top.fatweb.oxygen.api.vo.tool.ToolVo
|
||||||
@@ -210,9 +213,18 @@ class EditServiceImpl(
|
|||||||
return this.getOne(tool.id!!)
|
return this.getOne(tool.id!!)
|
||||||
}
|
}
|
||||||
|
|
||||||
override fun get(): List<ToolVo> =
|
override fun getPage(pageSortParam: PageSortParam): PageVo<ToolVo> {
|
||||||
baseMapper.selectPersonal(WebUtil.getLoginUserId()!!)
|
val toolIdsPage = Page<String>(pageSortParam.currentPage, 20)
|
||||||
.map(ToolConverter::toolToToolVo)
|
toolIdsPage.setOptimizeCountSql(false)
|
||||||
|
|
||||||
|
val toolIdsIPage = baseMapper.selectPersonalToolIdPage(toolIdsPage, WebUtil.getLoginUserId()!!)
|
||||||
|
val toolPage = Page<Tool>(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 {
|
override fun detail(username: String, toolId: String, ver: String, platform: ToolBase.Platform): ToolVo {
|
||||||
if (username == "!" && WebUtil.getLoginUserId() == null) {
|
if (username == "!" && WebUtil.getLoginUserId() == null) {
|
||||||
@@ -272,7 +284,12 @@ class EditServiceImpl(
|
|||||||
throw RecordAlreadyExists()
|
throw RecordAlreadyExists()
|
||||||
}
|
}
|
||||||
|
|
||||||
this.detail(toolFavoriteAddParam.username!!, toolFavoriteAddParam.toolId!!, "latest", toolFavoriteAddParam.platform!!)
|
this.detail(
|
||||||
|
toolFavoriteAddParam.username!!,
|
||||||
|
toolFavoriteAddParam.toolId!!,
|
||||||
|
"latest",
|
||||||
|
toolFavoriteAddParam.platform!!
|
||||||
|
)
|
||||||
|
|
||||||
toolFavoriteService.save(
|
toolFavoriteService.save(
|
||||||
ToolFavorite().apply {
|
ToolFavorite().apply {
|
||||||
|
|||||||
@@ -25,11 +25,11 @@ import top.fatweb.oxygen.api.vo.tool.ToolVo
|
|||||||
*/
|
*/
|
||||||
@Service
|
@Service
|
||||||
class StoreServiceImpl : ServiceImpl<StoreMapper, Tool>(), IStoreService {
|
class StoreServiceImpl : ServiceImpl<StoreMapper, Tool>(), IStoreService {
|
||||||
override fun getPage(toolStoreGetParam: ToolStoreGetParam?): PageVo<ToolVo> {
|
override fun getPage(toolStoreGetParam: ToolStoreGetParam): PageVo<ToolVo> {
|
||||||
val toolIdsPage = Page<Long>(toolStoreGetParam?.currentPage ?: 1, 20)
|
val toolIdsPage = Page<Long>(toolStoreGetParam.currentPage, 20)
|
||||||
toolIdsPage.setOptimizeCountSql(false)
|
toolIdsPage.setOptimizeCountSql(false)
|
||||||
|
|
||||||
val toolIdsIPage = baseMapper.selectAuthorToolIdPage(toolIdsPage, toolStoreGetParam?.searchValue)
|
val toolIdsIPage = baseMapper.selectAuthorToolIdPage(toolIdsPage, toolStoreGetParam.searchValue)
|
||||||
val toolPage = Page<Tool>(toolIdsIPage.current, toolIdsIPage.size, toolIdsIPage.total)
|
val toolPage = Page<Tool>(toolIdsIPage.current, toolIdsIPage.size, toolIdsIPage.total)
|
||||||
if (toolIdsIPage.total > 0) {
|
if (toolIdsIPage.total > 0) {
|
||||||
toolPage.setRecords(baseMapper.selectListByAuthorToolIds(toolIdsIPage.records, WebUtil.getLoginUserId()))
|
toolPage.setRecords(baseMapper.selectListByAuthorToolIds(toolIdsIPage.records, WebUtil.getLoginUserId()))
|
||||||
|
|||||||
@@ -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.mapper.tool.ToolFavoriteMapper
|
||||||
import top.fatweb.oxygen.api.service.tool.IToolFavoriteService
|
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
|
@Service
|
||||||
class ToolFavoriteServiceImpl : ServiceImpl<ToolFavoriteMapper, ToolFavorite>(), IToolFavoriteService
|
class ToolFavoriteServiceImpl : ServiceImpl<ToolFavoriteMapper, ToolFavorite>(), IToolFavoriteService
|
||||||
@@ -94,7 +94,15 @@
|
|||||||
and t_b_tool_main.id = #{id}
|
and t_b_tool_main.id = #{id}
|
||||||
</select>
|
</select>
|
||||||
|
|
||||||
<select id="selectPersonal" resultMap="top.fatweb.oxygen.api.mapper.tool.ManagementMapper.toolMap">
|
<select id="selectPersonalToolIdPage" resultType="string">
|
||||||
|
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
|
||||||
|
</select>
|
||||||
|
|
||||||
|
<select id="selectListByToolIds" resultMap="top.fatweb.oxygen.api.mapper.tool.ManagementMapper.toolMap">
|
||||||
select t_b_tool_main.id as tool_id,
|
select t_b_tool_main.id as tool_id,
|
||||||
t_b_tool_main.name as tool_name,
|
t_b_tool_main.name as tool_name,
|
||||||
t_b_tool_main.tool_id as tool_tool_id,
|
t_b_tool_main.tool_id as tool_tool_id,
|
||||||
@@ -126,9 +134,18 @@
|
|||||||
on t_b_tool_main.id = trtmc.tool_id
|
on t_b_tool_main.id = trtmc.tool_id
|
||||||
left join (select * from t_b_tool_category where deleted = 0 and enable = 1) as tbtc
|
left join (select * from t_b_tool_category where deleted = 0 and enable = 1) as tbtc
|
||||||
on tbtc.id = trtmc.category_id
|
on tbtc.id = trtmc.category_id
|
||||||
where t_b_tool_main.deleted = 0
|
<where>
|
||||||
and t_b_tool_main.author_id = #{userId}
|
and t_b_tool_main.deleted = 0
|
||||||
order by t_b_tool_main.id desc
|
and t_b_tool_main.author_id = #{userId}
|
||||||
|
<foreach collection="toolIds" item="item" index="index" open="and t_b_tool_main.tool_id in (" separator="," close=")"
|
||||||
|
nullable="true">
|
||||||
|
#{item}
|
||||||
|
</foreach>
|
||||||
|
</where>
|
||||||
|
<foreach collection="toolIds" item="item" index="index" open="order by field(t_b_tool_main.tool_id," separator=","
|
||||||
|
close="), t_b_tool_main.id desc" nullable="true">
|
||||||
|
#{item}
|
||||||
|
</foreach>
|
||||||
</select>
|
</select>
|
||||||
|
|
||||||
<select id="selectDetail" resultMap="top.fatweb.oxygen.api.mapper.tool.ManagementMapper.toolWithDataMap">
|
<select id="selectDetail" resultMap="top.fatweb.oxygen.api.mapper.tool.ManagementMapper.toolWithDataMap">
|
||||||
|
|||||||
Reference in New Issue
Block a user