Optimize tools api

This commit is contained in:
2024-02-18 17:39:12 +08:00
parent c5dcb432ef
commit 0baccbd0e5
4 changed files with 21 additions and 13 deletions

View File

@@ -79,7 +79,7 @@ class SecurityConfig(
"/forget",
"/retrieve"
).anonymous()
.requestMatchers("/tool/detail/**").permitAll()
.requestMatchers("/tool/detail/**", "/tool/store").permitAll()
// Authentication required
.anyRequest().authenticated()
}

View File

@@ -223,7 +223,7 @@ class EditServiceImpl(
if (tool.review == Tool.ReviewType.PROCESSING) {
throw ToolUnderReviewException()
}
if (tool.review == Tool.ReviewType.PASS || tool.publish != 0L) {
if (tool.review == Tool.ReviewType.PASS && tool.publish != 0L) {
throw ToolHasBeenPublishedException()
}
@@ -232,7 +232,7 @@ class EditServiceImpl(
override fun cancel(id: Long): Boolean {
val tool = getById(id)
if (tool.review == Tool.ReviewType.PASS || tool.publish != 0L) {
if (tool.review == Tool.ReviewType.PASS && tool.publish != 0L) {
throw ToolHasBeenPublishedException()
}
if (tool.review != Tool.ReviewType.PROCESSING) {

View File

@@ -111,7 +111,6 @@ class ManagementServiceImpl(
KtUpdateWrapper(Tool())
.eq(Tool::id, id)
.set(Tool::review, Tool.ReviewType.REJECT)
.set(Tool::publish, 0)
)
return this.getOne(id)

View File

@@ -2,31 +2,40 @@
<!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
select distinct tb.id from
(
select tbtm.id
from (select temp.*
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 rn
from t_b_tool_main where deleted = 0) temp
where temp.rn = 1) as tbtm
left join json_table(json_extract(tbtm.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
and tbtm.publish != 0 and tbtm.review = 'PASS'
<if test="searchValue != null">
and (
t_b_tool_main.name like concat('%', #{searchValue}, '%')
tbtm.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}),
order by instr(tbtm.name, #{searchValue}) = 0,
char_length(tbtm.name),
instr(tbtm.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
order by tbtm.publish desc
</otherwise>
</choose>
) as tb
</select>
<select id="selectListByIds" resultMap="top.fatweb.oxygen.api.mapper.tool.ManagementMapper.toolWithAuthor">