/** * 获取某些属性的枚举值 * * @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 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(); }