|
@@ -1,22 +1,65 @@
|
|
|
package com.szwl.handle.response;
|
|
|
|
|
|
+import com.alibaba.fastjson.JSON;
|
|
|
+import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper;
|
|
|
+import com.baomidou.mybatisplus.core.toolkit.Wrappers;
|
|
|
import com.szwl.constant.OperationType;
|
|
|
+import com.szwl.feign.bean.OrderFeign;
|
|
|
+import com.szwl.model.bean.CoinOrderVO;
|
|
|
+import com.szwl.model.bo.R;
|
|
|
import com.szwl.model.entity.MessageLog;
|
|
|
+import com.szwl.model.entity.TEquipment;
|
|
|
+import com.szwl.model.utils.PushUtils;
|
|
|
+import com.szwl.service.TEquipmentService;
|
|
|
+import lombok.extern.slf4j.Slf4j;
|
|
|
import org.springframework.stereotype.Component;
|
|
|
|
|
|
import javax.annotation.Resource;
|
|
|
+import java.util.concurrent.ExecutorService;
|
|
|
+import java.util.concurrent.Executors;
|
|
|
|
|
|
+@Slf4j
|
|
|
@Component
|
|
|
-public class UploadOrderProcessor implements ResponseProcessor{
|
|
|
+public class UploadOrderProcessor implements ResponseProcessor {
|
|
|
|
|
|
+ @Resource
|
|
|
+ private OrderFeign orderFeign;
|
|
|
+
|
|
|
+ @Resource
|
|
|
+ private TEquipmentService equipmentService;
|
|
|
+
|
|
|
+ private final ExecutorService sendExecutor =
|
|
|
+ Executors.newSingleThreadExecutor(); // 独立发送线程
|
|
|
|
|
|
|
|
|
@Override
|
|
|
public void process(MessageLog messageLog) {
|
|
|
Integer statusCode = messageLog.getStatusCode();
|
|
|
if (statusCode == 200) {
|
|
|
- String dataContent = messageLog.getDataContent();
|
|
|
+ Integer direction = messageLog.getDirection();
|
|
|
+ String clientId = messageLog.getClientId();
|
|
|
+ String responseContent = messageLog.getResponseContent();
|
|
|
|
|
|
+ // 查询设备
|
|
|
+ LambdaQueryWrapper<TEquipment> query = Wrappers.lambdaQuery();
|
|
|
+ query.eq(TEquipment::getClientId, clientId);
|
|
|
+ TEquipment equipment = equipmentService.getOne(query);
|
|
|
+ if (equipment != null) {
|
|
|
+ // 转换为对象
|
|
|
+ try {
|
|
|
+ CoinOrderVO coinOrderVO = JSON.parseObject(responseContent, CoinOrderVO.class);
|
|
|
+ String result = R.getDataIfSuccess(orderFeign.uploadCoinOrder(coinOrderVO));
|
|
|
+ if ("success".equals(result)) {
|
|
|
+ // 上传成功,通知设备端
|
|
|
+ String message = PushUtils.buildJson(OperationType.UPLOAD_ORDER.getCode(), coinOrderVO.getSn()).toString();
|
|
|
+ sendExecutor.execute(() -> {
|
|
|
+ equipmentService.responseSendMessage(messageLog, message, equipment.getAdminId());
|
|
|
+ });
|
|
|
+ }
|
|
|
+ } catch (Exception e) {
|
|
|
+ log.info("--解析失败:{}", e.getMessage());
|
|
|
+ }
|
|
|
+ }
|
|
|
}
|
|
|
}
|
|
|
|