审查视图

pkg/application/summary_evaluation/service/service.go 70.8 KB
tangxvhui authored
1 2
package service
tangxvhui authored
3
import (
4
	"errors"
tangxvhui authored
5
	"fmt"
tangxvhui authored
6
	"strconv"
tangxvhui authored
7
	"strings"
tangxvhui authored
8
	"time"
tangxvhui authored
9
tangxvhui authored
10 11 12
	"github.com/linmadan/egglib-go/core/application"
	"github.com/linmadan/egglib-go/utils/tool_funs"
	"gitlab.fjmaimaimai.com/allied-creation/performance/pkg/application/factory"
tangxvhui authored
13
	roleService "gitlab.fjmaimaimai.com/allied-creation/performance/pkg/application/role"
tangxvhui authored
14 15 16 17
	"gitlab.fjmaimaimai.com/allied-creation/performance/pkg/application/summary_evaluation/adapter"
	"gitlab.fjmaimaimai.com/allied-creation/performance/pkg/application/summary_evaluation/command"
	"gitlab.fjmaimaimai.com/allied-creation/performance/pkg/domain"
	"gitlab.fjmaimaimai.com/allied-creation/performance/pkg/infrastructure/dao"
18
	"gitlab.fjmaimaimai.com/allied-creation/performance/pkg/infrastructure/xredis"
tangxvhui authored
19 20
)
郑周 authored
21
type SummaryEvaluationService struct {
tangxvhui authored
22 23
}
郑周 authored
24 25
func NewSummaryEvaluationService() *SummaryEvaluationService {
	newService := &SummaryEvaluationService{}
tangxvhui authored
26 27 28
	return newService
}
29 30
// GetExecutorCycleList
// 获取评估执行人可用的周期列表
郑周 authored
31
func (srv *SummaryEvaluationService) GetExecutorCycleList(param *command.QueryCycleList) (map[string]interface{}, error) {
tangxvhui authored
32 33 34 35 36 37 38 39 40 41 42 43 44
	transactionContext, err := factory.CreateTransactionContext(nil)
	if err != nil {
		return nil, application.ThrowError(application.TRANSACTION_ERROR, err.Error())
	}
	if err := transactionContext.StartTransaction(); err != nil {
		return nil, application.ThrowError(application.TRANSACTION_ERROR, err.Error())
	}
	defer func() {
		_ = transactionContext.RollbackTransaction()
	}()
	evaluationDao := dao.NewSummaryEvaluationDao(map[string]interface{}{
		"transactionContext": transactionContext,
	})
45
46
	flagHrbp, err := roleService.GetHrBp(transactionContext, param.CompanyId, param.UserId)
47 48 49 50 51 52 53
	if err != nil {
		return nil, application.ThrowError(application.INTERNAL_SERVER_ERROR, err.Error())
	}
	var isHrbp bool
	if flagHrbp == 1 {
		isHrbp = true
	}
tangxvhui authored
54 55 56 57 58 59 60 61 62
	limit := 300
	offset := 0
	if param.PageSize > 0 {
		limit = param.PageSize
	}
	if param.PageNumber > 0 {
		offset = (param.PageNumber - 1) * param.PageSize
	}
tangxvhui authored
63
	cycleData, err := evaluationDao.GetExecutorCycleList(param.CompanyId, param.UserId, offset, limit, isHrbp)
tangxvhui authored
64 65 66 67
	if err != nil {
		return nil, application.ThrowError(application.INTERNAL_SERVER_ERROR, "获取周期列表"+err.Error())
	}
tangxvhui authored
68
	cnt, err := evaluationDao.CountExecutorCycleList(param.CompanyId, param.UserId, isHrbp)
tangxvhui authored
69 70 71 72 73 74
	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())
	}
tangxvhui authored
75
	cycleList := []adapter.CycleListAdapter{}
tangxvhui authored
76
	for _, v := range cycleData {
tangxvhui authored
77
		m := adapter.CycleListAdapter{
78 79
			CycleId:   v.CycleId,
			CycleName: v.CycleName,
tangxvhui authored
80 81 82 83
		}
		cycleList = append(cycleList, m)
	}
	return tool_funs.SimpleWrapGridMap(int64(cnt), cycleList), nil
