审查视图

pkg/application/summary_evaluation/service/service.go 70.6 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:       v.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
		}
		value, ok := valueMap[v.Id]
tangxvhui authored
358 359 360 361
		if ok {
			item.Score = value.Score
			item.Value = value.Value
			item.Remark = value.Remark
tangxvhui authored
362
			item.Rating = value.Rating
363
			item.EvaluatorName = value.Executor.UserName
tangxvhui authored
364 365 366 367 368 369
		}
		itemValues = append(itemValues, item)
	}
	return itemValues
}
tangxvhui authored
370 371
// 根据周期id和被评估人获取综合自评详情
func (srv *SummaryEvaluationService) GetEvaluationSelfByCycle(param *command.QueryEvaluation) (*adapter.EvaluationInfoSelfAdapter, error) {
tangxvhui authored
372 373 374 375 376 377 378 379 380 381 382 383 384 385 386 387
	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
388
	itemValueRepo := factory.CreateSummaryEvaluationValueRepository(map[string]interface{}{
tangxvhui authored
389 390 391
		"transactionContext": transactionContext,
	})
	_, evaluationList, err := evaluationRepo.Find(map[string]interface{}{
392 393 394 395
		"limit":        1,
		"cycleId":      param.CycleId,
		"targetUserId": param.TargetUserId,
		"types":        domain.EvaluationSelf,
tangxvhui authored
396 397 398 399 400
	})
	if err != nil {
		return nil, application.ThrowError(application.INTERNAL_SERVER_ERROR, err.Error())
	}
	if len(evaluationList) == 0 {
tangxvhui authored
401
		return &adapter.EvaluationInfoSelfAdapter{}, nil
tangxvhui authored
402 403
	}
	evaluationData := evaluationList[0]
404 405 406
	if evaluationData.CompanyId != param.CompanyId {
		return nil, application.ThrowError(application.BUSINESS_ERROR, "没有操作权限")
	}
tangxvhui authored
407 408 409 410 411 412 413
	_, 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
414 415 416 417 418 419 420 421

	_, 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
422 423
	//获取组装基本信息
	evaluationBase := srv.getSummaryEvaluation(transactionContext, evaluationData)
tangxvhui authored
424 425 426
	if err := transactionContext.CommitTransaction(); err != nil {
		return nil, application.ThrowError(application.INTERNAL_SERVER_ERROR, err.Error())
	}
tangxvhui authored
427 428

	itemValuesAdapter := srv.buildSummaryItemValue(itemList, itemValues)
tangxvhui authored
429 430 431 432

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

// 编辑综合自评详情
郑周 authored
485
func (srv *SummaryEvaluationService) EditEvaluationSelf(param *command.EditEvaluationValue) (map[string][]adapter.EvaluationItemAdapter, error) {
486 487 488 489 490 491 492 493
	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
494 495 496 497 498 499 500 501 502 503
	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
504 505 506 507 508 509 510 511 512 513 514 515 516 517
	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
518
		return nil, application.ThrowError(application.INTERNAL_SERVER_ERROR, "获取评估"+err.Error())
tangxvhui authored
519
	}
tangxvhui authored
520 521 522 523
	if evaluationData.Types != domain.EvaluationSelf {
		return nil, application.ThrowError(application.INTERNAL_SERVER_ERROR, "没有操作权限")
	}
tangxvhui authored
524 525 526 527 528 529 530
	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
531
tangxvhui authored
532
	_, itemList, err := itemUsedRepo.Find(map[string]interface{}{
tangxvhui authored
533
		"evaluationProjectId": evaluationData.EvaluationProjectId,
tangxvhui authored
534
		"nodeType":            domain.LinkNodeSelfAssessment,
tangxvhui authored
535 536 537 538 539 540 541
	})
	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
542
	})
tangxvhui authored
543
tangxvhui authored
544 545 546
	if err != nil {
		return nil, application.ThrowError(application.INTERNAL_SERVER_ERROR, err.Error())
	}
547
548
	err = srv.editEvaluationValue(evaluationData, &itemValueList, itemList, param.EvaluationItems, nil, param.IsTemporary)
