| | |
| | | if (preX != x || preY != y) { |
| | | fieldConfigObj = new JSONObject(); |
| | | areaList.add(fieldConfigObj); |
| | | } else if (areaList.size() > 0) { |
| | | fieldConfigObj = areaList.get(areaList.size() - 1); |
| | | } else { |
| | | continue; |
| | | } |
| | | fieldConfigObj = areaList.get(areaList.size() - 1); |
| | | } |
| | | fieldConfigObj.put(attrFse.getString(CmnConst.ATTR_NAME), attrFse.getString(CmnConst.ATTR_VALUE)); |
| | | fieldConfigObj.put(CmnConst.ATTR_X, x); |
| | | fieldConfigObj.put(CmnConst.ATTR_Y, y); |
| | |
| | | RedisUtil.setHash(reportConfigUUID, String.valueOf(entry.getKey()), entry.getValue()); |
| | | } |
| | | } |
| | | |
| | | |
| | | /** |
| | | * 获取报表 |
| | |
| | | return report; |
| | | } |
| | | |
| | | /** |
| | | * 获取报表 |
| | | * |
| | | * @return |
| | | */ |
| | | public JSONObject getReport(FieldSetEntity fse) { |
| | | String reportConfigUUID = fse.getUUID(); |
| | | DataTableEntity reportConfigDte = DataPoolCacheImpl.getInstance().getCacheData(CmnConst.CACHE_REPORT_CONFIG, new String[]{reportConfigUUID}); |
| | | if (BaseUtil.dataTableIsEmpty(reportConfigDte)) { |
| | | throw new BaseException(ReportCode.GET_CACHE_FIAL.getValue(), ReportCode.GET_CACHE_FIAL.getText() + ":" + CmnConst.CACHE_REPORT_CONFIG); |
| | | } |
| | | FieldSetEntity reportConfigFse = reportConfigDte.getFieldSetEntity(0); |
| | | if (!"1".equals(reportConfigFse.getString(CmnConst.IS_VALID))) { |
| | | throw new BaseException(ReportCode.INVALID_REPORT.getValue(), ReportCode.INVALID_REPORT.getText()); |
| | | } |
| | | |
| | | DataTableEntity reportTypeDte = DataPoolCacheImpl.getInstance().getCacheData(CmnConst.CACHE_REPORT_TYPE, new String[]{reportConfigFse.getString(CmnConst.TYPE_UUID)}); |
| | | if (BaseUtil.dataTableIsEmpty(reportTypeDte)) { |
| | | throw new BaseException(ReportCode.GET_CACHE_FIAL.getValue(), ReportCode.GET_CACHE_FIAL.getText() + ":" + CmnConst.CACHE_REPORT_TYPE); |
| | | } |
| | | FieldSetEntity reportTypeFse = reportTypeDte.getFieldSetEntity(0); |
| | | |
| | | StringBuilder sort = new StringBuilder(128); |
| | | // 获取报表缓存信息 |
| | | Map<Integer, List<JSONObject>> reportConfigMap = getReportConfig(reportConfigUUID, sort); |
| | | // 根据具体的function_uuid和button_uuid获取对应的路由,拼凑url |
| | | String url; |
| | | JSONObject valueObj; |
| | | for (Map.Entry<Integer, List<JSONObject>> entry : reportConfigMap.entrySet()) { |
| | | if (entry.getValue() != null) { |
| | | for (JSONObject tempValueObj : entry.getValue()) { |
| | | if (entry.getValue() != null) { |
| | | for (Map.Entry<String, Object> innerEntry : tempValueObj.entrySet()) { |
| | | if (innerEntry.getValue() instanceof JSONObject) { |
| | | valueObj = (JSONObject) innerEntry.getValue(); |
| | | if (!StringUtils.isEmpty(valueObj.getString(CmnConst.SUB_REPORT))) { |
| | | url = valueObj.getString(CmnConst.SUB_REPORT); |
| | | if (!StringUtils.isEmpty(valueObj.getString(CmnConst.ATTR_URL_PARAM))) { |
| | | url += "?" + valueObj.getString(CmnConst.ATTR_URL_PARAM); |
| | | } |
| | | valueObj.put(CmnConst.ATTR_URL, url); |
| | | valueObj.put("~isSubReport~", true); |
| | | } else { |
| | | if (!StringUtils.isEmpty(valueObj.getString(CmnConst.FUNCTION_UUID)) && !StringUtils.isEmpty(valueObj.getString(CmnConst.BUTTON_UUID))) { |
| | | url = routerService.functionSkipByButtonUuid(valueObj.getString(CmnConst.FUNCTION_UUID), valueObj.getString(CmnConst.BUTTON_UUID)); |
| | | if (StringUtils.isEmpty(url)) { |
| | | valueObj.remove(CmnConst.ATTR_URL); |
| | | } else { |
| | | if (!StringUtils.isEmpty(valueObj.getString(CmnConst.ATTR_URL_PARAM))) { |
| | | url += "?" + valueObj.getString(CmnConst.ATTR_URL_PARAM); |
| | | } |
| | | valueObj.put(CmnConst.ATTR_URL, url); |
| | | } |
| | | } else { |
| | | valueObj.remove(CmnConst.ATTR_URL); |
| | | } |
| | | } |
| | | } |
| | | } |
| | | } |
| | | } |
| | | } |
| | | } |
| | | // 获取报表类型 |
| | | String reportType = reportTypeFse.getString(CmnConst.TYPE_NAME); |
| | | // 获取数据源 |
| | | DataTableEntity reportSourceDte = DataPoolCacheImpl.getInstance().getCacheData(CmnConst.CACHE_REPORT_DATASOURCE_CONFIG, new String[]{reportConfigFse.getString(CmnConst.DATASOURCE_UUID)}); |
| | | if (BaseUtil.dataTableIsEmpty(reportSourceDte)) { |
| | | throw new BaseException(ReportCode.GET_REPORT_DATASOURCE_FIAL.getValue(), ReportCode.GET_REPORT_DATASOURCE_FIAL.getText()); |
| | | } |
| | | FieldSetEntity reportSourceFse = reportSourceDte.getFieldSetEntity(0); |
| | | int curPage = fse.getInteger(CmnConst.CPAGE) == null ? 1 : fse.getInteger(CmnConst.CPAGE); |
| | | |
| | | JSONObject resultObj = new JSONObject(); |
| | | // 首次加载,默认添加条件 |
| | | if (fse.getBoolean(CmnConst.FIRST_LOAD)) { |
| | | DataTableEntity allFilterDte = getDefaultSearchFilter(reportSourceFse.getUUID()); |
| | | Map<String, DataTableEntity> subMap = Maps.newHashMap(); |
| | | if (!DataTableEntity.isEmpty(allFilterDte)) { |
| | | subMap.put("systemFieldMeta", allFilterDte); |
| | | } |
| | | DataTableEntity defaultFilterDte = new DataTableEntity(); |
| | | |
| | | FieldSetEntity tempFse; |
| | | Map<String, Map<String, String>> outerMap = Maps.newHashMap(); |
| | | Map<String, String> innerMap; |
| | | for (int i = 0; i < allFilterDte.getRows(); i++) { |
| | | tempFse = allFilterDte.getFieldSetEntity(i); |
| | | if (StringUtils.isEmpty(tempFse.getString(CmnConst.LOGICAL_VALUE))) { |
| | | continue; |
| | | } |
| | | defaultFilterDte.addFieldSetEntity(tempFse); |
| | | innerMap = Maps.newHashMap(); |
| | | innerMap.put(CmnConst.LOGICAL_OPERATOR, tempFse.getString(CmnConst.LOGICAL_OPERATOR)); |
| | | innerMap.put(CmnConst.LOGICAL_VALUE, tempFse.getString(CmnConst.LOGICAL_VALUE)); |
| | | innerMap.put(CmnConst.FIELD_TYPE, tempFse.getString(CmnConst.FIELD_TYPE)); |
| | | outerMap.put(tempFse.getString(CmnConst.FIELD_NAME), innerMap); |
| | | } |
| | | resultObj.put("filterInfo", outerMap); |
| | | |
| | | if (!DataTableEntity.isEmpty(defaultFilterDte)) { |
| | | subMap.put("systemSeniorQueryString", defaultFilterDte); |
| | | } |
| | | fse.setSubData(subMap); |
| | | } |
| | | |
| | | DataTableEntity recordDte = getRecordDte(sort, curPage, reportSourceFse, fse, reportConfigFse, null); |
| | | // 是否添加总合计 |
| | | boolean totalStatisticsFlag = "1".equalsIgnoreCase(reportConfigFse.getString(CmnConst.LAST_TOTAL)); |
| | | String totalName = totalStatisticsFlag ? (StringUtils.isEmpty(reportConfigFse.getString(CmnConst.TOTAL_NAME)) ? "总计" : reportConfigFse.getString(CmnConst.TOTAL_NAME)) : ""; |
| | | |
| | | // JSONObject checkObj = checkRecordDte(recordDte); |
| | | // if (CmnConst.FALSE.equals(checkObj.getString(CmnConst.RETURN_ATTR_RESULT))) { |
| | | // return checkObj; |
| | | // } |
| | | |
| | | StringBuilder tableStyle = new StringBuilder(32); |
| | | String widthType = reportConfigFse.getString(CmnConst.REPORT_WIDTH_TYPE); |
| | | String width = reportConfigFse.getString(CmnConst.REPORT_WIDTH_VALUE); |
| | | if (!StringUtils.isEmpty(width)) { |
| | | if ("1".equals(widthType)) { |
| | | tableStyle.append(" style=\"width:").append(width).append("%\""); |
| | | } else if ("0".equals(widthType)) { |
| | | tableStyle.append(" style=\"width:").append(width).append("px\""); |
| | | } |
| | | } |
| | | |
| | | if (CmnConst.REPORT_TYPE_COMMON.equals(reportType)) { |
| | | resultObj.putAll(commonReportService.getReport(recordDte, totalName, reportConfigMap, tableStyle)); |
| | | } else if (CmnConst.REPORT_TYPE_GROUP.equals(reportType)) { |
| | | // 特殊处理额外查询内容 |
| | | recordDte.addFieldSetEntity(getRecordDte(sort, curPage, reportSourceFse, fse, reportConfigFse, reportConfigMap)); |
| | | resultObj.putAll(groupReportService.getReport(recordDte, totalName, reportConfigMap, tableStyle)); |
| | | } |
| | | |
| | | if (CmnConst.FALSE.equals(resultObj.getString(CmnConst.RETURN_ATTR_RESULT))) { |
| | | resultObj.put(CmnConst.RETURN_ATTR_RESULT, true); |
| | | resultObj.put(CmnConst.RETURN_ATTR_MESSAGE, "获取报表失败!"); |
| | | } else { |
| | | // 分页参数 |
| | | SQLEntity sqlEntity = recordDte.getSqle(); |
| | | if ("1".equals(reportConfigFse.getString(CmnConst.IS_PAGE)) && sqlEntity != null) { |
| | | resultObj.put(CmnConst.IS_PAGE, 1); |
| | | resultObj.put(CmnConst.CPAGE, curPage); |
| | | resultObj.put("totalCount", sqlEntity.getTotalCount()); |
| | | resultObj.put("totalpage", sqlEntity.getTotalpage()); |
| | | resultObj.put("pagesize", StringUtils.isEmpty(reportConfigFse.getString(CmnConst.PAGE_SIZE)) ? 0 : reportConfigFse.getInteger(CmnConst.PAGE_SIZE)); |
| | | } else { |
| | | resultObj.put(CmnConst.IS_PAGE, 0); |
| | | } |
| | | } |
| | | if (!DataTableEntity.isEmpty(recordDte)) { |
| | | resultObj.put("current_page_count", recordDte.getRows()); |
| | | } |
| | | resultObj.put("systemFieldMeta", getSearchInfo(reportSourceFse.getUUID())); |
| | | resultObj.put("report_type", reportConfigFse.getString("type_uuid")); |
| | | // System.out.println(resultObj.getString("html")); |
| | | |
| | | return resultObj; |
| | | } |
| | | |
| | | /** |
| | | * 获取报表缓存信息 |