wlzboy
2025-09-24 62a079a15b46925283581f6caaf631b5a4558927
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
package com.ruoyi.system.domain;
 
import java.util.Date;
import java.util.List;
import com.fasterxml.jackson.annotation.JsonFormat;
import com.ruoyi.common.annotation.Excel;
import com.ruoyi.common.core.domain.BaseEntity;
import com.ruoyi.system.domain.enums.TaskStatus;
import com.ruoyi.system.domain.enums.TaskType;
 
/**
 * 任务管理对象 sys_task
 * 
 * @author ruoyi
 * @date 2024-01-15
 */
public class SysTask extends BaseEntity {
    private static final long serialVersionUID = 1L;
 
    /** 任务ID */
    private Long taskId;
 
    /** 任务编号 */
    @Excel(name = "任务编号")
    private String taskCode;
 
    /** 任务类型 */
    @Excel(name = "任务类型", readConverterExp = "MAINTENANCE=维修保养,FUEL=加油任务,OTHER=其他")
    private String taskType;
 
    /** 任务状态 */
    @Excel(name = "任务状态", readConverterExp = "PENDING=待开始,IN_PROGRESS=任务中,COMPLETED=已完成,CANCELLED=已取消")
    private String taskStatus;
 
    /** 任务描述 */
    @Excel(name = "任务描述")
    private String taskDescription;
 
    /** 出发地址 */
    @Excel(name = "出发地址")
    private String departureAddress;
 
    /** 目的地址 */
    @Excel(name = "目的地址")
    private String destinationAddress;
 
    /** 出发地经度 */
    @Excel(name = "出发地经度")
    private java.math.BigDecimal departureLongitude;
 
    /** 出发地纬度 */
    @Excel(name = "出发地纬度")
    private java.math.BigDecimal departureLatitude;
 
    /** 目的地经度 */
    @Excel(name = "目的地经度")
    private java.math.BigDecimal destinationLongitude;
 
    /** 目的地纬度 */
    @Excel(name = "目的地纬度")
    private java.math.BigDecimal destinationLatitude;
 
    /** 预计公里数 */
    @Excel(name = "预计公里数")
    private java.math.BigDecimal estimatedDistance;
 
    /** 计划开始时间 */
    @JsonFormat(pattern = "yyyy-MM-dd HH:mm:ss")
    @Excel(name = "计划开始时间", width = 30, dateFormat = "yyyy-MM-dd HH:mm:ss")
    private Date plannedStartTime;
 
    /** 计划结束时间 */
    @JsonFormat(pattern = "yyyy-MM-dd HH:mm:ss")
    @Excel(name = "计划结束时间", width = 30, dateFormat = "yyyy-MM-dd HH:mm:ss")
    private Date plannedEndTime;
 
    /** 实际开始时间 */
    @JsonFormat(pattern = "yyyy-MM-dd HH:mm:ss")
    @Excel(name = "实际开始时间", width = 30, dateFormat = "yyyy-MM-dd HH:mm:ss")
    private Date actualStartTime;
 
    /** 实际结束时间 */
    @JsonFormat(pattern = "yyyy-MM-dd HH:mm:ss")
    @Excel(name = "实际结束时间", width = 30, dateFormat = "yyyy-MM-dd HH:mm:ss")
    private Date actualEndTime;
 
    /** 创建人ID */
    @Excel(name = "创建人ID")
    private Long creatorId;
 
    /** 执行人ID */
    @Excel(name = "执行人ID")
    private Long assigneeId;
 
    /** 归属部门ID */
    @Excel(name = "归属部门ID")
    private Long deptId;
 
    /** 创建人姓名 */
    @Excel(name = "创建人")
    private String creatorName;
 
    /** 执行人姓名 */
    @Excel(name = "执行人")
    private String assigneeName;
 
    /** 部门名称 */
    @Excel(name = "部门名称")
    private String deptName;
 
    /** 删除标志(0代表存在 2代表删除) */
    private String delFlag;
 
    /** 关联车辆列表 */
    private List<SysTaskVehicle> assignedVehicles;
 
