fusenapi/model/gmodel/fs_product_template_basemap_logic.go
laodaming 1a48387e92 fix
2023-06-25 11:28:37 +08:00

41 lines
1.2 KiB
Go

package gmodel
import (
"context"
"gorm.io/gorm"
)
// TODO: 使用model的属性做你想做的
func (bm *FsProductTemplateBasemapModel) GetAllEnabledList(ctx context.Context, fields ...string) (resp []FsProductTemplateBasemap, err error) {
db := bm.db.WithContext(ctx).Model(&FsProductTemplateBasemap{}).Where("`status` = ? ", 1)
if len(fields) != 0 {
db = db.Select(fields[0])
}
err = db.Find(&resp).Error
return resp, err
}
func (bm *FsProductTemplateBasemapModel) UpdateBaseMapWithTransaction(ctx context.Context, dataList []FsProductTemplateBasemap) error {
return bm.db.WithContext(ctx).Transaction(func(tx *gorm.DB) error {
notInIds := make([]int64, 0, len(dataList))
//更新
for _, v := range dataList {
notInIds = append(notInIds, v.Id)
err := tx.Where("`id` = ? ", v.Id).Updates(&v).Error
if err != nil {
return err
}
}
if len(notInIds) == 0 {
return nil
}
//删除不在ids里面的
return tx.Model(&FsProductTemplateBasemap{}).
Where("`status` = ? and `id` not in (?)", 1, notInIds).Update("status", 0).Error
})
}
func (bm *FsProductTemplateBasemapModel) Create(ctx context.Context, data *FsProductTemplateBasemap) error {
return bm.db.WithContext(ctx).Create(&data).Error
}