feat(附件签章): 修复附件标识与签章定位
build.yaml / build (push) Successful in 48s

This commit is contained in:
xiaoqidun committed 2026-10-10 17:03:06 +08:00
1 parent 07eb44c037
commit 341ad7cd7e
4 files changed
+72 -27

No files matched your search

+24 -2
View File
@@ -52,7 +52,15 @@ func (e *Editor) AddAttachment(name string, data []byte) (string, error) {
return "", err
}
}
id := strconv.Itoa(maximum + 1)
attachments, err := base.reader.Attachments()
if err != nil {
return "", err
}
used := make(map[string]bool, len(attachments))
for _, attachment := range attachments {
used[attachment.ID] = true
}
id, maximum := nextAttachmentID(used, maximum)
file := e.packageName("Attachments/Attachment_" + id)
attrs := ofdAttrs{}
attrs.add("ID", id)
@@ -121,10 +129,24 @@ func (e *Editor) AddAttachment(name string, data []byte) (string, error) {
if err := e.commitAnnotationParts(base, parts); err != nil {
return "", err
}
e.maxID, e.source.idsReady = maximum+1, true
e.maxID, e.source.idsReady = maximum, true
return id, nil
}
// nextAttachmentID 分配以字母开头且不与已有附件重复的标识
// 入参: used 已用附件标识, maximum 当前编号上限
// 返回: string 附件标识, int 更新后的编号上限
func nextAttachmentID(used map[string]bool, maximum int) (string, int) {
for {
maximum++
id := "a" + strconv.Itoa(maximum)
if !used[id] {
used[id] = true
return id, maximum
}
}
}
// RenameAttachment 修改附件显示名称,保留格式、内容及扩展字段,相同名称不产生撤销记录
// 入参: id 附件标识, name 显示名称
// 返回: error 名称或附件结构错误