作者 郑周

1. 考核结果 回填值优化

@@ -1484,6 +1484,11 @@ func (srv *SummaryEvaluationService) ConfirmScoreEvaluation(param *command.Confi @@ -1484,6 +1484,11 @@ func (srv *SummaryEvaluationService) ConfirmScoreEvaluation(param *command.Confi
1484 if err != nil { 1484 if err != nil {
1485 return application.ThrowError(application.INTERNAL_SERVER_ERROR, err.Error()) 1485 return application.ThrowError(application.INTERNAL_SERVER_ERROR, err.Error())
1486 } 1486 }
  1487 + // 更新填写值
  1488 + itemValues, err = srv.updateItemValuePriority(result, itemList, itemValues, true)
  1489 + if err != nil {
  1490 + return application.ThrowError(application.INTERNAL_SERVER_ERROR, err.Error())
  1491 + }
1487 } else { 1492 } else {
1488 // 评估项ID(除考核结果和上级) 1493 // 评估项ID(除考核结果和上级)
1489 var evaluationIds = make([]int, 0) 1494 var evaluationIds = make([]int, 0)
@@ -1501,28 +1506,25 @@ func (srv *SummaryEvaluationService) ConfirmScoreEvaluation(param *command.Confi @@ -1501,28 +1506,25 @@ func (srv *SummaryEvaluationService) ConfirmScoreEvaluation(param *command.Confi
1501 } 1506 }
1502 1507
1503 // 更新填写值 1508 // 更新填写值
1504 - itemValues, err = srv.updateItemValuePriority(result, itemList, itemValues) 1509 + itemValues, err = srv.updateItemValuePriority(result, itemList, itemValues, false)
1505 if err != nil { 1510 if err != nil {
1506 return application.ThrowError(application.INTERNAL_SERVER_ERROR, err.Error()) 1511 return application.ThrowError(application.INTERNAL_SERVER_ERROR, err.Error())
1507 } 1512 }
  1513 + }
  1514 + }
