作者 郑周

评估规则 优化

角色 优化
@@ -157,22 +157,22 @@ func (rs *EvaluationRuleService) Remove(in *command.DeleteRuleCommand) (interfac @@ -157,22 +157,22 @@ func (rs *EvaluationRuleService) Remove(in *command.DeleteRuleCommand) (interfac
157 return rule, nil 157 return rule, nil
158 } 158 }
159 159
160 -func (rs *EvaluationRuleService) List(in *command.QueryRuleCommand) (interface{}, error) {  
161 - transactionContext, err := factory.StartTransaction()  
162 - if err != nil {  
163 - return nil, err  
164 - }  
165 - defer func() {  
166 - transactionContext.RollbackTransaction()  
167 - }()  
168 - ruleRepository := factory.CreateEvaluationRuleRepository(map[string]interface{}{"transactionContext": transactionContext})  
169 -  
170 - total, rules, err := ruleRepository.Find(tool_funs.SimpleStructToMap(in))  
171 - if err != nil {  
172 - return nil, application.ThrowError(application.INTERNAL_SERVER_ERROR, err.Error())  
173 - }  
174 - return tool_funs.SimpleWrapGridMap(total, rules), nil  
175 -} 160 +//func (rs *EvaluationRuleService) List(in *command.QueryRuleCommand) (interface{}, error) {
  161 +// transactionContext, err := factory.StartTransaction()
  162 +// if err != nil {
  163 +// return nil, err
  164 +// }
  165 +// defer func() {
  166 +// transactionContext.RollbackTransaction()
  167 +// }()
  168 +// ruleRepository := factory.CreateEvaluationRuleRepository(map[string]interface{}{"transactionContext": transactionContext})
  169 +//
  170 +// total, rules, err := ruleRepository.Find(tool_funs.SimpleStructToMap(in))
  171 +// if err != nil {
  172 +// return nil, application.ThrowError(application.INTERNAL_SERVER_ERROR, err.Error())
  173 +// }
  174 +// return tool_funs.SimpleWrapGridMap(total, rules), nil
  175 +//}
