var excel = require('exceljs');
const system = require("./system");
var db = system.getObject("db.common.connection").getCon();

//读取模板文件
async function readxls(path) {
    var promise = new Promise((resv, rej) => {
        var workbook = new excel.Workbook();
        workbook.properties.date1904 = true;
        workbook.xlsx.readFile(path)
            .then(function () {
                return resv(workbook);
            }).catch(function (e) {
                return rej(e);
            });
    });
    return promise;
}

function getRowData() {
    var rowdata = {
        companycode: "",
        companyname: "",
        timetypecode: "",
        timetypename: "",
        batchdate: "",
        dateym: "",
        rpttypecode: "",
        position: "",
        valstr: "",
        desc: "",
    }
    return rowdata;
}

//GT--增值税一般纳税人解析
/* (async ()=>{
     var wb=await readxls("./rpttemp/at/GT.xlsx");
     var sheet = wb.getWorksheet(1);
     var insertrows=[];
     sheet.eachRow({ includeEmpty: true }, function(row, rowNumber) {
         if(rowNumber>=10 && rowNumber<=47){
           console.log(rowNumber,">>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>..");
           var rowDesc="";
           var cacheStr="";
           row.eachCell({ includeEmpty: true }, function(cell, colNumber) {
               if(colNumber==2){
                   if(typeof cell.value=="object"){
                     cell.value.richText.forEach(element => {
                       rowDesc+=element.text;
                     });
                   }else{
                       rowDesc+=cell.value;
                   }     
                   console.log(rowDesc);
                   cacheStr=rowDesc;
               }
               if(colNumber==19 || colNumber==26 || colNumber==36 || colNumber==40){
                   var colPos=1;
                   var buildRow=getRowData();
                   if(colNumber==19 || colNumber==26){
                       rowDesc=rowDesc+"/"+"一般项目";
                   }
                   if(colNumber==36 || colNumber==40){
                       rowDesc=rowDesc+"/"+"即征即退项目";
                   }
                   if(colNumber==19){
                       rowDesc+="/"+"本月数";
                       colPos=1;
                   }
                   if(colNumber==26){
                       rowDesc+="/"+"本年累计";
                       colPos=2;
                   }
                   if(colNumber==36){
                       rowDesc+="/"+"本月数";
                       colPos=3;
                   }
                   if(colNumber==40){
                       rowDesc+="/"+"本年累计";
                       colPos=4;
                   }
                   buildRow.rpttypecode="GT";
                   buildRow.timetypecode="Q";
                   buildRow.position=rowNumber+"-"+colPos;
                   buildRow.desc=rowDesc;
                   buildRow.valstr=cell.value;
                   console.log(JSON.stringify(buildRow));
                   insertrows.push(buildRow);
                   rowDesc=cacheStr;
               }
             });
         }
     });
     //db.models.rpthistory.bulkCreate(insertrows);
 })();*/

//ST--小规模纳税人解析
/*(async ()=>{
    var wb=await readxls("./rpttemp/at/ST.xlsx");
    var sheet = wb.getWorksheet(1);
    var insertrows=[];
    sheet.eachRow({ includeEmpty: true }, function(row, rowNumber) {
        if(rowNumber>=9 && rowNumber<=33){
          console.log(rowNumber,">>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>..");
          var rowDesc="";
          var cacheStr="";
          row.eachCell({ includeEmpty: true }, function(cell, colNumber) {
              if(colNumber==2){
                  if(typeof cell.value=="object"){
                    cell.value.richText.forEach(element => {
                      rowDesc+=element.text;
                    });
                  }else{
                      rowDesc+=cell.value;
                  }     
                  console.log(rowDesc);
                  cacheStr=rowDesc;
              }
              if(colNumber==5 || colNumber==6 || colNumber==7 || colNumber==8){
                  var colPos=1;
                  var buildRow=getRowData();
                  if(colNumber==5 || colNumber==6){
                      rowDesc=rowDesc+"/"+"本期数";
                  }
                  if(colNumber==7 || colNumber==8){
                      rowDesc=rowDesc+"/"+"本年累计";
                  }
                  if(colNumber==5){
                      rowDesc+="/"+"货物及劳务";
                      colPos=1;
                  }
                  if(colNumber==6){
                      rowDesc+="/"+"服务、不动产和无形资产";
                      colPos=2;
                  }
                  if(colNumber==7){
                      rowDesc+="/"+"货物及劳务";
                      colPos=3;
                  }
                  if(colNumber==8){
                      rowDesc+="/"+"服务、不动产和无形资产";
                      colPos=4;
                  }
                  buildRow.rpttypecode="GT";
                  buildRow.timetypecode="Q";
                  buildRow.position=rowNumber+"-"+colPos;
                  buildRow.desc=rowDesc;
                  buildRow.valstr=cell.value;
                  console.log(JSON.stringify(buildRow));
                  insertrows.push(buildRow);
                  rowDesc=cacheStr;
              }
            });
        }
    });
    
    //db.models.rpthistory.bulkCreate(insertrows);
})();*/

