| | |
| | | // @Router /api-wms/v1/forms/getInventoryForms [post] |
| | | func (slf ReportFormsController) GetInventoryForms(c *gin.Context) { |
| | | var params request.GetInventoryForms |
| | | if err := c.BindJSON(¶ms); err != nil { |
| | | err := c.BindJSON(¶ms) |
| | | 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() |
| | |
| | | } |
| | | 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) |
| | |
| | | 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 |
| | | } |
| | | } |
| | | |
| | | //查询出入库就绪数量 |
| | |
| | | |
| | | detailsSearch.Orm = detailsSearch.Orm.Model(&models.MoveHistory{}). |
| | | Select("number, updated_at as date, product_name as product_name, from_location_id, operation_id,to_location_id, amount, " + |
| | | "unit, operator as contacted_name, base_operation_type, weight, product_id, from_location, to_location, operation_type_name").Order("id desc") |
| | | "unit, operator as contacted_name, base_operation_type, weight, product_id, from_location, to_location, operation_type_name, weight").Order("id desc") |
| | | if len(ids) > 0 { |
| | | detailsSearch.Orm = detailsSearch.Orm.Where("id in ?", ids) |
| | | } |
| | |
| | | |
| | | util.ResponseFormatList(c, code.Success, result, int(total)) |
| | | } |
| | | |
| | | // MonthStats |
| | | // @Tags 报表 |
| | | // @Summary 月度统计库存报表 |
| | | // @Produce application/json |
| | | // @Param object body request.GetMonthStats true "查询参数" |
| | | // @Param Authorization header string true "token" |
| | | // @Success 200 {object} util.ResponseList{data=[]models.MonthStats} "成功" |
| | | // @Router /api-wms/v1/forms/monthStats [post] |
| | | func (slf ReportFormsController) MonthStats(c *gin.Context) { |
| | | var params request.GetMonthStats |
| | | if err := c.BindJSON(¶ms); err != nil { |
| | | util.ResponseFormat(c, code.RequestParamError, "参数解析失败,数据类型错误") |
| | | return |
| | | } |
| | | |
| | | list, total, err := models.NewMonthStatsSearch().SetPage(params.Page, params.PageSize).SetKeyword(params.Keyword).SetDate(params.Date).Find() |
| | | if err != nil { |
| | | util.ResponseFormat(c, code.InternalError, "查询失败") |
| | | return |
| | | } |
| | | |
| | | util.ResponseFormatList(c, code.Success, list, int(total)) |
| | | } |