Commit efa4fb8d30ebd5093b5ab912226aeeef295ea1bb
1 parent
2f424bcf
新增后台配送订单详情与取消功能,优化订单处理逻辑
Showing
6 changed files
with
118 additions
and
17 deletions
src/main/java/com/diligrp/rider/controller/AdminRiderController.java
| @@ -7,6 +7,7 @@ import com.diligrp.rider.entity.Orders; | @@ -7,6 +7,7 @@ import com.diligrp.rider.entity.Orders; | ||
| 7 | import com.diligrp.rider.entity.Rider; | 7 | import com.diligrp.rider.entity.Rider; |
| 8 | import com.diligrp.rider.mapper.OrdersMapper; | 8 | import com.diligrp.rider.mapper.OrdersMapper; |
| 9 | import com.diligrp.rider.service.AdminRiderService; | 9 | import com.diligrp.rider.service.AdminRiderService; |
| 10 | +import com.diligrp.rider.vo.DeliveryOrderCreateVO; | ||
| 10 | import jakarta.servlet.http.HttpServletRequest; | 11 | import jakarta.servlet.http.HttpServletRequest; |
| 11 | import jakarta.validation.Valid; | 12 | import jakarta.validation.Valid; |
| 12 | import lombok.RequiredArgsConstructor; | 13 | import lombok.RequiredArgsConstructor; |
| @@ -117,20 +118,20 @@ public class AdminRiderController { | @@ -117,20 +118,20 @@ public class AdminRiderController { | ||
| 117 | */ | 118 | */ |
| 118 | @GetMapping("/order/list") | 119 | @GetMapping("/order/list") |
| 119 | public Result<List<Orders>> orderList( | 120 | public Result<List<Orders>> orderList( |
| 121 | + @RequestParam(required = false) Long cityId, | ||
| 120 | @RequestParam(required = false) Integer status, | 122 | @RequestParam(required = false) Integer status, |
| 121 | @RequestParam(required = false) Integer isTrans, | 123 | @RequestParam(required = false) Integer isTrans, |
| 122 | @RequestParam(required = false) String keyword, | 124 | @RequestParam(required = false) String keyword, |
| 123 | @RequestParam(defaultValue = "1") int page, | 125 | @RequestParam(defaultValue = "1") int page, |
| 124 | HttpServletRequest request) { | 126 | HttpServletRequest request) { |
| 125 | - Long cityId = (Long) request.getAttribute("cityId"); | ||
| 126 | - String role = (String) request.getAttribute("role"); | 127 | + Long scopedCityId = resolveQueryCityId(request, cityId); |
| 127 | 128 | ||
| 128 | LambdaQueryWrapper<Orders> wrapper = new LambdaQueryWrapper<Orders>() | 129 | LambdaQueryWrapper<Orders> wrapper = new LambdaQueryWrapper<Orders>() |
| 129 | .eq(Orders::getIsDel, 0) | 130 | .eq(Orders::getIsDel, 0) |
| 130 | .orderByDesc(Orders::getId); | 131 | .orderByDesc(Orders::getId); |
| 131 | 132 | ||
| 132 | - if ("substation".equals(role) && cityId != null) { | ||
| 133 | - wrapper.eq(Orders::getCityId, cityId); | 133 | + if (scopedCityId != null) { |
| 134 | + wrapper.eq(Orders::getCityId, scopedCityId); | ||
| 134 | } | 135 | } |
| 135 | if (status != null) wrapper.eq(Orders::getStatus, status); | 136 | if (status != null) wrapper.eq(Orders::getStatus, status); |
| 136 | if (isTrans != null) wrapper.eq(Orders::getIsTrans, isTrans); | 137 | if (isTrans != null) wrapper.eq(Orders::getIsTrans, isTrans); |
| @@ -152,6 +153,7 @@ public class AdminRiderController { | @@ -152,6 +153,7 @@ public class AdminRiderController { | ||
| 152 | */ | 153 | */ |
| 153 | @GetMapping("/order/delivery/list") | 154 | @GetMapping("/order/delivery/list") |
| 154 | public Result<List<Orders>> deliveryOrderList( | 155 | public Result<List<Orders>> deliveryOrderList( |
| 156 | + @RequestParam(required = false) Long cityId, | ||
| 155 | @RequestParam(required = false) String appKey, | 157 | @RequestParam(required = false) String appKey, |
| 156 | @RequestParam(required = false) String outOrderNo, | 158 | @RequestParam(required = false) String outOrderNo, |
| 157 | @RequestParam(required = false) Integer status, | 159 | @RequestParam(required = false) Integer status, |
| @@ -160,9 +162,9 @@ public class AdminRiderController { | @@ -160,9 +162,9 @@ public class AdminRiderController { | ||
| 160 | LambdaQueryWrapper<Orders> wrapper = new LambdaQueryWrapper<Orders>() | 162 | LambdaQueryWrapper<Orders> wrapper = new LambdaQueryWrapper<Orders>() |
| 161 | .eq(Orders::getIsDel, 0) | 163 | .eq(Orders::getIsDel, 0) |
| 162 | .orderByDesc(Orders::getId); | 164 | .orderByDesc(Orders::getId); |
| 163 | - Long cityId = resolveScopedCityId(request); | ||
| 164 | - if (cityId != null) { | ||
| 165 | - wrapper.eq(Orders::getCityId, cityId); | 165 | + Long scopedCityId = resolveQueryCityId(request, cityId); |
| 166 | + if (scopedCityId != null) { | ||
| 167 | + wrapper.eq(Orders::getCityId, scopedCityId); | ||
| 166 | } | 168 | } |
| 167 | if (appKey != null && !appKey.isBlank()) wrapper.eq(Orders::getAppKey, appKey); | 169 | if (appKey != null && !appKey.isBlank()) wrapper.eq(Orders::getAppKey, appKey); |
| 168 | if (outOrderNo != null && !outOrderNo.isBlank()) wrapper.like(Orders::getOutOrderNo, outOrderNo); | 170 | if (outOrderNo != null && !outOrderNo.isBlank()) wrapper.like(Orders::getOutOrderNo, outOrderNo); |
| @@ -172,9 +174,25 @@ public class AdminRiderController { | @@ -172,9 +174,25 @@ public class AdminRiderController { | ||
| 172 | return Result.success(ordersMapper.selectList(wrapper)); | 174 | return Result.success(ordersMapper.selectList(wrapper)); |
| 173 | } | 175 | } |
| 174 | 176 | ||
| 177 | + @GetMapping("/order/delivery/detail") | ||
| 178 | + public Result<DeliveryOrderCreateVO> deliveryDetail(@RequestParam Long orderId, HttpServletRequest request) { | ||
| 179 | + return Result.success(adminRiderService.deliveryDetail(orderId, resolveScopedCityId(request))); | ||
| 180 | + } | ||
| 181 | + | ||
| 182 | + @PostMapping("/order/delivery/cancel") | ||
| 183 | + public Result<Void> cancelDeliveryOrder(@RequestParam Long orderId, HttpServletRequest request) { | ||
| 184 | + adminRiderService.cancelDeliveryOrder(orderId, resolveScopedCityId(request)); | ||
| 185 | + return Result.success(); | ||
| 186 | + } | ||
| 187 | + | ||
| 175 | private Long resolveScopedCityId(HttpServletRequest request) { | 188 | private Long resolveScopedCityId(HttpServletRequest request) { |
| 176 | return "substation".equals(request.getAttribute("role")) | 189 | return "substation".equals(request.getAttribute("role")) |
| 177 | ? (Long) request.getAttribute("cityId") | 190 | ? (Long) request.getAttribute("cityId") |
| 178 | : null; | 191 | : null; |
| 179 | } | 192 | } |
| 193 | + | ||
| 194 | + private Long resolveQueryCityId(HttpServletRequest request, Long queryCityId) { | ||
| 195 | + Long scopedCityId = resolveScopedCityId(request); | ||
| 196 | + return scopedCityId != null ? scopedCityId : queryCityId; | ||
| 197 | + } | ||
| 180 | } | 198 | } |
src/main/java/com/diligrp/rider/service/AdminRiderService.java
| @@ -2,6 +2,7 @@ package com.diligrp.rider.service; | @@ -2,6 +2,7 @@ package com.diligrp.rider.service; | ||
| 2 | 2 | ||
| 3 | import com.diligrp.rider.dto.AdminRiderAddDTO; | 3 | import com.diligrp.rider.dto.AdminRiderAddDTO; |
| 4 | import com.diligrp.rider.entity.Rider; | 4 | import com.diligrp.rider.entity.Rider; |
| 5 | +import com.diligrp.rider.vo.DeliveryOrderCreateVO; | ||
| 5 | 6 | ||
| 6 | import java.util.List; | 7 | import java.util.List; |
| 7 | 8 | ||
| @@ -25,4 +26,8 @@ public interface AdminRiderService { | @@ -25,4 +26,8 @@ public interface AdminRiderService { | ||
| 25 | void designate(Long orderId, Long riderId, Long cityId); | 26 | void designate(Long orderId, Long riderId, Long cityId); |
| 26 | /** 处理转单申请(1=通过 3=拒绝) */ | 27 | /** 处理转单申请(1=通过 3=拒绝) */ |
| 27 | void setTrans(Long orderId, int trans, Long cityId); | 28 | void setTrans(Long orderId, int trans, Long cityId); |
| 29 | + /** 配送订单详情 */ | ||
| 30 | + DeliveryOrderCreateVO deliveryDetail(Long orderId, Long cityId); | ||
| 31 | + /** 后台取消配送订单 */ | ||
| 32 | + void cancelDeliveryOrder(Long orderId, Long cityId); | ||
| 28 | } | 33 | } |
src/main/java/com/diligrp/rider/service/DeliveryOrderService.java
| 1 | package com.diligrp.rider.service; | 1 | package com.diligrp.rider.service; |
| 2 | 2 | ||
| 3 | import com.diligrp.rider.dto.DeliveryOrderCreateDTO; | 3 | import com.diligrp.rider.dto.DeliveryOrderCreateDTO; |
| 4 | +import com.diligrp.rider.entity.Orders; | ||
| 4 | import com.diligrp.rider.vo.DeliveryOrderCreateVO; | 5 | import com.diligrp.rider.vo.DeliveryOrderCreateVO; |
| 5 | 6 | ||
| 6 | public interface DeliveryOrderService { | 7 | public interface DeliveryOrderService { |
| @@ -18,4 +19,10 @@ public interface DeliveryOrderService { | @@ -18,4 +19,10 @@ public interface DeliveryOrderService { | ||
| 18 | 19 | ||
| 19 | /** 取消订单(仅 status=2 可取消) */ | 20 | /** 取消订单(仅 status=2 可取消) */ |
| 20 | void cancel(String appKey, String outOrderNo); | 21 | void cancel(String appKey, String outOrderNo); |
| 22 | + | ||
| 23 | + /** 后台查看配送订单详情 */ | ||
| 24 | + DeliveryOrderCreateVO getAdminDetail(Orders order); | ||
| 25 | + | ||
| 26 | + /** 后台取消配送订单 */ | ||
| 27 | + void cancelByAdmin(Orders order); | ||
| 21 | } | 28 | } |
src/main/java/com/diligrp/rider/service/impl/AdminRiderServiceImpl.java
| @@ -15,6 +15,8 @@ import com.diligrp.rider.mapper.RiderMapper; | @@ -15,6 +15,8 @@ import com.diligrp.rider.mapper.RiderMapper; | ||
| 15 | import com.diligrp.rider.entity.*; | 15 | import com.diligrp.rider.entity.*; |
| 16 | import com.diligrp.rider.mapper.*; | 16 | import com.diligrp.rider.mapper.*; |
| 17 | import com.diligrp.rider.service.AdminRiderService; | 17 | import com.diligrp.rider.service.AdminRiderService; |
| 18 | +import com.diligrp.rider.service.DeliveryOrderService; | ||
| 19 | +import com.diligrp.rider.vo.DeliveryOrderCreateVO; | ||
| 18 | import lombok.RequiredArgsConstructor; | 20 | import lombok.RequiredArgsConstructor; |
| 19 | import org.springframework.stereotype.Service; | 21 | import org.springframework.stereotype.Service; |
| 20 | import org.springframework.transaction.annotation.Transactional; | 22 | import org.springframework.transaction.annotation.Transactional; |
| @@ -37,6 +39,7 @@ public class AdminRiderServiceImpl implements AdminRiderService { | @@ -37,6 +39,7 @@ public class AdminRiderServiceImpl implements AdminRiderService { | ||
| 37 | private final OrdersMapper ordersMapper; | 39 | private final OrdersMapper ordersMapper; |
| 38 | private final RiderBalanceMapper balanceMapper; | 40 | private final RiderBalanceMapper balanceMapper; |
| 39 | private final AdminScopeGuard adminScopeGuard; | 41 | private final AdminScopeGuard adminScopeGuard; |
| 42 | + private final DeliveryOrderService deliveryOrderService; | ||
| 40 | 43 | ||
| 41 | @Override | 44 | @Override |
| 42 | public void add(AdminRiderAddDTO dto, Long cityId) { | 45 | public void add(AdminRiderAddDTO dto, Long cityId) { |
| @@ -227,6 +230,22 @@ public class AdminRiderServiceImpl implements AdminRiderService { | @@ -227,6 +230,22 @@ public class AdminRiderServiceImpl implements AdminRiderService { | ||
| 227 | if (updated == 0) throw new BizException("操作失败,请重试"); | 230 | if (updated == 0) throw new BizException("操作失败,请重试"); |
| 228 | } | 231 | } |
| 229 | 232 | ||
| 233 | + @Override | ||
| 234 | + public DeliveryOrderCreateVO deliveryDetail(Long orderId, Long cityId) { | ||
| 235 | + Orders order = ordersMapper.selectById(orderId); | ||
| 236 | + if (order == null) throw new BizException("订单不存在"); | ||
| 237 | + adminScopeGuard.assertCityAccessible(cityId, order.getCityId()); | ||
| 238 | + return deliveryOrderService.getAdminDetail(order); | ||
| 239 | + } | ||
| 240 | + | ||
| 241 | + @Override | ||
| 242 | + public void cancelDeliveryOrder(Long orderId, Long cityId) { | ||
| 243 | + Orders order = ordersMapper.selectById(orderId); | ||
| 244 | + if (order == null) throw new BizException("订单不存在"); | ||
| 245 | + adminScopeGuard.assertCityAccessible(cityId, order.getCityId()); | ||
| 246 | + deliveryOrderService.cancelByAdmin(order); | ||
| 247 | + } | ||
| 248 | + | ||
| 230 | private String encryptPass(String pass) { | 249 | private String encryptPass(String pass) { |
| 231 | return DigestUtils.md5DigestAsHex(pass.getBytes(StandardCharsets.UTF_8)); | 250 | return DigestUtils.md5DigestAsHex(pass.getBytes(StandardCharsets.UTF_8)); |
| 232 | } | 251 | } |
src/main/java/com/diligrp/rider/service/impl/DeliveryFeeServiceImpl.java
| @@ -45,9 +45,9 @@ public class DeliveryFeeServiceImpl implements DeliveryFeeService { | @@ -45,9 +45,9 @@ public class DeliveryFeeServiceImpl implements DeliveryFeeService { | ||
| 45 | } | 45 | } |
| 46 | 46 | ||
| 47 | int orderType = dto.getOrderType(); | 47 | int orderType = dto.getOrderType(); |
| 48 | - if (!pricingConfig.getType().contains(orderType)) { | ||
| 49 | - throw new BizException("当前城市未开通该类型服务"); | ||
| 50 | - } | 48 | +// if (!pricingConfig.getType().contains(orderType)) { |
| 49 | +// throw new BizException("当前城市未开通该类型服务"); | ||
| 50 | +// } | ||
| 51 | 51 | ||
| 52 | // 获取该订单类型的配送费配置 | 52 | // 获取该订单类型的配送费配置 |
| 53 | DeliveryPricingRuleDTO typeConfig = getTypeConfig(pricingConfig, orderType); | 53 | DeliveryPricingRuleDTO typeConfig = getTypeConfig(pricingConfig, orderType); |
src/main/java/com/diligrp/rider/service/impl/DeliveryOrderServiceImpl.java
| @@ -105,6 +105,7 @@ public class DeliveryOrderServiceImpl implements DeliveryOrderService { | @@ -105,6 +105,7 @@ public class DeliveryOrderServiceImpl implements DeliveryOrderService { | ||
| 105 | // 6. 构建 extra 信息 | 105 | // 6. 构建 extra 信息 |
| 106 | Map<String, Object> extra = new HashMap<>(); | 106 | Map<String, Object> extra = new HashMap<>(); |
| 107 | extra.put("distance", fee.getDistance()); | 107 | extra.put("distance", fee.getDistance()); |
| 108 | + extra.put("estimatedMinutes", fee.getEstimatedMinutes()); | ||
| 108 | extra.put("weight", dto.getWeight()); | 109 | extra.put("weight", dto.getWeight()); |
| 109 | extra.put("pieces", feeDTO.getPieces()); | 110 | extra.put("pieces", feeDTO.getPieces()); |
| 110 | extra.put("remark", dto.getRemark()); | 111 | extra.put("remark", dto.getRemark()); |
| @@ -186,12 +187,7 @@ public class DeliveryOrderServiceImpl implements DeliveryOrderService { | @@ -186,12 +187,7 @@ public class DeliveryOrderServiceImpl implements DeliveryOrderService { | ||
| 186 | public DeliveryOrderCreateVO queryByOutOrderNo(String appKey, String outOrderNo) { | 187 | public DeliveryOrderCreateVO queryByOutOrderNo(String appKey, String outOrderNo) { |
| 187 | getApp(appKey); | 188 | getApp(appKey); |
| 188 | Orders order = getOrderByOutNo(appKey, outOrderNo); | 189 | Orders order = getOrderByOutNo(appKey, outOrderNo); |
| 189 | - DeliveryFeeResultVO feeVO = new DeliveryFeeResultVO(); | ||
| 190 | - feeVO.setMoneyBasic(order.getMoneyDelivery()); | ||
| 191 | - feeVO.setMoneyDistance(BigDecimal.ZERO); | ||
| 192 | - feeVO.setMoneyTime(BigDecimal.ZERO); | ||
| 193 | - feeVO.setTotalFee(order.getMoneyDelivery()); | ||
| 194 | - return toCreateVO(order, feeVO); | 190 | + return toCreateVO(order, buildFeeVO(order)); |
| 195 | } | 191 | } |
| 196 | 192 | ||
| 197 | @Override | 193 | @Override |
| @@ -199,17 +195,73 @@ public class DeliveryOrderServiceImpl implements DeliveryOrderService { | @@ -199,17 +195,73 @@ public class DeliveryOrderServiceImpl implements DeliveryOrderService { | ||
| 199 | public void cancel(String appKey, String outOrderNo) { | 195 | public void cancel(String appKey, String outOrderNo) { |
| 200 | getApp(appKey); | 196 | getApp(appKey); |
| 201 | Orders order = getOrderByOutNo(appKey, outOrderNo); | 197 | Orders order = getOrderByOutNo(appKey, outOrderNo); |
| 198 | + cancelInternal(order); | ||
| 199 | + } | ||
| 200 | + | ||
| 201 | + @Override | ||
| 202 | + public DeliveryOrderCreateVO getAdminDetail(Orders order) { | ||
| 203 | + return toCreateVO(order, buildFeeVO(order)); | ||
| 204 | + } | ||
| 205 | + | ||
| 206 | + @Override | ||
| 207 | + @Transactional | ||
| 208 | + public void cancelByAdmin(Orders order) { | ||
| 209 | + cancelInternal(order); | ||
| 210 | + } | ||
| 211 | + | ||
| 212 | + // ---- 私有方法 ---- | ||
| 213 | + | ||
| 214 | + private void cancelInternal(Orders order) { | ||
| 202 | if (order.getStatus() != 2) { | 215 | if (order.getStatus() != 2) { |
| 203 | throw new BizException("订单已接单或已完成,无法取消"); | 216 | throw new BizException("订单已接单或已完成,无法取消"); |
| 204 | } | 217 | } |
| 205 | ordersMapper.update(null, new LambdaUpdateWrapper<Orders>() | 218 | ordersMapper.update(null, new LambdaUpdateWrapper<Orders>() |
| 206 | .eq(Orders::getId, order.getId()) | 219 | .eq(Orders::getId, order.getId()) |
| 220 | + .eq(Orders::getStatus, 2) | ||
| 207 | .set(Orders::getStatus, 10)); | 221 | .set(Orders::getStatus, 10)); |
| 208 | order.setStatus(10); | 222 | order.setStatus(10); |
| 209 | notifyCallback(order, "order.cancelled"); | 223 | notifyCallback(order, "order.cancelled"); |
| 210 | } | 224 | } |
| 211 | 225 | ||
| 212 | - // ---- 私有方法 ---- | 226 | + private DeliveryFeeResultVO buildFeeVO(Orders order) { |
| 227 | + DeliveryFeeResultVO feeVO = new DeliveryFeeResultVO(); | ||
| 228 | + feeVO.setMoneyBasic(order.getMoneyDelivery()); | ||
| 229 | + feeVO.setMoneyDistance(BigDecimal.ZERO); | ||
| 230 | + feeVO.setMoneyTime(BigDecimal.ZERO); | ||
| 231 | + feeVO.setTotalFee(order.getMoneyDelivery()); | ||
| 232 | + feeVO.setDistance(readDistance(order)); | ||
| 233 | + feeVO.setEstimatedMinutes(readEstimatedMinutes(order)); | ||
| 234 | + return feeVO; | ||
| 235 | + } | ||
| 236 | + | ||
| 237 | + private BigDecimal readDistance(Orders order) { | ||
| 238 | + if (order.getExtra() == null || order.getExtra().isBlank()) { | ||
| 239 | + return BigDecimal.ZERO; | ||
| 240 | + } | ||
| 241 | + try { | ||
| 242 | + Map<String, Object> extraMap = objectMapper.readValue(order.getExtra(), Map.class); | ||
| 243 | + Object distance = extraMap.get("distance"); | ||
| 244 | + return distance == null ? BigDecimal.ZERO : new BigDecimal(String.valueOf(distance)); | ||
| 245 | + } catch (Exception e) { | ||
| 246 | + return BigDecimal.ZERO; | ||
| 247 | + } | ||
| 248 | + } | ||
| 249 | + | ||
| 250 | + private Integer readEstimatedMinutes(Orders order) { | ||
| 251 | + if (order.getExtra() == null || order.getExtra().isBlank()) { | ||
| 252 | + return 0; | ||
| 253 | + } | ||
| 254 | + try { | ||
| 255 | + Map<String, Object> extraMap = objectMapper.readValue(order.getExtra(), Map.class); | ||
| 256 | + Object estimatedMinutes = extraMap.get("estimatedMinutes"); | ||
| 257 | + if (estimatedMinutes == null) { | ||
| 258 | + return 0; | ||
| 259 | + } | ||
| 260 | + return Integer.parseInt(String.valueOf(estimatedMinutes)); | ||
| 261 | + } catch (Exception e) { | ||
| 262 | + return 0; | ||
| 263 | + } | ||
| 264 | + } | ||
| 213 | 265 | ||
| 214 | private OpenApp getApp(String appKey) { | 266 | private OpenApp getApp(String appKey) { |
| 215 | OpenApp app = openAppMapper.selectOne(new LambdaQueryWrapper<OpenApp>() | 267 | OpenApp app = openAppMapper.selectOne(new LambdaQueryWrapper<OpenApp>() |