From 73b6baf6af3d88cdcb0e2df7932a9bd96b0b85c5 Mon Sep 17 00:00:00 2001 From: zhangqian <zhangqian@123.com> Date: 星期一, 01 七月 2024 22:32:34 +0800 Subject: [PATCH] 月度统计出入库按类型汇总报表定时任务和手动跑任务接口 --- service/input_history_search.go | 42 +++++++++++++++++++++++++++++++++++++++--- 1 files changed, 39 insertions(+), 3 deletions(-) diff --git a/service/input_history_search.go b/service/input_history_search.go index 45803c5..c2d96bb 100644 --- a/service/input_history_search.go +++ b/service/input_history_search.go @@ -1,9 +1,12 @@ package service import ( + "fmt" "github.com/spf13/cast" "gorm.io/gorm" + "regexp" "strconv" + "time" "wms/constvar" "wms/models" "wms/pkg/blevex" @@ -20,7 +23,7 @@ OperationTypeName string `json:"operationTypeName,omitempty"` //涓氬姟鍚嶇О FromLocation string `json:"fromLocation,omitempty"` //婧愪綅缃悕绉� ToLocation string `json:"toLocation,omitempty"` //鐩爣浣嶇疆鍚嶇О - Date string `json:"date,omitempty"` //鏃ユ湡 + Date time.Time `json:"date,omitempty"` //鏃ユ湡 Company string `json:"company,omitempty"` // 渚涘簲鍟�/瀹㈡埛 Carrier string `json:"carrier,omitempty"` //鎵胯繍鍟嗗悕绉� WaybillNumber string `json:"waybillNumber"` //杩愬崟鍙� @@ -68,11 +71,44 @@ } return } +func parseDateString(input string) (time.Time, error) { + // 瀹氫箟姝e垯琛ㄨ揪寮� + regex := regexp.MustCompile(`(\d{4})-(\d{2})-(\d{2})|(\d{4})/(\d{2})/(\d{2})|(\d{8})`) + + // 鍖归厤瀛楃涓� + matches := regex.FindStringSubmatch(input) + if len(matches) == 0 { + return time.Time{}, fmt.Errorf("Invalid date format") + } + // 鎻愬彇骞存湀鏃� + year := matches[1] + matches[4] + matches[7] + month := matches[2] + matches[5] + day := matches[3] + matches[6] + + // 鏋勫缓鏃堕棿瀵硅薄 + parsedTime, err := time.ParseInLocation("20060102", fmt.Sprintf("%s%s%s", year, month, day), time.Local) + if err != nil { + return time.Time{}, err + } + + return parsedTime, nil +} func SearchHistoryReport(keyword string, operationType constvar.BaseOperationType, page, pageSize int) (recordIds []int, total uint64, err error) { var ids []string from := (page - 1) * pageSize - ids, total, err = blevex.ComplexSearch(HistoryReportIndexName, keyword, map[string]interface{}{"baseOperationType": operationType}, from, pageSize) + t, err := time.ParseInLocation("20060102", keyword, time.Local) + //t, err := parseDateString(keyword) + m := make(map[string]interface{}) + if operationType > 0 { + m["baseOperationType"] = operationType + } + if err != nil || t.IsZero() { + ids, total, err = blevex.ComplexSearch(HistoryReportIndexName, keyword, m, from, pageSize) + } else { + ids, total, err = blevex.TimeSearch(HistoryReportIndexName, t, m, from, pageSize) + } + if err != nil { return } @@ -94,7 +130,7 @@ return } - report.Date = record.UpdatedAt.Format("2006-01-02") + report.Date = record.UpdatedAt report.Carrier = operation.LogisticCompany.Name report.Company = operation.CompanyName report.WaybillNumber = operation.WaybillNumber -- Gitblit v1.8.0