NotifyData.lua 1.8 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970
  1. local NotifyData = class("NotifyData", require("DataBase"))
  2. function NotifyData:ctor()
  3. self._notices = nil;
  4. end
  5. function NotifyData:RegisterNetEvents()
  6. end
  7. function NotifyData:Clear()
  8. self._notices = nil;
  9. end
  10. function NotifyData:Destroy()
  11. if self.Clear then
  12. self:Clear()
  13. end
  14. self:UnRegisterNetEvents()
  15. end
  16. function NotifyData:UnRegisterNetEvents()
  17. end
  18. function NotifyData:GetNoticeList()
  19. if self._notices == nil then
  20. self._notices = {}
  21. local _noticeCfgAll = ManagerContainer.CfgMgr:GetNoticeCfgAll();
  22. for _, _v in pairs(_noticeCfgAll) do
  23. table.insert(self._notices, _v);
  24. end
  25. end
  26. --剔除不能显示的
  27. self:JudgeOutTimeNotice();
  28. --排序
  29. self:SortData();
  30. --设置notice的开启和关闭的状态
  31. for _i = 1, #self._notices do
  32. self._notices[_i]._showing = _i == 1; --默认第一个开启
  33. end
  34. return self._notices;
  35. end
  36. --数据排序
  37. function NotifyData:SortData()
  38. if self._notices and #self._notices then
  39. table.sort(self._notices, function (_a, _b)
  40. return (_a.NoticOrder < _b.NoticOrder) or (_a.NoticOrder == _b.NoticOrder and _a._newAdd and (not _b._newAdd));
  41. end)
  42. end
  43. end
  44. --剔除不能显示得公告
  45. function NotifyData:JudgeOutTimeNotice()
  46. for _i = #self._notices, 1, -1 do
  47. local _data = self._notices[_i];
  48. local _beginTime = DateTimeUtil.DateTime2UtcTimeStamp(DateTimeUtil.convertTime(_data.NoticeBeginTime));
  49. local _endTime = DateTimeUtil.DateTime2UtcTimeStamp(DateTimeUtil.convertTime(_data.NoticeEndTime));
  50. local _timeNow = DateTimeUtil.GetCurrentUtcTimeStamp();
  51. if _timeNow >= _endTime or _timeNow <= _beginTime then
  52. table.remove(self._notices, _i);
  53. end
  54. end
  55. end
  56. return NotifyData