作者 庄敏学
... ... @@ -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
}
... ...
... ... @@ -85,7 +85,19 @@ func (controller *RuleController) ListRuleRelCreator() {
}
ua := middlewares.GetUser(controller.Ctx)
in.CompanyId = ua.CompanyId
//in.CompanyId = middlewares.GetCompanyId(controller.Ctx)
controller.Response(ruService.ListRelCreator(in))
}
}
func (controller *RuleController) ListCreator() {
ruService := service.NewEvaluationRuleService()
in := &command.QueryCreatorCommand{}
if err := controller.Unmarshal(in); err != nil {
controller.Response(nil, application.ThrowError(application.ARG_ERROR, err.Error()))
} else {
ua := middlewares.GetUser(controller.Ctx)
in.CompanyId = ua.CompanyId
controller.Response(ruService.ListCreator(in))
}
}
... ...
... ... @@ -111,8 +111,6 @@ func (controller *TemplateController) CopyTemplate() {
ua := middlewares.GetUser(controller.Ctx)
in.CompanyId = ua.CompanyId
in.CreatorId = ua.UserId
//in.CompanyId = middlewares.GetCompanyId(controller.Ctx)
//in.CreatorId = middlewares.GetUserId(controller.Ctx)
controller.Response(ruService.Copy(in))
}
}
... ...
... ... @@ -15,6 +15,7 @@ func init() {
web.NSRouter("/", &controllers.RuleController{}, "Delete:RemoveRule"),
web.NSRouter("/:Id", &controllers.RuleController{}, "Get:GetRule"),
web.NSRouter("/list", &controllers.RuleController{}, "Post:ListRuleRelCreator"),
web.NSRouter("/list-creator", &controllers.RuleController{}, "Post:ListCreator"),
)
web.AddNamespace(ns)
}
... ...
... ... @@ -16,6 +16,7 @@ func init() {
web.NSRouter("/:Id", &controllers.TemplateController{}, "Get:GetTemplate"),
web.NSRouter("/list", &controllers.TemplateController{}, "Post:ListTemplate"),
web.NSRouter("/list-enable", &controllers.TemplateController{}, "Post:ListEnableTemplate"),
web.NSRouter("/copy", &controllers.TemplateController{}, "Post:CopyTemplate"),
)
web.AddNamespace(ns)
}
... ...