474 lines
27 KiB
Go
474 lines
27 KiB
Go
package model
|
||
|
||
import (
|
||
"time"
|
||
|
||
"gitea.redpowerfuture.com/red-future/common/beans"
|
||
)
|
||
|
||
// ============================================================
|
||
// 实体定义
|
||
// ============================================================
|
||
|
||
// BusinessConfig 业务配置
|
||
type BusinessConfig struct {
|
||
beans.SQLBaseDO `orm:",inherit"`
|
||
BusinessCode string `orm:"business_code" json:"businessCode" dc:"业务编码" eg:"KUAISHOU"`
|
||
BusinessName string `orm:"business_name" json:"businessName" dc:"业务名称" eg:"快手电商"`
|
||
Description string `orm:"description" json:"description" dc:"描述" eg:"快手电商店铺每日统计报表"`
|
||
Status string `orm:"status" json:"status" dc:"status" eg:"ACTIVE"`
|
||
Config map[string]interface{} `orm:"config" json:"config" dc:"扩展配置"`
|
||
}
|
||
|
||
// ReportConfig 报表配置
|
||
type ReportConfig struct {
|
||
beans.SQLBaseDO `orm:",inherit"`
|
||
BusinessCode string `orm:"business_code" json:"businessCode" dc:"业务编码" eg:"KUAISHOU"`
|
||
ReportCode string `orm:"report_code" json:"reportCode" dc:"报表编码" eg:"shop_daily"`
|
||
ReportName string `orm:"report_name" json:"reportName" dc:"报表名称" eg:"店铺日报"`
|
||
Description string `orm:"description" json:"description" dc:"描述" eg:"快手电商店铺每日统计报表"`
|
||
Status string `orm:"status" json:"status" dc:"状态 ACTIVE/INACTIVE" eg:"ACTIVE"`
|
||
StatTableName string `orm:"stat_table_name" json:"statTableName" dc:"统计宽表名" eg:"stat_kuaishou_shop_daily"`
|
||
StatTableComment string `orm:"stat_table_comment" json:"statTableComment" dc:"统计宽表注释" eg:"快手电商-店铺日报"`
|
||
DateField string `orm:"date_field" json:"dateField" dc:"日期字段名" eg:"stat_date"`
|
||
PrimaryKeys []string `orm:"primary_keys" json:"primaryKeys" dc:"主键字段列表"`
|
||
ConflictKeys []string `orm:"conflict_keys" json:"conflictKeys" dc:"冲突键(唯一索引)"`
|
||
Config map[string]interface{} `orm:"config" json:"config" dc:"扩展配置"`
|
||
ExtractConfigIDs string `orm:"-" json:"extractConfigIds" dc:"抽取配置ID列表,逗号分隔" eg:"1,2,3"`
|
||
Fields []FieldConfig `orm:"-" json:"fields,omitempty" dc:"字段配置列表(查询时返回)"`
|
||
}
|
||
|
||
// FieldConfig 字段配置
|
||
type FieldConfig struct {
|
||
beans.SQLBaseDO `orm:",inherit"`
|
||
BusinessCode string `orm:"business_code" json:"businessCode" dc:"业务编码" eg:"KUAISHOU"`
|
||
ReportCode string `orm:"report_code" json:"reportCode" dc:"reportCode" eg:"shop_daily"`
|
||
FieldCode string `orm:"field_code" json:"fieldCode" dc:"字段编码" eg:"order_amount"`
|
||
FieldName string `orm:"field_name" json:"fieldName" dc:"字段名称" eg:"订单金额"`
|
||
FieldType string `orm:"field_type" json:"fieldType" dc:"字段类型 STRING/INT/FLOAT/DATE/DATETIME/JSONB" eg:"FLOAT"`
|
||
DataType string `orm:"data_type" json:"dataType" dc:"数据存储类型" eg:"STRING"`
|
||
FieldRole string `orm:"field_role" json:"fieldRole" dc:"字段角色 DIMENSION(维度)/INDICATOR(指标)/FILTER(筛选)/FILTER_ONLY(仅筛选)" eg:"DIMENSION"`
|
||
IsAggregatable bool `orm:"is_aggregatable" json:"isAggregatable" dc:"是否可聚合" eg:"true"`
|
||
IsFilterable bool `orm:"is_filterable" json:"isFilterable" dc:"是否可筛选" eg:"true"`
|
||
IsQueryable bool `orm:"is_queryable" json:"isQueryable" dc:"是否可查询" eg:"true"`
|
||
IsSortable bool `orm:"is_sortable" json:"isSortable" dc:"是否可排序" eg:"true"`
|
||
DefaultAggregate string `orm:"default_aggregate" json:"defaultAggregate" dc:"默认聚合方式 SUM/COUNT/AVG/MAX/MIN" eg:"SUM"`
|
||
ValidAggregates []string `orm:"valid_aggregates" json:"validAggregates" dc:"可选聚合列表"`
|
||
FilterOperators []string `orm:"filter_operators" json:"filterOperators" dc:"可选操作符列表 =/!=/>/</>=/<=/IN/LIKE/BETWEEN"`
|
||
Expression string `orm:"expression" json:"expression" dc:"表达式(衍生字段)" eg:"order_amount - refund_amount"`
|
||
ExpressionType string `orm:"expression_type" json:"expressionType" dc:"表达式类型 DIRECT/CALCULATED" eg:"DIRECT"`
|
||
FormatPattern string `orm:"format_pattern" json:"formatPattern" dc:"格式化模板" eg:"#,##0.00"`
|
||
Unit string `orm:"unit" json:"unit" dc:"单位"`
|
||
DictCode string `orm:"dict_code" json:"dictCode" dc:"字典编码" eg:"dict_order_type"`
|
||
SortOrder int `orm:"sort_order" json:"sortOrder" dc:"排序号" eg:"1"`
|
||
GroupName string `orm:"group_name" json:"groupName" dc:"分组名称" eg:"交易指标"`
|
||
Status string `orm:"status" json:"status" dc:"status" eg:"ACTIVE"`
|
||
}
|
||
|
||
// ExtractConfig 抽取配置
|
||
type ExtractConfig struct {
|
||
beans.SQLBaseDO `orm:",inherit"`
|
||
BusinessCode string `orm:"business_code" json:"businessCode" dc:"业务编码" eg:"KUAISHOU"`
|
||
ReportCode string `orm:"report_code" json:"reportCode" dc:"reportCode" eg:"shop_daily"`
|
||
ExtractCode string `orm:"extract_code" json:"extractCode" dc:"抽取编码" eg:"kuaishou_order_extract"`
|
||
ExtractName string `orm:"extract_name" json:"extractName" dc:"抽取名称" eg:"订单抽取"`
|
||
SourceTableName string `orm:"source_table_name" json:"sourceTableName" dc:"源表名" eg:"ods_kuaishou_order"`
|
||
SourceTableAlias string `orm:"source_table_alias" json:"sourceTableAlias" dc:"源表别名" eg:"o"`
|
||
TargetTableName string `orm:"target_table_name" json:"targetTableName" dc:"目标表名" eg:"stat_kuaishou_shop_daily"`
|
||
IsEnabled bool `orm:"is_enabled" json:"isEnabled" dc:"是否启用" eg:"true"`
|
||
ExtractType string `orm:"extract_type" json:"extractType" dc:"抽取类型 FULL/INCREMENTAL" eg:"INCREMENTAL"`
|
||
ExtractMode string `orm:"extract_mode" json:"extractMode" dc:"抽取模式 DIRECT(逐行)/AGGREGATE(聚合)" eg:"DIRECT"`
|
||
ExtractKeyField string `orm:"extract_key_field" json:"extractKeyField" dc:"抽取关键字段(增量依据)" eg:"updated_at"`
|
||
ExtractKeyFormat string `orm:"extract_key_format" json:"extractKeyFormat" dc:"关键字段格式" eg:"yyyy-MM-dd HH:mm:ss"`
|
||
GroupByFields []string `orm:"group_by_fields" json:"groupByFields" dc:"GROUP BY 字段列表"`
|
||
FilterExpression string `orm:"filter_expression" json:"filterExpression" dc:"过滤表达式" eg:"status = 'PAID'"`
|
||
JoinConfigs []JoinConfig `orm:"join_configs" json:"joinConfigs" dc:"JOIN配置"`
|
||
FieldMappings []FieldMapping `orm:"field_mappings" json:"fieldMappings" dc:"字段映射列表"`
|
||
TransformRules []TransformRule `orm:"transform_rules" json:"transformRules" dc:"转换规则列表"`
|
||
BatchSize int `orm:"batch_size" json:"batchSize" dc:"批处理大小" eg:"1000"`
|
||
Status string `orm:"status" json:"status" dc:"status" eg:"ACTIVE"`
|
||
}
|
||
|
||
// ExtractLog 抽取记录(不含 Creator/Updater/DeletedAt,表结构不同)
|
||
type ExtractLog struct {
|
||
ID int64 `orm:"id" json:"id" dc:"主键ID" eg:"1"`
|
||
TenantId uint64 `orm:"tenant_id" json:"tenantId" dc:"租户ID" eg:"1"`
|
||
BusinessCode string `orm:"business_code" json:"businessCode" dc:"业务编码" eg:"KUAISHOU"`
|
||
ReportCode string `orm:"report_code" json:"reportCode" dc:"reportCode" eg:"shop_daily"`
|
||
ExtractCode string `orm:"extract_code" json:"extractCode" dc:"抽取编码" eg:"kuaishou_order_extract"`
|
||
StatDate string `orm:"stat_date" json:"statDate" dc:"统计日期" eg:"2026-06-01"`
|
||
ExtractType string `orm:"extract_type" json:"extractType" dc:"抽取类型 FULL/INCREMENTAL" eg:"INCREMENTAL"`
|
||
Status string `orm:"status" json:"status" dc:"status" eg:"ACTIVE"`
|
||
TotalCount int `orm:"total_count" json:"totalCount" dc:"总记录数" eg:"100"`
|
||
SuccessCount int `orm:"success_count" json:"successCount" dc:"成功记录数" eg:"98"`
|
||
FailCount int `orm:"fail_count" json:"failCount" dc:"失败记录数" eg:"2"`
|
||
StartTime *time.Time `orm:"start_time" json:"startTime" dc:"开始时间"`
|
||
EndTime *time.Time `orm:"end_time" json:"endTime" dc:"结束时间"`
|
||
ErrorMessage string `orm:"error_message" json:"errorMessage" dc:"错误信息"`
|
||
Executor string `orm:"executor" json:"executor" dc:"执行人" eg:"system"`
|
||
CreatedAt *time.Time `orm:"created_at" json:"createdAt" dc:"创建时间"`
|
||
UpdatedAt *time.Time `orm:"updated_at" json:"updatedAt" dc:"更新时间"`
|
||
}
|
||
|
||
// ============================================================
|
||
// 辅助结构
|
||
// ============================================================
|
||
|
||
// JoinConfig 关联配置
|
||
type JoinConfig struct {
|
||
JoinTable string `json:"joinTable" dc:"关联表名" eg:"ods_kuaishou_shop"`
|
||
JoinAlias string `json:"joinAlias" dc:"关联表别名" eg:"s"`
|
||
JoinType string `json:"joinType" dc:"LEFT/RIGHT/INNER" eg:"LEFT"`
|
||
JoinCondition string `json:"joinCondition" dc:"关联条件" eg:"o.shop_id = s.shop_id"`
|
||
FieldMappings []FieldMapping `json:"fieldMappings" dc:"字段映射列表"`
|
||
}
|
||
|
||
// FieldMapping 字段映射
|
||
type FieldMapping struct {
|
||
SourceField string `json:"sourceField" dc:"源字段"`
|
||
TargetField string `json:"targetField" dc:"目标字段"`
|
||
FieldType string `json:"fieldType" dc:"字段类型 STRING/INT/FLOAT/DATE/DATETIME/JSONB" eg:"FLOAT"`
|
||
AggregateFunction string `json:"aggregateFunction" dc:"聚合函数 SUM/COUNT/AVG/MAX/MIN"`
|
||
DefaultValue interface{} `json:"defaultValue" dc:"默认值"`
|
||
TransformRule *TransformRule `json:"transformRule,omitempty" dc:"transformRule"`
|
||
}
|
||
|
||
// TransformRule 转换规则
|
||
type TransformRule struct {
|
||
RuleCode string `json:"ruleCode" dc:"规则编码" eg:"AMOUNT_CONVERT"`
|
||
RuleType string `json:"ruleType" dc:"DIRECT/MAPPING/FORMAT/CALCULATE" eg:"FORMAT"`
|
||
Expression string `json:"expression" dc:"表达式(衍生字段)" eg:"order_amount - refund_amount"`
|
||
Format string `json:"format" dc:"format" eg:"%Y-%m-%d"`
|
||
Mapping map[string]interface{} `json:"mapping" dc:"映射表(MAPPING类型时使用)"`
|
||
}
|
||
|
||
// ============================================================
|
||
// 前端请求/响应结构体
|
||
// ============================================================
|
||
|
||
// UserSelectQueryReq 用户选择查询请求
|
||
type UserSelectQueryReq struct {
|
||
BusinessCode string `json:"businessCode" v:"required" dc:"业务编码" eg:"KUAISHOU"`
|
||
ReportCode string `json:"reportCode" v:"required" dc:"报表编码" eg:"shop_daily"`
|
||
Dimensions []string `json:"dimensions" dc:"统计维度列表,如 shop_id/anchor_id/date"`
|
||
Indicators []IndicatorSelect `json:"indicators" dc:"统计指标列表(含聚合方式)"`
|
||
Filters []FilterCondition `json:"filters" dc:"筛选条件列表"`
|
||
TimeRange *TimeRange `json:"timeRange" dc:"时间范围"`
|
||
TimeGroup string `json:"timeGroup" dc:"时间分组: day/week/month/quarter" eg:"day"`
|
||
OrderBy []OrderCondition `json:"orderBy" dc:"排序条件"`
|
||
Page int `json:"page" dc:"页码" d:"1" eg:"1"`
|
||
PageSize int `json:"pageSize" dc:"每页条数" d:"20" eg:"20"`
|
||
}
|
||
|
||
// IndicatorSelect 指标选择
|
||
type IndicatorSelect struct {
|
||
FieldCode string `json:"fieldCode" dc:"字段编码" eg:"order_amount"`
|
||
Aggregate string `json:"aggregate" dc:"聚合方式: SUM/COUNT/AVG/MAX/MIN" eg:"SUM"`
|
||
Alias string `json:"alias" dc:"别名" eg:"总订单金额"`
|
||
}
|
||
|
||
// FilterCondition 筛选条件
|
||
type FilterCondition struct {
|
||
FieldCode string `json:"fieldCode" dc:"字段编码" eg:"order_amount"`
|
||
Operator string `json:"operator" dc:"操作符: =/!=/>/</>=/<=/IN/LIKE/BETWEEN" eg:"="`
|
||
Value interface{} `json:"value" dc:"值"`
|
||
Value2 interface{} `json:"value2" dc:"第二个值(BETWEEN时使用)"`
|
||
}
|
||
|
||
// TimeRange 时间范围
|
||
type TimeRange struct {
|
||
StartDate string `json:"startDate" dc:"开始日期 yyyy-MM-dd" eg:"2026-06-01"`
|
||
EndDate string `json:"endDate" dc:"结束日期 yyyy-MM-dd" eg:"2026-06-30"`
|
||
}
|
||
|
||
// OrderCondition 排序条件
|
||
type OrderCondition struct {
|
||
FieldCode string `json:"fieldCode" dc:"字段编码" eg:"order_amount"`
|
||
Direction string `json:"direction" dc:"排序方向: ASC/DESC" eg:"DESC"`
|
||
}
|
||
|
||
// UserSelectQueryResp 用户选择查询响应
|
||
type UserSelectQueryResp struct {
|
||
List []map[string]interface{} `json:"list" dc:"数据列表"`
|
||
Total int64 `json:"total" dc:"总数" eg:"100"`
|
||
Page int `json:"page" dc:"当前页" eg:"1"`
|
||
PageSize int `json:"pageSize" dc:"每页条数" eg:"20"`
|
||
TotalPages int `json:"totalPages" dc:"总页数" eg:"5"`
|
||
Sql string `json:"sql,omitempty" dc:"执行的SQL(调试用)" eg:"SELECT 1"`
|
||
ExecTimeMs int64 `json:"execTimeMs" dc:"执行耗时(毫秒)" eg:"1234"`
|
||
}
|
||
|
||
// ExtractDailyDataReq 按天抽取数据请求
|
||
type ExtractDailyDataReq struct {
|
||
BusinessCode string `json:"businessCode" v:"required" dc:"业务编码" eg:"KUAISHOU"`
|
||
ReportCode string `json:"reportCode" v:"required" dc:"报表编码" eg:"shop_daily"`
|
||
StatDate string `json:"statDate" v:"required" dc:"统计日期 yyyy-MM-dd" eg:"2026-06-01"`
|
||
Executor string `json:"executor" dc:"执行人" eg:"system"`
|
||
}
|
||
|
||
// ExtractDailyDataResp 按天抽取数据响应
|
||
type ExtractDailyDataResp struct {
|
||
Success bool `json:"success" dc:"是否成功" eg:"true"`
|
||
TotalCount int `json:"totalCount" dc:"总记录数" eg:"100"`
|
||
SuccessCount int `json:"successCount" dc:"成功记录数" eg:"98"`
|
||
FailCount int `json:"failCount" dc:"失败记录数" eg:"2"`
|
||
ExecTimeMs int64 `json:"execTimeMs" dc:"执行耗时(毫秒)" eg:"1234"`
|
||
ErrorMsg string `json:"errorMsg" dc:"错误信息"`
|
||
}
|
||
|
||
// AutoCreateStatTableReq 自动创建统计宽表请求
|
||
type AutoCreateStatTableReq struct {
|
||
BusinessCode string `json:"businessCode" v:"required" dc:"业务编码" eg:"KUAISHOU"`
|
||
ReportCode string `json:"reportCode" v:"required" dc:"报表编码" eg:"shop_daily"`
|
||
Creator string `json:"creator" dc:"创建人" eg:"admin"`
|
||
}
|
||
|
||
// AutoCreateStatTableResp 自动创建统计宽表响应
|
||
type AutoCreateStatTableResp struct {
|
||
Success bool `json:"success" dc:"是否成功" eg:"true"`
|
||
TableName string `json:"tableName" dc:"创建的表名" eg:"stat_kuaishou_shop_daily"`
|
||
ColumnCount int `json:"columnCount" dc:"字段数量" eg:"15"`
|
||
ExecTimeMs int64 `json:"execTimeMs" dc:"执行耗时(毫秒)" eg:"1234"`
|
||
}
|
||
|
||
// GetReportFieldsResp 获取报表可用字段响应
|
||
type GetReportFieldsResp struct {
|
||
BusinessCode string `json:"businessCode" dc:"业务编码" eg:"KUAISHOU"`
|
||
ReportCode string `json:"reportCode" dc:"报表编码" eg:"shop_daily"`
|
||
Dimensions []FieldConfig `json:"dimensions" dc:"维度字段列表"`
|
||
Indicators []FieldConfig `json:"indicators" dc:"指标字段列表"`
|
||
Filters []FieldConfig `json:"filters" dc:"筛选字段列表"`
|
||
}
|
||
|
||
// BackfillReq 批量回填请求
|
||
type BackfillReq struct {
|
||
BusinessCode string `json:"businessCode" v:"required" dc:"业务编码" eg:"KUAISHOU"`
|
||
ReportCode string `json:"reportCode" v:"required" dc:"报表编码" eg:"shop_daily"`
|
||
StartDate string `json:"startDate" v:"required" dc:"开始日期 yyyy-MM-dd" eg:"2026-06-01"`
|
||
EndDate string `json:"endDate" v:"required" dc:"结束日期 yyyy-MM-dd" eg:"2026-06-30"`
|
||
Executor string `json:"executor" dc:"执行人" eg:"admin"`
|
||
}
|
||
|
||
// BackfillResp 批量回填响应
|
||
type BackfillResp struct {
|
||
Success bool `json:"success" dc:"是否全部成功" eg:"true"`
|
||
TotalDays int `json:"totalDays" dc:"总天数" eg:"30"`
|
||
SuccessDays int `json:"successDays" dc:"成功天数" eg:"28"`
|
||
FailDays int `json:"failDays" dc:"失败天数" eg:"2"`
|
||
ExecTimeMs int64 `json:"execTimeMs" dc:"总耗时(毫秒)" eg:"5678"`
|
||
ErrorMsg string `json:"errorMsg" dc:"错误信息"`
|
||
}
|
||
|
||
// ============================================================
|
||
// 配置 CRUD 请求/响应
|
||
// ============================================================
|
||
|
||
// SaveBusinessReq 保存业务配置请求(新增/修改合一)
|
||
type SaveBusinessReq struct {
|
||
ID *int64 `json:"id" dc:"有值为更新,无值为新增" eg:"1"`
|
||
BusinessCode string `json:"businessCode" v:"required" dc:"业务编码" eg:"KUAISHOU"`
|
||
BusinessName string `json:"businessName" v:"required" dc:"业务名称" eg:"快手电商"`
|
||
Description string `json:"description" dc:"描述" eg:"快手电商店铺每日统计报表"`
|
||
Status string `json:"status" dc:"状态 ACTIVE/INACTIVE" d:"ACTIVE" eg:"ACTIVE"`
|
||
Config map[string]interface{} `json:"config" dc:"扩展配置"`
|
||
Operator string `json:"operator" dc:"操作人" eg:"="`
|
||
}
|
||
|
||
// SaveReportReq 保存报表配置请求
|
||
type SaveReportReq struct {
|
||
ID *int64 `json:"id" dc:"主键ID" eg:"1"`
|
||
BusinessCode string `json:"businessCode" v:"required" dc:"业务编码" eg:"KUAISHOU"`
|
||
ReportCode string `json:"reportCode" v:"required" dc:"报表编码" eg:"shop_daily"`
|
||
ReportName string `json:"reportName" v:"required" dc:"报表名称" eg:"店铺日报"`
|
||
Description string `json:"description" dc:"描述" eg:"快手电商店铺每日统计报表"`
|
||
Status string `json:"status" dc:"状态" d:"ACTIVE" eg:"ACTIVE"`
|
||
StatTableName string `json:"statTableName" v:"required" dc:"统计宽表名"`
|
||
StatTableComment string `json:"statTableComment" dc:"统计宽表注释"`
|
||
DateField string `json:"dateField" dc:"日期字段" d:"stat_date" eg:"stat_date"`
|
||
PrimaryKeys []string `json:"primaryKeys" dc:"主键字段"`
|
||
ConflictKeys []string `json:"conflictKeys" dc:"冲突键(唯一索引)"`
|
||
Config map[string]interface{} `json:"config" dc:"扩展配置"`
|
||
Operator string `json:"operator" dc:"操作人" eg:"="`
|
||
}
|
||
|
||
// SaveFieldReq 保存字段配置请求
|
||
type SaveFieldReq struct {
|
||
ID *int64 `json:"id" dc:"主键ID" eg:"1"`
|
||
BusinessCode string `json:"businessCode" dc:"业务编码" eg:"KUAISHOU"`
|
||
ReportCode string `json:"reportCode" dc:"报表编码" eg:"shop_daily"`
|
||
FieldCode string `json:"fieldCode" v:"required" dc:"字段编码" eg:"order_amount"`
|
||
FieldName string `json:"fieldName" v:"required" dc:"字段名称" eg:"订单金额"`
|
||
FieldType string `json:"fieldType" v:"required" dc:"字段类型 STRING/INT/FLOAT/DATE/DATETIME/JSONB" eg:"FLOAT"`
|
||
DataType string `json:"dataType" dc:"数据存储类型" d:"STRING" eg:"STRING"`
|
||
FieldRole string `json:"fieldRole" v:"required" dc:"字段角色 DIMENSION/INDICATOR/FILTER/FILTER_ONLY" eg:"DIMENSION"`
|
||
IsAggregatable bool `json:"isAggregatable" dc:"是否可聚合" eg:"true"`
|
||
IsFilterable bool `json:"isFilterable" dc:"是否可筛选" d:"true" eg:"true"`
|
||
IsQueryable bool `json:"isQueryable" dc:"是否可查询" d:"true" eg:"true"`
|
||
IsSortable bool `json:"isSortable" dc:"是否可排序" d:"true" eg:"true"`
|
||
DefaultAggregate string `json:"defaultAggregate" dc:"默认聚合方式" eg:"SUM"`
|
||
ValidAggregates []string `json:"validAggregates" dc:"可选聚合列表"`
|
||
FilterOperators []string `json:"filterOperators" dc:"可选操作符列表"`
|
||
Expression string `json:"expression" dc:"表达式(衍生字段)" eg:"order_amount - refund_amount"`
|
||
ExpressionType string `json:"expressionType" dc:"表达式类型 DIRECT/CALCULATED" eg:"DIRECT"`
|
||
FormatPattern string `json:"formatPattern" dc:"格式化模板" eg:"#,##0.00"`
|
||
Unit string `json:"unit" dc:"单位" eg:"元"`
|
||
DictCode string `json:"dictCode" dc:"字典编码" eg:"dict_order_type"`
|
||
SortOrder int `json:"sortOrder" dc:"排序" eg:"1"`
|
||
GroupName string `json:"groupName" dc:"分组名称" eg:"交易指标"`
|
||
Status string `json:"status" dc:"状态" d:"ACTIVE" eg:"ACTIVE"`
|
||
Operator string `json:"operator" dc:"操作人" eg:"admin"`
|
||
}
|
||
|
||
// SaveReportWithFieldsReq 保存报表及字段配置请求(字段全量替换)
|
||
type SaveReportWithFieldsReq struct {
|
||
ID *int64 `json:"id" dc:"主键ID(更新时必填,新建为空)"`
|
||
BusinessCode string `json:"businessCode" v:"required" dc:"业务编码" eg:"KUAISHOU"`
|
||
ReportCode string `json:"reportCode" v:"required" dc:"报表编码" eg:"shop_daily"`
|
||
ReportName string `json:"reportName" v:"required" dc:"报表名称" eg:"店铺日报"`
|
||
Description string `json:"description" dc:"描述" eg:"快手电商店铺每日统计报表"`
|
||
Status string `json:"status" dc:"状态" d:"ACTIVE" eg:"ACTIVE"`
|
||
StatTableName string `json:"statTableName" v:"required" dc:"统计宽表名" eg:"stat_kuaishou_shop_daily"`
|
||
StatTableComment string `json:"statTableComment" dc:"统计宽表注释" eg:"快手电商-店铺日报"`
|
||
DateField string `json:"dateField" dc:"日期字段" d:"stat_date" eg:"stat_date"`
|
||
PrimaryKeys []string `json:"primaryKeys" dc:"主键字段"`
|
||
ConflictKeys []string `json:"conflictKeys" dc:"冲突键(唯一索引)"`
|
||
Config map[string]interface{} `json:"config" dc:"扩展配置"`
|
||
Fields []SaveFieldReq `json:"fields" dc:"字段配置列表(全量替换,不在列表中的字段将被删除)"`
|
||
}
|
||
|
||
// SaveExtractConfigReq 保存抽取配置请求
|
||
type SaveExtractConfigReq struct {
|
||
ID *int64 `json:"id" dc:"主键ID" eg:"1"`
|
||
BusinessCode string `json:"businessCode" v:"required" dc:"业务编码" eg:"KUAISHOU"`
|
||
ReportCode string `json:"reportCode" v:"required" dc:"报表编码" eg:"shop_daily"`
|
||
ExtractCode string `json:"extractCode" v:"required" dc:"抽取编码" eg:"kuaishou_order_extract"`
|
||
ExtractName string `json:"extractName" v:"required" dc:"抽取名称" eg:"订单抽取"`
|
||
SourceTableName string `json:"sourceTableName" v:"required" dc:"源表名" eg:"ods_kuaishou_order"`
|
||
SourceTableAlias string `json:"sourceTableAlias" dc:"源表别名" eg:"o"`
|
||
TargetTableName string `json:"targetTableName" v:"required" dc:"目标表名" eg:"stat_kuaishou_shop_daily"`
|
||
IsEnabled bool `json:"isEnabled" dc:"是否启用" d:"true" eg:"true"`
|
||
ExtractType string `json:"extractType" dc:"抽取类型 FULL/INCREMENTAL" d:"INCREMENTAL" eg:"INCREMENTAL"`
|
||
ExtractMode string `json:"extractMode" dc:"抽取模式 DIRECT/AGGREGATE" d:"DIRECT" eg:"DIRECT"`
|
||
ExtractKeyField string `json:"extractKeyField" dc:"抽取关键字段(增量依据)" eg:"updated_at"`
|
||
ExtractKeyFormat string `json:"extractKeyFormat" dc:"关键字段格式" eg:"yyyy-MM-dd HH:mm:ss"`
|
||
GroupByFields []string `json:"groupByFields" dc:"GROUP BY 字段列表"`
|
||
FilterExpression string `json:"filterExpression" dc:"过滤表达式" eg:"status = 'PAID'"`
|
||
JoinConfigs []JoinConfig `json:"joinConfigs" dc:"JOIN配置"`
|
||
FieldMappings []FieldMapping `json:"fieldMappings" dc:"字段映射列表"`
|
||
TransformRules []TransformRule `json:"transformRules" dc:"转换规则列表"`
|
||
BatchSize int `json:"batchSize" dc:"批处理大小" d:"1000" eg:"1000"`
|
||
Status string `json:"status" dc:"状态" d:"ACTIVE" eg:"ACTIVE"`
|
||
Operator string `json:"operator" dc:"操作人" eg:"="`
|
||
}
|
||
|
||
// PageReq 分页请求参数
|
||
type PageReq struct {
|
||
PageNum int `json:"pageNum" d:"1" dc:"页码"`
|
||
PageSize int `json:"pageSize" d:"20" dc:"每页条数"`
|
||
}
|
||
|
||
// PageRes 分页响应
|
||
type PageRes struct {
|
||
Total int `json:"total" dc:"总数"`
|
||
Page int `json:"page" dc:"当前页"`
|
||
PageSize int `json:"pageSize" dc:"每页条数"`
|
||
TotalPages int `json:"totalPages" dc:"总页数"`
|
||
}
|
||
|
||
// IdReq 通用 ID 请求
|
||
type IdReq struct {
|
||
ID int64 `json:"id" v:"required" dc:"主键ID" eg:"1"`
|
||
}
|
||
|
||
// SaveResult 写操作通用返回
|
||
type SaveResult struct {
|
||
Success bool `json:"success" dc:"是否成功" eg:"true"`
|
||
ID int64 `json:"id" dc:"主键ID" eg:"1"`
|
||
Message string `json:"message" dc:"结果消息" eg:"操作成功"`
|
||
}
|
||
|
||
// DeleteResult 删除结果
|
||
type DeleteResult struct {
|
||
Success bool `json:"success" dc:"是否成功" eg:"true"`
|
||
Message string `json:"message" dc:"结果消息" eg:"操作成功"`
|
||
}
|
||
|
||
// GetExtractConfigsReq 获取抽取配置列表请求
|
||
type GetExtractConfigsReq struct {
|
||
BusinessCode string `json:"businessCode" v:"required" dc:"业务编码" eg:"KUAISHOU"`
|
||
ReportCode string `json:"reportCode" v:"required" dc:"报表编码" eg:"shop_daily"`
|
||
}
|
||
|
||
// ============================================================
|
||
// 常量定义
|
||
// ============================================================
|
||
|
||
const (
|
||
// 状态
|
||
StatusActive = "ACTIVE"
|
||
StatusInactive = "INACTIVE"
|
||
|
||
// 字段角色
|
||
RoleDimension = "DIMENSION"
|
||
RoleIndicator = "INDICATOR"
|
||
RoleFilter = "FILTER"
|
||
RoleFilterOnly = "FILTER_ONLY"
|
||
|
||
// 字段类型
|
||
FieldTypeString = "STRING"
|
||
FieldTypeInt = "INT"
|
||
FieldTypeFloat = "FLOAT"
|
||
FieldTypeDate = "DATE"
|
||
FieldTypeDatetime = "DATETIME"
|
||
FieldTypeJsonb = "JSONB"
|
||
|
||
// 聚合方式
|
||
AggregateSum = "SUM"
|
||
AggregateCount = "COUNT"
|
||
AggregateAvg = "AVG"
|
||
AggregateMax = "MAX"
|
||
AggregateMin = "MIN"
|
||
|
||
// 操作符
|
||
OperatorEq = "="
|
||
OperatorNe = "!="
|
||
OperatorGt = ">"
|
||
OperatorLt = "<"
|
||
OperatorGe = ">="
|
||
OperatorLe = "<="
|
||
OperatorIn = "IN"
|
||
OperatorLike = "LIKE"
|
||
OperatorBetween = "BETWEEN"
|
||
|
||
// 抽取类型
|
||
ExtractTypeFull = "FULL"
|
||
ExtractTypeIncremental = "INCREMENTAL"
|
||
|
||
// 抽取模式
|
||
ExtractModeDirect = "DIRECT" // 逐行抽取(默认,源表每行 → 宽表一行)
|
||
ExtractModeAggregate = "AGGREGATE" // 聚合抽取(按 GROUP BY 聚合,SUM/COUNT/AVG)
|
||
|
||
// 抽取状态
|
||
ExtractStatusRunning = "RUNNING"
|
||
ExtractStatusSuccess = "SUCCESS"
|
||
ExtractStatusFailed = "FAILED"
|
||
)
|
||
|
||
// FieldTypeToPG 字段类型转PG列类型定义
|
||
func FieldTypeToPG(fieldType string) string {
|
||
switch fieldType {
|
||
case FieldTypeInt:
|
||
return "NUMERIC(20,0) DEFAULT 0"
|
||
case FieldTypeFloat:
|
||
return "NUMERIC(20,4) DEFAULT 0"
|
||
case FieldTypeDate:
|
||
return "VARCHAR(16) DEFAULT ''"
|
||
case FieldTypeDatetime:
|
||
return "TIMESTAMP WITH TIME ZONE"
|
||
case FieldTypeJsonb:
|
||
return "JSONB DEFAULT '{}'"
|
||
default:
|
||
return "VARCHAR(256) DEFAULT ''"
|
||
}
|
||
}
|