mm_os 4.3.7 → 5.0.0

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.
Files changed (232) hide show
  1. package/README.md +101 -504
  2. package/index.js +26 -19
  3. package/lib/loader.js +787 -0
  4. package/lib/os.js +369 -0
  5. package/package.json +55 -84
  6. package/LICENSE +0 -21
  7. package/README_EN.md +0 -505
  8. package/adapter/adapter.js +0 -484
  9. package/adapter/custom_persistence.js +0 -661
  10. package/adapter/mqtt.js +0 -254
  11. package/adapter/socket.js +0 -244
  12. package/adapter/web.js +0 -92
  13. package/adapter/websocket.js +0 -43
  14. package/ai.js +0 -130
  15. package/com/api/README.md +0 -3
  16. package/com/api/com.json +0 -5
  17. package/com/api/config.tpl.json +0 -41
  18. package/com/api/drive.js +0 -732
  19. package/com/api/index.js +0 -201
  20. package/com/api/oauth.js +0 -200
  21. package/com/api/script.tpl.js +0 -32
  22. package/com/cmd/README.md +0 -11
  23. package/com/cmd/com.json +0 -5
  24. package/com/cmd/config.tpl.json +0 -48
  25. package/com/cmd/drive.js +0 -176
  26. package/com/cmd/index.js +0 -287
  27. package/com/cmd/job/config.json +0 -66
  28. package/com/cmd/job/index.js +0 -241
  29. package/com/cmd/job/test.js +0 -188
  30. package/com/cmd/msg.json +0 -48
  31. package/com/cmd/script.tpl.js +0 -12
  32. package/com/db/README.md +0 -3
  33. package/com/db/com.json +0 -5
  34. package/com/db/drive.js +0 -2206
  35. package/com/db/index.js +0 -241
  36. package/com/event/README.md +0 -4
  37. package/com/event/com.json +0 -5
  38. package/com/event/config.tpl.json +0 -20
  39. package/com/event/drive.js +0 -61
  40. package/com/event/index.js +0 -438
  41. package/com/event/script.tpl.js +0 -23
  42. package/com/mqtt/README.md +0 -47
  43. package/com/mqtt/com.json +0 -5
  44. package/com/mqtt/config.tpl.json +0 -42
  45. package/com/mqtt/drive.js +0 -704
  46. package/com/mqtt/index.js +0 -1052
  47. package/com/mqtt/index.test.js +0 -503
  48. package/com/mqtt/script.tpl.js +0 -719
  49. package/com/nav/README.md +0 -2
  50. package/com/nav/com.json +0 -5
  51. package/com/nav/config.tpl.json +0 -84
  52. package/com/nav/drive.js +0 -702
  53. package/com/nav/index.js +0 -228
  54. package/com/nav/tpl/admin_pc/page_channel.vue +0 -305
  55. package/com/nav/tpl/admin_pc/page_config.vue +0 -280
  56. package/com/nav/tpl/admin_pc/page_config_form.vue +0 -194
  57. package/com/nav/tpl/admin_pc/page_default.vue +0 -247
  58. package/com/nav/tpl/admin_pc/page_form.vue +0 -180
  59. package/com/nav/tpl/admin_pc/page_lang.vue +0 -264
  60. package/com/nav/tpl/admin_pc/page_nav.vue +0 -321
  61. package/com/nav/tpl/admin_pc/page_table.vue +0 -296
  62. package/com/nav/tpl/admin_pc/page_type.vue +0 -321
  63. package/com/nav/tpl/admin_pc/page_view.vue +0 -124
  64. package/com/nav/tpl/dev_pc/page_channel.vue +0 -253
  65. package/com/nav/tpl/dev_pc/page_config.vue +0 -253
  66. package/com/nav/tpl/dev_pc/page_default.vue +0 -247
  67. package/com/nav/tpl/dev_pc/page_form.vue +0 -162
  68. package/com/nav/tpl/dev_pc/page_nav.vue +0 -253
  69. package/com/nav/tpl/dev_pc/page_table.vue +0 -247
  70. package/com/nav/tpl/dev_pc/page_type.vue +0 -313
  71. package/com/nav/tpl/home_pc/page_channel.vue +0 -234
  72. package/com/nav/tpl/home_pc/page_default.vue +0 -234
  73. package/com/nav/tpl/home_pc/page_form.vue +0 -137
  74. package/com/nav/tpl/home_pc/page_list.vue +0 -234
  75. package/com/nav/tpl/home_pc/page_nav.vue +0 -221
  76. package/com/nav/tpl/home_pc/page_type.vue +0 -234
  77. package/com/nav/tpl/home_pc/page_view.vue +0 -125
  78. package/com/nav/tpl/home_phone/page_channel.vue +0 -234
  79. package/com/nav/tpl/home_phone/page_default.vue +0 -234
  80. package/com/nav/tpl/home_phone/page_form.vue +0 -137
  81. package/com/nav/tpl/home_phone/page_list.vue +0 -234
  82. package/com/nav/tpl/home_phone/page_nav.vue +0 -237
  83. package/com/nav/tpl/home_phone/page_type.vue +0 -234
  84. package/com/nav/tpl/home_phone/page_view.vue +0 -125
  85. package/com/nav/viewmodel.js +0 -446
  86. package/com/param/README.md +0 -2
  87. package/com/param/com.json +0 -5
  88. package/com/param/config.tpl.json +0 -136
  89. package/com/param/drive.js +0 -502
  90. package/com/param/index.js +0 -158
  91. package/com/param/script.tpl.js +0 -12
  92. package/com/pendant/README.md +0 -3
  93. package/com/pendant/com.json +0 -5
  94. package/com/pendant/config.tpl.json +0 -32
  95. package/com/pendant/drive.js +0 -204
  96. package/com/pendant/index.js +0 -467
  97. package/com/pendant/pendant.html +0 -16
  98. package/com/pendant/script.tpl.js +0 -18
  99. package/com/socket/README.md +0 -47
  100. package/com/socket/com.json +0 -5
  101. package/com/socket/config.tpl.json +0 -12
  102. package/com/socket/drive.js +0 -679
  103. package/com/socket/index.js +0 -402
  104. package/com/socket/script.tpl.js +0 -41
  105. package/com/sql/README.md +0 -3
  106. package/com/sql/com.json +0 -5
  107. package/com/sql/config.tpl.json +0 -74
  108. package/com/sql/drive.js +0 -1328
  109. package/com/sql/index.js +0 -152
  110. package/com/sql/script.tpl.js +0 -47
  111. package/com/static/README.md +0 -2
  112. package/com/static/com.json +0 -5
  113. package/com/static/config.tpl.json +0 -24
  114. package/com/static/drive.js +0 -194
  115. package/com/static/index.js +0 -237
  116. package/com/static/script.tpl.js +0 -28
  117. package/com/task/README.md +0 -3
  118. package/com/task/com.json +0 -5
  119. package/com/task/config.tpl.json +0 -24
  120. package/com/task/drive.js +0 -428
  121. package/com/task/index.js +0 -159
  122. package/com/task/script.tpl.js +0 -40
  123. package/com/template/com.json +0 -5
  124. package/com/template/config.tpl.json +0 -16
  125. package/com/template/drive.js +0 -81
  126. package/com/template/index.js +0 -141
  127. package/com.js +0 -237
  128. package/common/README.md +0 -2
  129. package/common/middleware/web_after/index.js +0 -26
  130. package/common/middleware/web_after/middleware.json +0 -9
  131. package/common/middleware/web_base/index.js +0 -113
  132. package/common/middleware/web_base/middleware.json +0 -19
  133. package/common/middleware/web_before/index.js +0 -33
  134. package/common/middleware/web_before/middleware.json +0 -9
  135. package/common/middleware/web_cors/index.js +0 -87
  136. package/common/middleware/web_cors/middleware.json +0 -24
  137. package/common/middleware/web_error/index.js +0 -131
  138. package/common/middleware/web_error/middleware.json +0 -19
  139. package/common/middleware/web_ip/index.js +0 -15
  140. package/common/middleware/web_ip/middleware.json +0 -14
  141. package/common/middleware/web_logger/index.js +0 -156
  142. package/common/middleware/web_logger/middleware.json +0 -14
  143. package/common/middleware/web_main/index.js +0 -26
  144. package/common/middleware/web_main/middleware.json +0 -9
  145. package/common/middleware/web_static/index.js +0 -73
  146. package/common/middleware/web_static/middleware.json +0 -54
  147. package/common/middleware/web_waf/index.js +0 -395
  148. package/common/middleware/web_waf/middleware.json +0 -13
  149. package/core/app/config.tpl.json +0 -67
  150. package/core/app/index.js +0 -711
  151. package/core/app/script.tpl.js +0 -52
  152. package/core/channel/index.js +0 -899
  153. package/core/channel/matcher.js +0 -585
  154. package/core/com/config.tpl.json +0 -16
  155. package/core/com/index.js +0 -77
  156. package/core/com/script.tpl.js +0 -5
  157. package/core/component/component.js +0 -42
  158. package/core/component/config.tpl.json +0 -63
  159. package/core/component/index.js +0 -273
  160. package/core/component/script.tpl.js +0 -19
  161. package/core/controller/config.tpl.json +0 -14
  162. package/core/controller/index.js +0 -371
  163. package/core/controller/script.tpl.js +0 -27
  164. package/core/factory/config.tpl.json +0 -14
  165. package/core/factory/entity.js +0 -275
  166. package/core/factory/index.js +0 -241
  167. package/core/factory/script.tpl.js +0 -16
  168. package/core/game/bat/index.js +0 -137
  169. package/core/game/bat/world.js +0 -622
  170. package/core/game/config.tpl.json +0 -16
  171. package/core/game/entity_admin.js +0 -230
  172. package/core/game/index.js +0 -186
  173. package/core/handler/config.tpl.json +0 -22
  174. package/core/handler/index.js +0 -181
  175. package/core/handler/script.tpl.js +0 -23
  176. package/core/logic/config.tpl.json +0 -14
  177. package/core/logic/index.js +0 -59
  178. package/core/logic/script.tpl.js +0 -19
  179. package/core/middleware/config.tpl.json +0 -16
  180. package/core/middleware/index.js +0 -117
  181. package/core/middleware/script.tpl.js +0 -37
  182. package/core/mod/config.tpl.json +0 -22
  183. package/core/mod/index.js +0 -136
  184. package/core/mod/script.tpl.js +0 -34
  185. package/core/model/config.tpl.json +0 -219
  186. package/core/model/index.js +0 -272
  187. package/core/model/model.js +0 -27
  188. package/core/model/script.tpl.js +0 -20
  189. package/core/notifier/config.tpl.json +0 -14
  190. package/core/notifier/index.js +0 -77
  191. package/core/notifier/script.tpl.js +0 -20
  192. package/core/plugin/config.tpl.json +0 -36
  193. package/core/plugin/index.js +0 -267
  194. package/core/plugin/script.tpl.js +0 -51
  195. package/core/pusher/config.tpl.json +0 -14
  196. package/core/pusher/index.js +0 -158
  197. package/core/pusher/script.tpl.js +0 -20
  198. package/core/room/bat/index.js +0 -170
  199. package/core/room/bat/room.js +0 -524
  200. package/core/room/config.tpl.json +0 -20
  201. package/core/room/index.js +0 -249
  202. package/core/room/room.js +0 -61
  203. package/core/scene/config.tpl.json +0 -14
  204. package/core/scene/index.js +0 -467
  205. package/core/scene/loop.js +0 -1306
  206. package/core/scene/map.js +0 -28
  207. package/core/scene/script.tpl.js +0 -22
  208. package/core/sender/config.tpl.json +0 -14
  209. package/core/sender/index.js +0 -79
  210. package/core/sender/script.tpl.js +0 -20
  211. package/core/service/config.tpl.json +0 -14
  212. package/core/service/index.js +0 -100
  213. package/core/service/script.tpl.js +0 -25
  214. package/core/store/config.tpl.json +0 -26
  215. package/core/store/index.js +0 -1794
  216. package/core/store/script.tpl.js +0 -22
  217. package/core/system/config.tpl.json +0 -18
  218. package/core/system/index.js +0 -312
  219. package/core/system/script.tpl.js +0 -77
  220. package/core/view/config.tpl.json +0 -14
  221. package/core/view/index.js +0 -91
  222. package/core/view/script.tpl.js +0 -20
  223. package/core/zone/bat/index.js +0 -744
  224. package/core/zone/config.tpl.json +0 -54
  225. package/core/zone/index.js +0 -655
  226. package/core/zone/script.tpl.js +0 -10
  227. package/core/zone/zone_bat.js +0 -136
  228. package/core//345/237/272/347/261/273/346/250/241/345/235/227/346/270/205/345/215/225.md +0 -24
  229. package/os.js +0 -53
  230. package/server.js +0 -602
  231. package/ulits/id_gen.js +0 -134
  232. package/ulits/word.js +0 -206