549 550
	if err != nil {
		return nil, application.ThrowError(application.BUSINESS_ERROR, err.Error())
tangxvhui authored
551
	}
tangxvhui authored
552
553
	//保存填写值
tangxvhui authored
554 555 556 557 558 559
	for _, v := range itemValueList {
		err = itemValueRepo.Save(v)
		if err != nil {
			return nil, application.ThrowError(application.INTERNAL_SERVER_ERROR, err.Error())
		}
	}
tangxvhui authored
560 561 562
	if !param.IsTemporary {
		evaluationData.Status = domain.EvaluationCompleted
	}
tangxvhui authored
563 564 565 566
	err = evaluationRepo.Save(evaluationData)
	if err != nil {
		return nil, application.ThrowError(application.INTERNAL_SERVER_ERROR, err.Error())
	}
tangxvhui authored
567 568 569
	if err := transactionContext.CommitTransaction(); err != nil {
		return nil, application.ThrowError(application.INTERNAL_SERVER_ERROR, err.Error())
	}
570 571 572 573 574 575 576
	if !param.IsTemporary {
		err = srv.AfterCompletedEvaluationSelf(evaluationData)
		if err != nil {
			return nil, err
		}
	}
577
	itemValueAdapter := srv.buildSummaryItemValue(itemList, itemValueList)
tangxvhui authored
578 579 580
	return map[string][]adapter.EvaluationItemAdapter{
		"EvaluationItems": itemValueAdapter,
	}, nil
tangxvhui authored
581
}
tangxvhui authored
582
tangxvhui authored
583 584
// 员工提交自评内容后,
// 员工作为被评估人,
585
// 变更360评估/人资评估/的开始时间
586
// 或者变更上级评估的开始时间
587
// 或者生成考核结果
588
func (srv *SummaryEvaluationService) AfterCompletedEvaluationSelf(param *domain.SummaryEvaluation) error {
589 590 591 592 593 594 595 596
	lock := xredis.NewLockSummaryEvaluation(param.TargetUser.UserId)
	err := lock.Lock()
	if err != nil {
		return application.ThrowError(application.INTERNAL_SERVER_ERROR, "未能完全提交评估内容")
	}
	defer func() {
		lock.UnLock()
	}()
597 598 599 600 601 602 603 604 605 606
	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
607 608 609 610 611
	evaluationRepo := factory.CreateSummaryEvaluationRepository(map[string]interface{}{
		"transactionContext": transactionContext,
	})
	_, evaluationList, err := evaluationRepo.Find(map[string]interface{}{
		"targetUserId": param.TargetUser.UserId,
612
		"typesList":    []int{int(domain.Evaluation360), int(domain.EvaluationHrbp)},
tangxvhui authored
613 614 615 616 617 618
		"cycleId":      param.CycleId,
		"limit":        1000,
	})
	if err != nil {
		return application.ThrowError(application.INTERNAL_SERVER_ERROR, err.Error())
	}
619 620 621 622 623 624 625 626 627 628 629 630
	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())
		}
	}
631
	nowTime := time.Now()
tangxvhui authored
632
	updatedId := []int{}
tangxvhui authored
633 634
	// 变更360评估/人资评估/上级评估的开始时间
	for _, v := range evaluationList {
635 636
		if v.BeginTime.After(nowTime) {
			v.BeginTime = nowTime
tangxvhui authored
637
			updatedId = append(updatedId, v.Id)
638
		}
tangxvhui authored
639
	}
tangxvhui authored
640 641 642 643 644 645 646
	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())
	}
647 648
	if len(evaluationList) == 0 {
		//没有上级评估、360评估、hrbp 评估
649 650 651 652 653 654 655 656 657 658
		//直接进入考核结果阶段
		_, 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())
		}
659
		if len(evaluationList) > 0 {
660 661 662
			//进入考核结果
			//自评的结束时间
			evaluationList[0].BeginTime = param.EndTime
tangxvhui authored
663 664
			evaluationList[0].Status = domain.EvaluationCompleted
			err = evaluationRepo.Save(evaluationList[0])
665 666 667 668
			if err != nil {
				return application.ThrowError(application.INTERNAL_SERVER_ERROR, "保存考核结果,"+err.Error())
			}
		}
