| | |
| | | <groupId>com.lx</groupId> |
| | | <artifactId>product-server-admin</artifactId> |
| | | </dependency> |
| | | <dependency> |
| | | <groupId>com.lx</groupId> |
| | | <artifactId>product-server-data-export-import</artifactId> |
| | | </dependency> |
| | | </dependencies> |
| | | </project> |
| | |
| | | package com.product.server.report.controller; |
| | | |
| | | import cn.hutool.core.date.DateTime; |
| | | import cn.hutool.core.date.DateUtil; |
| | | import com.product.core.config.CoreConst; |
| | | import com.product.core.controller.support.AbstractBaseController; |
| | | import com.product.core.entity.FieldSetEntity; |
| | | import com.product.core.entity.RequestParameterEntity; |
| | | import com.product.core.exception.BaseException; |
| | | import com.product.core.spring.context.SpringMVCContextHolder; |
| | | import com.product.module.data.config.CmnCode; |
| | | import com.product.module.data.config.CmnConst; |
| | | import com.product.module.data.service.SystemDataExportService; |
| | | import com.product.module.sys.version.ApiVersion; |
| | | import com.product.server.report.config.ReportCode; |
| | | import com.product.server.report.config.SystemCode; |
| | | import com.product.server.report.entity.ReportColumn; |
| | | import com.product.server.report.entity.ReportEntity; |
| | | import com.product.server.report.service.DataListReportService; |
| | | import com.product.util.BaseUtil; |
| | | import org.springframework.beans.factory.annotation.Autowired; |
| | | import org.springframework.web.bind.annotation.PostMapping; |
| | | import org.springframework.web.bind.annotation.RequestMapping; |
| | | import org.springframework.web.bind.annotation.RequestMethod; |
| | | import org.springframework.web.bind.annotation.RestController; |
| | | |
| | | import javax.annotation.Resource; |
| | | import javax.servlet.http.HttpServletRequest; |
| | | import javax.servlet.http.HttpServletResponse; |
| | | import java.util.List; |
| | | import java.util.TimeZone; |
| | | import java.util.stream.Collectors; |
| | | |
| | | /** |
| | | * Copyright © 6c |
| | |
| | | @RestController |
| | | @RequestMapping("/api/report/data-list") |
| | | public class DataListReportController extends AbstractBaseController { |
| | | @Autowired |
| | | private DataListReportService dataListReportService; |
| | | @Autowired |
| | | private DataListReportService dataListReportService; |
| | | |
| | | |
| | | /** |
| | | * 6c-test-设置报表缓存 |
| | | * |
| | | * @param request |
| | | * @return |
| | | */ |
| | | @RequestMapping(value = "/set-report-cache/{version}", method = RequestMethod.POST) |
| | | @ApiVersion(1) |
| | | public String setReportCache(HttpServletRequest request) { |
| | | try { |
| | | FieldSetEntity fse = null; |
| | | Object bean = request.getAttribute(CoreConst.API_POST_REQUEST_DATA); |
| | | if (bean != null) { |
| | | RequestParameterEntity reqp = (RequestParameterEntity) bean; |
| | | fse = reqp.getFormData(); |
| | | } |
| | | if (bean == null || fse == null) { |
| | | SpringMVCContextHolder.getSystemLogger().error(SystemCode.SYSTEM_FORM_NODATA.getValue(), SystemCode.SYSTEM_FORM_NODATA.getText()); |
| | | return this.error(SystemCode.SYSTEM_FORM_NODATA.getValue(), SystemCode.SYSTEM_FORM_NODATA.getText()); |
| | | } |
| | | if (!"1".equals(fse.getString("is_all"))) { |
| | | dataListReportService.setConfig(fse.getUUID()); |
| | | } else { |
| | | dataListReportService.setAllConfig(); |
| | | } |
| | | return OK(); |
| | | } catch (BaseException e) { |
| | | SpringMVCContextHolder.getSystemLogger().error(e); |
| | | return this.error(e.getCode(), e.getMessageInfo()); |
| | | } catch (Exception e) { |
| | | SpringMVCContextHolder.getSystemLogger().error(e); |
| | | e.printStackTrace(); |
| | | return error(ReportCode.GET_REPORT_FAIL.getValue(), ReportCode.GET_REPORT_FAIL.getText()); |
| | | } |
| | | } |
| | | |
| | | /** |
| | | * 6c-test-设置报表缓存 |
| | | * |
| | | * @param request |
| | | * @return |
| | | */ |
| | | @RequestMapping(value = "/set-report-cache/{version}", method = RequestMethod.POST) |
| | | @ApiVersion(1) |
| | | public String setReportCache(HttpServletRequest request) { |
| | | try { |
| | | FieldSetEntity fse = null; |
| | | Object bean = request.getAttribute(CoreConst.API_POST_REQUEST_DATA); |
| | | if (bean != null) { |
| | | RequestParameterEntity reqp = (RequestParameterEntity) bean; |
| | | fse = reqp.getFormData(); |
| | | } |
| | | if (bean == null || fse == null) { |
| | | SpringMVCContextHolder.getSystemLogger().error(SystemCode.SYSTEM_FORM_NODATA.getValue(), SystemCode.SYSTEM_FORM_NODATA.getText()); |
| | | return this.error(SystemCode.SYSTEM_FORM_NODATA.getValue(), SystemCode.SYSTEM_FORM_NODATA.getText()); |
| | | } |
| | | if (!"1".equals(fse.getString("is_all"))) { |
| | | dataListReportService.setConfig(fse.getUUID()); |
| | | } else { |
| | | dataListReportService.setAllConfig(); |
| | | } |
| | | return OK(); |
| | | } catch (BaseException e) { |
| | | SpringMVCContextHolder.getSystemLogger().error(e); |
| | | return this.error(e.getCode(), e.getMessageInfo()); |
| | | } catch (Exception e) { |
| | | SpringMVCContextHolder.getSystemLogger().error(e); |
| | | e.printStackTrace(); |
| | | return error(ReportCode.GET_REPORT_FAIL.getValue(), ReportCode.GET_REPORT_FAIL.getText()); |
| | | } |
| | | } |
| | | /** |
| | | * 获取报表 |
| | | * |
| | | * @param request |
| | | * @return |
| | | */ |
| | | @RequestMapping(value = "/get-report/{version}", method = RequestMethod.POST) |
| | | @ApiVersion(1) |
| | | public String getReport(HttpServletRequest request) { |
| | | try { |
| | | FieldSetEntity fse = null; |
| | | Object bean = request.getAttribute(CoreConst.API_POST_REQUEST_DATA); |
| | | if (bean != null) { |
| | | RequestParameterEntity reqp = (RequestParameterEntity) bean; |
| | | fse = reqp.getFormData(); |
| | | } |
| | | if (bean == null || fse == null) { |
| | | SpringMVCContextHolder.getSystemLogger().error(SystemCode.SYSTEM_FORM_NODATA.getValue(), SystemCode.SYSTEM_FORM_NODATA.getText()); |
| | | return this.error(SystemCode.SYSTEM_FORM_NODATA.getValue(), SystemCode.SYSTEM_FORM_NODATA.getText()); |
| | | } |
| | | return BaseUtil.success(dataListReportService.getReportEntity(fse)); |
| | | } catch (BaseException e) { |
| | | SpringMVCContextHolder.getSystemLogger().error(e); |
| | | return this.error(e.getCode(), e.getMessageInfo()); |
| | | } catch (Exception e) { |
| | | SpringMVCContextHolder.getSystemLogger().error(e); |
| | | e.printStackTrace(); |
| | | return error(ReportCode.GET_REPORT_FAIL.getValue(), ReportCode.GET_REPORT_FAIL.getText()); |
| | | } |
| | | } |
| | | |
| | | /** |
| | | * 获取报表 |
| | | * |
| | | * @param request |
| | | * @return |
| | | */ |
| | | @RequestMapping(value = "/get-report/{version}", method = RequestMethod.POST) |
| | | @ApiVersion(1) |
| | | public String getTableInfo(HttpServletRequest request) { |
| | | try { |
| | | FieldSetEntity fse = null; |
| | | Object bean = request.getAttribute(CoreConst.API_POST_REQUEST_DATA); |
| | | if (bean != null) { |
| | | RequestParameterEntity reqp = (RequestParameterEntity) bean; |
| | | fse = reqp.getFormData(); |
| | | } |
| | | if (bean == null || fse == null) { |
| | | SpringMVCContextHolder.getSystemLogger().error(SystemCode.SYSTEM_FORM_NODATA.getValue(), SystemCode.SYSTEM_FORM_NODATA.getText()); |
| | | return this.error(SystemCode.SYSTEM_FORM_NODATA.getValue(), SystemCode.SYSTEM_FORM_NODATA.getText()); |
| | | } |
| | | return BaseUtil.success(dataListReportService.getReportEntity(fse)); |
| | | } catch (BaseException e) { |
| | | SpringMVCContextHolder.getSystemLogger().error(e); |
| | | return this.error(e.getCode(), e.getMessageInfo()); |
| | | } catch (Exception e) { |
| | | SpringMVCContextHolder.getSystemLogger().error(e); |
| | | e.printStackTrace(); |
| | | return error(ReportCode.GET_REPORT_FAIL.getValue(), ReportCode.GET_REPORT_FAIL.getText()); |
| | | } |
| | | } |
| | | @PostMapping("report-export/{version}") |
| | | @ApiVersion(1) |
| | | public String reportDataExport(HttpServletRequest request, HttpServletResponse response) { |
| | | try { |
| | | FieldSetEntity fse = BaseUtil.getFieldSetEntity(request); |
| | | |
| | | //是否当前页 |
| | | boolean exportCurrentPage = fse.getBoolean("exportCurrentPage"); |
| | | if (!exportCurrentPage) { |
| | | //当前页号 |
| | | int pageIndex = fse.getInteger(CmnConst.CPAGE); |
| | | fse.setValue(CmnConst.CPAGE, pageIndex); |
| | | } else { |
| | | fse.setValue(CmnConst.CPAGE, 1); |
| | | fse.setValue(CmnConst.PAGESIZE, Integer.MAX_VALUE); |
| | | } |
| | | dataListReportService.outReportExcel(response,fse); |
| | | return OK(); |
| | | } catch (BaseException e) { |
| | | e.printStackTrace(); |
| | | SpringMVCContextHolder.getSystemLogger().error(e); |
| | | return error(e); |
| | | } catch (Exception e) { |
| | | e.printStackTrace(); |
| | | SpringMVCContextHolder.getSystemLogger().error(e); |
| | | return error(CmnCode.EXPORT_GENERAL_LIST_DATA_IMPORT_FIAL.getValue(), CmnCode.EXPORT_GENERAL_LIST_DATA_IMPORT_FIAL.getText() + e.getMessage()); |
| | | } |
| | | } |
| | | |
| | | } |
| | |
| | | package com.product.server.report.entity; |
| | | |
| | | import cn.hutool.core.util.NumberUtil; |
| | | import com.product.common.lang.StringUtils; |
| | | |
| | | import java.util.HashMap; |
| | | import java.util.Map; |
| | | import java.util.Set; |
| | | |
| | | /** |
| | | * @Author cheng |
| | |
| | | Map<String, String> otherParams = this.otherParams; |
| | | this.otherParams = new HashMap<>(); |
| | | otherParams.forEach((k, v) -> { |
| | | if ("rowspan".equals(v) && NumberUtil.isNumber(value) && k.equals(key)) { |
| | | this.rowspan = NumberUtil.parseInt(value); |
| | | } |
| | | this.otherParams.put(k.replace(key, value), v.replace(key, value)); |
| | | }); |
| | | } |
| | | if(!StringUtils.isEmpty(subReportProperty)){ |
| | | subReportProperty=subReportProperty.replace(key,value); |
| | | if (!StringUtils.isEmpty(subReportProperty)) { |
| | | subReportProperty = subReportProperty.replace(key, value); |
| | | } |
| | | if(!StringUtils.isEmpty(penetrateProperty)){ |
| | | penetrateProperty=penetrateProperty.replace(key,value); |
| | | if (!StringUtils.isEmpty(penetrateProperty)) { |
| | | penetrateProperty = penetrateProperty.replace(key, value); |
| | | } |
| | | if(!StringUtils.isEmpty(content)){ |
| | | content=content.replace(key,value); |
| | | if (!StringUtils.isEmpty(content)) { |
| | | content = content.replace(key, value); |
| | | } |
| | | } |
| | | |
| | |
| | | } |
| | | |
| | | public String getContent() { |
| | | return content; |
| | | return getContent(false); |
| | | } |
| | | |
| | | public String getContent(boolean emptyChar) { |
| | | if (emptyChar) { |
| | | return this.content == null ? "" : this.content; |
| | | } |
| | | return this.content; |
| | | } |
| | | |
| | | public void setContent(String content) { |
| | |
| | | private Map<String, Map<String, String>> filterInfo; |
| | | //字段信息 |
| | | private JSONArray systemFieldMeta; |
| | | //报表配置uuid |
| | | private String reportConfigUid; |
| | | //报表名称 |
| | | private String reportName; |
| | | |
| | | |
| | | |
| | | /************分页参数*************/ |
| | |
| | | |
| | | private int pageIndex; |
| | | |
| | | private int totalPage; |
| | | private int totalCount; |
| | | |
| | | /************分页参数************ |
| | | |
| | |
| | | this.systemFieldMeta = systemFieldMeta; |
| | | } |
| | | |
| | | public void setEntityType(String entityType) { |
| | | this.entityType = entityType; |
| | | } |
| | | |
| | | public String getReportConfigUid() { |
| | | return reportConfigUid; |
| | | } |
| | | |
| | | public void setReportConfigUid(String reportConfigUid) { |
| | | this.reportConfigUid = reportConfigUid; |
| | | } |
| | | |
| | | public String getReportName() { |
| | | return reportName; |
| | | } |
| | | |
| | | public void setReportName(String reportName) { |
| | | this.reportName = reportName; |
| | | } |
| | | |
| | | public boolean isPage() { |
| | | return isPage; |
| | | } |
| | |
| | | this.pageIndex = pageIndex; |
| | | } |
| | | |
| | | public int getTotalPage() { |
| | | return totalPage; |
| | | public int getTotalCount() { |
| | | return totalCount; |
| | | } |
| | | |
| | | public void setTotalPage(int totalPage) { |
| | | this.totalPage = totalPage; |
| | | public void setTotalCount(int totalCount) { |
| | | this.totalCount = totalCount; |
| | | } |
| | | } |
| | |
| | | * @param recordDte 业务数据dte |
| | | * @param totalStatisticsFlag 是否合计标识 |
| | | * @param reportConfigMap 报表配置缓存map |
| | | * @param tableStyle |
| | | * @return |
| | | */ |
| | | public ReportEntity getReportEntity(DataTableEntity recordDte, String totalName, Map<Integer, List<JSONObject>> reportConfigMap) { |
| | |
| | | |
| | | if (!CollectionUtil.isEmpty(headTitleRows)) { |
| | | List<List<ReportColumn>> reportHeader = report.getReportHeader(); |
| | | headTitleRows.addAll(reportHeader); |
| | | if (reportHeader != null) { |
| | | headTitleRows.addAll(reportHeader); |
| | | } |
| | | report.setReportHeader(headTitleRows); |
| | | } |
| | | if (!CollectionUtil.isEmpty(tailTitleRows)) { |
| | |
| | | } |
| | | } |
| | | paramKey = dataListReportService.concat(keyObj, CmnConst.ATTR_ROWSPAN); |
| | | column.setRowspan(NumberUtil.parseInt(paramKey)); |
| | | if (NumberUtil.isNumber(paramKey)) { |
| | | column.setRowspan(NumberUtil.parseInt(paramKey)); |
| | | } else { |
| | | column.addProperty(paramKey, "rowspan"); |
| | | } |
| | | replaceMap.put(paramKey, "1"); |
| | | } |
| | | // class |
| | |
| | | if (!StringUtils.isEmpty(totalName)) { |
| | | reportData.add(getDataAreaTotalStatistics(statisticsMap, dataAreaFieldConfigMap, dataAreaGroupFieldNameList, preFse, dataAreaGroupFieldRecordObj, totalName)); |
| | | } |
| | | for (Map.Entry<String, String> entry : replaceMap.entrySet()) { |
| | | reportData.stream().forEach(item -> { |
| | | item.stream().forEach(column -> { |
| | | reportData.stream().forEach(item -> { |
| | | item.stream().forEach(column -> { |
| | | for (Map.Entry<String, String> entry : replaceMap.entrySet()) { |
| | | column.replace(entry.getKey(), entry.getValue()); |
| | | }); |
| | | } |
| | | }); |
| | | } |
| | | }); |
| | | |
| | | |
| | | return reportData; |
| | | } |
| | |
| | | package com.product.server.report.service; |
| | | |
| | | import cn.hutool.core.collection.CollectionUtil; |
| | | import cn.hutool.core.date.DateTime; |
| | | import cn.hutool.core.util.NumberUtil; |
| | | import com.alibaba.fastjson.JSONArray; |
| | | import com.alibaba.fastjson.JSONObject; |
| | | import com.google.common.collect.Lists; |
| | |
| | | import com.product.core.service.support.AbstractBaseService; |
| | | import com.product.core.service.support.QueryFilterService; |
| | | import com.product.core.spring.context.SpringMVCContextHolder; |
| | | import com.product.module.data.service.SystemDataExportService; |
| | | import com.product.server.report.config.CmnConst; |
| | | import com.product.server.report.config.ReportCode; |
| | | import com.product.server.report.entity.ReportColumn; |
| | |
| | | import org.springframework.beans.factory.annotation.Autowired; |
| | | import org.springframework.stereotype.Component; |
| | | |
| | | import javax.annotation.Resource; |
| | | import javax.servlet.http.HttpServletResponse; |
| | | import java.io.IOException; |
| | | import java.math.BigDecimal; |
| | | import java.text.DecimalFormat; |
| | | import java.text.ParseException; |
| | |
| | | import java.util.*; |
| | | import java.util.regex.Matcher; |
| | | import java.util.regex.Pattern; |
| | | import java.util.stream.Collectors; |
| | | |
| | | /** |
| | | * Copyright © 6c |
| | |
| | | private QueryFilterService queryFilterService; |
| | | @Autowired |
| | | private RouterService routerService; |
| | | @Resource |
| | | private SystemDataExportService exportService; |
| | | |
| | | public void outReportExcel(HttpServletResponse response, FieldSetEntity fse) throws BaseException, IOException { |
| | | ReportEntity reportEntity = getReportEntity(fse); |
| | | List<List<ReportColumn>> reportHeader = reportEntity.getReportHeader(); |
| | | |
| | | List<List<String>> headerTemp = processingMergeData(reportHeader); |
| | | List<List<String>> header = headerTemp.get(0).stream().map(item -> new ArrayList<String>()).collect(Collectors.toList()); |
| | | int size = headerTemp.get(0).size(); |
| | | for (int i = 0; i < size; i++) { |
| | | for (int k = 0; k < headerTemp.size(); k++) { |
| | | header.get(i).add(headerTemp.get(k).get(i)); |
| | | } |
| | | } |
| | | |
| | | List<List<ReportColumn>> reportData = reportEntity.getReportData(); |
| | | if (!CollectionUtil.isEmpty(reportEntity.getReportTail())) { |
| | | reportData.addAll(reportEntity.getReportTail()); |
| | | } |
| | | |
| | | List<List<String>> data = processingMergeData(reportData); |
| | | exportService.writeExcel(header, data, "测试", response); |
| | | } |
| | | |
| | | |
| | | private static List<List<String>> processingMergeData(List<List<ReportColumn>> data) { |
| | | if (CollectionUtil.isEmpty(data)) { |
| | | return null; |
| | | } |
| | | List<List<String>> resultData = data.stream().map(item -> new ArrayList<String>()).collect(Collectors.toList()); |
| | | for (int i = 0; i < data.size(); i++) { |
| | | List<ReportColumn> columns = data.get(i); |
| | | for (ReportColumn column : columns) { |
| | | //跨行 |
| | | int rowspan = column.getRowspan() < 1 ? 1 : column.getRowspan(); |
| | | //跨列 |
| | | int colspan = column.getColspan() < 1 ? 1 : column.getColspan(); |
| | | List<String> currentCell = new ArrayList<>(); |
| | | for (int k = 0; k < colspan; k++) { |
| | | currentCell.add(column.getContent(true)); |
| | | } |
| | | for (int j = 0; j < rowspan; j++) { |
| | | resultData.get(j + i).addAll(currentCell); |
| | | } |
| | | System.out.println(resultData); |
| | | } |
| | | } |
| | | return resultData; |
| | | } |
| | | |
| | | public static void main(String[] args) { |
| | | List<List<ReportColumn>> data = new ArrayList<>(); |
| | | List<ReportColumn> columns = new ArrayList<>(); |
| | | ReportColumn column = new ReportColumn(); |
| | | column.setRowspan(2); |
| | | column.setColspan(4); |
| | | column.setContent("跨行数:2,跨列数:4"); |
| | | columns.add(column); |
| | | data.add(columns); |
| | | columns = new ArrayList<>(); |
| | | data.add(columns); |
| | | for (int i = 0; i < 3; i++) { |
| | | column = new ReportColumn(); |
| | | column.setContent("跨行数:1,跨列数:1,下标:" + i); |
| | | columns.add(column); |
| | | } |
| | | processingMergeData(data); |
| | | } |
| | | |
| | | |
| | | /** |
| | | * @param target |
| | | * @param content |
| | | * @param colspan |
| | | * @param rowspan |
| | | * @param currentColspan |
| | | * @param currentRowsSpan |
| | | */ |
| | | private void rowspanAndColspan(String[][] target, String content, int colspan, int rowspan, int currentColspan, int currentRowsSpan) { |
| | | int k = currentColspan; |
| | | int i = currentRowsSpan; |
| | | if (colspan > 1) { |
| | | for (int j = 1; j < colspan; j++) { |
| | | int index = j + k; |
| | | while (target[i][index] != null) { |
| | | index++; |
| | | } |
| | | target[i][index] = content; |
| | | } |
| | | } |
| | | if (rowspan > 1) { |
| | | for (int j = 1; j < rowspan; j++) { |
| | | int index = i + k; |
| | | while (target[index][k] != null) { |
| | | index++; |
| | | } |
| | | target[index][k] = content; |
| | | } |
| | | } |
| | | } |
| | | |
| | | /** |
| | | * 加载所有缓存 |
| | |
| | | ReportEntity report = null; |
| | | String reportConfigUUID = fse.getUUID(); |
| | | if (!StringUtils.isEmpty(fse.getString("~report_config_uuid~"))) { |
| | | //子报表会传入此key作为报表的uuid 规避参数中有uuid的key |
| | | reportConfigUUID = fse.getString("~report_config_uuid~"); |
| | | } |
| | | DataTableEntity reportConfigDte = DataPoolCacheImpl.getInstance().getCacheData(CmnConst.CACHE_REPORT_CONFIG, new String[]{reportConfigUUID}); |
| | |
| | | |
| | | 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)); |
| | | report = groupReportService.getReportEntity(recordDte, totalName, reportConfigMap); |
| | | // resultObj.putAll(groupReportService.getReport(recordDte, totalName, reportConfigMap, tableStyle)); |
| | | } |
| | | //TODO |
| | | |
| | | report.setReportConfigUid(reportConfigFse.getUUID()); |
| | | report.setReportName(reportConfigFse.getString(CmnConst.REPORT_NAME)); |
| | | // report.setFilterInfo(outerMap); |
| | | if (CmnConst.FALSE.equals(resultObj.getString(CmnConst.RETURN_ATTR_RESULT))) { |
| | | resultObj.put(CmnConst.RETURN_ATTR_RESULT, true); |
| | |
| | | SQLEntity sqlEntity = recordDte.getSqle(); |
| | | if ("1".equals(reportConfigFse.getString(CmnConst.IS_PAGE)) && sqlEntity != null) { |
| | | report.setPage(true); |
| | | report.setTotalPage(sqlEntity.getTotalpage()); |
| | | report.setTotalCount(sqlEntity.getTotalCount()); |
| | | report.setPageSize(StringUtils.isEmpty(reportConfigFse.getString(CmnConst.PAGE_SIZE)) ? 0 : reportConfigFse.getInteger(CmnConst.PAGE_SIZE)); |
| | | report.setPageIndex(curPage); |
| | | // resultObj.put(CmnConst.IS_PAGE, 1); |
| | |
| | | report.setSystemFieldMeta(getSearchInfo(reportSourceFse.getUUID())); |
| | | report.setReportType(reportConfigFse.getString("type_uuid")); |
| | | // resultObj.put("systemFieldMeta", ); |
| | | resultObj.put("report_type", reportConfigFse.getString("type_uuid")); |
| | | // resultObj.put("report_type", reportConfigFse.getString("type_uuid")); |
| | | // System.out.println(resultObj.getString("html")); |
| | | |
| | | return report; |
| | |
| | | * @param reportConfigFse |
| | | * @return |
| | | */ |
| | | private DataTableEntity getRecordDte(StringBuilder sort, int curPage, FieldSetEntity reportSourceFse, FieldSetEntity fse, FieldSetEntity reportConfigFse, Map<Integer, List<JSONObject>> reportConfigMap) { |
| | | private DataTableEntity getRecordDte(StringBuilder sort, int curPage, FieldSetEntity |
| | | reportSourceFse, FieldSetEntity fse, FieldSetEntity |
| | | reportConfigFse, Map<Integer, List<JSONObject>> reportConfigMap) { |
| | | boolean spTimeFlag = reportConfigMap != null; |
| | | String sql; |
| | | String sqlText = reportSourceFse.getString(CmnConst.SQL_TEXT); |
| | |
| | | * @param sort |
| | | * @return |
| | | */ |
| | | private String replaceSqlContent(String sqlText, FieldSetEntity fse, StringBuilder sort, FieldSetEntity reportConfigFse, int curPage, String selectedFields, Map<String, List<String>> queryFilterMap) { |
| | | private String replaceSqlContent(String sqlText, FieldSetEntity fse, StringBuilder sort, FieldSetEntity |
| | | reportConfigFse, int curPage, String selectedFields, Map<String, List<String>> queryFilterMap) { |
| | | queryFilterMap = queryFilterMap == null ? queryFilterService.getQueryFilterMore(fse) : queryFilterMap; |
| | | selectedFields = StringUtils.isEmpty(selectedFields) ? "*" : selectedFields; |
| | | // 替换sql中的系统参数 |
| | |
| | | return sql.toString(); |
| | | } |
| | | |
| | | private String replaceSqlContent(String sqlText, FieldSetEntity fse, StringBuilder sort, FieldSetEntity reportConfigFse, int curPage) { |
| | | private String replaceSqlContent(String sqlText, FieldSetEntity fse, StringBuilder sort, FieldSetEntity |
| | | reportConfigFse, int curPage) { |
| | | return replaceSqlContent(sqlText, fse, sort, reportConfigFse, curPage, null, null); |
| | | } |
| | | |
| | |
| | | * @param queryFilterMap |
| | | * @return |
| | | */ |
| | | private String spReplaceSqlContent(String suitContent, String regexp, int num, Map<String, List<String>> queryFilterMap, Map<String, List<String>> residueQueryFilterMap) { |
| | | private String spReplaceSqlContent(String suitContent, String regexp, int num, Map< |
| | | String, List<String>> queryFilterMap, Map<String, List<String>> residueQueryFilterMap) { |
| | | List<String> innerSuitList = getSuitContent(suitContent, regexp); |
| | | String curField; |
| | | String filter; |
| | |
| | | * @param queryFilterMap |
| | | * @param curFieldName |
| | | */ |
| | | private void spDealFilterForLastYear(Map<String, List<String>> tempQueryFilterMap, Map<String, List<String>> queryFilterMap, String curFieldName) { |
| | | private void spDealFilterForLastYear |
| | | (Map<String, List<String>> tempQueryFilterMap, Map<String, List<String>> queryFilterMap, String |
| | | curFieldName) { |
| | | List<String> paramList = tempQueryFilterMap.get(curFieldName); |
| | | for (int i = 0; i < paramList.size(); i++) { |
| | | paramList.set(i, paramList.get(i).replace("str_to_date(", "date_add(str_to_date(") |
| | |
| | | * @param queryFilterMap |
| | | * @param curFieldName |
| | | */ |
| | | private void spDealFilterForPrePeriod(Map<String, List<String>> tempQueryFilterMap, Map<String, List<String>> queryFilterMap, String curFieldName) { |
| | | private void spDealFilterForPrePeriod |
| | | (Map<String, List<String>> tempQueryFilterMap, Map<String, List<String>> queryFilterMap, String |
| | | curFieldName) { |
| | | List<String> paramList = tempQueryFilterMap.get(curFieldName); |
| | | String[] timeArr = paramList.get(0).split("~"); |
| | | try { |
| | |
| | | * @param dataList |
| | | * @return |
| | | */ |
| | | private Set<String> getFieldAndSpTimeStatisticsTypeSet(Set<String> baseFieldSet, Map<String, Map<String, JSONObject>> spTimeStatisticsFieldMap, List<JSONObject> dataList) { |
| | | private Set<String> getFieldAndSpTimeStatisticsTypeSet |
| | | (Set<String> baseFieldSet, Map<String, Map<String, JSONObject>> spTimeStatisticsFieldMap, List<JSONObject> dataList) { |
| | | Set<String> spTimeStatisticsTypeSet = Sets.newHashSet(); |
| | | JSONObject curFieldObj; |
| | | String fieldName; |
| | |
| | | * @param locationType 位置类型,head-头部,tail-尾部 |
| | | * @return |
| | | */ |
| | | public StringBuilder getTitleHtml(List<JSONObject> list, int totalColCount, Map<String, Set<String>> headAndTailTitleDataMap, String locationType) { |
| | | public StringBuilder getTitleHtml(List<JSONObject> list, int totalColCount, Map< |
| | | String, Set<String>> headAndTailTitleDataMap, String locationType) { |
| | | StringBuilder html = new StringBuilder(1024); |
| | | int colspan; |
| | | int preRow = 0; |
| | |
| | | * @param locationType 位置类型,head-头部,tail-尾部 |
| | | * @return |
| | | */ |
| | | public List<List<ReportColumn>> getTitle(List<JSONObject> list, int totalColCount, Map<String, Set<String>> headAndTailTitleDataMap, String locationType) { |
| | | 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); |
| | | // StringBuilder html = new StringBuilder(1024); |
| | | int colspan; |
| | | int preRow = 0; |
| | | int preCol = 0; |
| | | int curRow; |
| | | int curCol; |
| | | String value; |
| | | String style; |
| | | // String style; |
| | | |
| | | List<ReportColumn> reportColumns = new ArrayList<>(); |
| | | for (JSONObject singleObj : list) { |
| | |
| | | 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 ("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(!reportColumns.isEmpty()){ |
| | | row.add(reportColumns); |
| | | reportColumns=new ArrayList<>(); |
| | | } |
| | | if (preRow == 0 && preCol == 0 && preCol < curCol - 1) { |
| | | row.add(getAimNumTdPlaceholderColumn(curCol - preCol - 1, 1)); |
| | | } |
| | | // 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(reportColumns); |
| | | reportColumns.addAll(getAimNumTdPlaceholderColumn(totalColCount - preCol, 1)); |
| | | // reportColumns.addAll(getAimNumTdPlaceholderColumn(totalColCount - preCol, 1)); |
| | | // row.add(); |
| | | return row; |
| | | } |
| | |
| | | * @param lastStageFlag 是否末级(数据区分组字段末级和分组表头区字段都是末级才为末级) |
| | | * @return |
| | | */ |
| | | public JSONObject getStatisticsValueObj(JSONObject valueJsonObject, JSONObject dataAreaFieldConfigObj, String actualValue, String type, boolean lastStageFlag) { |
| | | public JSONObject getStatisticsValueObj(JSONObject valueJsonObject, JSONObject dataAreaFieldConfigObj, String |
| | | actualValue, String type, boolean lastStageFlag) { |
| | | if (valueJsonObject == null) { |
| | | valueJsonObject = new JSONObject(); |
| | | } |
| | |
| | | * @param set |
| | | * @param recordFse |
| | | */ |
| | | public void getHeadAndTailTitleDataMap(Map<String, Set<String>> headAndTailTitleDataMap, Set<String> set, FieldSetEntity recordFse) { |
| | | public void getHeadAndTailTitleDataMap |
| | | (Map<String, Set<String>> headAndTailTitleDataMap, Set<String> set, FieldSetEntity recordFse) { |
| | | for (String fieldName : set) { |
| | | headAndTailTitleDataMap.computeIfAbsent(fieldName, k -> Sets.newLinkedHashSet()).add(recordFse.getString(fieldName)); |
| | | } |
| | |
| | | return dealedValueSb.toString(); |
| | | } |
| | | |
| | | public int dealColumnWidth(JSONObject dataAreaFieldConfigObj) { |
| | | return NumberUtil.isNumber(dataAreaFieldConfigObj.getString(CmnConst.ATTR_WIDTH)) ? NumberUtil.parseInt(dataAreaFieldConfigObj.getString(CmnConst.ATTR_WIDTH)) : 0; |
| | | } |
| | | |
| | | /** |
| | | * 获取td的属性 |
| | | * |
| | |
| | | * @param singleObj |
| | | * @return |
| | | */ |
| | | public String replaceFormDataAndSysData(String str, Map<String, Set<String>> headAndTailTitleDataMap, JSONObject singleObj) { |
| | | public String replaceFormDataAndSysData(String |
| | | str, Map<String, Set<String>> headAndTailTitleDataMap, JSONObject singleObj) { |
| | | if (StringUtils.isEmpty(str)) { |
| | | return ""; |
| | | } |
| | |
| | | * @param type 类型:1-获取目标属性,其他-排除目标属性 |
| | | * @return |
| | | */ |
| | | public JSONObject extendJSONObject(JSONObject aimObj, JSONObject sourceObj, Collection<String> aimAttr, int type) { |
| | | public JSONObject extendJSONObject(JSONObject aimObj, JSONObject sourceObj, Collection<String> aimAttr, |
| | | int type) { |
| | | if (aimObj == null) { |
| | | aimObj = new JSONObject(); |
| | | } |
| | |
| | | import com.product.core.spring.context.SpringMVCContextHolder; |
| | | import com.product.server.report.config.CmnConst; |
| | | import com.product.server.report.entity.ReportColumn; |
| | | import com.product.server.report.entity.ReportEntity; |
| | | import com.product.util.BaseUtil; |
| | | import org.springframework.beans.factory.annotation.Autowired; |
| | | import org.springframework.stereotype.Component; |
| | |
| | | * @param recordDte 业务数据dte |
| | | * @param totalName 总计名称 |
| | | * @param reportConfigMap 报表配置缓存map |
| | | * @param tableStyle |
| | | * @return 获取分组报表的详情 |
| | | */ |
| | | public JSONObject getReportEntity(DataTableEntity recordDte, String totalName, Map<Integer, List<JSONObject>> reportConfigMap, StringBuilder tableStyle) { |
| | | StringBuilder reportHtml = new StringBuilder(4096); |
| | | |
| | | public ReportEntity getReportEntity(DataTableEntity recordDte, String totalName, Map<Integer, List<JSONObject>> reportConfigMap) { |
| | | // StringBuilder reportHtml = new StringBuilder(4096); |
| | | ReportEntity report = new ReportEntity(); |
| | | // css |
| | | // StringBuilder cssHtml = dataListReportService.getCssHtml(); |
| | | |
| | | // 分组表头区和数据区 |
| | | StringBuilder groupAndDataAreaHtml = new StringBuilder(1024); |
| | | // StringBuilder groupAndDataAreaHtml = new StringBuilder(1024); |
| | | List<List<ReportColumn>>[] rows = new List[2]; |
| | | Map<String, Set<String>> headAndTailTitleDataMap = Maps.newHashMap(); |
| | | int totalColCount = reportConfigMap.get(0).size(); |
| | | int dataAreaColCount = getGroupAndDataAreaHtmlAndReturnDataAreaColCount(groupAndDataAreaHtml, reportConfigMap, headAndTailTitleDataMap, recordDte, totalName); |
| | | int dataAreaColCount = getGroupAndDataAreaAndReturnDataAreaColCount(rows, reportConfigMap, headAndTailTitleDataMap, recordDte, totalName); |
| | | totalColCount = Math.max(totalColCount, dataAreaColCount); |
| | | |
| | | // 头部标题区 |
| | | StringBuilder headTitleHtml = null; |
| | | |
| | | List<List<ReportColumn>> headTitle = null; |
| | | if (!reportConfigMap.get(1).isEmpty()) { |
| | | headTitleHtml = dataListReportService.getTitleHtml(reportConfigMap.get(1), totalColCount, headAndTailTitleDataMap, "head"); |
| | | headTitle = dataListReportService.getTitle(reportConfigMap.get(1), totalColCount, headAndTailTitleDataMap, "head"); |
| | | } |
| | | |
| | | // 底部标题区 |
| | | StringBuilder tailTitleHtml = null; |
| | | List<List<ReportColumn>> tailTitle = null; |
| | | if (!reportConfigMap.get(3).isEmpty()) { |
| | | tailTitleHtml = dataListReportService.getTitleHtml(reportConfigMap.get(3), totalColCount, headAndTailTitleDataMap, "tail"); |
| | | tailTitle = dataListReportService.getTitle(reportConfigMap.get(3), totalColCount, headAndTailTitleDataMap, "tail"); |
| | | } |
| | | |
| | | // reportHtml.append("\n<body>\n<table").append(tableStyle).append(">") |
| | |
| | | // .append(tailTitleHtml == null ? "" : tailTitleHtml) |
| | | // .append("\n</table>\n</body>"); |
| | | |
| | | JSONObject resultObj = new JSONObject(); |
| | | resultObj.put(CmnConst.RETURN_ATTR_RESULT, true); |
| | | resultObj.put(CmnConst.RETURN_ATTR_MESSAGE, "获取报表成功!"); |
| | | resultObj.put(CmnConst.RETURN_ATTR_HTML, reportHtml); |
| | | return resultObj; |
| | | if (rows[0] != null) { |
| | | if (headTitle == null) { |
| | | headTitle = new ArrayList<>(); |
| | | } |
| | | headTitle.addAll(rows[0]); |
| | | } |
| | | report.setReportHeader(headTitle); |
| | | |
| | | report.setReportData(rows[1]); |
| | | report.setReportTail(tailTitle); |
| | | return report; |
| | | } |
| | | |
| | | /** |
| | |
| | | * @param totalName 总计名称 |
| | | * @return 数据区总列数 |
| | | */ |
| | | private int getGroupAndDataAreaAndReturnDataAreaColCount(List<List<ReportColumn>> groupAndDataArea, Map<Integer, List<JSONObject>> reportConfigMap, Map<String, Set<String>> headAndTailTitleDataMap, DataTableEntity recordDte, String totalName) { |
| | | private int getGroupAndDataAreaAndReturnDataAreaColCount(List<List<ReportColumn>>[] groupAndDataArea, Map<Integer, List<JSONObject>> reportConfigMap, Map<String, Set<String>> headAndTailTitleDataMap, DataTableEntity recordDte, String totalName) { |
| | | // 分组表头区字段缓存map |
| | | Map<String, JSONObject> groupAreaFieldConfigMap = dataListReportService.groupAndDataJSONObject2Map(reportConfigMap.get(2)); |
| | | // 数据区字段缓存map |
| | |
| | | // 数据标题list |
| | | List<JSONObject> dataTitleList = Lists.newArrayList(); |
| | | // 获取标题html |
| | | groupAndDataArea.addAll(getDataAreaTitle(dataTitleList, groupAreaFieldRecordObj, dataAreaFieldConfigMap, groupAreaRangeObj, dataAreaCommonStatisticsFieldNameList)); |
| | | groupAndDataArea[0] = (getDataAreaTitle(dataTitleList, groupAreaFieldRecordObj, dataAreaFieldConfigMap, groupAreaRangeObj, dataAreaCommonStatisticsFieldNameList)); |
| | | // 获取内容html |
| | | // groupAndDataAreaHtml.append(getDataAreaDataHtml(dataTitleList, dataAreaFieldRecordObj, statisticsMap, totalName, dataAreaGroupFieldNameList, dataAreaFieldConfigMap)); |
| | | groupAndDataArea[1] = (getDataAreaData(dataTitleList, dataAreaFieldRecordObj, statisticsMap, totalName, dataAreaGroupFieldNameList, dataAreaFieldConfigMap)); |
| | | |
| | | return totalColCount; |
| | | } |
| | |
| | | List<ReportColumn> columns = new ArrayList<>(); |
| | | // html.append("\n<tr class=\"").append(CmnConst.CLASS_TR_DATA_TITLE).append("\">\n "); |
| | | for (JSONObject dataTitleObj : rowList) { |
| | | ReportColumn column = new ReportColumn(); |
| | | rowspan = Math.max(1, dataTitleObj.getIntValue(CmnConst.ATTR_ROWSPAN)); |
| | | colspan = Math.max(1, dataTitleObj.getIntValue(CmnConst.ATTR_COLSPAN)); |
| | | value = dataTitleObj.getString(CmnConst.ATTR_SHOW_NAME); |
| | | if (!StringUtils.isEmpty(dataTitleObj.getString(CmnConst.ATTR_FIELD_INFO))) { |
| | | dataAreaFieldName = dataListReportService.fieldInfo2FieldName(dataTitleObj.getString(CmnConst.ATTR_FIELD_INFO)); |
| | | value = dataListReportService.dealTdWidth(dataAreaFieldConfigMap.get(dataAreaFieldName), value); |
| | | column.setColumnWidth(dataListReportService.dealColumnWidth(dataAreaFieldConfigMap.get(dataAreaFieldName))); |
| | | // value = dataListReportService.dealTdWidth(dataAreaFieldConfigMap.get(dataAreaFieldName), value); |
| | | } |
| | | ReportColumn column = new ReportColumn(); |
| | | column.setRowspan(rowspan); |
| | | column.setColspan(colspan); |
| | | column.setContent(value); |
| | |
| | | private List<List<ReportColumn>> getDataAreaData(List<JSONObject> dataTitleList, JSONObject dataAreaFieldRecordObj, Map<JSONObject, JSONObject> statisticsMap, String totalName, List<String> dataAreaGroupFieldNameList, Map<String, JSONObject> dataAreaFieldConfigMap) { |
| | | List<List<JSONObject>> dataAreaGroupFieldDataList = Lists.newArrayList(); |
| | | getDataAreaGroupFieldDataList(dataAreaFieldRecordObj, dataAreaGroupFieldDataList, new JSONObject(), 1, 1, dataAreaGroupFieldNameList.size(), null); |
| | | |
| | | List<List<ReportColumn>> dataRows = new ArrayList<>(); |
| | | List<JSONObject> groupTitleList = Lists.newArrayList(); |
| | | JSONObject obj; |
| | | for (List<JSONObject> rowList : dataAreaGroupFieldDataList) { |
| | |
| | | groupTitleList.add(obj); |
| | | } |
| | | |
| | | StringBuilder html = new StringBuilder(1024); |
| | | // StringBuilder html = new StringBuilder(1024); |
| | | JSONObject dataAreaGroupFieldObj; |
| | | int rowspan; |
| | | int colspan; |
| | |
| | | List<JSONObject> curRowList; |
| | | int index; |
| | | for (int i = 0; i < dataAreaGroupFieldDataList.size(); i++) { |
| | | List<ReportColumn> columns = new ArrayList<>(); |
| | | index = 0; |
| | | curRowList = dataAreaGroupFieldDataList.get(i); |
| | | if (!curRowList.isEmpty()) { |
| | |
| | | if (dataAreaGroupFieldObj.isEmpty()) { |
| | | continue; |
| | | } |
| | | if (index == 0) { |
| | | if ("1".equals(dataAreaGroupFieldObj.getString(CmnConst.ATTR_IS_STATISTICS_FIELD))) { |
| | | html.append("\n<tr class=\"").append(CmnConst.CLASS_TR_DATA_STATISTICS).append("\">\n "); |
| | | } else { |
| | | html.append("\n<tr class=\"").append(CmnConst.CLASS_TR_DATA_COMMON).append("\">\n "); |
| | | } |
| | | } |
| | | // if (index == 0) { |
| | | // if ("1".equals(dataAreaGroupFieldObj.getString(CmnConst.ATTR_IS_STATISTICS_FIELD))) { |
| | | // html.append("\n<tr class=\"").append(CmnConst.CLASS_TR_DATA_STATISTICS).append("\">\n "); |
| | | // } else { |
| | | // html.append("\n<tr class=\"").append(CmnConst.CLASS_TR_DATA_COMMON).append("\">\n "); |
| | | // } |
| | | // } |
| | | rowspan = Math.max(1, dataAreaGroupFieldObj.getIntValue(CmnConst.ATTR_ROWSPAN)); |
| | | colspan = Math.max(1, dataAreaGroupFieldObj.getIntValue(CmnConst.ATTR_COLSPAN)); |
| | | value = dataAreaGroupFieldObj.getString(CmnConst.ATTR_SHOW_NAME); |
| | | html.append("<td rowspan=\"").append(rowspan).append("\" colspan=\"").append(colspan).append("\">").append(value == null ? "" : value).append("</td>"); |
| | | ReportColumn column = new ReportColumn(); |
| | | column.setRowspan(rowspan); |
| | | column.setColspan(colspan); |
| | | column.setContent(value); |
| | | columns.add(column); |
| | | // html.append("<td rowspan=\"").append(rowspan).append("\" colspan=\"").append(colspan).append("\">").append(value == null ? "" : value).append("</td>"); |
| | | index++; |
| | | } |
| | | } else { |
| | | html.append("\n<tr class=\"").append(CmnConst.CLASS_TR_DATA_COMMON).append("\">\n "); |
| | | } |
| | | // else { |
| | | // html.append("\n<tr class=\"").append(CmnConst.CLASS_TR_DATA_COMMON).append("\">\n "); |
| | | // } |
| | | groupTitleObj = groupTitleList.get(i); |
| | | for (JSONObject dataTitleObj : dataTitleList) { |
| | | keyObj = dataListReportService.extendJSONObject((JSONObject) groupTitleObj.clone(), dataTitleObj, Arrays.asList(CmnConst.ATTR_ROWSPAN, CmnConst.ATTR_COLSPAN, CmnConst.ATTR_SHOW_NAME, CmnConst.ATTR_IS_STATISTICS_FIELD, CmnConst.ATTR_REAL_VALUE), -1); |
| | |
| | | } else { |
| | | value = ""; |
| | | } |
| | | html.append("<td"); |
| | | // html.append("<td"); |
| | | ReportColumn column = new ReportColumn(); |
| | | if (!StringUtils.isEmpty(value)) { |
| | | // class |
| | | if (!StringUtils.isEmpty(dataAreaFieldConfigObj.getString(CmnConst.ATTR_URL))) { |
| | | dataListReportService.extendJSONObject(keyObj, dataAreaFieldConfigObj, Collections.singletonList(CmnConst.ATTR_URL)); |
| | | html.append(" class=\"").append(CmnConst.CLASS_TD_CAN_TURN).append("\""); |
| | | // html.append(" class=\"").append(CmnConst.CLASS_TD_CAN_TURN).append("\""); |
| | | } |
| | | // 字段属性 |
| | | dataListReportService.getTdAttrObj(keyObj, groupTitleObj); |
| | | dataListReportService.getTdAttrObj(keyObj, dataTitleObj); |
| | | html.append(dataListReportService.getTdAttrByObj(keyObj)); |
| | | String attrUrL = keyObj.getString(CmnConst.ATTR_URL); |
| | | if (!StringUtils.isEmpty(attrUrL)) { |
| | | column.setPenetrateProperty(attrUrL.toString()); |
| | | column.setPenetrate(true); |
| | | } |
| | | for (String key : keyObj.keySet()) { |
| | | column.addProperty(key, keyObj.getString(key)); |
| | | } |
| | | // html.append(dataListReportService.getTdAttrByObj(keyObj)); |
| | | // 格式 |
| | | value = dataListReportService.formatValue(dataAreaFieldConfigObj, value); |
| | | } |
| | | html.append(">").append(value == null ? "" : value).append("</td>"); |
| | | // html.append(">").append(value == null ? "" : value).append("</td>"); |
| | | column.setContent(value); |
| | | columns.add(column); |
| | | } |
| | | html.append("\n</tr>"); |
| | | // html.append("\n</tr>"); |
| | | dataRows.add(columns); |
| | | } |
| | | |
| | | // 总计 |
| | | if (!StringUtils.isEmpty(totalName)) { |
| | | html.append(getTotalStatisticsHtml(statisticsMap, dataTitleList, dataAreaFieldConfigMap, dataAreaGroupFieldNameList.size(), getSubCnt(dataAreaFieldRecordObj), totalName)); |
| | | dataRows.add(getTotalStatistics(statisticsMap, dataTitleList, dataAreaFieldConfigMap, dataAreaGroupFieldNameList.size(), getSubCnt(dataAreaFieldRecordObj), totalName)); |
| | | } |
| | | |
| | | return null; |
| | | return dataRows; |
| | | } |
| | | |
| | | /** |
| | |
| | | * @param totalName 总计名称 |
| | | * @return |
| | | */ |
| | | private List<ReportColumn> getTotalStatistics(Map<JSONObject, JSONObject> statisticsMap, List<JSONObject> dataTitleList, Map<String, JSONObject> dataAreaFieldConfigMap, int dataAreaGroupFieldCount, int dataAreaSubCnt, String totalName) { |
| | | List<ReportColumn> columns = new ArrayList<>(); |
| | | // StringBuilder html = new StringBuilder(256); |
| | | // html.append("\n<tr class=\"").append(CmnConst.CLASS_TR_DATA_STATISTICS).append("\">\n "); |
| | | // html.append("<td colspan=\"").append(dataAreaGroupFieldCount).append("\">").append(totalName).append("</td>"); |
| | | ReportColumn column = new ReportColumn(); |
| | | columns.add(column); |
| | | column.setColspan(dataAreaGroupFieldCount); |
| | | column.setContent(totalName); |
| | | JSONObject dataTitleObj; |
| | | JSONObject keyObj; |
| | | JSONObject dataAreaFieldConfigObj; |
| | | String statisticsType; |
| | | JSONObject valueObj; |
| | | String value; |
| | | int groupAreaSubCnt; |
| | | for (int i = 0; i < dataTitleList.size(); i++) { |
| | | column = new ReportColumn(); |
| | | columns.add(column); |
| | | dataTitleObj = dataTitleList.get(i); |
| | | keyObj = dataListReportService.extendJSONObject(null, dataTitleObj, Arrays.asList(CmnConst.ATTR_ROWSPAN, CmnConst.ATTR_COLSPAN, CmnConst.ATTR_SHOW_NAME, CmnConst.ATTR_IS_STATISTICS_FIELD, CmnConst.ATTR_REAL_VALUE), -1); |
| | | dataAreaFieldConfigObj = dataAreaFieldConfigMap.get(dataListReportService.fieldInfo2FieldName(dataTitleObj.getString(CmnConst.ATTR_FIELD_INFO))); |
| | | if (dataAreaFieldConfigObj != null) { |
| | | groupAreaSubCnt = keyObj.getIntValue(CmnConst.ATTR_GROUP_AREA_SUB_CNT); |
| | | keyObj.remove(CmnConst.ATTR_GROUP_AREA_SUB_CNT); |
| | | statisticsType = dataAreaFieldConfigObj.getString(CmnConst.ATTR_STATISTICS); |
| | | valueObj = statisticsMap.get(keyObj); |
| | | if (valueObj == null || valueObj.isEmpty()) { |
| | | value = getFinalValue(keyObj, dataAreaFieldConfigObj, statisticsMap); |
| | | } else { |
| | | if (CmnConst.ATTR_STATISTICS_AVG.equals(statisticsType) && "1".equals(dataAreaFieldConfigObj.getString(CmnConst.ATTR_AVG_TYPE))) { |
| | | value = getTwoTypesGroupAvgStatisticsValue(dataAreaSubCnt, groupAreaSubCnt, valueObj, dataAreaFieldConfigObj, statisticsType); |
| | | } else { |
| | | value = valueObj.getString(statisticsType); |
| | | } |
| | | valueObj.put(CmnConst.ATTR_FINAL_VALUE, value); |
| | | } |
| | | } else { |
| | | value = ""; |
| | | } |
| | | // html.append("<td"); |
| | | if (!StringUtils.isEmpty(value)) { |
| | | // class |
| | | if (!StringUtils.isEmpty(dataAreaFieldConfigObj.getString(CmnConst.ATTR_URL))) { |
| | | dataListReportService.extendJSONObject(keyObj, dataAreaFieldConfigObj, Collections.singletonList(CmnConst.ATTR_URL)); |
| | | // html.append(" class=\"").append(CmnConst.CLASS_TD_CAN_TURN).append("\""); |
| | | } |
| | | // 字段属性 |
| | | dataListReportService.getTdAttrObj(keyObj, dataTitleObj); |
| | | String attrUrL = keyObj.getString(CmnConst.ATTR_URL); |
| | | if (!StringUtils.isEmpty(attrUrL)) { |
| | | column.setPenetrateProperty(attrUrL.toString()); |
| | | column.setPenetrate(true); |
| | | } |
| | | for (String key : keyObj.keySet()) { |
| | | column.addProperty(key, keyObj.getString(key)); |
| | | } |
| | | // html.append(dataListReportService.getTdAttrByObj(keyObj)); |
| | | // 格式 |
| | | value = dataListReportService.formatValue(dataAreaFieldConfigObj, value); |
| | | |
| | | } |
| | | column.setContent(value); |
| | | // html.append(">").append(value == null ? "" : value).append("</td>"); |
| | | } |
| | | // html.append("\n</tr>"); |
| | | return columns; |
| | | } |
| | | |
| | | /** |
| | | * 获取总计html |
| | | * |
| | | * @param statisticsMap 统计map |
| | | * @param dataTitleList 数据标题list |
| | | * @param dataAreaFieldConfigMap 数据区字段缓存map |
| | | * @param dataAreaGroupFieldCount 数据区分组字段个数 |
| | | * @param dataAreaSubCnt 数据区下级分组项数 |
| | | * @param totalName 总计名称 |
| | | * @return |
| | | */ |
| | | private StringBuilder getTotalStatisticsHtml(Map<JSONObject, JSONObject> statisticsMap, List<JSONObject> dataTitleList, Map<String, JSONObject> dataAreaFieldConfigMap, int dataAreaGroupFieldCount, int dataAreaSubCnt, String totalName) { |
| | | StringBuilder html = new StringBuilder(256); |
| | | html.append("\n<tr class=\"").append(CmnConst.CLASS_TR_DATA_STATISTICS).append("\">\n "); |
| | |
| | | |
| | | @Service |
| | | public class ListReportConfigServiceImple implements ListReportConfigService { |
| | | |
| | | |
| | | @Autowired |
| | | public BaseDao baseDao; |
| | | public BaseDao getBaseDao() { |
| | |
| | | this.baseDao = baseDao; |
| | | } |
| | | public ListReportServer reportServerNew; |
| | | |
| | | |
| | | public ListReportServer getReportServerNew() { |
| | | return reportServerNew; |
| | | } |
| | |
| | | }else{ |
| | | showGroupField[i] = false;//是否分组 |
| | | } |
| | | } |
| | | } |
| | | //是否固定表头 |
| | | if(felset.getString("fix_header").equals("1")){ |
| | | rc.setFixHeader(true); |
| | |
| | | // }else{ |
| | | // rc.setPage(false); |
| | | // } |
| | | DataTableEntity headerData = baseDao.listTable("product_sys_report_header_properties", "report_uuid = '"+tableUuid+"'"); |
| | | DataTableEntity headerData = baseDao.listTable("product_sys_report_header_properties", "report_uuid = '"+tableUuid+"'"); |
| | | if(headerData.getRows() > 0){ |
| | | int headerY = headerData.getRows() / fieldData.getRows();//二维数组y |
| | | int[][] headerColspan = new int[headerY][fieldData.getRows()];//跨列 |
| | |
| | | //列发生改变 |
| | | if(y != Integer.parseInt(header.getString("header_index").split("-")[1])){ |
| | | y = Integer.parseInt(header.getString("header_index").split("-")[1]); |
| | | |
| | | |
| | | } |
| | | headerTitle[y][x] = header.getString("header_name"); |
| | | headerColspan[y][x] = Integer.parseInt(header.getString("header_colspan")); |
| | |
| | | rc.setFormat(showFormat);//字段格式 |
| | | rc.setGroupField(showGroupField);//是否分组 |
| | | } |
| | | |
| | | |
| | | System.out.println(data.getRows()); |
| | | // rc.setCurrentPage(1);//当前页 |
| | | // rc.setTotalPage(data.getRows() / felset.getInteger("page_size"));//总页数 |
| | | // rc.setTotalCount(data.getRows() / felset.getInteger("page_size"));//总页数 |
| | | // rc.setTotalRow(data.getRows());//总条数 |
| | | rc.setDt(data); |
| | | System.out.println(rc.getDt().getRows()); |