system.msg.repo.js 1.0 KB

123456789101112131415161718192021222324252627282930
  1. "use strict";
  2. var log = require('../util/log');
  3. var imRepo = require("./database/im.db.js");
  4. exports.save = function(to, contentType, title, summary, content, handler) {
  5. imRepo.execQuery({
  6. "sql": "INSERT INTO msg_system (to_uid,type,title,content,data) VALUES (?,?,?,?,?)",
  7. "args": [to, contentType, title, summary, content],
  8. "handler": handler
  9. });
  10. };
  11. exports.getLastMessageByType = function (userId,type, handler) {
  12. var sql="select m.content as lastContent,m.czrq FROM ydf_message m where m.type in ("+type+") and m.readonly = 1 and m.receiver = ? order by m.czrq desc limit 0,1" ;
  13. imRepo.execQuery({
  14. "sql": sql,
  15. "args": [userId],
  16. "handler": handler
  17. });
  18. };
  19. exports.getMessagesAmountByType = function (userId,type, handler) {
  20. var sql="select count(1) as amount FROM ydf_message m where m.readonly = 1 and m.type in ("+type+") and m.receiver = ? order by m.czrq desc " ;
  21. imRepo.execQuery({
  22. "sql": sql,
  23. "args": [userId],
  24. "handler": handler
  25. });
  26. };