|
|
@@ -56,6 +56,7 @@ import org.springframework.data.domain.Page;
|
|
|
import org.springframework.data.domain.Pageable;
|
|
|
import org.springframework.stereotype.Service;
|
|
|
import org.springframework.transaction.annotation.Transactional;
|
|
|
+import org.springframework.util.StopWatch;
|
|
|
|
|
|
import java.math.BigDecimal;
|
|
|
import java.util.ArrayList;
|
|
|
@@ -117,7 +118,7 @@ public class ExpenseFlowServiceImpl extends SuperService implements ExpenseFlowS
|
|
|
}
|
|
|
|
|
|
/**
|
|
|
- * 创建订单
|
|
|
+ * 创建订单 (订单信息 关联改变)
|
|
|
*
|
|
|
* @param iotParam
|
|
|
* @return
|
|
|
@@ -135,7 +136,6 @@ public class ExpenseFlowServiceImpl extends SuperService implements ExpenseFlowS
|
|
|
expenseFlow.setPaymentNo(paymentNo);
|
|
|
// 支付金额
|
|
|
BigDecimal amount = CommonUtil.turnMoney2BigDecimal(iotParam.getAmount());
|
|
|
- amount = amount.stripTrailingZeros();
|
|
|
expenseFlow.setPayAmount(amount);
|
|
|
|
|
|
String deviceId = iotParam.getDeviceId();
|
|
|
@@ -150,6 +150,7 @@ public class ExpenseFlowServiceImpl extends SuperService implements ExpenseFlowS
|
|
|
expenseFlow.setOrderType(OrderState.WAIT_PAYMENT);
|
|
|
// 默认未结算状态
|
|
|
expenseFlow.setSettlementState(SettlementState.Unsettled);
|
|
|
+
|
|
|
// 验证参数、填充数据
|
|
|
commonVerifyExpenseFlow(expenseFlow);
|
|
|
return ResultContent.buildSuccess(expenseFlow);
|
|
|
@@ -248,6 +249,8 @@ public class ExpenseFlowServiceImpl extends SuperService implements ExpenseFlowS
|
|
|
*/
|
|
|
private void commonVerifyExpenseFlow(ExpenseFlow entity) {
|
|
|
String deviceId = entity.getDeviceId();
|
|
|
+ StopWatch stopWatch = new StopWatch();
|
|
|
+ stopWatch.start("设备");
|
|
|
|
|
|
// 验证设备
|
|
|
DeviceInfo deviceInfo = deviceInfoDao.findTopByDeviceId(deviceId);
|
|
|
@@ -267,11 +270,16 @@ public class ExpenseFlowServiceImpl extends SuperService implements ExpenseFlowS
|
|
|
entity.setVerifyError(String.format("设备未绑定机构"));
|
|
|
return;
|
|
|
}
|
|
|
+ stopWatch.stop();
|
|
|
+
|
|
|
+ stopWatch.start("区域");
|
|
|
// 设备所属的商户/机构
|
|
|
entity.setShopOid(deviceInfo.getBeLongOid());
|
|
|
// 设备区域
|
|
|
entity.setArea(areaService.toSimpleModel(deviceInfo.getArea()));
|
|
|
+ stopWatch.stop();
|
|
|
|
|
|
+ stopWatch.start("项目信息");
|
|
|
// 填充项目信息
|
|
|
String projectOid = deviceInfo.getProjectOid();
|
|
|
Organization projectInfo = organizationDao.findTopByOid(projectOid);
|
|
|
@@ -284,7 +292,9 @@ public class ExpenseFlowServiceImpl extends SuperService implements ExpenseFlowS
|
|
|
entity.setVerifyError("未绑定项目信息");
|
|
|
return;
|
|
|
}
|
|
|
+ stopWatch.stop();
|
|
|
|
|
|
+ stopWatch.start("卡片信息");
|
|
|
if (entity.getOrderFromType() == OrderFromType.Swipe) {
|
|
|
CardInfo cardInfo = cardInfoDao.findByCode(entity.getCardNo());
|
|
|
// 验证卡片
|
|
|
@@ -313,6 +323,7 @@ public class ExpenseFlowServiceImpl extends SuperService implements ExpenseFlowS
|
|
|
}
|
|
|
entity.setMode(iotParam.getMode());
|
|
|
}
|
|
|
+ stopWatch.stop();
|
|
|
|
|
|
// 验证用户信息
|
|
|
if (StringUtils.isEmpty(entity.getUserId())) {
|
|
|
@@ -320,6 +331,7 @@ public class ExpenseFlowServiceImpl extends SuperService implements ExpenseFlowS
|
|
|
return;
|
|
|
}
|
|
|
|
|
|
+ stopWatch.start("用户信息");
|
|
|
UserAccount userAccount = userCountDao.findTopByUserId(entity.getUserId());
|
|
|
if (ObjectUtils.isEmpty(userAccount)) {
|
|
|
entity.setVerifyError("用户未注册");
|
|
|
@@ -332,7 +344,9 @@ public class ExpenseFlowServiceImpl extends SuperService implements ExpenseFlowS
|
|
|
entity.setVerifyError("用户已锁定");
|
|
|
return;
|
|
|
}
|
|
|
+ stopWatch.stop();
|
|
|
|
|
|
+ stopWatch.start("用户设备权限");
|
|
|
// 判断设备和用户是否绑定
|
|
|
DevicePermiss devicePermiss = devicePermissDao.findTopByUserIdAndDeviceIdAndProjectOid(entity.getUserId(), entity.getDeviceId(), entity.getProjectOid());
|
|
|
if (ObjectUtils.isEmpty(devicePermiss)) {
|
|
|
@@ -343,7 +357,9 @@ public class ExpenseFlowServiceImpl extends SuperService implements ExpenseFlowS
|
|
|
entity.setVerifyError("用户设备权限未启用");
|
|
|
return;
|
|
|
}
|
|
|
+ stopWatch.stop();
|
|
|
|
|
|
+ stopWatch.start("end");
|
|
|
// 消费设备信息
|
|
|
if (deviceInfo.getDeviceType() != null) {
|
|
|
entity.setPayType(deviceInfo.getDeviceType().getRemark());
|
|
|
@@ -354,11 +370,13 @@ public class ExpenseFlowServiceImpl extends SuperService implements ExpenseFlowS
|
|
|
// 金额判断
|
|
|
BigDecimal payAmount = entity.getPayAmount();
|
|
|
if (entity.getMode() == 0 && CommonUtil.bigDecimalIsEmpty(payAmount)) {
|
|
|
- entity.setVerifyError("消费金额不能为0");
|
|
|
+ entity.setVerifyError("消费金额不能小于等于0");
|
|
|
return;
|
|
|
}
|
|
|
entity.setVerifyParamIsSuccess(Boolean.TRUE);
|
|
|
entity.setVerifyParamMsg("参数验证成功");
|
|
|
+ stopWatch.stop();
|
|
|
+ log.info("验证; {}", stopWatch.prettyPrint());
|
|
|
}
|
|
|
|
|
|
/**
|