topics.repo.js 21 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546
  1. /**
  2. * 搜索功能。
  3. */
  4. "use strict";
  5. let ImDb = require('../mysql/db/im.db');
  6. let log = require('../../util/log.js');
  7. const DB_TABLES = require('../../include/commons').DB_TABLES;
  8. class TopicRepo {
  9. constructor() {
  10. }
  11. /**
  12. * 查找议题.
  13. *
  14. * @param topicId
  15. * @param handler
  16. */
  17. static findOne(topicId, handler) {
  18. let sql = "select id, session_id, name, create_time, end_by, end_time," +
  19. " start_message_id, end_message_id, description, status from " + DB_TABLES.Topics + " where id = ?";
  20. ImDb.execQuery({
  21. sql: sql,
  22. args: [topicId],
  23. handler: handler || function (err, res) {
  24. if (err) log.error(err);
  25. }
  26. });
  27. }
  28. static findLastTopicStatus(sessionId, handler) {
  29. let sql = "select id from " + DB_TABLES.Topics + " where session_id = ? order by create_time desc limit 0, 1";
  30. ImDb.execQuery({
  31. sql: sql,
  32. args: [sessionId],
  33. handler: function (err, res) {
  34. if (res.length == 0) {
  35. handler(null, null);
  36. } else {
  37. TopicRepo.findTopicStatus(res[0].id, handler);
  38. }
  39. }
  40. });
  41. }
  42. static findLastBySessionId(sessionId, handler) {
  43. let sql = "select * from " + DB_TABLES.Topics + " where session_id = ? order by create_time desc limit 0, 1";
  44. ImDb.execQuery({
  45. sql: sql,
  46. args: [sessionId],
  47. handler: function (err, res) {
  48. handler(err, res);
  49. }
  50. });
  51. }
  52. //查找家庭病床医生发起的咨询
  53. static findBedBySessionId(sessionId, handler) {
  54. let sql = "select * from " + DB_TABLES.Sessions + " where session_id = ? and type=7 ";
  55. ImDb.execQuery({
  56. sql: sql,
  57. args: [sessionId],
  58. handler: function (err, res) {
  59. handler(err, res);
  60. }
  61. });
  62. }
  63. static findAllByUserAndReplyAndStatus(userId,reply,status,page,size,handler){
  64. let sql = "";
  65. var args =[];
  66. if(status==10){
  67. args.push(userId,status,page,size);
  68. sql = "SELECT t.*, s.avatar,s.sex,s.birthdate, s.`name` AS patient_name,c.doctor FROM "+
  69. DB_TABLES.Topics+" t,"+DB_TABLES.Participants+" p,"+DB_TABLES.Doctors+" d,"+DB_TABLES.WlyyConsult+" c,"+DB_TABLES.Patients+" s "+
  70. "WHERE d.id = p.participant_id AND c.id = t.id AND c.patient = s.id AND p.session_id = t.session_id "+
  71. "AND d.id in (?) AND t. STATUS = ? ORDER BY create_time DESC limit ?,?";
  72. }else{
  73. args.push(userId,status,reply,page,size);
  74. sql = "SELECT t.*, s.avatar,s.sex,s.birthdate, s.`name` AS patient_name,c.doctor FROM "+
  75. DB_TABLES.Topics+" t,"+DB_TABLES.Participants+" p,"+DB_TABLES.Doctors+" d,"+DB_TABLES.WlyyConsult+" c,"+DB_TABLES.Patients+" s "+
  76. "WHERE d.id = p.participant_id AND c.id = t.id AND c.patient = s.id AND p.session_id = t.session_id "+
  77. "AND d.id in (?) AND t. STATUS = ? and t.reply=? ORDER BY create_time DESC limit ?,?";
  78. }
  79. ImDb.execQuery({
  80. sql: sql,
  81. args: args,
  82. handler: function (err, res) {
  83. handler(err, res);
  84. }
  85. });
  86. }
  87. /**
  88. * 过滤名医咨询和续方咨询
  89. * @param userId
  90. * @param reply
  91. * @param status
  92. * @param page
  93. * @param size
  94. * @param patient
  95. * @param patientName
  96. * @param handler
  97. */
  98. static findAllByUserAndReplyAndStatusHealthTopic(userId,reply,status,page,size,patient,patientName,handler){
  99. let sql = "";
  100. var args =[];
  101. var tempParms = "";
  102. if (patient){
  103. tempParms += " and s.id='"+patient+"' ";
  104. }
  105. if (patientName){
  106. tempParms += " and s.name like '%"+patientName+"%' ";
  107. }
  108. if(status==10){
  109. args.push(userId,status,page,size);
  110. sql = "SELECT t.*, s.avatar,s.sex,s.birthdate, s.`name` AS patient_name,c.doctor FROM "+
  111. DB_TABLES.Topics+" t,"+DB_TABLES.Participants+" p,"+DB_TABLES.Doctors+" d,"+DB_TABLES.WlyyConsult+" c,"+DB_TABLES.Patients+" s "+
  112. "WHERE d.id = p.participant_id AND c.id = t.id AND c.patient = s.id AND p.session_id = t.session_id "+
  113. "AND d.id in (?) AND t. STATUS = ? AND c.type not in ('3','6','8')"+tempParms+" ORDER BY create_time DESC limit ?,?";
  114. }else{
  115. args.push(userId,status,reply,page,size);
  116. sql = "SELECT t.*, s.avatar,s.sex,s.birthdate, s.`name` AS patient_name,c.doctor FROM "+
  117. DB_TABLES.Topics+" t,"+DB_TABLES.Participants+" p,"+DB_TABLES.Doctors+" d,"+DB_TABLES.WlyyConsult+" c,"+DB_TABLES.Patients+" s "+
  118. "WHERE d.id = p.participant_id AND c.id = t.id AND c.patient = s.id AND p.session_id = t.session_id "+
  119. "AND d.id in (?) AND t. STATUS = ? and t.reply=? AND c.type not in ('3','6','8')"+tempParms+" ORDER BY create_time DESC limit ?,?";
  120. }
  121. ImDb.execQuery({
  122. sql: sql,
  123. args: args,
  124. handler: function (err, res) {
  125. handler(err, res);
  126. }
  127. });
  128. }
  129. /**
  130. * 按类型查找医生的未回复,进行中,已完成的咨询
  131. * @param userId
  132. * @param reply
  133. * @param status
  134. * @param type
  135. * @param patient
  136. * @param patientName
  137. * @param startTime
  138. * @param endTime
  139. * @param page
  140. * @param size
  141. * @param handler
  142. */
  143. static findAllTopicByType(userId,reply,status,type,patient,patientName,startTime,endTime,page,size,handler){
  144. let sql = "";
  145. var args =[];
  146. var tempParms = "";
  147. if(patient){
  148. tempParms += " and s.id = '"+patient+"' ";
  149. }
  150. if(patientName){
  151. tempParms += " and s.name like '%"+patientName+"%' ";
  152. }
  153. if(startTime){
  154. tempParms += " and t.create_time >= '"+startTime+"' ";
  155. }
  156. if(endTime){
  157. tempParms += " and t.create_time <= '"+endTime+"' ";
  158. }
  159. if(type){
  160. if(status==10){
  161. args.push(userId,status,type,page,size);
  162. sql = "SELECT t.*, s.avatar,s.sex,s.birthdate, s.`name` AS patient_name,c.doctor,c.type FROM "+
  163. DB_TABLES.Topics+" t,"+DB_TABLES.Participants+" p,"+DB_TABLES.Doctors+" d,"+DB_TABLES.WlyyConsult+" c,"+DB_TABLES.Patients+" s "+
  164. "WHERE d.id = p.participant_id AND c.id = t.id AND c.patient = s.id AND p.session_id = t.session_id "+
  165. "AND d.id in (?) AND t. STATUS = ? AND c.type =? "+tempParms+" ORDER BY create_time DESC limit ?,?";
  166. }else{
  167. args.push(userId,status,reply,type,page,size);
  168. sql = "SELECT t.*, s.avatar,s.sex,s.birthdate, s.`name` AS patient_name,c.doctor,c.type FROM "+
  169. DB_TABLES.Topics+" t,"+DB_TABLES.Participants+" p,"+DB_TABLES.Doctors+" d,"+DB_TABLES.WlyyConsult+" c,"+DB_TABLES.Patients+" s "+
  170. "WHERE d.id = p.participant_id AND c.id = t.id AND c.patient = s.id AND p.session_id = t.session_id "+
  171. "AND d.id in (?) AND t. STATUS = ? and t.reply=? AND c.type = ? "+tempParms+" ORDER BY create_time DESC limit ?,?";
  172. }
  173. }else{
  174. if(status==10){
  175. args.push(userId,status,page,size);
  176. sql = "SELECT t.*, s.avatar,s.sex,s.birthdate, s.`name` AS patient_name,c.doctor,c.type FROM "+
  177. DB_TABLES.Topics+" t,"+DB_TABLES.Participants+" p,"+DB_TABLES.Doctors+" d,"+DB_TABLES.WlyyConsult+" c,"+DB_TABLES.Patients+" s "+
  178. "WHERE d.id = p.participant_id AND c.id = t.id AND c.patient = s.id AND p.session_id = t.session_id "+
  179. "AND d.id in (?) AND t. STATUS = ? "+tempParms+" ORDER BY create_time DESC limit ?,?";
  180. }else{
  181. args.push(userId,status,reply,page,size);
  182. sql = "SELECT t.*, s.avatar,s.sex,s.birthdate, s.`name` AS patient_name,c.doctor,c.type FROM "+
  183. DB_TABLES.Topics+" t,"+DB_TABLES.Participants+" p,"+DB_TABLES.Doctors+" d,"+DB_TABLES.WlyyConsult+" c,"+DB_TABLES.Patients+" s "+
  184. "WHERE d.id = p.participant_id AND c.id = t.id AND c.patient = s.id AND p.session_id = t.session_id "+
  185. "AND d.id in (?) AND t. STATUS = ? and t.reply=? "+tempParms+" ORDER BY create_time DESC limit ?,?";
  186. }
  187. }
  188. log.info("sql:"+sql);
  189. ImDb.execQuery({
  190. sql: sql,
  191. args: args,
  192. handler: function (err, res) {
  193. handler(err, res);
  194. }
  195. });
  196. }
  197. /**
  198. * 按类型查找医生的未回复,进行中,已完成的咨询 总数
  199. * @param userId
  200. * @param reply
  201. * @param status
  202. * @param type
  203. * @param handler
  204. */
  205. static topicListCountByType(userId,reply,status,type,patientName,startTime,endTime,handler){
  206. let sql = "";
  207. var args =[];
  208. var tempParms = "";
  209. if(patientName){
  210. tempParms += " and s.name like '%"+patientName+"%' ";
  211. }
  212. if(startTime){
  213. tempParms += " and t.create_time >= '"+startTime+"' ";
  214. }
  215. if(endTime){
  216. tempParms += " and t.create_time <= '"+endTime+"' ";
  217. }
  218. if(status==10){
  219. args.push(userId,status,type);
  220. sql = "SELECT count(t.id) count FROM "+
  221. DB_TABLES.Topics+" t,"+DB_TABLES.Participants+" p,"+DB_TABLES.Doctors+" d,"+DB_TABLES.WlyyConsult+" c,"+DB_TABLES.Patients+" s "+
  222. "WHERE d.id = p.participant_id AND c.id = t.id AND c.patient = s.id AND p.session_id = t.session_id "+
  223. "AND d.id in (?) AND t. STATUS = ? AND c.type =? "+tempParms;
  224. }else{
  225. args.push(userId,status,reply,type);
  226. sql = "SELECT count(t.id) count FROM "+
  227. DB_TABLES.Topics+" t,"+DB_TABLES.Participants+" p,"+DB_TABLES.Doctors+" d,"+DB_TABLES.WlyyConsult+" c,"+DB_TABLES.Patients+" s "+
  228. "WHERE d.id = p.participant_id AND c.id = t.id AND c.patient = s.id AND p.session_id = t.session_id "+
  229. "AND d.id in (?) AND t. STATUS = ? and t.reply=? AND c.type = ? "+tempParms;
  230. }
  231. ImDb.execQuery({
  232. sql: sql,
  233. args: args,
  234. handler: function (err, res) {
  235. handler(err, res);
  236. }
  237. });
  238. }
  239. /**
  240. * 过滤名医咨询和续方咨询(区分团队)
  241. * @param userId
  242. * @param reply
  243. * @param status
  244. * @param page
  245. * @param size
  246. * @param handler
  247. */
  248. static findAllByUserAndReplyAndStatusHealthTeamTopic(userId,reply,status,adminTeamCode,page,size,handler){
  249. let sql = "";
  250. var args =[];
  251. if(status==10){
  252. args.push(adminTeamCode,userId,status,page,size);
  253. sql = "SELECT t.*, s.avatar,s.sex,s.birthdate, s.`name` AS patient_name,c.doctor FROM "+
  254. DB_TABLES.Topics+" t,"+DB_TABLES.Participants+" p,"+DB_TABLES.Doctors+" d,"+DB_TABLES.WlyyConsultTeam+" c,"+DB_TABLES.Patients+" s "+
  255. "WHERE d.id = p.participant_id AND c.consult = t.id AND c.patient = s.id AND p.session_id = t.session_id "+
  256. "AND c.admin_team_code =? AND d.id in (?) AND t. STATUS = ? AND c.type not in ('6','8') ORDER BY create_time DESC limit ?,?";
  257. }else{
  258. args.push(adminTeamCode,userId,status,reply,page,size);
  259. sql = "SELECT t.*, s.avatar,s.sex,s.birthdate, s.`name` AS patient_name,c.doctor FROM "+
  260. DB_TABLES.Topics+" t,"+DB_TABLES.Participants+" p,"+DB_TABLES.Doctors+" d,"+DB_TABLES.WlyyConsultTeam+" c,"+DB_TABLES.Patients+" s "+
  261. "WHERE d.id = p.participant_id AND c.consult = t.id AND c.patient = s.id AND p.session_id = t.session_id "+
  262. "AND c.admin_team_code =? AND d.id in (?) AND t. STATUS = ? and t.reply=? AND c.type not in ('6','8') ORDER BY create_time DESC limit ?,?";
  263. }
  264. ImDb.execQuery({
  265. sql: sql,
  266. args: args,
  267. handler: function (err, res) {
  268. handler(err, res);
  269. }
  270. });
  271. }
  272. static findReplyCount(userId,reply,status,adminTeamCode,handler){
  273. let sql = "";
  274. var args =[];
  275. if(status==10){
  276. args.push(adminTeamCode,userId,status);
  277. sql = "SELECT count(1) as count FROM "+
  278. DB_TABLES.Topics+" t,"+DB_TABLES.Participants+" p,"+DB_TABLES.Doctors+" d,"+DB_TABLES.WlyyConsultTeam+" c,"+DB_TABLES.Patients+" s "+
  279. "WHERE d.id = p.participant_id AND c.consult = t.id AND c.patient = s.id AND p.session_id = t.session_id "+
  280. "AND c.admin_team_code=? AND c.type!=8 AND d.id in (?) AND t. STATUS = ? ";
  281. }else if(status){
  282. args.push(adminTeamCode,userId,status,reply);
  283. sql = "SELECT count(1) as count FROM "+
  284. DB_TABLES.Topics+" t,"+DB_TABLES.Participants+" p,"+DB_TABLES.Doctors+" d,"+DB_TABLES.WlyyConsultTeam+" c,"+DB_TABLES.Patients+" s "+
  285. "WHERE d.id = p.participant_id AND c.consult = t.id AND c.patient = s.id AND p.session_id = t.session_id "+
  286. "AND c.admin_team_code=? AND c.type!=8 AND d.id in (?) AND t. STATUS = ? and t.reply=? ";
  287. }else{
  288. args.push(adminTeamCode,userId);
  289. sql = "SELECT count(1) as count FROM "+
  290. DB_TABLES.Topics+" t,"+DB_TABLES.Participants+" p,"+DB_TABLES.Doctors+" d,"+DB_TABLES.WlyyConsultTeam+" c,"+DB_TABLES.Patients+" s "+
  291. "WHERE d.id = p.participant_id AND c.consult = t.id AND c.patient = s.id AND p.session_id = t.session_id "+
  292. "AND c.admin_team_code=? AND c.type!=8 AND d.id in (?)";
  293. }
  294. ImDb.execQuery({
  295. sql: sql,
  296. args: args,
  297. handler: function (err, res) {
  298. if(err){
  299. log.error("get topic count error");
  300. handler(err,0);
  301. return;
  302. }
  303. handler(err, res[0].count);
  304. }
  305. });
  306. }
  307. static findLastTopicStatusAndType(sessionId, handler) {
  308. let sql = "select id from " + DB_TABLES.Topics + " where session_id = ? order by create_time desc limit 0, 1";
  309. ImDb.execQuery({
  310. sql: sql,
  311. args: [sessionId],
  312. handler: function (err, res) {
  313. if (res.length == 0) {
  314. handler(null, null);
  315. } else {
  316. TopicRepo.findTopicStatusAndType(res[0].id, handler);
  317. }
  318. }
  319. });
  320. }
  321. static findTopicStatus(topicId, handler) {
  322. let sql = "select id, name, description, status,agent from " + DB_TABLES.Topics + " where id = ?";
  323. ImDb.execQuery({
  324. sql: sql,
  325. args: [topicId],
  326. handler: handler || function (err, res) {
  327. if (err) log.error(err);
  328. }
  329. });
  330. }
  331. static findTopicStatusAndType(topicId, handler) {
  332. let sql = "select t.id, t.name, t.description, t.status,t.agent,c.type from topics t,wlyy.wlyy_consult c where t.id = ? and t.id = c.code";
  333. ImDb.execQuery({
  334. sql: sql,
  335. args: [topicId],
  336. handler: handler || function (err, res) {
  337. if (err) log.error(err);
  338. }
  339. });
  340. }
  341. /**
  342. * 获取会话中的议题。
  343. *
  344. * @param sessionId
  345. * @param handler
  346. */
  347. static findAllBySessionId(sessionId, handler) {
  348. let sql = "select id, session_id, name, create_time, end_by, end_time," +
  349. " start_message_id, end_message_id, description, status from " + DB_TABLES.Topics + " where session_id = ? order by id";
  350. ImDb.execQuery({
  351. sql: sql,
  352. args: [sessionId],
  353. handler: handler || function (err, res) {
  354. if (err) log.error(err);
  355. }
  356. });
  357. }
  358. /**
  359. * 获取会话中的议题。
  360. *
  361. * @param id
  362. * @param handler
  363. */
  364. static findAllByTopicId(id, handler) {
  365. let sql = "select id, session_id, name, create_time, end_by, end_time," +
  366. " start_message_id, end_message_id, description, status from " + DB_TABLES.Topics + " where id = ? order by id";
  367. ImDb.execQuery({
  368. sql: sql,
  369. args: [id],
  370. handler: handler || function (err, res) {
  371. if (err) log.error(err);
  372. }
  373. });
  374. }
  375. static findAllBySessionIdsAndStatus(sessionIds, status, page, pagesize, handler) {
  376. let sql = "select id, session_id, name, create_time, end_by, end_time," +
  377. " start_message_id, end_message_id, description, status from " + DB_TABLES.Topics + " where session_id in ('" + sessionIds + "') and status in (" + status + ") order by status desc limit ?,? ";
  378. ImDb.execQuery({
  379. sql: sql,
  380. args: [page, pagesize],
  381. handler: handler || function (err, res) {
  382. if (err) log.error(err);
  383. }
  384. });
  385. }
  386. /**
  387. * 保存议题
  388. *
  389. * @param topicName
  390. * @param topicId
  391. * @param sessionId
  392. * @param messageId
  393. * @param date
  394. * @param description
  395. * @param status
  396. * @param agent
  397. * @param handler
  398. */
  399. static saveTopic(topicName, topicId, sessionId, messageId, date, description, status, agent, handler) {
  400. let sql = "insert into " + DB_TABLES.Topics + " (id,session_id,name,create_time,start_message_id,description,status,agent) VALUES (?,?,?,?,?,?,?,?)";
  401. ImDb.execQuery({
  402. "sql": sql,
  403. "args": [topicId, sessionId, topicName, date, messageId, description, status, agent],
  404. "handler": function (err, res) {
  405. handler(err, res);
  406. }
  407. });
  408. }
  409. /**
  410. * 结束议题
  411. *
  412. * @param topicId
  413. * @param endUser
  414. * @param date
  415. * @param messageId
  416. * @param status
  417. */
  418. static endTopic(topicId, endUser, date, messageId, status) {
  419. let sql = "update " + DB_TABLES.Topics + " set end_by = ?,end_time=?,end_message_id=?,status = ? where id = ?";
  420. ImDb.execQuery({
  421. "sql": sql,
  422. "args": [endUser, date, messageId, status, topicId],
  423. "handler": function (err, res) {
  424. if (err) {
  425. log.error("endTopic is fail error: " + err);
  426. } else {
  427. log.info("endTopic is success");
  428. }
  429. }
  430. });
  431. }
  432. /**
  433. * 医生第一次回复咨询
  434. * @param reply_user
  435. * @param reply_message_id
  436. * @param topicId
  437. */
  438. static replyTopic(reply_user,reply_message_id,topicId,handler){
  439. let sql = "UPDATE " + DB_TABLES.Topics + " SET reply = 1,reply_time = now(),reply_user = ?,reply_message_id = ? WHERE id = ?";
  440. ImDb.execQuery({
  441. "sql": sql,
  442. "args": [reply_user, reply_message_id, topicId],
  443. "handler": handler
  444. });
  445. }
  446. /**
  447. * 医生第一次回复咨询
  448. * @param reply_user
  449. * @param reply_message_id
  450. * @param topicId
  451. */
  452. static specialistReplyTopic(reply_user,topicId,handler){
  453. let sql = "UPDATE wlyy.wlyy_consult_help SET status = '1',reply_time = now()" +
  454. ",response_time=TIMESTAMPDIFF(SECOND,create_time,now()) WHERE consult = ? and status='0' and specialist=?";
  455. ImDb.execQuery({
  456. "sql": sql,
  457. "args": [topicId,reply_user],
  458. "handler": handler
  459. });
  460. }
  461. /**
  462. * 更新议题状态。
  463. *
  464. * @param topicId
  465. * @param jsonValue
  466. * @param handler
  467. */
  468. static updateTopics(topicId, jsonValue, handler) {
  469. let values = [];
  470. let sql = "UPDATE topics SET ";
  471. let key = [];
  472. for (let j in jsonValue) {
  473. key.push(j + " = ?");
  474. values.push(jsonValue[j]);
  475. }
  476. sql = sql + key.join(",");
  477. sql = sql + " WHERE id = ?";
  478. values.push(topicId);
  479. ImDb.execQuery({
  480. "sql": sql,
  481. "args": values,
  482. "handler": handler
  483. });
  484. }
  485. /**
  486. * 搜索最后回复时间超过指定时限的议题,此议题最后一条消息的回复者必须是医生,即医生发送消息后,患者未理睬的,关闭。
  487. *
  488. * @param timespan 时限,以小时计
  489. * @param handler
  490. */
  491. static findAllBySessionLastActiveTime(timespan, handler) {
  492. let sql = "SELECT s.id session_id, s.name session_name, s.create_date session_create_time, s.last_message_time, " +
  493. "t.id topic_id, t.name topic_name, t.create_time topic_create_time, t.start_message_id " +
  494. "FROM sessions s, wlyy_consults t " +
  495. "WHERE s.id = t.session_id AND t.end_message_id IS NULL AND s.last_content_type in(1,2,3,4) and s.last_sender_id IN (SELECT id FROM doctors d where d.id<>t.patient) " +
  496. "AND UNIX_TIMESTAMP(now()) - UNIX_TIMESTAMP(s.last_message_time) > ? " +
  497. "ORDER BY t.create_time";
  498. ImDb.execQuery({
  499. sql: sql,
  500. args: [timespan * 3600],
  501. handler: handler
  502. });
  503. }
  504. }
  505. module.exports = TopicRepo;