From 307c699810c39714e82efac9de56f70b93a718a2 Mon Sep 17 00:00:00 2001
From: liujiandao <274878379@qq.com>
Date: 星期二, 31 十月 2023 11:54:23 +0800
Subject: [PATCH] 重订货规则开发

---
 /dev/null                              |  244 ---------
 response/report_forms_response.go      |   20 
 controllers/report_forms_controller.go |    5 
 models/db.go                           |    3 
 request/reorder_rule_request.go        |   24 
 controllers/reorder_rule_controller.go |  281 +++++++++++
 docs/swagger.yaml                      |  172 ++++++
 docs/docs.go                           |  274 ++++++++++
 models/operation_details.go            |    2 
 docs/swagger.json                      |  272 ++++++++++
 models/reorder_rule.go                 |  165 ++++++
 router/router.go                       |   11 
 12 files changed, 1,215 insertions(+), 258 deletions(-)

diff --git a/controllers/reorder_rule_controller.go b/controllers/reorder_rule_controller.go
new file mode 100644
index 0000000..4add8d6
--- /dev/null
+++ b/controllers/reorder_rule_controller.go
@@ -0,0 +1,281 @@
+package controllers
+
+import (
+	"github.com/gin-gonic/gin"
+	"github.com/shopspring/decimal"
+	"gorm.io/gorm"
+	"strconv"
+	"strings"
+	"time"
+	"wms/constvar"
+	"wms/extend/code"
+	"wms/extend/util"
+	"wms/models"
+	"wms/pkg/timex"
+	"wms/request"
+)
+
+type ReorderRuleController struct {
+}
+
+// AddReorderRule
+// @Tags      閲嶈璐ц鍒�
+// @Summary   娣诲姞閲嶈璐ц鍒�
+// @Produce   application/json
+// @Param     object  body  models.ReorderRule true  "閲嶈璐ц鍒�"
+// @Success   200 {object} util.Response "鎴愬姛"
+// @Router    /api-wms/v1/reorderRule/addReorderRule [post]
+func (slf ReorderRuleController) AddReorderRule(c *gin.Context) {
+	var params models.ReorderRule
+	if err := c.BindJSON(&params); err != nil {
+		util.ResponseFormat(c, code.RequestParamError, "鍙傛暟瑙f瀽澶辫触锛屾暟鎹被鍨嬮敊璇�")
+		return
+	}
+	count, err := models.NewReorderRuleSearch().SetProductId(params.ProductId).SetLocationId(params.LocationId).Count()
+	if err != nil {
+		util.ResponseFormat(c, code.RequestError, "鏁版嵁楠岃瘉閿欒")
+		return
+	}
+	if count > 0 {
+		util.ResponseFormat(c, code.RequestError, "褰撳墠浣嶇疆宸插瓨鍦ㄧ浉鍚屼骇鍝佺殑閲嶈璐ц鍒�")
+		return
+	}
+	err = models.NewReorderRuleSearch().Create(&params)
+	if err != nil {
+		util.ResponseFormat(c, code.RequestError, "閲嶈璐ц鍒欎繚瀛樺け璐�")
+		return
+	}
+	util.ResponseFormat(c, code.Success, "淇濆瓨鎴愬姛")
+}
+
+// GetReorderRuleList
+// @Tags      閲嶈璐ц鍒�
+// @Summary   鑾峰彇閲嶈璐ц鍒欏垪琛�
+// @Produce   application/json
+// @Param     object  body  request.GetReorderRuleList true  "鍙傛暟"
+// @Success   200 {object} util.ResponseList{data=[]models.ReorderRule} "鎴愬姛"
+// @Router    /api-wms/v1/reorderRule/getReorderRuleList [post]
+func (slf ReorderRuleController) GetReorderRuleList(c *gin.Context) {
+	var params request.GetReorderRuleList
+	if err := c.BindJSON(&params); err != nil {
+		util.ResponseFormat(c, code.RequestParamError, "鍙傛暟瑙f瀽澶辫触锛屾暟鎹被鍨嬮敊璇�")
+		return
+	}
+	search := models.NewReorderRuleSearch()
+	if params.PageInfo.Check() {
+		search.SetPage(params.Page, params.PageSize)
+	}
+	rules, total, err := search.SetPreload(true).SetKeyword(params.KeyWord).Find()
+	if err != nil {
+		util.ResponseFormat(c, code.RequestParamError, "鏌ヨ閲嶈璐ц鍒欏垪琛ㄥけ璐�")
+		return
+	}
+	productIds := make([]string, 0)
+	locationIds := make([]int, 0)
+	for _, rule := range rules {
+		productIds = append(productIds, rule.ProductId)
+		locationIds = append(locationIds, rule.LocationId)
+	}
+	//鍦ㄥ簱
+	var status = []constvar.OperationStatus{constvar.OperationStatus_Finish, constvar.OperationStatus_Ready}
+	var operationType = []constvar.BaseOperationType{constvar.BaseOperationTypeIncoming, constvar.BaseOperationTypeInternal}
+	amount, err := GetProductAmount(productIds, locationIds, nil, status, operationType)
+	if err != nil {
+		util.ResponseFormat(c, code.RequestParamError, "鏌ヨ閲嶈璐ц鍒欏垪琛ㄥけ璐�")
+		return
+	}
+	mp := make(map[int]decimal.Decimal)
+	for _, rule := range rules {
+		for _, productAmount := range amount {
+			if rule.ProductId == productAmount.ProductId && rule.LocationId == productAmount.ToLocationId &&
+				productAmount.Status == constvar.OperationStatus_Finish {
+				rule.Amount = rule.Amount.Add(productAmount.Amount)
+			}
+			if rule.ProductId == productAmount.ProductId && rule.LocationId == productAmount.ToLocationId &&
+				productAmount.Status == constvar.OperationStatus_Ready {
+				mp[rule.Id] = mp[rule.Id].Add(productAmount.Amount)
+			}
+		}
+	}
+	//棰勬祴
+	status = []constvar.OperationStatus{constvar.OperationStatus_Finish, constvar.OperationStatus_Ready}
+	operationType = []constvar.BaseOperationType{constvar.BaseOperationTypeOutgoing, constvar.BaseOperationTypeInternal}
+	amount, err = GetProductAmount(productIds, nil, locationIds, status, operationType)
+	if err != nil {
+		util.ResponseFormat(c, code.RequestParamError, "鏌ヨ閲嶈璐ц鍒欏垪琛ㄥけ璐�")
+		return
+	}
+	for _, rule := range rules {
+		for _, productAmount := range amount {
+			if rule.ProductId == productAmount.ProductId && rule.LocationId == productAmount.FromLocationId {
+				rule.Prediction = rule.Prediction.Add(productAmount.Amount)
+			}
+		}
+		rule.Prediction = rule.Amount.Add(mp[rule.Id]).Sub(rule.Prediction)
+	}
+
+	util.ResponseFormatList(c, code.Success, rules, int(total))
+}
+
+// 璁$畻鍦ㄥ簱涓庨娴嬫暟閲�
+func GetProductAmount(productIds []string, toLocationIds []int, fromLocationIds []int, status []constvar.OperationStatus,
+	operationType []constvar.BaseOperationType) ([]request.ProductAmount, error) {
+	var pa []request.ProductAmount
+	search := models.NewOperationDetailsSearch()
+	search.Orm = search.Orm.Model(&models.OperationDetails{}).
+		Select("wms_operation_details.product_id, wms_operation_details.amount, wms_operation.to_location_id as to_location_id, " +
+			"wms_operation.from_location_id as from_location_id, wms_operation.status").
+		Joins("left join wms_operation on wms_operation_details.operation_id = wms_operation.id")
+	if len(productIds) > 0 {
+		search.Orm.Where("wms_operation_details.product_id in (?)", productIds)
+	}
+	if len(toLocationIds) > 0 {
+		search.Orm.Where("wms_operation.to_location_id in (?)", toLocationIds)
+	}
+	if len(fromLocationIds) > 0 {
+		search.Orm.Where("wms_operation.from_location_id in (?)", fromLocationIds)
+	}
+	if len(status) > 0 {
+		search.Orm.Where("wms_operation.status in (?)", status)
+	}
+	if len(operationType) > 0 {
+		search.Orm.Where("wms_operation.base_operation_type in (?)", operationType)
+	}
+	err := search.Orm.Find(&pa).Error
+	return pa, err
+}
+
+// GetAmountAndPrediction
+// @Tags      閲嶈璐ц鍒�
+// @Summary   鑾峰彇鍦ㄥ簱涓庨娴嬫暟閲�
+// @Produce   application/json
+// @Param     object  body  request.GetAmountAndPrediction true  "閲嶈璐ц鍒�"
+// @Success   200 {object} util.ResponseList{data=[]map[string]interface{}} "鎴愬姛"
+// @Router    /api-wms/v1/reorderRule/getAmountAndPrediction [post]
+func (slf ReorderRuleController) GetAmountAndPrediction(c *gin.Context) {
+	var params request.GetAmountAndPrediction
+	if err := c.BindJSON(&params); err != nil {
+		util.ResponseFormat(c, code.RequestParamError, "鍙傛暟瑙f瀽澶辫触锛屾暟鎹被鍨嬮敊璇�")
+		return
+	}
+	productIds := make([]string, 0)
+	locationIds := make([]int, 0)
+	productIds = append(productIds, params.ProductId)
+	locationIds = append(locationIds, params.LocationId)
+	amount := decimal.NewFromInt(0)
+	p := decimal.NewFromInt(0)
+	prediction := decimal.NewFromInt(0)
+	//鍦ㄥ簱
+	var status = []constvar.OperationStatus{constvar.OperationStatus_Finish, constvar.OperationStatus_Ready}
+	var operationType = []constvar.BaseOperationType{constvar.BaseOperationTypeIncoming, constvar.BaseOperationTypeInternal}
+	list, err := GetProductAmount(productIds, locationIds, nil, status, operationType)
+	if err != nil {
+		util.ResponseFormat(c, code.RequestParamError, "鏌ヨ閲嶈璐ц鍒欏垪琛ㄥけ璐�")
+		return
+	}
+	for _, productAmount := range list {
+		if params.ProductId == productAmount.ProductId && params.LocationId == productAmount.ToLocationId &&
+			productAmount.Status == constvar.OperationStatus_Finish {
+			amount = amount.Add(productAmount.Amount)
+		}
+		if params.ProductId == productAmount.ProductId && params.LocationId == productAmount.ToLocationId &&
+			productAmount.Status == constvar.OperationStatus_Ready {
+			p = p.Add(productAmount.Amount)
+		}
+	}
+	//棰勬祴
+	status = []constvar.OperationStatus{constvar.OperationStatus_Finish, constvar.OperationStatus_Ready}
+	operationType = []constvar.BaseOperationType{constvar.BaseOperationTypeOutgoing, constvar.BaseOperationTypeInternal}
+	list, err = GetProductAmount(productIds, nil, locationIds, status, operationType)
+	if err != nil {
+		util.ResponseFormat(c, code.RequestParamError, "鏌ヨ閲嶈璐ц鍒欏垪琛ㄥけ璐�")
+		return
+	}
+	for _, productAmount := range list {
+		if params.ProductId == productAmount.ProductId && params.LocationId == productAmount.ToLocationId {
+			prediction = prediction.Add(productAmount.Amount)
+		}
+	}
+	prediction = amount.Add(p).Sub(prediction)
+	m := make(map[string]int64)
+	m["amount"] = amount.IntPart()
+	m["prediction"] = prediction.IntPart()
+	util.ResponseFormat(c, code.Success, m)
+}
+
+// UpdateReorderRule
+// @Tags      閲嶈璐ц鍒�
+// @Summary   鏇存柊閲嶈璐ц鍒�
+// @Produce   application/json
+// @Param     object  body  models.ReorderRule true  "閲嶈璐ц鍒�"
+// @Success   200 {object} util.Response "鎴愬姛"
+// @Router    /api-wms/v1/reorderRule/updateReorderRule [post]
+func (slf ReorderRuleController) UpdateReorderRule(c *gin.Context) {
+	var params models.ReorderRule
+	if err := c.BindJSON(&params); err != nil {
+		util.ResponseFormat(c, code.RequestParamError, "鍙傛暟瑙f瀽澶辫触锛屾暟鎹被鍨嬮敊璇�")
+		return
+	}
+	err := models.NewReorderRuleSearch().SetID(params.Id).Update(&params)
+	if err != nil {
+		util.ResponseFormat(c, code.RequestError, "閲嶈璐ц鍒欐洿鏂板け璐�")
+		return
+	}
+	util.ResponseFormat(c, code.Success, "鏇存柊鎴愬姛")
+}
+
+// OrderAgain
+// @Tags      閲嶈璐ц鍒�
+// @Summary   鍐嶈涓�娆�
+// @Produce   application/json
+// @Param     object  body  models.ReorderRule true  "閲嶈璐ц鍒�"
+// @Success   200 {object} util.Response "鎴愬姛"
+// @Router    /api-wms/v1/reorderRule/orderAgain [post]
+func (slf ReorderRuleController) OrderAgain(c *gin.Context) {
+	var params models.ReorderRule
+	if err := c.BindJSON(&params); err != nil {
+		util.ResponseFormat(c, code.RequestParamError, "鍙傛暟瑙f瀽澶辫触锛屾暟鎹被鍨嬮敊璇�")
+		return
+	}
+	location, err := models.NewLocationSearch().SetID(params.LocationId).First()
+	if err != nil {
+		util.ResponseFormat(c, code.RequestParamError, "鏌ヨ浣嶇疆淇℃伅澶辫触")
+		return
+	}
+	houseCode := strings.Split(location.JointName, "/")[0]
+	var operationType models.OperationType
+	err = models.NewOperationTypeSearch().Orm.Model(&models.OperationType{}).Joins("left join wms_warehouse on wms_job_type.warehouse_id = wms_warehouse.id").
+		Where("wms_job_type.base_operation_type = 1 and wms_warehouse.code = ?", houseCode).First(&operationType).Error
+	if err != nil {
+		util.ResponseFormat(c, code.RequestParamError, "鏌ヨ浣嶇疆淇℃伅澶辫触")
+		return
+	}
+	var operation models.Operation
+	var details models.OperationDetails
+	details.ProductId = params.ProductId
+	details.Amount = params.OrderNumber
+	operation.Details = append(operation.Details, &details)
+	operation.BaseOperationType = constvar.BaseOperationTypeIncoming
+	operation.Status = constvar.OperationStatus_Ready
+	operation.OperationTypeId = operationType.Id
+	operation.OperationTypeName = operationType.Name
+	operation.OperationDate = timex.TimeToString2(time.Now())
+	//todo 渚涘簲鍟嗕綅缃�
+	operation.FromLocationID = 1
+	operation.Number = strconv.FormatInt(time.Now().Unix(), 10)
+	operation.ToLocationID = params.LocationId
+
+	err = models.WithTransaction(func(db *gorm.DB) error {
+		if err = models.NewOperationSearch().SetOrm(db).Create(&operation); err != nil {
+			return err
+		}
+		params.OrderNumber = decimal.NewFromInt(0)
+		err = models.NewReorderRuleSearch().SetID(params.Id).Update(&params)
+		return err
+	})
+	if err != nil {
+		util.ResponseFormat(c, code.RequestParamError, "閲嶈澶辫触")
+		return
+	}
+	util.ResponseFormat(c, code.Success, "閲嶈鎴愬姛")
+}
diff --git a/controllers/report_forms_controller.go b/controllers/report_forms_controller.go
index 88dc93a..afffdb5 100644
--- a/controllers/report_forms_controller.go
+++ b/controllers/report_forms_controller.go
@@ -152,8 +152,8 @@
 	for _, detail := range details {
 		var resp response.InventoryHistory
 		resp.Amount = detail.Amount
-		resp.Unit = params.Unit
-		resp.ProductName = params.ProductName
+		resp.Unit = detail.Product.Unit
+		resp.ProductName = detail.Product.Name
 		for _, operation := range operations {
 			if detail.OperationID == operation.Id {
 				resp.Number = operation.Number
@@ -162,6 +162,7 @@
 				resp.ContactedName = operation.ContacterName
 				resp.FromLocation = operation.FromLocation.Name
 				resp.ToLocation = operation.ToLocation.Name
+				resp.BaseOperationType = operation.BaseOperationType
 				result = append(result, resp)
 				break
 			}
diff --git a/docs/docs.go b/docs/docs.go
index 56f55bb..58d7d71 100644
--- a/docs/docs.go
+++ b/docs/docs.go
@@ -1770,6 +1770,187 @@
                 }
             }
         },
