cgserver 6.0.6 → 6.0.9
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/dist/lib/AI/AiObject.js +10 -0
- package/dist/lib/AI/Astar.js +133 -0
- package/dist/lib/AI/BehaviorAI.js +307 -0
- package/dist/lib/AI/Entity.js +33 -0
- package/dist/lib/AI/Point.js +68 -0
- package/dist/lib/AI/TriggerMgr.js +201 -0
- package/dist/lib/Config/Config.js +37 -0
- package/dist/lib/Config/FrameworkConfig.js +234 -0
- package/dist/lib/Config/ServerConfig.js +18 -0
- package/dist/lib/Config/_error_.js +35 -0
- package/dist/lib/Core/Core.js +561 -0
- package/dist/lib/Core/Timer.js +116 -0
- package/dist/lib/Database/BaseMongoService.js +79 -0
- package/dist/lib/Database/BaseService.js +281 -0
- package/dist/lib/Database/Decorator/AutoIncrement.js +11 -0
- package/dist/lib/Database/Decorator/DBCache.js +64 -0
- package/dist/lib/Database/Decorator/NotNull.js +11 -0
- package/dist/lib/Database/Decorator/PrimaryKey.js +11 -0
- package/dist/lib/Database/Decorator/Property.js +61 -0
- package/dist/lib/Database/Decorator/Table.js +15 -0
- package/dist/lib/Database/Decorator/Type.js +20 -0
- package/dist/lib/Database/MSSqlManager.js +43 -0
- package/dist/lib/Database/MongoManager.js +401 -0
- package/dist/lib/Database/MysqlManager.js +180 -0
- package/dist/lib/Database/RedisManager.js +408 -0
- package/dist/lib/Logic/CacheTool.js +73 -0
- package/dist/lib/Logic/HttpTool.js +58 -0
- package/dist/lib/Logic/Log.js +77 -0
- package/dist/lib/Service/AccountService.js +473 -0
- package/dist/lib/Service/MongoAccountService.js +396 -0
- package/dist/lib/Service/MongoCacheService.js +27 -0
- package/dist/lib/Service/MongoUserService.js +93 -0
- package/dist/lib/Service/UserService.js +184 -0
- package/dist/lib/Service/ini.js +35 -0
- package/dist/lib/SocketServer/IClientWebSocket.js +71 -0
- package/dist/lib/SocketServer/IServerWebSocket.js +41 -0
- package/dist/lib/SocketServer/ISocketServer.js +190 -0
- package/dist/lib/SocketServer/IWebSocket.js +223 -0
- package/dist/lib/SocketServer/ProtoFilter/GoogleProtoFilter.js +57 -0
- package/dist/lib/SocketServer/ProtoFilter/IProtoFilter.js +8 -0
- package/dist/lib/SocketServer/ProtoFilter/JsonProtoFilter.js +29 -0
- package/dist/lib/SocketServer/ProtoFilter/ProtoFactory.js +31 -0
- package/dist/lib/ThirdParty/AlipayTool.js +122 -0
- package/dist/lib/ThirdParty/Alisms.js +46 -0
- package/dist/lib/ThirdParty/AppleTool.js +234 -0
- package/dist/lib/ThirdParty/EmailTool.js +33 -0
- package/dist/lib/ThirdParty/OpenSocial.js +32 -0
- package/dist/lib/ThirdParty/QQTool.js +115 -0
- package/dist/lib/ThirdParty/QiniuTool.js +21 -0
- package/dist/lib/ThirdParty/WechatOATool.js +61 -0
- package/dist/lib/ThirdParty/WechatTool.js +74 -0
- package/dist/lib/WebServer/Controller/BaseController.js +112 -0
- package/dist/lib/WebServer/Controller/BaseUserController.js +168 -0
- package/dist/lib/WebServer/Controller/MongoBaseUserController.js +168 -0
- package/dist/lib/WebServer/Decorator/AdminValidate.js +19 -0
- package/dist/lib/WebServer/Decorator/AuthorityValidate.js +22 -0
- package/dist/lib/WebServer/Decorator/CreatorValidate.js +19 -0
- package/dist/lib/WebServer/Decorator/JsonAdminValidate.js +15 -0
- package/dist/lib/WebServer/Decorator/JsonAuthorityValidate.js +20 -0
- package/dist/lib/WebServer/Decorator/JsonCreatorValidate.js +19 -0
- package/dist/lib/WebServer/Engine/ControllerManager.js +112 -0
- package/dist/lib/WebServer/Engine/Engine.js +135 -0
- package/dist/lib/WebServer/Engine/RazorJs.js +544 -0
- package/dist/lib/WebServer/Engine/Request.js +214 -0
- package/dist/lib/WebServer/Engine/Response.js +94 -0
- package/dist/lib/WebServer/IWebServer.js +49 -0
- package/dist/lib/cgserver.js +153 -0
- package/dist/{AI → types/AI}/AiObject.d.ts +0 -0
- package/dist/{AI → types/AI}/Astar.d.ts +0 -0
- package/dist/{AI → types/AI}/BehaviorAI.d.ts +0 -0
- package/dist/{AI → types/AI}/Entity.d.ts +0 -0
- package/dist/{AI → types/AI}/Point.d.ts +0 -0
- package/dist/{AI → types/AI}/TriggerMgr.d.ts +0 -0
- package/dist/{Config → types/Config}/Config.d.ts +0 -0
- package/dist/{Config → types/Config}/FrameworkConfig.d.ts +0 -0
- package/dist/{Config → types/Config}/ServerConfig.d.ts +0 -0
- package/dist/{Config → types/Config}/_error_.d.ts +0 -0
- package/dist/{Core → types/Core}/Core.d.ts +0 -0
- package/dist/{Core → types/Core}/Timer.d.ts +0 -0
- package/dist/{Database → types/Database}/BaseMongoService.d.ts +0 -0
- package/dist/{Database → types/Database}/BaseService.d.ts +0 -0
- package/dist/{Database → types/Database}/Decorator/AutoIncrement.d.ts +0 -0
- package/dist/{Database → types/Database}/Decorator/DBCache.d.ts +0 -0
- package/dist/{Database → types/Database}/Decorator/NotNull.d.ts +0 -0
- package/dist/{Database → types/Database}/Decorator/PrimaryKey.d.ts +0 -0
- package/dist/{Database → types/Database}/Decorator/Property.d.ts +0 -0
- package/dist/{Database → types/Database}/Decorator/Table.d.ts +0 -0
- package/dist/{Database → types/Database}/Decorator/Type.d.ts +0 -0
- package/dist/{Database → types/Database}/MSSqlManager.d.ts +0 -0
- package/dist/{Database → types/Database}/MongoManager.d.ts +0 -0
- package/dist/{Database → types/Database}/MysqlManager.d.ts +0 -0
- package/dist/{Database → types/Database}/RedisManager.d.ts +0 -0
- package/dist/{Logic → types/Logic}/CacheTool.d.ts +0 -0
- package/dist/{Logic → types/Logic}/HttpTool.d.ts +0 -0
- package/dist/{Logic → types/Logic}/Log.d.ts +0 -0
- package/dist/{Service → types/Service}/AccountService.d.ts +0 -0
- package/dist/{Service → types/Service}/MongoAccountService.d.ts +0 -0
- package/dist/{Service → types/Service}/MongoCacheService.d.ts +0 -0
- package/dist/{Service → types/Service}/MongoUserService.d.ts +0 -0
- package/dist/{Service → types/Service}/UserService.d.ts +0 -0
- package/dist/{Service → types/Service}/ini.d.ts +0 -0
- package/dist/{SocketServer → types/SocketServer}/IClientWebSocket.d.ts +0 -0
- package/dist/{SocketServer → types/SocketServer}/IServerWebSocket.d.ts +0 -0
- package/dist/{SocketServer → types/SocketServer}/ISocketServer.d.ts +0 -0
- package/dist/{SocketServer → types/SocketServer}/IWebSocket.d.ts +0 -0
- package/dist/{SocketServer → types/SocketServer}/ProtoFilter/GoogleProtoFilter.d.ts +0 -0
- package/dist/{SocketServer → types/SocketServer}/ProtoFilter/IProtoFilter.d.ts +0 -0
- package/dist/{SocketServer → types/SocketServer}/ProtoFilter/JsonProtoFilter.d.ts +0 -0
- package/dist/{SocketServer → types/SocketServer}/ProtoFilter/ProtoFactory.d.ts +0 -0
- package/dist/{ThirdParty → types/ThirdParty}/AlipayTool.d.ts +0 -0
- package/dist/{ThirdParty → types/ThirdParty}/Alisms.d.ts +0 -0
- package/dist/{ThirdParty → types/ThirdParty}/AppleTool.d.ts +0 -0
- package/dist/{ThirdParty → types/ThirdParty}/EmailTool.d.ts +0 -0
- package/dist/{ThirdParty → types/ThirdParty}/OpenSocial.d.ts +0 -0
- package/dist/{ThirdParty → types/ThirdParty}/QQTool.d.ts +0 -0
- package/dist/{ThirdParty → types/ThirdParty}/QiniuTool.d.ts +0 -0
- package/dist/{ThirdParty → types/ThirdParty}/WechatOATool.d.ts +0 -0
- package/dist/{ThirdParty → types/ThirdParty}/WechatTool.d.ts +0 -0
- package/dist/{WebServer → types/WebServer}/Controller/BaseController.d.ts +0 -0
- package/dist/{WebServer → types/WebServer}/Controller/BaseUserController.d.ts +0 -0
- package/dist/{WebServer → types/WebServer}/Controller/MongoBaseUserController.d.ts +0 -0
- package/dist/{WebServer → types/WebServer}/Decorator/AdminValidate.d.ts +0 -0
- package/dist/{WebServer → types/WebServer}/Decorator/AuthorityValidate.d.ts +0 -0
- package/dist/{WebServer → types/WebServer}/Decorator/CreatorValidate.d.ts +0 -0
- package/dist/{WebServer → types/WebServer}/Decorator/JsonAdminValidate.d.ts +0 -0
- package/dist/{WebServer → types/WebServer}/Decorator/JsonAuthorityValidate.d.ts +0 -0
- package/dist/{WebServer → types/WebServer}/Decorator/JsonCreatorValidate.d.ts +0 -0
- package/dist/{WebServer → types/WebServer}/Engine/ControllerManager.d.ts +0 -0
- package/dist/{WebServer → types/WebServer}/Engine/Engine.d.ts +0 -0
- package/dist/{WebServer → types/WebServer}/Engine/RazorJs.d.ts +0 -0
- package/dist/{WebServer → types/WebServer}/Engine/Request.d.ts +0 -0
- package/dist/{WebServer → types/WebServer}/Engine/Response.d.ts +0 -0
- package/dist/{WebServer → types/WebServer}/IWebServer.d.ts +0 -0
- package/dist/{cgserver.d.ts → types/cgserver.d.ts} +0 -0
- package/package.json +3 -2
- package/dist/cgserver.js +0 -1037
|
@@ -0,0 +1,79 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.BaseService = void 0;
|
|
4
|
+
const MongoManager_1 = require("./MongoManager");
|
|
5
|
+
class BaseService {
|
|
6
|
+
_table = "";
|
|
7
|
+
get table() {
|
|
8
|
+
return this._table;
|
|
9
|
+
}
|
|
10
|
+
_inited = false;
|
|
11
|
+
get isInited() {
|
|
12
|
+
return this._inited;
|
|
13
|
+
}
|
|
14
|
+
get mongo() {
|
|
15
|
+
return MongoManager_1.GMongoMgr.mongo;
|
|
16
|
+
}
|
|
17
|
+
_t_type = null;
|
|
18
|
+
constructor(table, type) {
|
|
19
|
+
this._t_type = type;
|
|
20
|
+
this._table = table;
|
|
21
|
+
}
|
|
22
|
+
async getNextId() {
|
|
23
|
+
let id = await MongoManager_1.GMongoMgr.getAutoIds(this._table);
|
|
24
|
+
return id;
|
|
25
|
+
}
|
|
26
|
+
/**
|
|
27
|
+
* 没有id(非_id)的表不能使用该函数
|
|
28
|
+
* @param id
|
|
29
|
+
*/
|
|
30
|
+
async getById(id) {
|
|
31
|
+
let rs = await MongoManager_1.GMongoMgr.findOne(this._table, null, { id: id });
|
|
32
|
+
return rs.one;
|
|
33
|
+
}
|
|
34
|
+
async get(proterty, where, sort) {
|
|
35
|
+
let rs = await MongoManager_1.GMongoMgr.findOne(this._table, proterty, where, sort);
|
|
36
|
+
return rs.one;
|
|
37
|
+
}
|
|
38
|
+
async getTotal(where) {
|
|
39
|
+
let rs = await MongoManager_1.GMongoMgr.findCount(this._table, where);
|
|
40
|
+
return rs.count;
|
|
41
|
+
}
|
|
42
|
+
async gets(property, where, sort, skip = 0, limit = 0) {
|
|
43
|
+
let rs = await MongoManager_1.GMongoMgr.findMany(this._table, property, where, sort, skip, limit);
|
|
44
|
+
return rs.list;
|
|
45
|
+
}
|
|
46
|
+
async getRandoms(num, proterty, where) {
|
|
47
|
+
let rs = await MongoManager_1.GMongoMgr.simpleAggregate(this._table, proterty, where, null, num);
|
|
48
|
+
return rs.list;
|
|
49
|
+
}
|
|
50
|
+
async updateOne(model, where, upsert = false) {
|
|
51
|
+
let rs = await MongoManager_1.GMongoMgr.updateOne(this._table, model, where, upsert);
|
|
52
|
+
return rs;
|
|
53
|
+
}
|
|
54
|
+
async updateMany(models, where) {
|
|
55
|
+
let rs = await MongoManager_1.GMongoMgr.updateMany(this._table, models, where);
|
|
56
|
+
return rs;
|
|
57
|
+
}
|
|
58
|
+
async insert(model) {
|
|
59
|
+
let rs = await MongoManager_1.GMongoMgr.insertOne(this._table, model);
|
|
60
|
+
return rs;
|
|
61
|
+
}
|
|
62
|
+
async deleteOne(where) {
|
|
63
|
+
let rs = await MongoManager_1.GMongoMgr.deleteOne(this._table, where);
|
|
64
|
+
return rs;
|
|
65
|
+
}
|
|
66
|
+
async deleteMany(where) {
|
|
67
|
+
let rs = await MongoManager_1.GMongoMgr.deleteMany(this._table, where);
|
|
68
|
+
return rs;
|
|
69
|
+
}
|
|
70
|
+
async createIndex(index, options) {
|
|
71
|
+
let rs = await MongoManager_1.GMongoMgr.createIndex(this._table, index, options);
|
|
72
|
+
return rs;
|
|
73
|
+
}
|
|
74
|
+
aggregate(pipeline, options) {
|
|
75
|
+
let ret = MongoManager_1.GMongoMgr.aggregate(this._table);
|
|
76
|
+
return ret;
|
|
77
|
+
}
|
|
78
|
+
}
|
|
79
|
+
exports.BaseService = BaseService;
|
|
@@ -0,0 +1,281 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.BaseService = exports.BaseModel = void 0;
|
|
4
|
+
const Property_1 = require("./Decorator/Property");
|
|
5
|
+
const MysqlManager_1 = require("./MysqlManager");
|
|
6
|
+
const Log_1 = require("../Logic/Log");
|
|
7
|
+
const DBCache_1 = require("./Decorator/DBCache");
|
|
8
|
+
const FrameworkConfig_1 = require("../Config/FrameworkConfig");
|
|
9
|
+
class BaseModel {
|
|
10
|
+
}
|
|
11
|
+
exports.BaseModel = BaseModel;
|
|
12
|
+
class BaseService {
|
|
13
|
+
_table = "";
|
|
14
|
+
get table() {
|
|
15
|
+
return this._table;
|
|
16
|
+
}
|
|
17
|
+
get version() {
|
|
18
|
+
let table = this._t_type.prototype[Property_1.TableProperty.key];
|
|
19
|
+
return table.version;
|
|
20
|
+
}
|
|
21
|
+
_inited = false;
|
|
22
|
+
get isInited() {
|
|
23
|
+
return this._inited;
|
|
24
|
+
}
|
|
25
|
+
_t_type = null;
|
|
26
|
+
constructor(type) {
|
|
27
|
+
this._t_type = type;
|
|
28
|
+
if (MysqlManager_1.GMysqlMgr.isValid) {
|
|
29
|
+
this._init();
|
|
30
|
+
}
|
|
31
|
+
else {
|
|
32
|
+
MysqlManager_1.GMysqlMgr.registerInitCb(this._init.bind(this));
|
|
33
|
+
}
|
|
34
|
+
}
|
|
35
|
+
async _init() {
|
|
36
|
+
if (this._inited) {
|
|
37
|
+
return;
|
|
38
|
+
}
|
|
39
|
+
this._inited = true;
|
|
40
|
+
let table = this._t_type.prototype[Property_1.TableProperty.key];
|
|
41
|
+
if (!table || !table.table) {
|
|
42
|
+
throw new Error("数据表的类必须要具有Table装饰器");
|
|
43
|
+
}
|
|
44
|
+
this._table = "`" + table.table + "`";
|
|
45
|
+
if (!FrameworkConfig_1.GFCfg.db.mysql.auto) {
|
|
46
|
+
//未开启自动创建数据表
|
|
47
|
+
return;
|
|
48
|
+
}
|
|
49
|
+
let droped = await this._checkDropTable(table.version);
|
|
50
|
+
if (!droped) {
|
|
51
|
+
Log_1.GLog.info("table(" + this._table + ")无需升级...", true);
|
|
52
|
+
//既然版本号没变,就快速返回
|
|
53
|
+
return;
|
|
54
|
+
}
|
|
55
|
+
let primary_key = null;
|
|
56
|
+
let sql = "create table if not exists " + this._table + " (";
|
|
57
|
+
for (let key in table.items) {
|
|
58
|
+
let item = table.items[key];
|
|
59
|
+
sql += "`" + key + "`" + " " + item.type;
|
|
60
|
+
if (item.type == Property_1.EPropertyType.Varchar
|
|
61
|
+
|| item.type == Property_1.EPropertyType.Char
|
|
62
|
+
|| item.type == Property_1.EPropertyType.NVarchar) {
|
|
63
|
+
sql += "(" + item.type_len + ")";
|
|
64
|
+
}
|
|
65
|
+
if (item.is_notnull) {
|
|
66
|
+
sql += " not null";
|
|
67
|
+
}
|
|
68
|
+
if (item.default != undefined && !item.is_primary) {
|
|
69
|
+
sql += " default \'" + item.default + "\'";
|
|
70
|
+
}
|
|
71
|
+
if (item.auto_increment) {
|
|
72
|
+
sql += " auto_increment";
|
|
73
|
+
}
|
|
74
|
+
if (item.is_primary) {
|
|
75
|
+
primary_key = key;
|
|
76
|
+
}
|
|
77
|
+
sql += ",";
|
|
78
|
+
}
|
|
79
|
+
if (primary_key) {
|
|
80
|
+
sql += "primary key (`" + primary_key + "`),";
|
|
81
|
+
sql += "unique key `" + primary_key + "_unique` (`" + primary_key + "`)";
|
|
82
|
+
}
|
|
83
|
+
else {
|
|
84
|
+
//去掉最后一个逗号
|
|
85
|
+
sql = sql.substr(0, sql.length - 1);
|
|
86
|
+
}
|
|
87
|
+
sql += ")";
|
|
88
|
+
sql += " engine=" + table.engine;
|
|
89
|
+
if (table.auto_increment != null) {
|
|
90
|
+
sql += " auto_increment=" + table.auto_increment;
|
|
91
|
+
}
|
|
92
|
+
sql += " default charset=" + table.charset;
|
|
93
|
+
if (table.comment) {
|
|
94
|
+
sql += " comment=\'" + table.comment + "\';";
|
|
95
|
+
}
|
|
96
|
+
let sr = await MysqlManager_1.GMysqlMgr.query(sql);
|
|
97
|
+
if (sr.error) {
|
|
98
|
+
Log_1.GLog.error(sr.error);
|
|
99
|
+
throw Error("table(" + this._table + ")创建失败...");
|
|
100
|
+
}
|
|
101
|
+
else {
|
|
102
|
+
DBCache_1.GDBCache.setVersion(this.table, table.version);
|
|
103
|
+
Log_1.GLog.info("table(" + this._table + ")初始化成功...", true);
|
|
104
|
+
await this._onReCreated();
|
|
105
|
+
}
|
|
106
|
+
}
|
|
107
|
+
async _onReCreated() {
|
|
108
|
+
}
|
|
109
|
+
async _onDroped() {
|
|
110
|
+
}
|
|
111
|
+
async _checkDropTable(cur_version) {
|
|
112
|
+
let local_version = DBCache_1.GDBCache.getVersion(this._table);
|
|
113
|
+
if (local_version == cur_version) {
|
|
114
|
+
return false;
|
|
115
|
+
}
|
|
116
|
+
let sql = "drop table if exists " + this._table;
|
|
117
|
+
let sr = await MysqlManager_1.GMysqlMgr.query(sql);
|
|
118
|
+
if (sr.error) {
|
|
119
|
+
Log_1.GLog.error(sr.error);
|
|
120
|
+
throw Error(sr.error);
|
|
121
|
+
}
|
|
122
|
+
else {
|
|
123
|
+
Log_1.GLog.info("table(" + this._table + ")删除成功...", true);
|
|
124
|
+
await this._onDroped();
|
|
125
|
+
}
|
|
126
|
+
return true;
|
|
127
|
+
}
|
|
128
|
+
/**
|
|
129
|
+
* 没有id的表不能使用该函数
|
|
130
|
+
* @param id
|
|
131
|
+
*/
|
|
132
|
+
async getById(id) {
|
|
133
|
+
let tm = null;
|
|
134
|
+
let sr = await MysqlManager_1.GMysqlMgr.query("select * from " + this._table + " where id=? limit 1", [id]);
|
|
135
|
+
if (sr.error || sr.results.length <= 0) {
|
|
136
|
+
return tm;
|
|
137
|
+
}
|
|
138
|
+
tm = sr.results[0];
|
|
139
|
+
return tm;
|
|
140
|
+
}
|
|
141
|
+
async get(proterty, where, args) {
|
|
142
|
+
let sql = "select ";
|
|
143
|
+
sql += proterty || "*";
|
|
144
|
+
sql += " from " + this._table;
|
|
145
|
+
if (where) {
|
|
146
|
+
sql += " where " + where;
|
|
147
|
+
}
|
|
148
|
+
sql += " limit 1";
|
|
149
|
+
let tm = null;
|
|
150
|
+
let sr = await MysqlManager_1.GMysqlMgr.query(sql, args);
|
|
151
|
+
if (sr.list && sr.list.length > 0) {
|
|
152
|
+
tm = sr.list[0];
|
|
153
|
+
}
|
|
154
|
+
return tm;
|
|
155
|
+
}
|
|
156
|
+
async getTotal(where, args) {
|
|
157
|
+
let sql = "select ";
|
|
158
|
+
sql += "count(*) as num";
|
|
159
|
+
sql += " from " + this._table;
|
|
160
|
+
if (where) {
|
|
161
|
+
sql += " where " + where;
|
|
162
|
+
}
|
|
163
|
+
let total = 0;
|
|
164
|
+
let sr = await MysqlManager_1.GMysqlMgr.query(sql, args);
|
|
165
|
+
if (sr.list && sr.list.length > 0) {
|
|
166
|
+
total = sr.list[0].num || 0;
|
|
167
|
+
}
|
|
168
|
+
return total;
|
|
169
|
+
}
|
|
170
|
+
async gets(proterty, where, args) {
|
|
171
|
+
let sql = "select ";
|
|
172
|
+
sql += proterty || "*";
|
|
173
|
+
sql += " from " + this._table;
|
|
174
|
+
if (where) {
|
|
175
|
+
sql += " where " + where;
|
|
176
|
+
}
|
|
177
|
+
let tms = null;
|
|
178
|
+
let sr = await MysqlManager_1.GMysqlMgr.query(sql, args);
|
|
179
|
+
tms = sr.list;
|
|
180
|
+
return tms;
|
|
181
|
+
}
|
|
182
|
+
async getCount(where, args) {
|
|
183
|
+
let sql = "select count(*) as num from " + this._table;
|
|
184
|
+
if (where) {
|
|
185
|
+
sql += " where " + where;
|
|
186
|
+
}
|
|
187
|
+
let sr = await MysqlManager_1.GMysqlMgr.query(sql, args);
|
|
188
|
+
if (sr.error || sr.results.length <= 0) {
|
|
189
|
+
return 0;
|
|
190
|
+
}
|
|
191
|
+
return sr.results[0]["num"] || 0;
|
|
192
|
+
}
|
|
193
|
+
async getRandoms(num, proterty, where, args) {
|
|
194
|
+
num = num || 5;
|
|
195
|
+
let sql = "select ";
|
|
196
|
+
sql += proterty || "*";
|
|
197
|
+
sql += " from " + this._table;
|
|
198
|
+
if (where) {
|
|
199
|
+
sql += " where " + where;
|
|
200
|
+
}
|
|
201
|
+
sql += " order by rand() limit ?";
|
|
202
|
+
args = args || [];
|
|
203
|
+
args.push(num);
|
|
204
|
+
let tms = null;
|
|
205
|
+
let sr = await MysqlManager_1.GMysqlMgr.query(sql, args);
|
|
206
|
+
tms = sr.list;
|
|
207
|
+
return tms;
|
|
208
|
+
}
|
|
209
|
+
async updateProperty(set, where, args, limit) {
|
|
210
|
+
let sql = "update " + this._table + " set ";
|
|
211
|
+
if (set) {
|
|
212
|
+
sql += set;
|
|
213
|
+
}
|
|
214
|
+
else {
|
|
215
|
+
sql += "?";
|
|
216
|
+
}
|
|
217
|
+
if (where) {
|
|
218
|
+
sql += " where " + where;
|
|
219
|
+
}
|
|
220
|
+
if (limit) {
|
|
221
|
+
sql += " limit " + limit;
|
|
222
|
+
}
|
|
223
|
+
let sr = await MysqlManager_1.GMysqlMgr.query(sql, args);
|
|
224
|
+
return sr;
|
|
225
|
+
}
|
|
226
|
+
async update(model, where, args, limit) {
|
|
227
|
+
let sql = "update " + this._table + " set ?";
|
|
228
|
+
if (!where) {
|
|
229
|
+
where = " id=?";
|
|
230
|
+
}
|
|
231
|
+
sql += " where " + where;
|
|
232
|
+
let id = model["id"];
|
|
233
|
+
delete model["id"];
|
|
234
|
+
let u_m = JSON.parse(JSON.stringify(model));
|
|
235
|
+
if (!args) {
|
|
236
|
+
args = [u_m, id];
|
|
237
|
+
}
|
|
238
|
+
else {
|
|
239
|
+
args.unshift(u_m);
|
|
240
|
+
}
|
|
241
|
+
if (limit) {
|
|
242
|
+
sql += " limit " + limit;
|
|
243
|
+
}
|
|
244
|
+
let sr = await MysqlManager_1.GMysqlMgr.query(sql, args);
|
|
245
|
+
if (id) {
|
|
246
|
+
model["id"] = id;
|
|
247
|
+
}
|
|
248
|
+
return sr;
|
|
249
|
+
}
|
|
250
|
+
async insert(model, ip) {
|
|
251
|
+
let table = model[Property_1.TableProperty.key];
|
|
252
|
+
let id_property = table.items["id"];
|
|
253
|
+
if (id_property) {
|
|
254
|
+
if (id_property.auto_increment) {
|
|
255
|
+
delete model["id"];
|
|
256
|
+
}
|
|
257
|
+
}
|
|
258
|
+
if (table.items["create_time"] && model["create_time"] <= 0) {
|
|
259
|
+
model["create_time"] = Date.now();
|
|
260
|
+
}
|
|
261
|
+
if (table.items["create_ip"] && ip) {
|
|
262
|
+
model["create_ip"] = ip;
|
|
263
|
+
}
|
|
264
|
+
let sql = "insert into " + this._table + " set ?";
|
|
265
|
+
//这步的做法是为了去掉model种的TableProperty.key(___table___)
|
|
266
|
+
model = JSON.parse(JSON.stringify(model));
|
|
267
|
+
let sr = await MysqlManager_1.GMysqlMgr.query(sql, [model]);
|
|
268
|
+
return sr;
|
|
269
|
+
}
|
|
270
|
+
async removeById(id) {
|
|
271
|
+
let sql = "delete from " + this._table + " where id=?";
|
|
272
|
+
let sr = await MysqlManager_1.GMysqlMgr.query(sql, [id]);
|
|
273
|
+
return sr;
|
|
274
|
+
}
|
|
275
|
+
async remove(where, args) {
|
|
276
|
+
let sql = "delete from " + this._table + " where " + where;
|
|
277
|
+
let sr = await MysqlManager_1.GMysqlMgr.query(sql, args);
|
|
278
|
+
return sr;
|
|
279
|
+
}
|
|
280
|
+
}
|
|
281
|
+
exports.BaseService = BaseService;
|
|
@@ -0,0 +1,11 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.AutoIncrement = void 0;
|
|
4
|
+
const Property_1 = require("./Property");
|
|
5
|
+
function AutoIncrement(target, propertyName) {
|
|
6
|
+
let table = target[Property_1.TableProperty.key] = target[Property_1.TableProperty.key] || new Property_1.TableProperty();
|
|
7
|
+
table.items[propertyName] = table.items[propertyName] || new Property_1.Property();
|
|
8
|
+
let pt = table.items[propertyName];
|
|
9
|
+
pt.auto_increment = true;
|
|
10
|
+
}
|
|
11
|
+
exports.AutoIncrement = AutoIncrement;
|
|
@@ -0,0 +1,64 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.GDBCache = exports.VersionModel = void 0;
|
|
4
|
+
const Log_1 = require("./../../Logic/Log");
|
|
5
|
+
const fs = require("fs");
|
|
6
|
+
class VersionModel {
|
|
7
|
+
table = "";
|
|
8
|
+
version = 0;
|
|
9
|
+
/**
|
|
10
|
+
* 创建时间
|
|
11
|
+
*/
|
|
12
|
+
create_time = 0;
|
|
13
|
+
/**
|
|
14
|
+
* 创建时间
|
|
15
|
+
*/
|
|
16
|
+
update_time = 0;
|
|
17
|
+
}
|
|
18
|
+
exports.VersionModel = VersionModel;
|
|
19
|
+
exports.GDBCache = null;
|
|
20
|
+
class DBCache {
|
|
21
|
+
_versions = new Map();
|
|
22
|
+
_path = __dirname + "/tmp_table_version.json";
|
|
23
|
+
async init() {
|
|
24
|
+
if (fs.existsSync(this._path)) {
|
|
25
|
+
try {
|
|
26
|
+
let table = fs.readFileSync(this._path);
|
|
27
|
+
this._versions = JSON.parse(table.toString());
|
|
28
|
+
}
|
|
29
|
+
catch (e) {
|
|
30
|
+
Log_1.GLog.info("error:" + this._path);
|
|
31
|
+
process.exit();
|
|
32
|
+
}
|
|
33
|
+
}
|
|
34
|
+
else {
|
|
35
|
+
this._versions = new Map();
|
|
36
|
+
fs.writeFileSync(this._path, JSON.stringify(this._versions));
|
|
37
|
+
}
|
|
38
|
+
}
|
|
39
|
+
async setVersion(table, version) {
|
|
40
|
+
let vm = this._versions[table];
|
|
41
|
+
if (!vm) {
|
|
42
|
+
vm = new VersionModel();
|
|
43
|
+
vm.table = table;
|
|
44
|
+
vm.version = version;
|
|
45
|
+
vm.create_time = Date.now();
|
|
46
|
+
vm.update_time = Date.now();
|
|
47
|
+
this._versions[table] = vm;
|
|
48
|
+
fs.writeFileSync(this._path, JSON.stringify(this._versions));
|
|
49
|
+
}
|
|
50
|
+
else if (vm.version != version) {
|
|
51
|
+
vm.version = version;
|
|
52
|
+
vm.update_time = Date.now();
|
|
53
|
+
fs.writeFileSync(this._path, JSON.stringify(this._versions));
|
|
54
|
+
}
|
|
55
|
+
}
|
|
56
|
+
getVersion(table) {
|
|
57
|
+
let vm = this._versions[table];
|
|
58
|
+
if (!vm) {
|
|
59
|
+
return -1;
|
|
60
|
+
}
|
|
61
|
+
return vm.version;
|
|
62
|
+
}
|
|
63
|
+
}
|
|
64
|
+
exports.GDBCache = new DBCache();
|
|
@@ -0,0 +1,11 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.NotNull = void 0;
|
|
4
|
+
const Property_1 = require("./Property");
|
|
5
|
+
function NotNull(target, propertyName) {
|
|
6
|
+
let table = target[Property_1.TableProperty.key] = target[Property_1.TableProperty.key] || new Property_1.TableProperty();
|
|
7
|
+
table.items[propertyName] = table.items[propertyName] || new Property_1.Property();
|
|
8
|
+
let pt = table.items[propertyName];
|
|
9
|
+
pt.is_notnull = true;
|
|
10
|
+
}
|
|
11
|
+
exports.NotNull = NotNull;
|
|
@@ -0,0 +1,11 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.PrimaryKey = void 0;
|
|
4
|
+
const Property_1 = require("./Property");
|
|
5
|
+
function PrimaryKey(target, propertyName) {
|
|
6
|
+
let table = target[Property_1.TableProperty.key] = target[Property_1.TableProperty.key] || new Property_1.TableProperty();
|
|
7
|
+
table.items[propertyName] = table.items[propertyName] || new Property_1.Property();
|
|
8
|
+
let pt = table.items[propertyName];
|
|
9
|
+
pt.is_primary = true;
|
|
10
|
+
}
|
|
11
|
+
exports.PrimaryKey = PrimaryKey;
|
|
@@ -0,0 +1,61 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.TableProperty = exports.Property = exports.EPropertyType = void 0;
|
|
4
|
+
class EPropertyType {
|
|
5
|
+
static Char = "char";
|
|
6
|
+
static NVarchar = "nvarchar";
|
|
7
|
+
static Varchar = "varchar";
|
|
8
|
+
static BigInt = "bigint";
|
|
9
|
+
static Decimal = "decimal";
|
|
10
|
+
static Double = "double";
|
|
11
|
+
static Float = "float";
|
|
12
|
+
static Int = "int";
|
|
13
|
+
static MediumInt = "Mediumint";
|
|
14
|
+
static Real = "real";
|
|
15
|
+
static SmallInt = "smallint";
|
|
16
|
+
static TinyInt = "tinyint";
|
|
17
|
+
static LongText = "longtext";
|
|
18
|
+
static MediumText = "mediumtext";
|
|
19
|
+
static Text = "text";
|
|
20
|
+
static TinyText = "tinytext";
|
|
21
|
+
static defs = {
|
|
22
|
+
"char": "",
|
|
23
|
+
"nvarchar": "",
|
|
24
|
+
"varchar": "",
|
|
25
|
+
"bigint": 0,
|
|
26
|
+
"decimal": 0,
|
|
27
|
+
"double": 0,
|
|
28
|
+
"float": 0,
|
|
29
|
+
"int": 0,
|
|
30
|
+
"Mediumint": 0,
|
|
31
|
+
"real": 0,
|
|
32
|
+
"smallint": 0,
|
|
33
|
+
"tinyint": 0,
|
|
34
|
+
"longtext": "",
|
|
35
|
+
"mediumtext": "",
|
|
36
|
+
"text": undefined,
|
|
37
|
+
"tinytext": ""
|
|
38
|
+
};
|
|
39
|
+
}
|
|
40
|
+
exports.EPropertyType = EPropertyType;
|
|
41
|
+
class Property {
|
|
42
|
+
is_primary = false;
|
|
43
|
+
is_notnull = false;
|
|
44
|
+
auto_increment = false;
|
|
45
|
+
auto_start = 1; //包含
|
|
46
|
+
type = EPropertyType.Varchar;
|
|
47
|
+
type_len = 45;
|
|
48
|
+
default = null;
|
|
49
|
+
}
|
|
50
|
+
exports.Property = Property;
|
|
51
|
+
class TableProperty {
|
|
52
|
+
static key = "___table___";
|
|
53
|
+
table = null;
|
|
54
|
+
version = 1;
|
|
55
|
+
engine = "InnoDB";
|
|
56
|
+
auto_increment = null;
|
|
57
|
+
charset = "utf8mb4";
|
|
58
|
+
comment = null;
|
|
59
|
+
items = new Map();
|
|
60
|
+
}
|
|
61
|
+
exports.TableProperty = TableProperty;
|
|
@@ -0,0 +1,15 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.Table = void 0;
|
|
4
|
+
const Property_1 = require("./Property");
|
|
5
|
+
function Table(table_name, version, comment, charset, auto_increment) {
|
|
6
|
+
return function (constructor) {
|
|
7
|
+
let table = constructor.prototype[Property_1.TableProperty.key] = constructor.prototype[Property_1.TableProperty.key] || new Property_1.TableProperty();
|
|
8
|
+
table.table = table_name;
|
|
9
|
+
table.version = version;
|
|
10
|
+
table.comment = comment || table.comment;
|
|
11
|
+
table.charset = charset || table.charset;
|
|
12
|
+
table.auto_increment = auto_increment || table.auto_increment;
|
|
13
|
+
};
|
|
14
|
+
}
|
|
15
|
+
exports.Table = Table;
|
|
@@ -0,0 +1,20 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.Type = void 0;
|
|
4
|
+
const Property_1 = require("./Property");
|
|
5
|
+
function Type(type, def, len) {
|
|
6
|
+
return function (target, propertyName) {
|
|
7
|
+
let table = target[Property_1.TableProperty.key] = target[Property_1.TableProperty.key] || new Property_1.TableProperty();
|
|
8
|
+
table.items[propertyName] = table.items[propertyName] || new Property_1.Property();
|
|
9
|
+
let pt = table.items[propertyName];
|
|
10
|
+
pt.type = type;
|
|
11
|
+
if (def != undefined) {
|
|
12
|
+
pt.default = def;
|
|
13
|
+
}
|
|
14
|
+
else {
|
|
15
|
+
pt.default = Property_1.EPropertyType.defs[type];
|
|
16
|
+
}
|
|
17
|
+
pt.type_len = len || pt.type_len;
|
|
18
|
+
};
|
|
19
|
+
}
|
|
20
|
+
exports.Type = Type;
|
|
@@ -0,0 +1,43 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.GMSSqlMgr = exports.MssqlReturn = void 0;
|
|
4
|
+
const mssql = require("mssql");
|
|
5
|
+
const FrameworkConfig_1 = require("../Config/FrameworkConfig");
|
|
6
|
+
const DBCache_1 = require("./Decorator/DBCache");
|
|
7
|
+
class MssqlReturn {
|
|
8
|
+
error = null;
|
|
9
|
+
fields = null;
|
|
10
|
+
list = null;
|
|
11
|
+
}
|
|
12
|
+
exports.MssqlReturn = MssqlReturn;
|
|
13
|
+
exports.GMSSqlMgr = null;
|
|
14
|
+
class MSSqlManager {
|
|
15
|
+
_init_cbs = [];
|
|
16
|
+
_pool = null;
|
|
17
|
+
get pool() {
|
|
18
|
+
return this._pool;
|
|
19
|
+
}
|
|
20
|
+
get isValid() {
|
|
21
|
+
return !!this._pool;
|
|
22
|
+
}
|
|
23
|
+
constructor() {
|
|
24
|
+
}
|
|
25
|
+
async init() {
|
|
26
|
+
if (this._pool
|
|
27
|
+
|| !FrameworkConfig_1.GFCfg.db.mssql
|
|
28
|
+
|| !FrameworkConfig_1.GFCfg.db.mssql.open) {
|
|
29
|
+
return;
|
|
30
|
+
}
|
|
31
|
+
this._pool = await mssql.connect(FrameworkConfig_1.GFCfg.db.mssql);
|
|
32
|
+
console.log("mssql config=" + JSON.stringify(FrameworkConfig_1.GFCfg.db.mssql));
|
|
33
|
+
//这个的初始化位置不能变,必须位于cbs前,pool后
|
|
34
|
+
await DBCache_1.GDBCache.init();
|
|
35
|
+
for (let i = 0; i < this._init_cbs.length; ++i) {
|
|
36
|
+
this._init_cbs[i]();
|
|
37
|
+
}
|
|
38
|
+
}
|
|
39
|
+
registerInitCb(cb) {
|
|
40
|
+
this._init_cbs.push(cb);
|
|
41
|
+
}
|
|
42
|
+
}
|
|
43
|
+
exports.GMSSqlMgr = new MSSqlManager();
|