init: 初始框架
This commit is contained in:
543
proto/cloudprint.proto
Normal file
543
proto/cloudprint.proto
Normal file
@@ -0,0 +1,543 @@
|
||||
syntax = "proto3";
|
||||
|
||||
package cloudprint;
|
||||
|
||||
option go_package = "github.com/cloudprint/cloudprint-backend/proto/generated";
|
||||
|
||||
import "google/protobuf/empty.proto";
|
||||
import "google/protobuf/timestamp.proto";
|
||||
|
||||
// ============ 通用消息 ============
|
||||
|
||||
message Empty {}
|
||||
|
||||
message StatusResponse {
|
||||
int32 code = 1;
|
||||
string message = 2;
|
||||
}
|
||||
|
||||
// ============ 用户相关 ============
|
||||
|
||||
message User {
|
||||
int32 id = 1;
|
||||
string openid = 2;
|
||||
string nickname = 3;
|
||||
string avatar = 4;
|
||||
double balance = 5;
|
||||
google.protobuf.Timestamp created_at = 6;
|
||||
}
|
||||
|
||||
message LoginRequest {
|
||||
string code = 1; // 微信授权码
|
||||
}
|
||||
|
||||
message LoginResponse {
|
||||
string access_token = 1;
|
||||
string refresh_token = 2;
|
||||
User user = 3;
|
||||
}
|
||||
|
||||
message RefreshRequest {
|
||||
string refresh_token = 1;
|
||||
}
|
||||
|
||||
message RefreshResponse {
|
||||
string access_token = 1;
|
||||
}
|
||||
|
||||
message GetUserInfoRequest {}
|
||||
|
||||
message UpdateUserRequest {
|
||||
string nickname = 1;
|
||||
string avatar = 2;
|
||||
}
|
||||
|
||||
// ============ 文件相关 ============
|
||||
|
||||
message FileInfo {
|
||||
int32 id = 1;
|
||||
string file_name = 2;
|
||||
string file_path = 3;
|
||||
string file_type = 4;
|
||||
int64 file_size = 5;
|
||||
string uploader_type = 6;
|
||||
int32 uploader_id = 7;
|
||||
google.protobuf.Timestamp created_at = 8;
|
||||
}
|
||||
|
||||
message UploadRequest {
|
||||
string file_name = 1;
|
||||
string file_type = 2;
|
||||
int64 file_size = 3;
|
||||
bytes data = 4;
|
||||
bool is_last_chunk = 5;
|
||||
string chunk_id = 6;
|
||||
int32 chunk_index = 7;
|
||||
int32 total_chunks = 8;
|
||||
}
|
||||
|
||||
message UploadResponse {
|
||||
int32 file_id = 1;
|
||||
string file_path = 2;
|
||||
string file_url = 3;
|
||||
}
|
||||
|
||||
message GetFileRequest {
|
||||
int32 file_id = 1;
|
||||
}
|
||||
|
||||
message FileData {
|
||||
bytes data = 1;
|
||||
bool is_last = 2;
|
||||
}
|
||||
|
||||
message DeleteFileRequest {
|
||||
int32 file_id = 1;
|
||||
}
|
||||
|
||||
message WatermarkRequest {
|
||||
int32 file_id = 1;
|
||||
string text = 2;
|
||||
float opacity = 3;
|
||||
int32 position = 4; // 1: 左上 2: 右上 3: 左下 4: 右下 5: 居中
|
||||
int32 font_size = 5;
|
||||
}
|
||||
|
||||
message WatermarkResponse {
|
||||
int32 file_id = 1;
|
||||
string file_path = 2;
|
||||
}
|
||||
|
||||
message GetFileListRequest {
|
||||
string uploader_type = 1;
|
||||
int32 uploader_id = 2;
|
||||
int32 page = 3;
|
||||
int32 page_size = 4;
|
||||
}
|
||||
|
||||
message FileListResponse {
|
||||
repeated FileInfo files = 1;
|
||||
int32 total = 2;
|
||||
}
|
||||
|
||||
// ============ 订单相关 ============
|
||||
|
||||
message Order {
|
||||
int32 id = 1;
|
||||
string order_no = 2;
|
||||
int32 user_id = 3;
|
||||
int32 status = 4;
|
||||
double total_amount = 5;
|
||||
string remark = 6;
|
||||
google.protobuf.Timestamp created_at = 7;
|
||||
google.protobuf.Timestamp paid_at = 8;
|
||||
repeated OrderItem items = 9;
|
||||
}
|
||||
|
||||
message OrderItem {
|
||||
int32 id = 1;
|
||||
int32 order_id = 2;
|
||||
int32 file_id = 3;
|
||||
FileInfo file = 4;
|
||||
int32 printer_id = 5;
|
||||
int32 copies = 6;
|
||||
bool color = 7;
|
||||
bool duplex = 8;
|
||||
string page_range = 9;
|
||||
double price = 10;
|
||||
}
|
||||
|
||||
message CreateOrderRequest {
|
||||
repeated CreateOrderItem items = 1;
|
||||
string remark = 2;
|
||||
}
|
||||
|
||||
message CreateOrderItem {
|
||||
int32 file_id = 1;
|
||||
int32 printer_id = 2;
|
||||
int32 copies = 3;
|
||||
bool color = 4;
|
||||
bool duplex = 5;
|
||||
string page_range = 6;
|
||||
}
|
||||
|
||||
message CreateOrderResponse {
|
||||
string order_no = 1;
|
||||
double total_amount = 2;
|
||||
}
|
||||
|
||||
message GetOrderRequest {
|
||||
string order_no = 1;
|
||||
}
|
||||
|
||||
message GetOrderListRequest {
|
||||
int32 user_id = 1;
|
||||
int32 status = 2;
|
||||
int32 page = 3;
|
||||
int32 page_size = 4;
|
||||
}
|
||||
|
||||
message OrderListResponse {
|
||||
repeated Order orders = 1;
|
||||
int32 total = 2;
|
||||
}
|
||||
|
||||
message UpdateOrderStatusRequest {
|
||||
string order_no = 1;
|
||||
int32 status = 2;
|
||||
}
|
||||
|
||||
message CancelOrderRequest {
|
||||
string order_no = 1;
|
||||
}
|
||||
|
||||
// ============ 打印机相关 ============
|
||||
|
||||
message Printer {
|
||||
int32 id = 1;
|
||||
string name = 2;
|
||||
string display_name = 3;
|
||||
bool is_active = 4;
|
||||
int32 status = 5; // 0: 空闲 1: 打印中 2: 离线
|
||||
google.protobuf.Timestamp last_heartbeat = 6;
|
||||
}
|
||||
|
||||
message GetPrintersRequest {}
|
||||
|
||||
message PrinterListResponse {
|
||||
repeated Printer printers = 1;
|
||||
}
|
||||
|
||||
message GetPrinterStatusRequest {
|
||||
int32 printer_id = 1;
|
||||
}
|
||||
|
||||
message PrinterStatusResponse {
|
||||
Printer printer = 1;
|
||||
int32 queue_count = 2;
|
||||
}
|
||||
|
||||
message RegisterPrinterRequest {
|
||||
string name = 1;
|
||||
string display_name = 2;
|
||||
string api_key = 3;
|
||||
}
|
||||
|
||||
message RegisterPrinterResponse {
|
||||
int32 printer_id = 1;
|
||||
string token = 2;
|
||||
}
|
||||
|
||||
message PrinterHeartbeatRequest {
|
||||
int32 printer_id = 1;
|
||||
int32 status = 2;
|
||||
string token = 3;
|
||||
}
|
||||
|
||||
// ============ 打印任务相关 ============
|
||||
|
||||
message PrintJob {
|
||||
int32 id = 1;
|
||||
string job_no = 2;
|
||||
int32 printer_id = 3;
|
||||
int32 order_item_id = 4;
|
||||
string status = 5; // pending/printing/completed/failed/cancelled
|
||||
int32 progress = 6;
|
||||
string error_msg = 7;
|
||||
google.protobuf.Timestamp started_at = 8;
|
||||
google.protobuf.Timestamp completed_at = 9;
|
||||
OrderItem order_item = 10;
|
||||
}
|
||||
|
||||
message SubmitPrintJobRequest {
|
||||
int32 order_item_id = 1;
|
||||
int32 printer_id = 2;
|
||||
string file_path = 3;
|
||||
int32 copies = 4;
|
||||
bool color = 5;
|
||||
bool duplex = 6;
|
||||
string page_range = 7;
|
||||
}
|
||||
|
||||
message SubmitPrintJobResponse {
|
||||
string job_no = 1;
|
||||
}
|
||||
|
||||
message CancelPrintJobRequest {
|
||||
string job_no = 1;
|
||||
}
|
||||
|
||||
message SubscribeJobsRequest {
|
||||
int32 printer_id = 1;
|
||||
string token = 2;
|
||||
}
|
||||
|
||||
message ReportJobStatusRequest {
|
||||
string job_no = 1;
|
||||
string status = 2;
|
||||
int32 progress = 3;
|
||||
string error_msg = 4;
|
||||
}
|
||||
|
||||
// ============ 文库相关 ============
|
||||
|
||||
message LibraryCategory {
|
||||
int32 id = 1;
|
||||
string name = 2;
|
||||
string icon = 3;
|
||||
int32 sort_order = 4;
|
||||
}
|
||||
|
||||
message LibraryFile {
|
||||
int32 id = 1;
|
||||
int32 category_id = 2;
|
||||
int32 file_id = 3;
|
||||
string title = 4;
|
||||
string description = 5;
|
||||
int32 page_count = 6;
|
||||
int32 download_count = 7;
|
||||
FileInfo file = 8;
|
||||
google.protobuf.Timestamp created_at = 9;
|
||||
}
|
||||
|
||||
message GetCategoriesRequest {}
|
||||
|
||||
message CategoryListResponse {
|
||||
repeated LibraryCategory categories = 1;
|
||||
}
|
||||
|
||||
message GetLibraryFilesRequest {
|
||||
int32 category_id = 1;
|
||||
int32 page = 2;
|
||||
int32 page_size = 3;
|
||||
}
|
||||
|
||||
message LibraryFileListResponse {
|
||||
repeated LibraryFile files = 1;
|
||||
int32 total = 2;
|
||||
}
|
||||
|
||||
message UploadLibraryFileRequest {
|
||||
int32 category_id = 1;
|
||||
string title = 2;
|
||||
string description = 3;
|
||||
bytes data = 4;
|
||||
string file_name = 5;
|
||||
string file_type = 6;
|
||||
}
|
||||
|
||||
message UploadLibraryFileResponse {
|
||||
int32 library_file_id = 1;
|
||||
}
|
||||
|
||||
message DeleteLibraryFileRequest {
|
||||
int32 library_file_id = 1;
|
||||
}
|
||||
|
||||
// ============ 价目表相关 ============
|
||||
|
||||
message PriceItem {
|
||||
int32 id = 1;
|
||||
string name = 2;
|
||||
string type = 3;
|
||||
double price = 4;
|
||||
string unit = 5;
|
||||
bool color_enabled = 6;
|
||||
bool is_active = 7;
|
||||
}
|
||||
|
||||
message GetPriceListRequest {}
|
||||
|
||||
message PriceListResponse {
|
||||
repeated PriceItem items = 1;
|
||||
}
|
||||
|
||||
message CreatePriceItemRequest {
|
||||
string name = 1;
|
||||
string type = 2;
|
||||
double price = 3;
|
||||
string unit = 4;
|
||||
bool color_enabled = 5;
|
||||
}
|
||||
|
||||
message UpdatePriceItemRequest {
|
||||
int32 id = 1;
|
||||
string name = 2;
|
||||
string type = 3;
|
||||
double price = 4;
|
||||
string unit = 5;
|
||||
bool color_enabled = 6;
|
||||
bool is_active = 7;
|
||||
}
|
||||
|
||||
// ============ 支付相关 ============
|
||||
|
||||
message WxPayRequest {
|
||||
string order_no = 1;
|
||||
double amount = 2;
|
||||
string description = 3;
|
||||
string openid = 4;
|
||||
string client_ip = 5;
|
||||
}
|
||||
|
||||
message WxPayResponse {
|
||||
string prepay_id = 1;
|
||||
string code_url = 2;
|
||||
string mweb_url = 3;
|
||||
}
|
||||
|
||||
message QueryPayStatusRequest {
|
||||
string order_no = 1;
|
||||
}
|
||||
|
||||
message PayStatusResponse {
|
||||
int32 status = 1; // 0: 待支付 1: 支付中 2: 成功 3: 失败
|
||||
string transaction_id = 2;
|
||||
}
|
||||
|
||||
message PayCallbackRequest {
|
||||
string body = 1;
|
||||
}
|
||||
|
||||
message PayCallbackResponse {
|
||||
string return_code = 1;
|
||||
string return_msg = 2;
|
||||
}
|
||||
|
||||
message PayByBalanceRequest {
|
||||
string order_no = 1;
|
||||
int32 user_id = 2;
|
||||
}
|
||||
|
||||
// ============ 管理后台相关 ============
|
||||
|
||||
message Admin {
|
||||
int32 id = 1;
|
||||
string username = 2;
|
||||
string nickname = 3;
|
||||
int32 role = 4;
|
||||
google.protobuf.Timestamp created_at = 5;
|
||||
}
|
||||
|
||||
message AdminLoginRequest {
|
||||
string username = 1;
|
||||
string password = 2;
|
||||
}
|
||||
|
||||
message AdminLoginResponse {
|
||||
string access_token = 1;
|
||||
Admin admin = 2;
|
||||
}
|
||||
|
||||
message GetStatisticsRequest {}
|
||||
|
||||
message Statistics {
|
||||
int32 total_users = 1;
|
||||
int32 total_orders = 2;
|
||||
int32 today_orders = 3;
|
||||
double today_revenue = 4;
|
||||
int32 pending_orders = 5;
|
||||
int32 active_printers = 6;
|
||||
}
|
||||
|
||||
// 创建管理员请求
|
||||
message CreateAdminRequest {
|
||||
string username = 1;
|
||||
string password = 2;
|
||||
string nickname = 3;
|
||||
int32 role = 4; // 1:普通管理员 2:超级管理员
|
||||
}
|
||||
|
||||
// 创建管理员响应
|
||||
message CreateAdminResponse {
|
||||
Admin admin = 1;
|
||||
}
|
||||
|
||||
// 获取管理员列表请求
|
||||
message GetAdminListRequest {
|
||||
int32 page = 1;
|
||||
int32 page_size = 2;
|
||||
}
|
||||
|
||||
// 管理员列表响应
|
||||
message AdminListResponse {
|
||||
repeated Admin admins = 1;
|
||||
int32 total = 2;
|
||||
}
|
||||
|
||||
// 更新管理员请求
|
||||
message UpdateAdminRequest {
|
||||
int32 id = 1;
|
||||
string nickname = 2;
|
||||
int32 role = 3;
|
||||
}
|
||||
|
||||
// 删除管理员请求
|
||||
message DeleteAdminRequest {
|
||||
int32 id = 1;
|
||||
}
|
||||
|
||||
// ============ 服务定义 ============
|
||||
|
||||
service AuthService {
|
||||
rpc Login(LoginRequest) returns (LoginResponse);
|
||||
rpc RefreshToken(RefreshRequest) returns (RefreshResponse);
|
||||
rpc GetUserInfo(GetUserInfoRequest) returns (User);
|
||||
rpc UpdateUser(UpdateUserRequest) returns (User);
|
||||
}
|
||||
|
||||
service FileService {
|
||||
rpc Upload(stream UploadRequest) returns (UploadResponse);
|
||||
rpc GetFile(GetFileRequest) returns (stream FileData);
|
||||
rpc DeleteFile(DeleteFileRequest) returns (Empty);
|
||||
rpc AddWatermark(WatermarkRequest) returns (WatermarkResponse);
|
||||
rpc GetFileList(GetFileListRequest) returns (FileListResponse);
|
||||
}
|
||||
|
||||
service OrderService {
|
||||
rpc CreateOrder(CreateOrderRequest) returns (CreateOrderResponse);
|
||||
rpc GetOrder(GetOrderRequest) returns (Order);
|
||||
rpc GetOrderList(GetOrderListRequest) returns (OrderListResponse);
|
||||
rpc UpdateOrderStatus(UpdateOrderStatusRequest) returns (Empty);
|
||||
rpc CancelOrder(CancelOrderRequest) returns (Empty);
|
||||
}
|
||||
|
||||
service PrintService {
|
||||
rpc GetPrinters(GetPrintersRequest) returns (PrinterListResponse);
|
||||
rpc GetPrinterStatus(GetPrinterStatusRequest) returns (PrinterStatusResponse);
|
||||
rpc RegisterPrinter(RegisterPrinterRequest) returns (RegisterPrinterResponse);
|
||||
rpc PrinterHeartbeat(PrinterHeartbeatRequest) returns (Empty);
|
||||
rpc SubmitPrintJob(SubmitPrintJobRequest) returns (SubmitPrintJobResponse);
|
||||
rpc CancelPrintJob(CancelPrintJobRequest) returns (Empty);
|
||||
rpc SubscribeJobs(SubscribeJobsRequest) returns (stream PrintJob);
|
||||
rpc ReportJobStatus(ReportJobStatusRequest) returns (Empty);
|
||||
}
|
||||
|
||||
service LibraryService {
|
||||
rpc GetCategories(GetCategoriesRequest) returns (CategoryListResponse);
|
||||
rpc GetFiles(GetLibraryFilesRequest) returns (LibraryFileListResponse);
|
||||
rpc UploadFile(stream UploadLibraryFileRequest) returns (UploadLibraryFileResponse);
|
||||
rpc DeleteFile(DeleteLibraryFileRequest) returns (Empty);
|
||||
}
|
||||
|
||||
service PriceService {
|
||||
rpc GetPriceList(GetPriceListRequest) returns (PriceListResponse);
|
||||
rpc CreatePriceItem(CreatePriceItemRequest) returns (PriceItem);
|
||||
rpc UpdatePriceItem(UpdatePriceItemRequest) returns (PriceItem);
|
||||
}
|
||||
|
||||
service PayService {
|
||||
rpc CreateWxPayOrder(WxPayRequest) returns (WxPayResponse);
|
||||
rpc QueryPayStatus(QueryPayStatusRequest) returns (PayStatusResponse);
|
||||
rpc HandlePayCallback(PayCallbackRequest) returns (PayCallbackResponse);
|
||||
rpc PayByBalance(PayByBalanceRequest) returns (StatusResponse);
|
||||
}
|
||||
|
||||
service AdminService {
|
||||
rpc Login(AdminLoginRequest) returns (AdminLoginResponse);
|
||||
rpc GetStatistics(GetStatisticsRequest) returns (Statistics);
|
||||
rpc CreateAdmin(CreateAdminRequest) returns (CreateAdminResponse);
|
||||
rpc GetAdminList(GetAdminListRequest) returns (AdminListResponse);
|
||||
rpc UpdateAdmin(UpdateAdminRequest) returns (Admin);
|
||||
rpc DeleteAdmin(DeleteAdminRequest) returns (Empty);
|
||||
}
|
||||
Reference in New Issue
Block a user