176 176
177 func (rs *EvaluationRuleService) ListRelCreator(in *command.QueryRuleCommand) (interface{}, error) { 177 func (rs *EvaluationRuleService) ListRelCreator(in *command.QueryRuleCommand) (interface{}, error) {
178 transactionContext, err := factory.StartTransaction() 178 transactionContext, err := factory.StartTransaction()
@@ -6,7 +6,6 @@ import ( @@ -6,7 +6,6 @@ import (
6 "gitlab.fjmaimaimai.com/allied-creation/performance/pkg/application/factory" 6 "gitlab.fjmaimaimai.com/allied-creation/performance/pkg/application/factory"
7 "gitlab.fjmaimaimai.com/allied-creation/performance/pkg/application/role/adapter" 7 "gitlab.fjmaimaimai.com/allied-creation/performance/pkg/application/role/adapter"
8 "gitlab.fjmaimaimai.com/allied-creation/performance/pkg/application/role/command" 8 "gitlab.fjmaimaimai.com/allied-creation/performance/pkg/application/role/command"
9 - "gitlab.fjmaimaimai.com/allied-creation/performance/pkg/domain"  
10 ) 9 )
11 10
12 type RoleService struct { 11 type RoleService struct {
@@ -17,122 +16,122 @@ func NewRoleService() *RoleService { @@ -17,122 +16,122 @@ func NewRoleService() *RoleService {
17 return newRoleService 16 return newRoleService
18 } 17 }
19 18
20 -// Create 创建  
21 -func (rs *RoleService) Create(in *command.CreateRoleCommand) (interface{}, error) {  
22 - transactionContext, err := factory.ValidateStartTransaction(in)  
23 - if err != nil {  
24 - return nil, err  
25 - }  
26 - defer func() {  
27 - transactionContext.RollbackTransaction()  
28 - }()  
29 - roleRepository := factory.CreateRoleRepository(map[string]interface{}{"transactionContext": transactionContext})  
30 -  
31 - // 检测名称重复  
32 - count, err := roleRepository.Count(map[string]interface{}{"name": in.Name, "companyId": in.CompanyId})  
33 - if err != nil {  
34 - return nil, application.ThrowError(application.INTERNAL_SERVER_ERROR, err.Error())  
35 - }  
36 - if count > 0 {  
37 - return nil, application.ThrowError(application.BUSINESS_ERROR, "角色名称已存在")  
38 - }  
39 - newRole := &domain.Role{  
40 - Id: 0,  
41 - Name: in.Name,  
42 - Type: domain.RoleTypeCommon,  
43 - Description: in.Description,  
44 - CompanyId: in.CompanyId,  
45 - }  
46 - role, err := roleRepository.Insert(newRole)  
47 - if err != nil {  
48 - return nil, application.ThrowError(application.INTERNAL_SERVER_ERROR, err.Error())  
49 - }  
50 - if err := transactionContext.CommitTransaction(); err != nil {  
51 - return nil, application.ThrowError(application.TRANSACTION_ERROR, err.Error())  
52 - }  
53 - return role, nil  
54 -  
55 -}  
56 -  
57 -func (rs *RoleService) Update(in *command.UpdateRoleCommand) (interface{}, error) {  
58 - transactionContext, err := factory.ValidateStartTransaction(in)  
59 - if err != nil {  
60 - return nil, err  
61 - }  
62 - defer func() {  
63 - transactionContext.RollbackTransaction()  
64 - }()  
65 -  
66 - roleRepository := factory.CreateRoleRepository(map[string]interface{}{"transactionContext": transactionContext})  
67 -  
68 - // 检测名称重复(排除自己)  
69 - count, err := roleRepository.Count(map[string]interface{}{"name": in.Name, "companyId": in.CompanyId, "notId": in.Id})  
70 - if err != nil {  
71 - return nil, application.ThrowError(application.INTERNAL_SERVER_ERROR, err.Error())  
72 - }  
73 - if count > 0 {  
74 - return nil, application.ThrowError(application.BUSINESS_ERROR, "角色名称已存在")  
75 - }  
76 -  
77 - role, err := roleRepository.FindOne(map[string]interface{}{"id": in.Id})  
78 - if err != nil {  
79 - return nil, application.ThrowError(application.INTERNAL_SERVER_ERROR, err.Error())  
80 - }  
81 -  
82 - role.Name = in.Name  
83 - role.Description = in.Description  
84 -  
85 - role, err = roleRepository.Insert(role)  
86 - if err != nil {  
87 - return nil, application.ThrowError(application.INTERNAL_SERVER_ERROR, err.Error())  
88 - }  
89 - if err := transactionContext.CommitTransaction(); err != nil {  
90 - return nil, application.ThrowError(application.TRANSACTION_ERROR, err.Error())  
91 - }  
92 - return role, nil  
93 -}  
94 -  
95 -func (rs *RoleService) Remove(in *command.DeleteRoleCommand) (interface{}, error) {  
96 - transactionContext, err := factory.ValidateStartTransaction(in)  
97 - if err != nil {  
98 - return nil, err  
99 - }  
100 - defer func() {  
101 - transactionContext.RollbackTransaction()  
102 - }()  
103 -  
104 - roleRepository := factory.CreateRoleRepository(map[string]interface{}{"transactionContext": transactionContext})  
105 - roleUserRepository := factory.CreateRoleUserRepository(map[string]interface{}{"transactionContext": transactionContext})  
106 -  
107 - role, err := roleRepository.FindOne(map[string]interface{}{"id": in.Id})  
108 - if err != nil {  
109 - return nil, application.ThrowError(application.INTERNAL_SERVER_ERROR, err.Error())  
110 - }  
111 - if _, err := roleRepository.Remove(role); err != nil {  
112 - return nil, application.ThrowError(application.INTERNAL_SERVER_ERROR, err.Error())  
113 - }  
114 -  
115 - // 获取角色所有关联的用户,并删除  
116 - _, roleUsers, err := roleUserRepository.Find(map[string]interface{}{"roleId": in.Id, "companyId": in.CompanyId})  
117 - if err != nil {  
118 - return nil, application.ThrowError(application.INTERNAL_SERVER_ERROR, err.Error())  
119 - }  
120 - ids := make([]int64, 0)  
121 - for i := range roleUsers {  
122 - ids = append(ids, roleUsers[i].Id)  
123 - }  
124 - if len(ids) > 0 {  
125 - err := roleUserRepository.BatchDeleteById(ids)  
126 - if err != nil {  
127 - return nil, application.ThrowError(application.INTERNAL_SERVER_ERROR, err.Error())  
128 - }  
129 - }  
130 -  
131 - if err := transactionContext.CommitTransaction(); err != nil {  
132 - return nil, application.ThrowError(application.TRANSACTION_ERROR, err.Error())  
133 - }  
134 - return role, nil  
135 -} 19 +//// Create 创建
  20 +//func (rs *RoleService) Create(in *command.CreateRoleCommand) (interface{}, error) {
  21 +// transactionContext, err := factory.ValidateStartTransaction(in)
  22 +// if err != nil {
  23 +// return nil, err
  24 +// }
  25 +// defer func() {
  26 +// transactionContext.RollbackTransaction()
  27 +// }()
  28 +// roleRepository := factory.CreateRoleRepository(map[string]interface{}{"transactionContext": transactionContext})
  29 +//
  30 +// // 检测名称重复
  31 +// count, err := roleRepository.Count(map[string]interface{}{"name": in.Name, "companyId": in.CompanyId})
  32 +// if err != nil {
  33 +// return nil, application.ThrowError(application.INTERNAL_SERVER_ERROR, err.Error())
  34 +// }
  35 +// if count > 0 {
  36 +// return nil, application.ThrowError(application.BUSINESS_ERROR, "角色名称已存在")
  37 +// }
  38 +// newRole := &domain.Role{
  39 +// Id: 0,
  40 +// Name: in.Name,
  41 +// Type: domain.RoleTypeCommon,
  42 +// Description: in.Description,
  43 +// CompanyId: in.CompanyId,
  44 +// }
  45 +// role, err := roleRepository.Insert(newRole)
  46 +// if err != nil {
  47 +// return nil, application.ThrowError(application.INTERNAL_SERVER_ERROR, err.Error())
  48 +// }
  49 +// if err := transactionContext.CommitTransaction(); err != nil {
  50 +// return nil, application.ThrowError(application.TRANSACTION_ERROR, err.Error())
  51 +// }
  52 +// return role, nil
  53 +//
  54 +//}
  55 +//
  56 +//func (rs *RoleService) Update(in *command.UpdateRoleCommand) (interface{}, error) {
  57 +// transactionContext, err := factory.ValidateStartTransaction(in)
  58 +// if err != nil {
  59 +// return nil, err
  60 +// }
  61 +// defer func() {
  62 +// transactionContext.RollbackTransaction()
  63 +// }()
  64 +//
  65 +// roleRepository := factory.CreateRoleRepository(map[string]interface{}{"transactionContext": transactionContext})
  66 +//
  67 +// // 检测名称重复(排除自己)
  68 +// count, err := roleRepository.Count(map[string]interface{}{"name": in.Name, "companyId": in.CompanyId, "notId": in.Id})
  69 +// if err != nil {
  70 +// return nil, application.ThrowError(application.INTERNAL_SERVER_ERROR, err.Error())
  71 +// }
  72 +// if count > 0 {
  73 +// return nil, application.ThrowError(application.BUSINESS_ERROR, "角色名称已存在")
  74 +// }
  75 +//
  76 +// role, err := roleRepository.FindOne(map[string]interface{}{"id": in.Id})
  77 +// if err != nil {
  78 +// return nil, application.ThrowError(application.INTERNAL_SERVER_ERROR, err.Error())
  79 +// }
  80 +//
  81 +// role.Name = in.Name
  82 +// role.Description = in.Description
  83 +//
  84 +// role, err = roleRepository.Insert(role)
  85 +// if err != nil {
  86 +// return nil, application.ThrowError(application.INTERNAL_SERVER_ERROR, err.Error())
  87 +// }
  88 +// if err := transactionContext.CommitTransaction(); err != nil {
  89 +// return nil, application.ThrowError(application.TRANSACTION_ERROR, err.Error())
  90 +// }
  91 +// return role, nil
  92 +//}
  93 +//
  94 +//func (rs *RoleService) Remove(in *command.DeleteRoleCommand) (interface{}, error) {
  95 +// transactionContext, err := factory.ValidateStartTransaction(in)
  96 +// if err != nil {
  97 +// return nil, err
  98 +// }
  99 +// defer func() {
  100 +// transactionContext.RollbackTransaction()
  101 +// }()
  102 +//
  103 +// roleRepository := factory.CreateRoleRepository(map[string]interface{}{"transactionContext": transactionContext})
  104 +// roleUserRepository := factory.CreateRoleUserRepository(map[string]interface{}{"transactionContext": transactionContext})
  105 +//
  106 +// role, err := roleRepository.FindOne(map[string]interface{}{"id": in.Id})
  107 +// if err != nil {
  108 +// return nil, application.ThrowError(application.INTERNAL_SERVER_ERROR, err.Error())
  109 +// }
  110 +// if _, err := roleRepository.Remove(role); err != nil {
  111 +// return nil, application.ThrowError(application.INTERNAL_SERVER_ERROR, err.Error())
  112 +// }
  113 +//
  114 +// // 获取角色所有关联的用户,并删除
  115 +// _, roleUsers, err := roleUserRepository.Find(map[string]interface{}{"roleId": in.Id, "companyId": in.CompanyId})
  116 +// if err != nil {
  117 +// return nil, application.ThrowError(application.INTERNAL_SERVER_ERROR, err.Error())
  118 +// }
  119 +// ids := make([]int64, 0)
  120 +// for i := range roleUsers {
  121 +// ids = append(ids, roleUsers[i].Id)
  122 +// }
  123 +// if len(ids) > 0 {
  124 +// err := roleUserRepository.BatchDeleteById(ids)
  125 +// if err != nil {
  126 +// return nil, application.ThrowError(application.INTERNAL_SERVER_ERROR, err.Error())
  127 +// }
  128 +// }
  129 +//
  130 +// if err := transactionContext.CommitTransaction(); err != nil {
  131 +// return nil, application.ThrowError(application.TRANSACTION_ERROR, err.Error())
  132 +// }
  133 +// return role, nil
  134 +//}
136 135
137 func (rs *RoleService) ListForUser(in *command.QueryRoleUserCommand) (interface{}, error) { 136 func (rs *RoleService) ListForUser(in *command.QueryRoleUserCommand) (interface{}, error) {
138 transactionContext, err := factory.StartTransaction() 137 transactionContext, err := factory.StartTransaction()
@@ -57,7 +57,22 @@ func (controller *RuleController) RemoveRule() { @@ -57,7 +57,22 @@ func (controller *RuleController) RemoveRule() {
57 } 57 }
58 } 58 }
59 59
60 -func (controller *RuleController) ListRule() { 60 +//func (controller *RuleController) ListRule() {
  61 +// ruService := service.NewEvaluationRuleService()
  62 +// in := &command.QueryRuleCommand{}
  63 +// in.Type = -1
  64 +// if err := controller.Unmarshal(in); err != nil {
  65 +// controller.Response(nil, application.ThrowError(application.ARG_ERROR, err.Error()))
  66 +// } else {
  67 +// if len(in.NameOrRemark) > 0 {
  68 +// in.NameOrRemark = "%" + in.NameOrRemark + "%"
  69 +// }
  70 +// in.CompanyId = middlewares.GetCompanyId(controller.Ctx)
  71 +// controller.Response(ruService.List(in))
  72 +// }
  73 +//}
  74 +
  75 +func (controller *RuleController) ListRuleRelCreator() {
61 ruService := service.NewEvaluationRuleService() 76 ruService := service.NewEvaluationRuleService()
62 in := &command.QueryRuleCommand{} 77 in := &command.QueryRuleCommand{}
63 in.Type = -1 78 in.Type = -1
@@ -68,17 +83,6 @@ func (controller *RuleController) ListRule() { @@ -68,17 +83,6 @@ func (controller *RuleController) ListRule() {
68 in.NameOrRemark = "%" + in.NameOrRemark + "%" 83 in.NameOrRemark = "%" + in.NameOrRemark + "%"
69 } 84 }
70 in.CompanyId = middlewares.GetCompanyId(controller.Ctx) 85 in.CompanyId = middlewares.GetCompanyId(controller.Ctx)
71 - controller.Response(ruService.List(in))  
72 - }  
73 -}  
74 -  
75 -func (controller *RuleController) ListRuleRelCreator() {  
76 - ruService := service.NewEvaluationRuleService()  
77 - in := &command.QueryRuleCommand{}  
78 - if err := controller.Unmarshal(in); err != nil {  
79 - controller.Response(nil, application.ThrowError(application.ARG_ERROR, err.Error()))  
80 - } else {  
81 - in.CompanyId = middlewares.GetCompanyId(controller.Ctx)  
82 controller.Response(ruService.ListRelCreator(in)) 86 controller.Response(ruService.ListRelCreator(in))
83 } 87 }
84 } 88 }
@@ -12,38 +12,38 @@ type RoleController struct { @@ -12,38 +12,38 @@ type RoleController struct {
12 beego.BaseController 12 beego.BaseController
13 } 13 }
14 14
15 -func (controller *RoleController) CreateRole() {  
16 - ruService := service.NewRoleService()  
17 - in := &command.CreateRoleCommand{}  
18 - if err := controller.Unmarshal(in); err != nil {  
19 - controller.Response(nil, application.ThrowError(application.ARG_ERROR, err.Error()))  
20 - } else {  
21 - in.CompanyId = middlewares.GetCompanyId(controller.Ctx)  
22 - controller.Response(ruService.Create(in))  
23 - }  
24 -}  
25 -  
26 -func (controller *RoleController) UpdateRole() {  
27 - ruService := service.NewRoleService()  
28 - in := &command.UpdateRoleCommand{}  
29 - if err := controller.Unmarshal(in); err != nil {  
30 - controller.Response(nil, application.ThrowError(application.ARG_ERROR, err.Error()))  
31 - } else {  
32 - in.CompanyId = middlewares.GetCompanyId(controller.Ctx)  
33 - controller.Response(ruService.Update(in))  
34 - }  
35 -}  
36 -  
37 -func (controller *RoleController) RemoveRole() {  
38 - ruService := service.NewRoleService()  
39 - in := &command.DeleteRoleCommand{}  
40 - if err := controller.Unmarshal(in); err != nil {  
41 - controller.Response(nil, application.ThrowError(application.ARG_ERROR, err.Error()))  
42 - } else {  
43 - in.CompanyId = middlewares.GetCompanyId(controller.Ctx)  
44 - controller.Response(ruService.Remove(in))  
45 - }  
46 -} 15 +//func (controller *RoleController) CreateRole() {
  16 +// ruService := service.NewRoleService()
  17 +// in := &command.CreateRoleCommand{}
  18 +// if err := controller.Unmarshal(in); err != nil {
  19 +// controller.Response(nil, application.ThrowError(application.ARG_ERROR, err.Error()))
  20 +// } else {
  21 +// in.CompanyId = middlewares.GetCompanyId(controller.Ctx)
  22 +// controller.Response(ruService.Create(in))
  23 +// }
  24 +//}
  25 +//
  26 +//func (controller *RoleController) UpdateRole() {
  27 +// ruService := service.NewRoleService()
  28 +// in := &command.UpdateRoleCommand{}
  29 +// if err := controller.Unmarshal(in); err != nil {
  30 +// controller.Response(nil, application.ThrowError(application.ARG_ERROR, err.Error()))
  31 +// } else {
  32 +// in.CompanyId = middlewares.GetCompanyId(controller.Ctx)
  33 +// controller.Response(ruService.Update(in))
  34 +// }
  35 +//}
  36 +//
  37 +//func (controller *RoleController) RemoveRole() {
  38 +// ruService := service.NewRoleService()
  39 +// in := &command.DeleteRoleCommand{}
  40 +// if err := controller.Unmarshal(in); err != nil {
  41 +// controller.Response(nil, application.ThrowError(application.ARG_ERROR, err.Error()))
  42 +// } else {
  43 +// in.CompanyId = middlewares.GetCompanyId(controller.Ctx)
  44 +// controller.Response(ruService.Remove(in))
  45 +// }
  46 +//}
47 47
48 func (controller *RoleController) ListForUserRole() { 48 func (controller *RoleController) ListForUserRole() {
49 ruService := service.NewRoleService() 49 ruService := service.NewRoleService()
@@ -14,7 +14,7 @@ func init() { @@ -14,7 +14,7 @@ func init() {
14 web.NSRouter("/", &controllers.RuleController{}, "Put:UpdateRule"), 14 web.NSRouter("/", &controllers.RuleController{}, "Put:UpdateRule"),
15 web.NSRouter("/", &controllers.RuleController{}, "Delete:RemoveRule"), 15 web.NSRouter("/", &controllers.RuleController{}, "Delete:RemoveRule"),
16 web.NSRouter("/:Id", &controllers.RuleController{}, "Get:GetRule"), 16 web.NSRouter("/:Id", &controllers.RuleController{}, "Get:GetRule"),
17 - web.NSRouter("/list", &controllers.RuleController{}, "Post:ListRule"), 17 + web.NSRouter("/list", &controllers.RuleController{}, "Post:ListRuleRelCreator"),
18 ) 18 )
19 web.AddNamespace(ns) 19 web.AddNamespace(ns)
20 } 20 }