Complete core functions #9
@@ -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<PageVo<ToolVo>> =
|
||||
ResponseResult.databaseSuccess(data = storeService.getPage(toolStoreGetParam))
|
||||
}
|
||||
@@ -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<Tool> {
|
||||
* @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<Tool> {
|
||||
* @return List of tool object
|
||||
* @author FatttSnake, fatttsnake@gmail.com
|
||||
* @since 1.0.0
|
||||
* @see Tool
|
||||
*/
|
||||
fun selectListByIds(@Param("ids") ids: List<Long>): List<Tool>
|
||||
}
|
||||
@@ -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<Tool> {
|
||||
/**
|
||||
* 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<Long>, @Param("searchValue") searchValue: String?): IPage<Long>
|
||||
|
||||
/**
|
||||
* 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<Long>): List<Tool>
|
||||
}
|
||||
@@ -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
|
||||
|
||||
@@ -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
|
||||
|
||||
@@ -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()
|
||||
@@ -28,7 +28,7 @@ interface IManagementService : IService<Tool> {
|
||||
fun getOne(id: Long): ToolVo
|
||||
|
||||
/**
|
||||
* Get tool as page
|
||||
* Get tool in page
|
||||
*
|
||||
* @param toolManagementGetParam Get tool parameters in tool management
|
||||
* @return PageVo<ToolVo> object
|
||||
|
||||
@@ -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<Tool> {
|
||||
/**
|
||||
* Get tool in page
|
||||
*
|
||||
* @author FatttSnake, fatttsnake@gmail.com
|
||||
* @since 1.0.0
|
||||
*/
|
||||
fun getPage(toolStoreGetParam: ToolStoreGetParam?): PageVo<ToolVo>
|
||||
}
|
||||
@@ -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<StoreMapper, Tool>(), IStoreService {
|
||||
override fun getPage(toolStoreGetParam: ToolStoreGetParam?): PageVo<ToolVo> {
|
||||
val toolIdsPage = Page<Long>(toolStoreGetParam?.currentPage ?: 1, 20)
|
||||
|
||||
val toolIdsIPage = baseMapper.selectPage(toolIdsPage, toolStoreGetParam?.searchValue)
|
||||
val toolPage = Page<Tool>(toolIdsIPage.current, toolIdsIPage.size, toolIdsIPage.total)
|
||||
if (toolIdsIPage.total > 0) {
|
||||
toolPage.setRecords(baseMapper.selectListByIds(toolIdsIPage.records))
|
||||
}
|
||||
|
||||
return ToolConverter.toolPageToToolPageVo(toolPage)
|
||||
}
|
||||
}
|
||||
83
src/main/resources/mapper/tool/StoreMapper.xml
Normal file
83
src/main/resources/mapper/tool/StoreMapper.xml
Normal file
@@ -0,0 +1,83 @@
|
||||
<?xml version="1.0" encoding="UTF-8"?>
|
||||
<!DOCTYPE mapper PUBLIC "-//mybatis.org//DTD Mapper 3.0//EN" "http://mybatis.org/dtd/mybatis-3-mapper.dtd">
|
||||
<mapper namespace="top.fatweb.oxygen.api.mapper.tool.StoreMapper">
|
||||
<select id="selectPage" resultType="long">
|
||||
select distinct t_b_tool_main.id
|
||||
from t_b_tool_main
|
||||
left join json_table(t_b_tool_main.keywords, '$[*]' columns (keyword varchar(50) path '$')) as tk on true
|
||||
<where>
|
||||
and t_b_tool_main.deleted = 0 and t_b_tool_main.publish != 0
|
||||
<if test="searchValue != null">
|
||||
and (
|
||||
t_b_tool_main.name like concat('%', #{searchValue}, '%')
|
||||
or tk.keyword like concat('%', #{searchValue}, '%')
|
||||
)
|
||||
</if>
|
||||
</where>
|
||||
<choose>
|
||||
<when test="searchValue != null">
|
||||
order by instr(t_b_tool_main.name, #{searchValue}) = 0,
|
||||
char_length(t_b_tool_main.name),
|
||||
instr(t_b_tool_main.name, #{searchValue}),
|
||||
instr(tk.keyword, #{searchValue}) = 0,
|
||||
char_length(tk.keyword),
|
||||
instr(tk.keyword, #{searchValue})
|
||||
</when>
|
||||
<otherwise>
|
||||
order by t_b_tool_main.publish desc
|
||||
</otherwise>
|
||||
</choose>
|
||||
</select>
|
||||
|
||||
<select id="selectListByIds" resultMap="top.fatweb.oxygen.api.mapper.tool.ManagementMapper.toolWithAuthor">
|
||||
select t_b_tool_main.id as tool_id,
|
||||
t_b_tool_main.name as tool_name,
|
||||
t_b_tool_main.tool_id as tool_tool_id,
|
||||
t_b_tool_main.icon as tool_icon,
|
||||
t_b_tool_main.description as tool_description,
|
||||
t_b_tool_main.base_id as tool_base_id,
|
||||
t_b_tool_main.author_id as tool_author_id,
|
||||
t_b_tool_main.ver as tool_ver,
|
||||
t_b_tool_main.keywords as tool_keywords,
|
||||
t_b_tool_main.source_id as tool_source_id,
|
||||
t_b_tool_main.dist_id as tool_dist_id,
|
||||
t_b_tool_main.entry_point as tool_entry_point,
|
||||
t_b_tool_main.publish as tool_publish,
|
||||
t_b_tool_main.review as tool_review,
|
||||
t_b_tool_main.create_time as tool_create_time,
|
||||
t_b_tool_main.update_time as tool_update_time,
|
||||
t_b_tool_main.deleted as tool_deleted,
|
||||
t_b_tool_main.version as tool_version,
|
||||
tsu.id as user_id,
|
||||
tsu.username as user_username,
|
||||
tsui.id as user_info_id,
|
||||
tsui.nickname as user_info_nickname,
|
||||
tsui.avatar as user_info_avatar,
|
||||
tsui.email as user_info_email,
|
||||
tbtc.id as tool_category_id,
|
||||
tbtc.name as tool_category_name,
|
||||
tbtc.enable as tool_category_enable,
|
||||
tbtc.create_time as tool_category_create_time,
|
||||
tbtc.update_time as tool_category_update_time,
|
||||
tbtc.deleted as tool_category_deleted,
|
||||
tbtc.version as tool_category_version
|
||||
from t_b_tool_main
|
||||
left join (select * from t_s_user where deleted = 0) as tsu on tsu.id = t_b_tool_main.author_id
|
||||
left join (select * from t_s_user_info where deleted = 0) as tsui
|
||||
on tsui.user_id = t_b_tool_main.author_id
|
||||
left join (select * from t_r_tool_main_category where deleted = 0) as trtmc
|
||||
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
|
||||
on tbtc.id = trtmc.category_id
|
||||
<where>
|
||||
<foreach collection="ids" item="item" index="index" open="and t_b_tool_main.id in (" separator="," close=")"
|
||||
nullable="true">
|
||||
#{item}
|
||||
</foreach>
|
||||
</where>
|
||||
<foreach collection="ids" item="item" index="index" open="order by field(t_b_tool_main.id," separator=","
|
||||
close=")" nullable="true">
|
||||
#{item}
|
||||
</foreach>
|
||||
</select>
|
||||
</mapper>
|
||||
Reference in New Issue
Block a user