审查视图

pkg/application/staff_assess/service/service_v2.go 49.1 KB
tangxvhui authored
1 2 3 4
package service

import (
	"fmt"
tangxvhui authored
5
	"sort"
tangxvhui authored
6
	"strconv"
7
	"time"
tangxvhui authored
8 9 10 11 12 13 14 15

	"github.com/linmadan/egglib-go/core/application"
	"github.com/linmadan/egglib-go/utils/tool_funs"
	"gitlab.fjmaimaimai.com/allied-creation/performance/pkg/application/factory"
	"gitlab.fjmaimaimai.com/allied-creation/performance/pkg/application/staff_assess/adapter"
	"gitlab.fjmaimaimai.com/allied-creation/performance/pkg/application/staff_assess/query"
	"gitlab.fjmaimaimai.com/allied-creation/performance/pkg/domain"
	"gitlab.fjmaimaimai.com/allied-creation/performance/pkg/infrastructure/dao"
tangxvhui authored
16
	"gitlab.fjmaimaimai.com/allied-creation/performance/pkg/log"
tangxvhui authored
17 18
)
19
// 获取我的项目周期列表
tangxvhui authored
20
func (srv StaffAssessServeice) SearchAssessTaskMeV2(param *query.SearchAssessMeQuery) (map[string]interface{}, error) {
tangxvhui authored
21 22 23 24 25 26 27 28 29 30 31
	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()
	}()
32
	staffAssessDao := dao.NewStaffAssessDao(map[string]interface{}{
tangxvhui authored
33 34
		"transactionContext": transactionContext,
	})
tangxvhui authored
35
	var limit int = 360
tangxvhui authored
36 37 38 39
	var offset int = 0
	if param.PageSize > 0 {
		limit = param.PageSize
	}
tangxvhui authored
40 41 42
	if param.PageNumber <= 0 {
		param.PageNumber = 1
	}
tangxvhui authored
43
	offset = (param.PageNumber - 1) * param.PageSize
44 45

	assessCycleList, cnt, err := staffAssessDao.SearchExecutorAssessBeforeNow(param.UserId, param.CompanyId, limit, offset)
tangxvhui authored
46 47 48
	if err != nil {
		return nil, application.ThrowError(application.INTERNAL_SERVER_ERROR, "查询评估周期"+err.Error())
	}
49
	assessCycleList2, err := staffAssessDao.SearchExecutorAssessAfterNow(param.UserId, param.CompanyId)
tangxvhui authored
50 51 52 53 54 55 56
	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 := make([]adapter.AssessCycleDayResp, 0, len(assessCycleList))
57
tangxvhui authored
58
	var temp adapter.AssessCycleDayResp
59 60 61 62 63 64 65 66 67 68
	for _, v := range assessCycleList2 {
		temp = adapter.AssessCycleDayResp{
			CycleId:   v.CycleId,
			CycleName: v.CycleName,
			BeginDay:  v.BeginDay,
			BeginTime: v.BeginTime,
			EndTime:   v.EndTime,
		}
		listData = append(listData, temp)
	}
tangxvhui authored
69 70
	for _, v := range assessCycleList {
		temp = adapter.AssessCycleDayResp{
tangxvhui authored
71 72 73
			CycleId:   v.CycleId,
			CycleName: v.CycleName,
			BeginDay:  v.BeginDay,
tangxvhui authored
74 75
			BeginTime: v.BeginTime,
			EndTime:   v.EndTime,
tangxvhui authored
76 77 78 79 80 81
		}
		listData = append(listData, temp)
	}
	return tool_funs.SimpleWrapGridMap(int64(cnt), listData), nil
}
82
// 获取我的项目周期进度描述
tangxvhui authored
83
func (srv StaffAssessServeice) AssessTaskDescV2(param *query.AssessTaskDescV2Query) (*adapter.AssessCycleDescResp, error) {
tangxvhui authored
84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101
	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()
	}()
	// 获取评估任务
	staffAssessTaskRepo := factory.CreateStaffAssessTaskRepository(map[string]interface{}{
		"transactionContext": transactionContext,
	})
	//获取个人参与的评估流程
	staffAssessRepo := factory.CreateStaffAssessRepository(map[string]interface{}{
		"transactionContext": transactionContext,
	})
tangxvhui authored
102
tangxvhui authored
103
	_, assessTaskList, err := staffAssessTaskRepo.Find(map[string]interface{}{
tangxvhui authored
104 105
		"beginDay":  param.BeginDay,
		"cycleId":   param.CycleId,
tangxvhui authored
106
		"companyId": param.CompanyId,
tangxvhui authored
107
		"limit":     1,
tangxvhui authored
108 109 110 111
	})
	if err != nil {
		return nil, application.ThrowError(application.TRANSACTION_ERROR, "评估任务不存在,"+err.Error())
	}
tangxvhui authored
112 113 114 115
	if len(assessTaskList) == 0 {
		return &adapter.AssessCycleDescResp{}, nil
	}
	assessTaskDataAny := assessTaskList[0]
tangxvhui authored
116
	//返回的数据结果
tangxvhui authored
117 118 119 120 121
	result := adapter.AssessCycleDescResp{
		CycleId:   int(assessTaskDataAny.CycleId),
		CycleName: assessTaskDataAny.CycleName,
		BeginDay:  assessTaskDataAny.BeginDay,
		StepList:  []adapter.AssessTaskStep{},
tangxvhui authored
122
	}
tangxvhui authored
123
	hasAssessSelf := false
