liujiandao
2023-10-31 307c699810c39714e82efac9de56f70b93a718a2
重订货规则开发
1个文件已删除
3个文件已添加
8个文件已修改
1473 ■■■■ 已修改文件
controllers/reorder_rule_controller.go 281 ●●●●● 补丁 | 查看 | 原始文档 | blame | 历史
controllers/report_forms_controller.go 5 ●●●●● 补丁 | 查看 | 原始文档 | blame | 历史
docs/docs.go 274 ●●●●● 补丁 | 查看 | 原始文档 | blame | 历史
docs/swagger.json 272 ●●●●● 补丁 | 查看 | 原始文档 | blame | 历史
docs/swagger.yaml 172 ●●●●● 补丁 | 查看 | 原始文档 | blame | 历史
models/db.go 3 ●●●● 补丁 | 查看 | 原始文档 | blame | 历史
models/move_history.go 244 ●●●●● 补丁 | 查看 | 原始文档 | blame | 历史
models/operation_details.go 2 ●●● 补丁 | 查看 | 原始文档 | blame | 历史
models/reorder_rule.go 165 ●●●●● 补丁 | 查看 | 原始文档 | blame | 历史
request/reorder_rule_request.go 24 ●●●●● 补丁 | 查看 | 原始文档 | blame | 历史
response/report_forms_response.go 20 ●●●●● 补丁 | 查看 | 原始文档 | blame | 历史
router/router.go 11 ●●●●● 补丁 | 查看 | 原始文档 | blame | 历史
controllers/reorder_rule_controller.go
New file
@@ -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, "参数解析失败,数据类型错误")
        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, "参数解析失败,数据类型错误")
        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, "参数解析失败,数据类型错误")
        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, "参数解析失败,数据类型错误")
        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, "参数解析失败,数据类型错误")
        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, "重订成功")
}
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
            }
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() {
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"
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:
models/db.go
@@ -81,12 +81,11 @@
        Operation{},
        OperationDetails{},
        Scrap{},
        MoveHistory{},
        //Product{},
        ProductCategory{},
        Material{},
        LocationProduct{},
        LocationProductAmount{},
        ReorderRule{},
    )
    return err
}
models/move_history.go
File was deleted
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)
    }
models/reorder_rule.go
New file
@@ -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
}
request/reorder_rule_request.go
New file
@@ -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"`
}
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 {
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
}