/*(async ()=>{
    var wb=await readxls("./rpttemp/at/GT.xlsx");
    var sheet = wb.getWorksheet(1);
    var insertrows=[];
    sheet.eachRow({ includeEmpty: true }, function(row, rowNumber) {
        if(rowNumber>=10 && rowNumber<=47){
          console.log(rowNumber,">>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>..");
          var rowDesc="";
          var cacheStr="";
          row.eachCell({ includeEmpty: true }, function(cell, colNumber) {
              if(colNumber==2){
                  if(typeof cell.value=="object"){
                    cell.value.richText.forEach(element => {
                      rowDesc+=element.text;
                    });
                  }else{
                      rowDesc+=cell.value;
                  }     
                  console.log(rowDesc);
                  cacheStr=rowDesc;
              }
              if(colNumber==19 || colNumber==26 || colNumber==36 || colNumber==40){
                  var colPos=1;
                  var buildRow=getRowData();
                  if(colNumber==19 || colNumber==26){
                      rowDesc=rowDesc+"/"+"一般项目";
                  }
                  if(colNumber==36 || colNumber==40){
                      rowDesc=rowDesc+"/"+"即征即退项目";
                  }
                  if(colNumber==19){
                      rowDesc+="/"+"本月数";
                      colPos=1;
                  }
                  if(colNumber==26){
                      rowDesc+="/"+"本年累计";
                      colPos=2;
                  }
                  if(colNumber==36){
                      rowDesc+="/"+"本月数";
                      colPos=3;
                  }
                  if(colNumber==40){
                      rowDesc+="/"+"本年累计";
                      colPos=4;
                  }
                  buildRow.rpttypecode="GT";
                  buildRow.timetypecode="Q";
                  buildRow.position=rowNumber+"-"+colPos;
                  buildRow.desc=rowDesc;
                  buildRow.valstr=cell.value;
                  console.log(JSON.stringify(buildRow));
                  insertrows.push(buildRow);
                  rowDesc=cacheStr;
              }
            });
        }
    });
    //db.models.rpthistory.bulkCreate(insertrows);
})();*/
//NA--资产负债表
/*(async ()=>{
    var wb=await readxls("./rpttemp/fi/NA.xlsx");
    var sheet = wb.getWorksheet(1);
    var insertrows=[];
    sheet.eachRow({ includeEmpty: true }, function(row, rowNumber) {
        if(rowNumber>=5 && rowNumber<=45){
          row.eachCell({ includeEmpty: true }, function(cell, colNumber) {
       
                 if(colNumber==1){
                      desc="资产/"+cell.value;
                      console.log(desc,">>>>>>>>>>>>>>>");
                 }
                 if(colNumber==3 || colNumber==4){
                     if(desc!="资产/"){
                          var buildRow=getRowData();
                          buildRow.rpttypecode="NA";
                          buildRow.timetypecode="Q";
                          buildRow.valstr=cell.value;
                      
                          buildRow.valstr=cell.value;
                          if(colNumber==3){
                              buildRow.desc=desc+"/期末余额";
                              buildRow.position=rowNumber+"-"+1;
                          }else{
                              buildRow.desc=desc+"/年初余额";
                              buildRow.position=rowNumber+"-"+2;
                          }
                          insertrows.push(buildRow);
                     }
                 }
                 if(colNumber==5){
                     desc="负债和所有者权益/"+cell.value;
                 }
                 if(colNumber==7 || colNumber==8){
                  if(desc!="负债和所有者权益/"){
                       buildRow=getRowData();
                       buildRow.rpttypecode="NA";
                       buildRow.timetypecode="Q";
                       buildRow.valstr=cell.value;
                       if(colNumber==7){
                          buildRow.desc=desc+"/期末余额";
                           buildRow.position=rowNumber+"-"+3;
                       }else{
                           buildRow.desc=desc+"/年初余额";
                           buildRow.position=rowNumber+"-"+4;
                       }
                       insertrows.push(buildRow);
                  }
              }
            });
        }
    });
    console.log(JSON.stringify(insertrows));
    //db.models.rpthistory.bulkCreate(insertrows);
})();*/

