作者 tangxvhui

暂存

  1 +package query
  2 +
  3 +type ListAssessInviteUserQuery struct {
  4 + CompanyId int `json:"companyId"` //对公司
  5 + UserId int `json:"userId"` //被评估的员工id
  6 + CycleId int `json:"CycleId"` //评估任务的周期id
  7 + BeginDay string `json:"beginDay"` //日期
  8 +}
@@ -2,6 +2,7 @@ package service @@ -2,6 +2,7 @@ package service
2 2
3 import ( 3 import (
4 "fmt" 4 "fmt"
  5 + "strconv"
5 6
6 "github.com/linmadan/egglib-go/core/application" 7 "github.com/linmadan/egglib-go/core/application"
7 "github.com/linmadan/egglib-go/utils/tool_funs" 8 "github.com/linmadan/egglib-go/utils/tool_funs"
@@ -12,7 +13,7 @@ import ( @@ -12,7 +13,7 @@ import (
12 "gitlab.fjmaimaimai.com/allied-creation/performance/pkg/infrastructure/dao" 13 "gitlab.fjmaimaimai.com/allied-creation/performance/pkg/infrastructure/dao"
13 ) 14 )
14 15
15 -//获取我的项目周期 16 +//获取我的项目周期列表
16 func (srv StaffAssessServeice) SearchAssessCycelMe(param *query.SearchAssessMeQuery) (map[string]interface{}, error) { 17 func (srv StaffAssessServeice) SearchAssessCycelMe(param *query.SearchAssessMeQuery) (map[string]interface{}, error) {
17 transactionContext, err := factory.CreateTransactionContext(nil) 18 transactionContext, err := factory.CreateTransactionContext(nil)
18 if err != nil { 19 if err != nil {
@@ -136,10 +137,10 @@ func (srv StaffAssessServeice) AssessCycleMeDesc(param *query.AssessCycleDescQue @@ -136,10 +137,10 @@ func (srv StaffAssessServeice) AssessCycleMeDesc(param *query.AssessCycleDescQue
136 if len(myAssessTask) > 0 { 137 if len(myAssessTask) > 0 {
137 //邀请别人评估自己 138 //邀请别人评估自己
138 _, assessInviteData, err := staffAssessRepo.Find(map[string]interface{}{ 139 _, assessInviteData, err := staffAssessRepo.Find(map[string]interface{}{
139 - // "staffAssessTaskId": assessTaskData.Id,  
140 - "targetUserId": param.UserId,  
141 - "typesList": []string{string(domain.AssessInviteDiffSuper), string(domain.AssessInviteSameSuper)},  
142 - "limit": 5, 140 + "staffAssessTaskId": myAssessTask[0].Id,
  141 + "targetUserId": param.UserId, //我被作为目标
  142 + "typesList": []string{string(domain.AssessInviteDiffSuper), string(domain.AssessInviteSameSuper)},
  143 + "limit": 5,
143 }) 144 })
144 if err != nil { 145 if err != nil {
145 return nil, application.ThrowError(application.TRANSACTION_ERROR, "获取个人的评估环节"+err.Error()) 146 return nil, application.ThrowError(application.TRANSACTION_ERROR, "获取个人的评估环节"+err.Error())
@@ -160,13 +161,13 @@ func (srv StaffAssessServeice) AssessCycleMeDesc(param *query.AssessCycleDescQue @@ -160,13 +161,13 @@ func (srv StaffAssessServeice) AssessCycleMeDesc(param *query.AssessCycleDescQue
160 //我评估别人,被邀请评估 161 //我评估别人,被邀请评估
161 _, assessInviteList, err := staffAssessRepo.Find(map[string]interface{}{ 162 _, assessInviteList, err := staffAssessRepo.Find(map[string]interface{}{
162 "beginDay": param.BeginDay, 163 "beginDay": param.BeginDay,
163 - "executorId": param.UserId, 164 + "cycleId": param.CycleId,
  165 + "executorId": param.UserId, //我作为执行人
164 "typesList": []string{string(domain.AssessInviteDiffSuper), string(domain.AssessInviteSameSuper)}, 166 "typesList": []string{string(domain.AssessInviteDiffSuper), string(domain.AssessInviteSameSuper)},
165 }) 167 })
166 if err != nil { 168 if err != nil {
167 return nil, application.ThrowError(application.TRANSACTION_ERROR, "获取个人的评估环节"+err.Error()) 169 return nil, application.ThrowError(application.TRANSACTION_ERROR, "获取个人的评估环节"+err.Error())
168 } 170 }
169 -  
170 if len(assessInviteList) > 0 { 171 if len(assessInviteList) > 0 {
171 stepItem.Status = string(domain.StaffAssessCompleted) 172 stepItem.Status = string(domain.StaffAssessCompleted)
172 stepItem.Desc = fmt.Sprintf("截止日期:%s", stepItem.EndTime) 173 stepItem.Desc = fmt.Sprintf("截止日期:%s", stepItem.EndTime)
@@ -180,7 +181,8 @@ func (srv StaffAssessServeice) AssessCycleMeDesc(param *query.AssessCycleDescQue @@ -180,7 +181,8 @@ func (srv StaffAssessServeice) AssessCycleMeDesc(param *query.AssessCycleDescQue
180 case domain.LinkNodeSuperiorAssessment: 181 case domain.LinkNodeSuperiorAssessment:
181 //我评估别人,上级评估 182 //我评估别人,上级评估
182 _, assessSupperList, err := staffAssessRepo.Find(map[string]interface{}{ 183 _, assessSupperList, err := staffAssessRepo.Find(map[string]interface{}{
183 - // "staffAssessTaskId": assessTaskData.Id, 184 + "cycleId": param.CycleId,
  185 + "beginDay": param.BeginDay,
184 "executorId": param.UserId, 186 "executorId": param.UserId,
185 "typesList": []string{string(domain.AssessSuper)}, 187 "typesList": []string{string(domain.AssessSuper)},
186 }) 188 })
@@ -209,3 +211,239 @@ func (srv StaffAssessServeice) AssessCycleMeDesc(param *query.AssessCycleDescQue @@ -209,3 +211,239 @@ func (srv StaffAssessServeice) AssessCycleMeDesc(param *query.AssessCycleDescQue
209 } 211 }
210 return &result, nil 212 return &result, nil
211 } 213 }
  214 +
  215 +//根据周期获取,我的自评任务的添加的邀请人
  216 +func (srv StaffAssessServeice) ListAssessInviteUser(param query.ListAssessInviteUserQuery) (*adapter.AssessInviteUserResp, error) {
  217 + transactionContext, err := factory.CreateTransactionContext(nil)
  218 + if err != nil {
  219 + return nil, application.ThrowError(application.TRANSACTION_ERROR, err.Error())
  220 + }
  221 + if err := transactionContext.StartTransaction(); err != nil {
  222 + return nil, application.ThrowError(application.TRANSACTION_ERROR, err.Error())
  223 + }
  224 + defer func() {
  225 + _ = transactionContext.RollbackTransaction()
  226 + }()
  227 +
  228 + assessReps := factory.CreateStaffAssessRepository(map[string]interface{}{
  229 + "transactionContext": transactionContext,
  230 + })
  231 +
  232 + assessTaskRepo := factory.CreateStaffAssessTaskRepository(map[string]interface{}{
  233 + "transactionContext": transactionContext,
  234 + })
  235 + _, myAssessTask, err := assessTaskRepo.Find(map[string]interface{}{
  236 + "cycleId": param.CycleId,
  237 + "beginDay": param.BeginDay,
  238 + "executorId": param.UserId,
  239 + "limit": 1,
  240 + })
  241 + if err != nil {
  242 + return nil, application.ThrowError(application.TRANSACTION_ERROR, "我的评估任务不存在,"+err.Error())
  243 + }
  244 +
  245 + if len(myAssessTask) == 0 {
  246 + return nil, application.ThrowError(application.TRANSACTION_ERROR, "未参与本次的自评")
  247 + }
  248 +
  249 + assessTaskData := myAssessTask[0]
  250 +
  251 + _, assessList, err := assessReps.Find(map[string]interface{}{
  252 + "typesList": []string{string(domain.AssessInviteDiffSuper), string(domain.AssessInviteSameSuper)},
  253 + "staffAssessTaskId": assessTaskData.Id,
  254 + "targetUserId": param.UserId,
  255 + })
  256 + if err != nil {
  257 + return nil, application.ThrowError(application.ARG_ERROR, "获取个人邀请列表"+err.Error())
  258 + }
  259 + if err := transactionContext.CommitTransaction(); err != nil {
  260 + return nil, application.ThrowError(application.INTERNAL_SERVER_ERROR, err.Error())
  261 + }
  262 +
  263 + result := adapter.AssessInviteUserResp{
  264 + AssessTaskId: assessTaskData.Id,
  265 + InviteDiffSuper: []domain.StaffDesc{},
  266 + InviteSameSuper: []domain.StaffDesc{},
  267 + }
  268 + for _, v := range assessTaskData.StepList {
  269 + if v.LinkNodeType != domain.LinkNodeAllInvite {
  270 + continue
  271 + }
  272 + result.LinkNodeId = v.LinkNodeId
  273 + result.LinkNodeName = v.LinkNodeName
  274 + result.BeginTime = v.BeginTime.Local().Format("2006-01-02 15:04:05")
  275 + result.EndTime = v.EndTime.Local().Format("2006-01-02 15:04:05")
  276 + break
  277 + }
  278 + for _, v := range assessList {
  279 + if v.Types == domain.AssessInviteDiffSuper {
  280 + result.InviteDiffSuper = append(result.InviteDiffSuper, v.Executor)
  281 + }
  282 + if v.Types == domain.AssessInviteSameSuper {
  283 + result.InviteSameSuper = append(result.InviteDiffSuper, v.Executor)
  284 + }
  285 + }
  286 + return &result, nil
  287 +}
  288 +
  289 +// 根据周期和日期获取我要执行的的360评估,用户列表和评估填写的值
  290 +func (srv StaffAssessServeice) ListExecutorInviteAssessDay(param *query.ListInviteUserAssessQuery) (
  291 + *adapter.ListInviteUserAssessResp, error) {
  292 + transactionContext, err := factory.CreateTransactionContext(nil)
  293 + if err != nil {
  294 + return nil, application.ThrowError(application.TRANSACTION_ERROR, err.Error())
  295 + }
  296 + if err := transactionContext.StartTransaction(); err != nil {
  297 + return nil, application.ThrowError(application.TRANSACTION_ERROR, err.Error())
  298 + }
  299 + defer func() {
  300 + _ = transactionContext.RollbackTransaction()
  301 + }()
  302 + //获取对应的评估任务
  303 + assessRepo := factory.CreateStaffAssessRepository(map[string]interface{}{
  304 + "transactionContext": transactionContext,
  305 + })
  306 + assessTaskRepo := factory.CreateStaffAssessTaskRepository(map[string]interface{}{
  307 + "transactionContext": transactionContext,
  308 + })
  309 +
  310 + //获取 executorId 对应的360评估任务 用户
  311 + condition := map[string]interface{}{
  312 + "staffAssessTaskId": param.AssessTaskId,
  313 + "executorId": param.ExecutorId,
  314 + "typesList": []string{string(domain.AssessInviteDiffSuper), string(domain.AssessInviteSameSuper)},
  315 + "limit": 20,
  316 + }
  317 + if param.PageSize > 0 {
  318 + condition["limit"] = param.PageSize
  319 + }
  320 + offset := (param.PageNumber - 1) * param.PageSize
  321 + if offset > 0 {
  322 + condition["offset"] = offset
  323 + }
  324 +
  325 + cnt, assessList, err := assessRepo.Find(condition)
  326 + if err != nil {
  327 + return nil, application.ThrowError(application.INTERNAL_SERVER_ERROR, err.Error())
  328 + }
  329 + var assessContentList []*domain.StaffAssessContent
  330 + if len(assessList) > 0 {
  331 + //获取评估用的所有评估项
  332 + assessContentList, err = srv.getAssessSelfInfoUncompleted(transactionContext, assessList[0])
  333 + if err != nil {
  334 + return nil, application.ThrowError(application.INTERNAL_SERVER_ERROR, "获取评估任务"+err.Error())
  335 + }
  336 + }
  337 + //可变的表格列
  338 + changeableHeader := []adapter.ListTableHeader{}
  339 + //列名与字段对应
  340 + keyMap := map[string]string{}
  341 + for i, v := range assessContentList {
  342 + name := fmt.Sprintf("%s-%s", v.Category, v.Name)
  343 + key := fmt.Sprintf("k%d", i)
  344 + keyMap[name] = key
  345 + changeableHeader = append(changeableHeader, adapter.ListTableHeader{
  346 + Key: key,
  347 + Name: name,
  348 + })
  349 + }
  350 + assessContentRepo := factory.CreateStaffAssessContentRepository(map[string]interface{}{
  351 + "transactionContext": transactionContext,
  352 + })
  353 + // 获取已经填报的内容
  354 + changeableRows := map[int]map[string]string{}
  355 + for _, v := range assessList {
  356 + _, contentList, err := assessContentRepo.Find(map[string]interface{}{
  357 + "staffAssessId": v.Id,
  358 + })
  359 + if err != nil {
  360 + return nil, application.ThrowError(application.INTERNAL_SERVER_ERROR, "获取评估内容"+err.Error())
  361 + }
  362 + row := map[string]string{}
  363 + for _, vv := range contentList {
  364 + name := fmt.Sprintf("%s-%s", vv.Category, vv.Name)
  365 + if kk, ok := keyMap[name]; ok {
  366 + row[kk] = vv.Value
  367 + }
  368 + }
  369 + changeableRows[v.TargetUser.UserId] = row
  370 + }
  371 +
  372 + //获取360邀请评估完成情况
  373 + //我评估别人,被邀请评估
  374 + cnnt, _, err := assessRepo.Find(map[string]interface{}{
  375 + "staffAssessTaskId": param.AssessTaskId,
  376 + "executorId": param.ExecutorId,
  377 + "typesList": []string{string(domain.AssessInviteDiffSuper), string(domain.AssessInviteSameSuper)},
  378 + "status": domain.StaffAssessUncompleted,
  379 + })
  380 + if err != nil {
  381 + return nil, application.ThrowError(application.TRANSACTION_ERROR, "获取个人的评估环节"+err.Error())
  382 + }
  383 +
  384 + assessTaskData, err := assessTaskRepo.FindOne(map[string]interface{}{
  385 + "id": param.AssessTaskId,
  386 + })
  387 + if err != nil {
  388 + return nil, application.ThrowError(application.TRANSACTION_ERROR, "获取评估任务"+err.Error())
  389 + }
  390 + if err := transactionContext.CommitTransaction(); err != nil {
  391 + return nil, application.ThrowError(application.INTERNAL_SERVER_ERROR, err.Error())
  392 + }
  393 +
  394 + //评估填写数据行转列
  395 + tableHeader := []adapter.ListTableHeader{
  396 + {Key: "userName", Name: "姓名"},
  397 + {Key: "status", Name: "状态"},
  398 + {Key: "types", Name: "360°评估关系"},
  399 + {Key: "endTime", Name: "360°评估截止日期"},
  400 + }
  401 + tableHeader = append(tableHeader, changeableHeader...)
  402 + listData := []map[string]string{}
  403 + for _, v := range assessList {
  404 + m := map[string]string{
  405 + "userName": v.TargetUser.UserName,
  406 + "userId": strconv.Itoa(v.TargetUser.UserId),
  407 + "status": string(v.Status),
  408 + "types": string(v.Types),
  409 + "endTime": v.EndTime.Local().Format("2006-01-02 15:04:05"),
  410 + "assessId": strconv.Itoa(v.Id),
  411 + }
  412 + switch v.Status {
  413 + case domain.StaffAssessCompleted:
  414 + m["status"] = "已经完成"
  415 + case domain.StaffAssessUncompleted:
  416 + m["status"] = "未完成"
  417 + }
  418 +
  419 + switch v.Types {
  420 + case domain.AssessInviteDiffSuper:
  421 + m["types"] = "不同上级同事"
  422 + case domain.AssessInviteSameSuper:
  423 + m["types"] = "相同上级同事"
  424 + }
  425 + if row, ok := changeableRows[v.TargetUser.UserId]; ok {
  426 + for k, v := range row {
  427 + m[k] = v
  428 + }
  429 + } else {
  430 + for _, v := range changeableHeader {
  431 + m[v.Key] = ""
  432 + }
  433 + }
  434 + listData = append(listData, m)
  435 + }
  436 + result := adapter.ListInviteUserAssessResp{
  437 + TableHeader: tableHeader,
  438 + List: listData,
  439 + Total: cnt,
  440 + }
  441 + for _, v := range assessTaskData.StepList {
  442 + if v.LinkNodeType == domain.LinkNodeAllAssessment {
  443 + result.LinkNodeId = v.LinkNodeId
  444 + result.LinkNodeName = v.LinkNodeName
  445 + result.LintNodeDesc = fmt.Sprintf("截止时间 %s 待评估%d人", v.EndTime.Local().Format("2006-01-02 15:04:05"), cnnt)
  446 + }
  447 + }
  448 + return &result, nil
  449 +}