作者 郑周

规则增加 创建人列表

@@ -8,3 +8,8 @@ type RuleAdapter struct { @@ -8,3 +8,8 @@ type RuleAdapter struct {
8 *domain.EvaluationRule 8 *domain.EvaluationRule
9 CreatorName string `json:"creatorName" comment:"创建人名称"` 9 CreatorName string `json:"creatorName" comment:"创建人名称"`
10 } 10 }
  11 +
  12 +type CreatorAdapter struct {
  13 + Id int64 `json:"id,string" comment:"创建人ID"`
  14 + Name string `json:"name" comment:"创建人名称"`
  15 +}
@@ -11,9 +11,20 @@ type QueryRuleCommand struct { @@ -11,9 +11,20 @@ type QueryRuleCommand struct {
11 PageSize int64 `cname:"分页数量" json:"pageSize" valid:"Required"` 11 PageSize int64 `cname:"分页数量" json:"pageSize" valid:"Required"`
12 } 12 }
13 13
  14 +type QueryCreatorCommand struct {
  15 + CompanyId int64 `cname:"公司ID" json:"companyId"`
  16 +}
  17 +
14 func (in *QueryRuleCommand) Valid(validation *validation.Validation) { 18 func (in *QueryRuleCommand) Valid(validation *validation.Validation) {
15 if in.CompanyId == 0 { 19 if in.CompanyId == 0 {
16 validation.SetError("companyId", "公司ID无效") 20 validation.SetError("companyId", "公司ID无效")
17 return 21 return
18 } 22 }
19 } 23 }
  24 +
  25 +func (in *QueryCreatorCommand) Valid(validation *validation.Validation) {
  26 + if in.CompanyId == 0 {
  27 + validation.SetError("companyId", "公司ID无效")
  28 + return
  29 + }
  30 +}
@@ -212,3 +212,40 @@ func (rs *EvaluationRuleService) ListRelCreator(in *command.QueryRuleCommand) (i @@ -212,3 +212,40 @@ func (rs *EvaluationRuleService) ListRelCreator(in *command.QueryRuleCommand) (i
212 } 212 }
213 return tool_funs.SimpleWrapGridMap(total, ras), nil 213 return tool_funs.SimpleWrapGridMap(total, ras), nil
214 } 214 }
  215 +
  216 +func (rs *EvaluationRuleService) ListCreator(in *command.QueryCreatorCommand) (interface{}, error) {
  217 + transactionContext, err := factory.StartTransaction()
  218 + if err != nil {
  219 + return nil, err
  220 + }
  221 + defer func() {
  222 + transactionContext.RollbackTransaction()
  223 + }()
  224 + ruleRepository := factory.CreateEvaluationRuleRepository(map[string]interface{}{"transactionContext": transactionContext})
  225 + userRepository := factory.CreateUserRepository(map[string]interface{}{"transactionContext": transactionContext})
  226 +
  227 + _, rules, err := ruleRepository.Find(tool_funs.SimpleStructToMap(in))
  228 + if err != nil {
  229 + return nil, application.ThrowError(application.INTERNAL_SERVER_ERROR, err.Error())
  230 + }
  231 +
  232 + // 获取所有创建人ID
  233 + creatorMap := map[int64]int64{}
  234 + for i := range rules {
  235 + creatorMap[rules[i].CreatorId] = rules[i].CreatorId
  236 + }
  237 + creatorIds := make([]int64, 0)
  238 + for k := range creatorMap {
  239 + creatorIds = append(creatorIds, k)
  240 + }
  241 + _, users, _ := userRepository.Find(map[string]interface{}{"ids": creatorIds, "limit": len(creatorIds)})
  242 + cas := make([]*adapter.CreatorAdapter, 0)
  243 + for i := range users {
  244 + ca := &adapter.CreatorAdapter{
  245 + Id: users[i].Id,
  246 + Name: users[i].Name,
  247 + }
  248 + cas = append(cas, ca)
  249 + }
  250 + return map[string]interface{}{"list": cas}, nil
  251 +}