Browse Source

适配达梦修改

LAPTOP-KB9HII50\70708 1 year ago
parent
commit
df512cb613

+ 1 - 1
src/server/models/messages/messages.js

@ -239,7 +239,7 @@ class Messages extends RedisModel {
                    if (err) {
                        ModelUtil.emitError(self.eventEmitter, {message: "this message not exist,id: " + messageId});
                    } else {
                        res[0].content = content;
                        res[0].CONTENT = content;
                        log.info("res[0].timestamp="+res[0].timestamp.getTime());
                        callback(null,res[0]);
                    }

+ 4 - 4
src/server/models/user/users.js

@ -428,7 +428,7 @@ class Users extends RedisModel {
     * @param callback
     */
    static updatePatientStatus1(userId,online, handler) {
        let sql = "update base.base_patient set on_line=? where id = ?";
        let sql = "update base.patient set on_line=? where id = ?";
        ImDb.execQuery({
            "sql": sql,
            "args": [online, userId],
@ -445,7 +445,7 @@ class Users extends RedisModel {
     * @param handler
     */
    static updateDoctorStatus1(userId,online, handler) {
        let sql = "update base.base_doctor set on_line=? where id = ?";
        let sql = "update base.doctor set on_line=? where id = ?";
        ImDb.execQuery({
            "sql": sql,
            "args": [online, userId],
@ -460,7 +460,7 @@ class Users extends RedisModel {
     * @param handler
     */
    static updateDoctorStatus0(handler) {
        let sql = "update base.base_doctor set on_line=0 ";
        let sql = "update base.doctor set on_line=0 ";
        ImDb.execQuery({
            "sql": sql,
            "handler": handler || function (err, res) {
@ -476,7 +476,7 @@ class Users extends RedisModel {
     * @param callback
     */
    static updatePatientStatus0(handler) {
        let sql = "update base.base_patient set on_line=0 ";
        let sql = "update base.patient set on_line=0 ";
        ImDb.execQuery({
            "sql": sql,
            "handler": handler || function (err, res) {

+ 8 - 4
src/server/repository/mysql/app.status.repo.js

@ -10,6 +10,7 @@
"use strict";
let ImDb = require("./db/im.db.js");
const {DB_TABLES} = require("../../include/commons");
class AppStatusRepo {
    constructor() {
@ -42,10 +43,13 @@ class AppStatusRepo {
     * @param handler
     */
    static save(userId, deviceToken, client_id, platform, handler) {
        let sql = "INSERT INTO app_status (user_id, platform, token, client_id, app_in_bg, last_login_time) " +
            "VALUES (?, ?, ?, ?, 0, now()) " +
            "ON DUPLICATE KEY UPDATE platform=?, token=?, client_id=?, app_in_bg=0,last_login_time=now()";
        // let sql = "INSERT INTO app_status (user_id, platform, token, client_id, app_in_bg, last_login_time) " +
        //     "VALUES (?, ?, ?, ?, 0, now()) " +
        //     "ON DUPLICATE KEY UPDATE platform=?, token=?, client_id=?, app_in_bg=0,last_login_time=now()";
        let sql = "merge into app_status t1 using( select ? user_id,? platform,? token,? client_id,0 app_in_bg,now() last_login_time from dual) t2 on (t1.user_id=t2.user_id) " +
            " WHEN MATCHED THEN update set t1.platform = t2.platform,t1.token=t2.token,t1.client_id=t2.client_id,t1.app_in_bg=0,t1.last_login_time=t2.last_login_time " +
            " WHEN NOT MATCHED THEN INSERT (user_id, platform, token, client_id, app_in_bg, last_login_time) VALUES " +
            " (t2.user_id, t2.platform, t2.token, t2.client_id, t2.app_in_bg, t2.last_login_time)"
        ImDb.execQuery({
            sql: sql,
            args: [userId, platform, deviceToken, client_id, platform, deviceToken, client_id],

+ 3 - 3
src/server/repository/mysql/doctor.repo.js

@ -14,7 +14,7 @@ class DoctorRepo {
    static findOne(doctorId, handler) {
        ImDb.execQuery({
            "sql": "select id, name, sex, birthdate, avatar ,idcard from doctors where id = ? ",
            "sql": "select id as \"id\", name as \"name\", sex as \"sex\", birthdate as \"birthdate\", avatar as \"avatar\",idcard as \"idcard\" from doctors where id = ? ",
            "args": [doctorId],
            "handler": handler
        });
@ -22,7 +22,7 @@ class DoctorRepo {
    static findByMobile(mobile, handler) {
        ImDb.execQuery({
            "sql": "select id, name, sex, birthdate, avatar from doctors where mobile = ? ",
            "sql": "select id as \"id\", name as \"name\", sex as \"sex\", birthdate as \"birthdate\", avatar as \"avatar\" from doctors where mobile = ? ",
            "args": [mobile],
            "handler": handler
        });
@ -30,7 +30,7 @@ class DoctorRepo {
    static addDoctor(id,name,mobile,sex,birthdate,avatar,hospital_name,level,idcard, handler) {
        ImDb.execQuery({
            "sql": "insert into base.base_doctor (id,name,mobile,sex,birthdate,photo,idcard,del) values (?,?,?,?,?,?,?,1)",
            "sql": "insert into base.doctor (id,name,mobile,sex,birthdate,photo,idcard,del) values (?,?,?,?,?,?,?,1)",
            "args": [id,name,mobile,sex,birthdate,avatar,idcard],
            "handler": handler
        });

+ 2 - 2
src/server/repository/mysql/message.repo.js

@ -53,7 +53,7 @@ class MessageRepo {
                    params.push(messageType);
                }
                let sql = "select id, session_id, sender_id, sender_name, content_type, content, timestamp from " +
                let sql = "select id as \"id\", session_id as \"session_id\", sender_id as \"sender_id\", sender_name as \"sender_name\", content_type as \"content_type\", content as \"content\", timestamp as \"timestamp\" from " +
                    MessageTable + " w where " + where + " order by w.id limit ?, ?";
                params.push(page);
                params.push(size);
@ -151,7 +151,7 @@ class MessageRepo {
     */
    static findLastMessage(sessionId,sessionType,handler){
        let sql =
            "SELECT s.content_type, s.content,s.agent FROM " + DB_TABLES.sessionTypeToTableName(sessionType) + " s " +
            "SELECT s.content_type as \"content_type\", s.content as \"content\",s.agent as \"agent\" FROM " + DB_TABLES.sessionTypeToTableName(sessionType) + " s " +
            "WHERE s.session_id = ? order by s.timestamp desc limit 1 ";
        log.info("获取会话医生的id sql : " + sql);
        log.info("获取会话医生的id args : " + [sessionId]);

+ 29 - 25
src/server/repository/mysql/participant.repo.js

@ -23,9 +23,10 @@ class ParticipantRepo {
     * @param handler
     */
    static findAll(sessionId, handler) {
        let sql = "SELECT u.id, u.name, u.sex, u.birthdate, u.avatar,u.hospital_name, p.participant_role role, false is_patient,p.last_fetch_time,u.level,u.mobile FROM sessions s, participants p, doctors u " +
        let sql = "SELECT u.id as \"id\", u.name as \"name\", u.sex as \"sex\", u.birthdate as \"birthdate\", u.avatar as \"avatar\",u.hospital_name as \"hospital_name\", p.participant_role as \"role\", false as \"is_patient\",p.last_fetch_time as \"last_fetch_time\",u.level as \"level\",u.mobile as\" mobile\" FROM sessions s, participants p, doctors u " +
            "WHERE s.id = ? AND s.id = p.session_id AND p.participant_id = u.id union " +
            "SELECT u.id, u.name, u.sex, u.birthdate, u.avatar,u.hospital_name, p.participant_role role, true is_patient,p.last_fetch_time,0 as level,u.mobile FROM sessions s, participants p, patients u " +
            // "SELECT u.id, u.name, u.sex, u.birthdate, u.avatar,u.hospital_name, p.participant_role role, true is_patient,p.last_fetch_time,0 as level,u.mobile FROM sessions s, participants p, patients u " +
            "SELECT u.id as \"id\", u.name as \"name\", u.sex as \"sex\", u.birthdate as \"birthdate\", u.avatar as \"avatar\",u.hospital_name as \"hospital_name\", p.participant_role as \"role\", true as \"is_patient\",p.last_fetch_time as \"last_fetch_time\",0 as \"level\",u.mobile as\" mobile\" FROM sessions s, participants p, patients u " +
            "WHERE s.id = ? AND s.id = p.session_id AND p.participant_id = u.id";
        ImDb.execQuery({
@ -52,10 +53,10 @@ class ParticipantRepo {
     */
    static findIds(sessionId, handler) {
        let sql =
            "SELECT u.id, u.name, false is_patient, p.participant_role,u.avatar FROM sessions s, participants p, doctors u " +
            "SELECT u.id as \"id\", u.name as \"name\", false \"is_patient\", p.participant_role as \"participant_role\",u.avatar as \"avatar\" FROM sessions s, participants p, doctors u " +
            "WHERE s.id = ? AND s.id = p.session_id AND p.participant_id = u.id " +
            "UNION " +
            "SELECT u.id, u.name, true is_patient, p.participant_role,u.avatar FROM sessions s, participants p, patients u " +
            "SELECT u.id as \"id\", u.name as \"name\", true \"is_patient\", p.participant_role as \"participant_role\",u.avatar as \"avatar\" FROM sessions s, participants p, patients u " +
            "WHERE s.id = ? AND s.id = p.session_id AND p.participant_id = u.id ";
        ImDb.execQuery({
@ -71,7 +72,7 @@ class ParticipantRepo {
     * @param handler
     */
    static findParricipantBySessionId(sessionId,handler){
        let sql = "select participant_id,participant_role from participants p where p.session_id = ?";
        let sql = "select participant_id as \"participant_id\",participant_role as \"participant_role\" from participants p where p.session_id = ?";
        ImDb.execQuery({
            "sql": sql,
            "args": [sessionId],
@ -86,7 +87,7 @@ class ParticipantRepo {
     */
    static findDoctorIds(sessionId,handler){
        let sql =
            "SELECT u.id, u.name, false is_patient, p.participant_role,u.avatar FROM sessions s, participants p, doctors u " +
            "SELECT u.id as \"id\", u.name as \"name\", false \"is_patient\", p.participant_role as \"participant_role\",u.avatar as \"avatar\" FROM sessions s, participants p, doctors u " +
            "WHERE s.id = ? AND s.id = p.session_id AND p.participant_id = u.id ";
        ImDb.execQuery({
@ -103,7 +104,7 @@ class ParticipantRepo {
     */
    static findFamilyIds(sessionId, handler){
        let sql =
            "SELECT u.id, u.name, true is_patient, p.participant_role,u.avatar,ps.name pname,ps.id pid " +
            "SELECT u.id as \"id\", u.name as \"name\", true \"is_patient\", p.participant_role as \"participant_role\",u.avatar as \"avatar\",ps.name as \"pname\",ps.id as \"pid\" " +
            "FROM sessions s, participants p, patients u ,wlyy.wlyy_patient_family_member m,patients ps " +
            "WHERE s.id = ? and s.id = p.session_id and p.participant_id = m.patient AND m.family_member = u.id and m.is_authorize = 1 and p.participant_id = ps.id ";
        //新增发送代理人
@ -122,9 +123,9 @@ class ParticipantRepo {
     * @param handler
     */
    static findAllAvatars(sessionId, handler) {
        let sql = "SELECT u.id, u.avatar,'0' as ispatient,u.name as name FROM sessions s, participants p, doctors u " +
        let sql = "SELECT u.id as \"id\", u.avatar as \"avatar\",'0' as \"ispatient\",u.name as \"name\" FROM sessions s, participants p, doctors u " +
            "WHERE s.id = ? AND s.id = p.session_id AND p.participant_id = u.id union " +
            "SELECT u.id, u.avatar,'1' as ispatient,u.name as name FROM sessions s, participants p, patients u " +
            "SELECT u.id as \"id\", u.avatar as \"avatar\",'1' as \"ispatient\",u.name as \"name\" FROM sessions s, participants p, patients u " +
            "WHERE s.id = ? AND s.id = p.session_id AND p.participant_id = u.id";
        ImDb.execQuery({
@ -164,10 +165,11 @@ class ParticipantRepo {
    }
    static getBusinessType(users, handler) {
        var userNew = users.join(",");
        let sql = "SELECT count(1) as count FROM patients p WHERE p.id in (?)";
        ImDb.execQuery({
            "sql": sql,
            "args": [users],
            "args": [userNew],
            "handler": function (err, res) {
                if (err) {
                    console.log("err businessType  : " + err);
@ -185,7 +187,8 @@ class ParticipantRepo {
    }
    static findNameById(userId, handler) {
        let sql = "SELECT p.name,p.sex,p.birthdate,2 as userType FROM patients p WHERE p.id =? union SELECT d.name,d.sex,d.birthdate,1 as userType FROM doctors d WHERE d.id =?";
        let sql = "SELECT p.name as \"name\",p.sex as \"sex\",p.birthdate as \"birthdate\",2 as \"userType\" FROM patients p WHERE p.id =? union" +
            " SELECT d.name as \"name\",d.sex as \"sex\",d.birthdate as \"birthdate\",1 as \"userType\" FROM doctors d WHERE d.id =?";
        ImDb.execQuery({
            "sql": sql,
            "args": [userId, userId],
@ -244,7 +247,7 @@ class ParticipantRepo {
     * @param handler
     */
    static existsParticipant(sessionId, userId, handler) {
        let sql = "SELECT case when count(*) > 0 then true else false end exist FROM participants w WHERE w.session_id =? AND w.participant_id = ? ";
        let sql = "SELECT case when count(*) > 0 then true else false end as \"exist\" FROM participants w WHERE w.session_id =? AND w.participant_id = ? ";
        log.info("用户是否在指定Session中:sql:" + sql);
        log.info("用户是否在指定Session中:args:" + [sessionId, userId]);
        ImDb.execQuery({
@ -262,25 +265,26 @@ class ParticipantRepo {
     * @param handler
     */
    static saveParticipantsToMysql(sessionId, users, handler) {
        let sql = "INSERT INTO " + DB_TABLES.Participants + " (session_id,participant_id,participant_role,last_fetch_time) VALUES ";
        let sql = "merge into " + DB_TABLES.Participants + " t1  using( ";
        let args = [];
        let nowDate = new Date();
        log.info("saveParticipantsToMysql:[sql] = " + sql);
        log.info("saveParticipantsToMysql:[users.length] = " + users.length);
        for (let j in users) {
        for (let j = 0; j < users.length; j++) {
            let tokens = users[j].split(":");
            sql += "(?,?,?,?)";
            args.push(sessionId);
            args.push(tokens[0]);
            args.push(tokens.length >= 1 ? tokens[1] : '0');
            args.push(nowDate);
            if (j != users.length - 1) sql += ", ";
            log.info("saveParticipantsToMysql:[args] = " + args);
            sql += " select '"+sessionId+"' session_id,'"+tokens[0]+"' participant_id,"+(tokens.length >= 1 ? tokens[1] : '0')+"" +
                " participant_role,now() last_fetch_time from dual ";
            if(j<(users.length-1)){
                sql += " union all ";
            }
        }
        sql += " ON DUPLICATE KEY UPDATE participant_role = VALUES(participant_role)";
        sql += " ) t2 on (t1.session_id=t2.session_id and t1.participant_id=t2.participant_id) "+
            " WHEN MATCHED THEN update set t1.participant_role = t2.participant_role " +
            " WHEN NOT MATCHED THEN INSERT (session_id,participant_id,participant_role,last_fetch_time) VALUES " +
            " (t2.session_id,t2.participant_id,t2.participant_role,t2.last_fetch_time)";
        log.info("saveParticipantsToMysql:[sql] = " + sql);
        ImDb.execQuery({
            "sql": sql,
            "args": args,
            "args": [],
            "handler": handler
        });
    }
@ -308,7 +312,7 @@ class ParticipantRepo {
    }
    static findLastFetchTime(sessionId,userId,handler){
        let sql = "select last_fetch_time from participants p where p.session_id = ? and p.participant_id=?";
        let sql = "select last_fetch_time as \"last_fetch_time\" from participants p where p.session_id = ? and p.participant_id=?";
        ImDb.execQuery({
            "sql": sql,
            "args": [sessionId,userId],

+ 4 - 14
src/server/repository/mysql/patient.repo.js

@ -16,14 +16,14 @@ class PatientRepo {
    static findOne(patientId, handler){
        ImDb.execQuery({
            "sql": "select id, name, sex, birthdate, avatar, openid, idcard,mobile from patients where id = ? ",
            "sql": "select id as \"id\", name as \"name\", sex as \"sex\", birthdate as \"birthdate\", avatar as \"avatar\", openid as \"openid\", idcard as \"idcard\",mobile as \"mobile\" from patients where id = ? ",
            "args": [patientId],
            "handler": handler
        });
    }
    static findWechatOpenId(code, handler) {
        var sql = "select openid from patients where id = ? ";
        var sql = "select openid as \"openid\" from patients where id = ? ";
        ImDb.execQuery({
            "sql": sql,
@ -38,10 +38,10 @@ class PatientRepo {
     * @param handler
     */
    static findWechatOpenIds(code, handler){
        var sql = "SELECT m.family_member code,p.name,p.openid from wlyy.wlyy_patient p,wlyy.wlyy_patient_family_member m" +
        var sql = "SELECT m.family_member as \"code\",p.name as \"name\",p.openid as \"openid\" from wlyy.wlyy_patient p,wlyy.wlyy_patient_family_member m" +
            "  WHERE m.patient = ? and m.family_member=p.code and p.openid is not null and m.is_authorize = 1 " +
            " UNION ALL" +
            "  SELECT p.code,p.name,p.openid  from wlyy.wlyy_patient p WHERE p.code = ?";
            "  SELECT p.code as \"code\",p.name as \"name\",p.openid as \"openid\"  from wlyy.wlyy_patient p WHERE p.code = ?";
        ImDb.execQuery({
            "sql": sql,
            "args": [code,code],
@ -49,16 +49,6 @@ class PatientRepo {
        });
    }
    // TODO: 不能直接访问三师库
    static getPatientDoctorConsult(patient, doctor, handler) {
        var sql = "select * from wlyy_consult_team where patient = ? and doctor = ? and status = 0 and del = '1' ";
        ImDb.execQuery({
            "sql": sql,
            "args": [patient, doctor],
            "handler": handler
        });
    };
}
module.exports = PatientRepo;

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

@ -18,11 +18,11 @@ class SearchRepo {
     * @param handler
     */
    static findTopicEndedSessionIdList(userId, handler) {
        let sql = "SELECT s.id " +
        let sql = "SELECT s.id as \"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) " +
            " UNION " +
            "SELECT s.id " +
            "SELECT s.id as \"id\" " +
            "FROM sessions s, participants p " +
            "WHERE p.participant_id = ? AND p.session_id = s.id AND s.`type` IN (2, 3, 4)";
@ -40,11 +40,11 @@ class SearchRepo {
     * @param handler
     */
    static findTopicActiveSessionIdList(userId, handler) {
        let sql = "SELECT s.id " +
        let sql = "SELECT s.id as \"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) " +
            " UNION " +
            "SELECT s.id " +
            "SELECT s.id as \"id\" " +
            "FROM sessions s, participants p " +
            "WHERE p.participant_id = ? AND p.session_id = s.id  AND s.`type` IN (2,3,4)  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  " +
@ -110,7 +110,8 @@ class SearchRepo {
     * @param handler
     */
    static searchUser(sessionIdList,userId, keyword, userTable, page, size, handler) {
        let sql = "SELECT DISTINCT u.name user_name,s.id session_id, s.name session_name, s.type session_type, s.business_type, u.id user_id,u.sex, u.birthdate, u.avatar,u.idcard %s " +
        let sql = "SELECT DISTINCT u.name \"user_name\",s.id \"session_id\", s.name \"session_name\", s.type \"session_type\"," +
            " s.business_type as \"business_type\", u.id \"user_id\",u.sex as \"sex\", u.birthdate as \"birthdate\", u.avatar as \"avatar\",u.idcard %s " +
            " FROM  participants p, " + userTable +
            " 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 ?) ";

+ 80 - 23
src/server/repository/mysql/session.repo.js

@ -22,7 +22,10 @@ class SessionRepo {
     * @param handler
     */
    static findOne(sessionId, handler) {
        let sessionSQL = "select id,name,type,create_date,business_type,status,last_message_time,last_content,last_content_type,last_sender_id,last_sender_name from " + DB_TABLES.Sessions + " s where s.id = ?";
        //let sessionSQL = "select id,name,type,create_date,business_type,status,last_message_time,last_content,last_content_type,last_sender_id,last_sender_name from " + DB_TABLES.Sessions + " s where s.id = ?";
        let sessionSQL = "SELECT s.\"ID\" AS \"id\",s.\"NAME\" AS \"name\",s.\"TYPE\" AS \"type\",s.\"CREATE_DATE\" AS \"create_date\",s.\"BUSINESS_TYPE\" as \"business_type\"," +
            "s.status as \"status\",s.last_message_time as \"last_message_time\",s.last_content as \"last_content\",s.last_content_type as \"last_content_type\",s.last_sender_id as \"last_sender_id\"," +
            "s.last_sender_name as \"last_sender_name\" FROM " + DB_TABLES.Sessions + " s WHERE s.id = :ID";
        ImDb.execQuery({
            "sql": sessionSQL,
            "args": [sessionId],
@ -61,7 +64,10 @@ class SessionRepo {
    static findUnEndAll(userId, handler) {
        let sql = "select session_id from " + DB_TABLES.Participants + " w where w.participant_id = ? and participant_role in(0,1)  group by w.session_id";
        let sys_session = "select session_id from " + DB_TABLES.Participants + " w where w.participant_id = 'system' and participant_role in(0,1)  group by w.session_id";
        let sessionSQL = "select id, name, type, create_date,business_type, last_sender_id, last_sender_name, last_content_type, last_content, last_message_time,status from "
        // let sessionSQL = "select id, name, type, create_date,business_type, last_sender_id, last_sender_name, last_content_type, last_content, last_message_time,status from "
        let sessionSQL = "select s.\"ID\" AS \"id\",s.\"NAME\" AS \"name\",s.\"TYPE\" AS \"type\",s.\"CREATE_DATE\" AS \"create_date\",s.\"BUSINESS_TYPE\" as \"business_type\"," +
            "s.status as \"status\",s.last_message_time as \"last_message_time\",s.last_content as \"last_content\",s.last_content_type as \"last_content_type\",s.last_sender_id as \"last_sender_id\"," +
            "s.last_sender_name as \"last_sender_name\"  from "
            + DB_TABLES.Sessions + " s where s.id in(" + sql + ") and s.id not in ("+sys_session+") and s.`status` = 0";
        ImDb.execQuery({
            "sql": sessionSQL,
@ -82,7 +88,10 @@ class SessionRepo {
    static findAllIgnoreRole(userId, handler) {
        let sql = "select session_id from " + DB_TABLES.Participants + " w where w.participant_id = ?  group by w.session_id";
        let sys_session = "select session_id from " + DB_TABLES.Participants + " w where w.participant_id = 'system' and participant_role =0  group by w.session_id";
        let sessionSQL = "select id, name, type, create_date,business_type, last_sender_id, last_sender_name, last_content_type, last_content, last_message_time,status from "
       // let sessionSQL = "select id, name, type, create_date,business_type, last_sender_id, last_sender_name, last_content_type, last_content, last_message_time,status from "
        let sessionSQL = "select s.\"ID\" AS \"id\",s.\"NAME\" AS \"name\",s.\"TYPE\" AS \"type\",s.\"CREATE_DATE\" AS \"create_date\",s.\"BUSINESS_TYPE\" as \"business_type\"," +
            "s.status as \"status\",s.last_message_time as \"last_message_time\",s.last_content as \"last_content\",s.last_content_type as \"last_content_type\",s.last_sender_id as \"last_sender_id\"," +
            "s.last_sender_name as \"last_sender_name\"  from "
            + DB_TABLES.Sessions + " s where s.id in(" + sql + ") and s.id not in ("+sys_session+")";
        ImDb.execQuery({
            "sql": sessionSQL,
@ -102,7 +111,10 @@ class SessionRepo {
     */
    static findAllByType(userId, type, handler) {
        let sql = "select session_id from " + DB_TABLES.Participants + " w where w.participant_id = ? and type=? group by w.session_id";
        let sessionSQL = "select id, name, type, create_date, last_sender_id, last_sender_name, last_content_type, last_content, last_message_time from "
        // let sessionSQL = "select id, name, type, create_date, last_sender_id, last_sender_name, last_content_type, last_content, last_message_time from "
        let sessionSQL = "select s.\"ID\" AS \"id\",s.\"NAME\" AS \"name\",s.\"TYPE\" AS \"type\",s.\"CREATE_DATE\" AS \"create_date\",s.\"BUSINESS_TYPE\" as \"business_type\"," +
            "s.status as \"status\",s.last_message_time as \"last_message_time\",s.last_content as \"last_content\",s.last_content_type as \"last_content_type\",s.last_sender_id as \"last_sender_id\"," +
            "s.last_sender_name as \"last_sender_name\"  from "
            + DB_TABLES.Sessions + " s where s.id in(" + sql + ") ";
        log.info("获取用户全部会话: sql :" + sql);
        log.info("获取用户全部会话: args :" + args);
@ -124,7 +136,10 @@ class SessionRepo {
     */
    static findAllByTypes(userId, type, handler) {
        let sql = "select session_id from " + DB_TABLES.Participants + " w where w.participant_id = ?  group by w.session_id";
        let sessionSQL = "select id, name, type, create_date, last_sender_id, last_sender_name, last_content_type, last_content, last_message_time from "
        // let sessionSQL = "select id, name, type, create_date, last_sender_id, last_sender_name, last_content_type, last_content, last_message_time from "
        let sessionSQL = "select s.\"ID\" AS \"id\",s.\"NAME\" AS \"name\",s.\"TYPE\" AS \"type\",s.\"CREATE_DATE\" AS \"create_date\",s.\"BUSINESS_TYPE\" as \"business_type\"," +
            "s.status as \"status\",s.last_message_time as \"last_message_time\",s.last_content as \"last_content\",s.last_content_type as \"last_content_type\",s.last_sender_id as \"last_sender_id\"," +
            "s.last_sender_name as \"last_sender_name\"  from "
            + DB_TABLES.Sessions + " s where s.id in(" + sql + ")  AND s.status = 0 ";
        log.info("获取用户全部会话: sql :" + sessionSQL);
        if(type){
@ -197,7 +212,10 @@ class SessionRepo {
        }
        sql +=" group by w.session_id ";
        let sessionSQL = "select id, name, type, create_date, last_sender_id, last_sender_name, last_content_type, last_content, last_message_time from "
        // let sessionSQL = "select id, name, type, create_date, last_sender_id, last_sender_name, last_content_type, last_content, last_message_time from "
        let sessionSQL = "select s.\"ID\" AS \"id\",s.\"NAME\" AS \"name\",s.\"TYPE\" AS \"type\",s.\"CREATE_DATE\" AS \"create_date\",s.\"BUSINESS_TYPE\" as \"business_type\"," +
            "s.status as \"status\",s.last_message_time as \"last_message_time\",s.last_content as \"last_content\",s.last_content_type as \"last_content_type\",s.last_sender_id as \"last_sender_id\"," +
            "s.last_sender_name as \"last_sender_name\"  from "
            + DB_TABLES.Sessions + " s where s.id in(" + sql + ") and s.type in("+type+") ";
        if(status != null && status != ""){
@ -236,7 +254,10 @@ class SessionRepo {
        }
        let sql = "select session_id from " + DB_TABLES.Participants + " w where w.participant_role <>0 group by w.session_id";
        let sessionSQL = "select id, name, type, create_date, last_sender_id, last_sender_name, last_content_type, last_content, last_message_time from "
        // let sessionSQL = "select id, name, type, create_date, last_sender_id, last_sender_name, last_content_type, last_content, last_message_time from "
        let sessionSQL = "select s.\"ID\" AS \"id\",s.\"NAME\" AS \"name\",s.\"TYPE\" AS \"type\",s.\"CREATE_DATE\" AS \"create_date\",s.\"BUSINESS_TYPE\" as \"business_type\"," +
            "s.status as \"status\",s.last_message_time as \"last_message_time\",s.last_content as \"last_content\",s.last_content_type as \"last_content_type\",s.last_sender_id as \"last_sender_id\"," +
            "s.last_sender_name as \"last_sender_name\"  from "
            + DB_TABLES.Sessions + " s where s.id not in(" + sql + ") and s.type in("+type+") ";
        if(status != null && status != ""){
@ -270,7 +291,10 @@ class SessionRepo {
                sql = "select session_id from " + DB_TABLES.Participants + " w where w.participant_id = ?  group by w.session_id";
                //找出角色讨论组中为旁听且未结束的咨询
                let sql1 = ("select session_id from " + DB_TABLES.Participants + " w where w.participant_id = ? and participant_role ="+PARTICIPANT_ROLES.REGULAR+" group by w.session_id")
                sessionSQL =  "select s.* from " + DB_TABLES.Sessions + " s, " + DB_TABLES.Participants + " p " +
                // sessionSQL =  "select s.* from " + DB_TABLES.Sessions + " s, " + DB_TABLES.Participants + " p " +
                sessionSQL =  "select s.\"ID\" AS \"id\",s.\"NAME\" AS \"name\",s.\"TYPE\" AS \"type\",s.\"CREATE_DATE\" AS \"create_date\",s.\"BUSINESS_TYPE\" as \"business_type\"," +
                    "s.status as \"status\",s.last_message_time as \"last_message_time\",s.last_content as \"last_content\",s.last_content_type as \"last_content_type\",s.last_sender_id as \"last_sender_id\"," +
                    "s.last_sender_name as \"last_sender_name\"  from " + DB_TABLES.Sessions + " s, " + DB_TABLES.Participants + " p " +
                    " where ((s.id in(" + sql + ") and s.business_type = ? and s.status = 1) or (s.id in(" + sql1 + ") and s.business_type = ? and s.status = 0)) " +
                    // " and s.id = p.session_id and p.participant_id = ? ORDER BY (p.last_fetch_time - s.last_message_time+1)>0,s.create_date desc limit "+page+","+pagesize;
                    " and s.id = p.session_id and p.participant_id = ? ORDER BY s.last_message_time desc limit "+page+","+pagesize;
@ -286,7 +310,10 @@ class SessionRepo {
                sql = "select session_id from " + DB_TABLES.Participants + " w where w.participant_id = ?  group by w.session_id";
                //找出角色讨论组中为旁听且未结束的咨询
                let sql1 = ("select session_id from " + DB_TABLES.Participants + " w where w.participant_id = ? and participant_role ="+PARTICIPANT_ROLES.REGULAR+" group by w.session_id")
                sessionSQL =  "select * from "
                // sessionSQL =  "select * from "
                sessionSQL =  "select s.\"ID\" AS \"id\",s.\"NAME\" AS \"name\",s.\"TYPE\" AS \"type\",s.\"CREATE_DATE\" AS \"create_date\",s.\"BUSINESS_TYPE\" as \"business_type\"," +
                    "s.status as \"status\",s.last_message_time as \"last_message_time\",s.last_content as \"last_content\",s.last_content_type as \"last_content_type\",s.last_sender_id as \"last_sender_id\"," +
                    "s.last_sender_name as \"last_sender_name\"  from "
                    + DB_TABLES.Sessions + " s where (s.id in(" + sql + ") and s.business_type = ? and s.status = 1) or (s.id in(" + sql1 + ") and s.business_type = ? and s.status = 0)  limit "+page+","+pagesize;
                log.info("findAllByTypeAndStatus: sql " + sessionSQL);
                log.info("findAllByTypeAndStatus: args " + [userId, businessType,userId,businessType]);
@ -302,7 +329,10 @@ class SessionRepo {
        }else{
            sql = "select session_id from " + DB_TABLES.Participants + " w where w.participant_id = ? and participant_role ="+PARTICIPANT_ROLES.HOST+" group by w.session_id";
            sessionSQL =  "select * from "
            // sessionSQL =  "select * from "
            sessionSQL =  "select s.\"ID\" AS \"id\",s.\"NAME\" AS \"name\",s.\"TYPE\" AS \"type\",s.\"CREATE_DATE\" AS \"create_date\",s.\"BUSINESS_TYPE\" as \"business_type\"," +
                "s.status as \"status\",s.last_message_time as \"last_message_time\",s.last_content as \"last_content\",s.last_content_type as \"last_content_type\",s.last_sender_id as \"last_sender_id\"," +
                "s.last_sender_name as \"last_sender_name\"  from "
                + DB_TABLES.Sessions + " s where s.id in(" + sql + ") and s.business_type in (?) and s.status = ? limit "+page+","+pagesize;
            log.info("findAllByTypeAndStatus: sql : "+sessionSQL);
            log.info("findAllByTypeAndStatus: args : "+[userId, businessType,status]);
@ -326,7 +356,10 @@ class SessionRepo {
                sql = "select session_id from " + DB_TABLES.Participants + " w where w.participant_id = ?  group by w.session_id";
                //找出角色讨论组中为旁听且未结束的咨询
                let sql1 = ("select session_id from " + DB_TABLES.Participants + " w where w.participant_id = ? and participant_role ="+PARTICIPANT_ROLES.REGULAR+" group by w.session_id")
                sessionSQL =  "select s.* from " + DB_TABLES.Sessions + " s, " + DB_TABLES.Participants + " p " +
                // sessionSQL =  "select s.* from " + DB_TABLES.Sessions + " s, " + DB_TABLES.Participants + " p " +
                sessionSQL =  "select s.\"ID\" AS \"id\",s.\"NAME\" AS \"name\",s.\"TYPE\" AS \"type\",s.\"CREATE_DATE\" AS \"create_date\",s.\"BUSINESS_TYPE\" as \"business_type\"," +
                    "s.status as \"status\",s.last_message_time as \"last_message_time\",s.last_content as \"last_content\",s.last_content_type as \"last_content_type\",s.last_sender_id as \"last_sender_id\"," +
                    "s.last_sender_name as \"last_sender_name\"  from " + DB_TABLES.Sessions + " s, " + DB_TABLES.Participants + " p " +
                    " where ((s.id in(" + sql + ") and s.business_type = ? and s.status = 1) or (s.id in(" + sql1 + ") and s.business_type = ? and s.status = 0)) " +
                    // " and s.id = p.session_id and p.participant_id = ? ORDER BY (p.last_fetch_time - s.last_message_time+1)>0,s.create_date desc limit "+page+","+pagesize;
                    " and s.id = p.session_id and p.participant_id = ? ORDER BY s.last_message_time desc ";
@ -342,7 +375,10 @@ class SessionRepo {
                sql = "select session_id from " + DB_TABLES.Participants + " w where w.participant_id = ?  group by w.session_id";
                //找出角色讨论组中为旁听且未结束的咨询
                let sql1 = ("select session_id from " + DB_TABLES.Participants + " w where w.participant_id = ? and participant_role ="+PARTICIPANT_ROLES.REGULAR+" group by w.session_id")
                sessionSQL =  "select * from "
                // sessionSQL =  "select * from "
                sessionSQL =  "select s.\"ID\" AS \"id\",s.\"NAME\" AS \"name\",s.\"TYPE\" AS \"type\",s.\"CREATE_DATE\" AS \"create_date\",s.\"BUSINESS_TYPE\" as \"business_type\"," +
                    "s.status as \"status\",s.last_message_time as \"last_message_time\",s.last_content as \"last_content\",s.last_content_type as \"last_content_type\",s.last_sender_id as \"last_sender_id\"," +
                    "s.last_sender_name as \"last_sender_name\"  from "
                    + DB_TABLES.Sessions + " s where (s.id in(" + sql + ") and s.business_type = ? and s.status = 1) or (s.id in(" + sql1 + ") and s.business_type = ? and s.status = 0)  ";
                log.info("findAllByTypeAndStatus: sql " + sessionSQL);
                log.info("findAllByTypeAndStatus: args " + [userId, businessType,userId,businessType]);
@ -358,7 +394,10 @@ class SessionRepo {
        }else{
            sql = "select session_id from " + DB_TABLES.Participants + " w where w.participant_id = ? and participant_role ="+PARTICIPANT_ROLES.HOST+" group by w.session_id";
            sessionSQL =  "select * from "
            // sessionSQL =  "select * from "
            sessionSQL =  "select s.\"ID\" AS \"id\",s.\"NAME\" AS \"name\",s.\"TYPE\" AS \"type\",s.\"CREATE_DATE\" AS \"create_date\",s.\"BUSINESS_TYPE\" as \"business_type\"," +
                "s.status as \"status\",s.last_message_time as \"last_message_time\",s.last_content as \"last_content\",s.last_content_type as \"last_content_type\",s.last_sender_id as \"last_sender_id\"," +
                "s.last_sender_name as \"last_sender_name\"  from "
                + DB_TABLES.Sessions + " s where s.id in(" + sql + ") and s.business_type in (?) and s.status = ? ";
            log.info("findAllByTypeAndStatus: sql : "+sessionSQL);
            log.info("findAllByTypeAndStatus: args : "+[userId, businessType,status]);
@ -382,7 +421,10 @@ class SessionRepo {
                sql = "select session_id from " + DB_TABLES.Participants + " w where w.participant_id = ?  group by w.session_id";
                //找出角色讨论组中为旁听且未结束的咨询
                let sql1 = ("select session_id from " + DB_TABLES.Participants + " w where w.participant_id = ? and participant_role ="+PARTICIPANT_ROLES.REGULAR+" group by w.session_id")
                sessionSQL =  "select s.* from " + DB_TABLES.Sessions + " s, " + DB_TABLES.Participants + " p " +
                // sessionSQL =  "select s.* from " + DB_TABLES.Sessions + " s, " + DB_TABLES.Participants + " p " +
                sessionSQL =  "select s.\"ID\" AS \"id\",s.\"NAME\" AS \"name\",s.\"TYPE\" AS \"type\",s.\"CREATE_DATE\" AS \"create_date\",s.\"BUSINESS_TYPE\" as \"business_type\"," +
                    "s.status as \"status\",s.last_message_time as \"last_message_time\",s.last_content as \"last_content\",s.last_content_type as \"last_content_type\",s.last_sender_id as \"last_sender_id\"," +
                    "s.last_sender_name as \"last_sender_name\"  from " + DB_TABLES.Sessions + " s, " + DB_TABLES.Participants + " p " +
                    " where ((s.id in(" + sql + ") and s.business_type = ? and s.status = 1) or (s.id in(" + sql1 + ") and s.business_type = ? and s.status = 0)) " +
                    // " and s.id = p.session_id and p.participant_id = ? ORDER BY (p.last_fetch_time - s.last_message_time+1)>0,s.create_date desc limit "+page+","+pagesize;
                    " and s.id = p.session_id and p.participant_id = ? ORDER BY s.last_message_time desc ";
@ -398,7 +440,10 @@ class SessionRepo {
                sql = "select session_id from " + DB_TABLES.Participants + " w where w.participant_id = ?  group by w.session_id";
                //找出角色讨论组中为旁听且未结束的咨询
                let sql1 = ("select session_id from " + DB_TABLES.Participants + " w where w.participant_id = ? and participant_role ="+PARTICIPANT_ROLES.REGULAR+" group by w.session_id")
                sessionSQL =  "select * from "
                // sessionSQL =  "select * from "
                sessionSQL =  "select s.\"ID\" AS \"id\",s.\"NAME\" AS \"name\",s.\"TYPE\" AS \"type\",s.\"CREATE_DATE\" AS \"create_date\",s.\"BUSINESS_TYPE\" as \"business_type\"," +
                    "s.status as \"status\",s.last_message_time as \"last_message_time\",s.last_content as \"last_content\",s.last_content_type as \"last_content_type\",s.last_sender_id as \"last_sender_id\"," +
                    "s.last_sender_name as \"last_sender_name\"  from "
                    + DB_TABLES.Sessions + " s where (s.id in(" + sql + ") and s.business_type = ? and s.status = 1) or (s.id in(" + sql1 + ") and s.business_type = ? and s.status = 0)  ";
                log.info("findAllByTypeAndStatus: sql " + sessionSQL);
                log.info("findAllByTypeAndStatus: args " + [userId, businessType,userId,businessType]);
@ -414,7 +459,10 @@ class SessionRepo {
        }else{
            sql = "select session_id from " + DB_TABLES.Participants + " w where w.participant_id = ? and participant_role ="+PARTICIPANT_ROLES.HOST+" group by w.session_id";
            sessionSQL =  "select * from "
            // sessionSQL =  "select * from "
            sessionSQL =  "select s.\"ID\" AS \"id\",s.\"NAME\" AS \"name\",s.\"TYPE\" AS \"type\",s.\"CREATE_DATE\" AS \"create_date\",s.\"BUSINESS_TYPE\" as \"business_type\"," +
                "s.status as \"status\",s.last_message_time as \"last_message_time\",s.last_content as \"last_content\",s.last_content_type as \"last_content_type\",s.last_sender_id as \"last_sender_id\"," +
                "s.last_sender_name as \"last_sender_name\"  from "
                + DB_TABLES.Sessions + " s where s.id in(" + sql + ") and s.business_type in (?) ";
            log.info("findAllByTypeAndStatus: sql : "+sessionSQL);
            log.info("findAllByTypeAndStatus: args : "+[userId, businessType]);
@ -445,7 +493,10 @@ class SessionRepo {
            //sql = "select session_id from " + DB_TABLES.Participants + " w where w.participant_id = ? and participant_role ="+PARTICIPANT_ROLES.HOST+" group by w.session_id";
            //中山医院无法查询到所有会话记录,暂时取消participant_role的判断条件 20190619
            sql = "select session_id from " + DB_TABLES.Participants + " w where w.participant_id = ? group by w.session_id";
            sessionSQL =  "select * from "
            // sessionSQL =  "select * from "
            sessionSQL =  "select s.\"ID\" AS \"id\",s.\"NAME\" AS \"name\",s.\"TYPE\" AS \"type\",s.\"CREATE_DATE\" AS \"create_date\",s.\"BUSINESS_TYPE\" as \"business_type\"," +
                "s.status as \"status\",s.last_message_time as \"last_message_time\",s.last_content as \"last_content\",s.last_content_type as \"last_content_type\",s.last_sender_id as \"last_sender_id\"," +
                "s.last_sender_name as \"last_sender_name\"  from "
                + DB_TABLES.Sessions + " s where s.id in(" + sql + ") and s.business_type = ? and s.type!=0 order by s.last_message_time desc limit "+page+","+pagesize;
            ImDb.execQuery({
                "sql": sessionSQL,
@ -460,7 +511,10 @@ class SessionRepo {
            //sql = "select session_id from " + DB_TABLES.Participants + " w where w.participant_id = ? and participant_role ="+PARTICIPANT_ROLES.HOST+" group by w.session_id";
            //中山医院无法查询到所有会话记录,暂时取消participant_role的判断条件 20190619
            sql = "select session_id from " + DB_TABLES.Participants + " w where w.participant_id = ? group by w.session_id";
            sessionSQL =  "select * from "
            // sessionSQL =  "select * from "
            sessionSQL =  "select s.\"ID\" AS \"id\",s.\"NAME\" AS \"name\",s.\"TYPE\" AS \"type\",s.\"CREATE_DATE\" AS \"create_date\",s.\"BUSINESS_TYPE\" as \"business_type\"," +
                "s.status as \"status\",s.last_message_time as \"last_message_time\",s.last_content as \"last_content\",s.last_content_type as \"last_content_type\",s.last_sender_id as \"last_sender_id\"," +
                "s.last_sender_name as \"last_sender_name\"  from "
                + DB_TABLES.Sessions + " s where s.id in(" + sql + ") and s.type!=0 order by s.last_message_time desc limit "+page+","+pagesize;
            ImDb.execQuery({
                "sql": sessionSQL,
@ -485,7 +539,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 as \"id\", CASE WHEN TYPE = 2 THEN d.name ELSE s.name END \"name\",s.last_content_type as \"last_content_type\", s.type as \"type\", s.create_date as \"create_date\", s.business_type as \"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' " +
@ -511,7 +565,7 @@ class SessionRepo {
     */
    static findStickySessions(userId, handler) {
        let sql = "select session_id from " + DB_TABLES.Participants + " w where w.participant_id = ? group by w.session_id";
        let sessionSQL = "select s.id,s.name,s.type,s.create_date from " + DB_TABLES.Sessions + " s," + DB_TABLES.StickySessions + " ss  where s.id = ss.session_id s.id in(" + sql + ")";
        let sessionSQL = "select s.id as \"id\",s.name as \"name\",s.type as \"type\",s.create_date as \"create_date\" from " + DB_TABLES.Sessions + " s," + DB_TABLES.StickySessions + " ss  where s.id = ss.session_id s.id in(" + sql + ")";
        ImDb.execQuery({
            "sql": sessionSQL,
            "args": [userId],
@ -532,11 +586,14 @@ class SessionRepo {
     * @param handler
     */
    static saveSession(sessionId, name, type, createDate, businessType, handler) {
        let sql = "insert into " + DB_TABLES.Sessions + " (id, name, type, create_date,business_type) VALUES (?,?,?,?,?) " +
            "ON DUPLICATE KEY UPDATE name = ?,type = ?";
        // let sql = "insert into " + DB_TABLES.Sessions + "(id, name, type, create_date,business_type) VALUES (?,?,?,?,?) " +
        //     "ON DUPLICATE KEY UPDATE name = ?,type = ?";
        let sql = "merge into " +DB_TABLES.Sessions+ " t1 using( select ? id,? name,? type from dual) t2 on (t1.id=t2.id) " +
            "WHEN MATCHED THEN update set t1.name = t2.name,t1.type=t2.type " +
            "WHEN NOT MATCHED THEN INSERT (id, name, type, create_date,business_type) VALUES (?,?,?,?,?)"
        ImDb.execQuery({
            "sql": sql,
            "args": [sessionId, name, type, createDate, businessType, name,type],
            "args": [sessionId, name, type,sessionId, name, type, createDate, businessType],
            "handler": handler || function (err, res) {
                if(err) log.error(err);
            }

+ 45 - 28
src/server/repository/mysql/topics.repo.js

@ -19,8 +19,8 @@ class TopicRepo {
     * @param handler
     */
    static findOne(topicId, handler) {
        let sql = "select id, session_id, name, create_time, end_by, end_time," +
            " start_message_id, end_message_id, description, status from " + DB_TABLES.Topics + " where id = ?";
        let sql = "select id as \"id\", session_id as \"session_id\", name as \"name\", create_time as \"create_time\", end_by as \"end_by\", end_time as \"end_time\"," +
            " start_message_id as \"start_message_id\", end_message_id as \"end_message_id\", description as \"description\", status as \"status\" from " + DB_TABLES.Topics + " where id = ?";
        ImDb.execQuery({
            sql: sql,
@ -32,7 +32,7 @@ class TopicRepo {
    }
    static findLastTopicStatus(sessionId, handler) {
        let sql = "select id from " + DB_TABLES.Topics + " where  session_id = ? order by create_time desc limit 0, 1";
        let sql = "select id as \"id\" from " + DB_TABLES.Topics + " where  session_id = ? order by create_time desc limit 0, 1";
        ImDb.execQuery({
            sql: sql,
            args: [sessionId],
@ -47,7 +47,8 @@ class TopicRepo {
    }
    static findLastBySessionId(sessionId, handler) {
        let sql = "select * from " + DB_TABLES.Topics + " where  session_id = ? order by create_time desc limit 0, 1";
        let sql = "select id as \"id\", session_id as \"session_id\", name as \"name\", create_time as \"create_time\", end_by as \"end_by\", end_time as \"end_time\"," +
            " start_message_id as \"start_message_id\", end_message_id as \"end_message_id\", description as \"description\", status as \"status\" from " + DB_TABLES.Topics + " where  session_id = ? order by create_time desc limit 0, 1";
        ImDb.execQuery({
            sql: sql,
            args: [sessionId],
@ -63,13 +64,17 @@ class TopicRepo {
        var args =[];
        if(status==10){
            args.push(userId,status,page,size);
            sql =  "SELECT t.*, s.avatar,s.sex,s.birthdate, s.`name` AS patient_name,c.doctor FROM "+
            sql =  "select t.id as \"id\", t.session_id as \"session_id\", t.name as \"name\", t.create_time as \"create_time\", t.end_by as \"end_by\", t.end_time as \"end_time\"," +
                " t.start_message_id as \"start_message_id\", t.end_message_id as \"end_message_id\", t.description as \"description\", t.status as \"status\" , s.avatar as \"avatar\"," +
                "s.sex as \"sex\",s.birthdate as \"birthdate\", s.name AS \"patient_name\",c.doctor as \"doctor\" FROM "+
                  DB_TABLES.Topics+" t,"+DB_TABLES.Participants+" p,"+DB_TABLES.Doctors+" d,"+DB_TABLES.WlyyConsult+" c,"+DB_TABLES.Patients+" s "+
                  "WHERE d.id = p.participant_id AND c.id = t.id AND c.patient = s.id AND p.session_id = t.session_id "+
                  "AND d.id in (?) AND t. STATUS = ? ORDER BY create_time DESC limit ?,?";
        }else{
            args.push(userId,status,reply,page,size);
            sql =  "SELECT t.*, s.avatar,s.sex,s.birthdate, s.`name` AS patient_name,c.doctor FROM "+
            sql =  "select t.id as \"id\", t.session_id as \"session_id\", t.name as \"name\", t.create_time as \"create_time\", t.end_by as \"end_by\", t.end_time as \"end_time\"," +
                " t.start_message_id as \"start_message_id\", t.end_message_id as \"end_message_id\", t.description as \"description\", t.status as \"status\" , s.avatar as \"avatar\"," +
                "s.sex as \"sex\",s.birthdate as \"birthdate\", s.name AS \"patient_name\",c.doctor as \"doctor\" FROM "+
                DB_TABLES.Topics+" t,"+DB_TABLES.Participants+" p,"+DB_TABLES.Doctors+" d,"+DB_TABLES.WlyyConsult+" c,"+DB_TABLES.Patients+" s "+
                "WHERE d.id = p.participant_id AND c.id = t.id AND c.patient = s.id AND p.session_id = t.session_id "+
                "AND d.id in (?) AND t. STATUS = ? and t.reply=? ORDER BY create_time DESC limit ?,?";
@ -97,13 +102,17 @@ class TopicRepo {
        var args =[];
        if(status==10){
            args.push(userId,status,page,size);
            sql =  "SELECT t.*, s.avatar,s.sex,s.birthdate, s.`name` AS patient_name,c.doctor FROM "+
            sql =  "select t.id as \"id\", t.session_id as \"session_id\", t.name as \"name\", t.create_time as \"create_time\", t.end_by as \"end_by\", t.end_time as \"end_time\"," +
                " t.start_message_id as \"start_message_id\", t.end_message_id as \"end_message_id\", t.description as \"description\", t.status as \"status\" , s.avatar as \"avatar\"," +
                "s.sex as \"sex\",s.birthdate as \"birthdate\", s.name AS \"patient_name\",c.doctor as \"doctor\" FROM "+
                DB_TABLES.Topics+" t,"+DB_TABLES.Participants+" p,"+DB_TABLES.Doctors+" d,"+DB_TABLES.WlyyConsult+" c,"+DB_TABLES.Patients+" s "+
                "WHERE d.id = p.participant_id AND c.id = t.id AND c.patient = s.id AND p.session_id = t.session_id "+
                "AND d.id in (?) AND t. STATUS = ? AND c.type not in ('6','8') ORDER BY create_time DESC limit ?,?";
        }else{
            args.push(userId,status,reply,page,size);
            sql =  "SELECT t.*, s.avatar,s.sex,s.birthdate, s.`name` AS patient_name,c.doctor FROM "+
            sql =  "select t.id as \"id\", t.session_id as \"session_id\", t.name as \"name\", t.create_time as \"create_time\", t.end_by as \"end_by\", t.end_time as \"end_time\"," +
                " t.start_message_id as \"start_message_id\", t.end_message_id as \"end_message_id\", t.description as \"description\", t.status as \"status\" , s.avatar as \"avatar\"," +
                "s.sex as \"sex\",s.birthdate as \"birthdate\", s.name AS \"patient_name\",c.doctor as \"doctor\" FROM "+
                DB_TABLES.Topics+" t,"+DB_TABLES.Participants+" p,"+DB_TABLES.Doctors+" d,"+DB_TABLES.WlyyConsult+" c,"+DB_TABLES.Patients+" s "+
                "WHERE d.id = p.participant_id AND c.id = t.id AND c.patient = s.id AND p.session_id = t.session_id "+
                "AND d.id in (?) AND t. STATUS = ? and t.reply=? AND c.type not in ('6','8') ORDER BY create_time DESC limit ?,?";
@ -142,13 +151,17 @@ class TopicRepo {
        }
        if(status==10){
            args.push(userId,status,type,page,size);
            sql =  "SELECT t.*, s.avatar,s.sex,s.birthdate, s.`name` AS patient_name,c.doctor FROM "+
            sql =  "select t.id as \"id\", t.session_id as \"session_id\", t.name as \"name\", t.create_time as \"create_time\", t.end_by as \"end_by\", t.end_time as \"end_time\"," +
                " t.start_message_id as \"start_message_id\", t.end_message_id as \"end_message_id\", t.description as \"description\", t.status as \"status\" , s.avatar as \"avatar\"," +
                "s.sex as \"sex\",s.birthdate as \"birthdate\", s.name AS \"patient_name\",c.doctor as \"doctor\" FROM "+
                DB_TABLES.Topics+" t,"+DB_TABLES.Participants+" p,"+DB_TABLES.Doctors+" d,"+DB_TABLES.WlyyConsult+" c,"+DB_TABLES.Patients+" s "+
                "WHERE d.id = p.participant_id AND c.id = t.id AND c.patient = s.id AND p.session_id = t.session_id "+
                "AND d.id in (?) AND t. STATUS = ? AND c.type =? "+tempParms+" ORDER BY create_time DESC limit ?,?";
        }else{
            args.push(userId,status,reply,type,page,size);
            sql =  "SELECT t.*, s.avatar,s.sex,s.birthdate, s.`name` AS patient_name,c.doctor FROM "+
            sql =  "select t.id as \"id\", t.session_id as \"session_id\", t.name as \"name\", t.create_time as \"create_time\", t.end_by as \"end_by\", t.end_time as \"end_time\"," +
                " t.start_message_id as \"start_message_id\", t.end_message_id as \"end_message_id\", t.description as \"description\", t.status as \"status\" , s.avatar as \"avatar\"," +
                "s.sex as \"sex\",s.birthdate as \"birthdate\", s.name AS \"patient_name\",c.doctor as \"doctor\" FROM "+
                DB_TABLES.Topics+" t,"+DB_TABLES.Participants+" p,"+DB_TABLES.Doctors+" d,"+DB_TABLES.WlyyConsult+" c,"+DB_TABLES.Patients+" s "+
                "WHERE d.id = p.participant_id AND c.id = t.id AND c.patient = s.id AND p.session_id = t.session_id "+
                "AND d.id in (?) AND t. STATUS = ? and t.reply=? AND c.type = ? "+tempParms+" ORDER BY create_time DESC limit ?,?";
@ -185,13 +198,13 @@ class TopicRepo {
        }
        if(status==10){
            args.push(userId,status,type);
            sql =  "SELECT count(t.id) count FROM "+
            sql =  "SELECT count(t.id) as \"count\" FROM "+
                DB_TABLES.Topics+" t,"+DB_TABLES.Participants+" p,"+DB_TABLES.Doctors+" d,"+DB_TABLES.WlyyConsult+" c,"+DB_TABLES.Patients+" s "+
                "WHERE d.id = p.participant_id AND c.id = t.id AND c.patient = s.id AND p.session_id = t.session_id "+
                "AND d.id in (?) AND t. STATUS = ? AND c.type =? "+tempParms;
        }else{
            args.push(userId,status,reply,type);
            sql =  "SELECT count(t.id) count FROM "+
            sql =  "SELECT count(t.id) as \"count\" FROM "+
                DB_TABLES.Topics+" t,"+DB_TABLES.Participants+" p,"+DB_TABLES.Doctors+" d,"+DB_TABLES.WlyyConsult+" c,"+DB_TABLES.Patients+" s "+
                "WHERE d.id = p.participant_id AND c.id = t.id AND c.patient = s.id AND p.session_id = t.session_id "+
                "AND d.id in (?) AND t. STATUS = ? and t.reply=? AND c.type = ? "+tempParms;
@ -219,13 +232,17 @@ class TopicRepo {
        var args =[];
        if(status==10){
            args.push(adminTeamCode,userId,status,page,size);
            sql =  "SELECT t.*, s.avatar,s.sex,s.birthdate, s.`name` AS patient_name,c.doctor FROM "+
            sql =  "select t.id as \"id\", t.session_id as \"session_id\", t.name as \"name\", t.create_time as \"create_time\", t.end_by as \"end_by\", t.end_time as \"end_time\"," +
                " t.start_message_id as \"start_message_id\", t.end_message_id as \"end_message_id\", t.description as \"description\", t.status as \"status\" , s.avatar as \"avatar\"," +
                "s.sex as \"sex\",s.birthdate as \"birthdate\", s.name AS \"patient_name\",c.doctor as \"doctor\" FROM "+
                DB_TABLES.Topics+" t,"+DB_TABLES.Participants+" p,"+DB_TABLES.Doctors+" d,"+DB_TABLES.WlyyConsultTeam+" c,"+DB_TABLES.Patients+" s "+
                "WHERE d.id = p.participant_id AND c.consult = t.id AND c.patient = s.id AND p.session_id = t.session_id "+
                "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 ?,?";
        }else{
            args.push(adminTeamCode,userId,status,reply,page,size);
            sql =  "SELECT t.*, s.avatar,s.sex,s.birthdate, s.`name` AS patient_name,c.doctor FROM "+
            sql =  "select t.id as \"id\", t.session_id as \"session_id\", t.name as \"name\", t.create_time as \"create_time\", t.end_by as \"end_by\", t.end_time as \"end_time\"," +
                " t.start_message_id as \"start_message_id\", t.end_message_id as \"end_message_id\", t.description as \"description\", t.status as \"status\" , s.avatar as \"avatar\"," +
                "s.sex as \"sex\",s.birthdate as \"birthdate\", s.name AS \"patient_name\",c.doctor as \"doctor\" FROM "+
                DB_TABLES.Topics+" t,"+DB_TABLES.Participants+" p,"+DB_TABLES.Doctors+" d,"+DB_TABLES.WlyyConsultTeam+" c,"+DB_TABLES.Patients+" s "+
                "WHERE d.id = p.participant_id AND c.consult = t.id AND c.patient = s.id AND p.session_id = t.session_id "+
                "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 ?,?";
@ -244,19 +261,19 @@ class TopicRepo {
        var args =[];
        if(status==10){
            args.push(adminTeamCode,userId,status);
            sql =  "SELECT count(1)  as count FROM "+
            sql =  "SELECT count(1)  as \"count\" FROM "+
                DB_TABLES.Topics+" t,"+DB_TABLES.Participants+" p,"+DB_TABLES.Doctors+" d,"+DB_TABLES.WlyyConsultTeam+" c,"+DB_TABLES.Patients+" s "+
                "WHERE d.id = p.participant_id AND c.consult = t.id AND c.patient = s.id AND p.session_id = t.session_id "+
                "AND c.admin_team_code=? AND c.type!=8 AND d.id in (?) AND t. STATUS = ? ";
        }else if(status){
            args.push(adminTeamCode,userId,status,reply);
            sql =  "SELECT count(1) as count FROM "+
            sql =  "SELECT count(1) as \"count\" FROM "+
                DB_TABLES.Topics+" t,"+DB_TABLES.Participants+" p,"+DB_TABLES.Doctors+" d,"+DB_TABLES.WlyyConsultTeam+" c,"+DB_TABLES.Patients+" s "+
                "WHERE d.id = p.participant_id AND c.consult = t.id AND c.patient = s.id AND p.session_id = t.session_id "+
                "AND c.admin_team_code=? AND c.type!=8 AND d.id in (?) AND t. STATUS = ? and t.reply=? ";
        }else{
            args.push(adminTeamCode,userId);
            sql =  "SELECT count(1) as count FROM "+
            sql =  "SELECT count(1) as \"count\" FROM "+
                DB_TABLES.Topics+" t,"+DB_TABLES.Participants+" p,"+DB_TABLES.Doctors+" d,"+DB_TABLES.WlyyConsultTeam+" c,"+DB_TABLES.Patients+" s "+
                "WHERE d.id = p.participant_id AND c.consult = t.id AND c.patient = s.id AND p.session_id = t.session_id "+
                "AND c.admin_team_code=? AND c.type!=8 AND d.id in (?)";
@ -276,7 +293,7 @@ class TopicRepo {
    }
    static findLastTopicStatusAndType(sessionId, handler) {
        let sql = "select id from " + DB_TABLES.Topics + " where  session_id = ? order by create_time desc limit 0, 1";
        let sql = "select id as \"id\" from " + DB_TABLES.Topics + " where  session_id = ? order by create_time desc limit 0, 1";
        ImDb.execQuery({
            sql: sql,
            args: [sessionId],
@ -292,7 +309,7 @@ class TopicRepo {
    static findTopicStatus(topicId, handler) {
        let sql = "select id, name, description, status,agent from " + DB_TABLES.Topics + " where id = ?";
        let sql = "select id as \"id\", name as \"name\", description as \"description\", status as \"status\",agent as \"agent\" from " + DB_TABLES.Topics + " where id = ?";
        ImDb.execQuery({
            sql: sql,
@ -304,7 +321,7 @@ class TopicRepo {
    }
    static findTopicStatusAndType(topicId, handler) {
        let sql = "select t.id, t.name, t.description, t.status,t.agent,c.type from topics t,base.wlyy_consult c where t.id = ? and t.id = c.id";
        let sql = "select t.id as \"id\", t.name as \"name\", t.description as \"description\", t.status as \"status\",t.agent as \"agent\",c.type as \"type\" from topics t,base.consult_info c where t.id = ? and t.id = c.id";
        ImDb.execQuery({
            sql: sql,
@ -322,8 +339,8 @@ class TopicRepo {
     * @param handler
     */
    static findAllBySessionId(sessionId, handler) {
        let sql = "select id, session_id, name, create_time, end_by, end_time," +
            " start_message_id, end_message_id, description, status from " + DB_TABLES.Topics + " where session_id = ? order by id";
        let sql = "select id as \"id\", session_id as \"session_id\", name as \"name\", create_time as \"create_time\", end_by as \"end_by\", end_time as \"end_time\"," +
            " start_message_id as \"start_message_id\", end_message_id as \"end_message_id\", description as \"description\", status as \"status\" from " + DB_TABLES.Topics + " where session_id = ? order by id";
        ImDb.execQuery({
            sql: sql,
@ -341,8 +358,8 @@ class TopicRepo {
     * @param handler
     */
    static findAllByTopicId(id, handler) {
        let sql = "select id, session_id, name, create_time, end_by, end_time," +
            " start_message_id, end_message_id, description, status from " + DB_TABLES.Topics + " where id = ? order by id";
        let sql = "select id as \"id\", session_id as \"session_id\", name as \"name\", create_time as \"create_time\", end_by as \"end_by\", end_time as \"end_time\"," +
            " start_message_id as \"start_message_id\", end_message_id as \"end_message_id\", description as \"description\", status as \"status\" from " + DB_TABLES.Topics + " where id = ? order by id";
        ImDb.execQuery({
            sql: sql,
@ -354,8 +371,8 @@ class TopicRepo {
    }
    static findAllBySessionIdsAndStatus(sessionIds, status, page, pagesize, handler) {
        let sql = "select id, session_id, name, create_time, end_by, end_time," +
            " 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 ?,? ";
        let sql = "select id as \"id\", session_id as \"session_id\", name as \"name\", create_time as \"create_time\", end_by as \"end_by\", end_time as \"end_time\"," +
            " start_message_id as \"start_message_id\", end_message_id as \"end_message_id\", description as \"description\", status as \"status\" from " + DB_TABLES.Topics + " where session_id in ('" + sessionIds + "') and status in (" + status + ") order by status desc limit ?,? ";
        ImDb.execQuery({
            sql: sql,
            args: [page, pagesize],
@ -463,8 +480,8 @@ class TopicRepo {
     * @param handler
     */
    static findAllBySessionLastActiveTime(timespan, handler) {
        let sql = "SELECT s.id session_id, s.name session_name, s.create_date session_create_time, s.last_message_time, " +
            "t.id topic_id, t.name topic_name, t.create_time topic_create_time, t.start_message_id " +
        let sql = "SELECT s.id \"session_id\", s.name \"session_name\", s.create_date \"session_create_time\", s.last_message_time \"last_message_time\", " +
            "t.id \"topic_id\", t.name \"topic_name\", t.create_time \"topic_create_time\", t.start_message_id \"start_message_id\" " +
            "FROM sessions s, wlyy_consults t " +
            "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) " +
            "AND UNIX_TIMESTAMP(now()) - UNIX_TIMESTAMP(s.last_message_time) > ? " +

+ 3 - 3
src/server/repository/mysql/wechat.token.repo.js

@ -22,7 +22,7 @@ class WeChatTokenRepo {
     */
    static findOne(handler) {
        ImDb.execQuery({
            "sql": "select access_token, expires_in, add_timestamp from wlyy.wx_access_token where acc_id = '"+config.wechatConfig.accId+"' order by add_timestamp desc limit 0, 1"
            "sql": "select access_token, expires_in, add_timestamp from wechat_access_token where acc_id = '"+config.wechatConfig.accId+"' order by add_timestamp desc limit 0, 1"
            , "handler": handler
        });
    };
@ -37,7 +37,7 @@ class WeChatTokenRepo {
     */
    static save(accessToken, expireIn, createTime, handler) {
        ImDb.execQuery({
            "sql": "insert into wlyy.wx_access_token (acc_id,access_token, expires_in, add_timestamp) values ('"+config.wechatConfig.accId+"',?,?,?)"
            "sql": "insert into wechat_access_token (acc_id,access_token, expires_in, add_timestamp) values ('"+config.wechatConfig.accId+"',?,?,?)"
            , "args": [accessToken, expireIn, createTime.getTime()]
            , "handler": handler
        });
@ -55,7 +55,7 @@ class WeChatTokenRepo {
     */
    static saveLog(openid,patient,name,request,response,status,createTime,handler){
        ImDb.execQuery({
            "sql": "insert into wlyy.wlyy_wx_push_log (type,openid, patient,name,request,response,status, create_time) values (3,?,?,?,?,?,?,?)"
            "sql": "insert into wechat_push_log (type,openid, patient,name,request,response,status, create_time) values (3,?,?,?,?,?,?,?)"
            , "args": [openid,patient,name,request,response,status, createTime]
            , "handler": handler
        });