overtime_model.dart 6.2 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183
  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)
  84. : null,
  85. clockOutTime: json['clockOutTime'] != null
  86. ? DateTime.parse(json['clockOutTime'] as String)
  87. : null,
  88. mealDeductHours: (json['mealDeductHours'] as num?)?.toDouble() ?? 0.5,
  89. approvalRecords:
  90. (json['approvalRecords'] as List<dynamic>?)
  91. ?.map((e) => ApprovalRecord.fromJson(e as Map<String, dynamic>))
  92. .toList() ??
  93. [],
  94. );
  95. }
  96. Map<String, dynamic> toJson() => {
  97. 'id': id,
  98. 'applicationNo': applicationNo,
  99. 'applicantId': applicantId,
  100. 'applicantName': applicantName,
  101. 'deptId': deptId,
  102. 'deptName': deptName,
  103. 'position': position,
  104. 'otDate': otDate.toIso8601String(),
  105. 'startTime': startTime.toIso8601String(),
  106. 'endTime': endTime.toIso8601String(),
  107. 'otHours': otHours,
  108. 'otType': otType,
  109. 'compensationType': compensationType,
  110. 'reason': reason,
  111. 'remark': remark,
  112. 'status': status,
  113. 'currentApproverId': currentApproverId,
  114. 'approvalChain': approvalChain,
  115. 'createTime': createTime.toIso8601String(),
  116. 'updateTime': updateTime.toIso8601String(),
  117. 'actualOtHours': actualOtHours,
  118. 'clockInTime': clockInTime?.toIso8601String(),
  119. 'clockOutTime': clockOutTime?.toIso8601String(),
  120. 'mealDeductHours': mealDeductHours,
  121. 'approvalRecords': approvalRecords.map((r) => r.toJson()).toList(),
  122. };
  123. OvertimeModel copyWith({
  124. String? id,
  125. String? applicationNo,
  126. String? applicantId,
  127. String? applicantName,
  128. String? deptId,
  129. String? deptName,
  130. String? position,
  131. DateTime? otDate,
  132. DateTime? startTime,
  133. DateTime? endTime,
  134. double? otHours,
  135. String? otType,
  136. String? compensationType,
  137. String? reason,
  138. String? remark,
  139. String? status,
  140. String? currentApproverId,
  141. List<String>? approvalChain,
  142. DateTime? createTime,
  143. DateTime? updateTime,
  144. double? actualOtHours,
  145. DateTime? clockInTime,
  146. DateTime? clockOutTime,
  147. double? mealDeductHours,
  148. List<ApprovalRecord>? approvalRecords,
  149. }) {
  150. return OvertimeModel(
  151. id: id ?? this.id,
  152. applicationNo: applicationNo ?? this.applicationNo,
  153. applicantId: applicantId ?? this.applicantId,
  154. applicantName: applicantName ?? this.applicantName,
  155. deptId: deptId ?? this.deptId,
  156. deptName: deptName ?? this.deptName,
  157. position: position ?? this.position,
  158. otDate: otDate ?? this.otDate,
  159. startTime: startTime ?? this.startTime,
  160. endTime: endTime ?? this.endTime,
  161. otHours: otHours ?? this.otHours,
  162. otType: otType ?? this.otType,
  163. compensationType: compensationType ?? this.compensationType,
  164. reason: reason ?? this.reason,
  165. remark: remark ?? this.remark,
  166. status: status ?? this.status,
  167. currentApproverId: currentApproverId ?? this.currentApproverId,
  168. approvalChain: approvalChain ?? this.approvalChain,
  169. createTime: createTime ?? this.createTime,
  170. updateTime: updateTime ?? this.updateTime,
  171. actualOtHours: actualOtHours ?? this.actualOtHours,
  172. clockInTime: clockInTime ?? this.clockInTime,
  173. clockOutTime: clockOutTime ?? this.clockOutTime,
  174. mealDeductHours: mealDeductHours ?? this.mealDeductHours,
  175. approvalRecords: approvalRecords ?? this.approvalRecords,
  176. );
  177. }
  178. }