查询用户订单统计新增超级管理员校验

This commit is contained in:
yanglei 2026-01-16 17:13:24 +08:00
parent a263b9b595
commit 988f3e4747
5 changed files with 70 additions and 19 deletions

View File

@ -14,6 +14,9 @@ import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping; import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController; import org.springframework.web.bind.annotation.RestController;
import java.util.Collections;
import java.util.Optional;
/** /**
* 用户订单统计 控制层 * 用户订单统计 控制层
* *
@ -37,7 +40,17 @@ public class EbikeStatisticsController {
public JsonResult<?> getOrderStatistics(@RequestBody @Validated FeignEbikeOrderStatisticsDto dto) { public JsonResult<?> getOrderStatistics(@RequestBody @Validated FeignEbikeOrderStatisticsDto dto) {
long staffId = StpUtil.getLoginIdAsLong(); long staffId = StpUtil.getLoginIdAsLong();
CommonStaffInfo staffInfo = StpUtil.getSession().getModel(String.valueOf(staffId), CommonStaffInfo.class); CommonStaffInfo staffInfo = StpUtil.getSession().getModel(String.valueOf(staffId), CommonStaffInfo.class);
if (staffInfo == null) {
throw new EbikeException("当前用户信息不存在");
}
boolean isSuperAdmin = Optional.ofNullable(staffInfo.getRoles())
.orElse(Collections.emptyList())
.stream()
.anyMatch(role -> "super_admin".equals(role.getRoleCode()));
// 判断是否超级管理员
if (!isSuperAdmin) {
dto.setOperatorId(staffInfo.getOperatorId()); dto.setOperatorId(staffInfo.getOperatorId());
}
JsonResult<?> jsonResult = userFeignClient.getOrderStatistics(dto); JsonResult<?> jsonResult = userFeignClient.getOrderStatistics(dto);
if (jsonResult.getCode() != Code.SUCCESS) { if (jsonResult.getCode() != Code.SUCCESS) {
throw new EbikeException(jsonResult.getMessage()); throw new EbikeException(jsonResult.getMessage());

View File

@ -88,7 +88,7 @@ public class EbikeOrderController {
*/ */
@GetMapping("checkHistoryOrder") @GetMapping("checkHistoryOrder")
public JsonResult<?> checkHistoryOrder(@Validated @NotNull(message = "用户id不能为空") @RequestParam("userId") Long userId) { public JsonResult<?> checkHistoryOrder(@Validated @NotNull(message = "用户id不能为空") @RequestParam("userId") Long userId) {
EbikeOrder userOrders = ebikeOrderService.checkHistoryOrder(userId); EbikeOrderDetailVo userOrders = ebikeOrderService.checkHistoryOrder(userId);
return JsonResult.success(userOrders); return JsonResult.success(userOrders);
} }

View File