+        "/api-wms/v1/reorderRule/addReorderRule": {
+            "post": {
+                "produces": [
+                    "application/json"
+                ],
+                "tags": [
+                    "閲嶈璐ц鍒�"
+                ],
+                "summary": "娣诲姞閲嶈璐ц鍒�",
+                "parameters": [
+                    {
+                        "description": "閲嶈璐ц鍒�",
+                        "name": "object",
+                        "in": "body",
+                        "required": true,
+                        "schema": {
+                            "$ref": "#/definitions/models.ReorderRule"
+                        }
+                    }
+                ],
+                "responses": {
+                    "200": {
+                        "description": "鎴愬姛",
+                        "schema": {
+                            "$ref": "#/definitions/util.Response"
+                        }
+                    }
+                }
+            }
+        },
+        "/api-wms/v1/reorderRule/getAmountAndPrediction": {
+            "post": {
+                "produces": [
+                    "application/json"
+                ],
+                "tags": [
+                    "閲嶈璐ц鍒�"
+                ],
+                "summary": "鑾峰彇鍦ㄥ簱涓庨娴嬫暟閲�",
+                "parameters": [
+                    {
+                        "description": "閲嶈璐ц鍒�",
+                        "name": "object",
+                        "in": "body",
+                        "required": true,
+                        "schema": {
+                            "$ref": "#/definitions/request.GetAmountAndPrediction"
+                        }
+                    }
+                ],
+                "responses": {
+                    "200": {
+                        "description": "鎴愬姛",
+                        "schema": {
+                            "allOf": [
+                                {
+                                    "$ref": "#/definitions/util.ResponseList"
+                                },
+                                {
+                                    "type": "object",
+                                    "properties": {
+                                        "data": {
+                                            "type": "array",
+                                            "items": {
+                                                "type": "object",
+                                                "additionalProperties": true
+                                            }
+                                        }
+                                    }
+                                }
+                            ]
+                        }
+                    }
+                }
+            }
+        },
+        "/api-wms/v1/reorderRule/getReorderRuleList": {
+            "post": {
+                "produces": [
+                    "application/json"
+                ],
+                "tags": [
+                    "閲嶈璐ц鍒�"
+                ],
+                "summary": "鑾峰彇閲嶈璐ц鍒欏垪琛�",
+                "parameters": [
+                    {
+                        "description": "鍙傛暟",
+                        "name": "object",
+                        "in": "body",
+                        "required": true,
+                        "schema": {
+                            "$ref": "#/definitions/request.GetReorderRuleList"
+                        }
+                    }
+                ],
+                "responses": {
+                    "200": {
+                        "description": "鎴愬姛",
+                        "schema": {
+                            "allOf": [
+                                {
+                                    "$ref": "#/definitions/util.ResponseList"
+                                },
+                                {
+                                    "type": "object",
+                                    "properties": {
+                                        "data": {
+                                            "type": "array",
+                                            "items": {
+                                                "$ref": "#/definitions/models.ReorderRule"
+                                            }
+                                        }
+                                    }
+                                }
+                            ]
+                        }
+                    }
+                }
+            }
+        },
+        "/api-wms/v1/reorderRule/orderAgain": {
+            "post": {
+                "produces": [
+                    "application/json"
+                ],
+                "tags": [
+                    "閲嶈璐ц鍒�"
+                ],
+                "summary": "鍐嶈涓�娆�",
+                "parameters": [
+                    {
+                        "description": "閲嶈璐ц鍒�",
+                        "name": "object",
+                        "in": "body",
+                        "required": true,
+                        "schema": {
+                            "$ref": "#/definitions/models.ReorderRule"
+                        }
+                    }
+                ],
+                "responses": {
+                    "200": {
+                        "description": "鎴愬姛",
+                        "schema": {
+                            "$ref": "#/definitions/util.Response"
+                        }
+                    }
+                }
+            }
+        },
+        "/api-wms/v1/reorderRule/updateReorderRule": {
+            "post": {
+                "produces": [
+                    "application/json"
+                ],
+                "tags": [
+                    "閲嶈璐ц鍒�"
+                ],
+                "summary": "鏇存柊閲嶈璐ц鍒�",
+                "parameters": [
+                    {
+                        "description": "閲嶈璐ц鍒�",
+                        "name": "object",
+                        "in": "body",
+                        "required": true,
+                        "schema": {
+                            "$ref": "#/definitions/models.ReorderRule"
+                        }
+                    }
+                ],
+                "responses": {
+                    "200": {
+                        "description": "鎴愬姛",
+                        "schema": {
+                            "$ref": "#/definitions/util.Response"
+                        }
+                    }
+                }
+            }
+        },
         "/api-wms/v1/warehouse/getWarehouseDetails/{id}": {
             "get": {
                 "produces": [
@@ -2688,6 +2869,62 @@
                 }
             }
         },
