作者 郑周

1. 考核结果 回填值优化

@@ -368,6 +368,7 @@ func (srv *SummaryEvaluationService) buildSummaryItemValue(itemList []*domain.Ev @@ -368,6 +368,7 @@ func (srv *SummaryEvaluationService) buildSummaryItemValue(itemList []*domain.Ev
368 item.Value = value.Value 368 item.Value = value.Value
369 item.Remark = value.Remark 369 item.Remark = value.Remark
370 item.Rating = value.Rating 370 item.Rating = value.Rating
  371 + item.EvaluatorName = value.Executor.UserName
371 } 372 }
372 itemValues = append(itemValues, item) 373 itemValues = append(itemValues, item)
373 } 374 }
@@ -463,24 +464,14 @@ func (srv *SummaryEvaluationService) getSummaryEvaluation(transactionContext app @@ -463,24 +464,14 @@ func (srv *SummaryEvaluationService) getSummaryEvaluation(transactionContext app
463 TotalScore: evaluationData.TotalScore, 464 TotalScore: evaluationData.TotalScore,
464 } 465 }
465 //获取用户信息 466 //获取用户信息
466 - companyRepo := factory.CreateCompanyRepository(map[string]interface{}{  
467 - "transactionContext": transactionContext,  
468 - })  
469 - userRepo := factory.CreateUserRepository(map[string]interface{}{  
470 - "transactionContext": transactionContext,  
471 - })  
472 -  
473 - companyData, err := companyRepo.FindOne(map[string]interface{}{  
474 - "id": evaluationData.CompanyId,  
475 - }) 467 + companyRepo := factory.CreateCompanyRepository(map[string]interface{}{"transactionContext": transactionContext})
  468 + userRepo := factory.CreateUserRepository(map[string]interface{}{"transactionContext": transactionContext})
476 469
  470 + companyData, err := companyRepo.FindOne(map[string]interface{}{"id": evaluationData.CompanyId})