tangxvhui authored
84 85
}
tangxvhui authored
86 87
// GetMenu
// 根据周期获取菜单显示
郑周 authored
88
func (srv *SummaryEvaluationService) GetMenu(param *command.QueryMenu) (map[string]interface{}, error) {
tangxvhui authored
89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105
	transactionContext, err := factory.CreateTransactionContext(nil)
	if err != nil {
		return nil, application.ThrowError(application.TRANSACTION_ERROR, err.Error())
	}
	if err := transactionContext.StartTransaction(); err != nil {
		return nil, application.ThrowError(application.TRANSACTION_ERROR, err.Error())
	}
	defer func() {
		_ = transactionContext.RollbackTransaction()
	}()
	evaluationRepo := factory.CreateSummaryEvaluationRepository(map[string]interface{}{
		"transactionContext": transactionContext,
	})

	//查找我的绩效
	_, selfEvaluation, err := evaluationRepo.Find(map[string]interface{}{
		"types":      int(domain.EvaluationSelf),
106
		"cycleId":    param.CycleId,
tangxvhui authored
107 108 109 110 111 112
		"executorId": param.UserId,
		"limit":      1,
	})
	if err != nil {
		return nil, application.ThrowError(application.INTERNAL_SERVER_ERROR, err.Error())
	}
113 114 115

	var cntAll360 int
	var cntUncompleted360 int
116
	//查找360评估,统计全部的
117
	cntAll360, _, err = evaluationRepo.Find(map[string]interface{}{
tangxvhui authored
118 119 120
		"types":      int(domain.Evaluation360),
		"executorId": param.UserId,
		"limit":      1,
121
		"cycleId":    param.CycleId,
122
		"beginTime":  time.Now(),
tangxvhui authored
123 124 125 126
	})
	if err != nil {
		return nil, application.ThrowError(application.INTERNAL_SERVER_ERROR, err.Error())
	}
127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144
	if cntAll360 > 0 {
		//查找360评估,统计未完成的
		cntUncompleted360, _, err = evaluationRepo.Find(map[string]interface{}{
			"types":      int(domain.Evaluation360),
			"executorId": param.UserId,
			"limit":      1,
			"cycleId":    param.CycleId,
			"status":     string(domain.EvaluationUncompleted),
			"beginTime":  time.Now(),
		})
		if err != nil {
			return nil, application.ThrowError(application.INTERNAL_SERVER_ERROR, err.Error())
		}
	}

	var cntAllSuper int
	var cntUncompletedSuper int
145
	//查询需要执行上级评估,全部的
146
	cntAllSuper, _, err = evaluationRepo.Find(map[string]interface{}{
147
		"types":      int(domain.EvaluationSuper),
tangxvhui authored
148 149
		"executorId": param.UserId,
		"limit":      1,
150
		"cycleId":    param.CycleId,
151
		"beginTime":  time.Now(),
tangxvhui authored
152 153 154 155
	})
	if err != nil {
		return nil, application.ThrowError(application.INTERNAL_SERVER_ERROR, err.Error())
	}
156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173
	if cntAllSuper > 0 {
		//查询需要执行上级评估,统计未完成
		cntUncompletedSuper, _, err = evaluationRepo.Find(map[string]interface{}{
			"types":      int(domain.EvaluationSuper),
			"executorId": param.UserId,
			"limit":      1,
			"cycleId":    param.CycleId,
			"status":     string(domain.EvaluationUncompleted),
			"beginTime":  time.Now(),
		})
		if err != nil {
			return nil, application.ThrowError(application.INTERNAL_SERVER_ERROR, err.Error())
		}
	}

	var cntAllHrbp int
	var cntUncompletedHrbp int
174
	//查询需要执行人资评估,全部的
175 176 177 178 179
	cntAllHrbp, _, err = evaluationRepo.Find(map[string]interface{}{
		"types":     int(domain.EvaluationHrbp),
		"limit":     1,
		"cycleId":   param.CycleId,
		"beginTime": time.Now(),
tangxvhui authored
180
	})
tangxvhui authored
181 182 183
	if err != nil {
		return nil, application.ThrowError(application.INTERNAL_SERVER_ERROR, err.Error())
	}
184 185 186 187 188 189 190 191 192 193 194 195 196
	if cntAllHrbp > 0 {
		// 查询需要执行人资评估,统计未完成
		cntUncompletedHrbp, _, err = evaluationRepo.Find(map[string]interface{}{
			"types":     int(domain.EvaluationHrbp),
			"limit":     1,
			"cycleId":   param.CycleId,
			"status":    string(domain.EvaluationUncompleted),
			"beginTime": time.Now(),
		})
		if err != nil {
			return nil, application.ThrowError(application.INTERNAL_SERVER_ERROR, err.Error())
		}
	}
197
	isHrbp, err := roleService.GetHrBp(transactionContext, param.CompanyId, param.UserId)
tangxvhui authored
198 199 200
	if err != nil {
		return nil, application.ThrowError(application.INTERNAL_SERVER_ERROR, err.Error())
	}
tangxvhui authored
201
tangxvhui authored
202
	//查找当前周期,我的考核结果
203 204
	_, myEvaluationFinish, _ := evaluationRepo.Find(map[string]interface{}{
		"types":        int(domain.EvaluationFinish),
tangxvhui authored
205 206 207
		"limit":        1,
		"targetUserId": param.UserId,
		"cycleId":      param.CycleId,
208
		"beginTime":    time.Now(),
tangxvhui authored
209
	})
tangxvhui authored
210
tangxvhui authored
211 212 213 214
	if err := transactionContext.CommitTransaction(); err != nil {
		return nil, application.ThrowError(application.INTERNAL_SERVER_ERROR, err.Error())
	}
tangxvhui authored
215
	menuList := []adapter.MenuListAdapter{}
tangxvhui authored
216 217

	//模块-我的绩效
tangxvhui authored
218
	menu1 := adapter.MenuListAdapter{
tangxvhui authored
219 220 221 222
		CycleId:    0,
		NodeName:   "我的绩效",
		StatusName: "",
		Types:      "",
tangxvhui authored
223
		Child:      []adapter.MenuListAdapter{},
tangxvhui authored
224
	}
tangxvhui authored
225
	menu1_1 := adapter.MenuListAdapter{
tangxvhui authored
226 227 228 229 230
		CycleId:      param.CycleId,
		NodeName:     "填写综合自评",
		StatusName:   "",
		TargetUserId: param.UserId,
		Types:        "填写综合自评",
tangxvhui authored
231
	}
tangxvhui authored
232
	menu1_2 := adapter.MenuListAdapter{
tangxvhui authored
233
		CycleId:      param.CycleId,
tangxvhui authored
234
		NodeName:     "查看我的绩效",
tangxvhui authored
235 236
		StatusName:   "",
		TargetUserId: param.UserId,
tangxvhui authored
237
		Types:        "查看我的绩效",
tangxvhui authored
238 239 240 241 242 243 244
	}
	if len(selfEvaluation) > 0 {
		if selfEvaluation[0].Status == domain.EvaluationCompleted {
			menu1_1.StatusName = "已完成"
		} else {
			menu1_1.StatusName = "未完成"
		}
tangxvhui authored
245
		menu1.Child = append(menu1.Child, menu1_1)
tangxvhui authored
246
	}
247 248
	if len(myEvaluationFinish) > 0 {
		if myEvaluationFinish[0].CheckResult == domain.EvaluationCheckCompleted {
tangxvhui authored
249 250 251 252
			menu1_2.StatusName = "已完成"
		} else {
			menu1_2.StatusName = "未完成"
		}
253
		menu1.Child = append(menu1.Child, menu1_2)
tangxvhui authored
254
	}
tangxvhui authored
255
256 257 258
	if len(selfEvaluation) > 0 {
		menuList = append(menuList, menu1)
	}
tangxvhui authored
259
	menu2 := adapter.MenuListAdapter{
tangxvhui authored
260 261 262 263
		CycleId:    0,
		NodeName:   "给他人评估",
		StatusName: "",
		Types:      "",
tangxvhui authored
264
		Child:      []adapter.MenuListAdapter{},
tangxvhui authored
265
	}
tangxvhui authored
266
	menu2_1 := adapter.MenuListAdapter{
tangxvhui authored
267 268 269 270 271
		CycleId:    param.CycleId,
		NodeName:   "360综评",
		StatusName: "",
		Types:      "360综评",
	}
272
	if cntUncompleted360 > 0 {
tangxvhui authored
273
		menu2_1.StatusName = "未完成"
274
	} else if cntAll360 > 0 {
tangxvhui authored
275 276
		menu2_1.StatusName = "已完成"
	}
tangxvhui authored
277
	menu2.Child = append(menu2.Child, menu2_1)
tangxvhui authored
278 279 280
	if cntAll360 > 0 {
		menuList = append(menuList, menu2)
	}
tangxvhui authored
281
	menu3 := adapter.MenuListAdapter{
tangxvhui authored
282 283 284 285
		CycleId:    0,
		NodeName:   "人资评估",
		StatusName: "",
		Types:      "",
tangxvhui authored
286
		Child:      []adapter.MenuListAdapter{},
tangxvhui authored
287
	}
tangxvhui authored
288
	menu3_1 := adapter.MenuListAdapter{
tangxvhui authored
289
		CycleId:    param.CycleId,
tangxvhui authored
290
		NodeName:   "人资综评",
tangxvhui authored
291
		StatusName: "",
tangxvhui authored
292
		Types:      "人资综评",
tangxvhui authored
293
	}
294
	if cntUncompletedHrbp > 0 {
tangxvhui authored
295
		menu3_1.StatusName = "未完成"
296
	} else if cntAllHrbp > 0 {
tangxvhui authored
297 298
		menu3_1.StatusName = "已完成"
	}
tangxvhui authored
299
	menu3.Child = append(menu3.Child, menu3_1)
tangxvhui authored
300
	//hrbp 才有这个菜单
tangxvhui authored
301
	if isHrbp > 0 && cntAllHrbp > 0 {
tangxvhui authored
302 303 304
		menuList = append(menuList, menu3)
	}
	menu4 := adapter.MenuListAdapter{
tangxvhui authored
305 306 307 308
		CycleId:    0,
		NodeName:   "我的团队绩效",
		StatusName: "",
		Types:      "",
tangxvhui authored
309
		Child:      []adapter.MenuListAdapter{},
tangxvhui authored
310
	}
tangxvhui authored
311
	menu4_1 := adapter.MenuListAdapter{
tangxvhui authored
312 313 314 315 316
		CycleId:    param.CycleId,
		NodeName:   "上级综评",
		StatusName: "",
		Types:      "上级综评",
	}
317
	if cntUncompletedSuper > 0 {
tangxvhui authored
318
		menu4_1.StatusName = "未完成"
319
	} else if cntAllSuper > 0 {
tangxvhui authored
320 321 322
		menu4_1.StatusName = "已完成"
	}
	menu4.Child = append(menu4.Child, menu4_1)
tangxvhui authored
323 324 325
	if cntAllSuper > 0 {
		menuList = append(menuList, menu4)
	}
tangxvhui authored
326 327 328 329 330 331
	result := map[string]interface{}{
		"menus": menuList,
	}
	return result, nil
}
tangxvhui authored
332
// buildSummaryItemValue 将填写值填充进评估项
333
func (srv *SummaryEvaluationService) buildSummaryItemValue(itemList []*domain.EvaluationItemUsed, valueList []*domain.SummaryEvaluationValue) (itemValues []adapter.EvaluationItemAdapter) {
tangxvhui authored
334 335 336 337 338 339 340 341 342 343 344 345
	itemValues = []adapter.EvaluationItemAdapter{}
	valueMap := map[int]*domain.SummaryEvaluationValue{}
	for _, v := range valueList {
		valueMap[v.EvaluationItemId] = v
	}
	for _, v := range itemList {
		item := adapter.EvaluationItemAdapter{
			EvaluationItemId: v.Id,
			SortBy:           v.SortBy,
			Category:         v.Category,
			Name:             v.Name,
			PromptTitle:      v.PromptTitle,
tangxvhui authored
346
			PromptText:       "",
tangxvhui authored
347 348 349 350 351 352 353 354
			EntryItems:       v.EntryItems,
			RuleType:         v.RuleType,
			Rule:             v.Rule,
			Weight:           v.Weight,
			Required:         v.Required,
			Value:            "",
			Score:            "",
			Remark:           "",
tangxvhui authored
355
			EvaluatorId:      v.EvaluatorId,
tangxvhui authored
356
		}
357
		//PromptText 页面展示 特殊处理
tangxvhui authored
358 359 360 361
		// if len(v.EntryItems) > 0 {

		for _, v2 := range v.EntryItems {
			item.PromptText += v2.Title + "\n"
362
		}
tangxvhui authored
363 364
		item.PromptText += v.PromptText
		// }
tangxvhui authored
365
		value, ok := valueMap[v.Id]
tangxvhui authored
366 367 368 369
		if ok {
			item.Score = value.Score
			item.Value = value.Value
			item.Remark = value.Remark
tangxvhui authored
370
			item.Rating = value.Rating
371
			item.EvaluatorName = value.Executor.UserName
tangxvhui authored
372 373 374 375 376 377
		}
		itemValues = append(itemValues, item)
	}
	return itemValues
}
tangxvhui authored
378 379
// 根据周期id和被评估人获取综合自评详情
func (srv *SummaryEvaluationService) GetEvaluationSelfByCycle(param *command.QueryEvaluation) (*adapter.EvaluationInfoSelfAdapter, error) {
tangxvhui authored
380 381 382 383 384 385 386 387 388 389 390 391 392 393 394 395
	transactionContext, err := factory.CreateTransactionContext(nil)
	if err != nil {
		return nil, application.ThrowError(application.TRANSACTION_ERROR, err.Error())
	}
	if err := transactionContext.StartTransaction(); err != nil {
		return nil, application.ThrowError(application.TRANSACTION_ERROR, err.Error())
	}
	defer func() {
		_ = transactionContext.RollbackTransaction()
	}()
	evaluationRepo := factory.CreateSummaryEvaluationRepository(map[string]interface{}{
		"transactionContext": transactionContext,
	})
	evaluationItemRepo := factory.CreateEvaluationItemUsedRepository(map[string]interface{}{
		"transactionContext": transactionContext,
	})
tangxvhui authored
396
	itemValueRepo := factory.CreateSummaryEvaluationValueRepository(map[string]interface{}{
tangxvhui authored
397 398 399
		"transactionContext": transactionContext,
	})
	_, evaluationList, err := evaluationRepo.Find(map[string]interface{}{
400 401 402 403
		"limit":        1,
		"cycleId":      param.CycleId,
		"targetUserId": param.TargetUserId,
		"types":        domain.EvaluationSelf,
tangxvhui authored
404 405 406 407 408
	})
	if err != nil {
		return nil, application.ThrowError(application.INTERNAL_SERVER_ERROR, err.Error())
	}
	if len(evaluationList) == 0 {
tangxvhui authored
409
		return &adapter.EvaluationInfoSelfAdapter{}, nil
tangxvhui authored
410 411
	}
	evaluationData := evaluationList[0]
412 413 414
	if evaluationData.CompanyId != param.CompanyId {
		return nil, application.ThrowError(application.BUSINESS_ERROR, "没有操作权限")
	}
tangxvhui authored
415 416 417 418 419 420 421
	_, itemList, err := evaluationItemRepo.Find(map[string]interface{}{
		"evaluationProjectId": evaluationData.EvaluationProjectId,
		"nodeType":            int(domain.LinkNodeSelfAssessment),
	})
	if err != nil {
		return nil, application.ThrowError(application.INTERNAL_SERVER_ERROR, err.Error())
	}
tangxvhui authored
422 423 424 425 426 427 428 429

	_, itemValues, err := itemValueRepo.Find(map[string]interface{}{
		"summaryEvaluationId": evaluationData.Id,
	})

	if err != nil {
		return nil, application.ThrowError(application.INTERNAL_SERVER_ERROR, err.Error())
	}
tangxvhui authored
430 431
	//获取组装基本信息
	evaluationBase := srv.getSummaryEvaluation(transactionContext, evaluationData)
tangxvhui authored
432 433 434
	if err := transactionContext.CommitTransaction(); err != nil {
		return nil, application.ThrowError(application.INTERNAL_SERVER_ERROR, err.Error())
	}
tangxvhui authored
435 436

	itemValuesAdapter := srv.buildSummaryItemValue(itemList, itemValues)
tangxvhui authored
437 438 439 440

	result := adapter.EvaluationInfoSelfAdapter{
		EvaluationBaseAdapter: evaluationBase,
	}
tangxvhui authored
441
	result.EvaluationItems = itemValuesAdapter
tangxvhui authored
442
	return &result, nil
tangxvhui authored
443 444
}
tangxvhui authored
445 446
func (srv *SummaryEvaluationService) getSummaryEvaluation(transactionContext application.TransactionContext, evaluationData *domain.SummaryEvaluation) adapter.EvaluationBaseAdapter {
	result := adapter.EvaluationBaseAdapter{
tangxvhui authored
447 448 449 450 451 452
		SummaryEvaluationId:   evaluationData.Id,
		CycleId:               int(evaluationData.CycleId),
		CycleName:             evaluationData.CycleName,
		EvaluationProjectId:   evaluationData.EvaluationProjectId,
		EvaluationProjectName: evaluationData.EvaluationProjectName,
		LinkNodeId:            evaluationData.NodeId,
tangxvhui authored
453 454
		BeginTime:             evaluationData.BeginTime.Local().Format("2006-01-02 15:04:05"),
		EndTime:               evaluationData.EndTime.Local().Format("2006-01-02 15:04:05"),
455 456
		TargetUserId:          evaluationData.TargetUser.UserId,
		TargetUserName:        evaluationData.TargetUser.UserName,
tangxvhui authored
457 458 459 460
		CompanyLogo:           "",
		CompanyName:           "",
		SupperUser:            "",
		DutyTime:              "",
461
		Types:                 int(evaluationData.Types),
tangxvhui authored
462
		Status:                string(evaluationData.Status),
tangxvhui authored
463
		CheckResult:           string(evaluationData.CheckResult),
tangxvhui authored
464
		TotalScore:            evaluationData.TotalScore,
tangxvhui authored
465
	}
tangxvhui authored
466
	//获取用户信息
467 468
	companyRepo := factory.CreateCompanyRepository(map[string]interface{}{"transactionContext": transactionContext})
	userRepo := factory.CreateUserRepository(map[string]interface{}{"transactionContext": transactionContext})
tangxvhui authored
469
470
	companyData, err := companyRepo.FindOne(map[string]interface{}{"id": evaluationData.CompanyId})
tangxvhui authored
471
	if err != nil {
tangxvhui authored
472
		return result
tangxvhui authored
473
	}
474
	userData, err := userRepo.FindOne(map[string]interface{}{"id": evaluationData.TargetUser.UserId})
tangxvhui authored
475
	if err != nil {
tangxvhui authored
476
		return result
tangxvhui authored
477 478 479 480 481
	}
	result.DutyTime = userData.EntryTime
	result.CompanyLogo = companyData.Logo
	result.CompanyName = companyData.Name
482 483 484 485 486 487
	if userData.ParentId > 0 {
		pUserData, err := userRepo.FindOne(map[string]interface{}{"id": userData.ParentId})
		if err != nil {
			return result
		}
		result.SupperUser = pUserData.Name
tangxvhui authored
488
	}
tangxvhui authored
489
	return result
tangxvhui authored
490
}
tangxvhui authored
491 492