+        "models.ReorderRule": {
+            "type": "object",
+            "properties": {
+                "amount": {
+                    "description": "鍦ㄥ簱鏁伴噺",
+                    "type": "number"
+                },
+                "createTime": {
+                    "type": "string"
+                },
+                "id": {
+                    "type": "integer"
+                },
+                "location": {
+                    "$ref": "#/definitions/models.Location"
+                },
+                "locationId": {
+                    "description": "浣嶇疆id",
+                    "type": "integer"
+                },
+                "maxInventory": {
+                    "description": "鏈�澶у簱瀛�",
+                    "type": "number"
+                },
+                "minInventory": {
+                    "description": "鏈�灏忓簱瀛�",
+                    "type": "number"
+                },
+                "orderNumber": {
+                    "description": "璁㈣喘鏁伴噺",
+                    "type": "number"
+                },
+                "prediction": {
+                    "description": "棰勬祴鏁伴噺",
+                    "type": "number"
+                },
+                "product": {
+                    "$ref": "#/definitions/models.Material"
+                },
+                "productId": {
+                    "description": "浜у搧id",
+                    "type": "string"
+                },
+                "route": {
+                    "description": "璺嚎",
+                    "type": "string"
+                },
+                "unit": {
+                    "description": "鍗曚綅",
+                    "type": "string"
+                },
+                "updateTime": {
+                    "type": "string"
+                }
+            }
+        },
         "models.Warehouse": {
             "type": "object",
             "required": [
@@ -3055,6 +3292,17 @@
                 }
             }
         },