//SA
/*(async ()=>{
  var wb=await readxls("./rpttemp/fi/SA.xlsx");
  var sheet = wb.getWorksheet(1);
  var insertrows=[];
  sheet.eachRow({ includeEmpty: true }, function(row, rowNumber) {
      if(rowNumber>=5 && rowNumber<=36){
        row.eachCell({ includeEmpty: true }, function(cell, colNumber) {
     
               if(colNumber==1){
                    desc="资产/"+cell.value;
                    console.log(desc,">>>>>>>>>>>>>>>");
               }
               if(colNumber==3 || colNumber==4){
                   if(desc!="资产/"){
                        var buildRow=getRowData();
                        buildRow.rpttypecode="NA";
                        buildRow.timetypecode="Q";
                        buildRow.valstr=cell.value;
                    
                        buildRow.valstr=cell.value;
                        if(colNumber==3){
                            buildRow.desc=desc+"/期末余额";
                            buildRow.position=rowNumber+"-"+1;
                        }else{
                            buildRow.desc=desc+"/年初余额";
                            buildRow.position=rowNumber+"-"+2;
                        }
                        insertrows.push(buildRow);
                   }
               }
               if(colNumber==5){
                   desc="负债和所有者权益/"+cell.value;
               }
               if(colNumber==7 || colNumber==8){
                if(desc!="负债和所有者权益/"){
                     buildRow=getRowData();
                     buildRow.rpttypecode="NA";
                     buildRow.timetypecode="Q";
                     buildRow.valstr=cell.value;
                     if(colNumber==7){
                        buildRow.desc=desc+"/期末余额";
                         buildRow.position=rowNumber+"-"+3;
                     }else{
                         buildRow.desc=desc+"/年初余额";
                         buildRow.position=rowNumber+"-"+4;
                     }
                     insertrows.push(buildRow);
                }
            }
          });
      }
  });
  console.log(JSON.stringify(insertrows));
  //db.models.rpthistory.bulkCreate(insertrows);
})();*/


//NP
/* (async ()=>{
    var wb=await readxls("./rpttemp/fi/NP.xlsx");
    var sheet = wb.getWorksheet(1);
    var insertrows=[];
    sheet.eachRow({ includeEmpty: true }, function(row, rowNumber) {
        if(rowNumber>=5 && rowNumber<=38){
          row.eachCell({ includeEmpty: true }, function(cell, colNumber) {
       
                 if(colNumber==1){
                    if(typeof cell.value=="object"){
                        desc="";
                        cell.value.richText.forEach(element => {
                            desc+=element.text;
                        });
                      }else{
                        desc=cell.value;
                      }     
                      console.log(desc,">>>>>>>>>>>>>>>");
                 }
                 if(colNumber==3 || colNumber==4){
                          var buildRow=getRowData();
                          buildRow.rpttypecode="NP";
                          buildRow.timetypecode="Q";
                          buildRow.valstr=cell.value;
                          if(colNumber==3){
                              buildRow.desc=desc+"/本期金额";
                              buildRow.position=rowNumber+"-"+1;
                          }else{
                              buildRow.desc=desc+"/本年累计金额";
                              buildRow.position=rowNumber+"-"+2;
                          }
                          insertrows.push(buildRow);
                 }
            });
        }
    });
    console.log(JSON.stringify(insertrows));
    //db.models.rpthistory.bulkCreate(insertrows);
})();*/

