KTD1 fourth step: - squad.Options.TaskPreparer + TaskPreparation (Attachment + Backfills + MirrorTemplateToOutput); squad stays sole writer of its workspace files - CDO quote calc/xlsx/backfill implementation moves to bizdev (quote_preparer.go); squad/quote_backfill.go relocated to bizdev - arch path rule enforced the boundary: bizdev may not name/write output.md; mirroring decided squad-side via flag - squad -> quote import eliminated; engine.go delegations now local - verified: build/vet/arch green, squad+bizdev short tests pass
75 lines
2.3 KiB
Go
75 lines
2.3 KiB
Go
package bizdev
|
|
|
|
import (
|
|
"os"
|
|
"path/filepath"
|
|
|
|
"chat-agent-system/internal/quote"
|
|
"chat-agent-system/internal/squad"
|
|
"chat-agent-system/internal/workflowdef"
|
|
)
|
|
|
|
// handleCDOQuotePreparation 为 CDO 报价任务执行 Excel 核算并生成回填内容
|
|
// (KTD1:报价领域规则、核算与 xlsx 资产归 Core;只计算,不写 squad 工作区,
|
|
// 文件由 squad 经 TaskPreparation.Backfills 统一写入)。
|
|
func (s *Service) handleCDOQuotePreparation(workDir string, req squad.SquadRunRequest) (*squad.TaskPreparation, error) {
|
|
in := quote.Input{
|
|
CustomerName: req.CustomerName,
|
|
ProductName: req.ProjectName,
|
|
Hours: map[string]float64{
|
|
"结构工程师": 320,
|
|
"硬件工程师": 320,
|
|
"软件工程师": 480,
|
|
"项目经理": 160,
|
|
},
|
|
}
|
|
// 核算写入临时文件后读回字节;工作区文件由 squad 写入。
|
|
tmp, err := os.CreateTemp("", "cdo-quote-*.xlsx")
|
|
if err != nil {
|
|
return nil, err
|
|
}
|
|
tmpPath := tmp.Name()
|
|
tmp.Close()
|
|
defer os.Remove(tmpPath)
|
|
|
|
summary, err := quote.CalculateAndFill(in, "templates/xlsx/cdo_quote.xlsx", tmpPath)
|
|
if err != nil {
|
|
return nil, err
|
|
}
|
|
data, err := os.ReadFile(tmpPath)
|
|
if err != nil {
|
|
return nil, err
|
|
}
|
|
|
|
backfills := map[string][]byte{
|
|
"CDO报价核算-V01.xlsx": data,
|
|
"artifacts/CDO报价核算-V01.xlsx": data,
|
|
}
|
|
// 回填 template.md 报价占位(模板存在时);output.md 镜像由 squad 决定
|
|
tmplBytes, tmplErr := os.ReadFile(filepath.Join(workDir, "template.md"))
|
|
mirror := false
|
|
if tmplErr == nil {
|
|
filled := BackfillCDOQuoteMarkdown(string(tmplBytes), summary)
|
|
backfills["template.md"] = []byte(filled)
|
|
mirror = true
|
|
}
|
|
|
|
return &squad.TaskPreparation{
|
|
Attachment: &squad.Attachment{
|
|
Filename: "CDO报价核算-V01.xlsx",
|
|
ContentType: "application/vnd.openxmlformats-officedocument.spreadsheetml.sheet",
|
|
Data: data,
|
|
},
|
|
Backfills: backfills,
|
|
MirrorTemplateToOutput: mirror,
|
|
}, nil
|
|
}
|
|
|
|
// squadTaskPreparer 仅对 CDO 报价任务触发领域准备,其余任务快速跳过。
|
|
func (s *Service) squadTaskPreparer(workDir string, req squad.SquadRunRequest) (*squad.TaskPreparation, error) {
|
|
if !workflowdef.SameTaskKey(req.TaskKey, "cdo_quote") {
|
|
return nil, nil
|
|
}
|
|
return s.handleCDOQuotePreparation(workDir, req)
|
|
}
|