利用new Gson()的toJson方法将map对象转成json字符串


 1 package mpsm.mcpsm.operation.demandInfoLoad.service;
 2 
 3 import java.sql.ResultSet;
 4 import java.text.DecimalFormat;
 5 import java.util.ArrayList;
 6 import java.util.HashMap;
 7 import java.util.List;
 8 
 9 import mpsm.mcpsm.operation.demandInfoLoad.dao.DemandFactoryQualifiedInfoLoadDao;
10 
11 import com.google.gson.Gson;
12 import com.longshine.indigo.component.description.ClassDescription;
13 
14 import epm.core.service.BaseService;
15 
16 public class DemandFactoryQualifiedInfoLoadService extends BaseService {
17     DemandFactoryQualifiedInfoLoadDao dao = new DemandFactoryQualifiedInfoLoadDao();
18     //单位:万只 千只
19     private int unit = 1000;
20     @Override
21     public ClassDescription getClassDescription() {
22 
23         return new ClassDescription("", DemandFactoryQualifiedInfoLoadService.class
24                 .getName(), "", "");
25     }
26 
27     /**
28      * 查询当年厂家设备到货情况汇总信息
29      * 
30      * @return
31      */
32     public String queryDemandFactoryQualifiedInfoLoad(String orgNo) {
33         List<Object> list_Num = new ArrayList<Object>();
34         List<String> list_Factory_Name = new ArrayList<String>();
35         DecimalFormat df=new DecimalFormat("#.##");
36         DecimalFormat df1=new DecimalFormat("0");
37         String factory_Name;//厂家名字
38         double sumDetectQlfNum;//检定合格数量
39         double sumDetectUnqlfNum2;//检定不合格数量
40         double detectQlfNumRatio = 0.0;
41         double change = 0.0;
42         double maxY = 0.0;
43         HashMap  checkMapNum ;
44         HashMap  checkMapFactoryName ;
45         try{
46             ResultSet rs = dao.queryDemandFactoryQualifiedInfoLoad(orgNo);
47             while(rs.next()){
48                 factory_Name = rs.getString("FACTORY_NAME");
49                 checkMapFactoryName = new HashMap();
50                 list_Factory_Name.add(factory_Name);
51                 
52                 sumDetectQlfNum = rs.getDouble("SUM_DETECT_QLF_NUM")/unit;
53                 sumDetectUnqlfNum2 = rs.getDouble("SUM_DETECT_UNQLF_NUM2")/unit;
54                 detectQlfNumRatio = rs.getDouble("DETECT_QLF_NUM_RATIO");
55                 
56                 checkMapNum = new HashMap();
57                 double[] value = new double[]{Double.parseDouble(df.format(sumDetectQlfNum)),Double.parseDouble(df.format(sumDetectUnqlfNum2))};
58                 checkMapNum.put("value", value);
59                 checkMapNum.put("percent", df.format(detectQlfNumRatio*100));
60                 list_Num.add(checkMapNum);
61                 
62                 change  = sumDetectQlfNum+sumDetectUnqlfNum2;
63                 if(change > maxY){
64                     maxY = change ;
65                 }
66             }
67         }catch(Exception e){
68             e.printStackTrace();
69         }
70         HashMap  dataMap = new HashMap();
71         if("01".equals(orgNo)){
72             dataMap.put("orgNo", "02");
73         }
74         if("02".equals(orgNo)){
75             dataMap.put("orgNo", "03");
76         }
77         if("03".equals(orgNo)){
78             dataMap.put("orgNo", "04");
79         }
80         if("04".equals(orgNo)){
81             dataMap.put("orgNo", "01");
82         }
83         Object[] factoryName = list_Factory_Name.toArray();
84         dataMap.put("dataList_Factory_Name", factoryName);
85         dataMap.put("dataList_data", list_Num);
86         dataMap.put("maxY", Integer.parseInt(df1.format(((maxY/5)+1)))*5);
87         //{"dataList_Num":[{"value":[67.6,0.6],"percent":"99.12"},{"value":[17.6,0.6],"percent":"96.7"},{"value":[7.6,0.6],"percent":"92.68"},{"value":[57.6,5.76],"percent":"90.91"}],"orgNo":"02","dataList_Factory_Name":["环球","报达","金雀","华兴"]}===
88         return new Gson().toJson(dataMap);
89     }
90 }
View Code

 

智能推荐

注意!

本站转载的文章为个人学习借鉴使用,本站对版权不负任何法律责任。如果侵犯了您的隐私权益,请联系我们删除。



 
© 2014-2019 ITdaan.com 粤ICP备14056181号  

赞助商广告