Prechádzať zdrojové kódy

消息统计接口新增

8 rokov pred
rodič
commit
8861de5899

+ 5 - 3
src/doctor/models/search.js

@ -266,7 +266,8 @@ class Search extends BaseModel{
                            content:t.content,
                            type:t.type,
                            msg_id:t.msg_id,
                            groupType:t.group_type
                            groupType:t.group_type,
                            avatar:t.photo
                        };
                        data.content.push(message);
@ -363,8 +364,9 @@ class Search extends BaseModel{
                        code: doctor.code,
                        name: doctor.name,
                        content:doctor.content,
                        msg_id:t.msg_id,
                        groupType:t.group_type
                        msg_id:doctor.msg_id,
                        avatar:doctor.photo,
                        groupType:doctor.group_type
                    });
                }
                modelUtil.emitData(self.eventEmitter, data);

+ 40 - 27
src/doctor/repository/group.msg.repo.js

@ -29,21 +29,28 @@ exports.findAllMessages = function (groupId, contentType, start, end, count, han
 * @param handler
 */
exports.findAllGroupsWithDoctor = function (userId, handler) {
    var sql = "SELECT * FROM (" +
        " SELECT DISTINCT g.id code, g.name name, ms.last_content_type, ms.last_content, ms.timestamp, ms.new_msg_count, '1' group_type " +
        " FROM wlyy.wlyy_admin_team g, wlyy.wlyy_admin_team_member m, wlyy.wlyy_doctor d, msg_statistic ms ," +
        " ( SELECT new_msg_count, from_gid  FROM  msg_statistic  WHERE uid =?  GROUP BY from_gid  ORDER BY  `timestamp` DESC ) msgcount " +
        " WHERE d.code = ? AND d.code = m.doctor_code AND msgcount.from_gid=ms.from_gid AND m.team_id = g.id AND g.id = ms.from_gid AND ms.last_content_type IN (1,2,3,5,6) GROUP BY g.id , g.name " +
        " UNION " +
        " SELECT m.group_code, m.group_name, ms.last_content_type, ms.last_content, ms.timestamp, ms.new_msg_count, '2' group_type " +
        " FROM wlyy.wlyy_talk_group g, wlyy.wlyy_talk_group_member m, wlyy.wlyy_doctor d, msg_statistic ms, " +
        " ( SELECT new_msg_count, from_gid  FROM  msg_statistic  WHERE uid =?  GROUP BY from_gid  ORDER BY  `timestamp` DESC ) msgcount " +
        " WHERE d.code = ? AND d.code = m.member_code AND msgcount.from_gid=ms.from_gid AND m.group_code = g.code AND g.type=2  AND g.code = ms.from_gid group by m.group_code, m.group_name" +
        ") X ORDER BY timestamp DESC";
    //var sql = "SELECT * FROM (" +
    //    " SELECT DISTINCT g.id code, g.name name, ms.last_content_type, ms.last_content, ms.timestamp, ms.new_msg_count, '1' group_type " +
    //    " FROM wlyy.wlyy_admin_team g, wlyy.wlyy_admin_team_member m, wlyy.wlyy_doctor d, msg_statistic ms ," +
    //    " ( SELECT new_msg_count, from_gid  FROM  msg_statistic  WHERE uid =?  GROUP BY from_gid  ORDER BY  `timestamp` DESC ) msgcount " +
    //    " WHERE d.code = ? AND d.code = m.doctor_code AND msgcount.from_gid=ms.from_gid AND m.team_id = g.id AND g.id = ms.from_gid AND ms.last_content_type IN (1,2,3,5,6) GROUP BY g.id , g.name " +
    //    " UNION " +
    //    " SELECT m.group_code, m.group_name, ms.last_content_type, ms.last_content, ms.timestamp, ms.new_msg_count, '2' group_type " +
    //    " FROM wlyy.wlyy_talk_group g, wlyy.wlyy_talk_group_member m, wlyy.wlyy_doctor d, msg_statistic ms, " +
    //    " ( SELECT new_msg_count, from_gid  FROM  msg_statistic  WHERE uid =?  GROUP BY from_gid  ORDER BY  `timestamp` DESC ) msgcount " +
    //    " WHERE d.code = ? AND d.code = m.member_code AND msgcount.from_gid=ms.from_gid AND m.group_code = g.code AND g.type=2  AND g.code = ms.from_gid group by m.group_code, m.group_name" +
    //    ") X ORDER BY timestamp DESC";
    var  sql="SELECT g.`code`, g.`name`, s.last_content_type, s.last_content, s. TIMESTAMP as timestamp, s.new_msg_count, g.type AS group_type " +
        "FROM msg_group w, wlyy.wlyy_talk_group g, wlyy.wlyy_talk_group_member t, msg_statistic s " +
        "WHERE w.to_gid = g.`code` AND t.type < 4 AND t.group_code = g. CODE " +
        "AND w.to_gid IN ( SELECT w1.group_code FROM wlyy.wlyy_talk_group_member w1 WHERE w1.member_code = ? AND w1. STATUS = 1 ) " +
        "AND W.to_gid NOT IN (SELECT w1.group_code FROM wlyy.wlyy_talk_group_member w1 WHERE w1.group_code = g.code and  w1. STATUS = 1  AND TYPE =4)"+
        "AND s.from_gid = g. CODE AND s.uid = ? GROUP BY g. NAME, g.`code` ORDER BY w.msg_id DESC;";
    imRepo.execQuery({
        "sql": sql,
        "args": [userId, userId, userId, userId],
        "args": [userId, userId],
        "handler": handler
    });
};
@ -55,21 +62,27 @@ exports.findAllGroupsWithDoctor = function (userId, handler) {
 * @param handler
 */
exports.findAllGroupsWithPatient = function (userId, handler) {
    var sql = "SELECT * FROM (" +
        " SELECT g.code, g.name, ms.last_content_type, ms.last_content, ms.timestamp, msgcount.new_msg_count, g.type group_type " +
        " FROM msg_statistic ms, (" +
        " SELECT g.code code, g.name name, g.type type FROM wlyy.wlyy_talk_group g, wlyy.wlyy_talk_group_member m " +
        " WHERE g.code = m.group_code and m.member_code = ?) g, wlyy.wlyy_patient p , " +
        " ( SELECT new_msg_count, from_gid  FROM  msg_statistic  WHERE uid =?  GROUP BY from_gid  ORDER BY  `timestamp` DESC ) msgcount " +
        " WHERE ((ms.uid = ? and ms.from_uid = p.code)) " +
        " and ms.from_gid = g.code and ms.msg_type = 2 AND ms.last_content_type in (1,2,3,5,6) AND msgcount.from_gid=ms.from_gid " +
        " UNION " +
        " SELECT m.group_code code, m.group_name name, ms.last_content_type, ms.last_content, ms.timestamp, ms.new_msg_count, '2' group_type " +
        " FROM wlyy.wlyy_talk_group g, wlyy.wlyy_talk_group_member m, wlyy.wlyy_doctor d, msg_statistic ms, " +
        " ( SELECT new_msg_count, from_gid  FROM  msg_statistic  WHERE uid =?  GROUP BY from_gid  ORDER BY  `timestamp` DESC ) msgcount " +
        " WHERE d.code = ? AND d.code = m.member_code AND msgcount.from_gid=ms.from_gid " +
        "   AND m.group_code = g.code AND g.type=1  AND g.code = ms.from_gid group by m.group_code, m.group_name" +
        ") X ORDER BY timestamp DESC";
    //var sql = "SELECT * FROM (" +
    //    " SELECT g.code, g.name, ms.last_content_type, ms.last_content, ms.timestamp, msgcount.new_msg_count, g.type group_type " +
    //    " FROM msg_statistic ms, (" +
    //    " SELECT g.code code, g.name name, g.type type FROM wlyy.wlyy_talk_group g, wlyy.wlyy_talk_group_member m " +
    //    " WHERE g.code = m.group_code and m.member_code = ?) g, wlyy.wlyy_patient p , " +
    //    " ( SELECT new_msg_count, from_gid  FROM  msg_statistic  WHERE uid =?  GROUP BY from_gid  ORDER BY  `timestamp` DESC ) msgcount " +
    //    " WHERE ((ms.uid = ? and ms.from_uid = p.code)) " +
    //    " and ms.from_gid = g.code and ms.msg_type = 2 AND ms.last_content_type in (1,2,3,5,6) AND msgcount.from_gid=ms.from_gid " +
    //    " UNION " +
    //    " SELECT m.group_code code, m.group_name name, ms.last_content_type, ms.last_content, ms.timestamp, ms.new_msg_count, '2' group_type " +
    //    " FROM wlyy.wlyy_talk_group g, wlyy.wlyy_talk_group_member m, wlyy.wlyy_doctor d, msg_statistic ms, " +
    //    " ( SELECT new_msg_count, from_gid  FROM  msg_statistic  WHERE uid =?  GROUP BY from_gid  ORDER BY  `timestamp` DESC ) msgcount " +
    //    " WHERE d.code = ? AND d.code = m.member_code AND msgcount.from_gid=ms.from_gid " +
    //    "   AND m.group_code = g.code AND g.type=1  AND g.code = ms.from_gid group by m.group_code, m.group_name" +
    //    ") X ORDER BY timestamp DESC";
    var sql ="SELECT g.`code`, g.`name`, s.last_content_type, s.last_content, s. TIMESTAMP as timestamp , s.new_msg_count, g.type group_type " +
              "FROM msg_group w, wlyy.wlyy_talk_group g, wlyy.wlyy_talk_group_member t, msg_statistic s " +
              "WHERE w.to_gid = g.`code` AND t.group_code = g. CODE " +
              "AND w.to_gid IN ( SELECT w1.group_code FROM wlyy.wlyy_talk_group_member w1 WHERE w1.member_code =? ) " +
              "AND s.uid = ? AND s.from_gid IS NOT NULL AND s.from_gid  = g.code GROUP BY g. NAME, g.`code` ORDER BY w.msg_id DESC;"
    imRepo.execQuery({
        "sql": sql,

+ 24 - 14
src/doctor/repository/private.msg.repo.js

@ -58,17 +58,23 @@ exports.findAllMessages = function (to, from, contentType, start, end, count, cl
 * @param handler
 */
exports.findAllP2PWithDoctor = function (userId, handler) {
    var sql = "SELECT DISTINCT d.code, d.name, d.sex, d.photo, ms3.last_content_type, ms3.last_content, ms3.timestamp, ms3.new_msg_count " +
        "FROM (SELECT DISTINCT CASE WHEN ms1.timestamp > ms2.timestamp THEN ms1.id ELSE ms2.id END id " +
        "      FROM msg_statistic ms1, msg_statistic ms2 " +
        "      WHERE ms1.from_gid IS NULL AND ms2.from_gid IS NULL " +
        "            AND ms1.uid = ms2.peer_uid AND ms1.peer_uid = ms2.uid) x, msg_statistic ms3, wlyy.wlyy_doctor d " +
        "WHERE x.id = ms3.id AND ms3.last_content_type in (1,2,3,5,6) AND " +
        "(ms3.uid = ? AND ms3.peer_uid = d.code) GROUP BY d.code, d.name ORDER BY ms3.timestamp DESC";
    //var sql = "SELECT DISTINCT d.code, d.name, d.sex, d.photo, ms3.last_content_type, ms3.last_content, ms3.timestamp, ms3.new_msg_count " +
    //    "FROM (SELECT DISTINCT CASE WHEN ms1.timestamp > ms2.timestamp THEN ms1.id ELSE ms2.id END id " +
    //    "      FROM msg_statistic ms1, msg_statistic ms2 " +
    //    "      WHERE ms1.from_gid IS NULL AND ms2.from_gid IS NULL " +
    //    "            AND ms1.uid = ms2.peer_uid AND ms1.peer_uid = ms2.uid) x, msg_statistic ms3, wlyy.wlyy_doctor d " +
    //    "WHERE x.id = ms3.id AND ms3.last_content_type in (1,2,3,5,6) AND " +
    //    "(ms3.uid = ? AND ms3.peer_uid = d.code) GROUP BY d.code, d.name ORDER BY ms3.timestamp DESC";
    var sql ="SELECT d. CODE as code, d. NAME as name,  d.sex, d.photo, s.last_content_type, s.last_content, s. TIMESTAMP as timestamp, s.new_msg_count " +
        "FROM msg_p2p p, wlyy.wlyy_doctor d, msg_statistic s " +
        "WHERE (( p.from_uid = d. CODE AND p.to_uid = ? ) OR ( p.to_uid = d. CODE AND p.from_uid = ? )) " +
        "AND s.from_gid IS NULL AND s.uid = ? " +
        "AND s.peer_uid = d. CODE " +
        "GROUP BY d. NAME, d. CODE, d.hospital_name, d.job_name, d.sex, d.photo ORDER BY p.msg_id DESC"
    imRepo.execQuery({
        "sql": sql,
        "args": [userId, userId],
        "args": [userId, userId,userId],
        "handler": handler
    });
};
@ -80,14 +86,18 @@ exports.findAllP2PWithDoctor = function (userId, handler) {
 * @param handler
 */
exports.findAllP2PWithPatient = function (userId, handler) {
    var sql = "SELECT p.code, p.name, p.birthday, p.sex, p.photo, ms.last_content_type, ms.last_content, ms.timestamp, ms.new_msg_count " +
        "FROM msg_statistic ms, wlyy.wlyy_patient p " +
        "WHERE ms.msg_type = 1 AND ms.last_content_type in (1,2,3,5,6) " +
        "AND ((ms.from_uid = ? AND ms.uid = p.code) OR (ms.uid = ? AND ms.from_uid = p.code)) ORDER BY ms.timestamp";
    //var sql = "SELECT p.code, p.name, p.birthday, p.sex, p.photo, ms.last_content_type, ms.last_content, ms.timestamp, ms.new_msg_count " +
    //    "FROM msg_statistic ms, wlyy.wlyy_patient p " +
    //    "WHERE ms.msg_type = 1 AND ms.last_content_type in (1,2,3,5,6) " +
    //    "AND ((ms.from_uid = ? AND ms.uid = p.code) OR (ms.uid = ? AND ms.from_uid = p.code)) ORDER BY ms.timestamp";
    var sql="SELECT p1. CODE as code , p1. NAME as name, p1.birthday, p1.sex, p1.photo, w.last_content, w.last_content_type, w. TIMESTAMP as timestamp, w.new_msg_count " +
             "FROM msg_p2p p, wlyy.wlyy_patient p1, msg_statistic w " +
             "WHERE (( p.to_uid = p1.`code` AND p.from_uid = ? ) OR ( p.from_uid = p1.`code` AND p.to_uid = ? )) " +
             "AND p.type IN (1, 2, 3, 5, 6) AND w.uid = ? AND w.peer_uid = p1.`code` AND w.from_gid IS NULL " +
        "GROUP BY p1. CODE, p1. NAME, p1.birthday, p1.sex, p1.photo"
    imRepo.execQuery({
        "sql": sql,
        "args": [userId, userId],
        "args": [userId, userId,userId],
        "handler": handler
    });
};

+ 8 - 6
src/doctor/repository/search.repo.js

@ -139,14 +139,15 @@ module.exports.searchP2Pdoctors = function(userId,keyword,handler){
 * 搜索聊天过的内容
 */
module.exports.searchDoctorsContent = function(userId,keyword,handler){
    var sql ="SELECT wt. CODE as code, wt.`name`, count(mg.content) AS amount, max(mg.content) AS content,max(mg.msg_id) as msg_id , 2 AS type,wt.type as group_type " +
    var sql ="SELECT wt. CODE as code, wt.`name`, count(mg.content) AS amount, max(mg.content) AS content,max(mg.msg_id) as msg_id , 2 AS type,wt.type as group_type,'' as photo " +
             "FROM msg_group mg, wlyy.wlyy_talk_group wt " +
             "WHERE mg.to_gid = wt.`code` " +
             "AND mg.content LIKE ? " +
             "AND wt.`code` IN ( SELECT me.group_code FROM wlyy.wlyy_talk_group_member me WHERE me.member_code = ? ) " +
             "AND wt.`code` NOT IN (SELECT me.group_code FROM wlyy.wlyy_talk_group_member me WHERE me.group_code = wt.code and  me.STATUS = 1  AND me.TYPE =4) "+
             "GROUP BY wt. CODE, wt.`name`,wt.type " +
             "UNION ALL " +
             "SELECT d. CODE as code, d. NAME as name, sum(1) AS amount, max(mp.content) AS content,max(mp.msg_id) as msg_id, 1 AS type ,0 as group_type " +
             "SELECT d. CODE as code, d. NAME as name, sum(1) AS amount, max(mp.content) AS content,max(mp.msg_id) as msg_id, 1 AS type ,0 as group_type,d.photo as photo " +
             "FROM msg_p2p mp, wlyy.wlyy_doctor d " +
             "WHERE (( mp.from_uid = d. CODE AND mp.to_uid = ? ) OR ( mp.to_uid = d. CODE AND mp.from_uid = ? )) " +
             "AND mp.content LIKE ?  GROUP BY d. NAME, d. CODE";
@ -163,7 +164,7 @@ module.exports.searchDoctorsContent = function(userId,keyword,handler){
 */
module.exports.searchDoctorsContentDetail = function(userId,keyword,groupcode,type,handler){
    if(type==2){
        var groupsql ="SELECT wt. CODE as code, wt.`name`,mg.content,mg.msg_id,wt.type as group_type" +
        var groupsql ="SELECT wt. CODE as code, wt.`name`,mg.content,mg.msg_id,wt.type as group_type " +
            "FROM msg_group mg, wlyy.wlyy_talk_group wt " +
            "WHERE mg.to_gid = wt.`code` " +
            "AND mg.content LIKE ? " +
@ -175,14 +176,14 @@ module.exports.searchDoctorsContentDetail = function(userId,keyword,groupcode,ty
        });
    }
    if(type==1){
         var p2psql  =    "SELECT d. CODE as code, d. NAME as name, mp.content,mp.msg_id,0 as group_type " +
         var p2psql  =  "SELECT d. CODE as code, d. NAME as name,d.photo, mp.content,mp.msg_id,0 as group_type " +
            "FROM msg_p2p mp, wlyy.wlyy_doctor d " +
            "WHERE (( mp.from_uid = ? AND mp.to_uid = ? ) OR ( mp.to_uid = ? AND mp.from_uid = ? )) " +
            "WHERE (( mp.from_uid = ? AND mp.to_uid = ? and mp.from_uid = d.`code`) OR ( mp.to_uid = ? AND mp.from_uid = ? and mp.to_uid = d.`code` )) " +
            "AND mp.content LIKE ? ;";
            imRepo.execQuery({
                "sql": p2psql,
                "args": [userId,groupcode,userId,userId,groupcode,"%" + keyword + "%"],
                "args": [userId,groupcode,userId,groupcode,"%" + keyword + "%"],
                "handler": handler
            });
        }
@ -199,6 +200,7 @@ module.exports.searchGroupDoctors = function(userId,keyword,handler){
        "WHERE w.to_gid = g.`code` and  t.type<4 " +
        "AND t.group_code = g. CODE " +
        "AND w.to_gid IN ( SELECT w1.group_code FROM wlyy.wlyy_talk_group_member w1 WHERE w1.member_code = ? ) " +
        "AND W.to_gid NOT IN (SELECT w1.group_code FROM wlyy.wlyy_talk_group_member w1 WHERE w1.group_code = g.code and  w1. STATUS = 1  AND w1.TYPE =4) "+
        "AND ( g.`name` LIKE ? OR t.member_name LIKE ?) " +
        "GROUP BY g. NAME, g.`code` order by w.msg_id desc";
    imRepo.execQuery({

+ 2 - 0
src/doctor/repository/stats.msg.repo.js

@ -48,6 +48,7 @@ exports.getChatAllUnReadCount = function (userId, handler) {
exports.updatePrivateChatSummary = function (userId, peerId, from, type, content, handler) {
    var uuid = userId + '_' + peerId;
    if (userId == from) {
        //userId  = from ,peerId = to from = from
        // 更新自身的统计信息
        var sql = "INSERT INTO msg_statistic (uid,uuid,from_uid,peer_uid,msg_type,last_content_type,last_content,new_msg_count) " +
            "VALUES (?,?,?,?,?,?,?,?) ON DUPLICATE KEY UPDATE peer_uid=?,last_content_type=?,last_content=?";
@ -58,6 +59,7 @@ exports.updatePrivateChatSummary = function (userId, peerId, from, type, content
            "handler": handler
        });
    } else {
        //userId  = to ,peerId = from, from = from
        var sql = "INSERT INTO msg_statistic (uid,uuid,from_uid,peer_uid,msg_type,last_content_type,last_content,new_msg_count) " +
            "VALUES (?,?,?,?,?,?,?,?) ON DUPLICATE KEY UPDATE peer_uid=?,last_content_type=?,last_content=?,new_msg_count=new_msg_count+1";
        // 更新对端的统计信息