participant.repo.js 3.0 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104
  1. /**
  2. * 搜索功能。
  3. */
  4. "use strict";
  5. let ImDb = require('../mysql/db/im.db');
  6. let log = require('../../util/log.js');
  7. const IMTABLE = require('../../include/commons').IM_DB;
  8. class ParticipantRepo {
  9. constructor() {
  10. }
  11. /**
  12. * 获取某个会话中的成员信息
  13. * @param sessionId
  14. * @param handler
  15. */
  16. static getParticipantsBySessionId(sessionId,handler){
  17. let sql ="select w.* from participants w where w.session_id =? ";
  18. ImDb.execQuery({
  19. "sql": sql,
  20. "args": [sessionId],
  21. "handler": function (err, res) {
  22. if(err) {
  23. log.error("getParticipantsBySessionId is fail error: "+err);
  24. }
  25. handler(res);
  26. }
  27. });
  28. }
  29. /**
  30. * 判断用户是否存在session中
  31. * @param sessionId
  32. * @param userId
  33. * @param handler
  34. */
  35. static existsUser(sessionId,userId,handler){
  36. let sql ="select count(1) as count from participants w where w.session_id =? and w.participaint_id = ? ";
  37. ImDb.execQuery({
  38. "sql": sql,
  39. "args": [sessionId,userId],
  40. "handler": function (err, res) {
  41. if(err) {
  42. log.error("existsUser is fail error: "+err);
  43. }
  44. handler(res[0].count);
  45. }
  46. });
  47. }
  48. /**
  49. * 根据医生和患者
  50. * @param patient
  51. * @param doctor
  52. */
  53. static getSessionIdByParticipants(patient,doctor,handler){
  54. let sql ="select session_id from "+IMTABLE.PARTICIPANTS+" p1 ,participants p2 " +
  55. "where p1.session_id = p2.session_id and " +
  56. "((p1.participaint_id = ? and p2.participaint_id = ?) or (p1.participaint_id = ? and p2.participaint_id = ?))"
  57. ImDb.execQuery({
  58. "sql": sql,
  59. "args": [patient,doctor,doctor,patient],
  60. "handler": function (err, res) {
  61. if(err) {
  62. log.error("getSessionIdByParticipants is fail error: "+err);
  63. }
  64. handler(err,res);
  65. }
  66. });
  67. }
  68. /**
  69. * mysql成员创建
  70. * @param users
  71. */
  72. createParticipantsToMysql(session_id,users){
  73. let sql="insert into "+IMTABLE.PARTICIPANTS +" (session_id,participaint_id,participaint_role,receiving) VALUES "
  74. let args=[];
  75. for(var j in users){
  76. sql+="(?,?,?,?),";
  77. args.push(session_id);
  78. args.push(users[j]);
  79. args.push(0);
  80. args.push(0);
  81. }
  82. sql = sql.substring(0,sql.lastIndexOf(","));
  83. ImDb.execQuery({
  84. "sql": sql,
  85. "args": args,
  86. "handler": function (err, res) {
  87. if(err) {
  88. log.error("createParticipantsForMysql is fail error: "+err+",session_id:"+session_id+",users:"+users.join(","));
  89. }else{
  90. return res;
  91. }
  92. }
  93. });
  94. return true;
  95. }
  96. }
  97. module.exports = ParticipantRepo;