Commit e1b8760d by 111-PC\111

[+]kafka消费数据修改

1 parent 3fab142b
package cn.com.glsx.smart.service; package cn.com.glsx.smart.service;
import cn.com.glsx.smart.commons.Constants;
import cn.com.glsx.smart.entity.ExecuteTaskVo;
import cn.com.glsx.smart.entity.MessageVo; import cn.com.glsx.smart.entity.MessageVo;
import cn.com.glsx.smart.entity.ResponseVo;
import cn.com.glsx.smart.entity.SmartSceneData;
import cn.com.glsx.smart.mapper.SmartSceneDataMapper;
import cn.com.glsx.smart.utils.HttpUtil; import cn.com.glsx.smart.utils.HttpUtil;
import com.alibaba.fastjson.JSONObject; import com.alibaba.fastjson.JSONObject;
import lombok.extern.slf4j.Slf4j; import lombok.extern.slf4j.Slf4j;
import org.apache.commons.collections.CollectionUtils;
import org.apache.commons.lang.StringUtils;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.beans.factory.annotation.Value; import org.springframework.beans.factory.annotation.Value;
import org.springframework.stereotype.Service; import org.springframework.stereotype.Service;
import java.io.IOException;
import java.util.ArrayList;
import java.util.HashMap; import java.util.HashMap;
import java.util.List;
import java.util.Map; import java.util.Map;
import java.util.stream.Collectors;
/** /**
* @author zhouhaibao * @author zhouhaibao
...@@ -30,14 +18,8 @@ import java.util.stream.Collectors; ...@@ -30,14 +18,8 @@ import java.util.stream.Collectors;
@Slf4j @Slf4j
public class OrderIssueService { public class OrderIssueService {
@Autowired @Value("${issueOrderUrl}")
private SmartSceneDataMapper smartSceneDataMapper; private String issueOrderUrl;
@Value("${orderIssueurl}")
private String orderIssueurl;
@Value("${instructionInfIssue}")
private String instructionInfIssue;
/** /**
* 处理消息 * 处理消息
...@@ -50,82 +32,16 @@ public class OrderIssueService { ...@@ -50,82 +32,16 @@ public class OrderIssueService {
log.info("数据异常"); log.info("数据异常");
return; return;
} }
List<SmartSceneData> smartTemplateParamList = smartSceneDataMapper.findByTemplateId(Integer.parseInt(messageVo.getScenseId())); Map<String, String> requestMap = new HashMap<>();
if (CollectionUtils.isEmpty(smartTemplateParamList)) { requestMap.put("id", messageVo.getScenseId() + "");
log.info("未查到该场景id的条件{}", messageVo.getScenseId()); String responseBody = null;
return; try {
responseBody = HttpUtil.sendPost(issueOrderUrl, JSONObject.toJSONString(requestMap), new HashMap<>());
log.info("场景id{}下发结果{}", messageVo.getScenseId(), responseBody);
} catch (Exception e) {
e.printStackTrace();
log.info("场景id{}下发指令异常,{}", messageVo.getScenseId(), e);
} }
// 下发指令
List<SmartSceneData> orders = smartTemplateParamList.stream().filter(index -> index.getParamKey().equals(Constants.Order_Issue)).collect(Collectors.toList());
if (CollectionUtils.isEmpty(orders)) {
log.info("未查到该场景id的指令{}", messageVo.getScenseId());
return;
}
orders.forEach(index -> {
Map<String, List<Map<String, Object>>> ordermaps = new HashMap<>();
List<Map<String, Object>> maps = new ArrayList<>();
Map<String, Object> ordermap = new HashMap<>();
String paramValue = index.getParamValue();
if (StringUtils.isEmpty(paramValue)) {
log.info("参数异常{}", index.getParamKey());
return;
}
ExecuteTaskVo executeTaskVo = JSONObject.parseObject(paramValue, ExecuteTaskVo.class);
if (StringUtils.isEmpty(executeTaskVo.getOrderCode()) || StringUtils.isEmpty(executeTaskVo.getDeviceId())) {
log.info("参数异常{}", index.getParamKey());
return;
}
// 根据遥控器id下发普通指令还是红外遥控指令
String remoteId = executeTaskVo.getRemoteId();
String devideId = executeTaskVo.getDeviceId();
JSONObject jsonObject = null;
try {
if (StringUtils.isBlank(remoteId)) {
String valueType = executeTaskVo.getOrderValueType();
ordermap.put("code", executeTaskVo.getOrderCode());
ordermap.put("value", revertType(valueType, executeTaskVo.getOrderValue()));
maps.add(ordermap);
ordermaps.put("commands", maps);
// 下发普通指令
jsonObject = HttpUtil.sendPost(orderIssueurl.replace("{device_id}", devideId), JSONObject.toJSONString(ordermaps), new HashMap<>());
} else {
ordermap.put("key", executeTaskVo.getOrderCode());
// 下发红外遥控指令
jsonObject = HttpUtil.sendPost(instructionInfIssue.replace("{remote_id}", remoteId).replace("{infrared_id}", devideId), JSONObject.toJSONString(ordermap), new HashMap<>());
}
if(jsonObject!=null){
ResponseVo responseVo = JSONObject.toJavaObject(jsonObject, ResponseVo.class);
if(responseVo.getCode().equals("200")){
log.info("设备{}下发成功", devideId);
}else{
log.info("设备{}下发失败,错误信息为{}", devideId,responseVo.getMsg());
}
}
} catch (IOException e) {
e.printStackTrace();
}
});
// 推送消息开始 ----- TODO
List<SmartSceneData> messageOrders = smartTemplateParamList.stream().filter(index -> index.getParamKey().equals(Constants.MESSAGE_NOTI)).collect(Collectors.toList());
// 推送消息结束 -----TODO
} }
private Object revertType(String valueType, String object) {
Object orderValue = null;
switch (valueType) {
case "1":
orderValue = object;
break;
case "2":
orderValue = Integer.parseInt(object);
break;
case "3":
orderValue = Boolean.valueOf(object);
break;
default:
orderValue = object;
break;
}
return orderValue;
}
} }
...@@ -181,12 +181,9 @@ public class HttpUtil { ...@@ -181,12 +181,9 @@ public class HttpUtil {
* @return * @return
* @throws IOException * @throws IOException
*/ */
public static JSONObject sendPost(String url, String json, Map<String, String> headerParams) throws IOException { public static String sendPost(String url, String json, Map<String, String> headerParams) throws IOException {
String formData = postData(url, json, headerParams); String formData = postData(url, json, headerParams);
if (StringUtils.isNotBlank(formData)) { return formData;
return JSONObject.parseObject(formData);
}
return new JSONObject();
} }
/** /**
......
Markdown is supported
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!