refactor(crud): 修改关联查询参数类型为字符串

- 将ClearFieldPage、ClearFieldList、ClearFieldOne等方法中的with参数从bool改为string
- 更新Preload逻辑从固定"*"改为动态传入的字符串参数
- 修改FindPri、First、All、Paginate等方法的with参数类型变更
- 更新IDE缓存文件中的模型和服务映射关系
- 添加News和User相关实体的缓存配置
- 更新数据库表结构映射配置
main v1.0.1013
black1552 2026-03-04 15:10:05 +08:00
parent 8bacccb894
commit 5581041da4
2 changed files with 156 additions and 22 deletions

View File

@ -101,6 +101,13 @@
</set>
</value>
</entry>
<entry key="News">
<value>
<set>
<option value="file://$PROJECT_DIR$/../gin_test/model/news.go" />
</set>
</value>
</entry>
<entry key="Paginate">
<value>
<set>
@ -150,6 +157,13 @@
</set>
</value>
</entry>
<entry key="User">
<value>
<set>
<option value="file://$PROJECT_DIR$/../gin_test/model/user.go" />
</set>
</value>
</entry>
<entry key="resFile">
<value>
<set>
@ -164,6 +178,34 @@
</set>
</value>
</entry>
<entry key="sNewsDao">
<value>
<set>
<option value="file://$PROJECT_DIR$/../gin_test/model/dao/newsDao.go" />
</set>
</value>
</entry>
<entry key="sNewsDb">
<value>
<set>
<option value="file://$PROJECT_DIR$/../gin_test/service/news.go" />
</set>
</value>
</entry>
<entry key="sUser">
<value>
<set>
<option value="file://$PROJECT_DIR$/../gin_test/service/user.go" />
</set>
</value>
</entry>
<entry key="sUserDao">
<value>
<set>
<option value="file://$PROJECT_DIR$/../gin_test/model/dao/userDao.go" />
</set>
</value>
</entry>
</map>
</option>
<option name="scannedPathMapping">
@ -200,7 +242,7 @@
<entry key="file://$PROJECT_DIR$/crud/curd.go">
<value>
<ScannedPath>
<option name="lastModified" value="1772421491111" />
<option name="lastModified" value="1772608170073" />
<option name="schema">
<list>
<option value="Paginate" />
@ -420,6 +462,92 @@
</ScannedPath>
</value>
</entry>
<entry key="file://$PROJECT_DIR$/../gin_test/controller/home/index.go">
<value>
<ScannedPath>
<option name="lastModified" value="1772606534126" />
</ScannedPath>
</value>
</entry>
<entry key="file://$PROJECT_DIR$/../gin_test/migrate/migrate.go">
<value>
<ScannedPath>
<option name="lastModified" value="1772607808155" />
</ScannedPath>
</value>
</entry>
<entry key="file://$PROJECT_DIR$/../gin_test/model/dao/newsDao.go">
<value>
<ScannedPath>
<option name="lastModified" value="1772605092268" />
<option name="schema">
<list>
<option value="sNewsDao" />
</list>
</option>
</ScannedPath>
</value>
</entry>
<entry key="file://$PROJECT_DIR$/../gin_test/model/dao/userDao.go">
<value>
<ScannedPath>
<option name="lastModified" value="1772605102821" />
<option name="schema">
<list>
<option value="sUserDao" />
</list>
</option>
</ScannedPath>
</value>
</entry>
<entry key="file://$PROJECT_DIR$/../gin_test/model/news.go">
<value>
<ScannedPath>
<option name="lastModified" value="1772607773437" />
<option name="schema">
<list>
<option value="News" />
</list>
</option>
</ScannedPath>
</value>
</entry>
<entry key="file://$PROJECT_DIR$/../gin_test/model/user.go">
<value>
<ScannedPath>
<option name="lastModified" value="1772606080031" />
<option name="schema">
<list>
<option value="User" />
</list>
</option>
</ScannedPath>
</value>
</entry>
<entry key="file://$PROJECT_DIR$/../gin_test/service/news.go">
<value>
<ScannedPath>
<option name="lastModified" value="1772593137875" />
<option name="schema">
<list>
<option value="sNewsDb" />
</list>
</option>
</ScannedPath>
</value>
</entry>
<entry key="file://$PROJECT_DIR$/../gin_test/service/user.go">
<value>
<ScannedPath>
<option name="lastModified" value="1772593163860" />
<option name="schema">
<list>
<option value="sUser" />
</list>
</option>
</ScannedPath>
</value>
</entry>
</map>
</option>
<option name="tableStructMapping">
@ -438,15 +566,21 @@
<entry key="jwt_config" value="JwtConfig" />
<entry key="manager" value="Manager" />
<entry key="msg" value="Msg" />
<entry key="news" value="News" />
<entry key="paginate" value="Paginate" />
<entry key="res_file" value="resFile" />
<entry key="response" value="response" />
<entry key="s_news_dao" value="sNewsDao" />
<entry key="s_news_db" value="sNewsDb" />
<entry key="s_user" value="sUser" />
<entry key="s_user_dao" value="sUserDao" />
<entry key="server_config" value="ServerConfig" />
<entry key="sq_lite_pool" value="SQLitePool" />
<entry key="tcp_connection" value="TcpConnection" />
<entry key="tcp_message" value="TcpMessage" />
<entry key="tcp_pool_config" value="TcpPoolConfig" />
<entry key="tcp_server" value="TCPServer" />
<entry key="user" value="User" />
</map>
</option>
<option name="lastTimeChecked" value="1772592078880" />

