切换导航条
此项目
正在载入...
登录
allied-creation
/
performance
·
提交
转到一个项目
GitLab
转到群组
项目
活动
文件
提交
管道
0
构建
0
图表
里程碑
问题
0
合并请求
0
成员
标记
维基
派生
网络
创建新的问题
下载为
邮件补丁
差异文件
浏览文件
作者
郑周
2 years ago
提交
7a7762596091e7cc922a11c6a6f08d76aab0cf1e
1 个父辈
70a8986e
评估规则 优化
角色 优化
隐藏空白字符变更
内嵌
并排对比
正在显示
5 个修改的文件
包含
181 行增加
和
178 行删除
pkg/application/evaluation_rule/rule_service.go
pkg/application/role/role_service.go
pkg/port/beego/controllers/evaluation_rule_controller.go
pkg/port/beego/controllers/role_controller.go
pkg/port/beego/routers/evaluation_rule_router.go
pkg/application/evaluation_rule/rule_service.go
查看文件 @
7a77625
...
...
@@ -157,22 +157,22 @@ func (rs *EvaluationRuleService) Remove(in *command.DeleteRuleCommand) (interfac
return
rule
,
nil
}
func
(
rs
*
EvaluationRuleService
)
List
(
in
*
command
.
QueryRuleCommand
)
(
interface
{},
error
)
{
transactionContext
,
err
:=
factory
.
StartTransaction
()
if
err
!=
nil
{
return
nil
,
err
}
defer
func
()
{
transactionContext
.
RollbackTransaction
()
}()
ruleRepository
:=
factory
.
CreateEvaluationRuleRepository
(
map
[
string
]
interface
{}{
"transactionContext"
:
transactionContext
})
total
,
rules
,
err
:=
ruleRepository
.
Find
(
tool_funs
.
SimpleStructToMap
(
in
))
if
err
!=
nil
{
return
nil
,
application
.
ThrowError
(
application
.
INTERNAL_SERVER_ERROR
,
err
.
Error
())
}
return
tool_funs
.
SimpleWrapGridMap
(
total
,
rules
),
nil
}
//func (rs *EvaluationRuleService) List(in *command.QueryRuleCommand) (interface{}, error) {
// transactionContext, err := factory.StartTransaction()
// if err != nil {
// return nil, err
// }
// defer func() {
// transactionContext.RollbackTransaction()
// }()
// ruleRepository := factory.CreateEvaluationRuleRepository(map[string]interface{}{"transactionContext": transactionContext})
//
// total, rules, err := ruleRepository.Find(tool_funs.SimpleStructToMap(in))
// if err != nil {
// return nil, application.ThrowError(application.INTERNAL_SERVER_ERROR, err.Error())
// }
// return tool_funs.SimpleWrapGridMap(total, rules), nil
//}
func
(
rs
*
EvaluationRuleService
)
ListRelCreator
(
in
*
command
.
QueryRuleCommand
)
(
interface
{},
error
)
{
transactionContext
,
err
:=
factory
.
StartTransaction
()
...
...
pkg/application/role/role_service.go
查看文件 @
7a77625
...
...
@@ -6,7 +6,6 @@ import (
"gitlab.fjmaimaimai.com/allied-creation/performance/pkg/application/factory"
"gitlab.fjmaimaimai.com/allied-creation/performance/pkg/application/role/adapter"
"gitlab.fjmaimaimai.com/allied-creation/performance/pkg/application/role/command"
"gitlab.fjmaimaimai.com/allied-creation/performance/pkg/domain"
)
type
RoleService
struct
{
...
...
@@ -17,122 +16,122 @@ func NewRoleService() *RoleService {
return
newRoleService
}
// Create 创建
func
(
rs
*
RoleService
)
Create
(
in
*
command
.
CreateRoleCommand
)
(
interface
{},
error
)
{
transactionContext
,
err
:=
factory
.
ValidateStartTransaction
(
in
)
if
err
!=
nil
{
return
nil
,
err
}
defer
func
()
{
transactionContext
.
RollbackTransaction
()
}()
roleRepository
:=
factory
.
CreateRoleRepository
(
map
[
string
]
interface
{}{
"transactionContext"
:
transactionContext
})
// 检测名称重复
count
,
err
:=
roleRepository
.
Count
(
map
[
string
]
interface
{}{
"name"
:
in
.
Name
,
"companyId"
:
in
.
CompanyId
})
if
err
!=
nil
{
return
nil
,
application
.
ThrowError
(
application
.
INTERNAL_SERVER_ERROR
,
err
.
Error
())
}
if
count
>
0
{
return
nil
,
application
.
ThrowError
(
application
.
BUSINESS_ERROR
,
"角色名称已存在"
)
}
newRole
:=
&
domain
.
Role
{
Id
:
0
,
Name
:
in
.
Name
,
Type
:
domain
.
RoleTypeCommon
,
Description
:
in
.
Description
,
CompanyId
:
in
.
CompanyId
,
}
role
,
err
:=
roleRepository
.
Insert
(
newRole
)
if
err
!=
nil
{
return
nil
,
application
.
ThrowError
(
application
.
INTERNAL_SERVER_ERROR
,
err
.
Error
())
}
if
err
:=
transactionContext
.
CommitTransaction
();
err
!=
nil
{
return
nil
,
application
.
ThrowError
(
application
.
TRANSACTION_ERROR
,
err
.
Error
())
}
return
role
,
nil
}
func
(
rs
*
RoleService
)
Update
(
in
*
command
.
UpdateRoleCommand
)
(
interface
{},
error
)
{
transactionContext
,
err
:=
factory
.
ValidateStartTransaction
(
in
)
if
err
!=
nil
{
return
nil
,
err
}
defer
func
()
{
transactionContext
.
RollbackTransaction
()
}()
roleRepository
:=
factory
.
CreateRoleRepository
(
map
[
string
]
interface
{}{
"transactionContext"
:
transactionContext
})
// 检测名称重复(排除自己)
count
,
err
:=
roleRepository
.
Count
(
map
[
string
]
interface
{}{
"name"
:
in
.
Name
,
"companyId"
:
in
.
CompanyId
,
"notId"
:
in
.
Id
})
if
err
!=
nil
{
return
nil
,
application
.
ThrowError
(
application
.
INTERNAL_SERVER_ERROR
,
err
.
Error
())
}
if
count
>
0
{
return
nil
,
application
.
ThrowError
(
application
.
BUSINESS_ERROR
,
"角色名称已存在"
)
}
role
,
err
:=
roleRepository
.
FindOne
(
map
[
string
]
interface
{}{
"id"
:
in
.
Id
})
if
err
!=
nil
{
return
nil
,
application
.
ThrowError
(
application
.
INTERNAL_SERVER_ERROR
,
err
.
Error
())
}
role
.
Name
=
in
.
Name
role
.
Description
=
in
.
Description
role
,
err
=
roleRepository
.
Insert
(
role
)
if
err
!=
nil
{
return
nil
,
application
.
ThrowError
(
application
.
INTERNAL_SERVER_ERROR
,
err
.
Error
())
}
if
err
:=
transactionContext
.
CommitTransaction
();
err
!=
nil
{
return
nil
,
application
.
ThrowError
(
application
.
TRANSACTION_ERROR
,
err
.
Error
())
}
return
role
,
nil
}
func
(
rs
*
RoleService
)
Remove
(
in
*
command
.
DeleteRoleCommand
)
(
interface
{},
error
)
{
transactionContext
,
err
:=
factory
.
ValidateStartTransaction
(
in
)
if
err
!=
nil
{
return
nil
,
err
}
defer
func
()
{
transactionContext
.
RollbackTransaction
()
}()
roleRepository
:=
factory
.
CreateRoleRepository
(
map
[
string
]
interface
{}{
"transactionContext"
:
transactionContext
})
roleUserRepository
:=
factory
.
CreateRoleUserRepository
(
map
[
string
]
interface
{}{
"transactionContext"
:
transactionContext
})
role
,
err
:=
roleRepository
.
FindOne
(
map
[
string
]
interface
{}{
"id"
:
in
.
Id
})
if
err
!=
nil
{
return
nil
,
application
.
ThrowError
(
application
.
INTERNAL_SERVER_ERROR
,
err
.
Error
())
}
if
_
,
err
:=
roleRepository
.
Remove
(
role
);
err
!=
nil
{
return
nil
,
application
.
ThrowError
(
application
.
INTERNAL_SERVER_ERROR
,
err
.
Error
())
}
// 获取角色所有关联的用户,并删除
_
,
roleUsers
,
err
:=
roleUserRepository
.
Find
(
map
[
string
]
interface
{}{
"roleId"
:
in
.
Id
,
"companyId"
:
in
.
CompanyId
})
if
err
!=
nil
{
return
nil
,
application
.
ThrowError
(
application
.
INTERNAL_SERVER_ERROR
,
err
.
Error
())
}
ids
:=
make
([]
int64
,
0
)
for
i
:=
range
roleUsers
{
ids
=
append
(
ids
,
roleUsers
[
i
]
.
Id
)
}
if
len
(
ids
)
>
0
{
err
:=
roleUserRepository
.
BatchDeleteById
(
ids
)
if
err
!=
nil
{
return
nil
,
application
.
ThrowError
(
application
.
INTERNAL_SERVER_ERROR
,
err
.
Error
())
}
}
if
err
:=
transactionContext
.
CommitTransaction
();
err
!=
nil
{
return
nil
,
application
.
ThrowError
(
application
.
TRANSACTION_ERROR
,
err
.
Error
())
}
return
role
,
nil
}
//// Create 创建
//func (rs *RoleService) Create(in *command.CreateRoleCommand) (interface{}, error) {
// transactionContext, err := factory.ValidateStartTransaction(in)
// if err != nil {
// return nil, err
// }
// defer func() {
// transactionContext.RollbackTransaction()
// }()
// roleRepository := factory.CreateRoleRepository(map[string]interface{}{"transactionContext": transactionContext})
//
// // 检测名称重复
// count, err := roleRepository.Count(map[string]interface{}{"name": in.Name, "companyId": in.CompanyId})
// if err != nil {
// return nil, application.ThrowError(application.INTERNAL_SERVER_ERROR, err.Error())
// }
// if count > 0 {
// return nil, application.ThrowError(application.BUSINESS_ERROR, "角色名称已存在")
// }
// newRole := &domain.Role{
// Id: 0,
// Name: in.Name,
// Type: domain.RoleTypeCommon,
// Description: in.Description,
// CompanyId: in.CompanyId,
// }
// role, err := roleRepository.Insert(newRole)
// if err != nil {
// return nil, application.ThrowError(application.INTERNAL_SERVER_ERROR, err.Error())
// }
// if err := transactionContext.CommitTransaction(); err != nil {
// return nil, application.ThrowError(application.TRANSACTION_ERROR, err.Error())
// }
// return role, nil
//
//}
//
//func (rs *RoleService) Update(in *command.UpdateRoleCommand) (interface{}, error) {
// transactionContext, err := factory.ValidateStartTransaction(in)
// if err != nil {
// return nil, err
// }
// defer func() {
// transactionContext.RollbackTransaction()
// }()
//
// roleRepository := factory.CreateRoleRepository(map[string]interface{}{"transactionContext": transactionContext})
//
// // 检测名称重复(排除自己)
// count, err := roleRepository.Count(map[string]interface{}{"name": in.Name, "companyId": in.CompanyId, "notId": in.Id})
// if err != nil {
// return nil, application.ThrowError(application.INTERNAL_SERVER_ERROR, err.Error())
// }
// if count > 0 {
// return nil, application.ThrowError(application.BUSINESS_ERROR, "角色名称已存在")
// }
//
// role, err := roleRepository.FindOne(map[string]interface{}{"id": in.Id})
// if err != nil {
// return nil, application.ThrowError(application.INTERNAL_SERVER_ERROR, err.Error())
// }
//
// role.Name = in.Name
// role.Description = in.Description
//
// role, err = roleRepository.Insert(role)
// if err != nil {
// return nil, application.ThrowError(application.INTERNAL_SERVER_ERROR, err.Error())
// }
// if err := transactionContext.CommitTransaction(); err != nil {
// return nil, application.ThrowError(application.TRANSACTION_ERROR, err.Error())
// }
// return role, nil
//}
//
//func (rs *RoleService) Remove(in *command.DeleteRoleCommand) (interface{}, error) {
// transactionContext, err := factory.ValidateStartTransaction(in)
// if err != nil {
// return nil, err
// }
// defer func() {
// transactionContext.RollbackTransaction()
// }()
//
// roleRepository := factory.CreateRoleRepository(map[string]interface{}{"transactionContext": transactionContext})
// roleUserRepository := factory.CreateRoleUserRepository(map[string]interface{}{"transactionContext": transactionContext})
//
// role, err := roleRepository.FindOne(map[string]interface{}{"id": in.Id})
// if err != nil {
// return nil, application.ThrowError(application.INTERNAL_SERVER_ERROR, err.Error())
// }
// if _, err := roleRepository.Remove(role); err != nil {
// return nil, application.ThrowError(application.INTERNAL_SERVER_ERROR, err.Error())
// }
//
// // 获取角色所有关联的用户,并删除
// _, roleUsers, err := roleUserRepository.Find(map[string]interface{}{"roleId": in.Id, "companyId": in.CompanyId})
// if err != nil {
// return nil, application.ThrowError(application.INTERNAL_SERVER_ERROR, err.Error())
// }
// ids := make([]int64, 0)
// for i := range roleUsers {
// ids = append(ids, roleUsers[i].Id)
// }
// if len(ids) > 0 {
// err := roleUserRepository.BatchDeleteById(ids)
// if err != nil {
// return nil, application.ThrowError(application.INTERNAL_SERVER_ERROR, err.Error())
// }
// }
//
// if err := transactionContext.CommitTransaction(); err != nil {
// return nil, application.ThrowError(application.TRANSACTION_ERROR, err.Error())
// }
// return role, nil
//}
func
(
rs
*
RoleService
)
ListForUser
(
in
*
command
.
QueryRoleUserCommand
)
(
interface
{},
error
)
{
transactionContext
,
err
:=
factory
.
StartTransaction
()
...
...
pkg/port/beego/controllers/evaluation_rule_controller.go
查看文件 @
7a77625
...
...
@@ -57,7 +57,22 @@ func (controller *RuleController) RemoveRule() {
}
}
func
(
controller
*
RuleController
)
ListRule
()
{
//func (controller *RuleController) ListRule() {
// ruService := service.NewEvaluationRuleService()
// in := &command.QueryRuleCommand{}
// in.Type = -1
// if err := controller.Unmarshal(in); err != nil {
// controller.Response(nil, application.ThrowError(application.ARG_ERROR, err.Error()))
// } else {
// if len(in.NameOrRemark) > 0 {
// in.NameOrRemark = "%" + in.NameOrRemark + "%"
// }
// in.CompanyId = middlewares.GetCompanyId(controller.Ctx)
// controller.Response(ruService.List(in))
// }
//}
func
(
controller
*
RuleController
)
ListRuleRelCreator
()
{
ruService
:=
service
.
NewEvaluationRuleService
()
in
:=
&
command
.
QueryRuleCommand
{}
in
.
Type
=
-
1
...
...
@@ -68,17 +83,6 @@ func (controller *RuleController) ListRule() {
in
.
NameOrRemark
=
"%"
+
in
.
NameOrRemark
+
"%"
}
in
.
CompanyId
=
middlewares
.
GetCompanyId
(
controller
.
Ctx
)
controller
.
Response
(
ruService
.
List
(
in
))
}
}
func
(
controller
*
RuleController
)
ListRuleRelCreator
()
{
ruService
:=
service
.
NewEvaluationRuleService
()
in
:=
&
command
.
QueryRuleCommand
{}
if
err
:=
controller
.
Unmarshal
(
in
);
err
!=
nil
{
controller
.
Response
(
nil
,
application
.
ThrowError
(
application
.
ARG_ERROR
,
err
.
Error
()))
}
else
{
in
.
CompanyId
=
middlewares
.
GetCompanyId
(
controller
.
Ctx
)
controller
.
Response
(
ruService
.
ListRelCreator
(
in
))
}
}
...
...
pkg/port/beego/controllers/role_controller.go
查看文件 @
7a77625
...
...
@@ -12,38 +12,38 @@ type RoleController struct {
beego
.
BaseController
}
func
(
controller
*
RoleController
)
CreateRole
()
{
ruService
:=
service
.
NewRoleService
()
in
:=
&
command
.
CreateRoleCommand
{}
if
err
:=
controller
.
Unmarshal
(
in
);
err
!=
nil
{
controller
.
Response
(
nil
,
application
.
ThrowError
(
application
.
ARG_ERROR
,
err
.
Error
()))
}
else
{
in
.
CompanyId
=
middlewares
.
GetCompanyId
(
controller
.
Ctx
)
controller
.
Response
(
ruService
.
Create
(
in
))
}
}
func
(
controller
*
RoleController
)
UpdateRole
()
{
ruService
:=
service
.
NewRoleService
()
in
:=
&
command
.
UpdateRoleCommand
{}
if
err
:=
controller
.
Unmarshal
(
in
);
err
!=
nil
{
controller
.
Response
(
nil
,
application
.
ThrowError
(
application
.
ARG_ERROR
,
err
.
Error
()))
}
else
{
in
.
CompanyId
=
middlewares
.
GetCompanyId
(
controller
.
Ctx
)
controller
.
Response
(
ruService
.
Update
(
in
))
}
}
func
(
controller
*
RoleController
)
RemoveRole
()
{
ruService
:=
service
.
NewRoleService
()
in
:=
&
command
.
DeleteRoleCommand
{}
if
err
:=
controller
.
Unmarshal
(
in
);
err
!=
nil
{
controller
.
Response
(
nil
,
application
.
ThrowError
(
application
.
ARG_ERROR
,
err
.
Error
()))
}
else
{
in
.
CompanyId
=
middlewares
.
GetCompanyId
(
controller
.
Ctx
)
controller
.
Response
(
ruService
.
Remove
(
in
))
}
}
//func (controller *RoleController) CreateRole() {
// ruService := service.NewRoleService()
// in := &command.CreateRoleCommand{}
// if err := controller.Unmarshal(in); err != nil {
// controller.Response(nil, application.ThrowError(application.ARG_ERROR, err.Error()))
// } else {
// in.CompanyId = middlewares.GetCompanyId(controller.Ctx)
// controller.Response(ruService.Create(in))
// }
//}
//
//func (controller *RoleController) UpdateRole() {
// ruService := service.NewRoleService()
// in := &command.UpdateRoleCommand{}
// if err := controller.Unmarshal(in); err != nil {
// controller.Response(nil, application.ThrowError(application.ARG_ERROR, err.Error()))
// } else {
// in.CompanyId = middlewares.GetCompanyId(controller.Ctx)
// controller.Response(ruService.Update(in))
// }
//}
//
//func (controller *RoleController) RemoveRole() {
// ruService := service.NewRoleService()
// in := &command.DeleteRoleCommand{}
// if err := controller.Unmarshal(in); err != nil {
// controller.Response(nil, application.ThrowError(application.ARG_ERROR, err.Error()))
// } else {
// in.CompanyId = middlewares.GetCompanyId(controller.Ctx)
// controller.Response(ruService.Remove(in))
// }
//}
func
(
controller
*
RoleController
)
ListForUserRole
()
{
ruService
:=
service
.
NewRoleService
()
...
...
pkg/port/beego/routers/evaluation_rule_router.go
查看文件 @
7a77625
...
...
@@ -14,7 +14,7 @@ func init() {
web
.
NSRouter
(
"/"
,
&
controllers
.
RuleController
{},
"Put:UpdateRule"
),
web
.
NSRouter
(
"/"
,
&
controllers
.
RuleController
{},
"Delete:RemoveRule"
),
web
.
NSRouter
(
"/:Id"
,
&
controllers
.
RuleController
{},
"Get:GetRule"
),
web
.
NSRouter
(
"/list"
,
&
controllers
.
RuleController
{},
"Post:ListRule"
),
web
.
NSRouter
(
"/list"
,
&
controllers
.
RuleController
{},
"Post:ListRule
RelCreator
"
),
)
web
.
AddNamespace
(
ns
)
}
...
...
请
注册
或
登录
后发表评论