...
|
...
|
@@ -2,6 +2,7 @@ package service |
|
|
|
|
|
import (
|
|
|
"fmt"
|
|
|
"sort"
|
|
|
"strconv"
|
|
|
"time"
|
|
|
|
...
|
...
|
@@ -118,6 +119,7 @@ func (srv StaffAssessServeice) AssessTaskDesc(param *query.AssessTaskDescQuery) |
|
|
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,
|
...
|
...
|
@@ -206,7 +208,10 @@ func (srv StaffAssessServeice) AssessTaskDesc(param *query.AssessTaskDescQuery) |
|
|
}
|
|
|
}
|
|
|
}
|
|
|
result.StepList = append(result.StepList, stepItem)
|
|
|
//未参与的,不算在个人的评估环节里
|
|
|
if stepItem.Status != "" {
|
|
|
result.StepList = append(result.StepList, stepItem)
|
|
|
}
|
|
|
}
|
|
|
if err := transactionContext.CommitTransaction(); err != nil {
|
|
|
return nil, application.ThrowError(application.INTERNAL_SERVER_ERROR, err.Error())
|
...
|
...
|
@@ -230,7 +235,7 @@ func (srv StaffAssessServeice) AssessSelfList(param *query.AssessSelfListQuery) |
|
|
staffAssessRepo := factory.CreateStaffAssessRepository(map[string]interface{}{
|
|
|
"transactionContext": transactionContext,
|
|
|
})
|
|
|
var limit int = 20
|
|
|
var limit int = 100
|
|
|
var offset int = 0
|
|
|
if param.PageSize > 0 {
|
|
|
limit = param.PageSize
|
...
|
...
|
@@ -241,8 +246,9 @@ func (srv StaffAssessServeice) AssessSelfList(param *query.AssessSelfListQuery) |
|
|
"companyId": param.CompanyId,
|
|
|
"typesList": []string{string(domain.AssessSelf)},
|
|
|
"limit": limit,
|
|
|
"status": string(domain.StaffAssessCompleted),
|
|
|
"endTime": time.Now(), //获取历史记录
|
|
|
}
|
|
|
// "status": string(domain.StaffAssessCompleted),
|
|
|
if offset > 0 {
|
|
|
condition["offset"] = offset
|
|
|
}
|
...
|
...
|
@@ -333,16 +339,6 @@ func (srv StaffAssessServeice) AssessSelfList(param *query.AssessSelfListQuery) |
|
|
|
|
|
// 根据项目评估的配置,创建员工的评估任务
|
|
|
func (srv StaffAssessServeice) CreateStaffAssessTask(transactionContext application.TransactionContext, param *command.CreateStaffAssessTask) (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()
|
|
|
// }()
|
|
|
log.Logger.Debug("CreateStaffAssessTask 获取参数", map[string]interface{}{
|
|
|
"param": param,
|
|
|
})
|
...
|
...
|
@@ -358,30 +354,64 @@ func (srv StaffAssessServeice) CreateStaffAssessTask(transactionContext applicat |
|
|
return nil, application.ThrowError(application.ARG_ERROR, "任务结束时间填写错误,"+param.EndTime)
|
|
|
}
|
|
|
nowTime := time.Now()
|
|
|
//建立评估任务
|
|
|
assessTaskData := &domain.StaffAssessTask{
|
|
|
Id: 0,
|
|
|
CompanyId: param.CompanyId,
|
|
|
EvaluationProjectId: param.EvaluationProjectId,
|
|
|
EvaluationProjectName: param.EvaluationProjectName,
|
|
|
CycleId: param.CycleId,
|
|
|
CycleName: param.CycleName,
|
|
|
BeginTime: taskBeginTime,
|
|
|
EndTime: taskEndTime,
|
|
|
StepList: []domain.AssessTaskStep{},
|
|
|
ExecutorId: nil,
|
|
|
CreatedAt: nowTime,
|
|
|
UpdatedAt: nowTime,
|
|
|
DeletedAt: nil,
|
|
|
BeginDay: taskBeginTime.Local().Format("2006-01-02"),
|
|
|
}
|
|
|
// }
|
|
|
|
|
|
//填充评估环节
|
|
|
_, assassessTaskList, err := assessTaskRepo.Find(map[string]interface{}{
|
|
|
"evaluationProjectId": param.EvaluationProjectId,
|
|
|
"beginDay": taskBeginTime.Local().Format("2006-01-02"),
|
|
|
})
|
|
|
if err != nil {
|
|
|
return nil, application.ThrowError(application.INTERNAL_SERVER_ERROR, "查询同日期同项目已存在的评估任务"+err.Error())
|
|
|
}
|
|
|
var assessTaskData *domain.StaffAssessTask
|
|
|
//更新旧数据或者新建数据
|
|
|
if len(assassessTaskList) > 0 {
|
|
|
assessTaskData = assassessTaskList[0]
|
|
|
assessTaskData.UpdatedAt = nowTime
|
|
|
} else {
|
|
|
//建立新的评估任务
|
|
|
assessTaskData = &domain.StaffAssessTask{
|
|
|
Id: 0,
|
|
|
CompanyId: param.CompanyId,
|
|
|
EvaluationProjectId: param.EvaluationProjectId,
|
|
|
EvaluationProjectName: param.EvaluationProjectName,
|
|
|
CycleId: param.CycleId,
|
|
|
CycleName: param.CycleName,
|
|
|
BeginTime: taskBeginTime,
|
|
|
EndTime: taskEndTime,
|
|
|
StepList: []domain.AssessTaskStep{},
|
|
|
ExecutorId: []int{},
|
|
|
CreatedAt: nowTime,
|
|
|
UpdatedAt: nowTime,
|
|
|
DeletedAt: nil,
|
|
|
BeginDay: taskBeginTime.Local().Format("2006-01-02"),
|
|
|
}
|
|
|
}
|
|
|
executorIds := []int{} //提取评估的参与人id
|
|
|
executorIdMap := map[int]struct{}{} //过滤重复的用户
|
|
|
//从入参中提取参与人
|
|
|
for _, v := range param.ExecutorId {
|
|
|
if _, ok := executorIdMap[v]; ok {
|
|
|
continue
|
|
|
}
|
|
|
executorIdMap[v] = struct{}{}
|
|
|
executorIds = append(executorIds, v)
|
|
|
}
|
|
|
//就数据中提取参与人
|
|
|
for _, v := range assessTaskData.ExecutorId {
|
|
|
if _, ok := executorIdMap[v]; ok {
|
|
|
continue
|
|
|
}
|
|
|
executorIdMap[v] = struct{}{}
|
|
|
executorIds = append(executorIds, v)
|
|
|
}
|
|
|
//填入新的参与人id
|
|
|
assessTaskData.ExecutorId = executorIds
|
|
|
//填充新的评估环节
|
|
|
loop:
|
|
|
for _, v := range param.StepList {
|
|
|
for _, vv := range assessTaskData.StepList {
|
|
|
if vv.LinkNodeType == v.LinkNodeType {
|
|
|
continue
|
|
|
if vv.LinkNodeId == v.LinkNodeId {
|
|
|
continue loop
|
|
|
}
|
|
|
}
|
|
|
stepBeginTime, err := time.ParseInLocation("2006-01-02 15:04:05", param.BeginTime, time.Local)
|
...
|
...
|
@@ -402,44 +432,15 @@ func (srv StaffAssessServeice) CreateStaffAssessTask(transactionContext applicat |
|
|
}
|
|
|
assessTaskData.StepList = append(assessTaskData.StepList, step)
|
|
|
}
|
|
|
//评估的参与人
|
|
|
executorIds := []int{}
|
|
|
executorIdMap := map[int]struct{}{} //过滤重复的用户
|
|
|
for _, v := range param.ExecutorId {
|
|
|
if _, ok := executorIdMap[v]; ok {
|
|
|
continue
|
|
|
}
|
|
|
executorIdMap[v] = struct{}{}
|
|
|
executorIds = append(executorIds, v)
|
|
|
}
|
|
|
assessTaskData.ExecutorId = executorIds
|
|
|
//排序流程环节
|
|
|
stepList := domain.SortTaskStep(assessTaskData.StepList)
|
|
|
sort.Sort(stepList)
|
|
|
assessTaskData.StepList = stepList
|
|
|
//添加员工的节点任务
|
|
|
assessList, err := srv.createStaffAssess(transactionContext, assessTaskData)
|
|
|
if err != nil {
|
|
|
return nil, application.ThrowError(application.INTERNAL_SERVER_ERROR, "生成个人评估项"+err.Error())
|
|
|
}
|
|
|
// var assessTaskData *domain.StaffAssessTask
|
|
|
_, assassessTaskList, err := assessTaskRepo.Find(map[string]interface{}{
|
|
|
"evaluationProjectId": param.EvaluationProjectId,
|
|
|
"beginDay": taskBeginTime.Local().Format("2006-01-02"),
|
|
|
})
|
|
|
if err != nil {
|
|
|
return nil, application.ThrowError(application.INTERNAL_SERVER_ERROR, "查询同日期已存在评估任务"+err.Error())
|
|
|
}
|
|
|
|
|
|
if len(assassessTaskList) > 0 {
|
|
|
//过滤就数据
|
|
|
assessTaskData.Id = assassessTaskList[0].Id
|
|
|
for _, v := range assassessTaskList[0].ExecutorId {
|
|
|
if _, ok := executorIdMap[v]; ok {
|
|
|
continue
|
|
|
}
|
|
|
executorIdMap[v] = struct{}{}
|
|
|
executorIds = append(executorIds, v)
|
|
|
}
|
|
|
assessTaskData.ExecutorId = executorIds
|
|
|
assessTaskData.StepList = append(assassessTaskList[0].StepList, assessTaskData.StepList...)
|
|
|
|
|
|
}
|
|
|
_, err = assessTaskRepo.Save(assessTaskData)
|
|
|
if err != nil {
|
|
|
return nil, application.ThrowError(application.INTERNAL_SERVER_ERROR, "保存评估任务"+err.Error())
|
...
|
...
|
@@ -455,10 +456,6 @@ func (srv StaffAssessServeice) CreateStaffAssessTask(transactionContext applicat |
|
|
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())
|
|
|
// }
|
|
|
return map[string]interface{}{
|
|
|
"assessTaskId": assessTaskData.Id,
|
|
|
}, nil
|
...
|
...
|
@@ -564,7 +561,6 @@ func (srv StaffAssessServeice) createStaffAssessSelf(assessTemp domain.StaffAsse |
|
|
userList []*domain.User, userDepartmentMap map[int64][]*domain.Department) []domain.StaffAssess {
|
|
|
result := []domain.StaffAssess{}
|
|
|
for _, usr := range userList {
|
|
|
|
|
|
assessTemp.TargetUser = domain.StaffDesc{
|
|
|
UserId: int(usr.Id),
|
|
|
Account: usr.Account,
|
...
|
...
|
@@ -588,7 +584,7 @@ func (srv StaffAssessServeice) createStaffAssessSelf(assessTemp domain.StaffAsse |
|
|
return result
|
|
|
}
|
|
|
|
|
|
// 构建员工上级评估
|
|
|
// 构建员工的上级评估
|
|
|
func (srv StaffAssessServeice) createStaffAssessSupper(
|
|
|
transactionContext application.TransactionContext,
|
|
|
assessTemp domain.StaffAssess,
|
...
|
...
|
@@ -608,6 +604,7 @@ func (srv StaffAssessServeice) createStaffAssessSupper( |
|
|
if len(vv2.ChargeUserIds) == 0 {
|
|
|
continue
|
|
|
}
|
|
|
//获取部门的主管
|
|
|
_, chargeUserList, err := userRepo.Find(map[string]interface{}{
|
|
|
"ids": vv2.ChargeUserIds,
|
|
|
"limit": 40,
|
...
|
...
|
@@ -728,7 +725,6 @@ func (srv StaffAssessServeice) SaveAssessInviteUser(param *command.SaveAssessInv |
|
|
defer func() {
|
|
|
_ = transactionContext.RollbackTransaction()
|
|
|
}()
|
|
|
|
|
|
assessReps := factory.CreateStaffAssessRepository(map[string]interface{}{
|
|
|
"transactionContext": transactionContext,
|
|
|
})
|
...
|
...
|
@@ -761,6 +757,12 @@ func (srv StaffAssessServeice) SaveAssessInviteUser(param *command.SaveAssessInv |
|
|
if inviteNode == nil {
|
|
|
return nil, application.ThrowError(application.ARG_ERROR, "评估任务没有邀请评估的环节")
|
|
|
}
|
|
|
//检查节点的结束时间
|
|
|
endTimeInt := inviteNode.EndTime.Unix()
|
|
|
if endTimeInt < time.Now().Unix() {
|
|
|
e := fmt.Sprintf("该环节已在%s截止", inviteNode.EndTime.Local().Format("2006-01-02 15:04:05"))
|
|
|
return nil, application.ThrowError(application.BUSINESS_ERROR, e)
|
|
|
}
|
|
|
|
|
|
targetUser, err := userRepo.FindOne(map[string]interface{}{
|
|
|
"id": param.TargetUserId,
|
...
|
...
|
@@ -1651,6 +1653,13 @@ func (srv StaffAssessServeice) SaveAssessInfo(param *command.SaveAssessInfoComma |
|
|
if err != nil {
|
|
|
return nil, application.ThrowError(application.INTERNAL_SERVER_ERROR, "获取员工的评估"+err.Error())
|
|
|
}
|
|
|
|
|
|
//检查截止时间
|
|
|
endTimeInt := assessData.EndTime.Unix()
|
|
|
if endTimeInt < time.Now().Unix() {
|
|
|
return nil, application.ThrowError(application.BUSINESS_ERROR, "当前环节已过截止时间,提交后无法修改内容")
|
|
|
}
|
|
|
|
|
|
assessContentRepo := factory.CreateStaffAssessContentRepository(map[string]interface{}{
|
|
|
"transactionContext": transactionContext,
|
|
|
})
|
...
|
...
|
@@ -1658,7 +1667,6 @@ func (srv StaffAssessServeice) SaveAssessInfo(param *command.SaveAssessInfoComma |
|
|
assessContentList := []*domain.StaffAssessContent{}
|
|
|
if assessData.Status == domain.StaffAssessCompleted {
|
|
|
//已完成
|
|
|
|
|
|
_, assessContentList, err = assessContentRepo.Find(map[string]interface{}{
|
|
|
"staffAssessId": assessData.Id,
|
|
|
})
|
...
|
...
|
|