| | |
| | | import com.baomidou.mybatisplus.extension.plugins.pagination.Page; |
| | | import com.ruoyi.common.core.constant.Constants; |
| | | import com.ruoyi.common.core.domain.R; |
| | | import com.ruoyi.common.core.domain.Result; |
| | | import com.ruoyi.common.core.exception.GlobalException; |
| | | import com.ruoyi.common.core.utils.DateUtils; |
| | | import com.ruoyi.common.core.utils.GaoDeMapUtil; |
| | | import com.ruoyi.common.redis.service.RedisService; |
| | | import com.ruoyi.common.security.service.TokenService; |
| | | import com.ruoyi.order.api.entity.ChangeDispatch; |
| | | import com.ruoyi.order.api.entity.Order; |
| | |
| | | import com.ruoyi.system.api.model.LoginUserInfo; |
| | | import com.ruoyi.worker.entity.MasterWorker; |
| | | import com.ruoyi.worker.entity.RecoveryServe; |
| | | import com.ruoyi.worker.entity.ServeCoordinate; |
| | | import com.ruoyi.worker.service.MasterWorkerService; |
| | | import com.ruoyi.worker.service.RecoveryServeService; |
| | | import com.ruoyi.worker.vo.ServeCoordinate; |
| | | import io.swagger.annotations.Api; |
| | | import io.swagger.annotations.ApiImplicitParam; |
| | | import io.swagger.annotations.ApiImplicitParams; |
| | | import io.swagger.annotations.ApiOperation; |
| | | import org.springframework.transaction.annotation.Transactional; |
| | | import org.springframework.web.bind.annotation.*; |
| | | |
| | | import javax.annotation.Resource; |
| | | import java.io.File; |
| | | import java.io.FileWriter; |
| | | import java.io.IOException; |
| | | import java.nio.file.Files; |
| | | import java.nio.file.Paths; |
| | | import java.util.ArrayList; |
| | | import java.util.HashSet; |
| | | import java.util.List; |
| | | import java.util.Map; |
| | | import java.util.Optional; |
| | | import java.util.Set; |
| | | import java.util.stream.Collectors; |
| | | import javax.annotation.Resource; |
| | | import org.springframework.transaction.annotation.Transactional; |
| | | import org.springframework.web.bind.annotation.GetMapping; |
| | | import org.springframework.web.bind.annotation.PostMapping; |
| | | 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; |
| | | |
| | | /** |
| | | * <p> |
| | |
| | | @Resource |
| | | private RecoveryServeService recoveryServeService; |
| | | |
| | | @Resource |
| | | private RedisService redisService; |
| | | |
| | | /** |
| | | * linux服务器保存订单轨迹文件夹 |
| | | */ |
| | | private static final String BASE_PATH = "/usr/local/coordinate/"; |
| | | // private static final String BASE_PATH = "/usr/local/coordinate/"; |
| | | private static final String BASE_PATH = "F:/DeskTop/coordinate/"; |
| | | // private static final String BASE_MARKER_PATH = "/usr/local/marker/"; |
| | | // private static final String BASE_PATH = "D:/Desktop/coordinate/"; |
| | | |
| | | private static final String BASE_MARKER_PATH = "F:/DeskTop/marker/"; |
| | | /** |
| | | * 师傅端-获取订单列表 |
| | | * |
| | |
| | | List<Integer> ids = orderList.stream().map(Order::getServeId).collect(Collectors.toList()); |
| | | if (!ids.isEmpty()) { |
| | | List<RecoveryServe> serveList = recoveryServeService.lambdaQuery() |
| | | .in(RecoveryServe::getId, ids).eq(RecoveryServe::getIsDelete, 0).list(); |
| | | .in(RecoveryServe::getId, ids).list(); |
| | | Map<Integer, String> map = serveList.stream().collect(Collectors.toMap(RecoveryServe::getId, |
| | | mw -> Optional.ofNullable(mw.getCover()).orElse(""))); |
| | | for (Order order : orderList) { |
| | | order.setCover(map.get(order.getServeId())); |
| | | if (order.getAddress()!=null) { |
| | | order.setReservationAddress(order.getReservationAddress() + order.getAddress()); |
| | | } |
| | | } |
| | | } |
| | | return R.ok(dataList); |
| | |
| | | /** |
| | | * 师傅端-定时调度记录师傅所走路线经纬度 |
| | | * |
| | | * @param orderId 订单id |
| | | * @param longitude 经度 |
| | | * @param latitude 纬度 |
| | | */ |
| | | @ApiOperation(value = "订单进行-记录路线经纬度", tags = {"师傅端-订单列表"}) |
| | | @ApiOperation(value = "订单进行-记录全天路线经纬度", tags = {"师傅端-订单列表"}) |
| | | @GetMapping(value = "/coordinate") |
| | | @ApiImplicitParams({ |
| | | @ApiImplicitParam(value = "订单id", name = "orderId", dataType = "String", required = true), |
| | | @ApiImplicitParam(value = "经度", name = "longitude", dataType = "Integer", required = true), |
| | | @ApiImplicitParam(value = "纬度", name = "latitude", dataType = "Integer", required = true) |
| | | }) |
| | | public R<Boolean> coordinate(@RequestParam String orderId, @RequestParam Double longitude, |
| | | @RequestParam Double latitude) { |
| | | public R<Boolean> coordinate(@RequestParam Double longitude, @RequestParam Double latitude) { |
| | | LoginUserInfo loginWorker = tokenService.getLoginUserByWorker(); |
| | | if (null == loginWorker) { |
| | | return R.loginExpire("登录失效!"); |
| | | } |
| | | // 获取当天时间 |
| | | String today = DateUtils.dateTimeNow("yyyy-MM-dd"); |
| | | Integer workerId = loginWorker.getUserid(); |
| | | ServeCoordinate serveCoordinate = new ServeCoordinate(); |
| | | serveCoordinate.setWorkerId(workerId); |
| | | serveCoordinate.setOrderId(orderId); |
| | | serveCoordinate.setDate(today); |
| | | serveCoordinate.setCoordinate(longitude + "," + latitude); |
| | | serveCoordinate.setLongitude(longitude); |
| | | serveCoordinate.setLatitude(latitude); |
| | |
| | | // 创建师傅ID的文件夹 |
| | | masterFolder.mkdirs(); |
| | | } |
| | | |
| | | // 检查订单ID的JSON文件是否存在,不存在则创建 |
| | | String jsonFilePath = masterFolderPath + "/" + orderId + ".json"; |
| | | String jsonFilePath = masterFolderPath + "/" + today + ".json"; |
| | | File jsonFile = new File(jsonFilePath); |
| | | if (!jsonFile.exists()) { |
| | | try { |
| | |
| | | // 订单轨迹信息 |
| | | ServeCoordinate data = new ServeCoordinate(); |
| | | data.setWorkerId(workerId); |
| | | data.setOrderId(orderId); |
| | | data.setDate(today); |
| | | data.setCoordinate(longitude + "," + latitude); |
| | | data.setLongitude(longitude); |
| | | data.setLatitude(latitude); |
| | |
| | | } |
| | | return R.ok(); |
| | | } |
| | | /** |
| | | * 师傅端-定时调度记录师傅当天的轨迹标点 |
| | | * |
| | | * @param longitude 经度 |
| | | * @param latitude 纬度 |
| | | */ |
| | | @ApiOperation(value = "订单进行-记录当天的轨迹标点", tags = {"师傅端-订单列表"}) |
| | | @GetMapping(value = "/marker") |
| | | @ApiImplicitParams({ |
| | | @ApiImplicitParam(value = "经度", name = "longitude", dataType = "Integer", required = true), |
| | | @ApiImplicitParam(value = "纬度", name = "latitude", dataType = "Integer", required = true) |
| | | }) |
| | | public R<Boolean> marker(@RequestParam Double longitude, @RequestParam Double latitude) { |
| | | LoginUserInfo loginWorker = tokenService.getLoginUserByWorker(); |
| | | if (null == loginWorker) { |
| | | return R.loginExpire("登录失效!"); |
| | | } |
| | | // 获取当天时间 |
| | | String today = DateUtils.dateTimeNow("yyyy-MM-dd"); |
| | | Integer workerId = 1; |
| | | // Integer workerId = loginWorker.getUserid(); |
| | | ServeCoordinate serveCoordinate = new ServeCoordinate(); |
| | | serveCoordinate.setWorkerId(workerId); |
| | | serveCoordinate.setDate(today); |
| | | serveCoordinate.setCoordinate(longitude + "," + latitude); |
| | | serveCoordinate.setLongitude(longitude); |
| | | serveCoordinate.setLatitude(latitude); |
| | | List<ServeCoordinate> list = new ArrayList<>(); |
| | | list.add(serveCoordinate); |
| | | String jsonString = JSONObject.toJSONString(list); |
| | | // 检查师傅ID的文件夹是否存在,不存在则创建 |
| | | String masterFolderPath = BASE_MARKER_PATH + workerId; |
| | | File masterFolder = new File(masterFolderPath); |
| | | if (!masterFolder.exists()) { |
| | | // 创建师傅ID的文件夹 |
| | | masterFolder.mkdirs(); |
| | | } |
| | | |
| | | // 检查今天的JSON文件是否存在,不存在则创建 |
| | | String jsonFilePath = masterFolderPath + "/" + today + ".json"; |
| | | File jsonFile = new File(jsonFilePath); |
| | | if (!jsonFile.exists()) { |
| | | try { |
| | | // 创建今天的JSON文件 |
| | | jsonFile.createNewFile(); |
| | | // 首次记录标点 |
| | | FileWriter writer = new FileWriter(jsonFile); |
| | | writer.write(jsonString); |
| | | writer.close(); |
| | | } catch (IOException e) { |
| | | return R.fail(e.getMessage()); |
| | | } |
| | | } else { |
| | | // 读取订单ID的JSON文件内容 |
| | | try { |
| | | String jsonContent = new String(Files.readAllBytes(Paths.get(jsonFilePath))); |
| | | System.out.println("JSON 文件内容:" + jsonContent); |
| | | List<ServeCoordinate> coordinate = JSONObject.parseObject(jsonContent, List.class); |
| | | // 订单轨迹信息 |
| | | ServeCoordinate data = new ServeCoordinate(); |
| | | data.setWorkerId(workerId); |
| | | data.setDate(today); |
| | | data.setCoordinate(longitude + "," + latitude); |
| | | data.setLongitude(longitude); |
| | | data.setLatitude(latitude); |
| | | coordinate.add(data); |
| | | String itemStr = JSONObject.toJSONString(coordinate); |
| | | FileWriter writer = new FileWriter(jsonFile); |
| | | writer.write(itemStr); |
| | | writer.close(); |
| | | } catch (IOException e) { |
| | | return R.fail(e.getMessage()); |
| | | } |
| | | } |
| | | return R.ok(); |
| | | } |
| | | |
| | | @ApiOperation(value = "上传经纬度", tags = {"师傅端-首页"}) |
| | | @GetMapping(value = "/putLocation") |
| | | @ApiImplicitParams({ |
| | | @ApiImplicitParam(value = "workId", name = "workId", dataType = "int", required = true), |
| | | @ApiImplicitParam(value = "师傅所在经度", name = "longitude", dataType = "String", required = true), |
| | | @ApiImplicitParam(value = "师傅所在纬度", name = "latitude", dataType = "String", required = true) |
| | | }) |
| | | public R<Object> orderNavigation(@RequestParam Integer workId, @RequestParam String longitude, |
| | | @RequestParam String latitude) { |
| | | Result<String> address = GaoDeMapUtil.getCityCode(longitude, latitude); |
| | | System.err.println(address.getDatas()); |
| | | Set<Integer> strings = new HashSet<>(); |
| | | strings.add(workId); |
| | | redisService.setCacheSet("workerLocation:"+address.getDatas()+":", strings); |
| | | redisService.setCacheObject("work:"+workId+":", longitude+","+latitude); |
| | | return R.ok(); |
| | | |
| | | } |
| | | |
| | | } |