/**
 * Created by Tony on 2021/10/6.
 */

let fs = require('fs');

// let data = fs.readFileSync('D:/GitHome/ConstructionOperation/tmp/testGLJData.js');

// let mixedData = fs.readFileSync('D:/GitHome/YangHuOperation/tmp/testDataResult_广西公路日常养护预算指标(2021).js');
let mixedData = fs.readFileSync('D:/GitHome/YangHuOperation/tmp/testDataResult_广西公路养护预算定额(2021).js');
let data = JSON.parse(mixedData);
let gljItemArr = data.gljList;

//----------------------------------------

// let gljItemArr = JSON.parse(data);

// console.log(gljItemArr);

let newData = [];
let firstStr = 'ID\tCode\tName\tSpecs\tUnit\tBasePrice\tMain\tNew\tType\tDetailType\tShortName\tName2\tUnit2\tSortParam\tCalculateType\tUUID\t字段1\t字段2';
newData.push(firstStr);

for (let item of gljItemArr) {

    let str = `${item.ID}\t${item.code}\t${item.name}\t${item.specs}\t${item.unit}\t${(item.basePrice !== undefined)?item.basePrice:0}\t0\t0\t${item.gljType}\t${item.gljClass}\t${item.shortName}\t\t\t\t\t\t\t\t`;

    newData.push(str);
}

let ttlStr = newData.join('\n');

let regExp = new RegExp('"', "gm");
ttlStr = ttlStr.replace(regExp, '');
let regExp1 = new RegExp('null', "gm");
ttlStr = ttlStr.replace(regExp1, '');

fs.writeFile(`D:/GitHome/YangHuOperation/tmp/工料机临时Data文件_${(new Date()).getTime()}.txt`, ttlStr, { 'flag': 'a', 'encoding': 'utf-8' }, function(err){
    if(err) throw err;
});


