From 518b81edee9001cd6455ec5c212851d901471e76 Mon Sep 17 00:00:00 2001 From: jiangshuai <291802688@qq.com> Date: 星期二, 26 十二月 2023 09:48:50 +0800 Subject: [PATCH] Merge branch 'master' of http://192.168.5.5:10010/r/aps/WMS --- service/input_history_search.go | 37 ++++++++++++++++++++++++++++++++++--- 1 files changed, 34 insertions(+), 3 deletions(-) diff --git a/service/input_history_search.go b/service/input_history_search.go index 45803c5..e81a10d 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,39 @@ } 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 := parseDateString(keyword) + if err != nil && t.IsZero() { + ids, total, err = blevex.ComplexSearch(HistoryReportIndexName, keyword, map[string]interface{}{"baseOperationType": operationType}, from, pageSize) + } else { + ids, total, err = blevex.TimeSearch(HistoryReportIndexName, t, map[string]interface{}{"baseOperationType": operationType}, from, pageSize) + } + if err != nil { return } @@ -94,7 +125,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