1508 1515
1509 - for i := range itemValues {  
1510 - err = itemValueRepo.Save(itemValues[i])  
1511 - if err != nil {  
1512 - return application.ThrowError(application.INTERNAL_SERVER_ERROR, err.Error())  
1513 - }  
1514 - } 1516 + for i := range itemValues {
  1517 + if err := itemValueRepo.Save(itemValues[i]); err != nil {
  1518 + return application.ThrowError(application.INTERNAL_SERVER_ERROR, err.Error())
1515 } 1519 }
1516 } 1520 }
1517 1521
1518 - err = result.EvaluationTotalScore(itemValues)  
1519 - if err != nil { 1522 + if err := result.EvaluationTotalScore(itemValues); err != nil {
1520 return application.ThrowError(application.TRANSACTION_ERROR, err.Error()) 1523 return application.ThrowError(application.TRANSACTION_ERROR, err.Error())
1521 } 1524 }
1522 1525
1523 result.CheckResult = domain.EvaluationCheckCompleted 1526 result.CheckResult = domain.EvaluationCheckCompleted
1524 - err = evaluationRepo.Save(result)  
1525 - if err != nil { 1527 + if err := evaluationRepo.Save(result); err != nil {
1526 return application.ThrowError(application.TRANSACTION_ERROR, err.Error()) 1528 return application.ThrowError(application.TRANSACTION_ERROR, err.Error())
1527 } 1529 }
1528 if err := transactionContext.CommitTransaction(); err != nil { 1530 if err := transactionContext.CommitTransaction(); err != nil {
@@ -1531,121 +1533,18 @@ func (srv *SummaryEvaluationService) ConfirmScoreEvaluation(param *command.Confi @@ -1531,121 +1533,18 @@ func (srv *SummaryEvaluationService) ConfirmScoreEvaluation(param *command.Confi
1531 return nil 1533 return nil
1532 } 1534 }
1533 1535
1534 -//// 按评估项优先级顺序(已确认考核结果 ->上级评估 ->HR或360评估 ->自评)  
1535 -//func (srv *SummaryEvaluationService) getEvaluationResult(list []*domain.SummaryEvaluation) (*domain.SummaryEvaluation, []*domain.SummaryEvaluation) {  
1536 -// var finish *domain.SummaryEvaluation // 绩效考核结果项(已完成确认)  
1537 -// var result *domain.SummaryEvaluation // 绩效考核结果项  
1538 -// var super *domain.SummaryEvaluation // 上级评估  
1539 -// var self *domain.SummaryEvaluation // 我的自评  
1540 -// var hr360 = make([]*domain.SummaryEvaluation, 0) // 评估项  
1541 -//  
1542 -// for i := range list {  
1543 -// it := list[i]  
1544 -//  
1545 -// if it.Types == domain.EvaluationFinish {  
1546 -// result = it  
1547 -// if it.CheckResult == domain.EvaluationCheckCompleted { // 绩效结果已确认  
1548 -// finish = it  
1549 -// break  
1550 -// }  
1551 -// } else if it.Types == domain.EvaluationSuper {  
1552 -// super = it  
1553 -// } else if it.Types == domain.EvaluationSelf {  
1554 -// self = it  
1555 -// } else if it.Types == domain.Evaluation360 || it.Types == domain.EvaluationHrbp {  
1556 -// hr360 = append(hr360, it)  
1557 -// }  
1558 -// }  
1559 -// if finish != nil {  
1560 -// return result, []*domain.SummaryEvaluation{finish}  
1561 -// }  
1562 -//  
1563 -// if super != nil {  
1564 -// return result, []*domain.SummaryEvaluation{super}  
1565 -// }  
1566 -//  
1567 -// if len(hr360) > 0 {  
1568 -// return result, hr360  
1569 -// }  
1570 -//  
1571 -// if self != nil {  
1572 -// return result, []*domain.SummaryEvaluation{self}  
1573 -// }  
1574 -//  
1575 -// return result, []*domain.SummaryEvaluation{}  
1576 -//}  
1577 -  
1578 -//func (srv *SummaryEvaluationService) findSummaryEvaluationByType(  
1579 -// repo domain.SummaryEvaluationRepository,  
1580 -// param *command.QueryEvaluation,  
1581 -// eType domain.EvaluationType) ([]*domain.SummaryEvaluation, error) {  
1582 -// p := map[string]interface{}{  
1583 -// "companyId": param.CompanyId,  
1584 -// "cycleId": param.CycleId,  
1585 -// "targetUserId": param.TargetUserId,  
1586 -// }  
1587 -// if eType == domain.EvaluationFinish || eType == domain.EvaluationSuper || eType == domain.EvaluationSelf {  
1588 -// p["types"] = eType  
1589 -// p["limit"] = 1  
1590 -// } else if eType == domain.Evaluation360 || eType == domain.EvaluationHrbp {  
1591 -// p["typesList"] = []int{int(domain.Evaluation360), int(domain.EvaluationHrbp)}  
1592 -// }  
1593 -// _, list, err := repo.Find(p)  
1594 -// if err != nil {  
1595 -// return nil, application.ThrowError(application.INTERNAL_SERVER_ERROR, err.Error())  
1596 -// }  
1597 -// return list, nil  
1598 -//}  
1599 -  
1600 -//func (srv *SummaryEvaluationService) findEvaluationItemValue(  
1601 -// repo domain.SummaryEvaluationRepository,  
1602 -// valueRepo domain.SummaryEvaluationValueRepository,  
1603 -// param *command.QueryEvaluation) (domain.EvaluationType, []*domain.SummaryEvaluationValue, error) {  
1604 -// var eType = domain.EvaluationSuper  
1605 -// list, err := srv.findSummaryEvaluationByType(repo, param, eType)  
1606 -// if err != nil {  
1607 -// return eType, nil, application.ThrowError(application.INTERNAL_SERVER_ERROR, err.Error())  
1608 -// }  
1609 -// if len(list) == 0 {  
1610 -// eType = domain.Evaluation360  
1611 -// list, err = srv.findSummaryEvaluationByType(repo, param, eType)  
1612 -// if err != nil {  
1613 -// return eType, nil, application.ThrowError(application.INTERNAL_SERVER_ERROR, err.Error())  
1614 -// }  
1615 -// }  
1616 -// if len(list) == 0 {  
1617 -// eType = domain.EvaluationSelf  
1618 -// list, err = srv.findSummaryEvaluationByType(repo, param, eType)  
1619 -// if err != nil {  
1620 -// return eType, nil, application.ThrowError(application.INTERNAL_SERVER_ERROR, err.Error())  
1621 -// }  
1622 -// }  
1623 -// if len(list) == 0 {  
1624 -// return eType, nil, application.ThrowError(application.INTERNAL_SERVER_ERROR, "没有找到符合条件的数据")  
1625 -// }  
1626 -//  
1627 -// evaluationIds := make([]int, 0)  
1628 -// for _, v := range list {  
1629 -// evaluationIds = append(evaluationIds, v.Id)  
1630 -// }  
1631 -// // 获取已填写的评估内容  
1632 -// _, itemValues, err := valueRepo.Find(map[string]interface{}{"summaryEvaluationIdList": evaluationIds})  
1633 -// if err != nil {  
1634 -// return eType, nil, err  
1635 -// }  
1636 -// return eType, itemValues, nil  
1637 -//}  
1638 -//  
1639 -  
1640 // 处理优先级 1536 // 处理优先级
1641 func (srv *SummaryEvaluationService) updateItemValuePriority( 1537 func (srv *SummaryEvaluationService) updateItemValuePriority(
1642 result *domain.SummaryEvaluation, 1538 result *domain.SummaryEvaluation,
1643 itemList []*domain.EvaluationItemUsed, 1539 itemList []*domain.EvaluationItemUsed,
1644 - itemValues []*domain.SummaryEvaluationValue) ([]*domain.SummaryEvaluationValue, error) { 1540 + itemValues []*domain.SummaryEvaluationValue,
  1541 + superior bool) ([]*domain.SummaryEvaluationValue, error) {
1645 1542
1646 tempSelf := map[int]*domain.SummaryEvaluationValue{} 1543 tempSelf := map[int]*domain.SummaryEvaluationValue{}
1647 temp360 := map[int]*domain.SummaryEvaluationValue{} 1544 temp360 := map[int]*domain.SummaryEvaluationValue{}
1648 tempHRBP := map[int]*domain.SummaryEvaluationValue{} 1545 tempHRBP := map[int]*domain.SummaryEvaluationValue{}
  1546 + tempSuperior := map[int]*domain.SummaryEvaluationValue{}
  1547 +
1649 for i := range itemValues { 1548 for i := range itemValues {
1650 it := itemValues[i] 1549 it := itemValues[i]
1651 if it.Types == domain.EvaluationSelf { 1550 if it.Types == domain.EvaluationSelf {
@@ -1654,6 +1553,8 @@ func (srv *SummaryEvaluationService) updateItemValuePriority( @@ -1654,6 +1553,8 @@ func (srv *SummaryEvaluationService) updateItemValuePriority(
1654 temp360[it.EvaluationItemId] = it 1553 temp360[it.EvaluationItemId] = it
1655 } else if it.Types == domain.EvaluationHrbp { 1554 } else if it.Types == domain.EvaluationHrbp {
1656 tempHRBP[it.EvaluationItemId] = it 1555 tempHRBP[it.EvaluationItemId] = it
  1556 + } else if it.Types == domain.EvaluationSuper {
  1557 + tempSuperior[it.EvaluationItemId] = it
1657 } 1558 }
1658 } 1559 }
1659 nowTime := time.Now() 1560 nowTime := time.Now()
@@ -1664,24 +1565,31 @@ func (srv *SummaryEvaluationService) updateItemValuePriority( @@ -1664,24 +1565,31 @@ func (srv *SummaryEvaluationService) updateItemValuePriority(
1664 var tempValue domain.SummaryEvaluationValue 1565 var tempValue domain.SummaryEvaluationValue
1665 tempValue.SetBlankValue(result, it) 1566 tempValue.SetBlankValue(result, it)
1666 1567
1667 - if it.EvaluatorId == 0 {  
1668 - if v, ok := tempSelf[it.Id]; ok {  
1669 - tempValue = *v  
1670 - }  
1671 - tempValue.Types = domain.EvaluationSelf  
1672 - } else if it.EvaluatorId == -1 {  
1673 - if v, ok := tempHRBP[it.Id]; ok { 1568 + if superior /* 上级数据 */ {
  1569 + if v, ok := tempSuperior[it.Id]; ok {
1674 tempValue = *v 1570 tempValue = *v
1675 } 1571 }
1676 - tempValue.Types = domain.EvaluationHrbp  
1677 - } else if it.EvaluatorId > 0 {  
1678 - if v, ok := temp360[it.Id]; ok {  
1679 - tempValue = *v 1572 + tempValue.Types = domain.EvaluationSuper
  1573 + } else /* 其它数据 */ {
  1574 + if it.EvaluatorId == 0 {
  1575 + if v, ok := tempSelf[it.Id]; ok {
  1576 + tempValue = *v
  1577 + }
  1578 + tempValue.Types = domain.EvaluationSelf
  1579 + } else if it.EvaluatorId == -1 {
  1580 + if v, ok := tempHRBP[it.Id]; ok {
  1581 + tempValue = *v
  1582 + }
  1583 + tempValue.Types = domain.EvaluationHrbp
  1584 + } else if it.EvaluatorId > 0 {
  1585 + if v, ok := temp360[it.Id]; ok {
  1586 + tempValue = *v
  1587 + }
  1588 + tempValue.Types = domain.Evaluation360
1680 } 1589 }
1681 - tempValue.Types = domain.Evaluation360  
1682 } 1590 }
1683 1591
1684 - // 清理ID 1592 + // ID置空
1685 tempValue.Id = 0 1593 tempValue.Id = 0
1686 tempValue.CreatedAt = nowTime 1594 tempValue.CreatedAt = nowTime
1687 tempValue.UpdatedAt = nowTime 1595 tempValue.UpdatedAt = nowTime
@@ -1771,7 +1679,7 @@ func (srv *SummaryEvaluationService) GetTargetUserEvaluationSuper(param *command @@ -1771,7 +1679,7 @@ func (srv *SummaryEvaluationService) GetTargetUserEvaluationSuper(param *command
1771 } 1679 }
1772 1680
1773 // 更新填写值 1681 // 更新填写值
1774 - itemValues, err = srv.updateItemValuePriority(result, itemList, itemValues) 1682 + itemValues, err = srv.updateItemValuePriority(result, itemList, itemValues, false)
1775 if err != nil { 1683 if err != nil {
1776 return nil, application.ThrowError(application.INTERNAL_SERVER_ERROR, err.Error()) 1684 return nil, application.ThrowError(application.INTERNAL_SERVER_ERROR, err.Error())
1777 } 1685 }
@@ -803,45 +803,3 @@ func (srv *SummaryEvaluationService) EditEvaluationHRBP(param *command.EditEvalu @@ -803,45 +803,3 @@ func (srv *SummaryEvaluationService) EditEvaluationHRBP(param *command.EditEvalu
803 "evaluationItems": itemValueAdapter, 803 "evaluationItems": itemValueAdapter,
804 }, nil 804 }, nil
805 } 805 }
806 -  
807 -func (srv *SummaryEvaluationService) SummaryEvaluationFinishNotUseSuper(  
808 - evaluation domain.SummaryEvaluation,  
809 - items []*domain.EvaluationItemUsed,  
810 - itemValue []*domain.SummaryEvaluationValue,  
811 -) []*domain.SummaryEvaluationValue {  
812 - typeSelf := map[int]*domain.SummaryEvaluationValue{}  
813 - typeHrbp360 := map[int]*domain.SummaryEvaluationValue{}  
814 - for _, v := range itemValue {  
815 - switch v.Types {  
816 - case domain.EvaluationSelf:  
817 - typeSelf[v.EvaluationItemId] = v  
818 - case domain.Evaluation360, domain.EvaluationHrbp:  
819 - typeHrbp360[v.EvaluationItemId] = v  
820 - }  
821 - }  
822 - newItemValue := []*domain.SummaryEvaluationValue{}  
823 - nowTime := time.Now()  
824 - for _, v := range items {  
825 - var itemValueTemp domain.SummaryEvaluationValue  
826 - if v.EvaluatorId == 0 {  
827 - if v2, ok := typeSelf[v.Id]; ok {  
828 - itemValueTemp = *v2  
829 - }  
830 - } else {  
831 - if v2, ok := typeHrbp360[v.Id]; ok {  
832 - itemValueTemp = *v2  
833 - }  
834 - }  
835 -  
836 - if itemValueTemp.Id == 0 {  
837 - //360 hrbp,或者自评 都没有填写过  
838 - itemValueTemp.SetBlankValue(&evaluation, v)  
839 - }  
840 - //清理id信息  
841 - itemValueTemp.Id = 0  
842 - itemValueTemp.CreatedAt = nowTime  
843 - itemValueTemp.UpdatedAt = nowTime  
844 - newItemValue = append(newItemValue, &itemValueTemp)  
845 - }  
846 - return newItemValue  
847 -}