瀏覽代碼

代码修改

yeshijie 7 年之前
父節點
當前提交
1ff94212e8

+ 0 - 10
src/server/models/client/app.client.js

@ -7,7 +7,6 @@ let RedisClient = require('../../repository/redis/redis.client');
let RedisModel = require('./../redis.model');
let AppStatusRepo = require('../../repository/mysql/app.status.repo');
let MessageNoticeSettingRepo = require('../../repository/mysql/message.noticeSetting.repo');
let SignFamilyRepo = require('../../repository/mysql/sign.family.repo');
let ModelUtil = require('../../util/model.util');
let clientCache = require('../socket.io/client.cache').clientCache();
let WlyySDK = require("../../util/wlyy.sdk");
@ -175,15 +174,6 @@ class AppClient extends RedisModel {
                //             if(master_switch==0||im_switch==0){
                //                 ModelUtil.logError(targetId+"-关闭im消息,消息id", message.id);
                //             }
                //             // else if(session_type==SESSION_TYPES.MUC&&family_topic_switch==1){
                //             //     SignFamilyRepo.isHealthDoctor(message.session_id,targetId,function (err,res) {
                //             //         if(res&&res.length==0){
                //             //             ModelUtil.logError("全科医生:"+targetId+"-关闭im消息,消息id", message.id);
                //             //         }else{
                //             //             AppClient.sendNotice(targetId, message, sessionType,badge,userStatus)
                //             //         }
                //             //     })
                //             // }
                //             else{
                //                 AppClient.sendNotice(targetId, message, sessionType,badge,userStatus);
                //             }

+ 0 - 160
src/server/repository/mysql/private.msg.repo.js

@ -1,160 +0,0 @@
/**
 * P2P消息库。
 */
"use strict";
var ImDb = require("../mysql/db/im.db.js");
class PrivateMsgRepo {
    constructor() {
    }
    /**
     * 保存消息。
     *
     * @param to
     * @param from
     * @param type
     * @param content
     * @param handler
     */
    static save(to, from, type, content, handler) {
        ImDb.execQuery({
            "sql": "INSERT INTO msg_p2p (to_uid,from_uid,type,content) VALUES (?,?,?,?)",
            "args": [to, from, type, content],
            "handler": handler
        });
    };
    static findOneMessage(messageId, handler) {
        ImDb.execQuery({
            "sql": "SELECT msg_id, to_uid, from_uid, type, content, timestamp from msg_p2p where msg_id = ?",
            "args": [messageId],
            "handler": handler
        });
    };
    static findOnePatientMessage(messageId, handler) {
        ImDb.execQuery({
            "sql": "SELECT m.*,d.name,d.photo FROM msg_p2p m, wlyy.wlyy_doctor d, wlyy.wlyy_patient p WHERE m.from_uid = d. CODE AND m.to_uid = p. CODE AND m.msg_id =?",
            "args": [messageId],
            "handler": handler
        });
    };
    /**
     * 查找所有消息。
     *
     * @param to
     * @param from
     * @param contentType
     * @param start
     * @param end
     * @param count
     * @param closedInterval
     * @param handler
     */
    static findAllMessages(to, from, contentType, start, end, count, closedInterval, handler) {
        var sql = "SELECT msg_id, to_uid, from_uid, type, content, timestamp from msg_p2p " +
            "WHERE ((to_uid=? AND from_uid=?) OR (to_uid=? AND from_uid=?)) " +
            "   AND type in (" + contentType + ") AND msg_id between ? and ? ORDER BY msg_id DESC LIMIT ?";
        ImDb.execQuery({
            "sql": sql,
            "args": [to, from, from, to, closedInterval ? end : end + 1, closedInterval ? start : start - 1, count],
            "handler": handler
        });
    };
    /**
     * 查找用户聊天过的医生列表。
     *
     * @param userId 指定的用户
     * @param handler
     */
    static findAllP2PWithDoctor(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 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"
        ImDb.execQuery({
            "sql": sql,
            "args": [userId, userId, userId],
            "handler": handler
        });
    };
    /**
     * 查找用户聊天过的患者列表。
     *
     * @param userId
     * @param handler
     */
    static findAllP2PWithPatient(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 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 w.last_content_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 " +
            "union all " +
            "SELECT p1. CODE AS code, p1. NAME AS name, p1.birthday, p1.sex, p1.photo, w.last_content, t.type, w. TIMESTAMP AS timestamp, w.new_msg_count " +
            "FROM msg_p2p p, wlyy.wlyy_patient p1, msg_statistic w, wlyy.wlyy_consult_team t " +
            "WHERE (( p.to_uid = p1.`code` AND p.from_uid = ? ) OR ( p.from_uid = p1.`code` AND p.to_uid = ? )) " +
            "AND w.last_content_type = 7 AND t.type = 6 " +
            "AND (( t.patient = p.from_uid AND t.doctor = p.to_uid ) OR ( t.patient = p.to_uid AND t.doctor = p.from_uid )) " +
            "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;";
        ImDb.execQuery({
            "sql": sql,
            "args": [userId, userId, userId, userId, userId, userId],
            "handler": handler
        });
    };
    /**
     * 查找未读消息。
     *
     * @param from
     * @param to
     * @param start
     * @param count
     * @param handler
     */
    static findUnread  (from, to, start, count, handler) {
        var sql = "SELECT msg_id, to_uid, from_uid, type, content, timestamp from msg_p2p " +
            "WHERE from_uid = ? AND to_uid = ? AND msg_id < ? ORDER BY timestamp DESC LIMIT ?";
        ImDb.execQuery({
            "sql": sql,
            "args": [from, to, start, count],
            "handler": handler
        });
    };
    static isCurrentSessionFinished(doctorId, patientId, handler) {
        var sql = "SELECT c.consult consult_id, case when c.end_msg_id is not null then 1 else 0 end finished " +
            "FROM wlyy.wlyy_consult_team c where c.doctor=? and c.patient = ? ORDER BY id DESC LIMIT 1";
        ImDb.execQuery({
            "sql": sql,
            "args": [doctorId, patientId],
            "handler": handler
        });
    };
}
module.exports = PrivateMsgRepo;

+ 6 - 6
src/server/repository/mysql/search.repo.js

@ -20,11 +20,11 @@ class SearchRepo {
    static findTopicEndedSessionIdList(userId, handler) {
        let sql = "SELECT s.id " +
            "FROM sessions s, topics t, participants p " +
            "WHERE p.participant_id = ? AND p.session_id = s.id AND s.id = t.session_id AND t.end_message_id IS NOT NULL AND s.`type` IN (1,2,8) " +
            "WHERE p.participant_id = ? AND p.session_id = s.id AND s.id = t.session_id AND t.end_message_id IS NOT NULL AND s.`type` IN (1) " +
            " UNION " +
            "SELECT s.id " +
            "FROM sessions s, participants p " +
            "WHERE p.participant_id = ? AND p.session_id = s.id AND s.`type` IN (2, 3)";
            "WHERE p.participant_id = ? AND p.session_id = s.id AND s.`type` IN (1, 3)";
        ImDb.execQuery({
            sql: sql,
@ -42,11 +42,11 @@ class SearchRepo {
    static findTopicActiveSessionIdList(userId, handler) {
        let sql = "SELECT s.id " +
            "FROM sessions s, topics t, participants p " +
            "WHERE p.participant_id = ? AND p.session_id = s.id AND s.id = t.session_id AND t.end_message_id IS NULL  AND s.`type` IN (1,2,8) " +
            "WHERE p.participant_id = ? AND p.session_id = s.id AND s.id = t.session_id AND t.end_message_id IS NULL  AND s.`type` IN (1) " +
            " UNION " +
            "SELECT s.id " +
            "FROM sessions s, participants p " +
            "WHERE p.participant_id = ? AND p.session_id = s.id  AND s.`type` IN (2,3)  and s.id not in(" +
            "WHERE p.participant_id = ? AND p.session_id = s.id  AND s.`type` IN (1,3)  and s.id not in(" +
            " select DISTINCT p1.session_id from  participants p1 ,topics t where p1.participant_id = ? and  t.session_id = p1.session_id  " +
            ") ";
        ImDb.execQuery({
@ -115,9 +115,9 @@ class SearchRepo {
            " u,sessions s WHERE s.id in (?) AND s.id = p.session_id AND p.participant_id = u.id and p.participant_id<>? AND (u.name like ? or u.idcard like ?) ";
        if (userTable === DB_TABLES.Doctors) {
            sql += " AND s.type in (2) and s.business_type = 1 ";
            sql += " AND s.type in (1) and s.business_type = 1 ";
        }else{
            sql += " AND s.type in (1,2,8)  and s.business_type = 2 ";
            sql += " AND s.type in (1)  and s.business_type = 2 ";
        }
        sql += " limit ?, ? ";
        sql = vsprintf(sql, [userTable == DB_TABLES.Doctors ? ', hospital_name' : '']);

+ 1 - 1
src/server/repository/mysql/session.repo.js

@ -203,7 +203,7 @@ class SessionRepo {
     * @param handler
     */
    static findAllByTimestampAndType(userId, dateSpan, handler) {
        let sql = "SELECT DISTINCT s.id, CASE WHEN TYPE = 2 THEN d.name ELSE s.name END 'name',s.last_content_type, s.type, s.create_date, s.business_type " +
        let sql = "SELECT DISTINCT s.id, CASE WHEN TYPE = 1 THEN d.name ELSE s.name END 'name',s.last_content_type, s.type, s.create_date, s.business_type " +
        "FROM sessions s, participants p " +
        "LEFT JOIN doctors d ON p.participant_id = d.id " +
        "WHERE s.id = p.session_id AND s.last_sender_id <> 'system' " +

+ 0 - 51
src/server/repository/mysql/sign.family.repo.js

@ -1,51 +0,0 @@
/**
 * Created by ysj on 2017/12/4.
 */
"use strict";
let log = require('../../util/log');
let ImDb = require('../mysql/db/im.db');
const DB_TABLES = require('../../include/commons').DB_TABLES;
class SignFamilyRepo{
    constructor(){
    }
    /**
     * 获取单个MessageNoticeSetting对象
     *
     * @param session_id
     * @param handler
     */
    static findDoctor(session_id, handler) {
        let sql = "SELECT s.doctor,s.doctor_health from "+DB_TABLES.Participants+" p,"+DB_TABLES.SignFamily+" s WHERE p.session_id = ? and p.participant_id = s.patient and s.`status`>0";
        ImDb.execQuery({
            "sql": sql,
            "args": [session_id],
            "handler": handler || function (err, res) {
                if(err) log.error(err);
            }
        });
    }
    /**
     * 判断医生在会话中是否是健管师
     * @param session_id
     * @param doctor
     * @param handler
     */
    static isHealthDoctor(session_id,doctor, handler) {
        let sql = "SELECT s.doctor_health from "+DB_TABLES.Participants+" p,"+DB_TABLES.SignFamily+" s WHERE p.session_id = ? and p.participant_id = s.patient and s.doctor_health=? and s.`status`>0";
        ImDb.execQuery({
            "sql": sql,
            "args": [session_id,doctor],
            "handler": handler || function (err, res) {
                if(err) log.error(err);
            }
        });
    }
}
module.exports = SignFamilyRepo;