切换导航条
此项目
正在载入...
登录
allied-creation
/
performance
·
提交
转到一个项目
GitLab
转到群组
项目
活动
文件
提交
管道
0
构建
0
图表
里程碑
问题
0
合并请求
0
成员
标记
维基
派生
网络
创建新的问题
下载为
邮件补丁
差异文件
浏览文件
作者
郑周
2 years ago
提交
3f701820cb291c9c4050aaea1261a8b06699b45c
1 个父辈
149cf89a
master
...
dev-pushdata
dev-tangxvhui
dev-zhengzhou
dev_zhuangmx
test
v1.3.2-fix
v1.4.0
v2.2.0-fix
20230410
20230403
20230331
20230324
20230315
20230203
20230112
20221208
20221205
v2.2.0
v2.0.0
v1.3.2
v1.3.2-fix
v1.3.1
v1.3.0
v1.2.4
1.评估规则 ruleService 业务编码
隐藏空白字符变更
内嵌
并排对比
正在显示
18 个修改的文件
包含
1101 行增加
和
34 行删除
pkg/application/evaluation_rule/adapter/rule_adapter.go
pkg/application/evaluation_rule/command/rule_create.go
pkg/application/evaluation_rule/command/rule_delete.go
pkg/application/evaluation_rule/command/rule_query.go
pkg/application/evaluation_rule/command/rule_update.go
pkg/application/evaluation_rule/rule_service.go
pkg/application/factory/reposetory.go
pkg/application/role/adapter/role_adapter.go
pkg/domain/evaluation_cycle.go
pkg/domain/evaluation_project.go
pkg/domain/evaluation_rule.go
pkg/domain/evaluation_template.go
pkg/infrastructure/pg/models/evaluation_cycle.go
pkg/infrastructure/pg/models/evaluation_project.go
pkg/infrastructure/repository/pg_evaluation_cycle_repository.go
pkg/infrastructure/repository/pg_evaluation_project_repository.go
pkg/infrastructure/repository/pg_evaluation_rule_repository.go
pkg/infrastructure/repository/pg_evaluation_template_repository.go
pkg/application/evaluation_rule/adapter/rule_adapter.go
0 → 100644
查看文件 @
3f70182
package
adapter
import
(
"gitlab.fjmaimaimai.com/allied-creation/performance/pkg/domain"
)
type
RuleAdapter
struct
{
*
domain
.
EvaluationRule
CreatorName
string
`json:"creatorName" comment:"创建人名称"`
}
...
...
pkg/application/evaluation_rule/command/rule_create.go
0 → 100644
查看文件 @
3f70182
package
command
import
(
"github.com/beego/beego/v2/core/validation"
"gitlab.fjmaimaimai.com/allied-creation/performance/pkg/domain"
)
type
CreateRuleCommand
struct
{
CompanyId
int64
`cname:"公司ID" json:"companyId"`
CreatorId
int64
`cname:"创建人ID" json:"creatorId"`
Name
string
`cname:"规则名称" json:"name" valid:"Required"`
Remark
string
`cname:"规则备注" json:"remark"`
Type
int
`cname:"评估方式" json:"type"`
Rating
*
domain
.
Rating
`cname:"评级" json:"rating"`
Score
*
domain
.
Score
`cname:"评分" json:"score"`
}
func
(
in
*
CreateRuleCommand
)
Valid
(
validation
*
validation
.
Validation
)
{
if
in
.
CompanyId
==
0
{
validation
.
SetError
(
"companyId"
,
"公司ID无效"
)
return
}
if
in
.
CreatorId
==
0
{
validation
.
SetError
(
"creatorId"
,
"创建人ID无效"
)
return
}
if
len
(
in
.
Name
)
>
40
{
validation
.
SetError
(
"name"
,
"角色名称最大长度40个字符"
)
return
}
if
in
.
Type
==
domain
.
EvaluationTypeRating
{
if
nil
==
in
.
Rating
||
len
(
in
.
Rating
.
Levels
)
==
0
{
validation
.
SetError
(
"rating"
,
"评级内容不能为空"
)
return
}
}
if
in
.
Type
==
domain
.
EvaluationTypeScore
{
if
nil
==
in
.
Score
{
validation
.
SetError
(
"rating"
,
"评分内容不能为空"
)
return
}
}
}
...
...
pkg/application/evaluation_rule/command/rule_delete.go
0 → 100644
查看文件 @
3f70182
package
command
import
"github.com/beego/beego/v2/core/validation"
type
DeleteRuleCommand
struct
{
CompanyId
int64
`cname:"公司ID" json:"companyId"`
Id
int64
`cname:"规则ID" json:"id,string" valid:"Required"`
}
func
(
in
*
DeleteRuleCommand
)
Valid
(
validation
*
validation
.
Validation
)
{
if
in
.
CompanyId
==
0
{
validation
.
SetError
(
"companyId"
,
"公司ID无效"
)
return
}
}
...
...
pkg/application/evaluation_rule/command/rule_query.go
0 → 100644
查看文件 @
3f70182
package
command
import
"github.com/beego/beego/v2/core/validation"
type
QueryRuleCommand
struct
{
CompanyId
int64
`cname:"公司ID" json:"companyId"`
PageNumber
int
`cname:"分页页码" json:"pageNumber" valid:"Required"`
PageSize
int
`cname:"分页数量" json:"pageSize" valid:"Required"`
}
func
(
in
*
QueryRuleCommand
)
Valid
(
validation
*
validation
.
Validation
)
{
if
in
.
CompanyId
==
0
{
validation
.
SetError
(
"companyId"
,
"公司ID无效"
)
return
}
}
...
...
pkg/application/evaluation_rule/command/rule_update.go
0 → 100644
查看文件 @
3f70182
package
command
import
(
"github.com/beego/beego/v2/core/validation"
"gitlab.fjmaimaimai.com/allied-creation/performance/pkg/domain"
)
type
UpdateRuleCommand
struct
{
Id
int64
`cname:"规则ID" json:"id,string" valid:"Required"`
CompanyId
int64
`cname:"公司ID" json:"companyId"`
CreatorId
int64
`cname:"创建人ID" json:"creatorId"`
Name
string
`cname:"规则名称" json:"name" valid:"Required"`
Remark
string
`cname:"规则备注" json:"remark"`
Type
int
`cname:"评估方式" json:"type"`
Rating
*
domain
.
Rating
`cname:"评级" json:"rating"`
Score
*
domain
.
Score
`cname:"评分" json:"score"`
}
func
(
in
*
UpdateRuleCommand
)
Valid
(
validation
*
validation
.
Validation
)
{
if
in
.
CompanyId
==
0
{
validation
.
SetError
(
"companyId"
,
"公司ID无效"
)
return
}
if
in
.
CreatorId
==
0
{
validation
.
SetError
(
"creatorId"
,
"创建人ID无效"
)
return
}
if
len
(
in
.
Name
)
>
40
{
validation
.
SetError
(
"name"
,
"角色名称最大长度40个字符"
)
return
}
if
in
.
Type
==
domain
.
EvaluationTypeRating
{
if
nil
==
in
.
Rating
||
len
(
in
.
Rating
.
Levels
)
==
0
{
validation
.
SetError
(
"rating"
,
"评级内容不能为空"
)
return
}
}
if
in
.
Type
==
domain
.
EvaluationTypeScore
{
if
nil
==
in
.
Score
{
validation
.
SetError
(
"rating"
,
"评分内容不能为空"
)
return
}
}
}
...
...
pkg/application/evaluation_rule/rule_service.go
0 → 100644
查看文件 @
3f70182
package
service
import
(
"github.com/linmadan/egglib-go/core/application"
"github.com/linmadan/egglib-go/utils/tool_funs"
"gitlab.fjmaimaimai.com/allied-creation/performance/pkg/application/evaluation_rule/adapter"
"gitlab.fjmaimaimai.com/allied-creation/performance/pkg/application/evaluation_rule/command"
"gitlab.fjmaimaimai.com/allied-creation/performance/pkg/application/factory"
"gitlab.fjmaimaimai.com/allied-creation/performance/pkg/domain"
)
type
EvaluationRuleService
struct
{
}
func
NewEvaluationRuleService
()
*
EvaluationRuleService
{
newRoleService
:=
&
EvaluationRuleService
{}
return
newRoleService
}
// Create 创建
func
(
rs
*
EvaluationRuleService
)
Create
(
in
*
command
.
CreateRuleCommand
)
(
interface
{},
error
)
{
transactionContext
,
err
:=
factory
.
ValidateStartTransaction
(
in
)
if
err
!=
nil
{
return
nil
,
err
}
defer
func
()
{
transactionContext
.
RollbackTransaction
()
}()
ruleRepository
:=
factory
.
CreateEvaluationRuleRepository
(
map
[
string
]
interface
{}{
"transactionContext"
:
transactionContext
})
// 检测名称重复
count
,
err
:=
ruleRepository
.
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
,
"名称已存在"
)
}
newRule
:=
&
domain
.
EvaluationRule
{
Id
:
0
,
Name
:
in
.
Name
,
Remark
:
in
.
Remark
,
CompanyId
:
in
.
CompanyId
,
CreatorId
:
in
.
CreatorId
,
Type
:
in
.
Type
,
Rating
:
in
.
Rating
,
Score
:
in
.
Score
,
}
rule
,
err
:=
ruleRepository
.
Insert
(
newRule
)
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
rule
,
nil
}
func
(
rs
*
EvaluationRuleService
)
Update
(
in
*
command
.
UpdateRuleCommand
)
(
interface
{},
error
)
{
transactionContext
,
err
:=
factory
.
ValidateStartTransaction
(
in
)
if
err
!=
nil
{
return
nil
,
err
}
defer
func
()
{
transactionContext
.
RollbackTransaction
()
}()
ruleRepository
:=
factory
.
CreateEvaluationRuleRepository
(
map
[
string
]
interface
{}{
"transactionContext"
:
transactionContext
})
// 检测名称重复(排除自己)
count
,
err
:=
ruleRepository
.
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
,
"名称已存在"
)
}
rule
,
err
:=
ruleRepository
.
FindOne
(
map
[
string
]
interface
{}{
"id"
:
in
.
Id
})
if
err
!=
nil
{
return
nil
,
application
.
ThrowError
(
application
.
INTERNAL_SERVER_ERROR
,
err
.
Error
())
}
rule
.
Name
=
in
.
Name
rule
.
Remark
=
in
.
Remark
rule
.
Type
=
in
.
Type
rule
.
Rating
=
in
.
Rating
rule
.
Score
=
in
.
Score
rule
,
err
=
ruleRepository
.
Insert
(
rule
)
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
rule
,
nil
}
func
(
rs
*
EvaluationRuleService
)
Remove
(
in
*
command
.
DeleteRuleCommand
)
(
interface
{},
error
)
{
transactionContext
,
err
:=
factory
.
ValidateStartTransaction
(
in
)
if
err
!=
nil
{
return
nil
,
err
}
defer
func
()
{
transactionContext
.
RollbackTransaction
()
}()
ruleRepository
:=
factory
.
CreateEvaluationRuleRepository
(
map
[
string
]
interface
{}{
"transactionContext"
:
transactionContext
})
rule
,
err
:=
ruleRepository
.
FindOne
(
map
[
string
]
interface
{}{
"id"
:
in
.
Id
})
if
err
!=
nil
{
return
nil
,
application
.
ThrowError
(
application
.
INTERNAL_SERVER_ERROR
,
err
.
Error
())
}
if
_
,
err
:=
ruleRepository
.
Remove
(
rule
);
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
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
})
userRepository
:=
factory
.
CreateUserRepository
(
map
[
string
]
interface
{}{
"transactionContext"
:
transactionContext
})
// Fixme 总数量是否使用Count获取一个总数量
count
,
rules
,
err
:=
ruleRepository
.
Find
(
tool_funs
.
SimpleStructToMap
(
in
))
if
err
!=
nil
{
return
nil
,
application
.
ThrowError
(
application
.
INTERNAL_SERVER_ERROR
,
err
.
Error
())
}
ras
:=
make
([]
*
adapter
.
RuleAdapter
,
0
)
creatorIds
:=
make
([]
int64
,
0
)
for
i
:=
range
rules
{
ra
:=
&
adapter
.
RuleAdapter
{}
ra
.
EvaluationRule
=
rules
[
i
]
ras
=
append
(
ras
,
ra
)
creatorIds
=
append
(
creatorIds
,
rules
[
i
]
.
CreatorId
)
}
_
,
users
,
_
:=
userRepository
.
Find
(
map
[
string
]
interface
{}{
"ids"
:
creatorIds
,
"limit"
:
len
(
creatorIds
)})
userNameMap
:=
map
[
int64
]
string
{}
if
users
!=
nil
{
for
i
:=
range
users
{
userNameMap
[
users
[
i
]
.
Id
]
=
users
[
i
]
.
Name
}
}
for
i
:=
range
ras
{
if
v
,
ok
:=
userNameMap
[
ras
[
i
]
.
CreatorId
];
ok
{
ras
[
i
]
.
CreatorName
=
v
}
}
return
tool_funs
.
SimpleWrapGridMap
(
count
,
ras
),
nil
}
...
...
pkg/application/factory/reposetory.go
查看文件 @
3f70182
...
...
@@ -80,3 +80,35 @@ func CreateReceivedMessageRepository(options map[string]interface{}) domain.Rece
}
return
repository
.
NewReceivedMessageRepository
(
transactionContext
)
}
func
CreateEvaluationRuleRepository
(
options
map
[
string
]
interface
{})
domain
.
EvaluationRuleRepository
{
var
transactionContext
*
pg
.
TransactionContext
if
value
,
ok
:=
options
[
"transactionContext"
];
ok
{
transactionContext
=
value
.
(
*
pg
.
TransactionContext
)
}
return
repository
.
NewEvaluationRuleRepository
(
transactionContext
)
}
func
CreateEvaluationTemplateRepository
(
options
map
[
string
]
interface
{})
domain
.
EvaluationTemplateRepository
{
var
transactionContext
*
pg
.
TransactionContext
if
value
,
ok
:=
options
[
"transactionContext"
];
ok
{
transactionContext
=
value
.
(
*
pg
.
TransactionContext
)
}
return
repository
.
NewEvaluationTemplateRepository
(
transactionContext
)
}
func
CreateEvaluationCycleRepository
(
options
map
[
string
]
interface
{})
domain
.
EvaluationCycleRepository
{
var
transactionContext
*
pg
.
TransactionContext
if
value
,
ok
:=
options
[
"transactionContext"
];
ok
{
transactionContext
=
value
.
(
*
pg
.
TransactionContext
)
}
return
repository
.
NewEvaluationCycleRepository
(
transactionContext
)
}
func
CreateEvaluationProjectRepository
(
options
map
[
string
]
interface
{})
domain
.
EvaluationProjectRepository
{
var
transactionContext
*
pg
.
TransactionContext
if
value
,
ok
:=
options
[
"transactionContext"
];
ok
{
transactionContext
=
value
.
(
*
pg
.
TransactionContext
)
}
return
repository
.
NewEvaluationProjectRepository
(
transactionContext
)
}
...
...
pkg/application/role/adapter/role_adapter.go
查看文件 @
3f70182
...
...
@@ -4,13 +4,6 @@ import (
"gitlab.fjmaimaimai.com/allied-creation/performance/pkg/domain"
)
//type RoleContainUser struct {
// RoleId int64 `json:"roleId,string"`
// UserId int64 `json:"userId,string"`
// UserName string `json:"userName"`
// UserEmail string `json:"userEmail"`
//}
type
RoleUserAdapter
struct
{
domain
.
Role
Users
[]
*
domain
.
RoleContainUser
`json:"users"`
...
...
pkg/domain/evaluation_cycle.go
查看文件 @
3f70182
...
...
@@ -17,3 +17,11 @@ type EvaluationCycle struct {
UpdatedAt
time
.
Time
`json:"updatedAt" comment:"更新时间"`
DeletedAt
*
time
.
Time
`json:"deletedAt" comment:"删除时间"`
}
type
EvaluationCycleRepository
interface
{
Insert
(
cycle
*
EvaluationCycle
)
(
*
EvaluationCycle
,
error
)
Remove
(
cycle
*
EvaluationCycle
)
(
*
EvaluationCycle
,
error
)
FindOne
(
queryOptions
map
[
string
]
interface
{})
(
*
EvaluationCycle
,
error
)
Find
(
queryOptions
map
[
string
]
interface
{})
(
int64
,
[]
*
EvaluationCycle
,
error
)
Count
(
queryOptions
map
[
string
]
interface
{})
(
int64
,
error
)
}
...
...
pkg/domain/evaluation_project.go
查看文件 @
3f70182
...
...
@@ -18,3 +18,11 @@ type EvaluationProject struct {
UpdatedAt
time
.
Time
`json:"updatedAt" comment:"更新时间"`
DeletedAt
*
time
.
Time
`json:"deletedAt" comment:"删除时间"`
}
type
EvaluationProjectRepository
interface
{
Insert
(
project
*
EvaluationProject
)
(
*
EvaluationProject
,
error
)
Remove
(
project
*
EvaluationProject
)
(
*
EvaluationProject
,
error
)
FindOne
(
queryOptions
map
[
string
]
interface
{})
(
*
EvaluationProject
,
error
)
Find
(
queryOptions
map
[
string
]
interface
{})
(
int64
,
[]
*
EvaluationProject
,
error
)
Count
(
queryOptions
map
[
string
]
interface
{})
(
int64
,
error
)
}
...
...
pkg/domain/evaluation_rule.go
查看文件 @
3f70182
...
...
@@ -10,7 +10,7 @@ const (
)
type
Rating
struct
{
Levels
[]
RatingLevel
`comment:"配置等级"`
Levels
[]
RatingLevel
`
json:"levels"
comment:"配置等级"`
}
type
RatingLevel
struct
{
...
...
@@ -48,3 +48,11 @@ type EvaluationRule struct {
UpdatedAt
time
.
Time
`json:"updatedAt" comment:"更新时间"`
DeletedAt
*
time
.
Time
`json:"deletedAt" comment:"删除时间"`
}
type
EvaluationRuleRepository
interface
{
Insert
(
rule
*
EvaluationRule
)
(
*
EvaluationRule
,
error
)
Remove
(
rule
*
EvaluationRule
)
(
*
EvaluationRule
,
error
)
FindOne
(
queryOptions
map
[
string
]
interface
{})
(
*
EvaluationRule
,
error
)
Find
(
queryOptions
map
[
string
]
interface
{})
(
int64
,
[]
*
EvaluationRule
,
error
)
Count
(
queryOptions
map
[
string
]
interface
{})
(
int64
,
error
)
}
...
...
pkg/domain/evaluation_template.go
查看文件 @
3f70182
...
...
@@ -68,6 +68,13 @@ type EvaluationTemplate struct {
CreatedAt
time
.
Time
`json:"createdAt" comment:"创建时间"`
UpdatedAt
time
.
Time
`json:"updatedAt" comment:"更新时间"`
DeletedAt
*
time
.
Time
`json:"deletedAt" comment:"删除时间"`
//Link EvaluationLink `json:"link" comment:"评估流程"`
}
type
EvaluationTemplateRepository
interface
{
Insert
(
template
*
EvaluationTemplate
)
(
*
EvaluationTemplate
,
error
)
Remove
(
template
*
EvaluationTemplate
)
(
*
EvaluationTemplate
,
error
)
FindOne
(
queryOptions
map
[
string
]
interface
{})
(
*
EvaluationTemplate
,
error
)
Find
(
queryOptions
map
[
string
]
interface
{})
(
int64
,
[]
*
EvaluationTemplate
,
error
)
Count
(
queryOptions
map
[
string
]
interface
{})
(
int64
,
error
)
}
...
...
pkg/infrastructure/pg/models/evaluation_cycle.go
查看文件 @
3f70182
package
models
import
(
"gitlab.fjmaimaimai.com/allied-creation/performance/pkg/domain"
"time"
)
type
EvaluationCycle
struct
{
tableName
struct
{}
`pg:"evaluation_cycle" comment:"评估周期"`
Id
int64
`pg:"pk:id" comment:"周期ID"`
Name
string
`comment:"名称"`
TimeStart
*
time
.
Time
`comment:"起始时间"`
TimeEnd
*
time
.
Time
`comment:"截至时间"`
CompanyId
int64
`comment:"公司ID"`
CreatorId
int64
`comment:"创建人ID"`
KpiCycle
int
`comment:"考核周期(0日、1周、2月)"`
Template
[]
EvaluationTemplate
`comment:"周期使用模板"`
CreatedAt
time
.
Time
`comment:"创建时间"`
UpdatedAt
time
.
Time
`comment:"更新时间"`
DeletedAt
*
time
.
Time
`comment:"删除时间"`
tableName
struct
{}
`pg:"evaluation_cycle" comment:"评估周期"`
Id
int64
`pg:"pk:id" comment:"周期ID"`
Name
string
`comment:"名称"`
TimeStart
*
time
.
Time
`comment:"起始时间"`
TimeEnd
*
time
.
Time
`comment:"截至时间"`
CompanyId
int64
`comment:"公司ID"`
CreatorId
int64
`comment:"创建人ID"`
KpiCycle
int
`comment:"考核周期(0日、1周、2月)"`
Template
[]
domain
.
EvaluationTemplate
`comment:"周期使用模板"`
CreatedAt
time
.
Time
`comment:"创建时间"`
UpdatedAt
time
.
Time
`comment:"更新时间"`
DeletedAt
*
time
.
Time
`comment:"删除时间"`
}
...
...
pkg/infrastructure/pg/models/evaluation_project.go
查看文件 @
3f70182
package
models
import
(
"gitlab.fjmaimaimai.com/allied-creation/performance/pkg/domain"
"time"
)
type
EvaluationProject
struct
{
tableName
struct
{}
`pg:"evaluation_project" comment:"评估项目"`
Id
int64
`pg:"pk:id" comment:"ID"`
Name
string
`comment:"名称"`
Describe
string
`comment:"描述"`
CompanyId
int64
`comment:"公司ID"`
CreatorId
int64
`comment:"创建人ID"`
HrBp
int
`comment:"HR角色权限"`
Pms
[]
string
`comment:"项目管理员ID"`
Recipients
[]
string
`comment:"被评估人ID"`
Template
*
EvaluationTemplate
`comment:"评估模板"`
CreatedAt
time
.
Time
`comment:"创建时间"`
UpdatedAt
time
.
Time
`comment:"更新时间"`
DeletedAt
*
time
.
Time
`comment:"删除时间"`
tableName
struct
{}
`pg:"evaluation_project" comment:"评估项目"`
Id
int64
`pg:"pk:id" comment:"ID"`
Name
string
`comment:"名称"`
Describe
string
`comment:"描述"`
CompanyId
int64
`comment:"公司ID"`
CreatorId
int64
`comment:"创建人ID"`
HrBp
int
`comment:"HR角色权限"`
Pms
[]
string
`comment:"项目管理员ID"`
Recipients
[]
string
`comment:"被评估人ID"`
Template
*
domain
.
EvaluationTemplate
`comment:"评估模板"`
CreatedAt
time
.
Time
`comment:"创建时间"`
UpdatedAt
time
.
Time
`comment:"更新时间"`
DeletedAt
*
time
.
Time
`comment:"删除时间"`
}
...
...
pkg/infrastructure/repository/pg_evaluation_cycle_repository.go
0 → 100644
查看文件 @
3f70182
package
repository
import
(
"errors"
"fmt"
"github.com/go-pg/pg/v10"
"github.com/linmadan/egglib-go/persistent/pg/sqlbuilder"
pgTransaction
"github.com/linmadan/egglib-go/transaction/pg"
"gitlab.fjmaimaimai.com/allied-creation/performance/pkg/domain"
"gitlab.fjmaimaimai.com/allied-creation/performance/pkg/infrastructure/pg/models"
"gitlab.fjmaimaimai.com/allied-creation/performance/pkg/utils"
"time"
)
type
EvaluationCycleRepository
struct
{
transactionContext
*
pgTransaction
.
TransactionContext
}
func
NewEvaluationCycleRepository
(
transactionContext
*
pgTransaction
.
TransactionContext
)
*
EvaluationCycleRepository
{
return
&
EvaluationCycleRepository
{
transactionContext
:
transactionContext
}
}
func
(
repo
*
EvaluationCycleRepository
)
TransformToDomain
(
m
*
models
.
EvaluationCycle
)
domain
.
EvaluationCycle
{
return
domain
.
EvaluationCycle
{
Id
:
m
.
Id
,
Name
:
m
.
Name
,
TimeStart
:
m
.
TimeStart
,
TimeEnd
:
m
.
TimeEnd
,
CompanyId
:
m
.
CompanyId
,
CreatorId
:
m
.
CreatorId
,
KpiCycle
:
m
.
KpiCycle
,
Template
:
m
.
Template
,
CreatedAt
:
m
.
CreatedAt
,
UpdatedAt
:
m
.
UpdatedAt
,
DeletedAt
:
m
.
DeletedAt
,
}
}
func
(
repo
*
EvaluationCycleRepository
)
TransformToModel
(
d
*
domain
.
EvaluationCycle
)
models
.
EvaluationCycle
{
return
models
.
EvaluationCycle
{
Id
:
d
.
Id
,
Name
:
d
.
Name
,
TimeStart
:
d
.
TimeStart
,
TimeEnd
:
d
.
TimeEnd
,
CompanyId
:
d
.
CompanyId
,
CreatorId
:
d
.
CreatorId
,
KpiCycle
:
d
.
KpiCycle
,
Template
:
d
.
Template
,
CreatedAt
:
d
.
CreatedAt
,
UpdatedAt
:
d
.
UpdatedAt
,
DeletedAt
:
d
.
DeletedAt
,
}
}
func
(
repo
*
EvaluationCycleRepository
)
nextIdentify
()
(
int64
,
error
)
{
return
utils
.
NewSnowflakeId
()
}
func
(
repo
*
EvaluationCycleRepository
)
Insert
(
d
*
domain
.
EvaluationCycle
)
(
*
domain
.
EvaluationCycle
,
error
)
{
var
isCreate
=
d
.
Id
==
0
if
isCreate
{
id
,
err
:=
repo
.
nextIdentify
()
if
err
!=
nil
{
return
d
,
err
}
d
.
Id
=
id
d
.
CreatedAt
=
time
.
Now
()
d
.
UpdatedAt
=
d
.
CreatedAt
}
else
{
d
.
UpdatedAt
=
time
.
Now
()
}
m
:=
repo
.
TransformToModel
(
d
)
tx
:=
repo
.
transactionContext
.
PgTx
var
err
error
if
isCreate
{
_
,
err
=
tx
.
Model
(
&
m
)
.
Returning
(
"id"
)
.
Insert
()
}
else
{
_
,
err
=
tx
.
Model
(
&
m
)
.
Returning
(
"id"
)
.
WherePK
()
.
Update
()
// 更新和删除必须增加条件
}
if
err
!=
nil
{
return
nil
,
err
}
d
.
Id
=
m
.
Id
return
d
,
nil
}
func
(
repo
*
EvaluationCycleRepository
)
Remove
(
d
*
domain
.
EvaluationCycle
)
(
*
domain
.
EvaluationCycle
,
error
)
{
tx
:=
repo
.
transactionContext
.
PgTx
nowTime
:=
time
.
Now
()
m
:=
repo
.
TransformToModel
(
d
)
m
.
DeletedAt
=
&
nowTime
if
_
,
err
:=
tx
.
Model
(
&
m
)
.
WherePK
()
.
Update
();
err
!=
nil
{
return
d
,
err
}
return
d
,
nil
}
func
(
repo
*
EvaluationCycleRepository
)
FindOne
(
queryOptions
map
[
string
]
interface
{})
(
*
domain
.
EvaluationCycle
,
error
)
{
tx
:=
repo
.
transactionContext
.
PgTx
m
:=
new
(
models
.
EvaluationCycle
)
query
:=
tx
.
Model
(
m
)
query
.
Where
(
"deleted_at isnull"
)
if
id
,
ok
:=
queryOptions
[
"id"
];
ok
{
query
.
Where
(
"id=?"
,
id
)
}
if
err
:=
query
.
First
();
err
!=
nil
{
if
errors
.
Is
(
err
,
pg
.
ErrNoRows
)
{
return
nil
,
fmt
.
Errorf
(
"没有此资源"
)
}
else
{
return
nil
,
err
}
}
u
:=
repo
.
TransformToDomain
(
m
)
return
&
u
,
nil
}
func
(
repo
*
EvaluationCycleRepository
)
Find
(
queryOptions
map
[
string
]
interface
{})
(
int64
,
[]
*
domain
.
EvaluationCycle
,
error
)
{
tx
:=
repo
.
transactionContext
.
PgTx
var
m
[]
*
models
.
EvaluationCycle
query
:=
tx
.
Model
(
&
m
)
.
Where
(
"deleted_at isnull"
)
.
Limit
(
20
)
if
name
,
ok
:=
queryOptions
[
"name"
];
ok
{
query
.
Where
(
"name = ?"
,
name
)
}
if
companyId
,
ok
:=
queryOptions
[
"companyId"
];
ok
{
query
.
Where
(
"company_id = ?"
,
companyId
)
}
if
v
,
ok
:=
queryOptions
[
"limit"
]
.
(
int
);
ok
{
query
.
Limit
(
v
)
}
if
v
,
ok
:=
queryOptions
[
"offset"
]
.
(
int
);
ok
{
query
.
Offset
(
v
)
}
count
,
err
:=
query
.
SelectAndCount
()
if
err
!=
nil
{
return
0
,
nil
,
err
}
var
arrays
[]
*
domain
.
EvaluationCycle
for
_
,
v
:=
range
m
{
d
:=
repo
.
TransformToDomain
(
v
)
arrays
=
append
(
arrays
,
&
d
)
}
return
int64
(
count
),
arrays
,
nil
}
func
(
repo
*
EvaluationCycleRepository
)
Count
(
queryOptions
map
[
string
]
interface
{})
(
int64
,
error
)
{
tx
:=
repo
.
transactionContext
.
PgTx
m
:=
new
(
models
.
EvaluationCycle
)
query
:=
sqlbuilder
.
BuildQuery
(
tx
.
Model
(
m
),
queryOptions
)
query
.
Where
(
"deleted_at isnull"
)
if
id
,
ok
:=
queryOptions
[
"id"
];
ok
{
query
.
Where
(
"id = ?"
,
id
)
}
if
notId
,
ok
:=
queryOptions
[
"notId"
];
ok
{
query
.
Where
(
"id != ?"
,
notId
)
}
if
name
,
ok
:=
queryOptions
[
"name"
];
ok
{
query
.
Where
(
"name = ?"
,
name
)
}
if
companyId
,
ok
:=
queryOptions
[
"companyId"
];
ok
{
query
.
Where
(
"company_id = ?"
,
companyId
)
}
count
,
err
:=
query
.
Count
()
if
err
!=
nil
{
return
0
,
err
}
return
int64
(
count
),
nil
}
...
...
pkg/infrastructure/repository/pg_evaluation_project_repository.go
0 → 100644
查看文件 @
3f70182
package
repository
import
(
"errors"
"fmt"
"github.com/go-pg/pg/v10"
"github.com/linmadan/egglib-go/persistent/pg/sqlbuilder"
pgTransaction
"github.com/linmadan/egglib-go/transaction/pg"
"gitlab.fjmaimaimai.com/allied-creation/performance/pkg/domain"
"gitlab.fjmaimaimai.com/allied-creation/performance/pkg/infrastructure/pg/models"
"gitlab.fjmaimaimai.com/allied-creation/performance/pkg/utils"
"time"
)
type
EvaluationProjectRepository
struct
{
transactionContext
*
pgTransaction
.
TransactionContext
}
func
NewEvaluationProjectRepository
(
transactionContext
*
pgTransaction
.
TransactionContext
)
*
EvaluationProjectRepository
{
return
&
EvaluationProjectRepository
{
transactionContext
:
transactionContext
}
}
func
(
repo
*
EvaluationProjectRepository
)
TransformToDomain
(
m
*
models
.
EvaluationProject
)
domain
.
EvaluationProject
{
return
domain
.
EvaluationProject
{
Id
:
m
.
Id
,
Name
:
m
.
Name
,
Describe
:
m
.
Describe
,
CompanyId
:
m
.
CompanyId
,
CreatorId
:
m
.
CreatorId
,
HrBp
:
m
.
HrBp
,
Pms
:
m
.
Pms
,
Recipients
:
m
.
Recipients
,
Template
:
m
.
Template
,
CreatedAt
:
m
.
CreatedAt
,
UpdatedAt
:
m
.
UpdatedAt
,
DeletedAt
:
m
.
DeletedAt
,
}
}
func
(
repo
*
EvaluationProjectRepository
)
TransformToModel
(
d
*
domain
.
EvaluationProject
)
models
.
EvaluationProject
{
return
models
.
EvaluationProject
{
Id
:
d
.
Id
,
Name
:
d
.
Name
,
Describe
:
d
.
Describe
,
CompanyId
:
d
.
CompanyId
,
CreatorId
:
d
.
CreatorId
,
HrBp
:
d
.
HrBp
,
Pms
:
d
.
Pms
,
Recipients
:
d
.
Recipients
,
Template
:
d
.
Template
,
CreatedAt
:
d
.
CreatedAt
,
UpdatedAt
:
d
.
UpdatedAt
,
DeletedAt
:
d
.
DeletedAt
,
}
}
func
(
repo
*
EvaluationProjectRepository
)
nextIdentify
()
(
int64
,
error
)
{
return
utils
.
NewSnowflakeId
()
}
func
(
repo
*
EvaluationProjectRepository
)
Insert
(
d
*
domain
.
EvaluationProject
)
(
*
domain
.
EvaluationProject
,
error
)
{
var
isCreate
=
d
.
Id
==
0
if
isCreate
{
id
,
err
:=
repo
.
nextIdentify
()
if
err
!=
nil
{
return
d
,
err
}
d
.
Id
=
id
d
.
CreatedAt
=
time
.
Now
()
d
.
UpdatedAt
=
d
.
CreatedAt
}
else
{
d
.
UpdatedAt
=
time
.
Now
()
}
m
:=
repo
.
TransformToModel
(
d
)
tx
:=
repo
.
transactionContext
.
PgTx
var
err
error
if
isCreate
{
_
,
err
=
tx
.
Model
(
&
m
)
.
Returning
(
"id"
)
.
Insert
()
}
else
{
_
,
err
=
tx
.
Model
(
&
m
)
.
Returning
(
"id"
)
.
WherePK
()
.
Update
()
// 更新和删除必须增加条件
}
if
err
!=
nil
{
return
nil
,
err
}
d
.
Id
=
m
.
Id
return
d
,
nil
}
func
(
repo
*
EvaluationProjectRepository
)
Remove
(
d
*
domain
.
EvaluationProject
)
(
*
domain
.
EvaluationProject
,
error
)
{
tx
:=
repo
.
transactionContext
.
PgTx
nowTime
:=
time
.
Now
()
m
:=
repo
.
TransformToModel
(
d
)
m
.
DeletedAt
=
&
nowTime
if
_
,
err
:=
tx
.
Model
(
&
m
)
.
WherePK
()
.
Update
();
err
!=
nil
{
return
d
,
err
}
return
d
,
nil
}
func
(
repo
*
EvaluationProjectRepository
)
FindOne
(
queryOptions
map
[
string
]
interface
{})
(
*
domain
.
EvaluationProject
,
error
)
{
tx
:=
repo
.
transactionContext
.
PgTx
m
:=
new
(
models
.
EvaluationProject
)
query
:=
tx
.
Model
(
m
)
query
.
Where
(
"deleted_at isnull"
)
if
id
,
ok
:=
queryOptions
[
"id"
];
ok
{
query
.
Where
(
"id=?"
,
id
)
}
if
err
:=
query
.
First
();
err
!=
nil
{
if
errors
.
Is
(
err
,
pg
.
ErrNoRows
)
{
return
nil
,
fmt
.
Errorf
(
"没有此资源"
)
}
else
{
return
nil
,
err
}
}
u
:=
repo
.
TransformToDomain
(
m
)
return
&
u
,
nil
}
func
(
repo
*
EvaluationProjectRepository
)
Find
(
queryOptions
map
[
string
]
interface
{})
(
int64
,
[]
*
domain
.
EvaluationProject
,
error
)
{
tx
:=
repo
.
transactionContext
.
PgTx
var
m
[]
*
models
.
EvaluationProject
query
:=
tx
.
Model
(
&
m
)
.
Where
(
"deleted_at isnull"
)
.
Limit
(
20
)
if
name
,
ok
:=
queryOptions
[
"name"
];
ok
{
query
.
Where
(
"name = ?"
,
name
)
}
if
companyId
,
ok
:=
queryOptions
[
"companyId"
];
ok
{
query
.
Where
(
"company_id = ?"
,
companyId
)
}
if
v
,
ok
:=
queryOptions
[
"limit"
]
.
(
int
);
ok
{
query
.
Limit
(
v
)
}
if
v
,
ok
:=
queryOptions
[
"offset"
]
.
(
int
);
ok
{
query
.
Offset
(
v
)
}
count
,
err
:=
query
.
SelectAndCount
()
if
err
!=
nil
{
return
0
,
nil
,
err
}
var
arrays
[]
*
domain
.
EvaluationProject
for
_
,
v
:=
range
m
{
d
:=
repo
.
TransformToDomain
(
v
)
arrays
=
append
(
arrays
,
&
d
)
}
return
int64
(
count
),
arrays
,
nil
}
func
(
repo
*
EvaluationProjectRepository
)
Count
(
queryOptions
map
[
string
]
interface
{})
(
int64
,
error
)
{
tx
:=
repo
.
transactionContext
.
PgTx
m
:=
new
(
models
.
EvaluationProject
)
query
:=
sqlbuilder
.
BuildQuery
(
tx
.
Model
(
m
),
queryOptions
)
query
.
Where
(
"deleted_at isnull"
)
if
id
,
ok
:=
queryOptions
[
"id"
];
ok
{
query
.
Where
(
"id = ?"
,
id
)
}
if
notId
,
ok
:=
queryOptions
[
"notId"
];
ok
{
query
.
Where
(
"id != ?"
,
notId
)
}
if
name
,
ok
:=
queryOptions
[
"name"
];
ok
{
query
.
Where
(
"name = ?"
,
name
)
}
if
companyId
,
ok
:=
queryOptions
[
"companyId"
];
ok
{
query
.
Where
(
"company_id = ?"
,
companyId
)
}
count
,
err
:=
query
.
Count
()
if
err
!=
nil
{
return
0
,
err
}
return
int64
(
count
),
nil
}
...
...
pkg/infrastructure/repository/pg_evaluation_rule_repository.go
0 → 100644
查看文件 @
3f70182
package
repository
import
(
"errors"
"fmt"
"github.com/go-pg/pg/v10"
"github.com/linmadan/egglib-go/persistent/pg/sqlbuilder"
pgTransaction
"github.com/linmadan/egglib-go/transaction/pg"
"gitlab.fjmaimaimai.com/allied-creation/performance/pkg/domain"
"gitlab.fjmaimaimai.com/allied-creation/performance/pkg/infrastructure/pg/models"
"gitlab.fjmaimaimai.com/allied-creation/performance/pkg/utils"
"time"
)
type
EvaluationRuleRepository
struct
{
transactionContext
*
pgTransaction
.
TransactionContext
}
func
NewEvaluationRuleRepository
(
transactionContext
*
pgTransaction
.
TransactionContext
)
*
EvaluationRuleRepository
{
return
&
EvaluationRuleRepository
{
transactionContext
:
transactionContext
}
}
func
(
repo
*
EvaluationRuleRepository
)
TransformToDomain
(
m
*
models
.
EvaluationRule
)
domain
.
EvaluationRule
{
return
domain
.
EvaluationRule
{
Id
:
m
.
Id
,
Name
:
m
.
Name
,
Remark
:
m
.
Remark
,
CompanyId
:
m
.
CompanyId
,
CreatorId
:
m
.
CreatorId
,
Type
:
m
.
Type
,
Rating
:
m
.
Rating
,
Score
:
m
.
Score
,
CreatedAt
:
m
.
CreatedAt
,
UpdatedAt
:
m
.
UpdatedAt
,
DeletedAt
:
m
.
DeletedAt
,
}
}
func
(
repo
*
EvaluationRuleRepository
)
TransformToModel
(
d
*
domain
.
EvaluationRule
)
models
.
EvaluationRule
{
return
models
.
EvaluationRule
{
Id
:
d
.
Id
,
Name
:
d
.
Name
,
Remark
:
d
.
Remark
,
CompanyId
:
d
.
CompanyId
,
CreatorId
:
d
.
CreatorId
,
Type
:
d
.
Type
,
Rating
:
d
.
Rating
,
Score
:
d
.
Score
,
CreatedAt
:
d
.
CreatedAt
,
UpdatedAt
:
d
.
UpdatedAt
,
DeletedAt
:
d
.
DeletedAt
,
}
}
func
(
repo
*
EvaluationRuleRepository
)
nextIdentify
()
(
int64
,
error
)
{
return
utils
.
NewSnowflakeId
()
}
func
(
repo
*
EvaluationRuleRepository
)
Insert
(
d
*
domain
.
EvaluationRule
)
(
*
domain
.
EvaluationRule
,
error
)
{
var
isCreate
=
d
.
Id
==
0
if
isCreate
{
id
,
err
:=
repo
.
nextIdentify
()
if
err
!=
nil
{
return
d
,
err
}
d
.
Id
=
id
d
.
CreatedAt
=
time
.
Now
()
d
.
UpdatedAt
=
d
.
CreatedAt
}
else
{
d
.
UpdatedAt
=
time
.
Now
()
}
m
:=
repo
.
TransformToModel
(
d
)
tx
:=
repo
.
transactionContext
.
PgTx
var
err
error
if
isCreate
{
_
,
err
=
tx
.
Model
(
&
m
)
.
Returning
(
"id"
)
.
Insert
()
}
else
{
_
,
err
=
tx
.
Model
(
&
m
)
.
Returning
(
"id"
)
.
WherePK
()
.
Update
()
// 更新和删除必须增加条件
}
if
err
!=
nil
{
return
nil
,
err
}
d
.
Id
=
m
.
Id
return
d
,
nil
}
func
(
repo
*
EvaluationRuleRepository
)
Remove
(
d
*
domain
.
EvaluationRule
)
(
*
domain
.
EvaluationRule
,
error
)
{
tx
:=
repo
.
transactionContext
.
PgTx
nowTime
:=
time
.
Now
()
m
:=
repo
.
TransformToModel
(
d
)
m
.
DeletedAt
=
&
nowTime
if
_
,
err
:=
tx
.
Model
(
&
m
)
.
WherePK
()
.
Update
();
err
!=
nil
{
return
d
,
err
}
return
d
,
nil
}
func
(
repo
*
EvaluationRuleRepository
)
FindOne
(
queryOptions
map
[
string
]
interface
{})
(
*
domain
.
EvaluationRule
,
error
)
{
tx
:=
repo
.
transactionContext
.
PgTx
m
:=
new
(
models
.
EvaluationRule
)
query
:=
tx
.
Model
(
m
)
query
.
Where
(
"deleted_at isnull"
)
if
id
,
ok
:=
queryOptions
[
"id"
];
ok
{
query
.
Where
(
"id=?"
,
id
)
}
if
err
:=
query
.
First
();
err
!=
nil
{
if
errors
.
Is
(
err
,
pg
.
ErrNoRows
)
{
return
nil
,
fmt
.
Errorf
(
"没有此资源"
)
}
else
{
return
nil
,
err
}
}
u
:=
repo
.
TransformToDomain
(
m
)
return
&
u
,
nil
}
func
(
repo
*
EvaluationRuleRepository
)
Find
(
queryOptions
map
[
string
]
interface
{})
(
int64
,
[]
*
domain
.
EvaluationRule
,
error
)
{
tx
:=
repo
.
transactionContext
.
PgTx
var
m
[]
*
models
.
EvaluationRule
query
:=
tx
.
Model
(
&
m
)
.
Where
(
"deleted_at isnull"
)
.
Limit
(
20
)
if
name
,
ok
:=
queryOptions
[
"name"
];
ok
{
query
.
Where
(
"name = ?"
,
name
)
}
if
companyId
,
ok
:=
queryOptions
[
"companyId"
];
ok
{
query
.
Where
(
"company_id = ?"
,
companyId
)
}
if
v
,
ok
:=
queryOptions
[
"limit"
]
.
(
int
);
ok
{
query
.
Limit
(
v
)
}
if
v
,
ok
:=
queryOptions
[
"offset"
]
.
(
int
);
ok
{
query
.
Offset
(
v
)
}
query
.
Count
()
count
,
err
:=
query
.
SelectAndCount
()
if
err
!=
nil
{
return
0
,
nil
,
err
}
var
arrays
[]
*
domain
.
EvaluationRule
for
_
,
v
:=
range
m
{
d
:=
repo
.
TransformToDomain
(
v
)
arrays
=
append
(
arrays
,
&
d
)
}
return
int64
(
count
),
arrays
,
nil
}
func
(
repo
*
EvaluationRuleRepository
)
Count
(
queryOptions
map
[
string
]
interface
{})
(
int64
,
error
)
{
tx
:=
repo
.
transactionContext
.
PgTx
m
:=
new
(
models
.
EvaluationRule
)
query
:=
sqlbuilder
.
BuildQuery
(
tx
.
Model
(
m
),
queryOptions
)
query
.
Where
(
"deleted_at isnull"
)
if
id
,
ok
:=
queryOptions
[
"id"
];
ok
{
query
.
Where
(
"id = ?"
,
id
)
}
if
notId
,
ok
:=
queryOptions
[
"notId"
];
ok
{
query
.
Where
(
"id != ?"
,
notId
)
}
if
name
,
ok
:=
queryOptions
[
"name"
];
ok
{
query
.
Where
(
"name = ?"
,
name
)
}
if
companyId
,
ok
:=
queryOptions
[
"companyId"
];
ok
{
query
.
Where
(
"company_id = ?"
,
companyId
)
}
count
,
err
:=
query
.
Count
()
if
err
!=
nil
{
return
0
,
err
}
return
int64
(
count
),
nil
}
...
...
pkg/infrastructure/repository/pg_evaluation_template_repository.go
0 → 100644
查看文件 @
3f70182
package
repository
import
(
"errors"
"fmt"
"github.com/go-pg/pg/v10"
"github.com/linmadan/egglib-go/persistent/pg/sqlbuilder"
pgTransaction
"github.com/linmadan/egglib-go/transaction/pg"
"gitlab.fjmaimaimai.com/allied-creation/performance/pkg/domain"
"gitlab.fjmaimaimai.com/allied-creation/performance/pkg/infrastructure/pg/models"
"gitlab.fjmaimaimai.com/allied-creation/performance/pkg/utils"
"time"
)
type
EvaluationTemplateRepository
struct
{
transactionContext
*
pgTransaction
.
TransactionContext
}
func
NewEvaluationTemplateRepository
(
transactionContext
*
pgTransaction
.
TransactionContext
)
*
EvaluationTemplateRepository
{
return
&
EvaluationTemplateRepository
{
transactionContext
:
transactionContext
}
}
func
(
repo
*
EvaluationTemplateRepository
)
TransformToDomain
(
m
*
models
.
EvaluationTemplate
)
domain
.
EvaluationTemplate
{
return
domain
.
EvaluationTemplate
{
Id
:
m
.
Id
,
Name
:
m
.
Name
,
Describe
:
m
.
Describe
,
CompanyId
:
m
.
CompanyId
,
CreatorId
:
m
.
CreatorId
,
State
:
m
.
State
,
Link
:
m
.
Link
,
CreatedAt
:
m
.
CreatedAt
,
UpdatedAt
:
m
.
UpdatedAt
,
DeletedAt
:
m
.
DeletedAt
,
}
}
func
(
repo
*
EvaluationTemplateRepository
)
TransformToModel
(
d
*
domain
.
EvaluationTemplate
)
models
.
EvaluationTemplate
{
return
models
.
EvaluationTemplate
{
Id
:
d
.
Id
,
Name
:
d
.
Name
,
Describe
:
d
.
Describe
,
CompanyId
:
d
.
CompanyId
,
CreatorId
:
d
.
CreatorId
,
State
:
d
.
State
,
Link
:
d
.
Link
,
CreatedAt
:
d
.
CreatedAt
,
UpdatedAt
:
d
.
UpdatedAt
,
DeletedAt
:
d
.
DeletedAt
,
}
}
func
(
repo
*
EvaluationTemplateRepository
)
nextIdentify
()
(
int64
,
error
)
{
return
utils
.
NewSnowflakeId
()
}
func
(
repo
*
EvaluationTemplateRepository
)
Insert
(
d
*
domain
.
EvaluationTemplate
)
(
*
domain
.
EvaluationTemplate
,
error
)
{
var
isCreate
=
d
.
Id
==
0
if
isCreate
{
id
,
err
:=
repo
.
nextIdentify
()
if
err
!=
nil
{
return
d
,
err
}
d
.
Id
=
id
d
.
CreatedAt
=
time
.
Now
()
d
.
UpdatedAt
=
d
.
CreatedAt
}
else
{
d
.
UpdatedAt
=
time
.
Now
()
}
m
:=
repo
.
TransformToModel
(
d
)
tx
:=
repo
.
transactionContext
.
PgTx
var
err
error
if
isCreate
{
_
,
err
=
tx
.
Model
(
&
m
)
.
Returning
(
"id"
)
.
Insert
()
}
else
{
_
,
err
=
tx
.
Model
(
&
m
)
.
Returning
(
"id"
)
.
WherePK
()
.
Update
()
// 更新和删除必须增加条件
}
if
err
!=
nil
{
return
nil
,
err
}
d
.
Id
=
m
.
Id
return
d
,
nil
}
func
(
repo
*
EvaluationTemplateRepository
)
Remove
(
d
*
domain
.
EvaluationTemplate
)
(
*
domain
.
EvaluationTemplate
,
error
)
{
tx
:=
repo
.
transactionContext
.
PgTx
nowTime
:=
time
.
Now
()
m
:=
repo
.
TransformToModel
(
d
)
m
.
DeletedAt
=
&
nowTime
if
_
,
err
:=
tx
.
Model
(
&
m
)
.
WherePK
()
.
Update
();
err
!=
nil
{
return
d
,
err
}
return
d
,
nil
}
func
(
repo
*
EvaluationTemplateRepository
)
FindOne
(
queryOptions
map
[
string
]
interface
{})
(
*
domain
.
EvaluationTemplate
,
error
)
{
tx
:=
repo
.
transactionContext
.
PgTx
m
:=
new
(
models
.
EvaluationTemplate
)
query
:=
tx
.
Model
(
m
)
query
.
Where
(
"deleted_at isnull"
)
if
id
,
ok
:=
queryOptions
[
"id"
];
ok
{
query
.
Where
(
"id=?"
,
id
)
}
if
err
:=
query
.
First
();
err
!=
nil
{
if
errors
.
Is
(
err
,
pg
.
ErrNoRows
)
{
return
nil
,
fmt
.
Errorf
(
"没有此资源"
)
}
else
{
return
nil
,
err
}
}
u
:=
repo
.
TransformToDomain
(
m
)
return
&
u
,
nil
}
func
(
repo
*
EvaluationTemplateRepository
)
Find
(
queryOptions
map
[
string
]
interface
{})
(
int64
,
[]
*
domain
.
EvaluationTemplate
,
error
)
{
tx
:=
repo
.
transactionContext
.
PgTx
var
m
[]
*
models
.
EvaluationTemplate
query
:=
tx
.
Model
(
&
m
)
.
Where
(
"deleted_at isnull"
)
.
Limit
(
20
)
if
name
,
ok
:=
queryOptions
[
"name"
];
ok
{
query
.
Where
(
"name = ?"
,
name
)
}
if
companyId
,
ok
:=
queryOptions
[
"companyId"
];
ok
{
query
.
Where
(
"company_id = ?"
,
companyId
)
}
if
v
,
ok
:=
queryOptions
[
"limit"
]
.
(
int
);
ok
{
query
.
Limit
(
v
)
}
if
v
,
ok
:=
queryOptions
[
"offset"
]
.
(
int
);
ok
{
query
.
Offset
(
v
)
}
count
,
err
:=
query
.
SelectAndCount
()
if
err
!=
nil
{
return
0
,
nil
,
err
}
var
arrays
[]
*
domain
.
EvaluationTemplate
for
_
,
v
:=
range
m
{
d
:=
repo
.
TransformToDomain
(
v
)
arrays
=
append
(
arrays
,
&
d
)
}
return
int64
(
count
),
arrays
,
nil
}
func
(
repo
*
EvaluationTemplateRepository
)
Count
(
queryOptions
map
[
string
]
interface
{})
(
int64
,
error
)
{
tx
:=
repo
.
transactionContext
.
PgTx
m
:=
new
(
models
.
EvaluationTemplate
)
query
:=
sqlbuilder
.
BuildQuery
(
tx
.
Model
(
m
),
queryOptions
)
query
.
Where
(
"deleted_at isnull"
)
if
id
,
ok
:=
queryOptions
[
"id"
];
ok
{
query
.
Where
(
"id = ?"
,
id
)
}
if
notId
,
ok
:=
queryOptions
[
"notId"
];
ok
{
query
.
Where
(
"id != ?"
,
notId
)
}
if
name
,
ok
:=
queryOptions
[
"name"
];
ok
{
query
.
Where
(
"name = ?"
,
name
)
}
if
companyId
,
ok
:=
queryOptions
[
"companyId"
];
ok
{
query
.
Where
(
"company_id = ?"
,
companyId
)
}
count
,
err
:=
query
.
Count
()
if
err
!=
nil
{
return
0
,
err
}
return
int64
(
count
),
nil
}
...
...
请
注册
或
登录
后发表评论