作者 郑周

Merge branch 'dev-zhengzhou' into test

@@ -5,7 +5,8 @@ type EditEvaluationValue struct { @@ -5,7 +5,8 @@ type EditEvaluationValue struct {
5 ExecutorId int `json:"-"` // 执行人id 5 ExecutorId int `json:"-"` // 执行人id
6 CompanyId int `json:"-"` // 公司id 6 CompanyId int `json:"-"` // 公司id
7 EvaluationItems []UpdatedItemValue `json:"evaluationItems"` 7 EvaluationItems []UpdatedItemValue `json:"evaluationItems"`
8 - IsTemporary bool `json:"isTemporary"` //是否是临时提交 8 + IsTemporary bool `json:"isTemporary"` // 是否是临时提交
  9 + Advanced int `json:"advanced"`
9 } 10 }
10 11
11 type UpdatedItemValue struct { 12 type UpdatedItemValue struct {
@@ -43,4 +43,6 @@ type QueryEvaluationHRBP struct { @@ -43,4 +43,6 @@ type QueryEvaluationHRBP struct {
43 type QueryEvaluationSuper struct { 43 type QueryEvaluationSuper struct {
44 SummaryEvaluationId int `json:"summaryEvaluationId,string"` 44 SummaryEvaluationId int `json:"summaryEvaluationId,string"`
45 CompanyId int `json:"-"` 45 CompanyId int `json:"-"`
  46 + UserId int `json:"-"`
  47 + Advanced int `json:"advanced"`
46 } 48 }
@@ -1091,6 +1091,79 @@ func (srv *SummaryEvaluationService) GetEvaluationSuper(param *command.QueryEval @@ -1091,6 +1091,79 @@ func (srv *SummaryEvaluationService) GetEvaluationSuper(param *command.QueryEval
1091 return &result, nil 1091 return &result, nil
1092 } 1092 }
1093 1093
  1094 +// GetEvaluationSuperForAdmin 根据执行人获取上级评估详情(超级管理员特殊处理)
  1095 +func (srv *SummaryEvaluationService) GetEvaluationSuperForAdmin(param *command.QueryEvaluationSuper) (*adapter.EvaluationInfoSuperAdapter, error) {
  1096 + transactionContext, err := factory.StartTransaction()
  1097 + if err != nil {
  1098 + return nil, err
  1099 + }
  1100 + defer func() {
  1101 + _ = transactionContext.RollbackTransaction()
  1102 + }()
  1103 +
  1104 + // 只有超级管理员可以使用的功能
  1105 + superAdmin, err := roleService.GetSuperAdmin(transactionContext, param.CompanyId, param.UserId)
  1106 + if err != nil {
  1107 + return nil, err
  1108 + }
  1109 + if superAdmin != domain.RoleTypeSuperAdmin {
  1110 + return nil, application.ThrowError(application.INTERNAL_SERVER_ERROR, "没有操作权限")
  1111 + }
  1112 +
  1113 + evaluationRepo := factory.CreateSummaryEvaluationRepository(map[string]interface{}{"transactionContext": transactionContext})
  1114 + evaluationItemRepo := factory.CreateEvaluationItemUsedRepository(map[string]interface{}{"transactionContext": transactionContext})
  1115 + itemValueRepo := factory.CreateSummaryEvaluationValueRepository(map[string]interface{}{"transactionContext": transactionContext})
  1116 + evaluationData, err := evaluationRepo.FindOne(map[string]interface{}{"id": param.SummaryEvaluationId})
  1117 + if err != nil {
  1118 + return nil, application.ThrowError(application.INTERNAL_SERVER_ERROR, err.Error())
  1119 + }
  1120 + if evaluationData.CompanyId != param.CompanyId {
  1121 + return nil, application.ThrowError(application.BUSINESS_ERROR, "没有操作权限")
  1122 + }
  1123 + _, itemList, err := evaluationItemRepo.Find(map[string]interface{}{"evaluationProjectId": evaluationData.EvaluationProjectId, "nodeType": domain.LinkNodeSelfAssessment})
  1124 + if err != nil {
  1125 + return nil, application.ThrowError(application.INTERNAL_SERVER_ERROR, err.Error())
  1126 + }
  1127 + // 获取已填写的评估内容
  1128 + _, itemValues, err := itemValueRepo.Find(map[string]interface{}{"summaryEvaluationId": evaluationData.Id})
  1129 + if err != nil {
  1130 + return nil, application.ThrowError(application.INTERNAL_SERVER_ERROR, err.Error())
  1131 + }
  1132 + if len(itemValues) == 0 {
  1133 + // 上级还未填写评估,获取 360 ,人资评估
  1134 + _, evaluationListOther, err := evaluationRepo.Find(map[string]interface{}{
  1135 + "typesList": []int{int(domain.Evaluation360), int(domain.EvaluationHrbp)},
  1136 + "targetUserId": evaluationData.TargetUser.UserId,
  1137 + "cycleId": evaluationData.CycleId,
  1138 + })
  1139 + if err != nil {
  1140 + return nil, application.ThrowError(application.INTERNAL_SERVER_ERROR, err.Error())
  1141 + }
  1142 + var evaluationIds []int
  1143 + for _, v := range evaluationListOther {
  1144 + evaluationIds = append(evaluationIds, v.Id)
  1145 + }
  1146 + if len(evaluationIds) > 0 {
  1147 + _, itemValues, err = itemValueRepo.Find(map[string]interface{}{"summaryEvaluationIdList": evaluationIds})
  1148 + if err != nil {
  1149 + return nil, application.ThrowError(application.INTERNAL_SERVER_ERROR, err.Error())
  1150 + }
  1151 + }
  1152 + }
  1153 + evaluationBase := srv.getSummaryEvaluation(transactionContext, evaluationData)
  1154 + if err := transactionContext.CommitTransaction(); err != nil {
  1155 + return nil, application.ThrowError(application.INTERNAL_SERVER_ERROR, err.Error())
  1156 + }
  1157 + //组合 评估填写的值和评估项
  1158 + itemValuesAdapter := srv.buildSummaryItemValue(itemList, itemValues)
  1159 +
  1160 + result := adapter.EvaluationInfoSuperAdapter{
  1161 + EvaluationBaseAdapter: evaluationBase,
  1162 + EvaluationItems: itemValuesAdapter,
  1163 + }
  1164 + return &result, nil
  1165 +}
  1166 +
1094 // EditEvaluationSuper 更新上级评估内容 1167 // EditEvaluationSuper 更新上级评估内容
1095 func (srv *SummaryEvaluationService) EditEvaluationSuper(param *command.EditEvaluationValue) (interface{}, error) { 1168 func (srv *SummaryEvaluationService) EditEvaluationSuper(param *command.EditEvaluationValue) (interface{}, error) {
1096 lock := xredis.NewLockSummaryEvaluationId(param.SummaryEvaluationId) 1169 lock := xredis.NewLockSummaryEvaluationId(param.SummaryEvaluationId)
@@ -1196,6 +1269,82 @@ func (srv *SummaryEvaluationService) EditEvaluationSuper(param *command.EditEval @@ -1196,6 +1269,82 @@ func (srv *SummaryEvaluationService) EditEvaluationSuper(param *command.EditEval
1196 }, nil 1269 }, nil
1197 } 1270 }
1198 1271
  1272 +// EditEvaluationSuperForAdmin 更新上级评估内容(超级管理员)
  1273 +func (srv *SummaryEvaluationService) EditEvaluationSuperForAdmin(param *command.EditEvaluationValue) (interface{}, error) {
  1274 + lock := xredis.NewLockSummaryEvaluationId(param.SummaryEvaluationId)
  1275 + err := lock.Lock()
  1276 + if err != nil {
  1277 + return nil, application.ThrowError(application.INTERNAL_SERVER_ERROR, "未能完全提交评估内容")
  1278 + }
  1279 + defer func() {
  1280 + lock.UnLock()
  1281 + }()
  1282 +
  1283 + transactionContext, err := factory.StartTransaction()
  1284 + if err != nil {
  1285 + return nil, err
  1286 + }
  1287 + defer func() {
  1288 + _ = transactionContext.RollbackTransaction()
  1289 + }()
  1290 +
  1291 + // 只有超级管理员可以使用的功能
  1292 + superAdmin, err := roleService.GetSuperAdmin(transactionContext, param.CompanyId, param.ExecutorId)
  1293 + if err != nil {
  1294 + return nil, err
  1295 + }
  1296 + if superAdmin != domain.RoleTypeSuperAdmin {
  1297 + return nil, application.ThrowError(application.INTERNAL_SERVER_ERROR, "没有操作权限")
  1298 + }
  1299 +
  1300 + evaluationRepo := factory.CreateSummaryEvaluationRepository(map[string]interface{}{"transactionContext": transactionContext})
  1301 + itemUsedRepo := factory.CreateEvaluationItemUsedRepository(map[string]interface{}{"transactionContext": transactionContext})
  1302 + itemValueRepo := factory.CreateSummaryEvaluationValueRepository(map[string]interface{}{"transactionContext": transactionContext})
  1303 + evaluationData, err := evaluationRepo.FindOne(map[string]interface{}{"id": param.SummaryEvaluationId})
  1304 + if err != nil {
  1305 + return nil, application.ThrowError(application.INTERNAL_SERVER_ERROR, err.Error())
  1306 + }
  1307 + if evaluationData.CompanyId != param.CompanyId {
  1308 + return nil, application.ThrowError(application.INTERNAL_SERVER_ERROR, "没有操作权限")
  1309 + }
  1310 + _, itemList, err := itemUsedRepo.Find(map[string]interface{}{"evaluationProjectId": evaluationData.EvaluationProjectId, "nodeType": domain.LinkNodeSelfAssessment})
  1311 + if err != nil {
  1312 + return nil, application.ThrowError(application.INTERNAL_SERVER_ERROR, err.Error())
  1313 + }
  1314 + // 获取已填写的评估内容
  1315 + _, itemValueList, err := itemValueRepo.Find(map[string]interface{}{"summaryEvaluationId": evaluationData.Id})
  1316 + if err != nil {
  1317 + return nil, application.ThrowError(application.INTERNAL_SERVER_ERROR, err.Error())
  1318 + }
  1319 + // 超级管理员编辑不限制截止时间
  1320 + err = srv.editEvaluationValueUnlimited(evaluationData, &itemValueList, itemList, param.EvaluationItems, nil, false)
  1321 + if err != nil {
  1322 + return nil, application.ThrowError(application.INTERNAL_SERVER_ERROR, err.Error())
  1323 + }
  1324 + for _, v := range itemValueList {
  1325 + err = itemValueRepo.Save(v) // 保存填写值
  1326 + if err != nil {
  1327 + return nil, application.ThrowError(application.INTERNAL_SERVER_ERROR, err.Error())
  1328 + }
  1329 + }
  1330 + evaluationData.Status = domain.EvaluationCompleted
  1331 + err = evaluationRepo.Save(evaluationData)
  1332 + if err != nil {
  1333 + return nil, application.ThrowError(application.INTERNAL_SERVER_ERROR, err.Error())
  1334 + }
  1335 + if err := transactionContext.CommitTransaction(); err != nil {
  1336 + return nil, application.ThrowError(application.INTERNAL_SERVER_ERROR, err.Error())
  1337 + }
  1338 +
  1339 + err = srv.AfterCompletedEvaluationSuper(evaluationData)
  1340 + if err != nil {
  1341 + return nil, err
  1342 + }
  1343 +
  1344 + itemValueAdapter := srv.buildSummaryItemValue(itemList, itemValueList)
  1345 + return map[string][]adapter.EvaluationItemAdapter{"EvaluationItems": itemValueAdapter}, nil
  1346 +}
  1347 +
1199 // getEvaluationSuperDefaultValue 1348 // getEvaluationSuperDefaultValue
1200 // 按照权限设置,是否获取上级评估内容的默认值 1349 // 按照权限设置,是否获取上级评估内容的默认值
1201 func (srv *SummaryEvaluationService) getEvaluationSuperDefaultValue(transactionContext application.TransactionContext, evaluationData *domain.SummaryEvaluation) ( 1350 func (srv *SummaryEvaluationService) getEvaluationSuperDefaultValue(transactionContext application.TransactionContext, evaluationData *domain.SummaryEvaluation) (
@@ -1873,12 +2022,7 @@ func (srv *SummaryEvaluationService) ListAllEvaluationFinish(param *command.Quer @@ -1873,12 +2022,7 @@ func (srv *SummaryEvaluationService) ListAllEvaluationFinish(param *command.Quer
1873 } 2022 }
1874 2023
1875 // editEvaluationValue 编辑评估的填写值 2024 // editEvaluationValue 编辑评估的填写值
1876 -// evaluationData 对应的评估任务  
1877 -// evaluationItems 对应的评估项  
1878 -// oldItemValue 旧的评估项填写的值  
1879 -// updatedValue 新填的评估值  
1880 -// defaultItemvalue 评估项保持的默认值  
1881 -func (srv *SummaryEvaluationService) editEvaluationValue( 2025 +func (srv *SummaryEvaluationService) editEvaluationValueUnlimited(
1882 evaluationData *domain.SummaryEvaluation, 2026 evaluationData *domain.SummaryEvaluation,
1883 itemValueList *[]*domain.SummaryEvaluationValue, 2027 itemValueList *[]*domain.SummaryEvaluationValue,
1884 evaluationItems []*domain.EvaluationItemUsed, 2028 evaluationItems []*domain.EvaluationItemUsed,
@@ -1886,14 +2030,9 @@ func (srv *SummaryEvaluationService) editEvaluationValue( @@ -1886,14 +2030,9 @@ func (srv *SummaryEvaluationService) editEvaluationValue(
1886 defaultItemValue []*domain.SummaryEvaluationValue, 2030 defaultItemValue []*domain.SummaryEvaluationValue,
1887 isTemporary bool, 2031 isTemporary bool,
1888 ) error { 2032 ) error {
1889 -  
1890 - ok := evaluationData.EndTime.Before(time.Now())  
1891 - if ok {  
1892 - return errors.New("评估时间已截止")  
1893 - }  
1894 evaluationItemMap := map[int]*domain.EvaluationItemUsed{} 2033 evaluationItemMap := map[int]*domain.EvaluationItemUsed{}
1895 evaluationValueMap := map[int]*domain.SummaryEvaluationValue{} 2034 evaluationValueMap := map[int]*domain.SummaryEvaluationValue{}
1896 - evaluationValueSlice := []*domain.SummaryEvaluationValue{} 2035 + var evaluationValueSlice []*domain.SummaryEvaluationValue
1897 evaluationData.TotalRating = nil //清空评级数量统计 2036 evaluationData.TotalRating = nil //清空评级数量统计
1898 for _, v := range evaluationItems { 2037 for _, v := range evaluationItems {
1899 newValue := &domain.SummaryEvaluationValue{} 2038 newValue := &domain.SummaryEvaluationValue{}
@@ -1976,6 +2115,34 @@ func (srv *SummaryEvaluationService) editEvaluationValue( @@ -1976,6 +2115,34 @@ func (srv *SummaryEvaluationService) editEvaluationValue(
1976 return nil 2115 return nil
1977 } 2116 }
1978 2117
  2118 +// editEvaluationValue 编辑评估的填写值(超过截止时间不能编辑)
  2119 +// evaluationData 对应的评估任务
  2120 +// evaluationItems 对应的评估项
  2121 +// oldItemValue 旧的评估项填写的值
  2122 +// updatedValue 新填的评估值
  2123 +// defaultItemValue 评估项保持的默认值
  2124 +func (srv *SummaryEvaluationService) editEvaluationValue(
  2125 + evaluationData *domain.SummaryEvaluation,
  2126 + itemValueList *[]*domain.SummaryEvaluationValue,
  2127 + evaluationItems []*domain.EvaluationItemUsed,
  2128 + updatedValue []command.UpdatedItemValue,
  2129 + defaultItemValue []*domain.SummaryEvaluationValue,
  2130 + isTemporary bool,
  2131 +) error {
  2132 + ok := evaluationData.EndTime.Before(time.Now())
  2133 + if ok {
  2134 + return errors.New("评估时间已截止")
  2135 + }
  2136 + return srv.editEvaluationValueUnlimited(
  2137 + evaluationData,
  2138 + itemValueList,
  2139 + evaluationItems,
  2140 + updatedValue,
  2141 + defaultItemValue,
  2142 + isTemporary,
  2143 + )
  2144 +}
  2145 +
1979 // 获取现在待执行的综合自评 2146 // 获取现在待执行的综合自评
1980 func (srv *SummaryEvaluationService) ListExecutorNowEvaluationSelf(param *command.QueryExecutorEvaluationList) (map[string]interface{}, error) { 2147 func (srv *SummaryEvaluationService) ListExecutorNowEvaluationSelf(param *command.QueryExecutorEvaluationList) (map[string]interface{}, error) {
1981 transactionContext, err := factory.CreateTransactionContext(nil) 2148 transactionContext, err := factory.CreateTransactionContext(nil)
@@ -247,8 +247,16 @@ func (c *SummaryEvaluationController) GetEvaluationSuper() { @@ -247,8 +247,16 @@ func (c *SummaryEvaluationController) GetEvaluationSuper() {
247 } 247 }
248 userReq := middlewares.GetUser(c.Ctx) 248 userReq := middlewares.GetUser(c.Ctx)
249 param.CompanyId = int(userReq.CompanyId) 249 param.CompanyId = int(userReq.CompanyId)
  250 + param.UserId = int(userReq.UserId)
  251 +
  252 + // 超级管理员可以修改上级评估数据
  253 + if param.Advanced == 1 {
  254 + data, err := srv.GetEvaluationSuperForAdmin(param)
  255 + c.Response(data, err)
  256 + } else {
250 data, err := srv.GetEvaluationSuper(param) 257 data, err := srv.GetEvaluationSuper(param)
251 c.Response(data, err) 258 c.Response(data, err)
  259 + }
252 } 260 }
253 261
254 // 编辑上级评估 262 // 编辑上级评估
@@ -264,8 +272,15 @@ func (c *SummaryEvaluationController) EditEvaluationSuper() { @@ -264,8 +272,15 @@ func (c *SummaryEvaluationController) EditEvaluationSuper() {
264 userReq := middlewares.GetUser(c.Ctx) 272 userReq := middlewares.GetUser(c.Ctx)
265 param.CompanyId = int(userReq.CompanyId) 273 param.CompanyId = int(userReq.CompanyId)
266 param.ExecutorId = int(userReq.UserId) 274 param.ExecutorId = int(userReq.UserId)
  275 +
  276 + // 超级管理员重新修改上级评估数据
  277 + if param.Advanced == 1 {
  278 + data, err := srv.EditEvaluationSuperForAdmin(param)
  279 + c.Response(data, err)
  280 + } else {
267 data, err := srv.EditEvaluationSuper(param) 281 data, err := srv.EditEvaluationSuper(param)
268 c.Response(data, err) 282 c.Response(data, err)
  283 + }
269 } 284 }
270 285
271 // 执行人的上级评估列表 286 // 执行人的上级评估列表