This commit is contained in:
Daniel 2025-07-27 19:34:17 +08:00
parent ff539bab03
commit d0662b5fde
No known key found for this signature in database
GPG key ID: 86211BA83DF03017
2 changed files with 19 additions and 13 deletions

View file

@ -220,6 +220,21 @@ func (view *View) GetGroup(groupID string) *View {
return nil
}
// GetGroupKey 获取分组视图的分组字段。
func (view *View) GetGroupKey(attrView *AttributeView) (ret *Key) {
if nil == view.Group || "" == view.Group.Field {
return
}
for _, kv := range attrView.KeyValues {
if kv.Key.ID == view.Group.Field {
ret = kv.Key
return
}
}
return
}
// GroupCalc 描述了分组计算规则和结果的结构。
type GroupCalc struct {
Field string `json:"field"` // 字段 ID

View file

@ -3063,7 +3063,7 @@ func addAttributeViewBlock(now int64, avID, blockID, groupID, previousBlockID, a
}
// 如果存在分组条件,则将分组条件应用到新添加的块上
groupKey := getViewGroupKey(view, attrView)
groupKey := view.GetGroupKey(attrView)
if nil != view && nil != groupKey {
if !filterKeyIDs[groupKey.ID] /* 过滤条件应用过的话就不重复处理了 */ && "" != groupID {
if groupView := view.GetGroup(groupID); nil != groupView {
@ -3868,6 +3868,7 @@ func updateAttributeViewColTemplate(operation *Operation) (err error) {
}
}
regenAttrViewViewGroups(attrView, operation.ID)
err = av.SaveAttributeView(attrView)
return
}
@ -4524,7 +4525,7 @@ func updateAttributeViewValue(tx *Transaction, attrView *av.AttributeView, keyID
func regenAttrViewViewGroups(attrView *av.AttributeView, keyID string) {
for _, view := range attrView.Views {
groupKey := getViewGroupKey(view, attrView)
groupKey := view.GetGroupKey(attrView)
if nil == groupKey {
continue
}
@ -4549,17 +4550,6 @@ func regenAttrViewViewGroups(attrView *av.AttributeView, keyID string) {
}
}
func getViewGroupKey(view *av.View, attrView *av.AttributeView) *av.Key {
if nil == view.Group {
return nil
}
if "" == view.Group.Field {
return nil
}
ret, _ := attrView.GetKey(view.Group.Field)
return ret
}
func unbindBlockAv(tx *Transaction, avID, blockID string) {
node, tree, err := getNodeByBlockID(tx, blockID)
if err != nil {
@ -4753,6 +4743,7 @@ func removeAttributeViewColumnOption(operation *Operation) (err error) {
break
}
regenAttrViewViewGroups(attrView, operation.ID)
err = av.SaveAttributeView(attrView)
return
}