| | |
| | | package service |
| | | |
| | | import ( |
| | | "fmt" |
| | | "github.com/spf13/cast" |
| | | "gorm.io/gorm" |
| | | "regexp" |
| | | "strconv" |
| | | "time" |
| | | "wms/constvar" |
| | | "wms/models" |
| | | "wms/pkg/blevex" |
| | |
| | | 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"` //运单号 |
| | |
| | | } |
| | | return |
| | | } |
| | | func parseDateString(input string) (time.Time, error) { |
| | | // 定义正则表达式 |
| | | 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 |
| | | } |
| | |
| | | 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 |