|
@@ -1118,226 +1118,6 @@ func (srv *SummaryEvaluationService) GetEvaluationSuper(param *command.QueryEval |
|
@@ -1118,226 +1118,6 @@ func (srv *SummaryEvaluationService) GetEvaluationSuper(param *command.QueryEval |
1118
|
return &result, nil
|
1118
|
return &result, nil
|
1119
|
}
|
1119
|
}
|
1120
|
|
1120
|
|
1121
|
-// GetEvaluationSuperForAdmin 根据执行人获取上级评估详情(超级管理员特殊处理)
|
|
|
1122
|
-func (srv *SummaryEvaluationService) GetEvaluationSuperForAdmin(param *command.QueryEvaluationSuper) (*adapter.EvaluationInfoSuperAdapter, error) {
|
|
|
1123
|
- transactionContext, err := factory.StartTransaction()
|
|
|
1124
|
- if err != nil {
|
|
|
1125
|
- return nil, err
|
|
|
1126
|
- }
|
|
|
1127
|
- defer func() {
|
|
|
1128
|
- _ = transactionContext.RollbackTransaction()
|
|
|
1129
|
- }()
|
|
|
1130
|
-
|
|
|
1131
|
- // 只有超级管理员可以使用的功能
|
|
|
1132
|
- superAdmin, err := roleService.GetSuperAdmin(transactionContext, param.CompanyId, param.UserId)
|
|
|
1133
|
- if err != nil {
|
|
|
1134
|
- return nil, err
|
|
|
1135
|
- }
|
|
|
1136
|
- if superAdmin != domain.RoleTypeSuperAdmin {
|
|
|
1137
|
- return nil, application.ThrowError(application.INTERNAL_SERVER_ERROR, "没有操作权限")
|
|
|
1138
|
- }
|
|
|
1139
|
-
|
|
|
1140
|
- evaluationRepo := factory.CreateSummaryEvaluationRepository(map[string]interface{}{"transactionContext": transactionContext})
|
|
|
1141
|
- evaluationItemRepo := factory.CreateEvaluationItemUsedRepository(map[string]interface{}{"transactionContext": transactionContext})
|
|
|
1142
|
- itemValueRepo := factory.CreateSummaryEvaluationValueRepository(map[string]interface{}{"transactionContext": transactionContext})
|
|
|
1143
|
- result, err := evaluationRepo.FindOne(map[string]interface{}{"id": param.SummaryEvaluationId})
|
|
|
1144
|
- if err != nil || result == nil {
|
|
|
1145
|
- return nil, application.ThrowError(application.INTERNAL_SERVER_ERROR, "获取评估"+err.Error())
|
|
|
1146
|
- }
|
|
|
1147
|
- if result.CompanyId != param.CompanyId {
|
|
|
1148
|
- return nil, application.ThrowError(application.BUSINESS_ERROR, "没有操作权限")
|
|
|
1149
|
- }
|
|
|
1150
|
- if result.Types != domain.EvaluationFinish {
|
|
|
1151
|
- return nil, application.ThrowError(application.INTERNAL_SERVER_ERROR, "考核结果类型错误")
|
|
|
1152
|
- }
|
|
|
1153
|
-
|
|
|
1154
|
- _, itemList, err := evaluationItemRepo.Find(map[string]interface{}{"evaluationProjectId": result.EvaluationProjectId, "nodeType": domain.LinkNodeSelfAssessment})
|
|
|
1155
|
- if err != nil {
|
|
|
1156
|
- return nil, application.ThrowError(application.INTERNAL_SERVER_ERROR, err.Error())
|
|
|
1157
|
- }
|
|
|
1158
|
-
|
|
|
1159
|
- // 获取已填写的评估内容
|
|
|
1160
|
- _, itemValues, err := itemValueRepo.Find(map[string]interface{}{"summaryEvaluationId": result.Id})
|
|
|
1161
|
- if err != nil {
|
|
|
1162
|
- return nil, application.ThrowError(application.INTERNAL_SERVER_ERROR, err.Error())
|
|
|
1163
|
- }
|
|
|
1164
|
- // 考核结果不存在 -> 获取上级考核 -> 获取360+HRBP+自评
|
|
|
1165
|
- if len(itemValues) == 0 {
|
|
|
1166
|
- itemValues, evaluationList, err := srv.findCycleItemValueByType(transactionContext, result.CycleId, result.TargetUser.UserId, []int{int(domain.EvaluationSuper)})
|
|
|
1167
|
- if err != nil {
|
|
|
1168
|
- return nil, application.ThrowError(application.INTERNAL_SERVER_ERROR, err.Error())
|
|
|
1169
|
- }
|
|
|
1170
|
- // 没有上级评估时(有上级考核类型时,不管分数有没有填写都算,没填写当作零)
|
|
|
1171
|
- if len(evaluationList) == 0 {
|
|
|
1172
|
- itemValues, _, err = srv.findCycleItemValueByType(transactionContext, result.CycleId, result.TargetUser.UserId, []int{int(domain.EvaluationSelf)})
|
|
|
1173
|
- if err != nil {
|
|
|
1174
|
- return nil, application.ThrowError(application.INTERNAL_SERVER_ERROR, err.Error())
|
|
|
1175
|
- }
|
|
|
1176
|
- hrItemValues, _, err := srv.findCycleItemValueByType(transactionContext, result.CycleId, result.TargetUser.UserId, []int{int(domain.Evaluation360), int(domain.EvaluationHrbp)})
|
|
|
1177
|
- if err != nil {
|
|
|
1178
|
- return nil, application.ThrowError(application.INTERNAL_SERVER_ERROR, err.Error())
|
|
|
1179
|
- }
|
|
|
1180
|
- // 自评分数
|
|
|
1181
|
- if len(itemValues) == 0 {
|
|
|
1182
|
- itemValues = hrItemValues
|
|
|
1183
|
- } else {
|
|
|
1184
|
- // HR360分数 替换 自评分数
|
|
|
1185
|
- hrItemMap := map[int]*domain.SummaryEvaluationValue{}
|
|
|
1186
|
- for i := range hrItemValues {
|
|
|
1187
|
- hrItemMap[hrItemValues[i].EvaluationItemId] = hrItemValues[i]
|
|
|
1188
|
- }
|
|
|
1189
|
- for i := range itemValues {
|
|
|
1190
|
- it := itemValues[i]
|
|
|
1191
|
- if v, ok := hrItemMap[it.EvaluationItemId]; ok {
|
|
|
1192
|
- itemValues[i] = v
|
|
|
1193
|
- }
|
|
|
1194
|
- }
|
|
|
1195
|
- }
|
|
|
1196
|
- }
|
|
|
1197
|
- }
|
|
|
1198
|
-
|
|
|
1199
|
- evaluationBase := srv.getSummaryEvaluation(transactionContext, result)
|
|
|
1200
|
- if err := transactionContext.CommitTransaction(); err != nil {
|
|
|
1201
|
- return nil, application.ThrowError(application.INTERNAL_SERVER_ERROR, err.Error())
|
|
|
1202
|
- }
|
|
|
1203
|
- //组合 评估填写的值和评估项
|
|
|
1204
|
- itemValuesAdapter := srv.buildSummaryItemValue(itemList, itemValues)
|
|
|
1205
|
-
|
|
|
1206
|
- ra := adapter.EvaluationInfoSuperAdapter{
|
|
|
1207
|
- EvaluationBaseAdapter: evaluationBase,
|
|
|
1208
|
- EvaluationItems: itemValuesAdapter,
|
|
|
1209
|
- }
|
|
|
1210
|
- return &ra, nil
|
|
|
1211
|
-}
|
|
|
1212
|
-
|
|
|
1213
|
-func (srv *SummaryEvaluationService) findCycleItemValueByType(
|
|
|
1214
|
- tc application.TransactionContext,
|
|
|
1215
|
- cycleId int64,
|
|
|
1216
|
- targetUserId int,
|
|
|
1217
|
- typesList []int,
|
|
|
1218
|
-) ([]*domain.SummaryEvaluationValue, []*domain.SummaryEvaluation, error) {
|
|
|
1219
|
- evaluationRepo := factory.CreateSummaryEvaluationRepository(map[string]interface{}{"transactionContext": tc})
|
|
|
1220
|
- itemValueRepo := factory.CreateSummaryEvaluationValueRepository(map[string]interface{}{"transactionContext": tc})
|
|
|
1221
|
-
|
|
|
1222
|
- _, evaluationList, err := evaluationRepo.Find(map[string]interface{}{
|
|
|
1223
|
- "typesList": typesList,
|
|
|
1224
|
- "limit": len(typesList),
|
|
|
1225
|
- "targetUserId": targetUserId,
|
|
|
1226
|
- "cycleId": cycleId,
|
|
|
1227
|
- })
|
|
|
1228
|
- if err != nil {
|
|
|
1229
|
- return nil, nil, application.ThrowError(application.INTERNAL_SERVER_ERROR, err.Error())
|
|
|
1230
|
- }
|
|
|
1231
|
- var eIds []int // 评估类型的ID列表
|
|
|
1232
|
- for _, v := range evaluationList {
|
|
|
1233
|
- eIds = append(eIds, v.Id)
|
|
|
1234
|
- }
|
|
|
1235
|
- if len(eIds) > 0 {
|
|
|
1236
|
- _, itemValues, err := itemValueRepo.Find(map[string]interface{}{"summaryEvaluationIdList": eIds})
|
|
|
1237
|
- if err != nil {
|
|
|
1238
|
- return nil, evaluationList, application.ThrowError(application.INTERNAL_SERVER_ERROR, err.Error())
|
|
|
1239
|
- } else {
|
|
|
1240
|
- return itemValues, evaluationList, nil
|
|
|
1241
|
- }
|
|
|
1242
|
- }
|
|
|
1243
|
- return make([]*domain.SummaryEvaluationValue, 0), evaluationList, nil
|
|
|
1244
|
-}
|
|
|
1245
|
-
|
|
|
1246
|
-// EditEvaluationSuperForAdmin 更新上级评估内容(超级管理员)
|
|
|
1247
|
-func (srv *SummaryEvaluationService) EditEvaluationSuperForAdmin(param *command.EditEvaluationValue) (interface{}, error) {
|
|
|
1248
|
- // 超管不接收临时数据提交
|
|
|
1249
|
- if param.IsTemporary {
|
|
|
1250
|
- return nil, nil
|
|
|
1251
|
- }
|
|
|
1252
|
-
|
|
|
1253
|
- lock := xredis.NewLockSummaryEvaluationId(param.SummaryEvaluationId)
|
|
|
1254
|
- err := lock.Lock()
|
|
|
1255
|
- if err != nil {
|
|
|
1256
|
- return nil, application.ThrowError(application.INTERNAL_SERVER_ERROR, "未能完全提交评估内容")
|
|
|
1257
|
- }
|
|
|
1258
|
- defer func() {
|
|
|
1259
|
- lock.UnLock()
|
|
|
1260
|
- }()
|
|
|
1261
|
-
|
|
|
1262
|
- transactionContext, err := factory.StartTransaction()
|
|
|
1263
|
- if err != nil {
|
|
|
1264
|
- return nil, err
|
|
|
1265
|
- }
|
|
|
1266
|
- defer func() {
|
|
|
1267
|
- _ = transactionContext.RollbackTransaction()
|
|
|
1268
|
- }()
|
|
|
1269
|
-
|
|
|
1270
|
- // 只有超级管理员可以使用的功能
|
|
|
1271
|
- superAdmin, err := roleService.GetSuperAdmin(transactionContext, param.CompanyId, param.ExecutorId)
|
|
|
1272
|
- if err != nil {
|
|
|
1273
|
- return nil, err
|
|
|
1274
|
- }
|
|
|
1275
|
- if superAdmin != domain.RoleTypeSuperAdmin {
|
|
|
1276
|
- return nil, application.ThrowError(application.INTERNAL_SERVER_ERROR, "没有操作权限")
|
|
|
1277
|
- }
|
|
|
1278
|
-
|
|
|
1279
|
- evaluationRepo := factory.CreateSummaryEvaluationRepository(map[string]interface{}{"transactionContext": transactionContext})
|
|
|
1280
|
- itemUsedRepo := factory.CreateEvaluationItemUsedRepository(map[string]interface{}{"transactionContext": transactionContext})
|
|
|
1281
|
- itemValueRepo := factory.CreateSummaryEvaluationValueRepository(map[string]interface{}{"transactionContext": transactionContext})
|
|
|
1282
|
- evaluationData, err := evaluationRepo.FindOne(map[string]interface{}{"id": param.SummaryEvaluationId})
|
|
|
1283
|
- if err != nil {
|
|
|
1284
|
- return nil, application.ThrowError(application.INTERNAL_SERVER_ERROR, err.Error())
|
|
|
1285
|
- }
|
|
|
1286
|
- if evaluationData.CompanyId != param.CompanyId {
|
|
|
1287
|
- return nil, application.ThrowError(application.INTERNAL_SERVER_ERROR, "没有操作权限")
|
|
|
1288
|
- }
|
|
|
1289
|
- _, evaluationList, err := evaluationRepo.Find(map[string]interface{}{
|
|
|
1290
|
- "targetUserId": evaluationData.TargetUser.UserId,
|
|
|
1291
|
- "typesList": []int{int(domain.EvaluationFinish)},
|
|
|
1292
|
- "cycleId": evaluationData.CycleId,
|
|
|
1293
|
- "limit": 1,
|
|
|
1294
|
- })
|
|
|
1295
|
- if err != nil {
|
|
|
1296
|
- return nil, application.ThrowError(application.INTERNAL_SERVER_ERROR, err.Error())
|
|
|
1297
|
- }
|
|
|
1298
|
- // 如果目标员工已经确认考核结果,就不能在进行评估编辑
|
|
|
1299
|
- if len(evaluationList) > 0 && evaluationList[0].CheckResult == domain.EvaluationCheckCompleted {
|
|
|
1300
|
- return nil, application.ThrowError(application.INTERNAL_SERVER_ERROR, "用户已经确认该周期的考核结果,不能再编辑!")
|
|
|
1301
|
- }
|
|
|
1302
|
-
|
|
|
1303
|
- _, itemList, err := itemUsedRepo.Find(map[string]interface{}{"evaluationProjectId": evaluationData.EvaluationProjectId, "nodeType": domain.LinkNodeSelfAssessment})
|
|
|
1304
|
- if err != nil {
|
|
|
1305
|
- return nil, application.ThrowError(application.INTERNAL_SERVER_ERROR, err.Error())
|
|
|
1306
|
- }
|
|
|
1307
|
- // 获取已填写的评估内容
|
|
|
1308
|
- _, itemValueList, err := itemValueRepo.Find(map[string]interface{}{"summaryEvaluationId": evaluationData.Id})
|
|
|
1309
|
- if err != nil {
|
|
|
1310
|
- return nil, application.ThrowError(application.INTERNAL_SERVER_ERROR, err.Error())
|
|
|
1311
|
- }
|
|
|
1312
|
- // 超级管理员编辑不限制截止时间、不校验填写项
|
|
|
1313
|
- err = srv.editEvaluationValueUnlimited(evaluationData, &itemValueList, itemList, param.EvaluationItems, nil, true)
|
|
|
1314
|
- if err != nil {
|
|
|
1315
|
- return nil, application.ThrowError(application.INTERNAL_SERVER_ERROR, err.Error())
|
|
|
1316
|
- }
|
|
|
1317
|
- for _, v := range itemValueList {
|
|
|
1318
|
- err = itemValueRepo.Save(v) // 保存填写值
|
|
|
1319
|
- if err != nil {
|
|
|
1320
|
- return nil, application.ThrowError(application.INTERNAL_SERVER_ERROR, err.Error())
|
|
|
1321
|
- }
|
|
|
1322
|
- }
|
|
|
1323
|
- evaluationData.Status = domain.EvaluationCompleted
|
|
|
1324
|
- err = evaluationRepo.Save(evaluationData)
|
|
|
1325
|
- if err != nil {
|
|
|
1326
|
- return nil, application.ThrowError(application.INTERNAL_SERVER_ERROR, err.Error())
|
|
|
1327
|
- }
|
|
|
1328
|
- if err := transactionContext.CommitTransaction(); err != nil {
|
|
|
1329
|
- return nil, application.ThrowError(application.INTERNAL_SERVER_ERROR, err.Error())
|
|
|
1330
|
- }
|
|
|
1331
|
-
|
|
|
1332
|
- // err = srv.AfterCompletedEvaluationSuper(evaluationData)
|
|
|
1333
|
- // if err != nil {
|
|
|
1334
|
- // return nil, err
|
|
|
1335
|
- // }
|
|
|
1336
|
-
|
|
|
1337
|
- itemValueAdapter := srv.buildSummaryItemValue(itemList, itemValueList)
|
|
|
1338
|
- return map[string][]adapter.EvaluationItemAdapter{"EvaluationItems": itemValueAdapter}, nil
|
|
|
1339
|
-}
|
|
|
1340
|
-
|
|
|
1341
|
// getEvaluationSuperDefaultValue
|
1121
|
// getEvaluationSuperDefaultValue
|
1342
|
// 按照权限设置,是否获取上级评估内容的默认值
|
1122
|
// 按照权限设置,是否获取上级评估内容的默认值
|
1343
|
func (srv *SummaryEvaluationService) getEvaluationSuperDefaultValue(transactionContext application.TransactionContext, evaluationData *domain.SummaryEvaluation) (
|
1123
|
func (srv *SummaryEvaluationService) getEvaluationSuperDefaultValue(transactionContext application.TransactionContext, evaluationData *domain.SummaryEvaluation) (
|