// 编辑综合自评详情
郑周 authored
493
func (srv *SummaryEvaluationService) EditEvaluationSelf(param *command.EditEvaluationValue) (map[string][]adapter.EvaluationItemAdapter, error) {
494 495 496 497 498 499 500 501
	lock := xredis.NewLockSummaryEvaluationId(param.SummaryEvaluationId)
	err := lock.Lock()
	if err != nil {
		return nil, application.ThrowError(application.INTERNAL_SERVER_ERROR, "未能完全提交评估内容")
	}
	defer func() {
		lock.UnLock()
	}()
tangxvhui authored
502 503 504 505 506 507 508 509 510 511
	transactionContext, err := factory.CreateTransactionContext(nil)
	if err != nil {
		return nil, application.ThrowError(application.TRANSACTION_ERROR, err.Error())
	}
	if err := transactionContext.StartTransaction(); err != nil {
		return nil, application.ThrowError(application.TRANSACTION_ERROR, err.Error())
	}
	defer func() {
		_ = transactionContext.RollbackTransaction()
	}()
tangxvhui authored
512 513 514 515 516 517 518 519 520 521 522 523 524 525
	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 {
tangxvhui authored
526
		return nil, application.ThrowError(application.INTERNAL_SERVER_ERROR, "获取评估"+err.Error())
tangxvhui authored
527
	}
tangxvhui authored
528 529 530 531
	if evaluationData.Types != domain.EvaluationSelf {
		return nil, application.ThrowError(application.INTERNAL_SERVER_ERROR, "没有操作权限")
	}
tangxvhui authored
532 533 534 535 536 537 538
	if evaluationData.Executor.UserId != param.ExecutorId {
		return nil, application.ThrowError(application.INTERNAL_SERVER_ERROR, "没有操作权限")
	}

	if evaluationData.CompanyId != param.CompanyId {
		return nil, application.ThrowError(application.INTERNAL_SERVER_ERROR, "没有操作权限")
	}
tangxvhui authored
539
tangxvhui authored
540
	_, itemList, err := itemUsedRepo.Find(map[string]interface{}{
tangxvhui authored
541
		"evaluationProjectId": evaluationData.EvaluationProjectId,
tangxvhui authored
542
		"nodeType":            domain.LinkNodeSelfAssessment,
tangxvhui authored
543 544 545 546 547 548 549
	})
	if err != nil {
		return nil, application.ThrowError(application.INTERNAL_SERVER_ERROR, err.Error())
	}

	_, itemValueList, err := itemValueRepo.Find(map[string]interface{}{
		"summaryEvaluationId": evaluationData.Id,
tangxvhui authored
550
	})
tangxvhui authored
551
tangxvhui authored
552 553 554
	if err != nil {
		return nil, application.ThrowError(application.INTERNAL_SERVER_ERROR, err.Error())
	}
555
556
	err = srv.editEvaluationValue(evaluationData, &itemValueList, itemList, param.EvaluationItems, nil, param.IsTemporary)
557 558
	if err != nil {
		return nil, application.ThrowError(application.BUSINESS_ERROR, err.Error())
tangxvhui authored
559
	}
tangxvhui authored
560
561
	//保存填写值
tangxvhui authored
562 563 564 565 566 567
	for _, v := range itemValueList {
		err = itemValueRepo.Save(v)
		if err != nil {
			return nil, application.ThrowError(application.INTERNAL_SERVER_ERROR, err.Error())
		}
	}
tangxvhui authored
568 569 570
	if !param.IsTemporary {
		evaluationData.Status = domain.EvaluationCompleted
	}
tangxvhui authored
571 572 573 574
	err = evaluationRepo.Save(evaluationData)
	if err != nil {
		return nil, application.ThrowError(application.INTERNAL_SERVER_ERROR, err.Error())
	}
tangxvhui authored
575 576 577
	if err := transactionContext.CommitTransaction(); err != nil {
		return nil, application.ThrowError(application.INTERNAL_SERVER_ERROR, err.Error())
	}
578 579 580 581 582 583 584
	if !param.IsTemporary {
		err = srv.AfterCompletedEvaluationSelf(evaluationData)
		if err != nil {
			return nil, err
		}
	}
585
	itemValueAdapter := srv.buildSummaryItemValue(itemList, itemValueList)
tangxvhui authored
586 587 588
	return map[string][]adapter.EvaluationItemAdapter{
		"EvaluationItems": itemValueAdapter,
	}, nil
tangxvhui authored
589
}
tangxvhui authored
590
tangxvhui authored
591 592
// 员工提交自评内容后,
// 员工作为被评估人,
593
// 变更360评估/人资评估/的开始时间
594
// 或者变更上级评估的开始时间
595
// 或者生成考核结果
596
func (srv *SummaryEvaluationService) AfterCompletedEvaluationSelf(param *domain.SummaryEvaluation) error {
597 598 599 600 601 602 603 604
	lock := xredis.NewLockSummaryEvaluation(param.TargetUser.UserId)
	err := lock.Lock()
	if err != nil {
		return application.ThrowError(application.INTERNAL_SERVER_ERROR, "未能完全提交评估内容")
	}
	defer func() {
		lock.UnLock()
	}()
605 606 607 608 609 610 611 612 613 614
	transactionContext, err := factory.CreateTransactionContext(nil)
	if err != nil {
		return application.ThrowError(application.TRANSACTION_ERROR, err.Error())
	}
	if err := transactionContext.StartTransaction(); err != nil {
		return application.ThrowError(application.TRANSACTION_ERROR, err.Error())
	}
	defer func() {
		_ = transactionContext.RollbackTransaction()
	}()
tangxvhui authored
615 616 617 618 619
	evaluationRepo := factory.CreateSummaryEvaluationRepository(map[string]interface{}{
		"transactionContext": transactionContext,
	})
	_, evaluationList, err := evaluationRepo.Find(map[string]interface{}{
		"targetUserId": param.TargetUser.UserId,
620
		"typesList":    []int{int(domain.Evaluation360), int(domain.EvaluationHrbp)},
tangxvhui authored
621 622 623 624 625 626
		"cycleId":      param.CycleId,
		"limit":        1000,
	})
	if err != nil {
		return application.ThrowError(application.INTERNAL_SERVER_ERROR, err.Error())
	}
627 628 629 630 631 632 633 634 635 636 637 638
	if len(evaluationList) == 0 {
		//如果没有360评估和hrbp 评估,查找上级评估
		_, evaluationList, err = evaluationRepo.Find(map[string]interface{}{
			"targetUserId": param.TargetUser.UserId,
			"typesList":    []int{int(domain.EvaluationSuper)},
			"cycleId":      param.CycleId,
			"limit":        10,
		})
		if err != nil {
			return application.ThrowError(application.INTERNAL_SERVER_ERROR, err.Error())
		}
	}
639
	nowTime := time.Now()
tangxvhui authored
640
	updatedId := []int{}
tangxvhui authored
641 642
	// 变更360评估/人资评估/上级评估的开始时间
	for _, v := range evaluationList {
643 644
		if v.BeginTime.After(nowTime) {
			v.BeginTime = nowTime
tangxvhui authored
645
			updatedId = append(updatedId, v.Id)
646
		}
tangxvhui authored
647
	}
tangxvhui authored
648 649 650 651 652 653 654
	evaluationDao := dao.NewSummaryEvaluationDao(map[string]interface{}{
		"transactionContext": transactionContext,
	})
	err = evaluationDao.UpdateBeginTime(updatedId, nowTime)
	if err != nil {
		return application.ThrowError(application.INTERNAL_SERVER_ERROR, err.Error())
	}
655 656
	if len(evaluationList) == 0 {
		//没有上级评估、360评估、hrbp 评估
657 658 659 660 661 662 663 664 665 666
		//直接进入考核结果阶段
		_, evaluationList, err = evaluationRepo.Find(map[string]interface{}{
			"targetUserId": param.TargetUser.UserId,
			"typesList":    []int{int(domain.EvaluationFinish)},
			"cycleId":      param.CycleId,
			"limit":        1,
		})
		if err != nil {
			return application.ThrowError(application.INTERNAL_SERVER_ERROR, err.Error())
		}
667
		if len(evaluationList) > 0 {
668 669 670
			//进入考核结果
			//自评的结束时间
			evaluationList[0].BeginTime = param.EndTime
tangxvhui authored
671 672
			evaluationList[0].Status = domain.EvaluationCompleted
			err = evaluationRepo.Save(evaluationList[0])
673 674 675 676
			if err != nil {
				return application.ThrowError(application.INTERNAL_SERVER_ERROR, "保存考核结果,"+err.Error())
			}
		}
677
	}
678 679 680
	if err := transactionContext.CommitTransaction(); err != nil {
		return application.ThrowError(application.INTERNAL_SERVER_ERROR, err.Error())
	}
tangxvhui authored
681 682 683
	return nil
}
684
// 提交员工的人资评估 或者 360 评估
tangxvhui authored
685
// 变更上级评估的开始时间
686
// 或者生成考核结果
687
func (srv *SummaryEvaluationService) AfterCompletedEvaluation360Hrbp(param *domain.SummaryEvaluation) error {
688 689 690 691 692 693 694 695
	lock := xredis.NewLockSummaryEvaluation(param.TargetUser.UserId)
	err := lock.Lock()
	if err != nil {
		return application.ThrowError(application.INTERNAL_SERVER_ERROR, "未能完全提交评估内容")
	}
	defer func() {
		lock.UnLock()
	}()
696 697 698 699 700 701 702 703 704 705 706
	transactionContext, err := factory.CreateTransactionContext(nil)
	if err != nil {
		return application.ThrowError(application.TRANSACTION_ERROR, err.Error())
	}
	if err := transactionContext.StartTransaction(); err != nil {
		return application.ThrowError(application.TRANSACTION_ERROR, err.Error())
	}
	defer func() {
		_ = transactionContext.RollbackTransaction()
	}()
tangxvhui authored
707 708 709 710 711 712 713 714 715 716 717 718 719 720 721 722 723 724 725 726 727 728 729 730 731 732
	evaluationRepo := factory.CreateSummaryEvaluationRepository(map[string]interface{}{
		"transactionContext": transactionContext,
	})
	_, evaluation360HrbList, err := evaluationRepo.Find(map[string]interface{}{
		"targetUserId": param.TargetUser.UserId,
		"typesList":    []int{int(domain.Evaluation360), int(domain.EvaluationHrbp)},
		"cycleId":      param.CycleId,
		"limit":        1000,
	})
	if err != nil {
		return application.ThrowError(application.INTERNAL_SERVER_ERROR, err.Error())
	}
	allCompleted := true
	for _, v := range evaluation360HrbList {
		if v.Status == domain.EvaluationUncompleted {
			allCompleted = false
			break
		}
	}
	if !allCompleted {
		return nil
	}
	_, evaluationList, err := evaluationRepo.Find(map[string]interface{}{
		"targetUserId": param.TargetUser.UserId,
		"typesList":    []int{int(domain.EvaluationSuper)},
		"cycleId":      param.CycleId,
tangxvhui authored
733
		"limit":        1,
tangxvhui authored
734 735 736 737
	})
	if err != nil {
		return application.ThrowError(application.INTERNAL_SERVER_ERROR, err.Error())
	}
738
	nowTime := time.Now()
tangxvhui authored
739
	updatedId := []int{}
740
	// 变更上级评估的开始时间
tangxvhui authored
741
	for _, v := range evaluationList {
742 743
		if v.BeginTime.After(nowTime) {
			v.BeginTime = nowTime
tangxvhui authored
744
			updatedId = append(updatedId, v.Id)
745
		}
tangxvhui authored
746 747 748 749 750 751 752
	}
	evaluationDao := dao.NewSummaryEvaluationDao(map[string]interface{}{
		"transactionContext": transactionContext,
	})
	err = evaluationDao.UpdateBeginTime(updatedId, nowTime)
	if err != nil {
		return application.ThrowError(application.INTERNAL_SERVER_ERROR, err.Error())
tangxvhui authored
753
	}
754 755 756 757 758 759 760 761 762 763 764 765
	if len(evaluationList) == 0 {
		//没有上级评估
		//直接进入考核结果阶段
		_, evaluationList, err = evaluationRepo.Find(map[string]interface{}{
			"targetUserId": param.TargetUser.UserId,
			"typesList":    []int{int(domain.EvaluationFinish)},
			"cycleId":      param.CycleId,
			"limit":        1,
		})
		if err != nil {
			return application.ThrowError(application.INTERNAL_SERVER_ERROR, err.Error())
		}
766
		if len(evaluationList) > 0 {
767 768
			//360评估的结束时间
			evaluationList[0].BeginTime = param.EndTime
tangxvhui authored
769 770
			evaluationList[0].Status = domain.EvaluationCompleted
			err = evaluationRepo.Save(evaluationList[0])
771 772 773 774 775 776 777 778 779 780 781
			if err != nil {
				return application.ThrowError(application.INTERNAL_SERVER_ERROR, "保存考核结果,"+err.Error())
			}
		}
	}
	if err := transactionContext.CommitTransaction(); err != nil {
		return application.ThrowError(application.INTERNAL_SERVER_ERROR, err.Error())
	}
	return nil
}
782
// 员工提交上级评估后
783 784 785 786 787 788 789 790 791 792 793 794 795 796 797 798 799 800 801 802 803 804 805 806 807 808 809 810 811 812 813 814 815 816 817
// 生成考核结果
func (srv *SummaryEvaluationService) AfterCompletedEvaluationSuper(param *domain.SummaryEvaluation) error {
	lock := xredis.NewLockSummaryEvaluation(param.TargetUser.UserId)
	err := lock.Lock()
	if err != nil {
		return application.ThrowError(application.INTERNAL_SERVER_ERROR, "未能完全提交评估内容")
	}
	defer func() {
		lock.UnLock()
	}()
	transactionContext, err := factory.CreateTransactionContext(nil)
	if err != nil {
		return application.ThrowError(application.TRANSACTION_ERROR, err.Error())
	}
	if err := transactionContext.StartTransaction(); err != nil {
		return application.ThrowError(application.TRANSACTION_ERROR, err.Error())
	}
	defer func() {
		_ = transactionContext.RollbackTransaction()
	}()

	evaluationRepo := factory.CreateSummaryEvaluationRepository(map[string]interface{}{
		"transactionContext": transactionContext,
	})
	//没有上级评估
	//直接进入考核结果阶段
	_, evaluationList, err := evaluationRepo.Find(map[string]interface{}{
		"targetUserId": param.TargetUser.UserId,
		"typesList":    []int{int(domain.EvaluationFinish)},
		"cycleId":      param.CycleId,
		"limit":        1,
	})
	if err != nil {
		return application.ThrowError(application.INTERNAL_SERVER_ERROR, err.Error())
	}
818
819
	if len(evaluationList) > 0 {
820 821
		//上级评估的结束时间
		evaluationList[0].BeginTime = param.EndTime
tangxvhui authored
822 823
		evaluationList[0].Status = domain.EvaluationCompleted
		err = evaluationRepo.Save(evaluationList[0])
824 825 826 827
		if err != nil {
			return application.ThrowError(application.INTERNAL_SERVER_ERROR, "保存考核结果,"+err.Error())
		}
	}
828 829 830
	if err := transactionContext.CommitTransaction(); err != nil {
		return application.ThrowError(application.INTERNAL_SERVER_ERROR, err.Error())
	}
tangxvhui authored
831 832 833
	return nil
}
834 835
// GetTargetUserCycleList
// 获取周期列表,被评估的周期列表
郑周 authored
836
func (srv *SummaryEvaluationService) GetTargetUserCycleList(param *command.QueryCycleList) (map[string]interface{}, error) {
837 838 839 840 841 842 843 844 845 846 847 848 849 850 851 852 853 854 855 856 857 858 859 860 861 862 863 864 865 866 867 868 869 870 871 872 873
	transactionContext, err := factory.CreateTransactionContext(nil)
	if err != nil {
		return nil, application.ThrowError(application.TRANSACTION_ERROR, err.Error())
	}
	if err := transactionContext.StartTransaction(); err != nil {
		return nil, application.ThrowError(application.TRANSACTION_ERROR, err.Error())
	}
	defer func() {
		_ = transactionContext.RollbackTransaction()
	}()
	evaluationDao := dao.NewSummaryEvaluationDao(map[string]interface{}{
		"transactionContext": transactionContext,
	})
	limit := 300
	offset := 0
	if param.PageSize > 0 {
		limit = param.PageSize
	}
	if param.PageNumber > 0 {
		offset = (param.PageNumber - 1) * param.PageSize
	}

	cycleData, err := evaluationDao.GetTargetUserCycleList(param.UserId, offset, limit, param.Types)
	if err != nil {
		return nil, application.ThrowError(application.INTERNAL_SERVER_ERROR, "获取周期列表"+err.Error())
	}

	cnt, err := evaluationDao.CountTargetUserCycleList(param.UserId, param.Types)
	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())
	}
	cycleList := []adapter.CycleListAdapter{}
	for _, v := range cycleData {
		m := adapter.CycleListAdapter{
874 875
			CycleId:   v.CycleId,
			CycleName: v.CycleName,
876
		}
877
878 879 880 881
		cycleList = append(cycleList, m)
	}
	return tool_funs.SimpleWrapGridMap(int64(cnt), cycleList), nil
}
tangxvhui authored
882
tangxvhui authored
883
// 周期综合自评小结详情
tangxvhui authored
884
func (srv *SummaryEvaluationService) CountEvaluationSelfLevel(param *command.QueryEvaluation) (*adapter.EvaluationInfoCountCodeAdapter, error) {
tangxvhui authored
885 886 887 888 889 890 891 892 893 894
	transactionContext, err := factory.CreateTransactionContext(nil)
	if err != nil {
		return nil, application.ThrowError(application.TRANSACTION_ERROR, err.Error())
	}
	if err := transactionContext.StartTransaction(); err != nil {
		return nil, application.ThrowError(application.TRANSACTION_ERROR, err.Error())
	}
	defer func() {
		_ = transactionContext.RollbackTransaction()
	}()
tangxvhui authored
895 896 897 898
	//统计周期内,评估项等级的数量
	assessDao := dao.NewStaffAssessDao(map[string]interface{}{
		"transactionContext": transactionContext,
	})
tangxvhui authored
899 900 901 902 903 904 905 906 907 908
	evaluationRepo := factory.CreateSummaryEvaluationRepository(map[string]interface{}{
		"transactionContext": transactionContext,
	})
	evaluationItemRepo := factory.CreateEvaluationItemUsedRepository(map[string]interface{}{
		"transactionContext": transactionContext,
	})
	itemValueRepo := factory.CreateSummaryEvaluationValueRepository(map[string]interface{}{
		"transactionContext": transactionContext,
	})
	_, evaluationList, err := evaluationRepo.Find(map[string]interface{}{
909 910 911 912
		"limit":        1,
		"cycleId":      param.CycleId,
		"targetUserId": param.TargetUserId,
		"types":        domain.EvaluationSelf,
tangxvhui authored
913 914 915 916 917 918 919 920
	})
	if err != nil {
		return nil, application.ThrowError(application.INTERNAL_SERVER_ERROR, err.Error())
	}
	if len(evaluationList) == 0 {
		return nil, application.ThrowError(application.INTERNAL_SERVER_ERROR, err.Error())
	}
	evaluationData := evaluationList[0]
tangxvhui authored
921 922 923 924
	levelCodeCountList, err := assessDao.CountAssessContentLevelCode(evaluationData.EvaluationProjectId, param.TargetUserId, domain.AssessSelf, param.CycleId)
	if err != nil {
		return nil, application.ThrowError(application.INTERNAL_SERVER_ERROR, err.Error())
	}
tangxvhui authored
925 926 927 928 929 930 931 932 933 934 935 936 937 938 939 940 941 942 943 944 945 946 947 948 949 950 951 952 953 954 955 956 957 958 959
	_, itemList, err := evaluationItemRepo.Find(map[string]interface{}{
		"evaluationProjectId": evaluationData.EvaluationProjectId,
		"nodeType":            int(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())
	}
	// 获取组装基本信息
	evaluationBase := srv.getSummaryEvaluation(transactionContext, evaluationData)
	if err := transactionContext.CommitTransaction(); err != nil {
		return nil, application.ThrowError(application.INTERNAL_SERVER_ERROR, err.Error())
	}

	evaluationItems := srv.buildSummaryItemValue(itemList, itemValues)

	levelCodeMap := map[int][]adapter.LevalCodeCount{}
	for _, v := range evaluationItems {
		codes := v.Rule.GetLevelCodes()
		levelCode := []adapter.LevalCodeCount{}
		for _, v2 := range codes {
			levelCode = append(levelCode, adapter.LevalCodeCount{
				Code:   v2,
				Number: 0,
			})
		}
		levelCodeMap[v.EvaluationItemId] = levelCode
	}
tangxvhui authored
960 961 962 963 964 965
	levelCodeCountMap := map[string]int{}
	for _, v := range levelCodeCountList {
		key := fmt.Sprintf("%s-%s-%s", v.Category, v.Name, v.LevelValue)
		levelCodeCountMap[key] = v.Cnt
	}
tangxvhui authored
966 967 968 969 970 971 972 973
	evaluationItemCount := []adapter.EvaluationItemCountCodeAdapter{}
	for i := range evaluationItems {
		itemCount := adapter.EvaluationItemCountCodeAdapter{
			EvaluationItemAdapter: evaluationItems[i],
			LevelCount:            []adapter.LevalCodeCount{},
		}
		evaluationItemCount = append(evaluationItemCount, itemCount)
		itemId := evaluationItems[i].EvaluationItemId
tangxvhui authored
974 975 976 977
		levelCodes, ok := levelCodeMap[itemId]
		if !ok {
			continue
		}
tangxvhui authored
978
		evaluationItemCount[i].LevelCount = levelCodes
tangxvhui authored
979 980
		for i2 := range levelCodes {
			key := fmt.Sprintf("%s-%s-%s",
tangxvhui authored
981 982
				evaluationItems[i].Category,
				evaluationItems[i].Name,
tangxvhui authored
983 984 985 986 987 988 989
				levelCodes[i2].Code,
			)
			if mVal, ok := levelCodeCountMap[key]; ok {
				levelCodes[i2].Number = mVal
			}
		}
	}
tangxvhui authored
990 991 992 993 994 995 996 997 998 999 1000 1001 1002 1003 1004 1005 1006 1007 1008 1009 1010 1011 1012 1013 1014 1015 1016 1017
	evaluationInfo := adapter.EvaluationInfoCountCodeAdapter{
		EvaluationBaseAdapter: evaluationBase,
		EvaluationItems:       evaluationItemCount,
	}
	return &evaluationInfo, nil
}

// GetEvaluationSuper 根据执行人获取上级评估详情
func (srv *SummaryEvaluationService) GetEvaluationSuper(param *command.QueryEvaluationSuper) (*adapter.EvaluationInfoSuperAdapter, error) {
	transactionContext, err := factory.CreateTransactionContext(nil)
	if err != nil {
		return nil, application.ThrowError(application.TRANSACTION_ERROR, err.Error())
	}
	if err := transactionContext.StartTransaction(); err != nil {
		return nil, application.ThrowError(application.TRANSACTION_ERROR, err.Error())
	}
	defer func() {
		_ = transactionContext.RollbackTransaction()
	}()
	evaluationRepo := factory.CreateSummaryEvaluationRepository(map[string]interface{}{
		"transactionContext": transactionContext,
	})
	evaluationItemRepo := factory.CreateEvaluationItemUsedRepository(map[string]interface{}{
		"transactionContext": transactionContext,
	})
	itemValueRepo := factory.CreateSummaryEvaluationValueRepository(map[string]interface{}{
		"transactionContext": transactionContext,
	})
1018
	// permissionRepository := factory.CreatePermissionRepository(map[string]interface{}{"transactionContext": transactionContext})
1019
	// 获取权限配置
1020 1021 1022 1023 1024
	// _, permissionList, err := permissionRepository.Find(map[string]interface{}{"companyId": param.CompanyId})
	// if err != nil {
	// 	return nil, application.ThrowError(application.INTERNAL_SERVER_ERROR, err.Error())
	// }
	permissinData, err := getPermission(int64(param.CompanyId))
1025
	if err != nil {
1026
		return nil, err
1027
	}
tangxvhui authored
1028 1029 1030 1031 1032 1033
	evaluationData, err := evaluationRepo.FindOne(map[string]interface{}{
		"id": param.SummaryEvaluationId,
	})
	if err != nil {
		return nil, application.ThrowError(application.INTERNAL_SERVER_ERROR, err.Error())
	}
tangxvhui authored
1034
	if evaluationData.Types != domain.EvaluationSuper {
tangxvhui authored
1035 1036
		return nil, application.ThrowError(application.BUSINESS_ERROR, "没有操作权限")
	}
tangxvhui authored
1037
	if evaluationData.CompanyId != param.CompanyId {
tangxvhui authored
1038 1039 1040 1041 1042 1043 1044 1045 1046 1047 1048 1049 1050 1051 1052 1053 1054 1055 1056 1057 1058 1059 1060 1061 1062 1063 1064 1065 1066 1067 1068 1069 1070 1071 1072 1073 1074 1075 1076 1077 1078
		return nil, application.ThrowError(application.BUSINESS_ERROR, "没有操作权限")
	}
	_, itemList, err := evaluationItemRepo.Find(map[string]interface{}{
		"evaluationProjectId": evaluationData.EvaluationProjectId,
		"nodeType":            int(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())
		}
		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)
tangxvhui authored
1079 1080 1081
	if err := transactionContext.CommitTransaction(); err != nil {
		return nil, application.ThrowError(application.INTERNAL_SERVER_ERROR, err.Error())
	}
tangxvhui authored
1082 1083
	//组合 评估填写的值和评估项
	itemValuesAdapter := srv.buildSummaryItemValue(itemList, itemValues)
1084
	for i, v := range itemValuesAdapter {
1085 1086 1087 1088 1089 1090 1091
		if permissinData.OptEvalScore == domain.PermissionOff &&
			v.EvaluatorId > 0 {
			itemValuesAdapter[i].ForbidEdit = true
		}
		if permissinData.OptHrScore == domain.PermissionOff &&
			v.EvaluatorId < 0 {
			itemValuesAdapter[i].ForbidEdit = true
1092 1093
		}
	}
tangxvhui authored
1094 1095
	result := adapter.EvaluationInfoSuperAdapter{
		EvaluationBaseAdapter: evaluationBase,
tangxvhui authored
1096 1097
		// LevelCount:            codeList,
		EvaluationItems: itemValuesAdapter,
tangxvhui authored
1098 1099
	}
	return &result, nil
tangxvhui authored
1100
}
tangxvhui authored
1101
tangxvhui authored
1102 1103
// EditEvaluationSuper 更新上级评估内容
func (srv *SummaryEvaluationService) EditEvaluationSuper(param *command.EditEvaluationValue) (interface{}, error) {
1104 1105 1106 1107 1108 1109 1110 1111
	lock := xredis.NewLockSummaryEvaluationId(param.SummaryEvaluationId)
	err := lock.Lock()
	if err != nil {
		return nil, application.ThrowError(application.INTERNAL_SERVER_ERROR, "未能完全提交评估内容")
	}
	defer func() {
		lock.UnLock()
	}()
tangxvhui authored
1112 1113 1114 1115 1116 1117 1118 1119 1120 1121 1122 1123 1124 1125 1126 1127 1128 1129 1130 1131 1132 1133 1134 1135 1136 1137 1138 1139 1140
	transactionContext, err := factory.CreateTransactionContext(nil)
	if err != nil {
		return nil, application.ThrowError(application.TRANSACTION_ERROR, err.Error())
	}
	if err := transactionContext.StartTransaction(); err != nil {
		return nil, application.ThrowError(application.TRANSACTION_ERROR, err.Error())
	}
	defer func() {
		_ = transactionContext.RollbackTransaction()
	}()
	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.Types != domain.EvaluationSuper {
		return nil, application.ThrowError(application.INTERNAL_SERVER_ERROR, "没有操作权限")
	}
tangxvhui authored
1141
tangxvhui authored
1142 1143 1144 1145 1146 1147 1148 1149 1150 1151 1152 1153 1154 1155 1156 1157 1158 1159 1160 1161 1162 1163 1164 1165 1166 1167 1168
	if evaluationData.Executor.UserId != param.ExecutorId {
		return nil, application.ThrowError(application.INTERNAL_SERVER_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())
	}
	//记录人资评估或者360评估的 填写项id
	hrbpOr360ItemValue, err := srv.getEvaluationSuperDefaultValue(transactionContext, evaluationData)
	if err != nil {
		return nil, err
	}
tangxvhui authored
1169
1170
	err = srv.editEvaluationValue(evaluationData, &itemValueList, itemList, param.EvaluationItems, hrbpOr360ItemValue, param.IsTemporary)
1171 1172
	if err != nil {
		return nil, application.ThrowError(application.INTERNAL_SERVER_ERROR, err.Error())
tangxvhui authored
1173
	}
1174 1175 1176 1177
	if !param.IsTemporary {
		//变更评估状态为已填写
		evaluationData.Status = domain.EvaluationCompleted
	}
1178
	for _, v := range itemValueList {
tangxvhui authored
1179 1180 1181 1182 1183 1184 1185 1186 1187 1188 1189 1190 1191 1192
		//保存填写值
		err = itemValueRepo.Save(v)
		if err != nil {
			return nil, application.ThrowError(application.INTERNAL_SERVER_ERROR, err.Error())
		}
	}
	//保存填写值
	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())
	}
