| New file |
| | |
| | | package com.ruoyi.web.controller.task; |
| | | |
| | | import java.util.List; |
| | | import javax.servlet.http.HttpServletResponse; |
| | | 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.PutMapping; |
| | | 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.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.SysTask; |
| | | import com.ruoyi.system.domain.SysTaskLog; |
| | | import com.ruoyi.system.domain.vo.TaskQueryVO; |
| | | import com.ruoyi.system.domain.vo.TaskCreateVO; |
| | | import com.ruoyi.system.domain.vo.TaskUpdateVO; |
| | | import com.ruoyi.system.domain.vo.TaskStatisticsVO; |
| | | import com.ruoyi.system.domain.enums.TaskStatus; |
| | | import com.ruoyi.system.service.ISysTaskService; |
| | | import com.ruoyi.common.utils.poi.ExcelUtil; |
| | | import com.ruoyi.common.core.page.TableDataInfo; |
| | | |
| | | /** |
| | | * 任务管理Controller |
| | | * |
| | | * @author ruoyi |
| | | * @date 2024-01-15 |
| | | */ |
| | | @RestController |
| | | @RequestMapping("/task") |
| | | public class SysTaskController extends BaseController { |
| | | |
| | | @Autowired |
| | | private ISysTaskService sysTaskService; |
| | | |
| | | /** |
| | | * 查询任务管理列表 |
| | | */ |
| | | @PreAuthorize("@ss.hasPermi('task:general:query')") |
| | | @GetMapping("/list") |
| | | public TableDataInfo list(TaskQueryVO queryVO) { |
| | | // 在后端自动获取当前用户信息,实现综合查询 |
| | | // 综合查询:当前用户所在机构任务 + 当前用户创建的任务 + 分配给当前用户的任务 |
| | | Long currentUserId = getUserId(); |
| | | Long currentDeptId = getDeptId(); |
| | | |
| | | // 如果前端没有传递这些参数,则使用当前登录用户信息 |
| | | if (queryVO.getCreatorId() == null && queryVO.getAssigneeId() == null && queryVO.getDeptId() == null) { |
| | | queryVO.setDeptId(currentDeptId); |
| | | queryVO.setCreatorId(currentUserId); |
| | | queryVO.setAssigneeId(currentUserId); |
| | | } |
| | | |
| | | startPage(); |
| | | List<SysTask> list = sysTaskService.selectSysTaskList(queryVO); |
| | | return getDataTable(list); |
| | | } |
| | | |
| | | /** |
| | | * 导出任务管理列表 |
| | | */ |
| | | @PreAuthorize("@ss.hasPermi('task:general:export')") |
| | | @Log(title = "任务管理", businessType = BusinessType.EXPORT) |
| | | @PostMapping("/export") |
| | | public void export(HttpServletResponse response, TaskQueryVO queryVO) { |
| | | List<SysTask> list = sysTaskService.selectSysTaskList(queryVO); |
| | | ExcelUtil<SysTask> util = new ExcelUtil<SysTask>(SysTask.class); |
| | | util.exportExcel(response, list, "任务管理数据"); |
| | | } |
| | | |
| | | /** |
| | | * 获取任务管理详细信息 |
| | | */ |
| | | @PreAuthorize("@ss.hasPermi('task:general:query')") |
| | | @GetMapping(value = "/{taskId}") |
| | | public AjaxResult getInfo(@PathVariable("taskId") Long taskId) { |
| | | return success(sysTaskService.getTaskDetail(taskId)); |
| | | } |
| | | |
| | | /** |
| | | * 新增任务管理 |
| | | */ |
| | | @PreAuthorize("@ss.hasPermi('task:general:add')") |
| | | @Log(title = "任务管理", businessType = BusinessType.INSERT) |
| | | @PostMapping |
| | | public AjaxResult add(@RequestBody TaskCreateVO createVO) { |
| | | return toAjax(sysTaskService.insertSysTask(createVO)); |
| | | } |
| | | |
| | | /** |
| | | * 修改任务管理 |
| | | */ |
| | | @PreAuthorize("@ss.hasPermi('task:general:edit')") |
| | | @Log(title = "任务管理", businessType = BusinessType.UPDATE) |
| | | @PutMapping |
| | | public AjaxResult edit(@RequestBody TaskUpdateVO updateVO) { |
| | | return toAjax(sysTaskService.updateSysTask(updateVO)); |
| | | } |
| | | |
| | | /** |
| | | * 删除任务管理 |
| | | */ |
| | | @PreAuthorize("@ss.hasPermi('task:general:remove')") |
| | | @Log(title = "任务管理", businessType = BusinessType.DELETE) |
| | | @DeleteMapping("/{taskIds}") |
| | | public AjaxResult remove(@PathVariable Long[] taskIds) { |
| | | return toAjax(sysTaskService.deleteSysTaskByTaskIds(taskIds)); |
| | | } |
| | | |
| | | /** |
| | | * 分配任务 |
| | | */ |
| | | @PreAuthorize("@ss.hasPermi('task:general:assign')") |
| | | @Log(title = "任务分配", businessType = BusinessType.UPDATE) |
| | | @PutMapping("/{taskId}/assign") |
| | | public AjaxResult assignTask(@PathVariable Long taskId, @RequestBody AssignTaskRequest request) { |
| | | return toAjax(sysTaskService.assignTask(taskId, request.getAssigneeId(), request.getRemark())); |
| | | } |
| | | |
| | | /** |
| | | * 更新任务状态 |
| | | */ |
| | | @PreAuthorize("@ss.hasPermi('task:general:status')") |
| | | @Log(title = "任务状态变更", businessType = BusinessType.UPDATE) |
| | | @PutMapping("/{taskId}/status") |
| | | public AjaxResult changeTaskStatus(@PathVariable Long taskId, @RequestBody ChangeStatusRequest request) { |
| | | TaskStatus newStatus = TaskStatus.getByCode(request.getTaskStatus()); |
| | | if (newStatus == null) { |
| | | return error("无效的任务状态"); |
| | | } |
| | | |
| | | // 如果包含GPS位置信息,使用带位置的方法 |
| | | if (request.getLatitude() != null && request.getLongitude() != null) { |
| | | SysTaskLog locationLog = new SysTaskLog(); |
| | | locationLog.setLatitude(request.getLatitude()); |
| | | locationLog.setLongitude(request.getLongitude()); |
| | | locationLog.setLocationAddress(request.getLocationAddress()); |
| | | locationLog.setLocationProvince(request.getLocationProvince()); |
| | | locationLog.setLocationCity(request.getLocationCity()); |
| | | locationLog.setLocationDistrict(request.getLocationDistrict()); |
| | | locationLog.setGpsAccuracy(request.getGpsAccuracy()); |
| | | locationLog.setAltitude(request.getAltitude()); |
| | | locationLog.setSpeed(request.getSpeed()); |
| | | locationLog.setHeading(request.getHeading()); |
| | | |
| | | return toAjax(sysTaskService.changeTaskStatusWithLocation(taskId, newStatus, request.getRemark(), locationLog)); |
| | | } |
| | | |
| | | return toAjax(sysTaskService.changeTaskStatus(taskId, newStatus, request.getRemark())); |
| | | } |
| | | |
| | | /** |
| | | * 查询任务统计信息 |
| | | */ |
| | | @PreAuthorize("@ss.hasPermi('task:general:query')") |
| | | @GetMapping("/statistics") |
| | | public AjaxResult getStatistics() { |
| | | TaskStatisticsVO statistics = sysTaskService.getTaskStatistics(); |
| | | return success(statistics); |
| | | } |
| | | |
| | | /** |
| | | * 查询超时任务列表 |
| | | */ |
| | | @PreAuthorize("@ss.hasPermi('task:general:query')") |
| | | @GetMapping("/overdue") |
| | | public AjaxResult getOverdueTasks() { |
| | | List<SysTask> list = sysTaskService.selectOverdueTasks(); |
| | | return success(list); |
| | | } |
| | | |
| | | /** |
| | | * 查询我的任务列表 |
| | | */ |
| | | @PreAuthorize("@ss.hasPermi('task:general:query')") |
| | | @GetMapping("/my") |
| | | public AjaxResult getMyTasks() { |
| | | List<SysTask> list = sysTaskService.selectMyTasks(getUserId()); |
| | | return success(list); |
| | | } |
| | | |
| | | /** |
| | | * 分配任务请求对象 |
| | | */ |
| | | public static class AssignTaskRequest { |
| | | private Long assigneeId; |
| | | private String remark; |
| | | |
| | | public Long getAssigneeId() { |
| | | return assigneeId; |
| | | } |
| | | |
| | | public void setAssigneeId(Long assigneeId) { |
| | | this.assigneeId = assigneeId; |
| | | } |
| | | |
| | | public String getRemark() { |
| | | return remark; |
| | | } |
| | | |
| | | public void setRemark(String remark) { |
| | | this.remark = remark; |
| | | } |
| | | } |
| | | |
| | | /** |
| | | * 变更状态请求对象 |
| | | */ |
| | | public static class ChangeStatusRequest { |
| | | private String taskStatus; |
| | | private String remark; |
| | | |
| | | // GPS位置信息字段 |
| | | private Double latitude; |
| | | private Double longitude; |
| | | private String locationAddress; |
| | | private String locationProvince; |
| | | private String locationCity; |
| | | private String locationDistrict; |
| | | private Double gpsAccuracy; |
| | | private Double altitude; |
| | | private Double speed; |
| | | private Double heading; |
| | | |
| | | public String getTaskStatus() { |
| | | return taskStatus; |
| | | } |
| | | |
| | | public void setTaskStatus(String taskStatus) { |
| | | this.taskStatus = taskStatus; |
| | | } |
| | | |
| | | public String getRemark() { |
| | | return remark; |
| | | } |
| | | |
| | | public void setRemark(String remark) { |
| | | this.remark = remark; |
| | | } |
| | | |
| | | public Double getLatitude() { |
| | | return latitude; |
| | | } |
| | | |
| | | public void setLatitude(Double latitude) { |
| | | this.latitude = latitude; |
| | | } |
| | | |
| | | public Double getLongitude() { |
| | | return longitude; |
| | | } |
| | | |
| | | public void setLongitude(Double longitude) { |
| | | this.longitude = longitude; |
| | | } |
| | | |
| | | public String getLocationAddress() { |
| | | return locationAddress; |
| | | } |
| | | |
| | | public void setLocationAddress(String locationAddress) { |
| | | this.locationAddress = locationAddress; |
| | | } |
| | | |
| | | public String getLocationProvince() { |
| | | return locationProvince; |
| | | } |
| | | |
| | | public void setLocationProvince(String locationProvince) { |
| | | this.locationProvince = locationProvince; |
| | | } |
| | | |
| | | public String getLocationCity() { |
| | | return locationCity; |
| | | } |
| | | |
| | | public void setLocationCity(String locationCity) { |
| | | this.locationCity = locationCity; |
| | | } |
| | | |
| | | public String getLocationDistrict() { |
| | | return locationDistrict; |
| | | } |
| | | |
| | | public void setLocationDistrict(String locationDistrict) { |
| | | this.locationDistrict = locationDistrict; |
| | | } |
| | | |
| | | public Double getGpsAccuracy() { |
| | | return gpsAccuracy; |
| | | } |
| | | |
| | | public void setGpsAccuracy(Double gpsAccuracy) { |
| | | this.gpsAccuracy = gpsAccuracy; |
| | | } |
| | | |
| | | public Double getAltitude() { |
| | | return altitude; |
| | | } |
| | | |
| | | public void setAltitude(Double altitude) { |
| | | this.altitude = altitude; |
| | | } |
| | | |
| | | public Double getSpeed() { |
| | | return speed; |
| | | } |
| | | |
| | | public void setSpeed(Double speed) { |
| | | this.speed = speed; |
| | | } |
| | | |
| | | public Double getHeading() { |
| | | return heading; |
| | | } |
| | | |
| | | public void setHeading(Double heading) { |
| | | this.heading = heading; |
| | | } |
| | | } |
| | | } |