修复库存监控提前停止并发布0.2.0
This commit is contained in:
@@ -68,7 +68,7 @@ func (a *App) startXiaodianSeckill(req types.FixedSeckillRequest, message string
|
||||
if !a.scheduler.TryStartRun() {
|
||||
return types.MessageResult{Error: "抢购任务正在运行,请勿重复提交"}
|
||||
}
|
||||
go a.scheduler.RunXiaodian(utils.CloneStringMap(req.AccountProducts), req.Attempts, req.DelayMs)
|
||||
go a.scheduler.RunXiaodian(utils.CloneStringMap(req.AccountProducts), req.Attempts, req.DelayMs, req.ReportSessionID)
|
||||
return types.MessageResult{Success: true, Msg: message}
|
||||
}
|
||||
|
||||
|
||||
@@ -13,6 +13,7 @@ import (
|
||||
"github.com/wailsapp/wails/v2/pkg/runtime"
|
||||
"github.com/xuri/excelize/v2"
|
||||
|
||||
"douyu_go/internal/constants"
|
||||
"douyu_go/internal/logger"
|
||||
"douyu_go/internal/types"
|
||||
)
|
||||
@@ -274,7 +275,7 @@ func xiaodianDetailsHeaders() []string {
|
||||
|
||||
func xiaodianSummaryRow(sequence int, report types.XiaodianRunReport, item xiaodianReportExportData) []interface{} {
|
||||
account := item.ReportAccount
|
||||
matched := selectedXiaodianRecord(item)
|
||||
matched := selectedXiaodianRecord(item, report)
|
||||
remarks := reportExportRemarks(item)
|
||||
return []interface{}{
|
||||
sequence,
|
||||
@@ -288,7 +289,7 @@ func xiaodianSummaryRow(sequence int, report types.XiaodianRunReport, item xiaod
|
||||
reportAssetValue(item, false),
|
||||
exportText(account.Status),
|
||||
exportText(account.FailureReason),
|
||||
exportText(selectedRecordVerification(item)),
|
||||
exportText(selectedRecordVerification(item, report)),
|
||||
exportText(selectedRecordStatus(item, matched)),
|
||||
account.Attempts,
|
||||
exportText(remarks),
|
||||
@@ -384,25 +385,58 @@ func reportAssetValue(item xiaodianReportExportData, coupons bool) interface{} {
|
||||
return item.Assets.Fragments
|
||||
}
|
||||
|
||||
func selectedXiaodianRecord(item xiaodianReportExportData) *types.XiaodianExchangeRecord {
|
||||
func selectedXiaodianRecord(item xiaodianReportExportData, report types.XiaodianRunReport) *types.XiaodianExchangeRecord {
|
||||
for index := range item.Records {
|
||||
if item.Records[index].CommodityID == item.ReportAccount.ProductID {
|
||||
return &item.Records[index]
|
||||
record := &item.Records[index]
|
||||
if record.CommodityID == item.ReportAccount.ProductID && recordBelongsToReport(*record, report) {
|
||||
return record
|
||||
}
|
||||
}
|
||||
return nil
|
||||
}
|
||||
|
||||
func selectedRecordVerification(item xiaodianReportExportData) string {
|
||||
func selectedRecordVerification(item xiaodianReportExportData, report types.XiaodianRunReport) string {
|
||||
if item.RecordError != "" {
|
||||
return "查询失败"
|
||||
}
|
||||
if selectedXiaodianRecord(item) != nil {
|
||||
if selectedXiaodianRecord(item, report) != nil {
|
||||
return "已兑换"
|
||||
}
|
||||
return "未发现订单"
|
||||
}
|
||||
|
||||
func recordBelongsToReport(record types.XiaodianExchangeRecord, report types.XiaodianRunReport) bool {
|
||||
if report.StartedAt.IsZero() {
|
||||
return false
|
||||
}
|
||||
value := strings.TrimSpace(record.BuyTime)
|
||||
if value == "" {
|
||||
value = strings.TrimSpace(record.PayTime)
|
||||
}
|
||||
recordedAt, ok := parseXiaodianRecordTime(value)
|
||||
return ok && !recordedAt.Before(report.StartedAt)
|
||||
}
|
||||
|
||||
func parseXiaodianRecordTime(value string) (time.Time, bool) {
|
||||
for _, layout := range []string{
|
||||
"2006-01-02 15:04:05.999999999",
|
||||
"2006-01-02 15:04:05",
|
||||
time.RFC3339Nano,
|
||||
time.RFC3339,
|
||||
} {
|
||||
if strings.Contains(layout, "Z07") {
|
||||
if parsed, err := time.Parse(layout, value); err == nil {
|
||||
return parsed, true
|
||||
}
|
||||
continue
|
||||
}
|
||||
if parsed, err := time.ParseInLocation(layout, value, constants.CST); err == nil {
|
||||
return parsed, true
|
||||
}
|
||||
}
|
||||
return time.Time{}, false
|
||||
}
|
||||
|
||||
func selectedRecordStatus(item xiaodianReportExportData, record *types.XiaodianExchangeRecord) string {
|
||||
if item.RecordError != "" {
|
||||
return "查询失败"
|
||||
|
||||
@@ -95,3 +95,20 @@ func TestSelectedRecordStatus(t *testing.T) {
|
||||
t.Fatalf("orderStatusText(empty) = %q", got)
|
||||
}
|
||||
}
|
||||
|
||||
func TestSelectedXiaodianRecordIgnoresHistoryBeforeReport(t *testing.T) {
|
||||
report := types.XiaodianRunReport{
|
||||
StartedAt: time.Date(2026, 8, 9, 15, 0, 0, 0, time.Local),
|
||||
}
|
||||
item := xiaodianReportExportData{
|
||||
ReportAccount: types.XiaodianRunReportAccount{ProductID: "goods-1"},
|
||||
Records: []types.XiaodianExchangeRecord{
|
||||
{CommodityID: "goods-1", BuyTime: "2026-08-09 14:59:59", Status: "3"},
|
||||
{CommodityID: "goods-1", BuyTime: "2026-08-09 15:00:01", Status: "3"},
|
||||
},
|
||||
}
|
||||
matched := selectedXiaodianRecord(item, report)
|
||||
if matched == nil || matched.BuyTime != "2026-08-09 15:00:01" {
|
||||
t.Fatalf("历史订单不应被选中: %+v", matched)
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user