作者 tangxvhui

新添加数据库操作

@@ -168,3 +168,27 @@ func CreateStaffAssessCacheRepository(options map[string]interface{}) domain.Sta @@ -168,3 +168,27 @@ func CreateStaffAssessCacheRepository(options map[string]interface{}) domain.Sta
168 } 168 }
169 return repository.NewStaffAssessCacheRepository(transactionContext) 169 return repository.NewStaffAssessCacheRepository(transactionContext)
170 } 170 }
  171 +
  172 +func CreateSummaryEvaluationRepository(options map[string]interface{}) domain.SummaryEvaluationRepository {
  173 + var transactionContext *pg.TransactionContext
  174 + if value, ok := options["transactionContext"]; ok {
  175 + transactionContext = value.(*pg.TransactionContext)
  176 + }
  177 + return repository.NewSummaryEvaluationRepository(transactionContext)
  178 +}
  179 +
  180 +func CreateSummaryEvaluationValueRepository(options map[string]interface{}) domain.SummaryEvaluationValueRepository {
  181 + var transactionContext *pg.TransactionContext
  182 + if value, ok := options["transactionContext"]; ok {
  183 + transactionContext = value.(*pg.TransactionContext)
  184 + }
  185 + return repository.NewSummaryEvaluationValueRepository(transactionContext)
  186 +}
  187 +
  188 +func CreateEvaluationItemUsedRepository(options map[string]interface{}) domain.EvaluationItemUsedRepository {
  189 + var transactionContext *pg.TransactionContext
  190 + if value, ok := options["transactionContext"]; ok {
  191 + transactionContext = value.(*pg.TransactionContext)
  192 + }
  193 + return repository.NewEvaluationItemUsedRepository(transactionContext)
  194 +}