1193 1194 1195 1196 1197 1198 1199 1200

	if !param.IsTemporary {
		err = srv.AfterCompletedEvaluationSuper(evaluationData)
		if err != nil {
			return nil, err
		}
	}
1201
	itemValueAdapter := srv.buildSummaryItemValue(itemList, itemValueList)
tangxvhui authored
1202 1203 1204
	return map[string][]adapter.EvaluationItemAdapter{
		"EvaluationItems": itemValueAdapter,
	}, nil
tangxvhui authored
1205 1206
}
tangxvhui authored
1207 1208 1209
// getEvaluationSuperDefaultValue
// 按照权限设置,是否获取上级评估内容的默认值
func (srv *SummaryEvaluationService) getEvaluationSuperDefaultValue(transactionContext application.TransactionContext, evaluationData *domain.SummaryEvaluation) (
1210
	[]*domain.SummaryEvaluationValue, error) {
tangxvhui authored
1211 1212 1213
	evaluationRepo := factory.CreateSummaryEvaluationRepository(map[string]interface{}{
		"transactionContext": transactionContext,
	})
tangxvhui authored
1214
tangxvhui authored
1215 1216 1217 1218
	itemValueRepo := factory.CreateSummaryEvaluationValueRepository(map[string]interface{}{
		"transactionContext": transactionContext,
	})
1219 1220 1221 1222 1223 1224 1225 1226 1227 1228
	// permissionRepository := factory.CreatePermissionRepository(map[string]interface{}{"transactionContext": transactionContext})
	// // 获取权限配置
	// _, permissionList, err := permissionRepository.Find(map[string]interface{}{"companyId": evaluationData.CompanyId})
	// if err != nil {
	// 	return nil, application.ThrowError(application.INTERNAL_SERVER_ERROR, err.Error())
	// }
	// if len(permissionList) == 0 {
	// 	return nil, nil
	// }
	permissionData, err := getPermission(int64(evaluationData.CompanyId))
tangxvhui authored
1229 1230 1231 1232 1233 1234 1235 1236 1237 1238 1239 1240 1241 1242 1243 1244 1245 1246 1247 1248 1249 1250 1251 1252 1253 1254 1255 1256 1257 1258
	if err != nil {
		return nil, application.ThrowError(application.INTERNAL_SERVER_ERROR, err.Error())
	}
	if permissionData.OptEvalScore == domain.PermissionOn && permissionData.OptHrScore == domain.PermissionOn {
		return nil, nil
	}
	// 获取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())
	}
	evaluationIds := []int{}
	for _, v := range evaluationListOther {
		evaluationIds = append(evaluationIds, v.Id)
	}
	if len(evaluationIds) == 0 {
		return nil, nil
	}
	// 将360评估,人资评估填写的值 作为默认值
	_, itemValuesOther, err := itemValueRepo.Find(map[string]interface{}{
		"summaryEvaluationIdList": evaluationIds,
	})
	if err != nil {
		return nil, application.ThrowError(application.INTERNAL_SERVER_ERROR, err.Error())
	}
	// 记录人资评估或者360评估的 填写项id
