作者 郑周

增加项目模型数据!~

package adapter
import (
"gitlab.fjmaimaimai.com/allied-creation/performance/pkg/domain"
"strconv"
)
type UserAdapter struct {
Id int64 `json:"id,string" comment:"用户Id"`
Name string `json:"name" comment:"用户名称"`
}
type EvaluationProjectAdapter struct {
*domain.EvaluationProject
RecipientList []*UserAdapter `json:"recipientList" comment:"被评估人"`
PmpList []*UserAdapter `json:"pmpList" comment:"项目管理员"`
}
func (adapter *EvaluationProjectAdapter) TransformRecipientAdapter(recipients []*domain.User) {
for i := range recipients {
adapter.RecipientList = append(adapter.RecipientList, &UserAdapter{
Id: recipients[i].Id,
Name: recipients[i].Name,
})
}
}
func (adapter *EvaluationProjectAdapter) TransformPmpAdapter(pms []*domain.User) {
for i := range pms {
adapter.PmpList = append(adapter.PmpList, &UserAdapter{
Id: pms[i].Id,
Name: pms[i].Name,
})
}
}
func TransformProjectListAdapter(projects []*domain.EvaluationProject, users []*domain.User) []*EvaluationProjectAdapter {
pmpUserMap := map[int64]*domain.User{}
for i := range users {
pmpUserMap[users[i].Id] = users[i]
}
projectAdapters := make([]*EvaluationProjectAdapter, 0)
for i := range projects {
project := projects[i]
epa := &EvaluationProjectAdapter{}
epa.EvaluationProject = project
projectAdapters = append(projectAdapters, epa)
for j := range project.PmpIds {
userId, _ := strconv.ParseInt(project.PmpIds[j], 10, 64)
if v, ok := pmpUserMap[userId]; ok {
epa.PmpList = append(epa.PmpList, &UserAdapter{
Id: v.Id,
Name: v.Name,
})
}
}
}
return projectAdapters
}
... ...
package command
import (
"github.com/beego/beego/v2/core/validation"
)
type CreateProjectCommand struct {
CompanyId int64 `cname:"公司ID" json:"companyId"`
CreatorId int64 `cname:"创建人ID" json:"creatorId"`
CycleId int64 `cname:"周期ID" json:"cycleId,string" valid:"Required"`
Name string `cname:"项目名称" json:"name" valid:"Required"`
Describe string `cname:"项目描述" json:"describe" valid:"Required"`
HrBp int `cname:"HR角色权限" json:"hrBp"`
Pmp int `cname:"PM角色权限" json:"pmp"`
PmpIds []string `cname:"项目管理员ID" json:"pms"`
}
func (in *CreateProjectCommand) 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
}
}
... ...
package command
import "github.com/beego/beego/v2/core/validation"
type DeleteProjectCommand struct {
Id int64 `cname:"项目ID" json:"id,string" valid:"Required"`
}
func (in *DeleteProjectCommand) Valid(*validation.Validation) {
}
... ...
package command
import "github.com/beego/beego/v2/core/validation"
type GetProjectCommand struct {
Id int64 `cname:"项目ID" json:"id,string" valid:"Required"`
}
func (in *GetProjectCommand) Valid(*validation.Validation) {
}
... ...
package command
import (
"github.com/beego/beego/v2/core/validation"
"gitlab.fjmaimaimai.com/allied-creation/performance/pkg/domain"
)
type StateProjectCommand struct {
Id int64 `cname:"模板ID" json:"id,string" valid:"Required"`
State int `cname:"模板状态" json:"state"`
}
type CopyProjectCommand struct {
Id int64 `cname:"模板ID" json:"id,string" valid:"Required"`
}
func (in *StateProjectCommand) Valid(validation *validation.Validation) {
switch in.State {
case domain.ProjectStateWaitConfig, domain.ProjectStateWaitActive, domain.ProjectStateEnable, domain.ProjectStateDisable:
default:
validation.SetError("state", "状态设置错误")
return
}
}
func (in *CopyProjectCommand) Valid(*validation.Validation) {
}
... ...
package command
import "github.com/beego/beego/v2/core/validation"
type QueryProjectCommand struct {
CompanyId int64 `cname:"公司ID" json:"companyId"`
CycleId int64 `cname:"周期ID" json:"cycleId,string"`
Name string `cname:"项目名称" json:"name"`
State int `cname:"项目状态" json:"state"`
PageNumber int `cname:"分页页码" json:"pageNumber" valid:"Required"`
PageSize int `cname:"分页数量" json:"pageSize" valid:"Required"`
}
func (in *QueryProjectCommand) Valid(validation *validation.Validation) {
if in.CompanyId == 0 {
validation.SetError("companyId", "公司ID无效")
return
}
}
... ...
package command
import (
"github.com/beego/beego/v2/core/validation"
"gitlab.fjmaimaimai.com/allied-creation/performance/pkg/domain"
)
type UpdateProjectCommand struct {
CompanyId int64 `cname:"公司ID" json:"companyId"`
CycleId int64 `cname:"周期ID" json:"cycleId,string" valid:"Required"`
Id int64 `cname:"项目ID" json:"id,string" valid:"Required"`
Name string `cname:"项目名称" json:"name" valid:"Required"`
Describe string `cname:"项目描述" json:"describe" valid:"Required"`
HrBp int `cname:"HR角色权限" json:"hrBp"`
Pmp int `cname:"PM角色权限" json:"pmp"`
PmpIds []string `cname:"项目管理员ID" json:"pms"`
}
type UpdateProjectTemplateCommand struct {
CompanyId int64 `cname:"公司ID" json:"companyId"`
CycleId int64 `cname:"周期ID" json:"cycleId,string" valid:"Required"`
Id int64 `cname:"项目ID" json:"id,string" valid:"Required"`
TemplateId int64 `cname:"评估模板ID" json:"templateId,string"`
Recipients []string `cname:"被评估人ID" json:"recipients"`
}
type UpdateProjectTemplateNodeCommand struct {
CompanyId int64 `cname:"公司ID" json:"companyId"`
CycleId int64 `cname:"周期ID" json:"cycleId,string" valid:"Required"`
Id int64 `cname:"项目ID" json:"id,string" valid:"Required"`
TemplateId int64 `cname:"评估模板ID" json:"templateId,string"`
LinkNodes []*domain.LinkNode `cname:"评估流程" json:"linkNodes"`
Activate int `cname:"启动项目" json:"activate"`
}
func (in *UpdateProjectCommand) Valid(validation *validation.Validation) {
if len(in.Name) > 40 {
validation.SetError("name", "角色名称最大长度40个字符")
return
}
}
func (in *UpdateProjectTemplateCommand) Valid(validation *validation.Validation) {
if len(in.Recipients) == 0 {
validation.SetError("recipients", "请选择被评估人")
return
}
}
... ...
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_project/adapter"
"gitlab.fjmaimaimai.com/allied-creation/performance/pkg/application/evaluation_project/command"
"gitlab.fjmaimaimai.com/allied-creation/performance/pkg/application/factory"
"gitlab.fjmaimaimai.com/allied-creation/performance/pkg/domain"
"gitlab.fjmaimaimai.com/allied-creation/performance/pkg/utils"
"strconv"
)
type EvaluationProjectService struct {
}
func NewEvaluationProjectService() *EvaluationProjectService {
newRoleService := &EvaluationProjectService{}
return newRoleService
}
// Create 创建
func (rs *EvaluationProjectService) Create(in *command.CreateProjectCommand) (interface{}, error) {
transactionContext, err := factory.ValidateStartTransaction(in)
if err != nil {
return nil, err
}
defer func() {
transactionContext.RollbackTransaction()
}()
projectRepository := factory.CreateEvaluationProjectRepository(map[string]interface{}{"transactionContext": transactionContext})
// 检测名称重复
count, err := projectRepository.Count(map[string]interface{}{"name": in.Name, "cycleId": in.CycleId, "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, "名称已存在")
}
newProject := &domain.EvaluationProject{
Id: 0,
Name: in.Name,
Describe: in.Describe,
CompanyId: in.CompanyId,
CreatorId: in.CreatorId,
State: domain.ProjectStateWaitConfig,
HrBp: in.HrBp,
Pmp: in.Pmp,
PmpIds: in.PmpIds,
}
project, err := projectRepository.Insert(newProject)
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 project, nil
}
func (rs *EvaluationProjectService) Update(in *command.UpdateProjectCommand) (interface{}, error) {
transactionContext, err := factory.ValidateStartTransaction(in)
if err != nil {
return nil, err
}
defer func() {
transactionContext.RollbackTransaction()
}()
projectRepository := factory.CreateEvaluationProjectRepository(map[string]interface{}{"transactionContext": transactionContext})
// 检测名称重复(排除自己)
count, err := projectRepository.Count(map[string]interface{}{"name": in.Name, "cycleId": in.CycleId, "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, "名称已存在")
}
project, err := projectRepository.FindOne(map[string]interface{}{"id": in.Id})
if err != nil {
return nil, application.ThrowError(application.INTERNAL_SERVER_ERROR, err.Error())
}
project.Name = in.Name
project.Describe = in.Describe
project.HrBp = in.HrBp
project.Pmp = in.Pmp
project.PmpIds = in.PmpIds
project, err = projectRepository.Insert(project)
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 project, nil
}
func (rs *EvaluationProjectService) UpdateTemplate(in *command.UpdateProjectTemplateCommand) (interface{}, error) {
transactionContext, err := factory.ValidateStartTransaction(in)
if err != nil {
return nil, err
}
defer func() {
transactionContext.RollbackTransaction()
}()
projectRepository := factory.CreateEvaluationProjectRepository(map[string]interface{}{"transactionContext": transactionContext})
cycleTemplateRepository := factory.CreateEvaluationCycleTemplateRepository(map[string]interface{}{"transactionContext": transactionContext})
project, err := projectRepository.FindOne(map[string]interface{}{"id": in.Id})
if err != nil {
return nil, application.ThrowError(application.INTERNAL_SERVER_ERROR, err.Error())
}
cycleTemplate, err := cycleTemplateRepository.FindOne(map[string]interface{}{"id": in.TemplateId, "includeDeleted": true})
if err != nil {
return nil, application.ThrowError(application.INTERNAL_SERVER_ERROR, err.Error())
}
project.Recipients = in.Recipients
project.Template = cycleTemplate.Template
project, err = projectRepository.Insert(project)
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 project, nil
}
func (rs *EvaluationProjectService) UpdateTemplateNode(in *command.UpdateProjectTemplateNodeCommand) (interface{}, error) {
transactionContext, err := factory.ValidateStartTransaction(in)
if err != nil {
return nil, err
}
defer func() {
transactionContext.RollbackTransaction()
}()
projectRepository := factory.CreateEvaluationProjectRepository(map[string]interface{}{"transactionContext": transactionContext})
project, err := projectRepository.FindOne(map[string]interface{}{"id": in.Id})
if err != nil {
return nil, application.ThrowError(application.INTERNAL_SERVER_ERROR, err.Error())
}
// FIXME 启动时,需要激活定时任务
if in.Activate == 1 {
project.State = domain.ProjectStateEnable
}
for i := range in.LinkNodes {
project.Template.LinkNodes[i].TimeStart = in.LinkNodes[i].TimeStart
project.Template.LinkNodes[i].TimeEnd = in.LinkNodes[i].TimeEnd
project.Template.LinkNodes[i].KpiCycle = in.LinkNodes[i].KpiCycle
}
project, err = projectRepository.Insert(project)
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 project, nil
}
func (rs *EvaluationProjectService) Get(in *command.GetProjectCommand) (interface{}, error) {
// Get 不需要事务
if err := utils.ValidateCommand(in); err != nil {
return nil, application.ThrowError(application.ARG_ERROR, err.Error())
}
transactionContext, err := factory.CreateTransactionContext(nil)
if err != nil {
return nil, application.ThrowError(application.TRANSACTION_ERROR, err.Error())
}
projectRepository := factory.CreateEvaluationProjectRepository(map[string]interface{}{"transactionContext": transactionContext})
project, err := projectRepository.FindOne(map[string]interface{}{"id": in.Id})
if err != nil {
return nil, application.ThrowError(application.INTERNAL_SERVER_ERROR, err.Error())
}
projectAdapter := &adapter.EvaluationProjectAdapter{}
projectAdapter.EvaluationProject = project
userRepository := factory.CreateUserRepository(map[string]interface{}{"transactionContext": transactionContext})
if len(project.PmpIds) > 0 {
_, users, _ := userRepository.Find(map[string]interface{}{"ids": project.PmpIds, "limit": len(project.PmpIds)})
projectAdapter.TransformPmpAdapter(users)
}
if len(project.Recipients) > 0 {
_, users, _ := userRepository.Find(map[string]interface{}{"ids": project.Recipients, "limit": len(project.Recipients)})
projectAdapter.TransformRecipientAdapter(users)
}
return projectAdapter, nil
}
func (rs *EvaluationProjectService) Remove(in *command.DeleteProjectCommand) (interface{}, error) {
transactionContext, err := factory.ValidateStartTransaction(in)
if err != nil {
return nil, err
}
defer func() {
transactionContext.RollbackTransaction()
}()
projectRepository := factory.CreateEvaluationProjectRepository(map[string]interface{}{"transactionContext": transactionContext})
project, err := projectRepository.FindOne(map[string]interface{}{"id": in.Id})
if err != nil {
return nil, application.ThrowError(application.INTERNAL_SERVER_ERROR, err.Error())
}
if _, err := projectRepository.Remove(project); 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 project, nil
}
func (rs *EvaluationProjectService) List(in *command.QueryProjectCommand) (interface{}, error) {
transactionContext, err := factory.StartTransaction()
if err != nil {
return nil, err
}
defer func() {
transactionContext.RollbackTransaction()
}()
projectRepository := factory.CreateEvaluationProjectRepository(map[string]interface{}{"transactionContext": transactionContext})
// FIXME 总数量是否使用Count获取一个总数量
count, projects, err := projectRepository.Find(tool_funs.SimpleStructToMap(in), "linkNodes")
if err != nil {
return nil, application.ThrowError(application.INTERNAL_SERVER_ERROR, err.Error())
}
pmpUsers := make([]*domain.User, 0)
pmpUserIds := make([]int64, 0)
for i := range projects {
project := projects[i]
for j := range project.PmpIds {
userId, _ := strconv.ParseInt(project.PmpIds[j], 10, 64)
pmpUserIds = append(pmpUserIds, userId)
}
}
if len(pmpUserIds) > 0 {
userRepository := factory.CreateUserRepository(map[string]interface{}{"transactionContext": transactionContext})
_, users, _ := userRepository.Find(map[string]interface{}{"ids": pmpUserIds, "limit": len(pmpUserIds)})
pmpUsers = users
}
projectAdapters := adapter.TransformProjectListAdapter(projects, pmpUsers)
return tool_funs.SimpleWrapGridMap(count, projectAdapters), nil
}
func (rs *EvaluationProjectService) State(in *command.StateProjectCommand) (interface{}, error) {
transactionContext, err := factory.ValidateStartTransaction(in)
if err != nil {
return nil, err
}
defer func() {
transactionContext.RollbackTransaction()
}()
projectRepository := factory.CreateEvaluationProjectRepository(map[string]interface{}{"transactionContext": transactionContext})
project, err := projectRepository.FindOne(map[string]interface{}{"id": in.Id})
if err != nil {
return nil, application.ThrowError(application.INTERNAL_SERVER_ERROR, err.Error())
}
project.State = in.State
project, err = projectRepository.Insert(project)
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 project, nil
}
func (rs *EvaluationProjectService) Copy(in *command.CopyProjectCommand) (interface{}, error) {
transactionContext, err := factory.ValidateStartTransaction(in)
if err != nil {
return nil, err
}
defer func() {
transactionContext.RollbackTransaction()
}()
projectRepository := factory.CreateEvaluationProjectRepository(map[string]interface{}{"transactionContext": transactionContext})
project, err := projectRepository.FindOne(map[string]interface{}{"id": in.Id})
if err != nil {
return nil, application.ThrowError(application.INTERNAL_SERVER_ERROR, err.Error())
}
// ID重置
project.Id = 0
// 如果拷贝已经启用的模板,默认先设置为待启用
if project.State == domain.ProjectStateEnable {
project.State = domain.ProjectStateWaitActive
}
project, err = projectRepository.Insert(project)
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 project, nil
}
... ...
... ... @@ -150,12 +150,8 @@ func (rs *EvaluationRuleService) List(in *command.QueryRuleCommand) (interface{}
transactionContext.RollbackTransaction()
}()
ruleRepository := factory.CreateEvaluationRuleRepository(map[string]interface{}{"transactionContext": transactionContext})
inMap := tool_funs.SimpleStructToMap(in)
if len(in.NameOrRemark) > 0 {
inMap["nameOrRemark"] = "%" + in.NameOrRemark + "%"
}
// FIXME 总数量是否使用Count获取一个总数量
count, rules, err := ruleRepository.Find(inMap)
count, rules, err := ruleRepository.Find(tool_funs.SimpleStructToMap(in))
if err != nil {
return nil, application.ThrowError(application.INTERNAL_SERVER_ERROR, err.Error())
}
... ...
... ... @@ -8,7 +8,6 @@ import (
type UpdateTemplateCommand 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"`
Describe string `cname:"模板描述" json:"remark"`
LinkNodes []*domain.LinkNode `cname:"评估流程" json:"linkNodes"`
... ... @@ -19,10 +18,6 @@ func (in *UpdateTemplateCommand) 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个字符")
... ...
... ... @@ -26,10 +26,10 @@ func (rs *EvaluationTemplateService) Create(in *command.CreateTemplateCommand) (
defer func() {
transactionContext.RollbackTransaction()
}()
ruleRepository := factory.CreateEvaluationTemplateRepository(map[string]interface{}{"transactionContext": transactionContext})
templateRepository := factory.CreateEvaluationTemplateRepository(map[string]interface{}{"transactionContext": transactionContext})
// 检测名称重复
count, err := ruleRepository.Count(map[string]interface{}{"name": in.Name, "companyId": in.CompanyId})
count, err := templateRepository.Count(map[string]interface{}{"name": in.Name, "companyId": in.CompanyId})
if err != nil {
return nil, application.ThrowError(application.INTERNAL_SERVER_ERROR, err.Error())
}
... ... @@ -73,14 +73,14 @@ func (rs *EvaluationTemplateService) Create(in *command.CreateTemplateCommand) (
State: domain.TemplateStateWaitConfig,
LinkNodes: linkNodes,
}
rule, err := ruleRepository.Insert(newTemplate)
template, err := templateRepository.Insert(newTemplate)
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
return template, nil
}
... ... @@ -175,12 +175,8 @@ func (rs *EvaluationTemplateService) List(in *command.QueryTemplateCommand) (int
}()
templateRepository := factory.CreateEvaluationTemplateRepository(map[string]interface{}{"transactionContext": transactionContext})
inMap := tool_funs.SimpleStructToMap(in)
if len(in.Name) > 0 {
inMap["name"] = "%" + in.Name + "%"
}
// FIXME 总数量是否使用Count获取一个总数量
count, templates, err := templateRepository.Find(inMap, "linkNodes")
count, templates, err := templateRepository.Find(tool_funs.SimpleStructToMap(in), "linkNodes")
if err != nil {
return nil, application.ThrowError(application.INTERNAL_SERVER_ERROR, err.Error())
}
... ...
... ... @@ -4,14 +4,23 @@ import (
"time"
)
const (
ProjectStateWaitConfig int = 0 // 项目状态-待完成配置
ProjectStateWaitActive int = 1 // 项目状态-待启用
ProjectStateEnable int = 2 // 项目状态-启用
ProjectStateDisable int = 3 // 项目状态-停用
)
type EvaluationProject struct {
Id int64 `json:"id,string" comment:"ID"`
Name string `json:"name" comment:"名称"`
Describe string `json:"describe" comment:"描述"`
CompanyId int64 `json:"companyId,string" comment:"公司ID"`
CreatorId int64 `json:"creatorId,string" comment:"创建人ID"`
State int `json:"state" comment:"状态(0待完成配置、1待启用、2启用、3结束)"`
HrBp int `json:"hrBp" comment:"HR角色权限"`
Pms []string `json:"pms" comment:"项目管理员ID"`
Pmp int `json:"pmp" comment:"PM角色权限"`
PmpIds []string `json:"pmpIds" comment:"项目管理员ID"`
Recipients []string `json:"recipients" comment:"被评估人ID"`
Template *EvaluationTemplate `json:"template" comment:"评估模板"`
CreatedAt time.Time `json:"createdAt" comment:"创建时间"`
... ... @@ -23,6 +32,6 @@ 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)
Find(queryOptions map[string]interface{}, excludeColumns ...string) (int64, []*EvaluationProject, error)
Count(queryOptions map[string]interface{}) (int64, error)
}
... ...
... ... @@ -37,12 +37,12 @@ type EntryItem struct {
// NodeContent 评估内容
type NodeContent struct {
Category string `json:"category" comment:"类别"`
Name string `json:"name" comment:"名称"`
RuleId int64 `json:"ruleId" comment:"评估规则ID"`
PromptTitle string `json:"promptTitle" comment:"提示项标题"`
PromptText string `json:"promptText" comment:"提示项正文"`
EntryItems []EntryItem `json:"entryItems" comment:"填写项"`
Category string `json:"category" comment:"类别"`
Name string `json:"name" comment:"名称"`
RuleId int64 `json:"ruleId" comment:"评估规则ID"`
PromptTitle string `json:"promptTitle" comment:"提示项标题"`
PromptText string `json:"promptText" comment:"提示项正文"`
EntryItems []*EntryItem `json:"entryItems" comment:"填写项"`
}
// NodeAllInvite 360°邀请
... ... @@ -57,7 +57,7 @@ type LinkNode struct {
Type int `json:"type" comment:"环节类型(1评估、2邀请、3绩效结果)"`
Name string `json:"name" comment:"环节名称"`
Describe string `json:"describe" comment:"环节描述"`
NodeContents []NodeContent `json:"nodeContents" comment:"环节-评估内容"`
NodeContents []*NodeContent `json:"nodeContents" comment:"环节-评估内容"`
NodeAllInvite *NodeAllInvite `json:"nodeAllInvite" comment:"环节-360°邀请"`
NodeKpiResult *NodeKpiResult `json:"nodeKpiResult" comment:"环节-绩效结果"`
TimeStart *time.Time `json:"timeStart" comment:"起始时间"`
... ...
... ... @@ -12,8 +12,10 @@ type EvaluationProject struct {
Describe string `comment:"描述"`
CompanyId int64 `comment:"公司ID"`
CreatorId int64 `comment:"创建人ID"`
State int `comment:"状态(0待完成配置、1待启用、2启用、3停用)"`
HrBp int `comment:"HR角色权限"`
Pms []string `comment:"项目管理员ID"`
Pmp int `comment:"PM角色权限"`
PmpIds []string `comment:"项目管理员ID"`
Recipients []string `comment:"被评估人ID"`
Template *domain.EvaluationTemplate `comment:"评估模板"`
CreatedAt time.Time `comment:"创建时间"`
... ...
... ... @@ -27,8 +27,10 @@ func (repo *EvaluationProjectRepository) TransformToDomain(m *models.EvaluationP
Describe: m.Describe,
CompanyId: m.CompanyId,
CreatorId: m.CreatorId,
State: m.State,
HrBp: m.HrBp,
Pms: m.Pms,
Pmp: m.Pmp,
PmpIds: m.PmpIds,
Recipients: m.Recipients,
Template: m.Template,
CreatedAt: m.CreatedAt,
... ... @@ -44,8 +46,10 @@ func (repo *EvaluationProjectRepository) TransformToModel(d *domain.EvaluationPr
Describe: d.Describe,
CompanyId: d.CompanyId,
CreatorId: d.CreatorId,
State: d.State,
HrBp: d.HrBp,
Pms: d.Pms,
Pmp: d.Pmp,
PmpIds: d.PmpIds,
Recipients: d.Recipients,
Template: d.Template,
CreatedAt: d.CreatedAt,
... ... @@ -116,11 +120,15 @@ func (repo *EvaluationProjectRepository) FindOne(queryOptions map[string]interfa
return &u, nil
}
func (repo *EvaluationProjectRepository) Find(queryOptions map[string]interface{}) (int64, []*domain.EvaluationProject, error) {
func (repo *EvaluationProjectRepository) Find(queryOptions map[string]interface{}, excludeColumns ...string) (int64, []*domain.EvaluationProject, error) {
tx := repo.transactionContext.PgTx
var m []*models.EvaluationProject
query := tx.Model(&m).Where("deleted_at isnull")
if len(excludeColumns) > 0 {
query.ExcludeColumn(excludeColumns...)
}
if v, ok := queryOptions["name"]; ok {
query.Where("name = ?", v)
}
... ... @@ -129,6 +137,14 @@ func (repo *EvaluationProjectRepository) Find(queryOptions map[string]interface{
query.Where("company_id = ?", v)
}
if v, ok := queryOptions["cycleId"]; ok {
query.Where("cycle_id = ?", v)
}
if v, ok := queryOptions["state"]; ok && v.(int) >= 0 {
query.Where("state = ?", v)
}
if v, ok := queryOptions["limit"].(int); ok {
query.Limit(v)
}
... ... @@ -170,6 +186,10 @@ func (repo *EvaluationProjectRepository) Count(queryOptions map[string]interface
query.Where("company_id = ?", v)
}
if v, ok := queryOptions["cycleId"]; ok {
query.Where("cycle_id = ?", v)
}
count, err := query.Count()
if err != nil {
return 0, err
... ...
package controllers
import (
"github.com/linmadan/egglib-go/core/application"
"github.com/linmadan/egglib-go/web/beego"
service "gitlab.fjmaimaimai.com/allied-creation/performance/pkg/application/evaluation_cycle"
"gitlab.fjmaimaimai.com/allied-creation/performance/pkg/application/evaluation_cycle/command"
"gitlab.fjmaimaimai.com/allied-creation/performance/pkg/port/beego/middlewares"
)
type CycleController struct {
beego.BaseController
}
func (controller *RoleController) CreateCycle() {
ruService := service.NewEvaluationCycleService()
in := &command.CreateCycleCommand{}
if err := controller.Unmarshal(in); err != nil {
controller.Response(nil, application.ThrowError(application.ARG_ERROR, err.Error()))
} else {
in.CompanyId = middlewares.GetCompanyId(controller.Ctx)
in.CreatorId = middlewares.GetUserId(controller.Ctx)
controller.Response(ruService.Create(in))
}
}
func (controller *CycleController) UpdateCycle() {
ruService := service.NewEvaluationCycleService()
in := &command.UpdateCycleCommand{}
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 *CycleController) GetCycle() {
ruService := service.NewEvaluationCycleService()
in := &command.GetCycleCommand{}
if id, err := controller.GetInt64(":Id"); err != nil {
controller.Response(nil, application.ThrowError(application.ARG_ERROR, err.Error()))
} else {
in.Id = id
controller.Response(ruService.Get(in))
}
}
func (controller *CycleController) RemoveCycle() {
ruService := service.NewEvaluationCycleService()
in := &command.DeleteCycleCommand{}
if err := controller.Unmarshal(in); err != nil {
controller.Response(nil, application.ThrowError(application.ARG_ERROR, err.Error()))
} else {
controller.Response(ruService.Remove(in))
}
}
func (controller *CycleController) ListCycle() {
ruService := service.NewEvaluationCycleService()
in := &command.QueryCycleCommand{}
if err := controller.Unmarshal(in); err != nil {
controller.Response(nil, application.ThrowError(application.ARG_ERROR, err.Error()))
} else {
if len(in.Name) > 0 {
in.Name = "%" + in.Name + "%"
}
in.CompanyId = middlewares.GetCompanyId(controller.Ctx)
controller.Response(ruService.List(in))
}
}
... ...
package controllers
import (
"github.com/linmadan/egglib-go/core/application"
"github.com/linmadan/egglib-go/web/beego"
service "gitlab.fjmaimaimai.com/allied-creation/performance/pkg/application/evaluation_project"
"gitlab.fjmaimaimai.com/allied-creation/performance/pkg/application/evaluation_project/command"
"gitlab.fjmaimaimai.com/allied-creation/performance/pkg/port/beego/middlewares"
)
type ProjectController struct {
beego.BaseController
}
func (controller *RoleController) CreateProject() {
ruService := service.NewEvaluationProjectService()
in := &command.CreateProjectCommand{}
if err := controller.Unmarshal(in); err != nil {
controller.Response(nil, application.ThrowError(application.ARG_ERROR, err.Error()))
} else {
in.CompanyId = middlewares.GetCompanyId(controller.Ctx)
in.CreatorId = middlewares.GetUserId(controller.Ctx)
controller.Response(ruService.Create(in))
}
}
func (controller *ProjectController) UpdateProject() {
ruService := service.NewEvaluationProjectService()
in := &command.UpdateProjectCommand{}
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 *ProjectController) UpdateProjectForTemplate() {
ruService := service.NewEvaluationProjectService()
in := &command.UpdateProjectTemplateCommand{}
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.UpdateTemplate(in))
}
}
func (controller *ProjectController) UpdateProjectForTemplateNode() {
ruService := service.NewEvaluationProjectService()
in := &command.UpdateProjectTemplateNodeCommand{}
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.UpdateTemplateNode(in))
}
}
func (controller *ProjectController) GetProject() {
ruService := service.NewEvaluationProjectService()
in := &command.GetProjectCommand{}
if id, err := controller.GetInt64(":Id"); err != nil {
controller.Response(nil, application.ThrowError(application.ARG_ERROR, err.Error()))
} else {
in.Id = id
controller.Response(ruService.Get(in))
}
}
func (controller *ProjectController) RemoveProject() {
ruService := service.NewEvaluationProjectService()
in := &command.DeleteProjectCommand{}
if err := controller.Unmarshal(in); err != nil {
controller.Response(nil, application.ThrowError(application.ARG_ERROR, err.Error()))
} else {
controller.Response(ruService.Remove(in))
}
}
func (controller *ProjectController) ListProject() {
ruService := service.NewEvaluationProjectService()
in := &command.QueryProjectCommand{}
in.State = -1 // 设置默认状态
if err := controller.Unmarshal(in); err != nil {
controller.Response(nil, application.ThrowError(application.ARG_ERROR, err.Error()))
} else {
if len(in.Name) > 0 {
in.Name = "%" + in.Name + "%"
}
in.CompanyId = middlewares.GetCompanyId(controller.Ctx)
controller.Response(ruService.List(in))
}
}
func (controller *ProjectController) StateProject() {
ruService := service.NewEvaluationProjectService()
in := &command.StateProjectCommand{}
if err := controller.Unmarshal(in); err != nil {
controller.Response(nil, application.ThrowError(application.ARG_ERROR, err.Error()))
} else {
controller.Response(ruService.State(in))
}
}
func (controller *ProjectController) CopyProject() {
ruService := service.NewEvaluationProjectService()
in := &command.CopyProjectCommand{}
if err := controller.Unmarshal(in); err != nil {
controller.Response(nil, application.ThrowError(application.ARG_ERROR, err.Error()))
} else {
controller.Response(ruService.Copy(in))
}
}
... ...
... ... @@ -63,6 +63,9 @@ func (controller *RuleController) ListRule() {
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))
}
... ...
... ... @@ -31,7 +31,6 @@ func (controller *TemplateController) UpdateTemplate() {
controller.Response(nil, application.ThrowError(application.ARG_ERROR, err.Error()))
} else {
in.CompanyId = middlewares.GetCompanyId(controller.Ctx)
in.CreatorId = middlewares.GetUserId(controller.Ctx)
controller.Response(ruService.Update(in))
}
}
... ... @@ -63,6 +62,9 @@ func (controller *TemplateController) ListTemplate() {
if err := controller.Unmarshal(in); err != nil {
controller.Response(nil, application.ThrowError(application.ARG_ERROR, err.Error()))
} else {
if len(in.Name) > 0 {
in.Name = "%" + in.Name + "%"
}
in.CompanyId = middlewares.GetCompanyId(controller.Ctx)
controller.Response(ruService.List(in))
}
... ...