overtime_model.dart 6.3 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181
  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 double actualOtHours;
  24. final DateTime? clockInTime;
  25. final DateTime? clockOutTime;
  26. final double mealDeductHours;
  27. final List<ApprovalRecord> approvalRecords;
  28. const OvertimeModel({
  29. required this.id,
  30. required this.applicationNo,
  31. required this.applicantId,
  32. required this.applicantName,
  33. required this.deptId,
  34. required this.deptName,
  35. this.position = '',
  36. required this.otDate,
  37. required this.startTime,
  38. required this.endTime,
  39. required this.otHours,
  40. required this.otType,
  41. required this.compensationType,
  42. required this.reason,
  43. this.remark = '',
  44. this.status = 'draft',
  45. this.currentApproverId = '',
  46. this.approvalChain = const [],
  47. required this.createTime,
  48. required this.updateTime,
  49. this.actualOtHours = 0.0,
  50. this.clockInTime,
  51. this.clockOutTime,
  52. this.mealDeductHours = 0.5,
  53. this.approvalRecords = const [],
  54. });
  55. factory OvertimeModel.fromJson(Map<String, dynamic> json) {
  56. return OvertimeModel(
  57. id: json['id'] as String,
  58. applicationNo: json['applicationNo'] as String? ?? '',
  59. applicantId: json['applicantId'] as String? ?? '',
  60. applicantName: json['applicantName'] as String? ?? '',
  61. deptId: json['deptId'] as String? ?? '',
  62. deptName: json['deptName'] as String? ?? '',
  63. position: json['position'] as String? ?? '',
  64. otDate: DateTime.parse(json['otDate'] as String),
  65. startTime: DateTime.parse(json['startTime'] as String),
  66. endTime: DateTime.parse(json['endTime'] as String),
  67. otHours: (json['otHours'] as num?)?.toDouble() ?? 0.0,
  68. otType: json['otType'] as String? ?? '工作日加班',
  69. compensationType: json['compensationType'] as String? ?? '加班费',
  70. reason: json['reason'] as String? ?? '',
  71. remark: json['remark'] as String? ?? '',
  72. status: json['status'] as String? ?? 'draft',
  73. currentApproverId: json['currentApproverId'] as String? ?? '',
  74. approvalChain:
  75. (json['approvalChain'] as List<dynamic>?)
  76. ?.map((e) => e as String)
  77. .toList() ??
  78. [],
  79. createTime: DateTime.parse(json['createTime'] as String),
  80. updateTime: DateTime.parse(json['updateTime'] as String),
  81. actualOtHours: (json['actualOtHours'] as num?)?.toDouble() ?? 0.0,
  82. clockInTime: json['clockInTime'] != null
  83. ? DateTime.parse(json['clockInTime'] as String) : null,
  84. clockOutTime: json['clockOutTime'] != null
  85. ? DateTime.parse(json['clockOutTime'] as String) : null,
  86. mealDeductHours: (json['mealDeductHours'] as num?)?.toDouble() ?? 0.5,
  87. approvalRecords:
  88. (json['approvalRecords'] as List<dynamic>?)
  89. ?.map((e) => ApprovalRecord.fromJson(e as Map<String, dynamic>))
  90. .toList() ??
  91. [],
  92. );
  93. }
  94. Map<String, dynamic> toJson() => {
  95. 'id': id,
  96. 'applicationNo': applicationNo,
  97. 'applicantId': applicantId,
  98. 'applicantName': applicantName,
  99. 'deptId': deptId,
  100. 'deptName': deptName,
  101. 'position': position,
  102. 'otDate': otDate.toIso8601String(),
  103. 'startTime': startTime.toIso8601String(),
  104. 'endTime': endTime.toIso8601String(),
  105. 'otHours': otHours,
  106. 'otType': otType,
  107. 'compensationType': compensationType,
  108. 'reason': reason,
  109. 'remark': remark,
  110. 'status': status,
  111. 'currentApproverId': currentApproverId,
  112. 'approvalChain': approvalChain,
  113. 'createTime': createTime.toIso8601String(),
  114. 'updateTime': updateTime.toIso8601String(),
  115. 'actualOtHours': actualOtHours,
  116. 'clockInTime': clockInTime?.toIso8601String(),
  117. 'clockOutTime': clockOutTime?.toIso8601String(),
  118. 'mealDeductHours': mealDeductHours,
  119. 'approvalRecords': approvalRecords.map((r) => r.toJson()).toList(),
  120. };
  121. OvertimeModel copyWith({
  122. String? id,
  123. String? applicationNo,
  124. String? applicantId,
  125. String? applicantName,
  126. String? deptId,
  127. String? deptName,
  128. String? position,
  129. DateTime? otDate,
  130. DateTime? startTime,
  131. DateTime? endTime,
  132. double? otHours,
  133. String? otType,
  134. String? compensationType,
  135. String? reason,
  136. String? remark,
  137. String? status,
  138. String? currentApproverId,
  139. List<String>? approvalChain,
  140. DateTime? createTime,
  141. DateTime? updateTime,
  142. double? actualOtHours,
  143. DateTime? clockInTime,
  144. DateTime? clockOutTime,
  145. double? mealDeductHours,
  146. List<ApprovalRecord>? approvalRecords,
  147. }) {
  148. return OvertimeModel(
  149. id: id ?? this.id,
  150. applicationNo: applicationNo ?? this.applicationNo,
  151. applicantId: applicantId ?? this.applicantId,
  152. applicantName: applicantName ?? this.applicantName,
  153. deptId: deptId ?? this.deptId,
  154. deptName: deptName ?? this.deptName,
  155. position: position ?? this.position,
  156. otDate: otDate ?? this.otDate,
  157. startTime: startTime ?? this.startTime,
  158. endTime: endTime ?? this.endTime,
  159. otHours: otHours ?? this.otHours,
  160. otType: otType ?? this.otType,
  161. compensationType: compensationType ?? this.compensationType,
  162. reason: reason ?? this.reason,
  163. remark: remark ?? this.remark,
  164. status: status ?? this.status,
  165. currentApproverId: currentApproverId ?? this.currentApproverId,
  166. approvalChain: approvalChain ?? this.approvalChain,
  167. createTime: createTime ?? this.createTime,
  168. updateTime: updateTime ?? this.updateTime,
  169. actualOtHours: actualOtHours ?? this.actualOtHours,
  170. clockInTime: clockInTime ?? this.clockInTime,
  171. clockOutTime: clockOutTime ?? this.clockOutTime,
  172. mealDeductHours: mealDeductHours ?? this.mealDeductHours,
  173. approvalRecords: approvalRecords ?? this.approvalRecords,
  174. );
  175. }
  176. }