    /** 附件列表 */
    private List<SysTaskAttachment> attachments;
 
    /** 操作日志列表 */
    private List<SysTaskLog> operationLogs;
 
    public void setTaskId(Long taskId) {
        this.taskId = taskId;
    }
 
    public Long getTaskId() {
        return taskId;
    }
 
    public void setTaskCode(String taskCode) {
        this.taskCode = taskCode;
    }
 
    public String getTaskCode() {
        return taskCode;
    }
 
    public void setTaskType(String taskType) {
        this.taskType = taskType;
    }
 
    public String getTaskType() {
        return taskType;
    }
 
    public void setTaskStatus(String taskStatus) {
        this.taskStatus = taskStatus;
    }
 
    public String getTaskStatus() {
        return taskStatus;
    }
 
    public void setTaskDescription(String taskDescription) {
        this.taskDescription = taskDescription;
    }
 
    public String getTaskDescription() {
        return taskDescription;
    }
 
    public void setDepartureAddress(String departureAddress) {
        this.departureAddress = departureAddress;
    }
 
    public String getDepartureAddress() {
        return departureAddress;
    }
 
    public void setDestinationAddress(String destinationAddress) {
        this.destinationAddress = destinationAddress;
    }
 
    public String getDestinationAddress() {
        return destinationAddress;
    }
 
    public void setDepartureLongitude(java.math.BigDecimal departureLongitude) {
        this.departureLongitude = departureLongitude;
    }
 
    public java.math.BigDecimal getDepartureLongitude() {
        return departureLongitude;
    }
 
    public void setDepartureLatitude(java.math.BigDecimal departureLatitude) {
        this.departureLatitude = departureLatitude;
    }
 
    public java.math.BigDecimal getDepartureLatitude() {
        return departureLatitude;
    }
 
    public void setDestinationLongitude(java.math.BigDecimal destinationLongitude) {
        this.destinationLongitude = destinationLongitude;
    }
 
    public java.math.BigDecimal getDestinationLongitude() {
        return destinationLongitude;
    }
 
    public void setDestinationLatitude(java.math.BigDecimal destinationLatitude) {
        this.destinationLatitude = destinationLatitude;
    }
 
    public java.math.BigDecimal getDestinationLatitude() {
        return destinationLatitude;
    }
 
    public void setEstimatedDistance(java.math.BigDecimal estimatedDistance) {
        this.estimatedDistance = estimatedDistance;
    }
 
    public java.math.BigDecimal getEstimatedDistance() {
        return estimatedDistance;
    }
 
    public void setPlannedStartTime(Date plannedStartTime) {
        this.plannedStartTime = plannedStartTime;
    }
 
    public Date getPlannedStartTime() {
        return plannedStartTime;
    }
 
    public void setPlannedEndTime(Date plannedEndTime) {
        this.plannedEndTime = plannedEndTime;
    }
 
    public Date getPlannedEndTime() {
        return plannedEndTime;
    }
 
    public void setActualStartTime(Date actualStartTime) {
        this.actualStartTime = actualStartTime;
    }
 
    public Date getActualStartTime() {
        return actualStartTime;
    }
 
    public void setActualEndTime(Date actualEndTime) {
        this.actualEndTime = actualEndTime;
    }
 
    public Date getActualEndTime() {
        return actualEndTime;
    }
 
    public void setCreatorId(Long creatorId) {
        this.creatorId = creatorId;
    }
 
    public Long getCreatorId() {
        return creatorId;
    }
 
    public void setAssigneeId(Long assigneeId) {
        this.assigneeId = assigneeId;
    }
 
    public Long getAssigneeId() {
        return assigneeId;
    }
 
    public void setDeptId(Long deptId) {
        this.deptId = deptId;
    }
 
    public Long getDeptId() {
        return deptId;
    }
 
    public void setCreatorName(String creatorName) {
        this.creatorName = creatorName;
    }
 
    public String getCreatorName() {
        return creatorName;
    }
 
    public void setAssigneeName(String assigneeName) {
        this.assigneeName = assigneeName;
    }
 