//SP
/*
(async ()=>{
    var wb=await readxls("./rpttemp/fi/SP.xlsx");
    var sheet = wb.getWorksheet(1);
    var insertrows=[];
    sheet.eachRow({ includeEmpty: true }, function(row, rowNumber) {
        if(rowNumber>=5 && rowNumber<=38){
          row.eachCell({ includeEmpty: true }, function(cell, colNumber) {
                 if(colNumber==1){
                    if(typeof cell.value=="object"){
                        desc="";
                        cell.value.richText.forEach(element => {
                            desc+=element.text;
                        });
                      }else{
                        desc=cell.value;
                      }     
                      console.log(desc,">>>>>>>>>>>>>>>");
                 }
                 if(colNumber==3 || colNumber==4){
                          var buildRow=getRowData();
                          buildRow.rpttypecode="NP";
                          buildRow.timetypecode="Q";
                          buildRow.valstr=cell.value;
                          if(colNumber==3){
                              buildRow.desc=desc+"/本年累计金额";
                              buildRow.position=rowNumber+"-"+1;
                          }else{
                              buildRow.desc=desc+"/本月金额";
                              buildRow.position=rowNumber+"-"+2;
                          }
                          insertrows.push(buildRow);
                 }
            });
        }
    });
    console.log(JSON.stringify(insertrows));
    //db.models.rpthistory.bulkCreate(insertrows);
})();*/
//ITQ
/*(async ()=>{
    var wb=await readxls("./rpttemp/it/Q/ITQ.xlsx");
    var sheet = wb.getWorksheet(1);
    var insertrows=[];
    sheet.eachRow({ includeEmpty: true }, function(row, rowNumber) {
        if(rowNumber>=13 && rowNumber<=27){
          row.eachCell({ includeEmpty: true }, function(cell, colNumber) {
                 if(colNumber==2){
                    if(typeof cell.value=="object"){
                        desc="";
                        cell.value.richText.forEach(element => {
                            desc+=element.text;
                        });
                      }else{
                        desc=cell.value;
                      }     
                      console.log(desc,">>>>>>>>>>>>>>>");
                 }
                 if(colNumber==11){
                          var buildRow=getRowData();
                          buildRow.rpttypecode="ITQ";
                          buildRow.timetypecode="Q";
                          buildRow.valstr=cell.value;
                          buildRow.desc=desc+"/本年累计金额";
                          buildRow.position=rowNumber+"-"+1;
                          insertrows.push(buildRow);
                 }
            });
        }
        if(rowNumber>=29 && rowNumber<=34){
            row.eachCell({ includeEmpty: true }, function(cell, colNumber) {
                if(colNumber==4){
                    if(typeof cell.value=="object"){
                        desc="";
                        cell.value.richText.forEach(element => {
                            desc+=element.text;
                        });
                      }else{
                        desc=cell.value;
                      }     
                      console.log(desc,">>>>>>>>>>>>>>>");
                 }
                 if(colNumber==11){
                    var buildRow=getRowData();
                    buildRow.rpttypecode="ITQ";
                    buildRow.timetypecode="Q";
                    buildRow.valstr=cell.value;
                    buildRow.desc=desc+"/本年累计金额";
                    buildRow.position=rowNumber+"-"+1;
                    insertrows.push(buildRow);
               }
            });
         
        }
        if(rowNumber>=39 && rowNumber<=40){
            row.eachCell({ includeEmpty: true }, function(cell, colNumber) {
                if(colNumber==1){
                    if(typeof cell.value=="object"){
                        desc="";
                        cell.value.richText.forEach(element => {
                            desc+=element.text;
                        });
                      }else{
                        desc=cell.value;
                      }     
                      console.log(desc,">>>>>>>>>>>>>>>");
                 }
                 if(colNumber==5){
                    var buildRow=getRowData();
                    buildRow.rpttypecode="ITQ";
                    buildRow.timetypecode="Q";
                    buildRow.valstr=cell.value;
                    buildRow.desc=desc;
                    buildRow.position=rowNumber+"-"+1;
                    insertrows.push(buildRow);
               }
               if(colNumber==8){
                if(typeof cell.value=="object"){
                    desc="";
                    cell.value.richText.forEach(element => {
                        desc+=element.text;
                    });
                  }else{
                    desc=cell.value;
                  }     
                  console.log(desc,">>>>>>>>>>>>>>>");
             }
             if(colNumber==11){
                var buildRow=getRowData();
                buildRow.rpttypecode="ITQ";
                buildRow.timetypecode="Q";
                buildRow.valstr=cell.value;
                buildRow.desc=desc;
                buildRow.position=rowNumber+"-"+2;
                insertrows.push(buildRow);
           }


            });
          
        }

    });
    console.log(JSON.stringify(insertrows));
    //db.models.rpthistory.bulkCreate(insertrows);
})();*/
//ITY
/*(async () => {
    var wb = await readxls("./rpttemp/it/Y/ITY.xlsx");
    var sheet = wb.getWorksheet(1);
    var insertrows = [];
    sheet.eachRow({ includeEmpty: true }, function (row, rowNumber) {
        if (rowNumber >= 3 && rowNumber <= 38) {
            row.eachCell({ includeEmpty: true }, function (cell, colNumber) {
                if (colNumber == 3) {
                    if (typeof cell.value == "object") {
                        desc = "";
                        cell.value.richText.forEach(element => {
                            desc += element.text;
                        });
                    } else {
                        desc = cell.value;
                    }
                    console.log(desc, ">>>>>>>>>>>>>>>");
                }
                if (colNumber == 4) {
                    var buildRow = getRowData();
                    buildRow.rpttypecode = "ITY";
                    buildRow.timetypecode = "Q";
                    buildRow.valstr = cell.value;
                    buildRow.desc = desc + "/金额";
                    buildRow.position = rowNumber + "-" + 1;
                    insertrows.push(buildRow);
                }
            });
        }


    });
    console.log(JSON.stringify(insertrows));
})();*/

