|
@@ -540,24 +540,37 @@ class GljDao extends OprDao{
|
|
|
let updateBulk = [];
|
|
let updateBulk = [];
|
|
|
//避免重复
|
|
//避免重复
|
|
|
let updateCodes = [];
|
|
let updateCodes = [];
|
|
|
|
|
+ //库中存在的人材机
|
|
|
|
|
+ let dateA = Date.now();
|
|
|
|
|
+ let existGljs = await gljModel.find({repositoryId: gljLibId}, '-_id code ID');
|
|
|
|
|
+ let existMapping = {};
|
|
|
|
|
+ for (let glj of existGljs) {
|
|
|
|
|
+ existMapping[glj.code] = glj;
|
|
|
|
|
+ }
|
|
|
for(let row = 0; row < sheetData.length; row++){
|
|
for(let row = 0; row < sheetData.length; row++){
|
|
|
if(row === 0){
|
|
if(row === 0){
|
|
|
continue;
|
|
continue;
|
|
|
}
|
|
}
|
|
|
- let gljCode = sheetData[row][colMapping.code];
|
|
|
|
|
- if(gljCode && gljCode !== '' && !updateCodes.includes(gljCode)){
|
|
|
|
|
|
|
+ let gljCode = sheetData[row][colMapping.code],
|
|
|
|
|
+ existGlj = existMapping[gljCode];
|
|
|
|
|
+ //更新多单价、不覆盖priceProperty字段,覆盖priceProperty下的子字段'priceProperty.x'
|
|
|
|
|
+ if(gljCode && gljCode !== '' && !updateCodes.includes(gljCode) && existGlj){
|
|
|
if(priceProperties.length > 0){
|
|
if(priceProperties.length > 0){
|
|
|
- let priceProperty = {};
|
|
|
|
|
for(let priceProp of priceProperties){
|
|
for(let priceProp of priceProperties){
|
|
|
let dataCode = priceProp.price.dataCode;
|
|
let dataCode = priceProp.price.dataCode;
|
|
|
let priceCellData = sheetData[row][colMapping[dataCode]];
|
|
let priceCellData = sheetData[row][colMapping[dataCode]];
|
|
|
- priceProperty[dataCode] = colMapping[dataCode] && priceCellData && !isNaN(priceCellData) ?
|
|
|
|
|
|
|
+ //Excel中没有这个单价则跳过
|
|
|
|
|
+ if (!colMapping[dataCode]) {
|
|
|
|
|
+ continue;
|
|
|
|
|
+ }
|
|
|
|
|
+ let updateSet = {};
|
|
|
|
|
+ updateSet['priceProperty.' + dataCode] = priceCellData && !isNaN(priceCellData) ?
|
|
|
scMathUtil.roundTo(parseFloat(priceCellData), -2) : 0;
|
|
scMathUtil.roundTo(parseFloat(priceCellData), -2) : 0;
|
|
|
|
|
+ updateBulk.push({
|
|
|
|
|
+ updateOne: {filter: {ID: existGlj.ID}, update: {$set: updateSet}}
|
|
|
|
|
+ });
|
|
|
}
|
|
}
|
|
|
updateCodes.push(gljCode);
|
|
updateCodes.push(gljCode);
|
|
|
- updateBulk.push({
|
|
|
|
|
- updateOne: {filter: {repositoryId: gljLibId, code: gljCode}, update: {$set: {priceProperty: priceProperty}}}
|
|
|
|
|
- });
|
|
|
|
|
}
|
|
}
|
|
|
else {
|
|
else {
|
|
|
if(colMapping.basePrice){
|
|
if(colMapping.basePrice){
|
|
@@ -566,14 +579,17 @@ class GljDao extends OprDao{
|
|
|
scMathUtil.roundTo(priceCellData, -2) : 0;
|
|
scMathUtil.roundTo(priceCellData, -2) : 0;
|
|
|
updateCodes.push(gljCode);
|
|
updateCodes.push(gljCode);
|
|
|
updateBulk.push({
|
|
updateBulk.push({
|
|
|
- updateOne: {filter: {repositoryId: gljLibId, code: gljCode}, update: {$set: {basePrice: basePrice}}}
|
|
|
|
|
|
|
+ updateOne: {filter: {ID: existGlj.ID}, update: {$set: {basePrice: basePrice}}}
|
|
|
});
|
|
});
|
|
|
}
|
|
}
|
|
|
}
|
|
}
|
|
|
}
|
|
}
|
|
|
}
|
|
}
|
|
|
if(updateBulk.length > 0){
|
|
if(updateBulk.length > 0){
|
|
|
- await gljModel.bulkWrite(updateBulk);
|
|
|
|
|
|
|
+ while (updateBulk.length > 0) {
|
|
|
|
|
+ let sliceBulk = updateBulk.splice(0, 1000);
|
|
|
|
|
+ await gljModel.bulkWrite(sliceBulk);
|
|
|
|
|
+ }
|
|
|
}
|
|
}
|
|
|
|
|
|
|
|
}
|
|
}
|