库存盘点应用按钮记录创建人,创建时间,应用时间、应用人员等信息;根据条形码查询产品详情;新增编辑产品增加条形码字段
| | |
| | | "wms/constvar" |
| | | "wms/extend/code" |
| | | "wms/extend/util" |
| | | "wms/middleware" |
| | | "wms/models" |
| | | "wms/pkg/mysqlx" |
| | | "wms/request" |
| | |
| | | util.ResponseFormat(c, code.RequestParamError, "参数解析失败,数据类型错误") |
| | | return |
| | | } |
| | | |
| | | if err := AddLocationProductAmount(reqParams); err != nil { |
| | | userInfo := middleware.GetUserInfo(c) |
| | | if err := AddLocationProductAmount(reqParams, userInfo); err != nil { |
| | | util.ResponseFormat(c, code.RequestError, err) |
| | | return |
| | | } |
| | |
| | | util.ResponseFormat(c, code.Success, "添加成功") |
| | | } |
| | | |
| | | func AddLocationProductAmount(reqParams request.UpdateLocationProductAmount) error { |
| | | func AddLocationProductAmount(reqParams request.UpdateLocationProductAmount, userInfo *request.CustomClaims) error { |
| | | if reqParams.LocationId == 0 { |
| | | return errors.New("参数异常,位置id信息不存在") |
| | | } |
| | |
| | | Details: []*models.OperationDetails{detail}, |
| | | LocationID: location.Id, |
| | | OperationTypeName: "库存调整", |
| | | CreatedBy: userInfo.Username, |
| | | } |
| | | |
| | | if err := models.WithTransaction(func(tx *gorm.DB) error { |
| | |
| | | util.ResponseFormat(c, code.RequestParamError, "参数解析失败,数据类型错误") |
| | | return |
| | | } |
| | | userInfo := middleware.GetUserInfo(c) |
| | | if reqParams.OperationId == 0 { |
| | | if err := AddLocationProductAmount(reqParams); err != nil { |
| | | if err := AddLocationProductAmount(reqParams, userInfo); err != nil { |
| | | util.ResponseFormat(c, code.RequestError, err.Error()) |
| | | return |
| | | } |
| | |
| | | return |
| | | } |
| | | adjustAmount := operation.Details[0].Amount.Sub(locProductAmount.Amount) |
| | | userInfo := middleware.GetUserInfo(c) |
| | | if err := models.WithTransaction(func(tx *gorm.DB) error { |
| | | if err := models.NewOperationSearch().SetOrm(tx).SetID(reqParams.OperationId).Update(&models.Operation{Status: constvar.OperationStatus_Finish}); err != nil { |
| | | if err := models.NewOperationSearch().SetOrm(tx).SetID(reqParams.OperationId).Update(&models.Operation{ |
| | | Status: constvar.OperationStatus_Finish, CheckedBy: userInfo.Username, |
| | | AuditDate: time.Now().Format("2006-01-02 15:04:05")}); err != nil { |
| | | return err |
| | | } |
| | | if err := models.NewMaterialSearch().SetOrm(tx).SetID(reqParams.ProductId).Update(&models.Material{Amount: material.Amount.Add(adjustAmount)}); err != nil { |
| | |
| | | |
| | | // GetProductDetails |
| | | // @Tags 产品 |
| | | // @Summary 获取产品详情 |
| | | // @Summary 通过产品/商品/物料 ID获取产品详情 |
| | | // @Produce application/json |
| | | // @Param Authorization header string true "token" |
| | | // @Param id path string true "id" "查询参数" |
| | |
| | | return |
| | | } |
| | | material, err := models.NewMaterialSearch().SetID(id).SetPreload(true).First() |
| | | if err != nil { |
| | | util.ResponseFormat(c, code.RequestParamError, "查找失败") |
| | | return |
| | | } |
| | | attributeValues, err := models.NewAttributeValueSearch().SetEntityID(material.ID).FindNotTotal() |
| | | if err != nil { |
| | | util.ResponseFormat(c, code.RequestParamError, "查找失败") |
| | | return |
| | | } |
| | | aids := make([]uint, 0) |
| | | for _, v := range attributeValues { |
| | | aids = append(aids, v.AttributeID) |
| | | } |
| | | attributes, err := models.NewAttributeSearch().SetIDs(aids).FindNotTotal() |
| | | attributesMap := make(map[uint]*models.Attribute, len(attributes)) |
| | | for _, v := range attributes { |
| | | attributesMap[v.ID] = v |
| | | } |
| | | if err != nil { |
| | | util.ResponseFormat(c, code.RequestParamError, "未知动态属性") |
| | | } |
| | | for _, v1 := range attributeValues { |
| | | attribute := attributesMap[v1.AttributeID] |
| | | if attribute == nil { |
| | | continue |
| | | } |
| | | //product.Attributes = append(product.Attributes,v1) |
| | | material.Attributes = append(material.Attributes, models.Attribute{ |
| | | Model: gorm.Model{ID: v1.ID, CreatedAt: v1.CreatedAt, UpdatedAt: v1.UpdatedAt, DeletedAt: v1.DeletedAt}, |
| | | Name: attribute.Name, |
| | | DataType: attribute.DataType, |
| | | EntityType: attribute.EntityType, |
| | | SelectValues: attribute.SelectValues, |
| | | SelectValue: attribute.SelectValue, |
| | | //Value: v1.Value, |
| | | Value: v1.Value, |
| | | }) |
| | | } |
| | | util.ResponseFormat(c, code.Success, material) |
| | | } |
| | | |
| | | // GetProductDetailsByBarCode |
| | | // @Tags 产品 |
| | | // @Summary 通过产品/商品/物料 条形码 获取产品详情 |
| | | // @Produce application/json |
| | | // @Param Authorization header string true "token" |
| | | // @Param barCode path string true "barCode" "查询参数" |
| | | // @Success 200 {object} util.Response{data=models.Material} "成功" |
| | | // @Router /api-wms/v1/product/getProductDetailsByBarCode/{barCode} [get] |
| | | func (slf ProductController) GetProductDetailsByBarCode(c *gin.Context) { |
| | | barCode := c.Param("barCode") |
| | | if barCode == "" { |
| | | util.ResponseFormat(c, code.RequestParamError, "无效条形码") |
| | | return |
| | | } |
| | | material, err := models.NewMaterialSearch().SetBarCode(barCode).SetPreload(true).First() |
| | | if err != nil { |
| | | util.ResponseFormat(c, code.RequestParamError, "查找失败") |
| | | return |
| | |
| | | |
| | | // DeleteProduct |
| | | // @Tags 产品 |
| | | // @Summary 删除产品 |
| | | // @Summary 通过产品/商品/物料 ID删除产品 |
| | | // @Produce application/json |
| | | // @Param id path string true "id" "查询参数" |
| | | // @Success 200 {object} util.Response "成功" |
| | |
| | | util.ResponseFormat(c, code.Success, "删除成功") |
| | | } |
| | | |
| | | // DeleteProductByBarCode |
| | | // @Tags 产品 |
| | | // @Summary 通过产品/商品/物料 条形码删除产品 |
| | | // @Produce application/json |
| | | // @Param barCode path string true "barCode" "查询参数" |
| | | // @Success 200 {object} util.Response "成功" |
| | | // @Router /api-wms/v1/product/deleteProductByBarCode/{barCode} [delete] |
| | | func (slf ProductController) DeleteProductByBarCode(c *gin.Context) { |
| | | barCode := c.Param("barCode") |
| | | if barCode == "" { |
| | | util.ResponseFormat(c, code.RequestParamError, "无效id") |
| | | return |
| | | } |
| | | err := models.NewMaterialSearch().SetBarCode(barCode).Delete() |
| | | if err != nil { |
| | | util.ResponseFormat(c, code.RequestParamError, "删除失败") |
| | | return |
| | | } |
| | | util.ResponseFormat(c, code.Success, "删除成功") |
| | | } |
| | | |
| | | // AddProductCategory |
| | | // @Tags 产品类型 |
| | | // @Summary 添加产品类型 |
| | |
| | | MinInventoryRule decimal.Decimal `json:"minInventoryRule" gorm:"-"` //最小库存 |
| | | MaxInventoryRule decimal.Decimal `json:"maxInventoryRule" gorm:"-"` //最大库存 |
| | | |
| | | CreateBy string `gorm:"type:varchar(255);comment:导入人、创建人" json:"createBy"` //创建人 |
| | | CreateBy string `gorm:"type:varchar(255);comment:导入人、创建人" json:"createBy"` //创建人 |
| | | BarCode string `gorm:"type:varchar(255);comment:(商品/产品/物料的)条形码" json:"barCode"` //创建人 |
| | | } |
| | | |
| | | MaterialSearch struct { |
| | |
| | | return slf |
| | | } |
| | | |
| | | func (slf *MaterialSearch) SetBarCode(barCode string) *MaterialSearch { |
| | | slf.BarCode = barCode |
| | | return slf |
| | | } |
| | | |
| | | func (slf *MaterialSearch) SetIsSale(isSale bool) *MaterialSearch { |
| | | slf.IsSale = isSale |
| | | return slf |
| | |
| | | if slf.ID != "" { |
| | | db = db.Where("id = ?", slf.ID) |
| | | } |
| | | if slf.BarCode != "" { |
| | | db = db.Where("bar_code = ?", slf.BarCode) |
| | | } |
| | | |
| | | if slf.Name != "" { |
| | | db = db.Where("name = ?", slf.Name) |
| | |
| | | productController := new(controllers.ProductController) |
| | | productAPI := r.Group(urlPrefix + "/product") |
| | | { |
| | | productAPI.POST("addProduct", productController.AddProduct) // 新增产品 |
| | | productAPI.POST("getProductList", productController.GetProductList) // 获取产品列表 |
| | | productAPI.GET("getProductDetails/:id", productController.GetProductDetails) // 获取产品详情 |
| | | productAPI.POST("updateProduct", productController.UpdateProduct) // 修改产品详情 |
| | | productAPI.DELETE("deleteProduct/:id", productController.DeleteProduct) // 删除产品 |
| | | productAPI.POST("addProduct", productController.AddProduct) // 新增产品 |
| | | productAPI.POST("getProductList", productController.GetProductList) // 获取产品列表 |
| | | productAPI.GET("getProductDetails/:id", productController.GetProductDetails) // 通过ID获取产品详情 |
| | | productAPI.GET("getProductDetailsByBarCode/:barCode", productController.GetProductDetailsByBarCode) // 通过条形码获取产品详情 |
| | | productAPI.POST("updateProduct", productController.UpdateProduct) // 修改产品详情 |
| | | productAPI.DELETE("deleteProduct/:id", productController.DeleteProduct) // 通过ID获删除产品 |
| | | productAPI.DELETE("deleteProductByBarCode/:barCode", productController.DeleteProductByBarCode) // 通过条形码删除产品 |
| | | |
| | | productAPI.POST("addProductCategory", productController.AddProductCategory) //添加产品类型 |
| | | productAPI.POST("getProductCategoryList", productController.GetProductCategoryList) //获取产品类型列表 |