作者 郑周

规则增加 创建人列表

... ... @@ -8,3 +8,8 @@ type RuleAdapter struct {
*domain.EvaluationRule
CreatorName string `json:"creatorName" comment:"创建人名称"`
}
type CreatorAdapter struct {
Id int64 `json:"id,string" comment:"创建人ID"`
Name string `json:"name" comment:"创建人名称"`
}
... ...
... ... @@ -11,9 +11,20 @@ type QueryRuleCommand struct {
PageSize int64 `cname:"分页数量" json:"pageSize" valid:"Required"`
}
type QueryCreatorCommand struct {
CompanyId int64 `cname:"公司ID" json:"companyId"`
}
func (in *QueryRuleCommand) Valid(validation *validation.Validation) {
if in.CompanyId == 0 {
validation.SetError("companyId", "公司ID无效")
return
}
}
func (in *QueryCreatorCommand) Valid(validation *validation.Validation) {
if in.CompanyId == 0 {
validation.SetError("companyId", "公司ID无效")
return
}
}
... ...
... ... @@ -212,3 +212,40 @@ func (rs *EvaluationRuleService) ListRelCreator(in *command.QueryRuleCommand) (i
}
return tool_funs.SimpleWrapGridMap(total, ras), nil
}
func (rs *EvaluationRuleService) ListCreator(in *command.QueryCreatorCommand) (interface{}, error) {
transactionContext, err := factory.StartTransaction()
if err != nil {
return nil, err
}
defer func() {
transactionContext.RollbackTransaction()
}()
ruleRepository := factory.CreateEvaluationRuleRepository(map[string]interface{}{"transactionContext": transactionContext})
userRepository := factory.CreateUserRepository(map[string]interface{}{"transactionContext": transactionContext})
_, rules, err := ruleRepository.Find(tool_funs.SimpleStructToMap(in))
if err != nil {
return nil, application.ThrowError(application.INTERNAL_SERVER_ERROR, err.Error())
}
// 获取所有创建人ID
creatorMap := map[int64]int64{}
for i := range rules {
creatorMap[rules[i].CreatorId] = rules[i].CreatorId
}
creatorIds := make([]int64, 0)
for k := range creatorMap {
creatorIds = append(creatorIds, k)
}
_, users, _ := userRepository.Find(map[string]interface{}{"ids": creatorIds, "limit": len(creatorIds)})
cas := make([]*adapter.CreatorAdapter, 0)
for i := range users {
ca := &adapter.CreatorAdapter{
Id: users[i].Id,
Name: users[i].Name,
}
cas = append(cas, ca)
}
return map[string]interface{}{"list": cas}, nil
}
... ...