669
	}
670 671 672
	if err := transactionContext.CommitTransaction(); err != nil {
		return application.ThrowError(application.INTERNAL_SERVER_ERROR, err.Error())
	}
tangxvhui authored
673 674 675
	return nil
}
676
// 提交员工的人资评估 或者 360 评估
tangxvhui authored
677
// 变更上级评估的开始时间
678
// 或者生成考核结果
679
func (srv *SummaryEvaluationService) AfterCompletedEvaluation360Hrbp(param *domain.SummaryEvaluation) error {
680 681 682 683 684 685 686 687
	lock := xredis.NewLockSummaryEvaluation(param.TargetUser.UserId)
	err := lock.Lock()
	if err != nil {
		return application.ThrowError(application.INTERNAL_SERVER_ERROR, "未能完全提交评估内容")
	}
	defer func() {
		lock.UnLock()
	}()
688 689 690 691 692 693 694 695 696 697 698
	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
699 700 701 702 703 704 705 706 707 708 709 710 711 712 713 714 715 716 717 718 719 720 721 722 723 724
	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
725
		"limit":        1,
tangxvhui authored
726 727 728 729
	})
	if err != nil {
		return application.ThrowError(application.INTERNAL_SERVER_ERROR, err.Error())
	}
730
	nowTime := time.Now()
tangxvhui authored
731
	updatedId := []int{}
732
	// 变更上级评估的开始时间
tangxvhui authored
733
	for _, v := range evaluationList {
734 735
		if v.BeginTime.After(nowTime) {
			v.BeginTime = nowTime
tangxvhui authored
736
			updatedId = append(updatedId, v.Id)
737
		}
tangxvhui authored
738 739 740 741 742 743 744
	}
	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
745
	}
746 747 748 749 750 751 752 753 754 755 756 757
	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())
		}
758
		if len(evaluationList) > 0 {
759 760
			//360评估的结束时间
			evaluationList[0].BeginTime = param.EndTime
tangxvhui authored
761 762
			evaluationList[0].Status = domain.EvaluationCompleted
			err = evaluationRepo.Save(evaluationList[0])
763 764 765 766 767 768 769 770 771 772 773
			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
}
774
// 员工提交上级评估后
775 776 777 778 779 780 781 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
// 生成考核结果
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())
	}
810
811
	if len(evaluationList) > 0 {
812 813
		//上级评估的结束时间
		evaluationList[0].BeginTime = param.EndTime
tangxvhui authored
814 815
		evaluationList[0].Status = domain.EvaluationCompleted
		err = evaluationRepo.Save(evaluationList[0])
816 817 818 819
		if err != nil {
			return application.ThrowError(application.INTERNAL_SERVER_ERROR, "保存考核结果,"+err.Error())
		}
	}
820 821 822
	if err := transactionContext.CommitTransaction(); err != nil {
		return application.ThrowError(application.INTERNAL_SERVER_ERROR, err.Error())
	}
tangxvhui authored
823 824 825
	return nil
}
826 827
// GetTargetUserCycleList
// 获取周期列表,被评估的周期列表
郑周 authored
828
func (srv *SummaryEvaluationService) GetTargetUserCycleList(param *command.QueryCycleList) (map[string]interface{}, error) {
829 830 831 832 833 834 835 836 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
	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{
866 867
			CycleId:   v.CycleId,
			CycleName: v.CycleName,
868
		}
869
870 871 872 873
		cycleList = append(cycleList, m)
	}
	return tool_funs.SimpleWrapGridMap(int64(cnt), cycleList), nil
}
tangxvhui authored
874
tangxvhui authored
875
// 周期综合自评小结详情
tangxvhui authored
876
func (srv *SummaryEvaluationService) CountEvaluationSelfLevel(param *command.QueryEvaluation) (*adapter.EvaluationInfoCountCodeAdapter, error) {
tangxvhui authored
877 878 879 880 881 882 883 884 885 886
	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
887 888 889 890
	//统计周期内,评估项等级的数量
	assessDao := dao.NewStaffAssessDao(map[string]interface{}{
		"transactionContext": transactionContext,
	})
tangxvhui authored
891 892 893 894 895 896 897 898 899 900
	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{}{
901 902 903 904
		"limit":        1,
		"cycleId":      param.CycleId,
		"targetUserId": param.TargetUserId,
		"types":        domain.EvaluationSelf,
tangxvhui authored
905 906 907 908 909 910 911 912
	})
	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
