From a07fc02a9f0aa49aaaf273f5ff9cce4c6d546de9 Mon Sep 17 00:00:00 2001
From: liujiandao <274878379@qq.com>
Date: 星期四, 21 九月 2023 15:25:36 +0800
Subject: [PATCH] 位置字段添加
---
controllers/product_controller.go | 214 +++++++++++++++++++++++++++++++++++++++++++++++++++--
1 files changed, 206 insertions(+), 8 deletions(-)
diff --git a/controllers/product_controller.go b/controllers/product_controller.go
index 7c78abc..0f57587 100644
--- a/controllers/product_controller.go
+++ b/controllers/product_controller.go
@@ -2,10 +2,12 @@
import (
"github.com/gin-gonic/gin"
+ "github.com/spf13/cast"
"wms/extend/code"
"wms/extend/util"
"wms/models"
"wms/request"
+ "wms/utils"
)
type ProductController struct {
@@ -15,11 +17,11 @@
// @Tags 浜у搧
// @Summary 娣诲姞浜у搧
// @Produce application/json
-// @Param object body models.Product true "浜у搧淇℃伅"
+// @Param object body models.Material true "浜у搧淇℃伅"
// @Success 200 {object} util.Response "鎴愬姛"
// @Router /api-wms/v1/product/addProduct [post]
func (slf ProductController) AddProduct(c *gin.Context) {
- var params models.Product
+ var params models.Material
if err := c.BindJSON(¶ms); err != nil {
util.ResponseFormat(c, code.RequestParamError, "鍙傛暟瑙f瀽澶辫触锛屾暟鎹被鍨嬮敊璇�")
return
@@ -32,7 +34,16 @@
util.ResponseFormat(c, code.RequestParamError, "浜у搧鍞环涓嶈兘灏忎簬绛変簬闆�")
return
}
- err := models.NewProductSearch().Create(¶ms)
+ if params.Model == "" {
+ util.ResponseFormat(c, code.RequestParamError, "鐗╂枡绫诲瀷涓嶈兘涓虹┖")
+ return
+ }
+ if params.Unit == "" {
+ util.ResponseFormat(c, code.RequestParamError, "鍗曚綅涓嶈兘涓虹┖")
+ return
+ }
+ params.ID = utils.GetUUID()
+ err := models.NewMaterialSearch().Create(¶ms)
if err != nil {
util.ResponseFormat(c, code.RequestParamError, "浜у搧淇℃伅淇濆瓨澶辫触")
return
@@ -45,7 +56,7 @@
// @Summary 鑾峰彇浜у搧鍒楄〃
// @Produce application/json
// @Param object body request.GetProductList true "鏌ヨ鍙傛暟"
-// @Success 200 {object} util.ResponseList{data=[]models.Product} "鎴愬姛"
+// @Success 200 {object} util.ResponseList{data=[]models.Material} "鎴愬姛"
// @Router /api-wms/v1/product/getProductList [post]
func (slf ProductController) GetProductList(c *gin.Context) {
var params request.GetProductList
@@ -53,7 +64,7 @@
util.ResponseFormat(c, code.RequestParamError, "鍙傛暟瑙f瀽澶辫触锛屾暟鎹被鍨嬮敊璇�")
return
}
- search := models.NewProductSearch()
+ search := models.NewMaterialSearch()
if params.PageInfo.Check() {
search.SetPage(params.Page, params.PageSize)
}
@@ -70,9 +81,196 @@
// @Tags 浜у搧
// @Summary 鑾峰彇浜у搧璇︽儏
// @Produce application/json
-// @Param object body request.GetProductList true "鏌ヨ鍙傛暟"
-// @Success 200 {object} util.ResponseList{data=[]models.Product} "鎴愬姛"
-// @Router /api-wms/v1/product/getProductList [post]
+// @Param id path string true "id" "鏌ヨ鍙傛暟"
+// @Success 200 {object} util.Response{data=models.Material} "鎴愬姛"
+// @Router /api-wms/v1/product/getProductDetails/{id} [get]
func (slf ProductController) GetProductDetails(c *gin.Context) {
+ id := c.Param("id")
+ if id == "" {
+ util.ResponseFormat(c, code.RequestParamError, "鏃犳晥id")
+ return
+ }
+ material, err := models.NewMaterialSearch().SetID(id).First()
+ if err != nil {
+ util.ResponseFormat(c, code.RequestParamError, "鏌ユ壘澶辫触")
+ return
+ }
+ util.ResponseFormat(c, code.Success, material)
+}
+// UpdateProduct
+// @Tags 浜у搧
+// @Summary 淇敼浜у搧
+// @Produce application/json
+// @Param object body models.Material true "浜у搧淇℃伅"
+// @Success 200 {object} util.Response "鎴愬姛"
+// @Router /api-wms/v1/product/updateProduct [post]
+func (slf ProductController) UpdateProduct(c *gin.Context) {
+ var params models.Material
+ if err := c.BindJSON(¶ms); err != nil {
+ util.ResponseFormat(c, code.RequestParamError, "鍙傛暟瑙f瀽澶辫触锛屾暟鎹被鍨嬮敊璇�")
+ return
+ }
+ if params.Name == "" {
+ util.ResponseFormat(c, code.RequestParamError, "浜у搧鍚嶇О涓嶈兘涓虹┖")
+ return
+ }
+ if params.SalePrice.IntPart() <= 0 {
+ util.ResponseFormat(c, code.RequestParamError, "浜у搧鍞环涓嶈兘灏忎簬绛変簬闆�")
+ return
+ }
+ if params.Model == "" {
+ util.ResponseFormat(c, code.RequestParamError, "鐗╂枡绫诲瀷涓嶈兘涓虹┖")
+ return
+ }
+ if params.Unit == "" {
+ util.ResponseFormat(c, code.RequestParamError, "鍗曚綅涓嶈兘涓虹┖")
+ return
+ }
+ err := models.NewMaterialSearch().SetID(params.ID).Save(¶ms)
+ if err != nil {
+ util.ResponseFormat(c, code.RequestParamError, "浜у搧淇℃伅鏇存柊澶辫触")
+ return
+ }
+ util.ResponseFormat(c, code.Success, "鏇存柊鎴愬姛")
+}
+
+// DeleteProduct
+// @Tags 浜у搧
+// @Summary 鍒犻櫎浜у搧
+// @Produce application/json
+// @Param id path string true "id" "鏌ヨ鍙傛暟"
+// @Success 200 {object} util.Response "鎴愬姛"
+// @Router /api-wms/v1/product/deleteProduct/{id} [delete]
+func (slf ProductController) DeleteProduct(c *gin.Context) {
+ id := c.Param("id")
+ if id == "" {
+ util.ResponseFormat(c, code.RequestParamError, "鏃犳晥id")
+ return
+ }
+ err := models.NewMaterialSearch().SetID(id).Delete()
+ if err != nil {
+ util.ResponseFormat(c, code.RequestParamError, "鍒犻櫎澶辫触")
+ return
+ }
+ util.ResponseFormat(c, code.Success, "鍒犻櫎鎴愬姛")
+}
+
+// AddProductCategory
+// @Tags 浜у搧绫诲瀷
+// @Summary 娣诲姞浜у搧绫诲瀷
+// @Produce application/json
+// @Param object body models.ProductCategory true "浜у搧绫诲瀷淇℃伅"
+// @Success 200 {object} util.Response "鎴愬姛"
+// @Router /api-wms/v1/product/addProductCategory [post]
+func (slf ProductController) AddProductCategory(c *gin.Context) {
+ var params models.ProductCategory
+ if err := c.BindJSON(¶ms); err != nil {
+ util.ResponseFormat(c, code.RequestParamError, "鍙傛暟瑙f瀽澶辫触锛屾暟鎹被鍨嬮敊璇�")
+ return
+ }
+ if params.Name == "" {
+ util.ResponseFormat(c, code.RequestParamError, "浜у搧绫诲瀷鍚嶇О涓嶈兘涓虹┖")
+ return
+ }
+ err := models.NewProductCategorySearch().Create(¶ms)
+ if err != nil {
+ util.ResponseFormat(c, code.RequestParamError, "浜у搧绫诲瀷淇℃伅淇濆瓨澶辫触")
+ return
+ }
+ util.ResponseFormat(c, code.Success, "淇濆瓨鎴愬姛")
+}
+
+// GetProductCategoryList
+// @Tags 浜у搧绫诲瀷
+// @Summary 鑾峰彇浜у搧绫诲瀷鍒楄〃
+// @Produce application/json
+// @Param object body request.GetProductList true "鏌ヨ鍙傛暟"
+// @Success 200 {object} util.ResponseList{data=[]models.ProductCategory} "鎴愬姛"
+// @Router /api-wms/v1/product/getProductCategoryList [post]
+func (slf ProductController) GetProductCategoryList(c *gin.Context) {
+ var params request.GetProductList
+ if err := c.BindJSON(¶ms); err != nil {
+ util.ResponseFormat(c, code.RequestParamError, "鍙傛暟瑙f瀽澶辫触锛屾暟鎹被鍨嬮敊璇�")
+ return
+ }
+ search := models.NewProductCategorySearch()
+ if params.PageInfo.Check() {
+ search.SetPage(params.Page, params.PageSize)
+ }
+ list, total, err := search.SetKeyword(params.KeyWord).SetOrder("created_at desc").Find()
+ if err != nil {
+ util.ResponseFormat(c, code.RequestParamError, "鏌ユ壘澶辫触")
+ return
+ }
+
+ util.ResponseFormatList(c, code.Success, list, int(total))
+}
+
+// GetProductCategoryDetails
+// @Tags 浜у搧绫诲瀷
+// @Summary 鑾峰彇浜у搧绫诲瀷璇︽儏
+// @Produce application/json
+// @Param id path string true "id" "鏌ヨ鍙傛暟"
+// @Success 200 {object} util.Response{data=models.Material} "鎴愬姛"
+// @Router /api-wms/v1/product/getProductCategoryDetails/{id} [get]
+func (slf ProductController) GetProductCategoryDetails(c *gin.Context) {
+ id := c.Param("id")
+ if id == "" {
+ util.ResponseFormat(c, code.RequestParamError, "鏃犳晥id")
+ return
+ }
+
+ first, err := models.NewProductCategorySearch().SetID(cast.ToUint(id)).First()
+ if err != nil {
+ util.ResponseFormat(c, code.RequestParamError, "鏌ユ壘澶辫触")
+ return
+ }
+ util.ResponseFormat(c, code.Success, first)
+}
+
+// UpdateProductCategory
+// @Tags 浜у搧绫诲瀷
+// @Summary 淇敼浜у搧绫诲瀷
+// @Produce application/json
+// @Param object body models.ProductCategory true "浜у搧淇℃伅"
+// @Success 200 {object} util.Response "鎴愬姛"
+// @Router /api-wms/v1/product/updateProductCategory [post]
+func (slf ProductController) UpdateProductCategory(c *gin.Context) {
+ var params models.ProductCategory
+ if err := c.BindJSON(¶ms); err != nil {
+ util.ResponseFormat(c, code.RequestParamError, "鍙傛暟瑙f瀽澶辫触锛屾暟鎹被鍨嬮敊璇�")
+ return
+ }
+ if params.Name == "" {
+ util.ResponseFormat(c, code.RequestParamError, "浜у搧绫诲瀷鍚嶇О涓嶈兘涓虹┖")
+ return
+ }
+ err := models.NewProductCategorySearch().SetID(params.ID).Save(¶ms)
+ if err != nil {
+ util.ResponseFormat(c, code.RequestParamError, "浜у搧绫诲瀷淇℃伅鏇存柊澶辫触")
+ return
+ }
+ util.ResponseFormat(c, code.Success, "鏇存柊鎴愬姛")
+}
+
+// DeleteProductCategory
+// @Tags 浜у搧绫诲瀷
+// @Summary 鍒犻櫎浜у搧绫诲瀷
+// @Produce application/json
+// @Param id path string true "id" "鏌ヨ鍙傛暟"
+// @Success 200 {object} util.Response "鎴愬姛"
+// @Router /api-wms/v1/product/deleteProductCategory/{id} [delete]
+func (slf ProductController) DeleteProductCategory(c *gin.Context) {
+ id := c.Param("id")
+ if id == "" {
+ util.ResponseFormat(c, code.RequestParamError, "鏃犳晥id")
+ return
+ }
+ err := models.NewProductCategorySearch().SetID(cast.ToUint(id)).Delete()
+ if err != nil {
+ util.ResponseFormat(c, code.RequestParamError, "鍒犻櫎澶辫触")
+ return
+ }
+ util.ResponseFormat(c, code.Success, "鍒犻櫎鎴愬姛")
}
--
Gitblit v1.8.0