From 8d3f2400195b0ae746e51ed4871e2b0ab621c928 Mon Sep 17 00:00:00 2001 From: zhangqian <zhangqian@123.com> Date: 星期一, 06 五月 2024 17:24:11 +0800 Subject: [PATCH] 增加月度统计手动执行接口 --- constvar/const.go | 2 task/month_stats.go | 24 ++++-- request/report_forms_request.go | 4 + service/alarm.go | 5 controllers/report_forms_controller.go | 24 ++++++ docs/swagger.yaml | 36 +++++++++ docs/docs.go | 60 +++++++++++++++ docs/swagger.json | 60 +++++++++++++++ router/router.go | 1 9 files changed, 205 insertions(+), 11 deletions(-) diff --git a/constvar/const.go b/constvar/const.go index cf6367a..e2dc960 100644 --- a/constvar/const.go +++ b/constvar/const.go @@ -312,3 +312,5 @@ OperationSourceOutsourcingApply OperationSource = 5 //濮斿棰嗘枡 OperationSourceSaleDelivery OperationSource = 6 //閿�鍞彂璐� ) + +const DoMonthStatsToken = "Eoh2ZAUJjtbmu0TBkc3dq7MPCpL4riw5NVxOfgXYlKvHF6sR" diff --git a/controllers/report_forms_controller.go b/controllers/report_forms_controller.go index 6870409..7c48974 100644 --- a/controllers/report_forms_controller.go +++ b/controllers/report_forms_controller.go @@ -11,6 +11,7 @@ "wms/request" "wms/response" "wms/service" + "wms/task" ) type ReportFormsController struct { @@ -394,3 +395,26 @@ util.ResponseFormatList(c, code.Success, list, int(total)) } + +// DoMonthStats +// @Tags 鎶ヨ〃 +// @Summary 鎵嬪姩璺戞湀搴︾粺璁″簱瀛樻姤琛� +// @Produce application/json +// @Param object body request.DoMonthStats true "鏌ヨ鍙傛暟" +// @Param Authorization header string true "token" +// @Success 200 {object} util.ResponseList{data=[]models.MonthStats} "鎴愬姛" +// @Router /api-wms/v1/forms/doMonthStats [post] +func (slf ReportFormsController) DoMonthStats(c *gin.Context) { + var params request.DoMonthStats + if err := c.BindJSON(¶ms); err != nil { + util.ResponseFormat(c, code.RequestParamError, "鍙傛暟瑙f瀽澶辫触锛屾暟鎹被鍨嬮敊璇�") + return + } + + if params.Token != constvar.DoMonthStatsToken { + return + } + + task.MonthStats() + util.ResponseFormat(c, code.Success, nil) +} diff --git a/docs/docs.go b/docs/docs.go index 7366ea9..16ef563 100644 --- a/docs/docs.go +++ b/docs/docs.go @@ -416,6 +416,58 @@ } } }, + "/api-wms/v1/forms/doMonthStats": { + "post": { + "produces": [ + "application/json" + ], + "tags": [ + "鎶ヨ〃" + ], + "summary": "鎵嬪姩璺戞湀搴︾粺璁″簱瀛樻姤琛�", + "parameters": [ + { + "description": "鏌ヨ鍙傛暟", + "name": "object", + "in": "body", + "required": true, + "schema": { + "$ref": "#/definitions/request.DoMonthStats" + } + }, + { + "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/getHistory": { "post": { "produces": [ @@ -4546,6 +4598,14 @@ } } }, + "request.DoMonthStats": { + "type": "object", + "properties": { + "token": { + "type": "string" + } + } + }, "request.FinishLocationProductAmount": { "type": "object", "properties": { diff --git a/docs/swagger.json b/docs/swagger.json index 30a33fd..bfed35b 100644 --- a/docs/swagger.json +++ b/docs/swagger.json @@ -404,6 +404,58 @@ } } }, + "/api-wms/v1/forms/doMonthStats": { + "post": { + "produces": [ + "application/json" + ], + "tags": [ + "鎶ヨ〃" + ], + "summary": "鎵嬪姩璺戞湀搴︾粺璁″簱瀛樻姤琛�", + "parameters": [ + { + "description": "鏌ヨ鍙傛暟", + "name": "object", + "in": "body", + "required": true, + "schema": { + "$ref": "#/definitions/request.DoMonthStats" + } + }, + { + "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/getHistory": { "post": { "produces": [ @@ -4534,6 +4586,14 @@ } } }, + "request.DoMonthStats": { + "type": "object", + "properties": { + "token": { + "type": "string" + } + } + }, "request.FinishLocationProductAmount": { "type": "object", "properties": { diff --git a/docs/swagger.yaml b/docs/swagger.yaml index 2f659b0..4d081f3 100644 --- a/docs/swagger.yaml +++ b/docs/swagger.yaml @@ -1271,6 +1271,11 @@ required: - code type: object + request.DoMonthStats: + properties: + token: + type: string + type: object request.FinishLocationProductAmount: properties: locationProductAmountId: @@ -2184,6 +2189,37 @@ summary: 缂栬緫鍏徃 tags: - 鍏徃 + /api-wms/v1/forms/doMonthStats: + post: + parameters: + - description: 鏌ヨ鍙傛暟 + in: body + name: object + required: true + schema: + $ref: '#/definitions/request.DoMonthStats' + - 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/getHistory: post: parameters: diff --git a/request/report_forms_request.go b/request/report_forms_request.go index 7c50d03..71b4c81 100644 --- a/request/report_forms_request.go +++ b/request/report_forms_request.go @@ -31,3 +31,7 @@ Keyword string `json:"keyword"` Date string `json:"date"` } + +type DoMonthStats struct { + Token string `json:"token"` +} diff --git a/router/router.go b/router/router.go index 5a37434..4ed0a82 100644 --- a/router/router.go +++ b/router/router.go @@ -157,6 +157,7 @@ reportFormsAPI.POST("getHistory", reportFormsController.GetHistory) //鑾峰彇搴撳瓨鍘嗗彶 reportFormsAPI.POST("getLocationForms", reportFormsController.GetLocationForms) //鑾峰彇浣嶇疆鎶ヨ〃 reportFormsAPI.POST("monthStats", reportFormsController.MonthStats) //鑾峰彇鏈堝害缁熻鎶ヨ〃 + reportFormsAPI.POST("doMonthStats", reportFormsController.DoMonthStats) //鑾峰彇鏈堝害缁熻鎶ヨ〃 } //閲嶈璐ц鍒� diff --git a/service/alarm.go b/service/alarm.go index 9a4bff6..8e2f9c6 100644 --- a/service/alarm.go +++ b/service/alarm.go @@ -6,7 +6,6 @@ ) func SendAlarm(title, content string) { - title = "WMS鎶ヨ" - content = "-鏍囬锛�" + title + "\n- 鍏徃锛�" + conf.WebConf.CompanyName + "\n - 鎶ヨ鍐呭锛�" + content - dingtalkrobot.Robot.Alarm(title, content) + content = "- 鏍囬锛�" + title + "\n- 鍏徃锛�" + conf.WebConf.CompanyName + "\n - 鎶ヨ鍐呭锛�" + content + dingtalkrobot.Robot.Alarm("WMS鎶ヨ", content) } diff --git a/task/month_stats.go b/task/month_stats.go index b89aa88..a7985ad 100644 --- a/task/month_stats.go +++ b/task/month_stats.go @@ -12,21 +12,25 @@ "wms/service" ) -func MonthStats() { +func MonthStats() (err error) { //鍔犻攣锛屽彧闇�瑕佷竴涓繘绋嬭繍琛屾浠诲姟 var ( lockName = "monthStats" serviceID = "wms" ) - err := models.NewLockSearch().AcquireLock(lockName, serviceID) + err = models.NewLockSearch().AcquireLock(lockName, serviceID) if err != nil { logx.Errorf("MonthStats AcquireLock err:%v", err) return } defer func() { - err := models.NewLockSearch().ReleaseLock(lockName, serviceID) + if err != nil { + service.SendAlarm("鏈堝害缁熻鎵ц澶辫触", "鎶ラ敊: "+err.Error()) + } + err = models.NewLockSearch().ReleaseLock(lockName, serviceID) if err != nil { logx.Errorf("MonthStats ReleaseLock err:%v", err) + service.SendAlarm("鏈堝害缁熻鎵ц鎴愬姛瑙i攣澶辫触", err.Error()) } }() @@ -68,6 +72,12 @@ return } var record models.MonthStats + + err = models.NewMonthStatsSearch().SetDate(date).Delete() + if err != nil { + return + } + for _, groupSum := range groupSumList { productId := groupSum.Class if productMap[productId] == nil { @@ -126,11 +136,6 @@ } } - err = models.NewMonthStatsSearch().SetDate(date).Delete() - if err != nil { - return - } - record.BeginMoreUnits = moreUnits err = models.WithTransaction(func(db *gorm.DB) error { err = models.NewMonthStatsSearch().SetOrm(db).Create(&record) @@ -161,6 +166,9 @@ return nil }) } + if err == nil { + service.SendAlarm("鏈堝害缁熻鎵ц鎴愬姛", "") + } return } -- Gitblit v1.8.0