作者 郑周

1. 超级管理员可以重新编辑 上级评估提交流程

... ... @@ -5,7 +5,8 @@ type EditEvaluationValue struct {
ExecutorId int `json:"-"` // 执行人id
CompanyId int `json:"-"` // 公司id
EvaluationItems []UpdatedItemValue `json:"evaluationItems"`
IsTemporary bool `json:"isTemporary"` //是否是临时提交
IsTemporary bool `json:"isTemporary"` // 是否是临时提交
Advanced int `json:"advanced"`
}
type UpdatedItemValue struct {
... ...
... ... @@ -43,4 +43,6 @@ type QueryEvaluationHRBP struct {
type QueryEvaluationSuper struct {
SummaryEvaluationId int `json:"summaryEvaluationId,string"`
CompanyId int `json:"-"`
UserId int `json:"-"`
Advanced int `json:"advanced"`
}
... ...
... ... @@ -1091,6 +1091,79 @@ func (srv *SummaryEvaluationService) GetEvaluationSuper(param *command.QueryEval
return &result, nil
}
// GetEvaluationSuperForAdmin 根据执行人获取上级评估详情(超级管理员特殊处理)
func (srv *SummaryEvaluationService) GetEvaluationSuperForAdmin(param *command.QueryEvaluationSuper) (*adapter.EvaluationInfoSuperAdapter, error) {
transactionContext, err := factory.StartTransaction()
if err != nil {
return nil, err
}
defer func() {
_ = transactionContext.RollbackTransaction()
}()
// 只有超级管理员可以使用的功能
superAdmin, err := roleService.GetSuperAdmin(transactionContext, param.CompanyId, param.UserId)
if err != nil {
return nil, err
}
if superAdmin != domain.RoleTypeSuperAdmin {
return nil, application.ThrowError(application.INTERNAL_SERVER_ERROR, "没有操作权限")
}
evaluationRepo := factory.CreateSummaryEvaluationRepository(map[string]interface{}{"transactionContext": transactionContext})
evaluationItemRepo := factory.CreateEvaluationItemUsedRepository(map[string]interface{}{"transactionContext": transactionContext})
itemValueRepo := factory.CreateSummaryEvaluationValueRepository(map[string]interface{}{"transactionContext": transactionContext})
evaluationData, err := evaluationRepo.FindOne(map[string]interface{}{"id": param.SummaryEvaluationId})
if err != nil {
return nil, application.ThrowError(application.INTERNAL_SERVER_ERROR, err.Error())
}
if evaluationData.CompanyId != param.CompanyId {
return nil, application.ThrowError(application.BUSINESS_ERROR, "没有操作权限")
}
_, itemList, err := evaluationItemRepo.Find(map[string]interface{}{"evaluationProjectId": evaluationData.EvaluationProjectId, "nodeType": domain.LinkNodeSelfAssessment})
if err != nil {
return nil, application.ThrowError(application.INTERNAL_SERVER_ERROR, err.Error())
}
// 获取已填写的评估内容
_, itemValues, err := itemValueRepo.Find(map[string]interface{}{"summaryEvaluationId": evaluationData.Id})
if err != nil {
return nil, application.ThrowError(application.INTERNAL_SERVER_ERROR, err.Error())
}
if len(itemValues) == 0 {
// 上级还未填写评估,获取 360 ,人资评估
_, evaluationListOther, err := evaluationRepo.Find(map[string]interface{}{
"typesList": []int{int(domain.Evaluation360), int(domain.EvaluationHrbp)},
"targetUserId": evaluationData.TargetUser.UserId,
"cycleId": evaluationData.CycleId,
})
if err != nil {
return nil, application.ThrowError(application.INTERNAL_SERVER_ERROR, err.Error())
}
var evaluationIds []int
for _, v := range evaluationListOther {
evaluationIds = append(evaluationIds, v.Id)
}
if len(evaluationIds) > 0 {
_, itemValues, err = itemValueRepo.Find(map[string]interface{}{"summaryEvaluationIdList": evaluationIds})
if err != nil {
return nil, application.ThrowError(application.INTERNAL_SERVER_ERROR, err.Error())
}
}
}
evaluationBase := srv.getSummaryEvaluation(transactionContext, evaluationData)
if err := transactionContext.CommitTransaction(); err != nil {
return nil, application.ThrowError(application.INTERNAL_SERVER_ERROR, err.Error())
}
//组合 评估填写的值和评估项
itemValuesAdapter := srv.buildSummaryItemValue(itemList, itemValues)
result := adapter.EvaluationInfoSuperAdapter{
EvaluationBaseAdapter: evaluationBase,
EvaluationItems: itemValuesAdapter,
}
return &result, nil
}
// EditEvaluationSuper 更新上级评估内容
func (srv *SummaryEvaluationService) EditEvaluationSuper(param *command.EditEvaluationValue) (interface{}, error) {
lock := xredis.NewLockSummaryEvaluationId(param.SummaryEvaluationId)
... ... @@ -1196,6 +1269,82 @@ func (srv *SummaryEvaluationService) EditEvaluationSuper(param *command.EditEval
}, nil
}
// EditEvaluationSuperForAdmin 更新上级评估内容(超级管理员)
func (srv *SummaryEvaluationService) EditEvaluationSuperForAdmin(param *command.EditEvaluationValue) (interface{}, error) {
lock := xredis.NewLockSummaryEvaluationId(param.SummaryEvaluationId)
err := lock.Lock()
if err != nil {
return nil, application.ThrowError(application.INTERNAL_SERVER_ERROR, "未能完全提交评估内容")
}
defer func() {
lock.UnLock()
}()
transactionContext, err := factory.StartTransaction()
if err != nil {
return nil, err
}
defer func() {
_ = transactionContext.RollbackTransaction()
}()
// 只有超级管理员可以使用的功能
superAdmin, err := roleService.GetSuperAdmin(transactionContext, param.CompanyId, param.ExecutorId)
if err != nil {
return nil, err
}
if superAdmin != domain.RoleTypeSuperAdmin {
return nil, application.ThrowError(application.INTERNAL_SERVER_ERROR, "没有操作权限")
}
evaluationRepo := factory.CreateSummaryEvaluationRepository(map[string]interface{}{"transactionContext": transactionContext})
itemUsedRepo := factory.CreateEvaluationItemUsedRepository(map[string]interface{}{"transactionContext": transactionContext})
itemValueRepo := factory.CreateSummaryEvaluationValueRepository(map[string]interface{}{"transactionContext": transactionContext})
evaluationData, err := evaluationRepo.FindOne(map[string]interface{}{"id": param.SummaryEvaluationId})
if err != nil {
return nil, application.ThrowError(application.INTERNAL_SERVER_ERROR, err.Error())
}
if evaluationData.CompanyId != param.CompanyId {
return nil, application.ThrowError(application.INTERNAL_SERVER_ERROR, "没有操作权限")
}
_, itemList, err := itemUsedRepo.Find(map[string]interface{}{"evaluationProjectId": evaluationData.EvaluationProjectId, "nodeType": domain.LinkNodeSelfAssessment})
if err != nil {
return nil, application.ThrowError(application.INTERNAL_SERVER_ERROR, err.Error())
}
// 获取已填写的评估内容
_, itemValueList, err := itemValueRepo.Find(map[string]interface{}{"summaryEvaluationId": evaluationData.Id})
if err != nil {
return nil, application.ThrowError(application.INTERNAL_SERVER_ERROR, err.Error())
}
// 超级管理员编辑不限制截止时间
err = srv.editEvaluationValueUnlimited(evaluationData, &itemValueList, itemList, param.EvaluationItems, nil, false)
if err != nil {
return nil, application.ThrowError(application.INTERNAL_SERVER_ERROR, err.Error())
}
for _, v := range itemValueList {
err = itemValueRepo.Save(v) // 保存填写值
if err != nil {
return nil, application.ThrowError(application.INTERNAL_SERVER_ERROR, err.Error())
}
}
evaluationData.Status = domain.EvaluationCompleted
err = evaluationRepo.Save(evaluationData)
if err != nil {
return nil, application.ThrowError(application.INTERNAL_SERVER_ERROR, err.Error())
}
if err := transactionContext.CommitTransaction(); err != nil {
return nil, application.ThrowError(application.INTERNAL_SERVER_ERROR, err.Error())
}
err = srv.AfterCompletedEvaluationSuper(evaluationData)
if err != nil {
return nil, err
}
itemValueAdapter := srv.buildSummaryItemValue(itemList, itemValueList)
return map[string][]adapter.EvaluationItemAdapter{"EvaluationItems": itemValueAdapter}, nil
}
// getEvaluationSuperDefaultValue
// 按照权限设置,是否获取上级评估内容的默认值
func (srv *SummaryEvaluationService) getEvaluationSuperDefaultValue(transactionContext application.TransactionContext, evaluationData *domain.SummaryEvaluation) (
... ... @@ -1873,12 +2022,7 @@ func (srv *SummaryEvaluationService) ListAllEvaluationFinish(param *command.Quer
}
// editEvaluationValue 编辑评估的填写值
// evaluationData 对应的评估任务
// evaluationItems 对应的评估项
// oldItemValue 旧的评估项填写的值
// updatedValue 新填的评估值
// defaultItemvalue 评估项保持的默认值
func (srv *SummaryEvaluationService) editEvaluationValue(
func (srv *SummaryEvaluationService) editEvaluationValueUnlimited(
evaluationData *domain.SummaryEvaluation,
itemValueList *[]*domain.SummaryEvaluationValue,
evaluationItems []*domain.EvaluationItemUsed,
... ... @@ -1886,14 +2030,9 @@ func (srv *SummaryEvaluationService) editEvaluationValue(
defaultItemValue []*domain.SummaryEvaluationValue,
isTemporary bool,
) error {
ok := evaluationData.EndTime.Before(time.Now())
if ok {
return errors.New("评估时间已截止")
}
evaluationItemMap := map[int]*domain.EvaluationItemUsed{}
evaluationValueMap := map[int]*domain.SummaryEvaluationValue{}
evaluationValueSlice := []*domain.SummaryEvaluationValue{}
var evaluationValueSlice []*domain.SummaryEvaluationValue
evaluationData.TotalRating = nil //清空评级数量统计
for _, v := range evaluationItems {
newValue := &domain.SummaryEvaluationValue{}
... ... @@ -1976,6 +2115,34 @@ func (srv *SummaryEvaluationService) editEvaluationValue(
return nil
}
// editEvaluationValue 编辑评估的填写值(超过截止时间不能编辑)
// evaluationData 对应的评估任务
// evaluationItems 对应的评估项
// oldItemValue 旧的评估项填写的值
// updatedValue 新填的评估值
// defaultItemValue 评估项保持的默认值
func (srv *SummaryEvaluationService) editEvaluationValue(
evaluationData *domain.SummaryEvaluation,
itemValueList *[]*domain.SummaryEvaluationValue,
evaluationItems []*domain.EvaluationItemUsed,
updatedValue []command.UpdatedItemValue,
defaultItemValue []*domain.SummaryEvaluationValue,
isTemporary bool,
) error {
ok := evaluationData.EndTime.Before(time.Now())
if ok {
return errors.New("评估时间已截止")
}
return srv.editEvaluationValueUnlimited(
evaluationData,
itemValueList,
evaluationItems,
updatedValue,
defaultItemValue,
isTemporary,
)
}
// 获取现在待执行的综合自评
func (srv *SummaryEvaluationService) ListExecutorNowEvaluationSelf(param *command.QueryExecutorEvaluationList) (map[string]interface{}, error) {
transactionContext, err := factory.CreateTransactionContext(nil)
... ...
... ... @@ -247,8 +247,16 @@ func (c *SummaryEvaluationController) GetEvaluationSuper() {
}
userReq := middlewares.GetUser(c.Ctx)
param.CompanyId = int(userReq.CompanyId)
param.UserId = int(userReq.UserId)
// 超级管理员可以修改上级评估数据
if param.Advanced == 1 {
data, err := srv.GetEvaluationSuperForAdmin(param)
c.Response(data, err)
} else {
data, err := srv.GetEvaluationSuper(param)
c.Response(data, err)
}
}
// 编辑上级评估
... ... @@ -264,8 +272,15 @@ func (c *SummaryEvaluationController) EditEvaluationSuper() {
userReq := middlewares.GetUser(c.Ctx)
param.CompanyId = int(userReq.CompanyId)
param.ExecutorId = int(userReq.UserId)
// 超级管理员重新修改上级评估数据
if param.Advanced == 1 {
data, err := srv.EditEvaluationSuperForAdmin(param)
c.Response(data, err)
} else {
data, err := srv.EditEvaluationSuper(param)
c.Response(data, err)
}
}
// 执行人的上级评估列表
... ...