|
|
package service
|
|
|
|
|
|
import (
|
|
|
"fmt"
|
|
|
"strconv"
|
|
|
"time"
|
|
|
|
|
|
"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/command"
|
|
|
"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/log"
|
|
|
)
|
|
|
|
|
|
// 员工评绩效评估
|
|
|
type StaffAssessServeice struct {
|
|
|
}
|
|
|
|
|
|
func NewStaffAssessServeice() *StaffAssessServeice {
|
|
|
newService := &StaffAssessServeice{}
|
|
|
return newService
|
|
|
}
|
|
|
|
|
|
// 获取我参与过的评估任务列表
|
|
|
func (srv StaffAssessServeice) SearchAssessTaskMe(param *query.SearchAssessMeQuery) (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()
|
|
|
}()
|
|
|
staffAssessTaskRepo := factory.CreateStaffAssessTaskRepository(map[string]interface{}{
|
|
|
"transactionContext": transactionContext,
|
|
|
})
|
|
|
var limit int = 20
|
|
|
var offset int = 0
|
|
|
if param.PageSize > 0 {
|
|
|
limit = param.PageSize
|
|
|
}
|
|
|
offset = (param.PageNumber - 1) * param.PageSize
|
|
|
condition := map[string]interface{}{
|
|
|
"executorId": param.UserId,
|
|
|
"companyId": param.CompanyId,
|
|
|
"limit": limit,
|
|
|
}
|
|
|
if offset > 0 {
|
|
|
condition["offset"] = offset
|
|
|
}
|
|
|
cnt, assessTaskList, err := staffAssessTaskRepo.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 := make([]adapter.SearchAssessMeResp, 0, len(assessTaskList))
|
|
|
var temp adapter.SearchAssessMeResp
|
|
|
for _, v := range assessTaskList {
|
|
|
temp = adapter.SearchAssessMeResp{
|
|
|
AssessTaskId: v.Id,
|
|
|
BeginTime: v.BeginTime.Format("2006-01-02 15:04:05"),
|
|
|
EndTime: v.EndTime.Format("2006-01-02 15:04:05"),
|
|
|
CycleId: v.CycleId,
|
|
|
CycleName: v.CycleName,
|
|
|
EvaluationProjectId: v.EvaluationProjectId,
|
|
|
EvaluationProjectName: v.EvaluationProjectName,
|
|
|
}
|
|
|
listData = append(listData, temp)
|
|
|
}
|
|
|
return tool_funs.SimpleWrapGridMap(int64(cnt), listData), nil
|
|
|
}
|
|
|
|
|
|
// 获取项目评估进度描述
|
|
|
func (srv StaffAssessServeice) AssessTaskDesc(param *query.AssessTaskDescQuery) (*adapter.AssessTaskDescResp, 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()
|
|
|
}()
|
|
|
// 获取评估任务
|
|
|
staffAssessTaskRepo := factory.CreateStaffAssessTaskRepository(map[string]interface{}{
|
|
|
"transactionContext": transactionContext,
|
|
|
})
|
|
|
//获取个人参与的评估流程
|
|
|
staffAssessRepo := factory.CreateStaffAssessRepository(map[string]interface{}{
|
|
|
"transactionContext": transactionContext,
|
|
|
})
|
|
|
assessTaskData, err := staffAssessTaskRepo.FindOne(map[string]interface{}{
|
|
|
"id": param.AssessTaskId,
|
|
|
})
|
|
|
if err != nil {
|
|
|
return nil, application.ThrowError(application.TRANSACTION_ERROR, "评估任务不存在,"+err.Error())
|
|
|
}
|
|
|
//返回的数据结果
|
|
|
result := adapter.AssessTaskDescResp{
|
|
|
AssessTaskId: assessTaskData.Id,
|
|
|
EvaluationProjectId: assessTaskData.EvaluationProjectId,
|
|
|
EvaluationProjectName: assessTaskData.EvaluationProjectName,
|
|
|
CycleName: assessTaskData.CycleName,
|
|
|
BeginTime: assessTaskData.BeginTime.Local().Format("2006-01-02 15:04-05"),
|
|
|
EndTime: assessTaskData.EndTime.Local().Format("2006-01-02 15:04-05"),
|
|
|
StepList: []adapter.AssessTaskStep{},
|
|
|
}
|
|
|
|
|
|
for _, v := range assessTaskData.StepList {
|
|
|
stepItem := adapter.AssessTaskStep{
|
|
|
SortBy: v.SortBy,
|
|
|
LinkNodeName: v.LinkNodeName,
|
|
|
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:
|
|
|
//个人自评完成情况
|
|
|
_, assessSelfData, err := staffAssessRepo.Find(map[string]interface{}{
|
|
|
"staffAssessTaskId": assessTaskData.Id,
|
|
|
"executorId": param.UserId,
|
|
|
"typesList": []string{string(domain.AssessSelf)},
|
|
|
})
|
|
|
if err != nil {
|
|
|
return nil, application.ThrowError(application.TRANSACTION_ERROR, "获取个人的评估环节"+err.Error())
|
|
|
}
|
|
|
if len(assessSelfData) > 0 {
|
|
|
stepItem.Status = string(assessSelfData[0].Status)
|
|
|
}
|
|
|
stepItem.Desc = fmt.Sprintf("截止日期:%s", stepItem.EndTime)
|
|
|
case domain.LinkNodeAllInvite:
|
|
|
//邀请别人评估自己
|
|
|
_, assessInviteData, err := staffAssessRepo.Find(map[string]interface{}{
|
|
|
"staffAssessTaskId": assessTaskData.Id,
|
|
|
"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())
|
|
|
}
|
|
|
//待邀请人数,为5人减去已邀请的人数。若邀请人数已等于或大于5人,则只显示截止日期即可
|
|
|
if len(assessInviteData) > 5 {
|
|
|
stepItem.Desc = fmt.Sprintf("截止日期:%s", stepItem.EndTime)
|
|
|
stepItem.Status = string(domain.StaffAssessCompleted)
|
|
|
} else {
|
|
|
stepItem.Desc = fmt.Sprintf("截止日期:%s 待邀请%d人", stepItem.EndTime, 5-len(assessInviteData))
|
|
|
stepItem.Status = string(domain.StaffAssessUncompleted)
|
|
|
}
|
|
|
case domain.LinkNodeAllAssessment:
|
|
|
//我评估别人,被邀请评估
|
|
|
_, assessInviteList, err := staffAssessRepo.Find(map[string]interface{}{
|
|
|
"staffAssessTaskId": assessTaskData.Id,
|
|
|
"executorId": param.UserId,
|
|
|
"typesList": []string{string(domain.AssessInviteDiffSuper), string(domain.AssessInviteSameSuper)},
|
|
|
})
|
|
|
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:
|
|
|
//我评估别人,上级评估
|
|
|
_, assessSupperList, err := staffAssessRepo.Find(map[string]interface{}{
|
|
|
"staffAssessTaskId": assessTaskData.Id,
|
|
|
"executorId": param.UserId,
|
|
|
"typesList": []string{string(domain.AssessSuper)},
|
|
|
})
|
|
|
if err != nil {
|
|
|
return nil, application.ThrowError(application.TRANSACTION_ERROR, "获取个人的评估环节"+err.Error())
|
|
|
}
|
|
|
if len(assessSupperList) > 0 {
|
|
|
stepItem.Status = string(domain.StaffAssessCompleted)
|
|
|
stepItem.Desc = fmt.Sprintf("截止日期:%s", stepItem.EndTime)
|
|
|
uncompletedNum := 0
|
|
|
for _, v := range assessSupperList {
|
|
|
if v.Status == domain.StaffAssessUncompleted {
|
|
|
uncompletedNum += 1
|
|
|
}
|
|
|
}
|
|
|
if uncompletedNum > 0 {
|
|
|
stepItem.Desc = fmt.Sprintf("截止日期:%s 待评估%d人", stepItem.EndTime, uncompletedNum)
|
|
|
}
|
|
|
}
|
|
|
}
|
|
|
result.StepList = append(result.StepList, stepItem)
|
|
|
}
|
|
|
if err := transactionContext.CommitTransaction(); err != nil {
|
|
|
return nil, application.ThrowError(application.INTERNAL_SERVER_ERROR, err.Error())
|
|
|
}
|
|
|
return &result, nil
|
|
|
}
|
|
|
|
|
|
// 获取个人的自评反馈历史记录列表
|
|
|
func (srv StaffAssessServeice) AssessSelfList(param *query.AssessSelfListQuery) (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()
|
|
|
}()
|
|
|
//获取个人参与的评估流程
|
|
|
staffAssessRepo := factory.CreateStaffAssessRepository(map[string]interface{}{
|
|
|
"transactionContext": transactionContext,
|
|
|
})
|
|
|
var limit int = 20
|
|
|
var offset int = 0
|
|
|
if param.PageSize > 0 {
|
|
|
limit = param.PageSize
|
|
|
}
|
|
|
offset = (param.PageNumber - 1) * param.PageSize
|
|
|
condition := map[string]interface{}{
|
|
|
"executorId": param.UserId,
|
|
|
"companyId": param.CompanyId,
|
|
|
"typesList": []string{string(domain.AssessSelf)},
|
|
|
"limit": limit,
|
|
|
"status": string(domain.StaffAssessCompleted),
|
|
|
}
|
|
|
if offset > 0 {
|
|
|
condition["offset"] = offset
|
|
|
}
|
|
|
//获取历史列表
|
|
|
cnt, assessList, err := staffAssessRepo.Find(condition)
|
|
|
if err != nil {
|
|
|
return nil, application.ThrowError(application.TRANSACTION_ERROR, "获取评估任务列表,"+err.Error())
|
|
|
}
|
|
|
|
|
|
//获取公司数据
|
|
|
companyRep := factory.CreateCompanyRepository(map[string]interface{}{
|
|
|
"transactionContext": transactionContext,
|
|
|
})
|
|
|
|
|
|
companyData, err := companyRep.FindOne(map[string]interface{}{
|
|
|
"id": param.CompanyId,
|
|
|
})
|
|
|
if err != nil {
|
|
|
log.Logger.Error("获取公司信息," + err.Error())
|
|
|
return nil, application.ThrowError(application.TRANSACTION_ERROR, "获取公司信息,"+err.Error())
|
|
|
}
|
|
|
|
|
|
//获取用户数据
|
|
|
userRepo := factory.CreateUserRepository(map[string]interface{}{
|
|
|
"transactionContext": transactionContext,
|
|
|
})
|
|
|
userData, err := userRepo.FindOne(map[string]interface{}{
|
|
|
"id": param.UserId,
|
|
|
})
|
|
|
if err != nil {
|
|
|
log.Logger.Error("获取用户信息," + err.Error())
|
|
|
return nil, application.ThrowError(application.TRANSACTION_ERROR, "获取用户信息,"+err.Error())
|
|
|
}
|
|
|
departmentRepo := factory.CreateDepartmentRepository(map[string]interface{}{
|
|
|
"transactionContext": transactionContext,
|
|
|
})
|
|
|
var supperUserList []*domain.User
|
|
|
if len(userData.DepartmentId) > 0 {
|
|
|
_, departmentList, err := departmentRepo.Find(map[string]interface{}{
|
|
|
"ids": userData.DepartmentId,
|
|
|
})
|
|
|
if err != nil {
|
|
|
return nil, application.ThrowError(application.TRANSACTION_ERROR, "获取部门信息,"+err.Error())
|
|
|
}
|
|
|
var chargeUserIds []int64
|
|
|
for _, v := range departmentList {
|
|
|
chargeUserIds = append(chargeUserIds, v.ChargeUserIds...)
|
|
|
}
|
|
|
if len(chargeUserIds) > 0 {
|
|
|
_, supperUserList, err = userRepo.Find(map[string]interface{}{
|
|
|
"ids": chargeUserIds,
|
|
|
})
|
|
|
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())
|
|
|
}
|
|
|
listData := make([]adapter.AssessSelfList, 0, len(assessList))
|
|
|
var itemTemp adapter.AssessSelfList
|
|
|
for _, v := range assessList {
|
|
|
itemTemp = adapter.AssessSelfList{
|
|
|
AssessId: v.Id,
|
|
|
BeginTime: v.BeginTime.Local().Format("2006-01-02 15:04:05"),
|
|
|
EndTime: v.EndTime.Local().Format("2006-01-02 15:04:05"),
|
|
|
CycleId: v.CycleId,
|
|
|
CycleName: v.CycleName,
|
|
|
EvaluationProjectId: v.EvaluationProjectId,
|
|
|
EvaluationProjectName: v.EvaluationProjectName,
|
|
|
}
|
|
|
listData = append(listData, itemTemp)
|
|
|
}
|
|
|
userInfo := adapter.StaffInfo{
|
|
|
UserName: userData.Name,
|
|
|
CompanyName: companyData.Name,
|
|
|
SupperUserName: "",
|
|
|
DutyTime: userData.CreateAt.Local().Format("2006-01-02 15:04:05"),
|
|
|
}
|
|
|
for _, v := range supperUserList {
|
|
|
userInfo.SupperUserName = userInfo.SupperUserName + v.Name + ";"
|
|
|
}
|
|
|
result := tool_funs.SimpleWrapGridMap(int64(cnt), listData)
|
|
|
result["userInfo"] = userInfo
|
|
|
return result, nil
|
|
|
}
|
|
|
|
|
|
// 更具项目评估的配置,创建员工的评估任务
|
|
|
func (srv StaffAssessServeice) CreateStaffAssessTask(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()
|
|
|
}()
|
|
|
|
|
|
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()
|
|
|
//建立评估任务
|
|
|
assessTask := 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,
|
|
|
}
|
|
|
//填充评估环节
|
|
|
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,
|
|
|
}
|
|
|
assessTask.StepList = append(assessTask.StepList, step)
|
|
|
}
|
|
|
|
|
|
assessTaskRepo := factory.CreateStaffAssessTaskRepository(map[string]interface{}{
|
|
|
"transactionContext": transactionContext,
|
|
|
})
|
|
|
_, err = assessTaskRepo.Save(&assessTask)
|
|
|
if err != nil {
|
|
|
return nil, application.ThrowError(application.INTERNAL_SERVER_ERROR, "保存评估任务"+err.Error())
|
|
|
}
|
|
|
|
|
|
assessList, err := srv.createStaffAssess(transactionContext, &assessTask)
|
|
|
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 {
|
|
|
_, err = assessRepo.Save(&assessList[i])
|
|
|
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())
|
|
|
}
|
|
|
return map[string]interface{}{
|
|
|
"assessTaskId": assessTask.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 {
|
|
|
return nil, application.ThrowError(application.ARG_ERROR, "未填写评估任务的执行人")
|
|
|
}
|
|
|
userRepo := factory.CreateUserRepository(map[string]interface{}{
|
|
|
"transactionContext": transactionContext,
|
|
|
})
|
|
|
//获取员工信息
|
|
|
_, userList, err := userRepo.Find(map[string]interface{}{
|
|
|
"ids": selfUserId,
|
|
|
})
|
|
|
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 {
|
|
|
_, 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: domain.AssessSelf,
|
|
|
// 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
|
|
|
assessListTemp := srv.createStaffAssessSelf(stepSelfTemp, userList, userDepartmentMap)
|
|
|
assessList = append(assessList, assessListTemp...)
|
|
|
}
|
|
|
if v.LinkNodeType == domain.LinkNodeSuperiorAssessment {
|
|
|
// TODO
|
|
|
stepSelfTemp.BeginTime = v.BeginTime
|
|
|
stepSelfTemp.EndTime = v.EndTime
|
|
|
stepSelfTemp.LinkNodeId = v.LinkNodeId
|
|
|
stepSelfTemp.LinkNodeName = v.LinkNodeName
|
|
|
assessListTemp, err := srv.createStaffAssessSupper(transactionContext, stepSelfTemp, userList, userDepartmentMap)
|
|
|
if err != nil {
|
|
|
return nil, err
|
|
|
}
|
|
|
assessList = append(assessList, assessListTemp...)
|
|
|
}
|
|
|
}
|
|
|
return assessList, nil
|
|
|
}
|
|
|
|
|
|
// 构建员工自评
|
|
|
func (srv StaffAssessServeice) createStaffAssessSelf(assessTemp domain.StaffAssess,
|
|
|
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,
|
|
|
UserName: usr.Account,
|
|
|
}
|
|
|
assessTemp.Executor = domain.StaffDesc{
|
|
|
UserId: int(usr.Id),
|
|
|
Account: usr.Account,
|
|
|
UserName: usr.Account,
|
|
|
}
|
|
|
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,
|
|
|
})
|
|
|
}
|
|
|
}
|
|
|
result = append(result, assessTemp)
|
|
|
}
|
|
|
return result
|
|
|
}
|
|
|
|
|
|
// 构建员工上级评估
|
|
|
func (srv StaffAssessServeice) createStaffAssessSupper(
|
|
|
transactionContext application.TransactionContext,
|
|
|
assessTemp domain.StaffAssess,
|
|
|
userList []*domain.User, userDepartmentMap map[int64][]*domain.Department,
|
|
|
) ([]domain.StaffAssess, error) {
|
|
|
|
|
|
// 获取员工的上级用户
|
|
|
|
|
|
return nil, nil
|
|
|
}
|
|
|
|
|
|
// 获取某个员工360邀请的人员
|
|
|
func (srv StaffAssessServeice) GetAssessInviteUser(param *query.GetAssessInviteUserQuery) (*adapter.AssessInviteUserResp, 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,
|
|
|
})
|
|
|
|
|
|
assessTaskReps := factory.CreateStaffAssessTaskRepository(map[string]interface{}{
|
|
|
"transactionContext": transactionContext,
|
|
|
})
|
|
|
assessTaskData, err := assessTaskReps.FindOne(map[string]interface{}{
|
|
|
"id": param.AssessTaskId,
|
|
|
})
|
|
|
if err != nil {
|
|
|
return nil, application.ThrowError(application.ARG_ERROR, "获取评估任务"+err.Error())
|
|
|
}
|
|
|
_, assessList, err := assessReps.Find(map[string]interface{}{
|
|
|
"typesList": []string{string(domain.AssessInviteDiffSuper), string(domain.AssessInviteSameSuper)},
|
|
|
"staffAssessTaskId": param.AssessTaskId,
|
|
|
"targetUserId": param.UsrId,
|
|
|
})
|
|
|
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,
|
|
|
}
|
|
|
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
|
|
|
}
|
|
|
for _, v := range assessList {
|
|
|
if v.Types == domain.AssessInviteDiffSuper {
|
|
|
result.InviteDiffSuper = append(result.InviteDiffSuper, v.Executor)
|
|
|
}
|
|
|
if v.Types == domain.AssessInviteSameSuper {
|
|
|
result.InviteSameSuper = append(result.InviteDiffSuper, v.Executor)
|
|
|
}
|
|
|
}
|
|
|
return &result, nil
|
|
|
}
|
|
|
|
|
|
// 获取某个员工360邀请的人员
|
|
|
func (srv StaffAssessServeice) SaveAssessInviteUser(param *command.SaveAssessInvite) (*adapter.AssessInviteUserResp, error) {
|
|
|
inviteSameSuperId := []int{}
|
|
|
InviteDiffSuperId := []int{}
|
|
|
for _, v := range param.InviteDiffSuper {
|
|
|
id, err := strconv.Atoi(v)
|
|
|
if err != nil {
|
|
|
return nil, application.ThrowError(application.ARG_ERROR, "用户填写错误")
|
|
|
}
|
|
|
InviteDiffSuperId = append(InviteDiffSuperId, id)
|
|
|
}
|
|
|
for _, v := range param.InviteSameSuper {
|
|
|
id, err := strconv.Atoi(v)
|
|
|
if err != nil {
|
|
|
return nil, application.ThrowError(application.ARG_ERROR, "用户填写错误")
|
|
|
}
|
|
|
inviteSameSuperId = append(inviteSameSuperId, id)
|
|
|
}
|
|
|
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,
|
|
|
})
|
|
|
userRepo := factory.CreateUserRepository(map[string]interface{}{
|
|
|
"transactionContext": transactionContext,
|
|
|
})
|
|
|
departmentRepo := factory.CreateDepartmentRepository(map[string]interface{}{
|
|
|
"transactionContext": transactionContext,
|
|
|
})
|
|
|
|
|
|
assessTaskReps := factory.CreateStaffAssessTaskRepository(map[string]interface{}{
|
|
|
"transactionContext": transactionContext,
|
|
|
})
|
|
|
assessTaskData, err := assessTaskReps.FindOne(map[string]interface{}{
|
|
|
"id": param.AssessTaskId,
|
|
|
})
|
|
|
if err != nil {
|
|
|
return nil, application.ThrowError(application.ARG_ERROR, "获取评估任务"+err.Error())
|
|
|
}
|
|
|
|
|
|
targetUser, err := userRepo.FindOne(map[string]interface{}{
|
|
|
"id": param.TargetUserId,
|
|
|
})
|
|
|
if err != nil {
|
|
|
return nil, application.ThrowError(application.ARG_ERROR, "获取被评估员工"+err.Error())
|
|
|
}
|
|
|
//被评估人的部门
|
|
|
var targetUserDepartment []domain.StaffDepartment
|
|
|
if len(targetUser.DepartmentId) > 0 {
|
|
|
_, departmentList, err := departmentRepo.Find(map[string]interface{}{
|
|
|
"ids": targetUser.DepartmentId,
|
|
|
})
|
|
|
if err != nil {
|
|
|
return nil, application.ThrowError(application.ARG_ERROR, "获取部门信息"+err.Error())
|
|
|
}
|
|
|
for _, v := range departmentList {
|
|
|
targetUserDepartment = append(targetUserDepartment, domain.StaffDepartment{
|
|
|
DepartmentId: int(v.Id),
|
|
|
DepartmentName: v.Name,
|
|
|
})
|
|
|
}
|
|
|
}
|
|
|
//邀请的相同上级的员工
|
|
|
var inviteSameSuper []domain.StaffDesc
|
|
|
if len(inviteSameSuperId) > 0 {
|
|
|
_, userList, err := userRepo.Find(map[string]interface{}{
|
|
|
"ids": inviteSameSuperId,
|
|
|
})
|
|
|
if err != nil {
|
|
|
return nil, application.ThrowError(application.ARG_ERROR, "获取用户信息"+err.Error())
|
|
|
}
|
|
|
for _, v := range userList {
|
|
|
inviteSameSuper = append(inviteSameSuper, domain.StaffDesc{
|
|
|
UserId: int(v.Id),
|
|
|
UserName: v.Name,
|
|
|
Account: v.Account,
|
|
|
})
|
|
|
}
|
|
|
}
|
|
|
//邀请的不同上级的员工
|
|
|
var inviteDiffSuper []domain.StaffDesc
|
|
|
if len(InviteDiffSuperId) > 0 {
|
|
|
_, userList, err := userRepo.Find(map[string]interface{}{
|
|
|
"ids": InviteDiffSuperId,
|
|
|
})
|
|
|
if err != nil {
|
|
|
return nil, application.ThrowError(application.ARG_ERROR, "获取用户信息"+err.Error())
|
|
|
}
|
|
|
for _, v := range userList {
|
|
|
inviteDiffSuper = append(inviteDiffSuper, domain.StaffDesc{
|
|
|
UserId: int(v.Id),
|
|
|
UserName: v.Name,
|
|
|
Account: v.Account,
|
|
|
})
|
|
|
}
|
|
|
}
|
|
|
_ = assessReps
|
|
|
_ = inviteSameSuper
|
|
|
_ = inviteDiffSuper
|
|
|
_ = targetUserDepartment
|
|
|
// _, assessList, err := assessReps.Find(map[string]interface{}{
|
|
|
// "typesList": []string{string(domain.AssessInviteDiffSuper), string(domain.AssessInviteSameSuper)},
|
|
|
// "staffAssessTaskId": param.AssessTaskId,
|
|
|
// "targetUserId": param.TargetUserId,
|
|
|
// })
|
|
|
// if err != nil {
|
|
|
// return nil, application.ThrowError(application.ARG_ERROR, "获取个人评估任务"+err.Error())
|
|
|
// }
|
|
|
// TODO
|
|
|
|
|
|
if err := transactionContext.CommitTransaction(); err != nil {
|
|
|
return nil, application.ThrowError(application.INTERNAL_SERVER_ERROR, err.Error())
|
|
|
}
|
|
|
|
|
|
result := adapter.AssessInviteUserResp{
|
|
|
AssessTaskId: assessTaskData.Id,
|
|
|
}
|
|
|
// 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
|
|
|
// }
|
|
|
// for _, v := range assessList {
|
|
|
// if v.Types == domain.AssessInviteDiffSuper {
|
|
|
// result.InviteDiffSuper = append(result.InviteDiffSuper, v.Executor)
|
|
|
// }
|
|
|
// if v.Types == domain.AssessInviteSameSuper {
|
|
|
// result.InviteSameSuper = append(result.InviteDiffSuper, v.Executor)
|
|
|
// }
|
|
|
// }
|
|
|
return &result, nil
|
|
|
}
|
|
|
|
|
|
// 获取员工自评的评估内容详情
|
|
|
func (srv StaffAssessServeice) GetAssessSelfInfo(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,
|
|
|
"staffAssessTaskId": param.AssessTaskId,
|
|
|
"targetUserId": param.TargetUserId,
|
|
|
"typesList": []string{string(domain.AssessSelf)},
|
|
|
})
|
|
|
if err != nil {
|
|
|
return nil, application.ThrowError(application.INTERNAL_SERVER_ERROR, "获取员工的评估"+err.Error())
|
|
|
}
|
|
|
if len(assessList) == 0 {
|
|
|
return &adapter.AssessInfoResp{}, nil
|
|
|
}
|
|
|
assessData := assessList[0]
|
|
|
projectRepo := factory.CreateEvaluationProjectRepository(map[string]interface{}{
|
|
|
"transactionContext": transactionContext,
|
|
|
})
|
|
|
projectData, err := projectRepo.FindOne(map[string]interface{}{
|
|
|
"id": assessData.EvaluationProjectId,
|
|
|
})
|
|
|
if err != nil {
|
|
|
return nil, application.ThrowError(application.INTERNAL_SERVER_ERROR, "获取项目评估配置"+err.Error())
|
|
|
}
|
|
|
if projectData.Template == nil {
|
|
|
return nil, application.ThrowError(application.INTERNAL_SERVER_ERROR, "未获取到项目评估配置模板")
|
|
|
}
|
|
|
var selfLinkNode *domain.LinkNode
|
|
|
for _, v := range projectData.Template.LinkNodes {
|
|
|
if v.Type == domain.LinkNodeSelfAssessment {
|
|
|
selfLinkNode = v
|
|
|
break
|
|
|
}
|
|
|
}
|
|
|
if selfLinkNode == nil {
|
|
|
return nil, application.ThrowError(application.INTERNAL_SERVER_ERROR, "未获取到项目评估自评配置")
|
|
|
}
|
|
|
//获取员工评估的填写内容
|
|
|
// assessContentReps := factory.CreateStaffAssessContentRepository(map[string]interface{}{
|
|
|
// "transactionContext": transactionContext,
|
|
|
// })
|
|
|
// _, assessContentList, err := assessContentReps.Find(map[string]interface{}{
|
|
|
// "staffAssessId": assessData.Id,
|
|
|
// })
|
|
|
// 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())
|
|
|
}
|
|
|
|
|
|
result := adapter.AssessInfoResp{
|
|
|
CycleId: assessData.CycleId,
|
|
|
CycleName: assessData.CycleName,
|
|
|
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,
|
|
|
AssessContent: nil,
|
|
|
}
|
|
|
assessContent := make([]adapter.AssessContent, 0)
|
|
|
for _, v := range selfLinkNode.NodeContents {
|
|
|
assessContent = append(assessContent, adapter.AssessContent{
|
|
|
Category: v.Category,
|
|
|
Name: v.Name,
|
|
|
PromptTitle: v.PromptTitle,
|
|
|
PromptText: v.PromptText,
|
|
|
EntryItems: v.EntryItems,
|
|
|
})
|
|
|
}
|
|
|
result.AssessContent = assessContent
|
|
|
return &result, nil
|
|
|
} |
...
|
...
|
|