913 914 915 916
	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
917 918 919 920 921 922 923 924 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
	_, 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
952 953 954 955 956 957
	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
958 959 960 961 962 963 964 965
	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
966 967 968 969
		levelCodes, ok := levelCodeMap[itemId]
		if !ok {
			continue
		}
tangxvhui authored
970
		evaluationItemCount[i].LevelCount = levelCodes
tangxvhui authored
971 972
		for i2 := range levelCodes {
			key := fmt.Sprintf("%s-%s-%s",
tangxvhui authored
973 974
				evaluationItems[i].Category,
				evaluationItems[i].Name,
tangxvhui authored
975 976 977 978 979 980 981
				levelCodes[i2].Code,
			)
			if mVal, ok := levelCodeCountMap[key]; ok {
				levelCodes[i2].Number = mVal
			}
		}
	}
tangxvhui authored
982 983 984 985 986 987 988 989 990 991 992 993 994 995 996 997 998 999 1000 1001 1002 1003 1004 1005 1006 1007 1008 1009
	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,
	})
1010
	// permissionRepository := factory.CreatePermissionRepository(map[string]interface{}{"transactionContext": transactionContext})
1011
	// 获取权限配置
1012 1013 1014 1015 1016
	// _, 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))
1017
	if err != nil {
1018
		return nil, err
1019
	}
tangxvhui authored
1020 1021 1022 1023 1024 1025
	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
1026
	if evaluationData.Types != domain.EvaluationSuper {
tangxvhui authored
1027 1028
		return nil, application.ThrowError(application.BUSINESS_ERROR, "没有操作权限")
	}
tangxvhui authored
1029
	if evaluationData.CompanyId != param.CompanyId {
tangxvhui authored
1030 1031 1032 1033 1034 1035 1036 1037 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
		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
1071 1072 1073
	if err := transactionContext.CommitTransaction(); err != nil {
		return nil, application.ThrowError(application.INTERNAL_SERVER_ERROR, err.Error())
	}
tangxvhui authored
1074 1075
	//组合 评估填写的值和评估项
	itemValuesAdapter := srv.buildSummaryItemValue(itemList, itemValues)
1076
	for i, v := range itemValuesAdapter {
1077 1078 1079 1080 1081 1082 1083
		if permissinData.OptEvalScore == domain.PermissionOff &&
			v.EvaluatorId > 0 {
			itemValuesAdapter[i].ForbidEdit = true
		}
		if permissinData.OptHrScore == domain.PermissionOff &&
			v.EvaluatorId < 0 {
			itemValuesAdapter[i].ForbidEdit = true
1084 1085
		}
	}
tangxvhui authored
1086 1087
	result := adapter.EvaluationInfoSuperAdapter{
		EvaluationBaseAdapter: evaluationBase,
tangxvhui authored
1088 1089
		// LevelCount:            codeList,
		EvaluationItems: itemValuesAdapter,
tangxvhui authored
1090 1091
	}
	return &result, nil
tangxvhui authored
1092
}
tangxvhui authored
1093
tangxvhui authored
1094 1095
// EditEvaluationSuper 更新上级评估内容
func (srv *SummaryEvaluationService) EditEvaluationSuper(param *command.EditEvaluationValue) (interface{}, error) {
1096 1097 1098 1099 1100 1101 1102 1103
	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
1104 1105 1106 1107 1108 1109 1110 1111 1112 1113 1114 1115 1116 1117 1118 1119 1120 1121 1122 1123 1124 1125 1126 1127 1128 1129 1130 1131 1132
	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
1133
tangxvhui authored
1134 1135 1136 1137 1138 1139 1140 1141 1142 1143 1144 1145 1146 1147 1148 1149 1150 1151 1152 1153 1154 1155 1156 1157 1158 1159 1160
	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
1161
1162
	err = srv.editEvaluationValue(evaluationData, &itemValueList, itemList, param.EvaluationItems, hrbpOr360ItemValue, param.IsTemporary)
1163 1164
	if err != nil {
		return nil, application.ThrowError(application.INTERNAL_SERVER_ERROR, err.Error())
tangxvhui authored
1165
	}
1166 1167 1168 1169
	if !param.IsTemporary {
		//变更评估状态为已填写
		evaluationData.Status = domain.EvaluationCompleted
	}
1170
	for _, v := range itemValueList {
tangxvhui authored
1171 1172 1173 1174 1175 1176 1177 1178 1179 1180 1181 1182 1183 1184
		//保存填写值
		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())
	}
