/** * 获取某些属性的枚举值 * * @param attrIdArr 属性ID集合 * @return * @throws Exception */ private List<ValueTableEntity> getValueTableByAttrIds(List<String> attrIdArr) throws Exception { List<ValueTableEntity> valueTables = new ArrayList<ValueTableEntity>(); if (attrIdArr != null && attrIdArr.size() > 0) { DefaultDal<ValueTableEntity> dal = new DefaultDal<ValueTableEntity>(ValueTableEntity.class); valueTables = dal.getLst( "SELECT * FROM BMP_VALUETABLE WHERE VALUE_TYPE IN (SELECT VALUE_TYPE FROM BMP_ATTRIBUTE WHERE ATTRIB_ID IN (" + StringUtils.join(attrIdArr, ',') + "))"); } return valueTables; }
/** * 更新 * * @param objXml 参数 * @throws Exception 异常 */ @Business public void updateReportFile(String objXml) throws Exception { DefaultDal<ReportFileEntity> dal = new DefaultDal<ReportFileEntity>(ReportFileEntity.class); dal.updateXml(objXml); }
/** * 新增 * * @param objXml 参数 * @return 结果 * @throws Exception 异常 */ @Business public String addReportFile(String objXml) throws Exception { DefaultDal<ReportFileEntity> dal = new DefaultDal<ReportFileEntity>(ReportFileEntity.class); return "" + dal.insertXml(objXml); }
/** * 获取其他类型的对象的性能数据 * * @param objXml 固定界面的对象的XML * @param type 对象类型 * @param objID 对象ID * @return 性能数据XML * @throws Exception 异常 */ public String getElseObjCollValue(String objXml, String type, int objID) throws Exception { // 定义一个Document作为返回结果 Document result_doc = DocumentHelper.parseText( "<?xml version=\"1.0\" encoding=\"UTF-8\"?><DataSource></DataSource>"); // 解析objXml,获取从哪些表获取哪些数据等信息 Document doc = DocumentHelper.parseText(objXml); List list = doc.selectNodes("ElseObject/" + type + "/DataTable"); if (list != null) { Iterator it = list.iterator(); while (it.hasNext()) { // 解析要查询的表及数据条数 Element tableEle = (Element) it.next(); String table = tableEle.attribute("table").getValue(); String collValueNum = tableEle.attribute("collValueNum").getValue(); // 在结果Document的根节点下添加表节点 Element ele = result_doc.getRootElement().addElement("DATA_TABLE"); ele.addAttribute("TABLE_NAME", table); // DVB_C类型的对象属性与其他类型的查询方式不同 // 获取最近的collValueNum个采集时间 String cmd = ""; if ("DVB_C".equals(type)) { cmd = sqlExecutor .getSqlParser() .getSelectCommandString( table, Integer.parseInt(collValueNum), false, "COLL_TIME", null, "ORDER BY COLL_TIME DESC", new SqlCondition( "FREQ_ID", "SELECT FREQ_ID FROM NMP_OBJDVBCTS WHERE OBJ_ID=" + objID + "", SqlLogicType.And, SqlRelationType.In, SqlParamType.UnKnow, true)); } else { cmd = sqlExecutor .getSqlParser() .getSelectCommandString( table, Integer.parseInt(collValueNum), false, "COLL_TIME", null, "ORDER BY COLL_TIME DESC", new SqlCondition( "OBJ_ID", String.valueOf(objID), SqlLogicType.And, SqlRelationType.Equal, SqlParamType.Numeric)); } // 将采集时间存入List final List<String> timeList = new ArrayList<String>(); DefaultDal.read( cmd, new IReadHandle() { @Override public void handle(ResultSet timeRS) throws Exception { while (timeRS.next()) { timeList.add(timeRS.getString("COLL_TIME")); } } }); // 针对每个采集时间,从指定的表中获取数据 if (timeList != null && timeList.size() > 0) { for (int k = 0; k < timeList.size(); k++) { // 如果是第一条,添加最大时间 if (k == 0) { ele.addAttribute("max_time", timeList.get(k)); } Document coll = null; if ("DVB_C".equals(type)) { coll = sqlExecutor.fill( "SELECT * FROM " + table + " WHERE FREQ_ID IN (SELECT FREQ_ID FROM NMP_OBJDVBCTS WHERE OBJ_ID=" + String.valueOf(objID) + ") AND COLL_TIME='" + timeList.get(k) + "'", "DataTable", table); } else { coll = sqlExecutor.fill( "SELECT * FROM " + table + " WHERE OBJ_ID=" + String.valueOf(objID) + " AND COLL_TIME='" + timeList.get(k) + "'", "DataTable", table); } // 组装结果 ele.appendContent(coll.getRootElement()); } } } } return result_doc.asXML(); }
/** * 获取某对象的某类别的自定义属性或者配置信息、表格数据的值 * * @param objId 对象ID * @param classId 分类ID * @param isFresh 是否刷新 * @return 自定义属性或者配置信息、表格数据的值XML * @throws Exception 异常 */ public String getObjAttrValueByObjAndClass(int objId, int classId, boolean isFresh) throws Exception { // 定义一个Document作为返回结果 Document result_doc = DocumentHelper.parseText( "<?xml version=\"1.0\" encoding=\"UTF-8\"?><DataSource></DataSource>"); // 查询该对象该分类下的所有对象属性 List<Map<String, String>> lst = new SqlQueryUtil() .getLst( "SELECT A.OBJATTR_ID,A.OBJATTR_NAME,A.ATTRIB_TYPE,B.VALUE_TYPE,B.DATA_UNIT FROM BMP_OBJATTRIB A " + "LEFT JOIN BMP_ATTRIBUTE B ON A.ATTRIB_ID=B.ATTRIB_ID LEFT JOIN BMP_ATTRIB2CLASS C ON B.ATTRIB_ID=C.ATTRIB_ID " + "LEFT JOIN BMP_ATTRIBCLASS D ON C.CLASS_ID=D.CLASS_ID WHERE A.IS_VISIBLE=1 AND A.OBJ_ID=" + objId + " AND D.CLASS_ID=" + classId); if (lst != null && lst.size() > 0) { List<String> valueArr = new ArrayList<String>(); List<Integer> objattrIdLst = new ArrayList<Integer>(); for (Map<String, String> map : lst) { objattrIdLst.add(Integer.valueOf(map.get("OBJATTR_ID"))); if (!StringUtil.isNullOrEmpty(map.get("VALUE_TYPE")) && !"0".equals(map.get("VALUE_TYPE"))) { valueArr.add(map.get("VALUE_TYPE")); } } // 查询枚举信息 List<ValueTableEntity> valueTables = new ArrayList<ValueTableEntity>(); if (valueArr != null && valueArr.size() > 0) { String valueTypes = StringUtils.join(valueArr, ','); DefaultDal<ValueTableEntity> dal = new DefaultDal<ValueTableEntity>(ValueTableEntity.class); valueTables = dal.getLst( new SqlCondition( "VALUE_TYPE", valueTypes, SqlLogicType.And, SqlRelationType.In, SqlParamType.Numeric)); } // 调用接口 int[] arr = ArrayUtils.listToIntArray(objattrIdLst); Map<Integer, QueryResult> values = CollDataQuery.getInstance().query(objId, arr, isFresh); // 根据结果组装XML if (values != null && values.size() > 0) { for (Map<String, String> map : lst) { String objattrId = map.get("OBJATTR_ID"); String objattrName = map.get("OBJATTR_NAME"); String valueType = map.get("VALUE_TYPE"); String dataUnit = map.get("DATA_UNIT"); String attribType = map.get("ATTRIB_TYPE"); Element ele = result_doc.getRootElement().addElement("DataTable"); Element eleId = ele.addElement("OBJATTR_ID"); eleId.setText(objattrId); Element eleName = ele.addElement("OBJATTR_NAME"); eleName.setText(objattrName); Element eleType = ele.addElement("VALUE_TYPE"); eleType.setText(valueType); Element eleUnit = ele.addElement("DATA_UNIT"); eleUnit.setText(dataUnit); Element eleValue = ele.addElement("STR_VALUE"); QueryResult resultLst = values.get(Integer.valueOf(objattrId)); String value = resultLst.getValue(); // 如果存在格式化信息,则格式化 if (!StringUtil.isNullOrEmpty(valueType) && !"0".equals(valueType) && valueTables.size() > 0) { List<ValueTableEntity> valueLst = new ArrayList<ValueTableEntity>(); for (ValueTableEntity entity : valueTables) { if (valueType.equals(String.valueOf(entity.getValueType()))) { valueLst.add(entity); } } eleValue.setText(formatObjAttribValue(value, attribType, valueLst)); } else { if (StringUtil.isNullOrEmpty(value)) { eleValue.setText(""); } else { eleValue.setText(value); } } } } } return result_doc.asXML(); }