477 if err != nil { 471 if err != nil {
478 return result 472 return result
479 } 473 }
480 -  
481 - userData, err := userRepo.FindOne(map[string]interface{}{  
482 - "id": evaluationData.TargetUser.UserId,  
483 - }) 474 + userData, err := userRepo.FindOne(map[string]interface{}{"id": evaluationData.TargetUser.UserId})
484 if err != nil { 475 if err != nil {
485 return result 476 return result
486 } 477 }
@@ -488,16 +479,13 @@ func (srv *SummaryEvaluationService) getSummaryEvaluation(transactionContext app @@ -488,16 +479,13 @@ func (srv *SummaryEvaluationService) getSummaryEvaluation(transactionContext app
488 result.CompanyLogo = companyData.Logo 479 result.CompanyLogo = companyData.Logo
489 result.CompanyName = companyData.Name 480 result.CompanyName = companyData.Name
490 481
491 - if userData.ParentId <= 0 {  
492 - return result  
493 - }  
494 - pUserData, err := userRepo.FindOne(map[string]interface{}{  
495 - "id": userData.ParentId,  
496 - })  
497 - if err != nil {  
498 - return result 482 + if userData.ParentId > 0 {
  483 + pUserData, err := userRepo.FindOne(map[string]interface{}{"id": userData.ParentId})
  484 + if err != nil {
  485 + return result
  486 + }
  487 + result.SupperUser = pUserData.Name
499 } 488 }
500 - result.SupperUser = pUserData.Name  
501 return result 489 return result
502 } 490 }
503 491
@@ -1444,39 +1432,110 @@ func (srv *SummaryEvaluationService) ListExecutorEvaluationSuper(param *command. @@ -1444,39 +1432,110 @@ func (srv *SummaryEvaluationService) ListExecutorEvaluationSuper(param *command.
1444 return result, nil 1432 return result, nil
1445 } 1433 }
1446 1434
1447 -// 员工确认综评考核结果  
1448 -func (srv *SummaryEvaluationService) ConfirmScoreSuperEvaluation(param *command.ConfirmScore) error {  
1449 - transactionContext, err := factory.CreateTransactionContext(nil) 1435 +// ConfirmScoreEvaluation 员工确认考核结果
  1436 +func (srv *SummaryEvaluationService) ConfirmScoreEvaluation(param *command.ConfirmScore) error {
  1437 + transactionContext, err := factory.ValidateStartTransaction(param)
1450 if err != nil { 1438 if err != nil {
1451 - return application.ThrowError(application.TRANSACTION_ERROR, err.Error())  
1452 - }  
1453 - if err := transactionContext.StartTransaction(); err != nil {  
1454 - return application.ThrowError(application.TRANSACTION_ERROR, err.Error()) 1439 + return err
1455 } 1440 }
1456 defer func() { 1441 defer func() {
1457 _ = transactionContext.RollbackTransaction() 1442 _ = transactionContext.RollbackTransaction()
1458 }() 1443 }()
1459 - evaluationRepo := factory.CreateSummaryEvaluationRepository(map[string]interface{}{  
1460 - "transactionContext": transactionContext,  
1461 - })  
1462 1444
1463 - evaluationData, err := evaluationRepo.FindOne(map[string]interface{}{  
1464 - "id": param.SummaryEvaluationId,  
1465 - }) 1445 + evaluationRepo := factory.CreateSummaryEvaluationRepository(map[string]interface{}{"transactionContext": transactionContext})
  1446 + evaluationItemRepo := factory.CreateEvaluationItemUsedRepository(map[string]interface{}{"transactionContext": transactionContext})
  1447 + itemValueRepo := factory.CreateSummaryEvaluationValueRepository(map[string]interface{}{"transactionContext": transactionContext})
  1448 +
  1449 + // 考核结果
  1450 + result, err := evaluationRepo.FindOne(map[string]interface{}{"id": param.SummaryEvaluationId})
1466 if err != nil { 1451 if err != nil {
1467 return application.ThrowError(application.TRANSACTION_ERROR, err.Error()) 1452 return application.ThrowError(application.TRANSACTION_ERROR, err.Error())
1468 } 1453 }
1469 - if evaluationData.Types != domain.EvaluationSuper { 1454 + if result.Types != domain.EvaluationFinish {
1470 return application.ThrowError(application.TRANSACTION_ERROR, "操作方式错误") 1455 return application.ThrowError(application.TRANSACTION_ERROR, "操作方式错误")
1471 } 1456 }
1472 - if evaluationData.TargetUser.UserId != param.UserId { 1457 + if result.TargetUser.UserId != param.UserId {
1473 return application.ThrowError(application.TRANSACTION_ERROR, "没有操作权限") 1458 return application.ThrowError(application.TRANSACTION_ERROR, "没有操作权限")
1474 } 1459 }
1475 - if evaluationData.Status == domain.EvaluationUncompleted {  
1476 - return application.ThrowError(application.TRANSACTION_ERROR, "上级还未正式提交评估内容") 1460 + if result.CheckResult == domain.EvaluationCheckCompleted {
  1461 + return application.ThrowError(application.TRANSACTION_ERROR, "考核结果已确认过了!")
1477 } 1462 }
1478 - evaluationData.CheckResult = domain.EvaluationCheckCompleted  
1479 - err = evaluationRepo.Save(evaluationData) 1463 + if result.Status == domain.EvaluationUncompleted {
  1464 + return application.ThrowError(application.TRANSACTION_ERROR, "前面流程暂未完成提交评估内容")
  1465 + }
  1466 +
  1467 + _, evaluationList, err := evaluationRepo.Find(map[string]interface{}{
  1468 + "companyId": result.CompanyId,
  1469 + "cycleId": result.CycleId,
  1470 + "targetUserId": result.TargetUser.UserId,
  1471 + })
  1472 + if err != nil {
  1473 + return application.ThrowError(application.INTERNAL_SERVER_ERROR, err.Error())
  1474 + }
  1475 +
  1476 + var super *domain.SummaryEvaluation // 上级评估
  1477 + for i := range evaluationList {
  1478 + it := evaluationList[i]
  1479 + if it.Types == domain.EvaluationSuper {
  1480 + super = it
  1481 + break
  1482 + }
  1483 + }
  1484 +
  1485 + // 评估内容和值
  1486 + var itemList []*domain.EvaluationItemUsed
  1487 + var itemValues []*domain.SummaryEvaluationValue
  1488 +
  1489 + // 获取自评模板内容
  1490 + _, itemList, err = evaluationItemRepo.Find(map[string]interface{}{"evaluationProjectId": result.EvaluationProjectId, "nodeType": domain.LinkNodeSelfAssessment})
  1491 + if err != nil {
  1492 + return application.ThrowError(application.INTERNAL_SERVER_ERROR, err.Error())
  1493 + }
  1494 +
  1495 + // 按评估项优先级顺序(已确认考核结果 ->上级评估 ->HR或360评估或自评)
  1496 + if super != nil {
  1497 + _, itemValues, err = itemValueRepo.Find(map[string]interface{}{"summaryEvaluationId": super.Id}) // 获取已填写的评估内容
  1498 + if err != nil {
  1499 + return application.ThrowError(application.INTERNAL_SERVER_ERROR, err.Error())
  1500 + }
  1501 + } else {
  1502 + // 评估项ID(除考核结果和上级)
  1503 + var evaluationIds = make([]int, 0)
  1504 + for i := range evaluationList {
  1505 + it := evaluationList[i]
  1506 + if it.Types == domain.EvaluationSelf || it.Types == domain.Evaluation360 || it.Types == domain.EvaluationHrbp {
  1507 + evaluationIds = append(evaluationIds, it.Id)
  1508 + }
  1509 + }
  1510 + if len(evaluationIds) > 0 {
  1511 + // 获取已填写的评估内容
  1512 + _, itemValues, err = itemValueRepo.Find(map[string]interface{}{"summaryEvaluationIdList": evaluationIds})
  1513 + if err != nil {
  1514 + return application.ThrowError(application.INTERNAL_SERVER_ERROR, err.Error())
  1515 + }
  1516 +
  1517 + // 更新填写值
  1518 + itemValues, err = srv.updateItemValuePriority(result, itemList, itemValues)
  1519 + if err != nil {
  1520 + return application.ThrowError(application.INTERNAL_SERVER_ERROR, err.Error())
  1521 + }
  1522 +
  1523 + for i := range itemValues {
  1524 + err = itemValueRepo.Save(itemValues[i])
  1525 + if err != nil {
  1526 + return application.ThrowError(application.INTERNAL_SERVER_ERROR, err.Error())
  1527 + }
  1528 + }
  1529 + }
  1530 + }
  1531 +
  1532 + err = result.EvaluationTotalScore(itemValues)
  1533 + if err != nil {
  1534 + return application.ThrowError(application.TRANSACTION_ERROR, err.Error())
  1535 + }
  1536 +
  1537 + result.CheckResult = domain.EvaluationCheckCompleted
  1538 + err = evaluationRepo.Save(result)
1480 if err != nil { 1539 if err != nil {
1481 return application.ThrowError(application.TRANSACTION_ERROR, err.Error()) 1540 return application.ThrowError(application.TRANSACTION_ERROR, err.Error())
1482 } 1541 }
@@ -1486,9 +1545,168 @@ func (srv *SummaryEvaluationService) ConfirmScoreSuperEvaluation(param *command. @@ -1486,9 +1545,168 @@ func (srv *SummaryEvaluationService) ConfirmScoreSuperEvaluation(param *command.
1486 return nil 1545 return nil
1487 } 1546 }
1488 1547
1489 -// 按照周期和被评估的人 获取上级评估详情 1548 +//// 按评估项优先级顺序(已确认考核结果 ->上级评估 ->HR或360评估 ->自评)
  1549 +//func (srv *SummaryEvaluationService) getEvaluationResult(list []*domain.SummaryEvaluation) (*domain.SummaryEvaluation, []*domain.SummaryEvaluation) {
  1550 +// var finish *domain.SummaryEvaluation // 绩效考核结果项(已完成确认)
  1551 +// var result *domain.SummaryEvaluation // 绩效考核结果项
  1552 +// var super *domain.SummaryEvaluation // 上级评估
  1553 +// var self *domain.SummaryEvaluation // 我的自评
  1554 +// var hr360 = make([]*domain.SummaryEvaluation, 0) // 评估项
  1555 +//
  1556 +// for i := range list {
  1557 +// it := list[i]
  1558 +//
  1559 +// if it.Types == domain.EvaluationFinish {
  1560 +// result = it
  1561 +// if it.CheckResult == domain.EvaluationCheckCompleted { // 绩效结果已确认
  1562 +// finish = it
  1563 +// break
  1564 +// }
  1565 +// } else if it.Types == domain.EvaluationSuper {
  1566 +// super = it
  1567 +// } else if it.Types == domain.EvaluationSelf {
  1568 +// self = it
  1569 +// } else if it.Types == domain.Evaluation360 || it.Types == domain.EvaluationHrbp {
  1570 +// hr360 = append(hr360, it)
  1571 +// }
  1572 +// }
  1573 +// if finish != nil {
  1574 +// return result, []*domain.SummaryEvaluation{finish}
  1575 +// }
  1576 +//
  1577 +// if super != nil {
  1578 +// return result, []*domain.SummaryEvaluation{super}
  1579 +// }
  1580 +//
  1581 +// if len(hr360) > 0 {
  1582 +// return result, hr360
  1583 +// }
  1584 +//
  1585 +// if self != nil {
  1586 +// return result, []*domain.SummaryEvaluation{self}
  1587 +// }
  1588 +//
  1589 +// return result, []*domain.SummaryEvaluation{}
  1590 +//}
  1591 +
  1592 +//func (srv *SummaryEvaluationService) findSummaryEvaluationByType(
  1593 +// repo domain.SummaryEvaluationRepository,
  1594 +// param *command.QueryEvaluation,
  1595 +// eType domain.EvaluationType) ([]*domain.SummaryEvaluation, error) {
  1596 +// p := map[string]interface{}{
  1597 +// "companyId": param.CompanyId,
  1598 +// "cycleId": param.CycleId,
  1599 +// "targetUserId": param.TargetUserId,
  1600 +// }
  1601 +// if eType == domain.EvaluationFinish || eType == domain.EvaluationSuper || eType == domain.EvaluationSelf {
  1602 +// p["types"] = eType
  1603 +// p["limit"] = 1
  1604 +// } else if eType == domain.Evaluation360 || eType == domain.EvaluationHrbp {
  1605 +// p["typesList"] = []int{int(domain.Evaluation360), int(domain.EvaluationHrbp)}
  1606 +// }
  1607 +// _, list, err := repo.Find(p)
  1608 +// if err != nil {
  1609 +// return nil, application.ThrowError(application.INTERNAL_SERVER_ERROR, err.Error())
  1610 +// }
  1611 +// return list, nil
  1612 +//}
  1613 +
  1614 +//func (srv *SummaryEvaluationService) findEvaluationItemValue(
  1615 +// repo domain.SummaryEvaluationRepository,
  1616 +// valueRepo domain.SummaryEvaluationValueRepository,
  1617 +// param *command.QueryEvaluation) (domain.EvaluationType, []*domain.SummaryEvaluationValue, error) {
  1618 +// var eType = domain.EvaluationSuper
  1619 +// list, err := srv.findSummaryEvaluationByType(repo, param, eType)
  1620 +// if err != nil {
  1621 +// return eType, nil, application.ThrowError(application.INTERNAL_SERVER_ERROR, err.Error())
  1622 +// }
  1623 +// if len(list) == 0 {
  1624 +// eType = domain.Evaluation360
  1625 +// list, err = srv.findSummaryEvaluationByType(repo, param, eType)
  1626 +// if err != nil {
  1627 +// return eType, nil, application.ThrowError(application.INTERNAL_SERVER_ERROR, err.Error())
  1628 +// }
  1629 +// }
  1630 +// if len(list) == 0 {
  1631 +// eType = domain.EvaluationSelf
  1632 +// list, err = srv.findSummaryEvaluationByType(repo, param, eType)
  1633 +// if err != nil {
  1634 +// return eType, nil, application.ThrowError(application.INTERNAL_SERVER_ERROR, err.Error())
  1635 +// }
  1636 +// }
  1637 +// if len(list) == 0 {
  1638 +// return eType, nil, application.ThrowError(application.INTERNAL_SERVER_ERROR, "没有找到符合条件的数据")
  1639 +// }
  1640 +//
  1641 +// evaluationIds := make([]int, 0)
  1642 +// for _, v := range list {
  1643 +// evaluationIds = append(evaluationIds, v.Id)
  1644 +// }
  1645 +// // 获取已填写的评估内容
  1646 +// _, itemValues, err := valueRepo.Find(map[string]interface{}{"summaryEvaluationIdList": evaluationIds})
  1647 +// if err != nil {
  1648 +// return eType, nil, err
  1649 +// }
  1650 +// return eType, itemValues, nil
  1651 +//}
  1652 +//
  1653 +
  1654 +// 处理优先级
  1655 +func (srv *SummaryEvaluationService) updateItemValuePriority(
  1656 + result *domain.SummaryEvaluation,
  1657 + itemList []*domain.EvaluationItemUsed,
  1658 + itemValues []*domain.SummaryEvaluationValue) ([]*domain.SummaryEvaluationValue, error) {
  1659 +
  1660 + tempSelf := map[int]*domain.SummaryEvaluationValue{}
  1661 + temp360 := map[int]*domain.SummaryEvaluationValue{}
  1662 + tempHRBP := map[int]*domain.SummaryEvaluationValue{}
  1663 + for i := range itemValues {
  1664 + it := itemValues[i]
  1665 + if it.Types == domain.EvaluationSelf {
  1666 + tempSelf[it.EvaluationItemId] = it
  1667 + } else if it.Types == domain.Evaluation360 {
  1668 + temp360[it.EvaluationItemId] = it
  1669 + } else if it.Types == domain.EvaluationHrbp {
  1670 + tempHRBP[it.EvaluationItemId] = it
  1671 + }
  1672 + }
  1673 + nowTime := time.Now()
  1674 + var newItemValues = make([]*domain.SummaryEvaluationValue, 0)
  1675 + for i := range itemList {
  1676 + it := itemList[i]
  1677 +
  1678 + var tempValue domain.SummaryEvaluationValue
  1679 + tempValue.SetBlankValue(result, it)
  1680 +
  1681 + if it.EvaluatorId == 0 {
  1682 + if v, ok := tempSelf[it.Id]; ok {
  1683 + tempValue = *v
  1684 + }
  1685 + tempValue.Types = domain.EvaluationSelf
  1686 + } else if it.EvaluatorId == -1 {
  1687 + if v, ok := tempHRBP[it.Id]; ok {
  1688 + tempValue = *v
  1689 + }
  1690 + tempValue.Types = domain.EvaluationHrbp
  1691 + } else if it.EvaluatorId > 0 {
  1692 + if v, ok := temp360[it.Id]; ok {
  1693 + tempValue = *v
  1694 + }
  1695 + tempValue.Types = domain.Evaluation360
  1696 + }
  1697 +
  1698 + // 清理ID
  1699 + tempValue.Id = 0
  1700 + tempValue.CreatedAt = nowTime
  1701 + tempValue.UpdatedAt = nowTime
  1702 + newItemValues = append(newItemValues, &tempValue)
  1703 + }
  1704 + return newItemValues, nil
  1705 +}
  1706 +
  1707 +// GetTargetUserEvaluationSuper 按照周期和被评估的人 获取上级评估详情
1490 func (srv *SummaryEvaluationService) GetTargetUserEvaluationSuper(param *command.QueryEvaluation) (*adapter.EvaluationInfoSuperAdapter, error) { 1708 func (srv *SummaryEvaluationService) GetTargetUserEvaluationSuper(param *command.QueryEvaluation) (*adapter.EvaluationInfoSuperAdapter, error) {
1491 - transactionContext, err := factory.CreateTransactionContext(nil) 1709 + transactionContext, err := factory.ValidateStartTransaction(param)
1492 if err != nil { 1710 if err != nil {
1493 return nil, application.ThrowError(application.TRANSACTION_ERROR, err.Error()) 1711 return nil, application.ThrowError(application.TRANSACTION_ERROR, err.Error())
1494 } 1712 }
@@ -1498,94 +1716,94 @@ func (srv *SummaryEvaluationService) GetTargetUserEvaluationSuper(param *command @@ -1498,94 +1716,94 @@ func (srv *SummaryEvaluationService) GetTargetUserEvaluationSuper(param *command
1498 defer func() { 1716 defer func() {
1499 _ = transactionContext.RollbackTransaction() 1717 _ = transactionContext.RollbackTransaction()
1500 }() 1718 }()
1501 - evaluationRepo := factory.CreateSummaryEvaluationRepository(map[string]interface{}{  
1502 - "transactionContext": transactionContext,  
1503 - })  
1504 - evaluationItemRepo := factory.CreateEvaluationItemUsedRepository(map[string]interface{}{  
1505 - "transactionContext": transactionContext,  
1506 - })  
1507 - itemValueRepo := factory.CreateSummaryEvaluationValueRepository(map[string]interface{}{  
1508 - "transactionContext": transactionContext,  
1509 - })  
1510 - permissionRepository := factory.CreatePermissionRepository(map[string]interface{}{"transactionContext": transactionContext})  
1511 - // 获取权限配置  
1512 - _, permissionList, err := permissionRepository.Find(map[string]interface{}{"companyId": param.CompanyId})  
1513 - if err != nil {  
1514 - return nil, application.ThrowError(application.INTERNAL_SERVER_ERROR, err.Error())  
1515 - } 1719 + evaluationRepo := factory.CreateSummaryEvaluationRepository(map[string]interface{}{"transactionContext": transactionContext})
  1720 + evaluationItemRepo := factory.CreateEvaluationItemUsedRepository(map[string]interface{}{"transactionContext": transactionContext})
  1721 + itemValueRepo := factory.CreateSummaryEvaluationValueRepository(map[string]interface{}{"transactionContext": transactionContext})
  1722 +
1516 _, evaluationList, err := evaluationRepo.Find(map[string]interface{}{ 1723 _, evaluationList, err := evaluationRepo.Find(map[string]interface{}{
1517 - "limit": 1, 1724 + "companyId": param.CompanyId,
1518 "cycleId": param.CycleId, 1725 "cycleId": param.CycleId,
1519 "targetUserId": param.TargetUserId, 1726 "targetUserId": param.TargetUserId,
1520 - "types": domain.EvaluationSuper,  
1521 }) 1727 })
1522 if err != nil { 1728 if err != nil {
1523 return nil, application.ThrowError(application.INTERNAL_SERVER_ERROR, err.Error()) 1729 return nil, application.ThrowError(application.INTERNAL_SERVER_ERROR, err.Error())
1524 } 1730 }
1525 - if len(evaluationList) == 0 {  
1526 - return nil, application.ThrowError(application.INTERNAL_SERVER_ERROR, "没有找到符合条件的数据")  
1527 - }  
1528 - evaluationData := evaluationList[0]  
1529 - if evaluationData.CompanyId != param.CompanyId {  
1530 - return nil, application.ThrowError(application.BUSINESS_ERROR, "没有操作权限") 1731 +
  1732 + var result *domain.SummaryEvaluation // 绩效考核结果项
  1733 + var super *domain.SummaryEvaluation // 上级评估
  1734 + for i := range evaluationList {
  1735 + it := evaluationList[i]
  1736 + if it.Types == domain.EvaluationFinish {
  1737 + result = it
  1738 + continue
  1739 + }
  1740 + if it.Types == domain.EvaluationSuper {
  1741 + super = it
  1742 + continue
  1743 + }
1531 } 1744 }
1532 - _, itemList, err := evaluationItemRepo.Find(map[string]interface{}{  
1533 - "evaluationProjectId": evaluationData.EvaluationProjectId,  
1534 - "nodeType": int(domain.LinkNodeSelfAssessment),  
1535 - })  
1536 - if err != nil {  
1537 - return nil, application.ThrowError(application.INTERNAL_SERVER_ERROR, err.Error()) 1745 + if result == nil {
  1746 + return nil, application.ThrowError(application.INTERNAL_SERVER_ERROR, "没有找到符合条件的数据")
1538 } 1747 }
1539 - //获取已填写的评估内容  
1540 - _, itemValues, err := itemValueRepo.Find(map[string]interface{}{  
1541 - "summaryEvaluationId": evaluationData.Id,  
1542 - })  
1543 1748
  1749 + // 评估内容和值
  1750 + var itemList []*domain.EvaluationItemUsed
  1751 + var itemValues []*domain.SummaryEvaluationValue
  1752 +
  1753 + // 获取自评模板内容
  1754 + _, itemList, err = evaluationItemRepo.Find(map[string]interface{}{"evaluationProjectId": result.EvaluationProjectId, "nodeType": domain.LinkNodeSelfAssessment})
1544 if err != nil { 1755 if err != nil {
1545 return nil, application.ThrowError(application.INTERNAL_SERVER_ERROR, err.Error()) 1756 return nil, application.ThrowError(application.INTERNAL_SERVER_ERROR, err.Error())
1546 } 1757 }
1547 - if len(itemValues) == 0 {  
1548 - //上级还未填写评估,获取 360 ,人资评估  
1549 - _, evaluationListOther, err := evaluationRepo.Find(map[string]interface{}{  
1550 - "typesList": []int{int(domain.Evaluation360), int(domain.EvaluationHrbp)},  
1551 - "targetUserId": evaluationData.TargetUser.UserId,  
1552 - "cycleId": evaluationData.CycleId,  
1553 - }) 1758 +
  1759 + // 按评估项优先级顺序(已确认考核结果 ->上级评估 ->HR或360评估或自评)
  1760 + if result.CheckResult == domain.EvaluationCheckCompleted { /* 已完成考核*/
  1761 + _, itemValues, err = itemValueRepo.Find(map[string]interface{}{"summaryEvaluationId": result.Id}) // 获取已填写的评估内容
1554 if err != nil { 1762 if err != nil {
1555 return nil, application.ThrowError(application.INTERNAL_SERVER_ERROR, err.Error()) 1763 return nil, application.ThrowError(application.INTERNAL_SERVER_ERROR, err.Error())
1556 } 1764 }
1557 - evaluationIds := []int{}  
1558 - for _, v := range evaluationListOther {  
1559 - evaluationIds = append(evaluationIds, v.Id)  
1560 - }  
1561 - if len(evaluationIds) > 0 {  
1562 - _, itemValues, err = itemValueRepo.Find(map[string]interface{}{  
1563 - "summaryEvaluationIdList": evaluationIds,  
1564 - }) 1765 + } else {
  1766 + if super != nil {
  1767 + _, itemValues, err = itemValueRepo.Find(map[string]interface{}{"summaryEvaluationId": super.Id}) // 获取已填写的评估内容
1565 if err != nil { 1768 if err != nil {
1566 return nil, application.ThrowError(application.INTERNAL_SERVER_ERROR, err.Error()) 1769 return nil, application.ThrowError(application.INTERNAL_SERVER_ERROR, err.Error())
1567 } 1770 }
  1771 + } else {
  1772 + // 评估项ID(除考核结果和上级)
  1773 + var evaluationIds = make([]int, 0)
  1774 + for i := range evaluationList {
  1775 + it := evaluationList[i]
  1776 + if it.Types == domain.EvaluationSelf || it.Types == domain.Evaluation360 || it.Types == domain.EvaluationHrbp {
  1777 + evaluationIds = append(evaluationIds, it.Id)
  1778 + }
  1779 + }
  1780 + if len(evaluationIds) > 0 {
  1781 + // 获取已填写的评估内容
  1782 + _, itemValues, err = itemValueRepo.Find(map[string]interface{}{"summaryEvaluationIdList": evaluationIds})
  1783 + if err != nil {
  1784 + return nil, application.ThrowError(application.INTERNAL_SERVER_ERROR, err.Error())
  1785 + }
  1786 +
  1787 + // 更新填写值
  1788 + itemValues, err = srv.updateItemValuePriority(result, itemList, itemValues)
  1789 + if err != nil {
  1790 + return nil, application.ThrowError(application.INTERNAL_SERVER_ERROR, err.Error())
  1791 + }
  1792 + }
1568 } 1793 }
1569 } 1794 }
1570 - evaluationBase := srv.getSummaryEvaluation(transactionContext, evaluationData) 1795 +
  1796 + // 基础数据
  1797 + evaluationBase := srv.getSummaryEvaluation(transactionContext, result)
1571 if err := transactionContext.CommitTransaction(); err != nil { 1798 if err := transactionContext.CommitTransaction(); err != nil {
1572 return nil, application.ThrowError(application.INTERNAL_SERVER_ERROR, err.Error()) 1799 return nil, application.ThrowError(application.INTERNAL_SERVER_ERROR, err.Error())
1573 } 1800 }
1574 - //组合 评估填写的值和评估项 1801 +
  1802 + // 组合 评估填写的值和评估项
1575 itemValuesAdapter := srv.buildSummaryItemValue(itemList, itemValues) 1803 itemValuesAdapter := srv.buildSummaryItemValue(itemList, itemValues)
1576 - codeList := []*adapter.LevalCodeCount{} 1804 + codeList := make([]*adapter.LevalCodeCount, 0)
1577 codeMap := map[string]*adapter.LevalCodeCount{} 1805 codeMap := map[string]*adapter.LevalCodeCount{}
1578 - for i, v := range itemValuesAdapter {  
1579 - if len(permissionList) > 0 {  
1580 - if permissionList[0].OptEvalScore == domain.PermissionOff &&  
1581 - v.EvaluatorId > 0 {  
1582 - itemValuesAdapter[i].ForbidEdit = true  
1583 - }  
1584 - if permissionList[0].OptHrScore == domain.PermissionOff &&  
1585 - v.EvaluatorId < 0 {  
1586 - itemValuesAdapter[i].ForbidEdit = true  
1587 - }  
1588 - } 1806 + for _, v := range itemValuesAdapter {
1589 if v.Weight == 0 { 1807 if v.Weight == 0 {
1590 if _, ok := codeMap[v.Value]; !ok { 1808 if _, ok := codeMap[v.Value]; !ok {
1591 code := &adapter.LevalCodeCount{ 1809 code := &adapter.LevalCodeCount{
@@ -1601,12 +1819,12 @@ func (srv *SummaryEvaluationService) GetTargetUserEvaluationSuper(param *command @@ -1601,12 +1819,12 @@ func (srv *SummaryEvaluationService) GetTargetUserEvaluationSuper(param *command
1601 } 1819 }
1602 } 1820 }
1603 1821
1604 - result := adapter.EvaluationInfoSuperAdapter{ 1822 + eiAdapter := adapter.EvaluationInfoSuperAdapter{
1605 EvaluationBaseAdapter: evaluationBase, 1823 EvaluationBaseAdapter: evaluationBase,
1606 LevelCount: codeList, 1824 LevelCount: codeList,
1607 EvaluationItems: itemValuesAdapter, 1825 EvaluationItems: itemValuesAdapter,
1608 } 1826 }
1609 - return &result, nil 1827 + return &eiAdapter, nil
1610 } 1828 }
1611 1829
1612 // 获取周期综合评估下,周期评估列表 1830 // 获取周期综合评估下,周期评估列表
@@ -1834,10 +2052,7 @@ func (srv *SummaryEvaluationService) editEvaluationValue( @@ -1834,10 +2052,7 @@ func (srv *SummaryEvaluationService) editEvaluationValue(
1834 func (srv *SummaryEvaluationService) ListExecutorNowEvaluationSelf(param *command.QueryExecutorEvaluationList) (map[string]interface{}, error) { 2052 func (srv *SummaryEvaluationService) ListExecutorNowEvaluationSelf(param *command.QueryExecutorEvaluationList) (map[string]interface{}, error) {
1835 transactionContext, err := factory.CreateTransactionContext(nil) 2053 transactionContext, err := factory.CreateTransactionContext(nil)
1836 if err != nil { 2054 if err != nil {
1837 - return nil, application.ThrowError(application.TRANSACTION_ERROR, err.Error())  
1838 - }  
1839 - if err := transactionContext.StartTransaction(); err != nil {  
1840 - return nil, application.ThrowError(application.TRANSACTION_ERROR, err.Error()) 2055 + return nil, err
1841 } 2056 }
1842 defer func() { 2057 defer func() {
1843 _ = transactionContext.RollbackTransaction() 2058 _ = transactionContext.RollbackTransaction()
@@ -21,7 +21,7 @@ type EvaluationItemUsed struct { @@ -21,7 +21,7 @@ type EvaluationItemUsed struct {
21 Rule EvaluationRule //评估的选项规则 21 Rule EvaluationRule //评估的选项规则
22 Weight float64 //"权重" 22 Weight float64 //"权重"
23 Required int //必填项 同 NodeContent.Required 23 Required int //必填项 同 NodeContent.Required
24 - EvaluatorId int //项目评估人ID ( 0=无评估人、-1=HRBP、 >0 =员工的id ) 24 + EvaluatorId int //项目评估人ID ( 0=无评估人、-1=HRBP、 >0 员工的id )
25 CreatedAt time.Time //数据创建时间 25 CreatedAt time.Time //数据创建时间
26 UpdatedAt time.Time //数据更新时间 26 UpdatedAt time.Time //数据更新时间
27 } 27 }
@@ -288,8 +288,8 @@ func (c *SummaryEvaluationController) ListExecutorEvaluationSuper() { @@ -288,8 +288,8 @@ func (c *SummaryEvaluationController) ListExecutorEvaluationSuper() {
288 c.Response(data, err) 288 c.Response(data, err)
289 } 289 }
290 290
291 -// 员工确认评估分数  
292 -func (c *SummaryEvaluationController) ConfirmScoreSuperEvaluation() { 291 +// ConfirmScoreEvaluation 员工确认评估分数
  292 +func (c *SummaryEvaluationController) ConfirmScoreEvaluation() {
293 srv := service.NewSummaryEvaluationService() 293 srv := service.NewSummaryEvaluationService()
294 param := &command.ConfirmScore{} 294 param := &command.ConfirmScore{}
295 err := c.BindJSON(param) 295 err := c.BindJSON(param)
@@ -300,7 +300,7 @@ func (c *SummaryEvaluationController) ConfirmScoreSuperEvaluation() { @@ -300,7 +300,7 @@ func (c *SummaryEvaluationController) ConfirmScoreSuperEvaluation() {
300 } 300 }
301 userReq := middlewares.GetUser(c.Ctx) 301 userReq := middlewares.GetUser(c.Ctx)
302 param.UserId = int(userReq.UserId) 302 param.UserId = int(userReq.UserId)
303 - err = srv.ConfirmScoreSuperEvaluation(param) 303 + err = srv.ConfirmScoreEvaluation(param)
304 c.Response(nil, err) 304 c.Response(nil, err)
305 } 305 }
306 306
@@ -27,7 +27,7 @@ func init() { @@ -27,7 +27,7 @@ func init() {
27 web.NSCtrlPost("/evaluation-super", (*controllers.SummaryEvaluationController).GetEvaluationSuper), 27 web.NSCtrlPost("/evaluation-super", (*controllers.SummaryEvaluationController).GetEvaluationSuper),
28 web.NSCtrlPost("/evaluation-super/edit", (*controllers.SummaryEvaluationController).EditEvaluationSuper), 28 web.NSCtrlPost("/evaluation-super/edit", (*controllers.SummaryEvaluationController).EditEvaluationSuper),
29 web.NSCtrlPost("/evaluation-super/list", (*controllers.SummaryEvaluationController).ListExecutorEvaluationSuper), 29 web.NSCtrlPost("/evaluation-super/list", (*controllers.SummaryEvaluationController).ListExecutorEvaluationSuper),
30 - web.NSCtrlPost("/evaluation-super/confirm", (*controllers.SummaryEvaluationController).ConfirmScoreSuperEvaluation), 30 + web.NSCtrlPost("/evaluation-super/confirm", (*controllers.SummaryEvaluationController).ConfirmScoreEvaluation),
31 web.NSCtrlPost("/target_user/evaluation-super", (*controllers.SummaryEvaluationController).GetTargetUserEvaluationSuper), 31 web.NSCtrlPost("/target_user/evaluation-super", (*controllers.SummaryEvaluationController).GetTargetUserEvaluationSuper),
32 web.NSCtrlPost("/evaluation-super/all", (*controllers.SummaryEvaluationController).ListAllEvaluationSuper), 32 web.NSCtrlPost("/evaluation-super/all", (*controllers.SummaryEvaluationController).ListAllEvaluationSuper),
33 web.NSCtrlPost("/evaluation-super/all/export", (*controllers.SummaryEvaluationController).ExportAllEvaluationSuper), 33 web.NSCtrlPost("/evaluation-super/all/export", (*controllers.SummaryEvaluationController).ExportAllEvaluationSuper),