|
|
@@ -1,11 +1,21 @@
|
|
|
package com.zhongshu.card.server.core.service.payment;
|
|
|
|
|
|
+import cn.hutool.json.JSONUtil;
|
|
|
import com.github.microservice.models.hxz.*;
|
|
|
+import com.github.microservice.models.hxz.base.BaseResultModel;
|
|
|
import com.zhongshu.card.client.ret.ResultContent;
|
|
|
+import com.zhongshu.card.client.utils.type.UserState;
|
|
|
+import com.zhongshu.card.client.utils.type.school.CardState;
|
|
|
+import com.zhongshu.card.server.core.dao.CardInfoDao;
|
|
|
+import com.zhongshu.card.server.core.dao.org.UserCountDao;
|
|
|
import com.zhongshu.card.server.core.dao.school.DeviceInfoDao;
|
|
|
+import com.zhongshu.card.server.core.domain.org.UserAccount;
|
|
|
+import com.zhongshu.card.server.core.domain.school.CardInfo;
|
|
|
import com.zhongshu.card.server.core.domain.school.DeviceInfo;
|
|
|
import com.zhongshu.card.server.core.httpRequest.ApiRequestService;
|
|
|
+import com.zhongshu.card.server.core.model.payment.ExpendParam;
|
|
|
import com.zhongshu.card.server.core.service.base.SuperService;
|
|
|
+import com.zhongshu.card.server.core.util.CommonUtil;
|
|
|
import lombok.extern.slf4j.Slf4j;
|
|
|
import org.apache.commons.lang3.ObjectUtils;
|
|
|
import org.springframework.beans.factory.annotation.Autowired;
|
|
|
@@ -29,13 +39,22 @@ public class HxzService extends SuperService {
|
|
|
@Autowired
|
|
|
ApiRequestService apiRequestService;
|
|
|
|
|
|
+ @Autowired
|
|
|
+ CardInfoDao cardInfoDao;
|
|
|
+
|
|
|
+ @Autowired
|
|
|
+ UserCountDao userCountDao;
|
|
|
+
|
|
|
+ @Autowired
|
|
|
+ ExpenseFlowServiceImpl expenseFlowService;
|
|
|
+
|
|
|
/**
|
|
|
* 得到系统时间
|
|
|
*
|
|
|
* @param param
|
|
|
* @return
|
|
|
*/
|
|
|
- public ResultContent<ServerTimeResult> serverTime(ServerTimeModel param) {
|
|
|
+ public ResultContent serverTime(ServerTimeModel param) {
|
|
|
String deviceId = param.getDeviceID().toString();
|
|
|
ServerTimeResult result = new ServerTimeResult();
|
|
|
DeviceInfo deviceInfo = deviceInfoDao.findTopByDeviceId(deviceId);
|
|
|
@@ -46,8 +65,9 @@ public class HxzService extends SuperService {
|
|
|
} else {
|
|
|
result.setSuccess();
|
|
|
}
|
|
|
+ String str = JSONUtil.toJsonStr(result);
|
|
|
requestInfoService.addRequestInfo(param, result);
|
|
|
- return ResultContent.buildSuccess(result);
|
|
|
+ return ResultContent.buildSuccess(str);
|
|
|
}
|
|
|
|
|
|
/**
|
|
|
@@ -56,13 +76,85 @@ public class HxzService extends SuperService {
|
|
|
* @param param
|
|
|
* @return
|
|
|
*/
|
|
|
- public ResultContent<ConsumTransactionsFullResult> consumTransactions(@RequestBody ConsumTransactionsFullParam param) {
|
|
|
+ public ResultContent consumTransactions(ConsumTransactionsFullParam param) {
|
|
|
+ // 返回参数
|
|
|
ConsumTransactionsFullResult result = new ConsumTransactionsFullResult();
|
|
|
- ConsumTransactionsResult model = new ConsumTransactionsResult();
|
|
|
+ result.setPaymentType(param.getPaymentType());
|
|
|
|
|
|
- requestInfoService.addRequestInfo(param, model);
|
|
|
+ ConsumTransactionsResult resultModel = new ConsumTransactionsResult();
|
|
|
+ // 参数
|
|
|
+ ConsumTransactionsModel iotParam = param.getParam();
|
|
|
|
|
|
- return ResultContent.buildSuccess(result);
|
|
|
+ // 检查设备
|
|
|
+ String deviceId = iotParam.getDeviceId();
|
|
|
+ DeviceInfo deviceInfo = deviceInfoDao.findTopByDeviceId(deviceId);
|
|
|
+ if (ObjectUtils.isEmpty(deviceInfo)) {
|
|
|
+ resultModel.setFailed("业务设备未注册");
|
|
|
+ requestInfoService.addRequestInfo(param, resultModel);
|
|
|
+ result.setModel(resultModel);
|
|
|
+ return ResultContent.buildSuccess(JSONUtil.toJsonStr(result));
|
|
|
+ }
|
|
|
+ // 验证卡片
|
|
|
+ CardInfo cardInfo = cardInfoDao.findByCode(iotParam.getCardNo());
|
|
|
+ if (ObjectUtils.isEmpty(cardInfo)) {
|
|
|
+ resultModel.setFailed("卡片未注册");
|
|
|
+ requestInfoService.addRequestInfo(param, resultModel);
|
|
|
+ result.setModel(resultModel);
|
|
|
+ return ResultContent.buildSuccess(JSONUtil.toJsonStr(result));
|
|
|
+ }
|
|
|
+
|
|
|
+ if (cardInfo.getCardState() != CardState.Enable) {
|
|
|
+ resultModel.setFailed(String.format("卡片", cardInfo.getCardState().getRemark()));
|
|
|
+ requestInfoService.addRequestInfo(param, resultModel);
|
|
|
+ result.setModel(resultModel);
|
|
|
+ return ResultContent.buildSuccess(JSONUtil.toJsonStr(result));
|
|
|
+ }
|
|
|
+
|
|
|
+ // 验证持卡人的钱包
|
|
|
+ String userId = cardInfo.getUserId();
|
|
|
+ UserAccount userAccount = userCountDao.findTopByUserId(userId);
|
|
|
+ if (ObjectUtils.isEmpty(userAccount)) {
|
|
|
+ resultModel.setFailed("持卡人为空");
|
|
|
+ requestInfoService.addRequestInfo(param, resultModel);
|
|
|
+ result.setModel(resultModel);
|
|
|
+ return ResultContent.buildSuccess(JSONUtil.toJsonStr(result));
|
|
|
+ }
|
|
|
+
|
|
|
+ if (userAccount.getState() == UserState.Locked) {
|
|
|
+ resultModel.setFailed("持卡人已锁定");
|
|
|
+ requestInfoService.addRequestInfo(param, resultModel);
|
|
|
+ result.setModel(resultModel);
|
|
|
+ return ResultContent.buildSuccess(JSONUtil.toJsonStr(result));
|
|
|
+ }
|
|
|
+
|
|
|
+ if (iotParam.getMode() == 0 && iotParam.getPayType() == 0) {
|
|
|
+ // 手动 刷卡扣费
|
|
|
+ String Amount = iotParam.getAmount();
|
|
|
+ ExpendParam expendParam = new ExpendParam();
|
|
|
+ expendParam.setCardInfo(cardInfo);
|
|
|
+ expendParam.setOrder(iotParam.getOrder());
|
|
|
+ expendParam.setAmount(CommonUtil.turnMoney2BigDecimal(Amount));
|
|
|
+ expendParam.setIotParam(iotParam);
|
|
|
+ ResultContent resultContent = expenseFlowService.expendPay(expendParam);
|
|
|
+ if (resultContent.isSuccess()) {
|
|
|
+ // 消费成功 设置返回参数
|
|
|
+ resultModel.setSuccess();
|
|
|
+ resultModel.setText("支付成功");
|
|
|
+ } else {
|
|
|
+ resultModel.setFailed(resultContent.getMsg());
|
|
|
+ requestInfoService.addRequestInfo(param, resultModel);
|
|
|
+ result.setModel(resultModel);
|
|
|
+ return ResultContent.buildSuccess(JSONUtil.toJsonStr(result));
|
|
|
+ }
|
|
|
+ } else {
|
|
|
+ resultModel.setFailed("消费模式不支持");
|
|
|
+ requestInfoService.addRequestInfo(param, resultModel);
|
|
|
+ result.setModel(resultModel);
|
|
|
+ return ResultContent.buildSuccess(JSONUtil.toJsonStr(result));
|
|
|
+ }
|
|
|
+ result.setModel(resultModel);
|
|
|
+ requestInfoService.addRequestInfo(param, resultModel);
|
|
|
+ return ResultContent.buildSuccess(JSONUtil.toJsonStr(result));
|
|
|
}
|
|
|
|
|
|
}
|