Skip to content

Commit

Permalink
feat: 增加获取扣费列表,开通扣费和关闭扣费接口
Browse files Browse the repository at this point in the history
  • Loading branch information
nai6514531 committed Jul 5, 2020
1 parent b9e884c commit 62e70c4
Show file tree
Hide file tree
Showing 15 changed files with 1,984 additions and 563 deletions.
3 changes: 2 additions & 1 deletion .vscode/settings.json
Original file line number Diff line number Diff line change
Expand Up @@ -68,6 +68,7 @@
"shared_mutex": "cpp",
"streambuf": "cpp",
"cfenv": "cpp",
"valarray": "cpp"
"valarray": "cpp",
"__mutex_base": "cpp"
}
}
209 changes: 175 additions & 34 deletions apis/cpp/protocol/v1/deduction.grpc.pb.cc

Large diffs are not rendered by default.

890 changes: 772 additions & 118 deletions apis/cpp/protocol/v1/deduction.grpc.pb.h

Large diffs are not rendered by default.

542 changes: 352 additions & 190 deletions apis/cpp/protocol/v1/deduction.pb.cc

Large diffs are not rendered by default.

572 changes: 393 additions & 179 deletions apis/cpp/protocol/v1/deduction.pb.h

Large diffs are not rendered by default.

26 changes: 20 additions & 6 deletions apis/protocol/v1/deduction.proto
Original file line number Diff line number Diff line change
@@ -1,27 +1,41 @@
syntax = "proto3";

import public "google/protobuf/timestamp.proto";

package protocol.payment.deduction.v1;

// The greeting service definition.
service DeductionAdminApi {
rpc GetDeductionList(DeductionAdminReq) returns (DeductionAdminResp) {}
rpc AdminOp(DeductionAdminReq) returns (DeductionAdminResp) {}
// 获取扣费服务列表
rpc GetDeductionList(DeductionReq) returns (DeductionResp) {}
// 获取已失效扣费服务列表
rpc GetExpiredDeductionList(DeductionReq) returns (DeductionResp) {}
// 开通扣费服务
rpc OpenDeduction(DeductionReq) returns (DeductionResp) {}
//关闭扣费服务
rpc CloseDeduction(DeductionReq) returns (DeductionResp) {}
// //新增扣费服务
rpc CreateDeduction(DeductionReq) returns (DeductionResp) {}
}
message DeductionStruct {
string title = 1;
string desc = 2;
uint32 status = 3;
uint32 id = 4;
uint32 pay_method_id = 5;
uint32 detail_id = 6;
google.protobuf.Timestamp start_time = 6;
}