tangxvhui authored
124
tangxvhui authored
125
	for _, v := range assessTaskDataAny.StepList {
tangxvhui authored
126 127 128 129 130 131 132 133 134 135 136 137
		stepItem := adapter.AssessTaskStep{
			SortBy:       v.SortBy,
			LinkNodeName: v.LinkNodeName,
			LinkNodeId:   v.LinkNodeId,
			BeginTime:    v.BeginTime.Local().Format("2006-01-02 15:04:05"),
			EndTime:      v.EndTime.Local().Format("2006-01-02 15:04:05"),
			LinkNodeType: v.LinkNodeType,
			Desc:         fmt.Sprintf("截止日期:%s", v.EndTime.Local().Format("2006-01-02 15:04:05")),
			Status:       "",
		}
		switch v.LinkNodeType {
		case domain.LinkNodeSelfAssessment:
tangxvhui authored
138 139 140 141 142 143 144 145 146
			//个人自评完成情况
			_, assessSelfData, err := staffAssessRepo.Find(map[string]interface{}{
				"cycleId":    assessTaskDataAny.CycleId,
				"beginDay":   assessTaskDataAny.BeginDay,
				"executorId": param.UserId, //我作为执行人
				"typesList":  []string{string(domain.AssessSelf)},
			})
			if err != nil {
				return nil, application.ThrowError(application.TRANSACTION_ERROR, "获取个人的评估环节"+err.Error())
tangxvhui authored
147
			}
tangxvhui authored
148
			if len(assessSelfData) > 0 {
tangxvhui authored
149
				hasAssessSelf = true
tangxvhui authored
150 151 152
				stepItem.Status = string(assessSelfData[0].Status)
			}
			stepItem.Desc = fmt.Sprintf("截止日期:%s", stepItem.EndTime)
tangxvhui authored
153
		case domain.LinkNodeAllInvite:
tangxvhui authored
154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174
			//邀请别人评估自己
			_, assessInviteData, err := staffAssessRepo.Find(map[string]interface{}{
				"cycleId":      assessTaskDataAny.CycleId,
				"beginDay":     assessTaskDataAny.BeginDay,
				"targetUserId": param.UserId, //我被作为目标
				"typesList":    []string{string(domain.AssessInviteDiffSuper), string(domain.AssessInviteSameSuper)},
				"limit":        5,
			})
			if err != nil {
				return nil, application.ThrowError(application.TRANSACTION_ERROR, "获取个人的评估环节"+err.Error())
			}
			if len(assessInviteData) > 0 {
				stepItem.Status = string(domain.StaffAssessCompleted)
			} else {
				stepItem.Status = string(domain.StaffAssessUncompleted)
			}
			//待邀请人数,为5人减去已邀请的人数。若邀请人数已等于或大于5人,则只显示截止日期即可
			if len(assessInviteData) > 5 {
				stepItem.Desc = fmt.Sprintf("截止日期:%s", stepItem.EndTime)
			} else {
				stepItem.Desc = fmt.Sprintf("截止日期:%s  待邀请%d人", stepItem.EndTime, 5-len(assessInviteData))
tangxvhui authored
175 176 177 178
			}
		case domain.LinkNodeAllAssessment:
			//我评估别人,被邀请评估
			_, assessInviteList, err := staffAssessRepo.Find(map[string]interface{}{
tangxvhui authored
179 180
				"cycleId":    assessTaskDataAny.CycleId,
				"beginDay":   assessTaskDataAny.BeginDay,
tangxvhui authored
181
				"executorId": param.UserId, //我作为执行人
tangxvhui authored
182
				"typesList":  []string{string(domain.AssessInviteDiffSuper), string(domain.AssessInviteSameSuper)},
tangxvhui authored
183 184 185 186 187 188 189 190 191 192 193 194 195 196 197 198
			})
			if err != nil {
				return nil, application.ThrowError(application.TRANSACTION_ERROR, "获取个人的评估环节"+err.Error())
			}
			if len(assessInviteList) > 0 {
				stepItem.Status = string(domain.StaffAssessCompleted)
				stepItem.Desc = fmt.Sprintf("截止日期:%s", stepItem.EndTime)
				for _, v := range assessInviteList {
					if v.Status == domain.StaffAssessUncompleted {
						stepItem.Status = string(domain.StaffAssessUncompleted)
						break
					}
				}
			}
		case domain.LinkNodeSuperiorAssessment:
			//我评估别人,上级评估
tangxvhui authored
199
			cnnt, _, err := staffAssessRepo.Find(map[string]interface{}{
tangxvhui authored
200 201
				"cycleId":    assessTaskDataAny.CycleId,
				"beginDay":   assessTaskDataAny.BeginDay,
tangxvhui authored
202 203
				"executorId": param.UserId,
				"typesList":  []string{string(domain.AssessSuper)},
tangxvhui authored
204 205
				"status":     domain.StaffAssessUncompleted,
				"limit":      1,
tangxvhui authored
206 207
			})
			if err != nil {
tangxvhui authored
208 209 210
				return nil, application.ThrowError(application.TRANSACTION_ERROR, "获取未完成的评估环节"+err.Error())
			}
			cnnt2, _, err := staffAssessRepo.Find(map[string]interface{}{
tangxvhui authored
211 212
				"cycleId":    assessTaskDataAny.CycleId,
				"beginDay":   assessTaskDataAny.BeginDay,
tangxvhui authored
213 214 215 216 217 218 219
				"executorId": param.UserId,
				"typesList":  []string{string(domain.AssessSuper)},
				"status":     domain.StaffAssessCompleted,
				"limit":      1,
			})
			if err != nil {
				return nil, application.ThrowError(application.TRANSACTION_ERROR, "获取已完成的评估环节"+err.Error())
tangxvhui authored
220
			}
tangxvhui authored
221
			if (cnnt + cnnt2) > 0 {
tangxvhui authored
222 223
				stepItem.Status = string(domain.StaffAssessCompleted)
				stepItem.Desc = fmt.Sprintf("截止日期:%s", stepItem.EndTime)
tangxvhui authored
224
				uncompletedNum := cnnt
tangxvhui authored
225 226 227 228 229
				if uncompletedNum > 0 {
					stepItem.Status = string(domain.StaffAssessUncompleted)
					stepItem.Desc = fmt.Sprintf("截止日期:%s 待评估%d人", stepItem.EndTime, uncompletedNum)
				}
			}
230 231 232 233 234 235 236 237 238 239 240 241 242 243 244 245 246 247 248 249
		case domain.LinkNodeViewResult:
			//我被上级评估
			_, assessSuperList, err := staffAssessRepo.Find(map[string]interface{}{
				"cycleId":      assessTaskDataAny.CycleId,
				"beginDay":     assessTaskDataAny.BeginDay,
				"targetUserId": param.UserId,
				"typesList":    []string{string(domain.AssessSuper)},
				"limit":        1,
			})
			if err != nil {
				return nil, application.ThrowError(application.TRANSACTION_ERROR, "获取未完成的评估环节"+err.Error())
			}
			if len(assessSuperList) > 0 {
				stepItem.Status = string(assessSuperList[0].Status)
				stepItem.Desc = fmt.Sprintf("截止日期:%s", stepItem.EndTime)
				if assessSuperList[0].Status == domain.StaffAssessUncompleted {
					stepItem.Status = string(domain.StaffAssessUncompleted)
					break
				}
			}
tangxvhui authored
250 251 252
		}
		result.StepList = append(result.StepList, stepItem)
	}
tangxvhui authored
253 254 255 256
	//排序评估阶段
	sort.Slice(result.StepList, func(i, j int) bool {
		return result.StepList[i].SortBy < result.StepList[j].SortBy
	})
tangxvhui authored
257 258 259 260 261 262 263
	for i := range result.StepList {
		if result.StepList[i].LinkNodeType == domain.LinkNodeAllInvite {
			if !hasAssessSelf {
				result.StepList[i].Status = ""
			}
		}
	}
tangxvhui authored
264 265 266 267 268
	if err := transactionContext.CommitTransaction(); err != nil {
		return nil, application.ThrowError(application.INTERNAL_SERVER_ERROR, err.Error())
	}
	return &result, nil
}
tangxvhui authored
269
270
// 根据周期获取,我的自评任务添加的邀请人
tangxvhui authored
271
func (srv StaffAssessServeice) ListAssessInviteUserV2(param *query.ListInviteUserQuery) (*adapter.AssessInviteUserResp, error) {
tangxvhui authored
272 273 274 275 276 277 278 279 280 281 282 283 284 285
	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()
	}()

	assessReps := factory.CreateStaffAssessRepository(map[string]interface{}{
		"transactionContext": transactionContext,
	})
tangxvhui authored
286 287 288 289 290 291
	companyReps := factory.CreateCompanyRepository(map[string]interface{}{
		"transactionContext": transactionContext,
	})
	companyInfo, _ := companyReps.FindOne(map[string]interface{}{
		"id": param.CompanyId,
	})
