68 lines
1.8 KiB
Go
68 lines
1.8 KiB
Go
package dao
|
|
|
|
import (
|
|
"errors"
|
|
"yintai-api/app/common/model"
|
|
|
|
"gorm.io/gorm"
|
|
)
|
|
|
|
type ProcessTranslations struct {
|
|
db *gorm.DB
|
|
}
|
|
|
|
func NewProcessTranslations(db ...*gorm.DB) *ProcessTranslations {
|
|
return &ProcessTranslations{db: getDB(db...)}
|
|
}
|
|
|
|
func (r *ProcessTranslations) TableName() string {
|
|
return "yt_process_translations"
|
|
}
|
|
|
|
func (r *ProcessTranslations) Create(m *model.ProcessTranslations) error {
|
|
return r.db.Table(r.TableName()).Create(m).Error
|
|
}
|
|
|
|
func (r *ProcessTranslations) Update(m *model.ProcessTranslations) error {
|
|
return r.db.Table(r.TableName()).Where("process_id = ? AND lang = ?", m.ProcessID, m.Lang).Save(m).Error
|
|
}
|
|
|
|
func (r *ProcessTranslations) Delete(id int64) error {
|
|
return r.db.Table(r.TableName()).Where("process_id = ?", id).Delete(&ProcessTranslations{}).Error
|
|
}
|
|
|
|
func (r *ProcessTranslations) Get(id int64) (*model.ProcessTranslations, error) {
|
|
var res model.ProcessTranslations
|
|
if err := r.db.Table(r.TableName()).Where("id = ?", id).First(&res).Error; err != nil {
|
|
if errors.Is(err, gorm.ErrRecordNotFound) {
|
|
return nil, nil
|
|
}
|
|
return nil, err
|
|
}
|
|
return &res, nil
|
|
}
|
|
|
|
func (r *ProcessTranslations) GetByMaster(masterID int64, lang string) (*model.ProcessTranslations, error) {
|
|
var res model.ProcessTranslations
|
|
tx := r.db.Table(r.TableName()).Where("process_id = ? AND lang = ?", masterID, lang).First(&res)
|
|
if tx.Error != nil {
|
|
if errors.Is(tx.Error, gorm.ErrRecordNotFound) {
|
|
return nil, nil
|
|
}
|
|
return nil, tx.Error
|
|
}
|
|
return &res, nil
|
|
}
|
|
|
|
func (r *ProcessTranslations) Exists(id int64) (bool, error) {
|
|
var count int64
|
|
if err := r.db.Table(r.TableName()).Where("id = ?", id).Count(&count).Error; err != nil {
|
|
return false, err
|
|
}
|
|
return count > 0, nil
|
|
}
|
|
|
|
func (r *ProcessTranslations) List(...any) ([]*model.ProcessTranslations, int64, error) {
|
|
panic("implement me")
|
|
}
|