作者 Your Name
... ... @@ -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) {
... ...
... ... @@ -8,7 +8,6 @@ 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"`
... ... @@ -21,10 +20,6 @@ func (in *UpdateRuleCommand) Valid(validation *validation.Validation) {
validation.SetError("companyId", "公司ID无效")
return
}
if in.CreatorId == 0 {
validation.SetError("creatorId", "创建人ID无效")
return
}
if len(in.Name) > 40 {
validation.SetError("name", "名称最大长度40个字符")
... ...
... ... @@ -35,7 +35,7 @@ func (rs *EvaluationRuleService) Create(in *command.CreateRuleCommand) (interfac
return nil, application.ThrowError(application.INTERNAL_SERVER_ERROR, err.Error())
}
if count > 0 {
return nil, application.ThrowError(application.BUSINESS_ERROR, "名称已存在")
return nil, application.ThrowError(application.BUSINESS_ERROR, "已存在相同名称的评估规则")
}
if in.Type == domain.EvaluationTypeRating { // 按等级量化值排序
... ... @@ -82,7 +82,7 @@ func (rs *EvaluationRuleService) Update(in *command.UpdateRuleCommand) (interfac
return nil, application.ThrowError(application.INTERNAL_SERVER_ERROR, err.Error())
}
if count > 0 {
return nil, application.ThrowError(application.BUSINESS_ERROR, "名称已存在")
return nil, application.ThrowError(application.BUSINESS_ERROR, "已存在相同名称的评估规则")
}
rule, err := ruleRepository.FindOne(map[string]interface{}{"id": in.Id})
... ...
... ... @@ -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
// }
//}
... ...
... ... @@ -34,7 +34,7 @@ func (rs *EvaluationTemplateService) Create(in *command.CreateTemplateCommand) (
return nil, application.ThrowError(application.INTERNAL_SERVER_ERROR, err.Error())
}
if count > 0 {
return nil, application.ThrowError(application.BUSINESS_ERROR, "名称已存在")
return nil, application.ThrowError(application.BUSINESS_ERROR, "已存在相同名称的评估模板")
}
linkNodes := make([]*domain.LinkNode, 0)
... ... @@ -44,30 +44,35 @@ func (rs *EvaluationTemplateService) Create(in *command.CreateTemplateCommand) (
Id: sid + 1,
Type: domain.LinkNodeSelfAssessment,
Name: "填写自评反馈",
NodeContents: make([]*domain.NodeContent, 0),
KpiCycle: domain.KpiCycleDay,
})
linkNodes = append(linkNodes, &domain.LinkNode{
Id: sid + 2,
Type: domain.LinkNodeAllInvite,
Name: "360°邀请",
NodeContents: make([]*domain.NodeContent, 0),
KpiCycle: domain.KpiCycleDay,
})
linkNodes = append(linkNodes, &domain.LinkNode{
Id: sid + 3,
Type: domain.LinkNodeAllAssessment,
Name: "360°评估",
NodeContents: make([]*domain.NodeContent, 0),
KpiCycle: domain.KpiCycleDay,
})
linkNodes = append(linkNodes, &domain.LinkNode{
Id: sid + 4,
Type: domain.LinkNodeSuperiorAssessment,
Name: "上级评估",
NodeContents: make([]*domain.NodeContent, 0),
KpiCycle: domain.KpiCycleDay,
})
linkNodes = append(linkNodes, &domain.LinkNode{
Id: sid + 5,
Type: domain.LinkNodeViewResult,
Name: "绩效结果查看",
NodeContents: make([]*domain.NodeContent, 0),
KpiCycle: domain.KpiCycleDay,
})
... ...
... ... @@ -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 {
... ... @@ -91,47 +92,53 @@ func NewRoleService() *RoleService {
// 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) 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 role.Type == domain.RoleTypeSystem {
return nil, application.ThrowError(application.BUSINESS_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()
... ... @@ -150,11 +157,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 +195,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
}
... ...
... ... @@ -28,6 +28,11 @@ func (rs *RoleUserService) Create(in *command.UserRoleCreateCommand) (interface{
}()
roleUserRepository := factory.CreateRoleUserRepository(map[string]interface{}{"transactionContext": transactionContext})
//int64Array := make([]int64, 0)
//for i := range in.UserIds {
// int64Num, _ := strconv.ParseInt(in.UserIds[i], 10, 64)
// int64Array = append(int64Array, int64Num)
//}
// 检测已存在的关联用户
_, rus, err := roleUserRepository.Find(map[string]interface{}{"roleId": in.RoleId, "companyId": in.CompanyId, "userIds": in.UserIds, "limit": 9999999})
if err != nil {
... ...
... ... @@ -33,7 +33,7 @@ type EntryItem struct {
type NodeContent struct {
Category string `json:"category" comment:"类别"`
Name string `json:"name" comment:"名称"`
RuleId int64 `json:"ruleId" comment:"评估规则ID"`
RuleId int64 `json:"ruleId,string" comment:"评估规则ID"`
Rule *EvaluationRule `json:"rule" comment:"评估规则对象"`
PromptTitle string `json:"promptTitle" comment:"提示项标题"`
PromptText string `json:"promptText" comment:"提示项正文"`
... ... @@ -59,7 +59,7 @@ type LinkNode struct {
NodeContents []*NodeContent `json:"nodeContents" comment:"环节-评估内容"`
TimeStart *time.Time `json:"timeStart" comment:"起始时间"`
TimeEnd *time.Time `json:"timeEnd" comment:"截至时间"`
KpiCycle int `json:"state" comment:"考核周期(1日、2周、3月)"`
KpiCycle int `json:"kpiCycle" comment:"考核周期(1日、2周、3月)"`
//NodeAllInvite *NodeAllInvite `json:"nodeAllInvite" comment:"360°邀请人员"`
}
... ...
... ... @@ -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"`
... ...
... ... @@ -17,5 +17,5 @@ type EvaluationRule struct {
Score domain.Score `comment:"评分"`
CreatedAt time.Time `comment:"创建时间"`
UpdatedAt time.Time `comment:"更新时间"`
DeletedAt *time.Time `comment:"删除时间" pg:",soft_delete"`
DeletedAt *time.Time `comment:"删除时间"`
}
... ...
... ... @@ -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:"删除时间"`
}
... ...
... ... @@ -10,5 +10,5 @@ type RoleUser struct {
CompanyId int64 `comment:"公司ID"`
CreatedAt time.Time `comment:"创建时间"`
UpdatedAt time.Time `comment:"更新时间"`
DeletedAt *time.Time `comment:"删除时间" pg:",soft_delete"`
DeletedAt *time.Time `comment:"删除时间"`
}
... ...
... ... @@ -125,7 +125,7 @@ func (repo *RoleUserRepository) Find(queryOptions map[string]interface{}) (int64
}
if userIds, ok := queryOptions["userIds"]; ok {
query.Where("user_id in (?)", userIds)
query.Where("user_id in (?)", pg.In(userIds))
}
if v, ok := queryOptions["limit"].(int); ok {
... ... @@ -182,7 +182,7 @@ func (repo *RoleUserRepository) BatchDeleteById(ids []int64) error {
return err
}
func (repo *RoleUserRepository) FindAllContainUser(pageSize int, pageNumber int, companyId int64, roleId int64) ([]*domain.RoleContainUser, error) {
func (repo *RoleUserRepository) FindAllContainUser(pageNumber int, pageSize int, companyId int64, roleId int64) ([]*domain.RoleContainUser, error) {
limit := pageSize
offset := limit * (pageNumber - 1)
if offset < 0 {
... ... @@ -192,7 +192,7 @@ func (repo *RoleUserRepository) FindAllContainUser(pageSize int, pageNumber int,
"role_user".role_id,
"role_user".user_id,
"user".name as user_name,
"user".email as user_email,
"user".email as user_email
`
whereFrom := `
FROM "role_user"
... ...
... ... @@ -21,8 +21,6 @@ func (controller *RuleController) CreateRule() {
ua := middlewares.GetUser(controller.Ctx)
in.CompanyId = ua.CompanyId
in.CreatorId = ua.UserId
//in.CompanyId = middlewares.GetCompanyId(controller.Ctx)
//in.CreatorId = middlewares.GetUserId(controller.Ctx)
controller.Response(ruService.Create(in))
}
}
... ... @@ -35,9 +33,6 @@ func (controller *RuleController) UpdateRule() {
} else {
ua := middlewares.GetUser(controller.Ctx)
in.CompanyId = ua.CompanyId
in.CreatorId = ua.UserId
//in.CompanyId = middlewares.GetCompanyId(controller.Ctx)
//in.CreatorId = middlewares.GetUserId(controller.Ctx)
controller.Response(ruService.Update(in))
}
}
... ...
... ... @@ -12,7 +12,7 @@ type RoleController struct {
beego.BaseController
}
//func (controller *RoleController) CreateRole() {
// func (controller *RoleController) CreateRole() {
// ruService := service.NewRoleService()
// in := &command.CreateRoleCommand{}
// if err := controller.Unmarshal(in); err != nil {
... ... @@ -21,9 +21,9 @@ type RoleController struct {
// in.CompanyId = middlewares.GetCompanyId(controller.Ctx)
// controller.Response(ruService.Create(in))
// }
//}
// }
//
//func (controller *RoleController) UpdateRole() {
// func (controller *RoleController) UpdateRole() {
// ruService := service.NewRoleService()
// in := &command.UpdateRoleCommand{}
// if err := controller.Unmarshal(in); err != nil {
... ... @@ -32,18 +32,18 @@ type RoleController struct {
// 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) 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 {
ua := middlewares.GetUser(controller.Ctx)
in.CompanyId = ua.CompanyId
controller.Response(ruService.Remove(in))
}
}
func (controller *RoleController) ListForUserRole() {
ruService := service.NewRoleService()
... ... @@ -53,7 +53,6 @@ func (controller *RoleController) ListForUserRole() {
} else {
ua := middlewares.GetUser(controller.Ctx)
in.CompanyId = ua.CompanyId
//in.CompanyId = middlewares.GetCompanyId(controller.Ctx)
controller.Response(ruService.ListForUser(in))
}
}
... ...
... ... @@ -12,7 +12,7 @@ func init() {
web.NSBefore(filters.AllowCors(), middlewares.CheckAdminToken()),
//web.NSRouter("/", &controllers.RoleController{}, "Post:CreateRole"),
//web.NSRouter("/", &controllers.RoleController{}, "Put:UpdateRole"),
//web.NSRouter("/", &controllers.RoleController{}, "Delete:RemoveRole"),
web.NSRouter("/", &controllers.RoleController{}, "Delete:RemoveRole"),
//web.NSRouter("/:Id", &controllers.RoleController{}, "Get:GetRole"),
web.NSRouter("/all", &controllers.RoleController{}, "Post:ListForUserRole"),
)
... ...