tangxvhui authored
292 293 294 295 296 297
	assessTaskRepo := factory.CreateStaffAssessTaskRepository(map[string]interface{}{
		"transactionContext": transactionContext,
	})
	_, myAssessTask, err := assessTaskRepo.Find(map[string]interface{}{
		"cycleId":    param.CycleId,
		"beginDay":   param.BeginDay,
tangxvhui authored
298
		"executorId": param.TargetUserId,
tangxvhui authored
299 300 301
		"limit":      1,
	})
	if err != nil {
tangxvhui authored
302
		return nil, application.ThrowError(application.TRANSACTION_ERROR, "我的自评任务不存在,"+err.Error())
tangxvhui authored
303 304 305 306 307 308 309 310 311 312 313
	}

	if len(myAssessTask) == 0 {
		return nil, application.ThrowError(application.TRANSACTION_ERROR, "未参与本次的自评")
	}

	assessTaskData := myAssessTask[0]

	_, assessList, err := assessReps.Find(map[string]interface{}{
		"typesList":         []string{string(domain.AssessInviteDiffSuper), string(domain.AssessInviteSameSuper)},
		"staffAssessTaskId": assessTaskData.Id,
tangxvhui authored
314
		"targetUserId":      param.TargetUserId,
tangxvhui authored
315 316 317 318 319 320 321 322 323 324 325 326 327 328 329 330 331 332 333 334 335 336 337
	})
	if err != nil {
		return nil, application.ThrowError(application.ARG_ERROR, "获取个人邀请列表"+err.Error())
	}
	if err := transactionContext.CommitTransaction(); err != nil {
		return nil, application.ThrowError(application.INTERNAL_SERVER_ERROR, err.Error())
	}

	result := adapter.AssessInviteUserResp{
		AssessTaskId:    assessTaskData.Id,
		InviteDiffSuper: []domain.StaffDesc{},
		InviteSameSuper: []domain.StaffDesc{},
	}
	for _, v := range assessTaskData.StepList {
		if v.LinkNodeType != domain.LinkNodeAllInvite {
			continue
		}
		result.LinkNodeId = v.LinkNodeId
		result.LinkNodeName = v.LinkNodeName
		result.BeginTime = v.BeginTime.Local().Format("2006-01-02 15:04:05")
		result.EndTime = v.EndTime.Local().Format("2006-01-02 15:04:05")
		break
	}
tangxvhui authored
338 339 340 341
	companyName := ""
	if companyInfo != nil {
		companyName = companyInfo.Name
	}
tangxvhui authored
342 343
	for _, v := range assessList {
		if v.Types == domain.AssessInviteDiffSuper {
tangxvhui authored
344
			v.Executor.CompanyName = companyName
tangxvhui authored
345 346 347
			result.InviteDiffSuper = append(result.InviteDiffSuper, v.Executor)
		}
		if v.Types == domain.AssessInviteSameSuper {
tangxvhui authored
348
			v.Executor.CompanyName = companyName
tangxvhui authored
349
			result.InviteSameSuper = append(result.InviteSameSuper, v.Executor)
tangxvhui authored
350 351 352 353 354 355
		}
	}
	return &result, nil
}

// 根据周期和日期获取我要执行的的360评估,用户列表和评估填写的值
tangxvhui authored
356
func (srv StaffAssessServeice) ListExecutorInviteAssessV2(param *query.ListExecutorAssessQuery) (
tangxvhui authored
357 358 359 360 361 362 363 364 365 366 367 368 369 370 371
	*adapter.ListInviteUserAssessResp, 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()
	}()
	//获取对应的评估任务
	assessRepo := factory.CreateStaffAssessRepository(map[string]interface{}{
		"transactionContext": transactionContext,
	})
tangxvhui authored
372 373 374 375 376 377
	companyRepo := factory.CreateCompanyRepository(map[string]interface{}{
		"transactionContext": transactionContext,
	})
	companyInfo, _ := companyRepo.FindOne(map[string]interface{}{
		"id": param.CompanyId,
	})
tangxvhui authored
378 379
	//获取 executorId 对应的360评估任务 用户
	condition := map[string]interface{}{
tangxvhui authored
380 381 382 383 384
		"beginDay":   param.BeginDay,
		"cycleId":    param.CycleId,
		"executorId": param.ExecutorId,
		"typesList":  []string{string(domain.AssessInviteDiffSuper), string(domain.AssessInviteSameSuper)},
		"limit":      20,
tangxvhui authored
385
	}
tangxvhui authored
386 387 388
	if len(param.UserName) > 0 {
		condition["targetUserName"] = param.UserName
	}
tangxvhui authored
389 390 391 392 393 394 395 396 397 398 399 400 401
	if param.PageSize > 0 {
		condition["limit"] = param.PageSize
	}
	offset := (param.PageNumber - 1) * param.PageSize
	if offset > 0 {
		condition["offset"] = offset
	}

	cnt, assessList, err := assessRepo.Find(condition)
	if err != nil {
		return nil, application.ThrowError(application.INTERNAL_SERVER_ERROR, err.Error())
	}
	var assessContentList []*domain.StaffAssessContent
tangxvhui authored
402 403 404 405 406 407 408
	projectIdMap := map[int]struct{}{}
	//获取评估用的所有评估项
	for i := range assessList {
		if _, ok := projectIdMap[assessList[i].EvaluationProjectId]; ok {
			continue
		}
		projectIdMap[assessList[i].EvaluationProjectId] = struct{}{}
409
		assessContentListTemp, err := srv.getAssessInfoUncompletedV2(transactionContext, assessList[i])
tangxvhui authored
410 411 412
		if err != nil {
			return nil, application.ThrowError(application.INTERNAL_SERVER_ERROR, "获取评估任务"+err.Error())
		}
tangxvhui authored
413
		assessContentList = append(assessContentList, assessContentListTemp...)
tangxvhui authored
414 415 416 417 418 419 420 421
	}
	//可变的表格列
	changeableHeader := []adapter.ListTableHeader{}
	//列名与字段对应
	keyMap := map[string]string{}
	for i, v := range assessContentList {
		name := fmt.Sprintf("%s-%s", v.Category, v.Name)
		key := fmt.Sprintf("k%d", i)
tangxvhui authored
422 423 424
		if _, ok := keyMap[name]; ok {
			continue
		}
tangxvhui authored
425 426 427 428 429 430 431 432 433 434 435 436 437 438 439 440 441 442 443 444 445 446 447 448 449 450 451 452 453 454 455
		keyMap[name] = key
		changeableHeader = append(changeableHeader, adapter.ListTableHeader{
			Key:  key,
			Name: name,
		})
	}
	assessContentRepo := factory.CreateStaffAssessContentRepository(map[string]interface{}{
		"transactionContext": transactionContext,
	})
	// 获取已经填报的内容
	changeableRows := map[int]map[string]string{}
	for _, v := range assessList {
		_, contentList, err := assessContentRepo.Find(map[string]interface{}{
			"staffAssessId": v.Id,
		})
		if err != nil {
			return nil, application.ThrowError(application.INTERNAL_SERVER_ERROR, "获取评估内容"+err.Error())
		}
		row := map[string]string{}
		for _, vv := range contentList {
			name := fmt.Sprintf("%s-%s", vv.Category, vv.Name)
			if kk, ok := keyMap[name]; ok {
				row[kk] = vv.Value
			}
		}
		changeableRows[v.TargetUser.UserId] = row
	}

	//获取360邀请评估完成情况
	//我评估别人,被邀请评估
	cnnt, _, err := assessRepo.Find(map[string]interface{}{
tangxvhui authored
456 457 458 459 460 461
		"beginDay":   param.BeginDay,
		"cycleId":    param.CycleId,
		"executorId": param.ExecutorId,
		"typesList":  []string{string(domain.AssessInviteDiffSuper), string(domain.AssessInviteSameSuper)},
		"status":     domain.StaffAssessUncompleted,
		"limit":      1,
tangxvhui authored
462 463 464 465 466 467 468 469 470 471 472 473 474 475 476 477 478
	})
	if err != nil {
		return nil, application.ThrowError(application.TRANSACTION_ERROR, "获取个人的评估环节"+err.Error())
	}

	if err := transactionContext.CommitTransaction(); err != nil {
		return nil, application.ThrowError(application.INTERNAL_SERVER_ERROR, err.Error())
	}

	//评估填写数据行转列
	tableHeader := []adapter.ListTableHeader{
		{Key: "userName", Name: "姓名"},
		{Key: "status", Name: "状态"},
		{Key: "types", Name: "360°评估关系"},
		{Key: "endTime", Name: "360°评估截止日期"},
	}
	tableHeader = append(tableHeader, changeableHeader...)
