feat(t225): freeze Go ERP protocol contract

This commit is contained in:
QiuSW
2026-07-29 09:21:32 +08:00
parent 11e480773a
commit c2f340d067
13 changed files with 836 additions and 31 deletions
@@ -13,7 +13,6 @@ import (
"unicode/utf8"
"cmroubao/backend-api/internal/domain"
"cmroubao/backend-api/internal/platform/erpconnector"
)
const (
@@ -350,11 +349,11 @@ func (service *FreightService) queryCreatedRange(
}
start, err := parseFreightDate(run.CreatedFrom, location)
if err != nil {
return domain.FreightSourceBatch{}, erpconnector.ErrProtocol
return domain.FreightSourceBatch{}, domain.ErrFreightSourceProtocol
}
end, err := parseFreightDate(run.CreatedTo, location)
if err != nil || end.Before(start) {
return domain.FreightSourceBatch{}, erpconnector.ErrProtocol
return domain.FreightSourceBatch{}, domain.ErrFreightSourceProtocol
}
orders := make([]domain.FreightSourceOrder, 0)
seen := make(map[string]domain.FreightSourceOrder)
@@ -379,20 +378,20 @@ func (service *FreightService) queryCreatedRange(
batch.Query.CreatedTo == nil ||
*batch.Query.CreatedFrom != fromValue ||
*batch.Query.CreatedTo != toValue {
return domain.FreightSourceBatch{}, erpconnector.ErrProtocol
return domain.FreightSourceBatch{}, domain.ErrFreightSourceProtocol
}
for _, order := range batch.Orders {
existing, exists := seen[order.ExternalStockID]
if exists {
if hashJSON(existing) != hashJSON(order) {
return domain.FreightSourceBatch{}, erpconnector.ErrProtocol
return domain.FreightSourceBatch{}, domain.ErrFreightSourceProtocol
}
continue
}
seen[order.ExternalStockID] = order
orders = append(orders, order)
if len(orders) > maxFreightOrdersPerSync {
return domain.FreightSourceBatch{}, erpconnector.ErrProtocol
return domain.FreightSourceBatch{}, domain.ErrFreightSourceProtocol
}
}
windowStart = windowEnd.AddDate(0, 0, 1)
@@ -672,13 +671,13 @@ func daysInclusive(start, end time.Time) int {
func freightSourceErrorCode(err error) string {
switch {
case errors.Is(err, erpconnector.ErrNotConfigured):
case errors.Is(err, domain.ErrFreightSourceNotConfigured):
return "ERP_CONNECTOR_NOT_CONFIGURED"
case errors.Is(err, erpconnector.ErrSessionRequired):
case errors.Is(err, domain.ErrFreightSourceSessionNeeded):
return "ERP_SESSION_REQUIRED"
case errors.Is(err, erpconnector.ErrNotFound):
case errors.Is(err, domain.ErrFreightSourceNotFound):
return "ERP_FREIGHT_NOT_FOUND"
case errors.Is(err, erpconnector.ErrProtocol):
case errors.Is(err, domain.ErrFreightSourceProtocol):
return "ERP_RESPONSE_INVALID"
default:
return "ERP_CONNECTOR_UNAVAILABLE"