Compare commits
2 Commits
820c7c7187
...
893976c3f4
| Author | SHA1 | Date | |
|---|---|---|---|
| 893976c3f4 | |||
| df9235dc10 |
@ -4,8 +4,10 @@ import com.cdzy.common.model.EbikeUserFaultreportDto;
|
||||
import com.cdzy.common.model.EbikeUserFaultreportQueryDto;
|
||||
import com.cdzy.common.model.JsonResult;
|
||||
import org.springframework.cloud.openfeign.FeignClient;
|
||||
import org.springframework.web.bind.annotation.GetMapping;
|
||||
import org.springframework.web.bind.annotation.PostMapping;
|
||||
import org.springframework.web.bind.annotation.RequestBody;
|
||||
import org.springframework.web.bind.annotation.RequestParam;
|
||||
|
||||
import java.util.List;
|
||||
|
||||
@ -35,4 +37,28 @@ public interface OrdersFeignClient {
|
||||
*/
|
||||
@PostMapping("ebikeUserFaultreport/list")
|
||||
JsonResult<?> getUserReportList(@RequestBody EbikeUserFaultreportQueryDto queryParam);
|
||||
|
||||
/**
|
||||
* 订单支付完成
|
||||
* @param queryParam 支付信息
|
||||
* @return @ {@code 200} 成功,{@code 500} 失败
|
||||
*/
|
||||
@PostMapping("userOrders/payment")
|
||||
JsonResult<?> payment(@RequestBody EbikeUserFaultreportQueryDto queryParam);
|
||||
|
||||
/**
|
||||
* 订单发起退款
|
||||
* @param orderId 订单ID
|
||||
* @return @ {@code 200} 成功,{@code 500} 失败
|
||||
*/
|
||||
@GetMapping("userOrders/refund")
|
||||
JsonResult<?> refund(@RequestParam("orderId")Long orderId);
|
||||
|
||||
/**
|
||||
* 订单退款完成
|
||||
* @param orderId 订单ID
|
||||
* @return @ {@code 200} 成功,{@code 500} 失败
|
||||
*/
|
||||
@GetMapping("userOrders/doneRefund")
|
||||
JsonResult<?> doneRefund(@RequestParam("orderId")Long orderId);
|
||||
}
|
||||
|
||||
@ -0,0 +1,28 @@
|
||||
package com.ebike.feign.model.res;
|
||||
|
||||
import lombok.Data;
|
||||
|
||||
import java.time.LocalDateTime;
|
||||
|
||||
/**
|
||||
* @author attiya
|
||||
* @since 2025-04-24
|
||||
*/
|
||||
@Data
|
||||
public class ResFeignOrderPaymentDto {
|
||||
|
||||
/**
|
||||
* 订单id
|
||||
*/
|
||||
private Long orderId;
|
||||
|
||||
/**
|
||||
* 支付方式:wechat/alipay/balance
|
||||
*/
|
||||
private String paymentMethod;
|
||||
|
||||
/**
|
||||
* 支付时间
|
||||
*/
|
||||
private LocalDateTime paymentTime;
|
||||
}
|
||||
@ -4,6 +4,7 @@ import com.cdzy.common.model.JsonResult;
|
||||
import com.cdzy.common.model.PageParam;
|
||||
import com.cdzy.orders.model.dto.req.ReqBikeDto;
|
||||
import com.cdzy.orders.model.dto.req.ReqOrderDto;
|
||||
import com.ebike.feign.model.res.ResFeignOrderPaymentDto;
|
||||
import com.cdzy.orders.model.dto.res.RspBikeDto;
|
||||
import com.cdzy.orders.model.entity.UserOrders;
|
||||
import com.cdzy.orders.service.UserOrdersService;
|
||||
@ -106,6 +107,43 @@ public class EbikeUserOrdersController {
|
||||
return JsonResult.success(orderId);
|
||||
}
|
||||
|
||||
/**
|
||||
* 订单支付。
|
||||
*
|
||||
* @param paymentDto 支付信息
|
||||
* @ {@code 200} 添加成功,{@code 500} 添加失败
|
||||
*/
|
||||
@PostMapping("payment")
|
||||
public JsonResult<?> payment(@RequestBody @Validated ResFeignOrderPaymentDto paymentDto) {
|
||||
userOrdersService.payment(paymentDto);
|
||||
return JsonResult.success();
|
||||
}
|
||||
|
||||
/**
|
||||
* 订单退款。
|
||||
*
|
||||
* @param orderId 订单ID
|
||||
* @ {@code 200} 添加成功,{@code 500} 添加失败
|
||||
*/
|
||||
@GetMapping("refund")
|
||||
public JsonResult<?> refund(@RequestParam("orderId")Long orderId) {
|
||||
userOrdersService.refund(orderId);
|
||||
return JsonResult.success();
|
||||
}
|
||||
|
||||
/**
|
||||
* 订单退款完成。
|
||||
*
|
||||
* @param orderId 订单ID
|
||||
* @ {@code 200} 添加成功,{@code 500} 添加失败
|
||||
*/
|
||||
@GetMapping("doneRefund")
|
||||
public JsonResult<?> doneRefund(@RequestParam("orderId")Long orderId) {
|
||||
userOrdersService.doneRefund(orderId);
|
||||
return JsonResult.success();
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* 检查车辆是否在运营区内。
|
||||
*
|
||||
|
||||
@ -21,6 +21,11 @@ public interface OrderStatus {
|
||||
*/
|
||||
int PENDING_PAYMENT = 2;
|
||||
|
||||
/**
|
||||
* 已支付
|
||||
*/
|
||||
int PAID = 3;
|
||||
|
||||
/**
|
||||
* 退款中
|
||||
*/
|
||||
|
||||
@ -2,6 +2,7 @@ package com.cdzy.orders.service;
|
||||
|
||||
import com.cdzy.orders.model.dto.req.ReqBikeDto;
|
||||
import com.cdzy.orders.model.dto.req.ReqOrderDto;
|
||||
import com.ebike.feign.model.res.ResFeignOrderPaymentDto;
|
||||
import com.cdzy.orders.model.dto.res.RspBikeDto;
|
||||
import com.mybatisflex.core.service.IService;
|
||||
import com.cdzy.orders.model.entity.UserOrders;
|
||||
@ -72,4 +73,22 @@ public interface UserOrdersService extends IService<UserOrders> {
|
||||
* @return true/false
|
||||
*/
|
||||
boolean checkBikeInParking(String bikeCode);
|
||||
|
||||
/**
|
||||
* 订单支付
|
||||
* @param paymentDto 支付信息
|
||||
*/
|
||||
void payment(ResFeignOrderPaymentDto paymentDto);
|
||||
|
||||
/**
|
||||
* 订单退款
|
||||
* @param orderId 订单ID
|
||||
*/
|
||||
void refund(Long orderId);
|
||||
|
||||
/**
|
||||
* 订单退款完成
|
||||
* @param orderId 订单ID
|
||||
*/
|
||||
void doneRefund(Long orderId);
|
||||
}
|
||||
|
||||
@ -12,6 +12,7 @@ import com.cdzy.orders.enums.OrderType;
|
||||
import com.cdzy.orders.mapper.UserOrdersMapper;
|
||||
import com.cdzy.orders.model.dto.req.ReqBikeDto;
|
||||
import com.cdzy.orders.model.dto.req.ReqOrderDto;
|
||||
import com.ebike.feign.model.res.ResFeignOrderPaymentDto;
|
||||
import com.cdzy.orders.model.dto.res.RedisPoint;
|
||||
import com.cdzy.orders.model.dto.res.RspBikeDto;
|
||||
import com.cdzy.orders.model.entity.UserOrders;
|
||||
@ -98,7 +99,7 @@ public class UserOrdersServiceImpl extends ServiceImpl<UserOrdersMapper, UserOrd
|
||||
String jsonString = JSONObject.toJSONString(redisUtil.get(ecuInfo.getEcuSn()));
|
||||
ResGPSDto resGpsDto = JSONObject.parseObject(jsonString, ResGPSDto.class);
|
||||
boolean pointInOperation = bikeInOperation(resGpsDto.getLongitude(), resGpsDto.getLatitude(), regionDto.getOrgId(), regionDto.getRegionId());
|
||||
if (!pointInOperation){
|
||||
if (!pointInOperation) {
|
||||
throw new RuntimeException("当前车辆在运营区外");
|
||||
}
|
||||
//开锁,并且等待结果
|
||||
@ -149,7 +150,7 @@ public class UserOrdersServiceImpl extends ServiceImpl<UserOrdersMapper, UserOrd
|
||||
FeignEbikeRegionDto regionDto = regionResult.getData();
|
||||
|
||||
ResFeignEbikeSysRcostsetDto feignEbikeSysRcostsetDto = operateJsonResult.getData();
|
||||
costCalculation(feignEbikeSysRcostsetDto,resGpsDto,regionDto,userOrders);
|
||||
costCalculation(feignEbikeSysRcostsetDto, resGpsDto, regionDto, userOrders);
|
||||
userOrdersMapper.update(userOrders);
|
||||
//关锁,并且等待结果
|
||||
CompletableFuture<String> stringCompletableFuture = ebikeCoreHandler.executeCommand(ecuInfo, CmdCode.LOCK, Long.valueOf(bikeInfoDto.getBikeId()), userId);
|
||||
@ -253,7 +254,7 @@ public class UserOrdersServiceImpl extends ServiceImpl<UserOrdersMapper, UserOrd
|
||||
FeignEbikeRegionDto regionDto = regionResult.getData();
|
||||
String jsonString = JSONObject.toJSONString(redisUtil.get(ecuInfo.getEcuSn()));
|
||||
ResGPSDto resGpsDto = JSONObject.parseObject(jsonString, ResGPSDto.class);
|
||||
return bikeInOperation(resGpsDto.getLongitude(),resGpsDto.getLatitude(),regionDto.getOrgId(),bikeInfoDto.getReginId());
|
||||
return bikeInOperation(resGpsDto.getLongitude(), resGpsDto.getLatitude(), regionDto.getOrgId(), bikeInfoDto.getReginId());
|
||||
}
|
||||
|
||||
@Override
|
||||
@ -271,7 +272,37 @@ public class UserOrdersServiceImpl extends ServiceImpl<UserOrdersMapper, UserOrd
|
||||
FeignEbikeRegionDto regionDto = regionResult.getData();
|
||||
String jsonString = JSONObject.toJSONString(redisUtil.get(ecuInfo.getEcuSn()));
|
||||
ResGPSDto resGpsDto = JSONObject.parseObject(jsonString, ResGPSDto.class);
|
||||
return redisUtil.isPointInParking(resGpsDto.getLongitude(),resGpsDto.getLatitude(),regionDto.getOrgId());
|
||||
return redisUtil.isPointInParking(resGpsDto.getLongitude(), resGpsDto.getLatitude(), regionDto.getOrgId());
|
||||
}
|
||||
|
||||
@Override
|
||||
public void refund(Long orderId) {
|
||||
QueryWrapper queryWrapper = QueryWrapper.create()
|
||||
.where(USER_ORDERS.ORDER_ID.eq(orderId))
|
||||
.where(USER_ORDERS.STATUS.eq(OrderStatus.PAID));
|
||||
UserOrders userOrders = this.mapper.selectOneByQuery(queryWrapper);
|
||||
userOrders.setStatus(OrderStatus.REFUNDING);
|
||||
this.mapper.update(userOrders);
|
||||
}
|
||||
|
||||
@Override
|
||||
public void doneRefund(Long orderId) {
|
||||
QueryWrapper queryWrapper = QueryWrapper.create()
|
||||
.where(USER_ORDERS.ORDER_ID.eq(orderId))
|
||||
.where(USER_ORDERS.STATUS.eq(OrderStatus.REFUNDING));
|
||||
UserOrders userOrders = this.mapper.selectOneByQuery(queryWrapper);
|
||||
userOrders.setStatus(OrderStatus.REFUNDED);
|
||||
this.mapper.update(userOrders);
|
||||
}
|
||||
|
||||
@Override
|
||||
public void payment(ResFeignOrderPaymentDto paymentDto) {
|
||||
UserOrders userOrders = this.mapper.selectOneById(paymentDto.getOrderId());
|
||||
userOrders.setStatus(OrderStatus.PAID);
|
||||
userOrders.setPaymentTime(paymentDto.getPaymentTime());
|
||||
userOrders.setPaymentMethod(paymentDto.getPaymentMethod());
|
||||
this.mapper.update(userOrders);
|
||||
|
||||
}
|
||||
|
||||
boolean bikeInOperation(double lng, double lat, Long orgId, Long regionId) {
|
||||
@ -281,12 +312,13 @@ public class UserOrdersServiceImpl extends ServiceImpl<UserOrdersMapper, UserOrd
|
||||
|
||||
/**
|
||||
* 计算费用
|
||||
*
|
||||
* @param feignEbikeSysRcostsetDto 计费规则
|
||||
* @param resGpsDto 定位信息
|
||||
* @param regionDto 运营区域信息
|
||||
* @param userOrders 订单信息
|
||||
* @param resGpsDto 定位信息
|
||||
* @param regionDto 运营区域信息
|
||||
* @param userOrders 订单信息
|
||||
*/
|
||||
void costCalculation(ResFeignEbikeSysRcostsetDto feignEbikeSysRcostsetDto, ResGPSDto resGpsDto,FeignEbikeRegionDto regionDto,UserOrders userOrders){
|
||||
void costCalculation(ResFeignEbikeSysRcostsetDto feignEbikeSysRcostsetDto, ResGPSDto resGpsDto, FeignEbikeRegionDto regionDto, UserOrders userOrders) {
|
||||
BigDecimal totalAmount = new BigDecimal(0);
|
||||
//是否在运营区内
|
||||
boolean pointInOperation = bikeInOperation(resGpsDto.getLongitude(), resGpsDto.getLatitude(), regionDto.getOrgId(), regionDto.getRegionId());
|
||||
@ -294,16 +326,16 @@ public class UserOrdersServiceImpl extends ServiceImpl<UserOrdersMapper, UserOrd
|
||||
boolean pointInParking = redisUtil.isPointInParking(resGpsDto.getLongitude(), resGpsDto.getLatitude(), regionDto.getOrgId());
|
||||
long minutes = TimeUtils.betweenMinutes(userOrders.getStartTime(), userOrders.getEndTime());
|
||||
//是否取消订单
|
||||
if (pointInOperation && pointInParking && minutes < feignEbikeSysRcostsetDto.getFreeDuration()){
|
||||
if (pointInOperation && pointInParking && minutes < feignEbikeSysRcostsetDto.getFreeDuration()) {
|
||||
userOrders.setStatus(OrderStatus.CANCELLED);
|
||||
return;
|
||||
}
|
||||
//计算调度费用
|
||||
if (pointInOperation && !pointInParking){
|
||||
if (pointInOperation && !pointInParking) {
|
||||
//停车区调度费用
|
||||
BigDecimal parkingAreaOutDispatchFee = feignEbikeSysRcostsetDto.getParkingAreaOutDispatchFee();
|
||||
totalAmount = totalAmount.add(parkingAreaOutDispatchFee);
|
||||
}else if (!pointInOperation){
|
||||
} else if (!pointInOperation) {
|
||||
//运营区调度费用
|
||||
BigDecimal dispatchFeeOutOperateArea = feignEbikeSysRcostsetDto.getDispatchFeeOutOperateArea();
|
||||
totalAmount = totalAmount.add(dispatchFeeOutOperateArea);
|
||||
@ -321,41 +353,44 @@ public class UserOrdersServiceImpl extends ServiceImpl<UserOrdersMapper, UserOrd
|
||||
|
||||
/**
|
||||
* 按照特殊时间段计费
|
||||
* @param totalAmount 当前金额(时间段计费前
|
||||
* @param minutes (骑行总分钟
|
||||
* @param userOrders 订单信息
|
||||
*
|
||||
* @param totalAmount 当前金额(时间段计费前
|
||||
* @param minutes (骑行总分钟
|
||||
* @param userOrders 订单信息
|
||||
* @param feignEbikeSysRcostsetDto 计费规则
|
||||
* @return 计费后总金额
|
||||
*/
|
||||
BigDecimal timeSlotCostCalculation(BigDecimal totalAmount,long minutes,UserOrders userOrders,ResFeignEbikeSysRcostsetDto feignEbikeSysRcostsetDto){
|
||||
BigDecimal timeSlotCostCalculation(BigDecimal totalAmount, long minutes, UserOrders userOrders, ResFeignEbikeSysRcostsetDto feignEbikeSysRcostsetDto) {
|
||||
return totalAmount;
|
||||
}
|
||||
|
||||
/**
|
||||
* 按照时间段计费
|
||||
* @param totalAmount 当前金额(时间段计费前
|
||||
* @param minutes (骑行总分钟
|
||||
* @param userOrders 订单信息
|
||||
*
|
||||
* @param totalAmount 当前金额(时间段计费前
|
||||
* @param minutes (骑行总分钟
|
||||
* @param userOrders 订单信息
|
||||
* @param feignEbikeSysRcostsetDto 计费规则
|
||||
* @return 计费后总金额
|
||||
*/
|
||||
BigDecimal weekCostCalculation(BigDecimal totalAmount,long minutes,UserOrders userOrders,ResFeignEbikeSysRcostsetDto feignEbikeSysRcostsetDto){
|
||||
BigDecimal weekCostCalculation(BigDecimal totalAmount, long minutes, UserOrders userOrders, ResFeignEbikeSysRcostsetDto feignEbikeSysRcostsetDto) {
|
||||
return totalAmount;
|
||||
}
|
||||
|
||||
/**
|
||||
* 按照时间段计费(默认
|
||||
* @param totalAmount 当前金额(时间段计费前
|
||||
* @param minutes (骑行总分钟
|
||||
*
|
||||
* @param totalAmount 当前金额(时间段计费前
|
||||
* @param minutes (骑行总分钟
|
||||
* @param feignEbikeSysRcostsetDto 计费规则
|
||||
* @return 计费后总金额
|
||||
*/
|
||||
BigDecimal defaultCostCalculation(BigDecimal totalAmount,long minutes,ResFeignEbikeSysRcostsetDto feignEbikeSysRcostsetDto){
|
||||
BigDecimal defaultCostCalculation(BigDecimal totalAmount, long minutes, ResFeignEbikeSysRcostsetDto feignEbikeSysRcostsetDto) {
|
||||
Integer startupDuration = feignEbikeSysRcostsetDto.getStartupDuration();
|
||||
BigDecimal startupCost = feignEbikeSysRcostsetDto.getStartupCost();
|
||||
totalAmount = totalAmount.add(startupCost);
|
||||
//超出起步时长计费
|
||||
if (minutes > startupDuration){
|
||||
if (minutes > startupDuration) {
|
||||
BigDecimal minutesNew = BigDecimal.valueOf(minutes);
|
||||
BigDecimal startupDurationNew = BigDecimal.valueOf(startupDuration);
|
||||
//超出时长
|
||||
|
||||
Loading…
x
Reference in New Issue
Block a user