tangxvhui authored
479
	listData := []map[string]interface{}{}
tangxvhui authored
480 481 482 483
	companyName := ""
	if companyInfo != nil {
		companyName = companyInfo.Name
	}
tangxvhui authored
484
	for _, v := range assessList {
tangxvhui authored
485 486 487 488 489 490 491 492 493 494
		m := map[string]interface{}{
			"staffAssessTaskId": v.StaffAssessTaskId,
			"userName":          v.TargetUser.UserName,
			"userId":            strconv.Itoa(v.TargetUser.UserId),
			"status":            string(v.Status),
			"cycleId":           strconv.FormatInt(v.CycleId, 10),
			"beginDay":          v.BeginTime.Local().Format("2006-01-02"),
			"types":             string(v.Types),
			"endTime":           v.EndTime.Local().Format("2006-01-02 15:04:05"),
			"assessId":          strconv.Itoa(v.Id),
tangxvhui authored
495
			"companyName":       companyName,
tangxvhui authored
496 497 498 499 500 501 502 503 504 505 506 507 508 509 510 511 512 513 514 515 516 517 518 519 520 521 522 523 524
		}
		switch v.Status {
		case domain.StaffAssessCompleted:
			m["status"] = "已经完成"
		case domain.StaffAssessUncompleted:
			m["status"] = "未完成"
		}
		switch v.Types {
		case domain.AssessInviteDiffSuper:
			m["types"] = "不同上级同事"
		case domain.AssessInviteSameSuper:
			m["types"] = "相同上级同事"
		}
		if row, ok := changeableRows[v.TargetUser.UserId]; ok {
			for k, v := range row {
				m[k] = v
			}
		} else {
			for _, v := range changeableHeader {
				m[v.Key] = ""
			}
		}
		listData = append(listData, m)
	}
	result := adapter.ListInviteUserAssessResp{
		TableHeader: tableHeader,
		List:        listData,
		Total:       cnt,
	}
tangxvhui authored
525 526 527 528 529

	if len(assessList) > 0 {
		result.BeginDay = assessList[0].BeginTime.Local().Format("2006-01-02")
		result.CycleId = int(assessList[0].CycleId)
		result.LintNodeDesc = fmt.Sprintf("截止时间 %s 待评估%d人", assessList[0].EndTime.Local().Format("2006-01-02 15:04:05"), cnnt)
tangxvhui authored
530
	}
tangxvhui authored
531
tangxvhui authored
532 533
	return &result, nil
}
tangxvhui authored
534
tangxvhui authored
535
// 根据周期和日期获取我需要执行的上级评估成员列表
tangxvhui authored
536
func (srv StaffAssessServeice) ListExecutorSupperAssessV2(param *query.ListExecutorAssessQuery) (map[string]interface{}, error) {
tangxvhui authored
537 538 539 540 541 542 543 544 545 546 547 548 549 550
	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()
	}()
	//获取对应的评估任务
	assessRepo := factory.CreateStaffAssessRepository(map[string]interface{}{
		"transactionContext": transactionContext,
	})
551 552 553 554 555 556 557 558
	//公司存储
	companyRepo := factory.CreateCompanyRepository(map[string]interface{}{
		"transactionContext": transactionContext,
	})

	companyInfo, _ := companyRepo.FindOne(map[string]interface{}{
		"id": param.CompanyId,
	})
tangxvhui authored
559
tangxvhui authored
560 561 562 563 564 565 566 567 568 569 570 571 572 573 574 575 576 577 578 579 580 581 582
	limit := 20
	if param.PageSize > 0 {
		limit = param.PageSize
	}
	condition := map[string]interface{}{
		"beginDay":   param.BeginDay,
		"cycleId":    param.CycleId,
		"executorId": param.ExecutorId,
		"typesList":  []string{string(domain.AssessSuper)},
		"limit":      limit,
	}
	if len(param.UserName) > 0 {
		condition["targetUserName"] = param.UserName
	}
	offset := (param.PageNumber - 1) * param.PageSize
	if offset > 0 {
		condition["offset"] = offset
	}
	//获取 executorId 对应的上级评估列表
	cnt, assessList, err := assessRepo.Find(condition)
	if err != nil {
		return nil, application.ThrowError(application.INTERNAL_SERVER_ERROR, err.Error())
	}
583
tangxvhui authored
584
	//获取目标用户
tangxvhui authored
585 586 587 588 589 590 591 592 593 594 595 596 597 598 599 600 601 602 603 604 605 606 607 608 609 610 611 612 613
	userIds := []int{}
	for _, v := range assessList {
		userIds = append(userIds, v.TargetUser.UserId)
	}
	//获取员工信息
	userRepo := factory.CreateUserRepository(map[string]interface{}{
		"transactionContext": transactionContext,
	})
	var targetUserList []*domain.User
	if len(userIds) > 0 {
		_, targetUserList, _ = userRepo.Find(map[string]interface{}{
			"ids": userIds,
		})
	}
	//获取职位信息
	positionRepo := factory.CreatePositionRepository(map[string]interface{}{
		"transactionContext": transactionContext,
	})
	//获取员工的职位
	userPositionMap := map[int64][]*domain.Position{}
	for _, v := range targetUserList {
		if len(v.PositionId) == 0 {
			continue
		}
		_, positionList, _ := positionRepo.Find(map[string]interface{}{
			"ids": v.PositionId,
		})
		userPositionMap[v.Id] = positionList
	}
tangxvhui authored
614
	//获取目标员工邀请的人完成360评估的数量
tangxvhui authored
615
	var inviteCompletedCount []dao.CountData
tangxvhui authored
616
	d := dao.NewStaffAssessDao(map[string]interface{}{
tangxvhui authored
617 618
		"transactionContext": transactionContext,
	})
tangxvhui authored
619 620 621 622 623
	if len(userIds) > 0 {
		inviteCompletedCount, err = d.CountTargetUserInviteAssess1(userIds, param.CycleId, param.BeginDay)
		if err != nil {
			log.Logger.Error("获取员工邀请的人完成情况" + err.Error())
		}
tangxvhui authored
624
	}
tangxvhui authored
625
tangxvhui authored
626 627
	//我评估别人,被邀请评估
	cnnt, _, err := assessRepo.Find(map[string]interface{}{
tangxvhui authored
628 629
		"beginDay":   param.BeginDay,
		"cycleId":    param.CycleId,
tangxvhui authored
630 631 632
		"executorId": param.ExecutorId,
		"typesList":  []string{string(domain.AssessSuper)},
		"status":     string(domain.StaffAssessUncompleted),
tangxvhui authored
633
		"limit":      1,
tangxvhui authored
634 635 636 637
	})
	if err != nil {
		return nil, application.ThrowError(application.TRANSACTION_ERROR, "获取个人的评估环节"+err.Error())
	}
638 639 640 641 642 643 644
	var allAssessId []int
	for _, v := range assessList {
		allAssessId = append(allAssessId, v.Id)
	}

	assessValueMap := d.SearchContentValueByAssessId(allAssessId)
tangxvhui authored
645 646 647
	if err := transactionContext.CommitTransaction(); err != nil {
		return nil, application.ThrowError(application.INTERNAL_SERVER_ERROR, err.Error())
	}
648 649 650 651
	companyName := ""
	if companyInfo != nil {
		companyName = companyInfo.Name
	}
