| | |
| | | package com.ruoyi.web.controller.task; |
| | | |
| | | import java.util.Date; |
| | | import java.util.List; |
| | | import javax.annotation.Resource; |
| | | import javax.servlet.http.HttpServletResponse; |
| | | |
| | | import com.fasterxml.jackson.annotation.JsonFormat; |
| | | import com.ruoyi.common.annotation.Anonymous; |
| | | import com.ruoyi.common.utils.DateUtils; |
| | | import com.ruoyi.common.utils.SecurityUtils; |
| | | import com.ruoyi.system.domain.SysTaskEmergency; |
| | | import com.ruoyi.system.service.*; |
| | | import org.springframework.beans.factory.annotation.Qualifier; |
| | | 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.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.core.domain.entity.SysUser; |
| | | import com.ruoyi.common.core.domain.entity.SysDept; |
| | | import com.ruoyi.common.enums.BusinessType; |
| | | import com.ruoyi.system.domain.SysTask; |
| | | import com.ruoyi.system.domain.SysTaskLog; |
| | | import com.ruoyi.system.domain.VehicleInfo; |
| | | 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; |
| | | import com.ruoyi.common.utils.StringUtils; |
| | | |
| | | /** |
| | | * 任务管理Controller |
| | |
| | | @Autowired |
| | | private ISysTaskService sysTaskService; |
| | | |
| | | @Autowired |
| | | private ISysTaskEmergencyService sysTaskEmergencyService; |
| | | |
| | | @Autowired |
| | | private IVehicleInfoService vehicleInfoService; |
| | | |
| | | @Autowired |
| | | private ISysUserService userService; |
| | | |
| | | @Autowired |
| | | private ISysDeptService deptService; |
| | | |
| | | |
| | | @Autowired |
| | | @Qualifier("tiandituMapService") |
| | | private IMapService mapService; |
| | | |
| | | /** |
| | | * 查询任务管理列表(后台管理端) |
| | | * 管理员权限,可以查看所有任务 |
| | |
| | | @GetMapping("/admin/list") |
| | | public TableDataInfo adminList(TaskQueryVO queryVO) { |
| | | startPage(); |
| | | List<SysTask> list = sysTaskService.selectSysTaskList(queryVO); |
| | | // Handle multi-field task code search |
| | | String searchTaskCode = queryVO.getTaskCode(); |
| | | List<SysTask> list; |
| | | if(searchTaskCode != null && !searchTaskCode.trim().isEmpty()){ |
| | | // Search across task_code, emergency_info.dispatch_code, and emergency_info.service_code |
| | | list = sysTaskService.selectSysTaskListByMultiCode(queryVO, searchTaskCode); |
| | | } else { |
| | | queryVO.setTaskCode(null); |
| | | list = sysTaskService.selectSysTaskList(queryVO); |
| | | } |
| | | |
| | | |
| | | return getDataTable(list); |
| | | } |
| | | |
| | | /** |
| | | * 查询任务列表(APP端) |
| | | * 仅显示当前用户相关的任务: |
| | | * 1. 当前用户所在机构的任务 |
| | | * 2. 当前用户创建的任务 |
| | | * 3. 分配给当前用户的任务 |
| | | * 根据用户权限返回不同范围的任务: |
| | | * 1. 有查看所有咨询单权限(canViewAllConsult='1'):返回该用户管理所有分公司下的所有任务单 |
| | | * 2. 无权限(canViewAllConsult='0'):只返回分配给该用户的单或该用户创建的单 |
| | | */ |
| | | @GetMapping("/list") |
| | | public TableDataInfo appList(TaskQueryVO queryVO) { |
| | | // 在后端自动获取当前用户信息,实现综合查询 |
| | | // 获取当前用户信息 |
| | | Long currentUserId = getUserId(); |
| | | Long currentDeptId = getDeptId(); |
| | | SysUser currentUser = userService.selectUserById(currentUserId); |
| | | |
| | | // APP端强制使用当前登录用户信息进行过滤 |
| | | queryVO.setDeptId(currentDeptId); |
| | | queryVO.setCreatorId(currentUserId); |
| | | queryVO.setAssigneeId(currentUserId); |
| | | if (currentUser == null) { |
| | | return getDataTable(new java.util.ArrayList<>()); |
| | | } |
| | | |
| | | // 判断用户是否有查看所有咨询单的权限 |
| | | String canViewAllConsult = currentUser.getCanViewAllConsult(); |
| | | |
| | | if ("1".equals(canViewAllConsult)) { |
| | | // 有权限:返回该用户管理所有分公司下的所有任务单 |
| | | // 1. 获取用户管理的分公司列表 |
| | | List<SysDept> branchCompanies = deptService.computeBranchCompaniesForUser(currentUser); |
| | | |
| | | if (branchCompanies != null && !branchCompanies.isEmpty()) { |
| | | // 2. 提取所有分公司ID |
| | | List<Long> deptIds = new java.util.ArrayList<>(); |
| | | for (SysDept dept : branchCompanies) { |
| | | deptIds.add(dept.getDeptId()); |
| | | } |
| | | |
| | | // 3. 设置查询条件为分公司ID列表(SQL会自动包含所有子部门) |
| | | queryVO.setDeptIds(deptIds); |
| | | // 清空创建人和执行人过滤条件,返回这些分公司下的所有任务 |
| | | queryVO.setCreatorId(null); |
| | | queryVO.setAssigneeId(null); |
| | | } else { |
| | | // 如果没有找到分公司,返回空列表 |
| | | return getDataTable(new java.util.ArrayList<>()); |
| | | } |
| | | } else { |
| | | // 无权限:只返回分配给该用户的单或该用户创建的单 |
| | | // 清空deptId和deptIds,使用creatorId和assigneeId进行OR查询 |
| | | queryVO.setDeptId(null); |
| | | queryVO.setDeptIds(null); |
| | | queryVO.setCreatorId(currentUserId); |
| | | queryVO.setAssigneeId(currentUserId); |
| | | } |
| | | |
| | | startPage(); |
| | | List<SysTask> list = sysTaskService.selectSysTaskList(queryVO); |
| | |
| | | @Log(title = "任务管理", businessType = BusinessType.INSERT) |
| | | @PostMapping("/admin") |
| | | public AjaxResult adminAdd(@RequestBody TaskCreateVO createVO) { |
| | | return toAjax(sysTaskService.insertSysTask(createVO)); |
| | | Long taskId = sysTaskService.insertSysTask(createVO); |
| | | return taskId > 0 ? AjaxResult.success("新增成功").put("taskId", taskId) : AjaxResult.error("新增失败"); |
| | | } |
| | | |
| | | /** |
| | |
| | | @Log(title = "任务创建", businessType = BusinessType.INSERT) |
| | | @PostMapping |
| | | public AjaxResult appAdd(@RequestBody TaskCreateVO createVO) { |
| | | return toAjax(sysTaskService.insertSysTask(createVO)); |
| | | Long taskId = sysTaskService.insertSysTask(createVO); |
| | | return taskId > 0 ? AjaxResult.success("新增成功").put("taskId", taskId) : AjaxResult.error("新增失败"); |
| | | } |
| | | |
| | | /** |
| | | * 检查任务是否重复(根据联系人电话和创建日期) |
| | | * @param phone 联系人电话 |
| | | * @param createDate 任务创建日期(格式:YYYY-MM-DD) |
| | | * @return 是否存在重复任务 |
| | | */ |
| | | @GetMapping("/checkDuplicate") |
| | | public AjaxResult checkDuplicate( |
| | | @RequestParam("phone") String phone, |
| | | @RequestParam("createDate") String createDate) { |
| | | |
| | | if (StringUtils.isEmpty(phone) || StringUtils.isEmpty(createDate)) { |
| | | return AjaxResult.error("参数不能为空"); |
| | | } |
| | | |
| | | boolean isDuplicate = sysTaskService.checkTaskDuplicate(phone, createDate); |
| | | |
| | | if (isDuplicate) { |
| | | return AjaxResult.error("该联系电话在该日期已有任务,不能重复提交"); |
| | | } |
| | | |
| | | return AjaxResult.success("未发现重复任务"); |
| | | } |
| | | |
| | | /** |
| | |
| | | @Log(title = "任务管理", businessType = BusinessType.UPDATE) |
| | | @PutMapping("/admin") |
| | | public AjaxResult adminEdit(@RequestBody TaskUpdateVO updateVO) { |
| | | return toAjax(sysTaskService.updateSysTask(updateVO)); |
| | | return toAjax(sysTaskService.updateSysTask(updateVO,false)); |
| | | } |
| | | |
| | | /** |
| | |
| | | @Log(title = "任务修改", businessType = BusinessType.UPDATE) |
| | | @PutMapping |
| | | public AjaxResult appEdit(@RequestBody TaskUpdateVO updateVO) { |
| | | return toAjax(sysTaskService.updateSysTask(updateVO)); |
| | | return toAjax(sysTaskService.updateSysTask(updateVO,false)); |
| | | } |
| | | |
| | | /** |
| | |
| | | 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)); |
| | | // 如果是取消状态,保存取消原因 |
| | | if (newStatus == TaskStatus.CANCELLED && StringUtils.isNotEmpty(request.getCancelReason())) { |
| | | sysTaskService.saveCancelInfo(taskId, request.getCancelReason()); |
| | | } |
| | | |
| | | // 如果是强制完成,更新实际开始时间和结束时间 |
| | | if (newStatus == TaskStatus.COMPLETED && request.getActualStartTime() != null && request.getActualEndTime() != null) { |
| | | SysTask task = new SysTask(); |
| | | task.setTaskId(taskId); |
| | | task.setTaskStatus(newStatus.getCode()); |
| | | //将String转成Date |
| | | |
| | | task.setActualStartTime(DateUtils.parseDate(request.getActualStartTime())); |
| | | task.setActualEndTime(DateUtils.parseDate(request.getActualEndTime())); |
| | | task.setRemark(request.getRemark()); |
| | | task.setUpdateBy(SecurityUtils.getUsername()); |
| | | task.setUpdateTime(DateUtils.getNowDate()); |
| | | |
| | | int result = sysTaskService.forceCompleteTask(task); |
| | | return toAjax(result); |
| | | } |
| | | |
| | | // 如果包含GPS位置信息,使用带位置的方法 |
| | | if (request.getLatitude() != null && request.getLongitude() != null) { |
| | | String address= mapService.reverseGeocoding(request.getLongitude(), request.getLatitude()); |
| | | request.setLocationAddress(address); |
| | | SysTaskLog locationLog = getLocationLog(request); |
| | | |
| | | return toAjax(sysTaskService.changeTaskStatusWithLocation(taskId, newStatus, request.getRemark(), locationLog)); |
| | | } |
| | | |
| | | return toAjax(sysTaskService.changeTaskStatus(taskId, newStatus, request.getRemark())); |
| | | } |
| | | |
| | | private static SysTaskLog getLocationLog(ChangeStatusRequest request) { |
| | | 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 locationLog; |
| | | } |
| | | |
| | | /** |
| | |
| | | } |
| | | |
| | | /** |
| | | * 检查车辆是否有正在进行中的任务(APP端) |
| | | * 正在进行中的任务是指状态不为:PENDING(待处理)、COMPLETED(已完成)、CANCELLED(已取消)的任务 |
| | | */ |
| | | @GetMapping("/vehicle/{vehicleId}/active") |
| | | public AjaxResult checkVehicleActiveTasks(@PathVariable Long vehicleId) { |
| | | List<SysTask> activeTasks = sysTaskService.checkVehicleActiveTasks(vehicleId); |
| | | return success(activeTasks); |
| | | } |
| | | |
| | | /** |
| | | * 检查任务是否可以出发(APP端) |
| | | * 检查: |
| | | * 1. 车辆是否有未完成的任务 |
| | | * 2. 执行人员是否有未完成的任务 |
| | | * |
| | | * @param taskId 任务ID |
| | | * @return 校验结果 |
| | | */ |
| | | @GetMapping("/{taskId}/check-depart") |
| | | public AjaxResult checkTaskCanDepart(@PathVariable Long taskId) { |
| | | return sysTaskService.checkTaskCanDepart(taskId); |
| | | } |
| | | |
| | | /** |
| | | * 执行人点击就绪(APP端) |
| | | */ |
| | | @PostMapping("/{taskId}/assignee/ready") |
| | | public AjaxResult setAssigneeReady(@PathVariable Long taskId) { |
| | | Long userId = getUserId(); |
| | | return sysTaskService.setAssigneeReady(taskId, userId); |
| | | } |
| | | |
| | | /** |
| | | * 执行人取消就绪(APP端) |
| | | */ |
| | | @PostMapping("/{taskId}/assignee/cancel-ready") |
| | | public AjaxResult cancelAssigneeReady(@PathVariable Long taskId) { |
| | | Long userId = getUserId(); |
| | | return sysTaskService.cancelAssigneeReady(taskId, userId); |
| | | } |
| | | |
| | | /** |
| | | * 分配任务请求对象 |
| | | */ |
| | | public static class AssignTaskRequest { |
| | |
| | | private Double altitude; |
| | | private Double speed; |
| | | private Double heading; |
| | | |
| | | // 取消相关字段 |
| | | private String cancelReason; // 取消原因(关联数据字典task_cancel_reason) |
| | | |
| | | // 强制完成相关字段 |
| | | @JsonFormat(pattern = "yyyy-MM-dd HH:mm") |
| | | private String actualStartTime; // 实际开始时间 |
| | | @JsonFormat(pattern = "yyyy-MM-dd HH:mm") |
| | | private String actualEndTime; // 实际结束时间 |
| | | |
| | | public String getTaskStatus() { |
| | | return taskStatus; |
| | |
| | | public void setHeading(Double heading) { |
| | | this.heading = heading; |
| | | } |
| | | |
| | | public String getCancelReason() { |
| | | return cancelReason; |
| | | } |
| | | |
| | | public void setCancelReason(String cancelReason) { |
| | | this.cancelReason = cancelReason; |
| | | } |
| | | |
| | | public String getActualStartTime() { |
| | | return actualStartTime; |
| | | } |
| | | |
| | | public void setActualStartTime(String actualStartTime) { |
| | | this.actualStartTime = actualStartTime; |
| | | } |
| | | |
| | | public String getActualEndTime() { |
| | | return actualEndTime; |
| | | } |
| | | |
| | | public void setActualEndTime(String actualEndTime) { |
| | | this.actualEndTime = actualEndTime; |
| | | } |
| | | } |
| | | } |