参数格式
代码
public void qinjiaoPush(){
String url = "http://dmpv1/callback";
JSONObject jsonObject = new JSONObject();
JSONArray msg = new JSONArray();//数组
jsonObject.put("platform","防汛防台");
AlertData alertData = new AlertData();
AlertData search = alertData.setType("0");
search.setIsDel(false);
AlertData check = alertDataMapper.selectOne(search);
String format = new SimpleDateFormat("yyyy-MM-dd HH").format(new Date());
// List<Sensor> sensors = sensorMapper.selectPage(new SensorQuery());
List<Sensor> sensorDatas = sensorMapper.searchAllToday(format);
for (Sensor o:sensorDatas){
BigDecimal xory = new BigDecimal(o.getXCoor().replace("+","").replace("-",""));
BigDecimal bigDecimal = new BigDecimal(9.8);
BigDecimal bigDecimal2= new BigDecimal(90);
BigDecimal multiplyxy= xory.divide(bigDecimal,5).multiply(bigDecimal2);
BigDecimal jiaodu= new BigDecimal(check.getDictValue());
if (multiplyxy.compareTo(jiaodu)==-1){
JSONObject json1 = new JSONObject();
json1.put("serialNumber","1440937040266");
String format1 = new SimpleDateFormat("yyyy-MM-dd HH:mm:ss").format(new Date());
json1.put("reportTime",format1);
json1.put("addr",o.getSensorAddress());
json1.put("battery",BigDecimal.ZERO);
json1.put("batteryType",2);
json1.put("signalNoiseRatio",BigDecimal.ZERO);
json1.put("signalStrength",BigDecimal.ZERO);
json1.put("msgType",1);
JSONObject json2 = new JSONObject();
json2.put("xcoor",o.getXCoor());
json2.put("ycoor",o.getYCoor());
json2.put("zcoor",o.getZCoor());
json1.put("data",json2);
msg.add(json1);
}
}
jsonObject.put("msg",msg);
String sendData = jsonObject.toJSONString();
httpUtils.httpPost(sendData,url);
}
算法
BigDecimal xory = new BigDecimal(o.getXCoor().replace("+","").replace("-",""));
BigDecimal bigDecimal = new BigDecimal(9.8);
BigDecimal bigDecimal2= new BigDecimal(90);
BigDecimal multiplyxy= xory.divide(bigDecimal,5).multiply(bigDecimal2);
(1.1326/9.8)保留5位*90
A.compareTo(B)用来比较A是否大于B
他返还的是一个Boolean值,如果A大于B,返还1。如果A等于B,返还0。如果A小于B,返还-1