作者 tangxvhui

暂存

package query
type ListAssessInviteUserQuery struct {
CompanyId int `json:"companyId"` //对公司
UserId int `json:"userId"` //被评估的员工id
CycleId int `json:"CycleId"` //评估任务的周期id
BeginDay string `json:"beginDay"` //日期
}
... ...
... ... @@ -2,6 +2,7 @@ package service
import (
"fmt"
"strconv"
"github.com/linmadan/egglib-go/core/application"
"github.com/linmadan/egglib-go/utils/tool_funs"
... ... @@ -12,7 +13,7 @@ import (
"gitlab.fjmaimaimai.com/allied-creation/performance/pkg/infrastructure/dao"
)
//获取我的项目周期
//获取我的项目周期列表
func (srv StaffAssessServeice) SearchAssessCycelMe(param *query.SearchAssessMeQuery) (map[string]interface{}, error) {
transactionContext, err := factory.CreateTransactionContext(nil)
if err != nil {
... ... @@ -136,8 +137,8 @@ func (srv StaffAssessServeice) AssessCycleMeDesc(param *query.AssessCycleDescQue
if len(myAssessTask) > 0 {
//邀请别人评估自己
_, assessInviteData, err := staffAssessRepo.Find(map[string]interface{}{
// "staffAssessTaskId": assessTaskData.Id,
"targetUserId": param.UserId,
"staffAssessTaskId": myAssessTask[0].Id,
"targetUserId": param.UserId, //我被作为目标
"typesList": []string{string(domain.AssessInviteDiffSuper), string(domain.AssessInviteSameSuper)},
"limit": 5,
})
... ... @@ -160,13 +161,13 @@ func (srv StaffAssessServeice) AssessCycleMeDesc(param *query.AssessCycleDescQue
//我评估别人,被邀请评估
_, assessInviteList, err := staffAssessRepo.Find(map[string]interface{}{
"beginDay": param.BeginDay,
"executorId": param.UserId,
"cycleId": param.CycleId,
"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)
... ... @@ -180,7 +181,8 @@ func (srv StaffAssessServeice) AssessCycleMeDesc(param *query.AssessCycleDescQue
case domain.LinkNodeSuperiorAssessment:
//我评估别人,上级评估
_, assessSupperList, err := staffAssessRepo.Find(map[string]interface{}{
// "staffAssessTaskId": assessTaskData.Id,
"cycleId": param.CycleId,
"beginDay": param.BeginDay,
"executorId": param.UserId,
"typesList": []string{string(domain.AssessSuper)},
})
... ... @@ -209,3 +211,239 @@ func (srv StaffAssessServeice) AssessCycleMeDesc(param *query.AssessCycleDescQue
}
return &result, nil
}
//根据周期获取,我的自评任务的添加的邀请人
func (srv StaffAssessServeice) ListAssessInviteUser(param query.ListAssessInviteUserQuery) (*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,
})
assessTaskRepo := factory.CreateStaffAssessTaskRepository(map[string]interface{}{
"transactionContext": transactionContext,
})
_, myAssessTask, err := assessTaskRepo.Find(map[string]interface{}{
"cycleId": param.CycleId,
"beginDay": param.BeginDay,
"executorId": param.UserId,
"limit": 1,
})
if err != nil {
return nil, application.ThrowError(application.TRANSACTION_ERROR, "我的评估任务不存在,"+err.Error())
}
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,
"targetUserId": param.UserId,
})
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
}
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) ListExecutorInviteAssessDay(param *query.ListInviteUserAssessQuery) (
*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,
})
assessTaskRepo := factory.CreateStaffAssessTaskRepository(map[string]interface{}{
"transactionContext": transactionContext,
})
//获取 executorId 对应的360评估任务 用户
condition := map[string]interface{}{
"staffAssessTaskId": param.AssessTaskId,
"executorId": param.ExecutorId,
"typesList": []string{string(domain.AssessInviteDiffSuper), string(domain.AssessInviteSameSuper)},
"limit": 20,
}
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
if len(assessList) > 0 {
//获取评估用的所有评估项
assessContentList, err = srv.getAssessSelfInfoUncompleted(transactionContext, assessList[0])
if err != nil {
return nil, application.ThrowError(application.INTERNAL_SERVER_ERROR, "获取评估任务"+err.Error())
}
}
//可变的表格列
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)
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{}{
"staffAssessTaskId": param.AssessTaskId,
"executorId": param.ExecutorId,
"typesList": []string{string(domain.AssessInviteDiffSuper), string(domain.AssessInviteSameSuper)},
"status": domain.StaffAssessUncompleted,
})
if err != nil {
return nil, application.ThrowError(application.TRANSACTION_ERROR, "获取个人的评估环节"+err.Error())
}
assessTaskData, err := assessTaskRepo.FindOne(map[string]interface{}{
"id": param.AssessTaskId,
})
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...)
listData := []map[string]string{}
for _, v := range assessList {
m := map[string]string{
"userName": v.TargetUser.UserName,
"userId": strconv.Itoa(v.TargetUser.UserId),
"status": string(v.Status),
"types": string(v.Types),
"endTime": v.EndTime.Local().Format("2006-01-02 15:04:05"),
"assessId": strconv.Itoa(v.Id),
}
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,
}
for _, v := range assessTaskData.StepList {
if v.LinkNodeType == domain.LinkNodeAllAssessment {
result.LinkNodeId = v.LinkNodeId
result.LinkNodeName = v.LinkNodeName
result.LintNodeDesc = fmt.Sprintf("截止时间 %s 待评估%d人", v.EndTime.Local().Format("2006-01-02 15:04:05"), cnnt)
}
}
return &result, nil
}
... ...