소스 검색

fix(report): 删除多余代码,优化计算式

lishihao 4 년 전
부모
커밋
dd67b56f6a
5개의 변경된 파일4개의 추가작업 그리고 227개의 파일을 삭제
  1. 1 22
      report/src/core/formulasDataSetter.ts
  2. 0 1
      report/src/core/jpc_flow_tab.ts
  3. 0 36
      report/src/public/fsUtil.ts
  4. 3 2
      report/src/public/index.ts
  5. 0 166
      report/src/public/treeUtil.ts

+ 1 - 22
report/src/core/formulasDataSetter.ts

@@ -251,33 +251,12 @@ const insertFieldValue = (fieldID: number, valIdx: number, newValue: number) =>
     }
 }
 
-//设置精度
+//复制精度
 const copyPrecision = (targetFieldID: number, orgFieldID: number) => {
-    // const targetField = <IGroupField>F(targetFieldID);
-    // const orgField = <IGroupField>F(orgFieldID);
-    // if (targetField && orgField) {
-    //     Object.assign(targetField.Precision, orgField.Precision);
-    // } else {
-    //     console.log(`指标${targetFieldID}和${orgFieldID}的数据不支持setPrecision操作`);
-    // }
     copyProperty(targetFieldID, orgFieldID,'Precision');
 }
 
 const copyFixedPrecisionNum = (targetFieldID: number, orgFieldID: number) => {
-    // const targetField = <IGroupField>F(targetFieldID);
-    // const orgField = <IGroupField>F(orgFieldID);
-    // if (targetField && orgField) {
-    //     if (orgField.fixedPrecisionNum) {
-    //         if (!targetField.fixedPrecisionNum) {
-    //             targetField.fixedPrecisionNum = 0;
-    //         }
-    //         Object.assign(targetField.fixedPrecisionNum, orgField.fixedPrecisionNum);
-    //     }else{
-    //         console.log(`指标${orgFieldID}不存在${fixedPrecisionNum}属性`);
-    //     }
-    // } else {
-    //     console.log(`指标${targetFieldID}和${orgFieldID}的数据不支持setPrecision操作`);
-    // }
     copyProperty(targetFieldID, orgFieldID,'fixedPrecisionNum');
 }
 

+ 0 - 1
report/src/core/jpc_flow_tab.ts

@@ -12,7 +12,6 @@ import JpcDiscreteHelper from './helper/jpc_helper_discrete';
 import JpcTextHelper from './helper/jpc_helper_text';
 import JpcCommonOutputHelper from './helper/jpc_helper_common_output';
 import JpcAreaHelper from './helper/jpc_helper_area';
