码迷,mamicode.com
首页 > Web开发 > 详细

JSONObject操作案例

时间:2020-05-13 20:19:13      阅读:57      评论:0      收藏:0      [点我收藏+]

标签:valueof   sql   eof   ase   new   not   exce   any   数据   

JSONObject jsonObject1 =JSONObject.parseObject(String)
@RequestMapping(params="getICInfo")
    @ResponseBody
    @ApiOperation(value="IC接口",produces="application/json",httpMethod="POST")
    public  JSONObject getICInfo(String token, String data) {
        JSONObject jsonObject =new JSONObject();
        JSONArray jsonarray = new JSONArray();  
        Date date = new Date();
        SimpleDateFormat sdf = new SimpleDateFormat("yyyy-MM-dd");  
        String sql = "";
        try {  
                if(StringUtils.isNotBlank(data)){
                    if("999".equals(data)){
                        sql = " select a.*,b.cus_company ,c.realname "
                                + "   from ld_ic_info a "
                                + "   left join ld_customer b on (a.ic_fromcompany = b.id) "
                                + "   left join t_s_base_user c on (a.ic_person = c.id ) "
                                + "  where update_state > 0 and ic_state in(‘3‘,‘4‘)";
                        List<Map<String, Object>> queryForList = jdbcTemplate.queryForList(sql);
                        if(queryForList!=null && queryForList.size()>0) {
                            
                            for (Map<String, Object> map : queryForList) { 
                                JSONObject json =new JSONObject(); 
                                String ic_code = "";
                                String cus_company = "";
                                String ic_bill_code = "";
                                String ic_comment = "";
                                String ic_pricecomment = "";
                                String ic_invoicecomment = "";
                                String ic_person = "";
                                String ic_ticket = "";
                                String ic_type = "";
                                String ic_rutime = "";
                                String ic_firstrutime = "";
                                String ic_Qyperson = "";
                                String ic_Qyperson_Phone = "";
                                String update_state = "";
                                String create_by = "";
                                String create_date = "";
                                String update_by = "";
                                String update_date = "";
                                if(map.get("ic_code")!=null){
                                    ic_code = String.valueOf(map.get("ic_code"));
                                }
                                if(map.get("cus_company")!=null){
                                    cus_company = String.valueOf(map.get("cus_company"));
                                }
                                if(map.get("ic_bill_code")!=null){
                                    ic_bill_code = String.valueOf(map.get("ic_bill_code"));
                                }
                                if(map.get("ic_comment")!=null){
                                    ic_comment = String.valueOf(map.get("ic_comment"));
                                }
                                if(map.get("ic_pricecomment")!=null){
                                    ic_pricecomment = String.valueOf(map.get("ic_pricecomment"));
                                }
                                if(map.get("ic_invoicecomment")!=null){
                                    ic_invoicecomment = String.valueOf(map.get("ic_invoicecomment"));
                                }
                                if(map.get("realname")!=null){
                                    ic_person = String.valueOf(map.get("realname"));
                                }
                                if(map.get("ic_ticket")!=null){
                                    ic_ticket = String.valueOf(map.get("ic_ticket"));
                                }
                                if(map.get("ic_type")!=null){
                                    ic_type = String.valueOf(map.get("ic_type"));
                                }
                                if(map.get("ic_rutime")!=null){
                                    ic_rutime = sdf.format(map.get("ic_rutime"));
                                } 
                                if(map.get("ic_firstrutime")!=null){
                                    ic_firstrutime = sdf.format(map.get("ic_firstrutime"));
                                }
                                if(map.get("ic_Qyperson")!=null){
                                    ic_Qyperson = String.valueOf(map.get("ic_Qyperson"));
                                }
                                if(map.get("ic_Qyperson_Phone")!=null){
                                    ic_Qyperson_Phone = String.valueOf(map.get("ic_Qyperson_Phone"));
                                }
                                if(map.get("update_state")!=null){
                                    update_state = String.valueOf(map.get("update_state"));
                                }
                                if(map.get("create_by")!=null){
                                    create_by = String.valueOf(map.get("create_by"));
                                }
                                if(map.get("create_date")!=null){
                                    create_date = sdf.format(map.get("create_date"));
                                }
                                if(map.get("update_by")!=null){
                                    update_by = String.valueOf(map.get("update_by"));
                                }
                                if(map.get("update_date")!=null){
                                    update_date = sdf.format(map.get("update_date"));
                                }
                                json.put("ic_code", ic_code);
                                json.put("ic_fromcompany", cus_company);
                                json.put("ic_bill_code", ic_bill_code);
                                json.put("ic_comment", ic_comment);
                                json.put("ic_pricecomment", ic_pricecomment);
                                
                                json.put("ic_invoicecomment", ic_invoicecomment);
                                json.put("ic_person", ic_person);
                                json.put("ic_ticket", ic_ticket);
                                json.put("ic_type", ic_type);
                                json.put("ic_rutime", ic_rutime);
                                
                                json.put("ic_firstrutime", ic_firstrutime);
                                json.put("ic_Qyperson", ic_Qyperson);
                                json.put("ic_Qyperson_Phone", ic_Qyperson_Phone);
                                json.put("updatestate", update_state);
                                json.put("create_by", create_by);
                                 
                                json.put("create_date", create_date);
                                json.put("update_by",update_by);
                                json.put("update_date", update_date);
                                
                                String ic_id = String.valueOf(map.get("id"));
                                sql = " select a.ic_type,a.ic_cost,a.ic_offer from ld_ic_price a ,ld_ic_info b where a.ic_id = b.id and b.id=‘"+ic_id+"‘";
                                List<Map<String, Object>> sonList = jdbcTemplate.queryForList(sql);
                                JSONArray jsonarray1 = new JSONArray();  
                                for (Map<String, Object> map2 : sonList) { 
                                    JSONObject json1 =new JSONObject();
                                    String ic_type1 = String.valueOf(map2.get("ic_type"));
                                    String ic_cost = String.valueOf(map2.get("ic_cost"));
                                    String ic_offer = String.valueOf(map2.get("ic_offer"));
                                    if(map2.get("ic_cost")==null){
                                        ic_cost="";
                                    }
                                    if(map2.get("ic_offer")==null){
                                        ic_offer="";
                                    }
                                    if(StringUtils.isNotBlank(ic_type1)){
                                        json1.put("ic_type", ic_type1);
                                        json1.put("ic_cost", ic_cost);
                                        json1.put("ic_offer", ic_offer);
                                        jsonarray1.add(json1);
                                    }
                                }
                                json.put("fy_info",JSONObject.toJSONString(jsonarray1));        
                                jsonarray.add(json);
                            }
                        } 
                    }else{
                        sql = " select a.*,b.cus_company ,c.realname "
                                + "   from ld_ic_info a "
                                + "   left join ld_customer b on (a.ic_fromcompany = b.id) "
                                + "   left join t_s_base_user c on (a.ic_person = c.id ) "
                                + "  where a.ic_code = ‘"+data+"‘  ";
                        Map<String, Object> map  = jdbcTemplate.queryForMap(sql);
                        if(map!=null && map.size()>0) {
                            JSONObject json =new JSONObject(); 
                            String ic_code = "";
                            String cus_company = "";
                            String ic_bill_code = "";
                            String ic_comment = "";
                            String ic_pricecomment = "";
                            String ic_invoicecomment = "";
                            String ic_person = "";
                            String ic_ticket = "";
                            String ic_type = "";
                            String ic_rutime = "";
                            String ic_firstrutime = "";
                            String ic_Qyperson = "";
                            String ic_Qyperson_Phone = "";
                            String update_state = "";
                            String create_by = "";
                            String create_date = "";
                            String update_by = "";
                            String update_date = "";
                            if(map.get("ic_code")!=null){
                                ic_code = String.valueOf(map.get("ic_code"));
                            }
                            if(map.get("cus_company")!=null){
                                cus_company = String.valueOf(map.get("cus_company"));
                            }
                            if(map.get("ic_bill_code")!=null){
                                ic_bill_code = String.valueOf(map.get("ic_bill_code"));
                            }
                            if(map.get("ic_comment")!=null){
                                ic_comment = String.valueOf(map.get("ic_comment"));
                            }
                            if(map.get("ic_pricecomment")!=null){
                                ic_pricecomment = String.valueOf(map.get("ic_pricecomment"));
                            }
                            if(map.get("ic_invoicecomment")!=null){
                                ic_invoicecomment = String.valueOf(map.get("ic_invoicecomment"));
                            }
                            if(map.get("realname")!=null){
                                ic_person = String.valueOf(map.get("realname"));
                            }
                            if(map.get("ic_ticket")!=null){
                                ic_ticket = String.valueOf(map.get("ic_ticket"));
                            }
                            if(map.get("ic_type")!=null){
                                ic_type = String.valueOf(map.get("ic_type"));
                            }
                            if(map.get("ic_rutime")!=null){
                                ic_rutime = sdf.format(map.get("ic_rutime"));
                            } 
                            if(map.get("ic_firstrutime")!=null){
                                ic_firstrutime = sdf.format(map.get("ic_firstrutime"));
                            }
                            if(map.get("ic_Qyperson")!=null){
                                ic_Qyperson = String.valueOf(map.get("ic_Qyperson"));
                            }
                            if(map.get("ic_Qyperson_Phone")!=null){
                                ic_Qyperson_Phone = String.valueOf(map.get("ic_Qyperson_Phone"));
                            }
                            if(map.get("update_state")!=null){
                                update_state = String.valueOf(map.get("update_state"));
                            }
                            if(map.get("create_by")!=null){
                                create_by = String.valueOf(map.get("create_by"));
                            }
                            if(map.get("create_date")!=null){
                                create_date = sdf.format(map.get("create_date"));
                            }
                            if(map.get("update_by")!=null){
                                update_by = String.valueOf(map.get("update_by"));
                            }
                            if(map.get("update_date")!=null){
                                update_date = sdf.format(map.get("update_date"));
                            }
                            json.put("ic_code", ic_code);
                            json.put("ic_fromcompany", cus_company);
                            json.put("ic_bill_code", ic_bill_code);
                            json.put("ic_comment", ic_comment);
                            json.put("ic_pricecomment", ic_pricecomment);
                            
                            json.put("ic_invoicecomment", ic_invoicecomment);
                            json.put("ic_person", ic_person);
                            json.put("ic_ticket", ic_ticket);
                            json.put("ic_type", ic_type);
                            json.put("ic_rutime", ic_rutime);
                            
                            json.put("ic_firstrutime", ic_firstrutime);
                            json.put("ic_Qyperson", ic_Qyperson);
                            json.put("ic_Qyperson_Phone", ic_Qyperson_Phone);
                            json.put("updatestate", update_state);
                            json.put("create_by", create_by);
                             
                            json.put("create_date", create_date);
                            json.put("update_by",update_by);
                            json.put("update_date", update_date);
                            String ic_id = String.valueOf(map.get("id"));
                            sql = " select a.ic_type,a.ic_cost,a.ic_offer from ld_ic_price a ,ld_ic_info b where a.ic_id = b.id and b.id=‘"+ic_id+"‘";
                            List<Map<String, Object>> sonList = jdbcTemplate.queryForList(sql);
                            JSONArray jsonarray1 = new JSONArray();  
                            for (Map<String, Object> map2 : sonList) { 
                                JSONObject json1 =new JSONObject();
                                String ic_type1 = String.valueOf(map2.get("ic_type"));
                                String ic_cost = String.valueOf(map2.get("ic_cost"));
                                String ic_offer = String.valueOf(map2.get("ic_offer"));
                                if(map2.get("ic_cost")==null){
                                    ic_cost="";
                                }
                                if(map2.get("ic_offer")==null){
                                    ic_offer="";
                                }
                                if(StringUtils.isNotBlank(ic_type1)){
                                    json1.put("ic_type", ic_type1);
                                    json1.put("ic_cost", ic_cost);
                                    json1.put("ic_offer", ic_offer);
                                    jsonarray1.add(json1);
                                }
                            }
                            json.put("fy_info",JSONObject.toJSONString(jsonarray1));        
                            jsonarray.add(json);
                        }
                    }
                } 
            
            jsonObject.put("content", jsonarray);
            jsonObject.put("result", "success");
            systemService.addLog("执行客户付款周期诚信数据同步", Globals.Log_Type_ldcorder, Globals.Log_Leavel_INFO);
    
            
        } catch (Exception e) {
            
            e.printStackTrace();
            jsonObject.put("result", "error");
        }
        
        return jsonObject;
    }


    @RequestMapping(params="setICUpdtaestate")
    @ResponseBody
    @ApiOperation(value="调用成功的数据返回设置update_state",produces="application/json",httpMethod="POST")
    public  JSONObject setICUpdtaestate(String token, String content) {
        JSONObject jsonObject =new JSONObject();
        List<Map> parseArray = JSONObject.parseArray(content, Map.class);
         
        try {
            for (Map map : parseArray) {
                
                String ic_code = (String) map.get("ordercode");    
                String update_state = (String) map.get("updatestate");     
                
                if(StringUtils.isNotEmpty(ic_code)) {
                     String sqldem=" update  ld_ic_info a set a.update_state = 0 where a.ic_code = ‘"+ic_code+"‘ and a.update_state = ‘"+update_state+"‘";
                     jdbcTemplate.execute(sqldem);    
                }  
            }
            jsonObject.put("result", "success");
        } catch (Exception e) {
            
            e.printStackTrace();
            jsonObject.put("result", "error");
        }
        
        return jsonObject;
    }

 

JSONObject操作案例

标签:valueof   sql   eof   ase   new   not   exce   any   数据   

原文地址:https://www.cnblogs.com/xueblvip/p/12884251.html

(0)
(0)
   
举报
评论 一句话评论(0
登录后才能评论!
© 2014 mamicode.com 版权所有  联系我们:gaon5@hotmail.com
迷上了代码!