ソースを参照

fix: 海康服务
1.海康消费机交易流程调整,第一个事件不再调用消费服务中的请求交易,而是在第2步调用全流程消费

luoyb 9 ヶ月 前
コミット
658ae3c0f8

+ 2 - 0
ruoyi-server/ruoyi-server-consume/src/main/java/org/dromara/server/consume/domain/XfTerm.java

@@ -342,6 +342,8 @@ public class XfTerm extends TenantEntity {
      */
     private String remark;
 
+    /*消费机品牌*/
+    private String brand;
     /**
      * 删除标志(0-未删除 2-已删除)
      */

+ 3 - 0
ruoyi-server/ruoyi-server-consume/src/main/java/org/dromara/server/consume/domain/vo/XfTermVo.java

@@ -123,6 +123,9 @@ public class XfTermVo implements Serializable {
      * 租户编号
      */
     private String tenantId;
+
+    /*消费机品牌*/
+    private String brand;
     /**
      * 应用系统,见YYXT数据字典类别
      */

+ 48 - 43
ruoyi-server/ruoyi-server-hik/src/main/java/org/dromara/server/hik/event/handler/ConsumptionEventHandler.java

@@ -50,7 +50,7 @@ public class ConsumptionEventHandler implements HikEventHandler {
             if (termVo == null) {
                 log.error("消费机交易记录事件,设备信息为空,mac:{}, 不存在系统中", receive.getMacAddress());
                 // 直接应答失败
-                return answerEvent(consumptionEvent, false,null, null, "设备未注册", "");
+                return answerEvent(consumptionEvent, false, null, null, "设备未注册", "");
             }
             /*
              * 消费机 交易预处理请求事件上报
@@ -58,31 +58,36 @@ public class ConsumptionEventHandler implements HikEventHandler {
              * minor:transactionPreprocessingRequest
              */
             // 业务逻辑处理的结果
-            boolean bussiRs  = true;
+            boolean bussiRs = true;
             // 处理交易预处理请求事件上报 根据业务数据校验 能不能消费 权限、账号、金额、设备、业务数据
             // 调用现有原始消费请求接口
             RemoteConsumeBo remoteBo = setParamBo(receive, consumptionEvent);
             remoteBo.setTermNo(termVo.getTermNo());
-            log.info("transactionPreprocessingRequest 调用消费服务的消费请求接口,入参:{}",JSONUtil.toJsonStr(remoteBo));
-            RemoteResultDto result = remoteConsumeService.dealHikRequestConsume(remoteBo);
-            R<ErrorInfo> errorInfo = result.getErrorInfo();
-            RemoteConsumeBo updatedRemoteBo = result.getUpdatedRemoteBo();
+            log.info("transactionPreprocessingRequest 调用消费服务的消费请求接口,入参:{}", JSONUtil.toJsonStr(remoteBo));
+            //RemoteResultDto result = remoteConsumeService.dealHikRequestConsume(remoteBo);
+            //R<ErrorInfo> errorInfo = result.getErrorInfo();
+            //RemoteConsumeBo updatedRemoteBo = result.getUpdatedRemoteBo();
+            //String reason = "";
+            //BigDecimal balance = updatedRemoteBo.getBalance();
+            //BigDecimal consumeMoney = updatedRemoteBo.getConsumeMoney();
+            //String deptName =updatedRemoteBo.getDeptName();
+            //if (R.isError(errorInfo)) {
+            //    // 应答失败
+            //    bussiRs = false;
+            //    reason = errorInfo.getMsg();
+            //    ErrorInfo data = errorInfo.getData();
+            //    if(data != null){
+            //        reason = data.getMessage();
+            //    }
+            //}
+            // 直接应答成功
+            String deptName = "";
             String reason = "";
-            BigDecimal balance = updatedRemoteBo.getBalance();
-            BigDecimal consumeMoney = updatedRemoteBo.getConsumeMoney();
-            String deptName =updatedRemoteBo.getDeptName();
-            if (R.isError(errorInfo)) {
-                // 应答失败
-                bussiRs = false;
-                reason = errorInfo.getMsg();
-                ErrorInfo data = errorInfo.getData();
-                if(data != null){
-                    reason = data.getMessage();
-                }
-            }
-            // 应答
-            return answerEvent(consumptionEvent, bussiRs, balance,consumeMoney, reason,deptName);
-        }else if(TRANSACTION_CONFIRMING_REQUEST.equals(consumptionEvent.getMinor())){
+            BigDecimal balance = remoteBo.getBalance();
+            BigDecimal consumeMoney = remoteBo.getConsumeMoney();
+
+            return answerEvent(consumptionEvent, bussiRs, balance, consumeMoney, reason, deptName);
+        } else if (TRANSACTION_CONFIRMING_REQUEST.equals(consumptionEvent.getMinor())) {
             HashMap<String, Object> rs = new HashMap<>(1);
             rs.put("result", "success");
             /*
@@ -91,7 +96,7 @@ public class ConsumptionEventHandler implements HikEventHandler {
               minor:transactionConfirmingRequest
              */
             Boolean cancel = consumptionEvent.getCancel();
-            if(cancel !=null && cancel){
+            if (cancel != null && cancel) {
                 log.info("消费机消费请求确认事件,取消交易:{}", JSONUtil.toJsonStr(receive));
                 // 将原始记录标记为删除 termVo.getTermNo() consumptionEvent.getSerialNo() TermRecordId
                 remoteConsumeService.cancleDeal(termVo.getTermNo(), consumptionEvent.getSerialNo());
@@ -103,8 +108,9 @@ public class ConsumptionEventHandler implements HikEventHandler {
             remoteBo.setRecordStatus(364L);
             remoteBo.setRecordId(0L);
             remoteBo.setTermNo(termVo.getTermNo());
-            log.info("transactionConfirmingRequest 调用消费服务的消费入库接口,入参:{}",JSONUtil.toJsonStr(remoteBo));
-            RemoteResultDto result = remoteConsumeService.dealHikUploadRecord(remoteBo);
+            log.info("transactionConfirmingRequest 调用消费服务的消费入库接口,入参:{}", JSONUtil.toJsonStr(remoteBo));
+            //RemoteResultDto result = remoteConsumeService.dealHikUploadRecord(remoteBo);
+            RemoteResultDto result = remoteConsumeService.dealHikFullRecord(remoteBo);
 //            log.info("消费机消费请求确认事件,结果:{}", JSONObject.toJSONString(result.getUpdatedRemoteBo()));
             R<ErrorInfo> errorInfo = result.getErrorInfo();
             if (R.isError(errorInfo)) {
@@ -112,7 +118,7 @@ public class ConsumptionEventHandler implements HikEventHandler {
                 rs.put("result", "failed");
             }
             return rs;
-        }else{
+        } else {
             log.warn("消费机事件,未知类型:{}", consumptionEvent.getMinor());
         }
 
@@ -139,46 +145,45 @@ public class ConsumptionEventHandler implements HikEventHandler {
     }
 
 
-    public Map<String, Object>  answerEvent(ConsumptionEventDetail consumptionEvent, boolean answerResult, BigDecimal balance,BigDecimal consumeMoney, String reason,String deptName)
-    {
+    public Map<String, Object> answerEvent(ConsumptionEventDetail consumptionEvent, boolean answerResult, BigDecimal balance, BigDecimal consumeMoney, String reason, String deptName) {
         ConsumptionEventConfirmBo confirmBo = new ConsumptionEventConfirmBo();
         confirmBo.setSerialNo(consumptionEvent.getSerialNo());
-        confirmBo.setResult(answerResult ?"success":"failed");
+        confirmBo.setResult(answerResult ? "success" : "failed");
         confirmBo.setMode(consumptionEvent.getMode());
         log.info("消费机交易预处理请求事件,消费模式:{}", consumptionEvent.getMode());
         confirmBo.setName(consumptionEvent.getName());
         confirmBo.setEmployeeNoString(consumptionEvent.getEmployeeNoString());
-        if(StringUtils.isNotBlank(consumptionEvent.getCardNo())){
+        if (StringUtils.isNotBlank(consumptionEvent.getCardNo())) {
             confirmBo.setCardNo(consumptionEvent.getCardNo());
-        }else{
+        } else {
             log.info("消费机交易预处理请求事件,方式:{}", "人脸或者二维码,不带卡号");
         }
         boolean isCountMode = ConsumeModeEnum.count.getCode().equals(consumptionEvent.getMode());
-        if(isCountMode){
+        if (isCountMode) {
             confirmBo.setTimes(0);
-            if(answerResult){
+            if (answerResult) {
                 confirmBo.setTimes(1);
             }
-        }else{
-            if(answerResult){
+        } else {
+            if (answerResult) {
                 BigDecimal con = consumeMoney.multiply(new BigDecimal("100"));
                 confirmBo.setActualPayment(con.toString().split("\\.")[0]);
                 BigDecimal balanceBeforeDeduct = balance.multiply(new BigDecimal("100")).add(con);
                 confirmBo.setBalanceBeforeDeduct(balanceBeforeDeduct.toString().split("\\.")[0]); // 未扣款前的余额,要根据余额加上扣款金额,单位为分 ,金额模式必填
-            }else{
+            } else {
                 confirmBo.setActualPayment("0");
                 confirmBo.setBalanceBeforeDeduct("0");
             }
         }
 
-        String broadcastVoice = isCountMode ? "刷卡成功":"支付成功";
+        String broadcastVoice = isCountMode ? "刷卡成功" : "支付成功";
         String newReason = reason;
-        if(!answerResult){
-            broadcastVoice = isCountMode ? "刷卡失败":"支付失败";
+        if (!answerResult) {
+            broadcastVoice = isCountMode ? "刷卡失败" : "支付失败";
             // 提示刷卡失败的原因
-            if(StringUtils.isNotBlank(reason) && reason.length() > 30){
+            if (StringUtils.isNotBlank(reason) && reason.length() > 30) {
                 log.info("海康消费失败原因:{}", reason);
-                newReason = reason.substring(0,30);
+                newReason = reason.substring(0, 30);
             }
             broadcastVoice += newReason;
             confirmBo.setReason("platformException");
@@ -191,9 +196,9 @@ public class ConsumptionEventHandler implements HikEventHandler {
         ConsumptionEventConfirmBo.ContentInfo contentInfo = new ConsumptionEventConfirmBo.ContentInfo();
         contentInfo.setTitle(consumptionEvent.getName());
         contentInfo.setContent(deptName);
-        if(!answerResult){
-            contentInfo.setTitle(consumptionEvent.getName()+ "  "+deptName);
-            contentInfo.setContent("失败原因:"+ newReason);
+        if (!answerResult) {
+            contentInfo.setTitle(consumptionEvent.getName() + "  " + deptName);
+            contentInfo.setContent("失败原因:" + newReason);
         }
         confirmBo.setContentInfo(contentInfo);