1259
	hrbpOr360ItemValue := []*domain.SummaryEvaluationValue{}
tangxvhui authored
1260 1261 1262 1263 1264 1265 1266 1267
	if permissionData.OptEvalScore == domain.PermissionOff {
		//上级是否可以修改360°综评分数
		//获取360综合评分
		for _, v := range itemValuesOther {
			//记录人资评估或者360评估的填写值
			if v.Types != domain.Evaluation360 {
				continue
			}
1268
			hrbpOr360ItemValue = append(hrbpOr360ItemValue, v)
tangxvhui authored
1269 1270 1271 1272 1273 1274 1275 1276 1277 1278 1279
		}
	}
	if permissionData.OptHrScore == domain.PermissionOff {
		//上级是否可以修改人资综评分数
		//获取人资综合评分
		for _, v := range itemValuesOther {
			//记录人资评估或者360评估的填写值
			if v.Types != domain.EvaluationHrbp {
				continue
			}
1280
			hrbpOr360ItemValue = append(hrbpOr360ItemValue, v)
tangxvhui authored
1281 1282
		}
	}
1283
	return hrbpOr360ItemValue, nil
tangxvhui authored
1284
}
tangxvhui authored
1285
1286 1287
// 获取执行人的上级评估的列表
func (srv *SummaryEvaluationService) ListExecutorEvaluationSuper(param *command.QueryExecutorEvaluationList) (map[string]interface{}, error) {
tangxvhui authored
1288 1289 1290 1291 1292 1293 1294 1295 1296 1297 1298 1299 1300 1301 1302 1303
	transactionContext, err := factory.CreateTransactionContext(nil)
	if err != nil {
		return nil, application.ThrowError(application.TRANSACTION_ERROR, err.Error())
	}
	if err := transactionContext.StartTransaction(); err != nil {
		return nil, application.ThrowError(application.TRANSACTION_ERROR, err.Error())
	}
	defer func() {
		_ = transactionContext.RollbackTransaction()
	}()
	evaluationRepo := factory.CreateSummaryEvaluationRepository(map[string]interface{}{
		"transactionContext": transactionContext,
	})
	userRepo := factory.CreateUserRepository(map[string]interface{}{
		"transactionContext": transactionContext,
	})
1304 1305 1306 1307 1308 1309 1310 1311 1312 1313 1314 1315
	positionRepo := factory.CreatePositionRepository(map[string]interface{}{
		"transactionContext": transactionContext,
	})
	limit := param.PageSize
	offset := (param.PageNumber - 1) * param.PageSize

	//获取评估列表信息
	condition1 := map[string]interface{}{
		"cycleId":    param.CycleId,
		"executorId": param.ExecutorId,
		"types":      int(domain.EvaluationSuper),
		"limit":      limit,
1316
		"beginTime":  time.Now(),
1317 1318 1319 1320
	}
	if offset > 0 {
		condition1["offset"] = offset
	}
tangxvhui authored
1321
	if len(param.TargetUserName) > 0 {
1322 1323 1324 1325 1326 1327 1328 1329 1330
		condition1["targetUserName"] = "%" + param.TargetUserName + "%"
	}
	//获取评估列表信息
	cnt, evaluationList, err := evaluationRepo.Find(condition1)
	if err != nil {
		return nil, application.ThrowError(application.INTERNAL_SERVER_ERROR, err.Error())
	}
	//获取未完成上级评估的数量
	cntUn, _, err := evaluationRepo.Find(map[string]interface{}{
tangxvhui authored
1331 1332 1333
		"cycleId":    param.CycleId,
		"executorId": param.ExecutorId,
		"types":      int(domain.EvaluationSuper),
1334 1335
		"status":     domain.EvaluationUncompleted,
		"limit":      1,
1336
		"beginTime":  time.Now(),
tangxvhui authored
1337 1338 1339 1340 1341 1342 1343 1344
	})
	if err != nil {
		return nil, application.ThrowError(application.INTERNAL_SERVER_ERROR, err.Error())
	}
	targetUserIds := []int{}
	for _, v := range evaluationList {
		targetUserIds = append(targetUserIds, v.TargetUser.UserId)
	}
1345 1346 1347 1348 1349 1350 1351 1352 1353 1354 1355 1356 1357 1358 1359 1360 1361 1362 1363
	//获取员工的综合自评
	evaluationSelfMap := map[int]*domain.SummaryEvaluation{}
	for _, v := range evaluationList {
		_, evaluationSelfList, err := evaluationRepo.Find(map[string]interface{}{
			"cycleId":    param.CycleId,
			"executorId": v.TargetUser.UserId,
			"types":      int(domain.EvaluationSelf),
			"limit":      1,
		})
		if err != nil {
			return nil, application.ThrowError(application.INTERNAL_SERVER_ERROR, "获取综合自评"+err.Error())
		}
		if len(evaluationSelfList) > 0 {
			evaluationSelfMap[v.TargetUser.UserId] = evaluationSelfList[0]
		}
	}

	//获取员工信息
	userMap := map[int64]*domain.User{}
tangxvhui authored
1364
	if len(targetUserIds) > 0 {
1365
		_, userList, err := userRepo.Find(map[string]interface{}{
tangxvhui authored
1366 1367 1368 1369 1370
			"ids": targetUserIds,
		})
		if err != nil {
			return nil, application.ThrowError(application.INTERNAL_SERVER_ERROR, err.Error())
		}
1371 1372 1373 1374 1375 1376 1377 1378 1379 1380
		for _, v := range userList {
			userMap[v.Id] = v
		}
	}
	var positionIds []int
	//获取职位列表
	positionMap := map[int64]*domain.Position{}
	for _, v := range userMap {
		positionIds = append(positionIds, v.PositionId...)
	}
tangxvhui authored
1381
1382
	if len(positionIds) > 0 {
1383
		_, positionList, err := positionRepo.Find(map[string]interface{}{"ids": positionIds})
1384 1385 1386 1387 1388 1389 1390
		if err != nil {
			return nil, application.ThrowError(application.INTERNAL_SERVER_ERROR, "获取部门信息"+err.Error())
		}
		for _, v := range positionList {
			positionMap[v.Id] = v
		}
	}
tangxvhui authored
1391 1392 1393
	if err := transactionContext.CommitTransaction(); err != nil {
		return nil, application.ThrowError(application.INTERNAL_SERVER_ERROR, err.Error())
	}
1394 1395 1396 1397 1398
	evaluationListAdapter := []*adapter.EvaluationSuperListAdapter{}
	for _, v := range evaluationList {
		item := adapter.EvaluationSuperListAdapter{
			SummaryEvaluationId: v.Id,
			TargetUserName:      v.TargetUser.UserName,
1399
			TargetUserId:        v.TargetUser.UserId,
1400 1401 1402 1403 1404 1405 1406
			EvaluationStatus:    string(v.Status),
			EndTime:             v.EndTime.Format("2006-01-02 15:04:05"),
			TotalScoreSelf:      "",
			Department:          "",
			Position:            "",
			EntryTime:           "",
		}
1407 1408 1409
		for _, dep := range v.TargetDepartment {
			item.Department += dep.DepartmentName + " "
		}
1410 1411 1412 1413 1414 1415 1416 1417 1418 1419 1420 1421 1422 1423 1424 1425 1426 1427 1428 1429 1430 1431 1432 1433 1434
		//填充员工信息
		if targetUser, ok := userMap[int64(v.TargetUser.UserId)]; ok {
			//填充职位信息
			for _, positionId := range targetUser.PositionId {
				if position, ok := positionMap[int64(positionId)]; ok {
					item.Position += position.Name + " "
				}
			}
			//填充入职时间
			item.EntryTime = targetUser.EntryTime
		}
		//填充自评总分
		if evaluationSelf, ok := evaluationSelfMap[v.TargetUser.UserId]; ok {
			item.TotalScoreSelf = evaluationSelf.TotalScore
		}
		evaluationListAdapter = append(evaluationListAdapter, &item)
	}
	result := tool_funs.SimpleWrapGridMap(int64(cnt), evaluationListAdapter)
	result["endTime"] = ""
	result["uncompleted_number"] = 0
	if len(evaluationList) > 0 {
		result["endTime"] = evaluationList[0].EndTime.Format("2006-01-02 15:04:05")
		result["uncompleted_number"] = cntUn
	}
	return result, nil
tangxvhui authored
1435
}
tangxvhui authored
1436
1437 1438 1439
// ConfirmScoreEvaluation 员工确认考核结果
func (srv *SummaryEvaluationService) ConfirmScoreEvaluation(param *command.ConfirmScore) error {
	transactionContext, err := factory.ValidateStartTransaction(param)
tangxvhui authored
1440
	if err != nil {
1441
		return err
tangxvhui authored
1442 1443 1444 1445 1446
	}
	defer func() {
		_ = transactionContext.RollbackTransaction()
	}()
1447 1448 1449 1450 1451 1452
	evaluationRepo := factory.CreateSummaryEvaluationRepository(map[string]interface{}{"transactionContext": transactionContext})
	evaluationItemRepo := factory.CreateEvaluationItemUsedRepository(map[string]interface{}{"transactionContext": transactionContext})
	itemValueRepo := factory.CreateSummaryEvaluationValueRepository(map[string]interface{}{"transactionContext": transactionContext})

	// 考核结果
	result, err := evaluationRepo.FindOne(map[string]interface{}{"id": param.SummaryEvaluationId})
tangxvhui authored
1453 1454 1455
	if err != nil {
		return application.ThrowError(application.TRANSACTION_ERROR, err.Error())
	}
1456
	if result.Types != domain.EvaluationFinish {
tangxvhui authored
1457 1458
		return application.ThrowError(application.TRANSACTION_ERROR, "操作方式错误")
	}
1459
	if result.TargetUser.UserId != param.UserId {
tangxvhui authored
1460 1461
		return application.ThrowError(application.TRANSACTION_ERROR, "没有操作权限")
	}
1462 1463
	if result.CheckResult == domain.EvaluationCheckCompleted {
		return application.ThrowError(application.TRANSACTION_ERROR, "考核结果已确认过了!")
tangxvhui authored
1464
	}
1465 1466 1467 1468 1469 1470 1471 1472 1473 1474 1475 1476 1477 1478 1479 1480 1481 1482 1483 1484 1485 1486 1487 1488 1489 1490 1491 1492 1493 1494 1495 1496 1497 1498 1499 1500 1501 1502
	if result.Status == domain.EvaluationUncompleted {
		return application.ThrowError(application.TRANSACTION_ERROR, "前面流程暂未完成提交评估内容")
	}

	_, evaluationList, err := evaluationRepo.Find(map[string]interface{}{
		"companyId":    result.CompanyId,
		"cycleId":      result.CycleId,
		"targetUserId": result.TargetUser.UserId,
	})
	if err != nil {
		return application.ThrowError(application.INTERNAL_SERVER_ERROR, err.Error())
	}

	var super *domain.SummaryEvaluation // 上级评估
	for i := range evaluationList {
		it := evaluationList[i]
		if it.Types == domain.EvaluationSuper {
			super = it
			break
		}
	}

	// 评估内容和值
	var itemList []*domain.EvaluationItemUsed
	var itemValues []*domain.SummaryEvaluationValue

	// 获取自评模板内容
	_, itemList, err = evaluationItemRepo.Find(map[string]interface{}{"evaluationProjectId": result.EvaluationProjectId, "nodeType": domain.LinkNodeSelfAssessment})
	if err != nil {
		return application.ThrowError(application.INTERNAL_SERVER_ERROR, err.Error())
	}

	// 按评估项优先级顺序(已确认考核结果 ->上级评估 ->HR或360评估或自评)
	if super != nil {
		_, itemValues, err = itemValueRepo.Find(map[string]interface{}{"summaryEvaluationId": super.Id}) // 获取已填写的评估内容
		if err != nil {
			return application.ThrowError(application.INTERNAL_SERVER_ERROR, err.Error())
		}
1503 1504 1505 1506 1507
		// 更新填写值
		itemValues, err = srv.updateItemValuePriority(result, itemList, itemValues, true)
		if err != nil {
			return application.ThrowError(application.INTERNAL_SERVER_ERROR, err.Error())
		}
1508 1509 1510 1511 1512 1513 1514 1515 1516 1517 1518 1519 1520 1521 1522 1523 1524
	} else {
		// 评估项ID(除考核结果和上级)
		var evaluationIds = make([]int, 0)
		for i := range evaluationList {
			it := evaluationList[i]
			if it.Types == domain.EvaluationSelf || it.Types == domain.Evaluation360 || it.Types == domain.EvaluationHrbp {
				evaluationIds = append(evaluationIds, it.Id)
			}
		}
		if len(evaluationIds) > 0 {
			// 获取已填写的评估内容
			_, itemValues, err = itemValueRepo.Find(map[string]interface{}{"summaryEvaluationIdList": evaluationIds})
			if err != nil {
				return application.ThrowError(application.INTERNAL_SERVER_ERROR, err.Error())
			}

			// 更新填写值
1525
			itemValues, err = srv.updateItemValuePriority(result, itemList, itemValues, false)
1526 1527 1528
			if err != nil {
				return application.ThrowError(application.INTERNAL_SERVER_ERROR, err.Error())
			}
1529 1530
		}
	}
1531
1532 1533 1534
	for i := range itemValues {
		if err := itemValueRepo.Save(itemValues[i]); err != nil {
			return application.ThrowError(application.INTERNAL_SERVER_ERROR, err.Error())
1535 1536
		}
	}
tangxvhui authored
1537 1538
	//重置评级汇总
	result.TotalRating = nil
tangxvhui authored
1539 1540 1541
	for i := range itemList {
		result.ResetTotalRating(itemList[i])
	}
1542
	if err := result.EvaluationTotalScore(itemValues); err != nil {
1543 1544 1545 1546
		return application.ThrowError(application.TRANSACTION_ERROR, err.Error())
	}

	result.CheckResult = domain.EvaluationCheckCompleted
1547
	if err := evaluationRepo.Save(result); err != nil {
tangxvhui authored
1548 1549 1550 1551 1552 1553 1554
		return application.ThrowError(application.TRANSACTION_ERROR, err.Error())
	}
	if err := transactionContext.CommitTransaction(); err != nil {
		return application.ThrowError(application.INTERNAL_SERVER_ERROR, err.Error())
	}
	return nil
}
tangxvhui authored
1555
1556 1557 1558 1559
// 处理优先级
func (srv *SummaryEvaluationService) updateItemValuePriority(
	result *domain.SummaryEvaluation,
	itemList []*domain.EvaluationItemUsed,
1560 1561
	itemValues []*domain.SummaryEvaluationValue,
	superior bool) ([]*domain.SummaryEvaluationValue, error) {
1562 1563 1564 1565

	tempSelf := map[int]*domain.SummaryEvaluationValue{}
	temp360 := map[int]*domain.SummaryEvaluationValue{}
	tempHRBP := map[int]*domain.SummaryEvaluationValue{}
1566 1567
	tempSuperior := map[int]*domain.SummaryEvaluationValue{}
1568 1569 1570 1571 1572 1573 1574 1575
	for i := range itemValues {
		it := itemValues[i]
		if it.Types == domain.EvaluationSelf {
			tempSelf[it.EvaluationItemId] = it
		} else if it.Types == domain.Evaluation360 {
			temp360[it.EvaluationItemId] = it
		} else if it.Types == domain.EvaluationHrbp {
			tempHRBP[it.EvaluationItemId] = it
1576 1577
		} else if it.Types == domain.EvaluationSuper {
			tempSuperior[it.EvaluationItemId] = it
1578 1579 1580 1581 1582 1583 1584 1585 1586 1587
		}
	}
	nowTime := time.Now()
	var newItemValues = make([]*domain.SummaryEvaluationValue, 0)
	for i := range itemList {
		it := itemList[i]

		var tempValue domain.SummaryEvaluationValue
		tempValue.SetBlankValue(result, it)
1588 1589
		if superior /* 上级数据 */ {
			if v, ok := tempSuperior[it.Id]; ok {
1590 1591
				tempValue = *v
			}
1592 1593 1594 1595 1596 1597 1598 1599 1600 1601 1602 1603 1604 1605 1606 1607 1608
			tempValue.Types = domain.EvaluationSuper
		} else /* 其它数据 */ {
			if it.EvaluatorId == 0 {
				if v, ok := tempSelf[it.Id]; ok {
					tempValue = *v
				}
				tempValue.Types = domain.EvaluationSelf
			} else if it.EvaluatorId == -1 {
				if v, ok := tempHRBP[it.Id]; ok {
					tempValue = *v
				}
				tempValue.Types = domain.EvaluationHrbp
			} else if it.EvaluatorId > 0 {
				if v, ok := temp360[it.Id]; ok {
					tempValue = *v
				}
				tempValue.Types = domain.Evaluation360
1609 1610 1611
			}
		}
1612
		// ID置空
1613
		tempValue.Id = 0
tangxvhui authored
1614
		tempValue.SummaryEvaluationId = result.Id
1615 1616 1617 1618 1619 1620 1621
		tempValue.CreatedAt = nowTime
		tempValue.UpdatedAt = nowTime
		newItemValues = append(newItemValues, &tempValue)
	}
	return newItemValues, nil
}
郑周 authored
1622 1623
// GetTargetEvaluationResult 按照周期和被评估的人 获取考核结果
func (srv *SummaryEvaluationService) GetTargetEvaluationResult(param *command.QueryEvaluation) (*adapter.EvaluationInfoSuperAdapter, error) {
1624
	transactionContext, err := factory.ValidateStartTransaction(param)
tangxvhui authored
1625 1626 1627
	if err != nil {
		return nil, application.ThrowError(application.TRANSACTION_ERROR, err.Error())
	}
tangxvhui authored
1628 1629 1630
	// if err := transactionContext.StartTransaction(); err != nil {
	// 	return nil, application.ThrowError(application.TRANSACTION_ERROR, err.Error())
	// }
tangxvhui authored
1631 1632 1633
	defer func() {
		_ = transactionContext.RollbackTransaction()
	}()
1634 1635 1636 1637
	evaluationRepo := factory.CreateSummaryEvaluationRepository(map[string]interface{}{"transactionContext": transactionContext})
	evaluationItemRepo := factory.CreateEvaluationItemUsedRepository(map[string]interface{}{"transactionContext": transactionContext})
	itemValueRepo := factory.CreateSummaryEvaluationValueRepository(map[string]interface{}{"transactionContext": transactionContext})
tangxvhui authored
1638
	_, evaluationList, err := evaluationRepo.Find(map[string]interface{}{
1639
		"companyId":    param.CompanyId,
1640 1641
		"cycleId":      param.CycleId,
		"targetUserId": param.TargetUserId,
tangxvhui authored
1642 1643 1644 1645
	})
	if err != nil {
		return nil, application.ThrowError(application.INTERNAL_SERVER_ERROR, err.Error())
	}
1646 1647 1648 1649 1650 1651 1652 1653 1654 1655 1656 1657 1658

	var result *domain.SummaryEvaluation // 绩效考核结果项
	var super *domain.SummaryEvaluation  // 上级评估
	for i := range evaluationList {
		it := evaluationList[i]
		if it.Types == domain.EvaluationFinish {
			result = it
			continue
		}
		if it.Types == domain.EvaluationSuper {
			super = it
			continue
		}
tangxvhui authored
1659
	}
1660 1661
	if result == nil {
		return nil, application.ThrowError(application.INTERNAL_SERVER_ERROR, "没有找到符合条件的数据")
tangxvhui authored
1662 1663
	}
1664 1665 1666 1667 1668 1669
	// 评估内容和值
	var itemList []*domain.EvaluationItemUsed
	var itemValues []*domain.SummaryEvaluationValue

	// 获取自评模板内容
	_, itemList, err = evaluationItemRepo.Find(map[string]interface{}{"evaluationProjectId": result.EvaluationProjectId, "nodeType": domain.LinkNodeSelfAssessment})
tangxvhui authored
1670 1671 1672
	if err != nil {
		return nil, application.ThrowError(application.INTERNAL_SERVER_ERROR, err.Error())
	}
1673 1674 1675 1676

	// 按评估项优先级顺序(已确认考核结果 ->上级评估 ->HR或360评估或自评)
	if result.CheckResult == domain.EvaluationCheckCompleted { /* 已完成考核*/
		_, itemValues, err = itemValueRepo.Find(map[string]interface{}{"summaryEvaluationId": result.Id}) // 获取已填写的评估内容
tangxvhui authored
1677 1678 1679
		if err != nil {
			return nil, application.ThrowError(application.INTERNAL_SERVER_ERROR, err.Error())
		}
1680 1681 1682
	} else {
		if super != nil {
			_, itemValues, err = itemValueRepo.Find(map[string]interface{}{"summaryEvaluationId": super.Id}) // 获取已填写的评估内容
tangxvhui authored
1683 1684 1685
			if err != nil {
				return nil, application.ThrowError(application.INTERNAL_SERVER_ERROR, err.Error())
			}
1686 1687 1688 1689 1690 1691 1692 1693 1694 1695 1696 1697 1698 1699 1700 1701 1702
		} else {
			// 评估项ID(除考核结果和上级)
			var evaluationIds = make([]int, 0)
			for i := range evaluationList {
				it := evaluationList[i]
				if it.Types == domain.EvaluationSelf || it.Types == domain.Evaluation360 || it.Types == domain.EvaluationHrbp {
					evaluationIds = append(evaluationIds, it.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())
				}

				// 更新填写值
1703
				itemValues, err = srv.updateItemValuePriority(result, itemList, itemValues, false)
1704 1705 1706 1707
				if err != nil {
					return nil, application.ThrowError(application.INTERNAL_SERVER_ERROR, err.Error())
				}
			}
tangxvhui authored
1708 1709
		}
	}
郑周 authored
1710 1711
	// 未完成考核,需要重新计算分数
	if result.CheckResult == domain.EvaluationCheckUncompleted {
tangxvhui authored
1712
		result.TotalRating = nil
tangxvhui authored
1713 1714 1715
		for i := range itemList {
			result.ResetTotalRating(itemList[i])
		}
郑周 authored
1716 1717 1718 1719 1720
		if err = result.EvaluationTotalScore(itemValues); err != nil {
			return nil, application.ThrowError(application.TRANSACTION_ERROR, err.Error())
		}
	}
tangxvhui authored
1721 1722 1723
	// 基础数据
	evaluationBase := srv.getSummaryEvaluation(transactionContext, result)
tangxvhui authored
1724 1725 1726
	if err := transactionContext.CommitTransaction(); err != nil {
		return nil, application.ThrowError(application.INTERNAL_SERVER_ERROR, err.Error())
	}
1727 1728

	// 组合 评估填写的值和评估项
tangxvhui authored
1729
	itemValuesAdapter := srv.buildSummaryItemValue(itemList, itemValues)
tangxvhui authored
1730
tangxvhui authored
1731
	codeMap := map[string]*adapter.LevalCodeCount{}
1732
	for _, v := range itemValuesAdapter {
tangxvhui authored
1733 1734
		//处理加分项评级汇总
		if v.Weight == 0 && len(v.Value) > 0 {
1735 1736 1737 1738 1739 1740 1741 1742 1743 1744 1745
			if _, ok := codeMap[v.Value]; !ok {
				code := &adapter.LevalCodeCount{
					Code:     v.Value,
					Number:   0,
					ItemList: []string{},
				}
				codeMap[v.Value] = code
			}
			codeMap[v.Value].ItemList = append(codeMap[v.Value].ItemList, v.Name)
			codeMap[v.Value].Number += 1
		}
tangxvhui authored
1746
	}
tangxvhui authored
1747 1748 1749 1750 1751 1752 1753 1754 1755 1756 1757 1758
	codeList := make([]*adapter.LevalCodeCount, 0)
	for _, val := range result.TotalRating {
		if codeItem, ok := codeMap[val.Code]; ok {
			codeList = append(codeList, codeItem)
		} else {
			codeList = append(codeList, &adapter.LevalCodeCount{
				Code:     val.Code,
				Number:   0,
				ItemList: []string{},
			})
		}
	}
1759
	eiAdapter := adapter.EvaluationInfoSuperAdapter{
tangxvhui authored
1760 1761 1762 1763
		EvaluationBaseAdapter: evaluationBase,
		LevelCount:            codeList,
		EvaluationItems:       itemValuesAdapter,
	}
1764
	return &eiAdapter, nil
tangxvhui authored
1765 1766
}
1767 1768
// 按周期获取所有员工的评估考核结果
func (srv *SummaryEvaluationService) ListAllEvaluationFinish(param *command.QueryEvaluationList) (map[string]interface{}, error) {
1769 1770 1771 1772 1773 1774 1775 1776 1777 1778
	transactionContext, err := factory.CreateTransactionContext(nil)
	if err != nil {
		return nil, application.ThrowError(application.TRANSACTION_ERROR, err.Error())
	}
	if err := transactionContext.StartTransaction(); err != nil {
		return nil, application.ThrowError(application.TRANSACTION_ERROR, err.Error())
	}
	defer func() {
		_ = transactionContext.RollbackTransaction()
	}()
tangxvhui authored
1779
	//判断是否是hrbp
1780
	flagHrbp, err := roleService.GetHrBp(transactionContext, param.CompanyId, param.UserId)
tangxvhui authored
1781 1782 1783
	if err != nil {
		return nil, application.ThrowError(application.INTERNAL_SERVER_ERROR, err.Error())
	}
1784
	if flagHrbp != domain.RoleTypeSystem {
tangxvhui authored
1785
		return tool_funs.SimpleWrapGridMap(0, []string{}), nil
tangxvhui authored
1786
	}
tangxvhui authored
1787 1788
	//判断是否是上级
	userRepo := factory.CreateUserRepository(map[string]interface{}{
1789 1790
		"transactionContext": transactionContext,
	})
tangxvhui authored
1791 1792 1793 1794 1795

	_, parentUser, _ := userRepo.Find(map[string]interface{}{
		"parentId": param.UserId,
		"limit":    1,
	})
1796
	if len(parentUser) == 0 && flagHrbp != domain.RoleTypeSystem {
tangxvhui authored
1797 1798 1799
		return tool_funs.SimpleWrapGridMap(0, []string{}), nil
	}
	evaluationRepo := factory.CreateSummaryEvaluationRepository(map[string]interface{}{
1800 1801
		"transactionContext": transactionContext,
	})
tangxvhui authored
1802
1803 1804 1805 1806 1807 1808 1809 1810
	positionRepo := factory.CreatePositionRepository(map[string]interface{}{
		"transactionContext": transactionContext,
	})
	limit := param.PageSize
	offset := (param.PageNumber - 1) * param.PageSize

	//获取评估列表信息
	condition1 := map[string]interface{}{
1811
		"cycleId":   param.CycleId,
1812
		"types":     int(domain.EvaluationFinish),
1813 1814
		"limit":     limit,
		"beginTime": time.Now(),
1815 1816 1817 1818
	}
	if offset > 0 {
		condition1["offset"] = offset
	}
tangxvhui authored
1819
	if len(param.TargetUserName) > 0 {
1820 1821 1822 1823 1824 1825 1826 1827 1828 1829 1830
		condition1["targetUserName"] = "%" + param.TargetUserName + "%"
	}
	//获取评估列表信息
	cnt, evaluationList, err := evaluationRepo.Find(condition1)
	if err != nil {
		return nil, application.ThrowError(application.INTERNAL_SERVER_ERROR, err.Error())
	}
	targetUserIds := []int{}
	for _, v := range evaluationList {
		targetUserIds = append(targetUserIds, v.TargetUser.UserId)
	}
tangxvhui authored
1831
1832 1833 1834 1835 1836 1837 1838 1839 1840 1841 1842 1843 1844 1845 1846 1847 1848 1849 1850 1851 1852 1853 1854 1855 1856 1857 1858 1859 1860 1861 1862 1863 1864 1865 1866 1867 1868 1869 1870 1871 1872 1873 1874 1875 1876 1877 1878 1879 1880 1881 1882 1883 1884 1885 1886 1887 1888 1889
	//获取员工信息
	userMap := map[int64]*domain.User{}
	if len(targetUserIds) > 0 {
		_, userList, err := userRepo.Find(map[string]interface{}{
			"ids": targetUserIds,
		})
		if err != nil {
			return nil, application.ThrowError(application.INTERNAL_SERVER_ERROR, err.Error())
		}
		for _, v := range userList {
			userMap[v.Id] = v
		}
	}
	var positionIds []int
	//获取职位列表
	positionMap := map[int64]*domain.Position{}
	for _, v := range userMap {
		positionIds = append(positionIds, v.PositionId...)
	}
	if len(positionIds) > 0 {
		_, positionList, err := positionRepo.Find(map[string]interface{}{"ids": positionIds})
		if err != nil {
			return nil, application.ThrowError(application.INTERNAL_SERVER_ERROR, "获取部门信息"+err.Error())
		}
		for _, v := range positionList {
			positionMap[v.Id] = v
		}
	}
	if err := transactionContext.CommitTransaction(); err != nil {
		return nil, application.ThrowError(application.INTERNAL_SERVER_ERROR, err.Error())
	}
	evaluationListAdapter := []*adapter.EvaluationSuperItemAdapter{}
	for _, v := range evaluationList {
		item := adapter.EvaluationSuperItemAdapter{
			SummaryEvaluationId: v.Id,
			TargetUserName:      v.TargetUser.UserName,
			TargetUserId:        v.TargetUser.UserId,
			CycleId:             v.CycleId,
			TotalScore:          v.TotalScore,
			Department:          "",
			Position:            "",
		}
		for _, dep := range v.TargetDepartment {
			item.Department += dep.DepartmentName + " "
		}
		//填充员工信息
		if targetUser, ok := userMap[int64(v.TargetUser.UserId)]; ok {
			//填充职位信息
			for _, positionId := range targetUser.PositionId {
				if position, ok := positionMap[int64(positionId)]; ok {
					item.Position += position.Name + " "
				}
			}
		}
		evaluationListAdapter = append(evaluationListAdapter, &item)
	}
	result := tool_funs.SimpleWrapGridMap(int64(cnt), evaluationListAdapter)
	return result, nil
tangxvhui authored
1890
}
1891 1892 1893 1894 1895 1896 1897 1898 1899 1900 1901 1902 1903