    public String getAssigneeName() {
        return assigneeName;
    }
 
    public void setDeptName(String deptName) {
        this.deptName = deptName;
    }
 
    public String getDeptName() {
        return deptName;
    }
 
    public void setDelFlag(String delFlag) {
        this.delFlag = delFlag;
    }
 
    public String getDelFlag() {
        return delFlag;
    }
 
    public void setAssignedVehicles(List<SysTaskVehicle> assignedVehicles) {
        this.assignedVehicles = assignedVehicles;
    }
 
    public List<SysTaskVehicle> getAssignedVehicles() {
        return assignedVehicles;
    }
 
    public void setAttachments(List<SysTaskAttachment> attachments) {
        this.attachments = attachments;
    }
 
    public List<SysTaskAttachment> getAttachments() {
        return attachments;
    }
 
    public void setOperationLogs(List<SysTaskLog> operationLogs) {
        this.operationLogs = operationLogs;
    }
 
    public List<SysTaskLog> getOperationLogs() {
        return operationLogs;
    }
 
    /**
     * 判断是否可以变更状态
     */
    public boolean canChangeStatus(TaskStatus newStatus) {
        TaskStatus currentStatus = TaskStatus.getByCode(this.taskStatus);
        if (currentStatus == null || newStatus == null) {
            return false;
        }
        
        // 状态流转规则
        switch (currentStatus) {
            case PENDING:
                return newStatus == TaskStatus.IN_PROGRESS || newStatus == TaskStatus.CANCELLED;
            case IN_PROGRESS:
                return newStatus == TaskStatus.COMPLETED || newStatus == TaskStatus.CANCELLED || newStatus == TaskStatus.PENDING;
            case COMPLETED:
            case CANCELLED:
                return false;
            default:
                return false;
        }
    }
 
    /**
     * 判断是否超时
     */
    public boolean isOverdue() {
        if (plannedEndTime == null) {
            return false;
        }
        return new Date().after(plannedEndTime) && !TaskStatus.COMPLETED.getCode().equals(taskStatus);
    }
 
    /**
     * 获取任务持续时间(分钟)
     */
    public long getDuration() {
        if (actualStartTime != null && actualEndTime != null) {
            return (actualEndTime.getTime() - actualStartTime.getTime()) / (1000 * 60);
        }
        return 0;
    }
 
    /**
     * 开始任务
     */
    public void start() {
        this.taskStatus = TaskStatus.IN_PROGRESS.getCode();
        this.actualStartTime = new Date();
    }
 
    /**
     * 完成任务
     */
    public void complete() {
        this.taskStatus = TaskStatus.COMPLETED.getCode();
        this.actualEndTime = new Date();
    }
 
    /**
     * 取消任务
     */
    public void cancel() {
        this.taskStatus = TaskStatus.CANCELLED.getCode();
    }
 
    /**
     * 检查是否分配了指定车辆
     */
    public boolean hasVehicle(Long vehicleId) {
        if (assignedVehicles == null || vehicleId == null) {
            return false;
        }
        return assignedVehicles.stream().anyMatch(v -> vehicleId.equals(v.getVehicleId()));
    }
 
    @Override
    public String toString() {
        return "SysTask{" +
                "taskId=" + taskId +
                ", taskCode='" + taskCode + '\'' +
                ", taskType='" + taskType + '\'' +
                ", taskStatus='" + taskStatus + '\'' +
                ", taskDescription='" + taskDescription + '\'' +
                ", departureAddress='" + departureAddress + '\'' +
                ", destinationAddress='" + destinationAddress + '\'' +
                ", plannedStartTime=" + plannedStartTime +
                ", plannedEndTime=" + plannedEndTime +
                ", actualStartTime=" + actualStartTime +
                ", actualEndTime=" + actualEndTime +
                ", creatorId=" + creatorId +
                ", assigneeId=" + assigneeId +
                ", deptId=" + deptId +
                ", creatorName='" + creatorName + '\'' +
                ", assigneeName='" + assigneeName + '\'' +
                ", deptName='" + deptName + '\'' +
                '}';
    }
}