Merge branch 'develop' of https://gitee.com/fusenpack/fusenapi into develop
This commit is contained in:
@@ -1,6 +1,9 @@
|
||||
package gmodel
|
||||
|
||||
import "context"
|
||||
import (
|
||||
"context"
|
||||
"gorm.io/gorm"
|
||||
)
|
||||
|
||||
func (ml *FsMapLibraryModel) GetAllEnabledList(ctx context.Context, fields ...string) (resp []FsMapLibrary, err error) {
|
||||
db := ml.db.WithContext(ctx).Model(&FsMapLibrary{}).Where("`status` = ?", 1)
|
||||
@@ -25,3 +28,26 @@ func (ml *FsMapLibraryModel) ChangeStatusByIds(ctx context.Context, ids []int64,
|
||||
}
|
||||
return ml.db.WithContext(ctx).Model(&FsMapLibrary{}).Where("`id` in (?) ", ids).Update("status", 0).Error
|
||||
}
|
||||
func (ml *FsMapLibraryModel) SaveMapLibraryWithTransaction(ctx context.Context, createList []FsMapLibrary, updateList []FsMapLibrary) error {
|
||||
return ml.db.WithContext(ctx).Transaction(func(tx *gorm.DB) error {
|
||||
//创建
|
||||
for _, v := range createList {
|
||||
if err := tx.Model(&FsMapLibrary{}).Create(&v).Error; err != nil {
|
||||
return err
|
||||
}
|
||||
}
|
||||
if len(updateList) == 0 {
|
||||
return nil
|
||||
}
|
||||
//更新
|
||||
notInIds := make([]int64, 0, len(updateList))
|
||||
for _, v := range updateList {
|
||||
notInIds = append(notInIds, v.Id)
|
||||
if err := tx.Model(&FsMapLibrary{}).Where("`id` = ?", v.Id).Updates(&v).Error; err != nil {
|
||||
return err
|
||||
}
|
||||
}
|
||||
//删除
|
||||
return tx.Model(&FsMapLibrary{}).Where("`id` not in (?) ", notInIds).Update("status", 0).Error
|
||||
})
|
||||
}
|
||||
|
||||
@@ -16,10 +16,12 @@ func (bm *FsProductTemplateBasemapModel) GetAllEnabledList(ctx context.Context,
|
||||
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 {
|
||||
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
|
||||
@@ -29,14 +31,7 @@ func (bm *FsProductTemplateBasemapModel) UpdateBaseMapWithTransaction(ctx contex
|
||||
return nil
|
||||
}
|
||||
//删除不在ids里面的
|
||||
return bm.SoftDeleteByIdsNotIn(ctx, notInIds)
|
||||
return tx.Model(&FsProductTemplateBasemap{}).
|
||||
Where("`status` = ? and `id` not in (?)", 1, notInIds).Update("status", 0).Error
|
||||
})
|
||||
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
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user