...
|
...
|
@@ -55,10 +55,19 @@ func (rs *EvaluationProjectService) Create(in *command.CreateProjectCommand) (in |
|
|
if err != nil {
|
|
|
return nil, application.ThrowError(application.INTERNAL_SERVER_ERROR, err.Error())
|
|
|
}
|
|
|
|
|
|
projectAdapter := &adapter.EvaluationProjectAdapter{}
|
|
|
projectAdapter.EvaluationProject = project
|
|
|
if len(project.PmpIds) > 0 {
|
|
|
userRepository := factory.CreateUserRepository(map[string]interface{}{"transactionContext": transactionContext})
|
|
|
_, users, _ := userRepository.Find(map[string]interface{}{"ids": project.PmpIds, "limit": len(project.PmpIds)})
|
|
|
projectAdapter.TransformPmpAdapter(users)
|
|
|
}
|
|
|
|
|
|
if err := transactionContext.CommitTransaction(); err != nil {
|
|
|
return nil, application.ThrowError(application.TRANSACTION_ERROR, err.Error())
|
|
|
}
|
|
|
return project, nil
|
|
|
return projectAdapter, nil
|
|
|
|
|
|
}
|
|
|
|
...
|
...
|
@@ -96,10 +105,19 @@ func (rs *EvaluationProjectService) Update(in *command.UpdateProjectCommand) (in |
|
|
if err != nil {
|
|
|
return nil, application.ThrowError(application.INTERNAL_SERVER_ERROR, err.Error())
|
|
|
}
|
|
|
|
|
|
projectAdapter := &adapter.EvaluationProjectAdapter{}
|
|
|
projectAdapter.EvaluationProject = project
|
|
|
if len(project.PmpIds) > 0 {
|
|
|
userRepository := factory.CreateUserRepository(map[string]interface{}{"transactionContext": transactionContext})
|
|
|
_, users, _ := userRepository.Find(map[string]interface{}{"ids": project.PmpIds, "limit": len(project.PmpIds)})
|
|
|
projectAdapter.TransformPmpAdapter(users)
|
|
|
}
|
|
|
|
|
|
if err := transactionContext.CommitTransaction(); err != nil {
|
|
|
return nil, application.ThrowError(application.TRANSACTION_ERROR, err.Error())
|
|
|
}
|
|
|
return project, nil
|
|
|
return projectAdapter, nil
|
|
|
}
|
|
|
|
|
|
func (rs *EvaluationProjectService) UpdateTemplate(in *command.UpdateProjectTemplateCommand) (interface{}, error) {
|
...
|
...
|
@@ -145,48 +163,33 @@ func (rs *EvaluationProjectService) UpdateTemplate(in *command.UpdateProjectTemp |
|
|
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})
|
|
|
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())
|
|
|
}
|
|
|
|
|
|
// FIXME 启动时,需要激活定时任务
|
|
|
if in.Activate == 1 {
|
|
|
if len(in.Recipients) == 0 {
|
|
|
return nil, application.ThrowError(application.BUSINESS_ERROR, "请添加被评估人")
|
|
|
}
|
|
|
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.Recipients = in.Recipients
|
|
|
project.Template = cycleTemplate.Template
|
|
|
for i := range project.Template.LinkNodes {
|
|
|
node := project.Template.LinkNodes[i]
|
|
|
node.KpiCycle = in.KpiCycle // 设置周期
|
|
|
if node.Type == domain.LinkNodeViewResult {
|
|
|
if in.KpiResultStart != nil {
|
|
|
node.TimeStart = in.KpiResultStart
|
|
|
}
|
|
|
} else {
|
|
|
node.TimeStart = in.TimeStart
|
|
|
node.TimeEnd = in.TimeEnd
|
|
|
}
|
|
|
}
|
|
|
|
|
|
project, err = projectRepository.Insert(project)
|
...
|
...
|
@@ -290,7 +293,7 @@ func (rs *EvaluationProjectService) List(in *command.QueryProjectCommand) (inter |
|
|
return tool_funs.SimpleWrapGridMap(total, projectAdapters), nil
|
|
|
}
|
|
|
|
|
|
func (rs *EvaluationProjectService) State(in *command.StateProjectCommand) (interface{}, error) {
|
|
|
func (rs *EvaluationProjectService) Activate(in *command.ActivateProjectCommand) (interface{}, error) {
|
|
|
transactionContext, err := factory.ValidateStartTransaction(in)
|
|
|
if err != nil {
|
|
|
return nil, err
|
...
|
...
|
@@ -300,13 +303,20 @@ func (rs *EvaluationProjectService) State(in *command.StateProjectCommand) (inte |
|
|
}()
|
|
|
|
|
|
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
|
|
|
if project.Template == nil {
|
|
|
return nil, application.ThrowError(application.BUSINESS_ERROR, "请添加评估模板")
|
|
|
}
|
|
|
|
|
|
if len(project.Recipients) == 0 {
|
|
|
return nil, application.ThrowError(application.BUSINESS_ERROR, "请添加被评估人")
|
|
|
}
|
|
|
|
|
|
project.State = domain.TemplateStateEnable
|
|
|
project, err = projectRepository.Insert(project)
|
|
|
if err != nil {
|
|
|
return nil, application.ThrowError(application.INTERNAL_SERVER_ERROR, err.Error())
|
...
|
...
|
@@ -332,6 +342,10 @@ func (rs *EvaluationProjectService) Copy(in *command.CopyProjectCommand) (interf |
|
|
}
|
|
|
// ID重置
|
|
|
project.Id = 0
|
|
|
project.Name = project.Name + " 副本"
|
|
|
project.CreatorId = in.CreatorId
|
|
|
project.Recipients = make([]string, 0) // 重置被评估人
|
|
|
|
|
|
// 如果拷贝已经启用的模板,默认先设置为待启用
|
|
|
if project.State == domain.ProjectStateEnable {
|
|
|
project.State = domain.ProjectStateWaitActive
|
...
|
...
|
@@ -346,7 +360,7 @@ func (rs *EvaluationProjectService) Copy(in *command.CopyProjectCommand) (interf |
|
|
return project, nil
|
|
|
}
|
|
|
|
|
|
func (rs *EvaluationProjectService) StatisticCycleUser(in *command.StatisticCycleProjectUserCommand) (interface{}, error) {
|
|
|
func (rs *EvaluationProjectService) CheckRecipients(in *command.CheckRecipientCommand) (interface{}, error) {
|
|
|
transactionContext, err := factory.ValidateStartTransaction(in)
|
|
|
if err != nil {
|
|
|
return nil, err
|
...
|
...
|
@@ -354,42 +368,41 @@ func (rs *EvaluationProjectService) StatisticCycleUser(in *command.StatisticCycl |
|
|
defer func() {
|
|
|
transactionContext.RollbackTransaction()
|
|
|
}()
|
|
|
|
|
|
projectRepository := factory.CreateEvaluationProjectRepository(map[string]interface{}{"transactionContext": transactionContext})
|
|
|
_, projects, err := projectRepository.Find(tool_funs.SimpleStructToMap(in), "linkNodes")
|
|
|
|
|
|
_, projects, err := projectRepository.Find(map[string]interface{}{"companyId": in.CompanyId, "cycleId": in.CycleId}, "linkNodes")
|
|
|
if err != nil {
|
|
|
return nil, application.ThrowError(application.INTERNAL_SERVER_ERROR, err.Error())
|
|
|
}
|
|
|
|
|
|
userIds := make([]int64, 0)
|
|
|
userIdMap := map[int64]int64{}
|
|
|
// 周期内的所有项目,员工不能重复被评估
|
|
|
rids := map[string]bool{}
|
|
|
for i := range projects {
|
|
|
project := projects[i]
|
|
|
for j := range project.Recipients {
|
|
|
userId, _ := strconv.ParseInt(project.Recipients[j], 10, 64)
|
|
|
userIdMap[userId] = userId
|
|
|
// 排除当前项目
|
|
|
if in.Id != projects[i].Id {
|
|
|
ids := projects[i].Recipients
|
|
|
for j := range ids {
|
|
|
rids[ids[j]] = true
|
|
|
}
|
|
|
}
|
|
|
}
|
|
|
for _, v := range userIdMap {
|
|
|
userIds = append(userIds, v)
|
|
|
}
|
|
|
|
|
|
userTotal := 0
|
|
|
departmentTotal := 0
|
|
|
if len(userIds) > 0 {
|
|
|
userRepository := factory.CreateUserRepository(map[string]interface{}{"transactionContext": transactionContext})
|
|
|
_, users, _ := userRepository.Find(map[string]interface{}{"ids": userIds, "limit": len(userIds)})
|
|
|
departmentIdMap := map[int]int{}
|
|
|
for i := range users {
|
|
|
for _, v := range users[i].DepartmentId {
|
|
|
departmentIdMap[v] = v
|
|
|
}
|
|
|
repeatNum := 0
|
|
|
for i := range in.Recipients {
|
|
|
id := in.Recipients[i]
|
|
|
if _, ok := rids[id]; ok {
|
|
|
repeatNum++
|
|
|
}
|
|
|
userTotal = len(users)
|
|
|
departmentTotal = len(departmentIdMap)
|
|
|
}
|
|
|
//if repeatNum > 0 {
|
|
|
// return nil, application.ThrowError(application.BUSINESS_ERROR, fmt.Sprintf("有%d人已经在本周期其他项目内,需要将他们移除", repeatNum))
|
|
|
//}
|
|
|
|
|
|
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 map[string]interface{}{"userTotal": userTotal, "departmentTotal": departmentTotal}, nil
|
|
|
return repeatNum, nil
|
|
|
} |
...
|
...
|
|