|
|
@@ -29,7 +29,10 @@ module.exports={
|
|
|
checkFiles:checkFiles,
|
|
|
copyForSectionError: copyForSectionError,
|
|
|
exportProject:exportProject,
|
|
|
- importProject:importProject
|
|
|
+ importProject:importProject,
|
|
|
+ uploadToken:uploadToken,
|
|
|
+ downLoadProjectFile:downLoadProjectFile,
|
|
|
+ importProcessChecking:importProcessChecking
|
|
|
};
|
|
|
|
|
|
|
|
|
@@ -54,6 +57,7 @@ let unitPriceFileModel = mongoose.model("unit_price_file");
|
|
|
let mixRatioModel = mongoose.model("mix_ratio");
|
|
|
let freightModel = mongoose.model("freight_calc");
|
|
|
let originalModel = mongoose.model("original_calc");
|
|
|
+let comElectrovalenceModel = mongoose.model("com_electrovalence");
|
|
|
let unitPriceModel = mongoose.model("unit_price");
|
|
|
let installationFeeModel = mongoose.model("installation_fee");
|
|
|
let rationGLJModel = mongoose.model('ration_glj');
|
|
|
@@ -65,6 +69,8 @@ let userModel = mongoose.model('user');
|
|
|
let compleGljSectionModel = mongoose.model('complementary_glj_section');
|
|
|
let compleGljSectionTModel = mongoose.model('complementary_glj_section_templates');
|
|
|
let progressiveModel = mongoose.model('std_progressive_lib');
|
|
|
+let importLogsModel = mongoose.model("import_logs");
|
|
|
+
|
|
|
|
|
|
let featureLibModel = mongoose.model("std_project_feature_lib");
|
|
|
let scMathUtil = require('../../../public/scMathUtil').getUtil();
|
|
|
@@ -77,6 +83,20 @@ import billsFlags from '../../common/const/bills_fixed';
|
|
|
const notDeleted = [{deleteInfo: null}, {'deleteInfo.deleted': false}];
|
|
|
let cipher = require('../../../public/cipher');
|
|
|
const compilationModel = mongoose.model('compilation');
|
|
|
+let qiniu = require("qiniu");
|
|
|
+let fs = require("fs");
|
|
|
+let path = require("path");
|
|
|
+let request = require("request");
|
|
|
+
|
|
|
+let qiniu_config = {
|
|
|
+ "AccessKey": "_gR1ed4vi1vT2G2YITGSf4_H0fJu_nRS9Tzk3T4z",
|
|
|
+ "SecretKey": "ty4zd0FHqgEDaiVzSLC8DfHlai99aS7bspLkw6s6",
|
|
|
+ "Bucket": "yun-update",
|
|
|
+ "Domain": "http://serverupdate.smartcost.com.cn"
|
|
|
+};
|
|
|
+let mac = new qiniu.auth.digest.Mac(qiniu_config.AccessKey, qiniu_config.SecretKey);
|
|
|
+
|
|
|
+
|
|
|
|
|
|
|
|
|
//拷贝例题项目
|
|
|
@@ -383,6 +403,7 @@ async function copyUnitPriceFile(newProjectID,rootProjectID,userID,originaluUnit
|
|
|
copySubList(originaluUnitPriceFileID,unitPriceFileID,mixRatioModel),
|
|
|
copySubList(originaluUnitPriceFileID,unitPriceFileID,freightModel,true),
|
|
|
copySubList(originaluUnitPriceFileID,unitPriceFileID,originalModel,true),
|
|
|
+ copySubList(originaluUnitPriceFileID,unitPriceFileID,comElectrovalenceModel,true),
|
|
|
copySubList(originaluUnitPriceFileID,unitPriceFileID,unitPriceModel)
|
|
|
];
|
|
|
|
|
|
@@ -1074,6 +1095,7 @@ async function exportUnitFiles(rootProjectID){
|
|
|
tem.mixRatios = await mixRatioModel.find({unit_price_file_id:f.id});
|
|
|
tem.freights = await freightModel.find({unit_price_file_id:f.id});
|
|
|
tem.originals = await originalModel.find({unit_price_file_id:f.id});
|
|
|
+ tem.com_electrovalence = await comElectrovalenceModel.find({unit_price_file_id:f.id});
|
|
|
unitFiles.push(tem);
|
|
|
}
|
|
|
return unitFiles;
|
|
|
@@ -1112,8 +1134,72 @@ async function exportTenderData(data){
|
|
|
return cipher.aesEncrypt(JSON.stringify(result));
|
|
|
}
|
|
|
|
|
|
+async function downLoadProjectFile(info) {
|
|
|
+ let result = {error:0};
|
|
|
+ let bucketManager2 = new qiniu.rs.BucketManager(mac, null);
|
|
|
+ let publicBucketDomain = qiniu_config.Domain;// "http://serverupdate.smartcost.com.cn";//这里不支持https
|
|
|
+ let deadline = parseInt(Date.now() / 1000) + 3600; // 1小时过期
|
|
|
+ let privateDownloadUrl = bucketManager2.privateDownloadUrl(publicBucketDomain, info.key, deadline);
|
|
|
+
|
|
|
+ let data = {
|
|
|
+ key:info.key,
|
|
|
+ userID:info.session.sessionUser.id,
|
|
|
+ status:"start",
|
|
|
+ create_time:+new Date()
|
|
|
+ };
|
|
|
+ await importLogsModel.create(data);
|
|
|
+ doDownLoadAndImport(privateDownloadUrl,info);
|
|
|
+ return result;
|
|
|
+}
|
|
|
+
|
|
|
+
|
|
|
+async function doDownLoadAndImport(privateDownloadUrl,info) {
|
|
|
+ let stream = fs.createWriteStream(path.join(__dirname, "../../../tmp/"+info.key));//
|
|
|
+ request(privateDownloadUrl).pipe(stream).on("close", async function (err) {
|
|
|
+ console.log("文件[" + info.key + "]下载完毕");
|
|
|
+ let doc = {status:"finish"};
|
|
|
+ try {
|
|
|
+ let data = fs.readFileSync(stream.path,'utf-8');
|
|
|
+ let result = await importProject(data,{session:info.session},info.updateData);
|
|
|
+ if(result.error == 1){
|
|
|
+ doc.errorMsg = result.msg;
|
|
|
+ doc.status = "error";
|
|
|
+ }
|
|
|
+ }catch (error){
|
|
|
+ console.log(error);
|
|
|
+ doc.errorMsg = "导入失败,请检查文件!";
|
|
|
+ doc.status = "error";
|
|
|
+ }finally {
|
|
|
+ await importLogsModel.update({key:info.key},doc);
|
|
|
+ fs.unlinkSync(stream.path);
|
|
|
+ }
|
|
|
+ });
|
|
|
+}
|
|
|
+
|
|
|
+async function importProcessChecking(data){
|
|
|
+ let result = {error:0};
|
|
|
+ let log = await importLogsModel.findOne({key:data.key});
|
|
|
+ if(log){
|
|
|
+ if(log.status == "finish"){
|
|
|
+ result.status = "complete";
|
|
|
+ await importLogsModel.remove({key:data.key});
|
|
|
+ }else if(log.status == "start"){
|
|
|
+ result.status = "processing";
|
|
|
+ }else if(log.status == "error"){
|
|
|
+ result.error = 1;
|
|
|
+ result.msg = log.errorMsg;
|
|
|
+ await importLogsModel.remove({key:data.key});
|
|
|
+ }
|
|
|
+ }else {
|
|
|
+ result.error = 1;
|
|
|
+ result.msg = `导入过程中发生错误!`;
|
|
|
+ }
|
|
|
+ return result;
|
|
|
|
|
|
-async function importProject(data,req,fields) {
|
|
|
+}
|
|
|
+
|
|
|
+
|
|
|
+async function importProject(data,req,updateData) {
|
|
|
let result = {error:0};
|
|
|
let stringArr = data.split("|----|");
|
|
|
let datas = [];
|
|
|
@@ -1132,7 +1218,7 @@ async function importProject(data,req,fields) {
|
|
|
result.error = 1;
|
|
|
result.msg = `导入失败:您要导入的文件是由“${fileCompilationName}”导出,当前软件是“${curCompilationName}”,请选择正确的编制办法再进行操作!`;
|
|
|
}else {
|
|
|
- let [projectIDMap,labourCoeFileIDMap,calcProgramFileIDMap] = await handleMainProjectDatas(mainData,JSON.parse(fields.updateData[0]),req.session.sessionUser.id);
|
|
|
+ let [projectIDMap,labourCoeFileIDMap,calcProgramFileIDMap] = await handleMainProjectDatas(mainData,updateData,req.session.sessionUser.id);
|
|
|
if(datas.length > 1 ){
|
|
|
for(let i = 1;i<datas.length;i++){
|
|
|
await handleEachProject(datas[i],projectIDMap,labourCoeFileIDMap,calcProgramFileIDMap)
|
|
|
@@ -1306,9 +1392,9 @@ async function handleMainProjectDatas(mainData,updateData,userID) {
|
|
|
|
|
|
async function importUnitPriceFiles(mainData,projectIDMap,unitPriceFileIDMap,userID) {
|
|
|
if(!mainData.files.unitFiles) return;
|
|
|
- let unitFiles = [],unitPrices =[],mixRatios=[],freights=[],originals=[];
|
|
|
+ let unitFiles = [],unitPrices =[],mixRatios=[],freights=[],originals=[],com_electrovalences=[];
|
|
|
for(let f of mainData.files.unitFiles){
|
|
|
- let file = f.unitFile,prices = f.unitPrices,mixs = f.mixRatios,fres = f.freights,ors = f.originals;
|
|
|
+ let file = f.unitFile,prices = f.unitPrices,mixs = f.mixRatios,fres = f.freights,ors = f.originals,ec=f.com_electrovalence;
|
|
|
//生成单价文件
|
|
|
delete file._id;
|
|
|
file.id = unitPriceFileIDMap[file.id]?unitPriceFileIDMap[file.id]:await getCounterID("unit_price_file");
|
|
|
@@ -1322,12 +1408,14 @@ async function importUnitPriceFiles(mainData,projectIDMap,unitPriceFileIDMap,use
|
|
|
if(mixs) await setSubList(mixs,mixRatios,file.id,mixRatioModel);
|
|
|
if(fres) await setSubList(fres,freights,file.id,freightModel,true);
|
|
|
if(ors) await setSubList(ors,originals,file.id,originalModel,true);
|
|
|
+ if(ec) await setSubList(ec,com_electrovalences,file.id,comElectrovalenceModel,true);
|
|
|
}
|
|
|
if(unitFiles.length > 0) await insertMany(unitFiles,unitPriceFileModel);
|
|
|
if(unitPrices.length > 0) await insertMany(unitPrices,unitPriceModel);
|
|
|
if(mixRatios.length > 0) await insertMany(mixRatios,mixRatioModel);
|
|
|
if(freights.length > 0) await insertMany(freights,freightModel);
|
|
|
if(originals.length > 0) await insertMany(originals,originalModel);
|
|
|
+ if(com_electrovalences.length > 0) await insertMany(com_electrovalences,comElectrovalenceModel);
|
|
|
|
|
|
async function setSubList(oList,nList,fileID,model,UUID=false) {
|
|
|
for(let o of oList){
|
|
|
@@ -1429,3 +1517,19 @@ async function checkFiles(projects) {
|
|
|
}
|
|
|
await Promise.all(task);
|
|
|
}
|
|
|
+
|
|
|
+function uploadToken() {
|
|
|
+ let options = {
|
|
|
+ scope: qiniu_config.Bucket,
|
|
|
+ deleteAfterDays: 1,
|
|
|
+ returnBody:
|
|
|
+ '{"key":"$(key)","hash":"$(etag)","fsize":$(fsize),"bucket":"$(bucket)","name":"$(x:name)"}'
|
|
|
+ };
|
|
|
+ let putPolicy = new qiniu.rs.PutPolicy(options);
|
|
|
+ let token = putPolicy.uploadToken(mac);
|
|
|
+ let result = {
|
|
|
+ uptoken: token,
|
|
|
+ domain: qiniu_config.Domain
|
|
|
+ }
|
|
|
+ return result
|
|
|
+}
|