Skip to content

Commit e150c9c

Browse files
authored
[app-builder] 新增用户对于模型列表增删改查接口 (#38)
* [app-platform] 新增用户对于模型列表增删改查接口 * [app-platform] 按照团队标准刷新注释信息, UserModelPo增加createdAt参数。 * [app-builder] 修改检视意见,重构了模型列表接口的代码,提高了可读性和维护性。 * [app-builder] 修改检视意见,为模型列表的增删改查功能添加了单元测试,确保接口的稳定性。 * [app-builder] 修改检视意见,修复单侧内容无实际意义。 * [app-builder] 修改检视意见,修改注释意义语病。 * [app-builder] 修改检视意见,修改接口各字段为更有意义的名字。 * [app-builder] 修改检视意见,优化 repo 层与 service 层的职责边界。
1 parent dad6d68 commit e150c9c

File tree

17 files changed

+1173
-48
lines changed

17 files changed

+1173
-48
lines changed

app-builder/plugins/aipp-custom-model-center/pom.xml

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -44,6 +44,10 @@
4444
<groupId>org.fitframework.integration</groupId>
4545
<artifactId>fit-druid</artifactId>
4646
</dependency>
47+
<dependency>
48+
<groupId>modelengine.fit.jade.service</groupId>
49+
<artifactId>tool-service</artifactId>
50+
</dependency>
4751

4852
<!-- Test -->
4953
<dependency>

app-builder/plugins/aipp-custom-model-center/src/main/java/modelengine/fit/jade/aipp/model/mapper/ModelMapper.java

Lines changed: 20 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,7 @@
77
package modelengine.fit.jade.aipp.model.mapper;
88

99
import modelengine.fit.jade.aipp.model.po.ModelPo;
10+
1011
import org.apache.ibatis.annotations.Mapper;
1112

1213
import java.util.List;
@@ -22,16 +23,30 @@ public interface ModelMapper {
2223
/**
2324
* 根据模型标识查询模型信息。
2425
*
25-
* @param modelId 表示模型标识
26-
* @return 模型信息 {@link ModelPo}。
26+
* @param modelId 表示模型标识的 {@link String}
27+
* @return 模型信息的 {@link ModelPo}。
2728
*/
28-
ModelPo get(String modelId);
29+
ModelPo getModel(String modelId);
2930

3031
/**
3132
* 根据模型标识列表批量查询模型信息。
3233
*
33-
* @param modelIds 表示模型标识列表
34-
* @return 模型信息列表 {@link List}{@code <}{@link ModelPo}{@code >}.
34+
* @param modelIds 表示模型标识列表的 {@link List}{@code <}{@link String}{@code >}
35+
* @return 模型信息列表的 {@link List}{@code <}{@link ModelPo}{@code >}
3536
*/
3637
List<ModelPo> listModels(List<String> modelIds);
38+
39+
/**
40+
* 插入模型信息。
41+
*
42+
* @param model 表示待插入的模型信息的 {@link ModelPo}。
43+
*/
44+
void insertModel(ModelPo model);
45+
46+
/**
47+
* 根据模型标识删除模型信息。
48+
*
49+
* @param modelId 表示待删除模型标识的 {@link String}。
50+
*/
51+
void deleteByModelId(String modelId);
3752
}

app-builder/plugins/aipp-custom-model-center/src/main/java/modelengine/fit/jade/aipp/model/mapper/UserModelMapper.java

Lines changed: 46 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,9 @@
77
package modelengine.fit.jade.aipp.model.mapper;
88

99
import modelengine.fit.jade.aipp.model.po.UserModelPo;
10+
1011
import org.apache.ibatis.annotations.Mapper;
12+
import org.apache.ibatis.annotations.Param;
1113

1214
import java.util.List;
1315

@@ -22,16 +24,56 @@ public interface UserModelMapper {
2224
/**
2325
* 根据用户标识获取用户模型关系列表。
2426
*
25-
* @param userId 表示用户标识
26-
* @return 用户模型关系列表 {@link List}{@code <}{@link UserModelPo}{@code >}.
27+
* @param userId 表示用户标识的 {@link String}
28+
* @return 用户模型关系列表的 {@link List}{@code <}{@link UserModelPo}{@code >}
2729
*/
2830
List<UserModelPo> listUserModels(String userId);
2931

3032
/**
3133
* 根据用户标识获取默认用户模型关系。
3234
*
33-
* @param userId 表示用户标识
34-
* @return 默认的用户模型关系
35+
* @param userId 表示用户标识的 {@link String}
36+
* @return 默认的用户模型关系的 {@link UserModelPo}
3537
*/
3638
UserModelPo getDefault(String userId);
39+
40+
/**
41+
* 判断指定用户是否已绑定默认模型。
42+
*
43+
* @param userId 表示用户标识的 {@link String}。
44+
* @return 若已绑定默认模型则返回 {@code true},否则返回 {@code false}。
45+
*/
46+
boolean hasDefaultModel(String userId);
47+
48+
/**
49+
* 插入用户模型绑定关系。
50+
*
51+
* @param userModel 表示待插入的用户模型关系对象的 {@link UserModelPo}。
52+
*/
53+
void insertUserModel(UserModelPo userModel);
54+
55+
/**
56+
* 根据模型标识删除对应的用户模型绑定关系。
57+
*
58+
* @param modelId 表示模型标识的 {@link String}。
59+
*/
60+
void deleteByModelId(String modelId);
61+
62+
/**
63+
* 查找指定用户最新创建的模型绑定记录(按创建时间降序,取第一条)。
64+
*
65+
* @param userId 表示用户标识的 {@link String}。
66+
* @return 最新的用户模型关系的 {@link UserModelPo}。
67+
*/
68+
UserModelPo findLatestUserModel(String userId);
69+
70+
/**
71+
* 更新指定用户的所有模型绑定记录的默认状态。
72+
* <p>若记录中的模型标识与传入的 {@code modelId} 一致,则设置为默认(1),否则设为非默认(0)。</p>
73+
*
74+
* @param userId 表示用户标识的 {@link String}。
75+
* @param modelId 表示需设为默认的模型标识的 {@link String}。
76+
* @return 成功更新的记录条数的 {@code int}。
77+
*/
78+
int setDefault(@Param("userId") String userId, @Param("modelId") String modelId);
3779
}

app-builder/plugins/aipp-custom-model-center/src/main/java/modelengine/fit/jade/aipp/model/po/ModelPo.java

Lines changed: 137 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -6,22 +6,157 @@
66

77
package modelengine.fit.jade.aipp.model.po;
88

9-
import lombok.AllArgsConstructor;
109
import lombok.Data;
1110
import modelengine.jade.common.po.BasePo;
1211

12+
import java.time.LocalDateTime;
13+
1314
/**
1415
* 模型信息 ORM 对象。
1516
*
1617
* @author lixin
1718
* @since 2025/3/11
1819
*/
1920
@Data
20-
@AllArgsConstructor
2121
public class ModelPo extends BasePo {
2222
private String modelId;
2323
private String name;
2424
private String tag;
2525
private String baseUrl;
2626
private String type;
27+
28+
/**
29+
* 用于构建 {@link ModelPo} 实例的构建器类。
30+
*/
31+
public static class Builder {
32+
private final ModelPo instance = new ModelPo();
33+
34+
/**
35+
* 设置模型标识符。
36+
*
37+
* @param modelId 表示模型唯一标识的 {@link String}。
38+
* @return {@link Builder} 构建器本身。
39+
*/
40+
public Builder modelId(String modelId) {
41+
this.instance.setModelId(modelId);
42+
return this;
43+
}
44+
45+
/**
46+
* 设置模型名称。
47+
*
48+
* @param name 表示模型名称的 {@link String}。
49+
* @return {@link Builder} 构建器本身。
50+
*/
51+
public Builder name(String name) {
52+
this.instance.setName(name);
53+
return this;
54+
}
55+
56+
/**
57+
* 设置模型标签。
58+
*
59+
* @param tag 表示模型所属标签的 {@link String}。
60+
* @return {@link Builder} 构建器本身。
61+
*/
62+
public Builder tag(String tag) {
63+
this.instance.setTag(tag);
64+
return this;
65+
}
66+
67+
/**
68+
* 设置模型基础地址。
69+
*
70+
* @param baseUrl 表示模型服务访问基础地址的 {@link String}。
71+
* @return {@link Builder} 构建器本身。
72+
*/
73+
public Builder baseUrl(String baseUrl) {
74+
this.instance.setBaseUrl(baseUrl);
75+
return this;
76+
}
77+
78+
/**
79+
* 设置模型类型。
80+
*
81+
* @param type 表示模型类型的 {@link String}。
82+
* @return {@link Builder} 构建器本身。
83+
*/
84+
public Builder type(String type) {
85+
this.instance.setType(type);
86+
return this;
87+
}
88+
89+
/**
90+
* 设置数据库主键标识。
91+
*
92+
* @param id 表示模型数据的唯一数据库主键的 {@link Long}。
93+
* @return {@link Builder} 构建器本身。
94+
*/
95+
public Builder id(Long id) {
96+
this.instance.setId(id);
97+
return this;
98+
}
99+
100+
/**
101+
* 设置创建时间。
102+
*
103+
* @param createdAt 表示模型创建时间的 {@link LocalDateTime}。
104+
* @return {@link Builder} 构建器本身。
105+
*/
106+
public Builder createdAt(LocalDateTime createdAt) {
107+
this.instance.setCreatedAt(createdAt);
108+
return this;
109+
}
110+
111+
/**
112+
* 设置更新时间。
113+
*
114+
* @param updatedAt 表示模型最近更新时间的 {@link LocalDateTime}。
115+
* @return {@link Builder} 构建器本身。
116+
*/
117+
public Builder updatedAt(LocalDateTime updatedAt) {
118+
this.instance.setUpdatedAt(updatedAt);
119+
return this;
120+
}
121+
122+
/**
123+
* 设置创建人标识。
124+
*
125+
* @param createdBy 表示创建该模型记录的用户标识的 {@link String}。
126+
* @return {@link Builder} 构建器本身。
127+
*/
128+
public Builder createdBy(String createdBy) {
129+
this.instance.setCreatedBy(createdBy);
130+
return this;
131+
}
132+
133+
/**
134+
* 设置更新人标识。
135+
*
136+
* @param updatedBy 表示最近更新该模型记录的用户标识的 {@link String}。
137+
* @return {@link Builder} 构建器本身。
138+
*/
139+
public Builder updatedBy(String updatedBy) {
140+
this.instance.setUpdatedBy(updatedBy);
141+
return this;
142+
}
143+
144+
/**
145+
* 构建并返回 {@link ModelPo} 实例。
146+
*
147+
* @return 构建完成的 {@link ModelPo} 实例。
148+
*/
149+
public ModelPo build() {
150+
return this.instance;
151+
}
152+
}
153+
154+
/**
155+
* 创建并返回一个新的 {@link Builder} 构建器实例。
156+
*
157+
* @return {@link Builder} 实例,用于构建 {@link ModelPo}。
158+
*/
159+
public static Builder builder() {
160+
return new Builder();
161+
}
27162
}

0 commit comments

Comments
 (0)