新增配送点资料只读卡片
This commit is contained in:
@@ -3,6 +3,7 @@ package delivery
|
||||
import (
|
||||
"net/url"
|
||||
"reflect"
|
||||
"time"
|
||||
|
||||
"git.apinb.com/bsm-sdk/core/infra"
|
||||
"git.apinb.com/heqiapp/platforms/backend/api/internal/config"
|
||||
@@ -13,6 +14,21 @@ import (
|
||||
"gorm.io/gorm"
|
||||
)
|
||||
|
||||
// deliveryProfileView 表示配送点管理员可查看的本点只读资料。
|
||||
type deliveryProfileView struct {
|
||||
ID uint64 `json:"id"`
|
||||
Identity string `json:"identity"`
|
||||
DeliveryCode string `json:"delivery_code"`
|
||||
Name string `json:"name"`
|
||||
Principal string `json:"principal"`
|
||||
Address string `json:"address"`
|
||||
GasBasicIdentity string `json:"gas_basic_identity"`
|
||||
GasBasicName string `json:"gas_basic_name"`
|
||||
Status int `json:"status"`
|
||||
CreatedAt time.Time `json:"created_at"`
|
||||
UpdatedAt time.Time `json:"updated_at"`
|
||||
}
|
||||
|
||||
func currentScope(ctx *gin.Context) (models.DeliveryBasic, models.GasBasic, bool) {
|
||||
_, point, station, ok := CurrentDeliveryAccount(ctx)
|
||||
return point, station, ok
|
||||
@@ -40,12 +56,33 @@ func InvitationQRCode(ctx *gin.Context) {
|
||||
infra.Response.Success(ctx, gin.H{"register_url": registerURL.String()})
|
||||
}
|
||||
|
||||
// ListProfile 返回 JWT 数据范围内唯一配送点的只读资料。
|
||||
func ListProfile(ctx *gin.Context) {
|
||||
_, point, _, ok := CurrentDeliveryAccount(ctx)
|
||||
_, point, station, ok := CurrentDeliveryAccount(ctx)
|
||||
if !ok {
|
||||
return
|
||||
}
|
||||
respondList(ctx, []models.DeliveryBasic{point}, 1)
|
||||
infra.Response.Success(ctx, gin.H{
|
||||
"total": 1,
|
||||
"list": []deliveryProfileView{buildDeliveryProfileView(point, station)},
|
||||
})
|
||||
}
|
||||
|
||||
// buildDeliveryProfileView 组合配送点与所属气站的公开展示字段。
|
||||
func buildDeliveryProfileView(point models.DeliveryBasic, station models.GasBasic) deliveryProfileView {
|
||||
return deliveryProfileView{
|
||||
ID: point.ID,
|
||||
Identity: point.Identity,
|
||||
DeliveryCode: point.DeliveryCode,
|
||||
Name: point.Name,
|
||||
Principal: point.Principal,
|
||||
Address: point.Address,
|
||||
GasBasicIdentity: station.Identity,
|
||||
GasBasicName: station.Name,
|
||||
Status: point.Status,
|
||||
CreatedAt: point.CreatedAt,
|
||||
UpdatedAt: point.UpdatedAt,
|
||||
}
|
||||
}
|
||||
|
||||
func respondList(ctx *gin.Context, list any, total int64) {
|
||||
|
||||
33
backend/api/internal/logic/delivery/profile_test.go
Normal file
33
backend/api/internal/logic/delivery/profile_test.go
Normal file
@@ -0,0 +1,33 @@
|
||||
// 功能描述:验证配送点资料响应仅暴露本点只读展示所需字段。版本:v1.0.0。
|
||||
package delivery
|
||||
|
||||
import (
|
||||
"testing"
|
||||
"time"
|
||||
|
||||
"git.apinb.com/heqiapp/platforms/backend/api/internal/models"
|
||||
)
|
||||
|
||||
// TestBuildDeliveryProfileView 验证资料响应包含所属气站名称且保持公开标识。
|
||||
func TestBuildDeliveryProfileView(t *testing.T) {
|
||||
now := time.Date(2026, time.August, 22, 10, 30, 0, 0, time.UTC)
|
||||
point := models.DeliveryBasic{
|
||||
Entity: models.Entity{ID: 19, Identity: "delivery-identity", Status: 1, CreatedAt: now, UpdatedAt: now},
|
||||
DeliveryCode: "D-001",
|
||||
Name: "测试配送点",
|
||||
Principal: "负责人",
|
||||
Address: "测试地址",
|
||||
}
|
||||
station := models.GasBasic{
|
||||
Entity: models.Entity{ID: 7, Identity: "gas-identity"},
|
||||
Name: "测试气站",
|
||||
}
|
||||
|
||||
view := buildDeliveryProfileView(point, station)
|
||||
if view.ID != point.ID || view.Identity != point.Identity || view.GasBasicIdentity != station.Identity {
|
||||
t.Fatalf("资料标识映射错误:%#v", view)
|
||||
}
|
||||
if view.GasBasicName != station.Name || view.Name != point.Name || view.Status != point.Status {
|
||||
t.Fatalf("资料展示字段映射错误:%#v", view)
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user