作者 tangxvhui

更新

  1 +package command
  2 +
  3 +type CancelAttentionCommand struct {
  4 + TaskId int `json:"taskId,string"`
  5 + UserId int `json:"-"`
  6 + CompanyId int `json:"-"`
  7 +}
@@ -479,3 +479,23 @@ func (t TaskService) canUpdateTask(taskData *domain.Task, stageList []*domain.Ta @@ -479,3 +479,23 @@ func (t TaskService) canUpdateTask(taskData *domain.Task, stageList []*domain.Ta
479 func (t TaskService) ListTask2() error { 479 func (t TaskService) ListTask2() error {
480 return nil 480 return nil
481 } 481 }
  482 +
  483 +// CancelAttention 用户取消关注某个任务
  484 +func (t TaskService) CancelAttention(param *command.CancelAttentionCommand) error {
  485 + transactionContext, err := factory.CreateTransactionContext(nil)
  486 + if err != nil {
  487 + return application.ThrowError(application.TRANSACTION_ERROR, err.Error())
  488 + }
  489 + if err := transactionContext.StartTransaction(); err != nil {
  490 + return application.ThrowError(application.TRANSACTION_ERROR, err.Error())
  491 + }
  492 + defer func() {
  493 + _ = transactionContext.RollbackTransaction()
  494 + }()
  495 + //0
  496 + //0
  497 + if err := transactionContext.CommitTransaction(); err != nil {
  498 + return application.ThrowError(application.INTERNAL_SERVER_ERROR, err.Error())
  499 + }
  500 + return nil
  501 +}
@@ -6,8 +6,9 @@ type TaskStageState int @@ -6,8 +6,9 @@ type TaskStageState int
6 6
7 const ( 7 const (
8 TaskStageUncompleted TaskStageState = 1 //里程碑未完成 8 TaskStageUncompleted TaskStageState = 1 //里程碑未完成
9 - TaskStageCompleted TaskStageState = 2 //里程碑完成  
10 - TaskStageCompletedOverdue TaskStageState = 3 //里程碑预期完成 9 + TaskStageCompletedOverdue TaskStageState = 2 //里程碑逾期完成
  10 + TaskStageCompleted TaskStageState = 3 //里程碑完成
  11 +
11 ) 12 )
12 13
13 // 任务阶段 14 // 任务阶段
1 package repository 1 package repository
2 2
3 import ( 3 import (
  4 + "errors"
  5 + "fmt"
  6 + "time"
  7 +
  8 + "github.com/go-pg/pg/v10"
4 pgTransaction "github.com/linmadan/egglib-go/transaction/pg" 9 pgTransaction "github.com/linmadan/egglib-go/transaction/pg"
5 "gitlab.fjmaimaimai.com/allied-creation/performance/pkg/domain" 10 "gitlab.fjmaimaimai.com/allied-creation/performance/pkg/domain"
  11 + "gitlab.fjmaimaimai.com/allied-creation/performance/pkg/infrastructure/pg/models"
6 ) 12 )
7 13
8 //任务 14 //任务
@@ -13,18 +19,81 @@ type TaskIgnoreRepository struct { @@ -13,18 +19,81 @@ type TaskIgnoreRepository struct {
13 19
14 var _ domain.TaskIgnoreRepository = (*TaskIgnoreRepository)(nil) 20 var _ domain.TaskIgnoreRepository = (*TaskIgnoreRepository)(nil)
15 21
  22 +func (repo *TaskIgnoreRepository) TransformToDomain(d *models.TaskIgnore) *domain.TaskIgnore {
  23 + return &domain.TaskIgnore{
  24 + Id: d.Id,
  25 + TaskId: d.TaskId,
  26 + UserId: d.UserId,
  27 + CreatedAt: d.CreatedAt,
  28 + }
  29 +}
  30 +
16 func (repo *TaskIgnoreRepository) Save(param *domain.TaskIgnore) error { 31 func (repo *TaskIgnoreRepository) Save(param *domain.TaskIgnore) error {
17 - panic("not implemented") // TODO: Implement 32 + if param.Id == 0 {
  33 + param.CreatedAt = time.Now()
  34 + return nil
  35 + }
  36 + m := models.TaskIgnore{
  37 + Id: param.Id,
  38 + TaskId: param.TaskId,
  39 + UserId: param.UserId,
  40 + CreatedAt: param.CreatedAt,
  41 + }
  42 + db := repo.transactionContext.PgTx
  43 + if m.Id == 0 {
  44 + _, err := db.Model(&m).Insert()
  45 + if err != nil {
  46 + return err
  47 + }
  48 + } else {
  49 + _, err := db.Model(&m).WherePK().Update()
  50 + if err != nil {
  51 + return err
  52 + }
  53 + }
  54 + param.Id = m.Id
  55 + return nil
18 } 56 }
19 57
20 func (repo *TaskIgnoreRepository) Remove(id int) error { 58 func (repo *TaskIgnoreRepository) Remove(id int) error {
21 - panic("not implemented") // TODO: Implement 59 + tx := repo.transactionContext.PgTx
  60 + _, err := tx.Model(&models.TaskIgnore{}).
  61 + Where("id=?", id).Delete()
  62 + return err
22 } 63 }
23 64
24 func (repo *TaskIgnoreRepository) FindOne(queryOptions map[string]interface{}) (*domain.TaskIgnore, error) { 65 func (repo *TaskIgnoreRepository) FindOne(queryOptions map[string]interface{}) (*domain.TaskIgnore, error) {
25 - panic("not implemented") // TODO: Implement 66 + tx := repo.transactionContext.PgTx
  67 + m := new(models.TaskIgnore)
  68 + query := tx.Model(m)
  69 + query.Where("deleted_at isnull")
  70 + if id, ok := queryOptions["id"]; ok {
  71 + query.Where("id=?", id)
  72 + }
  73 + if err := query.First(); err != nil {
  74 + if errors.Is(err, pg.ErrNoRows) {
  75 + return nil, fmt.Errorf("没有找到 task_ignore 数据")
  76 + } else {
  77 + return nil, err
  78 + }
  79 + }
  80 + u := repo.TransformToDomain(m)
  81 + return u, nil
26 } 82 }
27 83
28 func (repo *TaskIgnoreRepository) Find(queryOptions map[string]interface{}) (int, []*domain.TaskIgnore, error) { 84 func (repo *TaskIgnoreRepository) Find(queryOptions map[string]interface{}) (int, []*domain.TaskIgnore, error) {
29 - panic("not implemented") // TODO: Implement 85 + tx := repo.transactionContext.PgTx
  86 + var m []*models.TaskIgnore
  87 + query := tx.Model(&m)
  88 + query.Order("id desc")
  89 + count, err := query.SelectAndCount()
  90 + if err != nil {
  91 + return 0, nil, err
  92 + }
  93 + var datas []*domain.TaskIgnore
  94 + for _, v := range m {
  95 + d := repo.TransformToDomain(v)
  96 + datas = append(datas, d)
  97 + }
  98 + return count, datas, nil
30 } 99 }