|
|
@@ -6,6 +6,7 @@ import cn.hutool.core.util.ObjectUtil;
|
|
|
import com.izouma.dingdong.domain.*;
|
|
|
import com.izouma.dingdong.domain.merchant.Merchant;
|
|
|
import com.izouma.dingdong.domain.rider.Rider;
|
|
|
+import com.izouma.dingdong.domain.rider.RiderLocation;
|
|
|
import com.izouma.dingdong.domain.rider.RiderSign;
|
|
|
import com.izouma.dingdong.dto.RiderDTO;
|
|
|
import com.izouma.dingdong.dto.RiderDistanceDTO;
|
|
|
@@ -15,6 +16,7 @@ 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;
|
|
|
@@ -39,6 +41,7 @@ public class RiderService {
|
|
|
private OrderRefundApplyService orderRefundApplyService;
|
|
|
private RiderSignRepo riderSignRepo;
|
|
|
private SysConfigRepo sysConfigRepo;
|
|
|
+ private RiderLocationRepo riderLocationRepo;
|
|
|
|
|
|
|
|
|
/*
|
|
|
@@ -104,6 +107,7 @@ public class RiderService {
|
|
|
.longitude(longitude)
|
|
|
.riderId(riderId)
|
|
|
.signTime(LocalDateTime.now())
|
|
|
+ .takingOrders(false)
|
|
|
.build());
|
|
|
}
|
|
|
|
|
|
@@ -116,24 +120,30 @@ public class RiderService {
|
|
|
* @param type 流水类型
|
|
|
* @param remark 备注
|
|
|
*/
|
|
|
- public void income(Long riderId, Long fromUserId, BigDecimal amount, FinancialType type, String remark) {
|
|
|
+ public void income(Long riderId, Long fromUserId, BigDecimal amount, FinancialType type, String remark, RiderMoneyType moneyType) {
|
|
|
//骑手应得 riderRepo.findUserIdById(riderId)
|
|
|
User riderUser = userRepo.findById(riderId).orElseThrow(new BusinessException("无用户"));
|
|
|
riderUser.setMoney(riderUser.getMoney().add(amount));
|
|
|
userRepo.save(riderUser);
|
|
|
|
|
|
- //购买的user
|
|
|
- User user = userRepo.findById(fromUserId).orElseThrow(new BusinessException("无用户"));
|
|
|
-
|
|
|
+ String avatar = "";
|
|
|
+ String name = "叮咚外卖平台";
|
|
|
+ if (fromUserId != null) {
|
|
|
+ //购买的user
|
|
|
+ User user = userRepo.findById(fromUserId).orElseThrow(new BusinessException("无用户"));
|
|
|
+ avatar = user.getAvatar();
|
|
|
+ name = user.getNickname();
|
|
|
+ }
|
|
|
moneyRecordRepo.save(MoneyRecord.builder()
|
|
|
.amount(amount)
|
|
|
- .avatar(user.getAvatar())
|
|
|
- .name(user.getNickname())
|
|
|
+ .avatar(avatar)
|
|
|
+ .name(name)
|
|
|
.type(type)
|
|
|
.fromUserId(fromUserId)
|
|
|
.userId(riderUser.getId())
|
|
|
.time(LocalDateTime.now())
|
|
|
.remark(remark)
|
|
|
+ .content(moneyType.toString())
|
|
|
.enabled(true)
|
|
|
.build());
|
|
|
}
|
|
|
@@ -177,10 +187,13 @@ public class RiderService {
|
|
|
订单量相同,距离最近接单
|
|
|
商家3km内无骑手,取消订单
|
|
|
*/
|
|
|
- public void dispatch(Long orderId, List<RiderDistanceDTO> dtos) {
|
|
|
+ public void dispatch(Long orderId) {
|
|
|
OrderInfo orderInfo = orderInfoRepo.findById(orderId).orElseThrow(new BusinessException("无订单"));
|
|
|
+ //查找骑手位置列表
|
|
|
+ List<RiderLocation> locationList = riderLocationRepo.findAllByCreatedAt(orderInfo.getOrderTime());
|
|
|
+
|
|
|
Map<Long, Double> map = new HashMap<>();
|
|
|
- dtos.forEach(d -> {
|
|
|
+ locationList.forEach(d -> {
|
|
|
Merchant merchant = orderInfo.getMerchant();
|
|
|
Double distance = MapUtils.distance(merchant.getLongitude(), merchant.getLatitude(), d.getLongitude(), d.getLatitude());
|
|
|
map.put(d.getRiderId(), distance);
|
|
|
@@ -246,5 +259,16 @@ public class RiderService {
|
|
|
orderInfoRepo.save(orderInfo);
|
|
|
}
|
|
|
|
|
|
+ /*
|
|
|
+ 开始停止接单
|
|
|
+ */
|
|
|
+ public void stop(Long riderId) {
|
|
|
+// Rider rider = riderRepo.findById(riderId).orElseThrow(new BusinessException("骑手"));
|
|
|
+ RiderSign riderSign = riderSignRepo.findByRiderIdAndTakingOrders(riderId, true);
|
|
|
+ if (ObjectUtil.isNotNull(riderSign)) {
|
|
|
+ riderSign.setTakingOrders(false);
|
|
|
+ }
|
|
|
+
|
|
|
+ }
|
|
|
|
|
|
}
|