session.endpoint.js 22 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705
  1. /**
  2. * 会话接口。
  3. *
  4. * author: Sand
  5. * since: 12/15/2016
  6. */
  7. "use strict";
  8. let express = require('express');
  9. let router = express.Router();
  10. let ObjectUtil = require("../../util/object.util.js");
  11. let ControllerUtil = require('../../util/controller.util');
  12. let Sessions = require('../../models/sessions/sessions');
  13. let Messages = require('../../models/messages/messages');
  14. let Participants = require('../../models/sessions/participants');
  15. let log = require("../../util/log.js");
  16. let clientCache = require('../../models/socket.io/client.cache').clientCache();
  17. const SESSION_TYPES = require('../../include/commons').SESSION_TYPES;
  18. const APIv2 = require('../../include/endpoints').APIv2;
  19. /**
  20. * 创建会话。对MUC会话而言,需要创建的是议题,如果是第一次创建议题,那应该附带创建会话,而不是直接创建会话。
  21. *
  22. * session_type:1表示MUC会话,2表示P2P,3表示群会话,4表示临时讨论组
  23. * (咨询类型:1三师咨询,2视频咨询,3图文咨询,4公共咨询,5病友圈 6、患者名医咨询 7医生名医咨询 8续方咨询 9居民直接咨询专科 10医生发起的求助 11上门服务咨询)
  24. * users 讨论组包含的用户标示
  25. * sessionId 会话ID
  26. *
  27. * 请求URL: /sessions
  28. * 参数:
  29. * {
  30. * session_id: 会话ID,非必须,仅对群消息使用。
  31. * session_type: 会话类型,必须。
  32. * session_name: 会话名称,
  33. * participants: 此会话的成员列表,格式:["userId1:role", "userId2:role"],用户的ID及角色。
  34. * }
  35. */
  36. router.post("/", function (req, res) {
  37. let payload = req.body;
  38. let testing = ObjectUtil.fieldsCheck(payload, 'participants', 'session_name', 'session_type');
  39. if (!testing.pass) {
  40. throw testing.message;
  41. }
  42. let participants = payload.participants;
  43. let sessionName = payload.session_name;
  44. let sessionType = payload.session_type;
  45. let sessionId = payload.session_id;
  46. let sessions = new Sessions();
  47. let participantArray = [];
  48. log.info("participants: "+participants);
  49. participants = JSON.parse(participants);
  50. //获取传入的参与者数组长度
  51. let participantLength = 0;
  52. for (let i in participants) {
  53. participantLength ++;
  54. }
  55. for (let j in participants) {
  56. log.info("aaaa:"+j + ":" + participants[j]);
  57. if (payload.hasOwnProperty('videoconferencing') && payload.videoconferencing == 1){
  58. sessions.conversionAarticipant(j, (doctorid) => {
  59. participantArray.push(doctorid+":"+participants[j])
  60. //判断数组长度等于传入的长度,则执行创建会话的请求
  61. if(participantArray.length == participantLength){
  62. ControllerUtil.regModelEventHandler(sessions, res);
  63. console.log(sessionId, sessionName, sessionType, participantArray);
  64. sessions.createSession(sessionId, sessionName, sessionType, participantArray);
  65. ///是否视频会议的会话
  66. let videoconferencing = false;
  67. // participants = JSON.parse(participants);
  68. // for (let j in participants) {
  69. // participantArray.push(j + ":" + participants[j]);
  70. // }
  71. //视频会议的会话 szx add 20181121
  72. if (payload.hasOwnProperty('videoconferencing') && payload.videoconferencing == 1){
  73. let access_token = "";
  74. if(payload.hasOwnProperty("mobile"))access_token = payload.access_token;
  75. videoconferencing = true;
  76. //发送广播,给相关的与会人员
  77. for (let k in participants) {
  78. sessions.conversionAarticipant(k, (doctorid) => {
  79. let userId = "pcim_"+doctorid;
  80. let pc_doctorClient = clientCache.findById(userId);
  81. if(pc_doctorClient){
  82. log.info("videoconferencing send to "+userId);
  83. pc_doctorClient.socket.emit("startVideoconference",{"sessionId":sessionId,"user_id":j});
  84. }
  85. else{
  86. log.info("videoconferencing not find "+userId);
  87. }
  88. })
  89. }
  90. }
  91. }
  92. })
  93. }else{
  94. participantArray.push(j + ":" + participants[j]);
  95. //判断数组长度等于传入的长度,则执行创建会话的请求
  96. if(participantArray.length == participantLength){
  97. ControllerUtil.regModelEventHandler(sessions, res);
  98. console.log(sessionId, sessionName, sessionType, participantArray);
  99. sessions.createSession(sessionId, sessionName, sessionType, participantArray);
  100. ///是否视频会议的会话
  101. let videoconferencing = false;
  102. // participants = JSON.parse(participants);
  103. // for (let j in participants) {
  104. // participantArray.push(j + ":" + participants[j]);
  105. // }
  106. //视频会议的会话 szx add 20181121
  107. if (payload.hasOwnProperty('videoconferencing') && payload.videoconferencing == 1){
  108. let access_token = "";
  109. if(payload.hasOwnProperty("mobile"))access_token = payload.access_token;
  110. videoconferencing = true;
  111. //发送广播,给相关的与会人员
  112. for (let j in participants) {
  113. let userId = "pcim_"+j;
  114. let pc_doctorClient = clientCache.findById(userId);
  115. if(pc_doctorClient){
  116. log.info("videoconferencing send to "+userId);
  117. pc_doctorClient.socket.emit("startVideoconference",{"sessionId":sessionId,"user_id":j});
  118. }
  119. else{
  120. log.info("videoconferencing not find "+userId);
  121. }
  122. }
  123. }
  124. }
  125. }
  126. }
  127. });
  128. /**
  129. * 获取会话列表
  130. *
  131. * 请求URL /sessions?user_id=3121&page=0&size=10
  132. */
  133. router.get("/", function (req, res) {
  134. let page = req.query.page;
  135. let size = req.query.size;
  136. let userId = req.query.user_id;
  137. let businessType = req.query.business_type;
  138. let status = req.query.status;
  139. let name = req.query.name;
  140. let search_type = req.query.search_type;//搜索类型 1医生 2患者 3会话名称
  141. let videoconferencing = req.query.videoconferencing;
  142. if (!page) {
  143. throw {httpStatus: 406, message: 'Missing page.'};
  144. }
  145. if (!size) {
  146. throw {httpStatus: 406, message: 'Missing size.'};
  147. }
  148. if (!userId) {
  149. throw {httpStatus: 406, message: 'Missing user.'};
  150. }
  151. let sessions = new Sessions();
  152. ControllerUtil.regModelEventHandler(sessions, res);
  153. //判断是否是中山医院MDT的请求
  154. if(videoconferencing && videoconferencing == 1){
  155. sessions.conversionAarticipant(userId, (doctorid) => {
  156. //传入参数齐全走过滤方法
  157. if(status&&businessType&&doctorid&&size&&page){
  158. sessions.getUserStatusSessions(doctorid,status,businessType,name,search_type,page,size);
  159. }else{
  160. sessions.getUserSessions(doctorid,name,search_type, page, size, businessType);
  161. }
  162. })
  163. }else{
  164. //传入参数齐全走过滤方法
  165. if(status&&businessType&&userId&&size&&page){
  166. sessions.getUserStatusSessions(userId,status,businessType,name,search_type,page,size);
  167. }else{
  168. sessions.getUserSessions(userId,name,search_type, page, size, businessType);
  169. }
  170. }
  171. });
  172. router.get("/getOnlineCountByType", function (req, res) {
  173. let type = req.query.type;
  174. let sessions = new Sessions();
  175. ControllerUtil.regModelEventHandler(sessions, res);
  176. sessions.getOnlineCountByType(type)
  177. });
  178. router.get("/getOnlineListByType", function (req, res) {
  179. let type = req.query.type;
  180. let sessions = new Sessions();
  181. ControllerUtil.regModelEventHandler(sessions, res);
  182. sessions.getOnlineListByType(type)
  183. });
  184. router.get("/findByUserIdAndType", function (req, res) {
  185. let type = req.query.type;
  186. let userId = req.query.userId;
  187. if (!type) {
  188. throw {httpStatus: 406, message: 'Missing type.'};
  189. }
  190. if (!userId) {
  191. throw {httpStatus: 406, message: 'Missing userId.'};
  192. }
  193. let sessions = new Sessions();
  194. ControllerUtil.regModelEventHandler(sessions, res);
  195. sessions.findByUserIdAndType(userId,type)
  196. });
  197. /**
  198. * 按会话类型获取会话列表
  199. * 请求URL /sessions/sessionListByType?user_id=3121&page=0&size=10&type=4
  200. */
  201. router.get(APIv2.Sessions.SessionListByType, function (req, res) {
  202. let page = req.query.page;
  203. let size = req.query.size;
  204. let userId = req.query.user_id;
  205. let type = req.query.type;
  206. let status = req.query.status;
  207. let name = req.query.name;
  208. let searchType = req.query.search_type;//p2p会话类型 1医生 2患者
  209. if (!page) {
  210. throw {httpStatus: 406, message: 'Missing page.'};
  211. }
  212. if (!size) {
  213. throw {httpStatus: 406, message: 'Missing size.'};
  214. }
  215. if (!type) {
  216. throw {httpStatus: 406, message: 'Missing type.'};
  217. }
  218. /**
  219. * userId 为传值时:管理员调度大屏获取im消息
  220. */
  221. // if (!userId) {
  222. // throw {httpStatus: 406, message: 'Missing user.'};
  223. // }
  224. let sessions = new Sessions();
  225. ControllerUtil.regModelEventHandler(sessions, res);
  226. sessions.getUserSessionsByType(userId,type,page,size,status,name,searchType);
  227. });
  228. router.get(APIv2.Sessions.SessionListByNoParticipant, function (req, res) {
  229. let page = req.query.page;
  230. let size = req.query.size;
  231. let userId = req.query.user_id;
  232. let type = req.query.type;
  233. let status = req.query.status;
  234. if (!page) {
  235. throw {httpStatus: 406, message: 'Missing page.'};
  236. }
  237. if (!size) {
  238. throw {httpStatus: 406, message: 'Missing size.'};
  239. }
  240. if (!type) {
  241. throw {httpStatus: 406, message: 'Missing type.'};
  242. }
  243. if (!userId) {
  244. throw {httpStatus: 406, message: 'Missing user.'};
  245. }
  246. let sessions = new Sessions();
  247. ControllerUtil.regModelEventHandler(sessions, res);
  248. sessions.getUserSessionsByTypeAndNoParticipant(userId,type,page,size,status);
  249. });
  250. /**
  251. * 按会话类型获取会话总数
  252. * 请求URL /sessions/sessionCountByType?user_id=3121&type=4
  253. */
  254. router.get(APIv2.Sessions.SessionCountByType, function (req, res) {
  255. let userId = req.query.user_id;
  256. let type = req.query.type;
  257. let status = req.query.status;
  258. if (!type) {
  259. throw {httpStatus: 406, message: 'Missing type.'};
  260. }
  261. if (!userId) {
  262. throw {httpStatus: 406, message: 'Missing user.'};
  263. }
  264. let sessions = new Sessions();
  265. ControllerUtil.regModelEventHandler(sessions, res);
  266. sessions.getSessionCountByType(userId,type,status);
  267. });
  268. router.get(APIv2.Sessions.Session,function(req,res){
  269. let sessionId = req.params.session_id;
  270. let userId = req.query.user_id;
  271. if (!sessionId) {
  272. throw {httpStatus: 406, message: 'Missing sessionId.'};
  273. }
  274. if (!userId) {
  275. throw {httpStatus: 406, message: 'Missing user.'};
  276. }
  277. let sessions = new Sessions();
  278. ControllerUtil.regModelEventHandler(sessions, res);
  279. sessions.getSession(sessionId,userId);
  280. });
  281. /**
  282. * 最近会话列表。
  283. *
  284. * URL:
  285. * /sessions/recent?user_id=abc&date_span=7
  286. */
  287. router.get(APIv2.Sessions.RecentSessions, function (req, res) {
  288. ControllerUtil.checkRequestQueryParams(req, ['user_id', 'date_span']);
  289. let userId = req.query.user_id;
  290. let dateSpan = req.query.date_span;
  291. let sessions = new Sessions();
  292. ControllerUtil.regModelEventHandler(sessions, res);
  293. sessions.getRecentSessions(userId, dateSpan);
  294. });
  295. /**
  296. * 判断会话是否存在。
  297. *
  298. * URL:
  299. * /sessions/isExist?session_id=abc
  300. */
  301. router.get(APIv2.Sessions.IsExist, function (req, res) {
  302. let sessionId = req.query.session_id;
  303. if (!sessionId) {
  304. throw {httpStatus: 406, message: 'Missing sessionId.'}
  305. }
  306. let sessions = new Sessions();
  307. ControllerUtil.regModelEventHandler(sessions, res);
  308. sessions.isExist(sessionId);
  309. });
  310. /**
  311. * 某个聊天记录置顶操作
  312. *
  313. * 请求URL /stick?user=3121&sessionId=testsessionmsg1
  314. */
  315. router.post(APIv2.Sessions.SessionSticky, function (req, res) {
  316. let user = req.query.user;
  317. let sessionId = req.query.sessionId;
  318. if (!user) {
  319. throw {httpStatus: 406, message: 'Missing user.'};
  320. }
  321. if (!sessionId) {
  322. throw {httpStatus: 406, message: 'Missing sessionId.'};
  323. }
  324. let sessions = new Sessions();
  325. ControllerUtil.regModelEventHandler(sessions, res);
  326. sessions.stickSession(sessionId, user);
  327. });
  328. /**
  329. * 某个聊天记录置顶操作
  330. *
  331. * 请求URL /status?status=1&sessionId=testsessionmsg1
  332. */
  333. router.post(APIv2.Sessions.SessionStatus, function (req, res) {
  334. let sessionId = req.query.sessionId;
  335. let status = req.query.status;
  336. if (!sessionId) {
  337. throw {httpStatus: 406, message: 'Missing sessionId.'};
  338. }
  339. if (!status) {
  340. throw {httpStatus: 406, message: 'Missing status.'};
  341. }
  342. let sessions = new Sessions();
  343. ControllerUtil.regModelEventHandler(sessions, res);
  344. sessions.updateSessionStatus(sessionId, status);
  345. });
  346. /**
  347. * 修改会话名称(修改redis和数据库)
  348. *
  349. * 请求URL /name?name=哈哈&sessionId=testsessionmsg1
  350. */
  351. router.post(APIv2.Sessions.SessionName, function (req, res) {
  352. let sessionId = req.body.sessionId;
  353. let name = req.body.name;
  354. if (!sessionId) {
  355. throw {httpStatus: 406, message: 'Missing sessionId.'};
  356. }
  357. if (!name) {
  358. throw {httpStatus: 406, message: 'Missing name.'};
  359. }
  360. let sessions = new Sessions();
  361. ControllerUtil.regModelEventHandler(sessions, res);
  362. sessions.updateSessionName(sessionId, name);
  363. });
  364. /**
  365. * 取消置顶
  366. * 请求URL /cancelStick?user=3121&sessionId=testsessionmsg1
  367. */
  368. router.delete(APIv2.Sessions.SessionSticky, function (req, res) {
  369. let user = req.query.user;
  370. let sessionId = req.query.sessionId;
  371. if (!user) {
  372. throw {httpStatus: 406, message: 'Missing user.'};
  373. }
  374. if (!sessionId) {
  375. throw {httpStatus: 406, message: 'Missing sessionId.'};
  376. }
  377. let sessions = new Sessions();
  378. ControllerUtil.regModelEventHandler(sessions, res);
  379. sessions.cancelStickSession(sessionId, user);
  380. });
  381. /**
  382. * 获取会话成员。
  383. */
  384. router.get(APIv2.Sessions.Participants, function (req, res) {
  385. let sessionId = req.params.session_id;
  386. let participants = new Participants();
  387. ControllerUtil.regModelEventHandler(participants, res);
  388. participants.getParticipants(sessionId);
  389. });
  390. /**
  391. * 获取会话成员头像列表。
  392. */
  393. router.get(APIv2.Sessions.ParticipantsAvatar, function (req, res) {
  394. let sessionId = req.params.session_id;
  395. let participants = new Participants();
  396. ControllerUtil.regModelEventHandler(participants, res);
  397. participants.getParticipantsAvatar(sessionId);
  398. });
  399. /**
  400. * 增加成员
  401. * user:增加的人员
  402. * sessionId 会话ID
  403. */
  404. router.put(APIv2.Sessions.Participant, function (req, res) {
  405. let user = req.params.participant_id;
  406. if (!user) {
  407. throw {httpStatus: 406, message: 'Missing participant_id.'};
  408. }
  409. let sessionId = req.params.session_id;
  410. if (!sessionId) {
  411. throw {httpStatus: 406, message: 'Missing session_id.'};
  412. }
  413. let participants = new Participants();
  414. ControllerUtil.regModelEventHandler(participants, res);
  415. participants.addUser(sessionId, user);
  416. });
  417. /**
  418. * 增加成员
  419. * user_id:增加的人员
  420. * old_user_id:删除的人员
  421. * session_id 会话ID
  422. */
  423. router.post(APIv2.Sessions.ParticipantUpdate, function (req, res) {
  424. let payload = req.body;
  425. let testing = ObjectUtil.fieldsCheck(payload, 'user_id', 'session_id');
  426. if (!testing.pass) {
  427. throw testing.message;
  428. }
  429. let participants = new Participants();
  430. ControllerUtil.regModelEventHandler(participants, res);
  431. participants.updateSessionUser(payload.user_id, payload.old_user_id, payload.session_id);
  432. });
  433. /**
  434. * 增加活跃成员
  435. * user_id:增加的人员
  436. * old_user_id:删除的人员
  437. * session_id 会话ID
  438. */
  439. router.post(APIv2.Sessions.ParticipantUpdateNew, function (req, res) {
  440. let payload = req.body;
  441. let testing = ObjectUtil.fieldsCheck(payload, 'user_id', 'session_id');
  442. if (!testing.pass) {
  443. throw testing.message;
  444. }
  445. let participants = new Participants();
  446. ControllerUtil.regModelEventHandler(participants, res);
  447. participants.updateSessionUser0(payload.user_id, payload.old_user_id, payload.session_id);
  448. });
  449. /**
  450. * 移除成员
  451. * user:移除的人员
  452. * sessionId 会话ID
  453. */
  454. router.delete(APIv2.Sessions.Participant, function (req, res) {
  455. let user = req.params.participant_id;
  456. if (!user) {
  457. throw {httpStatus: 406, message: 'Missing user.'};
  458. }
  459. let sessionId = req.params.session_id;
  460. if (!sessionId) {
  461. throw {httpStatus: 406, message: 'Missing sessionId.'};
  462. }
  463. let participants = new Participants();
  464. ControllerUtil.regModelEventHandler(participants, res);
  465. participants.removeUser(sessionId, user);
  466. });
  467. /**
  468. * 发送消息
  469. *
  470. * 请求URL:
  471. * /sessions/:session_id/messages
  472. *
  473. * 消息体:
  474. * {
  475. * sender_id: bea851fc,
  476. * sender_name: 李毅,
  477. * content_type: 1,
  478. * content: 李医生,你好
  479. * }
  480. */
  481. router.post(APIv2.Sessions.Messages, function (req, res) {
  482. let payload = req.body;
  483. let testing = ObjectUtil.fieldsCheck(payload, "sender_id", "sender_name", "content_type", "content");
  484. if (!testing.pass) {
  485. throw {httpStatus: 406, message: testing.message}
  486. }
  487. if(payload.view&&payload.view==1){
  488. throw {httpStatus: 406, message: "观察者模式,不能发送消息!"};
  489. }
  490. // 消息的发送时间由服务端决定
  491. payload.timestamp = new Date((new Date().getTime()));
  492. let sessions = new Sessions();
  493. ControllerUtil.regModelEventHandler(sessions, res);
  494. log.info("入参"+payload);
  495. sessions.saveMessageBySession(req.params.session_id, payload);
  496. });
  497. router.post(APIv2.Sessions.TopicMessages, function (req, res) {
  498. let payload = req.body;
  499. let testing = ObjectUtil.fieldsCheck(payload, "sender_id", "sender_name", "content_type", "content");
  500. if (!testing.pass) {
  501. throw {httpStatus: 406, message: testing.message}
  502. }
  503. if(payload.view&&payload.view==1){
  504. throw {httpStatus: 406, message: "观察者模式,不能发送消息!"};
  505. }
  506. let sessions = new Sessions();
  507. ControllerUtil.regModelEventHandler(sessions, res);
  508. payload.timestamp = new Date((new Date().getTime()));
  509. sessions.sendTopicMessages(req.params.topic_id, payload);
  510. })
  511. /**
  512. * 获取消息
  513. *
  514. * 请求URL:
  515. * /sessions/:session_id/messages?session_id=blabla&user_id=abc&start_message_id=100&end_message_id=20
  516. */
  517. router.get(APIv2.Sessions.Messages, function (req, res) {
  518. let startMsgId = req.query.start_msg_id;
  519. let endMsgId = req.query.end_msg_id;
  520. let pagesize = req.query.pagesize;
  521. let page = req.query.page;
  522. let user = req.query.user;
  523. let sessionId = req.query.session_id;
  524. let content_type = req.query.content_type;
  525. let isoffset = req.query.isoffset;
  526. let type = req.query.type;//类型 1获取消息时医生不在session内要自动加入会话
  527. if (!user) {
  528. throw {httpStatus: 406, message: 'Missing user.'};
  529. }
  530. if (!sessionId) {
  531. throw {httpStatus: 406, message: 'Missing session_id.'};
  532. }
  533. if (!pagesize) {
  534. pagesize = 20;
  535. }
  536. if (!page) {
  537. page = 1;
  538. }
  539. if (content_type) {
  540. let messages = new Messages();
  541. ControllerUtil.regModelEventHandler(messages, res);
  542. messages.getMessageByType(sessionId, page, pagesize, content_type)
  543. } else {
  544. let sessions = new Sessions();
  545. ControllerUtil.regModelEventHandler(sessions, res);
  546. sessions.getMessages(sessionId, user, startMsgId, endMsgId, page, pagesize, isoffset,type);
  547. }
  548. });
  549. /**
  550. * 修改单条消息
  551. * session_id 会话ID
  552. * message_id:消息ID
  553. * content 消息内容
  554. */
  555. router.post(APIv2.Sessions.MessageUpdate, function (req, res) {
  556. let payload = req.body;
  557. let testing = ObjectUtil.fieldsCheck(payload,'session_type', 'session_id','message_id','content');
  558. if (!testing.pass) {
  559. throw testing.message;
  560. }
  561. let messages = new Messages();
  562. ControllerUtil.regModelEventHandler(messages, res);
  563. messages.updateMsgContent(payload.session_type, payload.session_id,payload.message_id, payload.content);
  564. });
  565. router.get(APIv2.Sessions.SessionUnreadMessages, function (req, res) {
  566. let sessionId = req.params.session_id;
  567. let userId = req.query.user_id;
  568. let sessions = new Sessions();
  569. ControllerUtil.regModelEventHandler(sessions, res);
  570. sessions.getSessionUnreadMessages(sessionId, userId);
  571. });
  572. /**
  573. * 获取所有会话未读消息数。
  574. *
  575. * 请求URL:/sessions/unread_message_count?user_id=xyz&type=1
  576. */
  577. router.get(APIv2.Sessions.SessionsUnreadMessageCount, function (req, res) {
  578. let userId = req.query.user_id;
  579. let type = req.query.type;
  580. let sessions = new Sessions();
  581. ControllerUtil.regModelEventHandler(sessions, res);
  582. sessions.getAllSessionsUnreadMessageCount(userId,type);
  583. });
  584. /**
  585. * 获取指定会话未读消息数
  586. *
  587. * 请求URL
  588. * /sessions/:session_id/unread_message_count?user_id=xyz
  589. */
  590. router.get(APIv2.Sessions.SessionUnreadMessageCount, function (req, res) {
  591. let sessionId = req.params.session_id;
  592. let userId = req.query.user_id;
  593. let sessions = new Sessions();
  594. ControllerUtil.regModelEventHandler(sessions, res);
  595. sessions.getSessionUnreadMessageCount(sessionId, userId);
  596. });
  597. /**
  598. * 获取所有会话未读消息数。
  599. *
  600. * 请求URL:/sessions/unread_message_count?user_id=xyz&type=1
  601. */
  602. router.get(APIv2.Sessions.SessionsUnreadMessageCountByBussinessType, function (req, res) {
  603. let userId = req.query.user_id;
  604. let businessType = req.query.business_type;
  605. let status= req.query.status
  606. let sessions = new Sessions();
  607. ControllerUtil.regModelEventHandler(sessions, res);
  608. sessions.getAllSessionsUnreadMessageCountByStatus(userId,businessType,status);
  609. });
  610. module.exports = router;