From 7edecfcf0f48ba6d6177486a57399a558c4c79e7 Mon Sep 17 00:00:00 2001 From: jiangshuai <291802688@qq.com> Date: 星期三, 27 九月 2023 11:14:17 +0800 Subject: [PATCH] 1.二期一部分代码 --- constvar/const.go | 3 models/location_product.go | 18 + models/db.go | 2 request/location_product_amount.go | 8 controllers/location_product.go | 2 docs/swagger.yaml | 193 +++++++++++ docs/docs.go | 301 +++++++++++++++++ docs/swagger.json | 299 +++++++++++++++++ controllers/location_product_amount.go | 127 +++++-- router/router.go | 16 10 files changed, 903 insertions(+), 66 deletions(-) diff --git a/constvar/const.go b/constvar/const.go index f92ca9a..5c6a63f 100644 --- a/constvar/const.go +++ b/constvar/const.go @@ -126,7 +126,8 @@ LocationTypeInventoryLoss // 搴撳瓨鎹熷け LocationTypeProduction // 鐢熶骇 LocationTypeTransit // 涓浆浣嶇疆 - LocationTypeDisuse + LocationTypeDisuse //鎶ュ簾浣嶇疆 + LocationTypeAdjust //搴撳瓨鐩樼偣 ) func (t LocationType) Valid() bool { diff --git a/controllers/location_product.go b/controllers/location_product.go index 07d012b..f7a1dc6 100644 --- a/controllers/location_product.go +++ b/controllers/location_product.go @@ -89,7 +89,7 @@ // @Tags 涓婃灦瑙勫垯 // @Summary 淇敼涓婃灦瑙勫垯 // @Produce application/json -// @Param object body request.UpdateLocationProduct true "鍏ュ簱淇℃伅" +// @Param object body request.UpdateLocationProduct true "淇敼鍙傛暟" // @Success 200 {object} util.Response "鎴愬姛" // @Router /api-wms/v1/locationProduct/update [post] func (slf LocationProductController) Update(c *gin.Context) { diff --git a/controllers/location_product_amount.go b/controllers/location_product_amount.go index 701a205..c3fc1b8 100644 --- a/controllers/location_product_amount.go +++ b/controllers/location_product_amount.go @@ -3,6 +3,10 @@ import ( "fmt" "github.com/gin-gonic/gin" + "github.com/shopspring/decimal" + "gorm.io/gorm" + "strconv" + "time" "wms/constvar" "wms/extend/code" "wms/extend/util" @@ -19,7 +23,7 @@ // @Produce application/json // @Param object body request.PageInfo true "鏌ヨ鍙傛暟" // @Success 200 {object} util.Response "鎴愬姛" -// @Router /api-wms/v1/locationProduct/list [post] +// @Router /api-wms/v1/locationProductamount/list [post] func (slf LocationProductAmountController) List(c *gin.Context) { var params request.PageInfo if err := c.BindJSON(¶ms); err != nil { @@ -63,40 +67,87 @@ // @Produce application/json // @Param object body request.AddLocationProductAmount true "鍏ュ簱/鍑哄簱淇℃伅" // @Success 200 {object} util.Response "鎴愬姛" -// @Router /api-wms/v1/operation/operation [post] -//func (slf LocationProductAmountController) Add(c *gin.Context) { -// var reqParams request.AddLocationProductAmount -// if err := c.BindJSON(&reqParams); err != nil { -// util.ResponseFormat(c, code.RequestParamError, "鍙傛暟瑙f瀽澶辫触锛屾暟鎹被鍨嬮敊璇�") -// return -// } -// if reqParams.LocationProductAmountId==0 { -// util.ResponseFormat(c, code.RequestParamError, "鍙傛暟寮傚父锛宭ocationProductAmountId涓�0") -// return -// } -// locAmount:=models.LocationProductAmount{ -// LocationProductId: reqParams.LocationProductAmountId -// } -// operationType, err := models.NewOperationTypeSearch().SetID(uint(params.OperationTypeId)).First() -// if err != nil { -// util.ResponseFormat(c, code.RequestParamError, err.Error()) -// return -// } -// ////// -// if location, err := models.NewLocationSearch().SetType(int(constvar.LocationTypeCustomer)).First(); err != nil { -// return err -// } else { -// params.ToLocationID = location.Id -// } -// -// -// params.Status = constvar.OperationStatus_Ready -// params.Number = strconv.FormatInt(time.Now().Unix(), 10) -// params.BaseOperationType = operationType.BaseOperationType -// if err := models.NewOperationSearch().Create(¶ms); err != nil { -// logx.Errorf("Operation create err: %v", err) -// util.ResponseFormat(c, code.SaveFail, "娣诲姞澶辫触锛�"+err.Error()) -// return -// } -// util.ResponseFormat(c, code.Success, "娣诲姞鎴愬姛") -//} +// @Router /api-wms/v1/locationProductamount/add [post] +func (slf LocationProductAmountController) Add(c *gin.Context) { + var reqParams request.AddLocationProductAmount + if err := c.BindJSON(&reqParams); err != nil { + util.ResponseFormat(c, code.RequestParamError, "鍙傛暟瑙f瀽澶辫触锛屾暟鎹被鍨嬮敊璇�") + return + } + if reqParams.LocationId == 0 { + util.ResponseFormat(c, code.RequestParamError, "鍙傛暟寮傚父锛岃閫夋嫨浣嶇疆") + return + } + if reqParams.ProductId == "" { + util.ResponseFormat(c, code.RequestParamError, "鍙傛暟寮傚父锛岃閫夋嫨浜у搧") + return + } + + var existCount int64 + if err := models.NewOperationSearch().Orm.Table("wms_operation").InnerJoins("inner join wms_operation_details on wms_operation_details.operation_id=wms_operation.id").Where("wms_operation.from_location_id=? and wms_operation_details.product_id=? and wms_operation.base_operation_type=? and wms_operaton.status=?", reqParams.LocationId, reqParams.ProductId, constvar.BaseOperationTypeAdjust, constvar.OperationStatus_Ready).Count(&existCount).Error; err != nil { + util.ResponseFormat(c, code.RequestParamError, err.Error()) + return + } + if existCount > 0 { + util.ResponseFormat(c, code.RequestError, "璇ュ晢鍝佸湪宸查�変腑鐨勪綅缃瓨鍦ㄦ湭楠岃瘉鐨勫簱瀛樼洏鐐逛俊鎭紝鏃犳硶缁х画娣诲姞鐩稿叧淇℃伅") + return + } + + locProduct, err := models.NewLocationProductSearch().SetLocationId(reqParams.LocationId).SetProductId(reqParams.ProductId).First() + if err != nil { + util.ResponseFormat(c, code.RequestParamError, "鍙傛暟寮傚父锛屾湭鎵惧埌璇ヤ笂鏋惰鍒�") + return + } + if locProduct.Id == 0 { + util.ResponseFormat(c, code.RequestError, "涓嶅瓨鍦ㄨ涓婃灦瑙勫垯锛屾棤娉曡繘琛屽簱瀛樼洏鐐�") + return + } + location, err := models.NewLocationSearch().SetType(int(constvar.LocationTypeAdjust)).First() + if err != nil { + util.ResponseFormat(c, code.RequestParamError, err.Error()) + return + } + reqParams.AdjustAmount = reqParams.Amount.Sub(reqParams.DifferenceAmount) + //reqParams.AdjustAmount = reqParams.DifferenceAmount.Sub(reqParams.Amount) + locAmount := models.LocationProductAmount{ + LocationProductId: locProduct.Id, + Amount: decimal.NewFromInt(0), + } + detail := &models.OperationDetails{ + ProductId: reqParams.ProductId, + Amount: reqParams.AdjustAmount, + } + operation := models.Operation{ + Number: strconv.FormatInt(time.Now().Unix(), 10), + Status: constvar.OperationStatus_Ready, + OperationDate: time.Now().Format("2006-01-02 15:04:05"), + Comment: "搴撳瓨鐩樼偣", + BaseOperationType: constvar.BaseOperationTypeAdjust, + Details: []*models.OperationDetails{detail}, + FromLocationID: reqParams.LocationId, + ToLocationID: location.Id, + } + + //if reqParams.AdjustAmount.GreaterThanOrEqual(decimal.NewFromInt(0)) { + // operation.FromLocationID = Location.Id + // operation.ToLocationID = reqParams.LocationId + //} else { + // operation.FromLocationID = reqParams.LocationId + // operation.ToLocationID = Location.Id + //} + + if err := models.WithTransaction(func(tx *gorm.DB) error { + if err := models.NewOperationSearch().SetOrm(tx).Create(&operation); err != nil { + return err + } + if err := models.NewLocationProductAmountSearch().SetOrm(tx).Create(&locAmount); err != nil { + return err + } + return nil + }); err != nil { + util.ResponseFormat(c, code.RequestError, err.Error()) + return + } + + util.ResponseFormat(c, code.Success, "娣诲姞鎴愬姛") +} diff --git a/docs/docs.go b/docs/docs.go index 20caec6..b6dbbbf 100644 --- a/docs/docs.go +++ b/docs/docs.go @@ -467,6 +467,184 @@ } } }, + "/api-wms/v1/locationProduct/add": { + "post": { + "produces": [ + "application/json" + ], + "tags": [ + "涓婃灦瑙勫垯" + ], + "summary": "娣诲姞涓婃灦瑙勫垯", + "parameters": [ + { + "description": "鏂板涓婃灦瑙勫垯", + "name": "object", + "in": "body", + "required": true, + "schema": { + "$ref": "#/definitions/request.AddLocationProduct" + } + } + ], + "responses": { + "200": { + "description": "鎴愬姛", + "schema": { + "$ref": "#/definitions/util.Response" + } + } + } + } + }, + "/api-wms/v1/locationProduct/delete/{id}": { + "delete": { + "produces": [ + "application/json" + ], + "tags": [ + "涓婃灦瑙勫垯" + ], + "summary": "鍒犻櫎涓婃灦瑙勫垯", + "parameters": [ + { + "type": "integer", + "description": "id", + "name": "id", + "in": "path", + "required": true + } + ], + "responses": { + "200": { + "description": "鎴愬姛", + "schema": { + "$ref": "#/definitions/util.Response" + } + } + } + } + }, + "/api-wms/v1/locationProduct/list": { + "post": { + "produces": [ + "application/json" + ], + "tags": [ + "涓婃灦瑙勫垯" + ], + "summary": "涓婃灦瑙勫垯鍒楄〃", + "parameters": [ + { + "description": "鏌ヨ鍙傛暟", + "name": "object", + "in": "body", + "required": true, + "schema": { + "$ref": "#/definitions/request.PageInfo" + } + } + ], + "responses": { + "200": { + "description": "鎴愬姛", + "schema": { + "$ref": "#/definitions/util.Response" + } + } + } + } + }, + "/api-wms/v1/locationProduct/update": { + "post": { + "produces": [ + "application/json" + ], + "tags": [ + "涓婃灦瑙勫垯" + ], + "summary": "淇敼涓婃灦瑙勫垯", + "parameters": [ + { + "description": "淇敼鍙傛暟", + "name": "object", + "in": "body", + "required": true, + "schema": { + "$ref": "#/definitions/request.UpdateLocationProduct" + } + } + ], + "responses": { + "200": { + "description": "鎴愬姛", + "schema": { + "$ref": "#/definitions/util.Response" + } + } + } + } + }, + "/api-wms/v1/locationProductamount/add": { + "post": { + "produces": [ + "application/json" + ], + "tags": [ + "搴撳瓨鐩樼偣" + ], + "summary": "娣诲姞搴撳瓨鐩樼偣淇℃伅", + "parameters": [ + { + "description": "鍏ュ簱/鍑哄簱淇℃伅", + "name": "object", + "in": "body", + "required": true, + "schema": { + "$ref": "#/definitions/request.AddLocationProductAmount" + } + } + ], + "responses": { + "200": { + "description": "鎴愬姛", + "schema": { + "$ref": "#/definitions/util.Response" + } + } + } + } + }, + "/api-wms/v1/locationProductamount/list": { + "post": { + "produces": [ + "application/json" + ], + "tags": [ + "搴撳瓨鐩樼偣" + ], + "summary": "搴撳瓨鐩樼偣鍒楄〃", + "parameters": [ + { + "description": "鏌ヨ鍙傛暟", + "name": "object", + "in": "body", + "required": true, + "schema": { + "$ref": "#/definitions/request.PageInfo" + } + } + ], + "responses": { + "200": { + "description": "鎴愬姛", + "schema": { + "$ref": "#/definitions/util.Response" + } + } + } + } + }, "/api-wms/v1/operation/finish/{id}": { "put": { "produces": [ @@ -1467,9 +1645,13 @@ "enum": [ 1, 2, - 3 + 3, + 4, + 5 ], "x-enum-comments": { + "BaseOperationTypeAdjust": "搴撳瓨鐩樼偣", + "BaseOperationTypeDisuse": "鎶ュ簾", "BaseOperationTypeIncoming": "鏀惰揣", "BaseOperationTypeInternal": "鍐呴儴璋冩嫧", "BaseOperationTypeOutgoing": "浜よ揣" @@ -1477,7 +1659,9 @@ "x-enum-varnames": [ "BaseOperationTypeIncoming", "BaseOperationTypeOutgoing", - "BaseOperationTypeInternal" + "BaseOperationTypeInternal", + "BaseOperationTypeDisuse", + "BaseOperationTypeAdjust" ] }, "constvar.CostingMethod": { @@ -1560,10 +1744,12 @@ 5, 6, 7, - 8 + 8, + 9 ], "x-enum-comments": { "LocationTypeCustomer": "瀹㈡埛浣嶇疆", + "LocationTypeDisuse": "鎶ュ簾浣嶇疆", "LocationTypeInternal": "鍐呴儴浣嶇疆", "LocationTypeInventoryLoss": "搴撳瓨鎹熷け", "LocationTypeProduction": "鐢熶骇", @@ -1579,7 +1765,8 @@ "LocationTypeInventoryLoss", "LocationTypeProduction", "LocationTypeTransit", - "LocationTypeDisuse" + "LocationTypeDisuse", + "LocationTypeAdjust" ] }, "constvar.MaterialMode": { @@ -1798,7 +1985,7 @@ }, "parentId": { "description": "涓婄骇id", - "type": "string" + "type": "integer" }, "recentlyCount": { "description": "鏈�杩戠洏鐐�", @@ -2016,6 +2203,14 @@ "models.Operation": { "type": "object", "properties": { + "baseOperationType": { + "description": "鍩虹浣滀笟绫诲瀷", + "allOf": [ + { + "$ref": "#/definitions/constvar.BaseOperationType" + } + ] + }, "comment": { "type": "string" }, @@ -2311,6 +2506,50 @@ } } }, + "request.AddLocationProduct": { + "type": "object", + "properties": { + "areaId": { + "description": "鍖哄煙id", + "type": "integer" + }, + "locationId": { + "description": "浣嶇疆id", + "type": "integer" + }, + "productCategoryId": { + "description": "浜у搧绉嶇被id", + "type": "integer" + }, + "productId": { + "description": "浜у搧id", + "type": "string" + } + } + }, + "request.AddLocationProductAmount": { + "type": "object", + "properties": { + "adjustAmount": { + "description": "宸��", + "type": "number" + }, + "decimal": { + "description": "搴撳瓨鏁伴噺", + "type": "number" + }, + "difference_amount": { + "description": "璁℃暟鏁伴噺", + "type": "number" + }, + "locationId": { + "type": "integer" + }, + "productId": { + "type": "string" + } + } + }, "request.AddOperation": { "type": "object", "properties": { @@ -2583,6 +2822,19 @@ } } }, + "request.PageInfo": { + "type": "object", + "properties": { + "page": { + "description": "椤电爜", + "type": "integer" + }, + "pageSize": { + "description": "姣忛〉澶у皬", + "type": "integer" + } + } + }, "request.QueryDisuseList": { "type": "object", "properties": { @@ -2658,8 +2910,10 @@ "type": "object", "properties": { "amount": { - "description": "ProductName string ` + "`" + `json:\"productName\"` + "`" + `", "type": "number" + }, + "baseOperationType": { + "$ref": "#/definitions/constvar.BaseOperationType" }, "fromLocationId": { "type": "integer" @@ -2668,7 +2922,6 @@ "type": "integer" }, "number": { - "description": "Unit string ` + "`" + `json:\"unit\"` + "`" + `", "type": "string" }, "operationDate": { @@ -2688,9 +2941,41 @@ } } }, + "request.UpdateLocationProduct": { + "type": "object", + "properties": { + "areaId": { + "description": "鍖哄煙id", + "type": "integer" + }, + "id": { + "type": "integer" + }, + "locationId": { + "description": "浣嶇疆id", + "type": "integer" + }, + "productCategoryId": { + "description": "浜у搧绉嶇被id", + "type": "integer" + }, + "productId": { + "description": "浜у搧id", + "type": "string" + } + } + }, "request.UpdateOperation": { "type": "object", "properties": { + "baseOperationType": { + "description": "鍩虹浣滀笟绫诲瀷", + "allOf": [ + { + "$ref": "#/definitions/constvar.BaseOperationType" + } + ] + }, "comment": { "description": "澶囨敞", "type": "string" @@ -2876,8 +3161,6 @@ Description: "", InfoInstanceName: "swagger", SwaggerTemplate: docTemplate, - LeftDelim: "{{", - RightDelim: "}}", } func init() { diff --git a/docs/swagger.json b/docs/swagger.json index 801bf26..2224517 100644 --- a/docs/swagger.json +++ b/docs/swagger.json @@ -455,6 +455,184 @@ } } }, + "/api-wms/v1/locationProduct/add": { + "post": { + "produces": [ + "application/json" + ], + "tags": [ + "涓婃灦瑙勫垯" + ], + "summary": "娣诲姞涓婃灦瑙勫垯", + "parameters": [ + { + "description": "鏂板涓婃灦瑙勫垯", + "name": "object", + "in": "body", + "required": true, + "schema": { + "$ref": "#/definitions/request.AddLocationProduct" + } + } + ], + "responses": { + "200": { + "description": "鎴愬姛", + "schema": { + "$ref": "#/definitions/util.Response" + } + } + } + } + }, + "/api-wms/v1/locationProduct/delete/{id}": { + "delete": { + "produces": [ + "application/json" + ], + "tags": [ + "涓婃灦瑙勫垯" + ], + "summary": "鍒犻櫎涓婃灦瑙勫垯", + "parameters": [ + { + "type": "integer", + "description": "id", + "name": "id", + "in": "path", + "required": true + } + ], + "responses": { + "200": { + "description": "鎴愬姛", + "schema": { + "$ref": "#/definitions/util.Response" + } + } + } + } + }, + "/api-wms/v1/locationProduct/list": { + "post": { + "produces": [ + "application/json" + ], + "tags": [ + "涓婃灦瑙勫垯" + ], + "summary": "涓婃灦瑙勫垯鍒楄〃", + "parameters": [ + { + "description": "鏌ヨ鍙傛暟", + "name": "object", + "in": "body", + "required": true, + "schema": { + "$ref": "#/definitions/request.PageInfo" + } + } + ], + "responses": { + "200": { + "description": "鎴愬姛", + "schema": { + "$ref": "#/definitions/util.Response" + } + } + } + } + }, + "/api-wms/v1/locationProduct/update": { + "post": { + "produces": [ + "application/json" + ], + "tags": [ + "涓婃灦瑙勫垯" + ], + "summary": "淇敼涓婃灦瑙勫垯", + "parameters": [ + { + "description": "淇敼鍙傛暟", + "name": "object", + "in": "body", + "required": true, + "schema": { + "$ref": "#/definitions/request.UpdateLocationProduct" + } + } + ], + "responses": { + "200": { + "description": "鎴愬姛", + "schema": { + "$ref": "#/definitions/util.Response" + } + } + } + } + }, + "/api-wms/v1/locationProductamount/add": { + "post": { + "produces": [ + "application/json" + ], + "tags": [ + "搴撳瓨鐩樼偣" + ], + "summary": "娣诲姞搴撳瓨鐩樼偣淇℃伅", + "parameters": [ + { + "description": "鍏ュ簱/鍑哄簱淇℃伅", + "name": "object", + "in": "body", + "required": true, + "schema": { + "$ref": "#/definitions/request.AddLocationProductAmount" + } + } + ], + "responses": { + "200": { + "description": "鎴愬姛", + "schema": { + "$ref": "#/definitions/util.Response" + } + } + } + } + }, + "/api-wms/v1/locationProductamount/list": { + "post": { + "produces": [ + "application/json" + ], + "tags": [ + "搴撳瓨鐩樼偣" + ], + "summary": "搴撳瓨鐩樼偣鍒楄〃", + "parameters": [ + { + "description": "鏌ヨ鍙傛暟", + "name": "object", + "in": "body", + "required": true, + "schema": { + "$ref": "#/definitions/request.PageInfo" + } + } + ], + "responses": { + "200": { + "description": "鎴愬姛", + "schema": { + "$ref": "#/definitions/util.Response" + } + } + } + } + }, "/api-wms/v1/operation/finish/{id}": { "put": { "produces": [ @@ -1455,9 +1633,13 @@ "enum": [ 1, 2, - 3 + 3, + 4, + 5 ], "x-enum-comments": { + "BaseOperationTypeAdjust": "搴撳瓨鐩樼偣", + "BaseOperationTypeDisuse": "鎶ュ簾", "BaseOperationTypeIncoming": "鏀惰揣", "BaseOperationTypeInternal": "鍐呴儴璋冩嫧", "BaseOperationTypeOutgoing": "浜よ揣" @@ -1465,7 +1647,9 @@ "x-enum-varnames": [ "BaseOperationTypeIncoming", "BaseOperationTypeOutgoing", - "BaseOperationTypeInternal" + "BaseOperationTypeInternal", + "BaseOperationTypeDisuse", + "BaseOperationTypeAdjust" ] }, "constvar.CostingMethod": { @@ -1548,10 +1732,12 @@ 5, 6, 7, - 8 + 8, + 9 ], "x-enum-comments": { "LocationTypeCustomer": "瀹㈡埛浣嶇疆", + "LocationTypeDisuse": "鎶ュ簾浣嶇疆", "LocationTypeInternal": "鍐呴儴浣嶇疆", "LocationTypeInventoryLoss": "搴撳瓨鎹熷け", "LocationTypeProduction": "鐢熶骇", @@ -1567,7 +1753,8 @@ "LocationTypeInventoryLoss", "LocationTypeProduction", "LocationTypeTransit", - "LocationTypeDisuse" + "LocationTypeDisuse", + "LocationTypeAdjust" ] }, "constvar.MaterialMode": { @@ -1786,7 +1973,7 @@ }, "parentId": { "description": "涓婄骇id", - "type": "string" + "type": "integer" }, "recentlyCount": { "description": "鏈�杩戠洏鐐�", @@ -2004,6 +2191,14 @@ "models.Operation": { "type": "object", "properties": { + "baseOperationType": { + "description": "鍩虹浣滀笟绫诲瀷", + "allOf": [ + { + "$ref": "#/definitions/constvar.BaseOperationType" + } + ] + }, "comment": { "type": "string" }, @@ -2299,6 +2494,50 @@ } } }, + "request.AddLocationProduct": { + "type": "object", + "properties": { + "areaId": { + "description": "鍖哄煙id", + "type": "integer" + }, + "locationId": { + "description": "浣嶇疆id", + "type": "integer" + }, + "productCategoryId": { + "description": "浜у搧绉嶇被id", + "type": "integer" + }, + "productId": { + "description": "浜у搧id", + "type": "string" + } + } + }, + "request.AddLocationProductAmount": { + "type": "object", + "properties": { + "adjustAmount": { + "description": "宸��", + "type": "number" + }, + "decimal": { + "description": "搴撳瓨鏁伴噺", + "type": "number" + }, + "difference_amount": { + "description": "璁℃暟鏁伴噺", + "type": "number" + }, + "locationId": { + "type": "integer" + }, + "productId": { + "type": "string" + } + } + }, "request.AddOperation": { "type": "object", "properties": { @@ -2571,6 +2810,19 @@ } } }, + "request.PageInfo": { + "type": "object", + "properties": { + "page": { + "description": "椤电爜", + "type": "integer" + }, + "pageSize": { + "description": "姣忛〉澶у皬", + "type": "integer" + } + } + }, "request.QueryDisuseList": { "type": "object", "properties": { @@ -2646,8 +2898,10 @@ "type": "object", "properties": { "amount": { - "description": "ProductName string `json:\"productName\"`", "type": "number" + }, + "baseOperationType": { + "$ref": "#/definitions/constvar.BaseOperationType" }, "fromLocationId": { "type": "integer" @@ -2656,7 +2910,6 @@ "type": "integer" }, "number": { - "description": "Unit string `json:\"unit\"`", "type": "string" }, "operationDate": { @@ -2676,9 +2929,41 @@ } } }, + "request.UpdateLocationProduct": { + "type": "object", + "properties": { + "areaId": { + "description": "鍖哄煙id", + "type": "integer" + }, + "id": { + "type": "integer" + }, + "locationId": { + "description": "浣嶇疆id", + "type": "integer" + }, + "productCategoryId": { + "description": "浜у搧绉嶇被id", + "type": "integer" + }, + "productId": { + "description": "浜у搧id", + "type": "string" + } + } + }, "request.UpdateOperation": { "type": "object", "properties": { + "baseOperationType": { + "description": "鍩虹浣滀笟绫诲瀷", + "allOf": [ + { + "$ref": "#/definitions/constvar.BaseOperationType" + } + ] + }, "comment": { "description": "澶囨敞", "type": "string" diff --git a/docs/swagger.yaml b/docs/swagger.yaml index 81acff3..fa7b60e 100644 --- a/docs/swagger.yaml +++ b/docs/swagger.yaml @@ -4,8 +4,12 @@ - 1 - 2 - 3 + - 4 + - 5 type: integer x-enum-comments: + BaseOperationTypeAdjust: 搴撳瓨鐩樼偣 + BaseOperationTypeDisuse: 鎶ュ簾 BaseOperationTypeIncoming: 鏀惰揣 BaseOperationTypeInternal: 鍐呴儴璋冩嫧 BaseOperationTypeOutgoing: 浜よ揣 @@ -13,6 +17,8 @@ - BaseOperationTypeIncoming - BaseOperationTypeOutgoing - BaseOperationTypeInternal + - BaseOperationTypeDisuse + - BaseOperationTypeAdjust constvar.CostingMethod: enum: - 1 @@ -78,9 +84,11 @@ - 6 - 7 - 8 + - 9 type: integer x-enum-comments: LocationTypeCustomer: 瀹㈡埛浣嶇疆 + LocationTypeDisuse: 鎶ュ簾浣嶇疆 LocationTypeInternal: 鍐呴儴浣嶇疆 LocationTypeInventoryLoss: 搴撳瓨鎹熷け LocationTypeProduction: 鐢熶骇 @@ -96,6 +104,7 @@ - LocationTypeProduction - LocationTypeTransit - LocationTypeDisuse + - LocationTypeAdjust constvar.MaterialMode: enum: - 鍘熸潗鏂� @@ -257,7 +266,7 @@ type: string parentId: description: 涓婄骇id - type: string + type: integer recentlyCount: description: 鏈�杩戠洏鐐� type: string @@ -422,6 +431,10 @@ type: object models.Operation: properties: + baseOperationType: + allOf: + - $ref: '#/definitions/constvar.BaseOperationType' + description: 鍩虹浣滀笟绫诲瀷 comment: type: string companyID: @@ -619,6 +632,37 @@ toLocationId: type: integer type: object + request.AddLocationProduct: + properties: + areaId: + description: 鍖哄煙id + type: integer + locationId: + description: 浣嶇疆id + type: integer + productCategoryId: + description: 浜у搧绉嶇被id + type: integer + productId: + description: 浜у搧id + type: string + type: object + request.AddLocationProductAmount: + properties: + adjustAmount: + description: 宸�� + type: number + decimal: + description: 搴撳瓨鏁伴噺 + type: number + difference_amount: + description: 璁℃暟鏁伴噺 + type: number + locationId: + type: integer + productId: + type: string + type: object request.AddOperation: properties: comment: @@ -808,6 +852,15 @@ sourceNumber: type: string type: object + request.PageInfo: + properties: + page: + description: 椤电爜 + type: integer + pageSize: + description: 姣忛〉澶у皬 + type: integer + type: object request.QueryDisuseList: properties: number: @@ -860,14 +913,14 @@ request.UpdateDisuse: properties: amount: - description: ProductName string `json:"productName"` type: number + baseOperationType: + $ref: '#/definitions/constvar.BaseOperationType' fromLocationId: type: integer id: type: integer number: - description: Unit string `json:"unit"` type: string operationDate: type: string @@ -880,8 +933,29 @@ toLocationId: type: integer type: object + request.UpdateLocationProduct: + properties: + areaId: + description: 鍖哄煙id + type: integer + id: + type: integer + locationId: + description: 浣嶇疆id + type: integer + productCategoryId: + description: 浜у搧绉嶇被id + type: integer + productId: + description: 浜у搧id + type: string + type: object request.UpdateOperation: properties: + baseOperationType: + allOf: + - $ref: '#/definitions/constvar.BaseOperationType' + description: 鍩虹浣滀笟绫诲瀷 comment: description: 澶囨敞 type: string @@ -1279,6 +1353,119 @@ summary: 淇敼浣嶇疆 tags: - 浣嶇疆 + /api-wms/v1/locationProduct/add: + post: + parameters: + - description: 鏂板涓婃灦瑙勫垯 + in: body + name: object + required: true + schema: + $ref: '#/definitions/request.AddLocationProduct' + produces: + - application/json + responses: + "200": + description: 鎴愬姛 + schema: + $ref: '#/definitions/util.Response' + summary: 娣诲姞涓婃灦瑙勫垯 + tags: + - 涓婃灦瑙勫垯 + /api-wms/v1/locationProduct/delete/{id}: + delete: + parameters: + - description: id + in: path + name: id + required: true + type: integer + produces: + - application/json + responses: + "200": + description: 鎴愬姛 + schema: + $ref: '#/definitions/util.Response' + summary: 鍒犻櫎涓婃灦瑙勫垯 + tags: + - 涓婃灦瑙勫垯 + /api-wms/v1/locationProduct/list: + post: + parameters: + - description: 鏌ヨ鍙傛暟 + in: body + name: object + required: true + schema: + $ref: '#/definitions/request.PageInfo' + produces: + - application/json + responses: + "200": + description: 鎴愬姛 + schema: + $ref: '#/definitions/util.Response' + summary: 涓婃灦瑙勫垯鍒楄〃 + tags: + - 涓婃灦瑙勫垯 + /api-wms/v1/locationProduct/update: + post: + parameters: + - description: 淇敼鍙傛暟 + in: body + name: object + required: true + schema: + $ref: '#/definitions/request.UpdateLocationProduct' + produces: + - application/json + responses: + "200": + description: 鎴愬姛 + schema: + $ref: '#/definitions/util.Response' + summary: 淇敼涓婃灦瑙勫垯 + tags: + - 涓婃灦瑙勫垯 + /api-wms/v1/locationProductamount/add: + post: + parameters: + - description: 鍏ュ簱/鍑哄簱淇℃伅 + in: body + name: object + required: true + schema: + $ref: '#/definitions/request.AddLocationProductAmount' + produces: + - application/json + responses: + "200": + description: 鎴愬姛 + schema: + $ref: '#/definitions/util.Response' + summary: 娣诲姞搴撳瓨鐩樼偣淇℃伅 + tags: + - 搴撳瓨鐩樼偣 + /api-wms/v1/locationProductamount/list: + post: + parameters: + - description: 鏌ヨ鍙傛暟 + in: body + name: object + required: true + schema: + $ref: '#/definitions/request.PageInfo' + produces: + - application/json + responses: + "200": + description: 鎴愬姛 + schema: + $ref: '#/definitions/util.Response' + summary: 搴撳瓨鐩樼偣鍒楄〃 + tags: + - 搴撳瓨鐩樼偣 /api-wms/v1/operation/finish/{id}: put: parameters: diff --git a/models/db.go b/models/db.go index ed1c78b..8f47201 100644 --- a/models/db.go +++ b/models/db.go @@ -85,6 +85,8 @@ //Product{}, ProductCategory{}, Material{}, + LocationProduct{}, + LocationProductAmount{}, ) return err } diff --git a/models/location_product.go b/models/location_product.go index b3edb61..bc98181 100644 --- a/models/location_product.go +++ b/models/location_product.go @@ -69,6 +69,16 @@ return slf } +func (slf *LocationProductSearch) SetProductId(productId string) *LocationProductSearch { + slf.ProductId = productId + return slf +} + +func (slf *LocationProductSearch) SetLocationId(locationId int) *LocationProductSearch { + slf.LocationId = locationId + return slf +} + func (slf *LocationProductSearch) build() *gorm.DB { var db = slf.Orm.Model(&LocationProduct{}) @@ -87,6 +97,14 @@ db = db.Model(&LocationProduct{}).Preload("Location").Preload("Area").Preload("ProductCategory").Preload("Product") } + if slf.LocationId != 0 { + db = db.Where("location_id = ?", slf.LocationId) + } + + if slf.ProductId != "" { + db = db.Where("product_id=?", slf.ProductId) + } + return db } diff --git a/request/location_product_amount.go b/request/location_product_amount.go index bc7fa2d..7b1ff44 100644 --- a/request/location_product_amount.go +++ b/request/location_product_amount.go @@ -3,9 +3,11 @@ import "github.com/shopspring/decimal" type AddLocationProductAmount struct { - LocationProductAmountId int `json:"locationProductAmountId"` //搴撳瓨鐩樼偣id - AdjustAmount decimal.Decimal `json:"adjustAmount" ` //宸�� - DifferenceAmount decimal.Decimal `json:"difference_amount"` //璁℃暟鏁伴噺 + LocationId int `json:"locationId"` + ProductId string `json:"productId"` + Amount decimal.Decimal `json:"decimal"` //搴撳瓨鏁伴噺 + AdjustAmount decimal.Decimal `json:"adjustAmount" ` //宸�� + DifferenceAmount decimal.Decimal `json:"difference_amount"` //璁℃暟鏁伴噺 } type UpdateLocationProductAmount struct { diff --git a/router/router.go b/router/router.go index c23bd3d..bac5f16 100644 --- a/router/router.go +++ b/router/router.go @@ -113,10 +113,18 @@ locationProductController := new(controllers.LocationProductController) locationProductAPI := r.Group(urlPrefix + "/locationProduct") { - locationProductAPI.GET("operationType", locationProductController.List) // 鑾峰彇涓婃灦瑙勫垯鍒楄〃 - locationProductAPI.POST("operationType", locationProductController.Add) // 鏂板涓婃灦瑙勫垯 - locationProductAPI.PUT("operationType/:id", locationProductController.Update) // 淇敼涓婃灦瑙勫垯 - locationProductAPI.DELETE("operationType/:id", locationProductController.Delete) // 鍒犻櫎涓婃灦瑙勫垯 + locationProductAPI.POST("list", locationProductController.List) // 鑾峰彇涓婃灦瑙勫垯鍒楄〃 + locationProductAPI.POST("add", locationProductController.Add) // 鏂板涓婃灦瑙勫垯 + locationProductAPI.POST("update", locationProductController.Update) // 淇敼涓婃灦瑙勫垯 + locationProductAPI.DELETE("delete/:id", locationProductController.Delete) // 鍒犻櫎涓婃灦瑙勫垯 + } + + //搴撳瓨鐩樼偣 + locationProductAmountController := new(controllers.LocationProductAmountController) + locationProductAmountAPI := r.Group(urlPrefix + "/locationProductAmount") + { + locationProductAmountAPI.POST("add", locationProductAmountController.Add) //娣诲姞搴撳瓨鐩樼偣淇℃伅 + locationProductAmountAPI.POST("list", locationProductAmountController.List) //鏌ョ湅搴撳瓨鐩樼偣鍒楄〃 } return r -- Gitblit v1.8.0