1185 1186 1187 1188 1189 1190 1191 1192

	if !param.IsTemporary {
		err = srv.AfterCompletedEvaluationSuper(evaluationData)
		if err != nil {
			return nil, err
		}
	}
1193
	itemValueAdapter := srv.buildSummaryItemValue(itemList, itemValueList)
tangxvhui authored
1194 1195 1196
	return map[string][]adapter.EvaluationItemAdapter{
		"EvaluationItems": itemValueAdapter,
	}, nil
tangxvhui authored
1197 1198
}
tangxvhui authored
1199 1200 1201
// getEvaluationSuperDefaultValue
// 按照权限设置,是否获取上级评估内容的默认值
func (srv *SummaryEvaluationService) getEvaluationSuperDefaultValue(transactionContext application.TransactionContext, evaluationData *domain.SummaryEvaluation) (
1202
	[]*domain.SummaryEvaluationValue, error) {
tangxvhui authored
1203 1204 1205
	evaluationRepo := factory.CreateSummaryEvaluationRepository(map[string]interface{}{
		"transactionContext": transactionContext,
	})
tangxvhui authored
1206
tangxvhui authored
1207 1208 1209 1210
	itemValueRepo := factory.CreateSummaryEvaluationValueRepository(map[string]interface{}{
		"transactionContext": transactionContext,
	})
1211 1212 1213 1214 1215 1216 1217 1218 1219 1220
	// 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
1221 1222 1223 1224 1225 1226 1227 1228 1229 1230 1231 1232 1233 1234 1235 1236 1237 1238 1239 1240 1241 1242 1243 1244 1245 1246 1247 1248 1249 1250
	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
1251
	hrbpOr360ItemValue := []*domain.SummaryEvaluationValue{}
tangxvhui authored
1252 1253 1254 1255 1256 1257 1258 1259
	if permissionData.OptEvalScore == domain.PermissionOff {
		//上级是否可以修改360°综评分数
		//获取360综合评分
		for _, v := range itemValuesOther {
			//记录人资评估或者360评估的填写值
			if v.Types != domain.Evaluation360 {
				continue
			}
1260
			hrbpOr360ItemValue = append(hrbpOr360ItemValue, v)
tangxvhui authored
1261 1262 1263 1264 1265 1266 1267 1268 1269 1270 1271
		}
	}
	if permissionData.OptHrScore == domain.PermissionOff {
		//上级是否可以修改人资综评分数
		//获取人资综合评分
		for _, v := range itemValuesOther {
			//记录人资评估或者360评估的填写值
			if v.Types != domain.EvaluationHrbp {
				continue
			}
1272
			hrbpOr360ItemValue = append(hrbpOr360ItemValue, v)
tangxvhui authored
1273 1274
		}
	}
1275
	return hrbpOr360ItemValue, nil
tangxvhui authored
1276
}
tangxvhui authored
1277
1278 1279
// 获取执行人的上级评估的列表
func (srv *SummaryEvaluationService) ListExecutorEvaluationSuper(param *command.QueryExecutorEvaluationList) (map[string]interface{}, error) {
tangxvhui authored
1280 1281 1282 1283 1284 1285 1286 1287 1288 1289 1290 1291 1292 1293 1294 1295
	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,
	})
