| | |
| | | private IUserTaxiCardService userTaxiCardService; |
| | | @Autowired |
| | | private IRegionService regionService; |
| | | @Autowired |
| | | private ITSysPushTypeService tSysPushTypeService; |
| | | |
| | | @Value("${callbackPath}") |
| | | private String callbackPath; |
| | | |
| | |
| | | driver.setState(3); |
| | | driverService.updateById(driver); |
| | | } |
| | | |
| | | |
| | | |
| | | |
| | | |
| | | |
| | | |
| | | //判断独享,一口价,拼车 |
| | | if (orderPrivateCar.getRideType() != 3) { |
| | | orderPrivateCar.setTotalPeopleNum(peopleNum); |
| | |
| | | if (orderPrivateCar.getState() == 1) { |
| | | this.pushOrder(orderPrivateCar); |
| | | } |
| | | |
| | | } else { |
| | | |
| | | |
| | |
| | | * @throws Exception |
| | | */ |
| | | public void pushOrder(OrderPrivateCar orderPrivateCar) throws Exception { |
| | | |
| | | |
| | | new Thread(new Runnable() { |
| | | @Override |
| | | public void run() { |
| | |
| | | integers = JSON.parseArray(vehicle).toJavaList(Integer.class); |
| | | } |
| | | OpenCity openCity = openCityService.openCity1(orderPrivateCar.getStartLon().toString(), orderPrivateCar.getStartLat().toString()); |
| | | List<PushOrder> querys = pushOrderService.querys(null, 1, openCity.getId());//获取需要推送的次数 |
| | | for (int i = 1; i <= querys.size() + 15; i++) { |
| | | |
| | | // 判断是否为派单模式 |
| | | TSysPushType sysPushType = tSysPushTypeService.selectOne(new EntityWrapper<TSysPushType>().eq("openCityId", openCity.getId())); |
| | | if(sysPushType!=null && sysPushType.getPushType()==2){ |
| | | OrderPrivateCar orderPrivateCar = orderPrivateCarMapper.selectById(id); |
| | | if (null == orderPrivateCar || orderPrivateCar.getState() > 1) { |
| | | break; |
| | | } |
| | | int finalI = i; |
| | | PushOrder pushOrder = querys.stream().filter(s -> s.getType() == (finalI <= 3 ? finalI : 3)).findFirst().orElse(null); |
| | | System.out.println("pushOrder:" + pushOrder); |
| | | int i2 = pushOrder.getPushTime() / 10; |
| | | if (i2 == 0) { |
| | | i2 = 1; |
| | | } |
| | | for (int i1 = 0; i1 < i2; i1++) { |
| | | if (orderPrivateCar.getState() > 1) { |
| | | break; |
| | | } |
| | | //获取空闲司机 |
| | | List<Driver> list = driverService.queryIdleDriver(orderType, orderPrivateCar.getServerCarModelId(), orderPrivateCar.getStartLon(), orderPrivateCar.getStartLat(), pushOrder.getPushDistance(), null);//所有附近空闲司机 |
| | | if (null == orderPrivateCar && orderPrivateCar.getState() == 1) { |
| | | // 固定5公里进行派单 |
| | | List<Driver> list = driverService.queryIdleDriver(orderType, orderPrivateCar.getServerCarModelId(), orderPrivateCar.getStartLon(), orderPrivateCar.getStartLat(), 5.0, null);//所有附近空闲司机 |
| | | if (list.size() > 0) { |
| | | double driverProportion = pushOrder.getDriverProportion() / 100;//推送占比计算成小数 |
| | | int lastIndex = Double.valueOf(list.size() * driverProportion).intValue();//计算占比转成整数(下标截取) |
| | | lastIndex = lastIndex == 0 ? list.size() : lastIndex; |
| | | list = list.subList(0, lastIndex);//获取空闲司机中占比数据 |
| | | for (Driver driver : list) {//开始进行推送 |
| | | boolean bo = false; |
| | | for (Integer integer : integers) { |
| | | if (integer.compareTo(driver.getId()) == 0) { |
| | | bo = true; |
| | | break; |
| | | Driver driver1 = list.stream().sorted(Comparator.comparingDouble(Driver::getDistance).reversed()).findFirst().get(); |
| | | if(orderPrivateCar.getType() == 3){ |
| | | //批量订单 |
| | | CarService carService = new CarService(); |
| | | carService.setCarId(driver1.getCarId()); |
| | | carService.setType(1); |
| | | CarService carService1 = carServiceMapper.selectOne(carService); |
| | | orderPrivateCar.setServerCarModelId(carService1.getServerCarModelId()); |
| | | //1=独享,2=一口价 |
| | | String serverCarModel = orderPrivateCar.getServerCarModel(); |
| | | JSONArray jsonArray = JSON.parseArray(serverCarModel); |
| | | Integer rideType1 = null; |
| | | for (int i = 0; i < jsonArray.size(); i++) { |
| | | JSONObject jsonObject = jsonArray.getJSONObject(i); |
| | | Integer serverCarModelId = jsonObject.getInteger("serverCarModelId"); |
| | | Integer rideType = jsonObject.getInteger("rideType"); |
| | | if(serverCarModelId.equals(carService1.getServerCarModelId())){ |
| | | rideType1 = rideType; |
| | | if(rideType == 1){ |
| | | break; |
| | | } |
| | | } |
| | | } |
| | | if (bo) { |
| | | continue; |
| | | } |
| | | pushUtil.pushOrderState(2, driver.getId(), orderPrivateCar.getId(), 1, orderPrivateCar.getState(), pushOrder.getPushTime()); |
| | | orderPrivateCar.setRideType(rideType1); |
| | | } |
| | | } |
| | | Thread.sleep(10000);//设置等待时间 |
| | | Integer state = orderPrivateCar.getState(); |
| | | if (state > 1) { |
| | | orderIds.remove(orderPrivateCar.getId()); |
| | | return; |
| | | } |
| | | if (i == querys.size() + 15 && state == 1) { |
| | | orderPrivateCar.setDriverId(driver1.getId()); |
| | | orderPrivateCar.setCarId(driver1.getCarId()); |
| | | orderPrivateCar.setCompanyId(driver1.getFranchiseeId() != null && driver1.getFranchiseeId() != 0 ? driver1.getFranchiseeId() : ( |
| | | driver1.getCompanyId() != null && driver1.getCompanyId() != 0 ? driver1.getCompanyId() : 1)); |
| | | orderPrivateCar.setState(2); |
| | | orderPrivateCar.setSnatchOrderTime(new Date()); |
| | | |
| | | // 是否推广订单 |
| | | Integer promotion = isPromotion(orderPrivateCar.getUserId(), driver1.getPlaceOfEmployment()); |
| | | if(null != promotion){ |
| | | orderPrivateCar.setPromotion(2); |
| | | driver1 = driverService.selectById(promotion); |
| | | orderPrivateCar.setPromotionUser(driver1.getName()); |
| | | orderPrivateCar.setPromotionPhone(driver1.getPhone()); |
| | | orderPrivateCar.setPromotionDriverId(promotion); |
| | | }else{ |
| | | orderPrivateCar.setPromotion(1); |
| | | } |
| | | orderPrivateCarMapper.updateById(orderPrivateCar); |
| | | |
| | | //如果是预约单,则不修改司机为服务中 |
| | | if(orderPrivateCar.getOrderType() != 2 || (orderPrivateCar.getOrderType() == 2 && orderPrivateCar.getTravelTime().getTime() < System.currentTimeMillis() + 600000)){ |
| | | //修改司机为服务中 |
| | | driver1.setState(3); |
| | | driverService.updateById(driver1); |
| | | } |
| | | |
| | | //推送相关代码------------------start---------------- |
| | | new Thread(new Runnable() { |
| | | @Override |
| | | public void run() { |
| | | pushUtil.pushOrderState(1, orderPrivateCar.getUserId(), orderPrivateCar.getId(), 1, orderPrivateCar.getState(),0); |
| | | pushUtil.pushOrderState(2, orderPrivateCar.getDriverId(), orderPrivateCar.getId(), 1, orderPrivateCar.getState(),0); |
| | | if(orderPrivateCar.getType() == 2){ |
| | | pushUtil.pushFerryOrderState(1, orderPrivateCar.getUserId(), orderPrivateCar.getId(), 1, 2); |
| | | } |
| | | |
| | | } |
| | | }).start(); |
| | | |
| | | new Thread(new Runnable() { |
| | | @Override |
| | | public void run() { |
| | | pushUtil.pushDriverPosition(orderPrivateCar.getId(), 1); |
| | | } |
| | | }).start(); |
| | | |
| | | systemNoticeService.addSystemNotice(2, "已为您派得快车订单,请及时联系客户!", orderPrivateCar.getDriverId(), 1); |
| | | systemNoticeService.addSystemNotice(1, "您的订单已指派给" + driver1.getName().substring(0, 1) + "师傅,请保持电话畅通!", orderPrivateCar.getUserId(), 1); |
| | | |
| | | if(pushMinistryOfTransport){ |
| | | new Thread(new Runnable() { |
| | | @Override |
| | | public void run() { |
| | | //上传数据 |
| | | pushMinistryOfTransportUtil.orderCreate(orderPrivateCar.getId()); |
| | | pushMinistryOfTransportUtil.orderMatch(orderPrivateCar.getId()); |
| | | } |
| | | }).start(); |
| | | } |
| | | |
| | | |
| | | }else { |
| | | // 没找到车辆 |
| | | orderPrivateCar.setState(10); |
| | | orderPrivateCarMapper.updateById(orderPrivateCar); |
| | | pushUtil.pushEndPush(1, orderPrivateCar.getUserId(), orderPrivateCar.getId(), 1, 1); |
| | | orderIds.remove(orderPrivateCar.getId()); |
| | | |
| | | // TODO 退款 |
| | | } |
| | | |
| | | |
| | | } |
| | | |
| | | }else { |
| | | |
| | | List<PushOrder> querys = pushOrderService.querys(null, 1, openCity.getId());//获取需要推送的次数 |
| | | for (int i = 1; i <= querys.size() + 15; i++) { |
| | | OrderPrivateCar orderPrivateCar = orderPrivateCarMapper.selectById(id); |
| | | if (null == orderPrivateCar || orderPrivateCar.getState() > 1) { |
| | | break; |
| | | } |
| | | int finalI = i; |
| | | PushOrder pushOrder = querys.stream().filter(s -> s.getType() == (finalI <= 3 ? finalI : 3)).findFirst().orElse(null); |
| | | System.out.println("pushOrder:" + pushOrder); |
| | | int i2 = pushOrder.getPushTime() / 10; |
| | | if (i2 == 0) { |
| | | i2 = 1; |
| | | } |
| | | for (int i1 = 0; i1 < i2; i1++) { |
| | | if (orderPrivateCar.getState() > 1) { |
| | | break; |
| | | } |
| | | //获取空闲司机 |
| | | List<Driver> list = driverService.queryIdleDriver(orderType, orderPrivateCar.getServerCarModelId(), orderPrivateCar.getStartLon(), orderPrivateCar.getStartLat(), pushOrder.getPushDistance(), null);//所有附近空闲司机 |
| | | if (list.size() > 0) { |
| | | double driverProportion = pushOrder.getDriverProportion() / 100;//推送占比计算成小数 |
| | | int lastIndex = Double.valueOf(list.size() * driverProportion).intValue();//计算占比转成整数(下标截取) |
| | | lastIndex = lastIndex == 0 ? list.size() : lastIndex; |
| | | list = list.subList(0, lastIndex);//获取空闲司机中占比数据 |
| | | for (Driver driver : list) {//开始进行推送 |
| | | boolean bo = false; |
| | | for (Integer integer : integers) { |
| | | if (integer.compareTo(driver.getId()) == 0) { |
| | | bo = true; |
| | | break; |
| | | } |
| | | } |
| | | if (bo) { |
| | | continue; |
| | | } |
| | | pushUtil.pushOrderState(2, driver.getId(), orderPrivateCar.getId(), 1, orderPrivateCar.getState(), pushOrder.getPushTime()); |
| | | } |
| | | } |
| | | Thread.sleep(10000);//设置等待时间 |
| | | Integer state = orderPrivateCar.getState(); |
| | | if (state > 1) { |
| | | orderIds.remove(orderPrivateCar.getId()); |
| | | return; |
| | | } |
| | | if (i == querys.size() + 15 && state == 1) { |
| | | pushUtil.pushEndPush(1, orderPrivateCar.getUserId(), orderPrivateCar.getId(), 1, 1); |
| | | orderIds.remove(orderPrivateCar.getId()); |
| | | } |
| | | } |
| | | } |
| | | } |
| | | |
| | | } catch (Exception e) { |
| | | e.printStackTrace(); |
| | | } |
| | |
| | | } |
| | | return maps; |
| | | } |
| | | |
| | | |
| | | } |
| | |
| | | */ |
| | | Map<String, Object> query(@Param("companyId") Integer companyId, @Param("type") Integer type, |
| | | @Param("serverCarModelId") Integer serverCarModelId, @Param("systemPriceCityId") Integer systemPriceCityId); |
| | | |
| | | |
| | | /** |
| | | * 获取价格 |
| | | * @param systemPriceCityId |
| | | * @param type |
| | | * @return |
| | | */ |
| | | Map<String, Object> query1(@Param("systemPriceCityId") Integer systemPriceCityId, @Param("type") Integer type, |
| | | @Param("serverCarModelId") Integer serverCarModelId); |
| | | } |
| New file |
| | |
| | | package com.stylefeng.guns.modular.system.dao; |
| | | |
| | | |
| | | import com.baomidou.mybatisplus.mapper.BaseMapper; |
| | | import com.stylefeng.guns.modular.system.model.TSysPushType; |
| | | |
| | | /** |
| | | * <p> |
| | | * 系统设置-推单 Mapper 接口 |
| | | * </p> |
| | | * |
| | | * @author 吕雪 |
| | | * @since 2020-06-09 |
| | | */ |
| | | public interface TSysPushTypeMapper extends BaseMapper<TSysPushType> { |
| | | |
| | | } |
| | |
| | | and systemPriceCityId = #{systemPriceCityId} |
| | | </if> |
| | | </select> |
| | | |
| | | |
| | | |
| | | <select id="query1" resultType="map"> |
| | | select |
| | | id as id, |
| | | content as content, |
| | | contentPutOne as contentPutOne, |
| | | contentNotOne as contentNotOne, |
| | | contentPutTwo as contentPutTwo, |
| | | contentNotTwo as contentNotTwo, |
| | | contentPutThree as contentPutThree, |
| | | contentNotThree as contentNotThree, |
| | | contentExclusive as contentExclusive, |
| | | contentPrice as contentPrice, |
| | | isOpen as isOpen |
| | | from t_system_price where state = 1 and systemPriceCityId = #{systemPriceCityId} |
| | | <if test="null != type"> |
| | | and `type` = #{type} |
| | | </if> |
| | | <if test="null != serverCarModelId"> |
| | | and serverCarModelId = #{serverCarModelId} |
| | | </if> |
| | | </select> |
| | | </mapper> |
| New file |
| | |
| | | <?xml version="1.0" encoding="UTF-8"?> |
| | | <!DOCTYPE mapper PUBLIC "-//mybatis.org//DTD Mapper 3.0//EN" "http://mybatis.org/dtd/mybatis-3-mapper.dtd"> |
| | | <mapper namespace="com.stylefeng.guns.modular.system.dao.TSysPushTypeMapper"> |
| | | |
| | | |
| | | </mapper> |
| | |
| | | @TableField("entercode") |
| | | private String entercode; |
| | | |
| | | |
| | | @TableField(exist = false) |
| | | private Double distance=0.0; |
| | | |
| | | public Double getDistance() { |
| | | return distance; |
| | | } |
| | | |
| | | public void setDistance(Double distance) { |
| | | this.distance = distance; |
| | | } |
| | | |
| | | public String getQrCode() { |
| | | return qrCode; |
| | | } |
| New file |
| | |
| | | package com.stylefeng.guns.modular.system.model; |
| | | |
| | | import com.baomidou.mybatisplus.activerecord.Model; |
| | | import com.baomidou.mybatisplus.annotations.TableField; |
| | | import com.baomidou.mybatisplus.annotations.TableId; |
| | | import com.baomidou.mybatisplus.annotations.TableName; |
| | | import com.baomidou.mybatisplus.enums.IdType; |
| | | import lombok.Data; |
| | | |
| | | import java.io.Serializable; |
| | | |
| | | /** |
| | | * <p> |
| | | * 系统设置-推单模式 |
| | | * </p> |
| | | * |
| | | * @author 吕雪 |
| | | * @since 2020-06-09 |
| | | */ |
| | | @TableName("t_sys_push_type") |
| | | @Data |
| | | public class TSysPushType extends Model<TSysPushType> { |
| | | |
| | | private static final long serialVersionUID = 1L; |
| | | |
| | | /** |
| | | * 主键id |
| | | */ |
| | | @TableId(value = "id", type = IdType.AUTO) |
| | | private Integer id; |
| | | /** |
| | | * 企业id |
| | | */ |
| | | private Integer companyId; |
| | | /** |
| | | * 开通城市id |
| | | */ |
| | | @TableField("openCityId") |
| | | private Integer openCityId; |
| | | /** |
| | | * 1推单 2派单 |
| | | */ |
| | | private Integer pushType; |
| | | |
| | | @Override |
| | | protected Serializable pkVal() { |
| | | return null; |
| | | } |
| | | } |
| New file |
| | |
| | | package com.stylefeng.guns.modular.system.service; |
| | | |
| | | import com.baomidou.mybatisplus.service.IService; |
| | | import com.stylefeng.guns.modular.system.model.TSysPushType; |
| | | |
| | | /** |
| | | * <p> |
| | | * 系统设置-推单 服务类 |
| | | * </p> |
| | | * |
| | | * @author 吕雪 |
| | | * @since 2020-06-09 |
| | | */ |
| | | public interface ITSysPushTypeService extends IService<TSysPushType> { |
| | | |
| | | } |
| | |
| | | Map<String, Double> distance1 = geodesyUtil.getDistance(lon + "," + lat, value); |
| | | double d = Double.valueOf(distance1.get("WGS84")).doubleValue(); |
| | | if(d < (distance * 1000)){ |
| | | driver.setDistance(d); |
| | | list.add(driver); |
| | | } |
| | | } |
| New file |
| | |
| | | package com.stylefeng.guns.modular.system.service.impl; |
| | | |
| | | |
| | | import com.baomidou.mybatisplus.service.impl.ServiceImpl; |
| | | import com.stylefeng.guns.modular.system.dao.TSysPushTypeMapper; |
| | | import com.stylefeng.guns.modular.system.model.TSysPushType; |
| | | import com.stylefeng.guns.modular.system.service.ITSysPushTypeService; |
| | | import org.springframework.stereotype.Service; |
| | | |
| | | /** |
| | | * <p> |
| | | * 系统设置-推单 服务实现类 |
| | | * </p> |
| | | * |
| | | * @author 吕雪 |
| | | * @since 2020-06-09 |
| | | */ |
| | | @Service |
| | | public class TSysPushTypeServiceImpl extends ServiceImpl<TSysPushTypeMapper, TSysPushType> implements ITSysPushTypeService { |
| | | |
| | | } |
| | |
| | | import com.stylefeng.guns.modular.system.service.*; |
| | | import com.stylefeng.guns.modular.taxi.service.ITransactionDetailsService; |
| | | import org.springframework.beans.factory.annotation.Autowired; |
| | | import org.springframework.data.redis.core.RedisTemplate; |
| | | import org.springframework.stereotype.Component; |
| | | |
| | | import javax.annotation.Resource; |
| | |
| | | */ |
| | | @Component |
| | | public class PushMinistryOfTransportUtil { |
| | | |
| | | |
| | | @Autowired |
| | | private IUserInfoService userInfoService; |
| | |
| | | |
| | | @Autowired |
| | | private IOrderEvaluateService orderEvaluateService; |
| | | |
| | | |
| | | @Resource |
| | | private RedisTemplate<String, Object> redisTemplate; |
| | | |
| | | private String path = "http://120.77.11.218:8868/"; |
| | | |
| | |
| | | map.put("amount3", amount3); |
| | | return map; |
| | | } |
| | | |
| | | |
| | | /** |
| | | * 订单发起接口 |
| | | * @param orderId |
| | | */ |
| | | public void orderCreate(Integer orderId){ |
| | | OrderPrivateCar orderPrivateCar = orderPrivateCarService.selectById(orderId); |
| | | Map<String, Object> query = systemPriceMapper.query1(orderPrivateCar.getCompanyId(), 1, orderPrivateCar.getServerCarModelId()); |
| | | JSONObject jsonObject = new JSONObject(); |
| | | jsonObject.put("Address", 450204);//发起第行政区划代码 |
| | | jsonObject.put("OrderId", orderPrivateCar.getOrderNum());//订单编号 |
| | | jsonObject.put("DepartTime", orderPrivateCar.getTravelTime());//预计用车时间YYYYMMDDhhmmss |
| | | jsonObject.put("OrderTime", orderPrivateCar.getInsertTime());//订单发起时间YYYYMMDDhhmmss |
| | | jsonObject.put("PassengerNote", "");//乘客备注 |
| | | jsonObject.put("Departure", orderPrivateCar.getStartAddress());//预计出发地点详细地址 |
| | | jsonObject.put("DepLongitude", orderPrivateCar.getStartLon());//预计出发地点经度 |
| | | jsonObject.put("DepLatitude", orderPrivateCar.getStartLat());//预计出发地点纬度 |
| | | jsonObject.put("Destination", orderPrivateCar.getEndAddress());//预计目的地 |
| | | jsonObject.put("DestLongitude", orderPrivateCar.getEndLon());//预计目的地经度 |
| | | jsonObject.put("DestLatitude", orderPrivateCar.getEndLat());//预计目的地纬度 |
| | | jsonObject.put("Encrypt", 1);//坐标加密标识(1:GCJ-02测绘局标准,2:WGS84 GPS标准,3:BD-09百度标准,4:CGCS2000北斗标准,0:其他) |
| | | jsonObject.put("FareType", query.get("id").toString());//运价类型编码 |
| | | Map<String, Object> map = new HashMap<>(); |
| | | map.put("orderCreate", jsonObject.toJSONString()); |
| | | |
| | | Map<String, String> header = new HashMap<>(); |
| | | header.put("Connection", "keep-alive"); |
| | | header.put("Content-Type", "application/x-www-form-urlencoded"); |
| | | header.put("Accept", "*/*"); |
| | | header.put("Accept-Encoding", "gzip"); |
| | | header.put("Accept-Charset", "utf-8"); |
| | | String result = httpClientUtil.pushHttpRequset("POST", path + "ministryOfTransport/orderCreate", map, header,"form"); |
| | | System.err.println("---------------------------订单发起接口----------------------:" + result); |
| | | } |
| | | |
| | | |
| | | /** |
| | | * 订单成功接口 |
| | | * @param orderId |
| | | */ |
| | | public void orderMatch(Integer orderId){ |
| | | OrderPrivateCar orderPrivateCar = orderPrivateCarService.selectById(orderId); |
| | | Driver driver = driverService.selectById(orderPrivateCar.getDriverId()); |
| | | Car car = carMapper.selectById(orderPrivateCar.getCarId()); |
| | | String value = (String) redisTemplate.opsForValue().get("dache:DRIVER" + orderPrivateCar.getDriverId()); |
| | | JSONObject jsonObject = new JSONObject(); |
| | | jsonObject.put("Address", 450204);//发起地行政区划代码 |
| | | jsonObject.put("OrderId", orderPrivateCar.getOrderNum());//订单编号 |
| | | jsonObject.put("Longitude", Double.valueOf(value.split(",")[0]));//车辆经度 |
| | | jsonObject.put("Latitude", Double.valueOf(value.split(",")[1]));//车辆纬度 |
| | | jsonObject.put("Encrypt", 1);//坐标加密标识(1:GCJ-02测绘局标准,2:WGS84 GPS标准,3:BD-09百度标准,4:CGCS2000北斗标准,0:其他) |
| | | jsonObject.put("LicenseId", driver.getDriveCard());//机动车驾驶证编号 |
| | | jsonObject.put("DriverPhone", driver.getPhone());//驾驶员手机号 |
| | | jsonObject.put("VehicleNo", car.getCarLicensePlate());//车辆号牌 |
| | | jsonObject.put("DistributeTime", new Date());//派单成功时间YYYYMMDDhhmmss |
| | | Map<String, Object> map = new HashMap<>(); |
| | | map.put("orderMatch", jsonObject.toJSONString()); |
| | | |
| | | Map<String, String> header = new HashMap<>(); |
| | | header.put("Connection", "keep-alive"); |
| | | header.put("Content-Type", "application/x-www-form-urlencoded"); |
| | | header.put("Accept", "*/*"); |
| | | header.put("Accept-Encoding", "gzip"); |
| | | header.put("Accept-Charset", "utf-8"); |
| | | String result = httpClientUtil.pushHttpRequset("POST", path + "ministryOfTransport/orderMatch", map, header,"form"); |
| | | System.err.println("--------------------------------订单成功接口---------------------------:" + result); |
| | | } |
| | | |
| | | } |
| | |
| | | |
| | | @Autowired |
| | | private IRegionService regionService; |
| | | |
| | | @Autowired |
| | | private ITSysPushTypeService tSysPushTypeService; |
| | | |
| | | public static List<Integer> orderIds = new ArrayList<>(); |
| | | |
| | |
| | | } |
| | | |
| | | OpenCity openCity = openCityService.openCity1(orderTaxi.getStartLon().toString(), orderTaxi.getStartLat().toString()); |
| | | List<PushOrder> querys = pushOrderService.querys(null, 2, openCity.getId());//获取需要推送的次数 |
| | | //整轮派单结束,若无司机接单,系统自动增加派单5轮,若增加5轮后任无司机接单,则系统结束派单,乘客端显示无司机接单、是否再次打车 |
| | | int num = 0; |
| | | for (int j = 0; j < 6; j++) { |
| | | Boolean push = false; |
| | | for (int i = 1; i <= querys.size(); i++) { |
| | | num++; |
| | | int finalI = i; |
| | | PushOrder pushOrder = querys.stream().filter(s -> s.getType() == (finalI <= 3 ? finalI : 3)).findFirst().orElse(null); |
| | | System.out.println("pushOrder:" + pushOrder); |
| | | //获取空闲司机 |
| | | List<Driver> list = driverService.queryIdleDriver(2, orderTaxi.getStartLon(), orderTaxi.getStartLat(), pushOrder.getPushDistance(), null);//所有附近空闲司机 |
| | | //随机排序 |
| | | Collections.shuffle(list); |
| | | if (list.size() > 0) { |
| | | double driverProportion = pushOrder.getDriverProportion() / 100;//推送占比计算成小数 |
| | | int lastIndex = Double.valueOf(list.size() * driverProportion).intValue();//计算占比转成整数(下标截取) |
| | | lastIndex = lastIndex == 0 ? list.size() : lastIndex; |
| | | list = list.subList(0, lastIndex);//获取空闲司机中占比数据 |
| | | for (Driver driver : list) {//开始进行推送 |
| | | //查询是否在限制推单范围内 |
| | | boolean bo = false; |
| | | for (Integer integer : integers) { |
| | | if (integer.compareTo(driver.getId()) == 0) { |
| | | bo = true; |
| | | break; |
| | | |
| | | // 判断是否为派单模式 |
| | | TSysPushType sysPushType = tSysPushTypeService.selectOne(new EntityWrapper<TSysPushType>().eq("openCityId", openCity.getId())); |
| | | if(sysPushType!=null && sysPushType.getPushType()==2){ |
| | | OrderTaxi orderTaxi1 = orderTaxiMapper.selectById(orderTaxi.getId()); |
| | | if (null == orderTaxi1 && orderTaxi1.getState() == 1) { |
| | | // 固定5公里进行派单 |
| | | List<Driver> listDriver = driverService.queryIdleDriver(2, orderTaxi1.getStartLon(), orderTaxi1.getStartLat(), 5.0, null);//所有附近空闲司机 |
| | | if (listDriver.size() > 0) { |
| | | Driver driver1 = listDriver.stream().sorted(Comparator.comparingDouble(Driver::getDistance).reversed()).findFirst().get(); |
| | | |
| | | orderTaxi1.setDriverId(driver1.getId()); |
| | | orderTaxi1.setCarId(driver1.getCarId()); |
| | | orderTaxi1.setCompanyId(driver1.getFranchiseeId() != null && driver1.getFranchiseeId() != 0 ? driver1.getFranchiseeId() : ( |
| | | driver1.getCompanyId() != null && driver1.getCompanyId() != 0 ? driver1.getCompanyId() : 1)); |
| | | orderTaxi1.setState(2); |
| | | orderTaxi1.setSnatchOrderTime(new Date()); |
| | | |
| | | // 是否推广订单 |
| | | Integer promotion = isPromotion(orderTaxi1.getUserId(), driver1.getPlaceOfEmployment()); |
| | | if(promotion!=null){ |
| | | orderTaxi1.setPromotion(2); |
| | | orderTaxi1.setPromotionUser(driver1.getName()); |
| | | orderTaxi1.setPromotionPhone(driver1.getPhone()); |
| | | orderTaxi1.setPromotionDriverId(promotion); |
| | | }else{ |
| | | orderTaxi1.setPromotion(1); |
| | | } |
| | | orderTaxiMapper.updateById(orderTaxi1); |
| | | |
| | | |
| | | if(orderTaxi.getType() == 2){ |
| | | List<OrderTaxi> list = orderTaxiMapper.selectList( |
| | | new EntityWrapper<OrderTaxi>() |
| | | .eq("type", 2) |
| | | .eq("userId", orderTaxi.getUserId()) |
| | | .ne("state", 1) |
| | | .eq("crossCityOrderId", orderTaxi.getCrossCityOrderId()) |
| | | .eq("place", orderTaxi.getPlace()).ne("id", orderTaxi.getId()) |
| | | ); |
| | | List<OrderPrivateCar> list1 = orderPrivateCarService.selectList( |
| | | new EntityWrapper<OrderPrivateCar>() |
| | | .eq("type", 2) |
| | | .eq("userId", orderTaxi.getUserId()) |
| | | .ne("state", 1) |
| | | .eq("crossCityOrderId", orderTaxi.getCrossCityOrderId()) |
| | | .eq("place", orderTaxi.getPlace()) |
| | | ); |
| | | for(OrderTaxi orderTaxi2 : list){ |
| | | orderTaxi2.setState(10); |
| | | orderTaxiMapper.updateById(orderTaxi2); |
| | | } |
| | | for(OrderPrivateCar orderPrivateCar : list1){ |
| | | orderPrivateCar.setState(10); |
| | | orderPrivateCarService.updateById(orderPrivateCar); |
| | | } |
| | | } |
| | | |
| | | |
| | | //如果是预约单,则不修改司机为服务中 |
| | | if(orderTaxi1.getOrderType() != 2 || (orderTaxi1.getOrderType() == 2 && orderTaxi1.getTravelTime().getTime() < System.currentTimeMillis() + 600000)){ |
| | | //修改司机为服务中 |
| | | driver1.setState(3); |
| | | driverService.updateById(driver1); |
| | | } |
| | | |
| | | //推送相关代码------------------start---------------- |
| | | OrderTaxi finalOrderTaxi = orderTaxi1; |
| | | new Thread(new Runnable() { |
| | | @Override |
| | | public void run() { |
| | | pushUtil.pushOrderState(1, finalOrderTaxi.getUserId(), finalOrderTaxi.getId(), 2, finalOrderTaxi.getState(),0); |
| | | pushUtil.pushOrderState(2, finalOrderTaxi.getDriverId(), finalOrderTaxi.getId(), 2, finalOrderTaxi.getState(),0); |
| | | if(finalOrderTaxi.getType() == 2){ |
| | | pushUtil.pushFerryOrderState(1, finalOrderTaxi.getUserId(), finalOrderTaxi.getId(), 2, 2); |
| | | System.err.println("----------------------------------推送摆渡订单-----------------------------"); |
| | | } |
| | | |
| | | } |
| | | }).start(); |
| | | |
| | | new Thread(new Runnable() { |
| | | @Override |
| | | public void run() { |
| | | pushUtil.pushDriverPosition(finalOrderTaxi.getId(), 2); |
| | | } |
| | | }).start(); |
| | | |
| | | systemNoticeService.addSystemNotice(2, "以为您派得出租车订单,请及时联系客户!", orderTaxi.getDriverId(), 1); |
| | | systemNoticeService.addSystemNotice(1, "您的订单已指派给" + driver1.getName().substring(0, 1) + "师傅,请保持电话畅通!", orderTaxi.getUserId(), 1); |
| | | |
| | | |
| | | }else { |
| | | // 没找到车辆 |
| | | OrderTaxi orderTaxi2 = orderTaxiMapper.selectById(orderTaxi.getId()); |
| | | orderTaxi2.setState(10); |
| | | orderTaxiMapper.updateById(orderTaxi2); |
| | | pushUtil.pushEndPush(1, orderTaxi2.getUserId(), orderTaxi2.getId(), 2, 1); |
| | | |
| | | // TODO 退款 |
| | | } |
| | | |
| | | |
| | | } |
| | | |
| | | }else { |
| | | |
| | | List<PushOrder> querys = pushOrderService.querys(null, 2, openCity.getId());//获取需要推送的次数 |
| | | //整轮派单结束,若无司机接单,系统自动增加派单5轮,若增加5轮后任无司机接单,则系统结束派单,乘客端显示无司机接单、是否再次打车 |
| | | int num = 0; |
| | | for (int j = 0; j < 6; j++) { |
| | | Boolean push = false; |
| | | for (int i = 1; i <= querys.size(); i++) { |
| | | num++; |
| | | int finalI = i; |
| | | PushOrder pushOrder = querys.stream().filter(s -> s.getType() == (finalI <= 3 ? finalI : 3)).findFirst().orElse(null); |
| | | System.out.println("pushOrder:" + pushOrder); |
| | | //获取空闲司机 |
| | | List<Driver> list = driverService.queryIdleDriver(2, orderTaxi.getStartLon(), orderTaxi.getStartLat(), pushOrder.getPushDistance(), null);//所有附近空闲司机 |
| | | //随机排序 |
| | | Collections.shuffle(list); |
| | | if (list.size() > 0) { |
| | | double driverProportion = pushOrder.getDriverProportion() / 100;//推送占比计算成小数 |
| | | int lastIndex = Double.valueOf(list.size() * driverProportion).intValue();//计算占比转成整数(下标截取) |
| | | lastIndex = lastIndex == 0 ? list.size() : lastIndex; |
| | | list = list.subList(0, lastIndex);//获取空闲司机中占比数据 |
| | | for (Driver driver : list) {//开始进行推送 |
| | | //查询是否在限制推单范围内 |
| | | boolean bo = false; |
| | | for (Integer integer : integers) { |
| | | if (integer.compareTo(driver.getId()) == 0) { |
| | | bo = true; |
| | | break; |
| | | } |
| | | } |
| | | if (bo) { |
| | | continue; |
| | | } |
| | | pushUtil.pushOrderState(2, driver.getId(), orderTaxi.getId(), 2, orderTaxi.getState(), pushOrder.getPushTime()); |
| | | } |
| | | if (bo) { |
| | | continue; |
| | | } |
| | | pushUtil.pushOrderState(2, driver.getId(), orderTaxi.getId(), 2, orderTaxi.getState(), pushOrder.getPushTime()); |
| | | } |
| | | Thread.sleep(pushOrder.getPushTime() * 1000);//设置等待时间 |
| | | OrderPrivateCar orderTaxi1 = orderPrivateCarService.selectById(orderTaxi.getId()); |
| | | if(null == orderTaxi1){ |
| | | break; |
| | | } |
| | | Integer state = orderTaxi1.getState(); |
| | | if (state != 1) { |
| | | push = true; |
| | | break; |
| | | } |
| | | if (num == 18 && state == 1) { |
| | | orderTaxi1.setState(10); |
| | | orderPrivateCarService.updateById(orderTaxi1); |
| | | pushUtil.pushEndPush(1, orderTaxi.getUserId(), orderTaxi.getId(), 2, 1); |
| | | orderIds.remove(orderTaxi.getId()); |
| | | } |
| | | } |
| | | Thread.sleep(pushOrder.getPushTime() * 1000);//设置等待时间 |
| | | OrderPrivateCar orderTaxi1 = orderPrivateCarService.selectById(orderTaxi.getId()); |
| | | if(null == orderTaxi1){ |
| | | if(push){ |
| | | break; |
| | | } |
| | | Integer state = orderTaxi1.getState(); |
| | | if (state != 1) { |
| | | push = true; |
| | | break; |
| | | } |
| | | if (num == 18 && state == 1) { |
| | | orderTaxi1.setState(10); |
| | | orderPrivateCarService.updateById(orderTaxi1); |
| | | pushUtil.pushEndPush(1, orderTaxi.getUserId(), orderTaxi.getId(), 2, 1); |
| | | orderIds.remove(orderTaxi.getId()); |
| | | } |
| | | } |
| | | if(push){ |
| | | break; |
| | | } |
| | | } |
| | | |
| | | |
| | | |
| | | |
| | | |
| | | } catch (Exception e) { |
| | | e.printStackTrace(); |
| | |
| | | } |
| | | }).start(); |
| | | } |
| | | |
| | | |
| | | |
| | | private Integer isPromotion(Integer userId, String code){ |
| | | UserInfo userInfo = userInfoService.selectById(userId); |
| | | if(userInfo.getBindDriverId()!=null && userInfo.getBindExpireDate().getTime()>=System.currentTimeMillis()){ |
| | | TDriverPromotionActivity tDriverPromotionActivity = driverPromotionActivityService.selectOne(new EntityWrapper<TDriverPromotionActivity>().eq("districtCode", code) |
| | | .eq("state",1).le("startTime", new Date()).ge("endTime", new Date()).last("AND FIND_IN_SET(" + 1 + ", bizType) limit 1")); |
| | | if(tDriverPromotionActivity!=null){ |
| | | return userInfo.getBindDriverId(); |
| | | } |
| | | } |
| | | return null; |
| | | |
| | | } |
| | | |
| | | @Override |
| | | public synchronized String getOrderNum() throws Exception { |