| | |
| | | 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.service.impl.OrderPositionServiceImpl; |
| | | import com.stylefeng.guns.modular.system.util.*; |
| | | import com.stylefeng.guns.modular.system.warpper.BaseWarpper; |
| | | import com.stylefeng.guns.modular.system.warpper.EndPushWarpper; |
| | |
| | | import java.math.MathContext; |
| | | import java.math.RoundingMode; |
| | | import java.text.SimpleDateFormat; |
| | | import java.time.LocalDate; |
| | | import java.time.LocalDateTime; |
| | | import java.util.*; |
| | | import java.util.stream.Collectors; |
| | |
| | | } |
| | | AssignOrder assignOrder = assignOrderService.selectOne(new EntityWrapper<AssignOrder>().eq("companyId", query.getId()).eq("type", 1)); |
| | | if(null != assignOrder){//配置了指派规则才处理 |
| | | boolean lock = redisUtil.lock("order_lock", 10); |
| | | if(!lock){ |
| | | int num1 = 1; |
| | | while (num1 <= 10){ |
| | | Thread.sleep(3000);//等待3秒 |
| | | lock = redisUtil.lock("order_lock", 10); |
| | | if(lock){ |
| | | break; |
| | | }else{ |
| | | num1++; |
| | | } |
| | | } |
| | | } |
| | | try { |
| | | //获取空闲司机 |
| | | List<Driver> drivers = driverService.queryIdleDriver(1, orderPrivateCar.getServerCarModelId(), orderPrivateCar.getStartLon(), orderPrivateCar.getStartLat(), assignOrder.getDistance(), null);//获取范围内空闲司机 |
| | | List<Integer> driverIds = drivers.stream().map(Driver::getId).collect(Collectors.toList()); |
| | |
| | | List<Integer> orderPrivateCarDriverIds = orderPrivateCars.stream().map(OrderPrivateCar::getDriverId).collect(Collectors.toList()); |
| | | for(int j = 0; j < drivers.size(); j++){ |
| | | Driver driver1 = drivers.get(j); |
| | | // 判断该司机是否有30分钟内预约单 |
| | | long count = orderPrivateCarss.stream().filter(orderPrivateCar1 -> driver1.getId().equals(orderPrivateCar1.getDriverId()) |
| | | && DateUtil.dateToLocalDateTime(orderPrivateCar1.getTravelTime()).minusMinutes(30).isBefore(LocalDateTime.now()) |
| | | && DateUtil.dateToLocalDateTime(orderPrivateCar1.getTravelTime()).isAfter(LocalDateTime.now())).count(); |
| | | if(orderPrivateCar.getOrderType() == 2 && orderPrivateCarDriverIds.contains(driver.getId())){ |
| | | continue; |
| | | } |
| | | // 判断该司机是否有30分钟内预约单 |
| | | long count = orderPrivateCarss.stream().filter(s -> s.getDriverId().equals(driver1.getId()) && |
| | | DateUtil.dateToLocalDateTime(s.getTravelTime()).minusMinutes(30).isBefore(LocalDateTime.now())).count(); |
| | | if(count > 0){ |
| | | continue; |
| | | } |
| | |
| | | |
| | | //发送短信给司机 |
| | | // aLiSendSms.sendSms(dr.getPhone(), "SMS_216832951", "{\"" + orderPrivateCar.getStartAddress() + "\"}"); |
| | | } |
| | | }catch (Exception e){ |
| | | e.printStackTrace(); |
| | | }finally { |
| | | redisUtil.unlock("order_lock"); |
| | | } |
| | | } |
| | | } |
| | |
| | | |
| | | @Override |
| | | public ResultUtil payPrivateCarOrder(Integer payType, Integer orderId, Integer couponId, Integer type) throws Exception { |
| | | String value = redisUtil.getValue(orderId + "_status_1"); |
| | | if(ToolUtil.isNotEmpty(value) && "8".equals(value)){ |
| | | return ResultUtil.error("订单已完成支付,不允许重复支付", ""); |
| | | boolean lock = redisUtil.lock(orderId + "_payment", 10); |
| | | if(!lock){ |
| | | int num1 = 1; |
| | | while (num1 <= 10){ |
| | | Thread.sleep(3000);//等待3秒 |
| | | lock = redisUtil.lock(orderId + "_payment", 10); |
| | | if(lock){ |
| | | break; |
| | | }else{ |
| | | num1++; |
| | | } |
| | | } |
| | | } |
| | | try { |
| | | OrderPrivateCar orderPrivateCar = this.selectById(orderId); |
| | | if(orderPrivateCar.getState() == 8 || orderPrivateCar.getState() == 9){ |
| | | return ResultUtil.error("订单已完成支付,不允许重复支付", ""); |
| | |
| | | } |
| | | //订单创建后15分钟 |
| | | while ((System.currentTimeMillis() - time) <= 900000) { |
| | | try { |
| | | String value1 = redisUtil.getValue(orderId + "_status_1"); |
| | | if(ToolUtil.isNotEmpty(value1) && "8".equals(value1)){ |
| | | OrderPrivateCar orderPrivateCar1 = OrderPrivateCarServiceImpl.this.selectById(orderId); |
| | | if(orderPrivateCar1.getState() != 7){ |
| | | break; |
| | | } |
| | | try { |
| | | ResultUtil<Map<String, Object>> resultUtil2 = payMoneyUtil.queryWXOrder("", code, "JSAPI"); |
| | | if (resultUtil2.getCode() == 200) { |
| | | /** |
| | |
| | | e.printStackTrace(); |
| | | } |
| | | } |
| | | String value1 = redisUtil.getValue(orderId + "_status_1"); |
| | | if(ToolUtil.isNotEmpty(value1) && "7".equals(value1)){ |
| | | |
| | | OrderPrivateCar orderPrivateCar1 = OrderPrivateCarServiceImpl.this.selectById(orderId); |
| | | if(7 == orderPrivateCar1.getState()){ |
| | | //关闭订单,不允许支付 |
| | | payMoneyUtil.closeWXOrder(code); |
| | | PaymentRecord paymentRecord = paymentRecordService.selectOne(new EntityWrapper<PaymentRecord>().eq("serialNumber", code)); |
| | |
| | | } |
| | | }).start(); |
| | | return resultUtil; |
| | | }catch (Exception e){ |
| | | e.printStackTrace(); |
| | | }finally { |
| | | redisUtil.unlock(orderId + "_payment"); |
| | | } |
| | | return ResultUtil.error("支付异常"); |
| | | } |
| | | |
| | | @Override |
| | |
| | | @Override |
| | | @Transactional(rollbackFor = Exception.class) |
| | | public synchronized void payOrderPrivateCarCallback(Integer id, String order_id, Integer type) throws Exception { |
| | | boolean lock = redisUtil.lock(order_id + "_paymentCallback", 10); |
| | | if(!lock){ |
| | | int num1 = 1; |
| | | while (num1 <= 10){ |
| | | Thread.sleep(3000);//等待3秒 |
| | | lock = redisUtil.lock(order_id + "_paymentCallback", 10); |
| | | if(lock){ |
| | | break; |
| | | }else{ |
| | | num1++; |
| | | } |
| | | } |
| | | } |
| | | |
| | | |
| | | try { |
| | | PaymentRecord query = paymentRecordService.query(1, null, null, Integer.valueOf(id), 1, type, null); |
| | | if(null != query){ |
| | | String value = redisUtil.getValue(order_id + "_status_1"); |
| | | if(ToolUtil.isNotEmpty(value) && "8".equals(value)){ |
| | | return; |
| | | } |
| | | //添加交易明细 |
| | | OrderPrivateCar orderPrivateCar = this.selectById(id); |
| | | if(7 != orderPrivateCar.getState()){ |
| | | return; |
| | | } |
| | | transactionDetailsService.saveData(orderPrivateCar.getUserId(), "完成订单", query.getAmount(), 2, 1, 1, 1, query.getOrderId()); |
| | | orderPrivateCar.setState(8); |
| | | orderPrivateCar.setPayType(type); |
| | |
| | | query.setState(2); |
| | | query.setCode(order_id); |
| | | paymentRecordService.updateById(query); |
| | | redisUtil.setStrValue(order_id + "_status_1", "8"); |
| | | |
| | | if(orderPrivateCar.getIsplatPay()==1){ |
| | | //添加已收入明细 |
| | |
| | | }else{ |
| | | System.err.println("预支付数据异常(orderId = " + id + ")"); |
| | | } |
| | | }catch (Exception e){ |
| | | e.printStackTrace(); |
| | | }finally { |
| | | redisUtil.unlock(order_id + "_paymentCallback"); |
| | | } |
| | | } |
| | | |
| | | @Override |