| | |
| | | util.ResponseFormat(c, code.RequestParamError, "请选择产品") |
| | | return |
| | | } |
| | | if params.ProductCategoryID == 0 { |
| | | util.ResponseFormat(c, code.RequestParamError, "请选择产品类别") |
| | | return |
| | | } |
| | | //if params.ProductCategoryID == 0 { |
| | | // util.ResponseFormat(c, code.RequestParamError, "请选择产品类别") |
| | | // return |
| | | //} |
| | | if err := models.NewLocationProductSearch().Create(¶ms); err != nil { |
| | | logx.Errorf("Operation create err: %v", err) |
| | | util.ResponseFormat(c, code.SaveFail, "添加失败:"+err.Error()) |
| | |
| | | // @Produce application/json |
| | | // @Param object body request.PageInfo true "查询参数" |
| | | // @Success 200 {object} util.Response "成功" |
| | | // @Router /api-wms/v1/locationProductamount/list [post] |
| | | // @Router /api-wms/v1/locationProductAmount/list [post] |
| | | func (slf LocationProductAmountController) List(c *gin.Context) { |
| | | var params request.PageInfo |
| | | if err := c.BindJSON(¶ms); err != nil { |
| | | util.ResponseFormat(c, code.RequestParamError, "参数解析失败,数据类型错误:"+err.Error()) |
| | | return |
| | | } |
| | | if params.Check() { |
| | | if !params.Check() { |
| | | util.ResponseFormat(c, code.RequestParamError, "参数异常") |
| | | return |
| | | } |
| | |
| | | search := models.NewLocationProductAmountSearch() |
| | | search.SetPage(params.Page, params.PageSize) |
| | | |
| | | search.Orm = search.Orm.Model(&models.LocationProductAmountWithOperation{}).Table("wms_location_product_amount").Select("wms_location_product_amount.*,wms_operation.amount as adjust_amount").InnerJoins("inner join wms_location_product on wms_location_product.id=wms_location_product_amount.location_product_id").InnerJoins("inner join wms_operation_details on wms_operation_details.product_id=wms_location_product.product_id").InnerJoins("inner join wms_operation on wms_operation.id=wms_operation_details.operation_id").Where("wms_operation.base_operation_type=?", constvar.BaseOperationTypeAdjust) |
| | | search.Orm = search.Orm. |
| | | Table("wms_location_product_amount"). |
| | | Select(` |
| | | wms_location.id as location_id, |
| | | wms_location.name as location_name, |
| | | material.id as product_id, |
| | | material.name as product_name, |
| | | wms_location_product_amount.amount, |
| | | material.unit, |
| | | wms_location_product_amount.create_date, |
| | | wms_operation_details.amount as adjust_amount`). |
| | | InnerJoins("inner join wms_location_product on wms_location_product.id=wms_location_product_amount.location_product_id"). |
| | | InnerJoins("inner join wms_location on wms_location.id=wms_location_product.location_id"). |
| | | InnerJoins("inner join wms_operation_details on wms_operation_details.product_id=wms_location_product.product_id"). |
| | | InnerJoins("inner join material on material.id=wms_operation_details.product_id"). |
| | | InnerJoins("inner join wms_operation on wms_operation.id=wms_operation_details.operation_id"). |
| | | Where("wms_operation.base_operation_type=?", constvar.BaseOperationTypeAdjust) |
| | | |
| | | var ( |
| | | records = make([]*models.ResponseDisuseList, 0) |
| | | records = make([]*models.LocationProductAmountWithOperation, 0) |
| | | total int64 |
| | | ) |
| | | |
| | |
| | | util.ResponseFormat(c, code.RequestError, fmt.Errorf("find count err: %v", err)) |
| | | return |
| | | } |
| | | search.Orm = search.Orm.Preload("LocationProduct").Preload("LocationProduct.Location").Preload("LocationProduct.Product") |
| | | //search.Orm = search.Orm.Preload("LocationProduct").Preload("LocationProduct.Location").Preload("LocationProduct.Product") |
| | | if params.Page*params.PageSize > 0 { |
| | | search.Orm = search.Orm.Offset((params.Page - 1) * params.PageSize).Limit(params.PageSize) |
| | | } |
| | |
| | | util.ResponseFormat(c, code.RequestError, fmt.Errorf("find count err: %v", err)) |
| | | return |
| | | } |
| | | |
| | | for k, v := range records { |
| | | records[k].DifferenceAmount = v.Amount.Sub(v.AdjustAmount) |
| | | } |
| | | util.ResponseFormatListWithPage(c, code.Success, records, int(total), params.Page, params.PageSize) |
| | | } |
| | | |
| | |
| | | // @Produce application/json |
| | | // @Param object body request.AddLocationProductAmount true "入库/出库信息" |
| | | // @Success 200 {object} util.Response "成功" |
| | | // @Router /api-wms/v1/locationProductamount/add [post] |
| | | // @Router /api-wms/v1/locationProductAmount/add [post] |
| | | func (slf LocationProductAmountController) Add(c *gin.Context) { |
| | | var reqParams request.AddLocationProductAmount |
| | | if err := c.BindJSON(&reqParams); err != nil { |
| | |
| | | } |
| | | |
| | | var existCount int64 |
| | | 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.from_location_id=? and wms_operation_details.product_id=? and wms_operation.base_operation_type=? and wms_operaton.status=?", reqParams.LocationId, reqParams.ProductId, constvar.BaseOperationTypeAdjust, constvar.OperationStatus_Ready).Count(&existCount).Error; err != nil { |
| | | 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.from_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 { |
| | | util.ResponseFormat(c, code.RequestParamError, err.Error()) |
| | | return |
| | | } |
| | |
| | | "github.com/gin-gonic/gin" |
| | | "github.com/shopspring/decimal" |
| | | "gorm.io/gorm" |
| | | "sort" |
| | | "strconv" |
| | | "time" |
| | | "wms/constvar" |
| | |
| | | util.ResponseFormat(c, code.RequestParamError, err.Error()) |
| | | return |
| | | } |
| | | |
| | | if CheckDetailsRepeat(params.Details) { |
| | | util.ResponseFormat(c, code.RequestParamError, "明细中不能存在重复的产品") |
| | | return |
| | | } |
| | | |
| | | operationType, err := models.NewOperationTypeSearch().SetID(uint(params.OperationTypeId)).First() |
| | | if err != nil { |
| | | util.ResponseFormat(c, code.RequestParamError, err.Error()) |
| | |
| | | return |
| | | } |
| | | util.ResponseFormat(c, code.Success, "添加成功") |
| | | } |
| | | |
| | | func CheckDetailsRepeat(details []*models.OperationDetails) bool { |
| | | detailIDs := []string{} |
| | | var tempID string |
| | | for _, v := range details { |
| | | detailIDs = append(detailIDs, v.ProductId) |
| | | } |
| | | sort.Strings(detailIDs) |
| | | for _, v := range detailIDs { |
| | | if v != tempID { |
| | | tempID = v |
| | | } else { |
| | | return true |
| | | } |
| | | } |
| | | return false |
| | | } |
| | | |
| | | func (slf OperationController) FormatLocation(params *models.Operation) error { |
| | |
| | | util.ResponseFormat(c, code.RequestParamError, err.Error()) |
| | | return |
| | | } |
| | | if CheckDetailsRepeat(params.Details) { |
| | | util.ResponseFormat(c, code.RequestParamError, "明细中不能存在重复的产品") |
| | | return |
| | | } |
| | | if err := slf.FormatLocation(¶ms); err != nil { |
| | | util.ResponseFormat(c, code.RequestParamError, err.Error()) |
| | | return |
| | |
| | | } |
| | | } |
| | | }, |
| | | "/api-wms/v1/locationProductamount/add": { |
| | | "/api-wms/v1/locationProductAmount/add": { |
| | | "post": { |
| | | "produces": [ |
| | | "application/json" |
| | |
| | | } |
| | | } |
| | | }, |
| | | "/api-wms/v1/locationProductamount/list": { |
| | | "/api-wms/v1/locationProductAmount/list": { |
| | | "post": { |
| | | "produces": [ |
| | | "application/json" |
| | |
| | | "request.AddLocationProductAmount": { |
| | | "type": "object", |
| | | "properties": { |
| | | "Amount": { |
| | | "description": "库存数量", |
| | | "type": "number" |
| | | }, |
| | | "adjustAmount": { |
| | | "description": "差值", |
| | | "type": "number" |
| | | }, |
| | | "decimal": { |
| | | "description": "库存数量", |
| | | "type": "number" |
| | | }, |
| | | "difference_amount": { |
| | | "differenceAmount": { |
| | | "description": "计数数量", |
| | | "type": "number" |
| | | }, |
| | |
| | | } |
| | | } |
| | | }, |
| | | "/api-wms/v1/locationProductamount/add": { |
| | | "/api-wms/v1/locationProductAmount/add": { |
| | | "post": { |
| | | "produces": [ |
| | | "application/json" |
| | |
| | | } |
| | | } |
| | | }, |
| | | "/api-wms/v1/locationProductamount/list": { |
| | | "/api-wms/v1/locationProductAmount/list": { |
| | | "post": { |
| | | "produces": [ |
| | | "application/json" |
| | |
| | | "request.AddLocationProductAmount": { |
| | | "type": "object", |
| | | "properties": { |
| | | "Amount": { |
| | | "description": "库存数量", |
| | | "type": "number" |
| | | }, |
| | | "adjustAmount": { |
| | | "description": "差值", |
| | | "type": "number" |
| | | }, |
| | | "decimal": { |
| | | "description": "库存数量", |
| | | "type": "number" |
| | | }, |
| | | "difference_amount": { |
| | | "differenceAmount": { |
| | | "description": "计数数量", |
| | | "type": "number" |
| | | }, |
| | |
| | | type: object |
| | | request.AddLocationProductAmount: |
| | | properties: |
| | | Amount: |
| | | description: 库存数量 |
| | | type: number |
| | | adjustAmount: |
| | | description: 差值 |
| | | type: number |
| | | decimal: |
| | | description: 库存数量 |
| | | type: number |
| | | difference_amount: |
| | | differenceAmount: |
| | | description: 计数数量 |
| | | type: number |
| | | locationId: |
| | |
| | | summary: 修改上架规则 |
| | | tags: |
| | | - 上架规则 |
| | | /api-wms/v1/locationProductamount/add: |
| | | /api-wms/v1/locationProductAmount/add: |
| | | post: |
| | | parameters: |
| | | - description: 入库/出库信息 |
| | |
| | | summary: 添加库存盘点信息 |
| | | tags: |
| | | - 库存盘点 |
| | | /api-wms/v1/locationProductamount/list: |
| | | /api-wms/v1/locationProductAmount/list: |
| | | post: |
| | | parameters: |
| | | - description: 查询参数 |
| | |
| | | LocationProductId int `json:"locationProductId" gorm:"type:int;not null;comment:上架规则id"` //上架规则id |
| | | LocationProduct LocationProduct `json:"locationProduct" gorm:"foreignKey:LocationProductId;references:Id"` |
| | | Amount decimal.Decimal `json:"amount" gorm:"type:decimal(20,2);not null;comment:库存数量"` //库存数量 |
| | | CreateDate string `json:"createDate" gorm:"type:varchar(63);comment:日期"` //日期 |
| | | } |
| | | |
| | | LocationProductAmountSearch struct { |
| | |
| | | } |
| | | |
| | | LocationProductAmountWithOperation struct { |
| | | LocationProductAmount LocationProductAmount `json:"locationProductAmount"` |
| | | AdjustAmount decimal.Decimal `json:"adjustAmount" gorm:"column:adjust_amount"` |
| | | DifferenceAmount decimal.Decimal `json:"difference_amount"` |
| | | //LocationProductAmount LocationProductAmount `json:"locationProductAmount"` |
| | | LocationId int `json:"locationId" gorm:"column:location_id"` |
| | | LocationName string `json:"locationName" gorm:"column:location_name"` |
| | | ProductId string `json:"productId" gorm:"column:product_id"` |
| | | ProductName string `json:"productName" gorm:"column:product_name"` |
| | | Amount decimal.Decimal `json:"amount" gorm:"column:amount"` |
| | | Unit string `json:"unit" gorm:"column:unit"` |
| | | CreateDate string `json:"createDate" gorm:"column:create_date"` |
| | | AdjustAmount decimal.Decimal `json:"adjustAmount" gorm:"column:adjust_amount"` |
| | | DifferenceAmount decimal.Decimal `json:"differenceAmount" gorm:"-"` |
| | | } |
| | | ) |
| | | |
| | |
| | | type AddLocationProductAmount struct { |
| | | LocationId int `json:"locationId"` |
| | | ProductId string `json:"productId"` |
| | | Amount decimal.Decimal `json:"decimal"` //库存数量 |
| | | AdjustAmount decimal.Decimal `json:"adjustAmount" ` //差值 |
| | | DifferenceAmount decimal.Decimal `json:"difference_amount"` //计数数量 |
| | | Amount decimal.Decimal `json:"Amount"` //库存数量 |
| | | AdjustAmount decimal.Decimal `json:"adjustAmount" ` //差值 |
| | | DifferenceAmount decimal.Decimal `json:"differenceAmount"` //计数数量 |
| | | } |
| | | |
| | | type UpdateLocationProductAmount struct { |
| | | LocationProductAmountId int `json:"locationProductAmountId"` //库存盘点id |
| | | AdjustAmount decimal.Decimal `json:"adjustAmount" ` //差值 |
| | | DifferenceAmount decimal.Decimal `json:"difference_amount"` //计数数量 |
| | | DifferenceAmount decimal.Decimal `json:"differenceAmount"` //计数数量 |
| | | } |