From 73b6baf6af3d88cdcb0e2df7932a9bd96b0b85c5 Mon Sep 17 00:00:00 2001 From: zhangqian <zhangqian@123.com> Date: 星期一, 01 七月 2024 22:32:34 +0800 Subject: [PATCH] 月度统计出入库按类型汇总报表定时任务和手动跑任务接口 --- task/warehouse_month_stats.go | 96 +++++++++ docs/swagger.yaml | 116 +++++++++++ docs/docs.go | 188 ++++++++++++++++++ docs/swagger.json | 188 ++++++++++++++++++ 4 files changed, 572 insertions(+), 16 deletions(-) diff --git a/docs/docs.go b/docs/docs.go index 4d24113..07fee6b 100644 --- a/docs/docs.go +++ b/docs/docs.go @@ -773,6 +773,58 @@ } } }, + "/api-wms/v1/forms/doWarehouseMonthStats": { + "post": { + "produces": [ + "application/json" + ], + "tags": [ + "鎶ヨ〃" + ], + "summary": "鎵嬪姩璺戞湀搴︾粺璁″簱瀛樻姤琛�", + "parameters": [ + { + "description": "鏌ヨ鍙傛暟", + "name": "object", + "in": "body", + "required": true, + "schema": { + "$ref": "#/definitions/request.DoWarehouseMonthStats" + } + }, + { + "type": "string", + "description": "token", + "name": "Authorization", + "in": "header", + "required": true + } + ], + "responses": { + "200": { + "description": "鎴愬姛", + "schema": { + "allOf": [ + { + "$ref": "#/definitions/util.ResponseList" + }, + { + "type": "object", + "properties": { + "data": { + "type": "array", + "items": { + "$ref": "#/definitions/models.MonthStats" + } + } + } + } + ] + } + } + } + } + }, "/api-wms/v1/forms/downloadHistory": { "post": { "produces": [ @@ -1146,6 +1198,58 @@ "鎶ヨ〃" ], "summary": "鏈堝害缁熻搴撳瓨鎶ヨ〃", + "parameters": [ + { + "description": "鏌ヨ鍙傛暟", + "name": "object", + "in": "body", + "required": true, + "schema": { + "$ref": "#/definitions/request.GetMonthStats" + } + }, + { + "type": "string", + "description": "token", + "name": "Authorization", + "in": "header", + "required": true + } + ], + "responses": { + "200": { + "description": "鎴愬姛", + "schema": { + "allOf": [ + { + "$ref": "#/definitions/util.ResponseList" + }, + { + "type": "object", + "properties": { + "data": { + "type": "array", + "items": { + "$ref": "#/definitions/models.MonthStats" + } + } + } + } + ] + } + } + } + } + }, + "/api-wms/v1/forms/warehouseMonthStats": { + "post": { + "produces": [ + "application/json" + ], + "tags": [ + "鎶ヨ〃" + ], + "summary": "浠撳簱鏈堝害缁熻搴撳瓨鎶ヨ〃", "parameters": [ { "description": "鏌ヨ鍙傛暟", @@ -1946,7 +2050,22 @@ "200": { "description": "鎴愬姛", "schema": { - "$ref": "#/definitions/util.Response" + "allOf": [ + { + "$ref": "#/definitions/util.ResponseList" + }, + { + "type": "object", + "properties": { + "data": { + "type": "array", + "items": { + "$ref": "#/definitions/models.Operation" + } + } + } + } + ] } } } @@ -2183,9 +2302,9 @@ "in": "query" }, { - "type": "integer", + "type": "string", "description": "浠撳簱id", - "name": "warehouseId", + "name": "warehouseIds", "in": "query" } ], @@ -3794,6 +3913,21 @@ "BaseOperationTypeAdjust" ] }, + "constvar.BoolType": { + "type": "integer", + "enum": [ + 1, + 2 + ], + "x-enum-comments": { + "BoolTypeFalse": "false", + "BoolTypeTrue": "true" + }, + "x-enum-varnames": [ + "BoolTypeTrue", + "BoolTypeFalse" + ] + }, "constvar.CostingMethod": { "type": "integer", "enum": [ @@ -3965,17 +4099,20 @@ "enum": [ 1, 2, - 3 + 3, + 4 ], "x-enum-comments": { "StockoutType": "鍑哄簱绫诲瀷", "StorageType": "鍏ュ簱绫诲瀷", + "TakeStock": "鐩樼偣绫诲瀷", "TransferType": "璋冩嫧绫诲瀷" }, "x-enum-varnames": [ - "TransferType", "StorageType", - "StockoutType" + "StockoutType", + "TransferType", + "TakeStock" ] }, "constvar.OperationSource": { @@ -5094,6 +5231,9 @@ "updateTime": { "type": "string" }, + "warehouse": { + "$ref": "#/definitions/models.Warehouse" + }, "warehouseId": { "type": "integer" }, @@ -5125,6 +5265,10 @@ "type": "number" }, "createTime": { + "type": "string" + }, + "dealerType": { + "description": "鍑哄叆搴撶被鍨�", "type": "string" }, "fromLocation": { @@ -5418,6 +5562,14 @@ "description": "浠撳簱鍚嶇О", "type": "string" }, + "openMonthStats": { + "description": "鏄惁寮�鍚湀搴︾粺璁�", + "allOf": [ + { + "$ref": "#/definitions/constvar.BoolType" + } + ] + }, "outboundTransportation": { "description": "鍑哄簱杩愯緭", "type": "integer" @@ -5645,6 +5797,9 @@ } }, "id": { + "type": "integer" + }, + "inventoryDealerType": { "type": "integer" }, "locationId": { @@ -5879,6 +6034,14 @@ } } }, + "request.DoWarehouseMonthStats": { + "type": "object", + "properties": { + "token": { + "type": "string" + } + } + }, "request.EditMiniDict": { "type": "object", "properties": { @@ -6097,6 +6260,12 @@ }, "pageSize": { "description": "姣忛〉澶у皬", + "type": "integer" + }, + "preload": { + "type": "boolean" + }, + "warehouseID": { "type": "integer" } } @@ -6665,6 +6834,9 @@ "id": { "type": "integer" }, + "inventoryDealerType": { + "type": "integer" + }, "locationId": { "description": "婧愪綅缃甶d", "type": "integer" @@ -6723,6 +6895,10 @@ "description": "鐩爣浣嶇疆id", "type": "integer" }, + "warehouseId": { + "description": "浠撳簱id", + "type": "integer" + }, "waybillNumber": { "description": "杩愬崟鍙�", "type": "string" diff --git a/docs/swagger.json b/docs/swagger.json index 42f03fc..1aff6fb 100644 --- a/docs/swagger.json +++ b/docs/swagger.json @@ -762,6 +762,58 @@ } } }, + "/api-wms/v1/forms/doWarehouseMonthStats": { + "post": { + "produces": [ + "application/json" + ], + "tags": [ + "鎶ヨ〃" + ], + "summary": "鎵嬪姩璺戞湀搴︾粺璁″簱瀛樻姤琛�", + "parameters": [ + { + "description": "鏌ヨ鍙傛暟", + "name": "object", + "in": "body", + "required": true, + "schema": { + "$ref": "#/definitions/request.DoWarehouseMonthStats" + } + }, + { + "type": "string", + "description": "token", + "name": "Authorization", + "in": "header", + "required": true + } + ], + "responses": { + "200": { + "description": "鎴愬姛", + "schema": { + "allOf": [ + { + "$ref": "#/definitions/util.ResponseList" + }, + { + "type": "object", + "properties": { + "data": { + "type": "array", + "items": { + "$ref": "#/definitions/models.MonthStats" + } + } + } + } + ] + } + } + } + } + }, "/api-wms/v1/forms/downloadHistory": { "post": { "produces": [ @@ -1135,6 +1187,58 @@ "鎶ヨ〃" ], "summary": "鏈堝害缁熻搴撳瓨鎶ヨ〃", + "parameters": [ + { + "description": "鏌ヨ鍙傛暟", + "name": "object", + "in": "body", + "required": true, + "schema": { + "$ref": "#/definitions/request.GetMonthStats" + } + }, + { + "type": "string", + "description": "token", + "name": "Authorization", + "in": "header", + "required": true + } + ], + "responses": { + "200": { + "description": "鎴愬姛", + "schema": { + "allOf": [ + { + "$ref": "#/definitions/util.ResponseList" + }, + { + "type": "object", + "properties": { + "data": { + "type": "array", + "items": { + "$ref": "#/definitions/models.MonthStats" + } + } + } + } + ] + } + } + } + } + }, + "/api-wms/v1/forms/warehouseMonthStats": { + "post": { + "produces": [ + "application/json" + ], + "tags": [ + "鎶ヨ〃" + ], + "summary": "浠撳簱鏈堝害缁熻搴撳瓨鎶ヨ〃", "parameters": [ { "description": "鏌ヨ鍙傛暟", @@ -1935,7 +2039,22 @@ "200": { "description": "鎴愬姛", "schema": { - "$ref": "#/definitions/util.Response" + "allOf": [ + { + "$ref": "#/definitions/util.ResponseList" + }, + { + "type": "object", + "properties": { + "data": { + "type": "array", + "items": { + "$ref": "#/definitions/models.Operation" + } + } + } + } + ] } } } @@ -2172,9 +2291,9 @@ "in": "query" }, { - "type": "integer", + "type": "string", "description": "浠撳簱id", - "name": "warehouseId", + "name": "warehouseIds", "in": "query" } ], @@ -3783,6 +3902,21 @@ "BaseOperationTypeAdjust" ] }, + "constvar.BoolType": { + "type": "integer", + "enum": [ + 1, + 2 + ], + "x-enum-comments": { + "BoolTypeFalse": "false", + "BoolTypeTrue": "true" + }, + "x-enum-varnames": [ + "BoolTypeTrue", + "BoolTypeFalse" + ] + }, "constvar.CostingMethod": { "type": "integer", "enum": [ @@ -3954,17 +4088,20 @@ "enum": [ 1, 2, - 3 + 3, + 4 ], "x-enum-comments": { "StockoutType": "鍑哄簱绫诲瀷", "StorageType": "鍏ュ簱绫诲瀷", + "TakeStock": "鐩樼偣绫诲瀷", "TransferType": "璋冩嫧绫诲瀷" }, "x-enum-varnames": [ - "TransferType", "StorageType", - "StockoutType" + "StockoutType", + "TransferType", + "TakeStock" ] }, "constvar.OperationSource": { @@ -5083,6 +5220,9 @@ "updateTime": { "type": "string" }, + "warehouse": { + "$ref": "#/definitions/models.Warehouse" + }, "warehouseId": { "type": "integer" }, @@ -5114,6 +5254,10 @@ "type": "number" }, "createTime": { + "type": "string" + }, + "dealerType": { + "description": "鍑哄叆搴撶被鍨�", "type": "string" }, "fromLocation": { @@ -5407,6 +5551,14 @@ "description": "浠撳簱鍚嶇О", "type": "string" }, + "openMonthStats": { + "description": "鏄惁寮�鍚湀搴︾粺璁�", + "allOf": [ + { + "$ref": "#/definitions/constvar.BoolType" + } + ] + }, "outboundTransportation": { "description": "鍑哄簱杩愯緭", "type": "integer" @@ -5634,6 +5786,9 @@ } }, "id": { + "type": "integer" + }, + "inventoryDealerType": { "type": "integer" }, "locationId": { @@ -5868,6 +6023,14 @@ } } }, + "request.DoWarehouseMonthStats": { + "type": "object", + "properties": { + "token": { + "type": "string" + } + } + }, "request.EditMiniDict": { "type": "object", "properties": { @@ -6086,6 +6249,12 @@ }, "pageSize": { "description": "姣忛〉澶у皬", + "type": "integer" + }, + "preload": { + "type": "boolean" + }, + "warehouseID": { "type": "integer" } } @@ -6654,6 +6823,9 @@ "id": { "type": "integer" }, + "inventoryDealerType": { + "type": "integer" + }, "locationId": { "description": "婧愪綅缃甶d", "type": "integer" @@ -6712,6 +6884,10 @@ "description": "鐩爣浣嶇疆id", "type": "integer" }, + "warehouseId": { + "description": "浠撳簱id", + "type": "integer" + }, "waybillNumber": { "description": "杩愬崟鍙�", "type": "string" diff --git a/docs/swagger.yaml b/docs/swagger.yaml index 71233a6..08e97ae 100644 --- a/docs/swagger.yaml +++ b/docs/swagger.yaml @@ -60,6 +60,17 @@ - BaseOperationTypeInternal - BaseOperationTypeDisuse - BaseOperationTypeAdjust + constvar.BoolType: + enum: + - 1 + - 2 + type: integer + x-enum-comments: + BoolTypeFalse: "false" + BoolTypeTrue: "true" + x-enum-varnames: + - BoolTypeTrue + - BoolTypeFalse constvar.CostingMethod: enum: - 1 @@ -200,15 +211,18 @@ - 1 - 2 - 3 + - 4 type: integer x-enum-comments: StockoutType: 鍑哄簱绫诲瀷 StorageType: 鍏ュ簱绫诲瀷 + TakeStock: 鐩樼偣绫诲瀷 TransferType: 璋冩嫧绫诲瀷 x-enum-varnames: - - TransferType - StorageType - StockoutType + - TransferType + - TakeStock constvar.OperationSource: enum: - 1 @@ -1006,6 +1020,8 @@ type: integer updateTime: type: string + warehouse: + $ref: '#/definitions/models.Warehouse' warehouseId: type: integer waybillNumber: @@ -1029,6 +1045,9 @@ description: 鎴愭湰鍗曚环 type: number createTime: + type: string + dealerType: + description: 鍑哄叆搴撶被鍨� type: string fromLocation: allOf: @@ -1223,6 +1242,10 @@ name: description: 浠撳簱鍚嶇О type: string + openMonthStats: + allOf: + - $ref: '#/definitions/constvar.BoolType' + description: 鏄惁寮�鍚湀搴︾粺璁� outboundTransportation: description: 鍑哄簱杩愯緭 type: integer @@ -1377,6 +1400,8 @@ $ref: '#/definitions/request.OperationDetails' type: array id: + type: integer + inventoryDealerType: type: integer locationId: description: 婧愪綅缃甶d @@ -1540,6 +1565,11 @@ token: type: string type: object + request.DoWarehouseMonthStats: + properties: + token: + type: string + type: object request.EditMiniDict: properties: id: @@ -1688,6 +1718,10 @@ type: integer pageSize: description: 姣忛〉澶у皬 + type: integer + preload: + type: boolean + warehouseID: type: integer type: object request.GetProductList: @@ -2077,6 +2111,8 @@ type: array id: type: integer + inventoryDealerType: + type: integer locationId: description: 婧愪綅缃甶d type: integer @@ -2118,6 +2154,9 @@ description: 鐘舵�� toLocationId: description: 鐩爣浣嶇疆id + type: integer + warehouseId: + description: 浠撳簱id type: integer waybillNumber: description: 杩愬崟鍙� @@ -2771,6 +2810,37 @@ summary: 鎵嬪姩璺戞湀搴︾粺璁″簱瀛樻姤琛� tags: - 鎶ヨ〃 + /api-wms/v1/forms/doWarehouseMonthStats: + post: + parameters: + - description: 鏌ヨ鍙傛暟 + in: body + name: object + required: true + schema: + $ref: '#/definitions/request.DoWarehouseMonthStats' + - description: token + in: header + name: Authorization + required: true + type: string + produces: + - application/json + responses: + "200": + description: 鎴愬姛 + schema: + allOf: + - $ref: '#/definitions/util.ResponseList' + - properties: + data: + items: + $ref: '#/definitions/models.MonthStats' + type: array + type: object + summary: 鎵嬪姩璺戞湀搴︾粺璁″簱瀛樻姤琛� + tags: + - 鎶ヨ〃 /api-wms/v1/forms/downloadHistory: post: parameters: @@ -3017,6 +3087,37 @@ type: array type: object summary: 鏈堝害缁熻搴撳瓨鎶ヨ〃 + tags: + - 鎶ヨ〃 + /api-wms/v1/forms/warehouseMonthStats: + post: + parameters: + - description: 鏌ヨ鍙傛暟 + in: body + name: object + required: true + schema: + $ref: '#/definitions/request.GetMonthStats' + - description: token + in: header + name: Authorization + required: true + type: string + produces: + - application/json + responses: + "200": + description: 鎴愬姛 + schema: + allOf: + - $ref: '#/definitions/util.ResponseList' + - properties: + data: + items: + $ref: '#/definitions/models.MonthStats' + type: array + type: object + summary: 浠撳簱鏈堝害缁熻搴撳瓨鎶ヨ〃 tags: - 鎶ヨ〃 /api-wms/v1/location/addLocation: @@ -3482,7 +3583,14 @@ "200": description: 鎴愬姛 schema: - $ref: '#/definitions/util.Response' + allOf: + - $ref: '#/definitions/util.ResponseList' + - properties: + data: + items: + $ref: '#/definitions/models.Operation' + type: array + type: object summary: 鍏ュ簱/鍑哄簱鍒楄〃 tags: - 鍏ュ簱/鍑哄簱 @@ -3631,8 +3739,8 @@ type: integer - description: 浠撳簱id in: query - name: warehouseId - type: integer + name: warehouseIds + type: string produces: - application/json responses: diff --git a/task/warehouse_month_stats.go b/task/warehouse_month_stats.go new file mode 100644 index 0000000..d811a3f --- /dev/null +++ b/task/warehouse_month_stats.go @@ -0,0 +1,96 @@ +package task + +import ( + "fmt" + "gorm.io/gorm" + "time" + "wms/constvar" + "wms/models" + "wms/pkg/logx" + "wms/service" +) + +func WarehouseMonthStats() (err error) { + //鍔犻攣锛屽彧闇�瑕佷竴涓繘绋嬭繍琛屾浠诲姟 + var ( + lockName = "WarehouseMonthStats" + serviceID = "wms" + ) + err = models.NewLockSearch().AcquireLock(lockName, serviceID) + if err != nil { + logx.Errorf("WarehouseMonthStats AcquireLock err:%v", err) + return + } + defer func() { + if err != nil { + service.SendAlarm("鏈堝害缁熻鎵ц澶辫触", "鎶ラ敊: "+err.Error()) + } + err = models.NewLockSearch().ReleaseLock(lockName, serviceID) + if err != nil { + logx.Errorf("WarehouseMonthStats ReleaseLock err:%v", err) + service.SendAlarm("鏈堝害缁熻鎵ц鎴愬姛瑙i攣澶辫触", err.Error()) + } + }() + + date := time.Now().Format("2006-01") + lastDate := time.Now().AddDate(0, -1, 0).Format("2006-01") + + warehouses, err := models.NewWarehouseSearch().SetOpenMonthStats(constvar.BoolTypeTrue).FindNotTotal() + if len(warehouses) == 0 { + return + } + + for _, warehouse := range warehouses { + warehouseId := warehouse.Id + oldRecords, err := models.NewWarehouseMonthStatsSearch(). + SetDate(lastDate).SetWarehouseId(warehouseId).SetFields("id, product_id").FindNotTotal() + if err != nil { + logx.Errorf("WarehouseMonthStats get last date record err:%v", err) + continue + } + oldRecordsMap := models.WarehouseMonthStatsMap(oldRecords) + + //鏈湀鏈熷垵鏁伴噺/涓婃湀缁撲綑鏁伴噺 + statsRecords, err := service.GetCurrentWarehouseStats(date, warehouseId, nil) + if err != nil { + continue + } + + err = models.NewWarehouseMonthStatsSearch().SetDate(date).Delete() + if err != nil { + continue + } + + for _, record := range statsRecords { + record.BeginAmount = record.EndAmount + err = models.WithTransaction(func(db *gorm.DB) error { + err = models.NewWarehouseMonthStatsSearch().SetOrm(db).Create(record) + if err != nil { + logx.Errorf("NewWarehouseMonthStatsSearch Create err:%v, record: %+v", err, record) + service.SendAlarm("鎸変粨搴撴湀搴︾粺璁″垱寤烘湰鏈堝け璐�", fmt.Sprintf("NewWarehouseMonthStatsSearch Create err:%v, record: %+v", err, record)) + } + + if oldRecordsMap[record.ProductId] != nil && oldRecordsMap[record.ProductId].Id != 0 { + oldRecordsMap[record.ProductId].EndAmount = record.EndAmount + if !record.InputAmount.IsZero() || !record.InputAmount.IsZero() { + oldRecordsMap[record.ProductId].InputAmount = record.InputAmount + oldRecordsMap[record.ProductId].InputItems = record.InputItems + oldRecordsMap[record.ProductId].OutputAmount = record.OutputAmount + oldRecordsMap[record.ProductId].OutputItems = record.OutputItems + } + err = models.NewWarehouseMonthStatsSearch().SetOrm(db).SetID(oldRecordsMap[record.ProductId].Id).Save(record) + if err != nil { + logx.Errorf("NewWarehouseMonthStatsSearch Save err:%v, record:%v", err, oldRecordsMap[record.ProductId]) + service.SendAlarm("鏈堝害缁熻鏇存敼涓婃湀澶辫触", fmt.Sprintf("NewWarehouseMonthStatsSearch Create err:%v, record: %+v", err, record)) + } + } + return nil + }) + } + } + if err == nil { + service.SendAlarm("鎸変粨搴撴湀搴︾粺璁℃墽琛屾垚鍔�", "") + } + + return +} -- Gitblit v1.8.0