1296 1297 1298 1299 1300 1301 1302 1303 1304 1305 1306 1307
	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,
1308
		"beginTime":  time.Now(),
1309 1310 1311 1312
	}
	if offset > 0 {
		condition1["offset"] = offset
	}
tangxvhui authored
1313
	if len(param.TargetUserName) > 0 {
1314 1315 1316 1317 1318 1319 1320 1321 1322
		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
1323 1324 1325
		"cycleId":    param.CycleId,
		"executorId": param.ExecutorId,
		"types":      int(domain.EvaluationSuper),
1326 1327
		"status":     domain.EvaluationUncompleted,
		"limit":      1,
1328
		"beginTime":  time.Now(),
tangxvhui authored
1329 1330 1331 1332 1333 1334 1335 1336
	})
	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)
	}
1337 1338 1339 1340 1341 1342 1343 1344 1345 1346 1347 1348 1349 1350 1351 1352 1353 1354 1355
	//获取员工的综合自评
	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
1356
	if len(targetUserIds) > 0 {
1357
		_, userList, err := userRepo.Find(map[string]interface{}{
tangxvhui authored
1358 1359 1360 1361 1362
			"ids": targetUserIds,
		})
		if err != nil {
			return nil, application.ThrowError(application.INTERNAL_SERVER_ERROR, err.Error())
		}
1363 1364 1365 1366 1367 1368 1369 1370 1371 1372
		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
1373
1374
	if len(positionIds) > 0 {
1375
		_, positionList, err := positionRepo.Find(map[string]interface{}{"ids": positionIds})
1376 1377 1378 1379 1380 1381 1382
		if err != nil {
			return nil, application.ThrowError(application.INTERNAL_SERVER_ERROR, "获取部门信息"+err.Error())
		}
		for _, v := range positionList {
			positionMap[v.Id] = v
		}
	}
tangxvhui authored
1383 1384 1385
	if err := transactionContext.CommitTransaction(); err != nil {
		return nil, application.ThrowError(application.INTERNAL_SERVER_ERROR, err.Error())
	}
1386 1387 1388 1389 1390
	evaluationListAdapter := []*adapter.EvaluationSuperListAdapter{}
	for _, v := range evaluationList {
		item := adapter.EvaluationSuperListAdapter{
			SummaryEvaluationId: v.Id,
			TargetUserName:      v.TargetUser.UserName,
1391
			TargetUserId:        v.TargetUser.UserId,
1392
			EvaluationStatus:    string(v.Status),
1393
			EndTime:             v.EndTime.Local().Format("2006-01-02 15:04:05"),
1394 1395 1396 1397 1398
			TotalScoreSelf:      "",
			Department:          "",
			Position:            "",
			EntryTime:           "",
		}
1399 1400 1401
		for _, dep := range v.TargetDepartment {
			item.Department += dep.DepartmentName + " "
		}
1402 1403 1404 1405 1406 1407 1408 1409 1410 1411 1412 1413 1414 1415 1416 1417 1418 1419 1420 1421 1422
		//填充员工信息
		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 {
1423
		result["endTime"] = evaluationList[0].EndTime.Local().Format("2006-01-02 15:04:05")
1424 1425 1426
		result["uncompleted_number"] = cntUn
	}
	return result, nil
tangxvhui authored
1427
}
tangxvhui authored
1428
1429 1430 1431
// ConfirmScoreEvaluation 员工确认考核结果
func (srv *SummaryEvaluationService) ConfirmScoreEvaluation(param *command.ConfirmScore) error {
	transactionContext, err := factory.ValidateStartTransaction(param)
tangxvhui authored
1432
	if err != nil {
1433
		return err
tangxvhui authored
1434 1435 1436 1437 1438
	}
	defer func() {
		_ = transactionContext.RollbackTransaction()
	}()
1439 1440 1441 1442 1443 1444
	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
1445 1446 1447
	if err != nil {
		return application.ThrowError(application.TRANSACTION_ERROR, err.Error())
	}
tangxvhui authored
1448
1449
	if result.Types != domain.EvaluationFinish {
tangxvhui authored
1450 1451
		return application.ThrowError(application.TRANSACTION_ERROR, "操作方式错误")
	}
1452
	if result.TargetUser.UserId != param.UserId {
tangxvhui authored
1453 1454
		return application.ThrowError(application.TRANSACTION_ERROR, "没有操作权限")
	}
1455 1456
	if result.CheckResult == domain.EvaluationCheckCompleted {
		return application.ThrowError(application.TRANSACTION_ERROR, "考核结果已确认过了!")
tangxvhui authored
1457
	}
1458 1459 1460 1461 1462 1463 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
	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())
		}
