|
|
@@ -26,6 +26,8 @@ import org.springframework.validation.annotation.Validated;
|
|
|
import org.springframework.web.bind.annotation.*;
|
|
|
|
|
|
import java.util.Objects;
|
|
|
+import java.util.concurrent.ScheduledExecutorService;
|
|
|
+import java.util.concurrent.TimeUnit;
|
|
|
|
|
|
/**
|
|
|
* name: ConsumeController
|
|
|
@@ -45,6 +47,7 @@ import java.util.Objects;
|
|
|
@RequestMapping("/v1/Consumes")
|
|
|
public class ConsumeController {
|
|
|
private final RecordConvertStrategyContent recordConvertStrategy;
|
|
|
+ private final ScheduledExecutorService scheduledExecutorService;
|
|
|
private final ConsumeBusiness consumeBusiness;
|
|
|
private final BaseBusiness baseBusiness;
|
|
|
private final DefaultConfig defaultConfig;
|
|
|
@@ -74,7 +77,15 @@ public class ConsumeController {
|
|
|
}
|
|
|
RedisUtils.setCacheMapValue(CacheNames.SCHOOL_CODE, Long.toString(userNo), qrcode);
|
|
|
|
|
|
- return doRecordData(record, "requestConsume", mac, xfPwd);
|
|
|
+ //return doRecordData(record, "requestConsume", mac, xfPwd);
|
|
|
+
|
|
|
+ Object object = doRecordData(record, "requestConsume", mac, xfPwd);
|
|
|
+ JSONObject jsonObject = JSONUtil.parseObj(object);
|
|
|
+ scheduledExecutorService.schedule(() -> {
|
|
|
+ sendConsumeToCloud(jsonObject, record);
|
|
|
+ }, 3, TimeUnit.SECONDS);
|
|
|
+
|
|
|
+ return object;
|
|
|
}
|
|
|
|
|
|
/**
|
|
|
@@ -88,7 +99,15 @@ public class ConsumeController {
|
|
|
@PostMapping("/ConsumeOriginal")
|
|
|
public Object consumeOriginal(@RequestBody Object record, @RequestParam(name = "mac", required = false) String mac,
|
|
|
@RequestParam(name = "xfPwd", required = false) String xfPwd) {
|
|
|
- return doRecordData(record, "requestConsume", mac, xfPwd);
|
|
|
+
|
|
|
+ Object object = doRecordData(record, "requestConsume", mac, xfPwd);
|
|
|
+ JSONObject jsonObject = JSONUtil.parseObj(object);
|
|
|
+
|
|
|
+ scheduledExecutorService.schedule(() -> {
|
|
|
+ sendConsumeToCloud(jsonObject, record);
|
|
|
+ }, 3, TimeUnit.SECONDS);
|
|
|
+
|
|
|
+ return object;
|
|
|
}
|
|
|
|
|
|
/**
|
|
|
@@ -161,9 +180,9 @@ public class ConsumeController {
|
|
|
if (Objects.equals(type, "requestConsume")) {
|
|
|
errorInfo = consumeBusiness.createOrder(bo, mac, xfPwd);
|
|
|
// 是否推送云端消费
|
|
|
- if (ObjectUtil.equals(defaultConfig.getLocationFlag(), DefaultConstants.LOCAL_FLAG)) {
|
|
|
- baseBusiness.sendCloudConsume(cloudConsumeBo);
|
|
|
- }
|
|
|
+ //if (ObjectUtil.equals(defaultConfig.getLocationFlag(), DefaultConstants.LOCAL_FLAG)) {
|
|
|
+ // baseBusiness.sendCloudConsume(cloudConsumeBo);
|
|
|
+ //}
|
|
|
} else if (Objects.equals(type, "uploadRecord")) {
|
|
|
errorInfo = consumeBusiness.postOrder(bo, mac, xfPwd);
|
|
|
} else {
|
|
|
@@ -178,4 +197,14 @@ public class ConsumeController {
|
|
|
}
|
|
|
return recordConvertStrategy.reConvert(bo, "YC");
|
|
|
}
|
|
|
+
|
|
|
+ private void sendConsumeToCloud(JSONObject jsonObject, Object record) {
|
|
|
+ if(ObjectUtil.isEmpty(jsonObject.get("body"))){
|
|
|
+ //发送消息
|
|
|
+ if (ObjectUtil.equals(defaultConfig.getLocationFlag(), DefaultConstants.LOCAL_FLAG)) {
|
|
|
+ ConsumptionBo bo = recordConvertStrategy.convert(record, "YC");
|
|
|
+ baseBusiness.sendCloudConsume(bo);
|
|
|
+ }
|
|
|
+ }
|
|
|
+ }
|
|
|
}
|