作者 郑周

周期下的 模板和规则数据 生成

@@ -30,6 +30,7 @@ func (rs *EvaluationCycleService) Create(in *command.CreateCycleCommand) (interf @@ -30,6 +30,7 @@ func (rs *EvaluationCycleService) Create(in *command.CreateCycleCommand) (interf
30 cycleRepository := factory.CreateEvaluationCycleRepository(map[string]interface{}{"transactionContext": transactionContext}) 30 cycleRepository := factory.CreateEvaluationCycleRepository(map[string]interface{}{"transactionContext": transactionContext})
31 cycleTemplateRepository := factory.CreateEvaluationCycleTemplateRepository(map[string]interface{}{"transactionContext": transactionContext}) 31 cycleTemplateRepository := factory.CreateEvaluationCycleTemplateRepository(map[string]interface{}{"transactionContext": transactionContext})
32 templateRepository := factory.CreateEvaluationTemplateRepository(map[string]interface{}{"transactionContext": transactionContext}) 32 templateRepository := factory.CreateEvaluationTemplateRepository(map[string]interface{}{"transactionContext": transactionContext})
  33 + ruleRepository := factory.CreateEvaluationRuleRepository(map[string]interface{}{"transactionContext": transactionContext})
33 34
34 // 检测名称重复 35 // 检测名称重复
35 count, err := cycleRepository.Count(map[string]interface{}{"name": in.Name, "companyId": in.CompanyId}) 36 count, err := cycleRepository.Count(map[string]interface{}{"name": in.Name, "companyId": in.CompanyId})
@@ -48,6 +49,7 @@ func (rs *EvaluationCycleService) Create(in *command.CreateCycleCommand) (interf @@ -48,6 +49,7 @@ func (rs *EvaluationCycleService) Create(in *command.CreateCycleCommand) (interf
48 return nil, application.ThrowError(application.INTERNAL_SERVER_ERROR, "模板不存在, 请重新选择") 49 return nil, application.ThrowError(application.INTERNAL_SERVER_ERROR, "模板不存在, 请重新选择")
49 } 50 }
50 51
  52 + // 生成新周期数据
51 newCycle := &domain.EvaluationCycle{ 53 newCycle := &domain.EvaluationCycle{
52 Id: 0, 54 Id: 0,
53 Name: in.Name, 55 Name: in.Name,
@@ -62,11 +64,41 @@ func (rs *EvaluationCycleService) Create(in *command.CreateCycleCommand) (interf @@ -62,11 +64,41 @@ func (rs *EvaluationCycleService) Create(in *command.CreateCycleCommand) (interf
62 return nil, application.ThrowError(application.INTERNAL_SERVER_ERROR, err.Error()) 64 return nil, application.ThrowError(application.INTERNAL_SERVER_ERROR, err.Error())
63 } 65 }
64 66
  67 + // 获取所有模板中的规则对象数据
  68 + ruleIds := make([]int64, 0)
  69 + ruleMap := map[int64]*domain.EvaluationRule{}
  70 + for i := range templates {
  71 + v := templates[i]
  72 + for j := range v.LinkNodes {
  73 + node := v.LinkNodes[j]
  74 + for k := range node.NodeContents {
  75 + nodeContent := node.NodeContents[k]
  76 + ruleIds = append(ruleIds, nodeContent.RuleId)
  77 + }
  78 + }
  79 + }
  80 + _, rules, err := ruleRepository.Find(map[string]interface{}{"ids": ruleIds, "companyId": in.CompanyId})
  81 + for i := range rules {
  82 + ruleMap[rules[i].Id] = rules[i]
  83 + }
  84 +
65 ctAdapter := &adapter.CycleTemplateAdapter{} 85 ctAdapter := &adapter.CycleTemplateAdapter{}
66 ctAdapter.EvaluationCycle = cycle 86 ctAdapter.EvaluationCycle = cycle
67 -  
68 for i := range templates { 87 for i := range templates {
69 v := templates[i] 88 v := templates[i]
  89 +
  90 + // 对评估模板中的评估规则进行数据赋值
  91 + for j := range v.LinkNodes {
  92 + node := v.LinkNodes[j]
  93 + for k := range node.NodeContents {
  94 + nodeContent := node.NodeContents[k]
  95 + if rule, ok := ruleMap[nodeContent.RuleId]; ok {
  96 + nodeContent.Rule = rule
  97 + }
  98 + }
  99 + }
  100 +
  101 + // 插入周期中的模板数据
70 cycleTemplate := &domain.EvaluationCycleTemplate{ 102 cycleTemplate := &domain.EvaluationCycleTemplate{
71 Id: 0, 103 Id: 0,
72 Name: v.Name, 104 Name: v.Name,
@@ -78,10 +110,11 @@ func (rs *EvaluationCycleService) Create(in *command.CreateCycleCommand) (interf @@ -78,10 +110,11 @@ func (rs *EvaluationCycleService) Create(in *command.CreateCycleCommand) (interf
78 return nil, application.ThrowError(application.INTERNAL_SERVER_ERROR, err.Error()) 110 return nil, application.ThrowError(application.INTERNAL_SERVER_ERROR, err.Error())
79 } 111 }
80 112
  113 + // 输出模板简单信息
81 ctAdapter.TemplateSimples = append(ctAdapter.TemplateSimples, &domain.TemplateSimple{ 114 ctAdapter.TemplateSimples = append(ctAdapter.TemplateSimples, &domain.TemplateSimple{
82 - Id: v.Id,  
83 - Name: v.Name,  
84 - CreatedAt: v.CreatedAt, 115 + Id: cycleTemplate.Id,
  116 + Name: cycleTemplate.Name,
  117 + CreatedAt: cycleTemplate.CreatedAt,
85 }) 118 })
86 } 119 }
87 120
@@ -33,7 +33,8 @@ type EntryItem struct { @@ -33,7 +33,8 @@ type EntryItem struct {
33 type NodeContent struct { 33 type NodeContent struct {
34 Category string `json:"category" comment:"类别"` 34 Category string `json:"category" comment:"类别"`
35 Name string `json:"name" comment:"名称"` 35 Name string `json:"name" comment:"名称"`
36 - RuleId string `json:"ruleId" comment:"评估规则ID"` 36 + RuleId int64 `json:"ruleId" comment:"评估规则ID"`
  37 + Rule *EvaluationRule `json:"rule" comment:"评估规则对象"`
37 PromptTitle string `json:"promptTitle" comment:"提示项标题"` 38 PromptTitle string `json:"promptTitle" comment:"提示项标题"`
38 PromptText string `json:"promptText" comment:"提示项正文"` 39 PromptText string `json:"promptText" comment:"提示项正文"`
39 EntryItems []*EntryItem `json:"entryItems" comment:"填写项"` 40 EntryItems []*EntryItem `json:"entryItems" comment:"填写项"`
@@ -58,9 +58,14 @@ func (repo *EvaluationCycleTemplateRepository) Insert(d *domain.EvaluationCycleT @@ -58,9 +58,14 @@ func (repo *EvaluationCycleTemplateRepository) Insert(d *domain.EvaluationCycleT
58 d.Id = id 58 d.Id = id
59 d.CreatedAt = time.Now() 59 d.CreatedAt = time.Now()
60 d.UpdatedAt = d.CreatedAt 60 d.UpdatedAt = d.CreatedAt
  61 + // 模板对象ID也更新
  62 + if d.Template != nil {
  63 + d.Template.Id = id
  64 + }
61 } else { 65 } else {
62 d.UpdatedAt = time.Now() 66 d.UpdatedAt = time.Now()
63 } 67 }
  68 +
64 m := repo.TransformToModel(d) 69 m := repo.TransformToModel(d)
65 tx := repo.transactionContext.PgTx 70 tx := repo.transactionContext.PgTx
66 var err error 71 var err error
@@ -123,6 +123,10 @@ func (repo *EvaluationRuleRepository) Find(queryOptions map[string]interface{}) @@ -123,6 +123,10 @@ func (repo *EvaluationRuleRepository) Find(queryOptions map[string]interface{})
123 query.Where("name LIKE ? or remark LIKE ?", v, v) 123 query.Where("name LIKE ? or remark LIKE ?", v, v)
124 } 124 }
125 125
  126 + if v, ok := queryOptions["ids"]; ok {
  127 + query.Where("id in(?)", pg.In(v))
  128 + }
  129 +
126 if v, ok := queryOptions["name"]; ok { 130 if v, ok := queryOptions["name"]; ok {
127 query.Where("name = ?", v) 131 query.Where("name = ?", v)
128 } 132 }