作者 Your Name

更改查询我参与的评估任务

@@ -37,27 +37,40 @@ func (srv StaffAssessServeice) SearchAssessTaskMe(param *query.SearchAssessMeQue @@ -37,27 +37,40 @@ func (srv StaffAssessServeice) SearchAssessTaskMe(param *query.SearchAssessMeQue
37 defer func() { 37 defer func() {
38 _ = transactionContext.RollbackTransaction() 38 _ = transactionContext.RollbackTransaction()
39 }() 39 }()
40 - staffAssessTaskRepo := factory.CreateStaffAssessTaskRepository(map[string]interface{}{ 40 + // staffAssessTaskRepo := factory.CreateStaffAssessTaskRepository(map[string]interface{}{
  41 + // "transactionContext": transactionContext,
  42 + // })
  43 +
  44 + staffAssessTaskRepo := dao.NewStaffAssessDao(map[string]interface{}{
41 "transactionContext": transactionContext, 45 "transactionContext": transactionContext,
42 }) 46 })
43 - var limit int = 20 47 +
  48 + var limit int = 200
44 var offset int = 0 49 var offset int = 0
45 if param.PageSize > 0 { 50 if param.PageSize > 0 {
46 limit = param.PageSize 51 limit = param.PageSize
47 } 52 }
48 offset = (param.PageNumber - 1) * param.PageSize 53 offset = (param.PageNumber - 1) * param.PageSize
49 - condition := map[string]interface{}{  
50 - "executorId": param.UserId,  
51 - "companyId": param.CompanyId,  
52 - "limit": limit,  
53 - }  
54 - if offset > 0 {  
55 - condition["offset"] = offset 54 + assessTaskList, err := staffAssessTaskRepo.SearchAssessTaskMe(param.UserId, param.CompanyId, limit, offset)
  55 + if err != nil {
  56 + return nil, application.ThrowError(application.INTERNAL_SERVER_ERROR, "查询评估任务"+err.Error())
56 } 57 }
57 - cnt, assessTaskList, err := staffAssessTaskRepo.Find(condition) 58 + cnt, err := staffAssessTaskRepo.CountAssessTaskMe(param.UserId, param.CompanyId)
58 if err != nil { 59 if err != nil {
59 - return nil, application.ThrowError(application.INTERNAL_SERVER_ERROR, "查询周期"+err.Error()) 60 + return nil, application.ThrowError(application.INTERNAL_SERVER_ERROR, "查询评估任务"+err.Error())
60 } 61 }
  62 + // condition := map[string]interface{}{
  63 + // "executorId": param.UserId,
  64 + // "companyId": param.CompanyId,
  65 + // "limit": limit,
  66 + // }
  67 + // if offset > 0 {
  68 + // condition["offset"] = offset
  69 + // }
  70 + // cnt, assessTaskList, err := staffAssessTaskRepo.Find(condition)
  71 + // if err != nil {
  72 + // return nil, application.ThrowError(application.INTERNAL_SERVER_ERROR, "查询周期"+err.Error())
  73 + // }
61 if err := transactionContext.CommitTransaction(); err != nil { 74 if err := transactionContext.CommitTransaction(); err != nil {
62 return nil, application.ThrowError(application.INTERNAL_SERVER_ERROR, err.Error()) 75 return nil, application.ThrowError(application.INTERNAL_SERVER_ERROR, err.Error())
63 } 76 }
@@ -200,6 +213,7 @@ func (srv StaffAssessServeice) AssessTaskDesc(param *query.AssessTaskDescQuery) @@ -200,6 +213,7 @@ func (srv StaffAssessServeice) AssessTaskDesc(param *query.AssessTaskDescQuery)
200 } 213 }
201 } 214 }
202 if uncompletedNum > 0 { 215 if uncompletedNum > 0 {
  216 + stepItem.Status = string(domain.StaffAssessUncompleted)
203 stepItem.Desc = fmt.Sprintf("截止日期:%s 待评估%d人", stepItem.EndTime, uncompletedNum) 217 stepItem.Desc = fmt.Sprintf("截止日期:%s 待评估%d人", stepItem.EndTime, uncompletedNum)
204 } 218 }
205 } 219 }
@@ -332,15 +346,15 @@ func (srv StaffAssessServeice) AssessSelfList(param *query.AssessSelfListQuery) @@ -332,15 +346,15 @@ func (srv StaffAssessServeice) AssessSelfList(param *query.AssessSelfListQuery)
332 // 根据项目评估的配置,创建员工的评估任务 346 // 根据项目评估的配置,创建员工的评估任务
333 func (srv StaffAssessServeice) CreateStaffAssessTask(transactionContext application.TransactionContext, param *command.CreateStaffAssessTask) (map[string]interface{}, error) { 347 func (srv StaffAssessServeice) CreateStaffAssessTask(transactionContext application.TransactionContext, param *command.CreateStaffAssessTask) (map[string]interface{}, error) {
334 transactionContext, err := factory.CreateTransactionContext(nil) 348 transactionContext, err := factory.CreateTransactionContext(nil)
335 - if err != nil {  
336 - return nil, application.ThrowError(application.TRANSACTION_ERROR, err.Error())  
337 - }  
338 - if err := transactionContext.StartTransaction(); err != nil {  
339 - return nil, application.ThrowError(application.TRANSACTION_ERROR, err.Error())  
340 - }  
341 - defer func() {  
342 - _ = transactionContext.RollbackTransaction()  
343 - }() 349 + // if err != nil {
  350 + // return nil, application.ThrowError(application.TRANSACTION_ERROR, err.Error())
  351 + // }
  352 + // if err := transactionContext.StartTransaction(); err != nil {
  353 + // return nil, application.ThrowError(application.TRANSACTION_ERROR, err.Error())
  354 + // }
  355 + // defer func() {
  356 + // _ = transactionContext.RollbackTransaction()
  357 + // }()
344 log.Logger.Debug("CreateStaffAssessTask 获取参数", map[string]interface{}{ 358 log.Logger.Debug("CreateStaffAssessTask 获取参数", map[string]interface{}{
345 "param": param, 359 "param": param,
346 }) 360 })
@@ -454,9 +468,9 @@ func (srv StaffAssessServeice) CreateStaffAssessTask(transactionContext applicat @@ -454,9 +468,9 @@ func (srv StaffAssessServeice) CreateStaffAssessTask(transactionContext applicat
454 } 468 }
455 } 469 }
456 470
457 - if err := transactionContext.CommitTransaction(); err != nil {  
458 - return nil, application.ThrowError(application.INTERNAL_SERVER_ERROR, err.Error())  
459 - } 471 + // if err := transactionContext.CommitTransaction(); err != nil {
  472 + // return nil, application.ThrowError(application.INTERNAL_SERVER_ERROR, err.Error())
  473 + // }
