|
@@ -0,0 +1,71 @@
|
|
|
+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.fasterxml.jackson.databind.ObjectMapper;
|
|
|
+import com.szwl.constant.OperationType;
|
|
|
+import com.szwl.model.entity.MessageLog;
|
|
|
+import com.szwl.model.entity.TEquipment;
|
|
|
+import com.szwl.model.entity.TProduct;
|
|
|
+import com.szwl.model.jsonParm.HeartParam;
|
|
|
+import com.szwl.service.TEquipmentService;
|
|
|
+import com.szwl.service.TProductService;
|
|
|
+import lombok.extern.slf4j.Slf4j;
|
|
|
+import org.springframework.stereotype.Component;
|
|
|
+
|
|
|
+import javax.annotation.Resource;
|
|
|
+import java.util.Arrays;
|
|
|
+import java.util.List;
|
|
|
+
|
|
|
+@Slf4j
|
|
|
+@Component
|
|
|
+public class UpdateProductProcessor implements ResponseProcessor {
|
|
|
+
|
|
|
+ @Resource
|
|
|
+ private TEquipmentService equipmentService;
|
|
|
+
|
|
|
+ @Resource
|
|
|
+ private TProductService productService;
|
|
|
+
|
|
|
+ @Override
|
|
|
+ public void process(MessageLog messageLog) {
|
|
|
+ Integer statusCode = messageLog.getStatusCode();
|
|
|
+ if (statusCode == 200) {
|
|
|
+ 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 {
|
|
|
+ // 转换为对象
|
|
|
+ TProduct product = JSON.parseObject(responseContent, TProduct.class);
|
|
|
+ LambdaQueryWrapper<TProduct> productWrapper = Wrappers.lambdaQuery();
|
|
|
+ productWrapper.eq(TProduct::getNo, product.getNo());
|
|
|
+ productWrapper.eq(TProduct::getEquipmentId, equipment.getId());
|
|
|
+ TProduct tProduct = productService.getOne(productWrapper);
|
|
|
+ if (tProduct != null) {
|
|
|
+ tProduct.setCodePrice(product.getCodePrice());
|
|
|
+ tProduct.setName(product.getName());
|
|
|
+ tProduct.setProductName(product.getProductName());
|
|
|
+ tProduct.setRmbPrice(product.getRmbPrice());
|
|
|
+ tProduct.setSellStatus(product.getSellStatus());
|
|
|
+ productService.updateById(tProduct);
|
|
|
+ }
|
|
|
+ } catch (Exception e) {
|
|
|
+ log.info("--解析失败:{}", e.getMessage());
|
|
|
+ }
|
|
|
+
|
|
|
+ }
|
|
|
+ }
|
|
|
+ }
|
|
|
+
|
|
|
+ @Override
|
|
|
+ public String getSupportedOperationType() {
|
|
|
+ return OperationType.UPDATE_PRODUCT.getCode();
|
|
|
+ }
|
|
|
+}
|