// 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,
1904
	isTemporary bool,
1905
) error {
1906 1907 1908 1909 1910

	ok := evaluationData.EndTime.Before(time.Now())
	if ok {
		return errors.New("评估时间已截止")
	}
1911 1912
	evaluationItemMap := map[int]*domain.EvaluationItemUsed{}
	evaluationValueMap := map[int]*domain.SummaryEvaluationValue{}
1913
	evaluationValueSlice := []*domain.SummaryEvaluationValue{}
1914 1915 1916 1917 1918 1919
	evaluationData.TotalRating = nil //清空评级数量统计
	for _, v := range evaluationItems {
		newValue := &domain.SummaryEvaluationValue{}
		newValue.SetBlankValue(evaluationData, v)
		evaluationValueMap[v.Id] = newValue
		evaluationItemMap[v.Id] = v
1920
		evaluationValueSlice = append(evaluationValueSlice, newValue)
1921 1922 1923
		//重置计数
		evaluationData.ResetTotalRating(v)
	}
1924
	//如果存在旧值
1925 1926 1927 1928 1929 1930 1931 1932
	//新值的id 替换为旧值id
	for _, v := range *itemValueList {
		if mValue, ok := evaluationValueMap[v.EvaluationItemId]; ok {
			mValue.Id = v.Id
		}
	}
	//填入填写的更新值
	for _, v := range updatedValue {
tangxvhui authored
1933
		v.Value = strings.TrimSpace(v.Value)
1934 1935 1936 1937 1938 1939 1940 1941
		newItemValue, ok := evaluationValueMap[v.EvaluationItemId]
		if !ok {
			continue
		}
		evaluationItem, ok := evaluationItemMap[v.EvaluationItemId]
		if !ok {
			continue
		}
tangxvhui authored
1942
		if !isTemporary {
1943 1944 1945 1946 1947 1948 1949 1950 1951 1952
			if evaluationData.Types != domain.EvaluationSelf {
				//除了综合自评,其他的评估任务 评估项直接全部按必填项处理
				if len(v.Value) == 0 {
					return fmt.Errorf("%s-%s 未填写", evaluationItem.Category, evaluationItem.Name)
				}
			} else if evaluationItem.Required == domain.NodeRequiredYes {
				// 综合自评 评估项必填项处理
				if len(v.Value) == 0 {
					return fmt.Errorf("%s-%s 未填写", evaluationItem.Category, evaluationItem.Name)
				}
tangxvhui authored
1953 1954
			}
		}
1955 1956 1957 1958 1959 1960 1961 1962 1963 1964 1965 1966 1967 1968 1969 1970 1971
		//填充评估填写值
		err := newItemValue.FillValue(evaluationItem, v.Value, v.Remark)
		if err != nil {
			return err
		}
	}
	// 填入固定的默认值
	for _, v := range defaultItemValue {
		newItemValue, ok := evaluationValueMap[v.EvaluationItemId]
		if !ok {
			continue
		}
		evaluationItem, ok := evaluationItemMap[v.EvaluationItemId]
		if !ok {
			continue
		}
		//填充评估填写值
tangxvhui authored
1972
		err := newItemValue.FillValue(evaluationItem, v.Value, newItemValue.Remark)
1973 1974 1975 1976 1977
		if err != nil {
			return err
		}
	}
	//完全更新itemValueList
1978 1979 1980 1981 1982 1983 1984 1985
	*itemValueList = evaluationValueSlice
	// *itemValueList = (*itemValueList)[0:0]
	// for _, v := range evaluationValueMap {
	// 	*itemValueList = append(*itemValueList, v)
	// }
	// sort.Slice(*itemValueList, func(i, j int) bool {
	// 	return (*itemValueList)[i].EvaluationItemId < (*itemValueList)[j].EvaluationItemId
	// })
1986
	// 计算总得分
tangxvhui authored
1987
	err := evaluationData.EvaluationTotalScore(*itemValueList)
1988 1989 1990 1991 1992
	if err != nil {
		return err
	}
	return nil
}
tangxvhui authored
1993 1994 1995 1996 1997