@ -6,8 +6,8 @@ import com.cdzy.common.model.response.JsonResult;
import com.cdzy.user.model.dto.EbikeUserPageDto; import com.cdzy.user.model.dto.EbikeUserPageDto;
import com.cdzy.user.model.dto.UserValidateDto; import com.cdzy.user.model.dto.UserValidateDto;
import com.cdzy.user.model.dto.WechatInfoDto; import com.cdzy.user.model.dto.WechatInfoDto;
import com.cdzy.user.model.entity.EbikeOrder;
import com.cdzy.user.model.entity.EbikeUser; import com.cdzy.user.model.entity.EbikeUser;
import com.cdzy.user.model.vo.EbikeOrderDetailVo;
import com.cdzy.user.model.vo.EbikeUserVo; import com.cdzy.user.model.vo.EbikeUserVo;
import com.cdzy.user.service.EbikeOrderService; import com.cdzy.user.service.EbikeOrderService;
import com.cdzy.user.service.EbikeUserRealInfoService; import com.cdzy.user.service.EbikeUserRealInfoService;
@ -141,7 +141,7 @@ public class EbikeUserController {
@PostMapping("deRegister") @PostMapping("deRegister")
public JsonResult<?> deRegister(@RequestBody EbikeUser ebikeUser) { public JsonResult<?> deRegister(@RequestBody EbikeUser ebikeUser) {
// 需要检测用户是否还有未支付的订单如果有则不能注销 // 需要检测用户是否还有未支付的订单如果有则不能注销
EbikeOrder unPayed = ebikeOrderTransactionService.checkHistoryOrder(ebikeUser.getUserId()); EbikeOrderDetailVo unPayed = ebikeOrderTransactionService.checkHistoryOrder(ebikeUser.getUserId());
if (unPayed != null) { if (unPayed != null) {
throw new EbikeException("用户还有未完成的订单,不能注销"); throw new EbikeException("用户还有未完成的订单,不能注销");
} }
@ -219,6 +219,7 @@ public class EbikeUserController {
/** /**
* 校验用户是否存在 * 校验用户是否存在
*
* @param userId 用户id * @param userId 用户id
* @return true 存在 false 不存在 * @return true 存在 false 不存在
*/ */

View File

@ -39,7 +39,7 @@ public interface EbikeOrderService extends IService<EbikeOrder> {
* *
* @param userId 用户id * @param userId 用户id
*/ */
EbikeOrder checkHistoryOrder(Long userId); EbikeOrderDetailVo checkHistoryOrder(Long userId);
/** /**
* 订单发起退款 * 订单发起退款

View File

@ -44,6 +44,7 @@ import jakarta.annotation.Resource;
import lombok.extern.slf4j.Slf4j; import lombok.extern.slf4j.Slf4j;
import org.springframework.stereotype.Service; import org.springframework.stereotype.Service;
import org.springframework.transaction.annotation.Transactional; import org.springframework.transaction.annotation.Transactional;
import org.springframework.util.CollectionUtils;
import java.math.BigDecimal; import java.math.BigDecimal;
import java.math.RoundingMode; import java.math.RoundingMode;
@ -89,7 +90,7 @@ public class EbikeOrderServiceImpl extends ServiceImpl<EbikeOrderMapper, EbikeOr
Long userId = orderDto.getUserId(); Long userId = orderDto.getUserId();
String bikeCode = orderDto.getBikeCode(); String bikeCode = orderDto.getBikeCode();
// 校验用户当前是否存在订单 // 校验用户当前是否存在订单
EbikeOrder history = checkHistoryOrder(userId); EbikeOrder history = checkExitHistoryOrder(userId);
if (Objects.nonNull(history)) { if (Objects.nonNull(history)) {
if (history.getOrderStatus() == OrderStatus.IN_PROGRESS) { if (history.getOrderStatus() == OrderStatus.IN_PROGRESS) {
throw new EbikeException("请完成当前订单后再试"); throw new EbikeException("请完成当前订单后再试");
@ -140,11 +141,44 @@ public class EbikeOrderServiceImpl extends ServiceImpl<EbikeOrderMapper, EbikeOr
@Override @Override
public EbikeOrder checkHistoryOrder(Long userId) { public EbikeOrderDetailVo checkHistoryOrder(Long userId) {
QueryWrapper queryWrapper = QueryWrapper.create() QueryWrapper queryWrapper = QueryWrapper.create()
.where(EBIKE_ORDER.USER_ID.eq(userId)) .where(EBIKE_ORDER.USER_ID.eq(userId))
.where(EBIKE_ORDER.ORDER_STATUS.eq(OrderStatus.IN_PROGRESS).or(EBIKE_ORDER.ORDER_STATUS.eq(OrderStatus.PENDING_PAYMENT))); .where(EBIKE_ORDER.ORDER_STATUS.eq(OrderStatus.IN_PROGRESS).or(EBIKE_ORDER.ORDER_STATUS.eq(OrderStatus.PENDING_PAYMENT)));
return ebikeOrderTransactionMapper.selectOneByQuery(queryWrapper); EbikeOrderDetailVo ebikeOrderDetailVo = this.mapper.selectOneByQueryAs(queryWrapper, EbikeOrderDetailVo.class);
if (Objects.isNull(ebikeOrderDetailVo)) {
return null;
}
ebikeOrderDetailVo.setUserDurationFee(BigDecimal.ZERO);
ebikeOrderDetailVo.setUserBaseFee(BigDecimal.ZERO);
ebikeOrderDetailVo.setUserDispatchFee(BigDecimal.ZERO);
ebikeOrderDetailVo.setUserHelmetFee(BigDecimal.ZERO);
//获取费用详情
List<EbikePaymentCostDetailVo> details = ebikeOrderDetailService.getOrderDetailsByOrderId(ebikeOrderDetailVo.getOrderId());
if (!CollectionUtils.isEmpty(details)) {
for (EbikePaymentCostDetailVo payDetailVo : details) {
//1-时长费用 2-起步费用 3-运营区调度费用 4-停车区外调度费用 5-禁停区调度费用 6-头盔使用费用
switch (payDetailVo.getDetailType()) {
case 1 -> {
BigDecimal current = payDetailVo.getDetailAmount();
ebikeOrderDetailVo.setUserDurationFee((current != null ? current : BigDecimal.ZERO));
}
case 2 -> {
BigDecimal current = payDetailVo.getDetailAmount();
ebikeOrderDetailVo.setUserBaseFee((current != null ? current : BigDecimal.ZERO));
}
case 3, 4, 5 -> {
BigDecimal current = payDetailVo.getDetailAmount();
ebikeOrderDetailVo.setUserDispatchFee((current != null ? current : BigDecimal.ZERO));
}
case 6 -> {
BigDecimal current = payDetailVo.getDetailAmount();
ebikeOrderDetailVo.setUserHelmetFee((current != null ? current : BigDecimal.ZERO));
}
}
}
}
return ebikeOrderDetailVo;
} }
@ -321,9 +355,13 @@ public class EbikeOrderServiceImpl extends ServiceImpl<EbikeOrderMapper, EbikeOr
if (Objects.isNull(ebikeOrderDetailVo)) { if (Objects.isNull(ebikeOrderDetailVo)) {
throw new EbikeException("订单不存在"); throw new EbikeException("订单不存在");
} }
ebikeOrderDetailVo.setUserDurationFee(BigDecimal.ZERO);
ebikeOrderDetailVo.setUserBaseFee(BigDecimal.ZERO);
ebikeOrderDetailVo.setUserDispatchFee(BigDecimal.ZERO);
ebikeOrderDetailVo.setUserHelmetFee(BigDecimal.ZERO);
//获取费用详情 //获取费用详情
List<EbikePaymentCostDetailVo> details = ebikeOrderDetailService.getOrderDetailsByOrderId(orderId); List<EbikePaymentCostDetailVo> details = ebikeOrderDetailService.getOrderDetailsByOrderId(orderId);
if (Objects.nonNull(details)) { if (!CollectionUtils.isEmpty(details)) {
for (EbikePaymentCostDetailVo payDetailVo : details) { for (EbikePaymentCostDetailVo payDetailVo : details) {
//1-时长费用 2-起步费用 3-运营区调度费用 4-停车区外调度费用 5-禁停区调度费用 6-头盔使用费用 //1-时长费用 2-起步费用 3-运营区调度费用 4-停车区外调度费用 5-禁停区调度费用 6-头盔使用费用
switch (payDetailVo.getDetailType()) { switch (payDetailVo.getDetailType()) {
@ -335,15 +373,7 @@ public class EbikeOrderServiceImpl extends ServiceImpl<EbikeOrderMapper, EbikeOr
BigDecimal current = payDetailVo.getDetailAmount(); BigDecimal current = payDetailVo.getDetailAmount();
ebikeOrderDetailVo.setUserBaseFee((current != null ? current : BigDecimal.ZERO)); ebikeOrderDetailVo.setUserBaseFee((current != null ? current : BigDecimal.ZERO));
} }
case 3 -> { case 3, 4, 5 -> {
BigDecimal current = payDetailVo.getDetailAmount();
ebikeOrderDetailVo.setUserDispatchFee((current != null ? current : BigDecimal.ZERO));
}
case 4 -> {
BigDecimal current = payDetailVo.getDetailAmount();
ebikeOrderDetailVo.setUserDispatchFee((current != null ? current : BigDecimal.ZERO));
}
case 5 -> {
BigDecimal current = payDetailVo.getDetailAmount(); BigDecimal current = payDetailVo.getDetailAmount();
ebikeOrderDetailVo.setUserDispatchFee((current != null ? current : BigDecimal.ZERO)); ebikeOrderDetailVo.setUserDispatchFee((current != null ? current : BigDecimal.ZERO));
} }
@ -546,4 +576,11 @@ public class EbikeOrderServiceImpl extends ServiceImpl<EbikeOrderMapper, EbikeOr
} }
return userOrders; return userOrders;
} }
private EbikeOrder checkExitHistoryOrder(Long userId) {
QueryWrapper queryWrapper = QueryWrapper.create()
.where(EBIKE_ORDER.USER_ID.eq(userId))
.where(EBIKE_ORDER.ORDER_STATUS.eq(OrderStatus.IN_PROGRESS).or(EBIKE_ORDER.ORDER_STATUS.eq(OrderStatus.PENDING_PAYMENT)));
return ebikeOrderTransactionMapper.selectOneByQuery(queryWrapper);
}
} }