package com.stylefeng.guns.modular.taxi.service.impl; import com.alibaba.fastjson.JSON; import com.alibaba.fastjson.JSONArray; import com.baomidou.mybatisplus.mapper.EntityWrapper; import com.baomidou.mybatisplus.service.impl.ServiceImpl; import com.stylefeng.guns.core.util.ToolUtil; import com.stylefeng.guns.modular.specialTrain.model.OrderPrivateCar; import com.stylefeng.guns.modular.specialTrain.server.IOrderPrivateCarService; import com.stylefeng.guns.modular.system.dao.*; import com.stylefeng.guns.modular.system.model.*; import com.stylefeng.guns.modular.system.service.*; import com.stylefeng.guns.modular.system.util.*; import com.stylefeng.guns.modular.taxi.dao.OrderTaxiMapper; import com.stylefeng.guns.modular.taxi.model.OrderTaxi; import com.stylefeng.guns.modular.taxi.service.IOrderTaxiService; import org.redisson.api.RLock; import org.redisson.api.RedissonClient; import org.springframework.beans.factory.annotation.Autowired; import org.springframework.data.redis.core.RedisTemplate; import org.springframework.stereotype.Service; import org.springframework.transaction.annotation.Isolation; import org.springframework.transaction.annotation.Propagation; import org.springframework.transaction.annotation.Transactional; import org.springframework.util.StringUtils; import javax.annotation.Resource; import java.math.BigDecimal; import java.util.*; import java.util.concurrent.TimeUnit; @Service @Transactional(isolation = Isolation.READ_UNCOMMITTED, propagation = Propagation.REQUIRED, rollbackFor = Exception.class) public class OrderTaxiServiceImpl extends ServiceImpl implements IOrderTaxiService { @Resource private OrderTaxiMapper orderTaxiMapper; @Autowired private IDriverService driverService; @Autowired private IUserRedPacketRecordService userRedPacketRecordService; @Autowired private PushUtil pushUtil; @Autowired private GDMapElectricFenceUtil gdMapElectricFenceUtil; @Autowired private GDFalconUtil gdFalconUtil; @Autowired private RedisUtil redisUtil; @Autowired private RedissonClient redissonClient; @Autowired private IOrderPositionService orderPositionService; @Autowired private ISystemNoticeService systemNoticeService; @Autowired private ChinaMobileUtil chinaMobileUtil; @Autowired private GeodesyUtil geodesyUtil; @Resource private RegionMapper regionMapper; @Autowired private GDMapGeocodingUtil gdMapGeocodingUtil; @Autowired private IOrderPrivateCarService orderPrivateCarService; @Resource private UserInfoMapper userInfoMapper; /** * 获取司机端首页订单列表 * * @param state 1=服务中,2=待服务(30分钟定义预约) * @param driverId * @return * @throws Exception */ @Override public List> queryOrderList(Integer state, Integer driverId) throws Exception { return orderTaxiMapper.queryOrderList(state, driverId); } /** * 获取司机端我的订单列表 * * @param state 1=全部,2=待支付,3=已取消 * @param uid * @return * @throws Exception */ @Override public List> queryMyAllOrder(Integer state, Integer uid) throws Exception { return orderTaxiMapper.queryMyAllOrder(state, uid); } /** * 获取订单数据 * * @param state * @param driverId * @return * @throws Exception */ @Override public List query(Integer driverId, Integer... state) throws Exception { List integers = Arrays.asList(state); return orderTaxiMapper.query(integers, driverId); } /** * 获取司机抢单页面的订单详情 * * @param orderId * @return * @throws Exception */ @Override public Map queryPushOrder(Integer orderId) throws Exception { return orderTaxiMapper.queryPushOrder(orderId); } @Autowired private ALiSendSms aLiSendSms; @Autowired private ICarService carService; @Resource private DriverWorkMapper driverWorkMapper; /** * 抢单操作 * * @param orderId * @param uid * @return * @throws Exception */ @Override public ResultUtil grabOrder(Integer orderId, Integer uid) throws Exception { RLock lock = redissonClient.getLock("grabOrder:" + orderId); if (!lock.tryLock(10, 10, TimeUnit.SECONDS)) { return ResultUtil.error("抢单失败"); } try { OrderTaxi orderTaxi = this.selectById(orderId); //处理摆渡车的情况 if (orderTaxi.getType() == 2) { //查看用户下的摆渡车是否已被人抢了 List list = this.selectList( new EntityWrapper() .eq("type", 2) .eq("userId", orderTaxi.getUserId()) .ne("state", 1) .eq("crossCityOrderId", orderTaxi.getCrossCityOrderId()) .eq("place", orderTaxi.getPlace()) ); List list1 = orderPrivateCarService.selectList( new EntityWrapper() .eq("type", 2) .eq("userId", orderTaxi.getUserId()) .ne("state", 1) .eq("crossCityOrderId", orderTaxi.getCrossCityOrderId()) .eq("place", orderTaxi.getPlace()) ); if (list.size() > 0 || list1.size() > 0) { return ResultUtil.error("手速有点慢哦,订单已被抢啦!"); } } if (orderTaxi.getState() == 10) { return ResultUtil.error("订单已取消"); } if (orderTaxi.getState() != 1) { return ResultUtil.error("手速有点慢哦,订单已被抢啦!"); } Driver driver = driverService.selectById(uid); orderTaxi.setDriverId(uid); orderTaxi.setCarId(driver.getCarId()); orderTaxi.setCompanyId(driver.getFranchiseeId() != null && driver.getFranchiseeId() != 0 ? driver.getFranchiseeId() : ( driver.getCompanyId() != null && driver.getCompanyId() != 0 ? driver.getCompanyId() : 1)); orderTaxi.setState(2); orderTaxi.setSnatchOrderTime(new Date()); //调用高德创建轨迹 // String s = gdFalconUtil.selectTerminal(driver.getPhone()); // String track = gdFalconUtil.createTrack(s); // orderTaxi.setTrackId(track); if (StringUtils.hasLength(orderTaxi.getAudioLinkUrl())) { List money = useMoneyMapper.selectList(null); orderTaxi.setState(9); orderTaxiMapper.updateById(orderTaxi); // 司机已经接单 删除订单标记 清除订单队列 driver.setState(2); driver.setBalance(driver.getBalance() - money.get(0).getMoney()); driverService.updateById(driver); // List list = driverService.queryIdleDriverAll(2);//所有附近空闲司机 // for (Driver driver1 : list) { // pushUtil.grabOrder(2,driver1.getId(),orderId);; // } // 新增扣除使用费记录 TransactionDetails transactionDetails = new TransactionDetails(); transactionDetails.setUserId(driver.getId()); transactionDetails.setInsertTime(new Date()); transactionDetails.setRemark("软件使用费"); transactionDetails.setMoney(money.get(0).getMoney()); transactionDetails.setState(2); transactionDetails.setType(1); transactionDetails.setUserType(2); transactionDetails.setOrderType(6); transactionDetails.setOrderId(orderTaxi.getId()); transactionDetailsMapper.insert(transactionDetails); } //调用移动的小号接口 /*Map geocode = gdMapGeocodingUtil.geocode(orderTaxi.getStartLon().toString(), orderTaxi.getStartLat().toString()); Region region = regionMapper.query(geocode.get("districtCode")); Map map = chinaMobileUtil.midAxbBindSend(orderTaxi.getPassengersPhone(), driver.getPhone(), Integer.valueOf(region.getCitycode().substring(1))); if(String.valueOf(map.get("code")).equals("200")){ orderTaxi.setTelX(map.get("telX")); orderTaxi.setBindId(map.get("bindId")); }*/ this.updateById(orderTaxi); if (orderTaxi.getType() == 2) { List list = this.selectList( new EntityWrapper() .eq("type", 2) .eq("userId", orderTaxi.getUserId()) .ne("state", 1) .eq("crossCityOrderId", orderTaxi.getCrossCityOrderId()) .eq("place", orderTaxi.getPlace()) ); List list1 = orderPrivateCarService.selectList( new EntityWrapper() .eq("type", 2) .eq("userId", orderTaxi.getUserId()) .ne("state", 1) .eq("crossCityOrderId", orderTaxi.getCrossCityOrderId()) .eq("place", orderTaxi.getPlace()) ); for (OrderTaxi orderTaxi1 : list) { orderTaxi1.setState(10); this.updateById(orderTaxi1); } for (OrderPrivateCar orderPrivateCar : list1) { orderPrivateCar.setState(10); orderPrivateCarService.updateById(orderPrivateCar); } } //如果是预约单,则不修改司机为服务中 if (orderTaxi.getOrderType() == 2 && orderTaxi.getTravelTime().getTime() < System.currentTimeMillis() + 600000) { //修改司机为服务中 driver.setState(3); driverService.updateById(driver); } //推送相关代码------------------start---------------- new Thread(new Runnable() { @Override public void run() { pushUtil.pushOrderState(1, orderTaxi.getUserId(), orderTaxi.getId(), 2, orderTaxi.getState()); pushUtil.pushOrderState(2, orderTaxi.getDriverId(), orderTaxi.getId(), 2, orderTaxi.getState()); if (orderTaxi.getType() == 2) { pushUtil.pushFerryOrderState(1, orderTaxi.getUserId(), orderTaxi.getId(), 2, 2); System.err.println("----------------------------------推送摆渡订单-----------------------------"); } } }).start(); //非电招订单才需要推实时位置 if (7 != orderTaxi.getOrderSource()) { new Thread(new Runnable() { @Override public void run() { pushUtil.pushDriverPosition(orderId, 2); } }).start(); } systemNoticeService.addSystemNotice(2, "您已成功抢得出租车订单,请及时联系客户!", orderTaxi.getDriverId()); systemNoticeService.addSystemNotice(1, "您的订单已指派给" + driver.getName().substring(0, 1) + "师傅,请保持电话畅通!", orderTaxi.getUserId()); //发送短信 UserInfo userInfo = userInfoMapper.selectById(orderTaxi.getUserId()); // String sData = aLiSendSms.sendSms(userInfo.getPhone(), "SMS_244480455", "{\"name\":\"" + driver.getName() + "\",\"phone\":\"" + driver.getPhone() + "\",\"carInfo\":\"" +carService.selectById(orderTaxi.getCarId()) .getCarLicensePlate() + "\",}"); Car car = carService.selectById(driver.getCarId()); String s = MsgUtil.SendDriverPost(orderTaxi.getPassengersPhone(), car.getCarLicensePlate(), driver.getName(), driver.getPhone()); System.err.println("====电话回调===" + s); } catch (Exception e) { return ResultUtil.error("抢单失败"); } finally { lock.unlock(); } return ResultUtil.success(); } /** * 抢单操作(车载端) * * @param orderId * @param uid * @return * @throws Exception */ @Override public synchronized ResultUtil grabOrder_(Integer orderId, Integer uid) throws Exception { OrderTaxi orderTaxi = this.selectById(orderId); if (orderTaxi.getState() == 9) { return ResultUtil.error("订单已取消"); } if (orderTaxi.getState() != 1) { return ResultUtil.error("手速有点慢哦,订单已被抢啦!"); } Driver driver = driverService.selectById(uid); orderTaxi.setDriverId(uid); orderTaxi.setCarId(driver.getCarId()); orderTaxi.setCompanyId(driver.getFranchiseeId() != null && driver.getFranchiseeId() != 0 ? driver.getFranchiseeId() : ( driver.getCompanyId() != null && driver.getCompanyId() != 0 ? driver.getCompanyId() : 1)); orderTaxi.setState(2); Date date = new Date(); orderTaxi.setSnatchOrderTime(date); orderTaxi.setSetOutTime(date); orderTaxi.setArriveTime(date); orderTaxi.setStartServiceTime(date); orderTaxi.setBoardingTime(date); String value = redisUtil.getValue("DRIVER" + uid); if (ToolUtil.isNotEmpty(value)) { String[] split = value.split(","); Map geocode1 = gdMapGeocodingUtil.geocode(split[0], split[1]); orderTaxi.setBoardingAddress(geocode1.get("address")); orderTaxi.setBoardingLon(Double.valueOf(split[0])); orderTaxi.setBoardingLat(Double.valueOf(split[1])); } //调用高德创建轨迹 String s = gdFalconUtil.selectTerminal(driver.getPhone()); String track = gdFalconUtil.createTrack(s); orderTaxi.setTrackId(track); //调用移动的小号接口 TODO 车载端使用真实号码 // Map geocode = gdMapGeocodingUtil.geocode(orderTaxi.getStartLon().toString(), orderTaxi.getStartLat().toString()); // Region region = regionMapper.query(geocode.get("districtCode")); // Map map = chinaMobileUtil.midAxbBindSend(orderTaxi.getPassengersPhone(), driver.getPhone(), Integer.valueOf(region.getCitycode().substring(1))); //// if(String.valueOf(map.get("code")).equals("200")){ //// orderTaxi.setTelX(map.get("telX")); //// orderTaxi.setBindId(map.get("bindId")); //// } this.updateById(orderTaxi); //如果是预约单,则不修改司机为服务中 if (orderTaxi.getOrderType() != 2 || (orderTaxi.getOrderType() == 2 && orderTaxi.getTravelTime().getTime() < System.currentTimeMillis() + 600000)) { //修改司机为服务中 driver.setState(3); driverService.updateById(driver); } //推送相关代码------------------start---------------- new Thread(new Runnable() { @Override public void run() { pushUtil.pushOrderState(1, orderTaxi.getUserId(), orderTaxi.getId(), 2, orderTaxi.getState()); pushUtil.pushOrderState(2, orderTaxi.getDriverId(), orderTaxi.getId(), 2, orderTaxi.getState()); } }).start(); new Thread(new Runnable() { @Override public void run() { pushUtil.pushDriverPosition(orderId, 2); } }).start(); systemNoticeService.addSystemNotice(2, "您已成功抢得出租车订单,请及时联系客户!", orderTaxi.getDriverId()); systemNoticeService.addSystemNotice(1, "您的订单已指派给" + driver.getName().substring(0, 1) + "师傅,请保持电话畅通!", orderTaxi.getUserId()); //发送短信 try { UserInfo userInfo = userInfoMapper.selectById(orderTaxi.getUserId()); String sData = aLiSendSms.sendSms(userInfo.getPhone(), "SMS_244480455", "{\"name\":\"" + driver.getName() + "\",\"phone\":\"" + driver.getPhone() + "\",\"carInfo\":\"" + carService.selectById(orderTaxi.getCarId()).getCarLicensePlate() + "\",}"); } catch (Exception e) { } return ResultUtil.success(); } /** * 获取订单详情页(服务中的页面) * * @param orderId * @return * @throws Exception */ @Override public Map queryOrderInfo(Integer orderId) throws Exception { return orderTaxiMapper.queryOrderInfo(orderId); } @Resource private TUseMoneyMapper useMoneyMapper; @Autowired private TransactionDetailsMapper transactionDetailsMapper; /** * 走订单流程操作 * * @param orderId * @param state * @return * @throws Exception */ @Override public ResultUtil process(Integer orderId, Integer state, Double lon, Double lat, String address) throws Exception { OrderTaxi orderTaxi = this.selectById(orderId); switch (state) { case 3://出发前往预约点 orderTaxi.setState(3); orderTaxi.setSetOutTime(new Date()); systemNoticeService.addSystemNotice(1, "司机已出发,请耐心等待", orderTaxi.getUserId()); break; case 4://到达预约点,等待客户上车 orderTaxi.setState(4); orderTaxi.setArriveTime(new Date()); systemNoticeService.addSystemNotice(1, "司机已到达您设置的预约地点,请及时上车", orderTaxi.getUserId()); break; case 5://开始服务 orderTaxi.setBoardingLon(lon); orderTaxi.setBoardingLat(lat); orderTaxi.setBoardingAddress(address); orderTaxi.setBoardingTime(new Date()); orderTaxi.setState(5); orderTaxi.setStartServiceTime(new Date()); pushUtil.pushDriverPosition(orderTaxi.getId(), 2);//主动推送司机定位 break; case 6://结束服务 orderTaxi.setGetoffLon(lon); orderTaxi.setGetoffLat(lat); orderTaxi.setGetoffAddress(address); orderTaxi.setGetoffTime(new Date()); orderTaxi.setState(6); orderTaxi.setEndServiceTime(new Date()); // 电话叫车订单不再扣一笔软件使用费 if (!StringUtils.hasLength(orderTaxi.getAudioLinkUrl())) { List money = useMoneyMapper.selectList(null); Driver driver = driverService.selectById(orderTaxi.getDriverId()); driver.setBalance(driver.getBalance() - money.get(0).getMoney()); // 新增扣除使用费记录 TransactionDetails transactionDetails = new TransactionDetails(); transactionDetails.setUserId(driver.getId()); transactionDetails.setInsertTime(new Date()); transactionDetails.setRemark("软件使用费"); transactionDetails.setMoney(money.get(0).getMoney()); transactionDetails.setState(2); transactionDetails.setType(1); transactionDetails.setUserType(2); transactionDetails.setOrderType(6); transactionDetails.setOrderId(orderTaxi.getId()); transactionDetailsMapper.insert(transactionDetails); driverService.updateById(driver); } pushUtil.removeTask(orderId, 2);//删除定时任务,结束推送数据 systemNoticeService.addSystemNotice(1, "司机已结束本次行程,谢谢使用", orderTaxi.getUserId()); break; } this.updateById(orderTaxi); // TODO: 2020/6/5 推送状态 new Thread(new Runnable() { @Override public void run() { pushUtil.pushOrderState(1, orderTaxi.getUserId(), orderTaxi.getId(), 2, orderTaxi.getState()); pushUtil.pushOrderState(2, orderTaxi.getDriverId(), orderTaxi.getId(), 2, orderTaxi.getState()); } }).start(); return ResultUtil.success(); } /** * 确认费用操作 * * @param orderId * @param type * @param travelFee * @param parkingFee * @param crossingFee * @return * @throws Exception */ @Override public ResultUtil confirmFees(Integer orderId, Integer type, Double travelFee, Double parkingFee, Double crossingFee) throws Exception { OrderTaxi orderTaxi = this.selectById(orderId); orderTaxi.setPayManner(type); if (type == 2) {//其他支付,不需要操作,直接完成订单 orderTaxi.setOrderMoney(0D); orderTaxi.setTravelMoney(0D); orderTaxi.setParkMoney(0D); orderTaxi.setRoadTollMoney(0D); orderTaxi.setRedPacketMoney(0D); orderTaxi.setCouponMoney(0D); orderTaxi.setDiscount(0D); orderTaxi.setDiscountMoney(0D); orderTaxi.setPayMoney(0D); orderTaxi.setState(8); } else { orderTaxi = this.setMoney(orderTaxi, travelFee, parkingFee, crossingFee); orderTaxi.setState(7); } this.updateById(orderTaxi); //回滚司机状态为空闲 Driver driver = driverService.selectById(orderTaxi.getDriverId()); driver.setState(2); driverService.updateById(driver); OrderTaxi finalOrderTaxi = orderTaxi; new Thread(new Runnable() { @Override public void run() { pushUtil.pushOrderState(1, finalOrderTaxi.getUserId(), finalOrderTaxi.getId(), 2, finalOrderTaxi.getState()); pushUtil.pushOrderState(2, finalOrderTaxi.getDriverId(), finalOrderTaxi.getId(), 2, finalOrderTaxi.getState()); } }).start(); return ResultUtil.success(); } /** * 确认费用(车载端) * * @param orderId * @param type * @param travelFee * @param lon * @param lat * @return * @throws Exception */ @Override public ResultUtil confirmFees_(Integer orderId, Integer type, Double travelFee, Double lon, Double lat, String address) throws Exception { OrderTaxi orderTaxi = this.selectById(orderId); if (orderTaxi.getState() == 5) {//服务中才能确认费用 orderTaxi.setPayManner(type); orderTaxi = this.setMoney(orderTaxi, travelFee, 0D, 0D); orderTaxi.setState(7); orderTaxi.setGetoffLon(lon); orderTaxi.setGetoffLat(lat); orderTaxi.setGetoffAddress(address); orderTaxi.setGetoffTime(new Date()); orderTaxi.setEndServiceTime(new Date()); this.updateById(orderTaxi); pushUtil.removeTask(orderId, 2);//删除定时任务,结束推送数据 systemNoticeService.addSystemNotice(1, "司机已结束本次行程,谢谢使用", orderTaxi.getUserId()); //回滚司机状态为空闲 Driver driver = driverService.selectById(orderTaxi.getDriverId()); driver.setState(2); driverService.updateById(driver); OrderTaxi finalOrderTaxi = orderTaxi; new Thread(new Runnable() { @Override public void run() { pushUtil.pushOrderState(1, finalOrderTaxi.getUserId(), finalOrderTaxi.getId(), 2, finalOrderTaxi.getState()); pushUtil.pushOrderState(2, finalOrderTaxi.getDriverId(), finalOrderTaxi.getId(), 2, finalOrderTaxi.getState()); } }).start(); //添加定时任务6分钟司机不确认收款自动完成支付(仅车载端),6分钟之内司机无法接单 String vehicle = redisUtil.getValue("VEHICLE"); JSONArray jsonArray = new JSONArray(); if (ToolUtil.isNotEmpty(vehicle)) { jsonArray = JSON.parseArray(vehicle); } jsonArray.add(orderTaxi.getDriverId()); redisUtil.setStrValue("VEHICLE", jsonArray.toJSONString());//添加司机不能接单标识 TimerTask timerTask = new TimerTask() { @Override public void run() { OrderTaxi orderTaxi1 = OrderTaxiServiceImpl.this.selectById(orderId); if (orderTaxi1.getState() == 7) {//如果是待支付 orderTaxi1.setPayManner(2);//其他方式支付 orderTaxi1.setRedPacketMoney(0D); orderTaxi1.setCouponMoney(0D); orderTaxi1.setDiscount(0D); orderTaxi1.setDiscountMoney(0D); orderTaxi1.setPayMoney(orderTaxi1.getOrderMoney()); orderTaxi1.setState(8); OrderTaxiServiceImpl.this.updateById(orderTaxi1); String vehicle = redisUtil.getValue("VEHICLE"); if (ToolUtil.isNotEmpty(vehicle)) { JSONArray jsonArray = JSON.parseArray(vehicle); for (int i = 0; i < jsonArray.size(); i++) { if (jsonArray.getInteger(i).compareTo(orderTaxi1.getDriverId()) == 0) { jsonArray.remove(i); break; } } redisUtil.setStrValue("VEHICLE", jsonArray.toJSONString()); } new Thread(new Runnable() { @Override public void run() { pushUtil.pushOrderState(1, orderTaxi1.getUserId(), orderId, 2, 8); pushUtil.pushOrderState(2, orderTaxi1.getDriverId(), orderId, 2, 8); } }).start(); } } }; Timer timer = new Timer(); timer.schedule(timerTask, 6 * 60 * 1000); } return ResultUtil.success(); } /** * 司机确认费用(车载端)不管之前数据状态直接修改到待支付(流程断网情况的处理流程) * * @param orderId * @param type * @param travelFee * @param lon * @param lat * @param address * @return * @throws Exception */ @Override public ResultUtil confirmFees$(Integer orderId, Integer type, Double travelFee, Double lon, Double lat, String address) throws Exception { OrderTaxi orderTaxi = this.selectById(orderId); orderTaxi.setPayManner(type); orderTaxi = this.setMoney(orderTaxi, travelFee, 0D, 0D); orderTaxi.setState(7); orderTaxi.setGetoffLon(lon); orderTaxi.setGetoffLat(lat); orderTaxi.setGetoffAddress(address); orderTaxi.setGetoffTime(new Date()); orderTaxi.setEndServiceTime(new Date()); this.updateById(orderTaxi); pushUtil.removeTask(orderId, 2);//删除定时任务,结束推送数据 systemNoticeService.addSystemNotice(1, "司机已结束本次行程,谢谢使用", orderTaxi.getUserId()); //回滚司机状态为空闲 Driver driver = driverService.selectById(orderTaxi.getDriverId()); driver.setState(2); driverService.updateById(driver); OrderTaxi finalOrderTaxi = orderTaxi; new Thread(new Runnable() { @Override public void run() { pushUtil.pushOrderState(1, finalOrderTaxi.getUserId(), finalOrderTaxi.getId(), 2, finalOrderTaxi.getState()); pushUtil.pushOrderState(2, finalOrderTaxi.getDriverId(), finalOrderTaxi.getId(), 2, finalOrderTaxi.getState()); } }).start(); //添加定时任务6分钟司机不确认收款自动完成支付(仅车载端),6分钟之内司机无法接单 String vehicle = redisUtil.getValue("VEHICLE"); JSONArray jsonArray = new JSONArray(); if (ToolUtil.isNotEmpty(vehicle)) { jsonArray = JSON.parseArray(vehicle); } jsonArray.add(orderTaxi.getDriverId()); redisUtil.setStrValue("VEHICLE", jsonArray.toJSONString());//添加司机不能接单标识 TimerTask timerTask = new TimerTask() { @Override public void run() { OrderTaxi orderTaxi1 = OrderTaxiServiceImpl.this.selectById(orderId); if (orderTaxi1.getState() == 7) {//如果是待支付 orderTaxi1.setPayManner(2);//其他方式支付 orderTaxi1.setRedPacketMoney(0D); orderTaxi1.setCouponMoney(0D); orderTaxi1.setDiscount(0D); orderTaxi1.setDiscountMoney(0D); orderTaxi1.setPayMoney(orderTaxi1.getOrderMoney()); orderTaxi1.setState(8); OrderTaxiServiceImpl.this.updateById(orderTaxi1); String vehicle = redisUtil.getValue("VEHICLE"); if (ToolUtil.isNotEmpty(vehicle)) { JSONArray jsonArray = JSON.parseArray(vehicle); for (int i = 0; i < jsonArray.size(); i++) { if (jsonArray.getInteger(i).compareTo(orderTaxi1.getDriverId()) == 0) { jsonArray.remove(i); break; } } redisUtil.setStrValue("VEHICLE", jsonArray.toJSONString()); } new Thread(new Runnable() { @Override public void run() { pushUtil.pushOrderState(1, orderTaxi1.getUserId(), orderId, 2, 8); pushUtil.pushOrderState(2, orderTaxi1.getDriverId(), orderId, 2, 8); } }).start(); } } }; Timer timer = new Timer(); timer.schedule(timerTask, 6 * 60 * 1000); return ResultUtil.success(); } /** * 计算已服务的实时里程 * * @param orderId * @param lon * @param lat */ @Override public boolean calculateMileage(Integer orderId, String lon, String lat) throws Exception { OrderTaxi orderTaxi = this.selectById(orderId); if (null == orderTaxi) { System.err.println("订单数据异常:" + orderId); return false; } OrderPosition orderPosition = orderPositionService.queryNew(orderId, 2); String now = lon + "," + lat; String old = null; if (null != orderPosition) { old = orderPosition.getLon() + "," + orderPosition.getLat(); } else { orderTaxi.setMileage(0D); this.updateById(orderTaxi); return true;//第一条数据不作处理,直接存储 } // Map distance = gdMapElectricFenceUtil.getDistance(now, old, 0);//直线距离 Map distance = geodesyUtil.getDistance(now, old); if (null != distance) { Double distance1 = distance.get("WGS84"); if (Double.valueOf(distance1) > 50 && orderTaxi.getState() == 5) {//大于50米表示在移动,且正在服务中的时候存入里程 orderTaxi.setMileage(new BigDecimal(orderTaxi.getMileage()).add(new BigDecimal(distance1)).setScale(2, BigDecimal.ROUND_HALF_EVEN).doubleValue()); this.updateById(orderTaxi); return true; } return false; } else { System.err.println("调用高德计算距离出错"); } return false; } /** * 获取所有快到期的预约单(出行时间在30分钟内) * * @return * @throws Exception */ @Override public List queryMaturity() throws Exception { return orderTaxiMapper.queryMaturity(); } /** * 获取订单完成后30分钟的数据 * * @return * @throws Exception */ @Override public List taskMidAxbUnBindSend() throws Exception { return orderTaxiMapper.taskMidAxbUnBindSend(); } @Override public List> queryHallOrderList() { return orderTaxiMapper.queryHallOrderList(); } @Override public List queryHallOrderListNoLimit() { return orderTaxiMapper.queryHallOrderListNoLimit(); } /** * 计算费用 * * @param orderTaxi * @param travelFee * @param parkingFee * @param crossingFee * @return */ public OrderTaxi setMoney(OrderTaxi orderTaxi, Double travelFee, Double parkingFee, Double crossingFee) throws Exception { orderTaxi.setTravelMoney(travelFee); orderTaxi.setParkMoney(parkingFee); orderTaxi.setRoadTollMoney(crossingFee); BigDecimal sum = new BigDecimal(travelFee).add(new BigDecimal(parkingFee)).add(new BigDecimal(crossingFee)).add(new BigDecimal(orderTaxi.getTipMoney())); orderTaxi.setOrderMoney(sum.setScale(2, BigDecimal.ROUND_HALF_EVEN).doubleValue()); return orderTaxi; } }