作者 tangxvhui

新添加数据库操作

... ... @@ -168,3 +168,27 @@ func CreateStaffAssessCacheRepository(options map[string]interface{}) domain.Sta
}
return repository.NewStaffAssessCacheRepository(transactionContext)
}
func CreateSummaryEvaluationRepository(options map[string]interface{}) domain.SummaryEvaluationRepository {
var transactionContext *pg.TransactionContext
if value, ok := options["transactionContext"]; ok {
transactionContext = value.(*pg.TransactionContext)
}
return repository.NewSummaryEvaluationRepository(transactionContext)
}
func CreateSummaryEvaluationValueRepository(options map[string]interface{}) domain.SummaryEvaluationValueRepository {
var transactionContext *pg.TransactionContext
if value, ok := options["transactionContext"]; ok {
transactionContext = value.(*pg.TransactionContext)
}
return repository.NewSummaryEvaluationValueRepository(transactionContext)
}
func CreateEvaluationItemUsedRepository(options map[string]interface{}) domain.EvaluationItemUsedRepository {
var transactionContext *pg.TransactionContext
if value, ok := options["transactionContext"]; ok {
transactionContext = value.(*pg.TransactionContext)
}
return repository.NewEvaluationItemUsedRepository(transactionContext)
}
... ...
... ... @@ -24,6 +24,6 @@ type EvaluationItemUsed struct {
}
type EvaluationItemUsedRepository interface {
Insert(Item []*EvaluationItemUsed) error
Find(queryOptions map[string]interface{}) (int64, []*EvaluationItemUsed, error)
BatchInsert(Item []*EvaluationItemUsed) error
Find(queryOptions map[string]interface{}) (int, []*EvaluationItemUsed, error)
}
... ...
... ... @@ -8,7 +8,8 @@ import (
// 实际被应用的评估条目
type EvaluationItemUsed struct {
Id int //id
tableName struct{} `comment:"实际被应用的评估条目" pg:"evaluation_item_used"`
Id int `pg:",pk"` //id
CompanyId int //公司id
EvaluationProjectId int //对应的项目id
NodeId int //填写评估评估节点对应id
... ...
... ... @@ -3,6 +3,7 @@ package repository
import (
pgTransaction "github.com/linmadan/egglib-go/transaction/pg"
"gitlab.fjmaimaimai.com/allied-creation/performance/pkg/domain"
"gitlab.fjmaimaimai.com/allied-creation/performance/pkg/infrastructure/pg/models"
)
type EvaluationItemUsedRepository struct {
... ... @@ -15,33 +16,76 @@ func NewEvaluationItemUsedRepository(transactionContext *pgTransaction.Transacti
return &EvaluationItemUsedRepository{transactionContext: transactionContext}
}
// func (repo *EvaluationItemUsedRepository) TransformToDomain(d *models.SummaryEvaluation) *domain.SummaryEvaluation {
// return &domain.SummaryEvaluation{
// Id: d.Id,
// CompanyId: d.CompanyId,
// EvaluationProjectId: d.EvaluationProjectId,
// EvaluationProjectName: d.EvaluationProjectName,
// CycleId: d.CycleId,
// CycleName: d.CycleName,
// TargetUser: d.TargetUser,
// TargetDepartment: d.TargetDepartment,
// Executor: d.Executor,
// Types: domain.EvaluationType(d.Types),
// Status: domain.EvaluationStatus(d.Status),
// CheckResult: d.CheckResult,
// BeginTime: d.BeginTime,
// EndTime: d.EndTime,
// TotalScore: d.TotalScore,
// CreatedAt: d.CreatedAt,
// UpdatedAt: d.UpdatedAt,
// DeletedAt: d.DeletedAt,
// }
// }
func (repo *EvaluationItemUsedRepository) TransformToDomain(d *models.EvaluationItemUsed) *domain.EvaluationItemUsed {
return &domain.EvaluationItemUsed{
Id: d.Id,
CompanyId: d.CompanyId,
EvaluationProjectId: d.EvaluationProjectId,
NodeId: d.NodeId,
NodeType: d.NodeType,
SortBy: d.SortBy,
Category: d.Category,
Name: d.Name,
PromptTitle: d.PromptTitle,
PromptText: d.PromptText,
EntryItems: d.EntryItems,
RuleType: d.RuleType,
Rule: d.Rule,
Weight: d.Weight,
Required: d.Required,
CreatedAt: d.CreatedAt,
UpdatedAt: d.UpdatedAt,
}
}
func (repo EvaluationItemUsedRepository) Insert(Item []*domain.EvaluationItemUsed) error {
panic("not implemented") // TODO: Implement
func (repo *EvaluationItemUsedRepository) BatchInsert(items []*domain.EvaluationItemUsed) error {
mList := []*models.EvaluationItemUsed{}
for _, v := range items {
m := models.EvaluationItemUsed{
Id: v.Id,
CompanyId: v.CompanyId,
EvaluationProjectId: v.EvaluationProjectId,
NodeId: v.NodeId,
NodeType: v.NodeType,
SortBy: v.SortBy,
Category: v.Category,
Name: v.Name,
PromptTitle: v.PromptTitle,
PromptText: v.PromptText,
EntryItems: v.EntryItems,
RuleType: v.RuleType,
Rule: v.Rule,
Weight: v.Weight,
Required: v.Required,
CreatedAt: v.CreatedAt,
UpdatedAt: v.UpdatedAt,
}
mList = append(mList, &m)
}
db := repo.transactionContext.PgTx
_, err := db.Model(&mList).Insert()
return err
}
func (repo EvaluationItemUsedRepository) Find(queryOptions map[string]interface{}) (int64, []*domain.EvaluationItemUsed, error) {
panic("not implemented") // TODO: Implement
func (repo *EvaluationItemUsedRepository) Find(queryOptions map[string]interface{}) (int, []*domain.EvaluationItemUsed, error) {
tx := repo.transactionContext.PgTx
var m []*models.EvaluationItemUsed
query := tx.Model(&m).
Where("deleted_at isnull").Limit(20)
if v, ok := queryOptions["limit"].(int); ok {
query.Limit(v)
}
if v, ok := queryOptions["offset"].(int); ok {
query.Offset(v)
}
count, err := query.SelectAndCount()
if err != nil {
return 0, nil, err
}
var datas []*domain.EvaluationItemUsed
for _, v := range m {
d := repo.TransformToDomain(v)
datas = append(datas, d)
}
return count, datas, nil
}
... ...