完成气站标准资源全页管理改造

This commit is contained in:
czl231
2026-08-18 00:26:39 +08:00
parent eef791427a
commit 084eccc3ec
51 changed files with 7081 additions and 1141 deletions

View File

@@ -1,4 +1,4 @@
package gas
package gas
import (
"strings"
@@ -33,6 +33,17 @@ func ListWalletBasic(ctx *gin.Context) {
listScoped(ctx, &models.WalletBasic{}, query, "wallet_basic.created_at desc")
}
// GetWalletBasic 返回当前气站拥有的单个钱包。
func GetWalletBasic(ctx *gin.Context) {
station, ok := currentGas(ctx)
if !ok {
return
}
query := common.ActiveRecords(impl.DBService.Model(&models.WalletBasic{})).
Where("identity = ? AND owner_type = ? AND owner_id = ?", ctx.Param("identity"), "gas", station.ID)
respondScopedRecord(ctx, query, &models.WalletBasic{})
}
func listWalletChild(ctx *gin.Context, model any, table string) {
station, ok := currentGas(ctx)
if !ok {
@@ -44,19 +55,45 @@ func listWalletChild(ctx *gin.Context, model any, table string) {
listScoped(ctx, model, query, table+".created_at desc")
}
// getWalletChild 返回当前气站钱包范围内的单条子资源。
func getWalletChild(ctx *gin.Context, model any, table string) {
station, ok := currentGas(ctx)
if !ok {
return
}
query := common.ActiveRecords(impl.DBService.Model(model)).
Select(table+".*").
Joins("JOIN wallet_basic ON wallet_basic.id = "+table+".wallet_basic_id").
Where(table+".identity = ? AND wallet_basic.owner_type = ? AND wallet_basic.owner_id = ?", ctx.Param("identity"), "gas", station.ID)
respondScopedRecord(ctx, query, model)
}
func ListWalletBank(ctx *gin.Context) { listWalletChild(ctx, &models.WalletBank{}, "wallet_bank") }
func GetWalletBank(ctx *gin.Context) { getWalletChild(ctx, &models.WalletBank{}, "wallet_bank") }
func ListPaymentOrder(ctx *gin.Context) {
listWalletChild(ctx, &models.PaymentOrder{}, "payment_order")
}
func GetPaymentOrder(ctx *gin.Context) {
getWalletChild(ctx, &models.PaymentOrder{}, "payment_order")
}
func ListWalletRecord(ctx *gin.Context) {
listWalletChild(ctx, &models.WalletRecord{}, "wallet_record")
}
func GetWalletRecord(ctx *gin.Context) {
getWalletChild(ctx, &models.WalletRecord{}, "wallet_record")
}
func ListPaymentRefund(ctx *gin.Context) {
listWalletChild(ctx, &models.PaymentRefund{}, "payment_refund")
}
func GetPaymentRefund(ctx *gin.Context) {
getWalletChild(ctx, &models.PaymentRefund{}, "payment_refund")
}
func ListWalletApplyCash(ctx *gin.Context) {
listWalletChild(ctx, &models.WalletApplyCash{}, "wallet_apply_cash")
}
func GetWalletApplyCash(ctx *gin.Context) {
getWalletChild(ctx, &models.WalletApplyCash{}, "wallet_apply_cash")
}
func CreateWalletApplyCash(ctx *gin.Context) {
account, station, ok := CurrentGasAccount(ctx)
@@ -120,8 +157,26 @@ func ListFinSettlement(ctx *gin.Context) {
listScoped(ctx, &models.FinSettlement{}, query, "fin_settlement.created_at desc")
}
// GetFinSettlement 返回当前气站主体范围内的单条结算记录。
func GetFinSettlement(ctx *gin.Context) {
station, ok := currentGas(ctx)
if !ok {
return
}
query := common.ActiveRecords(impl.DBService.Model(&models.FinSettlement{})).
Where("identity = ? AND subject_type = ? AND subject_id = ?", ctx.Param("identity"), "gas", station.ID)
respondScopedRecord(ctx, query, &models.FinSettlement{})
}
// 对账表目前没有主体归属字段,气站端不得暴露平台全局渠道数据。
func ListFinReconciliation(ctx *gin.Context) {
query := common.ActiveRecords(impl.DBService.Model(&models.FinReconciliation{})).Where("1 = 0")
listScoped(ctx, &models.FinReconciliation{}, query, "fin_reconciliation.created_at desc")
}
// GetFinReconciliation 保持与列表相同的数据边界;当前气站端不暴露全局对账记录。
func GetFinReconciliation(ctx *gin.Context) {
query := common.ActiveRecords(impl.DBService.Model(&models.FinReconciliation{})).
Where("identity = ? AND 1 = 0", ctx.Param("identity"))
respondScopedRecord(ctx, query, &models.FinReconciliation{})
}

View File

@@ -163,6 +163,19 @@ func ListGasorderContractProduct(ctx *gin.Context) {
listScoped(ctx, &models.GasorderContractProduct{}, query, "gasorder_contract_product.created_at desc")
}
// GetGasorderContractProduct 返回当前气站合同范围内的单条合同气瓶。
func GetGasorderContractProduct(ctx *gin.Context) {
station, ok := currentGas(ctx)
if !ok {
return
}
query := common.ActiveRecords(impl.DBService.Model(&models.GasorderContractProduct{})).
Select("gasorder_contract_product.*").
Joins("JOIN gasorder_contract ON gasorder_contract.id = gasorder_contract_product.gasorder_contract_id").
Where("gasorder_contract_product.identity = ? AND gasorder_contract.gas_basic_id = ?", ctx.Param("identity"), station.ID)
respondScopedRecord(ctx, query, &models.GasorderContractProduct{})
}
// ListContractProductCandidate 仅返回当前气站服务用户名下可用于合同绑定的气瓶。
func ListContractProductCandidate(ctx *gin.Context) {
station, ok := currentGas(ctx)
@@ -176,6 +189,19 @@ func ListContractProductCandidate(ctx *gin.Context) {
listScoped(ctx, &models.ProductInfo{}, query, "product_info.created_at desc")
}
// GetContractProductCandidate 返回当前气站服务用户范围内的单条候选气瓶。
func GetContractProductCandidate(ctx *gin.Context) {
station, ok := currentGas(ctx)
if !ok {
return
}
query := common.ActiveRecords(impl.DBService.Model(&models.ProductInfo{})).
Select("product_info.*").
Joins("JOIN user_service_relation ON user_service_relation.user_account_id = product_info.user_account_id AND user_service_relation.status <> ?", common.StatusArchived).
Where("product_info.identity = ? AND user_service_relation.gas_basic_id = ?", ctx.Param("identity"), station.ID)
respondScopedRecord(ctx, query, &models.ProductInfo{})
}
func ListGasorderContractRevision(ctx *gin.Context) {
station, ok := currentGas(ctx)
if !ok {
@@ -187,6 +213,19 @@ func ListGasorderContractRevision(ctx *gin.Context) {
listScoped(ctx, &models.GasorderContractRevision{}, query, "gasorder_contract_revision.created_at desc")
}
// GetGasorderContractRevision 返回当前气站合同范围内的单条修订记录。
func GetGasorderContractRevision(ctx *gin.Context) {
station, ok := currentGas(ctx)
if !ok {
return
}
query := common.ActiveRecords(impl.DBService.Model(&models.GasorderContractRevision{})).
Select("gasorder_contract_revision.*").
Joins("JOIN gasorder_contract ON gasorder_contract.id = gasorder_contract_revision.gasorder_contract_id").
Where("gasorder_contract_revision.identity = ? AND gasorder_contract.gas_basic_id = ?", ctx.Param("identity"), station.ID)
respondScopedRecord(ctx, query, &models.GasorderContractRevision{})
}
func ListGasorderBasic(ctx *gin.Context) {
station, ok := currentGas(ctx)
if !ok {

View File

@@ -72,9 +72,12 @@ func registerGasBusinessRoutes(group *gin.RouterGroup) {
contractProduct := group.Group("/gasorder_contract_product")
contractProduct.GET("", gaslogic.ListGasorderContractProduct)
contractProduct.POST("", gaslogic.BindGasorderContractProduct)
contractProduct.GET("/:identity", gaslogic.GetGasorderContractProduct)
contractProduct.POST("/:identity/unbind", gaslogic.UnbindGasorderContractProduct)
group.GET("/gasorder_contract_revision", gaslogic.ListGasorderContractRevision)
group.GET("/gasorder_contract_revision/:identity", gaslogic.GetGasorderContractRevision)
group.GET("/product_info", gaslogic.ListContractProductCandidate)
group.GET("/product_info/:identity", gaslogic.GetContractProductCandidate)
order := group.Group("/gasorder_basic")
order.GET("", gaslogic.ListGasorderBasic)
@@ -88,14 +91,22 @@ func registerGasBusinessRoutes(group *gin.RouterGroup) {
order.POST("/:identity/cancel", gaslogic.GasorderCancel)
group.GET("/wallet_basic", gaslogic.ListWalletBasic)
group.GET("/wallet_basic/:identity", gaslogic.GetWalletBasic)
group.GET("/wallet_bank", gaslogic.ListWalletBank)
group.GET("/wallet_bank/:identity", gaslogic.GetWalletBank)
group.GET("/payment_order", gaslogic.ListPaymentOrder)
group.GET("/payment_order/:identity", gaslogic.GetPaymentOrder)
group.GET("/wallet_record", gaslogic.ListWalletRecord)
group.GET("/wallet_record/:identity", gaslogic.GetWalletRecord)
group.GET("/payment_refund", gaslogic.ListPaymentRefund)
group.GET("/payment_refund/:identity", gaslogic.GetPaymentRefund)
group.GET("/wallet_apply_cash", gaslogic.ListWalletApplyCash)
group.GET("/wallet_apply_cash/:identity", gaslogic.GetWalletApplyCash)
group.POST("/wallet_apply_cash", gaslogic.CreateWalletApplyCash)
group.GET("/fin_settlement", gaslogic.ListFinSettlement)
group.GET("/fin_settlement/:identity", gaslogic.GetFinSettlement)
group.GET("/fin_reconciliation", gaslogic.ListFinReconciliation)
group.GET("/fin_reconciliation/:identity", gaslogic.GetFinReconciliation)
ticket := group.Group("/cs_ticket")
ticket.GET("", gaslogic.ListTicket)

View File

@@ -52,3 +52,32 @@ func TestGasOrderRoutesDoNotExposeDownstreamActions(t *testing.T) {
}
}
}
// TestGasReadonlyDetailRoutes 验证所有标准只读资源都支持独立详情页直达。
func TestGasReadonlyDetailRoutes(t *testing.T) {
gin.SetMode(gin.TestMode)
engine := gin.New()
RegisterGas("heqi", engine)
routes := map[string]bool{}
for _, route := range engine.Routes() {
routes[route.Method+" "+route.Path] = true
}
for _, path := range []string{
"/gasorder_contract_product/:identity",
"/gasorder_contract_revision/:identity",
"/product_info/:identity",
"/wallet_basic/:identity",
"/wallet_bank/:identity",
"/payment_order/:identity",
"/wallet_record/:identity",
"/payment_refund/:identity",
"/wallet_apply_cash/:identity",
"/fin_settlement/:identity",
"/fin_reconciliation/:identity",
} {
fullPath := "GET /heqi/gas/v1" + path
if !routes[fullPath] {
t.Fatalf("missing gas detail route %s", fullPath)
}
}
}