| | |
| | | // @Tags 库存盘点 |
| | | // @Summary 库存盘点列表 |
| | | // @Produce application/json |
| | | // @Param object body request.PageInfo true "查询参数" |
| | | // @Param object body request.GetList true "查询参数" |
| | | // @Success 200 {object} util.Response "成功" |
| | | // @Router /api-wms/v1/locationProductAmount/list [post] |
| | | func (slf LocationProductAmountController) List(c *gin.Context) { |
| | | var params request.PageInfo |
| | | var params request.GetList |
| | | if err := c.BindJSON(¶ms); err != nil { |
| | | util.ResponseFormat(c, code.RequestParamError, "参数解析失败,数据类型错误:"+err.Error()) |
| | | return |
| | |
| | | if !params.Check() { |
| | | util.ResponseFormat(c, code.RequestParamError, "参数异常") |
| | | return |
| | | } |
| | | productIds := make([]string, 0) |
| | | locationIds := make([]int, 0) |
| | | if params.Keyword != "" { |
| | | materials, _ := models.NewMaterialSearch().SetKeyword(params.Keyword).FindNotTotal() |
| | | for _, material := range materials { |
| | | productIds = append(productIds, material.ID) |
| | | } |
| | | locations, _ := models.NewLocationSearch().SetKeyword(params.Keyword).FindNotTotal() |
| | | for _, location := range locations { |
| | | locationIds = append(locationIds, location.Id) |
| | | } |
| | | } |
| | | |
| | | search := models.NewLocationProductAmountSearch() |
| | |
| | | records = make([]*models.LocationProductAmountWithOperation, 0) |
| | | total int64 |
| | | ) |
| | | if len(productIds) > 0 { |
| | | search.Orm = search.Orm.Where("wms_location_product_amount.product_id in (?)", productIds) |
| | | |
| | | } |
| | | if len(locationIds) > 0 { |
| | | search.Orm = search.Orm.Where("wms_location_product_amount.location_id in (?)", locationIds) |
| | | } |
| | | |
| | | if err := search.Orm.Count(&total).Error; err != nil { |
| | | util.ResponseFormat(c, code.RequestError, fmt.Errorf("find count err: %v", err)) |
| | |
| | | util.ResponseFormat(c, code.RequestError, fmt.Errorf("find count err: %v", err)) |
| | | return |
| | | } |
| | | var operation models.Operation |
| | | |
| | | for k, v := range records { |
| | | if res := mysqlx.GetDB().Table("wms_operation").InnerJoins("inner join wms_operation_details on wms_operation_details.operation_id=wms_operation.id").Where("wms_operation.base_operation_type=? and wms_operation.status=? and wms_operation_details.to_location_id=? and wms_operation_details.product_id=?", constvar.BaseOperationTypeAdjust, constvar.OperationStatus_Ready, v.LocationId, v.ProductId).First(&operation); res.Error != nil { |
| | | var operation models.Operation |
| | | db := mysqlx.GetDB() |
| | | if res := db.Table("wms_operation").Preload("Details").InnerJoins("inner join wms_operation_details "+ |
| | | "on wms_operation_details.operation_id=wms_operation.id").Where("wms_operation.base_operation_type=? and "+ |
| | | "wms_operation.status=? and wms_operation_details.to_location_id=? and wms_operation_details.product_id=?", constvar.BaseOperationTypeAdjust, |
| | | constvar.OperationStatus_Ready, v.LocationId, v.ProductId).First(&operation); res.Error != nil { |
| | | if errors.Is(res.Error, gorm.ErrRecordNotFound) { |
| | | records[k].Status = constvar.OperationStatus_Finish |
| | | records[k].BaseOperationType = constvar.BaseOperationTypeAdjust |
| | |
| | | |
| | | if err := AddLocationProductAmount(reqParams); err != nil { |
| | | util.ResponseFormat(c, code.RequestError, err) |
| | | return |
| | | } |
| | | |
| | | util.ResponseFormat(c, code.Success, "添加成功") |
| | |
| | | if err := models.NewOperationSearch().Orm. |
| | | Table("wms_operation"). |
| | | InnerJoins("inner join wms_operation_details on wms_operation_details.operation_id=wms_operation.id"). |
| | | Where("wms_operation.location_id=? and wms_operation_details.product_id=? and wms_operation.base_operation_type=? and wms_operation.status=?", reqParams.LocationId, reqParams.ProductId, constvar.BaseOperationTypeAdjust, constvar.OperationStatus_Ready). |
| | | Where("wms_operation_details.to_location_id=? and wms_operation_details.product_id=? and wms_operation.base_operation_type=? and wms_operation.status=?", reqParams.LocationId, reqParams.ProductId, constvar.BaseOperationTypeAdjust, constvar.OperationStatus_Ready). |
| | | Count(&existCount).Error; err != nil { |
| | | return err |
| | | } |
| | |
| | | BaseOperationType: constvar.BaseOperationTypeAdjust, |
| | | Details: []*models.OperationDetails{detail}, |
| | | LocationID: location.Id, |
| | | OperationTypeName: "库存调整", |
| | | } |
| | | |
| | | if err := models.WithTransaction(func(tx *gorm.DB) error { |