|
@@ -0,0 +1,250 @@
|
|
|
+'use strict';
|
|
|
+
|
|
|
+/**
|
|
|
+ * Created by Tony on 2023/4/14.
|
|
|
+ */
|
|
|
+
|
|
|
+const BaseService = require('../base/base_service');
|
|
|
+const JpcEx = require('../reports/rpt_component/jpc_ex');
|
|
|
+const JV = require('../reports/rpt_component/jpc_value_define');
|
|
|
+const rpt_xl_util = require('../reports/util/rpt_excel_util');
|
|
|
+const rptDataExtractor = require('../reports/util/rpt_calculation_data_util');
|
|
|
+const RPT_DEF_PROPERTIES = require('../const/report_defined_properties');
|
|
|
+
|
|
|
+module.exports = app => {
|
|
|
+
|
|
|
+ class JpcReport extends BaseService {
|
|
|
+
|
|
|
+ /**
|
|
|
+ * 构造函数
|
|
|
+ *
|
|
|
+ * @param {Object} ctx - egg全局变量
|
|
|
+ * @return {void}
|
|
|
+ */
|
|
|
+ constructor(ctx) {
|
|
|
+ super(ctx);
|
|
|
+ this.tableName = '';
|
|
|
+ this.dataId = '';
|
|
|
+ }
|
|
|
+
|
|
|
+ async getAllPagesCommon(ctx, rptTpl, params, option, outputType, baseDir, customSelect) {
|
|
|
+ // const rptDataUtil = new rptDataExtractor();
|
|
|
+ // rptDataUtil.initialize(rptTpl);
|
|
|
+ // const filter = rptDataUtil.getDataRequestFilter();
|
|
|
+ // const rawDataObj = await ctx.service.report.getReportData(params, filter.tables, filter.memFieldKeys,
|
|
|
+ // rptTpl[JV.NODE_CUSTOM_DEFINE], customSelect);
|
|
|
+ // // console.log(rawDataObj);
|
|
|
+ // try {
|
|
|
+ // const printCom = JpcEx.createNew();
|
|
|
+ // if (params.pageSize) rptTpl[JV.NODE_MAIN_INFO][JV.NODE_PAGE_INFO][JV.PROP_PAGE_SIZE] = params.pageSize;
|
|
|
+ // if (params.orientation && (params.orientation !== 'null')) rptTpl[JV.NODE_MAIN_INFO][JV.NODE_PAGE_INFO][JV.PROP_ORIENTATION] = params.orientation;
|
|
|
+
|
|
|
+ // const defProperties = RPT_DEF_PROPERTIES;
|
|
|
+ // const tplData = rptDataUtil.assembleData(ctx, rawDataObj, baseDir, printCom, customSelect);
|
|
|
+
|
|
|
+ // if (params.custCfg) {
|
|
|
+ // setupCustomizeCfg(params.custCfg, rptTpl, defProperties);
|
|
|
+ // } else {
|
|
|
+ // // setupCustomizeCfg(defProperties, rptTpl, defProperties);
|
|
|
+ // }
|
|
|
+ // const dftOption = params.option || JV.PAGING_OPTION_NORMAL;
|
|
|
+ // printCom.initialize(rptTpl);
|
|
|
+ // printCom.analyzeData(ctx.helper, rptTpl, tplData, defProperties, dftOption, outputType, customSelect);
|
|
|
+ // const maxPages = printCom.totalPages;
|
|
|
+ // let pageRst = null;
|
|
|
+ // if (maxPages > 0) {
|
|
|
+ // pageRst = printCom.outputAsSimpleJSONPageArray(ctx.helper, rptTpl, tplData, 1, maxPages, defProperties, params.custCfg, customSelect);
|
|
|
+ // } else {
|
|
|
+ // pageRst = printCom.outputAsPreviewPage(rptTpl, defProperties);
|
|
|
+ // }
|
|
|
+ // pageRst.id = params.rpt_tpl_id;
|
|
|
+ // return pageRst;
|
|
|
+ // } catch (ex) {
|
|
|
+ // console.log('报表数据异常, tender id: ' + params.tender_id);
|
|
|
+ // console.log(ex);
|
|
|
+ // }
|
|
|
+ }
|
|
|
+
|
|
|
+ getAllPreviewPagesCommon(rawRptTpl, pageSize) {
|
|
|
+ const printCom = JpcEx.createNew();
|
|
|
+ const defProperties = RPT_DEF_PROPERTIES;
|
|
|
+ const rptTpl = JSON.parse(rawRptTpl.rpt_content);
|
|
|
+ rptTpl[JV.NODE_MAIN_INFO][JV.NODE_PAGE_INFO][JV.PROP_PAGE_SIZE] = pageSize;
|
|
|
+ setupSomeDftCustomizeCfg(rptTpl);
|
|
|
+ printCom.initialize(rptTpl);
|
|
|
+ const pageRst = printCom.outputAsPreviewPage(rptTpl, defProperties);
|
|
|
+ return pageRst;
|
|
|
+ }
|
|
|
+ }
|
|
|
+
|
|
|
+ return JpcReport;
|
|
|
+};
|
|
|
+
|
|
|
+function setupCustomizeCfg(customizeCfg, rptTpl, defProperties) {
|
|
|
+ const tmpObj = {};
|
|
|
+ // 1. 字体
|
|
|
+ const newFonts = [];
|
|
|
+ for (const font of defProperties.fonts) {
|
|
|
+ const copyFont = {};
|
|
|
+ copyFont.ID = font.ID;
|
|
|
+ for (const fontProp of JV.FONT_PROPS) {
|
|
|
+ copyFont[fontProp] = font[fontProp];
|
|
|
+ }
|
|
|
+ newFonts.push(copyFont);
|
|
|
+ tmpObj[font.ID] = copyFont;
|
|
|
+ }
|
|
|
+ const private_setup_font = function(propStr, newFont) {
|
|
|
+ if (tmpObj[propStr]) {
|
|
|
+ tmpObj[propStr].Name = newFont.Name;
|
|
|
+ tmpObj[propStr].FontHeight = String(newFont.FontHeight);
|
|
|
+ tmpObj[propStr].FontBold = newFont.FontBold;
|
|
|
+ tmpObj[propStr].FontItalic = newFont.FontItalic;
|
|
|
+ tmpObj[propStr].FontUnderline = newFont.FontUnderline;
|
|
|
+ }
|
|
|
+ };
|
|
|
+ for (const custFont of customizeCfg.fonts) {
|
|
|
+ switch (custFont.CfgDispName) {
|
|
|
+ case '表标题':
|
|
|
+ private_setup_font('ReportTitle_Main', custFont);
|
|
|
+ break;
|
|
|
+ case '列标题':
|
|
|
+ private_setup_font('HeaderColumn', custFont);
|
|
|
+ private_setup_font('FooterColumn', custFont);
|
|
|
+ break;
|
|
|
+ case '正文内容':
|
|
|
+ private_setup_font('Content', custFont);
|
|
|
+ break;
|
|
|
+ case '合计':
|
|
|
+ private_setup_font('GrandTotal', custFont);
|
|
|
+ private_setup_font('SectionTotal', custFont);
|
|
|
+ break;
|
|
|
+ case '表眉/表脚':
|
|
|
+ private_setup_font('Header', custFont);
|
|
|
+ private_setup_font('Footer', custFont);
|
|
|
+ break;
|
|
|
+ default:
|
|
|
+ break;
|
|
|
+ }
|
|
|
+ }
|
|
|
+ // 1.1 窄体
|
|
|
+ if (tmpObj.Content_Narrow) {
|
|
|
+ if (customizeCfg.isNarrow) {
|
|
|
+ tmpObj.Content_Narrow.Name = 'Arial Narrow';
|
|
|
+ } else {
|
|
|
+ if (tmpObj.Content) {
|
|
|
+ tmpObj.Content_Narrow.Name = tmpObj.Content.Name;
|
|
|
+ } else {
|
|
|
+ tmpObj.Content_Narrow.Name = '宋体';
|
|
|
+ }
|
|
|
+ }
|
|
|
+ }
|
|
|
+ defProperties.fonts = newFonts;
|
|
|
+ // 2. 页边距
|
|
|
+ rptTpl[JV.NODE_MAIN_INFO][JV.NODE_MARGINS][JV.PROP_LEFT] = customizeCfg.margins[JV.PROP_LEFT] / 10;
|
|
|
+ rptTpl[JV.NODE_MAIN_INFO][JV.NODE_MARGINS][JV.PROP_RIGHT] = customizeCfg.margins[JV.PROP_RIGHT] / 10;
|
|
|
+ rptTpl[JV.NODE_MAIN_INFO][JV.NODE_MARGINS][JV.PROP_TOP] = customizeCfg.margins[JV.PROP_TOP] / 10;
|
|
|
+ rptTpl[JV.NODE_MAIN_INFO][JV.NODE_MARGINS][JV.PROP_BOTTOM] = customizeCfg.margins[JV.PROP_BOTTOM] / 10;
|
|
|
+ // 3. 边框宽度
|
|
|
+ if (customizeCfg.hasOwnProperty('borderThick')) {
|
|
|
+ for (let i = 0; i < defProperties.styles.length; i++) {
|
|
|
+ const style = defProperties.styles[i];
|
|
|
+ if (style.ID === 'BORDER_ALL_AROUND') {
|
|
|
+ for (const border of style.border_style) {
|
|
|
+ border.LineWeight = customizeCfg.borderThick;
|
|
|
+ }
|
|
|
+ }
|
|
|
+ }
|
|
|
+ }
|
|
|
+ // 4. 边框竖线
|
|
|
+ if (!(customizeCfg.showVerticalLine)) {
|
|
|
+ const private_copy_border = function(src) {
|
|
|
+ const rst = {};
|
|
|
+ rst.Position = src.Position;
|
|
|
+ rst.LineWeight = src.LineWeight;
|
|
|
+ rst.DashStyle = src.DashStyle;
|
|
|
+ rst.Color = src.Color;
|
|
|
+ return rst;
|
|
|
+ };
|
|
|
+ const newStyles = [];
|
|
|
+ for (let i = 0; i < defProperties.styles.length; i++) {
|
|
|
+ const style = defProperties.styles[i];
|
|
|
+ newStyles.push(style);
|
|
|
+ if (style.ID === 'BORDER_ALL_AROUND') {
|
|
|
+ const newStyle = {};
|
|
|
+ newStyle.ID = style.ID;
|
|
|
+ newStyle.CfgDispName = style.CfgDispName;
|
|
|
+ newStyle.border_style = [];
|
|
|
+ for (const border of style.border_style) {
|
|
|
+ const newBorder = private_copy_border(border);
|
|
|
+ newStyle.border_style.push(newBorder);
|
|
|
+ if (border.Position === 'Left' || border.Position === 'Right') {
|
|
|
+ newBorder.LineWeight = 0;
|
|
|
+ }
|
|
|
+ }
|
|
|
+ newStyles[newStyles.length - 1] = newStyle;
|
|
|
+ }
|
|
|
+ }
|
|
|
+ defProperties.styles = newStyles;
|
|
|
+ }
|
|
|
+ // 5. 补0
|
|
|
+ const private_Setup_Format = function(tabFields) {
|
|
|
+ if (tabFields) {
|
|
|
+ for (const tabField of tabFields) {
|
|
|
+ if (tabField[JV.PROP_FORMAT]) {
|
|
|
+ tabField[JV.PROP_FORMAT] = tabField[JV.PROP_FORMAT].replace(new RegExp('#', 'gm'), '0');
|
|
|
+ }
|
|
|
+ }
|
|
|
+ }
|
|
|
+ };
|
|
|
+ if (customizeCfg.fillZero) {
|
|
|
+ if (rptTpl[JV.NODE_FLOW_INFO]) {
|
|
|
+ if (rptTpl[JV.NODE_FLOW_INFO][JV.NODE_FLOW_CONTENT]) private_Setup_Format(rptTpl[JV.NODE_FLOW_INFO][JV.NODE_FLOW_CONTENT][JV.PROP_FLOW_FIELDS]);
|
|
|
+ if (rptTpl[JV.NODE_FLOW_INFO][JV.NODE_FLOW_PAGE_SUM]) private_Setup_Format(rptTpl[JV.NODE_FLOW_INFO][JV.NODE_FLOW_PAGE_SUM][JV.PROP_SUM_FIELDS]);
|
|
|
+ if (rptTpl[JV.NODE_FLOW_INFO][JV.NODE_FLOW_SEG_SUM]) private_Setup_Format(rptTpl[JV.NODE_FLOW_INFO][JV.NODE_FLOW_SEG_SUM][JV.PROP_SUM_FIELDS]);
|
|
|
+ if (rptTpl[JV.NODE_FLOW_INFO][JV.NODE_FLOW_GROUP] && rptTpl[JV.NODE_FLOW_INFO][JV.NODE_FLOW_GROUP][JV.PROP_GROUP_LINES]) private_Setup_Format(rptTpl[JV.NODE_FLOW_INFO][JV.NODE_FLOW_GROUP][JV.PROP_GROUP_LINES][JV.PROP_SUM_FIELDS]);
|
|
|
+ if (rptTpl[JV.NODE_FLOW_INFO][JV.NODE_DISCRETE_INFO]) {
|
|
|
+ for (const discrete of rptTpl[JV.NODE_FLOW_INFO][JV.NODE_DISCRETE_INFO]) {
|
|
|
+ private_Setup_Format(discrete[JV.PROP_DISCRETE_FIELDS]);
|
|
|
+ }
|
|
|
+ }
|
|
|
+ if (rptTpl[JV.NODE_FLOW_INFO_EX]) {
|
|
|
+ if (rptTpl[JV.NODE_FLOW_INFO_EX][JV.NODE_FLOW_CONTENT]) private_Setup_Format(rptTpl[JV.NODE_FLOW_INFO_EX][JV.NODE_FLOW_CONTENT][JV.PROP_FLOW_FIELDS]);
|
|
|
+ if (rptTpl[JV.NODE_FLOW_INFO_EX][JV.NODE_FLOW_PAGE_SUM]) private_Setup_Format(rptTpl[JV.NODE_FLOW_INFO_EX][JV.NODE_FLOW_PAGE_SUM][JV.PROP_SUM_FIELDS]);
|
|
|
+ if (rptTpl[JV.NODE_FLOW_INFO_EX][JV.NODE_FLOW_SEG_SUM]) private_Setup_Format(rptTpl[JV.NODE_FLOW_INFO_EX][JV.NODE_FLOW_SEG_SUM][JV.PROP_SUM_FIELDS]);
|
|
|
+ if (rptTpl[JV.NODE_FLOW_INFO_EX][JV.NODE_FLOW_GROUP]) private_Setup_Format(rptTpl[JV.NODE_FLOW_INFO_EX][JV.NODE_FLOW_GROUP][JV.PROP_SUM_FIELDS]);
|
|
|
+ if (rptTpl[JV.NODE_FLOW_INFO_EX][JV.NODE_FLOW_GROUP] && rptTpl[JV.NODE_FLOW_INFO_EX][JV.NODE_FLOW_GROUP][JV.PROP_GROUP_LINES]) private_Setup_Format(rptTpl[JV.NODE_FLOW_INFO_EX][JV.NODE_FLOW_GROUP][JV.PROP_GROUP_LINES][JV.PROP_SUM_FIELDS]);
|
|
|
+ if (rptTpl[JV.NODE_FLOW_INFO_EX][JV.NODE_DISCRETE_INFO]) {
|
|
|
+ for (const discrete of rptTpl[JV.NODE_FLOW_INFO_EX][JV.NODE_DISCRETE_INFO]) {
|
|
|
+ private_Setup_Format(discrete[JV.PROP_DISCRETE_FIELDS]);
|
|
|
+ }
|
|
|
+ }
|
|
|
+ }
|
|
|
+ } else if (rptTpl[JV.NODE_BILL_INFO]) {
|
|
|
+ if (rptTpl[JV.NODE_BILL_INFO][JV.NODE_BILL_CONTENT]) private_Setup_Format(rptTpl[JV.NODE_BILL_INFO][JV.NODE_BILL_CONTENT][JV.PROP_BILL_FIELDS]);
|
|
|
+ if (rptTpl[JV.NODE_BILL_INFO][JV.NODE_DISCRETE_INFO]) {
|
|
|
+ for (const discrete of rptTpl[JV.NODE_BILL_INFO][JV.NODE_DISCRETE_INFO]) {
|
|
|
+ private_Setup_Format(discrete[JV.PROP_DISCRETE_FIELDS]);
|
|
|
+ }
|
|
|
+ }
|
|
|
+ } else if (rptTpl[JV.NODE_CROSS_INFO]) {
|
|
|
+ if (rptTpl[JV.NODE_CROSS_INFO][JV.NODE_CROSS_CONTENT]) private_Setup_Format(rptTpl[JV.NODE_CROSS_INFO][JV.NODE_CROSS_CONTENT][JV.TAB_CROSS_FIELDS]);
|
|
|
+ if (rptTpl[JV.NODE_CROSS_INFO][JV.NODE_CROSS_ROW]) private_Setup_Format(rptTpl[JV.NODE_CROSS_INFO][JV.NODE_CROSS_ROW][JV.TAB_CROSS_FIELDS]);
|
|
|
+ if (rptTpl[JV.NODE_CROSS_INFO][JV.NODE_CROSS_COL]) private_Setup_Format(rptTpl[JV.NODE_CROSS_INFO][JV.NODE_CROSS_COL][JV.TAB_CROSS_FIELDS]);
|
|
|
+ if (rptTpl[JV.NODE_CROSS_INFO][JV.NODE_CROSS_COL_SUM]) private_Setup_Format(rptTpl[JV.NODE_CROSS_INFO][JV.NODE_CROSS_COL_SUM][JV.TAB_CROSS_FIELDS]);
|
|
|
+ if (rptTpl[JV.NODE_CROSS_INFO][JV.NODE_CROSS_ROW_EXT]) private_Setup_Format(rptTpl[JV.NODE_CROSS_INFO][JV.NODE_CROSS_ROW_EXT][JV.TAB_CROSS_FIELDS]);
|
|
|
+ if (rptTpl[JV.NODE_CROSS_INFO][JV.NODE_CROSS_ROW_SUM_EXT]) private_Setup_Format(rptTpl[JV.NODE_CROSS_INFO][JV.NODE_CROSS_ROW_SUM_EXT][JV.TAB_CROSS_FIELDS]);
|
|
|
+ if (rptTpl[JV.NODE_CROSS_INFO][JV.NODE_DISCRETE_INFO]) {
|
|
|
+ for (const discrete of rptTpl[JV.NODE_CROSS_INFO][JV.NODE_DISCRETE_INFO]) {
|
|
|
+ private_Setup_Format(discrete[JV.PROP_DISCRETE_FIELDS]);
|
|
|
+ }
|
|
|
+ }
|
|
|
+ }
|
|
|
+ }
|
|
|
+}
|
|
|
+
|
|
|
+function setupSomeDftCustomizeCfg(rptTpl) {
|
|
|
+ rptTpl[JV.NODE_MAIN_INFO][JV.NODE_MARGINS][JV.PROP_LEFT] = 1.5;
|
|
|
+ rptTpl[JV.NODE_MAIN_INFO][JV.NODE_MARGINS][JV.PROP_RIGHT] = 1.5;
|
|
|
+ rptTpl[JV.NODE_MAIN_INFO][JV.NODE_MARGINS][JV.PROP_TOP] = 1.5;
|
|
|
+ rptTpl[JV.NODE_MAIN_INFO][JV.NODE_MARGINS][JV.PROP_BOTTOM] = 1.5;
|
|
|
+}
|