审查视图

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 47 48 49 50 51 52 53

	flagHrbp, err := roleService.GetHRBP(transactionContext, param.CompanyId, param.UserId)
	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())
		}
	}
tangxvhui authored
197 198 199 200
	isHrbp, err := roleService.GetHRBP(transactionContext, param.CompanyId, param.UserId)
	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 346 347 348 349 350 351 352 353 354
	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,
			PromptText:       v.PromptText,
			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 358
		//PromptText 页面展示 特殊处理
		if len(v.EntryItems) > 0 {
tangxvhui authored
359
			item.PromptTitle = ""
360 361 362 363
			for _, v2 := range v.EntryItems {
				item.PromptTitle += v2.Title + "\n"
			}
		}
tangxvhui authored
364
		value, ok := valueMap[v.Id]
tangxvhui authored
365 366 367 368
		if ok {
			item.Score = value.Score
			item.Value = value.Value
			item.Remark = value.Remark
tangxvhui authored
369
			item.Rating = value.Rating
370
			item.EvaluatorName = value.Executor.UserName
tangxvhui authored
371 372 373 374 375 376
		}
		itemValues = append(itemValues, item)
	}
	return itemValues
}
tangxvhui authored
377 378
// 根据周期id和被评估人获取综合自评详情
func (srv *SummaryEvaluationService) GetEvaluationSelfByCycle(param *command.QueryEvaluation) (*adapter.EvaluationInfoSelfAdapter, error) {
tangxvhui authored
379 380 381 382 383 384 385 386 387 388 389 390 391 392 393 394
	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
395
	itemValueRepo := factory.CreateSummaryEvaluationValueRepository(map[string]interface{}{
tangxvhui authored
396 397 398
		"transactionContext": transactionContext,
	})
	_, evaluationList, err := evaluationRepo.Find(map[string]interface{}{
399 400 401 402
		"limit":        1,
		"cycleId":      param.CycleId,
		"targetUserId": param.TargetUserId,
		"types":        domain.EvaluationSelf,
tangxvhui authored
403 404 405 406 407
	})
	if err != nil {
		return nil, application.ThrowError(application.INTERNAL_SERVER_ERROR, err.Error())
	}
	if len(evaluationList) == 0 {
tangxvhui authored
408
		return &adapter.EvaluationInfoSelfAdapter{}, nil
tangxvhui authored
409 410
	}
	evaluationData := evaluationList[0]
411 412 413
	if evaluationData.CompanyId != param.CompanyId {
		return nil, application.ThrowError(application.BUSINESS_ERROR, "没有操作权限")
	}
tangxvhui authored
414 415 416 417 418 419 420
	_, 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
421 422 423 424 425 426 427 428

	_, 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
429 430
	//获取组装基本信息
	evaluationBase := srv.getSummaryEvaluation(transactionContext, evaluationData)
tangxvhui authored
431 432 433
	if err := transactionContext.CommitTransaction(); err != nil {
		return nil, application.ThrowError(application.INTERNAL_SERVER_ERROR, err.Error())
	}
tangxvhui authored
434 435

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

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

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

	if !param.IsTemporary {
		err = srv.AfterCompletedEvaluationSuper(evaluationData)
		if err != nil {
			return nil, err
		}
	}
1198
	itemValueAdapter := srv.buildSummaryItemValue(itemList, itemValueList)
tangxvhui authored
1199 1200 1201
	return map[string][]adapter.EvaluationItemAdapter{
		"EvaluationItems": itemValueAdapter,
	}, nil
tangxvhui authored
1202 1203
}
tangxvhui authored
1204 1205 1206
// getEvaluationSuperDefaultValue
// 按照权限设置,是否获取上级评估内容的默认值
func (srv *SummaryEvaluationService) getEvaluationSuperDefaultValue(transactionContext application.TransactionContext, evaluationData *domain.SummaryEvaluation) (
1207
	[]*domain.SummaryEvaluationValue, error) {
tangxvhui authored
1208 1209 1210
	evaluationRepo := factory.CreateSummaryEvaluationRepository(map[string]interface{}{
		"transactionContext": transactionContext,
	})
tangxvhui authored
1211
tangxvhui authored
1212 1213 1214 1215 1216 1217 1218 1219 1220 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 1251 1252
	itemValueRepo := factory.CreateSummaryEvaluationValueRepository(map[string]interface{}{
		"transactionContext": transactionContext,
	})

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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