vhbjknkm 2022-02-22 18:09 采纳率: 100%
浏览 229
已结题

如何将JSONObject用什么方法转成BigDecimal并将数据传给priceDataTable

java如何将JSONObject用什么方法转成BigDecimal并将数据传给priceDataTable
    public void queryPriceCompareInfo() {
        long start = System.currentTimeMillis();
        Map < String, Object > params = this.getParameters();
        if (params == null) {
            return;
        }
        //询价单id
        String askbillid = (String) params.get("askbillid");
        logger.info("queryPriceCompareInfo:askbillid:" + askbillid);
        @SuppressWarnings("unchecked")
        List < Integer > qlist = (List < Integer >) params.get("quotbids");
        //重新比价带过来的推荐理由
        HashMap < String, String > recommendReasons = new HashMap <>();
        if (params.get("recommendReasons") != null) {
            recommendReasons = JsonUtils.fromJson(params.get("recommendReasons").toString(), HashMap.class);
        }
        Long[] quotids = null;
        if (qlist != null && qlist.size() > 0) {
            String[] qids = qlist.toArray(new String[qlist.size()]);
            List < Long > qls = new ArrayList < Long >();
            for (String i : qids) {
                qls.add(Long.valueOf(i));
            }
            //报价单ids
            quotids = qls.toArray(new Long[qls.size()]);
        }

        try {
            long end7 = doQueryCompareInfoReal(Long.valueOf(askbillid), quotids, recommendReasons);

            //做查询数据之后的处理
            computeAfterQueryData(params);

            assembleDatatable();
            long end8 = System.currentTimeMillis();
            logger.info("组装datatables耗时(ms):{}", (end8 - end7));
            logger.info("queryPriceCompareInfo:结果返回");
            long end = System.currentTimeMillis();
            logger.info("--------------- 一、性能记录----------------------推荐供应商比价---------------性能记录---------------------- 总耗时(ms):{}", (end - start));
        } catch (Exception e) {
            ExceptionUtils.marsh(e, com.yonyou.cpu.multi.YcMessageUtils.getMessage("P_DIWORK_YC_CPU-PORTAL_0000057325") /* "查询定标单数据失败" */);
        }

    }

    protected void assembleDatatable() {
        askbillHeadDataTable.set(askbillhead1);
        askbillHeadDataTable.setSelect(new Integer[]{0});
        askbillBodyDataTable.set(askbillbodys1);
        askbillBodyDataTable.setTotalPages(1);//songpeng 增加物料规格和型号(根据物料id--product_id查询);产品描述(product_desc)、表体备注(bmemo);
        askbillBodyDataTable.setPageIndex(0);
        askbillBodyDataTable.setPageSize(1);
        priceDataTable.set(compareInfos1);//承兑价,现金价,报价说明,交货期
        priceDataTable.setTotalPages(1);
        priceDataTable.setPageIndex(0);
        priceDataTable.setPageSize(1);
        if (talksDataTable != null && quotationOffers1 != null) {
            talksDataTable.set(quotationOffers1.toArray(new QuotationOffer[0]));
            talksDataTable.setSelect(new Integer[]{0});
        }
        //本期平均价(含税)
        //priceDataTable-rows-data-quotationinfo-key- paymentPrice
        Row[] rows1 = priceDataTable.getRows();
        for (Row str : rows1) {
            Map < String, Field > data = str.getFields();
            Field quotationinfo = data.get("quotationinfo");
            Object[] value = (Object[]) quotationinfo.getValue();
//            HashMap value = (HashMap) quotationinfo.getValue();
//            JSONObject key = (JSONObject) value;
            for (Object o : value) {
            JSONObject key = JSONObject.parseObject(o.toString());
            BigDecimal bd = new BigDecimal(String.valueOf(key));
            BigDecimal paymentPrice1 = (BigDecimal) key.get("paymentPrice");
            BigDecimal a = paymentPrice1;
            BigDecimal d2= (BigDecimal) a;
            String s1 = String.valueOf(a);
            if (s1.contains(".")&&d2!=a){
                int i = s1.indexOf(".");
                for(int j=i;j<s1.length()-1;j++){
                    int lastIndex=s1.charAt(s1.length()-1);
                    int io = s1.lastIndexOf("0");
                    if (lastIndex==io){
                        s1=s1.substring(0,s1.length()-1);
                    }
                }
            }else {
                s1+="0";
            }
            logger.info("s1:"+s1);
            }

        }

img

img

  • 写回答

3条回答 默认 最新

  • 大鹏cool Java领域优质创作者 2022-02-22 19:03
    关注

    截图中 465到467行之间的代码:

                JSONObject key = JSONObject.parseObject(o.toString());
                BigDecimal bd = new BigDecimal(String.valueOf(key));
                BigDecimal paymentPrice1 = (BigDecimal) key.get("paymentPrice");
    

    修改如下可正确获取 paymentPrice1 的值:

                JSONObject key = ((JSONObject)o).getJSONObject("key");
                BigDecimal paymentPrice1 = key.getBigDecimal("paymentPrice");
    
    本回答被题主选为最佳回答 , 对您是否有帮助呢?
    评论
查看更多回答(2条)

报告相同问题?

问题事件

  • 系统已结题 3月3日
  • 已采纳回答 2月23日
  • 创建了问题 2月22日

悬赏问题

  • ¥20 Apache poi使用问题
  • ¥21 matlab怎么求时域信号的二阶导数
  • ¥15 判断两个表是否完全相同
  • ¥15 java map类型数据格式,如何快速通过前缀匹配元素
  • ¥15 stc12c5a60s2、QMC5883L、LCD1602组合测量磁场所需程序
  • ¥20 Win11测试yolov4,“找不到nvcuda.dll”怎么办?
  • ¥15 simulink绘制bode图
  • ¥15 php_network_getaddresses: getaddrinfo failed: Name or service not known
  • ¥15 用msg发消息出现的问题
  • ¥15 unity3d机械臂