月度统计出入库按类型汇总报表定时任务和手动跑任务接口
| | |
| | | } |
| | | return true |
| | | } |
| | | |
| | | // BoolType 布尔类型 |
| | | type BoolType int |
| | | |
| | | const ( |
| | | BoolTypeTrue BoolType = 1 // true |
| | | BoolTypeFalse BoolType = 2 // false |
| | | ) |
| | | |
| | | func (slf BoolType) IsValid() bool { |
| | | return slf == BoolTypeTrue || slf == BoolTypeFalse |
| | | } |
| | | |
| | | func (slf BoolType) Bool() bool { |
| | | return slf == BoolTypeTrue |
| | | } |
| | |
| | | |
| | | util.ResponseFormatList(c, code.Success, result, int(total)) |
| | | } |
| | | |
| | | // DoWareHouseMonthStats |
| | | // @Tags 报表 |
| | | // @Summary 手动跑月度统计库存报表 |
| | | // @Produce application/json |
| | | // @Param object body request.DoWarehouseMonthStats true "查询参数" |
| | | // @Param Authorization header string true "token" |
| | | // @Success 200 {object} util.ResponseList{data=[]models.MonthStats} "成功" |
| | | // @Router /api-wms/v1/forms/doWarehouseMonthStats [post] |
| | | func (slf ReportFormsController) DoWareHouseMonthStats(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.WarehouseMonthStats() |
| | | util.ResponseFormat(c, code.Success, nil) |
| | | } |
| | |
| | | Attribute{}, |
| | | AttributeValue{}, |
| | | SystemConfig{}, |
| | | WarehouseMonthStats{}, |
| | | WarehouseStatsItems{}, |
| | | ) |
| | | return err |
| | | } |
| | |
| | | Contacts string `json:"contacts" gorm:"type:varchar(255);comment:联系人"` //联系人 |
| | | FileTemplateCategoryIn constvar.FileTemplateCategory `json:"fileTemplateCategoryIn" gorm:"type:int(11);comment:入库模版种类"` |
| | | FileTemplateCategoryOut constvar.FileTemplateCategory `json:"fileTemplateCategoryOut" gorm:"type:int(11);comment:出库模版种类"` |
| | | OpenMonthStats constvar.BoolType `gorm:"type:int(11);default:2;comment:是否开启月度统计" json:"openMonthStats"` //是否开启月度统计 |
| | | } |
| | | |
| | | WarehouseSearch struct { |
| | |
| | | return slf |
| | | } |
| | | |
| | | func (slf *WarehouseSearch) SetOpenMonthStats(open constvar.BoolType) *WarehouseSearch { |
| | | slf.OpenMonthStats = open |
| | | return slf |
| | | } |
| | | |
| | | func (slf *WarehouseSearch) build() *gorm.DB { |
| | | var db = slf.Orm.Table(slf.TableName()) |
| | | |
| | |
| | | db = db.Where("code in ?", slf.Codes) |
| | | } |
| | | |
| | | if slf.OpenMonthStats != 0 { |
| | | db = db.Where("open_month_stats = ?", slf.OpenMonthStats) |
| | | } |
| | | |
| | | return db |
| | | } |
| | | |
| | |
| | | } |
| | | ) |
| | | |
| | | func (slf *WarehouseStatsItems) TableName() string { |
| | | return "wms_warehouse_month_stats_items" |
| | | } |
| | | |
| | | func (slf *WarehouseMonthStats) TableName() string { |
| | | return "wms_month_stats" |
| | | return "wms_warehouse_month_stats" |
| | | } |
| | | |
| | | func NewWarehouseMonthStatsSearch() *WarehouseMonthStatsSearch { |
| | |
| | | return slf |
| | | } |
| | | |
| | | func (slf *WarehouseMonthStatsSearch) SetWarehouseId(id int) *WarehouseMonthStatsSearch { |
| | | slf.WarehouseId = id |
| | | return slf |
| | | } |
| | | |
| | | func (slf *WarehouseMonthStatsSearch) Save(record *WarehouseMonthStats) error { |
| | | var db = slf.build() |
| | | |
| | | if err := db.Omit("CreatedAt").Save(record).Error; err != nil { |
| | | return fmt.Errorf("save err: %v, record: %+v", err, record) |
| | | } |
| | | |
| | | return nil |
| | | } |
| | | |
| | | func (slf *WarehouseMonthStatsSearch) build() *gorm.DB { |
| | | var db = slf.Orm.Model(&WarehouseMonthStats{}) |
| | | |
| | |
| | | db = db.Select(slf.Fields) |
| | | } |
| | | |
| | | if slf.WarehouseId != 0 { |
| | | db = db.Where("warehouse_id = ?", slf.WarehouseId) |
| | | } |
| | | |
| | | if slf.Preload { |
| | | db = db.Preload("InputItems").Preload("OutputItems") |
| | | } |
| | | |
| | | return db |
| | | } |
| | | |
| | |
| | | Keyword string `json:"keyword"` |
| | | Date string `json:"date"` |
| | | WarehouseID int `json:"warehouseID"` |
| | | Preload bool |
| | | } |
| | | |
| | | type DoMonthStats struct { |
| | | Token string `json:"token"` |
| | | } |
| | | |
| | | type DoWarehouseMonthStats struct { |
| | | Token string `json:"token"` |
| | | } |
| | |
| | | reportFormsAPI.POST("downloadMonthStats", reportFormsController.DownloadMonthStats) //下载月度统计报表 |
| | | reportFormsAPI.POST("doMonthStats", reportFormsController.DoMonthStats) //手动跑月度统计库存报表 |
| | | |
| | | reportFormsAPI.POST("warehouseMonthStats", reportFormsController.WarehouseMonthStats) //按仓库获取月度统计报表 |
| | | reportFormsAPI.POST("warehouseMonthStats", reportFormsController.WarehouseMonthStats) //按仓库获取月度统计报表 |
| | | reportFormsAPI.POST("doWarehouseMonthStats", reportFormsController.DoWareHouseMonthStats) //手动跑按仓库获取月度统计报表 |
| | | } |
| | | |
| | | //重订货规则 |
| | |
| | | |
| | | func (slf *WarehouseMonthFormsService) BuildSearch(params request.GetMonthStats) (search *models.WarehouseMonthStatsSearch) { |
| | | search = models.NewWarehouseMonthStatsSearch().SetKeyword(params.Keyword).SetDate(params.Date) |
| | | if params.Preload { |
| | | search = search.SetPreload(true) |
| | | } |
| | | return search |
| | | } |
| | | |
| | |
| | | logx.Errorf("init task err:%v", err) |
| | | return err |
| | | } |
| | | _, err = dynamicScheduler.Every(1).Month(day).At(timeStr).Do(WarehouseMonthStats) //每月初执行一次 |
| | | if err != nil { |
| | | logx.Errorf("init task err:%v", err) |
| | | return err |
| | | } |
| | | } |
| | | if dynamicScheduler.Len() == 0 { |
| | | return |