+        "request.GetAmountAndPrediction": {
+            "type": "object",
+            "properties": {
+                "locationId": {
+                    "type": "integer"
+                },
+                "productId": {
+                    "type": "string"
+                }
+            }
+        },
         "request.GetInventoryForms": {
             "type": "object",
             "properties": {
@@ -3148,6 +3396,22 @@
                 "categoryId": {
                     "type": "integer"
                 },
+                "keyWord": {
+                    "type": "string"
+                },
+                "page": {
+                    "description": "椤电爜",
+                    "type": "integer"
+                },
+                "pageSize": {
+                    "description": "姣忛〉澶у皬",
+                    "type": "integer"
+                }
+            }
+        },
+        "request.GetReorderRuleList": {
+            "type": "object",
+            "properties": {
                 "keyWord": {
                     "type": "string"
                 },
@@ -3630,6 +3894,14 @@
                     "description": "鏁伴噺",
                     "type": "number"
                 },
+                "baseOperationType": {
+                    "description": "鍩虹浣滀笟绫诲瀷",
+                    "allOf": [
+                        {
+                            "$ref": "#/definitions/constvar.BaseOperationType"
+                        }
+                    ]
+                },
                 "contactedName": {
                     "description": "瀹屾垚鑰�",
                     "type": "string"
@@ -3762,6 +4034,8 @@
 	Description:      "",
 	InfoInstanceName: "swagger",
 	SwaggerTemplate:  docTemplate,
+	LeftDelim:        "{{",
+	RightDelim:       "}}",
 }
 
 func init() {
diff --git a/docs/swagger.json b/docs/swagger.json
index 03c0a38..c430ead 100644
--- a/docs/swagger.json
+++ b/docs/swagger.json
@@ -1758,6 +1758,187 @@
                 }
             }
         },
+        "/api-wms/v1/reorderRule/addReorderRule": {
+            "post": {
+                "produces": [
+                    "application/json"
+                ],
+                "tags": [
+                    "閲嶈璐ц鍒�"
+                ],
+                "summary": "娣诲姞閲嶈璐ц鍒�",
+                "parameters": [
+                    {
+                        "description": "閲嶈璐ц鍒�",
+                        "name": "object",
+                        "in": "body",
+                        "required": true,
+                        "schema": {
+                            "$ref": "#/definitions/models.ReorderRule"
+                        }
+                    }
+                ],
+                "responses": {
+                    "200": {
+                        "description": "鎴愬姛",
+                        "schema": {
+                            "$ref": "#/definitions/util.Response"
+                        }
+                    }
+                }
+            }
+        },
+        "/api-wms/v1/reorderRule/getAmountAndPrediction": {
+            "post": {
+                "produces": [
+                    "application/json"
+                ],
+                "tags": [
+                    "閲嶈璐ц鍒�"
+                ],
+                "summary": "鑾峰彇鍦ㄥ簱涓庨娴嬫暟閲�",
+                "parameters": [
+                    {
+                        "description": "閲嶈璐ц鍒�",
+                        "name": "object",
+                        "in": "body",
+                        "required": true,
+                        "schema": {
+                            "$ref": "#/definitions/request.GetAmountAndPrediction"
+                        }
+                    }
+                ],
+                "responses": {
+                    "200": {
+                        "description": "鎴愬姛",
+                        "schema": {
+                            "allOf": [
+                                {
+                                    "$ref": "#/definitions/util.ResponseList"
+                                },
+                                {
+                                    "type": "object",
+                                    "properties": {
+                                        "data": {
+                                            "type": "array",
+                                            "items": {
+                                                "type": "object",
+                                                "additionalProperties": true
+                                            }
+                                        }
+                                    }
+                                }
+                            ]
+                        }
+                    }
+                }
+            }
+        },
+        "/api-wms/v1/reorderRule/getReorderRuleList": {
+            "post": {
+                "produces": [
+                    "application/json"
+                ],
+                "tags": [
+                    "閲嶈璐ц鍒�"
+                ],
+                "summary": "鑾峰彇閲嶈璐ц鍒欏垪琛�",
+                "parameters": [
+                    {
+                        "description": "鍙傛暟",
+                        "name": "object",
+                        "in": "body",
+                        "required": true,
+                        "schema": {
+                            "$ref": "#/definitions/request.GetReorderRuleList"
+                        }
+                    }
+                ],
+                "responses": {
+                    "200": {
+                        "description": "鎴愬姛",
+                        "schema": {
+                            "allOf": [
+                                {
+                                    "$ref": "#/definitions/util.ResponseList"
+                                },
+                                {
+                                    "type": "object",
+                                    "properties": {
+                                        "data": {
+                                            "type": "array",
+                                            "items": {
+                                                "$ref": "#/definitions/models.ReorderRule"
+                                            }
+                                        }
+                                    }
+                                }
+                            ]
+                        }
+                    }
+                }
+            }
+        },
+        "/api-wms/v1/reorderRule/orderAgain": {
+            "post": {
+                "produces": [
+                    "application/json"
+                ],
+                "tags": [
+                    "閲嶈璐ц鍒�"
+                ],
+                "summary": "鍐嶈涓�娆�",
+                "parameters": [
+                    {
+                        "description": "閲嶈璐ц鍒�",
+                        "name": "object",
+                        "in": "body",
+                        "required": true,
+                        "schema": {
+                            "$ref": "#/definitions/models.ReorderRule"
+                        }
+                    }
+                ],
+                "responses": {
+                    "200": {
+                        "description": "鎴愬姛",
+                        "schema": {
+                            "$ref": "#/definitions/util.Response"
+                        }
+                    }
+                }
+            }
+        },
+        "/api-wms/v1/reorderRule/updateReorderRule": {
+            "post": {
+                "produces": [
+                    "application/json"
+                ],
+                "tags": [
+                    "閲嶈璐ц鍒�"
+                ],
+                "summary": "鏇存柊閲嶈璐ц鍒�",
+                "parameters": [
+                    {
+                        "description": "閲嶈璐ц鍒�",
+                        "name": "object",
+                        "in": "body",
+                        "required": true,
+                        "schema": {
+                            "$ref": "#/definitions/models.ReorderRule"
+                        }
+                    }
+                ],
+                "responses": {
+                    "200": {
+                        "description": "鎴愬姛",
+                        "schema": {
+                            "$ref": "#/definitions/util.Response"
+                        }
+                    }
+                }
+            }
+        },
         "/api-wms/v1/warehouse/getWarehouseDetails/{id}": {
             "get": {
                 "produces": [
@@ -2676,6 +2857,62 @@
                 }
             }
         },
