fusenapi/model/gmodel/fs_product_design_logic.go
2023-08-10 19:08:06 +08:00

62 lines
2.0 KiB
Go
Executable File

package gmodel
import (
"context"
"gorm.io/gorm"
)
func (d *FsProductDesignModel) FindOneBySn(ctx context.Context, sn string, userId int64) (resp *FsProductDesign, err error) {
err = d.db.WithContext(ctx).Model(&FsProductDesign{}).Where("`sn` = ? and `user_id` = ? and `status` = ?", sn, userId, 1).First(&resp).Error
return resp, err
}
func (d *FsProductDesignModel) GetAllByIds(ctx context.Context, ids []int64) (resp []FsProductDesign, err error) {
if len(ids) == 0 {
return
}
err = d.db.WithContext(ctx).Model(&FsProductDesign{}).Where("`id` in (?) and `status` = ?", ids, 1).Find(&resp).Error
if err != nil {
return nil, err
}
return
}
func (d *FsProductDesignModel) GetAllByIdsWithoutStatus(ctx context.Context, ids []int64) (resp []FsProductDesign, err error) {
if len(ids) == 0 {
return
}
err = d.db.WithContext(ctx).Model(&FsProductDesign{}).Where("`id` in (?)", ids).Find(&resp).Error
if err != nil {
return nil, err
}
return
}
func (d *FsProductDesignModel) Create(ctx context.Context, data *FsProductDesign) error {
return d.db.WithContext(ctx).Model(&FsProductDesign{}).Create(&data).Error
}
func (d *FsProductDesignModel) UpdateBySn(ctx context.Context, sn string, data *FsProductDesign) error {
return d.db.WithContext(ctx).Model(&FsProductDesign{}).Where("`sn` = ?", sn).Updates(&data).Error
}
func (d *FsProductDesignModel) UpdateByIds(ctx context.Context, ids []int64, data *FsProductDesign) error {
return d.db.Table(d.name).WithContext(ctx).Model(&FsProductDesign{}).Where("`id` in ?", ids).Updates(&data).Error
}
func (d *FsProductDesignModel) RBUpdateByIds(rowBuilder *gorm.DB, ids []int64, data *FsProductDesign) error {
return rowBuilder.Where("`id` in ?", ids).Updates(&data).Error
}
func (m *FsProductDesignModel) BuilderTrans(ctx context.Context, selectData []string) *gorm.DB {
var rowBuilder = m.db.WithContext(ctx)
if selectData != nil {
rowBuilder = rowBuilder.Select(selectData)
} else {
rowBuilder = rowBuilder.Select("*")
}
return rowBuilder
}
func (m *FsProductDesignModel) TableName() string {
return m.name
}