//ITY_ADV
/*(async () => {
    var wb = await readxls("./rpttemp/it/Y/ITY_ADV.xlsx");
    var sheet = wb.getWorksheet(1);
    var insertrows = [];
    sheet.eachRow({ includeEmpty: true }, function (row, rowNumber) {
        if (rowNumber >= 3 && rowNumber <= 16) {
            row.eachCell({ includeEmpty: true }, function (cell, colNumber) {
                if (colNumber == 2) {
                    if (typeof cell.value == "object") {
                        desc = "";
                        cell.value.richText.forEach(element => {
                            desc += element.text;
                        });
                    } else {
                        desc = cell.value;
                    }
                    console.log(desc, ">>>>>>>>>>>>>>>");
                }
                if (colNumber == 3) {
                    var buildRow = getRowData();
                    buildRow.rpttypecode = "ITY";
                    buildRow.timetypecode = "Q";
                    buildRow.valstr = cell.value;
                    buildRow.desc = desc + "/金额";
                    buildRow.position = rowNumber + "-" + 1;
                    insertrows.push(buildRow);
                }
            });
        }
    });
    console.log(JSON.stringify(insertrows));
})();*/


//ITY_COST
/*(async () => {
    var wb = await readxls("./rpttemp/it/Y/ITY_COST.xlsx");
    var sheet = wb.getWorksheet(1);
    var insertrows = [];
    sheet.eachRow({ includeEmpty: true }, function (row, rowNumber) {
        if (rowNumber >= 3 && rowNumber <= 28) {
            row.eachCell({ includeEmpty: true }, function (cell, colNumber) {
                if (colNumber == 2) {
                    if (typeof cell.value == "object") {
                        desc = "";
                        cell.value.richText.forEach(element => {
                            desc += element.text;
                        });
                    } else {
                        desc = cell.value;
                    }
                    console.log(desc, ">>>>>>>>>>>>>>>");
                }
                if (colNumber == 3) {
                    var buildRow = getRowData();
                    buildRow.rpttypecode = "ITY_COST";
                    buildRow.timetypecode = "Q";
                    buildRow.valstr = cell.value;
                    buildRow.desc = desc + "/金额";
                    buildRow.position = rowNumber + "-" + 1;
                    insertrows.push(buildRow);
                }
            });
        }
    });
    console.log(JSON.stringify(insertrows));
})();*/


