示例代码放到了下面,思路上就是处理不同的模板上一些特定的校验或者解析成后端通用的数据格式;
至于具体如何实现,其实都是灵活的,只要能解决您的问题都是可以的,不必完全拘泥于具体格式。
- var finacePage = {
- /*
- * 组装财报结构化数据
- * */
- assembleFinanceDto: function (spread) {
- // 财报页面维度拼接 gxd
- // {指标名:xx,指标值:xx,维度:xx,系统标识:xx}
- var dataSources = spreadJSUtil.getDataSourceForSheets("ss");
- // 资产负债表-金融-非合并
- var bindData = dataSources[0].dataSource;
- var dataOne = _assembleHelper(bindData, "CustFiRE", "ZCFZB");
- // 利润表-金融-非合并
- bindData = dataSources[1].dataSource;
- var dataTwo = _assembleHelper(bindData, "CustFiRE", "LRB");
- // 现金流量表-金融-非合并
- bindData = dataSources[2].dataSource;
- var dataThree = _assembleHelper(bindData, "CustFiRE", "XJLLB");
- return dataOne.concat(dataTwo, dataThree);
- },
- /**
- * 对spread进行验证
- * @param spread spreadjs的spread对象
- */
- validation: function (spread) {
- var sheetCount = spread.getSheetCount();
- var result = {};
- var isValid = true;
- for (var i = 0; i < sheetCount; i++) {
- var sheet = spread.getSheet(i);
- var rowCount = sheet.getRowCount();
- var colCount = sheet.getColumnCount();
- for (var j = 0; j < rowCount; j++) {
- for (var k = 0; k < colCount; k++) {
- var dataValidator = sheet.getDataValidator(j, k);
- isValid = (dataValidator !== undefined) ? sheet.isValid(j, k, sheet.getValue(j, k)) : isValid;
- if(!isValid){
- result['isValid'] = isValid;
- result['isForce'] = true;
- return result;
- }
- }
- }
- }
- result['isValid'] = isValid;
- result['isForce'] = false;
- return result;
- }
- };
- function _assembleHelper(bindData, systemFlag, sheetName) {
- var dataArray = [];
- // 维度信息:编制单位,编制日期,财报值类型(包含本期金额,上期金额)
- var dimension = {};
- dimension["makeOrg"] = bindData["makeOrg"];
- dimension["makeDate"] = bindData["makeDate"];
- dimension["sheetName"] = sheetName;
- var bindingNames = Object.keys(bindData);
- for (var i = 0; i < bindingNames.length -2; i++) {
- if (bindingNames[i].indexOf("indicator") !== -1
- && (bindingNames[i + 1].indexOf("filed") !== -1
- || bindingNames[i + 1].indexOf("field") !== -1)) {
- dimension["valueType"] = "bqje";
- dataArray.push({
- "quotaName": bindingNames[i].substr(10),
- "dimension": JSON.stringify(dimension),
- "systemFlag": systemFlag,
- "quotaValue": bindData[bindingNames[i+1]]
- });
- dimension["valueType"] = "sqje";
- dataArray.push({
- "quotaName": bindingNames[i].substr(10),
- "dimension": JSON.stringify(dimension),
- "systemFlag": systemFlag,
- "quotaValue": bindData[bindingNames[i+2]]
- });
- i += 2;
- }
- }
- return dataArray;
- }
复制代码 |