Merge branch 'master' of https://git.evo-techina.com/hbyt/cloud-battery-manage
This commit is contained in:
commit
8efa1b2293
@ -98,7 +98,6 @@ public class OrderSwapBattery implements Serializable {
|
||||
private BigDecimal serviceFee;
|
||||
|
||||
@Schema(description = "费用标准")
|
||||
private List<BatteryStationHdFeeStandard> feeStandard; @Schema(description = "费用标准")
|
||||
private String feeStandardJson;
|
||||
|
||||
@Schema(description = "上次租赁电池时车辆里程")
|
||||
|
||||
@ -40,7 +40,7 @@ public class WalletAccount implements Serializable {
|
||||
private String ownerId;
|
||||
|
||||
@Schema(description = "名称")
|
||||
private String name;
|
||||
private String accName;
|
||||
|
||||
@Schema(description = "编码", hidden = true)
|
||||
private String code;
|
||||
|
||||
@ -0,0 +1,19 @@
|
||||
package com.evotech.hd.common.core.entity.cloud.request;
|
||||
|
||||
import io.swagger.v3.oas.annotations.media.Schema;
|
||||
import lombok.Data;
|
||||
|
||||
@Data
|
||||
@Schema(name = "开始换电接收参数")
|
||||
public class BatterySwapResponse {
|
||||
|
||||
@Schema(description = "消息")
|
||||
private String msg;
|
||||
|
||||
@Schema(description = "订单编号")
|
||||
private String orderNo;
|
||||
|
||||
@Schema(description = "状态码:0-失败,1-成功")
|
||||
private Integer code;
|
||||
|
||||
}
|
||||
@ -3,8 +3,6 @@ package com.evotech.hd.cloud.controller;
|
||||
import java.util.List;
|
||||
import java.util.Map;
|
||||
|
||||
import com.evotech.hd.cloud.entity.request.BatterySwapRequest;
|
||||
import com.evotech.hd.cloud.entity.request.BatterySwapResponse;
|
||||
import com.evotech.hd.cloud.mqtt.message.handle.RequestMessageService;
|
||||
import org.springdoc.core.annotations.ParameterObject;
|
||||
import org.springframework.web.bind.annotation.GetMapping;
|
||||
|
||||
@ -2,8 +2,7 @@ package com.evotech.hd.cloud.controller.order;
|
||||
|
||||
import java.util.List;
|
||||
|
||||
import com.evotech.hd.cloud.entity.request.BatterySwapRequest;
|
||||
import com.evotech.hd.cloud.entity.request.BatterySwapResponse;
|
||||
import com.evotech.hd.common.core.entity.cloud.request.BatterySwapResponse;
|
||||
import org.springdoc.core.annotations.ParameterObject;
|
||||
import org.springframework.web.bind.annotation.GetMapping;
|
||||
import org.springframework.web.bind.annotation.PostMapping;
|
||||
@ -154,17 +153,16 @@ public class OrderSwapBatteryController {
|
||||
return orderSwapBatteryService.cancelOrder(orderNo, null);
|
||||
}
|
||||
@Operation(summary = "开始换电")
|
||||
@GetMapping("/start")
|
||||
@ApiOperationSupport(order = 8)
|
||||
public Result<BatterySwapResponse> startSwap(@ParameterObject BatterySwapRequest battyreq ) {
|
||||
// 创建换电请求对象
|
||||
orderSwapBatteryService.startSwap(battyreq);
|
||||
// 通过 MQTT 发送开始换电的消息
|
||||
|
||||
//pro.request();
|
||||
|
||||
// 等待换电站的回复
|
||||
return null;
|
||||
@PostMapping("/startSwap")
|
||||
@ApiOperationSupport(order = 16)
|
||||
public Result<Boolean> startSwap(@RequestParam String wuid,String orderId) {
|
||||
return orderSwapBatteryService.startSwap(wuid,orderId);
|
||||
}
|
||||
@Operation(summary = "获取开始换电回复")
|
||||
@PostMapping("/getStartSwap")
|
||||
@ApiOperationSupport(order = 17)
|
||||
public Result<BatterySwapResponse> getStartSwap(@RequestParam String wuid, String orderId) {
|
||||
return orderSwapBatteryService.getStartSwap(wuid,orderId);
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
@ -88,5 +88,11 @@ public class WalletAccountController {
|
||||
public Result<Boolean> isOpenAccount(String wuid) {
|
||||
return walletAccountService.isOpenAccount(wuid);
|
||||
}
|
||||
@Operation(summary = "获取WalleCode")
|
||||
@PostMapping("/getWalleCode")
|
||||
@ApiOperationSupport(order = 8)
|
||||
public Result<String> getWalleCode(String wuid) {
|
||||
return walletAccountService.getWalleCode(wuid);
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
@ -1,9 +0,0 @@
|
||||
package com.evotech.hd.cloud.entity.request;
|
||||
|
||||
import lombok.Data;
|
||||
|
||||
@Data
|
||||
public class BatterySwapRequest {
|
||||
private String userId; // 用户ID
|
||||
private String plateNum; // 车牌号
|
||||
}
|
||||
@ -1,13 +0,0 @@
|
||||
package com.evotech.hd.cloud.entity.request;
|
||||
|
||||
import io.swagger.v3.oas.annotations.media.Schema;
|
||||
import lombok.Data;
|
||||
|
||||
@Data
|
||||
@Schema(name = "开始换电接收参数")
|
||||
public class BatterySwapResponse {
|
||||
|
||||
private boolean success; // 是否成功
|
||||
|
||||
private String errorMessage; // 错误信息(如果有)
|
||||
}
|
||||
@ -29,8 +29,9 @@ public enum RequestFunctionTypesEnum {
|
||||
FUN_BATTERYINFO("batteryInfo", "batteryInfoResponse", "站端请求电池数据"),
|
||||
FUN_PREORDER("preOrder", "preOrderResponse", "站端预约订单"),
|
||||
FUN_ORDERBYPLATENUM("orderByPlateNum", "orderByPlateNumResponse", "站端用车牌号查询订单"),
|
||||
FUN_CANCELORDER("cancelOrder", "cancelOrderResponse", "站端取消订单");
|
||||
|
||||
FUN_CANCELORDER("cancelOrder", "cancelOrderResponse", "站端取消订单"),
|
||||
FUN_STARTSWAP("BatterySwapReq", "BatterySwapResponse", "站端回复开始换电");
|
||||
|
||||
String function;
|
||||
String reFunction;
|
||||
String functionName;
|
||||
|
||||
@ -0,0 +1,14 @@
|
||||
package com.evotech.hd.cloud.mqtt.message.dto.newer.req.battery;
|
||||
|
||||
import io.swagger.v3.oas.annotations.media.Schema;
|
||||
import lombok.Data;
|
||||
|
||||
@Data
|
||||
@Schema(name = "发送到站端的开始换电请求参数")
|
||||
public class BatterySwapReq {
|
||||
@Schema(description = "订单编号")
|
||||
private String orderNo;
|
||||
@Schema(description = "消息")
|
||||
private String msg;
|
||||
|
||||
}
|
||||
@ -3,16 +3,17 @@ package com.evotech.hd.cloud.mqtt.message.handle;
|
||||
import java.util.ArrayList;
|
||||
import java.util.Date;
|
||||
import java.util.List;
|
||||
import java.util.Objects;
|
||||
import java.util.stream.Stream;
|
||||
|
||||
import cn.hutool.core.util.ObjectUtil;
|
||||
import cn.hutool.core.util.StrUtil;
|
||||
import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper;
|
||||
import com.evotech.hd.common.core.entity.cloud.request.BatterySwapResponse;
|
||||
import com.evotech.hd.cloud.mqtt.message.dto.newer.req.battery.*;
|
||||
import com.evotech.hd.cloud.mqtt.message.dto.newer.req.order.*;
|
||||
import com.evotech.hd.cloud.service.WechatUserService;
|
||||
import com.evotech.hd.common.core.dao.wechat.WechatUserDao;
|
||||
import com.evotech.hd.common.core.entity.Result;
|
||||
import com.evotech.hd.common.core.entity.wechat.WechatUser;
|
||||
import com.evotech.hd.common.redis.utils.RedisUtil;
|
||||
import lombok.extern.slf4j.Slf4j;
|
||||
import org.springframework.beans.BeanUtils;
|
||||
import org.springframework.scheduling.annotation.Async;
|
||||
@ -28,9 +29,6 @@ import com.evotech.hd.cloud.mqtt.enums.MqttMessageTypeEnum;
|
||||
import com.evotech.hd.cloud.mqtt.enums.RequestFunctionTypesEnum;
|
||||
import com.evotech.hd.cloud.mqtt.message.MessageTopic;
|
||||
import com.evotech.hd.cloud.mqtt.message.MqttMessageHeader;
|
||||
import com.evotech.hd.cloud.mqtt.message.dto.newer.req.battery.BatteryData;
|
||||
import com.evotech.hd.cloud.mqtt.message.dto.newer.req.battery.BatteryInfoReq;
|
||||
import com.evotech.hd.cloud.mqtt.message.dto.newer.req.battery.BatteryInfoResponse;
|
||||
import com.evotech.hd.cloud.mqtt.message.dto.newer.req.carinfo.CarInfoReq;
|
||||
import com.evotech.hd.cloud.mqtt.message.dto.newer.req.carinfo.CarInfoResponse;
|
||||
import com.evotech.hd.cloud.mqtt.message.dto.newer.req.carinfo.VehicleData;
|
||||
@ -69,10 +67,11 @@ public class RequestMessageService {
|
||||
private OrderSwapBatteryPreDao orderSwapBatteryPreDao;
|
||||
@Resource
|
||||
private OrderSwapBatteryService orderSwapBatteryService;
|
||||
|
||||
@Resource
|
||||
private RedisUtil redisUtil;
|
||||
@Async("taskExecutor")
|
||||
public void request(MessageTopic topic, MqttMessageHeader header, JSONObject dataBody) {
|
||||
switch (RequestFunctionTypesEnum.getFunctionType(header.getFunction())) {
|
||||
switch (Objects.requireNonNull(RequestFunctionTypesEnum.getFunctionType(header.getFunction()))) {
|
||||
case FUN_CARINFO:
|
||||
CarInfoReq carInfoReq = JSONUtil.toBean(dataBody, CarInfoReq.class);
|
||||
handleCarInfo(topic, header, carInfoReq);
|
||||
@ -93,12 +92,39 @@ public class RequestMessageService {
|
||||
CancelOrderReq cancelOrder = JSONUtil.toBean(dataBody, CancelOrderReq.class);
|
||||
handlOrderCancel(topic,header,cancelOrder);
|
||||
break;
|
||||
case FUN_STARTSWAP:
|
||||
BatterySwapResponse battery = JSONUtil.toBean(dataBody, BatterySwapResponse.class);
|
||||
handlStartSwap(topic,header,battery);
|
||||
break;
|
||||
|
||||
default:
|
||||
break;
|
||||
}
|
||||
|
||||
}
|
||||
/**
|
||||
* 站端回复开始换电
|
||||
* @param topic
|
||||
* @param header
|
||||
* @param battery
|
||||
*/
|
||||
private void handlStartSwap(MessageTopic topic, MqttMessageHeader header, BatterySwapResponse battery) {
|
||||
// 校验 battery.getOrderId() 是否有效
|
||||
String orderNo = battery.getOrderNo();
|
||||
if (orderNo == null || orderNo.isEmpty()) {
|
||||
log.error("电池订单编码无效: battery={}", battery);
|
||||
throw new IllegalArgumentException("电池订单orderNo无效");
|
||||
}
|
||||
// 定义 Redis 过期时间(5分钟)
|
||||
final int REDIS_EXPIRE_TIME_IN_SECONDS = 60 * 5; // 5分钟
|
||||
// Redis 键值
|
||||
String redisKey = "battery:" + orderNo;
|
||||
// 将响应存到 Redis 里
|
||||
redisUtil.set(redisKey, battery, REDIS_EXPIRE_TIME_IN_SECONDS);
|
||||
// 记录成功日志
|
||||
log.info("换电响应已成功存储到 Redis: key={}", redisKey);
|
||||
}
|
||||
|
||||
/**
|
||||
* 站端取消订单
|
||||
* @param topic
|
||||
|
||||
@ -5,6 +5,9 @@ import java.util.Objects;
|
||||
|
||||
import cn.hutool.core.date.DatePattern;
|
||||
import cn.hutool.json.JSONConfig;
|
||||
import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper;
|
||||
import com.evotech.hd.cloud.service.OrderSwapBatteryService;
|
||||
import com.evotech.hd.common.core.entity.Result;
|
||||
import org.springframework.beans.BeanUtils;
|
||||
import org.springframework.scheduling.annotation.Async;
|
||||
import org.springframework.stereotype.Service;
|
||||
@ -58,7 +61,8 @@ public class StateMessageService {
|
||||
private VehicleInfoDao vehicleInfoDao;
|
||||
@Resource
|
||||
private BatteryStationDcDao batteryStationDcDao;
|
||||
|
||||
@Resource
|
||||
private OrderSwapBatteryService orderSwapBatteryService;
|
||||
@Async("taskExecutor")
|
||||
public void state(MessageTopic topic, MqttMessageHeader header, JSONObject dataBody) {
|
||||
switch (Objects.requireNonNull(StateFunctionTypesEnum.getFunctionType(header.getFunction()))) {
|
||||
@ -95,7 +99,6 @@ public class StateMessageService {
|
||||
|
||||
/**
|
||||
* 订单状态更新处理
|
||||
*
|
||||
* @param orderStatus
|
||||
* @param statusData
|
||||
*/
|
||||
@ -154,8 +157,16 @@ public class StateMessageService {
|
||||
BatteryStationDc dc = new BatteryStationDc();
|
||||
dc.setStatus(3);
|
||||
dc.setSoc(statusData.getSoc());
|
||||
batteryStationDcDao.update(dc,
|
||||
new QueryWrapper<BatteryStationDc>().eq("bat_code", statusData.getBatCode()));
|
||||
//电量结算
|
||||
LambdaQueryWrapper<OrderSwapBattery> wrapper = new LambdaQueryWrapper<>();
|
||||
wrapper.eq(OrderSwapBattery::getOrderNo, orderStatus.getOrderNo());
|
||||
OrderSwapBattery orderSwapBattery = orderSwapBatteryDao.selectOne(wrapper);
|
||||
//计算费用方式
|
||||
if (orderSwapBattery.getFeeType()==3){
|
||||
log.info("\r\n=====>>>换电订单电量结算,订单号:{}",orderStatus.getOrderNo() );
|
||||
orderSwapBatteryService.calculateCost(orderStatus.getOrderNo());
|
||||
}
|
||||
batteryStationDcDao.update(dc, new QueryWrapper<BatteryStationDc>().eq("bat_code", statusData.getBatCode()));
|
||||
break;
|
||||
default:
|
||||
break;
|
||||
|
||||
@ -2,8 +2,7 @@ package com.evotech.hd.cloud.service;
|
||||
|
||||
import java.util.List;
|
||||
|
||||
import com.evotech.hd.cloud.entity.request.BatterySwapRequest;
|
||||
import com.evotech.hd.cloud.entity.request.BatterySwapResponse;
|
||||
import com.evotech.hd.common.core.entity.cloud.request.BatterySwapResponse;
|
||||
import com.evotech.hd.cloud.entity.vo.NativePayVO;
|
||||
import com.evotech.hd.common.core.entity.Result;
|
||||
import com.evotech.hd.common.core.entity.cloud.OrderSwapBattery;
|
||||
@ -47,5 +46,7 @@ public interface OrderSwapBatteryService {
|
||||
|
||||
public Result<Integer> markOrderAsExpired(Integer pkId);
|
||||
|
||||
public Result<BatterySwapResponse> startSwap(BatterySwapRequest battyreq);
|
||||
public Result<Boolean> startSwap(String wuid,String orderId);
|
||||
|
||||
public Result<BatterySwapResponse> getStartSwap(String wuid, String orderId);
|
||||
}
|
||||
|
||||
@ -24,4 +24,6 @@ public interface WalletAccountService {
|
||||
public Result<List<WalletAccountDetail>> listDetail(PageListWalletRequest plwr);
|
||||
|
||||
public Result<Boolean> isOpenAccount(String wuid);
|
||||
|
||||
public Result<String> getWalleCode(String wuid);
|
||||
}
|
||||
|
||||
@ -7,20 +7,29 @@ import java.util.Arrays;
|
||||
import java.util.Date;
|
||||
import java.util.List;
|
||||
|
||||
import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper;
|
||||
import com.evotech.hd.cloud.entity.request.BatterySwapRequest;
|
||||
import com.evotech.hd.cloud.entity.request.BatterySwapResponse;
|
||||
import cn.hutool.core.date.DatePattern;
|
||||
import cn.hutool.core.date.DateUtil;
|
||||
import cn.hutool.core.util.ObjectUtil;
|
||||
import cn.hutool.core.util.StrUtil;
|
||||
import cn.hutool.json.JSONConfig;
|
||||
import cn.hutool.json.JSONUtil;
|
||||
import com.evotech.hd.cloud.dao.*;
|
||||
import com.evotech.hd.common.core.entity.cloud.request.BatterySwapResponse;
|
||||
import com.evotech.hd.cloud.mqtt.message.dto.newer.req.battery.BatterySwapReq;
|
||||
import com.evotech.hd.cloud.mqtt.enums.MqttMessageTypeEnum;
|
||||
import com.evotech.hd.cloud.mqtt.enums.RequestFunctionTypesEnum;
|
||||
import com.evotech.hd.cloud.mqtt.message.MessageTopic;
|
||||
import com.evotech.hd.cloud.mqtt.message.MqttMessageHeader;
|
||||
import com.evotech.hd.cloud.mqtt.message.handle.MessageUtilService;
|
||||
import com.evotech.hd.common.core.entity.cloud.*;
|
||||
import com.evotech.hd.common.redis.utils.RedisUtil;
|
||||
import lombok.extern.slf4j.Slf4j;
|
||||
import org.springframework.stereotype.Service;
|
||||
import org.springframework.transaction.annotation.Transactional;
|
||||
import org.springframework.util.StringUtils;
|
||||
|
||||
import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
|
||||
import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
|
||||
import com.evotech.hd.cloud.dao.OrderSwapBatteryPreDao;
|
||||
import com.evotech.hd.cloud.dao.OrderSwapBatteryStepDao;
|
||||
import com.evotech.hd.cloud.dao.VehicleInfoDao;
|
||||
import com.evotech.hd.cloud.dao.WalletAccountDao;
|
||||
import com.evotech.hd.cloud.entity.vo.NativePayVO;
|
||||
import com.evotech.hd.cloud.service.OrderSwapBatteryService;
|
||||
import com.evotech.hd.cloud.service.TradeService;
|
||||
@ -31,13 +40,6 @@ import com.evotech.hd.cloud.utils.components.SwapOrderBasicFeeComponent;
|
||||
import com.evotech.hd.common.core.dao.cloud.OrderSwapBatteryDao;
|
||||
import com.evotech.hd.common.core.dao.wechat.WechatUserDao;
|
||||
import com.evotech.hd.common.core.entity.Result;
|
||||
import com.evotech.hd.common.core.entity.cloud.OrderSwapBattery;
|
||||
import com.evotech.hd.common.core.entity.cloud.OrderSwapBatteryPre;
|
||||
import com.evotech.hd.common.core.entity.cloud.OrderSwapBatteryStep;
|
||||
import com.evotech.hd.common.core.entity.cloud.TradeDetail;
|
||||
import com.evotech.hd.common.core.entity.cloud.VehicleInfo;
|
||||
import com.evotech.hd.common.core.entity.cloud.WalletAccount;
|
||||
import com.evotech.hd.common.core.entity.cloud.WalletAccountDetail;
|
||||
import com.evotech.hd.common.core.entity.cloud.request.PageListSwapOrderPreRequest;
|
||||
import com.evotech.hd.common.core.entity.cloud.request.PageListSwapOrderRequest;
|
||||
import com.evotech.hd.common.core.entity.wechat.WechatUser;
|
||||
@ -48,7 +50,7 @@ import com.evotech.hd.common.core.enums.TradeTypeEnums;
|
||||
import com.evotech.hd.common.core.utils.CommonUtil;
|
||||
|
||||
import jakarta.annotation.Resource;
|
||||
|
||||
@Slf4j
|
||||
@Service
|
||||
public class OrderSwapBatteryServiceImpl implements OrderSwapBatteryService {
|
||||
|
||||
@ -74,10 +76,12 @@ public class OrderSwapBatteryServiceImpl implements OrderSwapBatteryService {
|
||||
private TradeService tradeService;
|
||||
@Resource
|
||||
private WechatService wechatService;
|
||||
|
||||
@Resource
|
||||
private MessageUtilService messageUtilService;
|
||||
@Resource
|
||||
private RedisUtil redisUtil;
|
||||
|
||||
@Resource
|
||||
private BatteryStationDao batteryStationDao;
|
||||
@Override
|
||||
public Result<Integer> addPre(OrderSwapBatteryPre osbp) {
|
||||
// 1. 检查车辆
|
||||
@ -96,6 +100,26 @@ public class OrderSwapBatteryServiceImpl implements OrderSwapBatteryService {
|
||||
if (!b2) {
|
||||
return new Result<Integer>().error("用户认证信息不全!");
|
||||
}
|
||||
//判断换电站是否运营
|
||||
boolean b3 = batteryStationDao.exists(new QueryWrapper<BatteryStation>()
|
||||
.eq("code", osbp.getStationCode())
|
||||
.eq("status", 1));
|
||||
if (!b3){
|
||||
return new Result<Integer>().error("该换电站未运营!");
|
||||
}
|
||||
/* //判断预约时间是否在换电站开放时间范围内
|
||||
//示例 20210430
|
||||
String swapDay = osbp.getSwapDay();
|
||||
//预约时间段 6:00-20:00
|
||||
String swapDuration = osbp.getSwapDuration();
|
||||
boolean b4 = batteryStationDao.exists(new QueryWrapper<BatteryStation>()
|
||||
.eq("code", osbp.getStationCode())
|
||||
|
||||
|
||||
);
|
||||
if (!b4){
|
||||
return new Result<Integer>().error("该换电站开放时间范围!");
|
||||
}*/
|
||||
// 是否需要验证人和车绑定关系
|
||||
|
||||
// 是否需要验证公司和车的绑定关系
|
||||
@ -255,6 +279,7 @@ public class OrderSwapBatteryServiceImpl implements OrderSwapBatteryService {
|
||||
@Override
|
||||
public Result<String> calculateCost(String orderNo) {
|
||||
OrderSwapBattery order = orderSwapBatteryDao.selectOne(new QueryWrapper<OrderSwapBattery>().eq("order_no", orderNo));
|
||||
log.info("订单号:{}", JSONUtil.parseObj(order));
|
||||
if (order == null) {
|
||||
return new Result<String>().error("无此订单!");
|
||||
}
|
||||
@ -272,9 +297,9 @@ public class OrderSwapBatteryServiceImpl implements OrderSwapBatteryService {
|
||||
}
|
||||
// 3. 选择费用计算方式 计算费用
|
||||
if (order.getFeeType()==3){
|
||||
// 先按电量计算
|
||||
// 电量计算
|
||||
if (order.getElectAmount() == null) {
|
||||
return new Result<String>().error("充电订单 充电量 异常!");
|
||||
return new Result<String>().error("充电订单充电量异常!");
|
||||
}
|
||||
BigDecimal fee = order.getServiceFee().add(order.getBasicFee().multiply(order.getElectAmount())).setScale(0, RoundingMode.HALF_UP);
|
||||
// 4. 修改订单
|
||||
@ -453,20 +478,90 @@ public class OrderSwapBatteryServiceImpl implements OrderSwapBatteryService {
|
||||
}
|
||||
|
||||
@Override
|
||||
public Result<BatterySwapResponse> startSwap(BatterySwapRequest battyreq) {
|
||||
//获取用户wuid
|
||||
String wuid = battyreq.getUserId();
|
||||
LambdaQueryWrapper<OrderSwapBattery> wrapper = new LambdaQueryWrapper<>();
|
||||
wrapper.eq(OrderSwapBattery::getOrderPreUid,wuid)
|
||||
.eq(OrderSwapBattery::getPlateNum,battyreq.getPlateNum());
|
||||
OrderSwapBattery orderSwap = orderSwapBatteryDao.selectOne(wrapper);
|
||||
if (orderSwap!=null){
|
||||
//发送消息给站端
|
||||
|
||||
//
|
||||
|
||||
public Result<Boolean> startSwap(String wuid, String orderId) {
|
||||
if (StrUtil.isBlank(wuid) || StrUtil.isBlank(orderId)) {
|
||||
log.warn("换电请求参数无效, wuid: {}, orderId: {}", wuid, orderId);
|
||||
return new Result<Boolean>().error("换电请求参数无效");
|
||||
}
|
||||
|
||||
// 获取用户订单
|
||||
OrderSwapBattery orderSwap = orderSwapBatteryDao.selectById(orderId);
|
||||
if (orderSwap == null) {
|
||||
log.warn("未找到符合条件的订单, 用户ID: {}, 订单id: {}", wuid, orderId);
|
||||
return new Result<Boolean>().error("未找到符合条件的订单");
|
||||
}
|
||||
|
||||
try {
|
||||
log.info("开始处理换电请求, 订单编号: {}, 用户ID: {}", orderSwap.getOrderNo(), wuid);
|
||||
|
||||
// 构建换电请求消息
|
||||
BatterySwapReq batterySwapReq = new BatterySwapReq();
|
||||
batterySwapReq.setOrderNo(orderSwap.getOrderNo());
|
||||
batterySwapReq.setMsg("换电开始");
|
||||
|
||||
// 设置消息主题和头部信息
|
||||
MessageTopic topic = new MessageTopic();
|
||||
topic.setDataDirection("M2S");
|
||||
topic.setMessageType(MqttMessageTypeEnum.REQUEST.getType());
|
||||
|
||||
MqttMessageHeader header = new MqttMessageHeader();
|
||||
header.setFunction(RequestFunctionTypesEnum.FUN_STARTSWAP.getFunction());
|
||||
header.setTimeStamp(DateUtil.format(new Date(), DatePattern.NORM_DATETIME_FORMATTER));
|
||||
|
||||
// 发送消息给站端
|
||||
messageUtilService.publishAESMessage(topic, header,
|
||||
JSONUtil.parseObj(batterySwapReq, new JSONConfig().setDateFormat(DatePattern.NORM_DATETIME_PATTERN)));
|
||||
|
||||
log.info("换电开始消息发送成功, 订单编号: {}", orderSwap.getOrderNo());
|
||||
return new Result<Boolean>().success(true);
|
||||
|
||||
} catch (Exception e) {
|
||||
log.error("处理换电请求时发生异常, 订单编号: {}, 用户ID: {}", orderSwap.getOrderNo(), wuid, e);
|
||||
return new Result<Boolean>().error("系统处理换电请求时发生异常");
|
||||
}
|
||||
return null;
|
||||
}
|
||||
|
||||
@Override
|
||||
public Result<BatterySwapResponse> getStartSwap(String wuid, String orderId) {
|
||||
// 参数校验
|
||||
if (StrUtil.isBlank(wuid) || StrUtil.isBlank(orderId)) {
|
||||
log.warn("获取换电状态参数无效, wuid: {}, orderId: {}", wuid, orderId);
|
||||
return new Result<BatterySwapResponse>().error("参数无效");
|
||||
}
|
||||
|
||||
// 获取用户订单
|
||||
OrderSwapBattery orderSwap = orderSwapBatteryDao.selectById(orderId);
|
||||
if (orderSwap == null) {
|
||||
log.warn("未找到符合条件的订单, 用户ID: {}, 订单id: {}", wuid, orderId);
|
||||
return new Result<BatterySwapResponse>().error("未找到符合条件的订单");
|
||||
}
|
||||
|
||||
try {
|
||||
// 从 Redis 中获取换电信息
|
||||
String redisKey = "battery:" + orderSwap.getOrderNo();
|
||||
Object o = redisUtil.get(redisKey);
|
||||
if (ObjectUtil.isEmpty(o)) {
|
||||
log.info("未收到换电成功信息, 订单编号: {}", orderSwap.getOrderNo());
|
||||
return new Result<BatterySwapResponse>().error("未收到换电成功信息");
|
||||
}
|
||||
|
||||
// 将获取到的 JSON 字符串转换为 BatterySwapResponse 对象
|
||||
BatterySwapResponse response = JSONUtil.toBean(o.toString(), BatterySwapResponse.class);
|
||||
if (response == null) {
|
||||
log.error("换电响应数据解析失败, 订单编号: {}", orderSwap.getOrderNo());
|
||||
return new Result<BatterySwapResponse>().error("换电响应数据解析失败");
|
||||
}
|
||||
|
||||
if (response.getCode() == 1) {
|
||||
log.info("换电成功, 订单编号: {}", orderSwap.getOrderNo());
|
||||
return new Result<BatterySwapResponse>().success(response);
|
||||
} else {
|
||||
log.warn("换电失败, 订单编号: {}, 错误信息: {}", orderSwap.getOrderNo(), response.getMsg());
|
||||
return new Result<BatterySwapResponse>().error(response.getMsg());
|
||||
}
|
||||
} catch (Exception e) {
|
||||
log.error("获取换电状态时发生异常, 订单编号: {}", orderSwap.getOrderNo(), e);
|
||||
return new Result<BatterySwapResponse>().error("系统获取换电状态时发生异常");
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@ -3,6 +3,7 @@ package com.evotech.hd.cloud.service.impl;
|
||||
import java.util.Date;
|
||||
import java.util.List;
|
||||
|
||||
import cn.hutool.json.JSONUtil;
|
||||
import org.springframework.stereotype.Service;
|
||||
import org.springframework.transaction.annotation.Transactional;
|
||||
import org.springframework.util.StringUtils;
|
||||
@ -91,6 +92,7 @@ public class TradeServiceImpl implements TradeService {
|
||||
return new Result<String>().error("重复消息!");
|
||||
}
|
||||
// 添加交易
|
||||
log.info("请求时间{} 是否存在交易{} 添加交易>>>>>{}" ,new Date() ,b, JSONUtil.toJsonStr(tradeDetail));
|
||||
add(tradeDetail);
|
||||
// 2. 业务类型处理
|
||||
payNotifyHandleService.payNotifyBussinessHandle(tradeDetail);
|
||||
|
||||
@ -6,7 +6,9 @@ import java.util.List;
|
||||
import java.util.Map;
|
||||
|
||||
import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper;
|
||||
import com.evotech.hd.cloud.dao.CompanyDao;
|
||||
import com.evotech.hd.common.core.dao.wechat.WechatUserDao;
|
||||
import com.evotech.hd.common.core.entity.cloud.Company;
|
||||
import com.evotech.hd.common.core.entity.wechat.WechatUser;
|
||||
import org.springframework.stereotype.Service;
|
||||
import org.springframework.util.StringUtils;
|
||||
@ -25,31 +27,61 @@ import com.evotech.hd.common.core.utils.SnowflakeUtil;
|
||||
|
||||
import cn.hutool.core.util.RandomUtil;
|
||||
import jakarta.annotation.Resource;
|
||||
import cn.hutool.core.util.StrUtil;
|
||||
import org.slf4j.Logger;
|
||||
import org.slf4j.LoggerFactory;
|
||||
|
||||
|
||||
@Service
|
||||
public class WalletAccountServiceImpl implements WalletAccountService {
|
||||
|
||||
private static final Logger log = LoggerFactory.getLogger(WalletAccountServiceImpl.class);
|
||||
|
||||
@Resource
|
||||
private WalletAccountDao walletAccountDao;
|
||||
@Resource
|
||||
private WalletAccountDetailDao walletAccountDetailDao;
|
||||
@Resource
|
||||
private WechatUserDao wechatUserDao;
|
||||
@Resource
|
||||
private CompanyDao companyDao;
|
||||
|
||||
@Override
|
||||
public Result<Integer> add(WalletAccount wa) {
|
||||
//查询是否有相同的账户信息
|
||||
// 查询是否有相同的账户信息
|
||||
LambdaQueryWrapper<WalletAccount> queryWrapper = new LambdaQueryWrapper<>();
|
||||
queryWrapper.eq(WalletAccount::getOwnerId,wa.getOwnerId());
|
||||
queryWrapper.eq(WalletAccount::getOwnerId, wa.getOwnerId());
|
||||
WalletAccount walletAccount = walletAccountDao.selectOne(queryWrapper);
|
||||
|
||||
if (walletAccount != null) {
|
||||
return new Result<Integer>().error("该账户已存在,无法重复添加!");
|
||||
}
|
||||
LambdaQueryWrapper<WechatUser> eq = new LambdaQueryWrapper<>();
|
||||
eq.eq(WechatUser::getAppid,wa.getOwnerId());
|
||||
eq.eq(WechatUser::getWuid,wa.getOwnerId());
|
||||
WechatUser wechatUser = wechatUserDao.selectOne(eq);
|
||||
// 如果账户已存在,返回错误信息
|
||||
if (walletAccount != null) {
|
||||
return new Result<Integer>().error("该账户已存在,无法重复添加!");
|
||||
if (wa.getOwnerType()==1){
|
||||
if (wechatUser.getName() != null){
|
||||
//名称
|
||||
wa.setAccName(wechatUser.getName());
|
||||
}else {
|
||||
if (wechatUser.getNickName() != null){
|
||||
//昵称
|
||||
wa.setAccName(wechatUser.getNickName());
|
||||
}else {
|
||||
wa.setAccName(null);
|
||||
}
|
||||
}
|
||||
wa.setName(wechatUser.getName());
|
||||
}else {
|
||||
//查询是否有相同的账户信息
|
||||
QueryWrapper<Company> wrapper = new QueryWrapper<>();
|
||||
wrapper.eq("ccode",wa.getOwnerId());
|
||||
Company company = companyDao.selectOne(wrapper);
|
||||
if (company != null){
|
||||
wa.setAccName(company.getCname());
|
||||
}else {
|
||||
return new Result<Integer>().error("公司编码不存在!");
|
||||
}
|
||||
}
|
||||
wa.setCtime(new Date());
|
||||
String prefix = "YTWA" + (wa.getOwnerType() == 1 ? "P" : "C");
|
||||
wa.setCode(prefix + SnowflakeUtil.getIdStr() + RandomUtil.randomStringUpper(6));
|
||||
@ -75,6 +107,7 @@ public class WalletAccountServiceImpl implements WalletAccountService {
|
||||
@Override
|
||||
public Result<Integer> update(WalletAccount wa) {
|
||||
WalletAccount wa1 = new WalletAccount();
|
||||
wa1.setAccName(wa.getAccName());
|
||||
wa1.setGiftAmount(wa.getGiftAmount());
|
||||
wa1.setTotalAmount(wa.getTotalAmount());
|
||||
wa1.setRechargeAmount(wa.getRechargeAmount());
|
||||
@ -142,15 +175,40 @@ public class WalletAccountServiceImpl implements WalletAccountService {
|
||||
|
||||
@Override
|
||||
public Result<Boolean> isOpenAccount(String wuid) {
|
||||
LambdaQueryWrapper<WalletAccount> queryWrapper = new LambdaQueryWrapper<>();
|
||||
queryWrapper.eq(WalletAccount::getOwnerId,wuid);
|
||||
WalletAccount walletAccount = walletAccountDao.selectOne(queryWrapper);
|
||||
// 判断账户是否存在
|
||||
if (walletAccount != null) {
|
||||
return new Result<Boolean>().success(true); // 账户已开通
|
||||
} else {
|
||||
return new Result<Boolean>().success(false); // 账户未开通
|
||||
if (StrUtil.isBlank(wuid)) {
|
||||
return new Result<Boolean>().error("用户ID不能为空");
|
||||
}
|
||||
|
||||
try {
|
||||
LambdaQueryWrapper<WalletAccount> queryWrapper = new LambdaQueryWrapper<>();
|
||||
queryWrapper.eq(WalletAccount::getOwnerId, wuid);
|
||||
WalletAccount walletAccount = walletAccountDao.selectOne(queryWrapper);
|
||||
|
||||
return new Result<Boolean>().success(walletAccount != null);
|
||||
|
||||
} catch (Exception e) {
|
||||
log.error("查询用户钱包账户异常: wuid={}, error={}", wuid, e.getMessage(), e);
|
||||
return new Result<Boolean>().error("查询钱包账户异常");
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
public Result<String> getWalleCode(String wuid) {
|
||||
LambdaQueryWrapper<WalletAccount> queryWrapper = new LambdaQueryWrapper<>();
|
||||
queryWrapper.eq(WalletAccount::getOwnerId, wuid);
|
||||
WalletAccount walletAccount = walletAccountDao.selectOne(queryWrapper);
|
||||
if (walletAccount==null){
|
||||
WalletAccount walletAccount1 = new WalletAccount();
|
||||
walletAccount1.setOwnerId(wuid);
|
||||
walletAccount1.setOwnerType(1);
|
||||
if (add(walletAccount1).getCode()== CodeMsg.SUCCESS.getCode()){
|
||||
LambdaQueryWrapper<WalletAccount> queryWrapper1 = new LambdaQueryWrapper<>();
|
||||
queryWrapper1.eq(WalletAccount::getOwnerId, wuid);
|
||||
walletAccount = walletAccountDao.selectOne(queryWrapper1);
|
||||
|
||||
}
|
||||
}
|
||||
return new Result<String>().success("成功",(StringUtils.hasText(walletAccount.getAccName()) ? walletAccount.getAccName() : "")+"_"+walletAccount.getCode());
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
@ -21,30 +21,38 @@ import java.util.List;
|
||||
public class OrderSwapBatteryTask {
|
||||
@Resource
|
||||
private OrderSwapBatteryPreDao orderSwapBatteryPreDao;
|
||||
@Resource
|
||||
private RedisTemplate redisTemplate;
|
||||
@Scheduled(cron ="0 0 11,14,16,18,20 * * ?")
|
||||
|
||||
// @Scheduled(cron = "0 0 * * * ?") // 每小时执行一次
|
||||
public void orderSwapBatteryExpired() {
|
||||
log.info("\r\n===>>>开始查找预约单更新预约状态..");
|
||||
QueryWrapper<OrderSwapBatteryPre> eq = new QueryWrapper<>();
|
||||
eq.ne("status",4)
|
||||
.ne("status",3)
|
||||
.eq("del_flag",1);
|
||||
List<OrderSwapBatteryPre> orderSwapBatteryPreList = orderSwapBatteryPreDao.selectList(eq);
|
||||
log.info("\r\n===>>> 开始查找预约单更新预约状态..");
|
||||
|
||||
// 查询条件,排除已过期和无效状态
|
||||
QueryWrapper<OrderSwapBatteryPre> queryWrapper = new QueryWrapper<>();
|
||||
queryWrapper.ne("status", 4)//无效
|
||||
.ne("status", 3); //过期
|
||||
|
||||
List<OrderSwapBatteryPre> orderSwapBatteryPreList = orderSwapBatteryPreDao.selectList(queryWrapper);
|
||||
|
||||
// 获取当前时间
|
||||
Date currentTime = new Date();
|
||||
int expiredCount = 0; // 记录过期的预约单数量
|
||||
|
||||
for (OrderSwapBatteryPre order : orderSwapBatteryPreList) {
|
||||
// 检查预约时间是否已过期
|
||||
if (order.getReservationTime() != null && order.getReservationTime().before(currentTime)) {
|
||||
// 更新状态为过期(假设状态 5 表示过期)
|
||||
order.setStatus(3); // 设置为过期状态
|
||||
orderSwapBatteryPreDao.updateById(order); // 更新数据库
|
||||
expiredCount++;
|
||||
// 更新状态为过期
|
||||
order.setStatus(4); // 设置为过期状态
|
||||
try {
|
||||
orderSwapBatteryPreDao.updateById(order);
|
||||
expiredCount++;
|
||||
log.info("预约单已过期,订单ID: {}", order.getSourceId()); // 记录过期的订单ID
|
||||
} catch (Exception e) {
|
||||
log.error("更新预约单状态失败,预约人:{},订单ID: {}, 错误信息: {}",order.getUname(), order.getPkId(), e.getMessage());
|
||||
}
|
||||
}
|
||||
}
|
||||
log.info("\r\n===>>>预约单过期:{} 条数据", expiredCount);
|
||||
|
||||
log.info("\r\n===>>> 预约单过期:{} 条数据", expiredCount);
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
@ -5,6 +5,7 @@ import java.util.ArrayList;
|
||||
import java.util.List;
|
||||
|
||||
import cn.hutool.json.JSONUtil;
|
||||
import lombok.extern.slf4j.Slf4j;
|
||||
import org.springframework.stereotype.Component;
|
||||
|
||||
import com.evotech.hd.cloud.dao.BatteryStationHdFeeStandardDao;
|
||||
@ -16,6 +17,7 @@ import cn.hutool.core.date.DatePattern;
|
||||
import cn.hutool.core.date.DateUtil;
|
||||
import jakarta.annotation.Resource;
|
||||
|
||||
@Slf4j
|
||||
@Component
|
||||
public class SwapOrderBasicFeeComponent {
|
||||
|
||||
@ -32,6 +34,7 @@ public class SwapOrderBasicFeeComponent {
|
||||
public OrderSwapBattery orderBasicFee(OrderSwapBattery osb) {
|
||||
// 根据换电站编码和订单时间查询费用标准列表
|
||||
List<BatteryStationHdFeeStandard> list = batteryStationHdFeeStandardDao.listFeeStandard(osb.getStationCode(), DateUtil.format(osb.getOrderTime(), DatePattern.PURE_DATE_FORMATTER));
|
||||
log.info("换电站编码{}时间{}单费用计算参数========>:{}", DateUtil.format(osb.getOrderTime(), DatePattern.PURE_DATE_FORMATTER),osb.getStationCode(),JSONUtil.toJsonStr(osb));
|
||||
// 如果费用标准列表不为空,说明找到了相关的费用标准
|
||||
if (!list.isEmpty()) {
|
||||
// 获取第一个费用标准
|
||||
@ -48,25 +51,27 @@ public class SwapOrderBasicFeeComponent {
|
||||
// 如果过滤后的详细费用列表不为空,使用第一个有效的费用详情
|
||||
if (!detailList.isEmpty()) {
|
||||
BatteryStationHdFeeStandardDetail detail = detailList.get(0);
|
||||
log.info("当前时间在费用详情有效时间范围内=====>:{}", JSONUtil.toJsonStr(detail));
|
||||
// 设置基本费用和服务费用
|
||||
osb.setFeeStandardJson(JSONUtil.toJsonStr(detail));
|
||||
osb.setFeeStandard(battery);
|
||||
osb.setBasicFee(detail.getEachKwhFee());
|
||||
osb.setServiceFee(detail.getTimeServiceFee());
|
||||
} else {
|
||||
// 如果没有有效的详细费用,使用标准费用
|
||||
osb.setFeeStandard(battery);
|
||||
osb.setFeeStandardJson(JSONUtil.toJsonStr(standard));
|
||||
osb.setBasicFee(standard.getEachKwhFee());
|
||||
osb.setServiceFee(standard.getCommonRemainFee());
|
||||
}
|
||||
} else {
|
||||
osb.setFeeStandardJson(JSONUtil.toJsonStr(standard));
|
||||
// 如果没有详细费用,直接使用标准费用
|
||||
osb.setFeeStandard(battery);
|
||||
log.info("没有详细费用,直接使用标准费用=====>:{}", JSONUtil.toJsonStr(standard));
|
||||
osb.setBasicFee(standard.getEachKwhFee());
|
||||
osb.setServiceFee(standard.getCommonRemainFee());
|
||||
}
|
||||
}
|
||||
// 返回更新后的订单对象
|
||||
log.info("订单费用计算结果========>:{}", JSONUtil.toJsonStr(osb));
|
||||
return osb;
|
||||
}
|
||||
|
||||
|
||||
@ -2,6 +2,8 @@ package com.evotech.hd.wechat.controller;
|
||||
|
||||
import java.util.List;
|
||||
|
||||
|
||||
import com.evotech.hd.common.core.entity.cloud.request.BatterySwapResponse;
|
||||
import org.springdoc.core.annotations.ParameterObject;
|
||||
import org.springframework.web.bind.annotation.GetMapping;
|
||||
import org.springframework.web.bind.annotation.PostMapping;
|
||||
@ -78,10 +80,19 @@ public class SwapOrderController {
|
||||
public Result<String> walletPay(@RequestParam String orderNo, String wuid, String uname) {
|
||||
return orderService.walletPay(orderNo, wuid, uname);
|
||||
}
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
@Operation(summary = "开始换电")
|
||||
@PostMapping("/startSwap")
|
||||
@ApiOperationSupport(order = 16)
|
||||
public Result<Boolean> startSwap(@RequestParam String wuid,String orderId) throws Exception {
|
||||
return orderService.startSwap(wuid,orderId);
|
||||
}
|
||||
@Operation(summary = "获取开始换电回复")
|
||||
@PostMapping("/getStartSwap")
|
||||
@ApiOperationSupport(order = 17)
|
||||
public Result<BatterySwapResponse> getStartSwap(@RequestParam String wuid, String orderId) {
|
||||
return orderService.getStartSwap(wuid,orderId);
|
||||
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
@ -6,9 +6,11 @@ import com.evotech.hd.common.core.entity.Result;
|
||||
import com.evotech.hd.common.core.entity.cloud.OrderSwapBattery;
|
||||
import com.evotech.hd.common.core.entity.cloud.OrderSwapBatteryPre;
|
||||
import com.evotech.hd.common.core.entity.cloud.OrderSwapBatteryStep;
|
||||
import com.evotech.hd.common.core.entity.cloud.request.BatterySwapResponse;
|
||||
import com.evotech.hd.common.core.entity.cloud.request.PageListSwapOrderPreRequest;
|
||||
import com.evotech.hd.common.core.entity.cloud.request.PageListSwapOrderRequest;
|
||||
|
||||
|
||||
public interface OrderService {
|
||||
|
||||
public Result<Integer> addPre(OrderSwapBatteryPre osbp);
|
||||
@ -23,4 +25,7 @@ public interface OrderService {
|
||||
|
||||
public Result<String> walletPay(String orderNo, String wuid, String uname);
|
||||
|
||||
public Result<Boolean> startSwap(String wuid,String orderId) throws Exception;
|
||||
|
||||
public Result<BatterySwapResponse> getStartSwap(String wuid, String orderId );
|
||||
}
|
||||
|
||||
@ -3,6 +3,8 @@ package com.evotech.hd.wechat.service.impl;
|
||||
import java.util.List;
|
||||
import java.util.Optional;
|
||||
|
||||
|
||||
import com.evotech.hd.common.core.entity.cloud.request.BatterySwapResponse;
|
||||
import org.springframework.stereotype.Service;
|
||||
import org.springframework.util.StringUtils;
|
||||
|
||||
@ -18,6 +20,7 @@ import com.evotech.hd.wechat.service.rpc.CloudService;
|
||||
|
||||
import jakarta.annotation.Resource;
|
||||
import jakarta.servlet.http.HttpServletRequest;
|
||||
import org.springframework.web.bind.annotation.RequestParam;
|
||||
|
||||
|
||||
@Service
|
||||
@ -70,6 +73,16 @@ public class OrderServiceImpl implements OrderService {
|
||||
return cloudService.walletPay(orderNo, wuid, uname);
|
||||
}
|
||||
|
||||
|
||||
@Override
|
||||
public Result<Boolean> startSwap(String wuid ,String orderId ) throws Exception {
|
||||
if (!wuid.equals(request.getHeader(HDConstant.WECHAT_SERVER_AUTHORIZATION_KEY))) {
|
||||
throw new Exception("账号错误");
|
||||
}
|
||||
return cloudService.startSwap(wuid,orderId);
|
||||
}
|
||||
|
||||
@Override
|
||||
public Result<BatterySwapResponse> getStartSwap(String wuid, String orderId) {
|
||||
return cloudService.getStartSwap(wuid,orderId);
|
||||
}
|
||||
}
|
||||
|
||||
@ -4,6 +4,12 @@ import java.io.IOException;
|
||||
import java.util.Date;
|
||||
import java.util.List;
|
||||
|
||||
import ch.qos.logback.classic.spi.EventArgUtil;
|
||||
import cn.hutool.json.JSON;
|
||||
import com.evotech.hd.common.core.entity.cloud.WalletAccount;
|
||||
import com.evotech.hd.common.core.enums.CodeMsg;
|
||||
import com.evotech.hd.wechat.service.WechatUserService;
|
||||
import com.evotech.hd.wechat.service.rpc.CloudService;
|
||||
import org.springframework.beans.BeanUtils;
|
||||
import org.springframework.http.HttpStatus;
|
||||
import org.springframework.http.ResponseEntity;
|
||||
@ -73,8 +79,9 @@ public class WechatPayServiceImpl implements WechatPayService {
|
||||
private WechatPayPreOrderDao preOrderDao;
|
||||
@Resource
|
||||
private WechatPayComponent wechatPayComponent;
|
||||
|
||||
|
||||
@Resource
|
||||
private CloudService cloudService;
|
||||
|
||||
@Override
|
||||
public Result<String> xcxPrepay(PrePayVO prePay) {
|
||||
// 校验用户
|
||||
@ -82,6 +89,23 @@ public class WechatPayServiceImpl implements WechatPayService {
|
||||
if (wuser == null || !StringUtils.hasText(wuser.getOpenid())) {
|
||||
return new Result<String>().error("用户信息错误");
|
||||
}
|
||||
|
||||
//检查账户是否存在
|
||||
JSONObject entries = JSONUtil.parseObj(prePay.getAttach());
|
||||
log.info("PrePayVO==================> {}",JSONUtil.parseObj(prePay));
|
||||
if (!StringUtils.hasText(entries.getStr("walletCode"))) {
|
||||
Result<String> walleCode = cloudService.getWalleCode(prePay.getWuid());
|
||||
if (!walleCode.getCode().equals(CodeMsg.SUCCESS.getCode())) {
|
||||
return new Result<String>().error("钱包账户创建失败");
|
||||
}
|
||||
String[] split = String.valueOf(walleCode.getData()).split("_");
|
||||
if (!StringUtils.hasText(entries.getStr("trader"))) {
|
||||
prePay.setAttach(JSONUtil.toJsonStr(entries.set("trader", split[0])));
|
||||
}
|
||||
prePay.setAttach(JSONUtil.toJsonStr(entries.set("walletCode", split[1])));
|
||||
|
||||
}
|
||||
|
||||
WechatPayPreOrder preOrder = new WechatPayPreOrder();
|
||||
// 组装数据
|
||||
PrepayRequest request = new PrepayRequest();
|
||||
@ -113,7 +137,7 @@ public class WechatPayServiceImpl implements WechatPayService {
|
||||
preOrder.setGoodsDetail(JSONUtil.toJsonStr(goodsDetail));
|
||||
request.setDetail(detail);
|
||||
}
|
||||
|
||||
|
||||
// 场景信息
|
||||
if (StringUtils.hasText(prePay.getPayerClientIp())) {
|
||||
SceneInfo si = new SceneInfo();
|
||||
@ -141,6 +165,8 @@ public class WechatPayServiceImpl implements WechatPayService {
|
||||
Transaction transaction;
|
||||
try {
|
||||
transaction = WechatPayUtil.decryptWechatPayNotify(request, notificationConfig);
|
||||
|
||||
log.info("请求时间{} 验签解密验签解密验签transaction>>>>>{}" ,new Date() ,JSONUtil.toJsonStr(transaction));
|
||||
} catch (Exception e) {
|
||||
JSONObject jo = new JSONObject();
|
||||
jo.set("code", "FAIL");
|
||||
|
||||
@ -3,6 +3,8 @@ package com.evotech.hd.wechat.service.rpc;
|
||||
import java.util.List;
|
||||
import java.util.Map;
|
||||
|
||||
|
||||
import com.evotech.hd.common.core.entity.cloud.request.BatterySwapResponse;
|
||||
import org.springframework.cloud.openfeign.FeignClient;
|
||||
import org.springframework.cloud.openfeign.SpringQueryMap;
|
||||
import org.springframework.http.MediaType;
|
||||
@ -83,4 +85,14 @@ public interface CloudService {
|
||||
consumes = {MediaType.APPLICATION_FORM_URLENCODED_VALUE})
|
||||
public Result<Boolean> isOpenAccount( @RequestParam String wuid);
|
||||
|
||||
@PostMapping(value = "/cloud/order/swap/startSwap",
|
||||
consumes = {MediaType.APPLICATION_FORM_URLENCODED_VALUE})
|
||||
public Result<Boolean> startSwap( @RequestParam String wuid,String orderId);
|
||||
|
||||
@PostMapping(value = "/cloud/order/swap/getStartSwap",
|
||||
consumes = {MediaType.APPLICATION_FORM_URLENCODED_VALUE})
|
||||
public Result<BatterySwapResponse> getStartSwap(@RequestParam String wuid, String orderId);
|
||||
@PostMapping(value = "/cloud/wallet/getWalleCode",
|
||||
consumes = {MediaType.APPLICATION_FORM_URLENCODED_VALUE})
|
||||
public Result<String> getWalleCode(@RequestParam String wuid);
|
||||
}
|
||||
|
||||
@ -2,6 +2,8 @@ package com.evotech.hd.wechat.utils.wechatpay;
|
||||
|
||||
import java.util.Date;
|
||||
|
||||
import com.evotech.hd.common.core.entity.Result;
|
||||
import com.evotech.hd.common.core.entity.cloud.WalletAccount;
|
||||
import org.springframework.beans.BeanUtils;
|
||||
import org.springframework.stereotype.Component;
|
||||
|
||||
@ -21,16 +23,56 @@ import com.wechat.pay.java.service.payments.model.Transaction.TradeTypeEnum;
|
||||
import cn.hutool.core.date.DateUtil;
|
||||
import cn.hutool.json.JSONUtil;
|
||||
import jakarta.annotation.Resource;
|
||||
import cn.hutool.core.util.StrUtil;
|
||||
import org.slf4j.Logger;
|
||||
import org.slf4j.LoggerFactory;
|
||||
|
||||
@Component
|
||||
public class WechatPayComponent {
|
||||
|
||||
private static final Logger log = LoggerFactory.getLogger(WechatPayComponent.class);
|
||||
|
||||
@Resource
|
||||
private WechatPayPreOrderDao preOrderDao;
|
||||
@Resource
|
||||
private WechatUserDao wechatUserDao;
|
||||
@Resource
|
||||
private CloudService cloudService;
|
||||
|
||||
/**
|
||||
* 校验并创建钱包账户
|
||||
* @param wuid 用户ID
|
||||
* @return Result<Boolean> 校验结果
|
||||
*/
|
||||
public Result<Boolean> wechatPrePayLog1(String wuid) {
|
||||
if (StrUtil.isBlank(wuid)) {
|
||||
return new Result<Boolean>().error("用户ID不能为空");
|
||||
}
|
||||
|
||||
try {
|
||||
// 检查钱包账户是否存在
|
||||
Result<Boolean> accountResult = cloudService.isOpenAccount(wuid);
|
||||
// 如果账户不存在,创建新账户
|
||||
if (accountResult.getObj()) {
|
||||
// 创建钱包账户
|
||||
WalletAccount walletAccount = new WalletAccount();
|
||||
walletAccount.setOwnerId(wuid);
|
||||
walletAccount.setOwnerType(1); // 1表示个人账户
|
||||
walletAccount.setTotalAmount(0);
|
||||
walletAccount.setRechargeAmount(0);
|
||||
walletAccount.setGiftAmount(0);
|
||||
|
||||
|
||||
|
||||
log.info("成功创建钱包账户: wuid={}", wuid);
|
||||
}
|
||||
|
||||
return new Result<Boolean>().success(true);
|
||||
} catch (Exception e) {
|
||||
log.error("处理钱包账户异常: wuid={}, error={}", wuid, e.getMessage(), e);
|
||||
return new Result<Boolean>().error("处理钱包账户异常");
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* 记录预支付订单信息
|
||||
@ -95,6 +137,7 @@ public class WechatPayComponent {
|
||||
tradeDetail.setPayTime(DateUtil.parseISO8601(transaction.getSuccessTime()));
|
||||
|
||||
// 2. 处理订单,看要不要异步
|
||||
log.info("请求时间{} 处理订单开始{}" ,new Date() ,JSONUtil.toJsonStr(tradeDetail));
|
||||
cloudService.wechatPayNotifyHandle(tradeDetail);
|
||||
}
|
||||
|
||||
|
||||
Loading…
Reference in New Issue
Block a user