message DeductionAdminResp {
message DeductionResp {
bool success = 1;
repeated DeductionStruct data = 2;
string message = 3;
uint32 code = 4;
}

message DeductionAdminReq {
DeductionStruct data = 1;
message DeductionReq {
string title = 1;
string desc = 2;
uint32 pay_method_id = 3;
uint32 id = 4;
}
8 changes: 7 additions & 1 deletion apps/BUILD
Original file line number Diff line number Diff line change
Expand Up @@ -25,6 +25,11 @@ cc_library(
deps = [":3rd_json"]
)

cc_library(
name = "utils_enum",
hdrs = ["utils/enum.hpp"],
)


cc_library(
name = "3rd_mysqlplus",
Expand Down Expand Up @@ -66,6 +71,7 @@ cc_binary(
"//apis:deduction",
":3rd_mysqlplus",
":3rd_json",
":utils_config"
":utils_config",
":utils_enum"
],
)
89 changes: 80 additions & 9 deletions apps/client.cc
Original file line number Diff line number Diff line change
Expand Up @@ -7,14 +7,17 @@
#include "apps/3rd/json.hpp"

using namespace std;
using nlohmann::json;

using grpc::Channel;
using grpc::ClientContext;
using grpc::Status;


using protocol::payment::deduction::v1::DeductionAdminApi;
using protocol::payment::deduction::v1::DeductionAdminReq;
using protocol::payment::deduction::v1::DeductionAdminResp;
using protocol::payment::deduction::v1::DeductionReq;
using protocol::payment::deduction::v1::DeductionResp;
using protocol::payment::deduction::v1::DeductionStruct;

using utils::CmdMap;

Expand All @@ -27,6 +30,10 @@ class DeductionAdmin
{
reqHandlers = {
{"getlist", &DeductionAdmin::getList},
{"getexpiredlist", &DeductionAdmin::getExpiredList},
{"close", &DeductionAdmin::closeDeduction},
{"open", &DeductionAdmin::openDeduction},
{"create", &DeductionAdmin::createDeduction},
};
printOp.add_whitespace = true;
printOp.always_print_primitive_fields = true;
Expand All @@ -46,16 +53,62 @@ class DeductionAdmin
private:
void getList(string data)
{
DeductionAdminReq req;
// JsonStringToMessage(data, &req, parseOp);
DeductionAdminResp resp;
DeductionReq req;
DeductionResp resp;
ClientContext ctx;
Status status = stub_->GetDeductionList(&ctx, req, &resp);
string printJ;
MessageToJsonString(resp, &printJ, printOp);
cout << "\ngrpc code:" << status.error_code() << " , msg:" << status.error_message() << endl;
cout << printJ << endl;
}
void getExpiredList(string data)
{
DeductionReq req;
DeductionResp resp;
ClientContext ctx;
Status status = stub_->GetExpiredDeductionList(&ctx, req, &resp);
string printJ;
MessageToJsonString(resp, &printJ, printOp);
cout << "\ngrpc code:" << status.error_code() << " , msg:" << status.error_message() << endl;
cout << printJ << endl;
}
void closeDeduction(string data)
{
DeductionReq req;
DeductionResp resp;
ClientContext ctx;
JsonStringToMessage(data, &req, parseOp);
Status status = stub_->CloseDeduction(&ctx, req, &resp);
string printJ;
MessageToJsonString(resp, &printJ, printOp);
cout << "\ngrpc code:" << status.error_code() << " , msg:" << status.error_message() << endl;
cout << printJ << endl;
}
void openDeduction(string data)
{
DeductionReq req;
DeductionResp resp;
ClientContext ctx;
JsonStringToMessage(data, &req, parseOp);
Status status = stub_->OpenDeduction(&ctx, req, &resp);
string printJ;
MessageToJsonString(resp, &printJ, printOp);
cout << "\ngrpc code:" << status.error_code() << " , msg:" << status.error_message() << endl;
cout << printJ << endl;
}
void createDeduction(string data)
{
DeductionReq req;
DeductionResp resp;
ClientContext ctx;
JsonStringToMessage(data, &req, parseOp);
Status status = stub_->CreateDeduction(&ctx, req, &resp);
string printJ;
MessageToJsonString(resp, &printJ, printOp);
cout << "\ngrpc code:" << status.error_code() << " , msg:" << status.error_message() << endl;
cout << printJ << endl;
}
private:
using func = void (DeductionAdmin::*)(string);
google::protobuf::util::JsonPrintOptions printOp;
Expand All @@ -68,7 +121,27 @@ class DeductionAdmin
CmdMap cmdMap = {
{
"getlist", {
{"(no args)", "eg:config set {\"kick_mode\":1}"},
{"(no args)", "eg:getlist"},
}
},
{
"getexpiredlist", {
{"(no args)", "eg:getexpiredlist"},
}
},
{
"open", {
{"(args)", "eg:opend {\"id\":1}"},
}
},
{
"close", {
{"(args)", "eg:close {\"id\":1}"},
}
},
{
"create", {
{"(args)", "eg:create {\"id\":1,\"title\":\"测试\",\"desc\":\"程序添加进去的\"}"},
}
},
{
Expand All @@ -87,9 +160,7 @@ CmdMap cmdMap = {
vector<string> quits = {"exit"};
vector<string> helps = {"help"};
string adminPrompt = "admin> ";
string _exitPrompt = "Au revoir.\n";
string defaultAddr = "127.0.0.1:12345";
string _helpPrompt = "type `help` for admin commands info\n";
string _exitPrompt = "See you.\n";
string errorPrompt = "Invalid command, letters(a-zA-Z) only. Try `help` for more.\n";


Expand Down
Loading

0 comments on commit 62e70c4

Please sign in to comment.