overtime_model.dart 5.1 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153
  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 otType;
  10. final String compensationType;
  11. final double? compLeaveRatio;
  12. final DateTime startTime;
  13. final DateTime endTime;
  14. final double netOtHours;
  15. final String reason;
  16. final String status;
  17. final String approvalInstanceId;
  18. final DateTime createTime;
  19. final DateTime updateTime;
  20. // 审批相关
  21. final List<ApprovalRecord> approvalRecords;
  22. final List<String> approvalChain;
  23. final String currentApproverId;
  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. required this.otType,
  32. required this.compensationType,
  33. this.compLeaveRatio,
  34. required this.startTime,
  35. required this.endTime,
  36. required this.netOtHours,
  37. required this.reason,
  38. this.status = 'draft',
  39. this.approvalInstanceId = '',
  40. required this.createTime,
  41. required this.updateTime,
  42. this.approvalRecords = const [],
  43. this.approvalChain = const [],
  44. this.currentApproverId = '',
  45. });
  46. double get otHours => netOtHours;
  47. DateTime get otDate => startTime;
  48. factory OvertimeModel.fromJson(Map<String, dynamic> json) {
  49. return OvertimeModel(
  50. id: json['id'] as String,
  51. applicationNo: json['applicationNo'] as String? ?? '',
  52. applicantId: json['applicantId'] as String? ?? '',
  53. applicantName: json['applicantName'] as String? ?? '',
  54. deptId: json['deptId'] as String? ?? '',
  55. deptName: json['deptName'] as String? ?? '',
  56. otType: json['otType'] as String? ?? 'workday',
  57. compensationType: json['compensationType'] as String? ?? 'overtime_pay',
  58. compLeaveRatio: (json['compLeaveRatio'] as num?)?.toDouble(),
  59. startTime: DateTime.parse(json['startTime'] as String),
  60. endTime: DateTime.parse(json['endTime'] as String),
  61. netOtHours: (json['netOtHours'] as num?)?.toDouble() ?? 0.0,
  62. reason: json['reason'] as String? ?? '',
  63. status: json['status'] as String? ?? 'draft',
  64. approvalInstanceId: json['approvalInstanceId'] as String? ?? '',
  65. createTime: DateTime.parse(json['createTime'] as String),
  66. updateTime: DateTime.parse(json['updateTime'] as String),
  67. approvalRecords:
  68. (json['approvalRecords'] as List<dynamic>?)
  69. ?.map((e) => ApprovalRecord.fromJson(e as Map<String, dynamic>))
  70. .toList() ??
  71. [],
  72. approvalChain:
  73. (json['approvalChain'] as List<dynamic>?)
  74. ?.map((e) => e as String)
  75. .toList() ??
  76. [],
  77. currentApproverId: json['currentApproverId'] as String? ?? '',
  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. 'otType': otType,
  88. 'compensationType': compensationType,
  89. 'compLeaveRatio': compLeaveRatio,
  90. 'startTime': startTime.toIso8601String(),
  91. 'endTime': endTime.toIso8601String(),
  92. 'netOtHours': netOtHours,
  93. 'reason': reason,
  94. 'status': status,
  95. 'approvalInstanceId': approvalInstanceId,
  96. 'createTime': createTime.toIso8601String(),
  97. 'updateTime': updateTime.toIso8601String(),
  98. 'approvalRecords': approvalRecords.map((r) => r.toJson()).toList(),
  99. 'approvalChain': approvalChain,
  100. 'currentApproverId': currentApproverId,
  101. };
  102. OvertimeModel copyWith({
  103. String? id,
  104. String? applicationNo,
  105. String? applicantId,
  106. String? applicantName,
  107. String? deptId,
  108. String? deptName,
  109. String? otType,
  110. String? compensationType,
  111. double? compLeaveRatio,
  112. DateTime? startTime,
  113. DateTime? endTime,
  114. double? netOtHours,
  115. String? reason,
  116. String? status,
  117. String? approvalInstanceId,
  118. DateTime? createTime,
  119. DateTime? updateTime,
  120. List<ApprovalRecord>? approvalRecords,
  121. List<String>? approvalChain,
  122. String? currentApproverId,
  123. }) {
  124. return OvertimeModel(
  125. id: id ?? this.id,
  126. applicationNo: applicationNo ?? this.applicationNo,
  127. applicantId: applicantId ?? this.applicantId,
  128. applicantName: applicantName ?? this.applicantName,
  129. deptId: deptId ?? this.deptId,
  130. deptName: deptName ?? this.deptName,
  131. otType: otType ?? this.otType,
  132. compensationType: compensationType ?? this.compensationType,
  133. compLeaveRatio: compLeaveRatio ?? this.compLeaveRatio,
  134. startTime: startTime ?? this.startTime,
  135. endTime: endTime ?? this.endTime,
  136. netOtHours: netOtHours ?? this.netOtHours,
  137. reason: reason ?? this.reason,
  138. status: status ?? this.status,
  139. approvalInstanceId: approvalInstanceId ?? this.approvalInstanceId,
  140. createTime: createTime ?? this.createTime,
  141. updateTime: updateTime ?? this.updateTime,
  142. approvalRecords: approvalRecords ?? this.approvalRecords,
  143. approvalChain: approvalChain ?? this.approvalChain,
  144. currentApproverId: currentApproverId ?? this.currentApproverId,
  145. );
  146. }
  147. }