-import fsUtil from '../public/fsUtil';
 import strUtil from '../public/stringUtil';
 import fontWidthMap from './helper/jpc_helper_font_width';
 import {

+ 0 - 36
report/src/public/fsUtil.ts

@@ -1,36 +0,0 @@
-/**
- * Created by Tony on 2017/4/10.
- */
-'use strict';
-
-import * as fs from 'fs';
-
-export default {
-    writeArrayToFile: function(arr: any[], filePath: string) {
-        if (arr && filePath && Array.isArray(arr)) {
-            let chunks = [], len = 0;
-            for (let i = 0; i < arr.length; i++) {
-                let buffer = new Buffer(arr[i]);
-                chunks.push(buffer);
-                len += buffer.length;
-                //
-            }
-            let resultBuffer = new Buffer(len);
-            for(let i=0,size=chunks.length,pos=0;i<size;i++){
-                chunks[i].copy(resultBuffer,pos);
-                pos += chunks[i].length;
-            }
-            fs.writeFile(filePath, resultBuffer, function(err: any){
-                if(err) throw err;
-                //console.log('Write file: ' + filePath + ' ok!');
-            });
-        }
-    },
-    writeObjToFile: function(obj: any, filePath: string) {
-        if (obj) {
-            let arr = [];
-            arr.push(JSON.stringify(obj));
-            this.writeArrayToFile(arr, filePath);
-        }
-    }
-};

+ 3 - 2
report/src/public/index.ts

@@ -1,5 +1,6 @@
 export * from './ReportDate';
-export * from './fsUtil';
 export * from './scMathUtil';
 export * from './stringUtil';
-// export * from './treeUtil';
+export * from './scMathUtil';
+export * from './rptCommon';
+export * from './reportNumber';

+ 0 - 166
report/src/public/treeUtil.ts

@@ -1,166 +0,0 @@
-'use strict';
-
-/**
- * Created by Tony on 2017/3/14.
- */
-
-const NODE_ID = 'ledger_id';
-const P_ID = 'ledger_pid';
-const NEXT_ID = 'NextSiblingID';
-const ADHOC_PRE_ID = 'Previous_ID';
-const ORDER_ID = 'order';
-const CHILDREN_NODE = 'items';
-const SUB_ID = 'sub_ids';
-const EMPTY_ID_VAL = -1;
-const TREE_LEVEL = 'treeLevel';
-const TOP_BILL_ID = 'topBillID';
-const TREE_FLAT_SERIAL_ORDER = 'treeFlatSerialOrder';
-
-function sortOder(item1: any, item2: any) {
-    return parseInt(item1[ORDER_ID]) - parseInt(item2[ORDER_ID]);
-}
-
-const tree_Data_Helper = {
-    buildTreeNodeDirectly: function(data: any, addLevel: number): any[] {
-        let topArr = [], tmpNodes: { [k: string]: any } = {}, prefix = "id_";
-        const rst: any[] = []; 
-        let private_getStartNode = function (idArr: any[]) {
-            let tmpNodeRst = null;
-            for (let i = 0; i < idArr.length; i++) {
-                if (parseInt(tmpNodes[prefix + idArr[i]][ADHOC_PRE_ID]) === EMPTY_ID_VAL) {
-                    tmpNodeRst = tmpNodes[prefix + idArr[i]];
-                    break;
-                }
-            }
-            return tmpNodeRst;
-        };
-        let private_buildNodeData = function(parentItem: any, idArr: any[], treeLevel: number, tbID: number) {
-            let iter = [], nextNode = private_getStartNode(idArr), pushedIds = [];
-            while (nextNode !== null && nextNode !== undefined ) {
-                if (parentItem) {
-                    parentItem[CHILDREN_NODE].push(nextNode);
-                } else {
-                    rst.push(nextNode);
-                }
-                iter.push(nextNode);
-                pushedIds.push(nextNode[NODE_ID]);
-                nextNode[TOP_BILL_ID] = tbID;
-                if (parentItem === null) {
-                    nextNode[TOP_BILL_ID] = nextNode[NODE_ID];
-                    if (nextNode.flags && nextNode.flags.length > 0) {
-                        for (let flag of nextNode.flags) {
-                            if (flag.fieldName === "fixed") {
-                                nextNode[TOP_BILL_ID] = flag.flag;
-                                break;
-                            }
-                        }
-                    }
-                }
-                if (addLevel) nextNode[TREE_LEVEL] = treeLevel;
-                nextNode = tmpNodes[prefix + nextNode[NEXT_ID]];
-                if (nextNode === null || nextNode === undefined) {
-                    //备注: 考虑到实际数据的健壮性,有些节点会掉链子,需要用 parentItem[SUB_ID] 比对已经加上的节点,如发现加上的节点数量不够,那就得在这里补充上去
-                    if (parentItem) {
-                        if (parentItem[SUB_ID].length > iter.length) {
-                            for (let subId of parentItem[SUB_ID]) {
-                                if (pushedIds.indexOf(subId) < 0) {
-                                    let restNode = tmpNodes[prefix + subId];
-                                    if (addLevel) restNode[TREE_LEVEL] = treeLevel;
-                                    restNode[TOP_BILL_ID] = tbID;
-                                    parentItem[CHILDREN_NODE].push(restNode);
-                                    iter.push(restNode);
-                                }
-                            }
-                        }
-                    } else {
-                        if (idArr.length > iter.length) {
-                            for (let topId of idArr) {
-                                if (pushedIds.indexOf(topId) < 0) {
-                                    let restNode = tmpNodes[prefix + topId];
-                                    if (addLevel) restNode[TREE_LEVEL] = treeLevel;
-                                    restNode[TOP_BILL_ID] = restNode[NODE_ID];
-                                    if (restNode.flags && restNode.flags.length > 0) {
-                                        for (let flag of restNode.flags) {
-                                            if (flag.fieldName === "fixed") {
-                                                restNode[TOP_BILL_ID] = flag.flag;
-                                                break;
-                                            }
-                                        }
-                                    }
-                                    rst.push(restNode);
-                                    iter.push(restNode);
-                                }
-                            }
-                        }
-                    }
-                }
-            }
-            pushedIds = [];
-            for (let i = 0; i < iter.length; i++) {
-                let rtbID = tbID;
-                if (parentItem === null) {
-                    rtbID = iter[i][TOP_BILL_ID];
-                }
-                private_buildNodeData(iter[i], iter[i][SUB_ID], (treeLevel + 1), rtbID);
-            }
-        };
-        //1. 给每个节点设置key, 顺便找Top Node
-        for (let i = 0; i < data.length; i++) {
-            let propK = prefix + String(data[i][NODE_ID]);
-            tmpNodes[propK] = data[i];
-            data[i][ADHOC_PRE_ID] = EMPTY_ID_VAL;
-            data[i][SUB_ID] = [];
-            data[i][CHILDREN_NODE] = [];
-            if (parseInt(data[i][P_ID]) === EMPTY_ID_VAL) {
-                topArr.push(data[i][NODE_ID]);
-            }
-        }
-        //2. 通过key,设置好兄弟/父子关系
-        for (let i = 0; i < data.length; i++) {
-            if (parseInt(data[i][NEXT_ID]) !== EMPTY_ID_VAL) {
-                if (tmpNodes[prefix + data[i][NEXT_ID]] !== undefined){
-                    if (tmpNodes[prefix + data[i][NEXT_ID]][P_ID] === data[i][P_ID]) {
-                        tmpNodes[prefix + data[i][NEXT_ID]][ADHOC_PRE_ID] = data[i][NODE_ID];
-                    } else {
-                        tmpNodes[prefix + data[i][NEXT_ID]][ADHOC_PRE_ID] = EMPTY_ID_VAL;
-                        data[i][NEXT_ID] = EMPTY_ID_VAL;
-                    }
-                }
-            }
-            if (parseInt(data[i][P_ID]) !== EMPTY_ID_VAL) {
-                tmpNodes[prefix + data[i][P_ID]][SUB_ID].push(data[i][NODE_ID]);
-            }
-        }
-        //3. 开build
-        private_buildNodeData(null, topArr, 0, -1);
-        //try to release and return
-        // tmpNodes = null;
-        topArr.length = 0;
-        return rst;
-    },
-
-    getFlatArray: function(srcArr: any[], destArr: any[], addSerialOrder: boolean) {
-        let serialStartOrder = 0;
-        const private_put = function(parentItem: any) {
-            if (addSerialOrder) {
-                parentItem[TREE_FLAT_SERIAL_ORDER] = serialStartOrder;
-                serialStartOrder++;
-                // 说明:当清单通过树排序后,为了后续的排序方便,有必要加这个序号,并作为指标提供
-            }
-            destArr.push(parentItem);
-            if (parentItem[CHILDREN_NODE]) {
-                for (const subItem of parentItem[CHILDREN_NODE]) {
-                    private_put(subItem);
-                }
-            }
-        }
-        for (const node of srcArr) {
-            private_put(node);
-        }
-        for (const item of destArr) {
-            delete item[CHILDREN_NODE];
-        }
-    },
-};
-
-module.exports = tree_Data_Helper;