tangxvhui authored
652 653 654
	resultList := []adapter.ListSupperAssessResp{}
	for _, v := range assessList {
		item := adapter.ListSupperAssessResp{
tangxvhui authored
655 656 657 658 659 660 661 662 663 664 665 666
			StaffAssessTaskId: v.StaffAssessTaskId,
			AssessId:          v.Id,
			CycleId:           int(v.CycleId),
			BeginDay:          v.BeginTime.Local().Format("2006-01-02"),
			UserId:            v.TargetUser.UserId,
			UserName:          v.TargetUser.UserName,
			EndTime:           v.EndTime.Local().Format("2006-01-02 15:04:05"),
			InviteCompleted:   0,
			Status:            string(v.Status),
			InviteTotal:       5,
			Department:        "",
			Position:          "",
667
			CompanyName:       companyName,
tangxvhui authored
668
			DutyTime:          "",
669 670 671 672
			ContentValue:      []string{},
		}
		if values, ok := assessValueMap[v.Id]; ok {
			item.ContentValue = values
tangxvhui authored
673 674 675 676 677 678 679 680 681 682 683 684 685 686 687 688 689 690 691 692 693 694 695 696 697 698 699 700 701
		}
		//填入部门
		for _, vv := range v.TargetDepartment {
			item.Department += vv.DepartmentName + " "
		}
		for _, vv := range targetUserList {
			if vv.Id != int64(v.TargetUser.UserId) {
				continue
			}
			//填入入职时间
			item.DutyTime = vv.CreatedAt.Local().Format("2006-01-02 15:04:05")
			//填入职位
			for _, vvv := range userPositionMap[vv.Id] {
				item.Position += vvv.Name + " "
			}
			break
		}
		//
		for _, vv := range inviteCompletedCount {
			if v.TargetUser.UserId == vv.TargetUserId {
				item.InviteCompleted = vv.InviteCompleted
				item.InviteTotal = vv.InviteTotal
				break
			}
		}
		resultList = append(resultList, item)
	}
	result := tool_funs.SimpleWrapGridMap(int64(cnt), resultList)
	result["lintNodeDesc"] = ""
tangxvhui authored
702
	if len(assessList) > 0 {
tangxvhui authored
703 704
		result["cycleId"] = assessList[0].CycleId
		result["beginDay"] = assessList[0].BeginTime.Local().Format("2006-01-02")
tangxvhui authored
705
		result["lintNodeDesc"] = fmt.Sprintf("截止时间 %s 待评估 %d 人", assessList[0].EndTime.Local().Format("2006-01-02 15:04:05"), cnnt)
tangxvhui authored
706 707
	}
	return result, nil
tangxvhui authored
708
}
tangxvhui authored
709
tangxvhui authored
710
// 根据周期和日期,获取员工的自评内容
tangxvhui authored
711 712 713 714 715 716 717 718 719 720 721 722 723 724 725 726 727
func (srv StaffAssessServeice) GetAssessSelfInfoV2(param *query.GetExecutorSelfAssessQuery) (*adapter.AssessInfoResp, 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()
	}()
	assessReps := factory.CreateStaffAssessRepository(map[string]interface{}{
		"transactionContext": transactionContext,
	})
	// 获取员工的评估
	_, assessList, err := assessReps.Find(map[string]interface{}{
		"companyId":  param.CompanyId,
tangxvhui authored
728
		"executorId": param.TargetUserId,
tangxvhui authored
729 730 731 732 733 734 735 736 737
		"cycleId":    param.CycleId,
		"beginDay":   param.BeginDay,
		"typesList":  []string{string(domain.AssessSelf)},
		"limit":      1,
	})
	if err != nil {
		return nil, application.ThrowError(application.INTERNAL_SERVER_ERROR, "获取员工的评估"+err.Error())
	}
	if len(assessList) == 0 {
738
		return &adapter.AssessInfoResp{AssessId: -1}, nil
tangxvhui authored
739 740 741 742 743 744 745 746 747 748 749 750 751 752 753 754 755
	}
	assessData := assessList[0]

	assessContentList := []*domain.StaffAssessContent{}
	if assessData.Status == domain.StaffAssessCompleted {
		//已完成
		assessContentRepo := factory.CreateStaffAssessContentRepository(map[string]interface{}{
			"transactionContext": transactionContext,
		})
		_, assessContentList, err = assessContentRepo.Find(map[string]interface{}{
			"staffAssessId": assessData.Id,
		})
		if err != nil {
			return nil, application.ThrowError(application.INTERNAL_SERVER_ERROR, "获取项目填写内容"+err.Error())
		}
	} else if assessData.Status == domain.StaffAssessUncompleted {
		//未完成
756
		assessContentList, err = srv.getAssessInfoUncompletedV2(transactionContext, assessData)
tangxvhui authored
757 758 759 760 761
		if err != nil {
			return nil, application.ThrowError(application.INTERNAL_SERVER_ERROR, "获取项目填写内容"+err.Error())
		}
	}
762 763 764 765 766
	// 恢复缓存数据
	if param.AcquireCache != 0 {
		srv.recoverAssessCache(transactionContext, assessData.Id, assessContentList)
	}
tangxvhui authored
767
	//获取员工描述
tangxvhui authored
768
	staffDesc, _ := srv.getStaffDescrip(transactionContext, int64(param.TargetUserId))
tangxvhui authored
769 770 771 772 773 774 775 776 777 778 779 780 781 782 783 784 785 786
	if err := transactionContext.CommitTransaction(); err != nil {
		return nil, application.ThrowError(application.INTERNAL_SERVER_ERROR, err.Error())
	}
	result := adapter.AssessInfoResp{
		AssessId:              assessData.Id,
		CycleId:               assessData.CycleId,
		CycleName:             assessData.CycleName,
		LinkNodeId:            assessData.LinkNodeId,
		LinkNodeName:          assessData.LinkNodeName,
		EvaluationProjectId:   assessData.EvaluationProjectId,
		EvaluationProjectName: assessData.EvaluationProjectName,
		BeginTime:             assessData.BeginTime.Local().Format("2006-01-02 15:04:05"),
		EndTime:               assessData.EndTime.Local().Format("2006-01-02 15:04:05"),
		Status:                string(assessData.Status),
		TargetUserId:          assessData.TargetUser.UserId,
		TargetUserName:        assessData.TargetUser.UserName,
		CompanyId:             assessData.CompanyId,
		CompanyName:           "",
787
		CompanyLogo:           "",
tangxvhui authored
788 789 790 791 792 793
		SupperUser:            "",
		DutyTime:              "",
		AssessContent:         assessContentList,
	}
	if staffDesc != nil {
		result.CompanyName = staffDesc.CompanyName
794
		result.CompanyLogo = staffDesc.CompanyLogo
tangxvhui authored
795 796 797 798 799
		result.SupperUser = staffDesc.SupperUserName
		result.DutyTime = staffDesc.DutyTime
	}
	return &result, nil
}
tangxvhui authored
800
801
// 根据周期和日期。获取360评估的列表,员工的被其他人评估
tangxvhui authored
802
func (srv StaffAssessServeice) ListTargetUserInviteAssess(param *query.ListTargetAssessQuery) (map[string]interface{}, error) {
tangxvhui authored
803 804 805 806 807 808 809 810 811 812 813 814 815 816 817 818 819 820 821 822 823 824 825 826 827 828 829 830

	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()
	}()
	assessReps := factory.CreateStaffAssessRepository(map[string]interface{}{
		"transactionContext": transactionContext,
	})
	//获取员工的评估
	cnt, assessList, err := assessReps.Find(map[string]interface{}{
		"cycleId":      param.CycleId,
		"beginDay":     param.BeginDay,
		"companyId":    param.CompanyId,
		"targetUserId": param.TargetUserId,
		"typesList":    []string{string(domain.AssessInviteSameSuper), string(domain.AssessInviteDiffSuper)},
	})
	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())
	}
