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, notInIds []int64) error { err := bm.db.WithContext(ctx).Transaction(func(tx *gorm.DB) error { //更新 for _, v := range dataList { err := tx.Where("`id` = ? ", v.Id).Updates(&v).Error if err != nil { return err } } if len(notInIds) == 0 { return nil } //删除不在ids里面的 return bm.SoftDeleteByIdsNotIn(ctx, notInIds) }) return err } func (bm *FsProductTemplateBasemapModel) SoftDeleteByIdsNotIn(ctx context.Context, notInIds []int64) error { if len(notInIds) == 0 { return nil } return bm.db.WithContext(ctx).Model(&FsProductTemplateBasemap{}). Where("`status` = ? and `id` not in (?)", 1, notInIds).Update("status", 0).Error }