通过算法计算倾角仪是否倾斜推送到第三方平台

参数格式

在这里插入图片描述在这里插入图片描述

代码

 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

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值