831
	resultList := []map[string]interface{}{}
tangxvhui authored
832 833 834 835 836 837 838 839 840
	for _, v := range assessList {
		item := map[string]interface{}{
			"id":         v.Id,
			"targetUser": v.TargetUser,
			"executor":   v.Executor,
		}
		resultList = append(resultList, item)
	}
	return tool_funs.SimpleWrapGridMap(int64(cnt), resultList), nil
tangxvhui authored
841
}
tangxvhui authored
842
843
// 根据周期和日期。获取上级评估的列表,员工的被其他人评估
tangxvhui authored
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
func (srv StaffAssessServeice) ListTargetUserSuperAssess(param *query.ListTargetAssessQuery) (map[string]interface{}, 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()
	}()
	assessReps := factory.CreateStaffAssessRepository(map[string]interface{}{
		"transactionContext": transactionContext,
	})
	//获取员工的评估
	cnt, assessList, err := assessReps.Find(map[string]interface{}{
		"cycleId":      param.CycleId,
		"beginDay":     param.BeginDay,
		"companyId":    param.CompanyId,
		"targetUserId": param.TargetUserId,
		"typesList":    []string{string(domain.AssessSuper)},
	})
	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())
	}
873
	resultList := []map[string]interface{}{}
tangxvhui authored
874 875 876 877 878 879 880 881 882 883
	for _, v := range assessList {
		item := map[string]interface{}{
			"id":         v.Id,
			"targetUser": v.TargetUser,
			"executor":   v.Executor,
		}
		resultList = append(resultList, item)
	}
	return tool_funs.SimpleWrapGridMap(int64(cnt), resultList), nil
}
884 885 886 887 888 889 890 891 892 893 894 895 896 897 898 899 900 901 902 903 904 905 906 907 908 909 910 911 912 913 914 915 916 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 952 953 954 955 956 957

// 选择员工评估可邀请的用户
func (srv StaffAssessServeice) SelectAssessInviteUserV2(param *query.SelectAssessInviteUser) (map[string]interface{}, 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()
	}()
	//获取被评估的目标用户
	userRepo := factory.CreateUserRepository(map[string]interface{}{
		"transactionContext": transactionContext,
	})
	//获取公司信息
	companyRepo := factory.CreateCompanyRepository(map[string]interface{}{
		"transactionContext": transactionContext,
	})
	companyInfo, _ := companyRepo.FindOne(map[string]interface{}{
		"id": param.CompanyId,
	})
	targetUser, err := userRepo.FindOne(map[string]interface{}{
		"id": param.TargetUserId,
	})
	if err != nil {
		return nil, application.ThrowError(application.INTERNAL_SERVER_ERROR, "获取员工信息"+err.Error())
	}

	//查询员工数据
	condition := map[string]interface{}{
		"companyId": param.CompanyId,
		"name":      param.InviteUserName,
		"limit":     20,
		"status":    1,
	}
	if param.PageSize > 0 {
		condition["limit"] = param.PageSize
	}
	offset := (param.PageNumber - 1) * param.PageSize
	if offset > 0 {
		condition["offset"] = offset
	}
	cnt, userList, err := userRepo.Find(condition)
	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 := []adapter.SelectInviteUser{}
	companyName := ""
	if companyInfo != nil {
		companyName = companyInfo.Name
	}
	for _, v := range userList {
		_ = v
		_ = companyName
		item := adapter.SelectInviteUser{
			UserId:      int(v.Id),
			UserName:    v.Name,
			CompanyName: companyName,
			IsSupper:    false,
			Types:       2, //默认是不同上级
		}
		if targetUser.ParentId == v.ParentId {
			item.Types = 1
		}
		listData = append(listData, item)
	}
	return tool_funs.SimpleWrapGridMap(int64(cnt), listData), nil
}
Your Name authored
958 959

// 获取未完成的员工评估内容
960 961 962 963 964 965 966 967 968 969 970 971 972 973 974 975 976 977 978 979 980 981 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 1010 1011 1012 1013 1014 1015 1016 1017 1018 1019
func (srv StaffAssessServeice) getAssessInfoUncompletedV2(transactionContext application.TransactionContext,
	assess *domain.StaffAssess) ([]*domain.StaffAssessContent, error) {
	evaluationItemRepo := factory.CreateEvaluationItemUsedRepository(map[string]interface{}{
		"transactionContext": transactionContext,
	})
	var evaluationItemList []*domain.EvaluationItemUsed
	var err error
	_, evaluationItemList, err = evaluationItemRepo.Find(map[string]interface{}{
		"evaluationProjectId": assess.EvaluationProjectId,
		"nodeId":              assess.LinkNodeId,
	})
	if err != nil {
		return nil, application.ThrowError(application.INTERNAL_SERVER_ERROR, "获取项目填写内容"+err.Error())
	}
	if len(evaluationItemList) == 0 {
		//如果当前节点没有评估内容,就去 使用自评节点的评估内容
		_, evaluationItemList, err = evaluationItemRepo.Find(map[string]interface{}{
			"evaluationProjectId": assess.EvaluationProjectId,
			"nodeType":            domain.LinkNodeSelfAssessment,
		})
		if err != nil {
			return nil, application.ThrowError(application.INTERNAL_SERVER_ERROR, "获取自评项目填写内容"+err.Error())
		}
	}
	var contentList []*domain.StaffAssessContent
	nowTime := time.Now()
	for i, v := range evaluationItemList {
		item := &domain.StaffAssessContent{
			Id:            0,
			StaffAssessId: assess.Id,
			SortBy:        i + 1,
			Category:      v.Category,
			Name:          v.Name,
			PromptTitle:   v.PromptTitle,
			PromptText:    v.PromptText,
			Remark:        nil,
			Value:         "",
			ReteResult:    "",
			CreatedAt:     nowTime,
			Weight:        v.Weight,
			Required:      v.Required,
			UpdatedAt:     nowTime,
			DeletedAt:     nil,
			Rule:          v.Rule,
		}
		var remarks []domain.AssessContemtRemark
		for _, vv := range v.EntryItems {
			ritem := domain.AssessContemtRemark{
				Title:      vv.Title,
				HintText:   vv.HintText,
				Definition: vv.Definition,
				RemarkText: "",
			}
			remarks = append(remarks, ritem)
		}
		item.Remark = remarks
		contentList = append(contentList, item)
	}
	return contentList, nil
}
tangxvhui authored
1020
tangxvhui authored
1021 1022 1023 1024 1025 1026 1027 1028 1029 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 1071 1072 1073 1074 1075 1076 1077 1078 1079 1080 1081 1082 1083 1084 1085 1086 1087 1088 1089 1090 1091 1092 1093 1094
// 展示360评估内容,未填写的评估项不展示
func (srv StaffAssessServeice) StaffAssess360Show(param *query.AssessInfoQuery) (*adapter.AssessInfoResp, 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()
	}()
	assessReps := factory.CreateStaffAssessRepository(map[string]interface{}{
		"transactionContext": transactionContext,
	})
	//获取员工的评估
	_, assessList, err := assessReps.Find(map[string]interface{}{
		"companyId": param.CompanyId,
		"id":        param.AssessId,
	})
	if err != nil {
		return nil, application.ThrowError(application.INTERNAL_SERVER_ERROR, "获取员工的评估"+err.Error())
	}
	if len(assessList) == 0 {
		return &adapter.AssessInfoResp{}, nil
	}
	if assessList[0].Types != domain.AssessInviteSameSuper &&
		assessList[0].Types != domain.AssessInviteDiffSuper {
		return &adapter.AssessInfoResp{}, nil
	}
	assessData := assessList[0]
	//已完成
	assessContentRepo := factory.CreateStaffAssessContentRepository(map[string]interface{}{
		"transactionContext": transactionContext,
	})
	_, assessContentList, err := assessContentRepo.Find(map[string]interface{}{
		"staffAssessId": assessData.Id,
	})
	if err != nil {
		return nil, application.ThrowError(application.INTERNAL_SERVER_ERROR, "获取项目填写内容"+err.Error())
	}
	targetUserDesc, err := srv.getStaffDescrip(transactionContext, int64(assessData.TargetUser.UserId))
	if err != nil {
		log.Logger.Error("获取员工描述" + err.Error())
	}
	if err := transactionContext.CommitTransaction(); err != nil {
		return nil, application.ThrowError(application.INTERNAL_SERVER_ERROR, err.Error())
	}
	result := adapter.AssessInfoResp{
		AssessId:              assessData.Id,
		CycleId:               assessData.CycleId,
		CycleName:             assessData.CycleName,
		LinkNodeId:            assessData.LinkNodeId,
		LinkNodeName:          assessData.LinkNodeName,
		EvaluationProjectId:   assessData.EvaluationProjectId,
		EvaluationProjectName: assessData.EvaluationProjectName,
		BeginTime:             assessData.BeginTime.Local().Format("2006-01-02 15:04:05"),
		EndTime:               assessData.EndTime.Local().Format("2006-01-02 15:04:05"),
		Status:                string(assessData.Status),
		TargetUserId:          assessData.TargetUser.UserId,
		TargetUserName:        assessData.TargetUser.UserName,
		CompanyId:             assessData.CompanyId,
		CompanyName:           "",
		SupperUser:            "",
		DutyTime:              "",
		AssessContent:         []*domain.StaffAssessContent{},
	}
	if targetUserDesc != nil {
		result.CompanyName = targetUserDesc.CompanyName
		result.SupperUser = targetUserDesc.SupperUserName
		result.CompanyLogo = targetUserDesc.CompanyLogo
		result.DutyTime = targetUserDesc.DutyTime
	}
