作者 tangxvhui

更新评估任务的生成

@@ -352,36 +352,103 @@ func (srv StaffAssessServeice) CreateStaffAssessTask(transactionContext applicat @@ -352,36 +352,103 @@ func (srv StaffAssessServeice) CreateStaffAssessTask(transactionContext applicat
352 } 352 }
353 nowTime := time.Now() 353 nowTime := time.Now()
354 354
355 - _, assassessTaskList, err := assessTaskRepo.Find(map[string]interface{}{  
356 - "evaluationProjectId": param.EvaluationProjectId,  
357 - "beginDay": taskBeginTime.Local().Format("2006-01-02"),  
358 - })  
359 - if err != nil {  
360 - return nil, application.ThrowError(application.INTERNAL_SERVER_ERROR, "查询同日期同项目已存在的评估任务"+err.Error())  
361 - }  
362 - var assessTaskData *domain.StaffAssessTask  
363 - //更新旧数据或者新建数据  
364 - if len(assassessTaskList) > 0 {  
365 - assessTaskData = assassessTaskList[0]  
366 - assessTaskData.UpdatedAt = nowTime  
367 - } else {  
368 - //建立新的评估任务  
369 - assessTaskData = &domain.StaffAssessTask{  
370 - Id: 0,  
371 - CompanyId: param.CompanyId,  
372 - EvaluationProjectId: param.EvaluationProjectId,  
373 - EvaluationProjectName: param.EvaluationProjectName,  
374 - CycleId: param.CycleId,  
375 - CycleName: param.CycleName,  
376 - BeginTime: taskBeginTime,  
377 - EndTime: taskEndTime,  
378 - StepList: []domain.AssessTaskStep{},  
379 - ExecutorId: []int{},  
380 - CreatedAt: nowTime,  
381 - UpdatedAt: nowTime,  
382 - DeletedAt: nil,  
383 - BeginDay: taskBeginTime.Local().Format("2006-01-02"),  
384 - } 355 + // _, assassessTaskList, err := assessTaskRepo.Find(map[string]interface{}{
  356 + // "evaluationProjectId": param.EvaluationProjectId,
  357 + // "beginDay": taskBeginTime.Local().Format("2006-01-02"),
  358 + // })
  359 + // if err != nil {
  360 + // return nil, application.ThrowError(application.INTERNAL_SERVER_ERROR, "查询同日期同项目已存在的评估任务"+err.Error())
  361 + // }
  362 + // var assessTaskData *domain.StaffAssessTask
  363 + // //更新旧数据或者新建数据
  364 + // if len(assassessTaskList) > 0 {
  365 + // assessTaskData = assassessTaskList[0]
  366 + // assessTaskData.UpdatedAt = nowTime
  367 + // } else {
  368 + // //建立新的评估任务
  369 + // assessTaskData = &domain.StaffAssessTask{
  370 + // Id: 0,
  371 + // CompanyId: param.CompanyId,
  372 + // EvaluationProjectId: param.EvaluationProjectId,
  373 + // EvaluationProjectName: param.EvaluationProjectName,
  374 + // CycleId: param.CycleId,
  375 + // CycleName: param.CycleName,
  376 + // BeginTime: taskBeginTime,
  377 + // EndTime: taskEndTime,
  378 + // StepList: []domain.AssessTaskStep{},
  379 + // ExecutorId: []int{},
  380 + // CreatedAt: nowTime,
  381 + // UpdatedAt: nowTime,
  382 + // DeletedAt: nil,
  383 + // BeginDay: taskBeginTime.Local().Format("2006-01-02"),
  384 + // }
  385 + // }
  386 + // executorIds := []int{} //提取评估的参与人id
  387 + // executorIdMap := map[int]struct{}{} //过滤重复的用户
  388 + // //从入参中提取参与人
  389 + // for _, v := range param.ExecutorId {
  390 + // if _, ok := executorIdMap[v]; ok {
  391 + // continue
  392 + // }
  393 + // executorIdMap[v] = struct{}{}
  394 + // executorIds = append(executorIds, v)
  395 + // }
  396 + // //就数据中提取参与人
  397 + // for _, v := range assessTaskData.ExecutorId {
  398 + // if _, ok := executorIdMap[v]; ok {
  399 + // continue
  400 + // }
  401 + // executorIdMap[v] = struct{}{}
  402 + // executorIds = append(executorIds, v)
  403 + // }
  404 + // //填入新的参与人id
  405 + // assessTaskData.ExecutorId = executorIds
  406 + // //填充新的评估环节
  407 + // loop:
  408 + // for _, v := range param.StepList {
  409 + // for _, vv := range assessTaskData.StepList {
  410 + // if vv.LinkNodeId == v.LinkNodeId {
  411 + // continue loop
  412 + // }
  413 + // }
  414 + // stepBeginTime, err := time.ParseInLocation("2006-01-02 15:04:05", param.BeginTime, time.Local)
  415 + // if err != nil {
  416 + // return nil, application.ThrowError(application.ARG_ERROR, "评估环节开始时间填写错误,"+param.BeginTime)
  417 + // }
  418 + // stepEndTime, err := time.ParseInLocation("2006-01-02 15:04:05", param.EndTime, time.Local)
  419 + // if err != nil {
  420 + // return nil, application.ThrowError(application.ARG_ERROR, "评估环节结束时间填写错误,"+param.EndTime)
  421 + // }
  422 + // step := domain.AssessTaskStep{
  423 + // SortBy: v.SortBy,
  424 + // LinkNodeId: v.LinkNodeId,
  425 + // LinkNodeName: v.LinkNodeName,
  426 + // LinkNodeType: v.LinkNodeType,
  427 + // BeginTime: stepBeginTime,
  428 + // EndTime: stepEndTime,
  429 + // }
  430 + // assessTaskData.StepList = append(assessTaskData.StepList, step)
  431 + // }
  432 + // //排序流程环节
  433 + // stepList := domain.SortTaskStep(assessTaskData.StepList)
  434 + // sort.Sort(stepList)
  435 + // assessTaskData.StepList = stepList
  436 +
  437 + assessTaskData := &domain.StaffAssessTask{
  438 + Id: 0,
  439 + CompanyId: param.CompanyId,
  440 + EvaluationProjectId: param.EvaluationProjectId,
  441 + EvaluationProjectName: param.EvaluationProjectName,
  442 + CycleId: param.CycleId,
  443 + CycleName: param.CycleName,
  444 + BeginTime: taskBeginTime,
  445 + EndTime: taskEndTime,
  446 + StepList: []domain.AssessTaskStep{},
  447 + ExecutorId: []int{},
  448 + CreatedAt: nowTime,
  449 + UpdatedAt: nowTime,
  450 + DeletedAt: nil,
  451 + BeginDay: taskBeginTime.Local().Format("2006-01-02"),
385 } 452 }
386 executorIds := []int{} //提取评估的参与人id 453 executorIds := []int{} //提取评估的参与人id
387 executorIdMap := map[int]struct{}{} //过滤重复的用户 454 executorIdMap := map[int]struct{}{} //过滤重复的用户
@@ -393,24 +460,8 @@ func (srv StaffAssessServeice) CreateStaffAssessTask(transactionContext applicat @@ -393,24 +460,8 @@ func (srv StaffAssessServeice) CreateStaffAssessTask(transactionContext applicat
393 executorIdMap[v] = struct{}{} 460 executorIdMap[v] = struct{}{}
394 executorIds = append(executorIds, v) 461 executorIds = append(executorIds, v)
395 } 462 }
396 - //就数据中提取参与人  
397 - for _, v := range assessTaskData.ExecutorId {  
398 - if _, ok := executorIdMap[v]; ok {  
399 - continue  
400 - }  
401 - executorIdMap[v] = struct{}{}  
402 - executorIds = append(executorIds, v)  
403 - }  
404 - //填入新的参与人id  
405 assessTaskData.ExecutorId = executorIds 463 assessTaskData.ExecutorId = executorIds
406 - //填充新的评估环节  
407 -loop:  
408 for _, v := range param.StepList { 464 for _, v := range param.StepList {
409 - for _, vv := range assessTaskData.StepList {  
410 - if vv.LinkNodeId == v.LinkNodeId {  
411 - continue loop  
412 - }  
413 - }  
414 stepBeginTime, err := time.ParseInLocation("2006-01-02 15:04:05", param.BeginTime, time.Local) 465 stepBeginTime, err := time.ParseInLocation("2006-01-02 15:04:05", param.BeginTime, time.Local)
415 if err != nil { 466 if err != nil {
416 return nil, application.ThrowError(application.ARG_ERROR, "评估环节开始时间填写错误,"+param.BeginTime) 467 return nil, application.ThrowError(application.ARG_ERROR, "评估环节开始时间填写错误,"+param.BeginTime)
@@ -429,20 +480,45 @@ loop: @@ -429,20 +480,45 @@ loop:
429 } 480 }
430 assessTaskData.StepList = append(assessTaskData.StepList, step) 481 assessTaskData.StepList = append(assessTaskData.StepList, step)
431 } 482 }
432 - //排序流程环节  
433 - stepList := domain.SortTaskStep(assessTaskData.StepList)  
434 - sort.Sort(stepList)  
435 - assessTaskData.StepList = stepList  
436 //添加员工的节点任务 483 //添加员工的节点任务
437 assessList, err := srv.createStaffAssess(transactionContext, assessTaskData) 484 assessList, err := srv.createStaffAssess(transactionContext, assessTaskData)
438 if err != nil { 485 if err != nil {
439 return nil, application.ThrowError(application.INTERNAL_SERVER_ERROR, "生成个人评估项"+err.Error()) 486 return nil, application.ThrowError(application.INTERNAL_SERVER_ERROR, "生成个人评估项"+err.Error())
440 } 487 }
  488 +
  489 + //合并项目评估的新旧数据
  490 + _, assassessTaskList, err := assessTaskRepo.Find(map[string]interface{}{
  491 + "evaluationProjectId": param.EvaluationProjectId,
  492 + "beginDay": taskBeginTime.Local().Format("2006-01-02"),
  493 + })
  494 + if err != nil {
  495 + return nil, application.ThrowError(application.INTERNAL_SERVER_ERROR, "查询同日期同项目已存在的评估任务"+err.Error())
  496 + }
  497 +
  498 + if len(assassessTaskList) > 0 {
  499 + //就数据中提取参与人
  500 + for _, v := range assessTaskData.ExecutorId {
  501 + if _, ok := executorIdMap[v]; ok {
  502 + continue
  503 + }
  504 + executorIdMap[v] = struct{}{}
  505 + executorIds = append(executorIds, v)
  506 + }
  507 + assassessTaskList[0].UpdatedAt = time.Now()
  508 + assassessTaskList[0].ExecutorId = executorIds
  509 + //更新步骤
  510 + assassessTaskList[0].StepList = append(assassessTaskList[0].StepList, assessTaskData.StepList...)\
  511 + asassessTaskData=asassassessTaskList[0]
  512 + //排序流程环节
  513 + stepList := domain.SortTaskStep(assessTaskData.StepList)
  514 + sort.Sort(stepList)
  515 + }
