feat: 完善平台总后台模块
This commit is contained in:
15
backend/api/internal/models/aud_approval.go
Normal file
15
backend/api/internal/models/aud_approval.go
Normal file
@@ -0,0 +1,15 @@
|
||||
package models
|
||||
|
||||
import "git.apinb.com/bsm-sdk/core/database"
|
||||
|
||||
// AudApproval 对应 aud_approval,保存审批流与复核意见。
|
||||
type AudApproval struct {
|
||||
Entity
|
||||
BusinessType string `gorm:"column:business_type;type:varchar(64);not null" json:"business_type"`
|
||||
BusinessIdentity string `gorm:"column:business_identity;type:varchar(36);not null;index" json:"business_identity"`
|
||||
ApplicantIdentity string `gorm:"column:applicant_identity;type:varchar(36);not null;index" json:"applicant_identity"`
|
||||
Opinion string `gorm:"column:opinion;type:text;not null;default:''" json:"opinion"`
|
||||
}
|
||||
|
||||
func init() { database.AppendMigrate(&AudApproval{}) }
|
||||
func (table *AudApproval) TableName() string { return "aud_approval" }
|
||||
19
backend/api/internal/models/aud_export_log.go
Normal file
19
backend/api/internal/models/aud_export_log.go
Normal file
@@ -0,0 +1,19 @@
|
||||
package models
|
||||
|
||||
import (
|
||||
"git.apinb.com/bsm-sdk/core/database"
|
||||
"time"
|
||||
)
|
||||
|
||||
// AudExportLog 对应 aud_export_log,保存敏感导出审计。
|
||||
type AudExportLog struct {
|
||||
Entity
|
||||
ApplicantIdentity string `gorm:"column:applicant_identity;type:varchar(36);not null;index" json:"applicant_identity"`
|
||||
Purpose string `gorm:"column:purpose;type:varchar(255);not null" json:"purpose"`
|
||||
FieldScope string `gorm:"column:field_scope;type:jsonb;not null;default:'{}'" json:"field_scope"`
|
||||
ApprovedAt *time.Time `gorm:"column:approved_at;type:timestamptz" json:"approved_at"`
|
||||
FileURI string `gorm:"column:file_uri;type:varchar(512);not null;default:''" json:"file_uri"`
|
||||
}
|
||||
|
||||
func init() { database.AppendMigrate(&AudExportLog{}) }
|
||||
func (table *AudExportLog) TableName() string { return "aud_export_log" }
|
||||
17
backend/api/internal/models/aud_operation_log.go
Normal file
17
backend/api/internal/models/aud_operation_log.go
Normal file
@@ -0,0 +1,17 @@
|
||||
package models
|
||||
|
||||
import "git.apinb.com/bsm-sdk/core/database"
|
||||
|
||||
// AudOperationLog 对应 aud_operation_log,保存不可变操作审计。
|
||||
type AudOperationLog struct {
|
||||
Entity
|
||||
OperatorIdentity string `gorm:"column:operator_identity;type:varchar(36);not null;index" json:"operator_identity"`
|
||||
Action string `gorm:"column:action;type:varchar(64);not null" json:"action"`
|
||||
ObjectType string `gorm:"column:object_type;type:varchar(64);not null" json:"object_type"`
|
||||
ObjectIdentity string `gorm:"column:object_identity;type:varchar(36);not null;index" json:"object_identity"`
|
||||
BeforeData string `gorm:"column:before_data;type:jsonb;not null;default:'{}'" json:"before_data"`
|
||||
AfterData string `gorm:"column:after_data;type:jsonb;not null;default:'{}'" json:"after_data"`
|
||||
}
|
||||
|
||||
func init() { database.AppendMigrate(&AudOperationLog{}) }
|
||||
func (table *AudOperationLog) TableName() string { return "aud_operation_log" }
|
||||
16
backend/api/internal/models/cnt_content.go
Normal file
16
backend/api/internal/models/cnt_content.go
Normal file
@@ -0,0 +1,16 @@
|
||||
package models
|
||||
|
||||
import "git.apinb.com/bsm-sdk/core/database"
|
||||
|
||||
// CntContent 对应 cnt_content,保存公告与协议内容。
|
||||
type CntContent struct {
|
||||
Entity
|
||||
ContentType string `gorm:"column:content_type;type:varchar(32);not null" json:"content_type"`
|
||||
Title string `gorm:"column:title;type:varchar(256);not null" json:"title"`
|
||||
Body string `gorm:"column:body;type:text;not null;default:''" json:"body"`
|
||||
VersionNo int `gorm:"column:version_no;not null;default:1" json:"version_no"`
|
||||
PublishStatus string `gorm:"column:publish_status;type:varchar(32);not null;default:'draft'" json:"publish_status"`
|
||||
}
|
||||
|
||||
func init() { database.AppendMigrate(&CntContent{}) }
|
||||
func (table *CntContent) TableName() string { return "cnt_content" }
|
||||
15
backend/api/internal/models/cs_ticket.go
Normal file
15
backend/api/internal/models/cs_ticket.go
Normal file
@@ -0,0 +1,15 @@
|
||||
package models
|
||||
|
||||
import "git.apinb.com/bsm-sdk/core/database"
|
||||
|
||||
// CsTicket 对应 cs_ticket,保存客服工单。
|
||||
type CsTicket struct {
|
||||
Entity
|
||||
TicketNo string `gorm:"column:ticket_no;type:varchar(64);not null;uniqueIndex" json:"ticket_no"`
|
||||
UserAccountID uint64 `gorm:"column:user_account_id;not null;index" json:"user_account_id"`
|
||||
Category string `gorm:"column:category;type:varchar(64);not null" json:"category"`
|
||||
Priority string `gorm:"column:priority;type:varchar(16);not null;default:'normal'" json:"priority"`
|
||||
}
|
||||
|
||||
func init() { database.AppendMigrate(&CsTicket{}) }
|
||||
func (table *CsTicket) TableName() string { return "cs_ticket" }
|
||||
16
backend/api/internal/models/delivery_account.go
Normal file
16
backend/api/internal/models/delivery_account.go
Normal file
@@ -0,0 +1,16 @@
|
||||
package models
|
||||
|
||||
import "git.apinb.com/bsm-sdk/core/database"
|
||||
|
||||
// DeliveryAccount 对应 delivery_account,保存配送点登录账户。
|
||||
type DeliveryAccount struct {
|
||||
Entity
|
||||
DeliveryBasicID uint64 `gorm:"column:delivery_basic_id;not null;index" json:"delivery_basic_id"`
|
||||
Username string `gorm:"column:username;type:varchar(64);not null;uniqueIndex" json:"username"`
|
||||
DisplayName string `gorm:"column:display_name;type:varchar(64);not null;default:''" json:"display_name"`
|
||||
PasswordHash string `gorm:"column:password_hash;type:varchar(255);not null" json:"-"`
|
||||
RoleCode string `gorm:"column:role_code;type:varchar(64);not null" json:"role_code"`
|
||||
}
|
||||
|
||||
func init() { database.AppendMigrate(&DeliveryAccount{}) }
|
||||
func (table *DeliveryAccount) TableName() string { return "delivery_account" }
|
||||
18
backend/api/internal/models/delivery_basic.go
Normal file
18
backend/api/internal/models/delivery_basic.go
Normal file
@@ -0,0 +1,18 @@
|
||||
package models
|
||||
|
||||
import "git.apinb.com/bsm-sdk/core/database"
|
||||
|
||||
// DeliveryBasic 对应 delivery_basic,保存配送点主档案。
|
||||
type DeliveryBasic struct {
|
||||
Entity
|
||||
DeliveryCode string `gorm:"column:delivery_code;type:varchar(32);not null;uniqueIndex" json:"delivery_code"` // 配送点编码
|
||||
GasBasicID uint64 `gorm:"column:gas_basic_id;not null;default:0;index" json:"gas_basic_id"` // 所属可燃气体站自增主键,0 表示平台直属
|
||||
Name string `gorm:"column:name;type:varchar(128);not null" json:"name"` // 配送点名称
|
||||
Principal string `gorm:"column:principal;type:varchar(64);not null;default:''" json:"principal"` // 负责人
|
||||
Address string `gorm:"column:address;type:varchar(255);not null;default:''" json:"address"` // 配送点地址
|
||||
}
|
||||
|
||||
func init() { database.AppendMigrate(&DeliveryBasic{}) }
|
||||
|
||||
// TableName 返回与模型、文件名一致的单数数据表名。
|
||||
func (table *DeliveryBasic) TableName() string { return "delivery_basic" }
|
||||
14
backend/api/internal/models/delivery_task.go
Normal file
14
backend/api/internal/models/delivery_task.go
Normal file
@@ -0,0 +1,14 @@
|
||||
package models
|
||||
|
||||
import "git.apinb.com/bsm-sdk/core/database"
|
||||
|
||||
// DeliveryTask 对应 delivery_task,保存配送履约任务。
|
||||
type DeliveryTask struct {
|
||||
Entity
|
||||
EcOrderID uint64 `gorm:"column:ec_order_id;not null;index" json:"ec_order_id"`
|
||||
StaffAccountID uint64 `gorm:"column:staff_account_id;not null;default:0;index" json:"staff_account_id"`
|
||||
DeliveryPointID uint64 `gorm:"column:delivery_point_id;not null;index" json:"delivery_point_id"`
|
||||
}
|
||||
|
||||
func init() { database.AppendMigrate(&DeliveryTask{}) }
|
||||
func (table *DeliveryTask) TableName() string { return "delivery_task" }
|
||||
17
backend/api/internal/models/delivery_track.go
Normal file
17
backend/api/internal/models/delivery_track.go
Normal file
@@ -0,0 +1,17 @@
|
||||
package models
|
||||
|
||||
import (
|
||||
"git.apinb.com/bsm-sdk/core/database"
|
||||
"time"
|
||||
)
|
||||
|
||||
// DeliveryTrack 对应 delivery_track,保存配送轨迹摘要。
|
||||
type DeliveryTrack struct {
|
||||
Entity
|
||||
DeliveryTaskID uint64 `gorm:"column:delivery_task_id;not null;index" json:"delivery_task_id"`
|
||||
StartedAt *time.Time `gorm:"column:started_at;type:timestamptz" json:"started_at"`
|
||||
CompletedAt *time.Time `gorm:"column:completed_at;type:timestamptz" json:"completed_at"`
|
||||
}
|
||||
|
||||
func init() { database.AppendMigrate(&DeliveryTrack{}) }
|
||||
func (table *DeliveryTrack) TableName() string { return "delivery_track" }
|
||||
19
backend/api/internal/models/delivery_track_point.go
Normal file
19
backend/api/internal/models/delivery_track_point.go
Normal file
@@ -0,0 +1,19 @@
|
||||
package models
|
||||
|
||||
import (
|
||||
"git.apinb.com/bsm-sdk/core/database"
|
||||
"time"
|
||||
)
|
||||
|
||||
// DeliveryTrackPoint 对应 delivery_track_point,保存配送节点和位置。
|
||||
type DeliveryTrackPoint struct {
|
||||
Entity
|
||||
DeliveryTrackID uint64 `gorm:"column:delivery_track_id;not null;index" json:"delivery_track_id"`
|
||||
PointType string `gorm:"column:point_type;type:varchar(32);not null" json:"point_type"`
|
||||
OccurredAt time.Time `gorm:"column:occurred_at;type:timestamptz;not null" json:"occurred_at"`
|
||||
Longitude string `gorm:"column:longitude;type:varchar(32);not null;default:''" json:"longitude"`
|
||||
Latitude string `gorm:"column:latitude;type:varchar(32);not null;default:''" json:"latitude"`
|
||||
}
|
||||
|
||||
func init() { database.AppendMigrate(&DeliveryTrackPoint{}) }
|
||||
func (table *DeliveryTrackPoint) TableName() string { return "delivery_track_point" }
|
||||
18
backend/api/internal/models/dev_device_binding.go
Normal file
18
backend/api/internal/models/dev_device_binding.go
Normal file
@@ -0,0 +1,18 @@
|
||||
package models
|
||||
|
||||
import (
|
||||
"git.apinb.com/bsm-sdk/core/database"
|
||||
"time"
|
||||
)
|
||||
|
||||
// DevDeviceBinding 对应 dev_device_binding,保存设备授权绑定。
|
||||
type DevDeviceBinding struct {
|
||||
Entity
|
||||
SmartCylinderValveID uint64 `gorm:"column:smart_cylinder_valve_id;not null;index" json:"smart_cylinder_valve_id"`
|
||||
UserAccountID uint64 `gorm:"column:user_account_id;not null;index" json:"user_account_id"`
|
||||
EffectiveAt time.Time `gorm:"column:effective_at;type:timestamptz;not null" json:"effective_at"`
|
||||
ExpiredAt *time.Time `gorm:"column:expired_at;type:timestamptz" json:"expired_at"`
|
||||
}
|
||||
|
||||
func init() { database.AppendMigrate(&DevDeviceBinding{}) }
|
||||
func (table *DevDeviceBinding) TableName() string { return "dev_device_binding" }
|
||||
15
backend/api/internal/models/dev_smart_cylinder_valve.go
Normal file
15
backend/api/internal/models/dev_smart_cylinder_valve.go
Normal file
@@ -0,0 +1,15 @@
|
||||
package models
|
||||
|
||||
import "git.apinb.com/bsm-sdk/core/database"
|
||||
|
||||
// DevSmartCylinderValve 对应 dev_smart_cylinder_valve,保存智能瓶阀档案。
|
||||
type DevSmartCylinderValve struct {
|
||||
Entity
|
||||
DeviceNo string `gorm:"column:device_no;type:varchar(64);not null;uniqueIndex" json:"device_no"`
|
||||
Model string `gorm:"column:model;type:varchar(64);not null;default:''" json:"model"`
|
||||
OnlineStatus string `gorm:"column:online_status;type:varchar(32);not null;default:'offline'" json:"online_status"`
|
||||
OwnerIdentity string `gorm:"column:owner_identity;type:varchar(36);not null;default:'';index" json:"owner_identity"`
|
||||
}
|
||||
|
||||
func init() { database.AppendMigrate(&DevSmartCylinderValve{}) }
|
||||
func (table *DevSmartCylinderValve) TableName() string { return "dev_smart_cylinder_valve" }
|
||||
18
backend/api/internal/models/dev_telemetry.go
Normal file
18
backend/api/internal/models/dev_telemetry.go
Normal file
@@ -0,0 +1,18 @@
|
||||
package models
|
||||
|
||||
import (
|
||||
"git.apinb.com/bsm-sdk/core/database"
|
||||
"time"
|
||||
)
|
||||
|
||||
// DevTelemetry 对应 dev_telemetry,保存设备遥测摘要。
|
||||
type DevTelemetry struct {
|
||||
Entity
|
||||
SmartCylinderValveIdentity string `gorm:"column:smart_cylinder_valve_identity;type:varchar(36);not null;index" json:"smart_cylinder_valve_identity"`
|
||||
ReportedAt time.Time `gorm:"column:reported_at;type:timestamptz;not null;index" json:"reported_at"`
|
||||
Payload string `gorm:"column:payload;type:jsonb;not null;default:'{}'" json:"payload"`
|
||||
QualityFlag string `gorm:"column:quality_flag;type:varchar(32);not null;default:'normal'" json:"quality_flag"`
|
||||
}
|
||||
|
||||
func init() { database.AppendMigrate(&DevTelemetry{}) }
|
||||
func (table *DevTelemetry) TableName() string { return "dev_telemetry" }
|
||||
15
backend/api/internal/models/ec_cart.go
Normal file
15
backend/api/internal/models/ec_cart.go
Normal file
@@ -0,0 +1,15 @@
|
||||
package models
|
||||
|
||||
import "git.apinb.com/bsm-sdk/core/database"
|
||||
|
||||
// EcCart 对应 ec_cart,保存用户购物车明细。
|
||||
type EcCart struct {
|
||||
Entity
|
||||
UserAccountID uint64 `gorm:"column:user_account_id;not null;index" json:"user_account_id"`
|
||||
EcProductID uint64 `gorm:"column:ec_product_id;not null;index" json:"ec_product_id"`
|
||||
Quantity int `gorm:"column:quantity;not null;default:1" json:"quantity"`
|
||||
Selected bool `gorm:"column:selected;not null;default:true" json:"selected"`
|
||||
}
|
||||
|
||||
func init() { database.AppendMigrate(&EcCart{}) }
|
||||
func (table *EcCart) TableName() string { return "ec_cart" }
|
||||
14
backend/api/internal/models/ec_category.go
Normal file
14
backend/api/internal/models/ec_category.go
Normal file
@@ -0,0 +1,14 @@
|
||||
package models
|
||||
|
||||
import "git.apinb.com/bsm-sdk/core/database"
|
||||
|
||||
// EcCategory 对应 ec_category,保存商品分类树。
|
||||
type EcCategory struct {
|
||||
Entity
|
||||
ParentID uint64 `gorm:"column:parent_id;not null;default:0;index" json:"parent_id"`
|
||||
Name string `gorm:"column:name;type:varchar(128);not null" json:"name"`
|
||||
SortNo int `gorm:"column:sort_no;not null;default:0" json:"sort_no"`
|
||||
}
|
||||
|
||||
func init() { database.AppendMigrate(&EcCategory{}) }
|
||||
func (table *EcCategory) TableName() string { return "ec_category" }
|
||||
16
backend/api/internal/models/ec_order.go
Normal file
16
backend/api/internal/models/ec_order.go
Normal file
@@ -0,0 +1,16 @@
|
||||
package models
|
||||
|
||||
import "git.apinb.com/bsm-sdk/core/database"
|
||||
|
||||
// EcOrder 对应 ec_order,保存电商订单与组织快照。
|
||||
type EcOrder struct {
|
||||
Entity
|
||||
OrderNo string `gorm:"column:order_no;type:varchar(64);not null;uniqueIndex" json:"order_no"`
|
||||
UserAccountID uint64 `gorm:"column:user_account_id;not null;index" json:"user_account_id"`
|
||||
GasStationID uint64 `gorm:"column:gas_station_id;not null;default:0;index" json:"gas_station_id"`
|
||||
DeliveryPointID uint64 `gorm:"column:delivery_point_id;not null;default:0;index" json:"delivery_point_id"`
|
||||
TotalAmount int64 `gorm:"column:total_amount;not null;default:0" json:"total_amount"`
|
||||
}
|
||||
|
||||
func init() { database.AppendMigrate(&EcOrder{}) }
|
||||
func (table *EcOrder) TableName() string { return "ec_order" }
|
||||
16
backend/api/internal/models/ec_order_item.go
Normal file
16
backend/api/internal/models/ec_order_item.go
Normal file
@@ -0,0 +1,16 @@
|
||||
package models
|
||||
|
||||
import "git.apinb.com/bsm-sdk/core/database"
|
||||
|
||||
// EcOrderItem 对应 ec_order_item,保存订单商品快照。
|
||||
type EcOrderItem struct {
|
||||
Entity
|
||||
EcOrderID uint64 `gorm:"column:ec_order_id;not null;index" json:"ec_order_id"`
|
||||
EcProductID uint64 `gorm:"column:ec_product_id;not null;index" json:"ec_product_id"`
|
||||
ProductSnapshot string `gorm:"column:product_snapshot;type:jsonb;not null;default:'{}'" json:"product_snapshot"`
|
||||
Quantity int `gorm:"column:quantity;not null;default:1" json:"quantity"`
|
||||
SaleAmount int64 `gorm:"column:sale_amount;not null;default:0" json:"sale_amount"`
|
||||
}
|
||||
|
||||
func init() { database.AppendMigrate(&EcOrderItem{}) }
|
||||
func (table *EcOrderItem) TableName() string { return "ec_order_item" }
|
||||
16
backend/api/internal/models/ec_product.go
Normal file
16
backend/api/internal/models/ec_product.go
Normal file
@@ -0,0 +1,16 @@
|
||||
package models
|
||||
|
||||
import "git.apinb.com/bsm-sdk/core/database"
|
||||
|
||||
// EcProduct 对应 ec_product,保存可燃气体商品与服务。
|
||||
type EcProduct struct {
|
||||
Entity
|
||||
EcCategoryID uint64 `gorm:"column:ec_category_id;not null;index" json:"ec_category_id"`
|
||||
ProductCode string `gorm:"column:product_code;type:varchar(64);not null;uniqueIndex" json:"product_code"`
|
||||
Name string `gorm:"column:name;type:varchar(128);not null" json:"name"`
|
||||
PriceAmount int64 `gorm:"column:price_amount;not null;default:0" json:"price_amount"`
|
||||
StockQuantity int `gorm:"column:stock_quantity;not null;default:0" json:"stock_quantity"`
|
||||
}
|
||||
|
||||
func init() { database.AppendMigrate(&EcProduct{}) }
|
||||
func (table *EcProduct) TableName() string { return "ec_product" }
|
||||
15
backend/api/internal/models/ec_product_attribute.go
Normal file
15
backend/api/internal/models/ec_product_attribute.go
Normal file
@@ -0,0 +1,15 @@
|
||||
package models
|
||||
|
||||
import "git.apinb.com/bsm-sdk/core/database"
|
||||
|
||||
// EcProductAttribute 对应 ec_product_attribute,保存商品属性。
|
||||
type EcProductAttribute struct {
|
||||
Entity
|
||||
EcProductID uint64 `gorm:"column:ec_product_id;not null;index" json:"ec_product_id"`
|
||||
Name string `gorm:"column:name;type:varchar(64);not null" json:"name"`
|
||||
Value string `gorm:"column:value;type:varchar(255);not null" json:"value"`
|
||||
SortNo int `gorm:"column:sort_no;not null;default:0" json:"sort_no"`
|
||||
}
|
||||
|
||||
func init() { database.AppendMigrate(&EcProductAttribute{}) }
|
||||
func (table *EcProductAttribute) TableName() string { return "ec_product_attribute" }
|
||||
15
backend/api/internal/models/ec_product_image.go
Normal file
15
backend/api/internal/models/ec_product_image.go
Normal file
@@ -0,0 +1,15 @@
|
||||
package models
|
||||
|
||||
import "git.apinb.com/bsm-sdk/core/database"
|
||||
|
||||
// EcProductImage 对应 ec_product_image,保存商品受控图片资源。
|
||||
type EcProductImage struct {
|
||||
Entity
|
||||
EcProductID uint64 `gorm:"column:ec_product_id;not null;index" json:"ec_product_id"`
|
||||
ImageURI string `gorm:"column:image_uri;type:varchar(512);not null" json:"image_uri"`
|
||||
SortNo int `gorm:"column:sort_no;not null;default:0" json:"sort_no"`
|
||||
IsCover bool `gorm:"column:is_cover;not null;default:false" json:"is_cover"`
|
||||
}
|
||||
|
||||
func init() { database.AppendMigrate(&EcProductImage{}) }
|
||||
func (table *EcProductImage) TableName() string { return "ec_product_image" }
|
||||
16
backend/api/internal/models/ec_review.go
Normal file
16
backend/api/internal/models/ec_review.go
Normal file
@@ -0,0 +1,16 @@
|
||||
package models
|
||||
|
||||
import "git.apinb.com/bsm-sdk/core/database"
|
||||
|
||||
// EcReview 对应 ec_review,保存商品评论与审核状态。
|
||||
type EcReview struct {
|
||||
Entity
|
||||
EcOrderID uint64 `gorm:"column:ec_order_id;not null;index" json:"ec_order_id"`
|
||||
EcProductID uint64 `gorm:"column:ec_product_id;not null;index" json:"ec_product_id"`
|
||||
UserAccountID uint64 `gorm:"column:user_account_id;not null;index" json:"user_account_id"`
|
||||
Score int `gorm:"column:score;not null;default:5" json:"score"`
|
||||
Content string `gorm:"column:content;type:text;not null;default:''" json:"content"`
|
||||
}
|
||||
|
||||
func init() { database.AppendMigrate(&EcReview{}) }
|
||||
func (table *EcReview) TableName() string { return "ec_review" }
|
||||
@@ -1,4 +1,4 @@
|
||||
// Package models 定义与数据库表同名的领域模型和数据访问方法。
|
||||
// Package models 定义与数据表同名的领域模型和数据访问方法。
|
||||
package models
|
||||
|
||||
import (
|
||||
@@ -7,22 +7,21 @@ import (
|
||||
"github.com/google/uuid"
|
||||
)
|
||||
|
||||
// Entity 是所有主表共享字段;identity 必须由应用生成 UUID V7,禁止自增主键。
|
||||
// Entity 是所有主表共享字段。id 是数据库自增主键,identity 是应用生成的 UUID V7 业务标识。
|
||||
type Entity struct {
|
||||
Identity uuid.UUID `gorm:"column:identity;type:uuid;primaryKey" json:"identity"` // 主键,UUID V7
|
||||
CreatedAt time.Time `gorm:"column:created_at;type:timestamptz;not null" json:"created_at"` // 创建时间
|
||||
UpdatedAt time.Time `gorm:"column:updated_at;type:timestamptz;not null" json:"updated_at"` // 更新时间
|
||||
CreatedByIdentity *uuid.UUID `gorm:"column:created_by_identity;type:uuid" json:"created_by_identity,omitempty"` // 创建人主键
|
||||
UpdatedByIdentity *uuid.UUID `gorm:"column:updated_by_identity;type:uuid" json:"updated_by_identity,omitempty"` // 更新人主键
|
||||
Status string `gorm:"column:status;type:varchar(32);not null;default:'draft'" json:"status"` // 业务状态
|
||||
Version int `gorm:"column:version;not null;default:1" json:"version"` // 乐观锁版本
|
||||
ID uint64 `gorm:"column:id;primaryKey;autoIncrement" json:"id"` // 数据库自增主键
|
||||
Identity string `gorm:"column:identity;type:varchar(36);not null;uniqueIndex" json:"identity"` // UUID V7 业务标识
|
||||
CreatedAt time.Time `gorm:"column:created_at;type:timestamptz;not null" json:"created_at"` // 创建时间
|
||||
UpdatedAt time.Time `gorm:"column:updated_at;type:timestamptz;not null" json:"updated_at"` // 更新时间
|
||||
Status string `gorm:"column:status;type:varchar(32);not null;default:'draft'" json:"status"` // 业务状态
|
||||
Version int `gorm:"column:version;not null;default:1" json:"version"` // 乐观锁版本
|
||||
}
|
||||
|
||||
// NewIdentity 生成时间有序 UUID V7,生成失败属于不可恢复的运行时错误。
|
||||
func NewIdentity() uuid.UUID {
|
||||
// NewIdentity 生成时间有序的 UUID V7 字符串,生成失败属于不可恢复的运行时错误。
|
||||
func NewIdentity() string {
|
||||
identity, err := uuid.NewV7()
|
||||
if err != nil {
|
||||
panic(err)
|
||||
}
|
||||
return identity
|
||||
return identity.String()
|
||||
}
|
||||
|
||||
18
backend/api/internal/models/fin_payment.go
Normal file
18
backend/api/internal/models/fin_payment.go
Normal file
@@ -0,0 +1,18 @@
|
||||
package models
|
||||
|
||||
import (
|
||||
"git.apinb.com/bsm-sdk/core/database"
|
||||
"time"
|
||||
)
|
||||
|
||||
// FinPayment 对应 fin_payment,保存支付与退款记录。
|
||||
type FinPayment struct {
|
||||
Entity
|
||||
EcOrderID uint64 `gorm:"column:ec_order_id;not null;index" json:"ec_order_id"`
|
||||
Channel string `gorm:"column:channel;type:varchar(32);not null" json:"channel"`
|
||||
Amount int64 `gorm:"column:amount;not null;default:0" json:"amount"`
|
||||
PaidAt *time.Time `gorm:"column:paid_at;type:timestamptz" json:"paid_at"`
|
||||
}
|
||||
|
||||
func init() { database.AppendMigrate(&FinPayment{}) }
|
||||
func (table *FinPayment) TableName() string { return "fin_payment" }
|
||||
17
backend/api/internal/models/fin_reconciliation.go
Normal file
17
backend/api/internal/models/fin_reconciliation.go
Normal file
@@ -0,0 +1,17 @@
|
||||
package models
|
||||
|
||||
import (
|
||||
"git.apinb.com/bsm-sdk/core/database"
|
||||
"time"
|
||||
)
|
||||
|
||||
// FinReconciliation 对应 fin_reconciliation,保存渠道对账记录。
|
||||
type FinReconciliation struct {
|
||||
Entity
|
||||
Channel string `gorm:"column:channel;type:varchar(32);not null;index" json:"channel"`
|
||||
BillDate time.Time `gorm:"column:bill_date;type:date;not null" json:"bill_date"`
|
||||
DifferenceAmount int64 `gorm:"column:difference_amount;not null;default:0" json:"difference_amount"`
|
||||
}
|
||||
|
||||
func init() { database.AppendMigrate(&FinReconciliation{}) }
|
||||
func (table *FinReconciliation) TableName() string { return "fin_reconciliation" }
|
||||
19
backend/api/internal/models/fin_settlement.go
Normal file
19
backend/api/internal/models/fin_settlement.go
Normal file
@@ -0,0 +1,19 @@
|
||||
package models
|
||||
|
||||
import (
|
||||
"git.apinb.com/bsm-sdk/core/database"
|
||||
"time"
|
||||
)
|
||||
|
||||
// FinSettlement 对应 fin_settlement,保存结算单。
|
||||
type FinSettlement struct {
|
||||
Entity
|
||||
SettlementNo string `gorm:"column:settlement_no;type:varchar(64);not null;uniqueIndex" json:"settlement_no"`
|
||||
SubjectType string `gorm:"column:subject_type;type:varchar(32);not null" json:"subject_type"`
|
||||
SubjectID uint64 `gorm:"column:subject_id;not null;index" json:"subject_id"`
|
||||
PeriodStart time.Time `gorm:"column:period_start;type:timestamptz;not null" json:"period_start"`
|
||||
PeriodEnd time.Time `gorm:"column:period_end;type:timestamptz;not null" json:"period_end"`
|
||||
}
|
||||
|
||||
func init() { database.AppendMigrate(&FinSettlement{}) }
|
||||
func (table *FinSettlement) TableName() string { return "fin_settlement" }
|
||||
16
backend/api/internal/models/gas_account.go
Normal file
16
backend/api/internal/models/gas_account.go
Normal file
@@ -0,0 +1,16 @@
|
||||
package models
|
||||
|
||||
import "git.apinb.com/bsm-sdk/core/database"
|
||||
|
||||
// GasAccount 对应 gas_account,保存可燃气体站登录账户。
|
||||
type GasAccount struct {
|
||||
Entity
|
||||
GasBasicID uint64 `gorm:"column:gas_basic_id;not null;index" json:"gas_basic_id"` // 可燃气体站主键
|
||||
Username string `gorm:"column:username;type:varchar(64);not null;uniqueIndex" json:"username"` // 登录名称
|
||||
DisplayName string `gorm:"column:display_name;type:varchar(64);not null;default:''" json:"display_name"` // 展示名称
|
||||
PasswordHash string `gorm:"column:password_hash;type:varchar(255);not null" json:"-"` // 密码哈希
|
||||
RoleCode string `gorm:"column:role_code;type:varchar(64);not null" json:"role_code"` // 角色编码
|
||||
}
|
||||
|
||||
func init() { database.AppendMigrate(&GasAccount{}) }
|
||||
func (table *GasAccount) TableName() string { return "gas_account" }
|
||||
20
backend/api/internal/models/gas_basic.go
Normal file
20
backend/api/internal/models/gas_basic.go
Normal file
@@ -0,0 +1,20 @@
|
||||
package models
|
||||
|
||||
import "git.apinb.com/bsm-sdk/core/database"
|
||||
|
||||
// GasBasic 对应 gas_basic,保存可燃气体站的主体主档案。
|
||||
type GasBasic struct {
|
||||
Entity
|
||||
Code string `gorm:"column:code;type:varchar(32);not null;uniqueIndex" json:"code"` // 站点编码
|
||||
Name string `gorm:"column:name;type:varchar(128);not null" json:"name"` // 站点名称
|
||||
CreditCode string `gorm:"column:credit_code;type:varchar(64);not null;default:''" json:"credit_code"` // 统一社会信用代码
|
||||
Principal string `gorm:"column:principal;type:varchar(64);not null;default:''" json:"principal"` // 负责人
|
||||
Address string `gorm:"column:address;type:varchar(255);not null;default:''" json:"address"` // 站点地址
|
||||
Longitude string `gorm:"column:longitude;type:varchar(32);not null;default:''" json:"longitude"` // 经度
|
||||
Latitude string `gorm:"column:latitude;type:varchar(32);not null;default:''" json:"latitude"` // 纬度
|
||||
}
|
||||
|
||||
func init() { database.AppendMigrate(&GasBasic{}) }
|
||||
|
||||
// TableName 返回与模型、文件名一致的单数数据表名。
|
||||
func (table *GasBasic) TableName() string { return "gas_basic" }
|
||||
@@ -1,22 +0,0 @@
|
||||
package models
|
||||
|
||||
import "git.apinb.com/bsm-sdk/core/database"
|
||||
|
||||
// IdnAccount 对应 idn_account,表示用户或服务人员身份账户。
|
||||
type IdnAccount struct {
|
||||
Entity
|
||||
Username string `gorm:"column:username;type:varchar(64);uniqueIndex" json:"username"` // 登录用户名。
|
||||
DisplayName string `gorm:"column:display_name;type:varchar(64);not null;default:''" json:"display_name"` // 用户展示名称。
|
||||
PasswordHash string `gorm:"column:password_hash;type:varchar(255);not null;default:''" json:"-"` // 密码哈希值,禁止在接口中返回。
|
||||
RoleCode string `gorm:"column:role_code;type:varchar(64);not null;default:'user'" json:"role_code"` // 平台角色编码。
|
||||
MustChangePassword bool `gorm:"column:must_change_password;not null;default:false" json:"must_change_password"` // 是否必须修改初始密码。
|
||||
MFAEnabled bool `gorm:"column:mfa_enabled;not null;default:false" json:"mfa_enabled"` // 是否启用多因素认证。
|
||||
Phone string `gorm:"column:phone;type:varchar(32);uniqueIndex;not null" json:"phone"` // 手机号,用于登录和通知。
|
||||
AccountType string `gorm:"column:account_type;type:varchar(32);not null" json:"account_type"` // 账号类型,例如 user、operator。
|
||||
ServiceArea string `gorm:"column:service_area;type:varchar(128);not null" json:"service_area"` // 服务区域描述。
|
||||
}
|
||||
|
||||
func init() { database.AppendMigrate(&IdnAccount{}) }
|
||||
|
||||
// TableName 返回与模型、文件名一致的单数数据表名。
|
||||
func (table *IdnAccount) TableName() string { return "idn_account" }
|
||||
14
backend/api/internal/models/ntf_template.go
Normal file
14
backend/api/internal/models/ntf_template.go
Normal file
@@ -0,0 +1,14 @@
|
||||
package models
|
||||
|
||||
import "git.apinb.com/bsm-sdk/core/database"
|
||||
|
||||
// NtfTemplate 对应 ntf_template,保存通知模板。
|
||||
type NtfTemplate struct {
|
||||
Entity
|
||||
TemplateCode string `gorm:"column:template_code;type:varchar(64);not null;uniqueIndex" json:"template_code"`
|
||||
Channel string `gorm:"column:channel;type:varchar(32);not null" json:"channel"`
|
||||
Content string `gorm:"column:content;type:text;not null" json:"content"`
|
||||
}
|
||||
|
||||
func init() { database.AppendMigrate(&NtfTemplate{}) }
|
||||
func (table *NtfTemplate) TableName() string { return "ntf_template" }
|
||||
@@ -1,17 +0,0 @@
|
||||
package models
|
||||
|
||||
import "git.apinb.com/bsm-sdk/core/database"
|
||||
|
||||
// OrgDeliveryPoint 对应 org_delivery_point,表示末端配送组织单元。
|
||||
type OrgDeliveryPoint struct {
|
||||
Entity
|
||||
DeliveryCode string `gorm:"column:delivery_code;type:varchar(32);uniqueIndex;not null" json:"delivery_code"` // 配送点编码
|
||||
GasStationIdentity string `gorm:"column:gas_station_identity;type:uuid" json:"gas_station_identity"` // 归属气站主键
|
||||
Name string `gorm:"column:name;type:varchar(128);not null" json:"name"` // 配送点名称
|
||||
ServiceArea string `gorm:"column:service_area;type:varchar(128);not null" json:"service_area"` // 服务区域
|
||||
}
|
||||
|
||||
func init() { database.AppendMigrate(&OrgDeliveryPoint{}) }
|
||||
|
||||
// TableName 返回与模型、文件名一致的单数数据表名。
|
||||
func (table *OrgDeliveryPoint) TableName() string { return "org_delivery_point" }
|
||||
@@ -1,60 +0,0 @@
|
||||
package models
|
||||
|
||||
import (
|
||||
"errors"
|
||||
|
||||
"git.apinb.com/bsm-sdk/core/database"
|
||||
"git.apinb.com/bsm-sdk/core/errcode"
|
||||
"git.apinb.com/heqiapp/platforms/backend/api/internal/impl"
|
||||
"gorm.io/gorm"
|
||||
)
|
||||
|
||||
// OrgGasStation 对应 org_gas_station,表示可燃气体站经营主体。
|
||||
type OrgGasStation struct {
|
||||
Entity
|
||||
StationCode string `gorm:"column:station_code;type:varchar(32);uniqueIndex;not null" json:"station_code"` // 气站编码
|
||||
Name string `gorm:"column:name;type:varchar(128);not null" json:"name"` // 气站名称
|
||||
Principal string `gorm:"column:principal;type:varchar(64);not null" json:"principal"` // 负责人
|
||||
ServiceArea string `gorm:"column:service_area;type:varchar(128);not null" json:"service_area"` // 服务区域
|
||||
}
|
||||
|
||||
func init() {
|
||||
database.AppendMigrate(&OrgGasStation{})
|
||||
}
|
||||
|
||||
// TableName 返回与模型、文件名一致的单数数据表名。
|
||||
func (table *OrgGasStation) TableName() string { return "org_gas_station" }
|
||||
|
||||
// CreateOrgGasStation 创建待审核气站。
|
||||
func CreateOrgGasStation(data *OrgGasStation) error {
|
||||
if err := impl.DBService.Create(data).Error; err != nil {
|
||||
return errcode.ErrDB
|
||||
}
|
||||
return nil
|
||||
}
|
||||
|
||||
// ListOrgGasStation 按创建时间倒序查询气站。
|
||||
func ListOrgGasStation(page, size int) ([]OrgGasStation, int64, error) {
|
||||
var list []OrgGasStation
|
||||
var total int64
|
||||
databaseQuery := impl.DBService.Model(&OrgGasStation{})
|
||||
if err := databaseQuery.Count(&total).Error; err != nil {
|
||||
return nil, 0, errcode.ErrDB
|
||||
}
|
||||
if err := databaseQuery.Order("created_at desc").Offset((page - 1) * size).Limit(size).Find(&list).Error; err != nil {
|
||||
return nil, 0, errcode.ErrDB
|
||||
}
|
||||
return list, total, nil
|
||||
}
|
||||
|
||||
// GetOrgGasStationByIdentity 查询单个气站。
|
||||
func GetOrgGasStationByIdentity(identity string) (*OrgGasStation, error) {
|
||||
var data OrgGasStation
|
||||
if err := impl.DBService.Where("identity = ?", identity).First(&data).Error; err != nil {
|
||||
if errors.Is(err, gorm.ErrRecordNotFound) {
|
||||
return nil, errcode.ErrRecordNotFound
|
||||
}
|
||||
return nil, errcode.ErrDB
|
||||
}
|
||||
return &data, nil
|
||||
}
|
||||
@@ -1,20 +0,0 @@
|
||||
package models
|
||||
|
||||
import "git.apinb.com/bsm-sdk/core/database"
|
||||
|
||||
// OrgServicePerson 对应 org_service_person,表示安装维修、安检或配送服务人员。
|
||||
type OrgServicePerson struct {
|
||||
Entity
|
||||
AccountIdentity string `gorm:"column:account_identity;type:uuid;uniqueIndex" json:"account_identity"` // 关联 idn_account 主键
|
||||
GasStationIdentity string `gorm:"column:gas_station_identity;type:uuid" json:"gas_station_identity"` // 归属气站主键
|
||||
DeliveryPointIdentity string `gorm:"column:delivery_point_identity;type:uuid" json:"delivery_point_identity"` // 主归属配送点主键
|
||||
Name string `gorm:"column:name;type:varchar(64);not null" json:"name"` // 服务人员姓名
|
||||
Roles string `gorm:"column:roles;type:varchar(128);not null" json:"roles"` // 可执行角色集合
|
||||
WorkStatus string `gorm:"column:work_status;type:varchar(32);not null" json:"work_status"` // 上班与接单状态
|
||||
CredentialStatus string `gorm:"column:credential_status;type:varchar(32);not null" json:"credential_status"` // 资质状态
|
||||
}
|
||||
|
||||
func init() { database.AppendMigrate(&OrgServicePerson{}) }
|
||||
|
||||
// TableName 返回与模型、文件名一致的单数数据表名。
|
||||
func (table *OrgServicePerson) TableName() string { return "org_service_person" }
|
||||
19
backend/api/internal/models/platform_menu.go
Normal file
19
backend/api/internal/models/platform_menu.go
Normal file
@@ -0,0 +1,19 @@
|
||||
package models
|
||||
|
||||
import "git.apinb.com/bsm-sdk/core/database"
|
||||
|
||||
// PlatformMenu 对应 platform_menu,定义平台总后台的菜单树和访问路由。
|
||||
type PlatformMenu struct {
|
||||
Entity
|
||||
ParentID uint64 `gorm:"column:parent_id;not null;default:0;index" json:"parent_id"` // 父菜单自增主键,顶级菜单为 0
|
||||
MenuCode string `gorm:"column:menu_code;type:varchar(64);not null;uniqueIndex" json:"menu_code"` // 菜单编码
|
||||
Name string `gorm:"column:name;type:varchar(64);not null" json:"name"` // 菜单名称
|
||||
Icon string `gorm:"column:icon;type:varchar(64);not null;default:''" json:"icon"` // 前端图标名称
|
||||
Path string `gorm:"column:path;type:varchar(255);not null;default:''" json:"path"` // 前端路由地址
|
||||
SortNo int `gorm:"column:sort_no;not null;default:0" json:"sort_no"` // 同级排序号
|
||||
}
|
||||
|
||||
func init() { database.AppendMigrate(&PlatformMenu{}) }
|
||||
|
||||
// TableName 返回与模型、文件名一致的单数数据表名。
|
||||
func (table *PlatformMenu) TableName() string { return "platform_menu" }
|
||||
17
backend/api/internal/models/platform_role.go
Normal file
17
backend/api/internal/models/platform_role.go
Normal file
@@ -0,0 +1,17 @@
|
||||
package models
|
||||
|
||||
import "git.apinb.com/bsm-sdk/core/database"
|
||||
|
||||
// PlatformRole 对应 platform_role,定义平台总后台的数据范围与菜单权限角色。
|
||||
type PlatformRole struct {
|
||||
Entity
|
||||
RoleCode string `gorm:"column:role_code;type:varchar(64);not null;uniqueIndex" json:"role_code"` // 角色编码
|
||||
Name string `gorm:"column:name;type:varchar(64);not null" json:"name"` // 角色名称
|
||||
DataScope string `gorm:"column:data_scope;type:varchar(32);not null;default:'global'" json:"data_scope"` // 数据权限范围
|
||||
IsSystem bool `gorm:"column:is_system;not null;default:false" json:"is_system"` // 是否系统内置角色
|
||||
}
|
||||
|
||||
func init() { database.AppendMigrate(&PlatformRole{}) }
|
||||
|
||||
// TableName 返回与模型、文件名一致的单数数据表名。
|
||||
func (table *PlatformRole) TableName() string { return "platform_role" }
|
||||
20
backend/api/internal/models/platform_role_menu_relation.go
Normal file
20
backend/api/internal/models/platform_role_menu_relation.go
Normal file
@@ -0,0 +1,20 @@
|
||||
package models
|
||||
|
||||
import (
|
||||
"time"
|
||||
|
||||
"git.apinb.com/bsm-sdk/core/database"
|
||||
)
|
||||
|
||||
// PlatformRoleMenuRelation 对应 platform_role_menu_relation,记录角色拥有的菜单权限。
|
||||
type PlatformRoleMenuRelation struct {
|
||||
ID uint64 `gorm:"column:id;primaryKey;autoIncrement" json:"id"` // 数据库自增主键
|
||||
PlatformRoleID uint64 `gorm:"column:platform_role_id;not null;uniqueIndex:uk_platform_role_menu" json:"platform_role_id"` // 角色自增主键
|
||||
PlatformMenuID uint64 `gorm:"column:platform_menu_id;not null;uniqueIndex:uk_platform_role_menu" json:"platform_menu_id"` // 菜单自增主键
|
||||
CreatedAt time.Time `gorm:"column:created_at;type:timestamptz;not null" json:"created_at"` // 创建时间
|
||||
}
|
||||
|
||||
func init() { database.AppendMigrate(&PlatformRoleMenuRelation{}) }
|
||||
|
||||
// TableName 返回与模型、文件名一致的单数数据表名。
|
||||
func (table *PlatformRoleMenuRelation) TableName() string { return "platform_role_menu_relation" }
|
||||
19
backend/api/internal/models/platfrom_account.go
Normal file
19
backend/api/internal/models/platfrom_account.go
Normal file
@@ -0,0 +1,19 @@
|
||||
package models
|
||||
|
||||
import "git.apinb.com/bsm-sdk/core/database"
|
||||
|
||||
// PlatfromAccount 对应 platfrom_account,表示平台总后台登录账号。
|
||||
type PlatfromAccount struct {
|
||||
Entity
|
||||
Username string `gorm:"column:username;type:varchar(64);uniqueIndex;not null" json:"username"` // 登录用户名
|
||||
DisplayName string `gorm:"column:display_name;type:varchar(64);not null;default:''" json:"display_name"` // 用户展示名称
|
||||
Avatar string `gorm:"column:avatar;type:varchar(512);not null;default:''" json:"avatar"` // 头像资源地址
|
||||
PasswordHash string `gorm:"column:password_hash;type:varchar(255);not null;default:''" json:"-"` // 密码哈希值
|
||||
PlatformRoleCode string `gorm:"column:platform_role_code;type:varchar(64);not null;default:'root';index" json:"platform_role_code"` // 平台角色编码
|
||||
Phone string `gorm:"column:phone;type:varchar(32);uniqueIndex;not null;default:''" json:"phone"` // 手机号
|
||||
}
|
||||
|
||||
func init() { database.AppendMigrate(&PlatfromAccount{}) }
|
||||
|
||||
// TableName 返回与模型、文件名一致的单数数据表名。
|
||||
func (table *PlatfromAccount) TableName() string { return "platfrom_account" }
|
||||
@@ -2,28 +2,28 @@ package models
|
||||
|
||||
import "git.apinb.com/heqiapp/platforms/backend/api/internal/impl"
|
||||
|
||||
// DashboardOverview 是平台总后台的安全与组织聚合指标。
|
||||
// DashboardOverview 是平台总后台的跨组织运营概览指标。
|
||||
type DashboardOverview struct {
|
||||
GasStationCount int64 `json:"gas_station_count"` // 启用气站数量
|
||||
DeliveryPointCount int64 `json:"delivery_point_count"` // 启用配送点数量
|
||||
ServicePersonCount int64 `json:"service_person_count"` // 在岗服务人员数量
|
||||
UserCount int64 `json:"user_count"` // 启用普通用户数量
|
||||
GasBasicCount int64 `json:"gas_basic_count"` // 启用可燃气体站数量
|
||||
DeliveryBasicCount int64 `json:"delivery_basic_count"` // 启用配送点数量
|
||||
StaffCount int64 `json:"staff_count"` // 在岗服务人员数量
|
||||
UserCount int64 `json:"user_count"` // 启用业主客户数量
|
||||
PendingSafetyCount int64 `json:"pending_safety_count"` // 待处理安全事件数量
|
||||
}
|
||||
|
||||
// GetDashboardOverview 通过独立查询返回首期仪表盘指标。
|
||||
// GetDashboardOverview 通过独立查询返回首页概览指标。
|
||||
func GetDashboardOverview() (DashboardOverview, error) {
|
||||
var overview DashboardOverview
|
||||
if err := impl.DBService.Model(&OrgGasStation{}).Where("status = ?", "enabled").Count(&overview.GasStationCount).Error; err != nil {
|
||||
if err := impl.DBService.Model(&GasBasic{}).Where("status = ?", "enabled").Count(&overview.GasBasicCount).Error; err != nil {
|
||||
return DashboardOverview{}, err
|
||||
}
|
||||
if err := impl.DBService.Model(&OrgDeliveryPoint{}).Where("status = ?", "enabled").Count(&overview.DeliveryPointCount).Error; err != nil {
|
||||
if err := impl.DBService.Model(&DeliveryBasic{}).Where("status = ?", "enabled").Count(&overview.DeliveryBasicCount).Error; err != nil {
|
||||
return DashboardOverview{}, err
|
||||
}
|
||||
if err := impl.DBService.Model(&OrgServicePerson{}).Where("work_status = ?", "on_duty").Count(&overview.ServicePersonCount).Error; err != nil {
|
||||
if err := impl.DBService.Model(&StaffAccount{}).Where("work_status = ?", "on_duty").Count(&overview.StaffCount).Error; err != nil {
|
||||
return DashboardOverview{}, err
|
||||
}
|
||||
if err := impl.DBService.Model(&IdnAccount{}).Where("account_type = ? AND status = ?", "user", "enabled").Count(&overview.UserCount).Error; err != nil {
|
||||
if err := impl.DBService.Model(&UserAccount{}).Where("status = ?", "enabled").Count(&overview.UserCount).Error; err != nil {
|
||||
return DashboardOverview{}, err
|
||||
}
|
||||
if err := impl.DBService.Model(&SafEvent{}).Where("status = ?", "pending").Count(&overview.PendingSafetyCount).Error; err != nil {
|
||||
@@ -32,11 +32,11 @@ func GetDashboardOverview() (DashboardOverview, error) {
|
||||
return overview, nil
|
||||
}
|
||||
|
||||
// ListOrgDeliveryPoint 返回配送点分页列表。
|
||||
func ListOrgDeliveryPoint(page, size int) ([]OrgDeliveryPoint, int64, error) {
|
||||
var list []OrgDeliveryPoint
|
||||
// ListPlatfromAccount 返回平台账号分页列表,敏感字段由接口展示层脱敏。
|
||||
func ListPlatfromAccount(page, size int) ([]PlatfromAccount, int64, error) {
|
||||
var list []PlatfromAccount
|
||||
var total int64
|
||||
databaseQuery := impl.DBService.Model(&OrgDeliveryPoint{})
|
||||
databaseQuery := impl.DBService.Model(&PlatfromAccount{})
|
||||
if err := databaseQuery.Count(&total).Error; err != nil {
|
||||
return nil, 0, err
|
||||
}
|
||||
@@ -45,45 +45,3 @@ func ListOrgDeliveryPoint(page, size int) ([]OrgDeliveryPoint, int64, error) {
|
||||
}
|
||||
return list, total, nil
|
||||
}
|
||||
|
||||
// ListOrgServicePerson 返回服务人员分页列表。
|
||||
func ListOrgServicePerson(page, size int) ([]OrgServicePerson, int64, error) {
|
||||
var list []OrgServicePerson
|
||||
var total int64
|
||||
databaseQuery := impl.DBService.Model(&OrgServicePerson{})
|
||||
if err := databaseQuery.Count(&total).Error; err != nil {
|
||||
return nil, 0, err
|
||||
}
|
||||
if err := databaseQuery.Order("created_at desc").Offset((page - 1) * size).Limit(size).Find(&list).Error; err != nil {
|
||||
return nil, 0, err
|
||||
}
|
||||
return list, total, nil
|
||||
}
|
||||
|
||||
// ListIdnAccount 返回普通用户分页列表,手机号脱敏由前端展示层处理。
|
||||
func ListIdnAccount(page, size int) ([]IdnAccount, int64, error) {
|
||||
var list []IdnAccount
|
||||
var total int64
|
||||
databaseQuery := impl.DBService.Model(&IdnAccount{}).Where("account_type = ?", "user")
|
||||
if err := databaseQuery.Count(&total).Error; err != nil {
|
||||
return nil, 0, err
|
||||
}
|
||||
if err := databaseQuery.Order("created_at desc").Offset((page - 1) * size).Limit(size).Find(&list).Error; err != nil {
|
||||
return nil, 0, err
|
||||
}
|
||||
return list, total, nil
|
||||
}
|
||||
|
||||
// ListSafEvent 返回安全事件分页列表。
|
||||
func ListSafEvent(page, size int) ([]SafEvent, int64, error) {
|
||||
var list []SafEvent
|
||||
var total int64
|
||||
databaseQuery := impl.DBService.Model(&SafEvent{})
|
||||
if err := databaseQuery.Count(&total).Error; err != nil {
|
||||
return nil, 0, err
|
||||
}
|
||||
if err := databaseQuery.Order("level asc, created_at desc").Offset((page - 1) * size).Limit(size).Find(&list).Error; err != nil {
|
||||
return nil, 0, err
|
||||
}
|
||||
return list, total, nil
|
||||
}
|
||||
|
||||
18
backend/api/internal/models/report.go
Normal file
18
backend/api/internal/models/report.go
Normal file
@@ -0,0 +1,18 @@
|
||||
package models
|
||||
|
||||
import (
|
||||
"git.apinb.com/bsm-sdk/core/database"
|
||||
"time"
|
||||
)
|
||||
|
||||
// Report 对应 report,保存统计报表档案。
|
||||
type Report struct {
|
||||
Entity
|
||||
ReportCode string `gorm:"column:report_code;type:varchar(64);not null;uniqueIndex" json:"report_code"`
|
||||
ReportType string `gorm:"column:report_type;type:varchar(32);not null" json:"report_type"`
|
||||
StatPeriod string `gorm:"column:stat_period;type:varchar(64);not null" json:"stat_period"`
|
||||
GeneratedAt time.Time `gorm:"column:generated_at;type:timestamptz;not null" json:"generated_at"`
|
||||
}
|
||||
|
||||
func init() { database.AppendMigrate(&Report{}) }
|
||||
func (table *Report) TableName() string { return "report" }
|
||||
15
backend/api/internal/models/report_item.go
Normal file
15
backend/api/internal/models/report_item.go
Normal file
@@ -0,0 +1,15 @@
|
||||
package models
|
||||
|
||||
import "git.apinb.com/bsm-sdk/core/database"
|
||||
|
||||
// ReportItem 对应 report_item,保存报表维度明细。
|
||||
type ReportItem struct {
|
||||
Entity
|
||||
ReportID uint64 `gorm:"column:report_id;not null;index" json:"report_id"`
|
||||
Dimension string `gorm:"column:dimension;type:varchar(128);not null" json:"dimension"`
|
||||
MetricCode string `gorm:"column:metric_code;type:varchar(64);not null" json:"metric_code"`
|
||||
MetricValue string `gorm:"column:metric_value;type:varchar(128);not null" json:"metric_value"`
|
||||
}
|
||||
|
||||
func init() { database.AppendMigrate(&ReportItem{}) }
|
||||
func (table *ReportItem) TableName() string { return "report_item" }
|
||||
19
backend/api/internal/models/report_metric_snapshot.go
Normal file
19
backend/api/internal/models/report_metric_snapshot.go
Normal file
@@ -0,0 +1,19 @@
|
||||
package models
|
||||
|
||||
import (
|
||||
"git.apinb.com/bsm-sdk/core/database"
|
||||
"time"
|
||||
)
|
||||
|
||||
// ReportMetricSnapshot 对应 report_metric_snapshot,保存指标快照。
|
||||
type ReportMetricSnapshot struct {
|
||||
Entity
|
||||
MetricCode string `gorm:"column:metric_code;type:varchar(64);not null;index" json:"metric_code"`
|
||||
ScopeType string `gorm:"column:scope_type;type:varchar(32);not null" json:"scope_type"`
|
||||
ScopeID uint64 `gorm:"column:scope_id;not null;default:0;index" json:"scope_id"`
|
||||
StatAt time.Time `gorm:"column:stat_at;type:timestamptz;not null;index" json:"stat_at"`
|
||||
MetricValue string `gorm:"column:metric_value;type:varchar(128);not null" json:"metric_value"`
|
||||
}
|
||||
|
||||
func init() { database.AppendMigrate(&ReportMetricSnapshot{}) }
|
||||
func (table *ReportMetricSnapshot) TableName() string { return "report_metric_snapshot" }
|
||||
@@ -1,18 +1,19 @@
|
||||
package models
|
||||
|
||||
import "git.apinb.com/bsm-sdk/core/database"
|
||||
import (
|
||||
"git.apinb.com/bsm-sdk/core/database"
|
||||
"time"
|
||||
)
|
||||
|
||||
// SafEvent 对应 saf_event,表示需要平台跟踪处置的安全事件。
|
||||
// SafEvent 对应 saf_event,保存安全事件统一入口。
|
||||
type SafEvent struct {
|
||||
Entity
|
||||
EventCode string `gorm:"column:event_code;type:varchar(32);uniqueIndex;not null" json:"event_code"` // 安全事件编码
|
||||
Level int `gorm:"column:level;type:integer;not null" json:"level"` // 风险等级,1 至 3 级
|
||||
Title string `gorm:"column:title;type:varchar(256);not null" json:"title"` // 事件说明
|
||||
EventCode string `gorm:"column:event_code;type:varchar(64);not null;uniqueIndex" json:"event_code"`
|
||||
Level int `gorm:"column:level;not null;default:3" json:"level"`
|
||||
Title string `gorm:"column:title;type:varchar(256);not null;default:''" json:"title"`
|
||||
SmartCylinderValveIdentity string `gorm:"column:smart_cylinder_valve_identity;type:varchar(36);not null;default:'';index" json:"smart_cylinder_valve_identity"`
|
||||
SLAAt *time.Time `gorm:"column:sla_at;type:timestamptz" json:"sla_at"`
|
||||
}
|
||||
|
||||
func init() {
|
||||
database.AppendMigrate(&SafEvent{})
|
||||
}
|
||||
|
||||
// TableName 返回与模型、文件名一致的单数数据表名。
|
||||
func init() { database.AppendMigrate(&SafEvent{}) }
|
||||
func (table *SafEvent) TableName() string { return "saf_event" }
|
||||
|
||||
15
backend/api/internal/models/saf_event_disposal.go
Normal file
15
backend/api/internal/models/saf_event_disposal.go
Normal file
@@ -0,0 +1,15 @@
|
||||
package models
|
||||
|
||||
import "git.apinb.com/bsm-sdk/core/database"
|
||||
|
||||
// SafEventDisposal 对应 saf_event_disposal,保存安全处置记录。
|
||||
type SafEventDisposal struct {
|
||||
Entity
|
||||
SafEventIdentity string `gorm:"column:saf_event_identity;type:varchar(36);not null;index" json:"saf_event_identity"`
|
||||
Action string `gorm:"column:action;type:varchar(64);not null" json:"action"`
|
||||
Reason string `gorm:"column:reason;type:text;not null;default:''" json:"reason"`
|
||||
OperatorIdentity string `gorm:"column:operator_identity;type:varchar(36);not null;default:''" json:"operator_identity"`
|
||||
}
|
||||
|
||||
func init() { database.AppendMigrate(&SafEventDisposal{}) }
|
||||
func (table *SafEventDisposal) TableName() string { return "saf_event_disposal" }
|
||||
15
backend/api/internal/models/saf_inspection.go
Normal file
15
backend/api/internal/models/saf_inspection.go
Normal file
@@ -0,0 +1,15 @@
|
||||
package models
|
||||
|
||||
import "git.apinb.com/bsm-sdk/core/database"
|
||||
|
||||
// SafInspection 对应 saf_inspection,保存安检与复检记录。
|
||||
type SafInspection struct {
|
||||
Entity
|
||||
UserAccountID uint64 `gorm:"column:user_account_id;not null;index" json:"user_account_id"`
|
||||
StaffAccountID uint64 `gorm:"column:staff_account_id;not null;index" json:"staff_account_id"`
|
||||
Result string `gorm:"column:result;type:varchar(32);not null" json:"result"`
|
||||
EvidenceURI string `gorm:"column:evidence_uri;type:varchar(512);not null;default:''" json:"evidence_uri"`
|
||||
}
|
||||
|
||||
func init() { database.AppendMigrate(&SafInspection{}) }
|
||||
func (table *SafInspection) TableName() string { return "saf_inspection" }
|
||||
16
backend/api/internal/models/saf_rule.go
Normal file
16
backend/api/internal/models/saf_rule.go
Normal file
@@ -0,0 +1,16 @@
|
||||
package models
|
||||
|
||||
import "git.apinb.com/bsm-sdk/core/database"
|
||||
|
||||
// SafRule 对应 saf_rule,保存安全规则。
|
||||
type SafRule struct {
|
||||
Entity
|
||||
RuleCode string `gorm:"column:rule_code;type:varchar(64);not null;uniqueIndex" json:"rule_code"`
|
||||
VersionNo int `gorm:"column:version_no;not null;default:1" json:"version_no"`
|
||||
Threshold string `gorm:"column:threshold;type:jsonb;not null;default:'{}'" json:"threshold"`
|
||||
Action string `gorm:"column:action;type:varchar(64);not null" json:"action"`
|
||||
GrayScope string `gorm:"column:gray_scope;type:jsonb;not null;default:'{}'" json:"gray_scope"`
|
||||
}
|
||||
|
||||
func init() { database.AppendMigrate(&SafRule{}) }
|
||||
func (table *SafRule) TableName() string { return "saf_rule" }
|
||||
22
backend/api/internal/models/staff_account.go
Normal file
22
backend/api/internal/models/staff_account.go
Normal file
@@ -0,0 +1,22 @@
|
||||
package models
|
||||
|
||||
import "git.apinb.com/bsm-sdk/core/database"
|
||||
|
||||
// StaffAccount 对应 staff_account,是服务人员唯一的档案和 App 登录账户。
|
||||
type StaffAccount struct {
|
||||
Entity
|
||||
Username string `gorm:"column:username;type:varchar(64);not null;uniqueIndex" json:"username"` // 登录名称
|
||||
PasswordHash string `gorm:"column:password_hash;type:varchar(255);not null" json:"-"` // 密码哈希
|
||||
Name string `gorm:"column:name;type:varchar(64);not null" json:"name"` // 人员姓名
|
||||
Phone string `gorm:"column:phone;type:varchar(32);not null;default:'';index" json:"phone"` // 联系手机号
|
||||
Avatar string `gorm:"column:avatar;type:varchar(512);not null;default:''" json:"avatar"` // 头像资源地址
|
||||
RoleCode string `gorm:"column:role_code;type:varchar(64);not null;default:''" json:"role_code"` // 服务角色编码
|
||||
GasBasicID uint64 `gorm:"column:gas_basic_id;not null;default:0;index" json:"gas_basic_id"` // 所属可燃气体站主键
|
||||
DeliveryBasicID uint64 `gorm:"column:delivery_basic_id;not null;default:0;index" json:"delivery_basic_id"` // 所属配送点主键
|
||||
WorkStatus string `gorm:"column:work_status;type:varchar(32);not null;default:'off_duty'" json:"work_status"` // 在岗接单状态
|
||||
}
|
||||
|
||||
func init() { database.AppendMigrate(&StaffAccount{}) }
|
||||
|
||||
// TableName 返回与模型、文件名一致的单数数据表名。
|
||||
func (table *StaffAccount) TableName() string { return "staff_account" }
|
||||
18
backend/api/internal/models/staff_credential.go
Normal file
18
backend/api/internal/models/staff_credential.go
Normal file
@@ -0,0 +1,18 @@
|
||||
package models
|
||||
|
||||
import (
|
||||
"git.apinb.com/bsm-sdk/core/database"
|
||||
"time"
|
||||
)
|
||||
|
||||
// StaffCredential 对应 staff_credential,保存人员资质。
|
||||
type StaffCredential struct {
|
||||
Entity
|
||||
StaffAccountID uint64 `gorm:"column:staff_account_id;not null;index" json:"staff_account_id"`
|
||||
CredentialType string `gorm:"column:credential_type;type:varchar(64);not null" json:"credential_type"`
|
||||
CredentialNo string `gorm:"column:credential_no;type:varchar(128);not null;default:''" json:"credential_no"`
|
||||
ExpiredAt *time.Time `gorm:"column:expired_at;type:timestamptz" json:"expired_at"`
|
||||
}
|
||||
|
||||
func init() { database.AppendMigrate(&StaffCredential{}) }
|
||||
func (table *StaffCredential) TableName() string { return "staff_credential" }
|
||||
19
backend/api/internal/models/user_account.go
Normal file
19
backend/api/internal/models/user_account.go
Normal file
@@ -0,0 +1,19 @@
|
||||
package models
|
||||
|
||||
import "git.apinb.com/bsm-sdk/core/database"
|
||||
|
||||
// UserAccount 对应 user_account,是业主客户唯一的档案和用户端登录账户。
|
||||
type UserAccount struct {
|
||||
Entity
|
||||
Username string `gorm:"column:username;type:varchar(64);not null;uniqueIndex" json:"username"` // 登录名称
|
||||
PasswordHash string `gorm:"column:password_hash;type:varchar(255);not null" json:"-"` // 密码哈希
|
||||
Name string `gorm:"column:name;type:varchar(64);not null" json:"name"` // 客户姓名
|
||||
Phone string `gorm:"column:phone;type:varchar(32);not null;default:'';index" json:"phone"` // 联系手机号
|
||||
Avatar string `gorm:"column:avatar;type:varchar(512);not null;default:''" json:"avatar"` // 头像资源地址
|
||||
RealName string `gorm:"column:real_name;type:varchar(64);not null;default:''" json:"real_name"` // 实名认证名称
|
||||
}
|
||||
|
||||
func init() { database.AppendMigrate(&UserAccount{}) }
|
||||
|
||||
// TableName 返回与模型、文件名一致的单数数据表名。
|
||||
func (table *UserAccount) TableName() string { return "user_account" }
|
||||
16
backend/api/internal/models/user_address.go
Normal file
16
backend/api/internal/models/user_address.go
Normal file
@@ -0,0 +1,16 @@
|
||||
package models
|
||||
|
||||
import "git.apinb.com/bsm-sdk/core/database"
|
||||
|
||||
// UserAddress 对应 user_address,保存用户地址。
|
||||
type UserAddress struct {
|
||||
Entity
|
||||
UserAccountID uint64 `gorm:"column:user_account_id;not null;index" json:"user_account_id"`
|
||||
Address string `gorm:"column:address;type:varchar(255);not null" json:"address"`
|
||||
Longitude string `gorm:"column:longitude;type:varchar(32);not null;default:''" json:"longitude"`
|
||||
Latitude string `gorm:"column:latitude;type:varchar(32);not null;default:''" json:"latitude"`
|
||||
IsDefault bool `gorm:"column:is_default;not null;default:false" json:"is_default"`
|
||||
}
|
||||
|
||||
func init() { database.AppendMigrate(&UserAddress{}) }
|
||||
func (table *UserAddress) TableName() string { return "user_address" }
|
||||
15
backend/api/internal/models/user_service_relation.go
Normal file
15
backend/api/internal/models/user_service_relation.go
Normal file
@@ -0,0 +1,15 @@
|
||||
package models
|
||||
|
||||
import "git.apinb.com/bsm-sdk/core/database"
|
||||
|
||||
// UserServiceRelation 对应 user_service_relation,保存用户服务归属快照。
|
||||
type UserServiceRelation struct {
|
||||
Entity
|
||||
UserAccountID uint64 `gorm:"column:user_account_id;not null;index" json:"user_account_id"`
|
||||
GasBasicID uint64 `gorm:"column:gas_basic_id;not null;default:0;index" json:"gas_basic_id"`
|
||||
DeliveryBasicID uint64 `gorm:"column:delivery_basic_id;not null;default:0;index" json:"delivery_basic_id"`
|
||||
StaffAccountID uint64 `gorm:"column:staff_account_id;not null;default:0;index" json:"staff_account_id"`
|
||||
}
|
||||
|
||||
func init() { database.AppendMigrate(&UserServiceRelation{}) }
|
||||
func (table *UserServiceRelation) TableName() string { return "user_service_relation" }
|
||||
15
backend/api/internal/models/wallet.go
Normal file
15
backend/api/internal/models/wallet.go
Normal file
@@ -0,0 +1,15 @@
|
||||
package models
|
||||
|
||||
import "git.apinb.com/bsm-sdk/core/database"
|
||||
|
||||
// Wallet 对应 wallet,保存余额账户。
|
||||
type Wallet struct {
|
||||
Entity
|
||||
OwnerType string `gorm:"column:owner_type;type:varchar(32);not null" json:"owner_type"`
|
||||
OwnerID uint64 `gorm:"column:owner_id;not null;index" json:"owner_id"`
|
||||
BalanceAmount int64 `gorm:"column:balance_amount;not null;default:0" json:"balance_amount"`
|
||||
FrozenAmount int64 `gorm:"column:frozen_amount;not null;default:0" json:"frozen_amount"`
|
||||
}
|
||||
|
||||
func init() { database.AppendMigrate(&Wallet{}) }
|
||||
func (table *Wallet) TableName() string { return "wallet" }
|
||||
16
backend/api/internal/models/wallet_ledger.go
Normal file
16
backend/api/internal/models/wallet_ledger.go
Normal file
@@ -0,0 +1,16 @@
|
||||
package models
|
||||
|
||||
import "git.apinb.com/bsm-sdk/core/database"
|
||||
|
||||
// WalletLedger 对应 wallet_ledger,保存不可变资金流水。
|
||||
type WalletLedger struct {
|
||||
Entity
|
||||
WalletID uint64 `gorm:"column:wallet_id;not null;index" json:"wallet_id"`
|
||||
Amount int64 `gorm:"column:amount;not null" json:"amount"`
|
||||
Direction string `gorm:"column:direction;type:varchar(16);not null" json:"direction"`
|
||||
BalanceAfter int64 `gorm:"column:balance_after;not null" json:"balance_after"`
|
||||
ReferenceIdentity string `gorm:"column:reference_identity;type:varchar(36);not null;default:'';index" json:"reference_identity"`
|
||||
}
|
||||
|
||||
func init() { database.AppendMigrate(&WalletLedger{}) }
|
||||
func (table *WalletLedger) TableName() string { return "wallet_ledger" }
|
||||
14
backend/api/internal/models/wallet_recharge.go
Normal file
14
backend/api/internal/models/wallet_recharge.go
Normal file
@@ -0,0 +1,14 @@
|
||||
package models
|
||||
|
||||
import "git.apinb.com/bsm-sdk/core/database"
|
||||
|
||||
// WalletRecharge 对应 wallet_recharge,保存充值记录。
|
||||
type WalletRecharge struct {
|
||||
Entity
|
||||
WalletID uint64 `gorm:"column:wallet_id;not null;index" json:"wallet_id"`
|
||||
Amount int64 `gorm:"column:amount;not null" json:"amount"`
|
||||
Channel string `gorm:"column:channel;type:varchar(32);not null" json:"channel"`
|
||||
}
|
||||
|
||||
func init() { database.AppendMigrate(&WalletRecharge{}) }
|
||||
func (table *WalletRecharge) TableName() string { return "wallet_recharge" }
|
||||
14
backend/api/internal/models/wallet_withdrawal.go
Normal file
14
backend/api/internal/models/wallet_withdrawal.go
Normal file
@@ -0,0 +1,14 @@
|
||||
package models
|
||||
|
||||
import "git.apinb.com/bsm-sdk/core/database"
|
||||
|
||||
// WalletWithdrawal 对应 wallet_withdrawal,保存提现记录。
|
||||
type WalletWithdrawal struct {
|
||||
Entity
|
||||
WalletID uint64 `gorm:"column:wallet_id;not null;index" json:"wallet_id"`
|
||||
Amount int64 `gorm:"column:amount;not null" json:"amount"`
|
||||
BankAccountMasked string `gorm:"column:bank_account_masked;type:varchar(128);not null;default:''" json:"bank_account_masked"`
|
||||
}
|
||||
|
||||
func init() { database.AppendMigrate(&WalletWithdrawal{}) }
|
||||
func (table *WalletWithdrawal) TableName() string { return "wallet_withdrawal" }
|
||||
Reference in New Issue
Block a user