tangxvhui authored
1095
tangxvhui authored
1096 1097 1098 1099 1100 1101 1102 1103 1104
	for _, val := range assessContentList {
		if len(val.Value) == 0 {
			//跳过不展示未填写的
			continue
		}
		result.AssessContent = append(result.AssessContent, val)
	}

	return &result, nil
tangxvhui authored
1105 1106
}
tangxvhui authored
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 1133 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 1161 1162 1163 1164 1165 1166 1167 1168 1169 1170 1171 1172 1173 1174 1175 1176 1177 1178 1179 1180 1181 1182 1183 1184 1185 1186 1187 1188
// 展示上级评估内容,未填写的评估项不展示
func (srv StaffAssessServeice) StaffAssessSuperShow(param *query.AssessInfoQuery) (*adapter.AssessInfoResp, 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()
	}()
	assessReps := factory.CreateStaffAssessRepository(map[string]interface{}{
		"transactionContext": transactionContext,
	})
	//获取员工的评估
	_, assessList, err := assessReps.Find(map[string]interface{}{
		"companyId": param.CompanyId,
		"id":        param.AssessId,
	})
	if err != nil {
		return nil, application.ThrowError(application.INTERNAL_SERVER_ERROR, "获取员工的评估"+err.Error())
	}
	if len(assessList) == 0 {
		return &adapter.AssessInfoResp{}, nil
	}
	if assessList[0].Types != domain.AssessSuper {
		return &adapter.AssessInfoResp{}, nil
	}
	assessData := assessList[0]
	//已完成
	assessContentRepo := factory.CreateStaffAssessContentRepository(map[string]interface{}{
		"transactionContext": transactionContext,
	})
	_, assessContentList, err := assessContentRepo.Find(map[string]interface{}{
		"staffAssessId": assessData.Id,
	})
	if err != nil {
		return nil, application.ThrowError(application.INTERNAL_SERVER_ERROR, "获取项目填写内容"+err.Error())
	}
	targetUserDesc, err := srv.getStaffDescrip(transactionContext, int64(assessData.TargetUser.UserId))
	if err != nil {
		log.Logger.Error("获取员工描述" + err.Error())
	}
	if err := transactionContext.CommitTransaction(); err != nil {
		return nil, application.ThrowError(application.INTERNAL_SERVER_ERROR, err.Error())
	}
	result := adapter.AssessInfoResp{
		AssessId:              assessData.Id,
		CycleId:               assessData.CycleId,
		CycleName:             assessData.CycleName,
		LinkNodeId:            assessData.LinkNodeId,
		LinkNodeName:          assessData.LinkNodeName,
		EvaluationProjectId:   assessData.EvaluationProjectId,
		EvaluationProjectName: assessData.EvaluationProjectName,
		BeginTime:             assessData.BeginTime.Local().Format("2006-01-02 15:04:05"),
		EndTime:               assessData.EndTime.Local().Format("2006-01-02 15:04:05"),
		Status:                string(assessData.Status),
		TargetUserId:          assessData.TargetUser.UserId,
		TargetUserName:        assessData.TargetUser.UserName,
		CompanyId:             assessData.CompanyId,
		CompanyName:           "",
		SupperUser:            "",
		DutyTime:              "",
		AssessContent:         []*domain.StaffAssessContent{},
	}
	if targetUserDesc != nil {
		result.CompanyName = targetUserDesc.CompanyName
		result.SupperUser = targetUserDesc.SupperUserName
		result.CompanyLogo = targetUserDesc.CompanyLogo
		result.DutyTime = targetUserDesc.DutyTime
	}

	for _, val := range assessContentList {
		if len(val.Value) == 0 {
			//跳过不展示未填写的
			continue
		}
		result.AssessContent = append(result.AssessContent, val)
	}

	return &result, nil
tangxvhui authored
1189 1190 1191
}

// 360评估内容编辑前
tangxvhui authored
1192 1193 1194 1195 1196 1197 1198
func (srv StaffAssessServeice) StaffAssess360BeforeEdit(param *query.AssessInfoQuery) (*adapter.AssessInfoResp, error) {
	result, err := srv.getStaffAssessBeforeEdit(param)
	if err != nil {
		return &adapter.AssessInfoResp{}, err
	}
	//360评估全部是选填项
	for i := range result.AssessContent {
tangxvhui authored
1199 1200 1201 1202 1203
		if len(result.AssessContent[i].Value) == 0 {
			result.AssessContent[i].LevelValue = ""
			result.AssessContent[i].ScoreValue = 0
			result.AssessContent[i].ReteResult = ""
		}
tangxvhui authored
1204 1205 1206
		result.AssessContent[i].Required = domain.NodeRequiredNo
	}
	return result, nil
tangxvhui authored
1207 1208 1209
}

