代码补正

This commit is contained in:
xiao-fajia 2024-08-27 11:11:40 +08:00
parent 4db15761f0
commit e1dcb45e0b

View File

@ -22,12 +22,12 @@ import org.springframework.stereotype.Service;
import javax.annotation.Resource;
import java.nio.charset.StandardCharsets;
import java.util.Date;
import java.util.HashMap;
import java.util.List;
import java.util.Map;
import java.util.*;
import java.util.concurrent.locks.ReentrantLock;
import java.util.stream.Collectors;
import static cn.iocoder.yudao.framework.common.exception.util.ServiceExceptionUtil.exception;
import static cn.iocoder.yudao.framework.common.exception.util.ServiceExceptionUtil.exception0;
import static cn.iocoder.yudao.module.rescue.service.impl.RescueDriverInfoServiceImpl.getRandomString6;
@ -158,7 +158,7 @@ public class RescueOrderInfoServiceImpl extends ServiceImpl<RescueOrderInfoMappe
// }
// }
//待支付的情况下进行主动查询
orderInfo.setOrderNo("appJy" + "-" + System.currentTimeMillis() + "-" + getRandomString6());
orderInfo.setOrderNo("appJy" + "-" + System.currentTimeMillis() + "-" + getRandomString6() + "-" + rescueInfo.getId());
this.updateById(orderInfo);
RescueOrderDetail rescueOrderDetail =new RescueOrderDetail();
rescueOrderDetail.setRecordTime(new Date());
@ -178,6 +178,30 @@ public class RescueOrderInfoServiceImpl extends ServiceImpl<RescueOrderInfoMappe
return one;
}
/**
* 通过rescue_info_id去拿订单
* @author 小李
* @date 10:56 2024/8/27
* @param rescueInfoId
**/
private RescueOrderInfo getOrderByRescueInfoId(Integer rescueInfoId){
/*
不确定是否会出现多条记录的情况所以用创建订单时的时间降序去取最新的一条
*/
List<RescueOrderInfo> list = this.list(new LambdaQueryWrapper<RescueOrderInfo>().eq(RescueOrderInfo::getRescueInfoId, rescueInfoId));
// 没查到直接抛异常理论上讲是不会抛的但以防万一抛了好过直接报错
if (ObjectUtils.isEmpty(list) || CollectionUtil.isEmpty(list)){
throw exception0(500, "系统故障");
}
// 如果只有一条就用这一条
if (list.size() == 1){
return list.get(0);
}
// 多条就创建时间降序排序取第一条
List<RescueOrderInfo> result = list.stream().sorted(Comparator.comparing(RescueOrderInfo::getCreateTime).reversed()).collect(Collectors.toList());
return result.get(0);
}
public Map<String,Object> transactions(Long orderId){
RescueOrderInfo orderInfo = this.getById(orderId);
@ -216,9 +240,10 @@ public class RescueOrderInfoServiceImpl extends ServiceImpl<RescueOrderInfoMappe
JSONObject decryptDataObj = JSONObject.parseObject(decryptData, JSONObject.class);
if(lock.tryLock()) {
try {
// 解密resource中的通知数据
// 解密resource中的通知数据 TODO
String orderNo = decryptDataObj.get("out_trade_no").toString();
RescueOrderInfo orderInfo = this.getOrderByOrderNo(orderNo);
String rescueInfoId = orderNo.split("-")[orderNo.split("-").length - 1];
RescueOrderInfo orderInfo = getOrderByRescueInfoId(Integer.parseInt(rescueInfoId));
if (orderInfo.getOrderStatus().equals("1")){
RescueInfo rescueInfo = rescueInfoService.getById(orderInfo.getRescueInfoId());
DriverInfo driverInfo = driverInfoService.getById(rescueInfo.getDriverId());