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
package com.ruoyi.web.controller.task;
 
import java.util.List;
import org.springframework.security.access.prepost.PreAuthorize;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.DeleteMapping;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestParam;
import org.springframework.web.bind.annotation.RestController;
import com.ruoyi.common.annotation.Log;
import com.ruoyi.common.core.controller.BaseController;
import com.ruoyi.common.core.domain.AjaxResult;
import com.ruoyi.common.enums.BusinessType;
import com.ruoyi.system.domain.SysTaskVehicle;
import com.ruoyi.system.service.ISysTaskService;
 
/**
 * 任务车辆关联Controller
 * 
 * @author ruoyi
 * @date 2024-01-15
 */
@RestController
@RequestMapping("/task/vehicle")
public class SysTaskVehicleController extends BaseController {
    
    @Autowired
    private ISysTaskService sysTaskService;
 
    /**
     * 查询任务关联的车辆列表
     */
    @PreAuthorize("@ss.hasPermi('task:general:query')")
    @GetMapping("/list/{taskId}")
    public AjaxResult list(@PathVariable("taskId") Long taskId) {
        List<SysTaskVehicle> list = sysTaskService.getTaskVehicles(taskId);
        return success(list);
    }
 
    /**
     * 查询可用车辆列表
     */
    @PreAuthorize("@ss.hasPermi('task:general:query')")
    @GetMapping("/available")
    public AjaxResult getAvailableVehicles(@RequestParam Long deptId, @RequestParam(required = false) String taskType) {
        List<SysTaskVehicle> list = sysTaskService.getAvailableVehicles(deptId, taskType);
        return success(list);
    }
 
    /**
     * 分配车辆给任务
     */
    @PreAuthorize("@ss.hasPermi('task:general:assign')")
    @Log(title = "任务车辆分配", businessType = BusinessType.INSERT)
    @PostMapping("/assign/{taskId}")
    public AjaxResult assignVehicle(@PathVariable("taskId") Long taskId, @RequestBody AssignVehicleRequest request) {
        try {
            int result = sysTaskService.assignVehicleToTask(taskId, request.getVehicleId(), request.getRemark());
            if (result > 0) {
                return success("分配成功");
            } else {
                return error("分配失败");
            }
        } catch (Exception e) {
            return error("分配失败:" + e.getMessage());
        }
    }
 
    /**
     * 批量分配车辆给任务
     */
    @PreAuthorize("@ss.hasPermi('task:general:assign')")
    @Log(title = "任务车辆批量分配", businessType = BusinessType.INSERT)
    @PostMapping("/assign-batch/{taskId}")
    public AjaxResult assignVehicles(@PathVariable("taskId") Long taskId, @RequestBody BatchAssignVehicleRequest request) {
        try {
            // 设置请求对象中的taskId,确保参数一致性
            request.setTaskId(taskId);
            int result = sysTaskService.assignMultipleVehiclesToTask(request.getTaskId(), request.getVehicleIds(), request.getRemark());
            if (result > 0) {
                return success("批量分配成功,共分配 " + result + " 辆车");
            } else {
                return error("批量分配失败");
            }
        } catch (Exception e) {
            return error("批量分配失败:" + e.getMessage());
        }
    }
 
    /**
     * 取消任务车辆分配
     */
    @PreAuthorize("@ss.hasPermi('task:general:assign')")
    @Log(title = "取消任务车辆分配", businessType = BusinessType.DELETE)
    @DeleteMapping("/{taskId}/{vehicleId}")
    public AjaxResult unassignVehicle(@PathVariable("taskId") Long taskId, @PathVariable("vehicleId") Long vehicleId) {
        try {
            int result = sysTaskService.unassignVehicleFromTask(taskId, vehicleId);
            if (result > 0) {
                return success("取消分配成功");
            } else {
                return error("取消分配失败");
            }
        } catch (Exception e) {
            return error("取消分配失败:" + e.getMessage());
        }
    }
 
    /**
     * 分配车辆请求对象
     */
    public static class AssignVehicleRequest {
        private Long vehicleId;
        private String remark;
 
        public Long getVehicleId() {
            return vehicleId;
        }
 
        public void setVehicleId(Long vehicleId) {
            this.vehicleId = vehicleId;
        }
 
        public String getRemark() {
            return remark;
        }
 
        public void setRemark(String remark) {
            this.remark = remark;
        }
    }
 
    /**
     * 批量分配车辆请求对象
     */
    public static class BatchAssignVehicleRequest {
        private Long taskId;
        private List<Long> vehicleIds;
        private String remark;
 
        public Long getTaskId() {
            return taskId;
        }
 
        public void setTaskId(Long taskId) {
            this.taskId = taskId;
        }
 
        public List<Long> getVehicleIds() {
            return vehicleIds;
        }
 
        public void setVehicleIds(List<Long> vehicleIds) {
            this.vehicleIds = vehicleIds;
        }
 
        public String getRemark() {
            return remark;
        }
 
        public void setRemark(String remark) {
            this.remark = remark;
        }
    }
}