1496 1497 1498 1499 1500
		// 更新填写值
		itemValues, err = srv.updateItemValuePriority(result, itemList, itemValues, true)
		if err != nil {
			return application.ThrowError(application.INTERNAL_SERVER_ERROR, err.Error())
		}
1501 1502 1503 1504 1505 1506 1507 1508 1509 1510 1511 1512 1513 1514 1515 1516 1517
	} 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())
			}

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

	result.CheckResult = domain.EvaluationCheckCompleted
1540
	if err := evaluationRepo.Save(result); err != nil {
tangxvhui authored
1541 1542 1543 1544 1545 1546 1547
		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
1548
1549 1550 1551 1552
// 处理优先级
func (srv *SummaryEvaluationService) updateItemValuePriority(
	result *domain.SummaryEvaluation,
	itemList []*domain.EvaluationItemUsed,
1553 1554
	itemValues []*domain.SummaryEvaluationValue,
	superior bool) ([]*domain.SummaryEvaluationValue, error) {
1555 1556 1557 1558

	tempSelf := map[int]*domain.SummaryEvaluationValue{}
	temp360 := map[int]*domain.SummaryEvaluationValue{}
	tempHRBP := map[int]*domain.SummaryEvaluationValue{}
1559 1560
	tempSuperior := map[int]*domain.SummaryEvaluationValue{}
1561 1562 1563 1564 1565 1566 1567 1568
	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
1569 1570
		} else if it.Types == domain.EvaluationSuper {
			tempSuperior[it.EvaluationItemId] = it
1571 1572 1573 1574 1575 1576 1577 1578 1579 1580
		}
	}
	nowTime := time.Now()
	var newItemValues = make([]*domain.SummaryEvaluationValue, 0)
	for i := range itemList {
		it := itemList[i]

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

	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
1652
	}
1653 1654
	if result == nil {
		return nil, application.ThrowError(application.INTERNAL_SERVER_ERROR, "没有找到符合条件的数据")
tangxvhui authored
1655 1656
	}
1657 1658 1659 1660 1661 1662
	// 评估内容和值
	var itemList []*domain.EvaluationItemUsed
	var itemValues []*domain.SummaryEvaluationValue

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

	// 按评估项优先级顺序(已确认考核结果 ->上级评估 ->HR或360评估或自评)
	if result.CheckResult == domain.EvaluationCheckCompleted { /* 已完成考核*/
		_, itemValues, err = itemValueRepo.Find(map[string]interface{}{"summaryEvaluationId": result.Id}) // 获取已填写的评估内容
tangxvhui authored
1670 1671 1672
		if err != nil {
			return nil, application.ThrowError(application.INTERNAL_SERVER_ERROR, err.Error())
		}
1673 1674 1675
	} else {
		if super != nil {
			_, itemValues, err = itemValueRepo.Find(map[string]interface{}{"summaryEvaluationId": super.Id}) // 获取已填写的评估内容
tangxvhui authored
1676 1677 1678
			if err != nil {
				return nil, application.ThrowError(application.INTERNAL_SERVER_ERROR, err.Error())
			}
1679 1680 1681 1682 1683 1684 1685 1686 1687 1688 1689 1690 1691 1692 1693 1694 1695
		} 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())
				}

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

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

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

	//获取评估列表信息
	condition1 := map[string]interface{}{
tangxvhui authored
1804 1805 1806
		"cycleId": param.CycleId,
		"types":   int(domain.EvaluationFinish),
		"limit":   limit,
1807 1808 1809 1810
	}
	if offset > 0 {
		condition1["offset"] = offset
	}
