Commit d0b7d08a by 蒋勇

d

parent 8b70d15c
var system = require("../../system")
var settings = require("../../../config/settings");
const CtlBase = require("../ctl.base");
const uuidv4 = require('uuid/v4');
class MsgnoticeCtl extends CtlBase {
constructor() {
super(CtlBase.getServiceName(MsgnoticeCtl));
}
/**
* 从socket.io访问
* @param {*} p
* @param {*} msgHandler
*/
async findOnlinesByStr (p, msgHandler) {
let s = p.likestr
if (s && s != "") {
let d = await this.service.findOnlinesByStr(s)
let rtn = d.map((item) => {
return msgHandler.server.uinfos[item]
})
return system.getResult(rtn)
} else {
return system.getResult(null)
}
}
}
module.exports = MsgnoticeCtl;
......@@ -10,8 +10,10 @@ module.exports = (db, DataTypes) => {
},
sender: DataTypes.STRING,
senderId: DataTypes.INTEGER,
fromHeadUrl: DataTypes.STRING,
target: DataTypes.STRING,
targetId: DataTypes.INTEGER,//租户ID
toHeadUrl: DataTypes.STRING,
content: {
type: DataTypes.TEXT('long'),
allowNull: false,
......@@ -19,48 +21,49 @@ module.exports = (db, DataTypes) => {
isRead: {//是否已经读过
type: DataTypes.BOOLEAN,
defaultValue: false,
}
},
companyid: DataTypes.INTEGER,
}, {
paranoid: true,//假的删除
underscored: true,
version: true,
freezeTableName: true,
//freezeTableName: true,
// define the table's name
tableName: 'msghistory',
validate: {
paranoid: true,//假的删除
underscored: true,
version: true,
freezeTableName: true,
//freezeTableName: true,
// define the table's name
tableName: 'msghistory',
validate: {
},
indexes: [
// Create a unique index on email
// {
// unique: true,
// fields: ['email']
// },
//
// // Creates a gin index on data with the jsonb_path_ops operator
// {
// fields: ['data'],
// using: 'gin',
// operator: 'jsonb_path_ops'
// },
//
// // By default index name will be [table]_[fields]
// // Creates a multi column partial index
// {
// name: 'public_by_author',
// fields: ['author', 'status'],
// where: {
// status: 'public'
// }
// },
//
// // A BTREE index with a ordered field
// {
// name: 'title_index',
// method: 'BTREE',
// fields: ['author', {attribute: 'title', collate: 'en_US', order: 'DESC', length: 5}]
// }
]
});
},
indexes: [
// Create a unique index on email
// {
// unique: true,
// fields: ['email']
// },
//
// // Creates a gin index on data with the jsonb_path_ops operator
// {
// fields: ['data'],
// using: 'gin',
// operator: 'jsonb_path_ops'
// },
//
// // By default index name will be [table]_[fields]
// // Creates a multi column partial index
// {
// name: 'public_by_author',
// fields: ['author', 'status'],
// where: {
// status: 'public'
// }
// },
//
// // A BTREE index with a ordered field
// {
// name: 'title_index',
// method: 'BTREE',
// fields: ['author', {attribute: 'title', collate: 'en_US', order: 'DESC', length: 5}]
// }
]
});
}
......@@ -4,51 +4,54 @@ module.exports = (db, DataTypes) => {
return db.define("msgnotice", {
fromuser: DataTypes.STRING,//需要在后台补充
fromId: DataTypes.INTEGER,
fromHeadUrl: DataTypes.STRING,
touser: DataTypes.STRING,//需要在后台补充
toId: DataTypes.INTEGER,
toHeadUrl: DataTypes.STRING,
isAccepted: DataTypes.BOOLEAN,
lastMsgId: DataTypes.INTEGER,
companyid: DataTypes.INTEGER,
}, {
paranoid: true,//假的删除
underscored: true,
version: true,
freezeTableName: true,
//freezeTableName: true,
// define the table's name
tableName: 'msgnotice',
validate: {
paranoid: true,//假的删除
underscored: true,
version: true,
freezeTableName: true,
//freezeTableName: true,
// define the table's name
tableName: 'msgnotice',
validate: {
},
indexes: [
// Create a unique index on email
// {
// unique: true,
// fields: ['email']
// },
//
// // Creates a gin index on data with the jsonb_path_ops operator
// {
// fields: ['data'],
// using: 'gin',
// operator: 'jsonb_path_ops'
// },
//
// // By default index name will be [table]_[fields]
// // Creates a multi column partial index
// {
// name: 'public_by_author',
// fields: ['author', 'status'],
// where: {
// status: 'public'
// }
// },
//
// // A BTREE index with a ordered field
// {
// name: 'title_index',
// method: 'BTREE',
// fields: ['author', {attribute: 'title', collate: 'en_US', order: 'DESC', length: 5}]
// }
]
});
},
indexes: [
// Create a unique index on email
// {
// unique: true,
// fields: ['email']
// },
//
// // Creates a gin index on data with the jsonb_path_ops operator
// {
// fields: ['data'],
// using: 'gin',
// operator: 'jsonb_path_ops'
// },
//
// // By default index name will be [table]_[fields]
// // Creates a multi column partial index
// {
// name: 'public_by_author',
// fields: ['author', 'status'],
// where: {
// status: 'public'
// }
// },
//
// // A BTREE index with a ordered field
// {
// name: 'title_index',
// method: 'BTREE',
// fields: ['author', {attribute: 'title', collate: 'en_US', order: 'DESC', length: 5}]
// }
]
});
}
......@@ -5,12 +5,17 @@ class MsgNoticeService extends ServiceBase {
super(ServiceBase.getDaoName(MsgNoticeService));
this.userDao = system.getObject("db.auth.userDao");
this.msghistoryDao = system.getObject("db.msg.msghistoryDao");
this.redisClient = system.getObject("util.redisClient");
}
getApp(appkey) {
async findOnlinesByStr (str) {
let rtn = await this.redisClient.sscan('_onlines', str + "*")
return rtn
}
getApp (appkey) {
return this.cacheManager["AppCache"].cacheApp(appkey);
}
async getUserList(userId) {
async getUserList (userId) {
var list = await this.dao.model.findAll({
where: {
fromId: userId
......@@ -68,7 +73,7 @@ class MsgNoticeService extends ServiceBase {
item.serviceTypeOneName = t.name;
} else if (t.id == item.serviceTypeTwoId) {
item.serviceTypeTwoName = t.name;
} else {}
} else { }
}
}
}
......@@ -109,7 +114,7 @@ class MsgNoticeService extends ServiceBase {
return rs;
}
async countUnread(userId) {
async countUnread (userId) {
debugger;
var unreadList = await this.userDao.customQuery("SELECT COUNT(1) AS num FROM `msghistory` WHERE isRead = 0 AND targetId = " + userId);
var count = 0;
......
......@@ -137,13 +137,27 @@ class MsgHandler {
const from = msg.from;
const to = msg.to;
const msgContent = msg.content;
var arrs = to.split("¥");
var tochannel = arrs[0] + "¥" + arrs[1];
//发布消息
//持久化消息
var msgH = { msgType: msg.type ? msg.type : "single", sender: msg.from, target: msg.to, content: msg.content };
msgHistoryService.create(msgH).then((m) => {
redisClient.publish(tochannel, JSON.stringify(msg));
//取出当前人的头像,昵称
//如果目标是房间频道
//加入房间的时候,前端需要给出房间名称,需要指定房间默认的logo
// let nickNameFrom = self.server.uinfos[from].nickName
// let headUrlFrom = self.server.uinfos[from].headUrl
// let nickNameTo = self.server.uinfos[to].nickName
// let headUrlTo = self.server.uinfos[to].headUrl
var msgH = {
msgType: msg.type ? msg.type : "single",
senderId: msg.from
sender: msg.nickNameForm,
fromHeadUrl: msg.headUrlFrom,
targetId: msg.to,
target: msg.nickNameTo,
toHeadUrl: msg.headUrlTo,
content: msg.content
};
msgHistoryService.saveMsg(msgH).then((m) => {
redisClient.publish(to, JSON.stringify(msg));
}).catch(e => {
console.log(e);
});
......@@ -155,7 +169,7 @@ class MsgHandler {
var p = null;
var invokeObj = system.getObject("web." + msg.pkgname + "." + msg.cls);
if (invokeObj[msg.method]) {
p = invokeObj[msg.method].apply(invokeObj, [msg.data]);
p = invokeObj[msg.method].apply(invokeObj, [msg.data, self]);
}
p.then(r => {
fn(r);
......
......@@ -48,6 +48,7 @@
"pem-jwk": "^2.0.0",
"pinyin": "^2.8.3",
"qr-image": "^3.2.0",
"redis-scanrx": "^1.0.1",
"request": "^2.88.2",
"sequelize": "^4.37.8",
"sequelize-cli": "^4.1.1",
......@@ -68,4 +69,4 @@
"imagemin-pngquant": "^8.0.0",
"merge-stream": "^2.0.0"
}
}
\ No newline at end of file
}
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment