package employeecollection import ( "strings" "github.com/break/junhong_cmp_fiber/pkg/constants" "github.com/break/junhong_cmp_fiber/pkg/errors" ) // NormalizePaymentVouchers 校验并规范化支付凭证对象键列表。 // 规则:数量必须在 1 至 5 个之间、每个键去空格后非空且不超过长度上限、不允许重复。 // 只接受对象存储键引用,不接受内联内容,避免敏感付款材料进入业务事实。 func NormalizePaymentVouchers(keys []string) ([]string, error) { if len(keys) < constants.EmployeeCollectionVoucherMinCount || len(keys) > constants.EmployeeCollectionVoucherMaxCount { return nil, errors.New(errors.CodeEmployeeCollectionVoucherInvalid) } normalized := make([]string, 0, len(keys)) seen := make(map[string]struct{}, len(keys)) for _, key := range keys { trimmed := strings.TrimSpace(key) if trimmed == "" { return nil, errors.New(errors.CodeEmployeeCollectionVoucherInvalid) } if len([]rune(trimmed)) > constants.EmployeeCollectionVoucherKeyMaxLength { return nil, errors.New(errors.CodeEmployeeCollectionVoucherInvalid) } if _, exists := seen[trimmed]; exists { return nil, errors.New(errors.CodeEmployeeCollectionVoucherInvalid) } seen[trimmed] = struct{}{} normalized = append(normalized, trimmed) } return normalized, nil }