Dockerfile
This commit is contained in:
105
dao/procurement/purchase_inbound_dao.go
Normal file
105
dao/procurement/purchase_inbound_dao.go
Normal file
@@ -0,0 +1,105 @@
|
||||
package dao
|
||||
|
||||
import (
|
||||
"assets/consts/public"
|
||||
dto "assets/model/dto/procurement"
|
||||
entity "assets/model/entity/procurement"
|
||||
"context"
|
||||
|
||||
"gitea.com/red-future/common/beans"
|
||||
"gitea.com/red-future/common/db/mongo"
|
||||
"gitea.com/red-future/common/utils"
|
||||
"github.com/gogf/gf/v2/frame/g"
|
||||
"github.com/gogf/gf/v2/os/gtime"
|
||||
"go.mongodb.org/mongo-driver/v2/bson"
|
||||
)
|
||||
|
||||
type purchaseInbound struct{}
|
||||
|
||||
var PurchaseInbound = new(purchaseInbound)
|
||||
|
||||
// Insert 插入
|
||||
func (d *purchaseInbound) Insert(ctx context.Context, req *dto.CreatePurchaseInboundReq) (ids []interface{}, err error) {
|
||||
var result *entity.PurchaseInbound
|
||||
if err = utils.Struct(req, &result); err != nil {
|
||||
return
|
||||
}
|
||||
ids, err = mongo.DB().Insert(ctx, []interface{}{&result}, public.PurchaseInboundCollection)
|
||||
return
|
||||
}
|
||||
|
||||
// GetOne 查询单个
|
||||
func (d *purchaseInbound) GetOne(ctx context.Context, req *dto.GetPurchaseInboundReq) (res *entity.PurchaseInbound, err error) {
|
||||
filter := bson.M{"_id": req.Id}
|
||||
err = mongo.DB(false).FindOne(ctx, filter, &res, public.PurchaseInboundCollection)
|
||||
return
|
||||
}
|
||||
|
||||
// List 查询列表
|
||||
func (d *purchaseInbound) List(ctx context.Context, req *dto.ListPurchaseInboundReq) (list []entity.PurchaseInbound, total int64, err error) {
|
||||
filter := d.buildListFilter(req)
|
||||
var orderBy []beans.OrderBy
|
||||
if req.OrderBy.Field != "" {
|
||||
orderBy = []beans.OrderBy{req.OrderBy}
|
||||
}
|
||||
total, err = mongo.DB().Find(ctx, filter, &list, public.PurchaseInboundCollection, &req.Page, orderBy)
|
||||
return
|
||||
}
|
||||
|
||||
// UpdateDetails 更新入库记录详细信息
|
||||
func (d *purchaseInbound) UpdateDetails(ctx context.Context, id *bson.ObjectID, orderId *bson.ObjectID, inboundNo, batchNo, warehouseName, zoneName, locationName, privateSkuName, privateCategoryPath string) (err error) {
|
||||
filter := bson.M{"_id": id}
|
||||
update := bson.M{
|
||||
"$set": bson.M{
|
||||
"orderId": orderId,
|
||||
"inboundNo": inboundNo,
|
||||
"batchNo": batchNo,
|
||||
"warehouseName": warehouseName,
|
||||
"zoneName": zoneName,
|
||||
"locationName": locationName,
|
||||
"privateSkuName": privateSkuName,
|
||||
"privateCategoryPath": privateCategoryPath,
|
||||
},
|
||||
}
|
||||
_, err = mongo.DB().Update(ctx, filter, update, public.PurchaseInboundCollection)
|
||||
return
|
||||
}
|
||||
|
||||
// UpdatePrivateStockId 更新入库记录关联的库存ID
|
||||
func (d *purchaseInbound) UpdatePrivateStockId(ctx context.Context, id, privateStockId *bson.ObjectID) (err error) {
|
||||
filter := bson.M{"_id": id}
|
||||
update := bson.M{
|
||||
"$set": bson.M{
|
||||
"privateStockId": privateStockId,
|
||||
},
|
||||
}
|
||||
_, err = mongo.DB().Update(ctx, filter, update, public.PurchaseInboundCollection)
|
||||
return
|
||||
}
|
||||
|
||||
// buildListFilter 构建列表过滤条件
|
||||
func (d *purchaseInbound) buildListFilter(req *dto.ListPurchaseInboundReq) bson.M {
|
||||
filter := bson.M{}
|
||||
if !g.IsEmpty(req.OrderId) {
|
||||
filter["orderId"] = req.OrderId
|
||||
}
|
||||
if !g.IsEmpty(req.OrderItemId) {
|
||||
filter["orderItemId"] = req.OrderItemId
|
||||
}
|
||||
if !g.IsEmpty(req.InboundNo) {
|
||||
filter["inboundNo"] = bson.M{"$regex": req.InboundNo, "$options": "i"}
|
||||
}
|
||||
if !g.IsEmpty(req.StartDate) {
|
||||
startTime, _ := gtime.StrToTime(req.StartDate + " 00:00:00")
|
||||
filter["inboundDate"] = bson.M{"$gte": startTime}
|
||||
}
|
||||
if !g.IsEmpty(req.EndDate) {
|
||||
endTime, _ := gtime.StrToTime(req.EndDate + " 23:59:59")
|
||||
if filter["inboundDate"] != nil {
|
||||
filter["inboundDate"].(bson.M)["$lte"] = endTime
|
||||
} else {
|
||||
filter["inboundDate"] = bson.M{"$lte": endTime}
|
||||
}
|
||||
}
|
||||
return filter
|
||||
}
|
||||
113
dao/procurement/purchase_order_dao.go
Normal file
113
dao/procurement/purchase_order_dao.go
Normal file
@@ -0,0 +1,113 @@
|
||||
package dao
|
||||
|
||||
import (
|
||||
"assets/consts/public"
|
||||
dto "assets/model/dto/procurement"
|
||||
entity "assets/model/entity/procurement"
|
||||
"context"
|
||||
|
||||
"gitea.com/red-future/common/db/mongo"
|
||||
"gitea.com/red-future/common/utils"
|
||||
"github.com/gogf/gf/v2/frame/g"
|
||||
"go.mongodb.org/mongo-driver/v2/bson"
|
||||
)
|
||||
|
||||
var PurchaseOrder = new(purchaseOrder)
|
||||
|
||||
type purchaseOrder struct{}
|
||||
|
||||
// Insert 插入采购订单
|
||||
func (d *purchaseOrder) Insert(ctx context.Context, req *dto.CreatePurchaseOrderReq) (ids []any, err error) {
|
||||
var result *entity.PurchaseOrder
|
||||
if err = utils.Struct(req, &result); err != nil {
|
||||
return
|
||||
}
|
||||
ids, err = mongo.DB().Insert(ctx, []interface{}{&result}, public.PurchaseOrderCollection)
|
||||
return
|
||||
}
|
||||
|
||||
// BatchInsert 批量插入采购订单
|
||||
func (d *purchaseOrder) BatchInsert(ctx context.Context, req *dto.BatchCreatePurchaseOrdersReq) (ids []any, err error) {
|
||||
items := make([]*entity.PurchaseOrder, 0, len(req.Orders))
|
||||
for _, item := range req.Orders {
|
||||
var result *entity.PurchaseOrder
|
||||
if err = utils.Struct(item, &result); err != nil {
|
||||
return
|
||||
}
|
||||
items = append(items, result)
|
||||
}
|
||||
// 转换为 interface{} 切片
|
||||
interfaces := make([]interface{}, len(items))
|
||||
for i, item := range items {
|
||||
interfaces[i] = item
|
||||
}
|
||||
ids, err = mongo.DB().Insert(ctx, interfaces, public.PurchaseOrderCollection)
|
||||
return
|
||||
}
|
||||
|
||||
// GetOne 获取单个采购订单
|
||||
func (d *purchaseOrder) GetOne(ctx context.Context, id *bson.ObjectID) (order *entity.PurchaseOrder, err error) {
|
||||
filter := bson.M{"_id": id}
|
||||
err = mongo.DB().FindOne(ctx, filter, &order, public.PurchaseOrderCollection)
|
||||
return
|
||||
}
|
||||
|
||||
// Update 更新采购订单
|
||||
func (d *purchaseOrder) Update(ctx context.Context, req *dto.UpdatePurchaseOrderReq) (err error) {
|
||||
buildUpdateData, err := mongo.BuildUpdateData(ctx, req)
|
||||
if err != nil {
|
||||
return
|
||||
}
|
||||
filter := bson.M{"_id": req.ID}
|
||||
update := bson.M{"$set": buildUpdateData}
|
||||
_, err = mongo.DB().Update(ctx, filter, update, public.PurchaseOrderCollection)
|
||||
return
|
||||
}
|
||||
|
||||
// DeleteFake 删除采购订单-根据id进行假删
|
||||
func (d *purchaseOrder) DeleteFake(ctx context.Context, id *bson.ObjectID) (err error) {
|
||||
filter := bson.M{"_id": id}
|
||||
_, err = mongo.DB().DeleteSoft(ctx, filter, public.PurchaseOrderCollection)
|
||||
return
|
||||
}
|
||||
|
||||
// List 获取采购订单列表
|
||||
func (d *purchaseOrder) List(ctx context.Context, req *dto.ListPurchaseOrdersReq) (res []*entity.PurchaseOrder, total int64, err error) {
|
||||
filter, err := d.buildListFilter(ctx, req)
|
||||
if err != nil {
|
||||
return
|
||||
}
|
||||
|
||||
total, err = mongo.DB().Find(ctx, filter, &res, public.PurchaseOrderCollection, nil, nil)
|
||||
return
|
||||
}
|
||||
|
||||
// ListByBuyerId 根据采购方ID获取采购订单列表
|
||||
func (d *purchaseOrder) ListByBuyerId(ctx context.Context, buyerId *bson.ObjectID) (res []*entity.PurchaseOrder, err error) {
|
||||
filter := bson.M{"buyerId": buyerId}
|
||||
_, err = mongo.DB().Find(ctx, filter, &res, public.PurchaseOrderCollection, nil, nil)
|
||||
return
|
||||
}
|
||||
|
||||
// buildListFilter 构建列表查询的过滤条件
|
||||
func (d *purchaseOrder) buildListFilter(ctx context.Context, req *dto.ListPurchaseOrdersReq) (filter bson.M, err error) {
|
||||
_ = ctx
|
||||
filter = bson.M{}
|
||||
|
||||
if !g.IsEmpty(req.OrderNo) {
|
||||
filter["orderNo"] = req.OrderNo
|
||||
}
|
||||
if !g.IsEmpty(req.Title) {
|
||||
filter["title"] = bson.M{"$regex": req.Title, "$options": "i"}
|
||||
}
|
||||
if req.BuyerId != nil {
|
||||
filter["buyerId"] = req.BuyerId
|
||||
}
|
||||
if req.OrderType != "" {
|
||||
filter["orderType"] = req.OrderType
|
||||
}
|
||||
if req.Status != nil {
|
||||
filter["status"] = *req.Status
|
||||
}
|
||||
return
|
||||
}
|
||||
141
dao/procurement/purchase_order_item_dao.go
Normal file
141
dao/procurement/purchase_order_item_dao.go
Normal file
@@ -0,0 +1,141 @@
|
||||
package dao
|
||||
|
||||
import (
|
||||
"assets/consts/public"
|
||||
dto "assets/model/dto/procurement"
|
||||
entity "assets/model/entity/procurement"
|
||||
"context"
|
||||
|
||||
"gitea.com/red-future/common/db/mongo"
|
||||
"github.com/gogf/gf/v2/errors/gerror"
|
||||
"github.com/gogf/gf/v2/frame/g"
|
||||
"github.com/gogf/gf/v2/util/gconv"
|
||||
"go.mongodb.org/mongo-driver/v2/bson"
|
||||
)
|
||||
|
||||
var PurchaseOrderItem = new(purchaseOrderItem)
|
||||
|
||||
type purchaseOrderItem struct{}
|
||||
|
||||
// Insert 插入采购订单明细
|
||||
func (d *purchaseOrderItem) Insert(ctx context.Context, req *dto.CreatePurchaseOrderItemReq) (ids []any, err error) {
|
||||
var result *entity.PurchaseOrderItem
|
||||
if err = gconv.Struct(req, &result); err != nil {
|
||||
return
|
||||
}
|
||||
ids, err = mongo.DB().Insert(ctx, []interface{}{&result}, public.PurchaseOrderItemCollection)
|
||||
return
|
||||
}
|
||||
|
||||
// BatchInsert 批量插入采购订单明细
|
||||
func (d *purchaseOrderItem) BatchInsert(ctx context.Context, req *dto.BatchCreatePurchaseOrderItemsReq) (ids []any, err error) {
|
||||
items := make([]*entity.PurchaseOrderItem, 0, len(req.Items))
|
||||
for _, item := range req.Items {
|
||||
var result *entity.PurchaseOrderItem
|
||||
if err = gconv.Struct(item, &result); err != nil {
|
||||
return
|
||||
}
|
||||
items = append(items, result)
|
||||
}
|
||||
// 转换为 interface{} 切片
|
||||
interfaces := make([]interface{}, len(items))
|
||||
for i, item := range items {
|
||||
interfaces[i] = item
|
||||
}
|
||||
ids, err = mongo.DB().Insert(ctx, interfaces, public.PurchaseOrderItemCollection)
|
||||
return
|
||||
}
|
||||
|
||||
// GetOne 获取单个采购订单明细
|
||||
func (d *purchaseOrderItem) GetOne(ctx context.Context, id *bson.ObjectID) (item *entity.PurchaseOrderItem, err error) {
|
||||
filter := bson.M{"_id": id}
|
||||
err = mongo.DB().FindOne(ctx, filter, &item, public.PurchaseOrderItemCollection)
|
||||
return
|
||||
}
|
||||
|
||||
// Update 更新采购订单明细
|
||||
func (d *purchaseOrderItem) Update(ctx context.Context, req *dto.UpdatePurchaseOrderItemReq) (err error) {
|
||||
buildUpdateData, err := mongo.BuildUpdateData(ctx, req)
|
||||
if err != nil {
|
||||
return
|
||||
}
|
||||
filter := bson.M{"_id": req.ID}
|
||||
update := bson.M{"$set": buildUpdateData}
|
||||
_, err = mongo.DB().Update(ctx, filter, update, public.PurchaseOrderItemCollection)
|
||||
return
|
||||
}
|
||||
|
||||
// IncrementInboundQty 原子增加已入库数量(并发安全)
|
||||
// 使用$inc + $expr条件:inboundQty + deltaQty <= passQuantity,防止并发超量入库
|
||||
func (d *purchaseOrderItem) IncrementInboundQty(ctx context.Context, id *bson.ObjectID, deltaQty int) (err error) {
|
||||
filter := bson.M{
|
||||
"_id": id,
|
||||
"$expr": bson.M{
|
||||
"$lte": bson.A{
|
||||
bson.M{"$add": bson.A{"$inboundQty", deltaQty}},
|
||||
"$passQuantity",
|
||||
},
|
||||
},
|
||||
}
|
||||
update := bson.M{
|
||||
"$inc": bson.M{
|
||||
"inboundQty": deltaQty,
|
||||
},
|
||||
}
|
||||
modifiedCount, err := mongo.DB().Update(ctx, filter, update, public.PurchaseOrderItemCollection)
|
||||
if err != nil {
|
||||
return
|
||||
}
|
||||
if modifiedCount == 0 {
|
||||
return gerror.Newf("入库数量超出签收数量限制,本次入库%d", deltaQty)
|
||||
}
|
||||
return
|
||||
}
|
||||
|
||||
// DeleteFake 删除采购订单明细-根据id进行假删
|
||||
func (d *purchaseOrderItem) DeleteFake(ctx context.Context, id *bson.ObjectID) (err error) {
|
||||
filter := bson.M{"_id": id}
|
||||
_, err = mongo.DB().DeleteSoft(ctx, filter, public.PurchaseOrderItemCollection)
|
||||
return
|
||||
}
|
||||
|
||||
// List 获取采购订单明细列表
|
||||
func (d *purchaseOrderItem) List(ctx context.Context, req *dto.ListPurchaseOrderItemsReq) (res []*entity.PurchaseOrderItem, total int64, err error) {
|
||||
filter, err := d.buildListFilter(ctx, req)
|
||||
if err != nil {
|
||||
return
|
||||
}
|
||||
|
||||
total, err = mongo.DB().Find(ctx, filter, &res, public.PurchaseOrderItemCollection, nil, nil)
|
||||
return
|
||||
}
|
||||
|
||||
// ListByOrderId 根据订单ID获取采购订单明细列表
|
||||
func (d *purchaseOrderItem) ListByOrderId(ctx context.Context, orderId *bson.ObjectID) (res []*entity.PurchaseOrderItem, err error) {
|
||||
filter := bson.M{"orderId": orderId}
|
||||
_, err = mongo.DB().Find(ctx, filter, &res, public.PurchaseOrderItemCollection, nil, nil)
|
||||
return
|
||||
}
|
||||
|
||||
// buildListFilter 构建列表查询的过滤条件
|
||||
func (d *purchaseOrderItem) buildListFilter(ctx context.Context, req *dto.ListPurchaseOrderItemsReq) (filter bson.M, err error) {
|
||||
_ = ctx
|
||||
filter = bson.M{}
|
||||
|
||||
if req.OrderId != nil {
|
||||
filter["orderId"] = req.OrderId
|
||||
}
|
||||
if req.AssetId != nil {
|
||||
filter["assetId"] = req.AssetId
|
||||
}
|
||||
if req.AssetSkuId != nil {
|
||||
filter["assetSkuId"] = req.AssetSkuId
|
||||
}
|
||||
if !g.IsEmpty(req.ProductName) {
|
||||
filter["productName"] = bson.M{"$regex": req.ProductName, "$options": "i"}
|
||||
}
|
||||
if !g.IsEmpty(req.Brand) {
|
||||
filter["brand"] = bson.M{"$regex": req.Brand, "$options": "i"}
|
||||
}
|
||||
return
|
||||
}
|
||||
110
dao/procurement/supplier_dao.go
Normal file
110
dao/procurement/supplier_dao.go
Normal file
@@ -0,0 +1,110 @@
|
||||
package dao
|
||||
|
||||
import (
|
||||
"assets/consts/public"
|
||||
dto "assets/model/dto/procurement"
|
||||
entity "assets/model/entity/procurement"
|
||||
"context"
|
||||
|
||||
"gitea.com/red-future/common/db/mongo"
|
||||
"github.com/gogf/gf/v2/frame/g"
|
||||
"github.com/gogf/gf/v2/util/gconv"
|
||||
"go.mongodb.org/mongo-driver/v2/bson"
|
||||
)
|
||||
|
||||
var Supplier = new(supplier)
|
||||
|
||||
type supplier struct{}
|
||||
|
||||
// Insert 插入供应商
|
||||
func (d *supplier) Insert(ctx context.Context, req *dto.CreateSupplierReq) (ids []any, err error) {
|
||||
var result *entity.Supplier
|
||||
if err = gconv.Struct(req, &result); err != nil {
|
||||
return
|
||||
}
|
||||
ids, err = mongo.DB().Insert(ctx, []interface{}{&result}, public.SupplierCollection)
|
||||
return
|
||||
}
|
||||
|
||||
// BatchInsert 批量插入供应商
|
||||
func (d *supplier) BatchInsert(ctx context.Context, req *dto.BatchCreateSuppliersReq) (ids []any, err error) {
|
||||
items := make([]*entity.Supplier, 0, len(req.Suppliers))
|
||||
for _, item := range req.Suppliers {
|
||||
var result *entity.Supplier
|
||||
if err = gconv.Struct(item, &result); err != nil {
|
||||
return
|
||||
}
|
||||
items = append(items, result)
|
||||
}
|
||||
// 转换为 interface{} 切片
|
||||
interfaces := make([]interface{}, len(items))
|
||||
for i, item := range items {
|
||||
interfaces[i] = item
|
||||
}
|
||||
ids, err = mongo.DB().Insert(ctx, interfaces, public.SupplierCollection)
|
||||
return
|
||||
}
|
||||
|
||||
// GetOne 获取单个供应商
|
||||
func (d *supplier) GetOne(ctx context.Context, id *bson.ObjectID) (supplier *entity.Supplier, err error) {
|
||||
filter := bson.M{"_id": id}
|
||||
err = mongo.DB().FindOne(ctx, filter, &supplier, public.SupplierCollection)
|
||||
return
|
||||
}
|
||||
|
||||
// Update 更新供应商
|
||||
func (d *supplier) Update(ctx context.Context, req *dto.UpdateSupplierReq) (err error) {
|
||||
buildUpdateData, err := mongo.BuildUpdateData(ctx, req)
|
||||
if err != nil {
|
||||
return
|
||||
}
|
||||
filter := bson.M{"_id": req.ID}
|
||||
update := bson.M{"$set": buildUpdateData}
|
||||
_, err = mongo.DB().Update(ctx, filter, update, public.SupplierCollection)
|
||||
return
|
||||
}
|
||||
|
||||
// DeleteFake 删除供应商-根据id进行假删
|
||||
func (d *supplier) DeleteFake(ctx context.Context, id *bson.ObjectID) (err error) {
|
||||
filter := bson.M{"_id": id}
|
||||
_, err = mongo.DB().DeleteSoft(ctx, filter, public.SupplierCollection)
|
||||
return
|
||||
}
|
||||
|
||||
// List 获取供应商列表
|
||||
func (d *supplier) List(ctx context.Context, req *dto.ListSuppliersReq) (res []*entity.Supplier, total int64, err error) {
|
||||
filter, err := d.buildListFilter(ctx, req)
|
||||
if err != nil {
|
||||
return
|
||||
}
|
||||
|
||||
total, err = mongo.DB().Find(ctx, filter, &res, public.SupplierCollection, nil, nil)
|
||||
return
|
||||
}
|
||||
|
||||
// FindActiveSuppliers 获取活跃供应商列表
|
||||
func (d *supplier) FindActiveSuppliers(ctx context.Context) (res []*entity.Supplier, err error) {
|
||||
filter := bson.M{
|
||||
"status": 1, // consts.SupplierStatusActive
|
||||
"isDeleted": false,
|
||||
}
|
||||
_, err = mongo.DB().Find(ctx, filter, &res, public.SupplierCollection, nil, nil)
|
||||
return
|
||||
}
|
||||
|
||||
// buildListFilter 构建列表查询的过滤条件
|
||||
func (d *supplier) buildListFilter(ctx context.Context, req *dto.ListSuppliersReq) (filter bson.M, err error) {
|
||||
_ = ctx
|
||||
filter = bson.M{}
|
||||
|
||||
if !g.IsEmpty(req.Name) {
|
||||
filter["name"] = bson.M{"$regex": req.Name, "$options": "i"}
|
||||
}
|
||||
if !g.IsEmpty(req.Code) {
|
||||
filter["code"] = req.Code
|
||||
}
|
||||
if req.Status != nil {
|
||||
filter["status"] = *req.Status
|
||||
}
|
||||
return
|
||||
}
|
||||
Reference in New Issue
Block a user