@@ -24,6 +24,6 @@ type EvaluationItemUsed struct { @@ -24,6 +24,6 @@ type EvaluationItemUsed struct {
24 } 24 }
25 25
26 type EvaluationItemUsedRepository interface { 26 type EvaluationItemUsedRepository interface {
27 - Insert(Item []*EvaluationItemUsed) error  
28 - Find(queryOptions map[string]interface{}) (int64, []*EvaluationItemUsed, error) 27 + BatchInsert(Item []*EvaluationItemUsed) error
  28 + Find(queryOptions map[string]interface{}) (int, []*EvaluationItemUsed, error)
29 } 29 }
@@ -8,7 +8,8 @@ import ( @@ -8,7 +8,8 @@ import (
8 8
9 // 实际被应用的评估条目 9 // 实际被应用的评估条目
10 type EvaluationItemUsed struct { 10 type EvaluationItemUsed struct {
11 - Id int //id 11 + tableName struct{} `comment:"实际被应用的评估条目" pg:"evaluation_item_used"`
  12 + Id int `pg:",pk"` //id
12 CompanyId int //公司id 13 CompanyId int //公司id
13 EvaluationProjectId int //对应的项目id 14 EvaluationProjectId int //对应的项目id
14 NodeId int //填写评估评估节点对应id 15 NodeId int //填写评估评估节点对应id
@@ -3,6 +3,7 @@ package repository @@ -3,6 +3,7 @@ package repository
3 import ( 3 import (
4 pgTransaction "github.com/linmadan/egglib-go/transaction/pg" 4 pgTransaction "github.com/linmadan/egglib-go/transaction/pg"
5 "gitlab.fjmaimaimai.com/allied-creation/performance/pkg/domain" 5 "gitlab.fjmaimaimai.com/allied-creation/performance/pkg/domain"
  6 + "gitlab.fjmaimaimai.com/allied-creation/performance/pkg/infrastructure/pg/models"
6 ) 7 )
7 8
8 type EvaluationItemUsedRepository struct { 9 type EvaluationItemUsedRepository struct {
@@ -15,33 +16,76 @@ func NewEvaluationItemUsedRepository(transactionContext *pgTransaction.Transacti @@ -15,33 +16,76 @@ func NewEvaluationItemUsedRepository(transactionContext *pgTransaction.Transacti
15 return &EvaluationItemUsedRepository{transactionContext: transactionContext} 16 return &EvaluationItemUsedRepository{transactionContext: transactionContext}
16 } 17 }
17 18
18 -// func (repo *EvaluationItemUsedRepository) TransformToDomain(d *models.SummaryEvaluation) *domain.SummaryEvaluation {  
19 -// return &domain.SummaryEvaluation{  
20 -// Id: d.Id,  
21 -// CompanyId: d.CompanyId,  
22 -// EvaluationProjectId: d.EvaluationProjectId,  
23 -// EvaluationProjectName: d.EvaluationProjectName,  
24 -// CycleId: d.CycleId,  
25 -// CycleName: d.CycleName,  
26 -// TargetUser: d.TargetUser,  
27 -// TargetDepartment: d.TargetDepartment,  
28 -// Executor: d.Executor,  
29 -// Types: domain.EvaluationType(d.Types),  
30 -// Status: domain.EvaluationStatus(d.Status),  
31 -// CheckResult: d.CheckResult,  
32 -// BeginTime: d.BeginTime,  
33 -// EndTime: d.EndTime,  
34 -// TotalScore: d.TotalScore,  
35 -// CreatedAt: d.CreatedAt,  
36 -// UpdatedAt: d.UpdatedAt,  
37 -// DeletedAt: d.DeletedAt,  
38 -// }  
39 -// } 19 +func (repo *EvaluationItemUsedRepository) TransformToDomain(d *models.EvaluationItemUsed) *domain.EvaluationItemUsed {
  20 + return &domain.EvaluationItemUsed{
  21 + Id: d.Id,
  22 + CompanyId: d.CompanyId,
  23 + EvaluationProjectId: d.EvaluationProjectId,
  24 + NodeId: d.NodeId,
  25 + NodeType: d.NodeType,
  26 + SortBy: d.SortBy,
  27 + Category: d.Category,
  28 + Name: d.Name,
  29 + PromptTitle: d.PromptTitle,
  30 + PromptText: d.PromptText,
  31 + EntryItems: d.EntryItems,
  32 + RuleType: d.RuleType,
  33 + Rule: d.Rule,
  34 + Weight: d.Weight,
  35 + Required: d.Required,
  36 + CreatedAt: d.CreatedAt,
  37 + UpdatedAt: d.UpdatedAt,
  38 + }
  39 +}
40 40
41 -func (repo EvaluationItemUsedRepository) Insert(Item []*domain.EvaluationItemUsed) error {  
42 - panic("not implemented") // TODO: Implement 41 +func (repo *EvaluationItemUsedRepository) BatchInsert(items []*domain.EvaluationItemUsed) error {
  42 + mList := []*models.EvaluationItemUsed{}
  43 + for _, v := range items {
  44 + m := models.EvaluationItemUsed{
  45 + Id: v.Id,
  46 + CompanyId: v.CompanyId,
  47 + EvaluationProjectId: v.EvaluationProjectId,
  48 + NodeId: v.NodeId,
  49 + NodeType: v.NodeType,
  50 + SortBy: v.SortBy,
  51 + Category: v.Category,
  52 + Name: v.Name,
  53 + PromptTitle: v.PromptTitle,
  54 + PromptText: v.PromptText,
  55 + EntryItems: v.EntryItems,
  56 + RuleType: v.RuleType,
  57 + Rule: v.Rule,
  58 + Weight: v.Weight,
  59 + Required: v.Required,
  60 + CreatedAt: v.CreatedAt,
  61 + UpdatedAt: v.UpdatedAt,
  62 + }
  63 + mList = append(mList, &m)
  64 + }
  65 + db := repo.transactionContext.PgTx
  66 + _, err := db.Model(&mList).Insert()
  67 + return err
43 } 68 }
44 69
45 -func (repo EvaluationItemUsedRepository) Find(queryOptions map[string]interface{}) (int64, []*domain.EvaluationItemUsed, error) {  
46 - panic("not implemented") // TODO: Implement 70 +func (repo *EvaluationItemUsedRepository) Find(queryOptions map[string]interface{}) (int, []*domain.EvaluationItemUsed, error) {
  71 + tx := repo.transactionContext.PgTx
  72 + var m []*models.EvaluationItemUsed
  73 + query := tx.Model(&m).
  74 + Where("deleted_at isnull").Limit(20)
  75 + if v, ok := queryOptions["limit"].(int); ok {
  76 + query.Limit(v)
  77 + }
  78 + if v, ok := queryOptions["offset"].(int); ok {
  79 + query.Offset(v)
  80 + }
  81 + count, err := query.SelectAndCount()
  82 + if err != nil {
  83 + return 0, nil, err
  84 + }
  85 + var datas []*domain.EvaluationItemUsed
  86 + for _, v := range m {
  87 + d := repo.TransformToDomain(v)
  88 + datas = append(datas, d)
  89 + }
  90 + return count, datas, nil
47 } 91 }