rwadurian/backend/services/authorization-service/prisma/schema.prisma

375 lines
13 KiB
Plaintext
Raw Blame History

This file contains ambiguous Unicode characters

This file contains Unicode characters that might be confused with other characters. If you think that this is intentional, you can safely ignore this warning. Use the Escape button to reveal them.

// This is your Prisma schema file,
// learn more about it in the docs: https://pris.ly/d/prisma-schema
generator client {
provider = "prisma-client-js"
}
datasource db {
provider = "postgresql"
url = env("DATABASE_URL")
}
// ============ 授权角色表 ============
model AuthorizationRole {
id String @id @default(uuid())
userId String @map("user_id")
roleType RoleType @map("role_type")
regionCode String @map("region_code")
regionName String @map("region_name")
status AuthorizationStatus @default(PENDING)
displayTitle String @map("display_title")
// 授权信息
authorizedAt DateTime? @map("authorized_at")
authorizedBy String? @map("authorized_by")
revokedAt DateTime? @map("revoked_at")
revokedBy String? @map("revoked_by")
revokeReason String? @map("revoke_reason")
// 考核配置
initialTargetTreeCount Int @map("initial_target_tree_count")
monthlyTargetType MonthlyTargetType @map("monthly_target_type")
// 自有团队占比
requireLocalPercentage Decimal @default(5.0) @map("require_local_percentage") @db.Decimal(5, 2)
exemptFromPercentageCheck Boolean @default(false) @map("exempt_from_percentage_check")
// 权益状态
benefitActive Boolean @default(false) @map("benefit_active")
benefitActivatedAt DateTime? @map("benefit_activated_at")
benefitDeactivatedAt DateTime? @map("benefit_deactivated_at")
// 当前考核月份索引
currentMonthIndex Int @default(0) @map("current_month_index")
// 时间戳
createdAt DateTime @default(now()) @map("created_at")
updatedAt DateTime @updatedAt @map("updated_at")
// 关联
assessments MonthlyAssessment[]
bypassRecords MonthlyBypass[]
@@unique([userId, roleType, regionCode])
@@index([userId])
@@index([roleType, regionCode])
@@index([status])
@@index([roleType, status])
@@map("authorization_roles")
}
// ============ 月度考核表 ============
model MonthlyAssessment {
id String @id @default(uuid())
authorizationId String @map("authorization_id")
userId String @map("user_id")
roleType RoleType @map("role_type")
regionCode String @map("region_code")
// 考核月份
assessmentMonth String @map("assessment_month") // YYYY-MM
monthIndex Int @map("month_index") // 第几个月考核
// 考核目标
monthlyTarget Int @map("monthly_target")
cumulativeTarget Int @map("cumulative_target")
// 完成情况
monthlyCompleted Int @default(0) @map("monthly_completed")
cumulativeCompleted Int @default(0) @map("cumulative_completed")
completedAt DateTime? @map("completed_at") // 达标时间(用于排名)
// 自有团队占比
localTeamCount Int @default(0) @map("local_team_count")
totalTeamCount Int @default(0) @map("total_team_count")
localPercentage Decimal @default(0) @map("local_percentage") @db.Decimal(5, 2)
localPercentagePass Boolean @default(false) @map("local_percentage_pass")
// 超越目标占比
exceedRatio Decimal @default(0) @map("exceed_ratio") @db.Decimal(10, 4)
// 考核结果
result AssessmentResult @default(NOT_ASSESSED)
// 排名
rankingInRegion Int? @map("ranking_in_region")
isFirstPlace Boolean @default(false) @map("is_first_place")
// 豁免
isBypassed Boolean @default(false) @map("is_bypassed")
bypassedBy String? @map("bypassed_by")
bypassedAt DateTime? @map("bypassed_at")
// 时间戳
assessedAt DateTime? @map("assessed_at")
createdAt DateTime @default(now()) @map("created_at")
updatedAt DateTime @updatedAt @map("updated_at")
// 关联
authorization AuthorizationRole @relation(fields: [authorizationId], references: [id])
@@unique([authorizationId, assessmentMonth])
@@index([userId, assessmentMonth])
@@index([roleType, regionCode, assessmentMonth])
@@index([assessmentMonth, result])
@@index([assessmentMonth, roleType, exceedRatio(sort: Desc)])
@@map("monthly_assessments")
}
// ============ 单月豁免记录表 ============
model MonthlyBypass {
id String @id @default(uuid())
authorizationId String @map("authorization_id")
userId String @map("user_id")
roleType RoleType @map("role_type")
bypassMonth String @map("bypass_month") // YYYY-MM
// 授权信息
grantedBy String @map("granted_by")
grantedAt DateTime @map("granted_at")
reason String?
// 审批信息(三人授权)
approver1Id String @map("approver1_id")
approver1At DateTime @map("approver1_at")
approver2Id String? @map("approver2_id")
approver2At DateTime? @map("approver2_at")
approver3Id String? @map("approver3_id")
approver3At DateTime? @map("approver3_at")
approvalStatus ApprovalStatus @default(PENDING) @map("approval_status")
createdAt DateTime @default(now()) @map("created_at")
authorization AuthorizationRole @relation(fields: [authorizationId], references: [id])
@@unique([authorizationId, bypassMonth])
@@index([userId, bypassMonth])
@@map("monthly_bypasses")
}
// ============ 阶梯考核目标配置表 ============
model LadderTargetConfig {
id String @id @default(uuid())
roleType RoleType @map("role_type")
monthIndex Int @map("month_index")
monthlyTarget Int @map("monthly_target")
cumulativeTarget Int @map("cumulative_target")
isActive Boolean @default(true) @map("is_active")
createdAt DateTime @default(now()) @map("created_at")
updatedAt DateTime @updatedAt @map("updated_at")
@@unique([roleType, monthIndex])
@@map("ladder_target_configs")
}
// ============ 认种限制配置表 ============
model PlantingRestriction {
id String @id @default(uuid())
restrictionType RestrictionType @map("restriction_type")
// 账户限制配置
accountLimitDays Int? @map("account_limit_days")
accountLimitCount Int? @map("account_limit_count")
// 总量限制配置
totalLimitDays Int? @map("total_limit_days")
totalLimitCount Int? @map("total_limit_count")
currentTotalCount Int @default(0) @map("current_total_count")
// 生效时间
startAt DateTime @map("start_at")
endAt DateTime @map("end_at")
isActive Boolean @default(true) @map("is_active")
createdBy String @map("created_by")
createdAt DateTime @default(now()) @map("created_at")
updatedAt DateTime @updatedAt @map("updated_at")
@@map("planting_restrictions")
}
// ============ 管理员授权审批表 ============
model AdminApproval {
id String @id @default(uuid())
operationType OperationType @map("operation_type")
targetId String @map("target_id")
targetType String @map("target_type")
requestData Json @map("request_data")
// 审批状态
status ApprovalStatus @default(PENDING)
// 审批人
requesterId String @map("requester_id")
approver1Id String? @map("approver1_id")
approver1At DateTime? @map("approver1_at")
approver2Id String? @map("approver2_id")
approver2At DateTime? @map("approver2_at")
approver3Id String? @map("approver3_id")
approver3At DateTime? @map("approver3_at")
// 完成信息
completedAt DateTime? @map("completed_at")
rejectedBy String? @map("rejected_by")
rejectedAt DateTime? @map("rejected_at")
rejectReason String? @map("reject_reason")
createdAt DateTime @default(now()) @map("created_at")
updatedAt DateTime @updatedAt @map("updated_at")
@@index([status])
@@index([targetId, targetType])
@@map("admin_approvals")
}
// ============ 授权操作日志表 ============
model AuthorizationAuditLog {
id String @id @default(uuid())
operationType String @map("operation_type")
targetUserId String @map("target_user_id")
targetRoleType RoleType? @map("target_role_type")
targetRegionCode String? @map("target_region_code")
operatorId String @map("operator_id")
operatorRole String @map("operator_role")
beforeState Json? @map("before_state")
afterState Json? @map("after_state")
ipAddress String? @map("ip_address")
userAgent String? @map("user_agent")
createdAt DateTime @default(now()) @map("created_at")
@@index([targetUserId])
@@index([operatorId])
@@index([createdAt])
@@map("authorization_audit_logs")
}
// ============ 省市热度统计表 ============
model RegionHeatMap {
id String @id @default(uuid())
regionCode String @map("region_code")
regionName String @map("region_name")
regionType RegionType @map("region_type")
totalPlantings Int @default(0) @map("total_plantings")
monthlyPlantings Int @default(0) @map("monthly_plantings")
weeklyPlantings Int @default(0) @map("weekly_plantings")
dailyPlantings Int @default(0) @map("daily_plantings")
activeUsers Int @default(0) @map("active_users")
authCompanyCount Int @default(0) @map("auth_company_count")
heatScore Decimal @default(0) @map("heat_score") @db.Decimal(10, 2)
updatedAt DateTime @updatedAt @map("updated_at")
@@unique([regionCode, regionType])
@@map("region_heat_maps")
}
// ============ 火柴人排名视图数据表 ============
model StickmanRanking {
id String @id @default(uuid())
userId String @map("user_id")
authorizationId String @map("authorization_id")
roleType RoleType @map("role_type")
regionCode String @map("region_code")
regionName String @map("region_name")
// 用户信息
nickname String
avatarUrl String? @map("avatar_url")
// 进度信息
currentMonth String @map("current_month")
cumulativeCompleted Int @map("cumulative_completed")
cumulativeTarget Int @map("cumulative_target")
progressPercentage Decimal @map("progress_percentage") @db.Decimal(5, 2)
exceedRatio Decimal @map("exceed_ratio") @db.Decimal(10, 4)
// 排名
ranking Int
isFirstPlace Boolean @map("is_first_place")
// 本月收益
monthlyRewardUsdt Decimal @map("monthly_reward_usdt") @db.Decimal(18, 2)
monthlyRewardRwad Decimal @map("monthly_reward_rwad") @db.Decimal(18, 8)
updatedAt DateTime @updatedAt @map("updated_at")
@@unique([authorizationId, currentMonth])
@@index([roleType, regionCode, currentMonth])
@@map("stickman_rankings")
}
// ============ 系统配置表 ============
model AuthorizationConfig {
id String @id @default(uuid())
configKey String @unique @map("config_key")
configValue String @map("config_value")
description String?
isActive Boolean @default(true) @map("is_active")
createdAt DateTime @default(now()) @map("created_at")
updatedAt DateTime @updatedAt @map("updated_at")
@@map("authorization_configs")
}
// ============ 枚举定义 ============
enum RoleType {
COMMUNITY // 社区
AUTH_PROVINCE_COMPANY // 授权省公司团队权益20U
PROVINCE_COMPANY // 正式省公司区域权益15U+1%算力)
AUTH_CITY_COMPANY // 授权市公司团队权益40U
CITY_COMPANY // 正式市公司区域权益35U+2%算力)
}
enum AuthorizationStatus {
PENDING // 待授权/待考核
AUTHORIZED // 已授权
REVOKED // 已撤销
}
enum AssessmentResult {
NOT_ASSESSED // 未考核
PASS // 达标
FAIL // 未达标
BYPASSED // 豁免
}
enum MonthlyTargetType {
NONE // 无月度考核(正式省市公司)
FIXED // 固定目标社区10棵/月)
LADDER // 阶梯目标(授权省市公司)
}
enum RestrictionType {
ACCOUNT_LIMIT // 账户限时限量
TOTAL_LIMIT // 总量限制
}
enum ApprovalStatus {
PENDING // 待审批
APPROVED // 已通过
REJECTED // 已拒绝
}
enum OperationType {
GRANT_AUTHORIZATION // 授予授权
REVOKE_AUTHORIZATION // 撤销授权
GRANT_BYPASS // 授予豁免
EXEMPT_PERCENTAGE // 豁免占比考核
MODIFY_CONFIG // 修改配置
}
enum RegionType {
PROVINCE // 省
CITY // 市
}