tangxvhui authored
1811
	if len(param.TargetUserName) > 0 {
1812 1813 1814 1815 1816 1817 1818 1819 1820 1821 1822
		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
1823
1824 1825 1826 1827 1828 1829 1830 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
	//获取员工信息
	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
1882
}
1883 1884 1885 1886 1887 1888 1889 1890 1891 1892 1893 1894 1895

// 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,
1896
	isTemporary bool,
1897
) error {
1898 1899 1900 1901 1902

	ok := evaluationData.EndTime.Before(time.Now())
	if ok {
		return errors.New("评估时间已截止")
	}
1903 1904
	evaluationItemMap := map[int]*domain.EvaluationItemUsed{}
	evaluationValueMap := map[int]*domain.SummaryEvaluationValue{}
1905
	evaluationValueSlice := []*domain.SummaryEvaluationValue{}
1906 1907 1908 1909 1910 1911
	evaluationData.TotalRating = nil //清空评级数量统计
	for _, v := range evaluationItems {
		newValue := &domain.SummaryEvaluationValue{}
		newValue.SetBlankValue(evaluationData, v)
		evaluationValueMap[v.Id] = newValue
		evaluationItemMap[v.Id] = v
1912
		evaluationValueSlice = append(evaluationValueSlice, newValue)
1913 1914 1915
		//重置计数
		evaluationData.ResetTotalRating(v)
	}
1916
	//如果存在旧值
1917 1918 1919 1920 1921 1922 1923 1924
	//新值的id 替换为旧值id
	for _, v := range *itemValueList {
		if mValue, ok := evaluationValueMap[v.EvaluationItemId]; ok {
			mValue.Id = v.Id
		}
	}
	//填入填写的更新值
	for _, v := range updatedValue {
tangxvhui authored
1925
		v.Value = strings.TrimSpace(v.Value)
1926 1927 1928 1929 1930 1931 1932 1933
		newItemValue, ok := evaluationValueMap[v.EvaluationItemId]
		if !ok {
			continue
		}
		evaluationItem, ok := evaluationItemMap[v.EvaluationItemId]
		if !ok {
			continue
		}
tangxvhui authored
1934
		if !isTemporary {
1935 1936 1937 1938 1939 1940 1941 1942 1943 1944
			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
1945 1946
			}
		}
1947 1948 1949 1950 1951 1952 1953 1954 1955 1956 1957 1958 1959 1960 1961 1962 1963
		//填充评估填写值
		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
1964
		err := newItemValue.FillValue(evaluationItem, v.Value, newItemValue.Remark)
1965 1966 1967 1968 1969
		if err != nil {
			return err
		}
	}
	//完全更新itemValueList
1970 1971 1972 1973 1974 1975 1976 1977
	*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
	// })
1978
	// 计算总得分
tangxvhui authored
1979
	err := evaluationData.EvaluationTotalScore(*itemValueList)
1980 1981 1982 1983 1984
	if err != nil {
		return err
	}
	return nil
}
tangxvhui authored
1985 1986 1987 1988 1989

// 获取现在待执行的综合自评
func (srv *SummaryEvaluationService) ListExecutorNowEvaluationSelf(param *command.QueryExecutorEvaluationList) (map[string]interface{}, error) {
	transactionContext, err := factory.CreateTransactionContext(nil)
	if err != nil {
1990
		return nil, err
tangxvhui authored
1991
	}
tangxvhui authored
1992 1993 1994
	if err := transactionContext.StartTransaction(); err != nil {
		return nil, application.ThrowError(application.TRANSACTION_ERROR, err.Error())
	}
tangxvhui authored
1995 1996 1997 1998 1999 2000 2001 2002 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
	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
2033 2034 2035 2036 2037 2038 2039 2040 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

// 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
}