debug:订单流程优化(待测试)
This commit is contained in:
parent
d2085a4698
commit
f85e151b3b
|
@ -105,6 +105,7 @@ public class IotServiceImpl implements IotService {
|
|||
CommandResponse response = sendCommand(deviceName, IotConstants.COMMAND_OPEN, productId);
|
||||
IotHttpStatus status = IotHttpStatus.convertByCode(response.getCode());
|
||||
if (!IotHttpStatus.SUCCESS.equals(status)) {
|
||||
log.error("{}通电异常:{}", deviceName, status.getMsg());
|
||||
throw new ServiceException("通电发生异常:" + status.getMsg());
|
||||
}
|
||||
return true;
|
||||
|
@ -121,6 +122,7 @@ public class IotServiceImpl implements IotService {
|
|||
try {
|
||||
result = this.open(device.iotMac1(), device.getProductId());
|
||||
if (!result) {
|
||||
log.error("mac1通电失败:{}", device.iotMac1());
|
||||
throw new ServiceException("mac1通电失败");
|
||||
}
|
||||
} catch (Exception e) {
|
||||
|
@ -137,6 +139,7 @@ public class IotServiceImpl implements IotService {
|
|||
CommandResponse response = sendCommand(deviceName, IotConstants.COMMAND_CLOSE, productId);
|
||||
IotHttpStatus status = IotHttpStatus.convertByCode(response.getCode());
|
||||
if (!IotHttpStatus.SUCCESS.equals(status)) {
|
||||
log.error("断电发生异常:{}, {}", deviceName, status.getMsg());
|
||||
throw new ServiceException("断电发生异常:" + status.getMsg());
|
||||
}
|
||||
return true;
|
||||
|
|
|
@ -372,10 +372,10 @@ public interface DeviceService
|
|||
/**
|
||||
* 设置电量
|
||||
*/
|
||||
int setEle(DeviceVO device, BigDecimal ele);
|
||||
int setEle(DeviceVO device, BigDecimal ele, int tryCount);
|
||||
|
||||
/**
|
||||
* 设置剩余时间
|
||||
*/
|
||||
int setTime(DeviceVO device, long seconds);
|
||||
int setTime(DeviceVO device, long seconds, int tryCount);
|
||||
}
|
||||
|
|
|
@ -776,17 +776,22 @@ public class DeviceServiceImpl implements DeviceService
|
|||
}
|
||||
|
||||
@Override
|
||||
public int setEle(DeviceVO device, BigDecimal ele) {
|
||||
if (device == null || ele == null) {
|
||||
public int setEle(DeviceVO device, BigDecimal ele, int tryCount) {
|
||||
if (device == null || ele == null || tryCount <= 0) {
|
||||
log.error("设置电量失败:参数为空");
|
||||
return 0;
|
||||
}
|
||||
Integer result = transactionTemplate.execute(status -> {
|
||||
int update = this.updateSurplusEle(device.getDeviceId(), ele);
|
||||
ServiceUtil.assertion(update != 1, "更新设备数据失败");
|
||||
|
||||
CommandResponse res = iotService.setEle(device, ele);
|
||||
ServiceUtil.assertion(res == null, "发送命令失败:返回值为空");
|
||||
ServiceUtil.assertion(!res.isSuccess(), res.getMsg());
|
||||
CommandResponse res = iotService.trySetEle(device, ele, tryCount);
|
||||
if (res == null || !res.isSuccess()) {
|
||||
log.error("操作设备设置电量{}失败:{}", device.getDeviceId(), res);
|
||||
ServiceUtil.assertion(res == null, "充值电量失败");
|
||||
IotHttpStatus statusResult = IotHttpStatus.convertByCode(res.getCode());
|
||||
ServiceUtil.assertion(!res.isSuccess(), "充值电量失败:" + statusResult.getMsg());
|
||||
}
|
||||
|
||||
return update;
|
||||
});
|
||||
|
@ -795,8 +800,8 @@ public class DeviceServiceImpl implements DeviceService
|
|||
}
|
||||
|
||||
@Override
|
||||
public int setTime(DeviceVO device, long seconds) {
|
||||
return this.setTime(device, LocalDateTime.now().plusSeconds(seconds), true, 1);
|
||||
public int setTime(DeviceVO device, long seconds, int tryCount) {
|
||||
return this.setTime(device, LocalDateTime.now().plusSeconds(seconds), true, tryCount);
|
||||
}
|
||||
|
||||
private int updateSurplusEle(Long deviceId, BigDecimal ele) {
|
||||
|
|
|
@ -149,7 +149,7 @@ public class Store extends BaseEntity
|
|||
private Boolean show;
|
||||
|
||||
@ApiModelProperty("状态")
|
||||
@JsonView(JsonViewProfile.App.class)
|
||||
@JsonView({JsonViewProfile.App.class, StoreView.ListCount.class})
|
||||
private String status;
|
||||
|
||||
@ApiModelProperty("是否生效")
|
||||
|
|
|
@ -148,8 +148,9 @@ public interface TransactionBillService
|
|||
* 手动设备充值
|
||||
*
|
||||
* @param billId
|
||||
* @param tryCount
|
||||
*/
|
||||
boolean rechargeDevice(Long billId);
|
||||
boolean rechargeDevice(Long billId, int tryCount);
|
||||
|
||||
/**
|
||||
* 查询设备充值失败列表
|
||||
|
|
|
@ -124,13 +124,13 @@ public class RechargePayHandler implements AfterPay, AfterRefund {
|
|||
|
||||
// 操作成功
|
||||
if (result != null && result == 1) {
|
||||
// 充值设备,尝试1次
|
||||
transactionBillService.tryRechargeDevice(bill.getBillId(), 1);
|
||||
// 充值设备,尝试3次
|
||||
transactionBillService.rechargeDevice(bill.getBillId(), 3);
|
||||
|
||||
// 设备设置语音播报
|
||||
// 5秒后,设备设置语音播报
|
||||
scheduledExecutorService.schedule(() -> {
|
||||
transactionBillService.trySetVoice(bill, 3);
|
||||
}, 0, TimeUnit.SECONDS);
|
||||
}, 5, TimeUnit.SECONDS);
|
||||
}
|
||||
|
||||
return result == null ? 0 : result;
|
||||
|
|
|
@ -588,7 +588,7 @@ public class TransactionBillServiceImpl implements TransactionBillService, After
|
|||
}
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
// 判断今天提现成功和正在审核中的提现是否超过限额
|
||||
String dailyLimitStr = sysConfigService.selectConfigByKey(ConfigKey.DAILY_WITHDRAW_AMOUNT.getKey());
|
||||
String dailyLimitCountStr = sysConfigService.selectConfigByKey(ConfigKey.DAILY_WITHDRAW_COUNT.getKey());
|
||||
|
@ -886,10 +886,12 @@ public class TransactionBillServiceImpl implements TransactionBillService, After
|
|||
}
|
||||
|
||||
/**
|
||||
* 设备充值
|
||||
* 订单设备充值
|
||||
* @param billId 订单ID
|
||||
* @param tryCount 尝试次数
|
||||
*/
|
||||
@Override
|
||||
public boolean rechargeDevice(Long billId) {
|
||||
public boolean rechargeDevice(Long billId, int tryCount) {
|
||||
ServiceUtil.assertion(billId == null, "参数错误,billId不允许为空");
|
||||
// ServiceUtil.assertion(!redisLock.lock(RedisLockKey.RECHARGE_DEVICE, billId), "当前设备充值请求过于频繁,请等待");
|
||||
try {
|
||||
|
@ -906,18 +908,16 @@ public class TransactionBillServiceImpl implements TransactionBillService, After
|
|||
|
||||
// 设备开启状态描述
|
||||
AtomicReference<String> openMsg = new AtomicReference<>("成功");
|
||||
// 获取最新设备信息
|
||||
DeviceVO device = deviceService.selectById(bill.getDeviceId());
|
||||
deviceService.pullDeviceInfo(device);
|
||||
|
||||
Boolean result = transactionTemplate.execute(status -> {
|
||||
// 刷新设备数据
|
||||
deviceService.pullDeviceInfo(bill.getDeviceId());
|
||||
|
||||
DeviceVO device = deviceService.selectById(bill.getDeviceId());
|
||||
|
||||
// 更新套餐使用信息
|
||||
// 更新订单套餐使用信息
|
||||
int updateInfo = this.updateSuitInfoBeforeDevice(bill, device);
|
||||
ServiceUtil.assertion(updateInfo != 1, "更新套餐使用信息失败");
|
||||
|
||||
// 修改设备充值状态:成功
|
||||
// 更新订单设备充值状态:成功
|
||||
int updateRecharge = transactionBillMapper.updateDeviceRechargeStatus(
|
||||
bill.getBillId(),
|
||||
TransactionBillDeviceRechargeStatus.SUCCESS.getStatus(),
|
||||
|
@ -930,12 +930,12 @@ public class TransactionBillServiceImpl implements TransactionBillService, After
|
|||
if (SuitFeeType.TIME.getType().equals(bill.getSuitFeeType())) {
|
||||
// 设备设置时长
|
||||
long seconds = transactionBillConverter.toRechargeSeconds(bill);
|
||||
int setTime = deviceService.setTime(device, seconds);
|
||||
int setTime = deviceService.setTime(device, seconds, tryCount);
|
||||
ServiceUtil.assertion(setTime != 1, "设备时长充值失败");
|
||||
} else if (SuitFeeType.COUNT.getType().equals(bill.getSuitFeeType())) {
|
||||
// 设备设置电量
|
||||
BigDecimal ele = transactionBillConverter.toRechargeEle(bill);
|
||||
int setEle = deviceService.setEle(device, ele);
|
||||
int setEle = deviceService.setEle(device, ele, tryCount);
|
||||
ServiceUtil.assertion(setEle != 1, "设备时长充值失败");
|
||||
} else {
|
||||
throw new ServiceException("不支持的套餐类型");
|
||||
|
@ -973,7 +973,6 @@ public class TransactionBillServiceImpl implements TransactionBillService, After
|
|||
|
||||
/**
|
||||
* 在设备充值成功前,更新套餐使用信息
|
||||
* 开始时间 = 设备过期时间 - 套餐时间,过期时间 = 设备过期时间
|
||||
*/
|
||||
private int updateSuitInfoBeforeDevice(TransactionBillVO bill, DeviceVO device) {
|
||||
if (bill == null || device == null) {
|
||||
|
@ -1057,7 +1056,7 @@ public class TransactionBillServiceImpl implements TransactionBillService, After
|
|||
return;
|
||||
}
|
||||
try {
|
||||
boolean result = rechargeDevice(billId);
|
||||
boolean result = rechargeDevice(billId, 1);
|
||||
ServiceUtil.assertion(!result, String.format("尝试充值设备失败:billId=%s:剩余次数:%s,", billId, tryCount - 1));
|
||||
} catch (Exception e) {
|
||||
this.tryRechargeDevice(billId, tryCount - 1);
|
||||
|
|
|
@ -7,7 +7,6 @@ import com.ruoyi.common.core.domain.JsonViewProfile;
|
|||
import com.ruoyi.common.core.domain.ValidGroup;
|
||||
import com.ruoyi.common.core.domain.model.LoginUser;
|
||||
import com.ruoyi.common.core.page.TableDataInfo;
|
||||
import com.ruoyi.common.exception.ServiceException;
|
||||
import com.ruoyi.common.utils.DateUtils;
|
||||
import com.ruoyi.common.utils.ServiceUtil;
|
||||
import com.ruoyi.dashboard.domain.vo.BillCountVo;
|
||||
|
@ -365,7 +364,7 @@ public class AppTransactionBillController extends BaseController
|
|||
if (bill == null) {
|
||||
return error("订单不存在");
|
||||
}
|
||||
return success(transactionBillService.rechargeDevice(bill.getBillId()));
|
||||
return success(transactionBillService.rechargeDevice(bill.getBillId(), 1));
|
||||
}
|
||||
|
||||
}
|
||||
|
|
|
@ -20,7 +20,6 @@ import org.springframework.validation.annotation.Validated;
|
|||
import org.springframework.web.bind.annotation.GetMapping;
|
||||
import org.springframework.web.bind.annotation.PostMapping;
|
||||
import org.springframework.web.bind.annotation.PutMapping;
|
||||
import org.springframework.web.bind.annotation.DeleteMapping;
|
||||
import org.springframework.web.bind.annotation.PathVariable;
|
||||
import org.springframework.web.bind.annotation.RequestBody;
|
||||
import org.springframework.web.bind.annotation.RequestMapping;
|
||||
|
@ -29,7 +28,6 @@ import com.ruoyi.common.annotation.Log;
|
|||
import com.ruoyi.common.core.controller.BaseController;
|
||||
import com.ruoyi.common.core.domain.AjaxResult;
|
||||
import com.ruoyi.common.enums.BusinessType;
|
||||
import com.ruoyi.ss.transactionBill.domain.TransactionBill;
|
||||
import com.ruoyi.ss.transactionBill.service.TransactionBillService;
|
||||
import com.ruoyi.common.utils.poi.ExcelUtil;
|
||||
import com.ruoyi.common.core.page.TableDataInfo;
|
||||
|
@ -140,7 +138,7 @@ public class SmTransactionBillController extends BaseController
|
|||
@GetMapping("/rechargeDevice/{billId}")
|
||||
@Log(title = "手动设备充值", businessType = BusinessType.UPDATE)
|
||||
public AjaxResult rechargeDevice(@PathVariable Long billId) {
|
||||
return toAjax(transactionBillService.rechargeDevice(billId));
|
||||
return toAjax(transactionBillService.rechargeDevice(billId, 1));
|
||||
}
|
||||
|
||||
// 订单退款
|
||||
|
|
Loading…
Reference in New Issue
Block a user