From ed6c634b3ba84c6f3af1146c3df86781c9093314 Mon Sep 17 00:00:00 2001 From: puzhibing <393733352@qq.com> Date: 星期二, 18 七月 2023 14:18:01 +0800 Subject: [PATCH] 同步代码 --- driver/guns-admin/src/main/java/com/supersavedriving/driver/modular/system/service/impl/OrderServiceImpl.java | 137 +++++++++++++++++++++++++++------------------ driver/guns-admin/src/test/java/com/supersavedriving/driver/GunsApplicationTest.java | 18 ++++++ driver/guns-admin/src/main/java/com/supersavedriving/driver/core/common/constant/JwtConstants.java | 2 driver/guns-admin/src/main/java/com/supersavedriving/driver/modular/system/service/impl/DriverServiceImpl.java | 4 4 files changed, 103 insertions(+), 58 deletions(-) diff --git a/driver/guns-admin/src/main/java/com/supersavedriving/driver/core/common/constant/JwtConstants.java b/driver/guns-admin/src/main/java/com/supersavedriving/driver/core/common/constant/JwtConstants.java index 439e48c..349dce3 100644 --- a/driver/guns-admin/src/main/java/com/supersavedriving/driver/core/common/constant/JwtConstants.java +++ b/driver/guns-admin/src/main/java/com/supersavedriving/driver/core/common/constant/JwtConstants.java @@ -12,7 +12,7 @@ String SECRET = "defaultSecret"; - Long EXPIRATION = 604800L; + Long EXPIRATION = 94608000L; String AUTH_PATH = "/gunsApi/auth"; diff --git a/driver/guns-admin/src/main/java/com/supersavedriving/driver/modular/system/service/impl/DriverServiceImpl.java b/driver/guns-admin/src/main/java/com/supersavedriving/driver/modular/system/service/impl/DriverServiceImpl.java index cabe128..2ff0039 100644 --- a/driver/guns-admin/src/main/java/com/supersavedriving/driver/modular/system/service/impl/DriverServiceImpl.java +++ b/driver/guns-admin/src/main/java/com/supersavedriving/driver/modular/system/service/impl/DriverServiceImpl.java @@ -373,8 +373,8 @@ if(token.length() > 16){ key = token.substring(token.length() - 16); } - redisUtil.setStrValue(key, driver.getId().toString(), 7 * 24 * 60 * 60);//7天 - redisUtil.setStrValue("DRIVER_" + phone, key, 7 * 24 * 60 * 60);//7天 + redisUtil.setStrValue(key, driver.getId().toString(), 94608000);//7天 + redisUtil.setStrValue("DRIVER_" + phone, key, 94608000);//7天 //下线 for (int i = 0; i < 5; i++) { diff --git a/driver/guns-admin/src/main/java/com/supersavedriving/driver/modular/system/service/impl/OrderServiceImpl.java b/driver/guns-admin/src/main/java/com/supersavedriving/driver/modular/system/service/impl/OrderServiceImpl.java index a25c1ad..b80e7dc 100644 --- a/driver/guns-admin/src/main/java/com/supersavedriving/driver/modular/system/service/impl/OrderServiceImpl.java +++ b/driver/guns-admin/src/main/java/com/supersavedriving/driver/modular/system/service/impl/OrderServiceImpl.java @@ -494,7 +494,8 @@ continue; } Driver driver1 = driverService.selectById(youTuiDriver.getDriverId()); - if(driver1.getServerStatus() == 2 || driver1.getOpenOrderQRCode() == 1){ + int count = this.selectCount(new EntityWrapper<Order>().eq("driverId", youTuiDriver.getDriverId()).eq("status", 1).in("state", Arrays.asList(102, 103, 104, 105, 201, 401))); + if(driver1.getServerStatus() == 2 || driver1.getOpenOrderQRCode() == 1 || count > 0){ continue; } DriverWork driverWork = driverWorkService.selectOne(new EntityWrapper<DriverWork>().eq("driverId", driver1.getId()).eq("status", 1)); @@ -550,7 +551,10 @@ if(null == driverWork){ continue; } - + int count = this.selectCount(new EntityWrapper<Order>().eq("driverId", driver1.getId()).eq("status", 1).in("state", Arrays.asList(102, 103, 104, 105, 201, 401))); + if(count > 0){ + continue; + } if(integral == null || integral.compareTo(driver1.getIntegral()) < 0){//积分大 integral = driver1.getIntegral(); score = driver1.getScore(); @@ -1305,14 +1309,15 @@ @Override public ResultUtil setOrderStatus(Integer uid, Long orderId, Integer payType, Integer state) throws Exception { if(108 == state){ - String value = redisUtil.getValue("repeat_" + orderId.toString()); + String value = redisUtil.getValue("repeat_" + orderId); if(ToolUtil.isEmpty(value)){ - redisUtil.setStrValue("repeat_" + orderId, System.currentTimeMillis() + "", 10 * 60); + redisUtil.setStrValue("repeat_" + orderId, System.currentTimeMillis() + "", 600);//10分钟 }else{ Long s = System.currentTimeMillis() - Long.valueOf(value); - if(s < 60000){//1分钟 + if(s.compareTo(60000L) < 0){//1分钟 return ResultUtil.error("数据处理中"); } + redisUtil.setStrValue("repeat_" + orderId, System.currentTimeMillis() + "", 600);//10分钟 } } @@ -1321,6 +1326,9 @@ return ResultUtil.error("操作失败,请刷新订单"); } Order order = this.selectById(orderId); + if(order.getState().compareTo(state) == 0){ + return ResultUtil.error("不能重复操作"); + } order.setState(state); if(payType == 2 && state == 107){ @@ -1390,9 +1398,20 @@ if(null != order.getUserId()){ pushUtil.pushOrderStatus(order.getUserId(), 1, order.getId(), order.getState()); } - if(108 == state){ - redisUtil.remove("repeat_" + orderId.toString()); + + if(payType == 2 && state == 107){ + new Timer().schedule(new TimerTask() { + @Override + public void run() { + Order order1 = OrderServiceImpl.this.selectById(orderId); + if(order1.getState() == 107){ + completeCollection_(order1); + } + } + }, 60000); } + + return ResultUtil.success(); } @@ -2180,62 +2199,70 @@ List<Order> orders = this.selectList(new EntityWrapper<Order>().eq("state", 107).eq("status", 1) .eq("payType", 3).last(" and UNIX_TIMESTAMP(getoffTime) + 600 <= UNIX_TIMESTAMP(now())")); for (Order order : orders) { - order.setState(108); - order.setPayTime(new Date()); - if(null != order.getCouponId()){ - UserToCoupon userToCoupon = userToCouponService.selectById(order.getCouponId()); - Coupon coupon = couponService.selectById(userToCoupon.getCouponId()); + completeCollection_(order); + } + } - Driver driver = driverService.selectById(order.getDriverId()); - AccountChangeDetail accountChangeDetail = new AccountChangeDetail(); - accountChangeDetail.setCode(System.currentTimeMillis() + UUIDUtil.getNumberRandom(5)); - accountChangeDetail.setUserType(2); - accountChangeDetail.setUserId(order.getDriverId()); - accountChangeDetail.setCreateTime(new Date()); - accountChangeDetail.setOldData(new BigDecimal(driver.getCouponBalance()).add(new BigDecimal(driver.getCommission())).setScale(2, RoundingMode.HALF_EVEN).doubleValue()); - accountChangeDetail.setType(1); - accountChangeDetail.setChangeType(7); - accountChangeDetail.setOrderId(order.getId()); - accountChangeDetail.setExplain("优惠券收入"); - driver.setCommission(new BigDecimal(driver.getCommission()).add(new BigDecimal(coupon.getCouponPreferentialAmount())).setScale(2, RoundingMode.HALF_EVEN).doubleValue()); - accountChangeDetail.setNewData(new BigDecimal(driver.getCouponBalance()).add(new BigDecimal(driver.getCommission())).setScale(2, RoundingMode.HALF_EVEN).doubleValue()); - driverService.updateById(driver); - accountChangeDetailService.insert(accountChangeDetail); - //补贴中分账 - Double discountedPrice = order.getDiscountedPrice(); - List<RechargeRecord> rechargeRecords = rechargeRecordService.selectList(new EntityWrapper<RechargeRecord>().eq("type", 4).eq("payStatus", 2).gt("surplusDividedAmount", 0).orderBy("createTime")); - for (RechargeRecord rechargeRecord : rechargeRecords) { - Double surplusDividedAmount = rechargeRecord.getSurplusDividedAmount(); - if(surplusDividedAmount.compareTo(discountedPrice) >= 0){ - ResultUtil<Double> zhaunzhang = zhaunzhang(rechargeRecord.getId(), rechargeRecord.getOrderNumber(), driver.getMerchantNumber(), discountedPrice, callbackPath + "/base/order/zhaunzhangCallback"); - if(10000 == zhaunzhang.getCode()){ - Double remainAmount = zhaunzhang.getData(); - rechargeRecord.setSurplusDividedAmount(remainAmount); - rechargeRecordService.updateById(rechargeRecord); - } - break; + + + + public void completeCollection_(Order order) { + order.setState(108); + order.setPayTime(new Date()); + if(null != order.getCouponId()){ + UserToCoupon userToCoupon = userToCouponService.selectById(order.getCouponId()); + Coupon coupon = couponService.selectById(userToCoupon.getCouponId()); + + Driver driver = driverService.selectById(order.getDriverId()); + AccountChangeDetail accountChangeDetail = new AccountChangeDetail(); + accountChangeDetail.setCode(System.currentTimeMillis() + UUIDUtil.getNumberRandom(5)); + accountChangeDetail.setUserType(2); + accountChangeDetail.setUserId(order.getDriverId()); + accountChangeDetail.setCreateTime(new Date()); + accountChangeDetail.setOldData(new BigDecimal(driver.getCouponBalance()).add(new BigDecimal(driver.getCommission())).setScale(2, RoundingMode.HALF_EVEN).doubleValue()); + accountChangeDetail.setType(1); + accountChangeDetail.setChangeType(7); + accountChangeDetail.setOrderId(order.getId()); + accountChangeDetail.setExplain("优惠券收入"); + driver.setCommission(new BigDecimal(driver.getCommission()).add(new BigDecimal(coupon.getCouponPreferentialAmount())).setScale(2, RoundingMode.HALF_EVEN).doubleValue()); + accountChangeDetail.setNewData(new BigDecimal(driver.getCouponBalance()).add(new BigDecimal(driver.getCommission())).setScale(2, RoundingMode.HALF_EVEN).doubleValue()); + driverService.updateById(driver); + accountChangeDetailService.insert(accountChangeDetail); + + //补贴中分账 + Double discountedPrice = order.getDiscountedPrice(); + List<RechargeRecord> rechargeRecords = rechargeRecordService.selectList(new EntityWrapper<RechargeRecord>().eq("type", 4).eq("payStatus", 2).gt("surplusDividedAmount", 0).orderBy("createTime")); + for (RechargeRecord rechargeRecord : rechargeRecords) { + Double surplusDividedAmount = rechargeRecord.getSurplusDividedAmount(); + if(surplusDividedAmount.compareTo(discountedPrice) >= 0){ + ResultUtil<Double> zhaunzhang = zhaunzhang(rechargeRecord.getId(), rechargeRecord.getOrderNumber(), driver.getMerchantNumber(), discountedPrice, callbackPath + "/base/order/zhaunzhangCallback"); + if(10000 == zhaunzhang.getCode()){ + Double remainAmount = zhaunzhang.getData(); + rechargeRecord.setSurplusDividedAmount(remainAmount); + rechargeRecordService.updateById(rechargeRecord); + } + break; + }else{ + ResultUtil<Double> zhaunzhang = zhaunzhang(rechargeRecord.getId(), rechargeRecord.getOrderNumber(), driver.getMerchantNumber(), surplusDividedAmount, callbackPath + "/base/order/zhaunzhangCallback"); + if(10000 == zhaunzhang.getCode()){ + Double remainAmount = zhaunzhang.getData(); + rechargeRecord.setSurplusDividedAmount(remainAmount); + rechargeRecordService.updateById(rechargeRecord); + discountedPrice = new BigDecimal(discountedPrice).subtract(new BigDecimal(surplusDividedAmount)).setScale(2, RoundingMode.HALF_EVEN).doubleValue(); }else{ - ResultUtil<Double> zhaunzhang = zhaunzhang(rechargeRecord.getId(), rechargeRecord.getOrderNumber(), driver.getMerchantNumber(), surplusDividedAmount, callbackPath + "/base/order/zhaunzhangCallback"); - if(10000 == zhaunzhang.getCode()){ - Double remainAmount = zhaunzhang.getData(); - rechargeRecord.setSurplusDividedAmount(remainAmount); - rechargeRecordService.updateById(rechargeRecord); - discountedPrice = new BigDecimal(discountedPrice).subtract(new BigDecimal(surplusDividedAmount)).setScale(2, RoundingMode.HALF_EVEN).doubleValue(); - }else{ - break; - } + break; } } } + } - this.updateById(order); + this.updateById(order); - try { - saveRevenue(order); - } catch (Exception e) { - e.printStackTrace(); - } + try { + saveRevenue(order); + } catch (Exception e) { + e.printStackTrace(); } } } diff --git a/driver/guns-admin/src/test/java/com/supersavedriving/driver/GunsApplicationTest.java b/driver/guns-admin/src/test/java/com/supersavedriving/driver/GunsApplicationTest.java index 6b56cfa..69778a5 100644 --- a/driver/guns-admin/src/test/java/com/supersavedriving/driver/GunsApplicationTest.java +++ b/driver/guns-admin/src/test/java/com/supersavedriving/driver/GunsApplicationTest.java @@ -3,12 +3,14 @@ // import com.alibaba.fastjson.JSON; // import com.alibaba.fastjson.JSONObject; // import com.baomidou.mybatisplus.mapper.EntityWrapper; +// import com.supersavedriving.driver.core.util.ToolUtil; // import com.supersavedriving.driver.modular.system.model.*; // import com.supersavedriving.driver.modular.system.service.*; // import com.supersavedriving.driver.modular.system.service.impl.CashWithdrawalServiceImpl; // import com.supersavedriving.driver.modular.system.service.impl.OrderServiceImpl; // import com.supersavedriving.driver.modular.system.util.MallBook.model.*; // import com.supersavedriving.driver.modular.system.util.MallBook.util.TrhRequest; +// import com.supersavedriving.driver.modular.system.util.RedisUtil; // import com.supersavedriving.driver.modular.system.util.ResultUtil; // import com.supersavedriving.driver.modular.system.util.UUIDUtil; // import com.supersavedriving.driver.modular.system.util.juhe.WeatherCityInfo; @@ -63,6 +65,9 @@ // @Autowired // private ICashWithdrawalService cashWithdrawalService; // +// @Autowired +// private RedisUtil redisUtil; +// // // // @@ -111,6 +116,19 @@ //// }else{ //// System.err.println("结算接口异常【提现】:" + execute.getMsg()); //// } +// +// +// for (int i = 0; i < 2; i++) { +// String value = redisUtil.getValue("repeat_" + 10); +// if(ToolUtil.isEmpty(value)){ +// redisUtil.setStrValue("repeat_" + 10, System.currentTimeMillis() + "", 600);//10分钟 +// }else{ +// Long s = System.currentTimeMillis() - Long.valueOf(value); +// if(s.compareTo(60000L) < 0){//1分钟 +// System.err.println("数据处理中"); +// } +// } +// } // } // //} -- Gitblit v1.7.1