//ITY_DISCOUNT_ADJUST
/*(async () => {
    var wb = await readxls("./rpttemp/it/Y/ITY_DISCOUNT_ADJUST.xlsx");
    var sheet = wb.getWorksheet(1);
    var insertrows = [];
    sheet.eachRow({ includeEmpty: true }, function (row, rowNumber) {
        if (rowNumber >= 5 && rowNumber <= 41) {
            row.eachCell({ includeEmpty: true }, function (cell, colNumber) {
                if (colNumber == 3) {
                    if (typeof cell.value == "object") {
                        desc="";
                        cell.value.richText.forEach(element => {
                            desc += element.text;
                        });
                    } else {
                        desc = cell.value;
                    }
                    cachetmp=desc;
                    console.log(desc, ">>>>>>>>>>>>>>>");
                    
                }
                if (colNumber == 4) {
                    desc=cachetmp+"/资产原值";
                    console.log(desc,">>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>");
                }
                if (colNumber == 5) {
                    desc=cachetmp+"/本年折旧、摊销额";
                }
                if (colNumber == 6) {
                    desc+="/累计折旧、摊销额";
                }
                if (colNumber == 7) {
                    desc=cachetmp+"/资产计税基础";
                }
                if (colNumber == 8) {
                    desc=cachetmp+"/税收折旧、摊销额";
                }
                if (colNumber == 9) {
                    desc=cachetmp+"/享受加速折旧政策的资产按税收一般规定计算的折旧、摊销额";
                }
                if (colNumber == 10) {
                    desc=cachetmp+"/加速折旧、摊销统计额";
                }
                if (colNumber == 11) {
                    desc=cachetmp+"/ 累计折旧、摊销额";
                }
                if (colNumber == 12) {
                    desc=cachetmp+"/ 纳税调整金额";
                }
                if (colNumber >=4 && colNumber <=12) {
                    var colpos=colNumber-3;
                    var buildRow = getRowData();
                    buildRow.rpttypecode = "ITY_COST";
                    buildRow.timetypecode = "Q";
                    buildRow.valstr = cell.value;
                    buildRow.desc = desc;
                    buildRow.position = rowNumber + "-" + colpos;
                    insertrows.push(buildRow);
                }
            });
        }
    });
    console.log(JSON.stringify(insertrows));
})();*/
//ITY_FILL_LOST
/*(async () => {
    var wb = await readxls("./rpttemp/it/Y/ITY_FILL_LOST.xlsx");
    var sheet = wb.getWorksheet(1);
    var insertrows = [];
    sheet.eachRow({ includeEmpty: true }, function (row, rowNumber) {
        if (rowNumber >= 6 && rowNumber <= 17) {
            row.eachCell({ includeEmpty: true }, function (cell, colNumber) {
                    if (colNumber == 2) {
                        if (typeof cell.value == "object") {
                            desc="";
                            cell.value.richText.forEach(element => {
                                desc += element.text;
                            });
                        } else {
                            desc = cell.value;
                        }
                        cachetmp=desc;
                        console.log(desc, ">>>>>>>>>>>>>>>");
                        
                    }
                    if (colNumber == 3) {
                        desc=cachetmp+"/年度";
                        console.log(desc,">>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>");
                    }
                    if (colNumber == 4) {
                        desc=cachetmp+"/当年境内所得额";
                    }
                    if (colNumber == 5) {
                        desc+=cachetmp+"/分立转出的亏损额";
                    }
                    if (colNumber == 6) {
                        desc=cachetmp+"/可弥补年限5年";
                    }
                    if (colNumber == 7) {
                        desc=cachetmp+"/可弥补年限10年";
                    }
                    if (colNumber == 8) {
                        desc=cachetmp+"/弥补亏损企业类型";
                    }
                    if (colNumber == 9) {
                        desc=cachetmp+"/当年亏损额";
                    }
                    if (colNumber == 10) {
                        desc=cachetmp+"/ 当年待弥补的亏损额";
                    }
                    if (colNumber == 11) {
                        desc=cachetmp+"/使用境内所得弥补";
                    }
                    if (colNumber == 12) {
                        desc=cachetmp+"/使用境外所得弥补";
                    }
                    if (colNumber == 13) {
                        desc=cachetmp+"/当年可结转以后年度弥补的亏损额";
                    }
                    if (colNumber >=3 && colNumber <=13) {
                        var colpos=colNumber-2;
                        var buildRow = getRowData();
                        buildRow.rpttypecode = "ITY_FILL_LOST";
                        buildRow.timetypecode = "Q";
                        buildRow.valstr = cell.value;
                        buildRow.desc = desc;
                        buildRow.position = rowNumber + "-" + colpos;
                        insertrows.push(buildRow);
                    }
            });
        }
    });
    console.log(JSON.stringify(insertrows));
})();*/

//ITY_INCOME_DESC
/*(async () => {
    var wb = await readxls("./rpttemp/it/Y/ITY_INCOME_DESC.xlsx");
    var sheet = wb.getWorksheet(1);
    var insertrows = [];
    sheet.eachRow({ includeEmpty: true }, function (row, rowNumber) {
        if (rowNumber >= 3 && rowNumber <= 28) {
            row.eachCell({ includeEmpty: true }, function (cell, colNumber) {
                    if (colNumber == 2) {
                        if (typeof cell.value == "object") {
                            desc="";
                            cell.value.richText.forEach(element => {
                                desc += element.text;
                            });
                        } else {
                            desc = cell.value;
                        }
                        cachetmp=desc;
                        console.log(desc, ">>>>>>>>>>>>>>>");
                        
                    }
                    if (colNumber ==3 ) {
                        var buildRow = getRowData();
                        buildRow.rpttypecode = "ITY_INCOME_DESC";
                        buildRow.timetypecode = "Q";
                        buildRow.valstr = cell.value;
                        buildRow.desc = desc+"/金额";
                        buildRow.position = rowNumber + "-" + 1;
                        insertrows.push(buildRow);
                    }
            });
        }
    });
    console.log(JSON.stringify(insertrows));
})();*/

