|
|
@@ -13,12 +13,12 @@ import com.izouma.dingdong.enums.*;
|
|
|
import com.izouma.dingdong.exception.BusinessException;
|
|
|
import com.izouma.dingdong.repo.MoneyRecordRepo;
|
|
|
import com.izouma.dingdong.repo.OrderInfoRepo;
|
|
|
-import com.izouma.dingdong.repo.SysConfigRepo;
|
|
|
import com.izouma.dingdong.repo.UserRepo;
|
|
|
import com.izouma.dingdong.repo.rider.RiderLocationRepo;
|
|
|
import com.izouma.dingdong.repo.rider.RiderRepo;
|
|
|
import com.izouma.dingdong.repo.rider.RiderSignRepo;
|
|
|
import com.izouma.dingdong.service.OrderRefundApplyService;
|
|
|
+import com.izouma.dingdong.service.SysConfigService;
|
|
|
import com.izouma.dingdong.utils.MapUtils;
|
|
|
import lombok.AllArgsConstructor;
|
|
|
import org.apache.commons.lang3.RandomStringUtils;
|
|
|
@@ -39,8 +39,8 @@ public class RiderService {
|
|
|
private OrderInfoRepo orderInfoRepo;
|
|
|
private OrderRefundApplyService orderRefundApplyService;
|
|
|
private RiderSignRepo riderSignRepo;
|
|
|
- private SysConfigRepo sysConfigRepo;
|
|
|
private RiderLocationRepo riderLocationRepo;
|
|
|
+ private SysConfigService sysConfigService;
|
|
|
|
|
|
|
|
|
/*
|
|
|
@@ -96,8 +96,7 @@ public class RiderService {
|
|
|
public void sign(Long riderId, String password, Double longitude, Double latitude) {
|
|
|
Rider rider = riderRepo.findById(riderId).orElseThrow(new BusinessException("无骑手"));
|
|
|
Double distance = MapUtils.distance(longitude, latitude, rider.getLongitude(), rider.getLatitude());
|
|
|
- String range = sysConfigRepo.findByName("range").orElseThrow(new BusinessException("无配置")).getValue();
|
|
|
- if (distance > new Double(range)) {
|
|
|
+ if (distance > sysConfigService.getRange()) {
|
|
|
throw new BusinessException("不在工作区域");
|
|
|
}
|
|
|
User user = userRepo.findById(rider.getUserId()).orElseThrow(new BusinessException("无用户"));
|
|
|
@@ -170,6 +169,13 @@ public class RiderService {
|
|
|
throw new BusinessException("已被其他骑手接单");
|
|
|
}
|
|
|
|
|
|
+ //如果是货到付款
|
|
|
+ if (PayMethod.CASH_DELIVERY.equals(orderInfo.getPayMethod())) {
|
|
|
+ if (!this.canCash(riderId)) {
|
|
|
+ throw new BusinessException("不满足接货到付款订单");
|
|
|
+ }
|
|
|
+ }
|
|
|
+
|
|
|
List<OrderInfo> infos = orderInfoRepo.findAllByRiderIdAndRiderStatusIsNot(riderId, RiderStatus.CARRY_OUT);
|
|
|
if (infos.size() >= 5) {
|
|
|
throw new BusinessException("未完成订单已达上线");
|
|
|
@@ -199,7 +205,10 @@ public class RiderService {
|
|
|
locationList.forEach(d -> {
|
|
|
Merchant merchant = orderInfo.getMerchant();
|
|
|
Double distance = MapUtils.distance(merchant.getLongitude(), merchant.getLatitude(), d.getLongitude(), d.getLatitude());
|
|
|
- map.put(d.getRiderId(), distance);
|
|
|
+ //所有附近的骑手的距离
|
|
|
+ if (distance < sysConfigService.getRange()) {
|
|
|
+ map.put(d.getRiderId(), distance);
|
|
|
+ }
|
|
|
});
|
|
|
|
|
|
//无骑手,取消订单
|
|
|
@@ -215,19 +224,22 @@ public class RiderService {
|
|
|
list.sort(Comparator.comparing(Map.Entry<Long, Double>::getValue));
|
|
|
|
|
|
for (Map.Entry<Long, Double> m : list) {
|
|
|
- Rider rider = riderRepo.findById(m.getKey()).orElseThrow(new BusinessException("无骑手"));
|
|
|
- //if (rider.getSignIn()) {
|
|
|
+// Rider rider = riderRepo.findById(m.getKey()).orElseThrow(new BusinessException("无骑手"));
|
|
|
+
|
|
|
List<OrderInfo> infos = orderInfoRepo.findAllByRiderIdAndRiderStatusIsNot(m.getKey(), RiderStatus.CARRY_OUT);
|
|
|
- //有空闲骑手,自动接单,不可拒单
|
|
|
- if (CollUtil.isEmpty(infos)) {
|
|
|
- //riderId = m.getKey();
|
|
|
+ //如果是货到付款
|
|
|
+ boolean t = true;
|
|
|
+ if (PayMethod.CASH_DELIVERY.equals(orderInfo.getPayMethod())) {
|
|
|
+ t = this.canCash(m.getKey());
|
|
|
+ }
|
|
|
+ //有空闲骑手且可以接货到付款,自动接单,不可拒单
|
|
|
+ if (CollUtil.isEmpty(infos) && t) {
|
|
|
orderInfo.setRiderId(m.getKey());
|
|
|
orderInfo.setRiderStatus(RiderStatus.RECEIVED);
|
|
|
orderInfoRepo.save(orderInfo);
|
|
|
return;
|
|
|
//break;
|
|
|
}
|
|
|
- //}
|
|
|
}
|
|
|
|
|
|
//无空闲骑手,未完成订单最少的接单
|
|
|
@@ -238,6 +250,7 @@ public class RiderService {
|
|
|
int infos3 = orderInfoRepo.findAllByRiderIdAndRiderStatusIsNot(list.get(2)
|
|
|
.getKey(), RiderStatus.CARRY_OUT).size();
|
|
|
Long riderId = null;
|
|
|
+
|
|
|
if (infos1 < infos2 && infos1 < infos3) {
|
|
|
riderId = list.get(0).getKey();
|
|
|
} else if (infos2 < infos1 && infos2 < infos3) {
|
|
|
@@ -274,5 +287,14 @@ public class RiderService {
|
|
|
|
|
|
}
|
|
|
|
|
|
+ /*
|
|
|
+ 可不可以接货到付款订单
|
|
|
+ */
|
|
|
+ public Boolean canCash(Long riderId) {
|
|
|
+ Rider rider = riderRepo.findById(riderId).orElseThrow(new BusinessException("无骑手"));
|
|
|
+ BigDecimal account = sysConfigService.getBigDecimal("accountRequirements");
|
|
|
+ return account.compareTo(rider.getUser().getMoney()) <= 0;
|
|
|
+ }
|
|
|
+
|
|
|
|
|
|
}
|