| | |
| | | package com.ruoyi.web.controller.api; |
| | | |
| | | |
| | | import com.alibaba.fastjson.JSONArray; |
| | | import com.alibaba.fastjson.JSONObject; |
| | | import com.baomidou.mybatisplus.core.toolkit.Wrappers; |
| | | import com.ruoyi.common.annotation.Log; |
| | | import com.ruoyi.common.core.domain.R; |
| | | import com.ruoyi.common.enums.BusinessType; |
| | | import com.ruoyi.system.applet.dto.AppealDTO; |
| | | import com.ruoyi.system.dto.TTaskAuditBatchDTO; |
| | | import com.ruoyi.system.dto.TaskDetailDto; |
| | | import com.ruoyi.system.model.TAppeal; |
| | | import com.ruoyi.system.model.TLocation; |
| | | import com.ruoyi.system.model.TTask; |
| | | import com.ruoyi.system.model.TTaskDetail; |
| | | import com.ruoyi.system.service.TAppealService; |
| | | import com.ruoyi.system.service.TLocationService; |
| | | import com.ruoyi.system.service.TTaskCleanService; |
| | | import com.ruoyi.system.service.TTaskDetailService; |
| | | import com.ruoyi.web.controller.tool.AmapApiClient; |
| | | import com.ruoyi.web.controller.tool.GeoChecker; |
| | | import com.ruoyi.web.controller.tool.PathParser; |
| | | import io.swagger.annotations.Api; |
| | | import io.swagger.annotations.ApiOperation; |
| | | import org.springframework.beans.factory.annotation.Autowired; |
| | |
| | | import org.springframework.web.bind.annotation.RestController; |
| | | |
| | | import javax.validation.Valid; |
| | | import java.math.BigDecimal; |
| | | import java.time.LocalDateTime; |
| | | import java.util.ArrayList; |
| | | import java.util.List; |
| | |
| | | private TTaskCleanService taskService; |
| | | @Autowired |
| | | private TAppealService appealService; |
| | | @Autowired |
| | | private TLocationService locationService; |
| | | |
| | | @ApiOperation(value = "上传任务") |
| | | @PostMapping(value = "/uploadTask") |
| | | public R<Boolean> uploadTask(@RequestBody TTaskDetail dto) { |
| | | public R<Boolean> uploadTask(@RequestBody TaskDetailDto dto) { |
| | | double radius = 50; // 单位:米 |
| | | int segments = 4; // 四段,共 5 个点 |
| | | TTask task = taskService.getById(dto.getTaskId()); |
| | | if (task==null)return R.fail("任务不存在"); |
| | | TLocation location = locationService.getById(task.getLocationId()); |
| | | if (location==null)return R.fail("点位不存在"); |
| | | try { |
| | | String routeJson = AmapApiClient.getDrivingRoute(Double.parseDouble(location.getLocationLat()), |
| | | Double.parseDouble(location.getLocationLon()), |
| | | Double.parseDouble(location.getLocationLatEnd()), |
| | | Double.parseDouble(location.getLocationLonEnd())); |
| | | // 转化为json对象 |
| | | JSONObject jsonObject = JSONObject.parseObject(routeJson); |
| | | JSONObject route = jsonObject.getJSONObject("route"); |
| | | JSONArray paths = route.getJSONArray("paths"); |
| | | JSONObject o = (JSONObject)paths.get(0); |
| | | BigDecimal distance = o.getBigDecimal("distance"); |
| | | System.err.println( paths); |
| | | List<double[]> fivePoints = PathParser.parseAndInterpolate(routeJson, segments, |
| | | Double.parseDouble(location.getLocationLat()), |
| | | Double.parseDouble(location.getLocationLon()), |
| | | Double.parseDouble(location.getLocationLatEnd()), |
| | | Double.parseDouble(location.getLocationLonEnd())); |
| | | |
| | | if (GeoChecker.isInAnyCircle(Double.parseDouble(dto.getLat()), Double.parseDouble(dto.getLon()), |
| | | fivePoints, radius)) { |
| | | System.out.println("✅ 成功!您位于某个圆形电子围栏范围内。"); |
| | | } else { |
| | | System.out.println("❌ 失败!您不在任何圆形电子围栏范围内。"); |
| | | return R.fail("位置信息与点位不一致,请点击此处更新定位"); |
| | | } |
| | | } catch (Exception e) { |
| | | e.printStackTrace(); |
| | | } |
| | | taskDetailService.save(dto); |
| | | // 修改任务状态 |
| | | taskService.update(Wrappers.<TTask>lambdaUpdate().set(TTask::getStatus, 3).eq(TTask::getId, dto.getTaskId())); |
| | |
| | | |
| | | @ApiOperation(value = "申诉") |
| | | @PostMapping(value = "/appeal") |
| | | public R<Boolean> appeal(@RequestBody TAppeal dto) { |
| | | public R<Boolean> appeal(@RequestBody AppealDTO dto) { |
| | | appealService.save(dto); |
| | | // 添加任务详情 |
| | | TTaskDetail taskDetail = new TTaskDetail(); |