Updated approval topic code generation
This commit is contained in:
parent
aa37e330ef
commit
f730e6841e
|
|
@ -130,9 +130,6 @@ func (d *DynamicTopic) BuildTree() *FlowNode {
|
|||
return root
|
||||
}
|
||||
|
||||
// TopicCodeFromCollected: если задан codeTemplate на корневом узле дерева
|
||||
// категории — используем его; иначе прежняя дефолтная генерация кода
|
||||
// (актуально для delivery_clients и goods_order, где дефолт и так совпадает).
|
||||
func (d *DynamicTopic) TopicCodeFromCollected(collected map[string]string) (string, error) {
|
||||
baseCode := d.Code()
|
||||
|
||||
|
|
@ -187,19 +184,28 @@ func createTemplateFuncMap() template.FuncMap {
|
|||
|
||||
func (d *DynamicTopic) applyCodeTemplate(tmpl string, data map[string]string) (string, error) {
|
||||
logrus.Printf("🔍 DEBUG applyCodeTemplate: шаблон = %q", tmpl)
|
||||
t, err := template.New("code").Funcs(createTemplateFuncMap()).Parse(tmpl)
|
||||
|
||||
t, err := template.New("code").Option("missingkey=zero").Funcs(createTemplateFuncMap()).Parse(tmpl)
|
||||
if err != nil {
|
||||
return "", fmt.Errorf("parse code template: %w", err)
|
||||
}
|
||||
|
||||
// Шаблон кода работает с map[string]string напрямую (а не interface{}),
|
||||
// т.к. использует только .field и eq/ne без доп. переменных.
|
||||
var buf bytes.Buffer
|
||||
if err := t.Execute(&buf, data); err != nil {
|
||||
return "", fmt.Errorf("execute code template: %w", err)
|
||||
}
|
||||
|
||||
return strings.TrimSpace(buf.String()), nil
|
||||
result := buf.String()
|
||||
|
||||
result = strings.ReplaceAll(result, "<no value>", "")
|
||||
|
||||
for strings.Contains(result, "__") {
|
||||
result = strings.ReplaceAll(result, "__", "_")
|
||||
}
|
||||
|
||||
result = strings.TrimSuffix(result, "_")
|
||||
|
||||
return strings.TrimSpace(result), nil
|
||||
}
|
||||
|
||||
func (d *DynamicTopic) applyMessageTemplate(tmpl, initiatorName string, data map[string]string) string {
|
||||
|
|
|
|||
Loading…
Reference in New Issue