作者 郑周

HRBP角色 默认创建

... ... @@ -5,8 +5,8 @@ import "github.com/beego/beego/v2/core/validation"
type QueryCycleCommand struct {
CompanyId int64 `cname:"公司ID" json:"companyId"`
Name string `cname:"周期名称" json:"name"`
PageNumber int `cname:"分页页码" json:"pageNumber" valid:"Required"`
PageSize int `cname:"分页数量" json:"pageSize" valid:"Required"`
PageNumber int64 `cname:"分页页码" json:"pageNumber" valid:"Required"`
PageSize int64 `cname:"分页数量" json:"pageSize" valid:"Required"`
}
type StatisticCycleProjectUserCommand struct {
... ...
... ... @@ -8,8 +8,8 @@ type QueryProjectCommand struct {
Name string `cname:"项目名称" json:"name"`
State int `cname:"项目状态" json:"state"`
PmpIds []string `cname:"项目管理员ID" json:"pmpIds"`
PageNumber int `cname:"分页页码" json:"pageNumber" valid:"Required"`
PageSize int `cname:"分页数量" json:"pageSize" valid:"Required"`
PageNumber int64 `cname:"分页页码" json:"pageNumber" valid:"Required"`
PageSize int64 `cname:"分页数量" json:"pageSize" valid:"Required"`
}
func (in *QueryProjectCommand) Valid(validation *validation.Validation) {
... ...
... ... @@ -7,8 +7,8 @@ type QueryRuleCommand struct {
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"`
PageNumber int64 `cname:"分页页码" json:"pageNumber" valid:"Required"`
PageSize int64 `cname:"分页数量" json:"pageSize" valid:"Required"`
}
func (in *QueryRuleCommand) Valid(validation *validation.Validation) {
... ...
... ... @@ -10,8 +10,8 @@ type QueryTemplateCommand struct {
Name string `cname:"模板名称" json:"name"`
State int `cname:"模板状态" json:"state"`
CreatedAt *time.Time `cname:"创建时间" json:"createdAt"`
PageNumber int `cname:"分页页码" json:"pageNumber" valid:"Required"`
PageSize int `cname:"分页数量" json:"pageSize" valid:"Required"`
PageNumber int64 `cname:"分页页码" json:"pageNumber" valid:"Required"`
PageSize int64 `cname:"分页数量" json:"pageSize" valid:"Required"`
}
func (in *QueryTemplateCommand) Valid(validation *validation.Validation) {
... ... @@ -20,15 +20,3 @@ func (in *QueryTemplateCommand) Valid(validation *validation.Validation) {
return
}
}
//// AllEnableTemplateCommand 查询所有已启用的模板
//type AllEnableTemplateCommand struct {
// CompanyId int64 `cname:"公司ID" json:"companyId"`
//}
//
//func (in *AllEnableTemplateCommand) Valid(validation *validation.Validation) {
// if in.CompanyId == 0 {
// validation.SetError("companyId", "公司ID无效")
// return
// }
//}
... ...
... ... @@ -5,6 +5,6 @@ import (
)
type RoleUserAdapter struct {
domain.Role
*domain.Role
Users []*domain.RoleContainUser `json:"users"`
}
... ...
... ... @@ -5,8 +5,8 @@ import "github.com/beego/beego/v2/core/validation"
// QueryRoleUserCommand 查询角色列表(关联用户)
type QueryRoleUserCommand struct {
CompanyId int64 `cname:"公司ID" json:"companyId"`
PageNumber int `cname:"分页页码" json:"pageNumber" valid:"Required"`
PageSize int `cname:"分页数量" json:"pageSize" valid:"Required"`
PageNumber int64 `cname:"分页页码" json:"pageNumber" valid:"Required"`
PageSize int64 `cname:"分页数量" json:"pageSize" valid:"Required"`
}
func (in *QueryRoleUserCommand) Valid(validation *validation.Validation) {
... ...
... ... @@ -6,6 +6,7 @@ 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 {
... ... @@ -150,11 +151,37 @@ func (rs *RoleService) ListForUser(in *command.QueryRoleUserCommand) (interface{
if err != nil {
return nil, application.ThrowError(application.INTERNAL_SERVER_ERROR, err.Error())
}
if len(roles) == 0 {
return nil, application.ThrowError(application.BUSINESS_ERROR, "未找到角色数据")
}
adapterList := make([]*adapter.RoleUserAdapter, 0)
// 如果不存在系统预支hrbp角色时,插入一条数据
var havaSystemType = false
for i := range roles {
if roles[i].Type == domain.RoleTypeSystem {
havaSystemType = true
break
}
}
if !havaSystemType {
role := &domain.Role{
Id: 0,
Name: "HRBP",
Type: domain.RoleTypeSystem,
Description: "拥有全部权限,预置角色不可删除",
CompanyId: in.CompanyId,
}
role, err = roleRepository.Insert(role)
if err != nil {
return nil, application.ThrowError(application.INTERNAL_SERVER_ERROR, err.Error())
}
// 创建HRBP角色
roleUser := &adapter.RoleUserAdapter{}
roleUser.Role = role
roleUser.Users = make([]*domain.RoleContainUser, 0)
adapterList = append(adapterList, roleUser)
}
for i := range roles {
v := roles[i]
tempList, err := ruRepository.FindAllContainUser(1, 10, in.CompanyId, v.Id)
... ... @@ -162,13 +189,14 @@ func (rs *RoleService) ListForUser(in *command.QueryRoleUserCommand) (interface{
return nil, application.ThrowError(application.INTERNAL_SERVER_ERROR, err.Error())
}
roleUser := &adapter.RoleUserAdapter{}
roleUser.Id = v.Id
roleUser.Name = v.Name
roleUser.Type = v.Type
roleUser.Description = v.Description
roleUser.CompanyId = v.CompanyId
roleUser.Role = v
roleUser.Users = tempList
adapterList = append(adapterList, roleUser)
}
if err := transactionContext.CommitTransaction(); err != nil {
return nil, application.ThrowError(application.TRANSACTION_ERROR, err.Error())
}
return tool_funs.SimpleWrapGridMap(int64(len(adapterList)), adapterList), nil
}
... ...
... ... @@ -10,7 +10,7 @@ const (
type Role struct {
Id int64 `json:"id,string"`
Name string `json:"name"`
Type int `json:"type"`
Type int `json:"type" pg:",use_zero"`
Description string `json:"description"`
CompanyId int64 `json:"companyId,string"`
CreatedAt time.Time `json:"createdAt"`
... ...
... ... @@ -3,13 +3,13 @@ package models
import "time"
type Role struct {
tableName struct{} `pg:"role" comment:"角色"`
Id int64 `pg:"pk:id" comment:"ID"`
tableName struct{} `comment:"角色" pg:"role"`
Id int64 `comment:"ID" pg:"pk:id"`
Name string `comment:"角色名称"`
Type int `comment:"角色类型(0角色可删、1系统预置角色不可删)" pg:",use_zero"`
Description string `comment:"角色描述"`
CompanyId int64 `comment:"公司ID"`
CreatedAt time.Time `comment:"创建时间"`
UpdatedAt time.Time `comment:"更新时间"`
DeletedAt *time.Time `comment:"删除时间" pg:",soft_delete"`
DeletedAt *time.Time `comment:"删除时间"`
}
... ...