74 lines
4.2 KiB
Go
74 lines
4.2 KiB
Go
|
|
// Package platform 定义平台总后台各资源的可见字段搜索策略。
|
|||
|
|
// 版本:v1.0.0
|
|||
|
|
package platform
|
|||
|
|
|
|||
|
|
import (
|
|||
|
|
"git.apinb.com/heqiapp/platforms/backend/api/internal/logic/common"
|
|||
|
|
"git.apinb.com/heqiapp/platforms/backend/api/internal/models"
|
|||
|
|
)
|
|||
|
|
|
|||
|
|
type resourceSearchDefinition struct {
|
|||
|
|
name string
|
|||
|
|
model any
|
|||
|
|
fields []common.KeywordSearchField
|
|||
|
|
}
|
|||
|
|
|
|||
|
|
var resourceSearchDefinitions = []resourceSearchDefinition{
|
|||
|
|
searchDefinition("gas_basic", &models.GasBasic{}, text("code"), text("name")),
|
|||
|
|
searchDefinition("gas_account", &models.GasAccount{}, text("username"), text("display_name"), enum("role_code", value("admin", "气站管理员"))),
|
|||
|
|
searchDefinition("delivery_basic", &models.DeliveryBasic{}, text("delivery_code"), text("name")),
|
|||
|
|
searchDefinition("delivery_account", &models.DeliveryAccount{}, text("username"), text("display_name"), enum("role_code", value("admin", "配送点管理员"))),
|
|||
|
|
searchDefinition("staff_account", &models.StaffAccount{}, text("username"), enum("role_code", value("installer", "安装人员"), value("delivery", "配送人员"), value("operations", "运维人员"))),
|
|||
|
|
searchDefinition("staff_credential", &models.StaffCredential{}, text("credential_type")),
|
|||
|
|
searchDefinition("user_account", &models.UserAccount{}, text("username")),
|
|||
|
|
searchDefinition("producer_account", &models.ProducerAccount{}, text("name")),
|
|||
|
|
searchDefinition("product_type", &models.ProductType{}, text("code"), text("name")),
|
|||
|
|
searchDefinition("product_warehouse", &models.ProductWarehouse{}, text("code"), text("name")),
|
|||
|
|
searchDefinition("product_info", &models.ProductInfo{}, text("code"), text("name")),
|
|||
|
|
searchDefinition("product_repair", &models.ProductRepair{}, enum("result", value("pending", "待处理"), value("passed", "通过"), value("failed", "未通过"))),
|
|||
|
|
searchDefinition("ec_product", &models.EcProduct{}, text("product_code"), text("name")),
|
|||
|
|
searchDefinition("ec_product_attribute", &models.EcProductAttribute{}, text("name"), text("value")),
|
|||
|
|
searchDefinition("gasorder_contract", &models.GasorderContract{}, text("contract_no"), text("title")),
|
|||
|
|
searchDefinition("gasorder_basic", &models.GasorderBasic{}, text("request_no"), enum("creator_type", value("user", "用户"), value("staff", "工作人员"), value("delivery", "配送站"), value("gas", "气站"))),
|
|||
|
|
searchDefinition("fin_settlement", &models.FinSettlement{}, text("settlement_no"), text("subject_type")),
|
|||
|
|
searchDefinition("cms_content", &models.CmsContent{}, text("content_type"), text("title"), text("publish_status")),
|
|||
|
|
searchDefinition("cs_ticket", &models.CsTicket{}, text("ticket_no"), text("category"), text("priority")),
|
|||
|
|
searchDefinition("platform_account", &models.PlatformAccount{}, text("username"), text("display_name")),
|
|||
|
|
searchDefinition("platform_role", &models.PlatformRole{}, text("role_code"), text("name"), enum("location_scope", value("standard", "脱敏坐标"), value("precise", "精确坐标"))),
|
|||
|
|
searchDefinition("wallet_basic", &models.WalletBasic{}, text("owner_type")),
|
|||
|
|
searchDefinition("payment_refund", &models.PaymentRefund{}, text("refund_no")),
|
|||
|
|
searchDefinition("wallet_apply_cash", &models.WalletApplyCash{}, text("cash_no")),
|
|||
|
|
}
|
|||
|
|
|
|||
|
|
func init() {
|
|||
|
|
for _, definition := range resourceSearchDefinitions {
|
|||
|
|
common.RegisterKeywordSearchPolicy(definition.model, definition.fields)
|
|||
|
|
}
|
|||
|
|
}
|
|||
|
|
|
|||
|
|
// resourceSearchFields 返回资源公开搜索契约的副本;未配置资源明确不支持搜索。
|
|||
|
|
func resourceSearchFields(name string) []common.KeywordSearchField {
|
|||
|
|
for _, definition := range resourceSearchDefinitions {
|
|||
|
|
if definition.name == name {
|
|||
|
|
return common.ConfiguredKeywordSearchFields(definition.model)
|
|||
|
|
}
|
|||
|
|
}
|
|||
|
|
return nil
|
|||
|
|
}
|
|||
|
|
|
|||
|
|
func searchDefinition(name string, model any, fields ...common.KeywordSearchField) resourceSearchDefinition {
|
|||
|
|
return resourceSearchDefinition{name: name, model: model, fields: fields}
|
|||
|
|
}
|
|||
|
|
|
|||
|
|
func text(key string) common.KeywordSearchField {
|
|||
|
|
return common.KeywordSearchField{Key: key, Kind: common.KeywordSearchText}
|
|||
|
|
}
|
|||
|
|
|
|||
|
|
func enum(key string, values ...common.KeywordSearchValue) common.KeywordSearchField {
|
|||
|
|
return common.KeywordSearchField{Key: key, Kind: common.KeywordSearchEnum, Values: values}
|
|||
|
|
}
|
|||
|
|
|
|||
|
|
func value(code, label string) common.KeywordSearchValue {
|
|||
|
|
return common.KeywordSearchValue{Value: code, Label: label}
|
|||
|
|
}
|