From d45f3f7467e76477e8babbefd5844975bdff7af1 Mon Sep 17 00:00:00 2001 From: Pu Zhibing <393733352@qq.com> Date: 星期四, 28 十一月 2024 15:45:58 +0800 Subject: [PATCH] 修改bug --- UserIGOTravel/guns-admin/src/main/java/com/stylefeng/guns/modular/smallLogistics/server/impl/OrderLogisticsServiceImpl.java | 573 ++++++++++++++++++++++++++++++++++++-------------------- 1 files changed, 365 insertions(+), 208 deletions(-) diff --git a/UserIGOTravel/guns-admin/src/main/java/com/stylefeng/guns/modular/smallLogistics/server/impl/OrderLogisticsServiceImpl.java b/UserIGOTravel/guns-admin/src/main/java/com/stylefeng/guns/modular/smallLogistics/server/impl/OrderLogisticsServiceImpl.java index 495ce14..09cc925 100644 --- a/UserIGOTravel/guns-admin/src/main/java/com/stylefeng/guns/modular/smallLogistics/server/impl/OrderLogisticsServiceImpl.java +++ b/UserIGOTravel/guns-admin/src/main/java/com/stylefeng/guns/modular/smallLogistics/server/impl/OrderLogisticsServiceImpl.java @@ -41,12 +41,15 @@ import org.jsoup.nodes.Element; import org.jsoup.nodes.FormElement; import org.jsoup.select.Elements; +import org.slf4j.Logger; +import org.slf4j.LoggerFactory; import org.springframework.beans.factory.annotation.Autowired; import org.springframework.beans.factory.annotation.Value; import org.springframework.http.HttpEntity; import org.springframework.http.HttpHeaders; import org.springframework.http.MediaType; import org.springframework.stereotype.Service; +import org.springframework.transaction.annotation.Transactional; import org.springframework.util.LinkedMultiValueMap; import org.springframework.util.MultiValueMap; import org.springframework.util.StringUtils; @@ -63,6 +66,8 @@ @Service public class OrderLogisticsServiceImpl extends ServiceImpl<OrderLogisticsMapper, OrderLogistics> implements IOrderLogisticsService { + + private Logger log = LoggerFactory.getLogger(OrderLogisticsServiceImpl.class); @Resource private SystemPriceMapper systemPriceMapper; @@ -596,14 +601,21 @@ new Timer().schedule(new TimerTask() { @Override public void run() { - Process process = null; try { - process = Runtime.getRuntime().exec("sudo rm -rf /home/igotechgh/nginx/html/files/audio/" + fileName); - } catch (IOException e) { - throw new RuntimeException(e); - } - if (process != null) { - process.destroy(); + // 使用Runtime执行命令 + Process process = Runtime.getRuntime().exec("sudo rm -rf /home/igotechgh/nginx/html/files/audio/" + fileName); + // 读取命令的输出 + BufferedReader reader = new BufferedReader(new InputStreamReader(process.getInputStream())); + String line; + while ((line = reader.readLine()) != null) { + System.out.println(line); + } + // 等待命令执行完成 + process.waitFor(); + // 关闭流 + reader.close(); + } catch (IOException | InterruptedException e) { + e.printStackTrace(); } } }, 30000); @@ -761,34 +773,75 @@ UserInfo userInfo = userInfoService.selectById(uid); userInfo.setLanguage(language); userInfoService.updateById(userInfo); - - new Thread(() -> { - try { - String vehicleId = null; - if(null != orderLogistics.getDriverId()){ - Driver driver = driverService.selectById(orderLogistics.getDriverId()); - Car car = carMapper.selectById(driver.getCarId()); - if(!StringUtils.hasLength(car.getVehicleId())){ - car.setVehicleId(UUIDUtil.getRandomCode()); - carMapper.updateById(car); - } - //查询车辆信息,没有则创建信息 - String vehicles = fleetEngineUtil.getVehicles(car.getVehicleId()); - if(ToolUtil.isEmpty(vehicles)){ - CarModel carModel = carModelMapper.selectById(car.getCarModelId()); - fleetEngineUtil.createVehicles(carModel.getSeat() - 1, car.getCarLicensePlate(), car.getVehicleId()); - fleetEngineUtil.updateVehicles("ONLINE", carModel.getSeat() - 1, car.getCarLicensePlate(), car.getVehicleId()); - } - - } - //创建行程数据 - fleetEngineUtil.createTrip(vehicleId, 1, orderLogistics.getTripId(), - orderLogistics.getStartLat().toString(), orderLogistics.getStartLon().toString(), orderLogistics.getEndLat().toString(), orderLogistics.getEndLon().toString()); - }catch (Exception e){ - e.printStackTrace(); + //google创建车辆信息 + String vehicleId = null; + if(null != orderLogistics.getDriverId()){ + Driver driver = driverService.selectById(orderLogistics.getDriverId()); + Car car = carMapper.selectById(driver.getCarId()); + if(!StringUtils.hasLength(car.getVehicleId())){ + car.setVehicleId(UUIDUtil.getRandomCode()); + carMapper.updateById(car); } - }).start(); + //查询车辆信息,没有则创建信息 + String vehicles = fleetEngineUtil.getVehicles(car.getVehicleId()); + if(ToolUtil.isEmpty(vehicles)){ + CarModel carModel = carModelMapper.selectById(car.getCarModelId()); + boolean createVehicles = fleetEngineUtil.createVehicles(carModel.getSeat() - 1, car.getCarLicensePlate(), car.getVehicleId()); + if(!createVehicles){ + for (int i = 0; i < 5; i++) { + createVehicles = fleetEngineUtil.createVehicles(carModel.getSeat() - 1, car.getCarLicensePlate(), car.getVehicleId()); + if(createVehicles){ + break; + } + Thread.sleep(5000L); + } + } + boolean updateVehicles = fleetEngineUtil.updateVehicles("ONLINE", carModel.getSeat() - 1, car.getCarLicensePlate(), car.getVehicleId()); + if(!updateVehicles){ + for (int i = 0; i < 5; i++) { + updateVehicles = fleetEngineUtil.updateVehicles("ONLINE", carModel.getSeat() - 1, car.getCarLicensePlate(), car.getVehicleId()); + if(updateVehicles){ + break; + } + Thread.sleep(5000L); + } + } + } + } + + //创建行程数据 + String trip = fleetEngineUtil.getTrip(orderLogistics.getTripId()); + int count = this.selectCount(new EntityWrapper<OrderLogistics>().eq("tripId", orderLogistics.getTripId())); + int count1 = orderPrivateCarService.selectCount(new EntityWrapper<OrderPrivateCar>().eq("tripId", orderLogistics.getTripId())); + if(ToolUtil.isNotEmpty(trip) || (count + count1) > 0){ + String randomCode = UUIDUtil.getRandomCode(); + redisUtil.setStrValue("trip" + orderLogistics.getUserId(), randomCode); + OrderLogistics orderLogistics1 = new OrderLogistics(); + orderLogistics1.setId(orderLogistics.getId()); + orderLogistics1.setTripId(randomCode); + this.updateById(orderLogistics1); + orderLogistics.setTripId(randomCode); + } + JSONObject createTrip = fleetEngineUtil.createTrip(vehicleId, 1, orderLogistics.getTripId(), + orderLogistics.getStartLat().toString(), orderLogistics.getStartLon().toString(), orderLogistics.getEndLat().toString(), orderLogistics.getEndLon().toString()); + JSONObject error = createTrip.getJSONObject("error"); + if(null != error){ + for (int i = 0; i < 5; i++) { + createTrip = fleetEngineUtil.createTrip(vehicleId, 1, orderLogistics.getTripId(), + orderLogistics.getStartLat().toString(), orderLogistics.getStartLon().toString(), orderLogistics.getEndLat().toString(), orderLogistics.getEndLon().toString()); + error = createTrip.getJSONObject("error"); + String tripStatus = createTrip.getString("tripStatus"); + if(null == error && "NEW".equals(tripStatus)){ + break; + } + try { + Thread.sleep(3000L); + } catch (InterruptedException e) { + throw new RuntimeException(e); + } + } + } if(orderSource == 2){//扫码下单 Driver driver = driverService.selectById(orderLogistics.getDriverId()); @@ -817,14 +870,21 @@ new Timer().schedule(new TimerTask() { @Override public void run() { - Process process = null; try { - process = Runtime.getRuntime().exec("sudo rm -rf /home/igotechgh/nginx/html/files/audio/" + fileName); - } catch (IOException e) { - throw new RuntimeException(e); - } - if (process != null) { - process.destroy(); + // 使用Runtime执行命令 + Process process = Runtime.getRuntime().exec("sudo rm -rf /home/igotechgh/nginx/html/files/audio/" + fileName); + // 读取命令的输出 + BufferedReader reader = new BufferedReader(new InputStreamReader(process.getInputStream())); + String line; + while ((line = reader.readLine()) != null) { + System.out.println(line); + } + // 等待命令执行完成 + process.waitFor(); + // 关闭流 + reader.close(); + } catch (IOException | InterruptedException e) { + e.printStackTrace(); } } }, 30000); @@ -934,14 +994,21 @@ new Timer().schedule(new TimerTask() { @Override public void run() { - Process process = null; try { - process = Runtime.getRuntime().exec("sudo rm -rf /home/igotechgh/nginx/html/files/audio/" + fileName); - } catch (IOException e) { - throw new RuntimeException(e); - } - if (process != null) { - process.destroy(); + // 使用Runtime执行命令 + Process process = Runtime.getRuntime().exec("sudo rm -rf /home/igotechgh/nginx/html/files/audio/" + fileName); + // 读取命令的输出 + BufferedReader reader = new BufferedReader(new InputStreamReader(process.getInputStream())); + String line; + while ((line = reader.readLine()) != null) { + System.out.println(line); + } + // 等待命令执行完成 + process.waitFor(); + // 关闭流 + reader.close(); + } catch (IOException | InterruptedException e) { + e.printStackTrace(); } } }, 30000); @@ -986,10 +1053,14 @@ * @throws Exception */ @Override + @Transactional public ResultUtil payLogisticsOrder(Integer payType, Integer bankCardId, Integer orderId,Integer couponId, Integer redDeduction, Integer type, Integer language) throws Exception { OrderLogistics orderLogistics = this.selectById(orderId); - if(orderLogistics.getState() != 7){ + if(orderLogistics.getState() == 8 || orderLogistics.getState() == 9){ return ResultUtil.error(language == 1 ? "订单已完成支付,不允许重复支付" : language == 2 ? "The order has been paid, recurring payments is not allowed." : "La commande a été payée, les paiements récurrents ne sont pas autorisés.", ""); + } + if(orderLogistics.getState() != 7){ + return ResultUtil.error(language == 1 ? "订单不在待支付状态,不允许支付" : language == 2 ? "The order is no longer with Pending Payment, making payments is not allowed." : "La commande n’est plus en attente de paiement, il n’est pas permis d’effectuer des paiements.", ""); } Integer uid = orderLogistics.getUserId(); BigDecimal orderMoney = new BigDecimal(orderLogistics.getOrderMoney()); @@ -1019,7 +1090,6 @@ //计算优惠券 UserCouponRecord userCouponRecord = null; if(null != couponId){ - //TODO 待翻译 if(null != redDeduction && 1 == redDeduction){ return ResultUtil.error(language == 1 ? "优惠券和红包不能同时使用" : language == 2 ? "Coupons and lucky-promo cannot be used at the same time." : "Les coupons et les bonus ne peuvent pas être utilisés en même temps", ""); } @@ -1045,13 +1115,13 @@ } //计算红包 - if(null != redDeduction && 1 == redDeduction){ + if(null != redDeduction && 1 == redDeduction && null == orderLogistics.getRedPacketId()){ RedEnvelopePaymentSettings redEnvelopePaymentSettings = redEnvelopePaymentSettingsService.getRedEnvelopePaymentSettings(); if(null != redEnvelopePaymentSettings){ Double total = userRedPacketRecordService.queryRemainingAmount(uid); List<UserRedPacketRecord> userRedPacketRecords = userRedPacketRecordService.selectList(new EntityWrapper<UserRedPacketRecord>().eq("userId", uid) .eq("state", 1).eq("companyId", orderLogistics.getCompanyId()).gt("remainingAmount", 0).orderBy("insertTime", false)); - + BigDecimal deductionRatio = redEnvelopePaymentSettings.getDeductionRatio(); BigDecimal multiply1 = orderMoney.multiply(deductionRatio.divide(new BigDecimal(100))).setScale(2, RoundingMode.HALF_EVEN); if(total > 0 && multiply1.doubleValue() > 0 && total.compareTo(multiply1.doubleValue()) >= 0){ @@ -1061,27 +1131,28 @@ //获取红包id JSONArray jsonArray = new JSONArray(); for (UserRedPacketRecord userRedPacketRecord : userRedPacketRecords) { - JSONObject jsonObject = new JSONObject(); - jsonObject.put("id", userRedPacketRecord.getId()); - BigDecimal remainingAmount = new BigDecimal(userRedPacketRecord.getRemainingAmount()); if(multiply1.compareTo(BigDecimal.ZERO) == 0){ break; } + JSONObject jsonObject = new JSONObject(); + jsonObject.put("id", userRedPacketRecord.getId()); + BigDecimal remainingAmount = new BigDecimal(userRedPacketRecord.getRemainingAmount()); if(multiply1.compareTo(remainingAmount) >= 0){ userRedPacketRecord.setRemainingAmount(0D); userRedPacketRecord.setEndTime(new Date()); userRedPacketRecord.setState(2); multiply1 = multiply1.subtract(remainingAmount).setScale(2, RoundingMode.HALF_EVEN); - jsonObject.put("money", remainingAmount); + jsonObject.put("money", remainingAmount.setScale(2, RoundingMode.HALF_EVEN)); jsonArray.add(jsonObject); - userRedPacketRecordService.updateById(userRedPacketRecord); }else if(remainingAmount.compareTo(multiply1) > 0){ userRedPacketRecord.setRemainingAmount(remainingAmount.subtract(multiply1).setScale(2, RoundingMode.HALF_EVEN).doubleValue()); - jsonObject.put("money", multiply1); + jsonObject.put("money", multiply1.setScale(2, RoundingMode.HALF_EVEN)); jsonArray.add(jsonObject); - userRedPacketRecordService.updateById(userRedPacketRecord); multiply1 = BigDecimal.ZERO; } + } + if(userRedPacketRecords.size() > 0){ + userRedPacketRecordService.updateBatchById(userRedPacketRecords); } orderLogistics.setRedPacketId(jsonArray.toJSONString()); } @@ -1090,29 +1161,18 @@ orderMoney = orderMoney.subtract(new BigDecimal(total)).setScale(2, RoundingMode.HALF_EVEN); //获取红包id JSONArray jsonArray = new JSONArray(); - BigDecimal multiply = new BigDecimal(total); for (UserRedPacketRecord userRedPacketRecord : userRedPacketRecords) { JSONObject jsonObject = new JSONObject(); jsonObject.put("id", userRedPacketRecord.getId()); - BigDecimal remainingAmount = new BigDecimal(userRedPacketRecord.getRemainingAmount()); - if(multiply.compareTo(BigDecimal.ZERO) == 0){ - break; - } - if(multiply.compareTo(remainingAmount) >= 0){ - userRedPacketRecord.setRemainingAmount(0D); - userRedPacketRecord.setEndTime(new Date()); - userRedPacketRecord.setState(2); - multiply = multiply.subtract(remainingAmount).setScale(2, RoundingMode.HALF_EVEN); - jsonObject.put("money", remainingAmount); - jsonArray.add(jsonObject); - userRedPacketRecordService.updateById(userRedPacketRecord); - }else if(remainingAmount.compareTo(multiply) > 0){ - userRedPacketRecord.setRemainingAmount(remainingAmount.subtract(multiply).setScale(2, RoundingMode.HALF_EVEN).doubleValue()); - jsonObject.put("money", multiply); - jsonArray.add(jsonObject); - userRedPacketRecordService.updateById(userRedPacketRecord); - multiply = BigDecimal.ZERO; - } + jsonObject.put("money", userRedPacketRecord.getRemainingAmount()); + jsonArray.add(jsonObject); + + userRedPacketRecord.setRemainingAmount(0D); + userRedPacketRecord.setEndTime(new Date()); + userRedPacketRecord.setState(2); + } + if(userRedPacketRecords.size() > 0){ + userRedPacketRecordService.updateBatchById(userRedPacketRecords); } orderLogistics.setRedPacketId(jsonArray.toJSONString()); } @@ -1142,7 +1202,6 @@ }else{ resultUtil = ResultUtil.error(language == 1 ? "支付失败" : language == 2 ? "Payment failure" : "Paiement échoué", ""); } - return resultUtil; } if(payType == 2) {//银行卡支付 @@ -1165,12 +1224,12 @@ resultUtil = TinggPayUtil.checkoutRequest(checkoutRequest); if(resultUtil.getCode()==200){ + this.updateById(orderLogistics); paymentRecordService.saveData(1, null, null, orderId, 4, 2, orderMoney.setScale(2, RoundingMode.HALF_EVEN).doubleValue(), null, 1);//添加预支付数据 }else{ resultUtil = ResultUtil.error(language == 1 ? "支付失败" : language == 2 ? "Payment failure" : "Paiement échoué", ""); } - return resultUtil; } if(payType == 3){//余额支付 @@ -1221,29 +1280,27 @@ } } - if(orderLogistics.getIsplatPay()==1){ - //添加已收入明细 - Company company = companyService.selectById(orderLogistics.getCompanyId()); - Double speMoney = company.getSpeMoney(); - BigDecimal d = null;//企业收入 - BigDecimal c = null;//司机收入 - if(company.getIsSpeFixedOrProportional() == 2){//固定 - d = new BigDecimal(speMoney); - c = new BigDecimal(orderLogistics.getOrderMoney()).subtract(d);//只有出行金额参与抽成,其余归属司机 - } - if(company.getIsSpeFixedOrProportional() == 1){//比例 - Double price = orderLogistics.getStartMoney() + orderLogistics.getMileageMoney() + orderLogistics.getWaitMoney() + orderLogistics.getDurationMoney() + orderLogistics.getLongDistanceMoney(); - d = new BigDecimal(price).multiply(new BigDecimal(speMoney).divide(new BigDecimal(100), new MathContext(2, RoundingMode.HALF_EVEN))); - c = new BigDecimal(orderLogistics.getOrderMoney()).subtract(d).setScale(2, BigDecimal.ROUND_HALF_EVEN); - } - incomeService.saveData(1, orderLogistics.getCompanyId(), 2, orderLogistics.getId(), 4, d.doubleValue()); - incomeService.saveData(2, orderLogistics.getDriverId(), 2, orderLogistics.getId(), 4, c.doubleValue()); - Driver driver = driverService.selectById(orderLogistics.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); + //添加已收入明细 + Company company = companyService.selectById(orderLogistics.getCompanyId()); + Double speMoney = company.getSpeMoney(); + BigDecimal d = null;//企业收入 + BigDecimal c = null;//司机收入 + if(company.getIsSpeFixedOrProportional() == 2){//固定 + d = new BigDecimal(speMoney); + c = new BigDecimal(orderLogistics.getOrderMoney()).subtract(d);//只有出行金额参与抽成,其余归属司机 } + if(company.getIsSpeFixedOrProportional() == 1){//比例 + Double price = orderLogistics.getStartMoney() + orderLogistics.getMileageMoney() + orderLogistics.getWaitMoney() + orderLogistics.getDurationMoney() + orderLogistics.getLongDistanceMoney(); + d = new BigDecimal(price).multiply(new BigDecimal(speMoney).divide(new BigDecimal(100), new MathContext(2, RoundingMode.HALF_EVEN))); + c = new BigDecimal(orderLogistics.getOrderMoney()).subtract(d).setScale(2, BigDecimal.ROUND_HALF_EVEN); + } + incomeService.saveData(1, orderLogistics.getCompanyId(), 2, orderLogistics.getId(), 4, d.doubleValue()); + incomeService.saveData(2, orderLogistics.getDriverId(), 2, orderLogistics.getId(), 4, c.doubleValue()); + Driver driver = driverService.selectById(orderLogistics.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); // TODO: 2020/5/24 这里需要给司机和用户推送订单状态 new Thread(new Runnable() { @@ -1261,21 +1318,13 @@ language = userInfo.getLanguage(); - String payTypeChinese = ""; - String payTypeEnglish = ""; - String payTypeFrench = ""; - if(orderLogistics.getPayType() == 3){ - payTypeChinese = "余额支付"; - payTypeEnglish = "I-GO Wallet"; - payTypeFrench = "Portefeuille I-GO"; - } if(ToolUtil.isNotEmpty(userInfo.getEmail())){ String path = templatePath + "user/receiptLogistics.html"; Document document = Jsoup.parse(new File(path), "UTF-8"); SimpleDateFormat sdf2 = new SimpleDateFormat("yyyy-MM-dd"); SimpleDateFormat sdf1 = new SimpleDateFormat("yyyy-MM-dd HH:mm"); - Driver driver = driverService.selectById(orderLogistics.getDriverId()); + driver = driverService.selectById(orderLogistics.getDriverId()); Car car = carMapper.selectById(orderLogistics.getCarId()); Double aDouble = 0D; if(null != orderLogistics.getDriverId()){ @@ -1355,7 +1404,7 @@ Element xj_chinese = document.getElementById("xj_chinese"); xj_chinese.text("GHS " + new BigDecimal(orderLogistics.getPayMoney()).setScale(2, RoundingMode.HALF_EVEN)); Element pay_type_chinese = document.getElementById("pay_type_chinese"); - pay_type_chinese.text(payTypeChinese); + pay_type_chinese.text("余额支付"); Element pay_money_chinese = document.getElementById("pay_money_chinese"); pay_money_chinese.text("GHS " + new BigDecimal(orderLogistics.getPayMoney()).setScale(2, RoundingMode.HALF_EVEN)); Element dispute_chinese = document.getElementById("dispute_chinese"); @@ -1463,7 +1512,7 @@ Element xj_english = document.getElementById("xj_english"); xj_english.text("GHS " + new BigDecimal(orderLogistics.getPayMoney()).setScale(2, RoundingMode.HALF_EVEN)); Element pay_type_english = document.getElementById("pay_type_english"); - pay_type_english.text(payTypeEnglish); + pay_type_english.text("I-GO Wallet"); Element pay_money_english = document.getElementById("pay_money_english"); pay_money_english.text("GHS " + new BigDecimal(orderLogistics.getPayMoney()).setScale(2, RoundingMode.HALF_EVEN)); Element dispute_english = document.getElementById("dispute_english"); @@ -1571,7 +1620,7 @@ Element xj_french = document.getElementById("xj_french"); xj_french.text("GHS " + new BigDecimal(orderLogistics.getPayMoney()).setScale(2, RoundingMode.HALF_EVEN)); Element pay_type_french = document.getElementById("pay_type_french"); - pay_type_french.text(payTypeFrench); + pay_type_french.text("Portefeuille I-GO"); Element pay_money_french = document.getElementById("pay_money_french"); pay_money_french.text("GHS " + new BigDecimal(orderLogistics.getPayMoney()).setScale(2, RoundingMode.HALF_EVEN)); Element dispute_french = document.getElementById("dispute_french"); @@ -1707,21 +1756,20 @@ } - if(orderLogistics.getIsplatPay()==1){ - //添加已收入明细 - Company company = companyService.selectById(orderLogistics.getCompanyId()); - Double speMoney = company.getSpeMoney(); - BigDecimal d = null;//企业收入 - BigDecimal c = null;//司机收入 - if(company.getIsSpeFixedOrProportional() == 2){//固定 - d = new BigDecimal(speMoney); - c = new BigDecimal(orderLogistics.getOrderMoney()).subtract(d);//只有出行金额参与抽成,其余归属司机 - } - if(company.getIsSpeFixedOrProportional() == 1){//比例 - Double price = orderLogistics.getStartMoney() + orderLogistics.getMileageMoney() + orderLogistics.getWaitMoney() + orderLogistics.getDurationMoney() + orderLogistics.getLongDistanceMoney(); - d = new BigDecimal(price).multiply(new BigDecimal(speMoney).divide(new BigDecimal(100), new MathContext(2, RoundingMode.HALF_EVEN))); - c = new BigDecimal(orderLogistics.getOrderMoney()).subtract(d).setScale(2, BigDecimal.ROUND_HALF_EVEN); - } + //添加已收入明细 + Company company = companyService.selectById(orderLogistics.getCompanyId()); + Double speMoney = company.getSpeMoney(); + BigDecimal d = null;//企业收入 + BigDecimal c = null;//司机收入 + if(company.getIsSpeFixedOrProportional() == 2){//固定 + d = new BigDecimal(speMoney); + c = new BigDecimal(orderLogistics.getOrderMoney()).subtract(d);//只有出行金额参与抽成,其余归属司机 + } + if(company.getIsSpeFixedOrProportional() == 1){//比例 + Double price = orderLogistics.getStartMoney() + orderLogistics.getMileageMoney() + orderLogistics.getWaitMoney() + orderLogistics.getDurationMoney() + orderLogistics.getLongDistanceMoney(); + d = new BigDecimal(price).multiply(new BigDecimal(speMoney).divide(new BigDecimal(100), new MathContext(2, RoundingMode.HALF_EVEN))); + c = new BigDecimal(orderLogistics.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()); @@ -1729,51 +1777,109 @@ // 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); + + + //记录司机待结算金额 + if(d.compareTo(new BigDecimal(0)) > 0){ + SettlementDetail settlementDetail = new SettlementDetail(); + settlementDetail.setOrderId(orderId); + settlementDetail.setOrderType(4); + settlementDetail.setDriverId(driver.getId()); + settlementDetail.setOrderMoney(orderLogistics.getOrderMoney()); + settlementDetail.setPrice(d.doubleValue()); + settlementDetail.setCreateTime(new Date()); + settlementDetailService.insert(settlementDetail); - - //记录司机待结算金额 - if(d.compareTo(new BigDecimal(0)) > 0){ - SettlementDetail settlementDetail = new SettlementDetail(); - settlementDetail.setOrderId(orderId); - settlementDetail.setOrderType(1); - settlementDetail.setDriverId(driver.getId()); - settlementDetail.setOrderMoney(orderLogistics.getOrderMoney()); - settlementDetail.setPrice(d.doubleValue()); - settlementDetail.setCreateTime(new Date()); - settlementDetailService.insert(settlementDetail); - - SettlementAllocation settlementAllocation = settlementAllocationService.selectOne(null); - if(null != settlementAllocation){ - JSONObject jsonObject = JSON.parseObject(settlementAllocation.getContent()); - Double maxPrice = jsonObject.getDouble("maxPrice"); - if(null != maxPrice){ - List<SettlementDetail> settlementDetailList = settlementDetailService.selectList(new EntityWrapper<SettlementDetail>().eq("driverId", driver.getId()) - .isNull("settlementRecordId").last(" and DATE_FORMAT(now(), '%Y-%m-%d') = DATE_FORMAT(createTime, '%Y-%m-%d')")); - BigDecimal total = new BigDecimal(0); - for (SettlementDetail detail : settlementDetailList) { - total = total.add(new BigDecimal(detail.getPrice())); + SettlementAllocation settlementAllocation = settlementAllocationService.selectOne(null); + if(null != settlementAllocation){ + JSONObject jsonObject = JSON.parseObject(settlementAllocation.getContent()); + Double maxPrice = jsonObject.getDouble("maxPrice"); + Integer type1 = jsonObject.getInteger("type"); + if(null != maxPrice){ + List<SettlementDetail> settlementDetailList = settlementDetailService.selectList(new EntityWrapper<SettlementDetail>().eq("driverId", driver.getId()) + .isNull("settlementRecordId").last(" and DATE_FORMAT(now(), '%Y-%m-%d') = DATE_FORMAT(createTime, '%Y-%m-%d')")); + BigDecimal total = new BigDecimal(0); + for (SettlementDetail detail : settlementDetailList) { + total = total.add(new BigDecimal(detail.getPrice())); + } + //日结算 + if(maxPrice.compareTo(total.doubleValue()) <= 0){ + SettlementRecord settlementRecord = settlementRecordService.selectOne(new EntityWrapper<SettlementRecord>().eq("driverId", orderLogistics.getDriverId()) + .eq("type", type1).eq("paymentStatus", 1).last(" and day = DATE_FORMAT(now(), '%Y-%m-%d')")); + if(null == settlementRecord){ + settlementRecord = new SettlementRecord(); + settlementRecord.setDay(new Date()); + settlementRecord.setDriverId(orderLogistics.getDriverId()); + settlementRecord.setType(type1); + settlementRecord.setPaymentStatus(1); + settlementRecord.setPayMoney(total.doubleValue()); + settlementRecord.setInsertTime(new Date()); + settlementRecordService.insert(settlementRecord); + }else{ + settlementRecord.setPayMoney(settlementRecord.getPayMoney() + total.doubleValue()); + settlementRecordService.updateById(settlementRecord); } - //日结算 - if(maxPrice.compareTo(total.doubleValue()) <= 0){ - SettlementRecord settlementRecord = settlementRecordService.selectOne(new EntityWrapper<SettlementRecord>().eq("driverId", orderLogistics.getDriverId()) - .eq("type", 1).eq("paymentStatus", 1).last(" and day = DATE_FORMAT(now(), '%Y-%m-%d')")); - if(null == settlementRecord){ - settlementRecord = new SettlementRecord(); - settlementRecord.setDay(new Date()); - settlementRecord.setDriverId(orderLogistics.getDriverId()); - settlementRecord.setType(1); - settlementRecord.setPaymentStatus(1); - settlementRecord.setPayMoney(total.doubleValue()); - settlementRecord.setInsertTime(new Date()); - settlementRecordService.insert(settlementRecord); - }else{ - settlementRecord.setPayMoney(settlementRecord.getPayMoney() + total.doubleValue()); - settlementRecordService.updateById(settlementRecord); + for (SettlementDetail detail : settlementDetailList) { + detail.setSettlementRecordId(settlementRecord.getId()); + settlementDetailService.updateById(detail); + } + //强制司机下班 + DriverWork driverWork = driverWorkService.selectOne(new EntityWrapper<DriverWork>() + .eq("driverId", orderLogistics.getDriverId()).eq("state", 1)); + if(null != driverWork){ + driverWork.setEndTime(new Date()); + driverWork.setState(2); + driverWorkService.updateById(driverWork); + driver.setState(1); + driverService.updateById(driver); + Car car = carService.selectById(driver.getCarId()); + if(!org.apache.shiro.util.StringUtils.hasLength(car.getVehicleId())){ + car.setVehicleId(UUIDUtil.getRandomCode()); + carService.updateById(car); } - for (SettlementDetail detail : settlementDetailList) { - detail.setSettlementRecordId(settlementRecord.getId()); - settlementDetailService.updateById(detail); - } + + //司机下班,修改谷歌上的车辆信息 + new Thread(()->{ + try { + CarModel carModel = carModelMapper.selectById(car.getCarModelId()); + String vehicles = fleetEngineUtil.getVehicles(car.getVehicleId()); + if(ToolUtil.isEmpty(vehicles)){ + boolean createVehicles = fleetEngineUtil.createVehicles(carModel.getSeat() - 1, car.getCarLicensePlate(), car.getVehicleId()); + if(!createVehicles){ + for (int i = 0; i < 5; i++) { + createVehicles = fleetEngineUtil.createVehicles(carModel.getSeat() - 1, car.getCarLicensePlate(), car.getVehicleId()); + if(createVehicles){ + break; + } + Thread.sleep(5000L); + } + } + boolean updateVehicles = fleetEngineUtil.updateVehicles("OFFLINE", carModel.getSeat() - 1, car.getCarLicensePlate(), car.getVehicleId()); + if(!updateVehicles){ + for (int i = 0; i < 5; i++) { + updateVehicles = fleetEngineUtil.updateVehicles("OFFLINE", carModel.getSeat() - 1, car.getCarLicensePlate(), car.getVehicleId()); + if(updateVehicles){ + break; + } + Thread.sleep(5000L); + } + } + }else{ + boolean updateVehicles = fleetEngineUtil.updateVehicles("OFFLINE", carModel.getSeat() - 1, car.getCarLicensePlate(), car.getVehicleId()); + if(!updateVehicles){ + for (int i = 0; i < 5; i++) { + updateVehicles = fleetEngineUtil.updateVehicles("OFFLINE", carModel.getSeat() - 1, car.getCarLicensePlate(), car.getVehicleId()); + if(updateVehicles){ + break; + } + Thread.sleep(5000L); + } + } + } + }catch (Exception e){ + e.printStackTrace(); + } + }).start(); } } } @@ -1789,7 +1895,50 @@ public void run() { pushUtil.pushOrderState(1, orderLogistics.getUserId(), orderLogistics.getId(), orderLogistics.getType(), orderLogistics.getState(), 0, ""); pushUtil.pushOrderState(2, orderLogistics.getDriverId(), orderLogistics.getId(), orderLogistics.getType(), orderLogistics.getState(), 0, ""); - pushUtil.pushOfflinePayment(2, orderLogistics.getDriverId(), orderLogistics.getId(), 4, orderLogistics.getPayMoney()); + Integer language1 = driver.getLanguage(); + String text = ""; + switch (language1){ + case 1: + text = "客户已选择支付现金,因此您必须收款。确定您已收到此订单费用:现金GHS " + orderLogistics.getPayMoney(); + break; + case 2: + text = "The client chose to pay in cash, so you must collect the payment.Confirm if you received the charge for this order: Cash GHS " + orderLogistics.getPayMoney(); + break; + case 3: + text = "Le client a choisi de payer en espèces, vous devez donc encaisser le paiement.Confirmez si vous avez reçu les frais pour cette commande : Espèces GHS " + orderLogistics.getPayMoney(); + break; + + } + String audioUrl = ""; + String fileName = "offlinePayment" + orderLogistics.getDriverId() + UUIDUtil.getRandomCode(5) + ".mp3"; + try { + audioUrl = TextToSpeechUtil.create(language1 == 1 ? "cmn-CN" : language1 == 2 ? "en-US" : "fr-FR", text, fileName); + } catch (Exception e) { + throw new RuntimeException(e); + } + //定时任务删除语音文件 + new Timer().schedule(new TimerTask() { + @Override + public void run() { + try { + // 使用Runtime执行命令 + Process process = Runtime.getRuntime().exec("sudo rm -rf /home/igotechgh/nginx/html/files/audio/" + fileName); + // 读取命令的输出 + BufferedReader reader = new BufferedReader(new InputStreamReader(process.getInputStream())); + String line; + while ((line = reader.readLine()) != null) { + System.out.println(line); + } + // 等待命令执行完成 + process.waitFor(); + // 关闭流 + reader.close(); + } catch (IOException | InterruptedException e) { + e.printStackTrace(); + } + } + }, 30000); + pushUtil.pushOfflinePayment(2, orderLogistics.getDriverId(), orderLogistics.getId(), 4, orderLogistics.getPayMoney(), audioUrl); } }).start(); @@ -1798,15 +1947,6 @@ "Vous avez payé la commande de livraison avec succès, merci d’utiliser I-GO", uid, 1); language = userInfo.getLanguage(); - String payTypeChinese = ""; - String payTypeEnglish = ""; - String payTypeFrench = ""; - if(orderLogistics.getPayType() == 3){ - payTypeChinese = "现金"; - payTypeEnglish = "Cash"; - payTypeFrench = "En espèces"; - } - if(ToolUtil.isNotEmpty(userInfo.getEmail())){ String path = templatePath + "user/receiptLogistics.html"; Document document = Jsoup.parse(new File(path), "UTF-8"); @@ -1891,7 +2031,7 @@ Element xj_chinese = document.getElementById("xj_chinese"); xj_chinese.text("GHS " + new BigDecimal(orderLogistics.getPayMoney()).setScale(2, RoundingMode.HALF_EVEN)); Element pay_type_chinese = document.getElementById("pay_type_chinese"); - pay_type_chinese.text(payTypeChinese); + pay_type_chinese.text("现金"); Element pay_money_chinese = document.getElementById("pay_money_chinese"); pay_money_chinese.text("GHS " + new BigDecimal(orderLogistics.getPayMoney()).setScale(2, RoundingMode.HALF_EVEN)); Element dispute_chinese = document.getElementById("dispute_chinese"); @@ -1999,7 +2139,7 @@ Element xj_english = document.getElementById("xj_english"); xj_english.text("GHS " + new BigDecimal(orderLogistics.getPayMoney()).setScale(2, RoundingMode.HALF_EVEN)); Element pay_type_english = document.getElementById("pay_type_english"); - pay_type_english.text(payTypeEnglish); + pay_type_english.text("Cash"); Element pay_money_english = document.getElementById("pay_money_english"); pay_money_english.text("GHS " + new BigDecimal(orderLogistics.getPayMoney()).setScale(2, RoundingMode.HALF_EVEN)); Element dispute_english = document.getElementById("dispute_english"); @@ -2107,7 +2247,7 @@ Element xj_french = document.getElementById("xj_french"); xj_french.text("GHS " + new BigDecimal(orderLogistics.getPayMoney()).setScale(2, RoundingMode.HALF_EVEN)); Element pay_type_french = document.getElementById("pay_type_french"); - pay_type_french.text(payTypeFrench); + pay_type_french.text("En espèces"); Element pay_money_french = document.getElementById("pay_money_french"); pay_money_french.text("GHS " + new BigDecimal(orderLogistics.getPayMoney()).setScale(2, RoundingMode.HALF_EVEN)); Element dispute_french = document.getElementById("dispute_french"); @@ -2195,7 +2335,7 @@ } } - this.updateById(orderLogistics); + this.updateAllColumnById(orderLogistics); return resultUtil; } @@ -2411,6 +2551,28 @@ query.setState(2); query.setCode(order_id); paymentRecordService.updateById(query); + + //添加已收入明细 + Company company = companyService.selectById(orderLogistics.getCompanyId()); + Double speMoney = company.getSpeMoney(); + BigDecimal d = null;//企业收入 + BigDecimal c = null;//司机收入 + if(company.getIsSpeFixedOrProportional() == 2){//固定 + d = new BigDecimal(speMoney); + c = new BigDecimal(orderLogistics.getOrderMoney()).subtract(d);//只有出行金额参与抽成,其余归属司机 + } + if(company.getIsSpeFixedOrProportional() == 1){//比例 + Double price = orderLogistics.getStartMoney() + orderLogistics.getMileageMoney() + orderLogistics.getWaitMoney() + orderLogistics.getDurationMoney() + orderLogistics.getLongDistanceMoney(); + d = new BigDecimal(price).multiply(new BigDecimal(speMoney).divide(new BigDecimal(100), new MathContext(2, RoundingMode.HALF_EVEN))); + c = new BigDecimal(orderLogistics.getOrderMoney()).subtract(d).setScale(2, BigDecimal.ROUND_HALF_EVEN); + } + incomeService.saveData(1, orderLogistics.getCompanyId(), 2, orderLogistics.getId(), 4, d.doubleValue()); + incomeService.saveData(2, orderLogistics.getDriverId(), 2, orderLogistics.getId(), 4, c.doubleValue()); + Driver driver = driverService.selectById(orderLogistics.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); // TODO: 2020/5/24 这里需要给司机和用户推送订单状态 new Thread(new Runnable() { @@ -2427,26 +2589,12 @@ "Vous avez payé la commande de livraison avec succès, merci d’utiliser I-GO", orderLogistics.getUserId(), 1); language = userInfo.getLanguage(); - String payTypeChinese = ""; - String payTypeEnglish = ""; - String payTypeFrench = ""; - if(orderLogistics.getPayType() == 1){ - payTypeChinese = "手机支付"; - payTypeEnglish = "Mobile money"; - payTypeFrench = "Argent mobile"; - } - if(orderLogistics.getPayType() == 2){ - payTypeChinese = "银行卡支付"; - payTypeEnglish = "Bank card"; - payTypeFrench = "Carte bancaire"; - } - if(ToolUtil.isNotEmpty(userInfo.getEmail())){ String path = templatePath + "user/receiptLogistics.html"; Document document = Jsoup.parse(new File(path), "UTF-8"); SimpleDateFormat sdf2 = new SimpleDateFormat("yyyy-MM-dd"); SimpleDateFormat sdf1 = new SimpleDateFormat("yyyy-MM-dd HH:mm"); - Driver driver = driverService.selectById(orderLogistics.getDriverId()); + driver = driverService.selectById(orderLogistics.getDriverId()); Car car = carMapper.selectById(orderLogistics.getCarId()); Double aDouble = 0D; if(null != orderLogistics.getDriverId()){ @@ -2526,7 +2674,7 @@ Element xj_chinese = document.getElementById("xj_chinese"); xj_chinese.text("GHS " + new BigDecimal(orderLogistics.getPayMoney()).setScale(2, RoundingMode.HALF_EVEN)); Element pay_type_chinese = document.getElementById("pay_type_chinese"); - pay_type_chinese.text(payTypeChinese); + pay_type_chinese.text(orderLogistics.getPayType() == 1 ? "手机支付" : (orderLogistics.getPayType() == 2?"银行卡支付":(orderLogistics.getPayType() == 3?"余额支付":"现金支付"))); Element pay_money_chinese = document.getElementById("pay_money_chinese"); pay_money_chinese.text("GHS " + new BigDecimal(orderLogistics.getPayMoney()).setScale(2, RoundingMode.HALF_EVEN)); Element dispute_chinese = document.getElementById("dispute_chinese"); @@ -2634,7 +2782,7 @@ Element xj_english = document.getElementById("xj_english"); xj_english.text("GHS " + new BigDecimal(orderLogistics.getPayMoney()).setScale(2, RoundingMode.HALF_EVEN)); Element pay_type_english = document.getElementById("pay_type_english"); - pay_type_english.text(payTypeEnglish); + pay_type_english.text(orderLogistics.getPayType() == 1 ? "Mobile money" :(orderLogistics.getPayType() == 2?"Bank card":(orderLogistics.getPayType() == 3?"I-GO Wallet":"Cash"))); Element pay_money_english = document.getElementById("pay_money_english"); pay_money_english.text("GHS " + new BigDecimal(orderLogistics.getPayMoney()).setScale(2, RoundingMode.HALF_EVEN)); Element dispute_english = document.getElementById("dispute_english"); @@ -2742,7 +2890,7 @@ Element xj_french = document.getElementById("xj_french"); xj_french.text("GHS " + new BigDecimal(orderLogistics.getPayMoney()).setScale(2, RoundingMode.HALF_EVEN)); Element pay_type_french = document.getElementById("pay_type_french"); - pay_type_french.text(payTypeFrench); + pay_type_french.text(orderLogistics.getPayType() == 1 ? "Argent mobile" : (orderLogistics.getPayType() == 2?"Carte bancaire":(orderLogistics.getPayType() == 3?"Portefeuille I-GO":"En espèces"))); Element pay_money_french = document.getElementById("pay_money_french"); pay_money_french.text("GHS " + new BigDecimal(orderLogistics.getPayMoney()).setScale(2, RoundingMode.HALF_EVEN)); Element dispute_french = document.getElementById("dispute_french"); @@ -3110,11 +3258,20 @@ driverService.updateById(driver); } - if((orderLogistics.getState() == 10 || orderLogistics.getState() == 12) && null != orderLogistics.getDriverId()){ + if(orderLogistics.getState() == 10 || orderLogistics.getState() == 12){ + Car car = carService.selectById(orderLogistics.getCarId()); //修改行程信息 - fleetEngineUtil.updateTrip("CANCELED", null, null, orderLogistics.getTripId(), null, null, null, null); + boolean updateTrip = fleetEngineUtil.updateTrip("CANCELED", car.getVehicleId(), null, orderLogistics.getTripId(), null, null, null, null); + if(!updateTrip){ + for (int i = 0; i < 5; i++) { + updateTrip = fleetEngineUtil.updateTrip("CANCELED", car.getVehicleId(), null, orderLogistics.getTripId(), null, null, null, null); + if(updateTrip){ + break; + } + Thread.sleep(3000L); + } + } } - //添加消息 systemNoticeService.addSystemNotice(1, language == 1 ? "您已成功取消包裹订单,谢谢使用!" : language == 2 ? "You've cancelled the delivery order successfully, thank you for using I-GO " : "Vous avez annulé la commande de livraison avec succès, merci d’utiliser I-GO", orderLogistics.getUserId(), 1); @@ -3265,7 +3422,7 @@ public synchronized String getOrderNum() throws Exception{ int size = this.selectCount(null); - return "LOGISTICS" + String.valueOf(1000000 + size + 1).substring(1); + return "DELIVERY" + String.valueOf(1000000 + size + 1).substring(1); } @@ -3307,7 +3464,7 @@ BaseWarpper baseWarpper = new BaseWarpper(); double amount = 0; CancleOrder query = cancleOrderService.query(orderLogistics.getCompanyId()); - if(null == query || null == orderLogistics.getDriverId()){ + if(null == query || null == orderLogistics.getDriverId() || orderLogistics.getState() == 11){ baseWarpper.setAmount(amount); return ResultUtil.success(baseWarpper); } -- Gitblit v1.7.1