两个月度统计下载如果下载的是当前月,取实时数据 & 修复若干bug
| | |
| | | return |
| | | } |
| | | |
| | | now := time.Now().Local() |
| | | today := now.Day() |
| | | nowMonth := now.Format("2006-01") |
| | | nowMonth := time.Now().Local().Format("2006-01") |
| | | if nowMonth == params.Date { //实时查询 |
| | | result, err = MonthStatsReplaceRealtimeOperation(result, params.Date) |
| | | if err != nil { |
| | | util.ResponseFormat(c, code.InternalError, "查询失败") |
| | | return |
| | | } |
| | | } |
| | | |
| | | day, dateStr, _ := service.NewSystemConfigService().GetInventoryCutOffPoint() |
| | | if nowMonth == params.Date && today < day || today == day && now.Format("15:04") < dateStr { //本月未至结算时间点 |
| | | util.ResponseFormatList(c, code.Success, result, int(total)) |
| | | } |
| | | |
| | | func MonthStatsReplaceRealtimeOperation(result []*models.MonthStats, date string) ([]*models.MonthStats, error) { |
| | | productIds := make([]string, 0, len(result)) |
| | | for _, item := range result { |
| | | productIds = append(productIds, item.ProductId) |
| | | } |
| | | statsRecords, err := service.GetCurrentStats(params.Date, productIds) |
| | | statsRecords, err := service.GetCurrentStats(date, productIds) |
| | | if err != nil { |
| | | util.ResponseFormat(c, code.InternalError, "内部错误") |
| | | return |
| | | return nil, err |
| | | } |
| | | statsMap := models.MonthStatsMap(statsRecords) |
| | | for k, v := range result { |
| | |
| | | result[k].InputAmount = statsMap[v.ProductId].InputAmount |
| | | result[k].InputMoreUnits = statsMap[v.ProductId].InputMoreUnits |
| | | } |
| | | |
| | | } |
| | | |
| | | util.ResponseFormatList(c, code.Success, result, int(total)) |
| | | return result, nil |
| | | } |
| | | |
| | | // DownloadMonthStats |
| | |
| | | util.ResponseFormat(c, code.InternalError, "查询失败") |
| | | return |
| | | } |
| | | |
| | | nowMonth := time.Now().Local().Format("2006-01") |
| | | if nowMonth == params.Date { //实时查询 |
| | | list, err = MonthStatsReplaceRealtimeOperation(list, params.Date) |
| | | if err != nil { |
| | | util.ResponseFormat(c, code.InternalError, "查询失败") |
| | | return |
| | | } |
| | | } |
| | | |
| | | filename, err := monthFormsService.Export(list) |
| | | if err != nil { |
| | | logx.Errorf("DownloadMonthStats Export err:%v", err) |
| | |
| | | |
| | | nowMonth := time.Now().Local().Format("2006-01") |
| | | if nowMonth == params.Date { |
| | | productIds := make([]string, 0, len(result)) |
| | | for _, item := range result { |
| | | productIds = append(productIds, item.ProductId) |
| | | } |
| | | statsRecords, err := service.GetCurrentWarehouseStats(params.Date, params.WarehouseID, productIds, true) |
| | | result, err = WarehouseMonthStatsReplaceRealtimeOperation(result, params.Date, params.WarehouseID) |
| | | if err != nil { |
| | | util.ResponseFormat(c, code.InternalError, "内部错误") |
| | | util.ResponseFormat(c, code.InternalError, "查询失败") |
| | | return |
| | | } |
| | | statsMap := models.WarehouseMonthStatsMap(statsRecords) |
| | | for k, v := range result { |
| | | if statsMap[v.ProductId] == nil { |
| | | continue |
| | | } |
| | | |
| | | result[k].OutputAmount = statsMap[v.ProductId].OutputAmount |
| | | result[k].EndAmount = statsMap[v.ProductId].EndAmount |
| | | result[k].InputAmount = statsMap[v.ProductId].InputAmount |
| | | result[k].InputItems = statsMap[v.ProductId].InputItems |
| | | result[k].OutputItems = statsMap[v.ProductId].OutputItems |
| | | } |
| | | |
| | | } |
| | | |
| | | util.ResponseFormatList(c, code.Success, result, int(total)) |
| | |
| | | util.ResponseFormat(c, code.InternalError, "查询失败") |
| | | return |
| | | } |
| | | |
| | | nowMonth := time.Now().Local().Format("2006-01") |
| | | if nowMonth == params.Date { |
| | | list, err = WarehouseMonthStatsReplaceRealtimeOperation(list, params.Date, params.WarehouseID) |
| | | if err != nil { |
| | | util.ResponseFormat(c, code.InternalError, "查询失败") |
| | | return |
| | | } |
| | | } |
| | | |
| | | filename, err := monthFormsService.Export(list) |
| | | if err != nil { |
| | | logx.Errorf("DownloadMonthStats Export err:%v", err) |
| | |
| | | c.File(filename) |
| | | defer os.Remove(filename) |
| | | } |
| | | |
| | | func WarehouseMonthStatsReplaceRealtimeOperation(list []*models.WarehouseMonthStats, date string, warehouseId int) (newList []*models.WarehouseMonthStats, err error) { |
| | | productIds := make([]string, 0, len(list)) |
| | | for _, item := range list { |
| | | productIds = append(productIds, item.ProductId) |
| | | } |
| | | statsRecords, err := service.GetCurrentWarehouseStats(date, warehouseId, productIds, true) |
| | | if err != nil { |
| | | return nil, err |
| | | } |
| | | statsMap := models.WarehouseMonthStatsMap(statsRecords) |
| | | for k, v := range list { |
| | | if statsMap[v.ProductId] == nil { |
| | | continue |
| | | } |
| | | |
| | | list[k].OutputAmount = statsMap[v.ProductId].OutputAmount |
| | | list[k].EndAmount = statsMap[v.ProductId].EndAmount |
| | | list[k].InputAmount = statsMap[v.ProductId].InputAmount |
| | | list[k].InputItems = statsMap[v.ProductId].InputItems |
| | | list[k].OutputItems = statsMap[v.ProductId].OutputItems |
| | | } |
| | | return list, nil |
| | | } |
| | |
| | | f.SetCellValue("Sheet1", "E"+column, v.Unit) |
| | | f.SetCellValue("Sheet1", "F"+column, v.SalePrice) |
| | | |
| | | slf.FillDealerTypeToExcel(v.InputItems, inputStart, i+3, inputTypes, f) |
| | | slf.FillDealerTypeToExcel(v.OutputItems, outputStart, i+3, outputTypes, f) |
| | | slf.FillDealerTypeToExcel(v.InputItems, inputStart, i+3, inputTypes, f, constvar.InputTotalHeader) |
| | | slf.FillDealerTypeToExcel(v.OutputItems, outputStart, i+3, outputTypes, f, constvar.OutPutTotalHeader) |
| | | } |
| | | |
| | | fileName := fmt.Sprintf("%s月度统计报表%s.xlsx", "仓库", time.Now().Format("2006-01-02-1504")) |
| | |
| | | return sum |
| | | } |
| | | |
| | | func (slf *WarehouseMonthFormsService) FillDealerTypeToExcel(items []*models.WarehouseStatsItems, startIndex int, column int, dealerTypes []string, f *excelize.File) { |
| | | func (slf *WarehouseMonthFormsService) FillDealerTypeToExcel(items []*models.WarehouseStatsItems, startIndex int, column int, dealerTypes []string, f *excelize.File, totalHeader string) { |
| | | columnStr := strconv.Itoa(column) |
| | | sum := slf.SumItems(items) |
| | | detailMap := models.WarehouseStatsItemMap(items) |
| | |
| | | var amount decimal.Decimal |
| | | if detailMap[dealerTypes[i]] != nil { |
| | | amount = detailMap[dealerTypes[i]].Amount |
| | | } else if dealerTypes[i] == constvar.InputTotalHeader { |
| | | } else if dealerTypes[i] == totalHeader { |
| | | amount = sum |
| | | } |
| | | f.SetCellValue("Sheet1", getColumnAlphabet(startIndex+i)+columnStr, amount) |