作者 tangxvhui

剔除 无效代码

... ... @@ -161,14 +161,6 @@ func CreateStaffAssessTaskRepository(options map[string]interface{}) domain.Staf
return repository.NewStaffAssessTaskRepository(transactionContext)
}
func CreateStaffAssessContentTempRepository(options map[string]interface{}) domain.StaffAssessContentTempRepository {
var transactionContext *pg.TransactionContext
if value, ok := options["transactionContext"]; ok {
transactionContext = value.(*pg.TransactionContext)
}
return repository.NewStaffAssessContentTempRepository(transactionContext)
}
func CreateStaffAssessCacheRepository(options map[string]interface{}) domain.StaffAssessCacheRepository {
var transactionContext *pg.TransactionContext
if value, ok := options["transactionContext"]; ok {
... ...
package domain
import "time"
//填写的评估内容,临时保存的数据
type StaffAssessContentTemp struct {
Id int `json:"id"` //id
StaffAssessId int `json:"staffAssessId"` //用户需要的评估项id
SortBy int `json:"sortBy"` //排序
Category string `json:"category"` //类别
Name string `json:"name"` //名称
Remark []AssessContemtRemark `json:"remark"` //填写的反馈
Value string `json:"value"` //评估填写的值
CreatedAt time.Time `json:"createdAt"` //数据创建时间
UpdatedAt time.Time `json:"updatedAt"` //数据更新时间
}
type StaffAssessContentTempRepository interface {
Save(param *StaffAssessContentTemp) (*StaffAssessContentTemp, error)
Remove(id int) error
FindOne(queryOptions map[string]interface{}) (*StaffAssessContentTemp, error)
Find(queryOptions map[string]interface{}) (int, []*StaffAssessContentTemp, error)
}
package repository
import (
"errors"
"fmt"
"github.com/go-pg/pg/v10"
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 StaffAssessContentTempRepository struct {
transactionContext *pgTransaction.TransactionContext
}
var _ domain.StaffAssessContentTempRepository = (*StaffAssessContentTempRepository)(nil)
func NewStaffAssessContentTempRepository(transactionContext *pgTransaction.TransactionContext) *StaffAssessContentTempRepository {
return &StaffAssessContentTempRepository{transactionContext: transactionContext}
}
func (repo *StaffAssessContentTempRepository) TransformToDomain(d *models.StaffAssessContentTemp) *domain.StaffAssessContentTemp {
return &domain.StaffAssessContentTemp{
Id: d.Id,
StaffAssessId: d.StaffAssessId,
SortBy: d.SortBy,
Category: d.Category,
Name: d.Name,
Remark: d.Remark,
Value: d.Value,
CreatedAt: d.CreatedAt,
UpdatedAt: d.UpdatedAt,
}
}
func (repo *StaffAssessContentTempRepository) Save(d *domain.StaffAssessContentTemp) (*domain.StaffAssessContentTemp, error) {
saveModel := models.StaffAssessContentTemp{
Id: d.Id,
StaffAssessId: d.StaffAssessId,
SortBy: d.SortBy,
Category: d.Category,
Name: d.Name,
Remark: d.Remark,
Value: d.Value,
CreatedAt: d.CreatedAt,
UpdatedAt: d.UpdatedAt,
}
tx := repo.transactionContext.PgTx
var err error
if saveModel.Id == 0 {
_, err = tx.Model(&saveModel).Insert()
if err != nil {
return nil, err
}
} else {
_, err = tx.Model(&saveModel).WherePK().Update()
if err != nil {
return nil, err
}
}
d.Id = saveModel.Id
return d, nil
}
func (repo *StaffAssessContentTempRepository) Remove(id int) error {
tx := repo.transactionContext.PgTx
_, err := tx.Model(&models.StaffAssessContentTemp{}).
Where("id=?", id).Delete()
return err
}
func (repo *StaffAssessContentTempRepository) FindOne(queryOptions map[string]interface{}) (*domain.StaffAssessContentTemp, error) {
tx := repo.transactionContext.PgTx
m := new(models.StaffAssessContentTemp)
query := tx.Model(m)
if id, ok := queryOptions["id"]; ok {
query.Where("id=?", id)
}
if err := query.First(); err != nil {
if errors.Is(err, pg.ErrNoRows) {
return nil, fmt.Errorf("没有此资源")
} else {
return nil, err
}
}
u := repo.TransformToDomain(m)
return u, nil
}
func (repo *StaffAssessContentTempRepository) Find(queryOptions map[string]interface{}) (int, []*domain.StaffAssessContentTemp, error) {
tx := repo.transactionContext.PgTx
var m []*models.StaffAssessContentTemp
query := tx.Model(&m)
if companyId, ok := queryOptions["companyId"]; ok {
query.Where("company_id = ?", companyId)
}
if v, ok := queryOptions["staffAssessId"]; ok {
query.Where("staff_assess_id=?", v)
}
count, err := query.SelectAndCount()
if err != nil {
return 0, nil, err
}
var arrays []*domain.StaffAssessContentTemp
for _, v := range m {
d := repo.TransformToDomain(v)
arrays = append(arrays, d)
}
return count, arrays, nil
}