liujiandao
2024-04-12 efbe2bd4bbc6444dad4ab5fe8d7e839c38230805
库存报表修改
2个文件已修改
65 ■■■■ 已修改文件
controllers/report_forms_controller.go 55 ●●●●● 补丁 | 查看 | 原始文档 | blame | 历史
models/location_product_amount.go 10 ●●●●● 补丁 | 查看 | 原始文档 | blame | 历史
controllers/report_forms_controller.go
@@ -32,9 +32,33 @@
// @Router    /api-wms/v1/forms/getInventoryForms [post]
func (slf ReportFormsController) GetInventoryForms(c *gin.Context) {
    var params request.GetInventoryForms
    if err := c.BindJSON(&params); err != nil {
    err := c.BindJSON(&params)
    if err != nil {
        util.ResponseFormat(c, code.RequestParamError, "参数解析失败,数据类型错误")
        return
    }
    locationIds := make([]int, 0)
    productIds := make([]string, 0)
    productAmounts := make([]*models.LocationProductAmount, 0)
    if params.WarehouseCode != "" {
        locations, err := models.NewLocationSearch().SetJointName(params.WarehouseCode).FindNotTotal()
        if err != nil {
            util.ResponseFormat(c, code.RequestParamError, "查询仓库位置失败")
            return
        }
        for _, location := range locations {
            locationIds = append(locationIds, location.Id)
        }
        productAmounts, err = models.NewLocationProductAmountSearch().SetLocationIds(locationIds).SetQuery("amount > 0").Find()
        if err != nil {
            util.ResponseFormat(c, code.RequestParamError, "查询在库数量失败")
            return
        }
        for _, amount := range productAmounts {
            productIds = append(productIds, amount.ProductId)
        }
    }
    //查询产品
    search := models.NewMaterialSearch()
@@ -46,6 +70,9 @@
    }
    if params.KeyWord != "" {
        search.Orm.Where("material.name like ?", "%"+params.KeyWord+"%").Or("wms_product_category.name like ?", "%"+params.KeyWord+"%")
    }
    if len(productIds) > 0 {
        search.Orm.Where("material.id in (?)", productIds)
    }
    var (
        materials = make([]*models.Material, 0)
@@ -63,24 +90,16 @@
        return
    }
    locations, err := models.NewLocationSearch().SetJointName(params.WarehouseCode).FindNotTotal()
    if err != nil {
        util.ResponseFormat(c, code.RequestParamError, "查询仓库位置失败")
        return
    }
    locationIds := make([]int, 0)
    for _, location := range locations {
        locationIds = append(locationIds, location.Id)
    }
    //查询在库数量
    productIds := make([]string, 0)
    for _, material := range materials {
        productIds = append(productIds, material.ID)
    }
    productAmounts, err := models.NewLocationProductAmountSearch().SetProductIds(productIds).SetLocationIds(locationIds).Find()
    if err != nil {
        util.ResponseFormat(c, code.RequestParamError, "查询在库数量失败")
        return
    if len(productIds) == 0 {
        for _, material := range materials {
            productIds = append(productIds, material.ID)
        }
        productAmounts, err = models.NewLocationProductAmountSearch().SetProductIds(productIds).SetLocationIds(locationIds).Find()
        if err != nil {
            util.ResponseFormat(c, code.RequestParamError, "查询在库数量失败")
            return
        }
    }
    //查询出入库就绪数量
models/location_product_amount.go
@@ -36,6 +36,7 @@
        LocationIds []int
        ProductIds  []string
        Ids         []int
        Query       string
    }
    LocationProductAmountWithOperation struct {
@@ -119,6 +120,11 @@
    return slf
}
func (slf *LocationProductAmountSearch) SetQuery(query string) *LocationProductAmountSearch {
    slf.Query = query
    return slf
}
func (slf *LocationProductAmountSearch) build() *gorm.DB {
    var db = slf.Orm.Model(&LocationProductAmount{})
@@ -163,6 +169,10 @@
        db = db.Where("id in (?)", slf.Ids)
    }
    if slf.Query != "" {
        db = db.Where(slf.Query)
    }
    return db
}