feat(cloud-manage-server): 实现订单状态更新和费用结算功能
- 添加订单状态更新逻辑,处理不同状态下的订单 - 实现按电量和SOC计算订单费用的功能 - 优化换电步骤记录和电池状态更新 - 新增预约单过期检查和提醒功能 - 重构部分代码以提高可维护性
This commit is contained in:
parent
796e72cbfd
commit
9048b368d7
@ -0,0 +1,64 @@
|
|||||||
|
package com.evotech.hd.common.core.entity.cloud.vo;
|
||||||
|
|
||||||
|
import com.fasterxml.jackson.annotation.JsonFormat;
|
||||||
|
import io.swagger.v3.oas.annotations.media.Schema;
|
||||||
|
import jakarta.validation.constraints.NotBlank;
|
||||||
|
import jakarta.validation.constraints.NotNull;
|
||||||
|
import lombok.Data;
|
||||||
|
import org.springframework.format.annotation.DateTimeFormat;
|
||||||
|
|
||||||
|
import java.util.Date;
|
||||||
|
@Data
|
||||||
|
@Schema(name = "账户列表返回结果")
|
||||||
|
public class WalletAccountVO {
|
||||||
|
@Schema(hidden = true)
|
||||||
|
private Integer pkId;
|
||||||
|
|
||||||
|
@Schema(description = "户主类型:1-个人,2-企业", requiredMode = Schema.RequiredMode.REQUIRED)
|
||||||
|
@NotNull(message = "类型不能为空")
|
||||||
|
private Integer ownerType;
|
||||||
|
|
||||||
|
@Schema(description = "户主ID", requiredMode = Schema.RequiredMode.REQUIRED)
|
||||||
|
@NotBlank(message = "用户编码不能为空")
|
||||||
|
private String ownerId;
|
||||||
|
|
||||||
|
@Schema(description = "名称")
|
||||||
|
private String accName;
|
||||||
|
|
||||||
|
@Schema(description = "手机号")
|
||||||
|
private String phone;
|
||||||
|
|
||||||
|
@Schema(description = "编码", hidden = true)
|
||||||
|
private String code;
|
||||||
|
|
||||||
|
@Schema(description = "账户总金额,分:总金额=充值金额+赠送金额")
|
||||||
|
private Integer totalAmount;
|
||||||
|
|
||||||
|
@Schema(description = "充值余额,分")
|
||||||
|
private Integer rechargeAmount;
|
||||||
|
|
||||||
|
@Schema(description = "赠送金额,分")
|
||||||
|
private Integer giftAmount;
|
||||||
|
|
||||||
|
@Schema(description = "积分余额")
|
||||||
|
private Integer point;
|
||||||
|
|
||||||
|
@Schema(description = "押金")
|
||||||
|
private Integer deposit;
|
||||||
|
|
||||||
|
@Schema(description = "SN码")
|
||||||
|
private String snCode;
|
||||||
|
|
||||||
|
@Schema(description = "租金")
|
||||||
|
private Integer rent;
|
||||||
|
|
||||||
|
@Schema(description = "状态")
|
||||||
|
private Integer status;
|
||||||
|
|
||||||
|
@Schema(description = "引入站点")
|
||||||
|
private String stationCode;
|
||||||
|
|
||||||
|
@Schema(description = "创建人")
|
||||||
|
private String creater;
|
||||||
|
|
||||||
|
}
|
||||||
@ -110,8 +110,8 @@ public class OrderSwapBatteryController {
|
|||||||
@Operation(summary = "费用计算")
|
@Operation(summary = "费用计算")
|
||||||
@PostMapping({"/cost"})
|
@PostMapping({"/cost"})
|
||||||
@ApiOperationSupport(order = 9)
|
@ApiOperationSupport(order = 9)
|
||||||
public Result<String> calculateCost(@NotBlank @RequestParam String orderNo) {
|
public Result<String> calculateCost(@NotBlank @RequestParam OrderSwapBattery osb) {
|
||||||
return orderSwapBatteryService.calculateCost(orderNo);
|
return orderSwapBatteryService.calculateCost(osb);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
|||||||
@ -2,6 +2,7 @@ package com.evotech.hd.cloud.controller.order;
|
|||||||
|
|
||||||
import java.util.List;
|
import java.util.List;
|
||||||
|
|
||||||
|
import com.evotech.hd.common.core.entity.cloud.vo.WalletAccountVO;
|
||||||
import com.evotech.hd.common.core.entity.wechat.WechatPayAttach;
|
import com.evotech.hd.common.core.entity.wechat.WechatPayAttach;
|
||||||
import jakarta.servlet.http.HttpServletRequest;
|
import jakarta.servlet.http.HttpServletRequest;
|
||||||
import org.springdoc.core.annotations.ParameterObject;
|
import org.springdoc.core.annotations.ParameterObject;
|
||||||
@ -57,7 +58,7 @@ public class WalletAccountController {
|
|||||||
@Operation(summary = "查询")
|
@Operation(summary = "查询")
|
||||||
@GetMapping("/list")
|
@GetMapping("/list")
|
||||||
@ApiOperationSupport(order = 4)
|
@ApiOperationSupport(order = 4)
|
||||||
public Result<List<WalletAccount>> list(@ParameterObject PageListWalletRequest plwr) {
|
public Result<List<WalletAccountVO>> list(@ParameterObject PageListWalletRequest plwr) {
|
||||||
return walletAccountService.list(plwr);
|
return walletAccountService.list(plwr);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
@ -64,7 +64,7 @@ public class MqttMessageTestController {
|
|||||||
@PostMapping("/orderStatus")
|
@PostMapping("/orderStatus")
|
||||||
@ApiOperationSupport(order = 2)
|
@ApiOperationSupport(order = 2)
|
||||||
public Result<String> orderStatus(@ParameterObject OrderStatus orderStatus, @ParameterObject OrderStatusData statusData, String stationCode) {
|
public Result<String> orderStatus(@ParameterObject OrderStatus orderStatus, @ParameterObject OrderStatusData statusData, String stationCode) {
|
||||||
orderStatus.setStatusData(statusData);
|
|
||||||
JSONObject jo = JSONUtil.parseObj(orderStatus);
|
JSONObject jo = JSONUtil.parseObj(orderStatus);
|
||||||
String topic = mqttTestUtil.getTopic(stationCode, MqttMessageTypeEnum.STATE.getType());
|
String topic = mqttTestUtil.getTopic(stationCode, MqttMessageTypeEnum.STATE.getType());
|
||||||
MqttMessageHeader header = mqttTestUtil.getHeader(StateFunctionTypesEnum.FUN_ORDERSTATUS.getFunction());
|
MqttMessageHeader header = mqttTestUtil.getHeader(StateFunctionTypesEnum.FUN_ORDERSTATUS.getFunction());
|
||||||
|
|||||||
@ -5,7 +5,7 @@ import java.util.Arrays;
|
|||||||
public enum ConfirmFunctionTypesEnum {
|
public enum ConfirmFunctionTypesEnum {
|
||||||
|
|
||||||
FUN_CHARGE_RECORD_CONF("chargeRecordConf", "chargeRecord", "充电事件记录确认"),
|
FUN_CHARGE_RECORD_CONF("chargeRecordConf", "chargeRecord", "充电事件记录确认"),
|
||||||
FUN_SWAP_RECORD_CONF("swapRecordConf", "swapRecord", "换电事件记录确认"),
|
FUN_SWAP_RECORD_CONF("", "swapCompleteConfirm", "换电事件记录确认"),
|
||||||
FUN_FAULT_RECORD_CONF("faultRecordConf", "faultRecord", "故障告警事件记录确认");
|
FUN_FAULT_RECORD_CONF("faultRecordConf", "faultRecord", "故障告警事件记录确认");
|
||||||
|
|
||||||
String function;
|
String function;
|
||||||
|
|||||||
@ -1,15 +1,18 @@
|
|||||||
package com.evotech.hd.cloud.mqtt.enums;
|
package com.evotech.hd.cloud.mqtt.enums;
|
||||||
|
|
||||||
|
import com.evotech.hd.cloud.mqtt.message.dto.newer.state.OrderStatusData;
|
||||||
|
|
||||||
import java.util.Arrays;
|
import java.util.Arrays;
|
||||||
|
|
||||||
public enum EventFunctionTypesEnum {
|
public enum EventFunctionTypesEnum {
|
||||||
|
|
||||||
FUN_CHARGE_RECORD("chargeRecord", "chargeRecordConf", "充电事件记录"),
|
FUN_CHARGE_RECORD("chargeRecord", "chargeRecordConf", "充电事件记录"),
|
||||||
FUN_SWAP_RECORD("swapRecord", "swapRecordConf", "换电事件记录"),
|
FUN_SWAP_RECORD("swapRecord", "swapRecordConf", "换电事件记录"),
|
||||||
FUN_WARN_RECORD("faultRecord", "faultRecordConf", "故障告警事件记录");
|
FUN_WARN_RECORD("faultRecord", "faultRecordConf", "故障告警事件记录"),
|
||||||
|
FUN_ORDEREVENT("swapComplete", "swapCompleteConfirm", " 站端换电完成事件");
|
||||||
String function;
|
String function;
|
||||||
String reFunction;
|
String reFunction;
|
||||||
|
|
||||||
String functionName;
|
String functionName;
|
||||||
|
|
||||||
|
|
||||||
|
|||||||
@ -0,0 +1,14 @@
|
|||||||
|
package com.evotech.hd.cloud.mqtt.message.dto.newer.confirm;
|
||||||
|
|
||||||
|
import io.swagger.v3.oas.annotations.media.Schema;
|
||||||
|
import lombok.Data;
|
||||||
|
|
||||||
|
@Data
|
||||||
|
public class SwapCompleteConfirm {
|
||||||
|
@Schema(description = "订单号")
|
||||||
|
private String orderNo;
|
||||||
|
@Schema(description = "结果")
|
||||||
|
private Integer ackStatus;
|
||||||
|
@Schema(description = "失败原因 ")
|
||||||
|
private String error;
|
||||||
|
}
|
||||||
@ -0,0 +1,23 @@
|
|||||||
|
package com.evotech.hd.cloud.mqtt.message.dto.newer.event;
|
||||||
|
|
||||||
|
import com.evotech.hd.cloud.mqtt.message.dto.newer.state.OrderStatusData;
|
||||||
|
import io.swagger.v3.oas.annotations.media.Schema;
|
||||||
|
import lombok.Data;
|
||||||
|
import org.springframework.format.annotation.DateTimeFormat;
|
||||||
|
|
||||||
|
import java.util.Date;
|
||||||
|
@Data
|
||||||
|
public class SwapComplete {
|
||||||
|
|
||||||
|
private String orderNo;
|
||||||
|
|
||||||
|
private Integer status;
|
||||||
|
|
||||||
|
@Schema(description = "时间", example = "yyyy-MM-dd HH:mm:ss")
|
||||||
|
@DateTimeFormat(pattern = "yyyy-MM-dd HH:mm:ss")
|
||||||
|
private Date statusTime;
|
||||||
|
|
||||||
|
@Schema(hidden = true)
|
||||||
|
private OrderStatusData statusData;
|
||||||
|
|
||||||
|
}
|
||||||
@ -0,0 +1,17 @@
|
|||||||
|
package com.evotech.hd.cloud.mqtt.message.handle;
|
||||||
|
|
||||||
|
import cn.hutool.json.JSONObject;
|
||||||
|
import com.evotech.hd.cloud.mqtt.enums.EventFunctionTypesEnum;
|
||||||
|
import com.evotech.hd.cloud.mqtt.message.MessageTopic;
|
||||||
|
import com.evotech.hd.cloud.mqtt.message.MqttMessageHeader;
|
||||||
|
|
||||||
|
public class ConfirmMessageServeice {
|
||||||
|
public void event(MessageTopic topic, MqttMessageHeader header, JSONObject dataBody) {
|
||||||
|
switch (EventFunctionTypesEnum.getFunctionType(header.getFunction())) {
|
||||||
|
case FUN_WARN_RECORD:
|
||||||
|
|
||||||
|
default:
|
||||||
|
break;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
@ -1,5 +1,28 @@
|
|||||||
package com.evotech.hd.cloud.mqtt.message.handle;
|
package com.evotech.hd.cloud.mqtt.message.handle;
|
||||||
|
|
||||||
|
import cn.hutool.core.date.DatePattern;
|
||||||
|
import cn.hutool.core.date.DateUtil;
|
||||||
|
import cn.hutool.json.JSONConfig;
|
||||||
|
import cn.hutool.json.JSONUtil;
|
||||||
|
import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
|
||||||
|
import com.evotech.hd.cloud.dao.BatteryStationDcDao;
|
||||||
|
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.mqtt.enums.ConfirmFunctionTypesEnum;
|
||||||
|
import com.evotech.hd.cloud.mqtt.enums.MqttMessageTypeEnum;
|
||||||
|
import com.evotech.hd.cloud.mqtt.enums.RequestFunctionTypesEnum;
|
||||||
|
import com.evotech.hd.cloud.mqtt.message.dto.newer.confirm.SwapCompleteConfirm;
|
||||||
|
import com.evotech.hd.cloud.mqtt.message.dto.newer.event.SwapComplete;
|
||||||
|
import com.evotech.hd.cloud.mqtt.message.dto.newer.state.OrderStatus;
|
||||||
|
import com.evotech.hd.cloud.mqtt.message.dto.newer.state.OrderStatusData;
|
||||||
|
import com.evotech.hd.cloud.service.BatteryStationDcService;
|
||||||
|
import com.evotech.hd.cloud.service.OrderSwapBatteryService;
|
||||||
|
import com.evotech.hd.cloud.utils.components.HDStepDictComponent;
|
||||||
|
import com.evotech.hd.common.core.dao.cloud.OrderSwapBatteryDao;
|
||||||
|
import com.evotech.hd.common.core.entity.cloud.*;
|
||||||
|
import lombok.extern.slf4j.Slf4j;
|
||||||
|
import org.springframework.beans.BeanUtils;
|
||||||
import org.springframework.stereotype.Service;
|
import org.springframework.stereotype.Service;
|
||||||
|
|
||||||
import com.evotech.hd.cloud.mqtt.enums.EventFunctionTypesEnum;
|
import com.evotech.hd.cloud.mqtt.enums.EventFunctionTypesEnum;
|
||||||
@ -8,40 +31,159 @@ import com.evotech.hd.cloud.mqtt.message.MqttMessageHeader;
|
|||||||
import cn.hutool.json.JSONObject;
|
import cn.hutool.json.JSONObject;
|
||||||
import jakarta.annotation.Resource;
|
import jakarta.annotation.Resource;
|
||||||
|
|
||||||
|
import java.util.Date;
|
||||||
|
import java.util.Objects;
|
||||||
|
|
||||||
@Service
|
@Service
|
||||||
|
@Slf4j
|
||||||
public class EventMessageService {
|
public class EventMessageService {
|
||||||
|
|
||||||
@Resource
|
@Resource
|
||||||
private MessageUtilService messageUtilService;
|
private MessageUtilService messageUtilService;
|
||||||
|
|
||||||
|
@Resource
|
||||||
|
private OrderSwapBatteryDao orderSwapBatteryDao;
|
||||||
|
@Resource
|
||||||
|
private OrderSwapBatteryStepDao orderSwapBatteryStepDao;
|
||||||
|
@Resource
|
||||||
|
private BatteryStationDcService batteryStationDcService;
|
||||||
|
@Resource
|
||||||
|
private HDStepDictComponent hdStepDictComponent;
|
||||||
|
@Resource
|
||||||
|
private VehicleInfoDao vehicleInfoDao;
|
||||||
|
@Resource
|
||||||
|
private BatteryStationDcDao batteryStationDcDao;
|
||||||
|
@Resource
|
||||||
|
private OrderSwapBatteryService orderSwapBatteryService;
|
||||||
/**
|
/**
|
||||||
* event消息 处理
|
* event消息 处理
|
||||||
*/
|
*/
|
||||||
|
|
||||||
public void event(MessageTopic topic, MqttMessageHeader header, JSONObject dataBody) {
|
public void event(MessageTopic topic, MqttMessageHeader header, JSONObject dataBody) {
|
||||||
switch (EventFunctionTypesEnum.getFunctionType(header.getFunction())) {
|
switch (Objects.requireNonNull(EventFunctionTypesEnum.getFunctionType(header.getFunction()))) {
|
||||||
// // 这个事件不用了
|
|
||||||
// case FUN_CHARGE_RECORD:
|
|
||||||
// // TODO 写充电记录表
|
|
||||||
// // TODO 回复 confirm 消息
|
|
||||||
// // TODO 订单结算
|
|
||||||
//
|
|
||||||
// break;
|
|
||||||
// // 这个事件不用了
|
|
||||||
// case FUN_SWAP_RECORD:
|
|
||||||
// // TODO 写换电记录表
|
|
||||||
// // TODO 回复 confirm 消息
|
|
||||||
// // TODO 更新订单
|
|
||||||
// break;
|
|
||||||
case FUN_WARN_RECORD:
|
case FUN_WARN_RECORD:
|
||||||
// TODO 写预警记录表
|
// TODO 写预警记录表
|
||||||
// TODO 回复 confirm 消息
|
// TODO 回复 confirm 消息
|
||||||
// TODO 业务处理
|
// TODO 业务处理
|
||||||
break;
|
break;
|
||||||
|
// 站端反馈订单状态
|
||||||
|
case FUN_ORDEREVENT:
|
||||||
|
SwapComplete orderStatus = JSONUtil.toBean(dataBody, SwapComplete.class);
|
||||||
|
OrderStatusData statusData = JSONUtil.toBean(dataBody.getJSONObject("statusData"), OrderStatusData.class);
|
||||||
|
// 订单状态更新处理
|
||||||
|
handleOrderStatus(orderStatus, statusData);
|
||||||
|
Date d = new Date();
|
||||||
|
//回复 confirm 消息
|
||||||
|
SwapCompleteConfirm swapRecordConfirm = new SwapCompleteConfirm();
|
||||||
|
swapRecordConfirm.setAckStatus(1);
|
||||||
|
swapRecordConfirm.setOrderNo(orderStatus.getOrderNo());
|
||||||
|
swapRecordConfirm.setError("");
|
||||||
|
topic.setDataDirection("M2S");
|
||||||
|
topic.setMessageType(MqttMessageTypeEnum.CONFIRM.getType());
|
||||||
|
header.setFunction(ConfirmFunctionTypesEnum.FUN_SWAP_RECORD_CONF.getReFunction());
|
||||||
|
header.setTimeStamp(DateUtil.format(new Date(), DatePattern.NORM_DATETIME_FORMATTER));
|
||||||
|
log.info("\r\n=====>>>回复站端收到换电完成--MQTT发送到消息主题:{},头部信息:{}订单编码;{},message:{}", topic,header, orderStatus.getOrderNo(),JSONUtil.parseObj(swapRecordConfirm, new JSONConfig().setDateFormat(DatePattern.NORM_DATETIME_PATTERN)));
|
||||||
|
messageUtilService.publishAESMessage(topic, header, JSONUtil.parseObj(swapRecordConfirm, new JSONConfig().setDateFormat(DatePattern.NORM_DATETIME_PATTERN)));
|
||||||
|
break;
|
||||||
|
|
||||||
default:
|
default:
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
/**
|
||||||
|
* 订单最终状态的更新
|
||||||
|
* @param orderStatus
|
||||||
|
* @param statusData
|
||||||
|
*/
|
||||||
|
private void handleOrderStatus(SwapComplete orderStatus, OrderStatusData statusData) {
|
||||||
|
// 换电步骤添加最后一条
|
||||||
|
if (orderStatus.getStatus() == 3){
|
||||||
|
OrderSwapBattery osb = alterOrderStatus(orderStatus, statusData);
|
||||||
|
OrderSwapBatteryStep step = new OrderSwapBatteryStep();
|
||||||
|
step.setOrderNo(orderStatus.getOrderNo());
|
||||||
|
step.setStep(8);
|
||||||
|
step.setStepTime(orderStatus.getStatusTime());
|
||||||
|
step.setCtime(new Date());
|
||||||
|
step.setCreater("SYS");
|
||||||
|
step.setStepName(hdStepDictComponent.hdStepDictName(step.getStep()));
|
||||||
|
orderSwapBatteryStepDao.insert(step);
|
||||||
|
// 修改车上电池编码
|
||||||
|
VehicleInfo vi = new VehicleInfo();
|
||||||
|
vi.setBatCode(statusData.getRentBatCode());
|
||||||
|
vi.setBatSoc(statusData.getRentBatSoc());
|
||||||
|
vehicleInfoDao.update(vi, new QueryWrapper<VehicleInfo>().eq("plate_num", osb.getPlateNum()));
|
||||||
|
// 修改2块电池的信息
|
||||||
|
BatteryStationDc dc1 = new BatteryStationDc();
|
||||||
|
BatteryStationDc dc2 = new BatteryStationDc();
|
||||||
|
dc1.setStatus(1);
|
||||||
|
dc1.setSourceFrom(1);
|
||||||
|
dc1.setPointType(2);
|
||||||
|
dc1.setPointCode(osb.getPlateNum());
|
||||||
|
dc1.setPointName(osb.getPlateNum());
|
||||||
|
dc1.setSoc(statusData.getRentBatSoc());
|
||||||
|
dc1.setDccNo(0);
|
||||||
|
batteryStationDcDao.update(dc1, new QueryWrapper<BatteryStationDc>().eq("bat_code", statusData.getRentBatCode()));
|
||||||
|
dc2.setStatus(2);
|
||||||
|
dc2.setSourceFrom(1);
|
||||||
|
dc2.setPointType(1);
|
||||||
|
dc2.setPointCode(osb.getStationCode());
|
||||||
|
dc2.setPointName(osb.getStationName());
|
||||||
|
dc2.setSoc(statusData.getReturnBatSoc());
|
||||||
|
dc2.setDccNo(statusData.getReturnBatNo());
|
||||||
|
batteryStationDcDao.update(dc2, new QueryWrapper<BatteryStationDc>().eq("bat_code", statusData.getReturnBatCode()));
|
||||||
|
// 添加2块电池的溯源记录
|
||||||
|
addBatteryTrace(orderStatus, statusData, osb);
|
||||||
|
//计算费用方式
|
||||||
|
log.info("\r\n=====>>>订单状态更新处理订单状态开始结算:{},{}",orderStatus.getOrderNo(),orderStatus.getStatus() );
|
||||||
|
//费用结算
|
||||||
|
orderSwapBatteryService.calculateCost1(orderStatus.getOrderNo(), statusData);
|
||||||
|
|
||||||
|
}
|
||||||
|
}
|
||||||
|
/**
|
||||||
|
* 修改订单状态方法
|
||||||
|
*
|
||||||
|
* @param orderStatus
|
||||||
|
* @param statusData
|
||||||
|
* @return
|
||||||
|
*/
|
||||||
|
private OrderSwapBattery alterOrderStatus(SwapComplete orderStatus, OrderStatusData statusData) {
|
||||||
|
OrderSwapBattery osb = orderSwapBatteryDao.selectOne(new QueryWrapper<OrderSwapBattery>().eq("order_no", orderStatus.getOrderNo()));
|
||||||
|
osb.setStatus(orderStatus.getStatus());
|
||||||
|
if (orderStatus.getStatus() == 3) {
|
||||||
|
osb.setServiceTimeEnd(orderStatus.getStatusTime());
|
||||||
|
BeanUtils.copyProperties(statusData, osb);
|
||||||
|
}
|
||||||
|
osb.setUptime(null);
|
||||||
|
orderSwapBatteryDao.updateById(osb);
|
||||||
|
return osb;
|
||||||
|
}
|
||||||
|
/**
|
||||||
|
* 添加电池轨迹记录
|
||||||
|
*
|
||||||
|
* @param orderStatus
|
||||||
|
* @param statusData
|
||||||
|
* @param osb
|
||||||
|
*/
|
||||||
|
private void addBatteryTrace(SwapComplete orderStatus, OrderStatusData statusData, OrderSwapBattery osb) {
|
||||||
|
BatteryTrace bt1 = new BatteryTrace();
|
||||||
|
bt1.setOrderNo(orderStatus.getOrderNo());
|
||||||
|
bt1.setBatCode(statusData.getRentBatCode());
|
||||||
|
bt1.setSoc(statusData.getRentBatSoc());
|
||||||
|
bt1.setBeginTime(orderStatus.getStatusTime());
|
||||||
|
bt1.setPointType(2);
|
||||||
|
bt1.setPointCode(osb.getPlateNum());
|
||||||
|
bt1.setPointName(osb.getPlateNum());
|
||||||
|
bt1.setCreater("SYS");
|
||||||
|
BatteryTrace bt2 = new BatteryTrace();
|
||||||
|
BeanUtils.copyProperties(bt1, bt2);
|
||||||
|
bt2.setBatCode(statusData.getReturnBatCode());
|
||||||
|
bt2.setSoc(statusData.getRentBatSoc());
|
||||||
|
bt2.setPointType(1);
|
||||||
|
bt2.setPointCode(osb.getStationCode());
|
||||||
|
bt2.setPointName(osb.getStationName());
|
||||||
|
batteryStationDcService.addTrace(bt1);
|
||||||
|
batteryStationDcService.addTrace(bt2);
|
||||||
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|||||||
@ -45,8 +45,6 @@ import lombok.extern.slf4j.Slf4j;
|
|||||||
@Slf4j
|
@Slf4j
|
||||||
public class StateMessageService {
|
public class StateMessageService {
|
||||||
|
|
||||||
@Resource
|
|
||||||
private MessageUtilService messageUtilService;
|
|
||||||
@Resource
|
@Resource
|
||||||
private OrderSwapBatteryDao orderSwapBatteryDao;
|
private OrderSwapBatteryDao orderSwapBatteryDao;
|
||||||
@Resource
|
@Resource
|
||||||
@ -57,23 +55,17 @@ public class StateMessageService {
|
|||||||
private BatteryStationDcService batteryStationDcService;
|
private BatteryStationDcService batteryStationDcService;
|
||||||
@Resource
|
@Resource
|
||||||
private HDStepDictComponent hdStepDictComponent;
|
private HDStepDictComponent hdStepDictComponent;
|
||||||
@Resource
|
|
||||||
private VehicleInfoDao vehicleInfoDao;
|
|
||||||
@Resource
|
|
||||||
private BatteryStationDcDao batteryStationDcDao;
|
|
||||||
@Resource
|
|
||||||
private OrderSwapBatteryService orderSwapBatteryService;
|
|
||||||
@Async("taskExecutor")
|
@Async("taskExecutor")
|
||||||
public void state(MessageTopic topic, MqttMessageHeader header, JSONObject dataBody) {
|
public void state(MessageTopic topic, MqttMessageHeader header, JSONObject dataBody) {
|
||||||
switch (Objects.requireNonNull(StateFunctionTypesEnum.getFunctionType(header.getFunction()))) {
|
switch (Objects.requireNonNull(StateFunctionTypesEnum.getFunctionType(header.getFunction()))) {
|
||||||
// 站端反馈订单状态
|
// 站端反馈订单状态
|
||||||
case FUN_ORDERSTATUS:
|
case FUN_ORDERSTATUS:
|
||||||
OrderStatus orderStatus = JSONUtil.toBean(dataBody, OrderStatus.class);
|
OrderStatus orderStatus = JSONUtil.toBean(dataBody, OrderStatus.class);
|
||||||
OrderStatusData statusData = JSONUtil.toBean(dataBody.getJSONObject("statusData"),
|
OrderStatusData statusData = JSONUtil.toBean(dataBody.getJSONObject("statusData"), OrderStatusData.class);
|
||||||
OrderStatusData.class);
|
|
||||||
// 订单状态更新处理
|
// 订单状态更新处理
|
||||||
handleOrderStatus(orderStatus, statusData);
|
handleOrderStatus(orderStatus);
|
||||||
// TODO 回复一下收到了
|
|
||||||
break;
|
break;
|
||||||
// 站端反馈换电步骤
|
// 站端反馈换电步骤
|
||||||
case FUN_SWAPSTEP:
|
case FUN_SWAPSTEP:
|
||||||
@ -86,10 +78,8 @@ public class StateMessageService {
|
|||||||
step.setStepName(hdStepDictComponent.hdStepDictName(step.getStep()));
|
step.setStepName(hdStepDictComponent.hdStepDictName(step.getStep()));
|
||||||
log.info("\r\n=====>>>站端反馈换电步骤--MQTT收到消息主题:{},换电步骤名称:{}",topic,hdStepDictComponent.hdStepDictName(step.getStep()) );
|
log.info("\r\n=====>>>站端反馈换电步骤--MQTT收到消息主题:{},换电步骤名称:{}",topic,hdStepDictComponent.hdStepDictName(step.getStep()) );
|
||||||
orderSwapBatteryStepDao.insert(step);
|
orderSwapBatteryStepDao.insert(step);
|
||||||
|
|
||||||
break;
|
break;
|
||||||
case FUN_TEST:
|
case FUN_TEST:
|
||||||
|
|
||||||
break;
|
break;
|
||||||
default:
|
default:
|
||||||
break;
|
break;
|
||||||
@ -100,15 +90,15 @@ public class StateMessageService {
|
|||||||
/**
|
/**
|
||||||
* 订单状态更新处理
|
* 订单状态更新处理
|
||||||
* @param orderStatus
|
* @param orderStatus
|
||||||
* @param statusData
|
|
||||||
*/
|
*/
|
||||||
private void handleOrderStatus(OrderStatus orderStatus, OrderStatusData statusData) {
|
private void handleOrderStatus(OrderStatus orderStatus) {
|
||||||
switch (orderStatus.getStatus()) {
|
switch (orderStatus.getStatus()) {
|
||||||
case 2:
|
case 2:
|
||||||
orderStatus2(orderStatus);
|
orderStatus2(orderStatus);
|
||||||
break;
|
break;
|
||||||
case 3:
|
case 3:
|
||||||
// 修改订单状态和数据
|
/* // 修改订单状态和数据
|
||||||
OrderSwapBattery osb = alterOrderStatus(orderStatus, statusData);
|
OrderSwapBattery osb = alterOrderStatus(orderStatus, statusData);
|
||||||
// 换电步骤添加最后一条
|
// 换电步骤添加最后一条
|
||||||
OrderSwapBatteryStep step = new OrderSwapBatteryStep();
|
OrderSwapBatteryStep step = new OrderSwapBatteryStep();
|
||||||
@ -119,6 +109,10 @@ public class StateMessageService {
|
|||||||
step.setCreater("SYS");
|
step.setCreater("SYS");
|
||||||
step.setStepName(hdStepDictComponent.hdStepDictName(step.getStep()));
|
step.setStepName(hdStepDictComponent.hdStepDictName(step.getStep()));
|
||||||
orderSwapBatteryStepDao.insert(step);
|
orderSwapBatteryStepDao.insert(step);
|
||||||
|
//计算费用方式
|
||||||
|
log.info("\r\n=====>>>订单状态更新处理订单状态开始结算:{},{}",orderStatus.getOrderNo(),orderStatus.getStatus() );
|
||||||
|
//费用结算
|
||||||
|
orderSwapBatteryService.calculateCost1(orderStatus.getOrderNo(), statusData);
|
||||||
// 修改车上电池编码
|
// 修改车上电池编码
|
||||||
VehicleInfo vi = new VehicleInfo();
|
VehicleInfo vi = new VehicleInfo();
|
||||||
vi.setBatCode(statusData.getRentBatCode());
|
vi.setBatCode(statusData.getRentBatCode());
|
||||||
@ -141,33 +135,24 @@ public class StateMessageService {
|
|||||||
dc2.setPointName(osb.getStationName());
|
dc2.setPointName(osb.getStationName());
|
||||||
dc2.setSoc(statusData.getReturnBatSoc());
|
dc2.setSoc(statusData.getReturnBatSoc());
|
||||||
dc2.setDccNo(statusData.getReturnBatNo());
|
dc2.setDccNo(statusData.getReturnBatNo());
|
||||||
batteryStationDcDao.update(dc2,
|
batteryStationDcDao.update(dc2, new QueryWrapper<BatteryStationDc>().eq("bat_code", statusData.getReturnBatCode()));
|
||||||
new QueryWrapper<BatteryStationDc>().eq("bat_code", statusData.getReturnBatCode()));
|
|
||||||
// 添加2块电池的溯源记录
|
// 添加2块电池的溯源记录
|
||||||
addBatteryTrace(orderStatus, statusData, osb);
|
addBatteryTrace(orderStatus, statusData, osb);
|
||||||
break;
|
break;*/
|
||||||
case 4:
|
case 4:
|
||||||
// 修改订单状态
|
// 修改订单状态
|
||||||
alterOrderStatus(orderStatus, null);
|
alterOrderStatus(orderStatus);
|
||||||
break;
|
break;
|
||||||
case 5:
|
/* case 5:
|
||||||
// 修改订单状态和数据
|
// 修改订单状态和数据
|
||||||
alterOrderStatus(orderStatus, statusData);
|
alterOrderStatus(orderStatus, statusData);
|
||||||
// 修改电池状态
|
// 修改电池状态
|
||||||
BatteryStationDc dc = new BatteryStationDc();
|
BatteryStationDc dc = new BatteryStationDc();
|
||||||
dc.setStatus(3);
|
dc.setStatus(3);
|
||||||
dc.setSoc(statusData.getSoc());
|
dc.setSoc(statusData.getSoc());
|
||||||
//电量结算
|
|
||||||
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()));
|
batteryStationDcDao.update(dc, new QueryWrapper<BatteryStationDc>().eq("bat_code", statusData.getBatCode()));
|
||||||
break;
|
break;*/
|
||||||
default:
|
default:
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
@ -208,7 +193,7 @@ public class StateMessageService {
|
|||||||
*/
|
*/
|
||||||
private void orderStatus2(OrderStatus orderStatus) {
|
private void orderStatus2(OrderStatus orderStatus) {
|
||||||
// 修改订单状态
|
// 修改订单状态
|
||||||
OrderSwapBattery osb = alterOrderStatus(orderStatus, null);
|
OrderSwapBattery osb = alterOrderStatus(orderStatus);
|
||||||
// 添加换电步骤1-车辆进站
|
// 添加换电步骤1-车辆进站
|
||||||
OrderSwapBatteryStep step = new OrderSwapBatteryStep();
|
OrderSwapBatteryStep step = new OrderSwapBatteryStep();
|
||||||
step.setOrderNo(orderStatus.getOrderNo());
|
step.setOrderNo(orderStatus.getOrderNo());
|
||||||
@ -229,28 +214,21 @@ public class StateMessageService {
|
|||||||
* 修改订单状态方法
|
* 修改订单状态方法
|
||||||
*
|
*
|
||||||
* @param orderStatus
|
* @param orderStatus
|
||||||
* @param statusData
|
|
||||||
* @return
|
* @return
|
||||||
*/
|
*/
|
||||||
private OrderSwapBattery alterOrderStatus(OrderStatus orderStatus, OrderStatusData statusData) {
|
private OrderSwapBattery alterOrderStatus(OrderStatus orderStatus) {
|
||||||
OrderSwapBattery osb = orderSwapBatteryDao
|
OrderSwapBattery osb = orderSwapBatteryDao
|
||||||
.selectOne(new QueryWrapper<OrderSwapBattery>().eq("order_no", orderStatus.getOrderNo()));
|
.selectOne(new QueryWrapper<OrderSwapBattery>().eq("order_no", orderStatus.getOrderNo()));
|
||||||
osb.setStatus(orderStatus.getStatus());
|
osb.setStatus(orderStatus.getStatus());
|
||||||
if (orderStatus.getStatus() == 2) {
|
if (orderStatus.getStatus() == 2) {
|
||||||
osb.setServiceTimeBegin(orderStatus.getStatusTime());
|
osb.setServiceTimeBegin(orderStatus.getStatusTime());
|
||||||
}
|
}
|
||||||
if (orderStatus.getStatus() == 3) {
|
|
||||||
osb.setServiceTimeEnd(orderStatus.getStatusTime());
|
|
||||||
BeanUtils.copyProperties(statusData, osb);
|
|
||||||
}
|
|
||||||
if (orderStatus.getStatus() == 4) {
|
if (orderStatus.getStatus() == 4) {
|
||||||
osb.setChargeTimeBegin(orderStatus.getStatusTime());
|
osb.setChargeTimeBegin(orderStatus.getStatusTime());
|
||||||
}
|
}
|
||||||
if (orderStatus.getStatus() == 5) {
|
|
||||||
osb.setChargeTimeEnd(orderStatus.getStatusTime());
|
osb.setUptime(new Date());
|
||||||
osb.setElectAmount(statusData.getElectAmount());
|
|
||||||
}
|
|
||||||
osb.setUptime(null);
|
|
||||||
orderSwapBatteryDao.updateById(osb);
|
orderSwapBatteryDao.updateById(osb);
|
||||||
return osb;
|
return osb;
|
||||||
}
|
}
|
||||||
|
|||||||
@ -2,6 +2,7 @@ package com.evotech.hd.cloud.service;
|
|||||||
|
|
||||||
import java.util.List;
|
import java.util.List;
|
||||||
|
|
||||||
|
import com.evotech.hd.cloud.mqtt.message.dto.newer.state.OrderStatusData;
|
||||||
import com.evotech.hd.common.core.entity.cloud.request.BatterySwapResponse;
|
import com.evotech.hd.common.core.entity.cloud.request.BatterySwapResponse;
|
||||||
import com.evotech.hd.cloud.entity.vo.NativePayVO;
|
import com.evotech.hd.cloud.entity.vo.NativePayVO;
|
||||||
import com.evotech.hd.common.core.entity.Result;
|
import com.evotech.hd.common.core.entity.Result;
|
||||||
@ -31,7 +32,7 @@ public interface OrderSwapBatteryService {
|
|||||||
|
|
||||||
public Result<List<OrderSwapBatteryStep>> listStep(String orderNo);
|
public Result<List<OrderSwapBatteryStep>> listStep(String orderNo);
|
||||||
|
|
||||||
public Result<String> calculateCost(String orderNo);
|
public Result<String> calculateCost1(String orderNo, OrderStatusData statusData);
|
||||||
|
|
||||||
public Result<String> calculateCost(OrderSwapBattery osb);
|
public Result<String> calculateCost(OrderSwapBattery osb);
|
||||||
|
|
||||||
|
|||||||
@ -6,6 +6,7 @@ import com.evotech.hd.common.core.entity.Result;
|
|||||||
import com.evotech.hd.common.core.entity.cloud.WalletAccount;
|
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.WalletAccountDetail;
|
||||||
import com.evotech.hd.common.core.entity.cloud.request.PageListWalletRequest;
|
import com.evotech.hd.common.core.entity.cloud.request.PageListWalletRequest;
|
||||||
|
import com.evotech.hd.common.core.entity.cloud.vo.WalletAccountVO;
|
||||||
import com.evotech.hd.common.core.entity.wechat.WechatPayAttach;
|
import com.evotech.hd.common.core.entity.wechat.WechatPayAttach;
|
||||||
|
|
||||||
public interface WalletAccountService {
|
public interface WalletAccountService {
|
||||||
@ -16,7 +17,7 @@ public interface WalletAccountService {
|
|||||||
|
|
||||||
public Result<Integer> update(WalletAccount wa);
|
public Result<Integer> update(WalletAccount wa);
|
||||||
|
|
||||||
public Result<List<WalletAccount>> list(PageListWalletRequest plwr);
|
public Result<List<WalletAccountVO>> list(PageListWalletRequest plwr);
|
||||||
|
|
||||||
public Result<Integer> addDetail(WalletAccountDetail wad);
|
public Result<Integer> addDetail(WalletAccountDetail wad);
|
||||||
|
|
||||||
|
|||||||
@ -4,11 +4,7 @@ import java.io.IOException;
|
|||||||
import java.io.UnsupportedEncodingException;
|
import java.io.UnsupportedEncodingException;
|
||||||
import java.net.URLEncoder;
|
import java.net.URLEncoder;
|
||||||
import java.security.KeyPair;
|
import java.security.KeyPair;
|
||||||
import java.util.Base64;
|
import java.util.*;
|
||||||
import java.util.Date;
|
|
||||||
import java.util.HashMap;
|
|
||||||
import java.util.List;
|
|
||||||
import java.util.Map;
|
|
||||||
|
|
||||||
import org.springframework.beans.BeanUtils;
|
import org.springframework.beans.BeanUtils;
|
||||||
import org.springframework.http.MediaType;
|
import org.springframework.http.MediaType;
|
||||||
@ -159,8 +155,8 @@ public class BatteryStationServiceImpl implements BatteryStationService {
|
|||||||
|
|
||||||
@Override
|
@Override
|
||||||
public Result<List<BatteryStationVO>> listStation(String plateNum) {
|
public Result<List<BatteryStationVO>> listStation(String plateNum) {
|
||||||
|
//过滤未营业的换电站
|
||||||
List<BatteryStation> list = batteryStationDao.selectList(new QueryWrapper<BatteryStation>().eq("del_flag", 0));
|
List<BatteryStation> list = batteryStationDao.selectList(new QueryWrapper<BatteryStation>().eq("del_flag", 0).eq("status", 1));
|
||||||
if (list.isEmpty()) {
|
if (list.isEmpty()) {
|
||||||
return new Result<List<BatteryStationVO>>().error(CodeMsg.DATABASE_RESULT_NULL);
|
return new Result<List<BatteryStationVO>>().error(CodeMsg.DATABASE_RESULT_NULL);
|
||||||
}
|
}
|
||||||
@ -177,15 +173,14 @@ public class BatteryStationServiceImpl implements BatteryStationService {
|
|||||||
if (vi == null) {
|
if (vi == null) {
|
||||||
return new Result<List<BatteryStationVO>>().error("无车辆信息!");
|
return new Result<List<BatteryStationVO>>().error("无车辆信息!");
|
||||||
}
|
}
|
||||||
res = res.stream().map(i -> {
|
// 过滤未营业的换电站并根据车辆类型过滤
|
||||||
if (StringUtils.hasText(i.getCarTypeCode()) && i.getCarTypeCode().contains(vi.getTypeCode())) {
|
res = res.stream()
|
||||||
|
.filter(i -> StringUtils.hasText(i.getCarTypeCode()) && i.getCarTypeCode().contains(vi.getTypeCode()))
|
||||||
|
.map(i -> {
|
||||||
i.setIsSuitable(true);
|
i.setIsSuitable(true);
|
||||||
} else {
|
|
||||||
i.setIsSuitable(false);
|
|
||||||
}
|
|
||||||
return i;
|
return i;
|
||||||
})
|
})
|
||||||
.sorted((i1, i2) -> i1.getIsSuitable().compareTo(i2.getIsSuitable()))
|
.sorted(Comparator.comparing(BatteryStationVO::getIsSuitable))
|
||||||
.toList();
|
.toList();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
@ -14,6 +14,7 @@ import cn.hutool.core.util.StrUtil;
|
|||||||
import cn.hutool.json.JSONConfig;
|
import cn.hutool.json.JSONConfig;
|
||||||
import cn.hutool.json.JSONUtil;
|
import cn.hutool.json.JSONUtil;
|
||||||
import com.evotech.hd.cloud.dao.*;
|
import com.evotech.hd.cloud.dao.*;
|
||||||
|
import com.evotech.hd.cloud.mqtt.message.dto.newer.state.OrderStatusData;
|
||||||
import com.evotech.hd.common.core.entity.cloud.request.BatterySwapResponse;
|
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.message.dto.newer.req.battery.BatterySwapReq;
|
||||||
import com.evotech.hd.cloud.mqtt.enums.MqttMessageTypeEnum;
|
import com.evotech.hd.cloud.mqtt.enums.MqttMessageTypeEnum;
|
||||||
@ -116,8 +117,8 @@ public class OrderSwapBatteryServiceImpl implements OrderSwapBatteryService {
|
|||||||
.eq("order_pre_uid", osbp.getUcode())
|
.eq("order_pre_uid", osbp.getUcode())
|
||||||
.eq("status", 6)
|
.eq("status", 6)
|
||||||
.eq("order_pre_uname", osbp.getUname())
|
.eq("order_pre_uname", osbp.getUname())
|
||||||
.eq("station_code", osbp.getStationCode()));
|
);
|
||||||
if (ordercount > 3){
|
if (ordercount >= 3){
|
||||||
return new Result<Integer>().error("您有未支付的订单,请先支付!");
|
return new Result<Integer>().error("您有未支付的订单,请先支付!");
|
||||||
}
|
}
|
||||||
// 是否需要验证人和车绑定关系
|
// 是否需要验证人和车绑定关系
|
||||||
@ -131,6 +132,11 @@ public class OrderSwapBatteryServiceImpl implements OrderSwapBatteryService {
|
|||||||
osbp.setCtime(d);
|
osbp.setCtime(d);
|
||||||
int n = orderSwapBatteryPreDao.insert(osbp);
|
int n = orderSwapBatteryPreDao.insert(osbp);
|
||||||
if (n == 1) {
|
if (n == 1) {
|
||||||
|
// 计算过期时间(预约时间后30分钟)
|
||||||
|
Date expireTime = DateUtil.offsetMinute(osbp.getReservationTime(), 90);
|
||||||
|
// 将预约单ID和过期时间存入Redis,设置过期时间为预约时间后30分钟
|
||||||
|
String redisKey = "preorder:expire:" + osbp.getPkId();
|
||||||
|
redisUtil.set(redisKey, expireTime);
|
||||||
// 发送服务号消息,没有消息队列,先用接口吧
|
// 发送服务号消息,没有消息队列,先用接口吧
|
||||||
templateMessageService.preOrderMessageSend(osbp);
|
templateMessageService.preOrderMessageSend(osbp);
|
||||||
return new Result<Integer>().success(n);
|
return new Result<Integer>().success(n);
|
||||||
@ -170,6 +176,7 @@ public class OrderSwapBatteryServiceImpl implements OrderSwapBatteryService {
|
|||||||
|
|
||||||
@Override
|
@Override
|
||||||
public Result<Integer> add(OrderSwapBattery osb) {
|
public Result<Integer> add(OrderSwapBattery osb) {
|
||||||
|
|
||||||
// 加上费用标准
|
// 加上费用标准
|
||||||
osb = orderBasicFeeComponent.orderBasicFee(osb);
|
osb = orderBasicFeeComponent.orderBasicFee(osb);
|
||||||
osb.setCtime(new Date());
|
osb.setCtime(new Date());
|
||||||
@ -277,14 +284,14 @@ public class OrderSwapBatteryServiceImpl implements OrderSwapBatteryService {
|
|||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public Result<String> calculateCost(String orderNo) {
|
public Result<String> calculateCost1(String orderNo, OrderStatusData statusData) {
|
||||||
OrderSwapBattery order = orderSwapBatteryDao.selectOne(new QueryWrapper<OrderSwapBattery>().eq("order_no", orderNo));
|
OrderSwapBattery order = orderSwapBatteryDao.selectOne(new QueryWrapper<OrderSwapBattery>().eq("order_no", orderNo));
|
||||||
log.info("订单号:{}", JSONUtil.parseObj(order));
|
log.info("订单号:{}", JSONUtil.parseObj(order));
|
||||||
if (order == null) {
|
if (order == null) {
|
||||||
return new Result<String>().error("无此订单!");
|
return new Result<String>().error("无此订单!");
|
||||||
}
|
}
|
||||||
// 1. 检查状态
|
// 1. 检查状态
|
||||||
if (order.getStatus() != 5) {
|
if (order.getStatus() != 3) {
|
||||||
return new Result<String>().error("订单状态异常!");
|
return new Result<String>().error("订单状态异常!");
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -295,25 +302,37 @@ public class OrderSwapBatteryServiceImpl implements OrderSwapBatteryService {
|
|||||||
return new Result<String>().error("订单费用标准异常!");
|
return new Result<String>().error("订单费用标准异常!");
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
BigDecimal fee;
|
||||||
// 3. 选择费用计算方式 计算费用
|
// 3. 选择费用计算方式 计算费用
|
||||||
if (order.getFeeType()==3){
|
if (order.getFeeType()==3){
|
||||||
// 电量计算
|
// 电量计算
|
||||||
if (order.getElectAmount() == null) {
|
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);
|
fee = order.getServiceFee().add(order.getBasicFee().multiply(order.getElectAmount())).setScale(0, RoundingMode.HALF_UP);
|
||||||
|
|
||||||
|
}else if (order.getFeeType() == 2) {
|
||||||
|
// TODO 按SOC
|
||||||
|
if (statusData.getRentBatSoc() == null || statusData.getReturnBatSoc() == null) {
|
||||||
|
return new Result<String>().error("充电订单 SOC 异常!");
|
||||||
|
}
|
||||||
|
// 计算 SOC
|
||||||
|
BigDecimal socDifference = new BigDecimal(statusData.getRentBatSoc() - statusData.getReturnBatSoc());
|
||||||
|
fee = order.getServiceFee().add(order.getBasicFee().multiply(socDifference)).setScale(0, RoundingMode.HALF_UP);
|
||||||
|
order.setElectAmount(socDifference);
|
||||||
|
}else {
|
||||||
|
return new Result<String>().error("此订单不是按照电量计算");
|
||||||
|
}
|
||||||
// 4. 修改订单
|
// 4. 修改订单
|
||||||
|
|
||||||
order.setAmount(fee.intValue());
|
order.setAmount(fee.intValue());
|
||||||
order.setStatus(6);
|
order.setStatus(6);
|
||||||
orderSwapBatteryDao.updateById(order);
|
orderSwapBatteryDao.updateById(order);
|
||||||
log.info("订单费用计算完成:{}", JSONUtil.parseObj(order));
|
log.info("订单费用计算完成:{}", JSONUtil.parseObj(order));
|
||||||
gzhTemplateMessageService.orderMessageSend2(order.getPkId(),2);
|
gzhTemplateMessageService.orderMessageSend2(order.getPkId(),2);
|
||||||
return new Result<String>().success(fee);
|
return new Result<String>().success(fee);
|
||||||
}else {
|
|
||||||
return new Result<String>().error("此订单不是按照电量计算");
|
|
||||||
}
|
}
|
||||||
|
|
||||||
}
|
|
||||||
|
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
|
|||||||
@ -4,6 +4,10 @@ import java.util.Date;
|
|||||||
import java.util.List;
|
import java.util.List;
|
||||||
|
|
||||||
import cn.hutool.json.JSONUtil;
|
import cn.hutool.json.JSONUtil;
|
||||||
|
import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper;
|
||||||
|
import com.evotech.hd.cloud.service.newthread.GZHTemplateMessageService;
|
||||||
|
import com.evotech.hd.common.core.dao.cloud.OrderSwapBatteryDao;
|
||||||
|
import com.evotech.hd.common.core.entity.cloud.OrderSwapBattery;
|
||||||
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.StringUtils;
|
import org.springframework.util.StringUtils;
|
||||||
@ -28,8 +32,10 @@ public class TradeServiceImpl implements TradeService {
|
|||||||
private TradeDetailDao tradeDetailDao;
|
private TradeDetailDao tradeDetailDao;
|
||||||
@Resource
|
@Resource
|
||||||
private WechatPayNotifyHandleService payNotifyHandleService;
|
private WechatPayNotifyHandleService payNotifyHandleService;
|
||||||
|
@Resource
|
||||||
|
private GZHTemplateMessageService gzhTemplateMessageService;
|
||||||
|
@Resource
|
||||||
|
private OrderSwapBatteryDao orderSwapBatteryDao;
|
||||||
@Override
|
@Override
|
||||||
public Result<Integer> add(TradeDetail td) {
|
public Result<Integer> add(TradeDetail td) {
|
||||||
td.setCtime(new Date());
|
td.setCtime(new Date());
|
||||||
@ -91,6 +97,7 @@ public class TradeServiceImpl implements TradeService {
|
|||||||
log.info("\r\n===>>>已处理过此回调:" + tradeDetail);
|
log.info("\r\n===>>>已处理过此回调:" + tradeDetail);
|
||||||
return new Result<String>().error("重复消息!");
|
return new Result<String>().error("重复消息!");
|
||||||
}
|
}
|
||||||
|
|
||||||
// 添加交易
|
// 添加交易
|
||||||
log.info("请求时间{} 是否存在交易{} 添加交易>>>>>{}" ,new Date() ,b, JSONUtil.toJsonStr(tradeDetail));
|
log.info("请求时间{} 是否存在交易{} 添加交易>>>>>{}" ,new Date() ,b, JSONUtil.toJsonStr(tradeDetail));
|
||||||
add(tradeDetail);
|
add(tradeDetail);
|
||||||
|
|||||||
@ -72,7 +72,6 @@ public class VehicleServiceImpl implements VehicleService {
|
|||||||
.eq(StringUtils.hasText(plvr.getFrameworkNo()), "framework_no", plvr.getFrameworkNo())
|
.eq(StringUtils.hasText(plvr.getFrameworkNo()), "framework_no", plvr.getFrameworkNo())
|
||||||
.eq(StringUtils.hasText(plvr.getPhone()), "phone", plvr.getPhone())
|
.eq(StringUtils.hasText(plvr.getPhone()), "phone", plvr.getPhone())
|
||||||
.eq(StringUtils.hasText(plvr.getCcode()), "ccode", plvr.getCcode())
|
.eq(StringUtils.hasText(plvr.getCcode()), "ccode", plvr.getCcode())
|
||||||
.eq(StringUtils.hasText(plvr.getProxyOperaterId()), "proxy_operater_id", plvr.getProxyOperaterId())
|
|
||||||
.ne("del_flag", 1)
|
.ne("del_flag", 1)
|
||||||
.orderByAsc("plate_num"));
|
.orderByAsc("plate_num"));
|
||||||
if (page.getRecords().isEmpty()) {
|
if (page.getRecords().isEmpty()) {
|
||||||
|
|||||||
@ -4,13 +4,16 @@ import java.util.Date;
|
|||||||
import java.util.HashMap;
|
import java.util.HashMap;
|
||||||
import java.util.List;
|
import java.util.List;
|
||||||
import java.util.Map;
|
import java.util.Map;
|
||||||
|
import java.util.stream.Collectors;
|
||||||
|
|
||||||
|
import cn.hutool.core.bean.BeanUtil;
|
||||||
import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper;
|
import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper;
|
||||||
import com.evotech.hd.cloud.dao.CompanyDao;
|
import com.evotech.hd.cloud.dao.CompanyDao;
|
||||||
import com.evotech.hd.cloud.dao.TradeDetailDao;
|
import com.evotech.hd.cloud.dao.TradeDetailDao;
|
||||||
import com.evotech.hd.common.core.dao.wechat.WechatUserDao;
|
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.cloud.Company;
|
||||||
import com.evotech.hd.common.core.entity.cloud.TradeDetail;
|
import com.evotech.hd.common.core.entity.cloud.TradeDetail;
|
||||||
|
import com.evotech.hd.common.core.entity.cloud.vo.WalletAccountVO;
|
||||||
import com.evotech.hd.common.core.entity.wechat.WechatPayAttach;
|
import com.evotech.hd.common.core.entity.wechat.WechatPayAttach;
|
||||||
import com.evotech.hd.common.core.entity.wechat.WechatUser;
|
import com.evotech.hd.common.core.entity.wechat.WechatUser;
|
||||||
import org.springframework.stereotype.Service;
|
import org.springframework.stereotype.Service;
|
||||||
@ -126,7 +129,7 @@ public class WalletAccountServiceImpl implements WalletAccountService {
|
|||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public Result<List<WalletAccount>> list(PageListWalletRequest plwr) {
|
public Result<List<WalletAccountVO>> list(PageListWalletRequest plwr) {
|
||||||
Page<WalletAccount> page = new Page<WalletAccount>(plwr.getPageNo(), plwr.getPageSize());
|
Page<WalletAccount> page = new Page<WalletAccount>(plwr.getPageNo(), plwr.getPageSize());
|
||||||
|
|
||||||
page = walletAccountDao.selectPage(page, new QueryWrapper<WalletAccount>()
|
page = walletAccountDao.selectPage(page, new QueryWrapper<WalletAccount>()
|
||||||
@ -135,12 +138,37 @@ public class WalletAccountServiceImpl implements WalletAccountService {
|
|||||||
.eq(plwr.getOwnerType() != null, "owner_type", plwr.getOwnerType())
|
.eq(plwr.getOwnerType() != null, "owner_type", plwr.getOwnerType())
|
||||||
.eq(StringUtils.hasText(plwr.getOwnerId()), "owner_id", plwr.getOwnerId())
|
.eq(StringUtils.hasText(plwr.getOwnerId()), "owner_id", plwr.getOwnerId())
|
||||||
.orderByDesc("pk_id"));
|
.orderByDesc("pk_id"));
|
||||||
//获取交易明细对应的微信用户
|
|
||||||
|
|
||||||
if (page.getRecords().isEmpty()) {
|
if (page.getRecords().isEmpty()) {
|
||||||
return new Result<List<WalletAccount>>().error(CodeMsg.DATABASE_RESULT_NULL);
|
return new Result<List<WalletAccountVO>>().error(CodeMsg.DATABASE_RESULT_NULL);
|
||||||
}
|
}
|
||||||
return new Result<List<WalletAccount>>().success(page);
|
// 2. 转换为VO并查询用户信息
|
||||||
|
List<WalletAccountVO> voList = page.getRecords().stream().map(account -> {
|
||||||
|
WalletAccountVO vo = new WalletAccountVO();
|
||||||
|
// 复制基本属性
|
||||||
|
BeanUtil.copyProperties(account, vo);
|
||||||
|
// 查询微信用户信息
|
||||||
|
if (StringUtils.hasText(account.getOwnerId())) {
|
||||||
|
WechatUser wechatUser = wechatUserDao.selectOne(
|
||||||
|
new QueryWrapper<WechatUser>()
|
||||||
|
.eq("wuid", account.getOwnerId())
|
||||||
|
);
|
||||||
|
if (wechatUser != null) {
|
||||||
|
vo.setAccName(wechatUser.getName());
|
||||||
|
vo.setPhone(wechatUser.getPhoneNumber());
|
||||||
|
}
|
||||||
|
}
|
||||||
|
return vo;
|
||||||
|
|
||||||
|
}).collect(Collectors.toList());
|
||||||
|
|
||||||
|
// 3. 创建新的分页对象
|
||||||
|
Page<WalletAccountVO> voPage = new Page<>();
|
||||||
|
BeanUtil.copyProperties(page, voPage, "records");
|
||||||
|
voPage.setRecords(voList);
|
||||||
|
|
||||||
|
|
||||||
|
return new Result<List<WalletAccountVO>>().success(voPage);
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
|
|||||||
@ -1,26 +1,36 @@
|
|||||||
package com.evotech.hd.cloud.task;
|
package com.evotech.hd.cloud.task;
|
||||||
|
|
||||||
|
import cn.hutool.core.collection.CollectionUtil;
|
||||||
|
import cn.hutool.core.date.DateUnit;
|
||||||
import cn.hutool.core.date.DateUtil;
|
import cn.hutool.core.date.DateUtil;
|
||||||
import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
|
import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
|
||||||
import com.evotech.hd.cloud.dao.OrderSwapBatteryPreDao;
|
import com.evotech.hd.cloud.dao.OrderSwapBatteryPreDao;
|
||||||
import com.evotech.hd.cloud.service.OrderSwapBatteryService;
|
import com.evotech.hd.cloud.service.OrderSwapBatteryService;
|
||||||
|
import com.evotech.hd.cloud.service.newthread.GZHTemplateMessageService;
|
||||||
import com.evotech.hd.common.core.dao.cloud.OrderSwapBatteryDao;
|
import com.evotech.hd.common.core.dao.cloud.OrderSwapBatteryDao;
|
||||||
import com.evotech.hd.common.core.entity.cloud.OrderSwapBattery;
|
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.OrderSwapBatteryPre;
|
||||||
|
import com.evotech.hd.common.redis.utils.RedisUtil;
|
||||||
import jakarta.annotation.Resource;
|
import jakarta.annotation.Resource;
|
||||||
import lombok.extern.slf4j.Slf4j;
|
import lombok.extern.slf4j.Slf4j;
|
||||||
import org.springframework.data.redis.core.RedisTemplate;
|
import org.springframework.data.redis.core.RedisTemplate;
|
||||||
import org.springframework.scheduling.annotation.Scheduled;
|
import org.springframework.scheduling.annotation.Scheduled;
|
||||||
import org.springframework.stereotype.Component;
|
import org.springframework.stereotype.Component;
|
||||||
|
|
||||||
|
import java.util.Collections;
|
||||||
import java.util.Date;
|
import java.util.Date;
|
||||||
import java.util.List;
|
import java.util.List;
|
||||||
|
import java.util.Set;
|
||||||
|
|
||||||
@Component
|
@Component
|
||||||
@Slf4j
|
@Slf4j
|
||||||
public class OrderSwapBatteryTask {
|
public class OrderSwapBatteryTask {
|
||||||
@Resource
|
@Resource
|
||||||
private OrderSwapBatteryPreDao orderSwapBatteryPreDao;
|
private OrderSwapBatteryPreDao orderSwapBatteryPreDao;
|
||||||
|
@Resource
|
||||||
|
private GZHTemplateMessageService templateMessageService;
|
||||||
|
@Resource
|
||||||
|
private RedisUtil redisUtil;
|
||||||
|
|
||||||
@Scheduled(cron = "0 0 * * * ?") // 每小时执行一次
|
@Scheduled(cron = "0 0 * * * ?") // 每小时执行一次
|
||||||
public void orderSwapBatteryExpired() {
|
public void orderSwapBatteryExpired() {
|
||||||
@ -59,4 +69,45 @@ public class OrderSwapBatteryTask {
|
|||||||
log.info("\r\n===>>> 预约单过期:{} 条数据", expiredCount);
|
log.info("\r\n===>>> 预约单过期:{} 条数据", expiredCount);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// 每5分钟检查一次即将过期的预约单
|
||||||
|
@Scheduled(cron = "0 */5 * * * ?")
|
||||||
|
public void checkExpiringPreOrders() {
|
||||||
|
log.info("\r\n===>>> 开始检查即将过期的预约单..");
|
||||||
|
|
||||||
|
// 获取当前时间
|
||||||
|
Date currentTime = new Date();
|
||||||
|
int reminderCount = 0;
|
||||||
|
|
||||||
|
// 获取所有需要检查的预约单
|
||||||
|
Set<String> keys = redisUtil.keys("preorder:expire:*");
|
||||||
|
// 检查是否有未发送提醒的标记
|
||||||
|
if (CollectionUtil.isEmpty(keys)) {
|
||||||
|
log.info("没有需要提醒的预约单");
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
for (String key : keys) {
|
||||||
|
try {
|
||||||
|
String id = key.substring(key.lastIndexOf(":") + 1);
|
||||||
|
OrderSwapBatteryPre order = orderSwapBatteryPreDao.selectById(id);
|
||||||
|
if (order != null && order.getStatus() == 1) { // 只处理状态为1的预约单
|
||||||
|
// 获取过期时间
|
||||||
|
Date expireTime = (Date) redisUtil.get(key);
|
||||||
|
// 如果当前时间接近过期时间(5分钟内)
|
||||||
|
if (expireTime != null && DateUtil.between(currentTime, expireTime, DateUnit.MINUTE) <= 5) {
|
||||||
|
// 发送微信公众号提醒
|
||||||
|
templateMessageService.preOrderMessageSend(order);
|
||||||
|
reminderCount++;
|
||||||
|
// 从Redis中删除该预约单
|
||||||
|
redisUtil.del(key);
|
||||||
|
log.info("发送微信公众号即将过期提醒,预约人:{},订单ID: {}", order.getUname(), order.getPkId());
|
||||||
|
}
|
||||||
|
}
|
||||||
|
} catch (Exception e) {
|
||||||
|
log.error("处理预约单提醒失败,key: {}, 错误信息: {}", key, e.getMessage());
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
log.info("\r\n===>>> 发送微信公众号即将过期提醒:{} 条数据", reminderCount);
|
||||||
|
}
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@ -54,19 +54,19 @@ public class SwapOrderBasicFeeComponent {
|
|||||||
log.info("当前时间在费用详情有效时间范围内=====>:{}", JSONUtil.toJsonStr(detail));
|
log.info("当前时间在费用详情有效时间范围内=====>:{}", JSONUtil.toJsonStr(detail));
|
||||||
// 设置基本费用和服务费用
|
// 设置基本费用和服务费用
|
||||||
osb.setFeeStandardJson(JSONUtil.toJsonStr(detail));
|
osb.setFeeStandardJson(JSONUtil.toJsonStr(detail));
|
||||||
osb.setBasicFee(detail.getEachKwhFee());
|
osb.setBasicFee(detail.getEachSocFee());
|
||||||
osb.setServiceFee(detail.getTimeServiceFee());
|
osb.setServiceFee(detail.getTimeServiceFee());
|
||||||
} else {
|
} else {
|
||||||
// 如果没有有效的详细费用,使用标准费用
|
// 如果没有有效的详细费用,使用标准费用
|
||||||
osb.setFeeStandardJson(JSONUtil.toJsonStr(standard));
|
osb.setFeeStandardJson(JSONUtil.toJsonStr(standard));
|
||||||
osb.setBasicFee(standard.getEachKwhFee());
|
osb.setBasicFee(standard.getEachSocFee());
|
||||||
osb.setServiceFee(standard.getCommonRemainFee());
|
osb.setServiceFee(standard.getCommonRemainFee());
|
||||||
}
|
}
|
||||||
} else {
|
} else {
|
||||||
osb.setFeeStandardJson(JSONUtil.toJsonStr(standard));
|
osb.setFeeStandardJson(JSONUtil.toJsonStr(standard));
|
||||||
// 如果没有详细费用,直接使用标准费用
|
// 如果没有详细费用,直接使用标准费用
|
||||||
log.info("没有详细费用,直接使用标准费用=====>:{}", JSONUtil.toJsonStr(standard));
|
log.info("没有详细费用,直接使用标准费用=====>:{}", JSONUtil.toJsonStr(standard));
|
||||||
osb.setBasicFee(standard.getEachKwhFee());
|
osb.setBasicFee(standard.getEachSocFee());
|
||||||
osb.setServiceFee(standard.getCommonRemainFee());
|
osb.setServiceFee(standard.getCommonRemainFee());
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@ -6,6 +6,7 @@ import java.util.Map;
|
|||||||
import java.util.concurrent.CompletableFuture;
|
import java.util.concurrent.CompletableFuture;
|
||||||
import java.util.stream.Collectors;
|
import java.util.stream.Collectors;
|
||||||
|
|
||||||
|
import lombok.extern.slf4j.Slf4j;
|
||||||
import org.springframework.beans.factory.annotation.Value;
|
import org.springframework.beans.factory.annotation.Value;
|
||||||
import org.springframework.http.HttpMethod;
|
import org.springframework.http.HttpMethod;
|
||||||
import org.springframework.http.server.reactive.ServerHttpRequest;
|
import org.springframework.http.server.reactive.ServerHttpRequest;
|
||||||
@ -35,6 +36,7 @@ import reactor.core.publisher.Mono;
|
|||||||
* 资源服务的权限管理器
|
* 资源服务的权限管理器
|
||||||
* 鉴权时统一抛出OAuth2AuthorizationException
|
* 鉴权时统一抛出OAuth2AuthorizationException
|
||||||
*/
|
*/
|
||||||
|
@Slf4j
|
||||||
@Component
|
@Component
|
||||||
public class AuthorizationManager implements ReactiveAuthorizationManager<AuthorizationContext> {
|
public class AuthorizationManager implements ReactiveAuthorizationManager<AuthorizationContext> {
|
||||||
|
|
||||||
@ -104,6 +106,7 @@ public class AuthorizationManager implements ReactiveAuthorizationManager<Author
|
|||||||
}
|
}
|
||||||
// 验证wuid
|
// 验证wuid
|
||||||
if (!redisUtil.hasKey(HDConstant.openidPrefix + wuid)) {
|
if (!redisUtil.hasKey(HDConstant.openidPrefix + wuid)) {
|
||||||
|
log.error("验证wuid===============>"+HDConstant.openidPrefix + wuid);
|
||||||
throw new OAuth2AuthorizationException(new OAuth2Error(CodeMsg.WECHAT_LOGIN_ERROR.getCode(), CodeMsg.WECHAT_LOGIN_ERROR.getMsg(), uri));
|
throw new OAuth2AuthorizationException(new OAuth2Error(CodeMsg.WECHAT_LOGIN_ERROR.getCode(), CodeMsg.WECHAT_LOGIN_ERROR.getMsg(), uri));
|
||||||
}
|
}
|
||||||
// 验证token正确
|
// 验证token正确
|
||||||
@ -120,6 +123,7 @@ public class AuthorizationManager implements ReactiveAuthorizationManager<Author
|
|||||||
m = asyncRes.get();
|
m = asyncRes.get();
|
||||||
} catch (Exception e) {
|
} catch (Exception e) {
|
||||||
e.printStackTrace();
|
e.printStackTrace();
|
||||||
|
log.error("token获取异常=================>"+asyncRes);
|
||||||
throw new OAuth2AuthorizationException(new OAuth2Error(CodeMsg.WECHAT_LOGIN_ERROR.getCode(), CodeMsg.WECHAT_LOGIN_ERROR.getMsg(), "token异常"));
|
throw new OAuth2AuthorizationException(new OAuth2Error(CodeMsg.WECHAT_LOGIN_ERROR.getCode(), CodeMsg.WECHAT_LOGIN_ERROR.getMsg(), "token异常"));
|
||||||
}
|
}
|
||||||
throw new OAuth2AuthorizationException(new OAuth2Error(CodeMsg.WECHAT_TOKEN_EXPIRED.getCode(), CodeMsg.WECHAT_TOKEN_EXPIRED.getMsg(), JSONUtil.toJsonStr(m)));
|
throw new OAuth2AuthorizationException(new OAuth2Error(CodeMsg.WECHAT_TOKEN_EXPIRED.getCode(), CodeMsg.WECHAT_TOKEN_EXPIRED.getMsg(), JSONUtil.toJsonStr(m)));
|
||||||
|
|||||||
@ -78,6 +78,7 @@ public class WechatAuthorizationManager implements ReactiveAuthorizationManager<
|
|||||||
}
|
}
|
||||||
// 验证wuid
|
// 验证wuid
|
||||||
if (!redisUtil.hasKey(HDConstant.openidPrefix + wuid)) {
|
if (!redisUtil.hasKey(HDConstant.openidPrefix + wuid)) {
|
||||||
|
log.error("-验证wiud***===================>"+HDConstant.openidPrefix + wuid);
|
||||||
throw new OAuth2AuthorizationException(new OAuth2Error(CodeMsg.WECHAT_LOGIN_ERROR.getCode(), CodeMsg.WECHAT_LOGIN_ERROR.getMsg(), uri));
|
throw new OAuth2AuthorizationException(new OAuth2Error(CodeMsg.WECHAT_LOGIN_ERROR.getCode(), CodeMsg.WECHAT_LOGIN_ERROR.getMsg(), uri));
|
||||||
}
|
}
|
||||||
// 验证token正确
|
// 验证token正确
|
||||||
@ -98,6 +99,7 @@ public class WechatAuthorizationManager implements ReactiveAuthorizationManager<
|
|||||||
log.error("\r\n---777---" + m);
|
log.error("\r\n---777---" + m);
|
||||||
} catch (Exception e) {
|
} catch (Exception e) {
|
||||||
e.printStackTrace();
|
e.printStackTrace();
|
||||||
|
log.error("-验证wiud*21**===================>"+asyncRes);
|
||||||
throw new OAuth2AuthorizationException(new OAuth2Error(CodeMsg.WECHAT_LOGIN_ERROR.getCode(), CodeMsg.WECHAT_LOGIN_ERROR.getMsg(), "token异常"));
|
throw new OAuth2AuthorizationException(new OAuth2Error(CodeMsg.WECHAT_LOGIN_ERROR.getCode(), CodeMsg.WECHAT_LOGIN_ERROR.getMsg(), "token异常"));
|
||||||
}
|
}
|
||||||
throw new OAuth2AuthorizationException(new OAuth2Error(CodeMsg.WECHAT_TOKEN_EXPIRED.getCode(), CodeMsg.WECHAT_TOKEN_EXPIRED.getMsg(), JSONUtil.toJsonStr(m)));
|
throw new OAuth2AuthorizationException(new OAuth2Error(CodeMsg.WECHAT_TOKEN_EXPIRED.getCode(), CodeMsg.WECHAT_TOKEN_EXPIRED.getMsg(), JSONUtil.toJsonStr(m)));
|
||||||
|
|||||||
@ -31,4 +31,6 @@ public class GZHProperties {
|
|||||||
private String orderEndTemplateId;
|
private String orderEndTemplateId;
|
||||||
|
|
||||||
private String WalletRechargeTemplateId;
|
private String WalletRechargeTemplateId;
|
||||||
|
|
||||||
|
private String orderToPayTemplateId2;
|
||||||
}
|
}
|
||||||
|
|||||||
@ -0,0 +1,63 @@
|
|||||||
|
package com.evotech.hd.wechat.entity.gzh.templatemessage;
|
||||||
|
|
||||||
|
import cn.hutool.json.JSONObject;
|
||||||
|
import lombok.Getter;
|
||||||
|
/**
|
||||||
|
* 充电完成SOC 模板消息 关键词
|
||||||
|
*/
|
||||||
|
@Getter
|
||||||
|
public class ChargeTemplateData2 {
|
||||||
|
/*
|
||||||
|
订单编号
|
||||||
|
*/
|
||||||
|
private JSONObject character_string2;
|
||||||
|
/*
|
||||||
|
耗电量
|
||||||
|
*/
|
||||||
|
private JSONObject number15;
|
||||||
|
/*
|
||||||
|
车牌号码
|
||||||
|
*/
|
||||||
|
private JSONObject car_number8;
|
||||||
|
/*
|
||||||
|
充电服务费
|
||||||
|
*/
|
||||||
|
private JSONObject thing34;
|
||||||
|
/*
|
||||||
|
消费金额
|
||||||
|
|
||||||
|
*/
|
||||||
|
private JSONObject amount5;
|
||||||
|
|
||||||
|
|
||||||
|
public void setCharacter_string2(String value1) {
|
||||||
|
JSONObject jo = new JSONObject();
|
||||||
|
jo.set("value", value1);
|
||||||
|
this.character_string2 = jo;
|
||||||
|
}
|
||||||
|
|
||||||
|
public void setNumber15(String value2) {
|
||||||
|
JSONObject jo = new JSONObject();
|
||||||
|
jo.set("value", value2);
|
||||||
|
this.number15 = jo;
|
||||||
|
}
|
||||||
|
|
||||||
|
public void setCar_number8(String value3) {
|
||||||
|
JSONObject jo = new JSONObject();
|
||||||
|
jo.set("value", value3);
|
||||||
|
this.car_number8 = jo;
|
||||||
|
}
|
||||||
|
|
||||||
|
public void setThing34(String value4) {
|
||||||
|
JSONObject jo = new JSONObject();
|
||||||
|
jo.set("value", value4);
|
||||||
|
this.thing34 = jo;
|
||||||
|
}
|
||||||
|
|
||||||
|
public void setAmount5(String value5) {
|
||||||
|
JSONObject jo = new JSONObject();
|
||||||
|
jo.set("value", value5);
|
||||||
|
this.amount5 = jo;
|
||||||
|
}
|
||||||
|
|
||||||
|
}
|
||||||
@ -128,7 +128,7 @@ public class GZHMessageTemplateService {
|
|||||||
log.info("付款完成推送公众号消息=======>:{}", JSONUtil.parseObj(data));
|
log.info("付款完成推送公众号消息=======>:{}", JSONUtil.parseObj(data));
|
||||||
sendData.setData(JSONUtil.parseObj(data));
|
sendData.setData(JSONUtil.parseObj(data));
|
||||||
break;
|
break;
|
||||||
// 充电完成,待结算
|
/* // 充电完成,待结算
|
||||||
case 2:
|
case 2:
|
||||||
templateId = gzhProperties.getOrderToPayTemplateId();
|
templateId = gzhProperties.getOrderToPayTemplateId();
|
||||||
miniprogram.setPath(orderPage);
|
miniprogram.setPath(orderPage);
|
||||||
@ -136,10 +136,24 @@ public class GZHMessageTemplateService {
|
|||||||
chargeData.setCharacter_string14(osb.getOrderNo());
|
chargeData.setCharacter_string14(osb.getOrderNo());
|
||||||
chargeData.setCharacter_string31(osb.getReturnBatCode());
|
chargeData.setCharacter_string31(osb.getReturnBatCode());
|
||||||
chargeData.setCharacter_string25(osb.getElectAmount() + "");
|
chargeData.setCharacter_string25(osb.getElectAmount() + "");
|
||||||
chargeData.setAmount34(osb.getServiceFee() != null ? osb.getServiceFee().divide(new BigDecimal(100), 2, BigDecimal.ROUND_HALF_DOWN).setScale(2, RoundingMode.HALF_EVEN).toString().toString() : "");
|
chargeData.setAmount34(osb.getServiceFee() != null ? osb.getServiceFee().divide(new BigDecimal(100), 2, BigDecimal.ROUND_HALF_DOWN).setScale(2, RoundingMode.HALF_EVEN).toString() : "");
|
||||||
chargeData.setAmount28(osb.getAmount() != null ? new BigDecimal(osb.getAmount()).divide(new BigDecimal(100), 2, BigDecimal.ROUND_HALF_DOWN).setScale(2, RoundingMode.HALF_EVEN).toString(): "");
|
chargeData.setAmount28(osb.getAmount() != null ? new BigDecimal(osb.getAmount()).divide(new BigDecimal(100), 2, BigDecimal.ROUND_HALF_DOWN).setScale(2, RoundingMode.HALF_EVEN).toString(): "");
|
||||||
log.info("付款完成推送公众号消息=======>:{}", JSONUtil.parseObj(chargeData));
|
log.info("付款完成推送公众号消息=======>:{}", JSONUtil.parseObj(chargeData));
|
||||||
sendData.setData(JSONUtil.parseObj(chargeData));
|
sendData.setData(JSONUtil.parseObj(chargeData));
|
||||||
|
break;*/
|
||||||
|
// 充电完成,待结算(新模版SOC)
|
||||||
|
case 2:
|
||||||
|
templateId = gzhProperties.getOrderToPayTemplateId2();
|
||||||
|
miniprogram.setPath(orderPage);
|
||||||
|
ChargeTemplateData2 chargeData2 = new ChargeTemplateData2();
|
||||||
|
chargeData2.setCharacter_string2(osb.getOrderNo());
|
||||||
|
String soc = String.valueOf(osb.getRentBatSoc()- osb.getReturnBatSoc());
|
||||||
|
chargeData2.setNumber15(soc);
|
||||||
|
chargeData2.setCar_number8(osb.getPlateNum());
|
||||||
|
chargeData2.setThing34(osb.getStationName());
|
||||||
|
chargeData2.setAmount5(osb.getAmount() != null ? new BigDecimal(osb.getAmount()).divide(new BigDecimal(100), 2, BigDecimal.ROUND_HALF_DOWN).setScale(2, RoundingMode.HALF_EVEN).toString(): "");
|
||||||
|
log.info("付款完成推送公众号消息=======>:{}", JSONUtil.parseObj(chargeData2));
|
||||||
|
sendData.setData(JSONUtil.parseObj(chargeData2));
|
||||||
break;
|
break;
|
||||||
// 付款完成
|
// 付款完成
|
||||||
case 3:
|
case 3:
|
||||||
@ -154,6 +168,9 @@ public class GZHMessageTemplateService {
|
|||||||
log.info("付款完成推送公众号消息=======>:{}", JSONUtil.parseObj(payData));
|
log.info("付款完成推送公众号消息=======>:{}", JSONUtil.parseObj(payData));
|
||||||
sendData.setData(JSONUtil.parseObj(payData));
|
sendData.setData(JSONUtil.parseObj(payData));
|
||||||
break;
|
break;
|
||||||
|
//预约即将失效
|
||||||
|
case 4:
|
||||||
|
break;
|
||||||
default:
|
default:
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
|
|||||||
@ -4,6 +4,7 @@ import java.util.Date;
|
|||||||
import java.util.HashMap;
|
import java.util.HashMap;
|
||||||
import java.util.Map;
|
import java.util.Map;
|
||||||
|
|
||||||
|
import lombok.extern.slf4j.Slf4j;
|
||||||
import org.springframework.beans.factory.annotation.Value;
|
import org.springframework.beans.factory.annotation.Value;
|
||||||
import org.springframework.stereotype.Service;
|
import org.springframework.stereotype.Service;
|
||||||
import org.springframework.util.ObjectUtils;
|
import org.springframework.util.ObjectUtils;
|
||||||
@ -32,6 +33,7 @@ import cn.hutool.json.JSONObject;
|
|||||||
import cn.hutool.json.JSONUtil;
|
import cn.hutool.json.JSONUtil;
|
||||||
import jakarta.annotation.Resource;
|
import jakarta.annotation.Resource;
|
||||||
|
|
||||||
|
@Slf4j
|
||||||
@Service
|
@Service
|
||||||
public class LoginServiceImpl implements LoginService {
|
public class LoginServiceImpl implements LoginService {
|
||||||
|
|
||||||
@ -57,6 +59,7 @@ public class LoginServiceImpl implements LoginService {
|
|||||||
String res = LoginUtil.code2Session(xcxProperties.getAppid(), xcxProperties.getAppSecret(), js_code);
|
String res = LoginUtil.code2Session(xcxProperties.getAppid(), xcxProperties.getAppSecret(), js_code);
|
||||||
JSONObject jo = JSONUtil.parseObj(res);
|
JSONObject jo = JSONUtil.parseObj(res);
|
||||||
if (StringUtils.hasText(jo.getStr("errcode"))) {
|
if (StringUtils.hasText(jo.getStr("errcode"))) {
|
||||||
|
log.error("微信登陆失败=================>:{}", jo);
|
||||||
return new Result<Map<String, String>>().error(CodeMsg.WECHAT_LOGIN_ERROR, jo);
|
return new Result<Map<String, String>>().error(CodeMsg.WECHAT_LOGIN_ERROR, jo);
|
||||||
}
|
}
|
||||||
String openid = jo.getStr("openid");
|
String openid = jo.getStr("openid");
|
||||||
|
|||||||
@ -75,9 +75,9 @@ public class OrderServiceImpl implements OrderService {
|
|||||||
|
|
||||||
@Override
|
@Override
|
||||||
public Result<Boolean> startSwap(String wuid ,String orderId ) throws Exception {
|
public Result<Boolean> startSwap(String wuid ,String orderId ) throws Exception {
|
||||||
if (!wuid.equals(request.getHeader(HDConstant.WECHAT_SERVER_AUTHORIZATION_KEY))) {
|
/*if (!wuid.equals(request.getHeader(HDConstant.WECHAT_SERVER_AUTHORIZATION_KEY))) {
|
||||||
throw new Exception("账号错误");
|
throw new Exception("账号错误");
|
||||||
}
|
}*/
|
||||||
return cloudService.startSwap(wuid,orderId);
|
return cloudService.startSwap(wuid,orderId);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
@ -104,7 +104,14 @@ public class WechatPayServiceImpl implements WechatPayService {
|
|||||||
prePay.setAttach(JSONUtil.toJsonStr(entries.set("walletCode", split[1])));
|
prePay.setAttach(JSONUtil.toJsonStr(entries.set("walletCode", split[1])));
|
||||||
|
|
||||||
}
|
}
|
||||||
|
//判断是充值订单还是订单支付
|
||||||
|
if (!StringUtils.hasText(entries.getStr("type"))){
|
||||||
|
String type = entries.getStr("type");
|
||||||
|
if (StringUtils.hasText(type) && type.equals("1")) {
|
||||||
|
// 充值订单
|
||||||
|
|
||||||
|
}
|
||||||
|
}
|
||||||
WechatPayPreOrder preOrder = new WechatPayPreOrder();
|
WechatPayPreOrder preOrder = new WechatPayPreOrder();
|
||||||
// 组装数据
|
// 组装数据
|
||||||
PrepayRequest request = new PrepayRequest();
|
PrepayRequest request = new PrepayRequest();
|
||||||
@ -147,9 +154,8 @@ public class WechatPayServiceImpl implements WechatPayService {
|
|||||||
preOrder.setDeviceId(prePay.getDeviceId());
|
preOrder.setDeviceId(prePay.getDeviceId());
|
||||||
}
|
}
|
||||||
PrepayWithRequestPaymentResponse response = WechatPayUtil.jsapiPrepay(config, request);
|
PrepayWithRequestPaymentResponse response = WechatPayUtil.jsapiPrepay(config, request);
|
||||||
//判断是充值订单还是订单支付
|
|
||||||
|
|
||||||
// System.out.println("\r\n=====response>>>>>" + response);
|
|
||||||
// 写表
|
// 写表
|
||||||
BeanUtils.copyProperties(request, preOrder);
|
BeanUtils.copyProperties(request, preOrder);
|
||||||
wechatPayComponent.wechatPrePayLog(prePay.getWuid(), prePay.getCcode(), prePay.getCostPrice(), preOrder, JSONUtil.toJsonStr(response));
|
wechatPayComponent.wechatPrePayLog(prePay.getWuid(), prePay.getCcode(), prePay.getCostPrice(), preOrder, JSONUtil.toJsonStr(response));
|
||||||
|
|||||||
@ -74,9 +74,9 @@ public class WechatUserServiceImpl implements WechatUserService {
|
|||||||
|
|
||||||
@Override
|
@Override
|
||||||
public Result<Integer> openWallet(String wuid, HttpServletRequest request) {
|
public Result<Integer> openWallet(String wuid, HttpServletRequest request) {
|
||||||
if (!wuid.equals(request.getHeader(HDConstant.WECHAT_SERVER_AUTHORIZATION_KEY))) {
|
/*if (!wuid.equals(request.getHeader(HDConstant.WECHAT_SERVER_AUTHORIZATION_KEY))) {
|
||||||
return new Result<Integer>().error("账号错误");
|
return new Result<Integer>().error("账号错误");
|
||||||
}
|
}*/
|
||||||
WalletAccount wa = new WalletAccount();
|
WalletAccount wa = new WalletAccount();
|
||||||
wa.setOwnerType(1);
|
wa.setOwnerType(1);
|
||||||
wa.setOwnerId(wuid);
|
wa.setOwnerId(wuid);
|
||||||
@ -112,9 +112,9 @@ public class WechatUserServiceImpl implements WechatUserService {
|
|||||||
@Override
|
@Override
|
||||||
public Result<Boolean> isOpenAccount(String wuid, HttpServletRequest request) {
|
public Result<Boolean> isOpenAccount(String wuid, HttpServletRequest request) {
|
||||||
// 1. 从请求头获取 Token
|
// 1. 从请求头获取 Token
|
||||||
if (wuid == null || !wuid.equals(request.getHeader(HDConstant.WECHAT_SERVER_AUTHORIZATION_KEY))) {
|
/*if (wuid == null || !wuid.equals(request.getHeader(HDConstant.WECHAT_SERVER_AUTHORIZATION_KEY))) {
|
||||||
return new Result<Boolean>().error("账号错误!");
|
return new Result<Boolean>().error("账号错误!");
|
||||||
}
|
}*/
|
||||||
return cloudService.isOpenAccount(wuid);
|
return cloudService.isOpenAccount(wuid);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
Loading…
Reference in New Issue
Block a user