|
@ -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,
|