// 获取现在待执行的综合自评
func (srv *SummaryEvaluationService) ListExecutorNowEvaluationSelf(param *command.QueryExecutorEvaluationList) (map[string]interface{}, error) {
	transactionContext, err := factory.CreateTransactionContext(nil)
	if err != nil {
1998
		return nil, err
tangxvhui authored
1999
	}
tangxvhui authored
2000 2001 2002
	if err := transactionContext.StartTransaction(); err != nil {
		return nil, application.ThrowError(application.TRANSACTION_ERROR, err.Error())
	}
tangxvhui authored
2003 2004 2005 2006 2007 2008 2009 2010 2011 2012 2013 2014 2015 2016 2017 2018 2019 2020 2021 2022 2023 2024 2025 2026 2027 2028 2029 2030 2031 2032 2033 2034 2035 2036 2037 2038 2039 2040
	defer func() {
		_ = transactionContext.RollbackTransaction()
	}()
	evaluationRepo := factory.CreateSummaryEvaluationRepository(map[string]interface{}{
		"transactionContext": transactionContext,
	})
	condition1 := map[string]interface{}{
		"types":        int(domain.EvaluationSelf),
		"targetUserId": param.ExecutorId,
		"limit":        20,
		"beginTime":    time.Now(),
		"endTime":      time.Now(),
		"status":       string(domain.EvaluationUncompleted),
	}
	//获取评估列表信息
	cnt, evaluationList, err := evaluationRepo.Find(condition1)
	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())
	}

	listResult := []map[string]string{}
	for _, v := range evaluationList {
		item := map[string]string{
			"summaryEvaluationId": strconv.Itoa(v.Id),
			"cycleId":             strconv.Itoa(int(v.CycleId)),
			"cycleName":           v.CycleName,
			"evaluationStatus":    string(v.Status),
			"endTime":             v.EndTime.Local().Format("2006-01-02 15:04:05"),
			"beginTime":           v.BeginTime.Local().Format("2006-01-02 15:04:05"),
		}
		listResult = append(listResult, item)
	}
	result := tool_funs.SimpleWrapGridMap(int64(cnt), listResult)
	return result, nil
}
Your Name authored
2041 2042 2043 2044 2045 2046 2047 2048 2049 2050 2051 2052 2053 2054 2055 2056 2057 2058 2059 2060 2061 2062 2063 2064 2065 2066 2067 2068 2069 2070 2071 2072 2073 2074 2075 2076 2077 2078 2079 2080 2081

// SearchAssessRemark
func (srv *SummaryEvaluationService) SearchAssessRemark(param *command.QueryAssessRemark) (map[string][]map[string]string, error) {
	transactionContext, err := factory.CreateTransactionContext(nil)
	if err != nil {
		return nil, err
	}
	if err := transactionContext.StartTransaction(); err != nil {
		return nil, application.ThrowError(application.TRANSACTION_ERROR, err.Error())
	}
	defer func() {
		_ = transactionContext.RollbackTransaction()
	}()
	assessDao := dao.NewStaffAssessDao(map[string]interface{}{"transactionContext": transactionContext})

	data, err := assessDao.SearchAssessSelfContentRemark(param.ProjectId, param.TargetUserId, param.Category, param.Name, param.LevelValue)
	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())
	}
	listData := []map[string]string{}
	for _, val := range data {
		remark := ""
		for _, val2 := range val.Remark {
			remark = remark + val2.RemarkText + "\n"
		}
		d := map[string]string{
			"beginDay": val.BeginDay,
			"category": val.Category,
			"name":     val.Name,
			"remark":   remark,
		}
		listData = append(listData, d)
	}
	result := map[string][]map[string]string{
		"list": listData,
	}
	return result, nil
}