+        "models.ReorderRule": {
+            "type": "object",
+            "properties": {
+                "amount": {
+                    "description": "鍦ㄥ簱鏁伴噺",
+                    "type": "number"
+                },
+                "createTime": {
+                    "type": "string"
+                },
+                "id": {
+                    "type": "integer"
+                },
+                "location": {
+                    "$ref": "#/definitions/models.Location"
+                },
+                "locationId": {
+                    "description": "浣嶇疆id",
+                    "type": "integer"
+                },
+                "maxInventory": {
+                    "description": "鏈�澶у簱瀛�",
+                    "type": "number"
+                },
+                "minInventory": {
+                    "description": "鏈�灏忓簱瀛�",
+                    "type": "number"
+                },
+                "orderNumber": {
+                    "description": "璁㈣喘鏁伴噺",
+                    "type": "number"
+                },
+                "prediction": {
+                    "description": "棰勬祴鏁伴噺",
+                    "type": "number"
+                },
+                "product": {
+                    "$ref": "#/definitions/models.Material"
+                },
+                "productId": {
+                    "description": "浜у搧id",
+                    "type": "string"
+                },
+                "route": {
+                    "description": "璺嚎",
+                    "type": "string"
+                },
+                "unit": {
+                    "description": "鍗曚綅",
+                    "type": "string"
+                },
+                "updateTime": {
+                    "type": "string"
+                }
+            }
+        },
         "models.Warehouse": {
             "type": "object",
             "required": [
@@ -3043,6 +3280,17 @@
                 }
             }
         },
+        "request.GetAmountAndPrediction": {
+            "type": "object",
+            "properties": {
+                "locationId": {
+                    "type": "integer"
+                },
+                "productId": {
+                    "type": "string"
+                }
+            }
+        },
         "request.GetInventoryForms": {
             "type": "object",
             "properties": {
@@ -3136,6 +3384,22 @@
                 "categoryId": {
                     "type": "integer"
                 },
+                "keyWord": {
+                    "type": "string"
+                },
+                "page": {
+                    "description": "椤电爜",
+                    "type": "integer"
+                },
+                "pageSize": {
+                    "description": "姣忛〉澶у皬",
+                    "type": "integer"
+                }
+            }
+        },
+        "request.GetReorderRuleList": {
+            "type": "object",
+            "properties": {
                 "keyWord": {
                     "type": "string"
                 },
@@ -3618,6 +3882,14 @@
                     "description": "鏁伴噺",
                     "type": "number"
                 },
+                "baseOperationType": {
+                    "description": "鍩虹浣滀笟绫诲瀷",
+                    "allOf": [
+                        {
+                            "$ref": "#/definitions/constvar.BaseOperationType"
+                        }
+                    ]
+                },
                 "contactedName": {
                     "description": "瀹屾垚鑰�",
                     "type": "string"
diff --git a/docs/swagger.yaml b/docs/swagger.yaml
index c8df29e..a9369d0 100644
--- a/docs/swagger.yaml
+++ b/docs/swagger.yaml
@@ -541,6 +541,46 @@
         description: 鍏徃
         type: string
     type: object
+  models.ReorderRule:
+    properties:
+      amount:
+        description: 鍦ㄥ簱鏁伴噺
+        type: number
+      createTime:
+        type: string
+      id:
+        type: integer
+      location:
+        $ref: '#/definitions/models.Location'
+      locationId:
+        description: 浣嶇疆id
+        type: integer
+      maxInventory:
+        description: 鏈�澶у簱瀛�
+        type: number
+      minInventory:
+        description: 鏈�灏忓簱瀛�
+        type: number
+      orderNumber:
+        description: 璁㈣喘鏁伴噺
+        type: number
+      prediction:
+        description: 棰勬祴鏁伴噺
+        type: number
+      product:
+        $ref: '#/definitions/models.Material'
+      productId:
+        description: 浜у搧id
+        type: string
+      route:
+        description: 璺嚎
+        type: string
+      unit:
+        description: 鍗曚綅
+        type: string
+      updateTime:
+        type: string
+    type: object
   models.Warehouse:
     properties:
       active:
@@ -798,6 +838,13 @@
         description: 浜у搧id
         type: string
     type: object
+  request.GetAmountAndPrediction:
+    properties:
+      locationId:
+        type: integer
+      productId:
+        type: string
+    type: object
   request.GetInventoryForms:
     properties:
       categoryIds:
@@ -862,6 +909,17 @@
     properties:
       categoryId:
         type: integer
+      keyWord:
+        type: string
+      page:
+        description: 椤电爜
+        type: integer
+      pageSize:
+        description: 姣忛〉澶у皬
+        type: integer
+    type: object
+  request.GetReorderRuleList:
+    properties:
       keyWord:
         type: string
       page:
@@ -1196,6 +1254,10 @@
       amount:
         description: 鏁伴噺
         type: number
+      baseOperationType:
+        allOf:
+        - $ref: '#/definitions/constvar.BaseOperationType'
+        description: 鍩虹浣滀笟绫诲瀷
       contactedName:
         description: 瀹屾垚鑰�
         type: string
@@ -2364,6 +2426,116 @@
       summary: 淇敼浜у搧绫诲瀷
       tags:
       - 浜у搧绫诲瀷
+  /api-wms/v1/reorderRule/addReorderRule:
+    post:
+      parameters:
+      - description: 閲嶈璐ц鍒�
+        in: body
+        name: object
+        required: true
+        schema:
+          $ref: '#/definitions/models.ReorderRule'
+      produces:
+      - application/json
+      responses:
+        "200":
+          description: 鎴愬姛
+          schema:
+            $ref: '#/definitions/util.Response'
+      summary: 娣诲姞閲嶈璐ц鍒�
+      tags:
+      - 閲嶈璐ц鍒�
+  /api-wms/v1/reorderRule/getAmountAndPrediction:
+    post:
+      parameters:
+      - description: 閲嶈璐ц鍒�
+        in: body
+        name: object
+        required: true
+        schema:
+          $ref: '#/definitions/request.GetAmountAndPrediction'
+      produces:
+      - application/json
+      responses:
+        "200":
+          description: 鎴愬姛
+          schema:
+            allOf:
+            - $ref: '#/definitions/util.ResponseList'
+            - properties:
+                data:
+                  items:
+                    additionalProperties: true
+                    type: object
+                  type: array
+              type: object
+      summary: 鑾峰彇鍦ㄥ簱涓庨娴嬫暟閲�
+      tags:
+      - 閲嶈璐ц鍒�
+  /api-wms/v1/reorderRule/getReorderRuleList:
+    post:
+      parameters:
+      - description: 鍙傛暟
+        in: body
+        name: object
+        required: true
+        schema:
+          $ref: '#/definitions/request.GetReorderRuleList'
+      produces:
+      - application/json
+      responses:
+        "200":
+          description: 鎴愬姛
+          schema:
+            allOf:
+            - $ref: '#/definitions/util.ResponseList'
+            - properties:
+                data:
+                  items:
+                    $ref: '#/definitions/models.ReorderRule'
+                  type: array
+              type: object
+      summary: 鑾峰彇閲嶈璐ц鍒欏垪琛�
+      tags:
+      - 閲嶈璐ц鍒�
+  /api-wms/v1/reorderRule/orderAgain:
+    post:
+      parameters:
+      - description: 閲嶈璐ц鍒�
+        in: body
+        name: object
+        required: true
+        schema:
+          $ref: '#/definitions/models.ReorderRule'
+      produces:
+      - application/json
+      responses:
+        "200":
+          description: 鎴愬姛
+          schema:
+            $ref: '#/definitions/util.Response'
+      summary: 鍐嶈涓�娆�
+      tags:
+      - 閲嶈璐ц鍒�
+  /api-wms/v1/reorderRule/updateReorderRule:
+    post:
+      parameters:
+      - description: 閲嶈璐ц鍒�
+        in: body
+        name: object
+        required: true
+        schema:
+          $ref: '#/definitions/models.ReorderRule'
+      produces:
+      - application/json
+      responses:
+        "200":
+          description: 鎴愬姛
+          schema:
+            $ref: '#/definitions/util.Response'
+      summary: 鏇存柊閲嶈璐ц鍒�
+      tags:
+      - 閲嶈璐ц鍒�
   /api-wms/v1/warehouse/getWarehouseDetails/{id}:
     get:
       parameters:
diff --git a/models/db.go b/models/db.go
index a1570c8..480edaa 100644
--- a/models/db.go
+++ b/models/db.go
@@ -81,12 +81,11 @@
 		Operation{},
 		OperationDetails{},
 		Scrap{},
-		MoveHistory{},
-		//Product{},
 		ProductCategory{},
 		Material{},
 		LocationProduct{},
 		LocationProductAmount{},
+		ReorderRule{},
 	)
 	return err
 }
