作者 郑周

1. 增加项目中的 任务负责人ID

2. 任务负责人ID赋值
@@ -13,16 +13,31 @@ type UserAdapter struct { @@ -13,16 +13,31 @@ type UserAdapter struct {
13 type EvaluationProjectAdapter struct { 13 type EvaluationProjectAdapter struct {
14 *domain.EvaluationProject 14 *domain.EvaluationProject
15 RecipientList []*UserAdapter `json:"recipientList" comment:"被评估人"` 15 RecipientList []*UserAdapter `json:"recipientList" comment:"被评估人"`
  16 + Principal *UserAdapter `json:"principal" comment:"任务负责人"`
16 PmpList []*UserAdapter `json:"pmpList" comment:"项目管理员"` 17 PmpList []*UserAdapter `json:"pmpList" comment:"项目管理员"`
17 } 18 }
18 19
19 -func (adapter *EvaluationProjectAdapter) TransformRecipientAdapter(recipients []*domain.User) { 20 +func (adapter *EvaluationProjectAdapter) TransformRecipientAdapter(recipients []*domain.User, principalId string) {
  21 + // 任务负责人ID
  22 + var principalIdInt = int64(0)
  23 + if len(principalId) > 0 {
  24 + i, err := strconv.ParseInt(principalId, 10, 64)
  25 + if err == nil {
  26 + principalIdInt = i
  27 + }
  28 + }
  29 +
20 adapter.RecipientList = make([]*UserAdapter, 0) 30 adapter.RecipientList = make([]*UserAdapter, 0)
21 for i := range recipients { 31 for i := range recipients {
22 - adapter.RecipientList = append(adapter.RecipientList, &UserAdapter{ 32 + ua := &UserAdapter{
23 Id: recipients[i].Id, 33 Id: recipients[i].Id,
24 Name: recipients[i].Name, 34 Name: recipients[i].Name,
25 - }) 35 + }
  36 + adapter.RecipientList = append(adapter.RecipientList, ua)
  37 +
  38 + if ua.Id == principalIdInt {
  39 + adapter.Principal = ua
  40 + }
26 } 41 }
27 } 42 }
28 43
@@ -17,14 +17,15 @@ type UpdateProjectCommand struct { @@ -17,14 +17,15 @@ type UpdateProjectCommand struct {
17 } 17 }
18 18
19 type UpdateProjectTemplateCommand struct { 19 type UpdateProjectTemplateCommand struct {
20 - CompanyId int64 `cname:"公司ID" json:"companyId"`  
21 - CycleId int64 `cname:"周期ID" json:"cycleId,string" valid:"Required"`  
22 - Id int64 `cname:"项目ID" json:"id,string" valid:"Required"`  
23 - TemplateId int64 `cname:"模板ID" json:"templateId,string"`  
24 - Recipients []string `cname:"被评估人ID" json:"recipients"`  
25 - TimeStart string `cname:"自评起始时间" json:"timeStart" valid:"Required"`  
26 - TimeEnd string `cname:"自评截止时间" json:"timeEnd" valid:"Required"`  
27 - KpiCycle int `cname:"评估周期" json:"kpiCycle" valid:"Required"` 20 + CompanyId int64 `cname:"公司ID" json:"companyId"`
  21 + CycleId int64 `cname:"周期ID" json:"cycleId,string" valid:"Required"`
  22 + Id int64 `cname:"项目ID" json:"id,string" valid:"Required"`
  23 + TemplateId int64 `cname:"模板ID" json:"templateId,string"`
  24 + Recipients []string `cname:"被评估人ID" json:"recipients"`
  25 + PrincipalId string `cname:"任务负责人" json:"principalId"`
  26 + TimeStart string `cname:"自评起始时间" json:"timeStart" valid:"Required"`
  27 + TimeEnd string `cname:"自评截止时间" json:"timeEnd" valid:"Required"`
  28 + KpiCycle int `cname:"评估周期" json:"kpiCycle" valid:"Required"`
28 } 29 }
29 30
30 type CheckRecipientCommand struct { 31 type CheckRecipientCommand struct {
@@ -218,6 +218,22 @@ func (rs *EvaluationProjectService) UpdateTemplate(in *command.UpdateProjectTemp @@ -218,6 +218,22 @@ func (rs *EvaluationProjectService) UpdateTemplate(in *command.UpdateProjectTemp
218 return nil, application.ThrowError(application.BUSINESS_ERROR, "请添加模板") 218 return nil, application.ThrowError(application.BUSINESS_ERROR, "请添加模板")
219 } 219 }
220 220
  221 + // 指标任务的项目(存在一项类型为任务指标),必须添加项目负责人
  222 + var isIndicatorTypeTask = false
  223 + outerLoop:
  224 + for i := range cycleTemplate.Template.LinkNodes {
  225 + var node = cycleTemplate.Template.LinkNodes[i]
  226 + for j := range node.NodeContents {
  227 + if node.NodeContents[j].IndicatorType == domain.IndicatorTypeTask {
  228 + isIndicatorTypeTask = true
  229 + break outerLoop
  230 + }
  231 + }
  232 + }
  233 + if isIndicatorTypeTask && len(in.PrincipalId) == 0 {
  234 + return nil, application.ThrowError(application.BUSINESS_ERROR, "请选择任务负责人")
  235 + }
  236 +
221 start, err := time.ParseInLocation("2006-01-02 15:04:05", in.TimeStart, time.Local) 237 start, err := time.ParseInLocation("2006-01-02 15:04:05", in.TimeStart, time.Local)
222 if err != nil { 238 if err != nil {
223 return nil, application.ThrowError(application.INTERNAL_SERVER_ERROR, err.Error()) 239 return nil, application.ThrowError(application.INTERNAL_SERVER_ERROR, err.Error())
@@ -272,6 +288,7 @@ func (rs *EvaluationProjectService) UpdateTemplate(in *command.UpdateProjectTemp @@ -272,6 +288,7 @@ func (rs *EvaluationProjectService) UpdateTemplate(in *command.UpdateProjectTemp
272 project.State = domain.ProjectStateWaitActive 288 project.State = domain.ProjectStateWaitActive
273 } 289 }
274 project.Recipients = in.Recipients 290 project.Recipients = in.Recipients
  291 + project.PrincipalId = in.PrincipalId
275 project.Template = cycleTemplate.Template 292 project.Template = cycleTemplate.Template
276 293
277 // 项目起始截止时间(环节中的时间暂未分开计算) 294 // 项目起始截止时间(环节中的时间暂未分开计算)
@@ -378,7 +395,7 @@ func (rs *EvaluationProjectService) Get(in *command.GetProjectCommand) (interfac @@ -378,7 +395,7 @@ func (rs *EvaluationProjectService) Get(in *command.GetProjectCommand) (interfac
378 395
379 if len(project.Recipients) > 0 { 396 if len(project.Recipients) > 0 {
380 _, users, _ := userRepository.Find(map[string]interface{}{"ids": project.Recipients, "limit": len(project.Recipients)}) 397 _, users, _ := userRepository.Find(map[string]interface{}{"ids": project.Recipients, "limit": len(project.Recipients)})
381 - projectAdapter.TransformRecipientAdapter(users) 398 + projectAdapter.TransformRecipientAdapter(users, project.PrincipalId)
382 } 399 }
383 400
384 if err := transactionContext.CommitTransaction(); err != nil { 401 if err := transactionContext.CommitTransaction(); err != nil {
@@ -767,6 +784,7 @@ func (rs *EvaluationProjectService) Copy(in *command.CopyProjectCommand) (interf @@ -767,6 +784,7 @@ func (rs *EvaluationProjectService) Copy(in *command.CopyProjectCommand) (interf
767 project.Name = project.Name + " 副本" 784 project.Name = project.Name + " 副本"
768 project.CreatorId = in.CreatorId 785 project.CreatorId = in.CreatorId
769 project.Recipients = make([]string, 0) // 重置被评估人 786 project.Recipients = make([]string, 0) // 重置被评估人
  787 + project.PrincipalId = "" // 重置任务负责人
770 788
771 // 如果拷贝已经启用的模板,默认先设置为待启用 789 // 如果拷贝已经启用的模板,默认先设置为待启用
772 if project.State == domain.ProjectStateEnable || project.State == domain.ProjectStatePause { 790 if project.State == domain.ProjectStateEnable || project.State == domain.ProjectStatePause {
@@ -26,6 +26,7 @@ type EvaluationProject struct { @@ -26,6 +26,7 @@ type EvaluationProject struct {
26 Pmp int `json:"pmp" comment:"PM角色权限"` 26 Pmp int `json:"pmp" comment:"PM角色权限"`
27 PmpIds []string `json:"pmpIds" comment:"项目管理员ID"` 27 PmpIds []string `json:"pmpIds" comment:"项目管理员ID"`
28 Recipients []string `json:"recipients" comment:"被评估人ID"` 28 Recipients []string `json:"recipients" comment:"被评估人ID"`
  29 + PrincipalId string `json:"principalId" comment:"任务负责人ID"`
29 Template *EvaluationTemplate `json:"template" comment:"评估模板"` 30 Template *EvaluationTemplate `json:"template" comment:"评估模板"`
30 BeginTime time.Time `json:"beginTime" comment:"项目起始时间"` 31 BeginTime time.Time `json:"beginTime" comment:"项目起始时间"`
31 EndTime time.Time `json:"endTime" comment:"项目截至时间"` 32 EndTime time.Time `json:"endTime" comment:"项目截至时间"`
@@ -20,6 +20,7 @@ type EvaluationProject struct { @@ -20,6 +20,7 @@ type EvaluationProject struct {
20 Pmp int `comment:"PM角色权限" pg:",use_zero"` 20 Pmp int `comment:"PM角色权限" pg:",use_zero"`
21 PmpIds []string `comment:"项目管理员ID"` 21 PmpIds []string `comment:"项目管理员ID"`
22 Recipients []string `comment:"被评估人ID"` 22 Recipients []string `comment:"被评估人ID"`
  23 + PrincipalId string `comment:"任务负责人ID"`
23 Template *domain.EvaluationTemplate `comment:"评估模板"` 24 Template *domain.EvaluationTemplate `comment:"评估模板"`
24 BeginTime time.Time `comment:"项目起始时间"` 25 BeginTime time.Time `comment:"项目起始时间"`
25 EndTime time.Time `comment:"项目截至时间 "` 26 EndTime time.Time `comment:"项目截至时间 "`
@@ -47,6 +47,7 @@ func (repo *EvaluationProjectRepository) TransformToDomain(m *models.EvaluationP @@ -47,6 +47,7 @@ func (repo *EvaluationProjectRepository) TransformToDomain(m *models.EvaluationP
47 Pmp: m.Pmp, 47 Pmp: m.Pmp,
48 PmpIds: m.PmpIds, 48 PmpIds: m.PmpIds,
49 Recipients: m.Recipients, 49 Recipients: m.Recipients,
  50 + PrincipalId: m.PrincipalId,
50 Template: m.Template, 51 Template: m.Template,
51 BeginTime: m.BeginTime, 52 BeginTime: m.BeginTime,
52 EndTime: m.EndTime, 53 EndTime: m.EndTime,
@@ -70,6 +71,7 @@ func (repo *EvaluationProjectRepository) TransformToModel(d *domain.EvaluationPr @@ -70,6 +71,7 @@ func (repo *EvaluationProjectRepository) TransformToModel(d *domain.EvaluationPr
70 Pmp: d.Pmp, 71 Pmp: d.Pmp,
71 PmpIds: d.PmpIds, 72 PmpIds: d.PmpIds,
72 Recipients: d.Recipients, 73 Recipients: d.Recipients,
  74 + PrincipalId: d.PrincipalId,
73 Template: d.Template, 75 Template: d.Template,
74 BeginTime: d.BeginTime, 76 BeginTime: d.BeginTime,
75 EndTime: d.EndTime, 77 EndTime: d.EndTime,
1 1
2 -- 增加指标分类字段, 默认0 2 -- 增加指标分类字段, 默认0
3 ALTER TABLE public.evaluation_item_used ADD indicator_type int4 NOT NULL DEFAULT 0; 3 ALTER TABLE public.evaluation_item_used ADD indicator_type int4 NOT NULL DEFAULT 0;
  4 +COMMENT ON COLUMN public.evaluation_item_used.indicator_type IS '指标类型';
  5 +
  6 +-- 增加项目表-任务负责人ID
  7 +ALTER TABLE public.evaluation_project ADD principal_id text NULL;
  8 +COMMENT ON COLUMN public.evaluation_project.principal_id IS '任务负责人ID';