| | |
| | | package com.stylefeng.guns.modular.specialTrain.server.impl; |
| | | |
| | | import com.alibaba.fastjson.JSON; |
| | | import com.alibaba.fastjson.JSONArray; |
| | | import com.alibaba.fastjson.JSONObject; |
| | | import com.baomidou.mybatisplus.mapper.EntityWrapper; |
| | | import com.baomidou.mybatisplus.service.impl.ServiceImpl; |
| | |
| | | import com.stylefeng.guns.modular.system.util.*; |
| | | import com.stylefeng.guns.modular.taxi.model.OrderTaxi; |
| | | import com.stylefeng.guns.modular.taxi.service.IOrderTaxiService; |
| | | import org.gavaghan.geodesy.Ellipsoid; |
| | | import org.gavaghan.geodesy.GeodeticCalculator; |
| | | import org.gavaghan.geodesy.GeodeticCurve; |
| | | import org.gavaghan.geodesy.GlobalCoordinates; |
| | | import org.springframework.beans.factory.annotation.Autowired; |
| | | import org.springframework.beans.factory.annotation.Value; |
| | | import org.springframework.stereotype.Service; |
| | | import org.springframework.util.CollectionUtils; |
| | | import org.springframework.util.StringUtils; |
| | | |
| | | import javax.annotation.Resource; |
| | | import java.io.File; |
| | |
| | | import java.math.BigDecimal; |
| | | import java.math.MathContext; |
| | | import java.math.RoundingMode; |
| | | import java.time.Duration; |
| | | import java.time.LocalDateTime; |
| | | import java.util.*; |
| | | |
| | | |
| | |
| | | |
| | | @Resource |
| | | private UserInfoMapper userInfoMapper; |
| | | |
| | | @Autowired |
| | | private ITransactionDetailsService transactionDetailsService; |
| | | @Autowired |
| | | private ICompanyService companyService; |
| | | |
| | | @Autowired |
| | | private IIncomeService incomeService; |
| | | |
| | | @Autowired |
| | | private ISpecialAreaBillingService specialAreaBillingService; |
| | | @Autowired |
| | | private PayMoneyUtil payMoneyUtil; |
| | | |
| | | @Value("${filePath}") |
| | | private String filePath; |
| | |
| | | orderPrivateCar.setSnatchOrderTime(new Date()); |
| | | |
| | | //调用高德创建轨迹 |
| | | String s = gdFalconUtil.selectTerminal(driver.getPhone()); |
| | | String track = gdFalconUtil.createTrack(s); |
| | | orderPrivateCar.setTrackId(track); |
| | | // String s = gdFalconUtil.selectTerminal(driver.getPhone()); |
| | | // String track = gdFalconUtil.createTrack(s); |
| | | // JSONObject jsonObject = JSONObject.parseObject(track); |
| | | // orderPrivateCar.setTrackId(String.valueOf(jsonObject.getInteger("trid"))); |
| | | |
| | | //调用移动的小号接口 |
| | | /*Map<String, String> geocode = gdMapGeocodingUtil.geocode(orderPrivateCar.getStartLon().toString(), orderPrivateCar.getStartLat().toString()); |
| | |
| | | public void run() { |
| | | if(pushMinistryOfTransport){ |
| | | //上传数据 |
| | | pushMinistryOfTransportUtil.orderCreate(orderId); |
| | | pushMinistryOfTransportUtil.orderMatch(orderId); |
| | | try { |
| | | pushMinistryOfTransportUtil.orderCreate(orderId); |
| | | } catch (Exception e) { |
| | | throw new RuntimeException(e); |
| | | } |
| | | try { |
| | | pushMinistryOfTransportUtil.orderMatch(orderId); |
| | | } catch (Exception e) { |
| | | throw new RuntimeException(e); |
| | | } |
| | | } |
| | | } |
| | | }).start(); |
| | |
| | | }*/ |
| | | switch (state){ |
| | | case 3://出发前往预约点 |
| | | // 判断是否有其他未完成的单子 |
| | | List<OrderPrivateCar> orderPrivateCars = orderPrivateCarMapper.queryDriverByState(orderPrivateCar.getDriverId(), 1, 1, 3,4, 5,6); |
| | | if(!CollectionUtils.isEmpty(orderPrivateCars)){ |
| | | return ResultUtil.error("有未完成的服务订单"); |
| | | } |
| | | orderPrivateCar.setState(3); |
| | | orderPrivateCar.setSetOutTime(new Date()); |
| | | systemNoticeService.addSystemNotice(1, "司机已出发,请耐心等待", orderPrivateCar.getUserId()); |
| | |
| | | } |
| | | } |
| | | }).start(); |
| | | OrderPosition orderPosition = new OrderPosition(); |
| | | orderPosition.setOrderId(orderId); |
| | | orderPosition.setOrderType(1); |
| | | orderPosition.setDriverId(orderPrivateCar.getDriverId()); |
| | | orderPosition.setLat(lat.toString()); |
| | | orderPosition.setLon(lon.toString()); |
| | | orderPosition.setAltitude("0"); |
| | | orderPosition.setDirectionAngle("0"); |
| | | //先计算里程,在存储最新位置 |
| | | orderPosition.setInsertTime(new Date()); |
| | | //将数据存储到文件中 |
| | | List<OrderPosition> orderPositions = orderPositionService.queryPosition(orderPosition.getOrderId(), orderPosition.getOrderType()); |
| | | File file = new File(filePath + orderPosition.getOrderId() + "_" + orderPosition.getOrderType() + ".txt"); |
| | | if(!file.exists()){ |
| | | file.getParentFile().mkdirs(); |
| | | file.createNewFile(); |
| | | } |
| | | //写入相应的文件 |
| | | PrintWriter out = new PrintWriter(new FileWriter(file)); |
| | | orderPositions.add(orderPosition); |
| | | out.write(JSON.toJSONString(orderPositions)); |
| | | out.flush(); |
| | | out.close(); |
| | | break; |
| | | case 6://结束服务(专车可以返回继续服务)不修改状态 |
| | | orderPrivateCar.setGetoffLon(lon); |
| | |
| | | orderPrivateCar.setGetoffAddress(address); |
| | | orderPrivateCar.setGetoffTime(new Date()); |
| | | orderPrivateCar.setEndServiceTime(new Date()); |
| | | |
| | | // 结束服务时查询轨迹,计算距离 |
| | | Driver driver = driverService.selectById(orderPrivateCar.getDriverId()); |
| | | double sum = 0; |
| | | try { |
| | | String tid = gdFalconUtil.selectTerminal(driver.getPhone()); |
| | | String result = gdFalconUtil.selectTrack(tid, orderPrivateCar.getTrackId(),1); |
| | | |
| | | JSONObject jsonObject = JSONObject.parseObject(result); |
| | | JSONArray tracks = jsonObject.getJSONArray("tracks"); |
| | | Integer counts = jsonObject.getInteger("counts"); |
| | | JSONArray points = new JSONArray(); |
| | | // 如果一单轨迹点数大于999,需进行分页查询,将所有的点查询出 |
| | | if(counts > 999){ |
| | | int i = counts%999; |
| | | for (int j = 1; j < i + 1; j++) { |
| | | String res = gdFalconUtil.selectTrack(tid, orderPrivateCar.getTrackId(),1); |
| | | JSONObject jsonObject1 = JSONObject.parseObject(res); |
| | | JSONArray tracks1 = jsonObject1.getJSONArray("tracks"); |
| | | Object ob = tracks1.get(0); |
| | | String obs = JSONObject.toJSONString(ob); |
| | | JSONObject object = JSONObject.parseObject(obs); |
| | | JSONArray point = object.getJSONArray("points"); |
| | | points.addAll(point); |
| | | } |
| | | } |
| | | // 轨迹点数小于999,一页查询出即可 |
| | | if(counts > 0 && counts < 999){ |
| | | Object ob = tracks.get(0); |
| | | String obs = JSONObject.toJSONString(ob); |
| | | JSONObject object = JSONObject.parseObject(obs); |
| | | JSONArray point = object.getJSONArray("points"); |
| | | points.addAll(point); |
| | | } |
| | | |
| | | String toLonLat = ""; |
| | | List<OrderPosition> orderPositions = new ArrayList<>(); |
| | | for (Object o : points) { |
| | | String s = JSONObject.toJSONString(o); |
| | | JSONObject obj = JSONObject.parseObject(s); |
| | | String fromLonLat = obj.getString("location"); |
| | | String[] split = fromLonLat.split(","); |
| | | Long locatetime = obj.getLong("locatetime"); |
| | | Date date = new Date(locatetime); |
| | | if(date.after(orderPrivateCar.getStartServiceTime()) && date.before(orderPrivateCar.getEndServiceTime())){ |
| | | // 封装定位文件里的单个定位对象 |
| | | OrderPosition orderPosition = new OrderPosition(); |
| | | orderPosition.setOrderId(orderId); |
| | | orderPosition.setOrderType(1); |
| | | orderPosition.setDriverId(orderPrivateCar.getDriverId()); |
| | | orderPosition.setLat(split[1]); |
| | | orderPosition.setLon(split[0]); |
| | | orderPosition.setAltitude("0"); |
| | | orderPosition.setDirectionAngle("0"); |
| | | //先计算里程,在存储最新位置 |
| | | orderPosition.setInsertTime(new Date()); |
| | | orderPositions.add(orderPosition); |
| | | if(StringUtils.hasLength(fromLonLat) && StringUtils.hasLength(toLonLat)){ |
| | | String[] from = fromLonLat.split(","); |
| | | String[] to = toLonLat.split(","); |
| | | GlobalCoordinates source = new GlobalCoordinates(Double.valueOf(from[1]), Double.valueOf(from[0])); |
| | | GlobalCoordinates target = new GlobalCoordinates(Double.valueOf(to[1]), Double.valueOf(to[0])); |
| | | double WGS84 = getDistanceMeter(source, target, Ellipsoid.WGS84); |
| | | sum += WGS84; |
| | | } |
| | | toLonLat = fromLonLat; |
| | | } |
| | | } |
| | | |
| | | //存储轨迹 |
| | | // 将数据存储到文件中 |
| | | File file = new File(filePath + orderId + "_" + 1 + ".txt"); |
| | | if(!file.exists()){ |
| | | file.getParentFile().mkdirs(); |
| | | file.createNewFile(); |
| | | } |
| | | //写入相应的文件 |
| | | PrintWriter out = new PrintWriter(new FileWriter(file)); |
| | | out.write(JSON.toJSONString(orderPositions)); |
| | | out.flush(); |
| | | out.close(); |
| | | }catch (Exception e){ |
| | | e.printStackTrace(); |
| | | System.err.println("查询高德轨迹出错,使用本地轨迹计算"); |
| | | List<OrderPosition> list = orderPositionService.queryPosition(orderId, 1); |
| | | String fromLonLat = ""; |
| | | for (OrderPosition orderPosition : list) { |
| | | String toLonLat = orderPosition.getLon() + "," + orderPosition.getLat(); |
| | | if(StringUtils.hasLength(fromLonLat) && StringUtils.hasLength(toLonLat)){ |
| | | String[] from = fromLonLat.split(","); |
| | | String[] to = toLonLat.split(","); |
| | | GlobalCoordinates source = new GlobalCoordinates(Double.valueOf(from[1]), Double.valueOf(from[0])); |
| | | GlobalCoordinates target = new GlobalCoordinates(Double.valueOf(to[1]), Double.valueOf(to[0])); |
| | | double WGS84 = getDistanceMeter(source, target, Ellipsoid.WGS84); |
| | | sum += WGS84; |
| | | } |
| | | fromLonLat = toLonLat; |
| | | } |
| | | } |
| | | orderPrivateCar.setMileage(sum); |
| | | orderPrivateCar.setIsAbnormal(0); |
| | | break; |
| | | } |
| | | this.updateById(orderPrivateCar); |
| | |
| | | return ResultUtil.success(); |
| | | } |
| | | |
| | | private double getDistanceMeter(GlobalCoordinates gpsFrom, GlobalCoordinates gpsTo, Ellipsoid ellipsoid){ |
| | | //创建GeodeticCalculator,调用计算方法,传入坐标系、经纬度用于计算距离 |
| | | GeodeticCurve geoCurve = new GeodeticCalculator().calculateGeodeticCurve(ellipsoid, gpsFrom, gpsTo); |
| | | return geoCurve.getEllipsoidalDistance(); |
| | | } |
| | | |
| | | |
| | | /** |
| | |
| | | @Override |
| | | public ResultUtil confirmFees(Integer orderId, Integer type, Double parkingFee, Double crossingFee) throws Exception { |
| | | OrderPrivateCar orderPrivateCar = this.selectById(orderId); |
| | | if(Objects.nonNull(orderPrivateCar.getPriceAuditState()) && orderPrivateCar.getPriceAuditState() == 1){ |
| | | return ResultUtil.error("待平台审核中"); |
| | | } |
| | | if(orderPrivateCar.getState() != 5){ |
| | | return ResultUtil.error("异常操作,请刷新订单"); |
| | | } |
| | | if(orderPrivateCar.getArriveTime()==null){ |
| | | orderPrivateCar.setArriveTime(orderPrivateCar.getStartServiceTime()); |
| | | } |
| | | orderPrivateCar = this.setMoney(orderPrivateCar, 0D, 0D);//计算费用 |
| | | |
| | | // 查询起点或者终点在特殊区域中 |
| | | List<SpecialAreaBilling> specialAreaBillings = specialAreaBillingService.selectList(new EntityWrapper<SpecialAreaBilling>() |
| | | .eq("state", 1)); |
| | | if(!CollectionUtils.isEmpty(specialAreaBillings)){ |
| | | // 判断起点或者终点在特殊区域中 |
| | | Iterator<SpecialAreaBilling> iterator = specialAreaBillings.iterator(); |
| | | while (iterator.hasNext()) { |
| | | SpecialAreaBilling specialAreaBilling = iterator.next(); |
| | | // 起点 |
| | | Double startLon = orderPrivateCar.getStartLon(); |
| | | Double startLat = orderPrivateCar.getStartLat(); |
| | | boolean start = ElectricFenceUtil.monitorElectricFenc(specialAreaBilling.getCoordinate(), startLon + "," + startLat); |
| | | // 终点 |
| | | Double endLon = orderPrivateCar.getEndLon(); |
| | | Double endLat = orderPrivateCar.getEndLat(); |
| | | boolean end = ElectricFenceUtil.monitorElectricFenc(specialAreaBilling.getCoordinate(), endLon + "," + endLat); |
| | | if(!start && !end){ |
| | | iterator.remove(); |
| | | } |
| | | } |
| | | if(!CollectionUtils.isEmpty(specialAreaBillings)){ |
| | | // 拿到价格系数最高的特殊区域 |
| | | specialAreaBillings.sort(new Comparator<SpecialAreaBilling>() { |
| | | @Override |
| | | public int compare(SpecialAreaBilling o1, SpecialAreaBilling o2) { |
| | | return o2.getPriceCoefficient().compareTo(o1.getPriceCoefficient()); |
| | | } |
| | | }); |
| | | BigDecimal priceCoefficient = specialAreaBillings.get(0).getPriceCoefficient(); |
| | | orderPrivateCar.setOrderMoney(Objects.nonNull(orderPrivateCar.getOrderMoney())?new BigDecimal(orderPrivateCar.getOrderMoney()).multiply(priceCoefficient).setScale(2, BigDecimal.ROUND_HALF_EVEN).doubleValue():0D); |
| | | orderPrivateCar.setStartMoney(Objects.nonNull(orderPrivateCar.getStartMoney())?new BigDecimal(orderPrivateCar.getStartMoney()).multiply(priceCoefficient).setScale(2, BigDecimal.ROUND_HALF_EVEN).doubleValue():0D); |
| | | orderPrivateCar.setMileageMoney(Objects.nonNull(orderPrivateCar.getMileageMoney())?new BigDecimal(orderPrivateCar.getMileageMoney()).multiply(priceCoefficient).setScale(2, BigDecimal.ROUND_HALF_EVEN).doubleValue():0D); |
| | | orderPrivateCar.setDurationMoney(Objects.nonNull(orderPrivateCar.getDurationMoney())?new BigDecimal(orderPrivateCar.getDurationMoney()).multiply(priceCoefficient).setScale(2, BigDecimal.ROUND_HALF_EVEN).doubleValue():0D); |
| | | orderPrivateCar.setWaitMoney(Objects.nonNull(orderPrivateCar.getWaitMoney())?new BigDecimal(orderPrivateCar.getWaitMoney()).multiply(priceCoefficient).setScale(2, BigDecimal.ROUND_HALF_EVEN).doubleValue():0D); |
| | | orderPrivateCar.setLongDistanceMoney(Objects.nonNull(orderPrivateCar.getLongDistanceMoney())?new BigDecimal(orderPrivateCar.getLongDistanceMoney()).multiply(priceCoefficient).setScale(2, BigDecimal.ROUND_HALF_EVEN).doubleValue():0D); |
| | | orderPrivateCar.setParkMoney(Objects.nonNull(orderPrivateCar.getParkMoney())?new BigDecimal(orderPrivateCar.getParkMoney()).multiply(priceCoefficient).setScale(2, BigDecimal.ROUND_HALF_EVEN).doubleValue():0D); |
| | | orderPrivateCar.setRoadTollMoney(Objects.nonNull(orderPrivateCar.getRoadTollMoney())?new BigDecimal(orderPrivateCar.getRoadTollMoney()).multiply(priceCoefficient).setScale(2, BigDecimal.ROUND_HALF_EVEN).doubleValue():0D); |
| | | } |
| | | } |
| | | |
| | | orderPrivateCar.setPayManner(type); |
| | | orderPrivateCar.setParkMoney(null == parkingFee ? 0D : parkingFee); |
| | | orderPrivateCar.setRoadTollMoney(null == crossingFee ? 0D : crossingFee); |
| | | orderPrivateCar.setOrderMoney(orderPrivateCar.getOrderMoney() + orderPrivateCar.getParkMoney() + orderPrivateCar.getRoadTollMoney()); |
| | | orderPrivateCar.setIsConfirm(1); |
| | | //判断是否首单免费-免费直接完成 |
| | | Integer orderNumber = this.selectCount(new EntityWrapper<OrderPrivateCar>().eq("userId",orderPrivateCar.getUserId()).last("and (state=8 or state=9)")); |
| | | |
| | | if(orderNumber<=0){//判断是否是首单 |
| | | //判断是否免单 |
| | | UserInfo userInfo = userInfoMapper.selectById(orderPrivateCar.getUserId()); |
| | | if(userInfo.getFreeMoney().doubleValue()>0d){ |
| | | if(Objects.nonNull(userInfo.getFreeMoney()) && userInfo.getFreeMoney().doubleValue()>0d){ |
| | | if(orderPrivateCar.getOrderMoney()<=userInfo.getFreeMoney().doubleValue()){ |
| | | orderPrivateCar.setState(8); |
| | | orderPrivateCar.setIsFree(2); |
| | |
| | | c = new BigDecimal(orderPrivateCar.getOrderMoney()).subtract(d).setScale(2, BigDecimal.ROUND_HALF_EVEN); |
| | | } |
| | | incomeService.saveData(1, orderPrivateCar.getCompanyId(), 2, orderPrivateCar.getId(), 1, d.doubleValue()); |
| | | incomeService.saveData(2, orderPrivateCar.getDriverId(), 2, orderPrivateCar.getId(), 1, c.doubleValue()); |
| | | Driver driver = driverService.selectById(orderPrivateCar.getDriverId()); |
| | | driver.setBusinessMoney(new BigDecimal(null != driver.getBusinessMoney() ? driver.getBusinessMoney() : 0).add(c).setScale(2, BigDecimal.ROUND_HALF_EVEN).doubleValue()); |
| | | driver.setLaveBusinessMoney(new BigDecimal(null != driver.getLaveBusinessMoney() ? driver.getLaveBusinessMoney() : 0).add(c).setScale(2, BigDecimal.ROUND_HALF_EVEN).doubleValue()); |
| | | driver.setBalance(new BigDecimal(null != driver.getBalance() ? driver.getBalance() : 0).add(c).setScale(2, BigDecimal.ROUND_HALF_EVEN).doubleValue()); |
| | | driverService.updateById(driver); |
| | | incomeService.saveDriverData(2, orderPrivateCar.getDriverId(), 2, orderPrivateCar.getId(), 1, c.doubleValue(),driver.getLaveBusinessMoney()); |
| | | }else{ |
| | | orderPrivateCar.setState(7); |
| | | orderPrivateCar.setOrderMoney(orderPrivateCar.getOrderMoney()-userInfo.getFreeMoney().doubleValue()); |
| | |
| | | orderPrivateCar.setState(7); |
| | | } |
| | | |
| | | if(orderPrivateCar.getPayMethod() == 0 && new BigDecimal(orderPrivateCar.getPaymentAdvanceMoney()).compareTo(BigDecimal.ZERO)>0 && new BigDecimal(orderPrivateCar.getPaymentAdvanceMoney()).compareTo(new BigDecimal(orderPrivateCar.getOrderMoney()))>-1) { |
| | | orderPrivateCar.setState(8); |
| | | // 退款情况 |
| | | if (new BigDecimal(orderPrivateCar.getPaymentAdvanceMoney()).compareTo(new BigDecimal(orderPrivateCar.getOrderMoney())) > 0) { |
| | | // 退款 |
| | | if (orderPrivateCar.getPayType() == 1 && orderPrivateCar.getOrderMoney() != 0) {//微信退款 |
| | | // 微信退款 |
| | | payMoneyUtil.wxRefund(orderPrivateCar.getTransactionId(), orderPrivateCar.getOrderNum(), String.valueOf(orderPrivateCar.getPaymentAdvanceMoney()), String.valueOf(new BigDecimal(orderPrivateCar.getPaymentAdvanceMoney()).subtract(new BigDecimal(orderPrivateCar.getOrderMoney()))), "/base/transferWXNotify"); |
| | | orderPrivateCar.setPayMoney(new BigDecimal(orderPrivateCar.getOrderMoney()).doubleValue()); |
| | | } |
| | | if (orderPrivateCar.getPayType() == 2 && orderPrivateCar.getOrderMoney() != 0) {//支付宝退款 |
| | | // 支付宝退款 |
| | | payMoneyUtil.aliRefund(orderPrivateCar.getTransactionId(), String.valueOf(new BigDecimal(orderPrivateCar.getPaymentAdvanceMoney()).subtract(new BigDecimal(orderPrivateCar.getOrderMoney())).multiply(new BigDecimal(100)))); |
| | | orderPrivateCar.setPayMoney(new BigDecimal(orderPrivateCar.getOrderMoney()).doubleValue()); |
| | | } |
| | | if (orderPrivateCar.getPayType() == 3 && orderPrivateCar.getOrderMoney() != 0) {//余额支付 |
| | | BigDecimal refundMoney = new BigDecimal(orderPrivateCar.getPaymentAdvanceMoney()).subtract(new BigDecimal(orderPrivateCar.getOrderMoney())); |
| | | // 余额退款 |
| | | UserInfo userInfo = userInfoMapper.selectById(orderPrivateCar.getUserId()); |
| | | userInfo.setBalance(new BigDecimal(userInfo.getBalance()).add(refundMoney).doubleValue()); |
| | | userInfoMapper.updateById(userInfo); |
| | | //添加交易明细 |
| | | transactionDetailsService.saveData(orderPrivateCar.getUserId(), "专车差价退款", refundMoney.doubleValue(), 2, 1, 1, 1, orderPrivateCar.getId()); |
| | | } |
| | | } else { |
| | | orderPrivateCar.setPayMoney(new BigDecimal(orderPrivateCar.getPaymentAdvanceMoney()).doubleValue()); |
| | | } |
| | | //添加已收入明细 |
| | | Company company = companyService.selectById(orderPrivateCar.getCompanyId()); |
| | | Double speMoney = company.getSpeMoney(); |
| | | BigDecimal d = null;//企业收入 |
| | | BigDecimal c = null;//司机收入 |
| | | if(company.getIsSpeFixedOrProportional() == 2){//固定 |
| | | d = new BigDecimal(speMoney); |
| | | c = new BigDecimal(orderPrivateCar.getOrderMoney()).subtract(d);//只有出行金额参与抽成,其余归属司机 |
| | | if(c.compareTo(BigDecimal.ZERO)<1){ |
| | | c = BigDecimal.ZERO; |
| | | } |
| | | } |
| | | if(company.getIsSpeFixedOrProportional() == 1){//比例 |
| | | Double price = orderPrivateCar.getStartMoney() + orderPrivateCar.getMileageMoney() + orderPrivateCar.getWaitMoney() + orderPrivateCar.getDurationMoney() + orderPrivateCar.getLongDistanceMoney(); |
| | | d = new BigDecimal(price).multiply(new BigDecimal(speMoney).divide(new BigDecimal(100), new MathContext(2, RoundingMode.HALF_EVEN))).setScale(2, BigDecimal.ROUND_HALF_EVEN); |
| | | c = new BigDecimal(orderPrivateCar.getOrderMoney()).subtract(d).setScale(2, BigDecimal.ROUND_HALF_EVEN); |
| | | } |
| | | incomeService.saveData(1, orderPrivateCar.getCompanyId(), 2, orderPrivateCar.getId(), 1, d.doubleValue()); |
| | | Driver driver = driverService.selectById(orderPrivateCar.getDriverId()); |
| | | driver.setBusinessMoney(new BigDecimal(null != driver.getBusinessMoney() ? driver.getBusinessMoney() : 0).add(c).setScale(2, BigDecimal.ROUND_HALF_EVEN).doubleValue()); |
| | | driver.setLaveBusinessMoney(new BigDecimal(null != driver.getLaveBusinessMoney() ? driver.getLaveBusinessMoney() : 0).add(c).setScale(2, BigDecimal.ROUND_HALF_EVEN).doubleValue()); |
| | | driver.setBalance(new BigDecimal(null != driver.getBalance() ? driver.getBalance() : 0).add(c).setScale(2, BigDecimal.ROUND_HALF_EVEN).doubleValue()); |
| | | driverService.updateById(driver); |
| | | incomeService.saveDriverData(2, orderPrivateCar.getDriverId(), 2, orderPrivateCar.getId(), 1, c.doubleValue(), driver.getLaveBusinessMoney()); |
| | | }else { |
| | | orderPrivateCar.setState(7); |
| | | } |
| | | |
| | | // Map<String, String> map = chinaMobileUtil.midAxbUnBindSend(orderPrivateCar.getBindId(),orderPrivateCar.getTelX()); |
| | | // if(String.valueOf(map.get("code")).equals("200")){ |
| | | // orderPrivateCar.setTelX(""); |
| | | // orderPrivateCar.setBindId(""); |
| | | // } |
| | | // 判断预估金额和订单金额差异是否大于3元 |
| | | if(BigDecimal.valueOf(orderPrivateCar.getOrderMoney()).subtract(new BigDecimal(orderPrivateCar.getEstimatedPrice())).abs().doubleValue() > 3){ |
| | | orderPrivateCar.setIsException(1); |
| | | } |
| | | // if(orderPrivateCar.getIsException() == 1){ |
| | | // orderPrivateCar.setState(13); |
| | | // } |
| | | this.updateById(orderPrivateCar); |
| | | |
| | |
| | | this.setMoney(orderPrivateCar, 0D, 0D); |
| | | } |
| | | |
| | | if(Objects.isNull(orderPrivateCar.getEstimatedPrice())){ |
| | | orderPrivateCar.setEstimatedPrice(0D); |
| | | } |
| | | if(BigDecimal.valueOf(orderPrivateCar.getOrderMoney()).subtract(new BigDecimal(orderPrivateCar.getEstimatedPrice())).abs().doubleValue() > 3){ |
| | | orderPrivateCar.setIsException(1); |
| | | } |
| | | this.updateById(orderPrivateCar); |
| | | |
| | | if(orderPrivateCar.getIsConfirm() == 0){ |
| | | // 查询起点或者终点在特殊区域中 |
| | | List<SpecialAreaBilling> specialAreaBillings = specialAreaBillingService.selectList(new EntityWrapper<SpecialAreaBilling>() |
| | | .eq("state", 1)); |
| | | if(!CollectionUtils.isEmpty(specialAreaBillings)){ |
| | | // 判断起点或者终点在特殊区域中 |
| | | Iterator<SpecialAreaBilling> iterator = specialAreaBillings.iterator(); |
| | | while (iterator.hasNext()) { |
| | | SpecialAreaBilling specialAreaBilling = iterator.next(); |
| | | // 起点 |
| | | Double startLon = orderPrivateCar.getStartLon(); |
| | | Double startLat = orderPrivateCar.getStartLat(); |
| | | boolean start = ElectricFenceUtil.monitorElectricFenc(specialAreaBilling.getCoordinate(), startLon + "," + startLat); |
| | | // 终点 |
| | | Double endLon = orderPrivateCar.getEndLon(); |
| | | Double endLat = orderPrivateCar.getEndLat(); |
| | | boolean end = ElectricFenceUtil.monitorElectricFenc(specialAreaBilling.getCoordinate(), endLon + "," + endLat); |
| | | if(!start && !end){ |
| | | iterator.remove(); |
| | | } |
| | | } |
| | | if(!CollectionUtils.isEmpty(specialAreaBillings)){ |
| | | // 拿到价格系数最高的特殊区域 |
| | | specialAreaBillings.sort(new Comparator<SpecialAreaBilling>() { |
| | | @Override |
| | | public int compare(SpecialAreaBilling o1, SpecialAreaBilling o2) { |
| | | return o2.getPriceCoefficient().compareTo(o1.getPriceCoefficient()); |
| | | } |
| | | }); |
| | | BigDecimal priceCoefficient = specialAreaBillings.get(0).getPriceCoefficient(); |
| | | orderPrivateCar.setOrderMoney(Objects.nonNull(orderPrivateCar.getOrderMoney())?new BigDecimal(orderPrivateCar.getOrderMoney()).multiply(priceCoefficient).setScale(2, BigDecimal.ROUND_HALF_EVEN).doubleValue():0D); |
| | | orderPrivateCar.setStartMoney(Objects.nonNull(orderPrivateCar.getStartMoney())?new BigDecimal(orderPrivateCar.getStartMoney()).multiply(priceCoefficient).setScale(2, BigDecimal.ROUND_HALF_EVEN).doubleValue():0D); |
| | | orderPrivateCar.setMileageMoney(Objects.nonNull(orderPrivateCar.getMileageMoney())?new BigDecimal(orderPrivateCar.getMileageMoney()).multiply(priceCoefficient).setScale(2, BigDecimal.ROUND_HALF_EVEN).doubleValue():0D); |
| | | orderPrivateCar.setDurationMoney(Objects.nonNull(orderPrivateCar.getDurationMoney())?new BigDecimal(orderPrivateCar.getDurationMoney()).multiply(priceCoefficient).setScale(2, BigDecimal.ROUND_HALF_EVEN).doubleValue():0D); |
| | | orderPrivateCar.setWaitMoney(Objects.nonNull(orderPrivateCar.getWaitMoney())?new BigDecimal(orderPrivateCar.getWaitMoney()).multiply(priceCoefficient).setScale(2, BigDecimal.ROUND_HALF_EVEN).doubleValue():0D); |
| | | orderPrivateCar.setLongDistanceMoney(Objects.nonNull(orderPrivateCar.getLongDistanceMoney())?new BigDecimal(orderPrivateCar.getLongDistanceMoney()).multiply(priceCoefficient).setScale(2, BigDecimal.ROUND_HALF_EVEN).doubleValue():0D); |
| | | orderPrivateCar.setParkMoney(Objects.nonNull(orderPrivateCar.getParkMoney())?new BigDecimal(orderPrivateCar.getParkMoney()).multiply(priceCoefficient).setScale(2, BigDecimal.ROUND_HALF_EVEN).doubleValue():0D); |
| | | orderPrivateCar.setRoadTollMoney(Objects.nonNull(orderPrivateCar.getRoadTollMoney())?new BigDecimal(orderPrivateCar.getRoadTollMoney()).multiply(priceCoefficient).setScale(2, BigDecimal.ROUND_HALF_EVEN).doubleValue():0D); |
| | | } |
| | | } |
| | | } |
| | | |
| | | Map<String, Object> map = new HashMap<>(); |
| | | map.put("orderMoney", orderPrivateCar.getOrderMoney());//订单金额 |
| | | map.put("startMileage", orderPrivateCar.getStartMileage());//起步价 |
| | |
| | | map.put("couponMoney", orderPrivateCar.getCouponMoney());//优惠券抵扣金额 |
| | | map.put("discountMoney", orderPrivateCar.getDiscountMoney());//折扣抵扣金额 |
| | | map.put("discount", orderPrivateCar.getDiscount());//折扣 |
| | | map.put("estimatedPrice", orderPrivateCar.getEstimatedPrice()); |
| | | map.put("isException", orderPrivateCar.getIsException());//是否异常 |
| | | return map; |
| | | } |
| | | |
| | |
| | | @Override |
| | | public boolean calculateMileage(Integer orderId, String lon, String lat) throws Exception { |
| | | OrderPrivateCar orderPrivateCar = this.selectById(orderId); |
| | | // 判断距离上一次推送时间是否超过1分钟 |
| | | if(Objects.nonNull(orderPrivateCar.getLastPushTime())){ |
| | | LocalDateTime now = LocalDateTime.now(); |
| | | if(Duration.between(orderPrivateCar.getLastPushTime(), now).toMinutes() > 1){ |
| | | orderPrivateCar.setIsException(1); |
| | | } |
| | | orderPrivateCar.setLastPushTime(now); |
| | | }else { |
| | | orderPrivateCar.setLastPushTime(LocalDateTime.now()); |
| | | } |
| | | OrderPosition orderPosition = orderPositionService.queryNew(orderId, 1); |
| | | String now = lon + "," + lat; |
| | | String old = null; |
| | |
| | | this.updateById(orderPrivateCar); |
| | | return true;//第一条数据不作处理,直接存储 |
| | | } |
| | | Map<String, String> distance = gdMapElectricFenceUtil.getDistance(now, old, 0);//直线距离 |
| | | Map<String, Double> distance = GeodesyUtil.getDistance(now, old);//直线距离 |
| | | if(null != distance){ |
| | | String distance1 = distance.get("distance"); |
| | | if(Double.valueOf(distance1) > 50 && orderPrivateCar.getState()==5/* && orderPosition.getInsertTime().getTime()>=orderPrivateCar.getBoardingTime().getTime()*/){//大于50米表示在移动 |
| | | Double distance1 = distance.get("WGS84"); |
| | | if(distance1 > 50 && orderPrivateCar.getState()==5){//大于50米表示在移动 |
| | | orderPrivateCar.setMileage(new BigDecimal(orderPrivateCar.getMileage()).add(new BigDecimal(distance1)).setScale(2, BigDecimal.ROUND_HALF_EVEN).doubleValue()); |
| | | this.updateById(orderPrivateCar); |
| | | return true; |
| | |
| | | public List<OrderPrivateCar> getSmsOrderList() { |
| | | return this.baseMapper.getSmsOrderList(); |
| | | } |
| | | |
| | | @Override |
| | | public void getTrackId(Integer orderId, Integer trackId) { |
| | | OrderPrivateCar orderPrivateCar = this.selectById(orderId); |
| | | orderPrivateCar.setTrackId(String.valueOf(trackId)); |
| | | this.updateById(orderPrivateCar); |
| | | } |
| | | |
| | | @Override |
| | | public void updatePrice(Integer orderId, Integer priceType, BigDecimal updatePrice) { |
| | | OrderPrivateCar orderPrivateCar = this.selectById(orderId); |
| | | orderPrivateCar.setPriceType(priceType); |
| | | orderPrivateCar.setUpdatePrice(updatePrice); |
| | | orderPrivateCar.setOrderMoney(updatePrice.doubleValue()); |
| | | orderPrivateCar.setPriceAuditState(1); |
| | | orderPrivateCar.setState(6); |
| | | this.updateById(orderPrivateCar); |
| | | // 推送新的价格给用户 |
| | | pushUtil.pushOrderMoney(1, orderPrivateCar.getUserId(), orderPrivateCar.getId(), 1, updatePrice, 0); |
| | | pushUtil.pushOrderMoney(2, orderPrivateCar.getDriverId(), orderPrivateCar.getId(), 1, updatePrice, 0); |
| | | } |
| | | } |