diff --git a/models/move_history.go b/models/move_history.go
deleted file mode 100644
index 3bd9974..0000000
--- a/models/move_history.go
+++ /dev/null
@@ -1,244 +0,0 @@
-package models
-
-import (
-	"fmt"
-	"google.golang.org/genproto/googleapis/type/decimal"
-	"gorm.io/gorm"
-	"wms/constvar"
-	"wms/pkg/mysqlx"
-)
-
-type (
-	// MoveHistory 绉诲姩鍘嗗彶
-	MoveHistory struct {
-		WmsModel
-		Id                int                        `json:"id" gorm:"column:id;primary_key;AUTO_INCREMENT"`
-		Number            string                     `json:"number" gorm:"column:number;type:varchar(255)"`                 //鍗曞彿
-		BaseOperationType constvar.BaseOperationType `json:"baseOperationType" gorm:"type:tinyint;not null;comment:鍩虹浣滀笟绫诲瀷"` //鍩虹浣滀笟绫诲瀷
-		OperationTypeId   int                        `json:"operationTypeId" gorm:"type:int;not null;comment:浣滀笟绫诲瀷id"`       //浣滀笟绫诲瀷id
-		OperationId       int                        `json:"operationRecordId" gorm:"type:int;not null;comment:鎿嶄綔id"`       //鎿嶄綔id
-
-		ProductId   int             `json:"productId" gorm:"type:int;not null;comment:浜у搧id"`            //浜у搧id
-		ProductName string          `json:"productName" gorm:"type:varchar(255);not null;comment:浜у搧鍚嶇О"` //浜у搧鍚嶇О
-		Quantity    decimal.Decimal `json:"quantity" gorm:"type:decimal(20,2);not null;comment:鏁伴噺"`     //鏁伴噺
-
-		FromLocationId int      `json:"fromLocationId"   gorm:"type:int;not null;comment:婧愪綅缃甶d"` //婧愪綅缃甶d
-		FromLocation   Location `json:"fromLocation"     gorm:"foreignKey:FromLocationId"`       //婧愪綅缃�
-		ToLocationId   int      `json:"toLocationId"  gorm:"type:int;not null;comment:鐩爣浣嶇疆id"`   //鐩爣浣嶇疆id
-		ToLocation     Location `json:"toLocation"    gorm:"foreignKey:ToLocationId"`            //鐩爣浣嶇疆
-	}
-
-	MoveHistorySearch struct {
-		MoveHistory
-		Order    string
-		PageNum  int
-		PageSize int
-		Keyword  string
-		Orm      *gorm.DB
-		Preload  bool
-	}
-)
-
-func (slf *MoveHistory) TableName() string {
-	return "wms_move_history"
-}
-
-func NewMoveHistorySearch() *MoveHistorySearch {
-	return &MoveHistorySearch{Orm: mysqlx.GetDB()}
-}
-
-func (slf *MoveHistorySearch) SetOrm(tx *gorm.DB) *MoveHistorySearch {
-	slf.Orm = tx
-	return slf
-}
-
-func (slf *MoveHistorySearch) SetPage(page, size int) *MoveHistorySearch {
-	slf.PageNum, slf.PageSize = page, size
-	return slf
-}
-
-func (slf *MoveHistorySearch) SetOrder(order string) *MoveHistorySearch {
-	slf.Order = order
-	return slf
-}
-
-func (slf *MoveHistorySearch) SetID(id uint) *MoveHistorySearch {
-	slf.ID = id
-	return slf
-}
-
-func (slf *MoveHistorySearch) SetKeyword(keyword string) *MoveHistorySearch {
-	slf.Keyword = keyword
-	return slf
-}
-
-func (slf *MoveHistorySearch) SetPreload(preload bool) *MoveHistorySearch {
-	slf.Preload = preload
-	return slf
-}
-
-func (slf *MoveHistorySearch) build() *gorm.DB {
-	var db = slf.Orm.Model(&MoveHistory{})
-
-	if slf.ID != 0 {
-		db = db.Where("id = ?", slf.ID)
-	}
-
-	if slf.Order != "" {
-		db = db.Order(slf.Order)
-	}
-
-	if slf.Keyword != "" {
-		db = db.Where("product_name like ?", fmt.Sprintf("%%%v%%", slf.Keyword))
-	}
-
-	return db
-}
-
-// Create 鍗曟潯鎻掑叆
-func (slf *MoveHistorySearch) Create(record *MoveHistory) error {
-	var db = slf.build()
-
-	if err := db.Create(record).Error; err != nil {
-		return err
-	}
-
-	return nil
-}
-
-// CreateBatch 鎵归噺鎻掑叆
-func (slf *MoveHistorySearch) CreateBatch(records []*MoveHistory) error {
-	var db = slf.build()
-
-	if err := db.Create(&records).Error; err != nil {
-		return fmt.Errorf("create batch err: %v, records: %+v", err, records)
-	}
-
-	return nil
-}
-
-func (slf *MoveHistorySearch) Update(record *MoveHistory) error {
-	var db = slf.build()
-
-	if err := db.Omit("CreatedAt").Updates(record).Error; err != nil {
-		return fmt.Errorf("save err: %v, record: %+v", err, record)
-	}
-
-	return nil
-}
-
-func (slf *MoveHistorySearch) UpdateByMap(upMap map[string]interface{}) error {
-	var (
-		db = slf.build()
-	)
-
-	if err := db.Updates(upMap).Error; err != nil {
-		return fmt.Errorf("update by map err: %v, upMap: %+v", err, upMap)
-	}
-
-	return nil
-}
-
-func (slf *MoveHistorySearch) UpdateByQuery(query string, args []interface{}, upMap map[string]interface{}) error {
-	var (
-		db = slf.Orm.Table(slf.TableName()).Where(query, args...)
-	)
-
-	if err := db.Updates(upMap).Error; err != nil {
-		return fmt.Errorf("update by query err: %v, query: %s, args: %+v, upMap: %+v", err, query, args, upMap)
-	}
-
-	return nil
-}
-
-func (slf *MoveHistorySearch) Delete() error {
-	var db = slf.build()
-	return db.Delete(&MoveHistory{}).Error
-}
-
-func (slf *MoveHistorySearch) First() (*MoveHistory, error) {
-	var (
-		record = new(MoveHistory)
-		db     = slf.build()
-	)
-
-	if err := db.First(record).Error; err != nil {
-		return record, err
-	}
-
-	return record, nil
-}
-
-func (slf *MoveHistorySearch) Find() ([]*MoveHistory, int64, error) {
-	var (
-		records = make([]*MoveHistory, 0)
-		total   int64
-		db      = slf.build()
-	)
-
-	if err := db.Count(&total).Error; err != nil {
-		return records, total, fmt.Errorf("find count err: %v", err)
-	}
-	if slf.PageNum*slf.PageSize > 0 {
-		db = db.Offset((slf.PageNum - 1) * slf.PageSize).Limit(slf.PageSize)
-	}
-	if err := db.Find(&records).Error; err != nil {
-		return records, total, fmt.Errorf("find records err: %v", err)
-	}
-
-	return records, total, nil
-}
-
-func (slf *MoveHistorySearch) FindNotTotal() ([]*MoveHistory, error) {
-	var (
-		records = make([]*MoveHistory, 0)
-		db      = slf.build()
-	)
-
-	if slf.PageNum*slf.PageSize > 0 {
-		db = db.Offset((slf.PageNum - 1) * slf.PageSize).Limit(slf.PageSize)
-	}
-	if err := db.Find(&records).Error; err != nil {
-		return records, fmt.Errorf("find records err: %v", err)
-	}
-
-	return records, nil
-}
-
-// FindByQuery 鎸囧畾鏉′欢鏌ヨ.
-func (slf *MoveHistorySearch) FindByQuery(query string, args []interface{}) ([]*MoveHistory, int64, error) {
-	var (
-		records = make([]*MoveHistory, 0)
-		total   int64
-		db      = slf.Orm.Table(slf.TableName()).Where(query, args...)
-	)
-
-	if err := db.Count(&total).Error; err != nil {
-		return records, total, fmt.Errorf("find by query count err: %v", err)
-	}
-	if slf.PageNum*slf.PageSize > 0 {
-		db = db.Offset((slf.PageNum - 1) * slf.PageSize).Limit(slf.PageSize)
-	}
-	if err := db.Find(&records).Error; err != nil {
-		return records, total, fmt.Errorf("find by query records err: %v, query: %s, args: %+v", err, query, args)
-	}
-
-	return records, total, nil
-}
-
-// FindByQueryNotTotal 鎸囧畾鏉′欢鏌ヨ&涓嶆煡璇㈡�绘潯鏁�.
-func (slf *MoveHistorySearch) FindByQueryNotTotal(query string, args []interface{}) ([]*MoveHistory, error) {
-	var (
-		records = make([]*MoveHistory, 0)
-		db      = slf.Orm.Table(slf.TableName()).Where(query, args...)
-	)
-
-	if slf.PageNum*slf.PageSize > 0 {
-		db = db.Offset((slf.PageNum - 1) * slf.PageSize).Limit(slf.PageSize)
-	}
-	if err := db.Find(&records).Error; err != nil {
-		return records, fmt.Errorf("find by query records err: %v, query: %s, args: %+v", err, query, args)
-	}
-
-	return records, nil
-}
diff --git a/models/operation_details.go b/models/operation_details.go
index 9e89e77..8517d8c 100644
--- a/models/operation_details.go
+++ b/models/operation_details.go
@@ -207,7 +207,7 @@
 	if slf.PageNum*slf.PageSize > 0 {
 		db = db.Offset((slf.PageNum - 1) * slf.PageSize).Limit(slf.PageSize)
 	}