//ITY_PERIOD
(async () => {
    var wb = await readxls("./rpttemp/it/Y/ITY_PERIOD.xlsx");
    var sheet = wb.getWorksheet(1);
    var insertrows = [];
    sheet.eachRow({ includeEmpty: true }, function (row, rowNumber) {
        if (rowNumber >= 5 && rowNumber <= 30) {
            row.eachCell({ includeEmpty: true }, function (cell, colNumber) {
                    if (colNumber == 2) {
                        if (typeof cell.value == "object") {
                            desc="";
                            cell.value.richText.forEach(element => {
                                desc += element.text;
                            });
                        } else {
                            desc = cell.value;
                        }
                        cachetmp=desc;
                        console.log(desc, ">>>>>>>>>>>>>>>");
                        
                    }
                    if (colNumber == 3) {
                        desc=cachetmp+"/销售费用";
                        console.log(desc,">>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>");
                    }
                    if (colNumber == 4) {
                        desc=cachetmp+"/其中：境外支付";
                    }
                    if (colNumber == 5) {
                        desc+=cachetmp+"/管理费用";
                    }
                    if (colNumber == 6) {
                        desc=cachetmp+"/其中：境外支付";
                    }
                    if (colNumber == 7) {
                        desc=cachetmp+"/财务费用";
                    }
                    if (colNumber == 8) {
                        desc=cachetmp+"/其中：境外支付";
                    }
                    
                    if (colNumber >=3 && colNumber <=8) {
                        var colpos=colNumber-2;
                        var buildRow = getRowData();
                        buildRow.rpttypecode = "ITY_PERIOD";
                        buildRow.timetypecode = "Q";
                        buildRow.valstr = cell.value;
                        buildRow.desc = desc;
                        buildRow.position = rowNumber + "-" + colpos;
                        insertrows.push(buildRow);
                    }
            });
        }
    });
    console.log(JSON.stringify(insertrows));
})();





// var twice = {
// 	apply:function(target, ctx, args) {
//         console.log("xxxxxxxxxxxxxxxxxxxxxxxxxxx");
//         console.log(target);
//         console.log("ctx",ctx,"args",args);
//         console.log(...arguments);
// 		return Reflect.apply(...arguments) * 2;
//     }
// };
// class s{
//     async apply(target, ctx, args){
//         console.log("xxxxxxxxxxxxxxxxxxxxxxxxxxx");
//         var rtn=await Reflect.apply(...arguments) * 2;
//         console.log(arguments);
//         return rtn
//     }
// }
// class obj extends s{
//     async sum(left, right){
//         return left + right;
//     }
// }
// // var objnew=new obj();
// // var proxy = new Proxy(objnew.sum, objnew);
// // var y=proxy(5, 6) // 22
// // console.log(y.then(n=>console.log(n)));

// function x(m,...items){
//   console.log(m);
//   console.log(...items);
//   console.log(items);
// }
// x(2,3,4,5);

// class A{
// 	a(params) {
// 		console.log(params);
// 	}
// 	b(params) {
// 		console.log(params);
// 	}
// }
// console.log(A.toString());
// var reg1 = /([a-z])*\(.*\)/g;
// var m=A.toString().match(reg1);
// console.log(m);
// var WXPay = require('wx-pay');
// var wxpay = WXPay({
// 	appid: 'wx6f3ebe44defe336a',
// 	mch_id: '1232813602',
// 	partner_key: 'sinotone2014sinotone2014sinotone', //微信商户平台API密钥
// 	//pfx: fs.readFileSync('./wxpay_cert.p12'), //微信商户平台证书
//   //pfx: "sinotone2014sinotone2014sinotone"
// });
// // var out_trade_no='20160203'+Math.random().toString().substr(2, 10);
// // wxpay.createUnifiedOrder({
// // 	body: '充值兑换宝币',
// // 	out_trade_no: out_trade_no,
// // 	total_fee: 1,
// // 	spbill_create_ip: '192.168.2.210',
// // 	notify_url: 'http://www.gongsibao.com',
// // 	trade_type: 'NATIVE',
// // 	product_id: '1234567890'
// // }, function(err, result){
// // 	console.log(result);
// // 	//查询订单
// // 	//通过微信订单号查
// // 	wxpay.queryOrder({ out_trade_no:out_trade_no}, function(err, order){
// // 		console.log(order);
// // 	});
// //
// // });

