fix: 更新数据库表名引用及配置

This commit is contained in:
2026-03-27 11:10:11 +08:00
parent b9ed1b2492
commit 70b8cf0316
12 changed files with 141 additions and 192 deletions

View File

@@ -23,7 +23,7 @@ func (d *assetDao) Insert(ctx context.Context, req *dto.CreateAssetReq) (id int6
if err = gconv.Struct(req, &res); err != nil {
return
}
r, err := gfdb.DB(ctx).Model(ctx, public.AssetCollection).Data(&res).Insert()
r, err := gfdb.DB(ctx).Model(ctx, public.TableNameAsset).Data(&res).Insert()
if err != nil {
return
}
@@ -32,7 +32,7 @@ func (d *assetDao) Insert(ctx context.Context, req *dto.CreateAssetReq) (id int6
// Update 更新资产
func (d *assetDao) Update(ctx context.Context, req *dto.UpdateAssetReq) (rows int64, err error) {
r, err := gfdb.DB(ctx).Model(ctx, public.AssetCollection).Data(&req).OmitEmpty().Where(entity.AssetCol.Id, req.Id).Update()
r, err := gfdb.DB(ctx).Model(ctx, public.TableNameAsset).Data(&req).OmitEmpty().Where(entity.AssetCol.Id, req.Id).Update()
if err != nil {
return
}
@@ -41,7 +41,7 @@ func (d *assetDao) Update(ctx context.Context, req *dto.UpdateAssetReq) (rows in
// Delete 删除资产-根据id进行假删
func (d *assetDao) Delete(ctx context.Context, req *dto.DeleteAssetReq) (rows int64, err error) {
r, err := gfdb.DB(ctx).Model(ctx, public.AssetCollection).Where(entity.AssetCol.Id, req.Id).Delete()
r, err := gfdb.DB(ctx).Model(ctx, public.TableNameAsset).Where(entity.AssetCol.Id, req.Id).Delete()
if err != nil {
return
}
@@ -50,7 +50,7 @@ func (d *assetDao) Delete(ctx context.Context, req *dto.DeleteAssetReq) (rows in
// GetOne 获取单个资产
func (d *assetDao) GetOne(ctx context.Context, req *dto.GetAssetReq, fields ...string) (res *entity.Asset, err error) {
r, err := gfdb.DB(ctx).Model(ctx, public.AssetCollection).Where(entity.AssetCol.Id, req.Id).Fields(fields).One()
r, err := gfdb.DB(ctx).Model(ctx, public.TableNameAsset).Where(entity.AssetCol.Id, req.Id).Fields(fields).One()
if err != nil {
return
}
@@ -81,7 +81,7 @@ func (d *assetDao) List(ctx context.Context, req *dto.ListAssetReq, fields ...st
// buildListFilter 构建列表查询的过滤条件
func (d *assetDao) buildListFilter(ctx context.Context, req *dto.ListAssetReq) *gdb.Model {
model := gfdb.DB(ctx).Model(ctx, public.AssetCollection).Model
model := gfdb.DB(ctx).Model(ctx, public.TableNameAsset).Cache(ctx)
if !g.IsEmpty(req.Keyword) {
model.WhereLike(entity.AssetCol.Name, "%"+req.Keyword+"%")
}

View File

@@ -23,7 +23,7 @@ func (d *assetSku) Insert(ctx context.Context, req *dto.CreateAssetSkuReq) (id i
if err = gconv.Struct(req, &res); err != nil {
return
}
r, err := gfdb.DB(ctx).Model(ctx, public.AssetSkuCollection).Data(&res).Insert()
r, err := gfdb.DB(ctx).Model(ctx, public.TableNameAssetSku).Data(&res).Insert()
if err != nil {
return
}
@@ -32,7 +32,7 @@ func (d *assetSku) Insert(ctx context.Context, req *dto.CreateAssetSkuReq) (id i
// Update 更新SKU
func (d *assetSku) Update(ctx context.Context, req *dto.UpdateAssetSkuReq) (rows int64, err error) {
r, err := gfdb.DB(ctx).Model(ctx, public.AssetSkuCollection).Data(&req).OmitEmpty().Where(entity.AssetCol.Id, req.Id).Update()
r, err := gfdb.DB(ctx).Model(ctx, public.TableNameAssetSku).Data(&req).OmitEmpty().Where(entity.AssetCol.Id, req.Id).Update()
if err != nil {
return
}
@@ -41,7 +41,7 @@ func (d *assetSku) Update(ctx context.Context, req *dto.UpdateAssetSkuReq) (rows
// Delete 删除SKU-根据id进行假删
func (d *assetSku) Delete(ctx context.Context, req *dto.DeleteAssetSkuReq) (rows int64, err error) {
r, err := gfdb.DB(ctx).Model(ctx, public.AssetSkuCollection).Where(entity.AssetSkuCol.Id, req.Id).Delete()
r, err := gfdb.DB(ctx).Model(ctx, public.TableNameAssetSku).Where(entity.AssetSkuCol.Id, req.Id).Delete()
if err != nil {
return
}
@@ -50,7 +50,7 @@ func (d *assetSku) Delete(ctx context.Context, req *dto.DeleteAssetSkuReq) (rows
// GetOne 获取单个SKU
func (d *assetSku) GetOne(ctx context.Context, req *dto.GetAssetSkuReq, fields ...string) (res *entity.AssetSku, err error) {
r, err := gfdb.DB(ctx).Model(ctx, public.AssetSkuCollection).Where(entity.AssetCol.Id, req.Id).Fields(fields).One()
r, err := gfdb.DB(ctx).Model(ctx, public.TableNameAssetSku).Where(entity.AssetCol.Id, req.Id).Fields(fields).One()
if err != nil {
return
}
@@ -60,7 +60,7 @@ func (d *assetSku) GetOne(ctx context.Context, req *dto.GetAssetSkuReq, fields .
// GetListByAssetIdExcludeCurrentSku 根据资产ID获取SKU列表并且排除当前SKU
func (d *assetSku) GetListByAssetIdExcludeCurrentSku(ctx context.Context, assetId int64, req *dto.ListAssetSkuReq, fields ...string) (res []entity.AssetSku, total int, err error) {
model := gfdb.DB(ctx).Model(ctx, public.AssetSkuCollection)
model := gfdb.DB(ctx).Model(ctx, public.TableNameAssetSku)
model.Fields(fields)
model.Where(entity.AssetSkuCol.AssetId, assetId)
model.WhereNot(entity.AssetSkuCol.Id, req.Id)
@@ -94,7 +94,7 @@ func (d *assetSku) List(ctx context.Context, req *dto.ListAssetSkuReq, fields ..
// buildListFilter 构建列表查询的过滤条件
func (d *assetSku) buildListFilter(ctx context.Context, req *dto.ListAssetSkuReq) *gdb.Model {
model := gfdb.DB(ctx).Model(ctx, public.AssetSkuCollection).Model
model := gfdb.DB(ctx).Model(ctx, public.TableNameAssetSku).Cache(ctx)
if !g.IsEmpty(req.Keyword) {
model.WhereLike(entity.AssetCol.Name, "%"+req.Keyword+"%")
model.WhereOrLike(entity.AssetSkuCol.SkuName, "%"+req.Keyword+"%")

View File

@@ -23,7 +23,7 @@ func (d *category) Insert(ctx context.Context, req *dto.CreateCategoryReq) (id i
if err = gconv.Struct(req, &res); err != nil {
return
}
r, err := gfdb.DB(ctx).Model(ctx, public.CategoryCollection).Insert(&res)
r, err := gfdb.DB(ctx).Model(ctx, public.TableNameCategory).Insert(&res)
if err != nil {
return
}
@@ -32,7 +32,7 @@ func (d *category) Insert(ctx context.Context, req *dto.CreateCategoryReq) (id i
// Update 更新分类
func (d *category) Update(ctx context.Context, req *dto.UpdateCategoryReq) (rows int64, err error) {
r, err := gfdb.DB(ctx).Model(ctx, public.CategoryCollection).Data(&req).OmitEmpty().Where(entity.CategoryCol.Id, req.Id).Update()
r, err := gfdb.DB(ctx).Model(ctx, public.TableNameCategory).Data(&req).OmitEmpty().Where(entity.CategoryCol.Id, req.Id).Update()
if err != nil {
return
}
@@ -41,7 +41,7 @@ func (d *category) Update(ctx context.Context, req *dto.UpdateCategoryReq) (rows
// Delete 删除分类-根据id及父id进行假删
func (d *category) Delete(ctx context.Context, req *dto.DeleteCategoryReq) (rows int64, err error) {
r, err := gfdb.DB(ctx).Model(ctx, public.CategoryCollection).Where(entity.CategoryCol.Id, req.Id).Delete()
r, err := gfdb.DB(ctx).Model(ctx, public.TableNameCategory).Where(entity.CategoryCol.Id, req.Id).Delete()
if err != nil {
return
}
@@ -50,7 +50,7 @@ func (d *category) Delete(ctx context.Context, req *dto.DeleteCategoryReq) (rows
// GetOne 获取单个分类
func (d *category) GetOne(ctx context.Context, req *dto.GetCategoryReq, fields ...string) (res *entity.Category, err error) {
r, err := gfdb.DB(ctx).Model(ctx, public.CategoryCollection).Where(entity.CategoryCol.Id, req.Id).Fields(fields).One()
r, err := gfdb.DB(ctx).Model(ctx, public.TableNameCategory).Where(entity.CategoryCol.Id, req.Id).Fields(fields).One()
if err != nil {
return
}
@@ -82,7 +82,7 @@ func (d *category) List(ctx context.Context, req *dto.ListCategoryReq, fields ..
// buildListFilter 构建列表查询的过滤条件
func (d *category) buildListFilter(ctx context.Context, req *dto.ListCategoryReq) *gdb.Model {
model := gfdb.DB(ctx).Model(ctx, public.CategoryCollection).Cache(ctx)
model := gfdb.DB(ctx).Model(ctx, public.TableNameCategory).Cache(ctx)
if !g.IsEmpty(req.Keyword) {
model.WhereLike(entity.CategoryCol.Name, "%"+req.Keyword+"%")
}

View File

@@ -154,14 +154,14 @@ func (d *location) DeleteByWarehouseId(ctx context.Context, warehouseId string)
// CountStockDetailsByLocationId 统计库位上的库存明细数量(用于删除前检查)
func (d *location) CountStockDetailsByLocationId(ctx context.Context, locationId string) (count int64, err error) {
filter := bson.M{"locationId": locationId}
count, err = mongo.DB().Count(ctx, filter, public.StockDetailsCollection)
count, err = mongo.DB().Count(ctx, filter, public.TableNameStockDetails)
return
}
// CountStockBatchByLocationId 统计库位上的批次库存数量(用于删除前检查)
func (d *location) CountStockBatchByLocationId(ctx context.Context, locationId string) (count int64, err error) {
filter := bson.M{"locationId": locationId}
count, err = mongo.DB().Count(ctx, filter, public.StockBatchCollection)
count, err = mongo.DB().Count(ctx, filter, public.TableNameStockBatch)
return
}

View File

@@ -27,7 +27,7 @@ func (d *stockBatch) Insert(ctx context.Context, req *dto.CreateSockBatchReq) (i
if err = gconv.Struct(req, &res); err != nil {
return
}
r, err := gfdb.DB(ctx).Model(ctx, public.StockBatchCollection).Data(&res).Insert()
r, err := gfdb.DB(ctx).Model(ctx, public.TableNameStockBatch).Data(&res).Insert()
if err != nil {
return
}
@@ -35,7 +35,7 @@ func (d *stockBatch) Insert(ctx context.Context, req *dto.CreateSockBatchReq) (i
}
func (d *stockBatch) Update(ctx context.Context, req *dto.UpdateSockBatchReq) (rows int64, err error) {
model := gfdb.DB(ctx).Model(ctx, public.StockBatchCollection).OmitEmpty().Where(entity.StockBatchCol.Id, req.Id)
model := gfdb.DB(ctx).Model(ctx, public.TableNameStockBatch).OmitEmpty().Where(entity.StockBatchCol.Id, req.Id)
model.Data(entity.StockBatchCol.BatchQty, &gdb.Counter{
Field: entity.StockBatchCol.BatchQty,
Value: gconv.Float64(req.BatchQty),
@@ -53,7 +53,7 @@ func (d *stockBatch) Update(ctx context.Context, req *dto.UpdateSockBatchReq) (r
// One 根据批次号查询使用NoCache跳过缓存确保获取最新数据
func (d *stockBatch) One(ctx context.Context, req *dto.GetSockBatchReq, fields ...string) (res *entity.StockBatch, err error) {
model := gfdb.DB(ctx).Model(ctx, public.StockBatchCollection)
model := gfdb.DB(ctx).Model(ctx, public.TableNameStockBatch)
if !g.IsEmpty(req.Id) {
model.Where(entity.StockBatchCol.Id, req.Id)
}

View File

@@ -26,7 +26,7 @@ func (d *stockDetails) BatchInsert(ctx context.Context, req []*dto.CreateSockDet
if err = gconv.Structs(req, &res); err != nil {
return
}
r, err := gfdb.DB(ctx).Model(ctx, public.StockDetailsCollection).Data(res).Save()
r, err := gfdb.DB(ctx).Model(ctx, public.TableNameStockDetails).Data(res).Save()
if err != nil {
return
}
@@ -34,7 +34,7 @@ func (d *stockDetails) BatchInsert(ctx context.Context, req []*dto.CreateSockDet
}
func (d *stockDetails) Delete(ctx context.Context, req []dto.DeleteSockDetailsReq) (rows int64, err error) {
r, err := gfdb.DB(ctx).Model(ctx, public.StockDetailsCollection).Where(entity.StockDetailsCol.Id, &req).Delete()
r, err := gfdb.DB(ctx).Model(ctx, public.TableNameStockDetails).Where(entity.StockDetailsCol.Id, &req).Delete()
if err != nil {
return
}
@@ -62,7 +62,7 @@ func (d *stockDetails) List(ctx context.Context, req *dto.GetSockDetailsReq, fie
// buildListFilter 构建列表查询的过滤条件
func (d *stockDetails) buildListFilter(ctx context.Context, req *dto.GetSockDetailsReq) *gdb.Model {
model := gfdb.DB(ctx).Model(ctx, public.StockDetailsCollection).Model
model := gfdb.DB(ctx).Model(ctx, public.TableNameStockDetails).Model
model.Where(entity.StockDetailsCol.Id, req.Id)
model.Where(entity.StockDetailsCol.AssetId, req.AssetId)
model.Where(entity.StockDetailsCol.AssetSkuId, req.AssetSkuId)