123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161 |
- package com.chart;
- import java.lang.reflect.Method;
- import java.util.ArrayList;
- import java.util.Arrays;
- import java.util.HashMap;
- import java.util.List;
- import java.util.Map;
- import org.apache.log4j.Logger;
- import com.chart.common.ExtendJdbcHelp;
- import com.chart.vo.ChartData;
- import com.chart.vo.QueryVo;
- import com.formaction.vo.RowSet;
- import com.sysmodel.datamodel.xmlmodel.ModelFactory;
- import com.sysmodel.datamodel.xmlmodel.Reference;
- import com.sysmodel.datamodel.xmlmodel.able.MdpAttribute;
- import com.sysmodel.datamodel.xmlmodel.able.MdpClass;
- import com.sysmodel.datamodel.xmlmodel.able.MdpConstant;
- import com.sysmodel.datamodel.xmlmodel.able.SysModel;
- /**
- * 统计分析图查询的主类
- *
- * @author peterkong
- *
- */
- public abstract class Chart{
- public final static int PIE = 1;
- public final static int LINE = 2;
- public final static int BAR = 3;
- private static SysModel sysmodel = ModelFactory.getSysmodel();
- private final static Logger log = Logger.getLogger(ExtendJdbcHelp.class);
- private final static String params[] = { "TypeChart", "FieldXAxis", "classid", "StartTime",
- "EndTime", "FieldTime" };
- /**
- * 返回给前台的JSON数据,在子类中实现自己的数据格式
- *
- * @return
- */
- public abstract List<ChartData> getJsonData();
- /**
- * 查询数据同一方法,返回数据格式未定
- *
- * @param classid
- * @param propertyName
- * 统计字段的名称
- * @return
- */
- public List<RowSet> queryData(QueryVo extParam) {
- int classId = Integer.valueOf(extParam.getClassid());
- String typeChart = extParam.getTypeChart();
- ExtendJdbcHelp ejh = new ExtendJdbcHelp(classId);
- MdpClass mdpClass = sysmodel.getMdpClassByClassID(classId);
- String tableName = mdpClass.getName();
- List<RowSet> rowSetList = new ArrayList<RowSet>();
- String businessWhere = "";
- String dateWhere = "";
- if (typeChart.equals(String.valueOf(Chart.PIE))
- || typeChart.equals(String.valueOf(Chart.BAR))) {
- // List<MdpAttributeImpl> attributeList =
- // mdpClass.getAllMdpAttributes();
- if (extParam.getFieldXAxis() != null) {
- businessWhere = ejh.assemblyWhereSql(extParam.getFieldXAxis(),
- new ArrayList<String>(extParam.getTranferConstant().keySet()));
- }
- if (extParam.getFieldTime() != null) {
- dateWhere = ejh.assemblyWhereDate(extParam.getFieldTime(), extParam.getStartTime(),
- extParam.getEndTime());
- }
- String executeSql = ejh.assemblyQuerySql(tableName, extParam.getFieldXAxis(),
- businessWhere, dateWhere);
- log.info("执行统计语句:" + executeSql);
- rowSetList.add(ejh.queryData(executeSql));// 执行SQL语句返回具体内容
- } else if (typeChart.equals(String.valueOf(Chart.LINE))) {
- }
- return rowSetList;
- }
- private static QueryVo initConstant(QueryVo vo) {
- int classid = Integer.valueOf(vo.getClassid());
- MdpClass mdpClass = sysmodel.getMdpClassByClassID(classid);
- String referenceTable = null;
- MdpAttribute atttrbute = mdpClass.getMdpAttributeByName(vo.getFieldXAxis());// getxAxis是作为饼图的属性字段
- Reference reference = atttrbute.getReference();// 取得子集
- referenceTable = reference.getReferenceTable();// 获取相关联的常量表
- MdpConstant mdpConstant = sysmodel.getMdpConstantByName(referenceTable);// 读取某一常量的具体数据
- List<String[]> nodeList = mdpConstant.getAllNode();// 这是全部的常量值
- Map<String, String> transConstant = new HashMap<String, String>();
- for (String[] ConstantValue : nodeList) {
- transConstant.put(ConstantValue[0], ConstantValue[1]);
- }
- vo.setTranferConstant(transConstant);
- return vo;
- }
- /**
- * 解析前台的参数,并转成QueryVo对象 解析参数需要注意的是,前台的参数名称需要和VO中的名称相等,这样才能利用反射实现动态读取
- *
- * @param propertyName
- * @return
- */
- @SuppressWarnings({ "unchecked", "rawtypes" })
- public static QueryVo paraseParam(String propertyName) {
- QueryVo qvReturn = new QueryVo();
- String[] splitParam = propertyName.split("&");
- int splitValue = -1;
- String tmpName = null;
- String tmpValue = null;
- List<String> p = Arrays.asList(params);
- try {
- Class c = Class.forName("com.chart.vo.QueryVo");
- Object obj = c.newInstance();
- Method m = null;
- for (String value : splitParam) {
- splitValue = value.indexOf("=");
- tmpName = value.substring(0, splitValue);
- tmpValue = value.substring(splitValue + 1);
- if (p.contains(tmpName)) {
- m = c.getMethod(getGetMethod(tmpName),
- new Class[] { Class.forName("java.lang.String") });
- m.invoke(obj, new Object[] { tmpValue });
- }
- }
- qvReturn = (QueryVo) obj;
- qvReturn = initConstant(qvReturn);
- } catch (Exception e) {
- log.error(e);
- }
- return qvReturn;
- }
- private static String getGetMethod(String proName) {
- proName = "set" + proName.substring(0, 1).toUpperCase() + proName.substring(1);
- return proName;
- }
- }
|