460 return map[string]interface{}{ 474 return map[string]interface{}{
461 "assessTaskId": assessTaskData.Id, 475 "assessTaskId": assessTaskData.Id,
462 }, nil 476 }, nil
@@ -5,6 +5,7 @@ import ( @@ -5,6 +5,7 @@ import (
5 5
6 "github.com/go-pg/pg/v10" 6 "github.com/go-pg/pg/v10"
7 pgTransaction "github.com/linmadan/egglib-go/transaction/pg" 7 pgTransaction "github.com/linmadan/egglib-go/transaction/pg"
  8 + "gitlab.fjmaimaimai.com/allied-creation/performance/pkg/domain"
8 ) 9 )
9 10
10 type StaffAssessDao struct { 11 type StaffAssessDao struct {
@@ -54,3 +55,46 @@ func (d *StaffAssessDao) CountInviteAssessByTargetUser(userIds []int, assessTask @@ -54,3 +55,46 @@ func (d *StaffAssessDao) CountInviteAssessByTargetUser(userIds []int, assessTask
54 _, err := tx.Query(&result, sqlStr, condition...) 55 _, err := tx.Query(&result, sqlStr, condition...)
55 return result, err 56 return result, err
56 } 57 }
  58 +
  59 +// 搜索 executorId 参与的评估任务
  60 +func (d *StaffAssessDao) SearchAssessTaskMe(executorId int, companyId int, limit int, offset int) ([]*domain.StaffAssessTask, error) {
  61 +
  62 + if limit < 0 {
  63 + limit = 20
  64 + }
  65 + if offset < 0 {
  66 + offset = 0
  67 + }
  68 +
  69 + sqlStr := `SELECT DISTINCT staff_assess_task.* FROM staff_assess_task
  70 + JOIN staff_assess ON staff_assess_task."id" = staff_assess."staff_assess_task_id"
  71 + WHERE staff_assess.company_id=?
  72 + and staff_assess.executor->>'userId'='?'
  73 + limit ? offset ?
  74 + `
  75 + tx := d.transactionContext.PgTx
  76 + condition := []interface{}{
  77 + companyId, executorId, limit, offset,
  78 + }
  79 + result := []*domain.StaffAssessTask{}
  80 + _, err := tx.Query(&result, sqlStr, condition...)
  81 + return result, err
  82 +
  83 +}
  84 +
  85 +// 搜索 executorId 参与的评估任务
  86 +func (d *StaffAssessDao) CountAssessTaskMe(executorId int, companyId int) (int, error) {
  87 + sqlStr := `SELECT count( DISTINCT staff_assess_task."id") FROM staff_assess_task
  88 + JOIN staff_assess ON staff_assess_task."id" = staff_assess."staff_assess_task_id"
  89 + WHERE staff_assess.company_id=?
  90 + and staff_assess.executor->>'userId'='?'
  91 + `
  92 + tx := d.transactionContext.PgTx
  93 + condition := []interface{}{
  94 + companyId, executorId,
  95 + }
  96 + result := 0
  97 + _, err := tx.QueryOne(pg.Scan(&result), sqlStr, condition...)
  98 + return result, err
  99 +
  100 +}