OrderIssueService.java
2.39 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
package cn.com.glsx.smart.service;
import cn.com.glsx.smart.commons.Constants;
import cn.com.glsx.smart.entity.MessageVo;
import cn.com.glsx.smart.entity.SmartTemplateParam;
import cn.com.glsx.smart.mapper.SmartTemplateParamMapper;
import cn.com.glsx.smart.utils.HttpUtil;
import com.alibaba.fastjson.JSONObject;
import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.beans.factory.annotation.Value;
import org.springframework.stereotype.Service;
import java.io.IOException;
import java.util.HashMap;
import java.util.List;
import java.util.Map;
import java.util.stream.Collectors;
/**
* @author zhouhaibao
* @date 2021/3/12 16:38
*/
@Service
@Slf4j
public class OrderIssueService {
@Autowired
private SmartTemplateParamMapper smartTemplateParamMapper;
@Value("${orderIssueurl}")
private String orderIssueurl;
/**
* 处理消息
*
* @param data
*/
public void processMessage(String data) {
MessageVo messageVo = JSONObject.parseObject(data, MessageVo.class);
List<SmartTemplateParam> smartTemplateParamList=smartTemplateParamMapper.findByTemplateId(messageVo.getTemplateId());
// 下发指令
List<SmartTemplateParam> orders = smartTemplateParamList.stream().filter(index -> index.getParamKey().equals(Constants.Order_Issue)).collect(Collectors.toList());
orders.forEach(index->{
Map<String,Map<String,String>> ordermaps=new HashMap<>();
Map<String,String> ordermap=new HashMap<>();
List<String> list = JSONObject.parseArray(index.getParamValue(), String.class);
ordermap.put("code",list.get(1));
ordermap.put("value",list.get(2));
ordermaps.put("commands",ordermap);
try {
JSONObject jsonObject = HttpUtil.sendPost(orderIssueurl.replace("{device_id}", list.get(0)), JSONObject.toJSONString(ordermaps), null);
if(jsonObject.get("success").equals("true")){
log.info("设备{}下发指令成功",list.get(0));
}
} catch (IOException e) {
e.printStackTrace();
}
});
// 推送消息----- TODO
List<SmartTemplateParam> messageOrders = smartTemplateParamList.stream().filter(index -> index.getParamKey().equals(Constants.MESSAGE_NOTI)).collect(Collectors.toList());
}
}