overtime_model.dart 5.1 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155
  1. import '../../shared/models/approval_status.dart';
  2. class OvertimeModel {
  3. final String id;
  4. final String applicationNo;
  5. final String applicantId;
  6. final String applicantName;
  7. final String deptId;
  8. final String deptName;
  9. final String position;
  10. final DateTime otDate;
  11. final DateTime startTime;
  12. final DateTime endTime;
  13. final double otHours;
  14. final String otType;
  15. final String compensationType;
  16. final String reason;
  17. final String remark;
  18. final String status;
  19. final String currentApproverId;
  20. final List<String> approvalChain;
  21. final DateTime createTime;
  22. final DateTime updateTime;
  23. final List<ApprovalRecord> approvalRecords;
  24. const OvertimeModel({
  25. required this.id,
  26. required this.applicationNo,
  27. required this.applicantId,
  28. required this.applicantName,
  29. required this.deptId,
  30. required this.deptName,
  31. this.position = '',
  32. required this.otDate,
  33. required this.startTime,
  34. required this.endTime,
  35. required this.otHours,
  36. required this.otType,
  37. required this.compensationType,
  38. required this.reason,
  39. this.remark = '',
  40. this.status = 'draft',
  41. this.currentApproverId = '',
  42. this.approvalChain = const [],
  43. required this.createTime,
  44. required this.updateTime,
  45. this.approvalRecords = const [],
  46. });
  47. factory OvertimeModel.fromJson(Map<String, dynamic> json) {
  48. return OvertimeModel(
  49. id: json['id'] as String,
  50. applicationNo: json['applicationNo'] as String? ?? '',
  51. applicantId: json['applicantId'] as String? ?? '',
  52. applicantName: json['applicantName'] as String? ?? '',
  53. deptId: json['deptId'] as String? ?? '',
  54. deptName: json['deptName'] as String? ?? '',
  55. position: json['position'] as String? ?? '',
  56. otDate: DateTime.parse(json['otDate'] as String),
  57. startTime: DateTime.parse(json['startTime'] as String),
  58. endTime: DateTime.parse(json['endTime'] as String),
  59. otHours: (json['otHours'] as num?)?.toDouble() ?? 0.0,
  60. otType: json['otType'] as String? ?? '工作日加班',
  61. compensationType: json['compensationType'] as String? ?? '加班费',
  62. reason: json['reason'] as String? ?? '',
  63. remark: json['remark'] as String? ?? '',
  64. status: json['status'] as String? ?? 'draft',
  65. currentApproverId: json['currentApproverId'] as String? ?? '',
  66. approvalChain:
  67. (json['approvalChain'] as List<dynamic>?)
  68. ?.map((e) => e as String)
  69. .toList() ??
  70. [],
  71. createTime: DateTime.parse(json['createTime'] as String),
  72. updateTime: DateTime.parse(json['updateTime'] as String),
  73. approvalRecords:
  74. (json['approvalRecords'] as List<dynamic>?)
  75. ?.map((e) => ApprovalRecord.fromJson(e as Map<String, dynamic>))
  76. .toList() ??
  77. [],
  78. );
  79. }
  80. Map<String, dynamic> toJson() => {
  81. 'id': id,
  82. 'applicationNo': applicationNo,
  83. 'applicantId': applicantId,
  84. 'applicantName': applicantName,
  85. 'deptId': deptId,
  86. 'deptName': deptName,
  87. 'position': position,
  88. 'otDate': otDate.toIso8601String(),
  89. 'startTime': startTime.toIso8601String(),
  90. 'endTime': endTime.toIso8601String(),
  91. 'otHours': otHours,
  92. 'otType': otType,
  93. 'compensationType': compensationType,
  94. 'reason': reason,
  95. 'remark': remark,
  96. 'status': status,
  97. 'currentApproverId': currentApproverId,
  98. 'approvalChain': approvalChain,
  99. 'createTime': createTime.toIso8601String(),
  100. 'updateTime': updateTime.toIso8601String(),
  101. 'approvalRecords': approvalRecords.map((r) => r.toJson()).toList(),
  102. };
  103. OvertimeModel copyWith({
  104. String? id,
  105. String? applicationNo,
  106. String? applicantId,
  107. String? applicantName,
  108. String? deptId,
  109. String? deptName,
  110. String? position,
  111. DateTime? otDate,
  112. DateTime? startTime,
  113. DateTime? endTime,
  114. double? otHours,
  115. String? otType,
  116. String? compensationType,
  117. String? reason,
  118. String? remark,
  119. String? status,
  120. String? currentApproverId,
  121. List<String>? approvalChain,
  122. DateTime? createTime,
  123. DateTime? updateTime,
  124. List<ApprovalRecord>? approvalRecords,
  125. }) {
  126. return OvertimeModel(
  127. id: id ?? this.id,
  128. applicationNo: applicationNo ?? this.applicationNo,
  129. applicantId: applicantId ?? this.applicantId,
  130. applicantName: applicantName ?? this.applicantName,
  131. deptId: deptId ?? this.deptId,
  132. deptName: deptName ?? this.deptName,
  133. position: position ?? this.position,
  134. otDate: otDate ?? this.otDate,
  135. startTime: startTime ?? this.startTime,
  136. endTime: endTime ?? this.endTime,
  137. otHours: otHours ?? this.otHours,
  138. otType: otType ?? this.otType,
  139. compensationType: compensationType ?? this.compensationType,
  140. reason: reason ?? this.reason,
  141. remark: remark ?? this.remark,
  142. status: status ?? this.status,
  143. currentApproverId: currentApproverId ?? this.currentApproverId,
  144. approvalChain: approvalChain ?? this.approvalChain,
  145. createTime: createTime ?? this.createTime,
  146. updateTime: updateTime ?? this.updateTime,
  147. approvalRecords: approvalRecords ?? this.approvalRecords,
  148. );
  149. }
  150. }