[feat] 完善 NewVirtualResource 方法

This commit is contained in:
what 2024-11-25 15:28:19 +08:00
parent 6675dca359
commit a911a305e1

View File

@ -440,17 +440,25 @@ func (this Resource) onUserEvent(builder *db.Builder, user req.User) {
} }
func NewVirtualResource(pRes req.Resource, code, name, sql string, fields []ResField) req.Resource { func NewVirtualResource(pRes req.Resource, code, name, sql string, fields []ResField) req.Resource {
fieldsCopy := make([]ResField, len(fields))
copy(fieldsCopy, fields)
for i := 0; i < len(fieldsCopy); i++ {
fieldsCopy[i].CodeResource = code
}
return &Resource{ return &Resource{
Uuid: code, Uuid: code,
PUuid: pRes.GetUuid(), PUuid: pRes.GetUuid(),
Code: code, Code: code,
Name: name, Name: name,
IsResVirtual: true, IsResVirtual: true,
Table: sql,
IsResSystem: pRes.IsSystem(), IsResSystem: pRes.IsSystem(),
Table: sql,
IsHistoryRecord: false, IsHistoryRecord: false,
HistoryCacheMax: 0, HistoryCacheMax: 0,
Fields: fields, Fields: fieldsCopy,
Roles: nil, Roles: nil,
} }
} }