作者 tangxvhui

暂存

... ... @@ -2,6 +2,10 @@ package service
import (
"fmt"
"strconv"
"strings"
"time"
"github.com/linmadan/egglib-go/core/application"
"github.com/linmadan/egglib-go/utils/tool_funs"
"gitlab.fjmaimaimai.com/allied-creation/performance/pkg/application/evaluation_project/adapter"
... ... @@ -11,9 +15,6 @@ import (
taskService "gitlab.fjmaimaimai.com/allied-creation/performance/pkg/application/task/service"
"gitlab.fjmaimaimai.com/allied-creation/performance/pkg/domain"
"gitlab.fjmaimaimai.com/allied-creation/performance/pkg/utils"
"strconv"
"strings"
"time"
)
type EvaluationProjectService struct {
... ... @@ -870,7 +871,6 @@ func (rs *EvaluationProjectService) CheckRecipients(in *command.CheckRecipientCo
}
func (rs *EvaluationProjectService) generateEvaluationItemUsed(transactionContext application.TransactionContext, project *domain.EvaluationProject) error {
var itemUsedList []*domain.EvaluationItemUsed
nowTime := time.Now()
for _, v := range project.Template.LinkNodes {
... ... @@ -948,3 +948,8 @@ outerLoop:
return map[string]interface{}{"indicatorTypeTask": indicatorTypeTask}, nil
}
// 生成指标任务
func (rs *EvaluationProjectService) generateEvaluationTask() error {
return nil
}
... ...
... ... @@ -8,6 +8,7 @@ import (
"github.com/linmadan/egglib-go/core/application"
"gitlab.fjmaimaimai.com/allied-creation/performance/pkg/application/factory"
"gitlab.fjmaimaimai.com/allied-creation/performance/pkg/application/notify/adapter"
"gitlab.fjmaimaimai.com/allied-creation/performance/pkg/application/notify/command"
"gitlab.fjmaimaimai.com/allied-creation/performance/pkg/domain"
)
... ... @@ -106,12 +107,89 @@ func (srv *MessagePersonalService) TodayMessageSummaryEvaluationSelf(param *comm
// 获取关于任务里程碑异常的消息
// 每日一次
func (srv *MessagePersonalService) TodayMessageTaskStageAnomaly(param *command.GetUserMessageCommand) (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()
}()
messageRepo := factory.CreateMessagePersonalRepository(map[string]interface{}{
"transactionContext": transactionContext,
})
cnt, _, err := messageRepo.Find(map[string]interface{}{
"types": domain.MessageTypesTaskStage,
"targetUserId": param.UserId,
"limit": 1,
})
if err != nil {
return nil, application.ThrowError(application.INTERNAL_SERVER_ERROR, "检查任务里程碑异常的消息"+err.Error())
}
if cnt > 0 {
resp := map[string]interface{}{
"needNotify": false,
"list": []adapter.MessageListAdapter{},
}
return resp, nil
}
return nil, nil
// TDOD
if err := transactionContext.CommitTransaction(); err != nil {
return nil, application.ThrowError(application.INTERNAL_SERVER_ERROR, err.Error())
}
resp := map[string]interface{}{
"needNotify": false,
"list": []adapter.MessageListAdapter{},
}
return resp, nil
}
// 获取关于任务反馈碑异常的消息
// 每日一次
func (srv *MessagePersonalService) TodayMessageTaskRecordAnomaly(param *command.GetUserMessageCommand) (map[string]interface{}, error) {
return nil, nil
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()
}()
messageRepo := factory.CreateMessagePersonalRepository(map[string]interface{}{
"transactionContext": transactionContext,
})
cnt, _, err := messageRepo.Find(map[string]interface{}{
"types": domain.MessageTypesTaskStage,
"targetUserId": param.UserId,
"limit": 1,
})
if err != nil {
return nil, application.ThrowError(application.INTERNAL_SERVER_ERROR, "检查任务里程碑异常的消息"+err.Error())
}
if cnt > 0 {
resp := map[string]interface{}{
"needNotify": false,
"list": []adapter.MessageListAdapter{},
}
return resp, nil
}
// TODO
if err := transactionContext.CommitTransaction(); err != nil {
return nil, application.ThrowError(application.INTERNAL_SERVER_ERROR, err.Error())
}
resp := map[string]interface{}{
"needNotify": false,
"list": []adapter.MessageListAdapter{},
}
return resp, nil
}
... ...
package service
import (
"sort"
"strconv"
"time"
"github.com/linmadan/egglib-go/core/application"
"gitlab.fjmaimaimai.com/allied-creation/performance/pkg/application/factory"
"gitlab.fjmaimaimai.com/allied-creation/performance/pkg/application/notify"
"gitlab.fjmaimaimai.com/allied-creation/performance/pkg/application/staff_assess/command"
"gitlab.fjmaimaimai.com/allied-creation/performance/pkg/domain"
"gitlab.fjmaimaimai.com/allied-creation/performance/pkg/log"
)
// 定时调用 ,按时下发员工的需要填写的评估
// 根据项目评估的配置,创建员工的评估任务
func (srv StaffAssessServeice) CreateStaffAssessTask(transactionContext application.TransactionContext, param *command.CreateStaffAssessTask) (map[string]interface{}, error) {
log.Logger.Debug("CreateStaffAssessTask 获取参数", map[string]interface{}{
"param": param,
})
assessTaskRepo := factory.CreateStaffAssessTaskRepository(map[string]interface{}{
"transactionContext": transactionContext,
})
taskBeginTime, err := time.ParseInLocation("2006-01-02 15:04:05", param.BeginTime, time.Local)
if err != nil {
return nil, application.ThrowError(application.ARG_ERROR, "任务开始时间填写错误,"+param.BeginTime)
}
taskEndTime, err := time.ParseInLocation("2006-01-02 15:04:05", param.EndTime, time.Local)
if err != nil {
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: []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)
}
assessTaskData.ExecutorId = executorIds
for _, v := range param.StepList {
stepBeginTime, err := time.ParseInLocation("2006-01-02 15:04:05", param.BeginTime, time.Local)
if err != nil {
return nil, application.ThrowError(application.ARG_ERROR, "评估环节开始时间填写错误,"+param.BeginTime)
}
stepEndTime, err := time.ParseInLocation("2006-01-02 15:04:05", param.EndTime, time.Local)
if err != nil {
return nil, application.ThrowError(application.ARG_ERROR, "评估环节结束时间填写错误,"+param.EndTime)
}
step := domain.AssessTaskStep{
SortBy: v.SortBy,
LinkNodeId: v.LinkNodeId,
LinkNodeName: v.LinkNodeName,
LinkNodeType: v.LinkNodeType,
BeginTime: stepBeginTime,
EndTime: stepEndTime,
}
assessTaskData.StepList = append(assessTaskData.StepList, step)
}
//添加员工的节点任务
assessList, err := srv.buildStaffAssess(transactionContext, assessTaskData)
if err != nil {
return nil, application.ThrowError(application.INTERNAL_SERVER_ERROR, "生成个人评估项"+err.Error())
}
//合并项目评估的新旧数据
_, 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 {
//旧数据中提取参与人
for _, v := range assassessTaskList[0].ExecutorId {
if _, ok := executorIdMap[v]; ok {
continue
}
executorIdMap[v] = struct{}{}
executorIds = append(executorIds, v)
}
assassessTaskList[0].UpdatedAt = time.Now()
assassessTaskList[0].ExecutorId = executorIds
//更新步骤
assassessTaskList[0].StepList = append(assassessTaskList[0].StepList, assessTaskData.StepList...)
for _, val := range assessTaskData.StepList {
hasFound := false
for _, val2 := range assassessTaskList[0].StepList {
if val.LinkNodeType == val2.LinkNodeType {
hasFound = true
break
}
}
if !hasFound {
assassessTaskList[0].StepList = append(assassessTaskList[0].StepList, val)
}
}
assessTaskData = assassessTaskList[0]
//排序流程环节
}
stepList := domain.SortTaskStep(assessTaskData.StepList)
sort.Sort(stepList)
_, err = assessTaskRepo.Save(assessTaskData)
if err != nil {
return nil, application.ThrowError(application.INTERNAL_SERVER_ERROR, "保存评估任务"+err.Error())
}
//保存 员工的需要填写的每日评估
assessRepo := factory.CreateStaffAssessRepository(map[string]interface{}{
"transactionContext": transactionContext,
})
for i := range assessList {
assessList[i].StaffAssessTaskId = assessTaskData.Id
_, err = assessRepo.Save(&assessList[i])
if err != nil {
return nil, application.ThrowError(application.INTERNAL_SERVER_ERROR, "保存个人评估项"+err.Error())
}
if assessList[i].Types == domain.AssessSelf {
//添加待发送的短信通知
notify.AddNotifyStaffAssess(&assessList[i])
//添加 指标任务
}
}
return map[string]interface{}{
"assessTaskId": assessTaskData.Id,
}, nil
}
// 添加节点任务
func (srv StaffAssessServeice) buildStaffAssess(transactionContext application.TransactionContext, param *domain.StaffAssessTask) ([]domain.StaffAssess, error) {
selfUserId := []int{} //评估的参与人
userIdMap := map[int]struct{}{} //过滤重复的用户
for _, v := range param.ExecutorId {
if _, ok := userIdMap[v]; ok {
continue
}
selfUserId = append(selfUserId, v)
}
// 获取用户的信息
if len(selfUserId) == 0 {
log.Logger.Error("createStaffAssess", map[string]interface{}{
"param": param,
})
return nil, application.ThrowError(application.ARG_ERROR, "未填写评估任务的执行人")
}
userRepo := factory.CreateUserRepository(map[string]interface{}{
"transactionContext": transactionContext,
})
//获取员工信息
_, userList, err := userRepo.Find(map[string]interface{}{
"ids": selfUserId,
"status": 1,
})
if err != nil {
return nil, application.ThrowError(application.ARG_ERROR, "获取员工信息"+err.Error())
}
departmentRepo := factory.CreateDepartmentRepository(map[string]interface{}{
"transactionContext": transactionContext,
})
//获取用户的部门
userDepartmentMap := map[int64][]*domain.Department{}
for _, v := range userList {
if len(v.DepartmentId) == 0 {
continue
}
_, departmemtList, err := departmentRepo.Find(map[string]interface{}{
"ids": v.DepartmentId,
})
if err != nil {
return nil, application.ThrowError(application.ARG_ERROR, "获取员工的部门信息"+err.Error())
}
userDepartmentMap[v.Id] = departmemtList
}
assessList := []domain.StaffAssess{}
//数据样板
stepSelfTemp := domain.StaffAssess{
Id: 0,
CompanyId: param.CompanyId,
EvaluationProjectId: param.EvaluationProjectId,
EvaluationProjectName: param.EvaluationProjectName,
CycleId: param.CycleId,
CycleName: param.CycleName,
StaffAssessTaskId: param.Id,
// TargetUser: domain.StaffDesc{},
// TargetDepartment: nil,
// Executor: domain.StaffDesc{},
Types: "",
// LinkNodeId: v.LinkNodeId,
Status: domain.StaffAssessUncompleted,
// BeginTime: time.Time{},
// EndTime: time.Time{},
CreatedAt: param.CreatedAt,
UpdatedAt: param.UpdatedAt,
DeletedAt: nil,
}
for _, v := range param.StepList {
if v.LinkNodeType == domain.LinkNodeSelfAssessment {
//员工自评
stepSelfTemp.BeginTime = v.BeginTime
stepSelfTemp.EndTime = v.EndTime
stepSelfTemp.LinkNodeId = v.LinkNodeId
stepSelfTemp.LinkNodeName = v.LinkNodeName
stepSelfTemp.Types = domain.AssessSelf
assessListTemp, err := srv.buildStaffAssessSelf(stepSelfTemp, userList, userDepartmentMap)
if err != nil {
return nil, err
}
assessList = append(assessList, assessListTemp...)
}
if v.LinkNodeType == domain.LinkNodeSuperiorAssessment {
// 创建上级评估
stepSelfTemp.BeginTime = v.BeginTime
stepSelfTemp.EndTime = v.EndTime
stepSelfTemp.LinkNodeId = v.LinkNodeId
stepSelfTemp.LinkNodeName = v.LinkNodeName
stepSelfTemp.Types = domain.AssessSuper
assessListTemp2, err := srv.buildStaffAssessSupper(stepSelfTemp, userList, userDepartmentMap)
if err != nil {
return nil, err
}
assessList = append(assessList, assessListTemp2...)
}
}
return assessList, nil
}
// 构建员工自评
func (srv StaffAssessServeice) buildStaffAssessSelf(
assessTemp domain.StaffAssess,
userList []*domain.User,
userDepartmentMap map[int64][]*domain.Department) ([]domain.StaffAssess, 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,
})
beginDay := assessTemp.BeginTime.Local().Format("2006-01-02")
_, assessListOld, err := assessRepo.Find(map[string]interface{}{"cycleId": assessTemp.CycleId, "beginDay": beginDay, "types": domain.AssessSelf})
if err != nil {
return nil, err
}
userMapReal := map[int]*domain.User{}
for _, val := range userList {
userMapReal[int(val.Id)] = val
}
for _, val := range assessListOld {
delete(userMapReal, val.TargetUser.UserId)
}
assessListNew := []domain.StaffAssess{}
for _, usr := range userMapReal {
assessTemp.TargetUser = domain.StaffDesc{
UserId: int(usr.Id),
Account: usr.Account,
UserName: usr.Name,
}
assessTemp.Executor = domain.StaffDesc{
UserId: int(usr.Id),
Account: usr.Account,
UserName: usr.Name,
}
if depList, ok := userDepartmentMap[usr.Id]; ok {
for _, dep := range depList {
assessTemp.TargetDepartment = append(assessTemp.TargetDepartment, domain.StaffDepartment{
DepartmentId: int(dep.Id),
DepartmentName: dep.Name,
})
}
}
assessListNew = append(assessListNew, assessTemp)
}
if err := transactionContext.CommitTransaction(); err != nil {
return nil, application.ThrowError(application.INTERNAL_SERVER_ERROR, err.Error())
}
return assessListNew, nil
}
// 构建员工的上级评估
func (srv StaffAssessServeice) buildStaffAssessSupper(
assessTemp domain.StaffAssess,
userList []*domain.User,
userDepartmentMap map[int64][]*domain.Department,
) ([]domain.StaffAssess, 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,
})
beginDay := assessTemp.BeginTime.Local().Format("2006-01-02")
_, assessListOld, err := assessRepo.Find(map[string]interface{}{"cycleId": assessTemp.CycleId, "beginDay": beginDay, "types": domain.AssessSuper})
if err != nil {
return nil, err
}
userMapReal := map[int]*domain.User{}
for _, val := range userList {
userMapReal[int(val.Id)] = val
}
for _, val := range assessListOld {
delete(userMapReal, val.TargetUser.UserId)
}
var assessListNew []domain.StaffAssess
for _, v := range userMapReal {
//获取上级
chargeUserList, err := srv.getStaffSuper(transactionContext, *v)
if err != nil {
return nil, err
}
if len(chargeUserList) == 0 {
continue
}
for _, v2 := range chargeUserList {
assessTemp.TargetUser = domain.StaffDesc{
UserId: int(v.Id),
Account: v.Account,
UserName: v.Name,
}
assessTemp.Executor = domain.StaffDesc{
UserId: int(v2.Id),
Account: v2.Account,
UserName: v2.Name,
}
targetDepartment := []domain.StaffDepartment{}
if departmentList, ok := userDepartmentMap[v.Id]; ok {
for _, department := range departmentList {
targetDepartment = append(targetDepartment, domain.StaffDepartment{
DepartmentId: int(department.Id),
DepartmentName: department.Name,
})
}
}
assessTemp.TargetDepartment = targetDepartment
assessListNew = append(assessListNew, assessTemp)
}
}
if err := transactionContext.CommitTransaction(); err != nil {
return nil, application.ThrowError(application.INTERNAL_SERVER_ERROR, err.Error())
}
return assessListNew, nil
}
// 按照评估模板中指标类型,创建里程碑任务
// staffAssess 每日自评评估
func (srv StaffAssessCacheService) buildTaskRecord(staffAssess *domain.StaffAssess) ([]*domain.TaskRecord, 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()
}()
projectRepo := factory.CreateEvaluationProjectRepository(map[string]interface{}{
"transactionContext": transactionContext,
})
itemUsedRepo := factory.CreateEvaluationItemUsedRepository(map[string]interface{}{
"transactionContext": transactionContext,
})
projectData, err := projectRepo.FindOne(map[string]interface{}{"id": staffAssess.EvaluationProjectId})
if err != nil {
return nil, application.ThrowError(application.ARG_ERROR, "获取项目EvaluationProject信息"+err.Error())
}
// projectData.PrincipalId
userIdstr := strconv.Itoa(staffAssess.Executor.UserId)
if projectData.PrincipalId != userIdstr {
return nil, nil
}
_, evaluationItem, err := itemUsedRepo.Find(map[string]interface{}{
"indicatorType": domain.IndicatorTypeTask,
"evaluationProjectId": projectData.Id,
})
if err != nil {
return nil, application.ThrowError(application.ARG_ERROR, "获取评估项EvaluationItemUsed信息"+err.Error())
}
_ = evaluationItem
if err := transactionContext.CommitTransaction(); err != nil {
return nil, application.ThrowError(application.INTERNAL_SERVER_ERROR, err.Error())
}
return nil, nil
}
... ...
... ... @@ -2,7 +2,6 @@ package service
import (
"fmt"
"sort"
"strconv"
"time"
... ... @@ -12,7 +11,6 @@ import (
"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/notify"
"gitlab.fjmaimaimai.com/allied-creation/performance/pkg/application/staff_assess/adapter"
"gitlab.fjmaimaimai.com/allied-creation/performance/pkg/application/staff_assess/command"
"gitlab.fjmaimaimai.com/allied-creation/performance/pkg/application/staff_assess/query"
... ... @@ -135,342 +133,342 @@ func (srv StaffAssessServeice) AssessSelfList(param *query.AssessSelfListQuery)
}
// 根据项目评估的配置,创建员工的评估任务
func (srv StaffAssessServeice) CreateStaffAssessTask(transactionContext application.TransactionContext, param *command.CreateStaffAssessTask) (map[string]interface{}, error) {
log.Logger.Debug("CreateStaffAssessTask 获取参数", map[string]interface{}{
"param": param,
})
assessTaskRepo := factory.CreateStaffAssessTaskRepository(map[string]interface{}{
"transactionContext": transactionContext,
})
taskBeginTime, err := time.ParseInLocation("2006-01-02 15:04:05", param.BeginTime, time.Local)
if err != nil {
return nil, application.ThrowError(application.ARG_ERROR, "任务开始时间填写错误,"+param.BeginTime)
}
taskEndTime, err := time.ParseInLocation("2006-01-02 15:04:05", param.EndTime, time.Local)
if err != nil {
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: []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)
}
assessTaskData.ExecutorId = executorIds
for _, v := range param.StepList {
stepBeginTime, err := time.ParseInLocation("2006-01-02 15:04:05", param.BeginTime, time.Local)
if err != nil {
return nil, application.ThrowError(application.ARG_ERROR, "评估环节开始时间填写错误,"+param.BeginTime)
}
stepEndTime, err := time.ParseInLocation("2006-01-02 15:04:05", param.EndTime, time.Local)
if err != nil {
return nil, application.ThrowError(application.ARG_ERROR, "评估环节结束时间填写错误,"+param.EndTime)
}
step := domain.AssessTaskStep{
SortBy: v.SortBy,
LinkNodeId: v.LinkNodeId,
LinkNodeName: v.LinkNodeName,
LinkNodeType: v.LinkNodeType,
BeginTime: stepBeginTime,
EndTime: stepEndTime,
}
assessTaskData.StepList = append(assessTaskData.StepList, step)
}
//添加员工的节点任务
assessList, err := srv.createStaffAssess(transactionContext, assessTaskData)
if err != nil {
return nil, application.ThrowError(application.INTERNAL_SERVER_ERROR, "生成个人评估项"+err.Error())
}
// func (srv StaffAssessServeice) CreateStaffAssessTask(transactionContext application.TransactionContext, param *command.CreateStaffAssessTask) (map[string]interface{}, error) {
// log.Logger.Debug("CreateStaffAssessTask 获取参数", map[string]interface{}{
// "param": param,
// })
// assessTaskRepo := factory.CreateStaffAssessTaskRepository(map[string]interface{}{
// "transactionContext": transactionContext,
// })
// taskBeginTime, err := time.ParseInLocation("2006-01-02 15:04:05", param.BeginTime, time.Local)
// if err != nil {
// return nil, application.ThrowError(application.ARG_ERROR, "任务开始时间填写错误,"+param.BeginTime)
// }
// taskEndTime, err := time.ParseInLocation("2006-01-02 15:04:05", param.EndTime, time.Local)
// if err != nil {
// 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: []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)
// }
// assessTaskData.ExecutorId = executorIds
// for _, v := range param.StepList {
// stepBeginTime, err := time.ParseInLocation("2006-01-02 15:04:05", param.BeginTime, time.Local)
// if err != nil {
// return nil, application.ThrowError(application.ARG_ERROR, "评估环节开始时间填写错误,"+param.BeginTime)
// }
// stepEndTime, err := time.ParseInLocation("2006-01-02 15:04:05", param.EndTime, time.Local)
// if err != nil {
// return nil, application.ThrowError(application.ARG_ERROR, "评估环节结束时间填写错误,"+param.EndTime)
// }
// step := domain.AssessTaskStep{
// SortBy: v.SortBy,
// LinkNodeId: v.LinkNodeId,
// LinkNodeName: v.LinkNodeName,
// LinkNodeType: v.LinkNodeType,
// BeginTime: stepBeginTime,
// EndTime: stepEndTime,
// }
// assessTaskData.StepList = append(assessTaskData.StepList, step)
// }
// //添加员工的节点任务
// assessList, err := srv.createStaffAssess(transactionContext, assessTaskData)
// if err != nil {
// return nil, application.ThrowError(application.INTERNAL_SERVER_ERROR, "生成个人评估项"+err.Error())
// }
//合并项目评估的新旧数据
_, 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())
}
// //合并项目评估的新旧数据
// _, 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 {
//就数据中提取参与人
for _, v := range assessTaskData.ExecutorId {
if _, ok := executorIdMap[v]; ok {
continue
}
executorIdMap[v] = struct{}{}
executorIds = append(executorIds, v)
}
assassessTaskList[0].UpdatedAt = time.Now()
assassessTaskList[0].ExecutorId = executorIds
//更新步骤
assassessTaskList[0].StepList = append(assassessTaskList[0].StepList, assessTaskData.StepList...)
for _, val := range assessTaskData.StepList {
hasFound := false
for _, val2 := range assassessTaskList[0].StepList {
if val.LinkNodeType == val2.LinkNodeType {
hasFound = true
break
}
}
if !hasFound {
assassessTaskList[0].StepList = append(assassessTaskList[0].StepList, val)
}
}
assessTaskData = assassessTaskList[0]
//排序流程环节
}
stepList := domain.SortTaskStep(assessTaskData.StepList)
sort.Sort(stepList)
_, err = assessTaskRepo.Save(assessTaskData)
if err != nil {
return nil, application.ThrowError(application.INTERNAL_SERVER_ERROR, "保存评估任务"+err.Error())
}
// if len(assassessTaskList) > 0 {
// //就数据中提取参与人
// for _, v := range assessTaskData.ExecutorId {
// if _, ok := executorIdMap[v]; ok {
// continue
// }
// executorIdMap[v] = struct{}{}
// executorIds = append(executorIds, v)
// }
// assassessTaskList[0].UpdatedAt = time.Now()
// assassessTaskList[0].ExecutorId = executorIds
// //更新步骤
// assassessTaskList[0].StepList = append(assassessTaskList[0].StepList, assessTaskData.StepList...)
// for _, val := range assessTaskData.StepList {
// hasFound := false
// for _, val2 := range assassessTaskList[0].StepList {
// if val.LinkNodeType == val2.LinkNodeType {
// hasFound = true
// break
// }
// }
// if !hasFound {
// assassessTaskList[0].StepList = append(assassessTaskList[0].StepList, val)
// }
// }
// assessTaskData = assassessTaskList[0]
// //排序流程环节
// }
// stepList := domain.SortTaskStep(assessTaskData.StepList)
// sort.Sort(stepList)
// _, err = assessTaskRepo.Save(assessTaskData)
// if err != nil {
// return nil, application.ThrowError(application.INTERNAL_SERVER_ERROR, "保存评估任务"+err.Error())
// }
//保存 员工的评估任务
assessRepo := factory.CreateStaffAssessRepository(map[string]interface{}{
"transactionContext": transactionContext,
})
for i := range assessList {
assessList[i].StaffAssessTaskId = assessTaskData.Id
_, err = assessRepo.Save(&assessList[i])
if err != nil {
return nil, application.ThrowError(application.INTERNAL_SERVER_ERROR, "保存个人评估项"+err.Error())
}
if assessList[i].Types == domain.AssessSelf {
//添加待发送的短信通知
notify.AddNotifyStaffAssess(&assessList[i])
}
}
return map[string]interface{}{
"assessTaskId": assessTaskData.Id,
}, nil
}
// //保存 员工的评估任务
// assessRepo := factory.CreateStaffAssessRepository(map[string]interface{}{
// "transactionContext": transactionContext,
// })
// for i := range assessList {
// assessList[i].StaffAssessTaskId = assessTaskData.Id
// _, err = assessRepo.Save(&assessList[i])
// if err != nil {
// return nil, application.ThrowError(application.INTERNAL_SERVER_ERROR, "保存个人评估项"+err.Error())
// }
// if assessList[i].Types == domain.AssessSelf {
// //添加待发送的短信通知
// notify.AddNotifyStaffAssess(&assessList[i])
// }
// }
// return map[string]interface{}{
// "assessTaskId": assessTaskData.Id,
// }, nil
// }
// 添加节点任务
func (srv StaffAssessServeice) createStaffAssess(transactionContext application.TransactionContext, param *domain.StaffAssessTask) ([]domain.StaffAssess, error) {
selfUserId := []int{} //评估的参与人
userIdMap := map[int]struct{}{} //过滤重复的用户
for _, v := range param.ExecutorId {
if _, ok := userIdMap[v]; ok {
continue
}
selfUserId = append(selfUserId, v)
}
// 获取用户的信息
if len(selfUserId) == 0 {
log.Logger.Error("createStaffAssess", map[string]interface{}{
"param": param,
})
return nil, application.ThrowError(application.ARG_ERROR, "未填写评估任务的执行人")
}
userRepo := factory.CreateUserRepository(map[string]interface{}{
"transactionContext": transactionContext,
})
//获取员工信息
_, userList, err := userRepo.Find(map[string]interface{}{
"ids": selfUserId,
"status": 1,
})
if err != nil {
return nil, application.ThrowError(application.ARG_ERROR, "获取员工信息"+err.Error())
}
departmentRepo := factory.CreateDepartmentRepository(map[string]interface{}{
"transactionContext": transactionContext,
})
//获取用户的部门
userDepartmentMap := map[int64][]*domain.Department{}
for _, v := range userList {
if len(v.DepartmentId) == 0 {
continue
}
_, departmemtList, err := departmentRepo.Find(map[string]interface{}{
"ids": v.DepartmentId,
})
if err != nil {
return nil, application.ThrowError(application.ARG_ERROR, "获取员工的部门信息"+err.Error())
}
userDepartmentMap[v.Id] = departmemtList
}
assessList := []domain.StaffAssess{}
//数据样板
stepSelfTemp := domain.StaffAssess{
Id: 0,
CompanyId: param.CompanyId,
EvaluationProjectId: param.EvaluationProjectId,
EvaluationProjectName: param.EvaluationProjectName,
CycleId: param.CycleId,
CycleName: param.CycleName,
StaffAssessTaskId: param.Id,
// TargetUser: domain.StaffDesc{},
// TargetDepartment: nil,
// Executor: domain.StaffDesc{},
Types: "",
// LinkNodeId: v.LinkNodeId,
Status: domain.StaffAssessUncompleted,
// BeginTime: time.Time{},
// EndTime: time.Time{},
CreatedAt: param.CreatedAt,
UpdatedAt: param.UpdatedAt,
DeletedAt: nil,
}
for _, v := range param.StepList {
if v.LinkNodeType == domain.LinkNodeSelfAssessment {
//员工自评
stepSelfTemp.BeginTime = v.BeginTime
stepSelfTemp.EndTime = v.EndTime
stepSelfTemp.LinkNodeId = v.LinkNodeId
stepSelfTemp.LinkNodeName = v.LinkNodeName
stepSelfTemp.Types = domain.AssessSelf
assessListTemp, err := srv.createStaffAssessSelf(transactionContext, stepSelfTemp, userList, userDepartmentMap)
if err != nil {
return nil, err
}
assessList = append(assessList, assessListTemp...)
}
if v.LinkNodeType == domain.LinkNodeSuperiorAssessment {
// 创建上级评估
stepSelfTemp.BeginTime = v.BeginTime
stepSelfTemp.EndTime = v.EndTime
stepSelfTemp.LinkNodeId = v.LinkNodeId
stepSelfTemp.LinkNodeName = v.LinkNodeName
stepSelfTemp.Types = domain.AssessSuper
assessListTemp2, err := srv.createStaffAssessSupper(transactionContext, stepSelfTemp, userList, userDepartmentMap)
if err != nil {
return nil, err
}
assessList = append(assessList, assessListTemp2...)
}
}
return assessList, nil
}
// func (srv StaffAssessServeice) createStaffAssess(transactionContext application.TransactionContext, param *domain.StaffAssessTask) ([]domain.StaffAssess, error) {
// selfUserId := []int{} //评估的参与人
// userIdMap := map[int]struct{}{} //过滤重复的用户
// for _, v := range param.ExecutorId {
// if _, ok := userIdMap[v]; ok {
// continue
// }
// selfUserId = append(selfUserId, v)
// }
// // 获取用户的信息
// if len(selfUserId) == 0 {
// log.Logger.Error("createStaffAssess", map[string]interface{}{
// "param": param,
// })
// return nil, application.ThrowError(application.ARG_ERROR, "未填写评估任务的执行人")
// }
// userRepo := factory.CreateUserRepository(map[string]interface{}{
// "transactionContext": transactionContext,
// })
// //获取员工信息
// _, userList, err := userRepo.Find(map[string]interface{}{
// "ids": selfUserId,
// "status": 1,
// })
// if err != nil {
// return nil, application.ThrowError(application.ARG_ERROR, "获取员工信息"+err.Error())
// }
// departmentRepo := factory.CreateDepartmentRepository(map[string]interface{}{
// "transactionContext": transactionContext,
// })
// //获取用户的部门
// userDepartmentMap := map[int64][]*domain.Department{}
// for _, v := range userList {
// if len(v.DepartmentId) == 0 {
// continue
// }
// _, departmemtList, err := departmentRepo.Find(map[string]interface{}{
// "ids": v.DepartmentId,
// })
// if err != nil {
// return nil, application.ThrowError(application.ARG_ERROR, "获取员工的部门信息"+err.Error())
// }
// userDepartmentMap[v.Id] = departmemtList
// }
// assessList := []domain.StaffAssess{}
// //数据样板
// stepSelfTemp := domain.StaffAssess{
// Id: 0,
// CompanyId: param.CompanyId,
// EvaluationProjectId: param.EvaluationProjectId,
// EvaluationProjectName: param.EvaluationProjectName,
// CycleId: param.CycleId,
// CycleName: param.CycleName,
// StaffAssessTaskId: param.Id,
// // TargetUser: domain.StaffDesc{},
// // TargetDepartment: nil,
// // Executor: domain.StaffDesc{},
// Types: "",
// // LinkNodeId: v.LinkNodeId,
// Status: domain.StaffAssessUncompleted,
// // BeginTime: time.Time{},
// // EndTime: time.Time{},
// CreatedAt: param.CreatedAt,
// UpdatedAt: param.UpdatedAt,
// DeletedAt: nil,
// }
// for _, v := range param.StepList {
// if v.LinkNodeType == domain.LinkNodeSelfAssessment {
// //员工自评
// stepSelfTemp.BeginTime = v.BeginTime
// stepSelfTemp.EndTime = v.EndTime
// stepSelfTemp.LinkNodeId = v.LinkNodeId
// stepSelfTemp.LinkNodeName = v.LinkNodeName
// stepSelfTemp.Types = domain.AssessSelf
// assessListTemp, err := srv.createStaffAssessSelf(transactionContext, stepSelfTemp, userList, userDepartmentMap)
// if err != nil {
// return nil, err
// }
// assessList = append(assessList, assessListTemp...)
// }
// if v.LinkNodeType == domain.LinkNodeSuperiorAssessment {
// // 创建上级评估
// stepSelfTemp.BeginTime = v.BeginTime
// stepSelfTemp.EndTime = v.EndTime
// stepSelfTemp.LinkNodeId = v.LinkNodeId
// stepSelfTemp.LinkNodeName = v.LinkNodeName
// stepSelfTemp.Types = domain.AssessSuper
// assessListTemp2, err := srv.createStaffAssessSupper(transactionContext, stepSelfTemp, userList, userDepartmentMap)
// if err != nil {
// return nil, err
// }
// assessList = append(assessList, assessListTemp2...)
// }
// }
// return assessList, nil
// }
// 构建员工自评
func (srv StaffAssessServeice) createStaffAssessSelf(
transactionContext application.TransactionContext,
assessTemp domain.StaffAssess,
userList []*domain.User,
userDepartmentMap map[int64][]*domain.Department) ([]domain.StaffAssess, error) {
assessRepo := factory.CreateStaffAssessRepository(map[string]interface{}{
"transactionContext": transactionContext,
})
beginDay := assessTemp.BeginTime.Local().Format("2006-01-02")
_, assessListOld, err := assessRepo.Find(map[string]interface{}{"cycleId": assessTemp.CycleId, "beginDay": beginDay, "types": domain.AssessSelf})
if err != nil {
return nil, err
}
userMapReal := map[int]*domain.User{}
for _, val := range userList {
userMapReal[int(val.Id)] = val
}
for _, val := range assessListOld {
delete(userMapReal, val.TargetUser.UserId)
}
assessListNew := []domain.StaffAssess{}
for _, usr := range userMapReal {
assessTemp.TargetUser = domain.StaffDesc{
UserId: int(usr.Id),
Account: usr.Account,
UserName: usr.Name,
}
assessTemp.Executor = domain.StaffDesc{
UserId: int(usr.Id),
Account: usr.Account,
UserName: usr.Name,
}
if depList, ok := userDepartmentMap[usr.Id]; ok {
for _, dep := range depList {
assessTemp.TargetDepartment = append(assessTemp.TargetDepartment, domain.StaffDepartment{
DepartmentId: int(dep.Id),
DepartmentName: dep.Name,
})
}
}
assessListNew = append(assessListNew, assessTemp)
}
return assessListNew, nil
}
// func (srv StaffAssessServeice) createStaffAssessSelf(
// transactionContext application.TransactionContext,
// assessTemp domain.StaffAssess,
// userList []*domain.User,
// userDepartmentMap map[int64][]*domain.Department) ([]domain.StaffAssess, error) {
// assessRepo := factory.CreateStaffAssessRepository(map[string]interface{}{
// "transactionContext": transactionContext,
// })
// beginDay := assessTemp.BeginTime.Local().Format("2006-01-02")
// _, assessListOld, err := assessRepo.Find(map[string]interface{}{"cycleId": assessTemp.CycleId, "beginDay": beginDay, "types": domain.AssessSelf})
// if err != nil {
// return nil, err
// }
// userMapReal := map[int]*domain.User{}
// for _, val := range userList {
// userMapReal[int(val.Id)] = val
// }
// for _, val := range assessListOld {
// delete(userMapReal, val.TargetUser.UserId)
// }
// assessListNew := []domain.StaffAssess{}
// for _, usr := range userMapReal {
// assessTemp.TargetUser = domain.StaffDesc{
// UserId: int(usr.Id),
// Account: usr.Account,
// UserName: usr.Name,
// }
// assessTemp.Executor = domain.StaffDesc{
// UserId: int(usr.Id),
// Account: usr.Account,
// UserName: usr.Name,
// }
// if depList, ok := userDepartmentMap[usr.Id]; ok {
// for _, dep := range depList {
// assessTemp.TargetDepartment = append(assessTemp.TargetDepartment, domain.StaffDepartment{
// DepartmentId: int(dep.Id),
// DepartmentName: dep.Name,
// })
// }
// }
// assessListNew = append(assessListNew, assessTemp)
// }
// return assessListNew, nil
// }
// 构建员工的上级评估
func (srv StaffAssessServeice) createStaffAssessSupper(
transactionContext application.TransactionContext,
assessTemp domain.StaffAssess,
userList []*domain.User, userDepartmentMap map[int64][]*domain.Department,
) ([]domain.StaffAssess, error) {
assessRepo := factory.CreateStaffAssessRepository(map[string]interface{}{
"transactionContext": transactionContext,
})
beginDay := assessTemp.BeginTime.Local().Format("2006-01-02")
_, assessListOld, err := assessRepo.Find(map[string]interface{}{"cycleId": assessTemp.CycleId, "beginDay": beginDay, "types": domain.AssessSuper})
if err != nil {
return nil, err
}
userMapReal := map[int]*domain.User{}
for _, val := range userList {
userMapReal[int(val.Id)] = val
}
for _, val := range assessListOld {
delete(userMapReal, val.TargetUser.UserId)
}
// func (srv StaffAssessServeice) createStaffAssessSupper(
// transactionContext application.TransactionContext,
// assessTemp domain.StaffAssess,
// userList []*domain.User, userDepartmentMap map[int64][]*domain.Department,
// ) ([]domain.StaffAssess, error) {
// assessRepo := factory.CreateStaffAssessRepository(map[string]interface{}{
// "transactionContext": transactionContext,
// })
// beginDay := assessTemp.BeginTime.Local().Format("2006-01-02")
// _, assessListOld, err := assessRepo.Find(map[string]interface{}{"cycleId": assessTemp.CycleId, "beginDay": beginDay, "types": domain.AssessSuper})
// if err != nil {
// return nil, err
// }
// userMapReal := map[int]*domain.User{}
// for _, val := range userList {
// userMapReal[int(val.Id)] = val
// }
// for _, val := range assessListOld {
// delete(userMapReal, val.TargetUser.UserId)
// }
var assessListNew []domain.StaffAssess
for _, v := range userMapReal {
//获取上级
chargeUserList, err := srv.getStaffSuper(transactionContext, *v)
if err != nil {
return nil, err
}
if len(chargeUserList) == 0 {
continue
}
for _, v2 := range chargeUserList {
assessTemp.TargetUser = domain.StaffDesc{
UserId: int(v.Id),
Account: v.Account,
UserName: v.Name,
}
assessTemp.Executor = domain.StaffDesc{
UserId: int(v2.Id),
Account: v2.Account,
UserName: v2.Name,
}
targetDepartment := []domain.StaffDepartment{}
if departmentList, ok := userDepartmentMap[v.Id]; ok {
for _, department := range departmentList {
targetDepartment = append(targetDepartment, domain.StaffDepartment{
DepartmentId: int(department.Id),
DepartmentName: department.Name,
})
}
}
assessTemp.TargetDepartment = targetDepartment
assessListNew = append(assessListNew, assessTemp)
}
// var assessListNew []domain.StaffAssess
// for _, v := range userMapReal {
// //获取上级
// chargeUserList, err := srv.getStaffSuper(transactionContext, *v)
// if err != nil {
// return nil, err
// }
// if len(chargeUserList) == 0 {
// continue
// }
// for _, v2 := range chargeUserList {
// assessTemp.TargetUser = domain.StaffDesc{
// UserId: int(v.Id),
// Account: v.Account,
// UserName: v.Name,
// }
// assessTemp.Executor = domain.StaffDesc{
// UserId: int(v2.Id),
// Account: v2.Account,
// UserName: v2.Name,
// }
// targetDepartment := []domain.StaffDepartment{}
// if departmentList, ok := userDepartmentMap[v.Id]; ok {
// for _, department := range departmentList {
// targetDepartment = append(targetDepartment, domain.StaffDepartment{
// DepartmentId: int(department.Id),
// DepartmentName: department.Name,
// })
// }
// }
// assessTemp.TargetDepartment = targetDepartment
// assessListNew = append(assessListNew, assessTemp)
// }
}
return assessListNew, nil
}
// }
// return assessListNew, nil
// }
// 获取某个员工360评估邀请的人员
// func (srv StaffAssessServeice) GetAssessInviteUser(param *query.GetAssessInviteUserQuery) (*adapter.AssessInviteUserResp, error) {
... ...
... ... @@ -10,7 +10,7 @@ type EvaluationItemUsed struct {
CompanyId int //公司id
EvaluationProjectId int //对应的项目id
NodeId int //填写评估评估节点对应id
NodeType int //填写评估评估节点对应类型同evaluation_template.go->LinkNode.Type,
NodeType int //填写评估评估节点对应类型,同evaluation_template.go->LinkNode.Type,
SortBy int //排序
Category string //类别
Name string //名称
... ... @@ -22,7 +22,7 @@ type EvaluationItemUsed struct {
Weight float64 //"权重"
Required int //必填项 同 NodeContent.Required
EvaluatorId int //项目评估人ID ( 0=无评估人、-1=HRBP、 >0 员工的id )
IndicatorType int //指标类型
IndicatorType int //指标类型,值同 evaluation_template.go->NodeContent.IndicatorType
CreatedAt time.Time //数据创建时间
UpdatedAt time.Time //数据更新时间
}
... ...
... ... @@ -102,6 +102,9 @@ func (repo *EvaluationItemUsedRepository) Find(queryOptions map[string]interface
if v, ok := queryOptions["evaluatorId"]; ok {
query.Where("evaluator_id=?", v)
}
if v, ok := queryOptions["indicatorType"]; ok {
query.Where("indicator_type=?", v)
}
query.Order("sort_by")
count, err := query.SelectAndCount()
... ...