| | |
| | | OperationSourceOutsourcingApply OperationSource = 5 //委外领料 |
| | | OperationSourceSaleDelivery OperationSource = 6 //销售发货 |
| | | ) |
| | | |
| | | const DoMonthStatsToken = "Eoh2ZAUJjtbmu0TBkc3dq7MPCpL4riw5NVxOfgXYlKvHF6sR" |
| | |
| | | "wms/request" |
| | | "wms/response" |
| | | "wms/service" |
| | | "wms/task" |
| | | ) |
| | | |
| | | type ReportFormsController struct { |
| | |
| | | |
| | | 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, "参数解析失败,数据类型错误") |
| | | return |
| | | } |
| | | |
| | | if params.Token != constvar.DoMonthStatsToken { |
| | | return |
| | | } |
| | | |
| | | task.MonthStats() |
| | | util.ResponseFormat(c, code.Success, nil) |
| | | } |
| | |
| | | } |
| | | } |
| | | }, |
| | | "/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": [ |
| | |
| | | } |
| | | } |
| | | }, |
| | | "request.DoMonthStats": { |
| | | "type": "object", |
| | | "properties": { |
| | | "token": { |
| | | "type": "string" |
| | | } |
| | | } |
| | | }, |
| | | "request.FinishLocationProductAmount": { |
| | | "type": "object", |
| | | "properties": { |
| | |
| | | } |
| | | } |
| | | }, |
| | | "/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": [ |
| | |
| | | } |
| | | } |
| | | }, |
| | | "request.DoMonthStats": { |
| | | "type": "object", |
| | | "properties": { |
| | | "token": { |
| | | "type": "string" |
| | | } |
| | | } |
| | | }, |
| | | "request.FinishLocationProductAmount": { |
| | | "type": "object", |
| | | "properties": { |
| | |
| | | required: |
| | | - code |
| | | type: object |
| | | request.DoMonthStats: |
| | | properties: |
| | | token: |
| | | type: string |
| | | type: object |
| | | request.FinishLocationProductAmount: |
| | | properties: |
| | | locationProductAmountId: |
| | |
| | | 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: |
| | |
| | | Keyword string `json:"keyword"` |
| | | Date string `json:"date"` |
| | | } |
| | | |
| | | type DoMonthStats struct { |
| | | Token string `json:"token"` |
| | | } |
| | |
| | | reportFormsAPI.POST("getHistory", reportFormsController.GetHistory) //获取库存历史 |
| | | reportFormsAPI.POST("getLocationForms", reportFormsController.GetLocationForms) //获取位置报表 |
| | | reportFormsAPI.POST("monthStats", reportFormsController.MonthStats) //获取月度统计报表 |
| | | reportFormsAPI.POST("doMonthStats", reportFormsController.DoMonthStats) //获取月度统计报表 |
| | | } |
| | | |
| | | //重订货规则 |
| | |
| | | ) |
| | | |
| | | 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) |
| | | } |
| | |
| | | "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("月度统计执行成功解锁失败", err.Error()) |
| | | } |
| | | }() |
| | | |
| | |
| | | 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 { |
| | |
| | | } |
| | | } |
| | | |
| | | 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) |
| | |
| | | return nil |
| | | }) |
| | | } |
| | | if err == nil { |
| | | service.SendAlarm("月度统计执行成功", "") |
| | | } |
| | | return |
| | | } |
| | | |