| | |
| | | import com.product.core.spring.context.SpringMVCContextHolder; |
| | | import com.product.server.report.config.CmnConst; |
| | | import com.product.server.report.config.ReportCode; |
| | | import com.product.server.report.entity.ReportColumn; |
| | | import com.product.server.report.entity.ReportEntity; |
| | | import com.product.util.BaseUtil; |
| | | import com.product.util.SystemParamReplace; |
| | | import org.springframework.beans.factory.annotation.Autowired; |
| | |
| | | for (Map.Entry<Integer, List<JSONObject>> entry : reportConfigMap.entrySet()) { |
| | | RedisUtil.setHash(reportConfigUUID, String.valueOf(entry.getKey()), entry.getValue()); |
| | | } |
| | | } |
| | | |
| | | /** |
| | | * 获取报表 |
| | | * |
| | | * @return |
| | | */ |
| | | public ReportEntity getReportEntity(FieldSetEntity fse) { |
| | | ReportEntity report = null; |
| | | String reportConfigUUID = fse.getUUID(); |
| | | if (!StringUtils.isEmpty(fse.getString("~report_config_uuid~"))) { |
| | | reportConfigUUID = fse.getString("~report_config_uuid~"); |
| | | } |
| | | 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(); |
| | | // 首次加载,默认添加条件 |
| | | Map<String, Map<String, String>> outerMap = Maps.newHashMap(); |
| | | 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, 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)) { |
| | | report = commonReportService.getReportEntity(recordDte, totalName, reportConfigMap); |
| | | //TODO |
| | | report.setFilterInfo(outerMap); |
| | | } 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)); |
| | | } |
| | | //TODO |
| | | |
| | | // report.setFilterInfo(outerMap); |
| | | 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) { |
| | | report.setPage(true); |
| | | report.setTotalPage(sqlEntity.getTotalpage()); |
| | | report.setPageSize(StringUtils.isEmpty(reportConfigFse.getString(CmnConst.PAGE_SIZE)) ? 0 : reportConfigFse.getInteger(CmnConst.PAGE_SIZE)); |
| | | report.setPageIndex(curPage); |
| | | // 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)); |
| | | } |
| | | } |
| | | // if (!DataTableEntity.isEmpty(recordDte)) { |
| | | // resultObj.put("current_page_count", recordDte.getRows()); |
| | | // } |
| | | report.setSystemFieldMeta(getSearchInfo(reportSourceFse.getUUID())); |
| | | report.setReportType(reportConfigFse.getString("type_uuid")); |
| | | // resultObj.put("systemFieldMeta", ); |
| | | resultObj.put("report_type", reportConfigFse.getString("type_uuid")); |
| | | // System.out.println(resultObj.getString("html")); |
| | | |
| | | return report; |
| | | } |
| | | |
| | | /** |
| | |
| | | } |
| | | |
| | | /** |
| | | * 报表-解析-获取头部或者尾部标题Html |
| | | * |
| | | * @param list 报表配置信息,缓存list |
| | | * @param totalColCount 总列数 |
| | | * @param headAndTailTitleDataMap 头部、尾部标题区数据字段map |
| | | * @param locationType 位置类型,head-头部,tail-尾部 |
| | | * @return |
| | | */ |
| | | public List<List<ReportColumn>> getTitle(List<JSONObject> list, int totalColCount, Map<String, Set<String>> headAndTailTitleDataMap, String locationType) { |
| | | List<List<ReportColumn>> row = new ArrayList<>(); |
| | | StringBuilder html = new StringBuilder(1024); |
| | | int colspan; |
| | | int preRow = 0; |
| | | int preCol = 0; |
| | | int curRow; |
| | | int curCol; |
| | | String value; |
| | | String style; |
| | | |
| | | List<ReportColumn> reportColumns = new ArrayList<>(); |
| | | for (JSONObject singleObj : list) { |
| | | curRow = singleObj.getIntValue(CmnConst.ATTR_Y); |
| | | curCol = singleObj.getIntValue(CmnConst.ATTR_X); |
| | | colspan = singleObj.getIntValue(CmnConst.ATTR_COLSPAN); |
| | | colspan = colspan < 0 ? totalColCount : Math.max(1, colspan); |
| | | value = replaceFormDataAndSysData(singleObj.getString(CmnConst.ATTR_SHOW_NAME), headAndTailTitleDataMap, singleObj); |
| | | value = value == null ? "" : value; |
| | | if ("1".equals(singleObj.getString(CmnConst.ATTR_IS_TITLE))) { |
| | | style = " class=\"" + CmnConst.CLASS_TR_REPORT_TITLE + "\""; |
| | | } else { |
| | | if ("head".equals(locationType)) { |
| | | style = " class=\"" + CmnConst.CLASS_TR_HEAD + "\""; |
| | | } else { |
| | | style = " class=\"" + CmnConst.CLASS_TR_TAIL + "\""; |
| | | } |
| | | } |
| | | if (preRow < curRow) { |
| | | if (preRow != 0) { |
| | | row.add(getAimNumTdPlaceholderColumn(totalColCount - preCol, 1)); |
| | | } |
| | | if (preRow == 0 && preCol == 0 && preCol < curCol - 1) { |
| | | row.add(getAimNumTdPlaceholderColumn(curCol - preCol - 1, 1)); |
| | | } |
| | | preCol = curCol; |
| | | } |
| | | if (preCol < curCol - 1) { |
| | | row.add(getAimNumTdPlaceholderColumn(curCol - preCol - 1, 1)); |
| | | } |
| | | if ("1".equals(singleObj.getString(CmnConst.ATTR_IS_TITLE))) { |
| | | colspan = totalColCount; |
| | | } |
| | | ReportColumn column = new ReportColumn(); |
| | | column.setColspan(colspan); |
| | | column.setContent(value); |
| | | reportColumns.add(column); |
| | | preRow = curRow; |
| | | preCol = curCol + singleObj.getIntValue(CmnConst.ATTR_COLSPAN) - 1; |
| | | if ("1".equals(singleObj.getString(CmnConst.ATTR_IS_TITLE))) { |
| | | preCol = totalColCount; |
| | | } |
| | | } |
| | | row.add(reportColumns); |
| | | reportColumns.addAll(getAimNumTdPlaceholderColumn(totalColCount - preCol, 1)); |
| | | // row.add(); |
| | | return row; |
| | | } |
| | | |
| | | /** |
| | | * 获取指定数据集中包含的数据区字段集合 |
| | | * |
| | | * @param list 指定数据集合 |
| | |
| | | * @param num |
| | | * @return |
| | | */ |
| | | public List<ReportColumn> getAimNumTdPlaceholderColumn(int num, int type) { |
| | | List<ReportColumn> columns = new ArrayList<>(); |
| | | if (num <= 0) { |
| | | return columns; |
| | | } |
| | | if (type == 0) { |
| | | for (int i = 0; i < num; i++) { |
| | | columns.add(new ReportColumn()); |
| | | } |
| | | } else { |
| | | |
| | | ReportColumn column = new ReportColumn(); |
| | | column.setColspan(num); |
| | | columns.add(column); |
| | | } |
| | | return columns; |
| | | } |
| | | |
| | | /** |
| | | * 获取指定个数的td占位 |
| | | * |
| | | * @param num |
| | | * @return |
| | | */ |
| | | public String getAimNumTdPlaceholder(int num, int type) { |
| | | StringBuilder result = new StringBuilder(64); |
| | | if (num <= 0) { |