-	if err := db.Find(&records).Error; err != nil {
+	if err := db.Preload("Product").Find(&records).Error; err != nil {
 		return records, fmt.Errorf("find records err: %v", err)
 	}
 
diff --git a/models/reorder_rule.go b/models/reorder_rule.go
new file mode 100644
index 0000000..868ef41
--- /dev/null
+++ b/models/reorder_rule.go
@@ -0,0 +1,165 @@
+package models
+
+import (
+	"fmt"
+	"github.com/shopspring/decimal"
+	"gorm.io/gorm"
+	"wms/pkg/mysqlx"
+)
+
+type (
+	ReorderRule struct {
+		WmsModel
+		Id           int             `json:"id" gorm:"column:id;primary_key;AUTO_INCREMENT"`
+		ProductId    string          `json:"productId" gorm:"type:varchar(191);not null;comment:浜у搧id"` //浜у搧id
+		Product      Material        `json:"product" gorm:"foreignKey:ProductId;references:ID"`
+		LocationId   int             `json:"locationId" gorm:"type:int;not null;comment:浣嶇疆id"` //浣嶇疆id
+		Location     Location        `json:"location" gorm:"foreignKey:LocationId;references:id"`
+		Route        string          `json:"route" gorm:"type:varchar(255);comment:璺嚎"`            //璺嚎
+		MinInventory decimal.Decimal `json:"minInventory" gorm:"type:decimal(35,18);comment:鏈�灏忓簱瀛�"` //鏈�灏忓簱瀛�
+		MaxInventory decimal.Decimal `json:"maxInventory" gorm:"type:decimal(35,18);comment:鏈�澶у簱瀛�"` //鏈�澶у簱瀛�
+		OrderNumber  decimal.Decimal `json:"orderNumber" gorm:"type:decimal(35,18);comment:璁㈣喘鏁伴噺"`  //璁㈣喘鏁伴噺
+		Unit         string          `json:"unit" gorm:"type:varchar(100);comment:鍗曚綅"`             //鍗曚綅
+		Amount       decimal.Decimal `json:"amount" gorm:"-"`                                      //鍦ㄥ簱鏁伴噺
+		Prediction   decimal.Decimal `json:"prediction" gorm:"-"`                                  //棰勬祴鏁伴噺
+	}
+	ReorderRuleSearch struct {
+		ReorderRule
+		PageNum  int
+		PageSize int
+		Keyword  string
+		Orm      *gorm.DB
+		Preload  bool
+	}
+)
+
+func (slf *ReorderRule) TableName() string {
+	return "wms_reorder_rule"
+}
+
+func NewReorderRuleSearch() *ReorderRuleSearch {
+	return &ReorderRuleSearch{Orm: mysqlx.GetDB()}
+}
+
+func (slf *ReorderRuleSearch) SetOrm(tx *gorm.DB) *ReorderRuleSearch {
+	slf.Orm = tx
+	return slf
+}
+
+func (slf *ReorderRuleSearch) SetPage(page, size int) *ReorderRuleSearch {
+	slf.PageNum, slf.PageSize = page, size
+	return slf
+}
+
+func (slf *ReorderRuleSearch) SetID(ID int) *ReorderRuleSearch {
+	slf.Id = ID
+	return slf
+}
+
+func (slf *ReorderRuleSearch) SetKeyword(keyword string) *ReorderRuleSearch {
+	slf.Keyword = keyword
+	return slf
+}
+
+func (slf *ReorderRuleSearch) SetProductId(productId string) *ReorderRuleSearch {
+	slf.ProductId = productId
+	return slf
+}
+
+func (slf *ReorderRuleSearch) SetLocationId(locationId int) *ReorderRuleSearch {
+	slf.LocationId = locationId
+	return slf
+}
+
+func (slf *ReorderRuleSearch) SetPreload(preload bool) *ReorderRuleSearch {
+	slf.Preload = preload
+	return slf
+}
+
+func (slf *ReorderRuleSearch) build() *gorm.DB {
+	var db = slf.Orm.Model(&ReorderRule{})
+	if slf.Id != 0 {
+		db = db.Where("id = ?", slf.Id)
+	}
+	if slf.ProductId != "" {
+		db = db.Where("product_id = ?", slf.ProductId)
+	}
+	if slf.LocationId != 0 {
+		db = db.Where("location_id = ?", slf.LocationId)
+	}
+
+	if slf.Preload {
+		db = db.Preload("Product").Preload("Location")
+	}
+
+	return db
+}
+
+// Create 鍗曟潯鎻掑叆
+func (slf *ReorderRuleSearch) Create(record *ReorderRule) error {
+	var db = slf.build()
+
+	if err := db.Create(record).Error; err != nil {
+		return err
+	}
+
+	return nil
+}
+
+func (slf *ReorderRuleSearch) Update(record *ReorderRule) error {
+	var db = slf.build()
+
+	if err := db.Omit("CreatedAt").Updates(record).Error; err != nil {
+		return fmt.Errorf("update err: %v, record: %+v", err, record)
+	}
+
+	return nil
+}
+
+func (slf *ReorderRuleSearch) Count() (int64, error) {
+	var (
+		total int64
+		db    = slf.build()
+	)
+
+	err := db.Count(&total).Error
+	return total, err
+}
+
+func (slf *ReorderRuleSearch) First() (*ReorderRule, error) {
+	var (
+		record = new(ReorderRule)
+		db     = slf.build()
+	)
+
+	if err := db.First(record).Error; err != nil {
+		return record, err
+	}
+
+	return record, nil
+}
+
+func (slf *ReorderRuleSearch) Find() ([]*ReorderRule, int64, error) {
+	var (
+		records = make([]*ReorderRule, 0)
+		total   int64
+		db      = slf.build()
+	)
+
+	if err := db.Count(&total).Error; err != nil {
+		return records, total, fmt.Errorf("find count err: %v", err)
+	}
+	if slf.PageNum*slf.PageSize > 0 {
+		db = db.Offset((slf.PageNum - 1) * slf.PageSize).Limit(slf.PageSize)
+	}
+	if err := db.Order("created_at desc").Find(&records).Error; err != nil {
+		return records, total, fmt.Errorf("find records err: %v", err)
+	}
+
+	return records, total, nil
+}
+
+func (slf *ReorderRuleSearch) Delete() error {
+	var db = slf.build()
+	return db.Delete(&ReorderRule{}).Error
+}
diff --git a/request/reorder_rule_request.go b/request/reorder_rule_request.go
new file mode 100644
index 0000000..bd33ec4
--- /dev/null
+++ b/request/reorder_rule_request.go
@@ -0,0 +1,24 @@
+package request
+
+import (
+	"github.com/shopspring/decimal"
+	"wms/constvar"
+)
+
+type GetReorderRuleList struct {
+	PageInfo
+	KeyWord string `json:"keyWord"`
+}
+
+type ProductAmount struct {
+	ProductId      string                   `json:"productId"`
+	ToLocationId   int                      `json:"toLocationId"`
+	FromLocationId int                      `json:"fromLocationId"`
+	Amount         decimal.Decimal          `json:"amount"`
+	Status         constvar.OperationStatus `json:"status"`
+}
+
+type GetAmountAndPrediction struct {
+	ProductId  string `json:"productId"`
+	LocationId int    `json:"locationId"`
+}
diff --git a/response/report_forms_response.go b/response/report_forms_response.go
index 8bf283c..200903d 100644
--- a/response/report_forms_response.go
+++ b/response/report_forms_response.go
@@ -2,6 +2,7 @@
 
 import (
 	"github.com/shopspring/decimal"
+	"wms/constvar"
 )
 
 type InventoryForms struct {
@@ -18,15 +19,16 @@
 }
 
 type InventoryHistory struct {
-	Number        string          `json:"number"`        //鍗曞彿
-	Date          string          `json:"date"`          //鏃ユ湡
-	ProductName   string          `json:"productName"`   //浜у搧鍚嶇О
-	FromLocation  string          `json:"fromLocation"`  //婧愪綅缃�
-	ToLocation    string          `json:"toLocation"`    //鐩爣浣嶇疆
-	Amount        decimal.Decimal `json:"amount"`        //鏁伴噺
-	Unit          string          `json:"unit"`          //鍗曚綅
-	ContactedName string          `json:"contactedName"` //瀹屾垚鑰�
-	Status        string          `json:"status"`        //鐘舵��
+	Number            string                     `json:"number"`            //鍗曞彿
+	Date              string                     `json:"date"`              //鏃ユ湡
+	ProductName       string                     `json:"productName"`       //浜у搧鍚嶇О
+	FromLocation      string                     `json:"fromLocation"`      //婧愪綅缃�
+	ToLocation        string                     `json:"toLocation"`        //鐩爣浣嶇疆
+	Amount            decimal.Decimal            `json:"amount"`            //鏁伴噺
+	Unit              string                     `json:"unit"`              //鍗曚綅
+	ContactedName     string                     `json:"contactedName"`     //瀹屾垚鑰�
+	Status            string                     `json:"status"`            //鐘舵��
+	BaseOperationType constvar.BaseOperationType `json:"baseOperationType"` //鍩虹浣滀笟绫诲瀷
 }
 
 type LocationForms struct {
diff --git a/router/router.go b/router/router.go
index 4ac8ab8..a591cf7 100644
--- a/router/router.go
+++ b/router/router.go
@@ -142,5 +142,16 @@
 		reportFormsAPI.POST("getLocationForms", reportFormsController.GetLocationForms)   //鑾峰彇浣嶇疆鎶ヨ〃
 	}
 
+	//閲嶈璐ц鍒�
+	reorderRuleController := new(controllers.ReorderRuleController)
+	reorderRuleAPI := r.Group(urlPrefix + "/reorderRule")
+	{
+		reorderRuleAPI.POST("addReorderRule", reorderRuleController.AddReorderRule)                 //娣诲姞閲嶈璐ц鍒�
+		reorderRuleAPI.POST("getReorderRuleList", reorderRuleController.GetReorderRuleList)         //鑾峰彇閲嶈璐ц鍒欏垪琛�
+		reorderRuleAPI.POST("getAmountAndPrediction", reorderRuleController.GetAmountAndPrediction) //鑾峰彇鍦ㄥ簱涓庨娴嬫暟閲�
+		reorderRuleAPI.POST("updateReorderRule", reorderRuleController.UpdateReorderRule)           //鏇存柊閲嶈璐ц鍒�
+		reorderRuleAPI.POST("orderAgain", reorderRuleController.OrderAgain)                         //鍐嶈涓�娆�
+	}
+
 	return r
 }

--
Gitblit v1.8.0