zhangqian
2024-05-06 8d3f2400195b0ae746e51ed4871e2b0ab621c928
增加月度统计手动执行接口
9个文件已修改
216 ■■■■■ 已修改文件
constvar/const.go 2 ●●●●● 补丁 | 查看 | 原始文档 | blame | 历史
controllers/report_forms_controller.go 24 ●●●●● 补丁 | 查看 | 原始文档 | blame | 历史
docs/docs.go 60 ●●●●● 补丁 | 查看 | 原始文档 | blame | 历史
docs/swagger.json 60 ●●●●● 补丁 | 查看 | 原始文档 | blame | 历史
docs/swagger.yaml 36 ●●●●● 补丁 | 查看 | 原始文档 | blame | 历史
request/report_forms_request.go 4 ●●●● 补丁 | 查看 | 原始文档 | blame | 历史
router/router.go 1 ●●●● 补丁 | 查看 | 原始文档 | blame | 历史
service/alarm.go 5 ●●●●● 补丁 | 查看 | 原始文档 | blame | 历史
task/month_stats.go 24 ●●●●● 补丁 | 查看 | 原始文档 | blame | 历史
constvar/const.go
@@ -312,3 +312,5 @@
    OperationSourceOutsourcingApply OperationSource = 5 //委外领料
    OperationSourceSaleDelivery     OperationSource = 6 //销售发货
)
const DoMonthStatsToken = "Eoh2ZAUJjtbmu0TBkc3dq7MPCpL4riw5NVxOfgXYlKvHF6sR"
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(&params); err != nil {
        util.ResponseFormat(c, code.RequestParamError, "参数解析失败,数据类型错误")
        return
    }
    if params.Token != constvar.DoMonthStatsToken {
        return
    }
    task.MonthStats()
    util.ResponseFormat(c, code.Success, nil)
}
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": {
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": {
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:
request/report_forms_request.go
@@ -31,3 +31,7 @@
    Keyword string `json:"keyword"`
    Date    string `json:"date"`
}
type DoMonthStats struct {
    Token string `json:"token"`
}
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)           //获取月度统计报表
    }
    //重订货规则
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)
}
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("月度统计执行成功解锁失败", 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
}