作者 郑周

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

... ... @@ -30,6 +30,7 @@ func (rs *EvaluationCycleService) Create(in *command.CreateCycleCommand) (interf
cycleRepository := factory.CreateEvaluationCycleRepository(map[string]interface{}{"transactionContext": transactionContext})
cycleTemplateRepository := factory.CreateEvaluationCycleTemplateRepository(map[string]interface{}{"transactionContext": transactionContext})
templateRepository := factory.CreateEvaluationTemplateRepository(map[string]interface{}{"transactionContext": transactionContext})
ruleRepository := factory.CreateEvaluationRuleRepository(map[string]interface{}{"transactionContext": transactionContext})
// 检测名称重复
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
return nil, application.ThrowError(application.INTERNAL_SERVER_ERROR, "模板不存在, 请重新选择")
}
// 生成新周期数据
newCycle := &domain.EvaluationCycle{
Id: 0,
Name: in.Name,
... ... @@ -62,11 +64,41 @@ func (rs *EvaluationCycleService) Create(in *command.CreateCycleCommand) (interf
return nil, application.ThrowError(application.INTERNAL_SERVER_ERROR, err.Error())
}
// 获取所有模板中的规则对象数据
ruleIds := make([]int64, 0)
ruleMap := map[int64]*domain.EvaluationRule{}
for i := range templates {
v := templates[i]
for j := range v.LinkNodes {
node := v.LinkNodes[j]
for k := range node.NodeContents {
nodeContent := node.NodeContents[k]
ruleIds = append(ruleIds, nodeContent.RuleId)
}
}
}
_, rules, err := ruleRepository.Find(map[string]interface{}{"ids": ruleIds, "companyId": in.CompanyId})
for i := range rules {
ruleMap[rules[i].Id] = rules[i]
}
ctAdapter := &adapter.CycleTemplateAdapter{}
ctAdapter.EvaluationCycle = cycle
for i := range templates {
v := templates[i]
// 对评估模板中的评估规则进行数据赋值
for j := range v.LinkNodes {
node := v.LinkNodes[j]
for k := range node.NodeContents {
nodeContent := node.NodeContents[k]
if rule, ok := ruleMap[nodeContent.RuleId]; ok {
nodeContent.Rule = rule
}
}
}
// 插入周期中的模板数据
cycleTemplate := &domain.EvaluationCycleTemplate{
Id: 0,
Name: v.Name,
... ... @@ -78,10 +110,11 @@ func (rs *EvaluationCycleService) Create(in *command.CreateCycleCommand) (interf
return nil, application.ThrowError(application.INTERNAL_SERVER_ERROR, err.Error())
}
// 输出模板简单信息
ctAdapter.TemplateSimples = append(ctAdapter.TemplateSimples, &domain.TemplateSimple{
Id: v.Id,
Name: v.Name,
CreatedAt: v.CreatedAt,
Id: cycleTemplate.Id,
Name: cycleTemplate.Name,
CreatedAt: cycleTemplate.CreatedAt,
})
}
... ...
... ... @@ -31,12 +31,13 @@ type EntryItem struct {
// NodeContent 评估内容
type NodeContent struct {
Category string `json:"category" comment:"类别"`
Name string `json:"name" comment:"名称"`
RuleId string `json:"ruleId" comment:"评估规则ID"`
PromptTitle string `json:"promptTitle" comment:"提示项标题"`
PromptText string `json:"promptText" comment:"提示项正文"`
EntryItems []*EntryItem `json:"entryItems" comment:"填写项"`
Category string `json:"category" comment:"类别"`
Name string `json:"name" comment:"名称"`
RuleId int64 `json:"ruleId" comment:"评估规则ID"`
Rule *EvaluationRule `json:"rule" comment:"评估规则对象"`
PromptTitle string `json:"promptTitle" comment:"提示项标题"`
PromptText string `json:"promptText" comment:"提示项正文"`
EntryItems []*EntryItem `json:"entryItems" comment:"填写项"`
}
//// NodeAllInvite 360°邀请
... ...
... ... @@ -58,9 +58,14 @@ func (repo *EvaluationCycleTemplateRepository) Insert(d *domain.EvaluationCycleT
d.Id = id
d.CreatedAt = time.Now()
d.UpdatedAt = d.CreatedAt
// 模板对象ID也更新
if d.Template != nil {
d.Template.Id = id
}
} else {
d.UpdatedAt = time.Now()
}
m := repo.TransformToModel(d)
tx := repo.transactionContext.PgTx
var err error
... ...
... ... @@ -123,6 +123,10 @@ func (repo *EvaluationRuleRepository) Find(queryOptions map[string]interface{})
query.Where("name LIKE ? or remark LIKE ?", v, v)
}
if v, ok := queryOptions["ids"]; ok {
query.Where("id in(?)", pg.In(v))
}
if v, ok := queryOptions["name"]; ok {
query.Where("name = ?", v)
}
... ...