feat(themes): 支持主题标签数组存储与按风格查询
- 新增 StringArrayTypeHandler 实现 PostgreSQL text[] ↔ Java String[] 映射 - 将 theme_tag 字段类型由 VARCHAR 改为 ARRAY,实体与 VO 同步调整为 String[] - 移除废弃的 selectAllThemes 方法,统一使用 selectThemesByStyle(Long) - 9999 风格 ID 保留查询全部上架主题逻辑,其余按风格过滤 - 开放 /themes/listByStyle 接口免鉴权,并修正 theme_status=true 查询条件
This commit is contained in:
@@ -85,7 +85,8 @@ public class SaTokenConfigure implements WebMvcConfigurer {
|
||||
"/character/list",
|
||||
"/user/resetPassWord",
|
||||
"/chat/talk",
|
||||
"/chat/save_embed"
|
||||
"/chat/save_embed",
|
||||
"/themes/listByStyle"
|
||||
};
|
||||
}
|
||||
@Bean
|
||||
|
||||
@@ -30,9 +30,6 @@ public class ThemesController {
|
||||
@Resource
|
||||
private KeyboardThemesService themesService;
|
||||
|
||||
@Resource
|
||||
private KeyboardThemesService keyboardThemesService;
|
||||
|
||||
@Resource
|
||||
private KeyboardThemeStylesService keyboardThemeStylesService;
|
||||
|
||||
|
||||
@@ -4,6 +4,7 @@ import com.baomidou.mybatisplus.annotation.IdType;
|
||||
import com.baomidou.mybatisplus.annotation.TableField;
|
||||
import com.baomidou.mybatisplus.annotation.TableId;
|
||||
import com.baomidou.mybatisplus.annotation.TableName;
|
||||
import com.yolo.keyborad.typehandler.StringArrayTypeHandler;
|
||||
import io.swagger.v3.oas.annotations.media.Schema;
|
||||
import java.math.BigDecimal;
|
||||
import java.util.Date;
|
||||
@@ -30,9 +31,9 @@ public class KeyboardThemes {
|
||||
@Schema(description="键盘价格")
|
||||
private BigDecimal themePrice;
|
||||
|
||||
@TableField(value = "theme_tag")
|
||||
@TableField(value = "theme_tag", typeHandler = StringArrayTypeHandler.class)
|
||||
@Schema(description="主题标签")
|
||||
private String themeTag;
|
||||
private String[] themeTag;
|
||||
|
||||
@TableField(value = "theme_download")
|
||||
@Schema(description="主题下载次数")
|
||||
|
||||
@@ -34,7 +34,7 @@ public class KeyboardThemesRespVO {
|
||||
* 主题标签
|
||||
*/
|
||||
@Schema(description = "主题标签")
|
||||
private String themeTag;
|
||||
private String[] themeTag;
|
||||
|
||||
/**
|
||||
* 主题下载次数
|
||||
|
||||
@@ -12,12 +12,6 @@ import java.util.List;
|
||||
|
||||
public interface KeyboardThemesService extends IService<KeyboardThemes>{
|
||||
|
||||
/**
|
||||
* 查询所有主题列表(未删除且上架)
|
||||
* @return 主题列表
|
||||
*/
|
||||
List<KeyboardThemesRespVO> selectAllThemes();
|
||||
|
||||
/**
|
||||
* 按主题风格查询主题列表(未删除且上架)
|
||||
* @param themeStyle 主题风格
|
||||
|
||||
@@ -17,27 +17,19 @@ import com.yolo.keyborad.service.KeyboardThemesService;
|
||||
@Service
|
||||
public class KeyboardThemesServiceImpl extends ServiceImpl<KeyboardThemesMapper, KeyboardThemes> implements KeyboardThemesService {
|
||||
|
||||
@Override
|
||||
public List<KeyboardThemesRespVO> selectAllThemes() {
|
||||
List<KeyboardThemes> themesList = this.lambdaQuery()
|
||||
.eq(KeyboardThemes::getDeleted, false)
|
||||
.eq(KeyboardThemes::getThemeStatus, false)
|
||||
.list();
|
||||
return BeanUtil.copyToList(themesList, KeyboardThemesRespVO.class);
|
||||
}
|
||||
|
||||
@Override
|
||||
public List<KeyboardThemesRespVO> selectThemesByStyle(Long themeStyle) {
|
||||
if (themeStyle == 9999) {
|
||||
List<KeyboardThemes> themesList = this.lambdaQuery()
|
||||
.eq(KeyboardThemes::getDeleted, false)
|
||||
.eq(KeyboardThemes::getThemeStatus, false)
|
||||
.eq(KeyboardThemes::getThemeStatus, true)
|
||||
.list();
|
||||
return BeanUtil.copyToList(themesList, KeyboardThemesRespVO.class);
|
||||
}
|
||||
List<KeyboardThemes> themesList = this.lambdaQuery()
|
||||
.eq(KeyboardThemes::getDeleted, false)
|
||||
.eq(KeyboardThemes::getThemeStatus, false)
|
||||
.eq(KeyboardThemes::getThemeStatus, true)
|
||||
.eq(KeyboardThemes::getThemeStyle, themeStyle)
|
||||
.list();
|
||||
return BeanUtil.copyToList(themesList, KeyboardThemesRespVO.class);
|
||||
|
||||
@@ -0,0 +1,59 @@
|
||||
package com.yolo.keyborad.typehandler;
|
||||
|
||||
import org.apache.ibatis.type.BaseTypeHandler;
|
||||
import org.apache.ibatis.type.JdbcType;
|
||||
import org.apache.ibatis.type.MappedJdbcTypes;
|
||||
import org.apache.ibatis.type.MappedTypes;
|
||||
|
||||
import java.sql.*;
|
||||
|
||||
/**
|
||||
* String数组类型处理器,用于处理PostgreSQL的数组类型
|
||||
* @author: ziin
|
||||
* @date: 2025/12/9
|
||||
*/
|
||||
@MappedTypes({String[].class})
|
||||
@MappedJdbcTypes({JdbcType.ARRAY, JdbcType.VARCHAR})
|
||||
public class StringArrayTypeHandler extends BaseTypeHandler<String[]> {
|
||||
|
||||
@Override
|
||||
public void setNonNullParameter(PreparedStatement ps, int i, String[] parameter, JdbcType jdbcType) throws SQLException {
|
||||
if (parameter == null || parameter.length == 0) {
|
||||
ps.setNull(i, Types.ARRAY);
|
||||
} else {
|
||||
Connection conn = ps.getConnection();
|
||||
Array array = conn.createArrayOf("text", parameter);
|
||||
ps.setArray(i, array);
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
public String[] getNullableResult(ResultSet rs, String columnName) throws SQLException {
|
||||
return getArray(rs.getArray(columnName));
|
||||
}
|
||||
|
||||
@Override
|
||||
public String[] getNullableResult(ResultSet rs, int columnIndex) throws SQLException {
|
||||
return getArray(rs.getArray(columnIndex));
|
||||
}
|
||||
|
||||
@Override
|
||||
public String[] getNullableResult(CallableStatement cs, int columnIndex) throws SQLException {
|
||||
return getArray(cs.getArray(columnIndex));
|
||||
}
|
||||
|
||||
private String[] getArray(Array array) throws SQLException {
|
||||
if (array == null) {
|
||||
return null;
|
||||
}
|
||||
Object[] objects = (Object[]) array.getArray();
|
||||
if (objects == null || objects.length == 0) {
|
||||
return new String[0];
|
||||
}
|
||||
String[] result = new String[objects.length];
|
||||
for (int i = 0; i < objects.length; i++) {
|
||||
result[i] = objects[i] == null ? null : objects[i].toString();
|
||||
}
|
||||
return result;
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user