| | |
| | | util.ResponseFormat(c, code.RequestParamError, "单位不能为空") |
| | | return |
| | | } |
| | | if params.BarCode != "" { |
| | | m, err := models.NewMaterialSearch().SetBarCode(params.BarCode).First() |
| | | if err == nil && m.ID != "" { //查出物料表是物料已存在 |
| | | util.ResponseFormat(c, code.RequestParamError, "条形码已经被使用") |
| | | return |
| | | } |
| | | } |
| | | //params.ID = utils.GetUUID() |
| | | |
| | | err := models.WithTransaction(func(tx *gorm.DB) error { |
| | |
| | | |
| | | // GetProductDetails |
| | | // @Tags 产品 |
| | | // @Summary 获取产品详情 |
| | | // @Summary 通过产品/商品/物料 ID获取产品详情 |
| | | // @Produce application/json |
| | | // @Param Authorization header string true "token" |
| | | // @Param id path string true "id" "查询参数" |
| | | // @Success 200 {object} util.Response{data=models.Material} "成功" |
| | | // @Router /api-wms/v1/product/getProductDetails/{id} [get] |
| | |
| | | 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 |
| | | } |
| | | 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) |
| | | } |
| | |
| | | if params.Unit == "" { |
| | | util.ResponseFormat(c, code.RequestParamError, "单位不能为空") |
| | | return |
| | | } |
| | | if params.BarCode != "" { |
| | | m, err := models.NewMaterialSearch().SetBarCode(params.BarCode).First() |
| | | if err == nil && m.ID != params.ID { //查出物料且ID不一样, |
| | | util.ResponseFormat(c, code.RequestParamError, "条形码已经被使用") |
| | | return |
| | | } |
| | | } |
| | | err := models.NewMaterialSearch().SetID(params.ID).Save(¶ms) |
| | | if err != nil { |
| | |
| | | |
| | | // DeleteProduct |
| | | // @Tags 产品 |
| | | // @Summary 删除产品 |
| | | // @Summary 通过产品/商品/物料 ID删除产品 |
| | | // @Produce application/json |
| | | // @Param id path string true "id" "查询参数" |
| | | // @Success 200 {object} util.Response "成功" |
| | |
| | | return |
| | | } |
| | | err := models.NewMaterialSearch().SetID(id).Delete() |
| | | if err != nil { |
| | | util.ResponseFormat(c, code.RequestParamError, "删除失败") |
| | | return |
| | | } |
| | | 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 |
| | |
| | | // |
| | | // @Tags 物料管理 |
| | | // @Summary 导入物料 |
| | | // |
| | | // @Accept multipart/form-data |
| | | // @Param file formData file true "file" |
| | | // @Param Authorization header string true "token" |
| | | // |
| | | // @Produce application/xlsx |
| | | // @Success 200 {object} util.Response "成功" |
| | | // @Router /api-wms/v1/product/inputProduct [post] |