"use strict";(function(){"use strict";var e=0;var t=7;var i=3;var n=require("util");var o=require("events");var c=require("./jsUtil");var r=require("moment");function l(e){o.EventEmitter.call(this);if(false===this instanceof l){return new l(e)}this._createTable(e)}n.inherits(l,o.EventEmitter);l.prototype._createTable=function(e){var t=this;var i="CREATE TABLE IF NOT EXISTS cloud_notice(notice_id VARCHAR(255) PRIMARY KEY, notice_time DATETIME, notice_content NTEXT, isclick BOOLEAN)";console.log("setUpDb cloud_notice sql:",i);t.db=e;t.db.run(i,function(e){if(e){console.log("create cloud_notice table faile: ",e)}else{t._deleteOldNotices()}})};l.prototype._deleteOldNotices=function(e){var i=this;var n=c.getLogStartTime(t);i.db.run("DELETE FROM cloud_notice WHERE notice_time < ?;",[n],function(t){if(t){console.log("delete cloud_notice table old records failed: ",t)}if(e!=undefined){e(t)}})};l.prototype._getNotices=function(e){var t=this;var n="select * from cloud_notice ORDER BY notice_time DESC limit ?";t.db.all(n,[i],function(t,i){if(t!=null){console.log("get cloud_notice table records failed: ",t)}if(e!=undefined){e(t,i)}})};l.prototype._updateNotice=function(e,t,i){var n=this;n.db.run("update cloud_notice set isclick = ? where notice_id = ?",[t?1:0,e],function(e){if(e!=null){console.log("update cloud_notice table record failed: ",e)}if(i!=undefined){i(e)}})};l.prototype._insertNotice=function(e,t){var i=this;var n=[e.notice_id!=undefined?e.notice_id:"",e.notice_time!=undefined?e.notice_time:"",e.notice_content!=undefined?e.notice_content:"",e.isclick!=undefined?e.isclick?1:0:0];i.db.run("INSERT OR REPLACE INTO cloud_notice (notice_id, notice_time, notice_content, isclick) VALUES (?, ?, ?, ?)",n,function(e){if(e!=null){console.log("insert cloud_notice table record failed: ",e)}if(t!=undefined){t(e)}})};l.prototype._getCloudNotice=function(e,t,i){var n=this;var o=t.getUserInfo().sessionId;var l={Cookie:"JSESSIONID="+o};var u={};u.clientVersion=e.version;u.userName=e.userName;c.commonPost("/api/notify/push",u,function(e,t){if(e!=null||t.code!=0||t.list.length==0){i(e,[]);return}var o=t.list[0];var c={};var l={};l.title=o.title;l.content=o.content;c.notice_id=o.id;c.notice_time=r(o.publishTime).format("YYYY-MM-DD HH:mm:ss");c.isclick=0;c.notice_content=JSON.stringify(l);n._deleteOldNotices(function(e){if(e!=null){i(e);return}n._insertNotice(c,function(e){if(e!=null){i(e);return}n._getNotices(function(e,t){i(e,t)})})})},undefined,l)};module.exports=l;(function(){console.log("begin test cloud notice");if(e){var t=require("./deviceLinkMgr");var i=new t;var n=i.getDbInstance();var o=new l(n);o._getCloudNotice(function(e,t){})}})()})();