View File

@ -212,14 +212,14 @@ func (c Crud[R]) ClearField(req any, delField []string, subField ...map[string]a
}
// ClearFieldPage -------------------------- 原ClearFieldPage对应实现清理参数+分页查询 --------------------------
func (c Crud[R]) ClearFieldPage(ctx ctx, req any, delField []string, where any, page *Paginate, order any, with bool) (items []*R, total int64, err error) {
func (c Crud[R]) ClearFieldPage(ctx ctx, req any, delField []string, where any, page *Paginate, order any, with string) (items []*R, total int64, err error) {
// 1. 清理请求参数
filterMap := c.ClearField(req, delField)
// 2. 初始化GORM查询
db := c.Dao.Ctx(ctx)
if with {
db = db.Preload("*") // GORM 关联查询全部对应GF的WithAll()
if with != "" {
db = db.Preload(with) // GORM 关联查询全部对应GF的WithAll()
}
// 3. 构建查询条件
@ -250,12 +250,12 @@ func (c Crud[R]) ClearFieldPage(ctx ctx, req any, delField []string, where any,
}
// ClearFieldList -------------------------- 原ClearFieldList对应实现清理参数+列表查询(不分页) --------------------------
func (c Crud[R]) ClearFieldList(ctx ctx, req any, delField []string, where any, order any, with bool) (items []*R, err error) {
func (c Crud[R]) ClearFieldList(ctx ctx, req any, delField []string, where any, order any, with string) (items []*R, err error) {
filterMap := c.ClearField(req, delField)
db := c.Dao.Ctx(ctx).Model(new(R))
if with {
db = db.Preload("*")
if with != "" {
db = db.Preload(with)
}
if where != nil {
db = db.Where(where)
@ -269,13 +269,13 @@ func (c Crud[R]) ClearFieldList(ctx ctx, req any, delField []string, where any,
}
// ClearFieldOne -------------------------- 原ClearFieldOne对应实现清理参数+单条查询 --------------------------
func (c Crud[R]) ClearFieldOne(ctx ctx, req any, delField []string, where any, order any, with bool) (item *R, err error) {
func (c Crud[R]) ClearFieldOne(ctx ctx, req any, delField []string, where any, order any, with string) (item *R, err error) {
item = new(R)
filterMap := c.ClearField(req, delField)
db := c.Dao.Ctx(ctx).Model(item)
if with {
db = db.Preload("*")
if with != "" {
db = db.Preload(with)
}
if where != nil {
db = db.Where(where)
@ -371,7 +371,7 @@ func (c Crud[R]) ArrayField(ctx ctx, where any, field any) []interface{} {
}
// FindPri -------------------------- 原FindPri对应实现按主键查询单条记录 --------------------------
func (c Crud[R]) FindPri(ctx ctx, primaryKey any, with bool) (model *R) {
func (c Crud[R]) FindPri(ctx ctx, primaryKey any, with string) (model *R) {
model = new(R)
db := c.Dao.Ctx(ctx).Model(model)
pk := c.Dao.PrimaryKey()
@ -379,8 +379,8 @@ func (c Crud[R]) FindPri(ctx ctx, primaryKey any, with bool) (model *R) {
if pk == "" {
panic("主键字段未配置")
}
if with {
db = db.Preload("*")
if with != "" {
db = db.Preload(with)
}
// 按主键查询
@ -392,12 +392,12 @@ func (c Crud[R]) FindPri(ctx ctx, primaryKey any, with bool) (model *R) {
}
// -------------------------- 原First对应实现按条件查询第一条记录 --------------------------
func (c Crud[R]) First(ctx ctx, where any, order any, with bool) (model *R) {
func (c Crud[R]) First(ctx ctx, where any, order any, with string) (model *R) {
model = new(R)
db := c.Dao.Ctx(ctx).Model(model)
if with {
db = db.Preload("*")
if with != "" {
db = db.Preload(with)
}
if where != nil {
db = db.Where(where)
@ -424,11 +424,11 @@ func (c Crud[R]) Exists(ctx ctx, where any) (exists bool) {
}
// -------------------------- 原All对应实现查询所有符合条件的记录 --------------------------
func (c Crud[R]) All(ctx ctx, where any, order any, with bool) (items []*R) {
func (c Crud[R]) All(ctx ctx, where any, order any, with string) (items []*R) {
db := c.Dao.Ctx(ctx).Model(new(R))
if with {
db = db.Preload("*")
if with != "" {
db = db.Preload(with)
}
if where != nil {
db = db.Where(where)
@ -487,7 +487,7 @@ func (c Crud[R]) UpdatePri(ctx ctx, primaryKey any, data any) (count int64) {
}
// -------------------------- 原Paginate对应实现分页查询 --------------------------
func (c Crud[R]) Paginate(ctx context.Context, where any, p Paginate, with bool, order any) (items []*R, total int64) {
func (c Crud[R]) Paginate(ctx context.Context, where any, p Paginate, with string, order any) (items []*R, total int64) {
db := c.Dao.Ctx(ctx).Model(new(R))
// 1. 构建查询条件
@ -501,8 +501,8 @@ func (c Crud[R]) Paginate(ctx context.Context, where any, p Paginate, with bool,
}
// 3. 关联查询
if with {
db = db.Preload("*")
if with != "" {
db = db.Preload(with)
}
// 4. 排序