作者 郑周

评估规则 开发

... ... @@ -249,10 +249,9 @@ func (rs *EvaluationCycleService) List(in *command.QueryCycleCommand) (interface
transactionContext.RollbackTransaction()
}()
cycleRepository := factory.CreateEvaluationCycleRepository(map[string]interface{}{"transactionContext": transactionContext})
// FIXME 总数量是否使用Count获取一个总数量
count, cycles, err := cycleRepository.Find(tool_funs.SimpleStructToMap(in))
total, cycles, err := cycleRepository.Find(tool_funs.SimpleStructToMap(in))
if err != nil {
return nil, application.ThrowError(application.INTERNAL_SERVER_ERROR, err.Error())
}
return tool_funs.SimpleWrapGridMap(count, cycles), nil
return tool_funs.SimpleWrapGridMap(total, cycles), nil
}
... ...
... ... @@ -268,8 +268,7 @@ func (rs *EvaluationProjectService) List(in *command.QueryProjectCommand) (inter
}()
projectRepository := factory.CreateEvaluationProjectRepository(map[string]interface{}{"transactionContext": transactionContext})
// FIXME 总数量是否使用Count获取一个总数量
count, projects, err := projectRepository.Find(tool_funs.SimpleStructToMap(in), "linkNodes")
total, projects, err := projectRepository.Find(tool_funs.SimpleStructToMap(in), "linkNodes")
if err != nil {
return nil, application.ThrowError(application.INTERNAL_SERVER_ERROR, err.Error())
}
... ... @@ -288,7 +287,7 @@ func (rs *EvaluationProjectService) List(in *command.QueryProjectCommand) (inter
pmpUsers = users
}
projectAdapters := adapter.TransformProjectListAdapter(projects, pmpUsers)
return tool_funs.SimpleWrapGridMap(count, projectAdapters), nil
return tool_funs.SimpleWrapGridMap(total, projectAdapters), nil
}
func (rs *EvaluationProjectService) State(in *command.StateProjectCommand) (interface{}, error) {
... ...
... ... @@ -6,13 +6,13 @@ import (
)
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"`
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) {
... ... @@ -26,20 +26,23 @@ func (in *CreateRuleCommand) Valid(validation *validation.Validation) {
}
if len(in.Name) > 40 {
validation.SetError("name", "角色名称最大长度40个字符")
validation.SetError("name", "名称最大长度40个字符")
return
}
if len(in.Remark) > 100 {
validation.SetError("remark", "备注不能超过100个字符")
return
}
if in.Type == domain.EvaluationTypeRating {
if nil == in.Rating || len(in.Rating.Levels) == 0 {
if len(in.Rating.Levels) == 0 {
validation.SetError("rating", "评级内容不能为空")
return
}
}
if in.Type == domain.EvaluationTypeScore {
if nil == in.Score {
validation.SetError("rating", "评分内容不能为空")
} else if in.Type == domain.EvaluationTypeScore {
if len(in.Score.Levels) == 0 {
validation.SetError("score", "评分内容不能为空")
return
}
}
... ...
... ... @@ -5,6 +5,8 @@ import "github.com/beego/beego/v2/core/validation"
type QueryRuleCommand struct {
CompanyId int64 `cname:"公司ID" json:"companyId"`
NameOrRemark string `cname:"规则名称或备注" json:"nameOrRemark"`
Type int `cname:"评估方式(0评级、1评分)" json:"type"`
CreatorId int64 `cname:"创建人ID" json:"creatorId,string"`
PageNumber int `cname:"分页页码" json:"pageNumber" valid:"Required"`
PageSize int `cname:"分页数量" json:"pageSize" valid:"Required"`
}
... ...
... ... @@ -6,14 +6,14 @@ import (
)
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"`
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) {
... ... @@ -27,20 +27,23 @@ func (in *UpdateRuleCommand) Valid(validation *validation.Validation) {
}
if len(in.Name) > 40 {
validation.SetError("name", "角色名称最大长度40个字符")
validation.SetError("name", "名称最大长度40个字符")
return
}
if len(in.Remark) > 100 {
validation.SetError("remark", "备注不能超过100个字符")
return
}
if in.Type == domain.EvaluationTypeRating {
if nil == in.Rating || len(in.Rating.Levels) == 0 {
if len(in.Rating.Levels) == 0 {
validation.SetError("rating", "评级内容不能为空")
return
}
}
if in.Type == domain.EvaluationTypeScore {
if nil == in.Score {
validation.SetError("rating", "评分内容不能为空")
} else if in.Type == domain.EvaluationTypeScore {
if len(in.Score.Levels) == 0 {
validation.SetError("score", "评分内容不能为空")
return
}
}
... ...
... ... @@ -7,6 +7,7 @@ import (
"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"
"sort"
)
type EvaluationRuleService struct {
... ... @@ -36,6 +37,13 @@ func (rs *EvaluationRuleService) Create(in *command.CreateRuleCommand) (interfac
if count > 0 {
return nil, application.ThrowError(application.BUSINESS_ERROR, "名称已存在")
}
if in.Type == domain.EvaluationTypeRating { // 按等级量化值排序
sort.SliceStable(in.Rating.Levels, func(i, j int) bool {
return in.Rating.Levels[i].QuantizedValue < in.Rating.Levels[j].QuantizedValue
})
}
newRule := &domain.EvaluationRule{
Id: 0,
Name: in.Name,
... ... @@ -82,6 +90,12 @@ func (rs *EvaluationRuleService) Update(in *command.UpdateRuleCommand) (interfac
return nil, application.ThrowError(application.INTERNAL_SERVER_ERROR, err.Error())
}
if in.Type == domain.EvaluationTypeRating { // 按等级量化值排序
sort.SliceStable(in.Rating.Levels, func(i, j int) bool {
return in.Rating.Levels[i].QuantizedValue < in.Rating.Levels[j].QuantizedValue
})
}
rule.Name = in.Name
rule.Remark = in.Remark
rule.Type = in.Type
... ... @@ -152,12 +166,12 @@ func (rs *EvaluationRuleService) List(in *command.QueryRuleCommand) (interface{}
transactionContext.RollbackTransaction()
}()
ruleRepository := factory.CreateEvaluationRuleRepository(map[string]interface{}{"transactionContext": transactionContext})
// FIXME 总数量是否使用Count获取一个总数量
count, rules, err := ruleRepository.Find(tool_funs.SimpleStructToMap(in))
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(count, rules), nil
return tool_funs.SimpleWrapGridMap(total, rules), nil
}
func (rs *EvaluationRuleService) ListRelCreator(in *command.QueryRuleCommand) (interface{}, error) {
... ... @@ -171,8 +185,7 @@ func (rs *EvaluationRuleService) ListRelCreator(in *command.QueryRuleCommand) (i
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))
total, rules, err := ruleRepository.Find(tool_funs.SimpleStructToMap(in))
if err != nil {
return nil, application.ThrowError(application.INTERNAL_SERVER_ERROR, err.Error())
}
... ... @@ -197,5 +210,5 @@ func (rs *EvaluationRuleService) ListRelCreator(in *command.QueryRuleCommand) (i
ras[i].CreatorName = v
}
}
return tool_funs.SimpleWrapGridMap(count, ras), nil
return tool_funs.SimpleWrapGridMap(total, ras), nil
}
... ...
... ... @@ -184,13 +184,11 @@ func (rs *EvaluationTemplateService) List(in *command.QueryTemplateCommand) (int
transactionContext.RollbackTransaction()
}()
templateRepository := factory.CreateEvaluationTemplateRepository(map[string]interface{}{"transactionContext": transactionContext})
// FIXME 总数量是否使用Count获取一个总数量
count, templates, err := templateRepository.Find(tool_funs.SimpleStructToMap(in), "linkNodes")
total, templates, err := templateRepository.Find(tool_funs.SimpleStructToMap(in), "linkNodes")
if err != nil {
return nil, application.ThrowError(application.INTERNAL_SERVER_ERROR, err.Error())
}
return tool_funs.SimpleWrapGridMap(count, templates), nil
return tool_funs.SimpleWrapGridMap(total, templates), nil
}
func (rs *EvaluationTemplateService) ListForEnable(in *command.AllEnableTemplateCommand) (interface{}, error) {
... ...
... ... @@ -17,7 +17,7 @@ type EvaluationCycle struct {
TimeEnd *time.Time `json:"timeEnd" comment:"截至时间"`
CompanyId int64 `json:"companyId,string" comment:"公司ID"`
CreatorId int64 `json:"creatorId,string" comment:"创建人ID"`
KpiCycle int `json:"state" comment:"考核周期(0日、1周、2月)"`
KpiCycle int `json:"state" comment:"考核周期(1日、2周、3月)"`
CreatedAt time.Time `json:"createdAt" comment:"创建时间"`
UpdatedAt time.Time `json:"updatedAt" comment:"更新时间"`
DeletedAt *time.Time `json:"deletedAt" comment:"删除时间"`
... ...
... ... @@ -42,8 +42,8 @@ type EvaluationRule struct {
CompanyId int64 `json:"companyId,string" comment:"公司ID"`
CreatorId int64 `json:"creatorId,string" comment:"创建人ID"`
Type int `json:"type" comment:"评估方式(0评级、1评分)"`
Rating *Rating `json:"rating" comment:"评级"`
Score *Score `json:"score" comment:"评分"`
Rating Rating `json:"rating" comment:"评级"`
Score Score `json:"score" comment:"评分"`
CreatedAt time.Time `json:"createdAt" comment:"创建时间"`
UpdatedAt time.Time `json:"updatedAt" comment:"更新时间"`
DeletedAt *time.Time `json:"deletedAt" comment:"删除时间"`
... ...
... ... @@ -25,9 +25,9 @@ const (
)
const (
KpiCycleDay int = 0 // 考核周期-日
KpiCycleWeek int = 1 // 考核周期-周
KpiCycleMonth int = 2 // 考核周期-月
KpiCycleDay int = 1 // 考核周期-日
KpiCycleWeek int = 2 // 考核周期-周
KpiCycleMonth int = 3 // 考核周期-月
)
type EntryItem struct {
... ... @@ -65,7 +65,7 @@ type LinkNode struct {
NodeAllInvite *NodeAllInvite `json:"nodeAllInvite" comment:"360°邀请人员"`
TimeStart *time.Time `json:"timeStart" comment:"起始时间"`
TimeEnd *time.Time `json:"timeEnd" comment:"截至时间"`
KpiCycle int `json:"state" comment:"考核周期(0日、1周、2月)"`
KpiCycle int `json:"state" comment:"考核周期(1日、2周、3月)"`
}
// 评估模板
... ...
... ... @@ -33,6 +33,11 @@ func init() {
&models.ReceivedMessage{},
&models.Role{},
&models.RoleUser{},
&models.EvaluationRule{},
&models.EvaluationTemplate{},
&models.EvaluationCycle{},
&models.EvaluationCycleTemplate{},
&models.EvaluationProject{},
}
for _, model := range tables {
err := DB.Model(model).CreateTable(&orm.CreateTableOptions{
... ...
... ... @@ -5,14 +5,14 @@ import (
)
type EvaluationCycle struct {
tableName struct{} `pg:"evaluation_cycle" comment:"评估周期"`
Id int64 `pg:"pk:id" comment:"周期ID"`
tableName struct{} `comment:"评估周期" pg:"evaluation_cycle"`
Id int64 `comment:"周期ID" pg:"pk: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月)"`
KpiCycle int `comment:"考核周期(1日、2周、3月)"`
CreatedAt time.Time `comment:"创建时间"`
UpdatedAt time.Time `comment:"更新时间"`
DeletedAt *time.Time `comment:"删除时间"`
... ...
... ... @@ -6,8 +6,8 @@ import (
)
type EvaluationCycleTemplate struct {
tableName struct{} `pg:"evaluation_cycle_template" comment:"评估周期模板"`
Id int64 `pg:"pk:id" comment:"模板ID"`
tableName struct{} `comment:"评估周期模板" pg:"evaluation_cycle_template"`
Id int64 `comment:"模板ID" pg:"pk:id"`
Name string `comment:"模板名称"`
Template *domain.EvaluationTemplate `comment:"模板数据"`
CycleId int64 `comment:"周期ID"`
... ...
... ... @@ -6,14 +6,14 @@ import (
)
type EvaluationProject struct {
tableName struct{} `pg:"evaluation_project" comment:"评估项目"`
Id int64 `pg:"pk:id" comment:"ID"`
tableName struct{} `comment:"评估项目" pg:"evaluation_project"`
Id int64 `comment:"ID" pg:"pk:id"`
Name string `comment:"名称"`
Describe string `comment:"描述"`
CompanyId int64 `comment:"公司ID"`
CycleId int64 `comment:"周期ID"`
CreatorId int64 `comment:"创建人ID"`
State int `comment:"状态(0待完成配置、1待启用、2启用、3停用)"`
State int `comment:"状态(0待完成配置、1待启用、2启用、3停用)" pg:",use_zero"`
HrBp int `comment:"HR角色权限"`
Pmp int `comment:"PM角色权限"`
PmpIds []string `comment:"项目管理员ID"`
... ...
... ... @@ -6,16 +6,16 @@ import (
)
type EvaluationRule struct {
tableName struct{} `pg:"evaluation_rule" comment:"评估规则"`
Id int64 `pg:"pk:id" comment:"ID"`
Name string `comment:"名称"`
Remark string `comment:"备注"`
CompanyId int64 `comment:"公司ID"`
CreatorId int64 `comment:"创建人ID"`
Type int `comment:"评估方式(0评级、1评分)"`
Rating *domain.Rating `comment:"评级"`
Score *domain.Score `comment:"评分"`
CreatedAt time.Time `comment:"创建时间"`
UpdatedAt time.Time `comment:"更新时间"`
DeletedAt *time.Time `comment:"删除时间"`
tableName struct{} `comment:"评估规则" pg:"evaluation_rule"`
Id int64 `comment:"ID" pg:"pk:id"`
Name string `comment:"名称"`
Remark string `comment:"备注"`
CompanyId int64 `comment:"公司ID"`
CreatorId int64 `comment:"创建人ID"`
Type int `comment:"评估方式(0评级、1评分)" pg:",use_zero"`
Rating domain.Rating `comment:"评级"`
Score domain.Score `comment:"评分"`
CreatedAt time.Time `comment:"创建时间"`
UpdatedAt time.Time `comment:"更新时间"`
DeletedAt *time.Time `comment:"删除时间" pg:",soft_delete"`
}
... ...
... ... @@ -6,13 +6,13 @@ import (
)
type EvaluationTemplate struct {
tableName struct{} `pg:"evaluation_template" comment:"评估模板"`
Id int64 `comment:"ID"`
tableName struct{} `comment:"评估模板" pg:"evaluation_template"`
Id int64 `comment:"ID" pg:"pk:id"`
Name string `comment:"名称"`
Describe string `comment:"描述"`
CompanyId int64 `comment:"公司ID"`
CreatorId int64 `comment:"创建人ID"`
State int `comment:"状态(0待完成配置、1待启用、2启用、3停用)"`
State int `comment:"状态(0待完成配置、1待启用、2启用、3停用)" pg:",use_zero"`
LinkNodes []*domain.LinkNode `comment:"评估流程"`
CreatedAt time.Time `comment:"创建时间"`
UpdatedAt time.Time `comment:"更新时间"`
... ...
... ... @@ -6,7 +6,7 @@ type Role struct {
tableName struct{} `pg:"role" comment:"角色"`
Id int64 `pg:"pk:id" comment:"ID"`
Name string `comment:"角色名称"`
Type int `comment:"角色类型(0角色可删、1系统预置角色不可删)"`
Type int `comment:"角色类型(0角色可删、1系统预置角色不可删)" pg:",use_zero"`
Description string `comment:"角色描述"`
CompanyId int64 `comment:"公司ID"`
CreatedAt time.Time `comment:"创建时间"`
... ...
... ... @@ -131,6 +131,14 @@ func (repo *EvaluationRuleRepository) Find(queryOptions map[string]interface{})
query.Where("company_id = ?", v)
}
if v, ok := queryOptions["creatorId"]; ok && v.(int64) > 0 {
query.Where("creator_id = ?", v)
}
if v, ok := queryOptions["type"]; ok && v.(int) >= 0 {
query.Where("type = ?", v)
}
if v, ok := queryOptions["limit"].(int); ok {
query.Limit(v)
}
... ...
... ... @@ -60,6 +60,7 @@ func (controller *RuleController) RemoveRule() {
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 {
... ...
package routers
import (
"github.com/beego/beego/v2/server/web"
"github.com/linmadan/egglib-go/web/beego/filters"
"gitlab.fjmaimaimai.com/allied-creation/performance/pkg/port/beego/controllers"
"gitlab.fjmaimaimai.com/allied-creation/performance/pkg/port/beego/middlewares"
)
func init() {
ns := web.NewNamespace("/v1/evaluation-rule",
web.NSBefore(filters.AllowCors(), middlewares.CheckToken()),
web.NSRouter("/", &controllers.RuleController{}, "Post:CreateRule"),
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.AddNamespace(ns)
}
... ...