saveMeans({job:job,step:pcs_step,chklist:oChecklistName}) function mkPath(path, list) { if (list.length) { var newPath = path + '/' + list.shift() if (!fs.dirExists(newPath)) {fs.mkdir(newPath)} return mkPath(newPath, list) } else { return path } } function saveMeans(props){ var job = props.job var custstep = props.step var chklist = props.chklist var nact = props.nact var jobpath = GEN.getJobPath({job: job}) var filter = props.filter var afterPath = mkPath(jobpath, ["user", "opencam", "steps"]) var steps; if (custstep) { steps = [custstep] } else { steps = GEN.getStepList({job: job}) } if(!steps || steps.length==0){ return } steps.forEach(function (step) { var chkPath = mkPath(afterPath, [step, "chk"]) var chks if (chklist) {chks = [chklist]}else { chks = GEN.getChecklist({job: job,step: step}) } if(chks && chks.length){ chks.forEach(function (item, i) { var afterChkPath = mkPath(chkPath, [item]) var hdr = "{\n\ \"title\": \"" + item + "\",\n\ \"sequence\": " + (i + 1) + "\n\ }" fs.writeFile(afterChkPath + "/hdr", _.toString(hdr)) var nacts = [] if (nact) { nacts = [nact] } else { var nactCount = GEN.getChklistActCount({job:job,step:step,chklist:item}) for (var i = 0; i < nactCount; i++) { nacts.push(i+1) } } if(nacts.length > 0){ var actionPath = mkPath(afterChkPath, ["actions"]) nacts.forEach(function(index){ var titleFile = GEN.INFO({ entity_type: "check", entity_path: job + "/" + step + "/" + item, data_type: "TITLE", options: "action=" + index, parse:'no' }) var title = fs.readFile(titleFile) title = title.split("=")[1].trim() title = title.substring(1, title.length-1) var nackPath = mkPath(actionPath, [index+"-"+title]) fs.writeFile(nackPath + "/hdr", "{\n\ \"title\": \"" + (index + "-" + title) + "\",\n\ \"sequence\": " + index + ",\n\ \"dfm_name\": \"" + title + "\"\n\ }") var displayFile = GEN.INFO({ entity_type: 'check', entity_path: job + "/" + step + "/" + item, data_type: 'MEAS_DISP_ID', options: "action=" + index, parse:'no' }); fs.writeFile(nackPath + "/disp", fs.readFile(displayFile)) var measFile = GEN.INFO({entity_type:'check', entity_path:job+'/'+step+'/'+item, data_type:'MEAS', options:"index+action="+index, parse:'no'}); var means if(filter){ // 处理过滤 var fileArray = [] var file = fs.openFile(measFile,'r'); while(!file.atEnd()) { fileArray.push(file.readLine()) } if(Array.isArray(filter)){ var nowFilter = filter.filter(function(item2){ for (var key in item2) { var value = item2[key] if (!Array.isArray(value)){ item2[key] = [value] } } return item2.step.indexOf(step)>=0 && item2.chk.indexOf(item)>=0 && item2.nact.indexOf(index)>=0 }) if (nowFilter.length > 0){ var nowfilter = nowFilter.map(function(v){return v.filter}).reduce(function(a,b){ b.forEach(function(v2){ if (a.indexOf(v2)<0){ a.push(v2) } }) return a },[]) fileArray = fileArray.filter(function(line){ var flag = false nowfilter.forEach(function(f){ var reg = new RegExp(f, "ig") if (reg.test(line)){ flag = true } }) return flag }) } } else if (typeof filter == "object") { if (filter[step] && filter[step][item] && filter[step][item][String(index)]) { var nowFilter = filter[step][item][String(index)] if (!Array.isArray(nowFilter)){nowFilter = [nowFilter]} fileArray = fileArray.filter(function(line){ var flag = false nowFilter.forEach(function(f){ var reg = new RegExp(f, "ig") if (reg.test(line)){ flag = true } }) return flag }) } } means = fileArray.join("\n") } else { means = fs.readFile(measFile) } fs.writeFile(nackPath + "/meas", means) }) } }) } }) } // 自定义信息 saveCustChk({job:job,custChk:custChk}) function saveCustChk(props){ var job = props.job var chkinfo = props.custChk var path = mkPath(GEN.getJobPath({job: job}), ["user", "opencam", "steps"]) chkinfo.forEach(function(chk){ var ckpath = mkPath(path, [chk.step, "chk","custom_chk"]) // 写入action hdr fs.writeFile(ckpath+"/hdr", "{\n\ \"title\": \"cust_chk\",\n\ \"sequence\": 0\n\ }") var actionPath = mkPath(ckpath, ["actions"]) chk.action.forEach(function(action, i){ var nact = i + 1 var nactPath = mkPath(actionPath, [nact+"-"+action.name]) // nactPath 写入 meas hdr display fs.writeFile(nactPath + "/hdr", "{\n\ \"title\": \"" + (nact + "-" + action.name) + "\",\n\ \"sequence\": " + nact + ",\n\ \"dfm_name\": \"" + action.name + "\"\n\ }") if (Array.isArray(action.meas)){ action.meas = action.meas.map(function(mea, i){ return mea + " " + nact + " R " + String(i + 1) }) action.meas = action.meas.join("\n") } else { action.meas = action.meas + " " + nact + " G " + 1 } if (!/string/ig.test(typeof action.disp) ) { action.disp = action.disp.workLayer + " "+ nact+" "+action.disp.showLayers.join(" ") } fs.writeFile(nactPath + "/disp", action.disp) fs.writeFile(nactPath + "/meas", action.meas) }) }) }