作者 tangxvhui
... ... @@ -173,6 +173,19 @@ func (rs *EvaluationRuleService) ListRelCreator(in *command.QueryRuleCommand) (i
ruleRepository := factory.CreateEvaluationRuleRepository(map[string]interface{}{"transactionContext": transactionContext})
userRepository := factory.CreateUserRepository(map[string]interface{}{"transactionContext": transactionContext})
// 查询系统默认规则
_, sysRules, err := ruleRepository.Find(map[string]interface{}{"companyId": in.CompanyId, "sysType": domain.EvaluationSysTypeSystem, "limit": 1})
if err != nil {
return nil, application.ThrowError(application.INTERNAL_SERVER_ERROR, err.Error())
}
// 不存在,生成默认规则
if len(sysRules) == 0 {
newRule := domain.GenerateSysRule(in.CompanyId)
if _, err := ruleRepository.Insert(newRule); err != nil {
return nil, application.ThrowError(application.INTERNAL_SERVER_ERROR, err.Error())
}
}
total, rules, err := ruleRepository.Find(tool_funs.SimpleStructToMap(in))
if err != nil {
return nil, application.ThrowError(application.INTERNAL_SERVER_ERROR, err.Error())
... ... @@ -180,31 +193,11 @@ func (rs *EvaluationRuleService) ListRelCreator(in *command.QueryRuleCommand) (i
ras := make([]*adapter.RuleAdapter, 0)
creatorIds := make([]int64, 0)
var havaSystemType = false
for i := range rules {
ra := &adapter.RuleAdapter{}
ra.EvaluationRule = rules[i]
ras = append(ras, ra)
creatorIds = append(creatorIds, rules[i].CreatorId)
if rules[i].SysType == domain.EvaluationSysTypeSystem {
havaSystemType = true
break
}
}
// 如果不存在系统默认就生成一个
if !havaSystemType {
newRule := domain.GenerateSysRule(in.CompanyId)
rule, err := ruleRepository.Insert(newRule)
if err != nil {
return nil, application.ThrowError(application.INTERNAL_SERVER_ERROR, err.Error())
}
ra := &adapter.RuleAdapter{}
ra.EvaluationRule = rule
ras = append(ras, ra)
total += 1
}
_, users, _ := userRepository.Find(map[string]interface{}{"ids": creatorIds, "limit": len(creatorIds)})
... ... @@ -218,7 +211,6 @@ func (rs *EvaluationRuleService) ListRelCreator(in *command.QueryRuleCommand) (i
if v, ok := userNameMap[ras[i].CreatorId]; ok {
ras[i].CreatorName = v
}
}
if err := transactionContext.CommitTransaction(); err != nil {
... ...