announcement_model.dart 2.4 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576
  1. class AnnouncementModel {
  2. final String id;
  3. final String title;
  4. final String content;
  5. final String contentType;
  6. final String type;
  7. final String publisherId;
  8. final String publisherName;
  9. final DateTime publishTime;
  10. final bool isTop;
  11. final int privateLevel;
  12. final List<String> targetDepts;
  13. final List<String> targetUsers;
  14. final bool requireConfirm;
  15. final DateTime expiryDate;
  16. final List<String> attachments;
  17. final int readCount;
  18. final int unreadCount;
  19. final DateTime createTime;
  20. const AnnouncementModel({
  21. required this.id,
  22. required this.title,
  23. required this.content,
  24. this.contentType = 'text',
  25. this.type = '通知公告',
  26. required this.publisherId,
  27. required this.publisherName,
  28. required this.publishTime,
  29. this.isTop = false,
  30. this.privateLevel = 0,
  31. this.targetDepts = const [],
  32. this.targetUsers = const [],
  33. this.requireConfirm = false,
  34. required this.expiryDate,
  35. this.attachments = const [],
  36. this.readCount = 0,
  37. this.unreadCount = 0,
  38. required this.createTime,
  39. });
  40. factory AnnouncementModel.fromJson(Map<String, dynamic> json) {
  41. return AnnouncementModel(
  42. id: json['id'] as String,
  43. title: json['title'] as String,
  44. content: json['content'] as String? ?? '',
  45. contentType: json['contentType'] as String? ?? 'text',
  46. type: json['type'] as String? ?? '通知公告',
  47. publisherId: json['publisherId'] as String? ?? '',
  48. publisherName: json['publisherName'] as String? ?? '',
  49. publishTime: DateTime.parse(json['publishTime'] as String),
  50. isTop: json['isTop'] as bool? ?? false,
  51. privateLevel: json['privateLevel'] as int? ?? 0,
  52. targetDepts:
  53. (json['targetDepts'] as List<dynamic>?)
  54. ?.map((e) => e as String)
  55. .toList() ??
  56. [],
  57. targetUsers:
  58. (json['targetUsers'] as List<dynamic>?)
  59. ?.map((e) => e as String)
  60. .toList() ??
  61. [],
  62. requireConfirm: json['requireConfirm'] as bool? ?? false,
  63. expiryDate: DateTime.parse(json['expiryDate'] as String),
  64. attachments:
  65. (json['attachments'] as List<dynamic>?)
  66. ?.map((e) => e as String)
  67. .toList() ??
  68. [],
  69. readCount: json['readCount'] as int? ?? 0,
  70. unreadCount: json['unreadCount'] as int? ?? 0,
  71. createTime: DateTime.parse(json['createTime'] as String),
  72. );
  73. }
  74. }