package/com/cmd/index.js DELETED
@@ -1,287 +0,0 @@
1
- require('mm_expand');
2
- const Manager = require('mm_machine').Manager;
3
- const Drive = require('./drive');
4
-
5
- /**
6
- * 指令管理器
7
- */
8
- class Cmd extends Manager {
9
- static config = {
10
- name: '',
11
- title: '指令管理',
12
- filename: 'cmd.json',
13
- tpl_dir: __dirname,
14
- dir: './app'.fullname(),
15
- search_way: 'file',
16
- session_timeout: 600,
17
- };
18
-
19
- /**
20
- * 构造函数
21
- * @param {object} config 配置参数
22
- * @param {object} parent 父级模块
23
- */
24
- constructor(config, parent) {
25
- super({ ...Cmd.config, ...config }, parent);
26
- this.list_before = [];
27
- this.list_main = [];
28
- this.list_after = [];
29
- }
30
- }
31
-
32
- /**
33
- * Cmd驱动类
34
- */
35
- Cmd.prototype.Drive = Drive;
36
-
37
- /**
38
- * 构建指令列表
39
- * @private
40
- */
41
- Cmd.prototype._fullList = function () {
42
- this.list_before.clear();
43
- this.list_main.clear();
44
- this.list_after.clear();
45
-
46
- var infos = this.getInfos();
47
- for (var i = 0; i < infos.length; i++) {
48
- var info = infos[i];
49
- if (info.state !== 1) {
50
- continue;
51
- }
52
- var mod = this.getMod(info.name);
53
- if (!mod) {
54
- continue;
55
- }
56
- switch (mod.config.tense) {
57
- case 'before':
58
- this.list_before.push(info);
59
- break;
60
- case 'after':
61
- this.list_after.push(info);
62
- break;
63
- default:
64
- this.list_main.push(info);
65
- break;
66
- }
67
- }
68
- };
69
-
70
- /**
71
- * 更新后回调
72
- * @param {string} dir_path 目录路径
73
- */
74
- Cmd.prototype.updateAfter = async function (dir_path) {
75
- this._fullList();
76
- };
77
-
78
- /**
79
- * 执行指令
80
- * @param {object} msg 消息对象
81
- * @param {object} db 数据管理器
82
- * @returns {object|string} 返回执行结果
83
- */
84
- Cmd.prototype.run = async function (msg, db) {
85
- if (!msg || !msg.content) {
86
- return null;
87
- }
88
- var ret;
89
- var session = await this._getSession(msg);
90
-
91
- if (session) {
92
- ret = await this._runSession(msg, db, session);
93
- } else {
94
- ret = await this.runSub(msg, db, 'before');
95
- if (!ret) {
96
- ret = await this.runSub(msg, db, 'main');
97
- }
98
- if (!ret) {
99
- ret = await this.runSub(msg, db, 'after');
100
- }
101
- }
102
- ret = this._make(msg, ret);
103
- db.ret = ret;
104
- return ret;
105
- };
106
-
107
- /**
108
- * 按列表执行指令
109
- * @param {object} msg 消息对象
110
- * @param {object} db 数据管理器
111
- * @param {string} tense 时态
112
- * @returns {object|string} 返回执行结果
113
- */
114
- Cmd.prototype.runSub = async function (msg, db, tense) {
115
- var list = this['list_' + tense];
116
- if (!list) {
117
- return null;
118
- }
119
- var ret;
120
- for (var i = 0; i < list.length; i++) {
121
- var info = list[i];
122
- if (info.state !== 1) {
123
- continue;
124
- }
125
- var mod = this.getMod(info.name);
126
- if (!mod) {
127
- continue;
128
- }
129
- ret = await mod.run(msg, db);
130
- if (ret) {
131
- msg.cmd = info.name;
132
- if (msg.end === 0) {
133
- this._saveSession(msg, {
134
- cmd: msg.cmd,
135
- form: msg.form,
136
- stage: msg.stage,
137
- });
138
- break;
139
- }
140
- if (mod.config.end) {
141
- break;
142
- }
143
- }
144
- }
145
- return ret;
146
- };
147
-
148
- /**
149
- * 继续执行会话指令
150
- * @param {object} msg 消息对象
151
- * @param {object} db 数据管理器
152
- * @param {object} session 会话信息
153
- * @returns {object|string} 返回执行结果
154
- * @private
155
- */
156
- Cmd.prototype._runSession = async function (msg, db, session) {
157
- var mod = this.getMod(session.cmd);
158
- if (!mod) {
159
- this._clearSession(msg);
160
- return null;
161
- }
162
- msg.cmd = session.cmd;
163
- msg.form = session.form;
164
- msg.stage = session.stage;
165
- msg.end = 0;
166
-
167
- try {
168
- var ret = await mod.run(msg, db);
169
- if (msg.end === 0) {
170
- this._saveSession(msg, {
171
- cmd: msg.cmd,
172
- form: msg.form,
173
- stage: msg.stage,
174
- });
175
- } else {
176
- this._clearSession(msg);
177
- }
178
- return ret;
179
- } catch (error) {
180
- this.log('error', '会话指令执行失败', error.message);
181
- this._clearSession(msg);
182
- return null;
183
- }
184
- };
185
-
186
- /**
187
- * 包装出站消息, from_user/to_user 反转
188
- * @param {object} msg 入站消息
189
- * @param {object|string} ret 原始返回值
190
- * @returns {object} 出站消息
191
- * @private
192
- */
193
- Cmd.prototype._makeResult = function (msg, ret) {
194
- if (!ret) return ret;
195
- var result = typeof ret === 'string' ? { content: ret } : { ...ret };
196
- if (msg.to_user) result.from_user = msg.to_user;
197
- if (msg.from_user) result.to_user = msg.from_user;
198
- if (msg.chatid) result.chatid = msg.chatid;
199
- if (msg.cmd) result.cmd = msg.cmd;
200
- if (msg.form) result.form = msg.form;
201
- if (msg.end != null) result.end = msg.end;
202
- return result;
203
- };
204
-
205
- /**
206
- * 获取会话
207
- * @param {object} msg 消息对象
208
- * @returns {object|null} 会话信息
209
- * @private
210
- */
211
- Cmd.prototype._getSession = async function (msg) {
212
- var key = this._getKey(msg);
213
- var val = await $.cache.get(key);
214
- if (!val) {
215
- return null;
216
- }
217
- if (typeof val === 'string') {
218
- return JSON.parse(val);
219
- }
220
- return val;
221
- };
222
-
223
- /**
224
- * 保存会话
225
- * @param {object} msg 消息对象
226
- * @param {object} session 会话信息
227
- * @private
228
- */
229
- Cmd.prototype._saveSession = function (msg, session) {
230
- var key = this._getKey(msg);
231
- $.cache.set(key, session, this.config.session_timeout);
232
- };
233
-
234
- /**
235
- * 清除会话
236
- * @param {object} msg 消息对象
237
- * @private
238
- */
239
- Cmd.prototype._clearSession = function (msg) {
240
- var key = this._getKey(msg);
241
- $.cache.del(key);
242
- };
243
-
244
- /**
245
- * 获取会话缓存键
246
- * @param {object} msg 消息对象
247
- * @returns {string} 缓存键
248
- * @private
249
- */
250
- Cmd.prototype._getKey = function (msg) {
251
- return 'cmd_session_' + (msg.chatid || msg.from_user || 'default');
252
- };
253
-
254
- module.exports = { Cmd };
255
-
256
- /**
257
- * Cmd事件池
258
- */
259
- if (!$.pool.cmd) {
260
- $.pool.cmd = {};
261
- }
262
-
263
- /**
264
- * Cmd管理器工厂函数
265
- * @param {string} scope 作用域
266
- * @param {string} title 标题
267
- * @returns {object} 返回Cmd管理器实例
268
- */
269
- function cmdAdmin(scope, title) {
270
- var sc = scope || $.val.scope + '';
271
- var obj = $.pool.cmd[sc];
272
- if (!obj) {
273
- $.pool.cmd[sc] = new Cmd({
274
- name: sc,
275
- title: title || sc,
276
- });
277
- obj = $.pool.cmd[sc];
278
- }
279
- return obj;
280
- }
281
-
282
- /**
283
- * 注册到全局管理器
284
- */
285
- if ($.admin) {
286
- $.admin.cmd = cmdAdmin;
287
- }
@@ -1,66 +0,0 @@
1
- {
2
- "name": "job",
3
- "title": "找工作",
4
- "description": "用户输入求职意向, 登记信息并搜索匹配岗位",
5
- "main": "./index.js",
6
- "state": 1,
7
- "tense": "main",
8
- "match": ["找工作", "求职", "应聘", "找工作"],
9
- "not": [],
10
- "sort": 100,
11
- "end": 1,
12
- "params": {
13
- "properties": {
14
- "position": {
15
- "type": "string",
16
- "description": "意向岗位",
17
- "example": "前端开发",
18
- "question": "你想找什么岗位的工作?比如: 前端开发、后端开发、UI设计",
19
- "match": "{中文}",
20
- "default": null
21
- },
22
- "name": {
23
- "type": "string",
24
- "description": "姓名",
25
- "example": "张三",
26
- "match": "{中文}",
27
- "default": null
28
- },
29
- "phone": {
30
- "type": "string",
31
- "description": "手机号码",
32
- "example": "13800138000",
33
- "match": "{手机号码}",
34
- "default": null
35
- },
36
- "location": {
37
- "type": "string",
38
- "description": "工作地点",
39
- "example": "深圳",
40
- "question": "想在哪个城市工作?",
41
- "match": "{中文}",
42
- "enum": [
43
- "北京",
44
- "上海",
45
- "广州",
46
- "深圳",
47
- "杭州",
48
- "成都",
49
- "武汉",
50
- "南京"
51
- ],
52
- "default": null
53
- },
54
- "salary": {
55
- "type": "string",
56
- "description": "期望薪资",
57
- "example": "15k",
58
- "question": "期望薪资多少?比如: 10k-15k",
59
- "match": "{数字}k",
60
- "remove": ["k"],
61
- "default": null
62
- }
63
- },
64
- "required": ["position"]
65
- }
66
- }
@@ -1,241 +0,0 @@
1
- /**
2
- * 模拟岗位库
3
- */
4
- var jobPool = [
5
- {
6
- title: '前端开发工程师',
7
- company: '科技公司A',
8
- location: '深圳',
9
- salary: '12k-18k',
10
- },
11
- {
12
- title: '高级前端开发',
13
- company: '互联网公司B',
14
- location: '北京',
15
- salary: '18k-25k',
16
- },
17
- {
18
- title: '前端架构师',
19
- company: '金融科技C',
20
- location: '上海',
21
- salary: '25k-35k',
22
- },
23
- {
24
- title: 'Web前端开发',
25
- company: '电商平台D',
26
- location: '广州',
27
- salary: '10k-15k',
28
- },
29
- {
30
- title: 'React前端工程师',
31
- company: '游戏公司E',
32
- location: '杭州',
33
- salary: '15k-22k',
34
- },
35
- {
36
- title: 'Vue前端开发',
37
- company: '教育科技F',
38
- location: '成都',
39
- salary: '10k-16k',
40
- },
41
- {
42
- title: '前端负责人',
43
- company: 'AI公司G',
44
- location: '深圳',
45
- salary: '20k-30k',
46
- },
47
- {
48
- title: '全栈开发',
49
- company: '创业公司H',
50
- location: '北京',
51
- salary: '15k-25k',
52
- },
53
- {
54
- title: '后端开发工程师',
55
- company: '云计算I',
56
- location: '深圳',
57
- salary: '15k-22k',
58
- },
59
- {
60
- title: 'Java开发',
61
- company: '银行J',
62
- location: '上海',
63
- salary: '14k-20k',
64
- },
65
- {
66
- title: 'Go开发工程师',
67
- company: '区块链K',
68
- location: '杭州',
69
- salary: '20k-30k',
70
- },
71
- {
72
- title: 'Python开发',
73
- company: 'AI公司L',
74
- location: '北京',
75
- salary: '18k-28k',
76
- },
77
- {
78
- title: 'UI设计师',
79
- company: '设计公司M',
80
- location: '上海',
81
- salary: '12k-18k',
82
- },
83
- {
84
- title: '产品经理',
85
- company: '互联网公司N',
86
- location: '深圳',
87
- salary: '15k-25k',
88
- },
89
- {
90
- title: '测试工程师',
91
- company: '软件公司O',
92
- location: '武汉',
93
- salary: '10k-15k',
94
- },
95
- {
96
- title: '运维工程师',
97
- company: '数据中心P',
98
- location: '南京',
99
- salary: '12k-18k',
100
- },
101
- ];
102
-
103
- /**
104
- * 解析薪资范围取中间值
105
- * @param {string} range 薪资范围字符串, 如 "12k-18k"
106
- * @returns {number} 中间值
107
- */
108
- function getAvg(range) {
109
- var parts = range.replace(/k/g, '').split('-');
110
- return (parseInt(parts[0], 10) + parseInt(parts[1], 10)) / 2;
111
- }
112
-
113
- /**
114
- * 按关键词过滤岗位
115
- * @param {Array} lt 岗位列表
116
- * @param {string} kw 关键词
117
- * @returns {Array} 过滤结果
118
- */
119
- function filterByKw(lt, kw) {
120
- var ret = lt.filter((j) => {
121
- return j.title.indexOf(kw) !== -1 || j.title.indexOf(kw.replace('开发', '')) !== -1;
122
- });
123
- return ret.length > 0 ? ret : jobPool.slice(0, 5);
124
- }
125
-
126
- /**
127
- * 按城市排序
128
- * @param {Array} lt 岗位列表
129
- * @param {string} loc 目标城市
130
- */
131
- function sortByLocation(lt, loc) {
132
- lt.sort((a, b) => {
133
- if (a.location === loc && b.location !== loc) return -1;
134
- if (b.location === loc && a.location !== loc) return 1;
135
- return 0;
136
- });
137
- }
138
-
139
- /**
140
- * 按薪资接近度排序
141
- * @param {Array} lt 岗位列表
142
- * @param {string} salary 期望薪资
143
- */
144
- function sortBySalary(lt, salary) {
145
- var target = parseInt(salary, 10) || 15;
146
- lt.sort((a, b) => {
147
- return Math.abs(getAvg(a.salary) - target) - Math.abs(getAvg(b.salary) - target);
148
- });
149
- }
150
-
151
- /**
152
- * 格式化岗位列表为文本
153
- * @param {Array} lt 岗位列表
154
- * @returns {string} 格式化文本
155
- */
156
- function formatList(lt) {
157
- var list = lt.slice(0, 4).map((j, i) => {
158
- return (i + 1) + '. ' + j.title + ' | ' + j.company + ' | ' + j.location + ' | ' + j.salary;
159
- });
160
- return '为你找到以下岗位:\n\n' + list.join('\n') + '\n\n已登记求职信息, 有合适岗位将推送通知';
161
- }
162
-
163
- /**
164
- * 搜索岗位
165
- * @param {object} form 用户表单
166
- * @returns {string} 搜索结果文本
167
- */
168
- function search(form) {
169
- var results = jobPool.slice();
170
- if (form.position) {
171
- results = filterByKw(results, form.position);
172
- }
173
- if (form.location) {
174
- sortByLocation(results, form.location);
175
- }
176
- if (form.salary) {
177
- sortBySalary(results, form.salary);
178
- }
179
- return formatList(results);
180
- }
181
-
182
- /**
183
- * 收集缺失的可选信息
184
- * @param {object} form 用户表单
185
- * @returns {Array} 缺失信息列表
186
- */
187
- function getMissing(form) {
188
- var missing = [];
189
- if (!form.name) missing.push('姓名');
190
- if (!form.phone) missing.push('手机号');
191
- if (!form.location) missing.push('工作城市');
192
- if (!form.salary) missing.push('期望薪资(如: 15k)');
193
- return missing;
194
- }
195
-
196
- /**
197
- * 构建已收集信息摘要
198
- * @param {object} form 用户表单
199
- * @returns {Array} 摘要行
200
- */
201
- function buildSummary(form) {
202
- var has = ['岗位: ' + form.position];
203
- if (form.location) has.push('城市: ' + form.location);
204
- if (form.salary) has.push('薪资: ' + form.salary + 'k');
205
- if (form.name) has.push('姓名: ' + form.name);
206
- return has;
207
- }
208
-
209
- module.exports = {
210
- /**
211
- * 执行指令主函数
212
- * @param {object} msg 消息对象
213
- * @param {object} db 数据管理器
214
- * @returns {object|string} 执行结果
215
- */
216
- async main(msg, db) {
217
- var form = msg.form || {};
218
- if (msg.content === '搜索' || msg.content === '好了' || msg.content === '跳过') {
219
- return search(form);
220
- }
221
- var missing = getMissing(form);
222
- if (missing.length > 0) {
223
- msg.end = 0;
224
- return (
225
- '已收集:\n' +
226
- buildSummary(form).join('\n') +
227
- '\n\n还需要: ' +
228
- missing.join('、') +
229
- '\n请回复补充, 或回复"搜索"直接查找'
230
- );
231
- }
232
- if (db && db.table) {
233
- try {
234
- await db.table('job_candidate').addObj(form);
235
- } catch {
236
- // 登记失败不影响搜索
237
- }
238
- }
239
- return search(form);
240
- },
241
- };