From b3a318b7f707ca49fa9127881bbe709654eaa761 Mon Sep 17 00:00:00 2001 From: liujiandao <274878379@qq.com> Date: 星期三, 27 九月 2023 17:27:51 +0800 Subject: [PATCH] 报表功能开发 --- request/report_forms_request.go | 19 response/report_forms_response.go | 40 + controllers/report_forms_controller.go | 199 +++++++ models/material.go | 19 models/operation.go | 22 controllers/warehouse.go | 2 docs/swagger.yaml | 284 ++++++++++ controllers/location.go | 2 docs/docs.go | 434 ++++++++++++++++ docs/swagger.json | 434 ++++++++++++++++ router/router.go | 9 models/location_product.go | 4 models/location.go | 31 models/operation_details.go | 8 14 files changed, 1,472 insertions(+), 35 deletions(-) diff --git a/controllers/location.go b/controllers/location.go index 2d7946f..5785eb6 100644 --- a/controllers/location.go +++ b/controllers/location.go @@ -33,7 +33,7 @@ } if params.ParentId != 0 { //鏌ヨ涓婄骇鍚嶇О - first, err := models.NewLocationSearch().SetParentId(params.ParentId).First() + first, err := models.NewLocationSearch().SetID(params.ParentId).First() if err != nil { util.ResponseFormat(c, code.RequestParamError, "鏌ヨ涓婄骇鍚嶇О澶辫触") return diff --git a/controllers/report_forms_controller.go b/controllers/report_forms_controller.go new file mode 100644 index 0000000..d9ea817 --- /dev/null +++ b/controllers/report_forms_controller.go @@ -0,0 +1,199 @@ +package controllers + +import ( + "github.com/gin-gonic/gin" + "wms/constvar" + "wms/extend/code" + "wms/extend/util" + "wms/models" + "wms/request" + "wms/response" +) + +type ReportFormsController struct { +} + +// GetInventoryForms +// @Tags 鎶ヨ〃 +// @Summary 鑾峰彇搴撳瓨鎶ヨ〃 +// @Produce application/json +// @Param object body request.GetInventoryForms true "鏌ヨ鍙傛暟" +// @Success 200 {object} util.ResponseList{data=[]response.InventoryForms} "鎴愬姛" +// @Router /api-wms/v1/forms/getInventoryForms [post] +func (slf ReportFormsController) GetInventoryForms(c *gin.Context) { + var params request.GetInventoryForms + if err := c.BindJSON(¶ms); err != nil { + util.ResponseFormat(c, code.RequestParamError, "鍙傛暟瑙f瀽澶辫触锛屾暟鎹被鍨嬮敊璇�") + return + } + //鏌ヨ浜у搧 + search := models.NewMaterialSearch() + if params.PageInfo.Check() { + search.SetPage(params.Page, params.PageSize) + } + materials, total, err := search.SetCategoryIds(params.CategoryIds).Find() + if err != nil { + util.ResponseFormat(c, code.RequestParamError, "鏌ヨ浜у搧绫诲瀷澶辫触") + return + } + //鏌ヨ浜у搧绫诲瀷 + categories, err := models.NewProductCategorySearch().SetIds(params.CategoryIds).FindNotTotal() + if err != nil { + util.ResponseFormat(c, code.RequestParamError, "鏌ヨ浜у搧绫诲瀷澶辫触") + return + } + //鏌ヨ鍑哄叆搴撴暟閲� + locations, err := models.NewLocationSearch().SetJointName(params.WarehouseCode).FindNotTotal() + if err != nil { + util.ResponseFormat(c, code.RequestParamError, "鏌ヨ浠撳簱浣嶇疆澶辫触") + return + } + locationIds := make([]int, 0) + for _, location := range locations { + locationIds = append(locationIds, location.Id) + } + var inHouse []models.OperationDetails + var outHouse []models.OperationDetails + dbIn := models.NewOperationDetailsSearch().Orm.Model(&models.OperationDetails{}). + Joins("left join wms_operation ON wms_operation_details.operation_id=wms_operation.id"). + Where("wms_operation.base_operation_type=?", constvar.BaseOperationTypeIncoming). + Where("wms_operation.status=?", constvar.OperationStatus_Ready) + dbOut := models.NewOperationDetailsSearch().Orm.Model(&models.OperationDetails{}). + Joins("left join wms_operation ON wms_operation_details.operation_id=wms_operation.id"). + Where("wms_operation.base_operation_type=?", constvar.BaseOperationTypeOutgoing). + Where("wms_operation.status=?", constvar.OperationStatus_Ready) + if len(locationIds) > 0 { + dbIn.Where("wms_operation.from_location_id in (?)", locationIds) + dbOut.Where("wms_operation.from_location_id in (?)", locationIds) + } + err = dbIn.Find(&inHouse).Error + if err != nil { + util.ResponseFormat(c, code.RequestParamError, "鏌ヨ鍏ュ簱鏁伴噺澶辫触") + return + } + err = dbOut.Find(&outHouse).Error + if err != nil { + util.ResponseFormat(c, code.RequestParamError, "鏌ヨ鍑哄簱鏁伴噺澶辫触") + return + } + var result []response.InventoryForms + for _, material := range materials { + var resp response.InventoryForms + resp.ProduceId = material.ID + resp.ProductName = material.Name + resp.Cost = material.Cost + resp.Amount = material.Amount + resp.Unit = material.Unit + resp.Value = material.Amount.Mul(material.Cost) + for _, category := range categories { + if material.CategoryId == int(category.ID) { + resp.ProductType = category.Name + break + } + } + for _, details := range inHouse { + if material.ID == details.ProductId { + resp.In = resp.In.Add(details.Amount) + } + } + for _, details := range outHouse { + if material.ID == details.ProductId { + resp.Out = resp.Out.Add(details.Amount) + } + } + resp.AvailableNumber = resp.Amount + result = append(result, resp) + } + util.ResponseFormatList(c, code.Success, result, int(total)) +} + +// GetHistory +// @Tags 鎶ヨ〃 +// @Summary 鑾峰彇鍘嗗彶淇℃伅 +// @Produce application/json +// @Param object body request.GetInventoryHistory true "鏌ヨ鍙傛暟" +// @Success 200 {object} util.ResponseList{data=[]response.InventoryHistory} "鎴愬姛" +// @Router /api-wms/v1/forms/getHistory [post] +func (slf ReportFormsController) GetHistory(c *gin.Context) { + var params request.GetInventoryHistory + if err := c.BindJSON(¶ms); err != nil { + util.ResponseFormat(c, code.RequestParamError, "鍙傛暟瑙f瀽澶辫触锛屾暟鎹被鍨嬮敊璇�") + return + } + //鑾峰彇鎿嶄綔璇︽儏 + detailsSearch := models.NewOperationDetailsSearch() + if params.PageInfo.Check() { + detailsSearch.SetPage(params.Page, params.PageSize) + } + details, total, err := detailsSearch.SetProductId(params.ProduceId).Find() + if err != nil { + util.ResponseFormat(c, code.RequestParamError, "鏌ヨ鎿嶄綔璇︽儏澶辫触") + return + } + var operationIds []int + for _, detail := range details { + operationIds = append(operationIds, detail.OperationID) + } + //鑾峰彇鎿嶄綔璁板綍 + operations, err := models.NewOperationSearch().SetIds(operationIds).SetStatus(constvar.OperationStatus_Finish).FindNotTotal() + if err != nil { + util.ResponseFormat(c, code.RequestParamError, "鏌ヨ鎿嶄綔璁板綍澶辫触") + return + } + var result []response.InventoryHistory + for _, detail := range details { + var resp response.InventoryHistory + resp.Amount = detail.Amount + resp.Unit = params.Unit + for _, operation := range operations { + if detail.OperationID == operation.Id { + resp.Number = operation.Number + resp.Date = operation.UpdateTime + resp.BaseOperationType = operation.BaseOperationType + resp.ContactedName = operation.ContacterName + resp.FromLocation = operation.FromLocation.Name + resp.ToLocation = operation.ToLocation.Name + result = append(result, resp) + break + } + } + } + util.ResponseFormatList(c, code.Success, result, int(total)) +} + +// GetLocationForms +// @Tags 鎶ヨ〃 +// @Summary 鑾峰彇浣嶇疆鎶ヨ〃 +// @Produce application/json +// @Param object body request.PageInfo true "鏌ヨ鍙傛暟" +// @Success 200 {object} util.ResponseList{data=[]response.LocationForms} "鎴愬姛" +// @Router /api-wms/v1/forms/getLocationForms [post] +func (slf ReportFormsController) GetLocationForms(c *gin.Context) { + var params request.GetLocationForms + if err := c.BindJSON(¶ms); err != nil { + util.ResponseFormat(c, code.RequestParamError, "鍙傛暟瑙f瀽澶辫触锛屾暟鎹被鍨嬮敊璇�") + return + } + search := models.NewLocationProductSearch() + if params.PageInfo.Check() { + search.SetPage(params.Page, params.PageSize) + } + find, total, err := search.SetKeyword(params.KeyWord).FindByPage() + if err != nil { + util.ResponseFormat(c, code.RequestParamError, "鏌ヨ涓婃灦瑙勫垯澶辫触") + return + } + var result []response.LocationForms + for _, product := range find { + var resp response.LocationForms + resp.LocationName = product.Location.Name + resp.ProduceId = product.Product.ID + resp.ProductName = product.Product.Name + resp.ProductTypeName = product.ProductCategory.Name + resp.Amount = product.Product.Amount + resp.Unit = product.Product.Unit + resp.Value = product.Product.Amount.Mul(product.Product.Cost) + result = append(result, resp) + } + util.ResponseFormatList(c, code.Success, result, int(total)) +} diff --git a/controllers/warehouse.go b/controllers/warehouse.go index 94210d0..8606ee1 100644 --- a/controllers/warehouse.go +++ b/controllers/warehouse.go @@ -143,7 +143,7 @@ for _, warehouse := range list { codes = append(codes, warehouse.Code) } - locations, err := models.NewLocationSearch().SetCodes(codes).FindNotTotal() + locations, err := models.NewLocationSearch().SetJointNames(codes).FindNotTotal() if err != nil { util.ResponseFormat(c, code.RequestParamError, "浣嶇疆淇℃伅鏌ユ壘澶辫触") return diff --git a/docs/docs.go b/docs/docs.go index 20caec6..00d724a 100644 --- a/docs/docs.go +++ b/docs/docs.go @@ -294,6 +294,96 @@ } } }, + "/api-wms/v1/forms/getInventoryForms": { + "post": { + "produces": [ + "application/json" + ], + "tags": [ + "鎶ヨ〃" + ], + "summary": "鑾峰彇搴撳瓨鎶ヨ〃", + "parameters": [ + { + "description": "鏌ヨ鍙傛暟", + "name": "object", + "in": "body", + "required": true, + "schema": { + "$ref": "#/definitions/request.GetInventoryForms" + } + } + ], + "responses": { + "200": { + "description": "鎴愬姛", + "schema": { + "allOf": [ + { + "$ref": "#/definitions/util.ResponseList" + }, + { + "type": "object", + "properties": { + "data": { + "type": "array", + "items": { + "$ref": "#/definitions/response.InventoryForms" + } + } + } + } + ] + } + } + } + } + }, + "/api-wms/v1/forms/getInventoryHistory": { + "post": { + "produces": [ + "application/json" + ], + "tags": [ + "鎶ヨ〃" + ], + "summary": "鑾峰彇搴撳瓨鍘嗗彶", + "parameters": [ + { + "description": "鏌ヨ鍙傛暟", + "name": "object", + "in": "body", + "required": true, + "schema": { + "$ref": "#/definitions/request.GetInventoryHistory" + } + } + ], + "responses": { + "200": { + "description": "鎴愬姛", + "schema": { + "allOf": [ + { + "$ref": "#/definitions/util.ResponseList" + }, + { + "type": "object", + "properties": { + "data": { + "type": "array", + "items": { + "$ref": "#/definitions/response.InventoryHistory" + } + } + } + } + ] + } + } + } + } + }, "/api-wms/v1/location/addLocation": { "post": { "produces": [ @@ -454,6 +544,124 @@ "required": true, "schema": { "$ref": "#/definitions/models.Location" + } + } + ], + "responses": { + "200": { + "description": "鎴愬姛", + "schema": { + "$ref": "#/definitions/util.Response" + } + } + } + } + }, + "/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" } } ], @@ -1467,9 +1675,13 @@ "enum": [ 1, 2, - 3 + 3, + 4, + 5 ], "x-enum-comments": { + "BaseOperationTypeAdjust": "搴撳瓨鐩樼偣", + "BaseOperationTypeDisuse": "鎶ュ簾", "BaseOperationTypeIncoming": "鏀惰揣", "BaseOperationTypeInternal": "鍐呴儴璋冩嫧", "BaseOperationTypeOutgoing": "浜よ揣" @@ -1477,7 +1689,9 @@ "x-enum-varnames": [ "BaseOperationTypeIncoming", "BaseOperationTypeOutgoing", - "BaseOperationTypeInternal" + "BaseOperationTypeInternal", + "BaseOperationTypeDisuse", + "BaseOperationTypeAdjust" ] }, "constvar.CostingMethod": { @@ -1798,7 +2012,7 @@ }, "parentId": { "description": "涓婄骇id", - "type": "string" + "type": "integer" }, "recentlyCount": { "description": "鏈�杩戠洏鐐�", @@ -2016,6 +2230,14 @@ "models.Operation": { "type": "object", "properties": { + "baseOperationType": { + "description": "鍩虹浣滀笟绫诲瀷", + "allOf": [ + { + "$ref": "#/definitions/constvar.BaseOperationType" + } + ] + }, "comment": { "type": "string" }, @@ -2311,6 +2533,27 @@ } } }, + "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.AddOperation": { "type": "object", "properties": { @@ -2506,6 +2749,55 @@ } } }, + "request.GetInventoryForms": { + "type": "object", + "properties": { + "categoryIds": { + "description": "浜у搧绫诲瀷id", + "type": "array", + "items": { + "type": "integer" + } + }, + "page": { + "description": "椤电爜", + "type": "integer" + }, + "pageSize": { + "description": "姣忛〉澶у皬", + "type": "integer" + }, + "warehouseCode": { + "description": "浠撳簱缂╁啓", + "type": "string" + } + } + }, + "request.GetInventoryHistory": { + "type": "object", + "properties": { + "page": { + "description": "椤电爜", + "type": "integer" + }, + "pageSize": { + "description": "姣忛〉澶у皬", + "type": "integer" + }, + "produceId": { + "description": "浜у搧id", + "type": "string" + }, + "productName": { + "description": "浜у搧鍚嶇О", + "type": "string" + }, + "unit": { + "description": "鍗曚綅", + "type": "string" + } + } + }, "request.GetProductList": { "type": "object", "properties": { @@ -2580,6 +2872,19 @@ }, "sourceNumber": { "type": "string" + } + } + }, + "request.PageInfo": { + "type": "object", + "properties": { + "page": { + "description": "椤电爜", + "type": "integer" + }, + "pageSize": { + "description": "姣忛〉澶у皬", + "type": "integer" } } }, @@ -2658,8 +2963,10 @@ "type": "object", "properties": { "amount": { - "description": "ProductName string ` + "`" + `json:\"productName\"` + "`" + `", "type": "number" + }, + "baseOperationType": { + "$ref": "#/definitions/constvar.BaseOperationType" }, "fromLocationId": { "type": "integer" @@ -2668,7 +2975,6 @@ "type": "integer" }, "number": { - "description": "Unit string ` + "`" + `json:\"unit\"` + "`" + `", "type": "string" }, "operationDate": { @@ -2688,9 +2994,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" @@ -2830,6 +3168,92 @@ } } }, + "response.InventoryForms": { + "type": "object", + "properties": { + "amount": { + "description": "鍦ㄥ簱鏁伴噺", + "type": "number" + }, + "availableNumber": { + "description": "鍙敤搴撳瓨", + "type": "number" + }, + "cost": { + "description": "鎴愭湰", + "type": "number" + }, + "in": { + "description": "鍏ュ簱", + "type": "number" + }, + "out": { + "description": "鍑哄簱", + "type": "number" + }, + "produceId": { + "description": "浜у搧id", + "type": "string" + }, + "productName": { + "description": "浜у搧鍚嶇О", + "type": "string" + }, + "productType": { + "description": "浜у搧绫诲瀷", + "type": "string" + }, + "unit": { + "description": "鍗曚綅", + "type": "string" + }, + "value": { + "description": "鎬讳环鍊�", + "type": "number" + } + } + }, + "response.InventoryHistory": { + "type": "object", + "properties": { + "amount": { + "description": "鏁伴噺", + "type": "number" + }, + "baseOperationType": { + "description": "鍩虹浣滀笟绫诲瀷", + "allOf": [ + { + "$ref": "#/definitions/constvar.BaseOperationType" + } + ] + }, + "contactedName": { + "description": "瀹屾垚鑰�", + "type": "string" + }, + "date": { + "description": "鏃ユ湡", + "type": "string" + }, + "fromLocation": { + "description": "婧愪綅缃�", + "type": "string" + }, + "number": { + "description": "鍗曞彿", + "type": "string" + }, + "toLocation": { + "description": "鐩爣浣嶇疆", + "type": "string" + }, + "unit": { + "description": "鍗曚綅", + "type": "string" + } + } + }, "util.Response": { "type": "object", "properties": { diff --git a/docs/swagger.json b/docs/swagger.json index 801bf26..f34ccf1 100644 --- a/docs/swagger.json +++ b/docs/swagger.json @@ -282,6 +282,96 @@ } } }, + "/api-wms/v1/forms/getInventoryForms": { + "post": { + "produces": [ + "application/json" + ], + "tags": [ + "鎶ヨ〃" + ], + "summary": "鑾峰彇搴撳瓨鎶ヨ〃", + "parameters": [ + { + "description": "鏌ヨ鍙傛暟", + "name": "object", + "in": "body", + "required": true, + "schema": { + "$ref": "#/definitions/request.GetInventoryForms" + } + } + ], + "responses": { + "200": { + "description": "鎴愬姛", + "schema": { + "allOf": [ + { + "$ref": "#/definitions/util.ResponseList" + }, + { + "type": "object", + "properties": { + "data": { + "type": "array", + "items": { + "$ref": "#/definitions/response.InventoryForms" + } + } + } + } + ] + } + } + } + } + }, + "/api-wms/v1/forms/getInventoryHistory": { + "post": { + "produces": [ + "application/json" + ], + "tags": [ + "鎶ヨ〃" + ], + "summary": "鑾峰彇搴撳瓨鍘嗗彶", + "parameters": [ + { + "description": "鏌ヨ鍙傛暟", + "name": "object", + "in": "body", + "required": true, + "schema": { + "$ref": "#/definitions/request.GetInventoryHistory" + } + } + ], + "responses": { + "200": { + "description": "鎴愬姛", + "schema": { + "allOf": [ + { + "$ref": "#/definitions/util.ResponseList" + }, + { + "type": "object", + "properties": { + "data": { + "type": "array", + "items": { + "$ref": "#/definitions/response.InventoryHistory" + } + } + } + } + ] + } + } + } + } + }, "/api-wms/v1/location/addLocation": { "post": { "produces": [ @@ -442,6 +532,124 @@ "required": true, "schema": { "$ref": "#/definitions/models.Location" + } + } + ], + "responses": { + "200": { + "description": "鎴愬姛", + "schema": { + "$ref": "#/definitions/util.Response" + } + } + } + } + }, + "/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" } } ], @@ -1455,9 +1663,13 @@ "enum": [ 1, 2, - 3 + 3, + 4, + 5 ], "x-enum-comments": { + "BaseOperationTypeAdjust": "搴撳瓨鐩樼偣", + "BaseOperationTypeDisuse": "鎶ュ簾", "BaseOperationTypeIncoming": "鏀惰揣", "BaseOperationTypeInternal": "鍐呴儴璋冩嫧", "BaseOperationTypeOutgoing": "浜よ揣" @@ -1465,7 +1677,9 @@ "x-enum-varnames": [ "BaseOperationTypeIncoming", "BaseOperationTypeOutgoing", - "BaseOperationTypeInternal" + "BaseOperationTypeInternal", + "BaseOperationTypeDisuse", + "BaseOperationTypeAdjust" ] }, "constvar.CostingMethod": { @@ -1786,7 +2000,7 @@ }, "parentId": { "description": "涓婄骇id", - "type": "string" + "type": "integer" }, "recentlyCount": { "description": "鏈�杩戠洏鐐�", @@ -2004,6 +2218,14 @@ "models.Operation": { "type": "object", "properties": { + "baseOperationType": { + "description": "鍩虹浣滀笟绫诲瀷", + "allOf": [ + { + "$ref": "#/definitions/constvar.BaseOperationType" + } + ] + }, "comment": { "type": "string" }, @@ -2299,6 +2521,27 @@ } } }, + "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.AddOperation": { "type": "object", "properties": { @@ -2494,6 +2737,55 @@ } } }, + "request.GetInventoryForms": { + "type": "object", + "properties": { + "categoryIds": { + "description": "浜у搧绫诲瀷id", + "type": "array", + "items": { + "type": "integer" + } + }, + "page": { + "description": "椤电爜", + "type": "integer" + }, + "pageSize": { + "description": "姣忛〉澶у皬", + "type": "integer" + }, + "warehouseCode": { + "description": "浠撳簱缂╁啓", + "type": "string" + } + } + }, + "request.GetInventoryHistory": { + "type": "object", + "properties": { + "page": { + "description": "椤电爜", + "type": "integer" + }, + "pageSize": { + "description": "姣忛〉澶у皬", + "type": "integer" + }, + "produceId": { + "description": "浜у搧id", + "type": "string" + }, + "productName": { + "description": "浜у搧鍚嶇О", + "type": "string" + }, + "unit": { + "description": "鍗曚綅", + "type": "string" + } + } + }, "request.GetProductList": { "type": "object", "properties": { @@ -2568,6 +2860,19 @@ }, "sourceNumber": { "type": "string" + } + } + }, + "request.PageInfo": { + "type": "object", + "properties": { + "page": { + "description": "椤电爜", + "type": "integer" + }, + "pageSize": { + "description": "姣忛〉澶у皬", + "type": "integer" } } }, @@ -2646,8 +2951,10 @@ "type": "object", "properties": { "amount": { - "description": "ProductName string `json:\"productName\"`", "type": "number" + }, + "baseOperationType": { + "$ref": "#/definitions/constvar.BaseOperationType" }, "fromLocationId": { "type": "integer" @@ -2656,7 +2963,6 @@ "type": "integer" }, "number": { - "description": "Unit string `json:\"unit\"`", "type": "string" }, "operationDate": { @@ -2676,9 +2982,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" @@ -2818,6 +3156,92 @@ } } }, + "response.InventoryForms": { + "type": "object", + "properties": { + "amount": { + "description": "鍦ㄥ簱鏁伴噺", + "type": "number" + }, + "availableNumber": { + "description": "鍙敤搴撳瓨", + "type": "number" + }, + "cost": { + "description": "鎴愭湰", + "type": "number" + }, + "in": { + "description": "鍏ュ簱", + "type": "number" + }, + "out": { + "description": "鍑哄簱", + "type": "number" + }, + "produceId": { + "description": "浜у搧id", + "type": "string" + }, + "productName": { + "description": "浜у搧鍚嶇О", + "type": "string" + }, + "productType": { + "description": "浜у搧绫诲瀷", + "type": "string" + }, + "unit": { + "description": "鍗曚綅", + "type": "string" + }, + "value": { + "description": "鎬讳环鍊�", + "type": "number" + } + } + }, + "response.InventoryHistory": { + "type": "object", + "properties": { + "amount": { + "description": "鏁伴噺", + "type": "number" + }, + "baseOperationType": { + "description": "鍩虹浣滀笟绫诲瀷", + "allOf": [ + { + "$ref": "#/definitions/constvar.BaseOperationType" + } + ] + }, + "contactedName": { + "description": "瀹屾垚鑰�", + "type": "string" + }, + "date": { + "description": "鏃ユ湡", + "type": "string" + }, + "fromLocation": { + "description": "婧愪綅缃�", + "type": "string" + }, + "number": { + "description": "鍗曞彿", + "type": "string" + }, + "toLocation": { + "description": "鐩爣浣嶇疆", + "type": "string" + }, + "unit": { + "description": "鍗曚綅", + "type": "string" + } + } + }, "util.Response": { "type": "object", "properties": { diff --git a/docs/swagger.yaml b/docs/swagger.yaml index 81acff3..d0c176d 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 @@ -257,7 +263,7 @@ type: string parentId: description: 涓婄骇id - type: string + type: integer recentlyCount: description: 鏈�杩戠洏鐐� type: string @@ -422,6 +428,10 @@ type: object models.Operation: properties: + baseOperationType: + allOf: + - $ref: '#/definitions/constvar.BaseOperationType' + description: 鍩虹浣滀笟绫诲瀷 comment: type: string companyID: @@ -619,6 +629,21 @@ 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.AddOperation: properties: comment: @@ -754,6 +779,41 @@ required: - code type: object + request.GetInventoryForms: + properties: + categoryIds: + description: 浜у搧绫诲瀷id + items: + type: integer + type: array + page: + description: 椤电爜 + type: integer + pageSize: + description: 姣忛〉澶у皬 + type: integer + warehouseCode: + description: 浠撳簱缂╁啓 + type: string + type: object + request.GetInventoryHistory: + properties: + page: + description: 椤电爜 + type: integer + pageSize: + description: 姣忛〉澶у皬 + type: integer + produceId: + description: 浜у搧id + type: string + productName: + description: 浜у搧鍚嶇О + type: string + unit: + description: 鍗曚綅 + type: string + type: object request.GetProductList: properties: categoryId: @@ -808,6 +868,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 +929,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 +949,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 @@ -975,6 +1065,67 @@ warehouseId: description: 浠撳簱id type: integer + type: object + response.InventoryForms: + properties: + amount: + description: 鍦ㄥ簱鏁伴噺 + type: number + availableNumber: + description: 鍙敤搴撳瓨 + type: number + cost: + description: 鎴愭湰 + type: number + in: + description: 鍏ュ簱 + type: number + out: + description: 鍑哄簱 + type: number + produceId: + description: 浜у搧id + type: string + productName: + description: 浜у搧鍚嶇О + type: string + productType: + description: 浜у搧绫诲瀷 + type: string + unit: + description: 鍗曚綅 + type: string + value: + description: 鎬讳环鍊� + type: number + type: object + response.InventoryHistory: + properties: + amount: + description: 鏁伴噺 + type: number + baseOperationType: + allOf: + - $ref: '#/definitions/constvar.BaseOperationType' + description: 鍩虹浣滀笟绫诲瀷 + contactedName: + description: 瀹屾垚鑰� + type: string + date: + description: 鏃ユ湡 + type: string + fromLocation: + description: 婧愪綅缃� + type: string + number: + description: 鍗曞彿 + type: string + toLocation: + description: 鐩爣浣嶇疆 + type: string + unit: + description: 鍗曚綅 + type: string type: object util.Response: properties: @@ -1174,6 +1325,58 @@ summary: 缂栬緫鍏徃 tags: - 鍏徃 + /api-wms/v1/forms/getInventoryForms: + post: + parameters: + - description: 鏌ヨ鍙傛暟 + in: body + name: object + required: true + schema: + $ref: '#/definitions/request.GetInventoryForms' + produces: + - application/json + responses: + "200": + description: 鎴愬姛 + schema: + allOf: + - $ref: '#/definitions/util.ResponseList' + - properties: + data: + items: + $ref: '#/definitions/response.InventoryForms' + type: array + type: object + summary: 鑾峰彇搴撳瓨鎶ヨ〃 + tags: + - 鎶ヨ〃 + /api-wms/v1/forms/getInventoryHistory: + post: + parameters: + - description: 鏌ヨ鍙傛暟 + in: body + name: object + required: true + schema: + $ref: '#/definitions/request.GetInventoryHistory' + produces: + - application/json + responses: + "200": + description: 鎴愬姛 + schema: + allOf: + - $ref: '#/definitions/util.ResponseList' + - properties: + data: + items: + $ref: '#/definitions/response.InventoryHistory' + type: array + type: object + summary: 鑾峰彇搴撳瓨鍘嗗彶 + tags: + - 鎶ヨ〃 /api-wms/v1/location/addLocation: post: parameters: @@ -1279,6 +1482,81 @@ 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/operation/finish/{id}: put: parameters: diff --git a/models/location.go b/models/location.go index db96855..64676df 100644 --- a/models/location.go +++ b/models/location.go @@ -30,13 +30,13 @@ LocationSearch struct { Location - Order string - PageNum int - PageSize int - Keyword string - Orm *gorm.DB - Preload bool - Codes []string + Order string + PageNum int + PageSize int + Keyword string + Orm *gorm.DB + Preload bool + JointNames []string } ) @@ -67,8 +67,14 @@ slf.Id = ID return slf } -func (slf *LocationSearch) SetCodes(ids []string) *LocationSearch { - slf.Codes = ids + +func (slf *LocationSearch) SetJointName(code string) *LocationSearch { + slf.JointName = code + return slf +} + +func (slf *LocationSearch) SetJointNames(codes []string) *LocationSearch { + slf.JointNames = codes return slf } @@ -131,8 +137,11 @@ if slf.CompanyId != 0 { db = db.Where("company_id=?", slf.CompanyId) } - if len(slf.Codes) != 0 { - db = db.Where("warehouse_code in (?)", slf.Codes) + if slf.JointName != "" { + db = db.Where("joint_name like ?", slf.JointName+"%") + } + if len(slf.JointNames) != 0 { + db = db.Where("joint_name in (?)", slf.JointNames) } return db diff --git a/models/location_product.go b/models/location_product.go index b3edb61..7f8a946 100644 --- a/models/location_product.go +++ b/models/location_product.go @@ -153,7 +153,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("Location").Preload("ProductCategory").Preload("Product").Find(&records).Error; err != nil { return records, total, fmt.Errorf("find records err: %v", err) } @@ -166,7 +166,7 @@ db = slf.build() ) - if err := db.Find(&records).Error; err != nil { + if err := db.Preload("Location").Preload("ProductCategory").Preload("Product").Find(&records).Error; err != nil { return records, fmt.Errorf("find records err: %v", err) } diff --git a/models/material.go b/models/material.go index df61270..f22f5b9 100644 --- a/models/material.go +++ b/models/material.go @@ -77,11 +77,12 @@ //MaterialTypes []constvar.MaterialType Keyword string //SetTemplateType constvar.SetTemplateType - Order string - PageNum int - PageSize int - Ids []string - Orm *gorm.DB + Order string + PageNum int + PageSize int + Ids []string + Orm *gorm.DB + CategoryIds []int } IdAndName struct { @@ -157,6 +158,11 @@ return slf } +func (slf *MaterialSearch) SetCategoryIds(ids []int) *MaterialSearch { + slf.CategoryIds = ids + return slf +} + // //func (slf *MaterialSearch) SetSetTemplateType(setType constvar.SetTemplateType) *MaterialSearch { // slf.SetTemplateType = setType @@ -230,6 +236,9 @@ if slf.CategoryId > 0 { db = db.Where("category_id = ?", slf.CategoryId) } + if len(slf.CategoryIds) > 0 { + db = db.Where("category_id in ?", slf.CategoryIds) + } return db } diff --git a/models/operation.go b/models/operation.go index 5f20228..1fd2daf 100644 --- a/models/operation.go +++ b/models/operation.go @@ -41,6 +41,7 @@ Orm *gorm.DB Preload bool Disuse bool + Ids []int } ) @@ -102,6 +103,15 @@ return slf } +func (slf *OperationSearch) SetIds(ids []int) *OperationSearch { + slf.Ids = ids + return slf +} +func (slf *OperationSearch) SetStatus(status constvar.OperationStatus) *OperationSearch { + slf.Status = status + return slf +} + func (slf *OperationSearch) build() *gorm.DB { var db = slf.Orm.Model(&Operation{}) @@ -134,6 +144,14 @@ if slf.Disuse { db = db.Where("operation_type_id = ?", 0) + } + + if len(slf.Ids) > 0 { + db = db.Where("id in (?)", slf.Ids) + } + + if slf.Status > 0 { + db = db.Where("status = ?", slf.Status) } return db @@ -236,7 +254,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("FromLocation").Preload("ToLocation").Find(&records).Error; err != nil { return records, total, fmt.Errorf("find records err: %v", err) } @@ -252,7 +270,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("FromLocation").Preload("ToLocation").Find(&records).Error; err != nil { return records, fmt.Errorf("find records err: %v", err) } diff --git a/models/operation_details.go b/models/operation_details.go index 32e8f9a..9e89e77 100644 --- a/models/operation_details.go +++ b/models/operation_details.go @@ -74,6 +74,11 @@ return slf } +func (slf *OperationDetailsSearch) SetProductId(productId string) *OperationDetailsSearch { + slf.ProductId = productId + return slf +} + func (slf *OperationDetailsSearch) build() *gorm.DB { var db = slf.Orm.Model(&OperationDetails{}) @@ -92,6 +97,9 @@ if slf.OperationID != 0 { db = db.Where("operation_id = ?", slf.OperationID) } + if slf.ProductId != "" { + db = db.Where("product_id = ?", slf.ProductId) + } return db } diff --git a/request/report_forms_request.go b/request/report_forms_request.go new file mode 100644 index 0000000..f659a9b --- /dev/null +++ b/request/report_forms_request.go @@ -0,0 +1,19 @@ +package request + +type GetInventoryForms struct { + PageInfo + CategoryIds []int `json:"categoryIds"` //浜у搧绫诲瀷id + WarehouseCode string `json:"warehouseCode"` //浠撳簱缂╁啓 +} + +type GetInventoryHistory struct { + PageInfo + ProduceId string `json:"produceId"` //浜у搧id + ProductName string `json:"productName"` //浜у搧鍚嶇О + Unit string `json:"unit"` //鍗曚綅 +} + +type GetLocationForms struct { + PageInfo + KeyWord string `json:"keyWord"` +} diff --git a/response/report_forms_response.go b/response/report_forms_response.go new file mode 100644 index 0000000..63ee819 --- /dev/null +++ b/response/report_forms_response.go @@ -0,0 +1,40 @@ +package response + +import ( + "github.com/shopspring/decimal" + "wms/constvar" +) + +type InventoryForms struct { + ProduceId string `json:"produceId"` //浜у搧id + ProductName string `json:"productName"` //浜у搧鍚嶇О + ProductType string `json:"productType"` //浜у搧绫诲瀷 + Cost decimal.Decimal `json:"cost"` //鎴愭湰 + Value decimal.Decimal `json:"value"` //鎬讳环鍊� + Amount decimal.Decimal `json:"amount"` //鍦ㄥ簱鏁伴噺 + AvailableNumber decimal.Decimal `json:"availableNumber"` //鍙敤搴撳瓨 + In decimal.Decimal `json:"in"` //鍏ュ簱 + Out decimal.Decimal `json:"out"` //鍑哄簱 + Unit string `json:"unit"` //鍗曚綅 +} + +type InventoryHistory struct { + Number string `json:"number"` //鍗曞彿 + Date string `json:"date"` //鏃ユ湡 + FromLocation string `json:"fromLocation"` //婧愪綅缃� + ToLocation string `json:"toLocation"` //鐩爣浣嶇疆 + Amount decimal.Decimal `json:"amount"` //鏁伴噺 + Unit string `json:"unit"` //鍗曚綅 + ContactedName string `json:"contactedName"` //瀹屾垚鑰� + BaseOperationType constvar.BaseOperationType `json:"baseOperationType"` //鍩虹浣滀笟绫诲瀷 +} + +type LocationForms struct { + ProduceId string `json:"produceId"` //浜у搧id + LocationName string `json:"locationName"` //浣嶇疆鍚嶇О + ProductName string `json:"productName"` //浜у搧鍚嶇О + ProductTypeName string `json:"productTypeName"` //浜у搧绫诲埆 + Amount decimal.Decimal `json:"amount"` //鏁伴噺 + Unit string `json:"unit"` //鍗曚綅 + Value decimal.Decimal `json:"value"` //鎬讳环鍊� +} diff --git a/router/router.go b/router/router.go index c23bd3d..f18f617 100644 --- a/router/router.go +++ b/router/router.go @@ -119,5 +119,14 @@ locationProductAPI.DELETE("operationType/:id", locationProductController.Delete) // 鍒犻櫎涓婃灦瑙勫垯 } + //鎶ヨ〃 + reportFormsController := new(controllers.ReportFormsController) + reportFormsAPI := r.Group(urlPrefix + "/forms") + { + reportFormsAPI.POST("getInventoryForms", reportFormsController.GetInventoryForms) //鑾峰彇搴撳瓨鎶ヨ〃 + reportFormsAPI.POST("getHistory", reportFormsController.GetHistory) //鑾峰彇搴撳瓨鍘嗗彶 + reportFormsAPI.POST("getLocationForms", reportFormsController.GetLocationForms) //鑾峰彇浣嶇疆鎶ヨ〃 + } + return r } -- Gitblit v1.8.0