强化配送订单合同调度约束
This commit is contained in:
@@ -1,6 +1,9 @@
|
||||
// 功能描述:提供平台配送点资源管理与受控候选筛选。
|
||||
// 版本:v1.1.0
|
||||
package delivery
|
||||
|
||||
import (
|
||||
"strconv"
|
||||
"strings"
|
||||
|
||||
"git.apinb.com/bsm-sdk/core/errcode"
|
||||
@@ -11,6 +14,19 @@ import (
|
||||
"github.com/gin-gonic/gin"
|
||||
)
|
||||
|
||||
// parseDeliveryStatusFilter 解析可选的配送点通用状态筛选,拒绝归档和未知状态。
|
||||
func parseDeliveryStatusFilter(value string) (*int, bool) {
|
||||
value = strings.TrimSpace(value)
|
||||
if value == "" {
|
||||
return nil, true
|
||||
}
|
||||
status, err := strconv.Atoi(value)
|
||||
if err != nil || !common.IsGenericRecordStatus(status) || status == common.StatusArchived {
|
||||
return nil, false
|
||||
}
|
||||
return &status, true
|
||||
}
|
||||
|
||||
// ListDeliveryBasic 查询配送点分页列表。
|
||||
func ListDeliveryBasic(ctx *gin.Context) {
|
||||
page, size := common.PageSize(ctx)
|
||||
@@ -22,6 +38,11 @@ func ListDeliveryBasic(ctx *gin.Context) {
|
||||
infra.Response.Error(ctx, errcode.ErrInvalidArgument)
|
||||
return
|
||||
}
|
||||
status, ok := parseDeliveryStatusFilter(ctx.Query("status"))
|
||||
if !ok {
|
||||
infra.Response.Error(ctx, errcode.ErrInvalidArgument)
|
||||
return
|
||||
}
|
||||
var list []models.DeliveryBasic
|
||||
var total int64
|
||||
query := common.ApplyKeywordFilter(ctx, common.ActiveRecords(impl.DBService.Model(&models.DeliveryBasic{})), &models.DeliveryBasic{})
|
||||
@@ -32,6 +53,9 @@ func ListDeliveryBasic(ctx *gin.Context) {
|
||||
common.StatusArchived,
|
||||
)
|
||||
}
|
||||
if status != nil {
|
||||
query = query.Where("delivery_basic.status = ?", *status)
|
||||
}
|
||||
if err := query.Count(&total).Error; err != nil {
|
||||
infra.Response.Error(ctx, err)
|
||||
return
|
||||
|
||||
@@ -1,3 +1,5 @@
|
||||
// 功能描述:验证平台配送点展示与候选筛选规则。
|
||||
// 版本:v1.1.0
|
||||
package delivery
|
||||
|
||||
import (
|
||||
@@ -37,6 +39,21 @@ func TestRestoreDeliveryBasicAddress(t *testing.T) {
|
||||
}
|
||||
}
|
||||
|
||||
// TestParseDeliveryStatusFilter 验证分配候选只接受明确的非归档通用状态。
|
||||
func TestParseDeliveryStatusFilter(t *testing.T) {
|
||||
if status, ok := parseDeliveryStatusFilter("1"); !ok || status == nil || *status != 1 {
|
||||
t.Fatalf("启用状态筛选解析失败:status=%v ok=%v", status, ok)
|
||||
}
|
||||
if status, ok := parseDeliveryStatusFilter(""); !ok || status != nil {
|
||||
t.Fatalf("空状态筛选应保持兼容:status=%v ok=%v", status, ok)
|
||||
}
|
||||
for _, value := range []string{"3", "enabled", "99"} {
|
||||
if _, ok := parseDeliveryStatusFilter(value); ok {
|
||||
t.Fatalf("非法配送点状态筛选被接受:%q", value)
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
// TestNewDeliveryAccountUsesAdminRole 验证平台创建配送点账号时固定后台唯一支持的角色编码。
|
||||
func TestNewDeliveryAccountUsesAdminRole(t *testing.T) {
|
||||
account := newDeliveryAccount(9, accountRequest{Username: "delivery-admin", DisplayName: "配送点管理员"}, "password-hash")
|
||||
|
||||
Reference in New Issue
Block a user