// 上级评估内容编辑前
tangxvhui authored
1210 1211 1212 1213 1214 1215 1216
func (srv StaffAssessServeice) StaffAssessSuperBeforeEdit(param *query.AssessInfoQuery) (*adapter.AssessInfoResp, error) {
	result, err := srv.getStaffAssessBeforeEdit(param)
	if err != nil {
		return &adapter.AssessInfoResp{}, err
	}
	//上级评估全部是选填项
	for i := range result.AssessContent {
tangxvhui authored
1217 1218 1219 1220 1221
		if len(result.AssessContent[i].Value) == 0 {
			result.AssessContent[i].LevelValue = ""
			result.AssessContent[i].ScoreValue = 0
			result.AssessContent[i].ReteResult = ""
		}
tangxvhui authored
1222 1223 1224
		result.AssessContent[i].Required = domain.NodeRequiredNo
	}
	return result, nil
tangxvhui authored
1225 1226
}
tangxvhui authored
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
func (srv StaffAssessServeice) getStaffAssessBeforeEdit(param *query.AssessInfoQuery) (*adapter.AssessInfoResp, 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()
	}()
	assessReps := factory.CreateStaffAssessRepository(map[string]interface{}{
		"transactionContext": transactionContext,
	})
	//获取员工的评估
	_, assessList, err := assessReps.Find(map[string]interface{}{
		"companyId": param.CompanyId,
		"id":        param.AssessId,
	})
	if err != nil {
		return nil, application.ThrowError(application.INTERNAL_SERVER_ERROR, "获取员工的评估"+err.Error())
	}
	if len(assessList) == 0 {
		return &adapter.AssessInfoResp{}, nil
	}
	assessData := assessList[0]
tangxvhui authored
1253 1254 1255 1256 1257 1258 1259 1260 1261 1262 1263 1264
	var assessContentList []*domain.StaffAssessContent
	//已完成
	assessContentRepo := factory.CreateStaffAssessContentRepository(map[string]interface{}{
		"transactionContext": transactionContext,
	})
	_, assessContentList, err = assessContentRepo.Find(map[string]interface{}{
		"staffAssessId": assessData.Id,
	})
	if err != nil {
		return nil, application.ThrowError(application.INTERNAL_SERVER_ERROR, "获取项目填写内容"+err.Error())
	}
	if len(assessContentList) == 0 {
tangxvhui authored
1265 1266 1267 1268 1269
		//未完成
		assessContentList, err = srv.getAssessInfoUncompletedV2(transactionContext, assessData)
		if err != nil {
			return nil, application.ThrowError(application.INTERNAL_SERVER_ERROR, "获取项目填写内容"+err.Error())
		}
tangxvhui authored
1270
tangxvhui authored
1271 1272 1273 1274 1275 1276 1277 1278 1279 1280 1281 1282 1283 1284 1285 1286 1287 1288 1289 1290 1291 1292 1293 1294 1295 1296 1297 1298 1299 1300 1301 1302 1303 1304 1305 1306 1307 1308 1309 1310
	}
	// 恢复缓存数据
	srv.recoverAssessCache(transactionContext, assessData.Id, assessContentList)
	targetUserDesc, err := srv.getStaffDescrip(transactionContext, int64(assessData.TargetUser.UserId))
	if err != nil {
		log.Logger.Error("获取员工描述" + err.Error())
	}
	if err := transactionContext.CommitTransaction(); err != nil {
		return nil, application.ThrowError(application.INTERNAL_SERVER_ERROR, err.Error())
	}

	result := adapter.AssessInfoResp{
		AssessId:              assessData.Id,
		CycleId:               assessData.CycleId,
		CycleName:             assessData.CycleName,
		LinkNodeId:            assessData.LinkNodeId,
		LinkNodeName:          assessData.LinkNodeName,
		EvaluationProjectId:   assessData.EvaluationProjectId,
		EvaluationProjectName: assessData.EvaluationProjectName,
		BeginTime:             assessData.BeginTime.Local().Format("2006-01-02 15:04:05"),
		EndTime:               assessData.EndTime.Local().Format("2006-01-02 15:04:05"),
		Status:                string(assessData.Status),
		TargetUserId:          assessData.TargetUser.UserId,
		TargetUserName:        assessData.TargetUser.UserName,
		CompanyId:             assessData.CompanyId,
		CompanyName:           "",
		SupperUser:            "",
		DutyTime:              "",
		AssessContent:         assessContentList,
	}
	if len(assessContentList) == 0 {
		result.AssessContent = []*domain.StaffAssessContent{}
	}
	if targetUserDesc != nil {
		result.CompanyName = targetUserDesc.CompanyName
		result.SupperUser = targetUserDesc.SupperUserName
		result.CompanyLogo = targetUserDesc.CompanyLogo
		result.DutyTime = targetUserDesc.DutyTime
	}
	return &result, nil
tangxvhui authored
1311 1312 1313
}

// 获取未完成评估任务的执行人员名单
tangxvhui authored
1314 1315 1316 1317 1318 1319 1320 1321 1322 1323 1324
func (srv StaffAssessServeice) ListExcutorUncompleted(param *query.ListExecutorQuery) (map[string]interface{}, 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()
	}()
1325 1326 1327 1328 1329 1330 1331 1332 1333 1334 1335 1336 1337 1338 1339 1340 1341 1342 1343 1344 1345 1346 1347 1348 1349 1350 1351 1352 1353

	if param.Types == "invite" {
		staffAssessDao := dao.NewStaffAssessDao(map[string]interface{}{
			"transactionContext": transactionContext,
		})
		targetUserList, err := staffAssessDao.ListTargetUserNoInvite(param.CompanyId, param.CycleId, param.BeginDay)
		if err != nil {
			return nil, application.ThrowError(application.INTERNAL_SERVER_ERROR, "获取员工列表"+err.Error())
		}
		userList := []map[string]string{}
		userMap := map[string]struct{}{} //过滤重复的用户id
		for _, val := range targetUserList {
			if _, ok := userMap[val.UserId]; ok {
				continue
			} else {
				userMap[val.UserId] = struct{}{}
			}
			u := map[string]string{
				"userId":   val.UserId,
				"userName": val.UserName,
			}
			userList = append(userList, u)
		}
		result := map[string]interface{}{
			"userList": userList,
		}
		return result, nil
	}
tangxvhui authored
1354 1355 1356 1357 1358 1359 1360 1361 1362 1363 1364 1365 1366 1367 1368
	assessReps := factory.CreateStaffAssessRepository(map[string]interface{}{
		"transactionContext": transactionContext,
	})
	condition := map[string]interface{}{
		"cycleId":   param.CycleId,
		"beginDay":  param.BeginDay,
		"companyId": param.CompanyId,
		"status":    string(domain.StaffAssessUncompleted),
		"typesList": []string{""},
	}
	switch param.Types {
	case "self":
		condition["typesList"] = []string{string(domain.AssessSelf)}
	case "super":
		condition["typesList"] = []string{string(domain.AssessSuper)}
tangxvhui authored
1369
	case "360":
tangxvhui authored
1370 1371 1372 1373
		condition["typesList"] = []string{string(domain.AssessInviteDiffSuper), string(domain.AssessInviteSameSuper)}
	}
	_, assessList, err := assessReps.Find(condition)
	if err != nil {
1374
		return nil, application.ThrowError(application.INTERNAL_SERVER_ERROR, "获取员工列表"+err.Error())
tangxvhui authored
1375 1376 1377 1378 1379 1380 1381 1382 1383 1384 1385 1386 1387 1388 1389 1390 1391 1392 1393 1394 1395 1396
	}
	if err := transactionContext.CommitTransaction(); err != nil {
		return nil, application.ThrowError(application.INTERNAL_SERVER_ERROR, err.Error())
	}
	userList := []map[string]string{}
	userMap := map[int]struct{}{} //过滤重复的用户id
	for _, val := range assessList {
		if _, ok := userMap[val.TargetUser.UserId]; ok {
			continue
		} else {
			userMap[val.TargetUser.UserId] = struct{}{}
		}
		u := map[string]string{
			"userId":   strconv.Itoa(val.TargetUser.UserId),
			"userName": val.TargetUser.UserName,
		}
		userList = append(userList, u)
	}
	result := map[string]interface{}{
		"userList": userList,
	}
	return result, nil
tangxvhui authored
1397
}