// async function queryWxOrder(idkey){
// 	var p=new Promise((resv,rej)=>{
// 		 wxpay.queryOrder({ out_trade_no:idkey}, function(err, order){
// 			if(err){
// 				return rej(err);
// 			}else{
// 				return resv(order);
// 			}
// 		});
// 	});
// 	return p;
// }

// async function testQuery(){
// 	try{
// 		var result = await queryWxOrder("d942bc2ccd784034af60c2d92079c897");
// 		console.log(result);
// 	}catch(e){
// 		console.log(e);
// 		console.log("error.................");
// 	}

// }
// testQuery();








// 二、框架
// 三、实战





// async function getCacheByKey(k){
//   return k;
// }
// async function buildData(data){
//   console.log(data);
//   console.log("xxxxxxxxxxxxxxxx");
//   console.log(data.length);
//   var ds=[]
//   for(var i=0;i<data.length;i++){
//     console.log(i);
//     var source={name:""};
//     var count=await getCacheByKey(data[i].name);
//     source.name=data[i].name;
//     source.value=count;
//     ds.push(source);
//   }
//   return  ds;
// }
// async function out(){
//   var data=[
//     {"name":"jy"},
//     {"name":"tom"}
//   ];
//   var ds=await buildData(data);
//   console.log(ds);
// }
//
// out();

// async function ok1(){
//   var p=new Promise(function(res,rej){
//     setTimeout(()=>{
//       return res("ok1");
//     },2000);
//   });
//   return p;
// }
// async function ok2(){
//   return "ok2";
// }
// async function ok3(){
//   var k1=await ok1();
//   console.log(k1);
//   var k2=await ok2();
//   console.log(k2);
// }
// ok3();
// const uuidv4 = require('uuid/v4');
// var u=uuidv4()
// console.log(u.replace(/\-/g,""))
// async function testAsync1(){
//   return 5;
// }
//
// async function testAsync2(){
//   return 5;
// }
// async function testAsync3(){
//   var x=  await testAsync1();
//   var y=  await testAsync2();
//   return 5;
// }

// var x=testAsync().then(function(r){
//   console.log(r);
//   return 6;
// }).then(function(r){
//   console.log(r);
//   return 7;
// });
// x.then(function(r){
//   console.log(r);
// }).catch(function(err){
//
// });
// function getArgs(func){
// 		//匹配函数括号里的参数
// 		var args=func.toString().match(/[async|function]\s.*?\(([^)]*)\)/)[1];
// 		//分解参数成数组
// 		return args.split(",").map(function (arg){
// 			//去空格和内联注释
// 			return arg.replace(/\/\*.*\*\//,"").trim();
// 		}).filter(function(args) {
// 			//确保没有undefineds
// 			return args;
// 		});
// }
// console.log(convertoss["testMethod"].toString());
// var inObj={a:"hello",b:"ok"}
// var p=convertoss["testMethod"].apply(convertoss,["hello","kkkk"]);
// var args=getArgs(convertoss["testMethod"])
// console.log(args);
//var p=convertoss["testMethod"].call(convertoss,["hello"]);
//var p=Reflect.apply(,convertoss,"hello");
// p.then(function(r){
// 	console.log(r);
// });
// convertoss.convert2pdf(key).then(function(result){
// 	console.log(result);
// }).catch(function(e){
// 	console.log(e);
// });


// var routes=[
//     {
//       path:'/',components:{
//          default:componentFactory("products"),
//         // shows:demo
//       }
//     },
//     {
//       path:'/products/:id/detail',components:{
//          default:componentFactory("detail"),
//          //shows:demo
//       }
//     },
//     {
//       path:'/platform/apps',components:{
//          default:componentFactory("apps"),
//          //shows:demo
//       }
//     },
//     {
//       path:'/platform/users',components:{
//          default:componentFactory("users"),
//          //shows:demo
//       }
//     },
//     {
//       path:'/platform/op/oplogs',components:{
//          default:componentFactory("oplogs"),
//          //shows:demo
//       }
//     },
// ]


// 40d64e586551405c9bcafab87266bb04
// f99d413b767f09b5dff0b3610366bb46


// 40d64e586551405c9bcafab87266bc04
// f99d413b767f09b5dff0b3610366cc46
// 115.28.188.38:8888

