手动结束订单
This commit is contained in:
@ -152,7 +152,11 @@ public class ZcOrderMainController extends BaseController
|
||||
@ResponseBody
|
||||
public AjaxResult manualEndOrder(Long orderId)
|
||||
{
|
||||
return toAjax(zcOrderMainService.updateManualEndOrder(orderId));
|
||||
int flag = zcOrderMainService.updateManualEndOrder(orderId);
|
||||
if(flag > 0) {
|
||||
|
||||
}
|
||||
return toAjax(flag);
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
@ -0,0 +1,36 @@
|
||||
package com.ruoyi.orders.dto;
|
||||
|
||||
import java.math.BigDecimal;
|
||||
|
||||
public class StoreOrderStats {
|
||||
/** 门店名称 */
|
||||
private String storeName;
|
||||
|
||||
/** 订单金额 */
|
||||
private BigDecimal orderAmount;
|
||||
|
||||
// 构造函数
|
||||
public StoreOrderStats() {}
|
||||
|
||||
public StoreOrderStats(String storeName, BigDecimal orderAmount) {
|
||||
this.storeName = storeName;
|
||||
this.orderAmount = orderAmount;
|
||||
}
|
||||
|
||||
// Getter 和 Setter 方法
|
||||
public String getStoreName() {
|
||||
return storeName;
|
||||
}
|
||||
|
||||
public void setStoreName(String storeName) {
|
||||
this.storeName = storeName;
|
||||
}
|
||||
|
||||
public BigDecimal getOrderAmount() {
|
||||
return orderAmount;
|
||||
}
|
||||
|
||||
public void setOrderAmount(BigDecimal orderAmount) {
|
||||
this.orderAmount = orderAmount;
|
||||
}
|
||||
}
|
||||
@ -3,6 +3,8 @@ package com.ruoyi.orders.mapper;
|
||||
import java.util.List;
|
||||
import com.ruoyi.orders.domain.ZcOrderMain;
|
||||
import com.ruoyi.orders.domain.ZcOrderSub;
|
||||
import com.ruoyi.orders.dto.StoreOrderStats;
|
||||
import org.apache.ibatis.annotations.Param;
|
||||
|
||||
/**
|
||||
* 租车订单Mapper接口
|
||||
@ -91,4 +93,12 @@ public interface ZcOrderMainMapper
|
||||
* @return 结果
|
||||
*/
|
||||
public int deleteZcOrderSubByOrderId(Long orderId);
|
||||
|
||||
/**
|
||||
* 查询门店订单统计排名(前N条)
|
||||
*
|
||||
* @param limit 前N条记录
|
||||
* @return 门店订单统计列表
|
||||
*/
|
||||
List<StoreOrderStats> selectTopStoreOrderStats(@Param("limit") int limit);
|
||||
}
|
||||
|
||||
@ -2,6 +2,7 @@ package com.ruoyi.orders.service;
|
||||
|
||||
import java.util.List;
|
||||
import com.ruoyi.orders.domain.ZcOrderMain;
|
||||
import com.ruoyi.orders.dto.StoreOrderStats;
|
||||
|
||||
/**
|
||||
* 租车订单Service接口
|
||||
@ -63,4 +64,12 @@ public interface IZcOrderMainService
|
||||
|
||||
public int updateManualEndOrder(Long orderId);
|
||||
|
||||
/**
|
||||
* 获取门店订单统计排名(前N条)
|
||||
*
|
||||
* @param limit 前N条记录
|
||||
* @return 门店订单统计列表
|
||||
*/
|
||||
List<StoreOrderStats> getTopStoreOrderStats(int limit);
|
||||
|
||||
}
|
||||
|
||||
@ -10,6 +10,7 @@ import com.ruoyi.operation.domain.ZcCar;
|
||||
import com.ruoyi.operation.service.IZcCarService;
|
||||
import com.ruoyi.operation.util.CarStatusEnum;
|
||||
import com.ruoyi.orders.dto.RefundRequest;
|
||||
import com.ruoyi.orders.dto.StoreOrderStats;
|
||||
import com.ruoyi.orders.service.IZcOrderSubService;
|
||||
import com.ruoyi.orders.util.OrderStatusEnum;
|
||||
import com.ruoyi.orders.util.OrderUtil;
|
||||
@ -18,6 +19,7 @@ import org.springframework.http.HttpHeaders;
|
||||
import org.springframework.http.HttpStatus;
|
||||
import org.springframework.http.MediaType;
|
||||
import org.springframework.http.ResponseEntity;
|
||||
import org.springframework.transaction.annotation.Propagation;
|
||||
import org.springframework.web.client.RestTemplate;
|
||||
import org.slf4j.Logger;
|
||||
import org.slf4j.LoggerFactory;
|
||||
@ -149,7 +151,7 @@ public class ZcOrderMainServiceImpl implements IZcOrderMainService
|
||||
zcOrderMainMapper.deleteZcOrderSubByOrderId(orderId);
|
||||
return zcOrderMainMapper.deleteZcOrderMainByOrderId(orderId);
|
||||
}
|
||||
@Transactional
|
||||
|
||||
@Override
|
||||
public int updateManualEndOrder(Long orderId) {
|
||||
// 1. 参数校验
|
||||
@ -172,33 +174,9 @@ public class ZcOrderMainServiceImpl implements IZcOrderMainService
|
||||
logger.error("退款处理失败,订单ID: {}", orderId);
|
||||
throw new RuntimeException("退款处理失败");
|
||||
}
|
||||
|
||||
// 4. 退款成功后,更新订单状态
|
||||
ZcOrderMain zcOrderMain = new ZcOrderMain();
|
||||
zcOrderMain.setOrderId(orderId);
|
||||
zcOrderMain.setOrderStatus(OrderStatusEnum.MANUAL_END.getCode());
|
||||
zcOrderMain.setUpdateBy(ShiroUtils.getSysUser().getLoginName());
|
||||
zcOrderMain.setUpdateTime(DateUtils.getNowDate());
|
||||
zcOrderMain.setEndOrderTime(DateUtils.getNowDate());
|
||||
|
||||
// 5. 计算逾期费用
|
||||
long overdueDays = DateUtils.daysBetween(queryOrder.getEndRentTime(), DateUtils.getNowDate());
|
||||
if (overdueDays > 0) {
|
||||
zcOrderMain.setOverdueDays(overdueDays);
|
||||
zcOrderMain.setOverdueAmount(queryOrder.getOverdueFee().multiply(new BigDecimal(overdueDays)));
|
||||
} else {
|
||||
zcOrderMain.setOverdueDays(0L);
|
||||
zcOrderMain.setOverdueAmount(BigDecimal.ZERO);
|
||||
}
|
||||
|
||||
// 6. 更新订单状态
|
||||
int flag = zcOrderMainMapper.updateZcOrderMain(zcOrderMain);
|
||||
if (flag <= 0) {
|
||||
logger.error("更新订单状态失败,订单ID: {}", orderId);
|
||||
throw new RuntimeException("更新订单状态失败");
|
||||
}
|
||||
|
||||
// 7. 释放车辆状态
|
||||
// 4. 退款成功后,更新订单状态 (计算逾期费用,更新订单状态)
|
||||
int flag = updateRefundZcOrderMain(orderId, queryOrder);
|
||||
// 5. 释放车辆状态
|
||||
ZcCar zcCar = new ZcCar();
|
||||
zcCar.setId(queryOrder.getVehicleId());
|
||||
zcCar.setStatus(CarStatusEnum.CAR_STATUS_0.getCode());
|
||||
@ -206,6 +184,7 @@ public class ZcOrderMainServiceImpl implements IZcOrderMainService
|
||||
|
||||
logger.info("手动结束订单处理完成,订单ID: {}", orderId);
|
||||
return flag;
|
||||
|
||||
} catch (Exception e) {
|
||||
logger.error("手动结束订单处理异常,订单ID: " + orderId, e);
|
||||
throw new RuntimeException("手动结束订单处理失败: " + e.getMessage(), e);
|
||||
@ -250,35 +229,80 @@ public class ZcOrderMainServiceImpl implements IZcOrderMainService
|
||||
refundSub.setRefundId(suborderNo);
|
||||
refundSub.setCreateTime(DateUtils.getNowDate());
|
||||
|
||||
// 调用退款接口并检查结果
|
||||
boolean bool = callRefundApi(querySub, suborderNo, refundAmount, queryOrder.getOperatorId());
|
||||
if(bool) {
|
||||
// 创建退款成功子订单
|
||||
zcOrderSubService.insertZcOrderSub(refundSub);
|
||||
}
|
||||
return bool;
|
||||
// // 调用退款接口并检查结果
|
||||
// boolean bool = callRefundApi(querySub, suborderNo, refundAmount, queryOrder.getOperatorId());
|
||||
// if(bool) {
|
||||
// // 创建退款成功子订单
|
||||
// zcOrderSubService.insertZcOrderSub(refundSub);
|
||||
// }
|
||||
// return bool;
|
||||
|
||||
// 在新事务中插入退款子订单
|
||||
insertRefundSubInNewTransaction(refundSub);
|
||||
|
||||
// 调用退款接口并检查结果(此时数据库中已有退款订单数据)
|
||||
return callRefundApi(refundSub, queryOrder.getOperatorId());
|
||||
|
||||
}
|
||||
return true; // 如果没有押金子订单,认为退款成功
|
||||
}
|
||||
/**
|
||||
* 在新事务中插入退款子订单
|
||||
* @param refundSub 退款子订单
|
||||
*/
|
||||
@Transactional(propagation = Propagation.REQUIRES_NEW)
|
||||
public void insertRefundSubInNewTransaction(ZcOrderSub refundSub) {
|
||||
zcOrderSubService.insertZcOrderSub(refundSub);
|
||||
}
|
||||
|
||||
@Transactional
|
||||
public int updateRefundZcOrderMain(Long orderId, ZcOrderMain queryOrder){
|
||||
// 4. 退款成功后,更新订单状态
|
||||
ZcOrderMain zcOrderMain = new ZcOrderMain();
|
||||
zcOrderMain.setOrderId(orderId);
|
||||
zcOrderMain.setOrderStatus(OrderStatusEnum.MANUAL_END.getCode());
|
||||
zcOrderMain.setUpdateBy(ShiroUtils.getSysUser().getLoginName());
|
||||
zcOrderMain.setUpdateTime(DateUtils.getNowDate());
|
||||
zcOrderMain.setEndOrderTime(DateUtils.getNowDate());
|
||||
|
||||
// 计算逾期费用
|
||||
long overdueDays = DateUtils.daysBetween(queryOrder.getEndRentTime(), DateUtils.getNowDate());
|
||||
if (overdueDays > 0) {
|
||||
zcOrderMain.setOverdueDays(overdueDays);
|
||||
zcOrderMain.setOverdueAmount(queryOrder.getOverdueFee().multiply(new BigDecimal(overdueDays)));
|
||||
} else {
|
||||
zcOrderMain.setOverdueDays(0L);
|
||||
zcOrderMain.setOverdueAmount(BigDecimal.ZERO);
|
||||
}
|
||||
|
||||
// 更新订单状态
|
||||
int flag = zcOrderMainMapper.updateZcOrderMain(zcOrderMain);
|
||||
if (flag <= 0) {
|
||||
logger.error("更新订单状态失败,订单ID: {}", orderId);
|
||||
throw new RuntimeException("更新订单状态失败");
|
||||
}
|
||||
logger.info("更新订单状态成功,订单ID: {}", orderId);
|
||||
return flag;
|
||||
|
||||
}
|
||||
|
||||
/**
|
||||
* 调用退款接口
|
||||
* @param querySub 原始押金子订单
|
||||
* @param refundNo 退款单号
|
||||
* @param refundAmount 退款金额
|
||||
* @param refundSub
|
||||
* @param operatorId 运营商ID
|
||||
* @return 退款是否成功
|
||||
*/
|
||||
private boolean callRefundApi(ZcOrderSub querySub, String refundNo, BigDecimal refundAmount, Long operatorId) {
|
||||
private boolean callRefundApi(ZcOrderSub refundSub, Long operatorId) {
|
||||
String refundNo = refundSub.getRefundId();
|
||||
try {
|
||||
// 准备退款请求参数
|
||||
RefundRequest refundRequest = new RefundRequest();
|
||||
refundRequest.setCompanyId(operatorId);// 运营商id
|
||||
refundRequest.setOutTradeNo(querySub.getPaymentId()); // 子订单押金payment_id
|
||||
refundRequest.setOutTradeNo(refundSub.getPaymentId()); // 原始押金子订单payment_id
|
||||
refundRequest.setOutRefundNo(refundNo);// 退款子订单编号
|
||||
refundRequest.setRefundDesc("手动结束订单退款");// 退款描述
|
||||
refundRequest.setTotalFee(new BigDecimal(0));
|
||||
refundRequest.setRefundFee(refundAmount); // 退款金额
|
||||
refundRequest.setRefundFee(refundSub.getAmount().multiply(new BigDecimal(100))); // 退款金额 分
|
||||
|
||||
// 发送HTTP请求调用退款接口
|
||||
HttpHeaders headers = new HttpHeaders();
|
||||
@ -349,4 +373,17 @@ public class ZcOrderMainServiceImpl implements IZcOrderMainService
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* 获取门店订单统计排名(前N条)
|
||||
*
|
||||
* @param limit 前N条记录
|
||||
* @return 门店订单统计列表
|
||||
*/
|
||||
@Override
|
||||
public List<StoreOrderStats> getTopStoreOrderStats(int limit) {
|
||||
return zcOrderMainMapper.selectTopStoreOrderStats(limit);
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
@ -6,6 +6,8 @@ import javax.servlet.http.Cookie;
|
||||
import javax.servlet.http.HttpServletResponse;
|
||||
|
||||
import com.ruoyi.common.utils.*;
|
||||
import com.ruoyi.orders.dto.StoreOrderStats;
|
||||
import com.ruoyi.orders.service.IZcOrderMainService;
|
||||
import com.ruoyi.system.domain.SysNotice;
|
||||
import com.ruoyi.system.service.ISysNoticeService;
|
||||
import com.ruoyi.system.service.ISysUserOnlineService;
|
||||
@ -48,6 +50,8 @@ public class SysIndexController extends BaseController
|
||||
private ISysUserOnlineService sysUserOnlineService;
|
||||
@Autowired
|
||||
private ISysNoticeService noticeService;
|
||||
@Autowired
|
||||
private IZcOrderMainService zcOrderMainService;
|
||||
|
||||
// 系统首页
|
||||
@GetMapping("/index")
|
||||
@ -146,6 +150,10 @@ public class SysIndexController extends BaseController
|
||||
// HomeStatisticsVo homeStatisticsVo = idWarningMemberService.selectHomeStatistics();
|
||||
// mmap.put("homeStatisticsVo", homeStatisticsVo);
|
||||
|
||||
// 获取门店订单统计数据
|
||||
List<StoreOrderStats> storeOrderStats = zcOrderMainService.getTopStoreOrderStats(9);
|
||||
mmap.put("storeOrderStats", storeOrderStats);
|
||||
|
||||
List<SysNotice> sysNotices = noticeService.selectHomeNoticeList();
|
||||
mmap.put("sysNotices", sysNotices);
|
||||
|
||||
|
||||
Reference in New Issue
Block a user