441 _, err = assessTaskRepo.Save(assessTaskData) 516 _, err = assessTaskRepo.Save(assessTaskData)
442 if err != nil { 517 if err != nil {
443 return nil, application.ThrowError(application.INTERNAL_SERVER_ERROR, "保存评估任务"+err.Error()) 518 return nil, application.ThrowError(application.INTERNAL_SERVER_ERROR, "保存评估任务"+err.Error())
444 } 519 }
445 520
  521 + //保存 员工的评估任务
446 assessRepo := factory.CreateStaffAssessRepository(map[string]interface{}{ 522 assessRepo := factory.CreateStaffAssessRepository(map[string]interface{}{
447 "transactionContext": transactionContext, 523 "transactionContext": transactionContext,
448 }) 524 })
@@ -453,6 +529,9 @@ loop: @@ -453,6 +529,9 @@ loop:
453 return nil, application.ThrowError(application.INTERNAL_SERVER_ERROR, "保存个人评估项"+err.Error()) 529 return nil, application.ThrowError(application.INTERNAL_SERVER_ERROR, "保存个人评估项"+err.Error())
454 } 530 }
455 } 531 }
  532 +
  533 + //处理生成的项目评估
  534 +
456 return map[string]interface{}{ 535 return map[string]interface{}{
457 "assessTaskId": assessTaskData.Id, 536 "assessTaskId": assessTaskData.Id,
458 }, nil 537 }, nil