|  |  |  | 
|---|
|  |  |  | package com.ruoyi.worker.controller; | 
|---|
|  |  |  |  | 
|---|
|  |  |  |  | 
|---|
|  |  |  | import cn.afterturn.easypoi.cache.manager.IFileLoader; | 
|---|
|  |  |  | import com.alibaba.fastjson2.JSONObject; | 
|---|
|  |  |  | import com.baomidou.mybatisplus.core.toolkit.Wrappers; | 
|---|
|  |  |  | import com.baomidou.mybatisplus.extension.plugins.pagination.Page; | 
|---|
|  |  |  | import com.ruoyi.admin.api.feignClient.AdminClient; | 
|---|
|  |  |  | 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.order.api.feignClient.ExchangeDispatchClient; | 
|---|
|  |  |  | import com.ruoyi.order.api.feignClient.OrderClient; | 
|---|
|  |  |  | import com.ruoyi.system.api.model.LoginUserInfo; | 
|---|
|  |  |  | import com.ruoyi.worker.entity.IamConfig; | 
|---|
|  |  |  | import com.ruoyi.worker.entity.MasterWorker; | 
|---|
|  |  |  | import com.ruoyi.worker.entity.OrderRecording; | 
|---|
|  |  |  | import com.ruoyi.worker.entity.RecoveryServe; | 
|---|
|  |  |  | import com.ruoyi.worker.entity.ServeCoordinate; | 
|---|
|  |  |  | import com.ruoyi.worker.service.IamConfigService; | 
|---|
|  |  |  | import com.ruoyi.worker.service.MasterWorkerService; | 
|---|
|  |  |  | import com.ruoyi.worker.service.OrderRecordingService; | 
|---|
|  |  |  | import com.ruoyi.worker.service.RecoveryServeService; | 
|---|
|  |  |  | import com.ruoyi.worker.vo.ServeCoordinate; | 
|---|
|  |  |  | import com.ruoyi.worker.voice.util.AXBUtil; | 
|---|
|  |  |  | 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.List; | 
|---|
|  |  |  | import java.util.Map; | 
|---|
|  |  |  | import java.util.Optional; | 
|---|
|  |  |  | import java.time.Duration; | 
|---|
|  |  |  | import java.time.LocalDateTime; | 
|---|
|  |  |  | import java.time.format.DateTimeFormatter; | 
|---|
|  |  |  | import java.util.*; | 
|---|
|  |  |  | import java.util.concurrent.TimeUnit; | 
|---|
|  |  |  | import java.util.stream.Collectors; | 
|---|
|  |  |  | import javax.annotation.Resource; | 
|---|
|  |  |  |  | 
|---|
|  |  |  | import lombok.Synchronized; | 
|---|
|  |  |  | import org.springframework.transaction.annotation.Transactional; | 
|---|
|  |  |  | import org.springframework.util.CollectionUtils; | 
|---|
|  |  |  | import org.springframework.util.StringUtils; | 
|---|
|  |  |  | 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; | 
|---|
|  |  |  | @Resource | 
|---|
|  |  |  | private IamConfigService iamConfigService; | 
|---|
|  |  |  | @Resource | 
|---|
|  |  |  | private OrderRecordingService orderRecordingService; | 
|---|
|  |  |  |  | 
|---|
|  |  |  | /** | 
|---|
|  |  |  | * 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/"; | 
|---|
|  |  |  | /** | 
|---|
|  |  |  | * 师傅端-获取订单列表 | 
|---|
|  |  |  | * | 
|---|
|  |  |  | * @param state 订单状态(0:全部、1:待上门、2:已完结) | 
|---|
|  |  |  | */ | 
|---|
|  |  |  | @ApiOperation(value = "订单列表", tags = {"师傅端-订单列表"}) | 
|---|
|  |  |  | @ApiOperation(value = "订单列表", tags = {"师傅端-订单列表[2.0]"}) | 
|---|
|  |  |  | @GetMapping(value = "/orderList") | 
|---|
|  |  |  | @ApiImplicitParams({ | 
|---|
|  |  |  | @ApiImplicitParam(value = "订单状态(0:全部、1:待上门、2:已完结)", name = "state", dataType = "Integer", required = true) | 
|---|
|  |  |  | @ApiImplicitParam(value = "订单状态(0:全部、1:待上门、2:已完结、7:待预约)", name = "state", dataType = "Integer", required = true), | 
|---|
|  |  |  | @ApiImplicitParam(value = "姓名,电话,地址搜索", name = "searchValues", dataType = "String", required = false), | 
|---|
|  |  |  | }) | 
|---|
|  |  |  | public R<Page<Order>> orderList(@RequestParam Integer state, | 
|---|
|  |  |  | @RequestParam String searchValues, | 
|---|
|  |  |  | @RequestParam(name = "pageNum", defaultValue = "1") Integer pageNum, | 
|---|
|  |  |  | @RequestParam(name = "pageSize", defaultValue = "10") Integer pageSize) { | 
|---|
|  |  |  | LoginUserInfo loginWorker = tokenService.getLoginUserByWorker(); | 
|---|
|  |  |  | if (null == loginWorker) { | 
|---|
|  |  |  | return R.loginExpire("登录失效!"); | 
|---|
|  |  |  | } | 
|---|
|  |  |  | Page<Order> dataList = orderClient.orderListWorker(loginWorker.getUserid(), state, pageNum, pageSize).getData(); | 
|---|
|  |  |  | Page<Order> dataList = orderClient.orderListWorker(loginWorker.getUserid(), state,searchValues, pageNum, pageSize).getData(); | 
|---|
|  |  |  | List<Order> orderList = dataList.getRecords(); | 
|---|
|  |  |  | List<Integer> ids = orderList.stream().map(Order::getServeId).collect(Collectors.toList()); | 
|---|
|  |  |  | if (!ids.isEmpty()) { | 
|---|
|  |  |  | 
|---|
|  |  |  | 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); | 
|---|
|  |  |  | 
|---|
|  |  |  | if (null == loginWorker) { | 
|---|
|  |  |  | return R.loginExpire("登录失效!"); | 
|---|
|  |  |  | } | 
|---|
|  |  |  | return orderClient.orderSubmit(orderSubmitRequest); | 
|---|
|  |  |  | R<String> result = orderClient.orderSubmit(orderSubmitRequest); | 
|---|
|  |  |  | String subscriptionId = result.getData(); | 
|---|
|  |  |  | boolean flag = false; | 
|---|
|  |  |  | if (StringUtils.hasLength(subscriptionId)) { | 
|---|
|  |  |  | IamConfig iamConfig = iamConfigService.getById(1); | 
|---|
|  |  |  | // 查询音频链接 | 
|---|
|  |  |  | OrderDetailVO data = orderClient.orderDetail(orderSubmitRequest.getOrderId()).getData(); | 
|---|
|  |  |  | if(Objects.nonNull(data)){ | 
|---|
|  |  |  | Order orderInfo = data.getOrderInfo(); | 
|---|
|  |  |  | if (Objects.nonNull(orderInfo) && Objects.nonNull(orderInfo.getIsOpenVirtualNumber()) && orderInfo.getIsOpenVirtualNumber() == 1){ | 
|---|
|  |  |  | //                    List<OrderRecording> orderRecordingList = orderRecordingService.list(Wrappers.lambdaQuery(OrderRecording.class) | 
|---|
|  |  |  | //                            .eq(OrderRecording::getOrderId, orderInfo.getId())); | 
|---|
|  |  |  | //                    if(!CollectionUtils.isEmpty(orderRecordingList)){ | 
|---|
|  |  |  | //                        for (OrderRecording orderRecording : orderRecordingList) { | 
|---|
|  |  |  | //                            String recordDomain = orderRecording.getRecordDomain(); | 
|---|
|  |  |  | //                            String recordObjectName = orderRecording.getRecordObjectName(); | 
|---|
|  |  |  | //                            String audioUrl = AXBUtil.axbGetRecordDownloadLink(iamConfig.getAppKey(), iamConfig.getAppSecret(),recordDomain, recordObjectName); | 
|---|
|  |  |  | //                            orderRecording.setPhoneRecording(audioUrl); | 
|---|
|  |  |  | ////                            // 设置音频 | 
|---|
|  |  |  | ////                            orderClient.updatePhoneRecording(orderInfo.getId(), audioUrl); | 
|---|
|  |  |  | //                        } | 
|---|
|  |  |  | //                        orderRecordingService.updateBatchById(orderRecordingList); | 
|---|
|  |  |  | //                    } | 
|---|
|  |  |  | // 虚拟号码解绑 | 
|---|
|  |  |  | AXBUtil.axbUnbindNumber(iamConfig.getAppKey(), iamConfig.getAppSecret(),subscriptionId, iamConfig.getVirtualNumber()); | 
|---|
|  |  |  | } | 
|---|
|  |  |  | } | 
|---|
|  |  |  | flag = true; | 
|---|
|  |  |  | } | 
|---|
|  |  |  | return R.ok(flag); | 
|---|
|  |  |  | } | 
|---|
|  |  |  |  | 
|---|
|  |  |  | private static final double EARTH_RADIUS_METERS = 6371000.0; | 
|---|
|  |  |  | /** | 
|---|
|  |  |  | * 师傅端-定时调度记录师傅所走路线经纬度 | 
|---|
|  |  |  | * | 
|---|
|  |  |  | * @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) { | 
|---|
|  |  |  | @Synchronized | 
|---|
|  |  |  | public R<Boolean> coordinate(@RequestParam Double longitude, @RequestParam Double latitude) { | 
|---|
|  |  |  |  | 
|---|
|  |  |  | System.err.println("调用记录经纬度"+ LocalDateTime.now()); | 
|---|
|  |  |  |  | 
|---|
|  |  |  | LoginUserInfo loginWorker = tokenService.getLoginUserByWorker(); | 
|---|
|  |  |  | if (null == loginWorker) { | 
|---|
|  |  |  | return R.loginExpire("登录失效!"); | 
|---|
|  |  |  | } | 
|---|
|  |  |  | Object cacheObject2 = redisService.getCacheObject("LOCK" + loginWorker.getUserid()); | 
|---|
|  |  |  | if (cacheObject2!=null){ | 
|---|
|  |  |  | return R.ok(); | 
|---|
|  |  |  | }else { | 
|---|
|  |  |  | redisService.setCacheObject("LOCK" + loginWorker.getUserid(),"1", 10L, TimeUnit.SECONDS); | 
|---|
|  |  |  | } | 
|---|
|  |  |  |  | 
|---|
|  |  |  | // 获取当天时间 | 
|---|
|  |  |  | 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 { | 
|---|
|  |  |  | 
|---|
|  |  |  | // 读取订单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.setOrderId(orderId); | 
|---|
|  |  |  | 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()); | 
|---|
|  |  |  | } | 
|---|
|  |  |  | } | 
|---|
|  |  |  |  | 
|---|
|  |  |  |  | 
|---|
|  |  |  | //拿到三十分钟之前的时间,并已 yyyy-MM-dd HH:mm格式存储 | 
|---|
|  |  |  | // 当前时间 | 
|---|
|  |  |  | LocalDateTime now = LocalDateTime.now(); | 
|---|
|  |  |  |  | 
|---|
|  |  |  | // 减去三十分钟 | 
|---|
|  |  |  | LocalDateTime thirtyMinutesAgo = now.minusMinutes(5); | 
|---|
|  |  |  |  | 
|---|
|  |  |  | // 定义日期时间格式 | 
|---|
|  |  |  | DateTimeFormatter formatter = DateTimeFormatter.ofPattern("yyyy-MM-dd HH:mm"); | 
|---|
|  |  |  |  | 
|---|
|  |  |  | // 格式化时间 | 
|---|
|  |  |  | String formattedTime = thirtyMinutesAgo.format(formatter); | 
|---|
|  |  |  | String nowStr = now.format(formatter); | 
|---|
|  |  |  |  | 
|---|
|  |  |  |  | 
|---|
|  |  |  | redisService.setCacheObject("MARK:"+workerId+":"+nowStr,longitude + "," + latitude, 10L, TimeUnit.MINUTES); | 
|---|
|  |  |  |  | 
|---|
|  |  |  | String cacheObject = redisService.getCacheObject("MARK:" + workerId + ":" + formattedTime); | 
|---|
|  |  |  | if (cacheObject!=null){ | 
|---|
|  |  |  |  | 
|---|
|  |  |  | String cacheObject1 = redisService.getCacheObject("TIME:" + workerId); | 
|---|
|  |  |  | if (cacheObject1==null){ | 
|---|
|  |  |  | cacheObject1 = "2000-09-06 20:24:10.740"; | 
|---|
|  |  |  | } | 
|---|
|  |  |  | // 定义日期时间格式 | 
|---|
|  |  |  | DateTimeFormatter formatter1 = DateTimeFormatter.ofPattern("yyyy-MM-dd HH:mm:ss.SSS"); | 
|---|
|  |  |  |  | 
|---|
|  |  |  | // 解析字符串为 LocalDateTime | 
|---|
|  |  |  | LocalDateTime localDateTime = LocalDateTime.parse(cacheObject1, formatter1); | 
|---|
|  |  |  | if (isWithinTwoMinutes(localDateTime, now)){ | 
|---|
|  |  |  | //计算两点之间的距离 | 
|---|
|  |  |  | String[] split = cacheObject.split(","); | 
|---|
|  |  |  | String longitude1 = split[0]; | 
|---|
|  |  |  | String latitude1 = split[1]; | 
|---|
|  |  |  | double longitude1Double = Double.parseDouble(longitude1); | 
|---|
|  |  |  | double latitude1Double = Double.parseDouble(latitude1); | 
|---|
|  |  |  | double lat1Rad = Math.toRadians(latitude); | 
|---|
|  |  |  | double lon1Rad = Math.toRadians(longitude); | 
|---|
|  |  |  | double lat2Rad = Math.toRadians(latitude1Double); | 
|---|
|  |  |  | double lon2Rad = Math.toRadians(longitude1Double); | 
|---|
|  |  |  |  | 
|---|
|  |  |  | // 计算经纬度差值 | 
|---|
|  |  |  | double dlon = lon2Rad - lon1Rad; | 
|---|
|  |  |  | double dlat = lat2Rad - lat1Rad; | 
|---|
|  |  |  |  | 
|---|
|  |  |  | // Haversine 公式 | 
|---|
|  |  |  | double a = Math.pow(Math.sin(dlat / 2), 2) + | 
|---|
|  |  |  | Math.cos(lat1Rad) * Math.cos(lat2Rad) * | 
|---|
|  |  |  | Math.pow(Math.sin(dlon / 2), 2); | 
|---|
|  |  |  | double c = 2 * Math.atan2(Math.sqrt(a), Math.sqrt(1 - a)); | 
|---|
|  |  |  | // 计算距离 | 
|---|
|  |  |  | double distance = EARTH_RADIUS_METERS * c; | 
|---|
|  |  |  | System.err.println("-----当前距离"+distance); | 
|---|
|  |  |  | //如果超出一定范围,存入Mark文件 | 
|---|
|  |  |  | if (distance<50){ | 
|---|
|  |  |  | redisService.setCacheObject("TIME:"+workerId,LocalDateTime.now(), 10L, TimeUnit.MINUTES); | 
|---|
|  |  |  | marker(longitude,latitude); | 
|---|
|  |  |  | } | 
|---|
|  |  |  | } | 
|---|
|  |  |  | } | 
|---|
|  |  |  |  | 
|---|
|  |  |  |  | 
|---|
|  |  |  | redisService.deleteObject("LOCK" + loginWorker.getUserid()); | 
|---|
|  |  |  | return R.ok(); | 
|---|
|  |  |  | } | 
|---|
|  |  |  |  | 
|---|
|  |  |  | public static boolean isWithinTwoMinutes(LocalDateTime dateTime1, LocalDateTime dateTime2) { | 
|---|
|  |  |  | // 计算两个时间之间的差值 | 
|---|
|  |  |  | Duration duration = Duration.between(dateTime1, dateTime2); | 
|---|
|  |  |  |  | 
|---|
|  |  |  | // 检查差值是否小于等于2分钟 | 
|---|
|  |  |  | long minutes = Math.abs(duration.toMinutes()); | 
|---|
|  |  |  | return minutes >= 5; | 
|---|
|  |  |  | } | 
|---|
|  |  |  | /** | 
|---|
|  |  |  | * 师傅端-定时调度记录师傅当天的轨迹标点 | 
|---|
|  |  |  | * | 
|---|
|  |  |  | * @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) { | 
|---|
|  |  |  | System.err.println("调用标点"+ LocalDateTime.now()); | 
|---|
|  |  |  | 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))); | 
|---|
|  |  |  | 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); | 
|---|
|  |  |  | 
|---|
|  |  |  | } | 
|---|
|  |  |  | return R.ok(); | 
|---|
|  |  |  | } | 
|---|
|  |  |  | //    @ApiOperation(value = "算经纬度", tags = {"师傅端-订单列表"}) | 
|---|
|  |  |  | //    @GetMapping(value = "/distance") | 
|---|
|  |  |  | //    @ApiImplicitParams({ | 
|---|
|  |  |  | //            @ApiImplicitParam(value = "经度", name = "longitude", dataType = "Integer", required = true), | 
|---|
|  |  |  | //            @ApiImplicitParam(value = "纬度", name = "latitude", dataType = "Integer", required = true) | 
|---|
|  |  |  | //    }) | 
|---|
|  |  |  | //    public R<Boolean> distance(@RequestParam Double longitude1, @RequestParam Double latitude1,@RequestParam Double longitude2, @RequestParam Double latitude2) { | 
|---|
|  |  |  | // | 
|---|
|  |  |  | // | 
|---|
|  |  |  | //    } | 
|---|
|  |  |  |  | 
|---|
|  |  |  | @ApiOperation(value = "上传经纬度", tags = {"师傅端-首页[2.0]"}) | 
|---|
|  |  |  | @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); | 
|---|
|  |  |  | String cityCode = address.getDatas(); | 
|---|
|  |  |  | System.err.println("城市code"+cityCode); | 
|---|
|  |  |  | String provinceCode = cityCode.substring(0, 2) + "0000"; | 
|---|
|  |  |  | System.err.println("省份code"+provinceCode); | 
|---|
|  |  |  | Set<Integer> strings = new HashSet<>(); | 
|---|
|  |  |  | strings.add(workId); | 
|---|
|  |  |  | redisService.setCacheSet("workerLocation:"+cityCode+":", strings); | 
|---|
|  |  |  | redisService.setCacheSet("workerLocation:"+provinceCode+":", strings); | 
|---|
|  |  |  | redisService.setCacheObject("work:"+workId+":", longitude+","+latitude); | 
|---|
|  |  |  | masterWorkerService.lambdaUpdate() | 
|---|
|  |  |  | .set(MasterWorker::getWorkerLon, longitude) | 
|---|
|  |  |  | .set(MasterWorker::getWorkerLat, latitude) | 
|---|
|  |  |  | .eq(MasterWorker::getId, workId) | 
|---|
|  |  |  | .eq(MasterWorker::getIsDelete, 0).update(); | 
|---|
|  |  |  | return R.ok(); | 
|---|
|  |  |  |  | 
|---|
|  |  |  | } | 
|---|
|  |  |  |  | 
|---|
|  |  |  | } | 
|---|