|
@@ -4,7 +4,9 @@
|
|
const mongoose = require('mongoose');
|
|
const mongoose = require('mongoose');
|
|
const gljMapModel = mongoose.model('std_glj_lib_map');
|
|
const gljMapModel = mongoose.model('std_glj_lib_map');
|
|
const gljModel = mongoose.model('std_glj_lib_gljList');
|
|
const gljModel = mongoose.model('std_glj_lib_gljList');
|
|
|
|
+const gljModelBackup = mongoose.model('std_glj_lib_gljList_backup');
|
|
const gljClassModel = mongoose.model('std_glj_lib_gljClass');
|
|
const gljClassModel = mongoose.model('std_glj_lib_gljClass');
|
|
|
|
+const gljClassModelBackup = mongoose.model('std_glj_lib_gljClass_backup');
|
|
const projectGLJModel = mongoose.model('glj_list');
|
|
const projectGLJModel = mongoose.model('glj_list');
|
|
const projectModel = mongoose.model('projects');
|
|
const projectModel = mongoose.model('projects');
|
|
const userModel = mongoose.model('users');
|
|
const userModel = mongoose.model('users');
|
|
@@ -14,13 +16,29 @@ const scMathUtil = require('../../../public/scMathUtil').getUtil();
|
|
const rationMapModel = mongoose.model('std_ration_lib_map');
|
|
const rationMapModel = mongoose.model('std_ration_lib_map');
|
|
const rationModel = mongoose.model('std_ration_lib_ration_items');
|
|
const rationModel = mongoose.model('std_ration_lib_ration_items');
|
|
const complementaryRationModel = mongoose.model('complementary_ration_items');
|
|
const complementaryRationModel = mongoose.model('complementary_ration_items');
|
|
-import {OprDao} from "./gljMapModel";
|
|
|
|
|
|
+import { OprDao } from "./gljMapModel";
|
|
import moment from "moment";
|
|
import moment from "moment";
|
|
import counter from "../../../public/counter/counter";
|
|
import counter from "../../../public/counter/counter";
|
|
import async from "async";
|
|
import async from "async";
|
|
let _ = require("lodash");
|
|
let _ = require("lodash");
|
|
|
|
|
|
-class GljDao extends OprDao{
|
|
|
|
|
|
+class GljDao extends OprDao {
|
|
|
|
+
|
|
|
|
+ // 处理单价,将多单价的第一个价格字段,设置成定额价
|
|
|
|
+ async setBasePrice(libID) {
|
|
|
|
+ const gljs = await gljModel.find({ repositoryId: libID }).lean();
|
|
|
|
+ const bulks = [];
|
|
|
|
+ gljs.forEach(glj => {
|
|
|
|
+ const basePrice = glj.priceProperty && glj.priceProperty.price1 !== undefined && glj.priceProperty.price1 !== null ? glj.priceProperty.price1 : 0;
|
|
|
|
+ bulks.push({ updateOne: { filter: { ID: glj.ID }, update: { $set: { basePrice, priceProperty: {} } } } })
|
|
|
|
+ });
|
|
|
|
+ const chunks = _.chunk(bulks, 1000);
|
|
|
|
+ for (const chunk of chunks) {
|
|
|
|
+ if (chunk.length) {
|
|
|
|
+ await gljModel.bulkWrite(chunk);
|
|
|
|
+ }
|
|
|
|
+ }
|
|
|
|
+ }
|
|
|
|
|
|
async copyLib(sourceLibID, targetLibID) {
|
|
async copyLib(sourceLibID, targetLibID) {
|
|
const task = [
|
|
const task = [
|
|
@@ -33,7 +51,7 @@ class GljDao extends OprDao{
|
|
async copyClassData(sourceLibID, targetLibID) {
|
|
async copyClassData(sourceLibID, targetLibID) {
|
|
const sourceClassData = await gljClassModel.find({ repositoryId: sourceLibID }, '-_id').lean();
|
|
const sourceClassData = await gljClassModel.find({ repositoryId: sourceLibID }, '-_id').lean();
|
|
const insertData = sourceClassData.map(item => ({
|
|
const insertData = sourceClassData.map(item => ({
|
|
- ... item,
|
|
|
|
|
|
+ ...item,
|
|
repositoryId: targetLibID
|
|
repositoryId: targetLibID
|
|
}));
|
|
}));
|
|
if (insertData.length) {
|
|
if (insertData.length) {
|
|
@@ -70,14 +88,14 @@ class GljDao extends OprDao{
|
|
}
|
|
}
|
|
|
|
|
|
async getReference(repositoryId, gljId) {
|
|
async getReference(repositoryId, gljId) {
|
|
- const gljLib = await gljMapModel.findOne({ID: repositoryId});
|
|
|
|
|
|
+ const gljLib = await gljMapModel.findOne({ ID: repositoryId });
|
|
const rationLibIds = gljLib.rationLibs.map(lib => lib.ID);
|
|
const rationLibIds = gljLib.rationLibs.map(lib => lib.ID);
|
|
- const rationLibs = await rationMapModel.find({ID: {$in: rationLibIds}}, '-_id ID dispName');
|
|
|
|
|
|
+ const rationLibs = await rationMapModel.find({ ID: { $in: rationLibIds } }, '-_id ID dispName');
|
|
const rationLibNameMapping = {};
|
|
const rationLibNameMapping = {};
|
|
rationLibs.forEach(item => {
|
|
rationLibs.forEach(item => {
|
|
rationLibNameMapping[item.ID] = item.dispName;
|
|
rationLibNameMapping[item.ID] = item.dispName;
|
|
});
|
|
});
|
|
- const stdRations = await rationModel.find({rationRepId: {$in: rationLibIds}, 'rationGljList.gljId': gljId}, '-_id code rationRepId');
|
|
|
|
|
|
+ const stdRations = await rationModel.find({ rationRepId: { $in: rationLibIds }, 'rationGljList.gljId': gljId }, '-_id code rationRepId');
|
|
const rst = {};
|
|
const rst = {};
|
|
const unknownLib = '未知定额库';
|
|
const unknownLib = '未知定额库';
|
|
const complementaryLib = '补充定额库';
|
|
const complementaryLib = '补充定额库';
|
|
@@ -88,35 +106,35 @@ class GljDao extends OprDao{
|
|
}
|
|
}
|
|
rst[libName].push(ration);
|
|
rst[libName].push(ration);
|
|
});
|
|
});
|
|
- const complementaryRations = await complementaryRationModel.find({'rationGljList.gljId': gljId}, '-_id code');
|
|
|
|
|
|
+ const complementaryRations = await complementaryRationModel.find({ 'rationGljList.gljId': gljId }, '-_id code');
|
|
if (complementaryRations.length) {
|
|
if (complementaryRations.length) {
|
|
rst[complementaryLib] = [];
|
|
rst[complementaryLib] = [];
|
|
}
|
|
}
|
|
- complementaryRations.forEach(ration => rst[complementaryLib].push({code: ration.code}));
|
|
|
|
|
|
+ complementaryRations.forEach(ration => rst[complementaryLib].push({ code: ration.code }));
|
|
return rst;
|
|
return rst;
|
|
}
|
|
}
|
|
|
|
|
|
async getUsedInfo(repositoryId, gljId) {
|
|
async getUsedInfo(repositoryId, gljId) {
|
|
let userMap = {};
|
|
let userMap = {};
|
|
let userIDList = [];
|
|
let userIDList = [];
|
|
- let projectList = await projectGLJModel.find({"glj_id":gljId},'-_id project_id').lean();
|
|
|
|
- if(projectList.length > 0){
|
|
|
|
- let projectUserList = await projectModel.find({'ID':{$in:_.map(projectList,"project_id")}},'-_id ID userID').lean();
|
|
|
|
- for(let p of projectUserList){
|
|
|
|
- if(!userMap[p.userID]){
|
|
|
|
|
|
+ let projectList = await projectGLJModel.find({ "glj_id": gljId }, '-_id project_id').lean();
|
|
|
|
+ if (projectList.length > 0) {
|
|
|
|
+ let projectUserList = await projectModel.find({ 'ID': { $in: _.map(projectList, "project_id") } }, '-_id ID userID').lean();
|
|
|
|
+ for (let p of projectUserList) {
|
|
|
|
+ if (!userMap[p.userID]) {
|
|
userMap[p.userID] = true;
|
|
userMap[p.userID] = true;
|
|
userIDList.push(p.userID);
|
|
userIDList.push(p.userID);
|
|
}
|
|
}
|
|
}
|
|
}
|
|
- let userList = await userModel.find({'_id':{$in:userIDList}},'_id username mobile').lean();
|
|
|
|
- for(let u of userList){
|
|
|
|
|
|
+ let userList = await userModel.find({ '_id': { $in: userIDList } }, '_id username mobile').lean();
|
|
|
|
+ for (let u of userList) {
|
|
userMap[u._id.toString()] = u;
|
|
userMap[u._id.toString()] = u;
|
|
}
|
|
}
|
|
- for(let p of projectUserList){
|
|
|
|
|
|
+ for (let p of projectUserList) {
|
|
p.username = userMap[p.userID].username;
|
|
p.username = userMap[p.userID].username;
|
|
p.mobile = userMap[p.userID].mobile;
|
|
p.mobile = userMap[p.userID].mobile;
|
|
}
|
|
}
|
|
- return projectUserList
|
|
|
|
|
|
+ return projectUserList
|
|
}
|
|
}
|
|
|
|
|
|
|
|
|
|
@@ -125,33 +143,33 @@ class GljDao extends OprDao{
|
|
|
|
|
|
|
|
|
|
async getGljTreeSync(gljLibId) {
|
|
async getGljTreeSync(gljLibId) {
|
|
- return await gljClassModel.find({repositoryId: gljLibId});
|
|
|
|
|
|
+ return await gljClassModel.find({ repositoryId: gljLibId });
|
|
}
|
|
}
|
|
|
|
|
|
- getGljTypes (gljLibId, callback){
|
|
|
|
- gljClassModel.find({"repositoryId": gljLibId, "$or": [{"isDeleted": null}, {"isDeleted": false}, {deleted: false} ]},
|
|
|
|
- '-_id', {lean: true}, function(err,data){
|
|
|
|
- if(err) callback("获取工料机类型错误!",false)
|
|
|
|
- else {
|
|
|
|
- callback(0, data);
|
|
|
|
- }
|
|
|
|
- })
|
|
|
|
|
|
+ getGljTypes(gljLibId, callback) {
|
|
|
|
+ gljClassModel.find({ "repositoryId": gljLibId, "$or": [{ "isDeleted": null }, { "isDeleted": false }, { deleted: false }] },
|
|
|
|
+ '-_id', { lean: true }, function (err, data) {
|
|
|
|
+ if (err) callback("获取工料机类型错误!", false)
|
|
|
|
+ else {
|
|
|
|
+ callback(0, data);
|
|
|
|
+ }
|
|
|
|
+ })
|
|
}
|
|
}
|
|
|
|
|
|
- _exist(data, attr){
|
|
|
|
|
|
+ _exist(data, attr) {
|
|
return data && data[attr] !== 'undefined' && data[attr];
|
|
return data && data[attr] !== 'undefined' && data[attr];
|
|
}
|
|
}
|
|
|
|
|
|
- sortToNumber(datas){
|
|
|
|
- for(let i = 0, len = datas.length; i < len; i++){
|
|
|
|
|
|
+ sortToNumber(datas) {
|
|
|
|
+ for (let i = 0, len = datas.length; i < len; i++) {
|
|
let data = datas[i]._doc;
|
|
let data = datas[i]._doc;
|
|
- if(this._exist(data, 'basePrice')){
|
|
|
|
|
|
+ if (this._exist(data, 'basePrice')) {
|
|
data['basePrice'] = parseFloat(data['basePrice']);
|
|
data['basePrice'] = parseFloat(data['basePrice']);
|
|
}
|
|
}
|
|
- if(this._exist(data, 'component')){
|
|
|
|
- for(let j = 0, jLen = data['component'].length; j < jLen; j++){
|
|
|
|
|
|
+ if (this._exist(data, 'component')) {
|
|
|
|
+ for (let j = 0, jLen = data['component'].length; j < jLen; j++) {
|
|
let comGljObj = data['component'][j]._doc;
|
|
let comGljObj = data['component'][j]._doc;
|
|
- if(this._exist(comGljObj, 'consumeAmt')){
|
|
|
|
|
|
+ if (this._exist(comGljObj, 'consumeAmt')) {
|
|
comGljObj['consumeAmt'] = parseFloat(comGljObj['consumeAmt']);
|
|
comGljObj['consumeAmt'] = parseFloat(comGljObj['consumeAmt']);
|
|
}
|
|
}
|
|
}
|
|
}
|
|
@@ -160,42 +178,42 @@ class GljDao extends OprDao{
|
|
}
|
|
}
|
|
|
|
|
|
async getGljItemsSync(gljLibId) {
|
|
async getGljItemsSync(gljLibId) {
|
|
- return await gljModel.find({repositoryId: gljLibId}, '-_id', {lean: true});
|
|
|
|
|
|
+ return await gljModel.find({ repositoryId: gljLibId }, '-_id', { lean: true });
|
|
}
|
|
}
|
|
|
|
|
|
- async getGljItemsByRep(repositoryId,callback = null){
|
|
|
|
- /* let me = this;
|
|
|
|
- if (callback === null) {
|
|
|
|
- return gljModel.find({"repositoryId": repositoryId});
|
|
|
|
- } else {
|
|
|
|
- gljModel.find({"repositoryId": repositoryId},function(err,data){
|
|
|
|
- if(err) callback(true, "")
|
|
|
|
- else {
|
|
|
|
- me.sortToNumber(data);
|
|
|
|
- callback(false,data);
|
|
|
|
- }
|
|
|
|
- })
|
|
|
|
- }*/
|
|
|
|
|
|
+ async getGljItemsByRep(repositoryId, callback = null) {
|
|
|
|
+ /* let me = this;
|
|
|
|
+ if (callback === null) {
|
|
|
|
+ return gljModel.find({"repositoryId": repositoryId});
|
|
|
|
+ } else {
|
|
|
|
+ gljModel.find({"repositoryId": repositoryId},function(err,data){
|
|
|
|
+ if(err) callback(true, "")
|
|
|
|
+ else {
|
|
|
|
+ me.sortToNumber(data);
|
|
|
|
+ callback(false,data);
|
|
|
|
+ }
|
|
|
|
+ })
|
|
|
|
+ }*/
|
|
|
|
|
|
let me = this;
|
|
let me = this;
|
|
let rst = [];
|
|
let rst = [];
|
|
//批量获取异步
|
|
//批量获取异步
|
|
let functions = [];
|
|
let functions = [];
|
|
- let count = await gljModel.find({repositoryId: repositoryId, $or: [{deleted: null}, {deleted: false}]}).count();
|
|
|
|
- let findCount = Math.ceil(count/500);
|
|
|
|
- for(let i = 0, len = findCount; i < len; i++){
|
|
|
|
- functions.push((function(flag) {
|
|
|
|
|
|
+ let count = await gljModel.find({ repositoryId: repositoryId, $or: [{ deleted: null }, { deleted: false }] }).count();
|
|
|
|
+ let findCount = Math.ceil(count / 500);
|
|
|
|
+ for (let i = 0, len = findCount; i < len; i++) {
|
|
|
|
+ functions.push((function (flag) {
|
|
return function (cb) {
|
|
return function (cb) {
|
|
- gljModel.find({repositoryId: repositoryId, deleted: null}, '-_id', {lean: true}, cb).skip(flag).sort({ID: 1}).limit(500);
|
|
|
|
|
|
+ gljModel.find({ repositoryId: repositoryId, deleted: null }, '-_id', { lean: true }, cb).skip(flag).sort({ ID: 1 }).limit(500);
|
|
}
|
|
}
|
|
- })(i*500));
|
|
|
|
|
|
+ })(i * 500));
|
|
}
|
|
}
|
|
- async.parallel(functions, function (err, results) {
|
|
|
|
- if(err){
|
|
|
|
|
|
+ async.parallel(functions, function (err, results) {
|
|
|
|
+ if (err) {
|
|
callback(err, null);
|
|
callback(err, null);
|
|
}
|
|
}
|
|
- else{
|
|
|
|
- for(let stdGljs of results){
|
|
|
|
|
|
+ else {
|
|
|
|
+ for (let stdGljs of results) {
|
|
rst = rst.concat(stdGljs);
|
|
rst = rst.concat(stdGljs);
|
|
}
|
|
}
|
|
me.sortToNumber(rst);
|
|
me.sortToNumber(rst);
|
|
@@ -204,10 +222,10 @@ class GljDao extends OprDao{
|
|
});
|
|
});
|
|
}
|
|
}
|
|
|
|
|
|
- getGljItemByType (repositoryId, type, callback){
|
|
|
|
|
|
+ getGljItemByType(repositoryId, type, callback) {
|
|
let me = this;
|
|
let me = this;
|
|
- gljModel.find({"repositoryId": repositoryId, "gljType": type},function(err,data){
|
|
|
|
- if(err) callback(true, "");
|
|
|
|
|
|
+ gljModel.find({ "repositoryId": repositoryId, "gljType": type }, function (err, data) {
|
|
|
|
+ if (err) callback(true, "");
|
|
else {
|
|
else {
|
|
me.sortToNumber(data);
|
|
me.sortToNumber(data);
|
|
callback(false, data);
|
|
callback(false, data);
|
|
@@ -215,10 +233,10 @@ class GljDao extends OprDao{
|
|
})
|
|
})
|
|
};
|
|
};
|
|
|
|
|
|
- getGljItem (repositoryId, code, callback){
|
|
|
|
|
|
+ getGljItem(repositoryId, code, callback) {
|
|
let me = this;
|
|
let me = this;
|
|
- gljModel.find({"repositoryId": repositoryId, "code": code},function(err,data){
|
|
|
|
- if(err) callback(true, "")
|
|
|
|
|
|
+ gljModel.find({ "repositoryId": repositoryId, "code": code }, function (err, data) {
|
|
|
|
+ if (err) callback(true, "")
|
|
else {
|
|
else {
|
|
me.sortToNumber(data);
|
|
me.sortToNumber(data);
|
|
callback(false, data);
|
|
callback(false, data);
|
|
@@ -226,10 +244,10 @@ class GljDao extends OprDao{
|
|
})
|
|
})
|
|
};
|
|
};
|
|
|
|
|
|
- getGljItems (gljIds, callback){
|
|
|
|
|
|
+ getGljItems(gljIds, callback) {
|
|
let me = this;
|
|
let me = this;
|
|
- gljModel.find({"ID": {"$in": gljIds}},function(err,data){
|
|
|
|
- if(err) callback(true, "")
|
|
|
|
|
|
+ gljModel.find({ "ID": { "$in": gljIds } }, function (err, data) {
|
|
|
|
+ if (err) callback(true, "")
|
|
else {
|
|
else {
|
|
me.sortToNumber(data);
|
|
me.sortToNumber(data);
|
|
callback(false, data);
|
|
callback(false, data);
|
|
@@ -237,10 +255,10 @@ class GljDao extends OprDao{
|
|
})
|
|
})
|
|
};
|
|
};
|
|
|
|
|
|
- getGljItemsByCode (repositoryId, codes, callback){
|
|
|
|
|
|
+ getGljItemsByCode(repositoryId, codes, callback) {
|
|
let me = this;
|
|
let me = this;
|
|
- gljModel.find({"repositoryId": repositoryId,"code": {"$in": codes}},function(err,data){
|
|
|
|
- if(err) callback(true, "");
|
|
|
|
|
|
+ gljModel.find({ "repositoryId": repositoryId, "code": { "$in": codes } }, function (err, data) {
|
|
|
|
+ if (err) callback(true, "");
|
|
else {
|
|
else {
|
|
me.sortToNumber(data);
|
|
me.sortToNumber(data);
|
|
callback(false, data);
|
|
callback(false, data);
|
|
@@ -248,19 +266,19 @@ class GljDao extends OprDao{
|
|
})
|
|
})
|
|
};
|
|
};
|
|
|
|
|
|
- updateComponent(libId, oprtor, updateArr, callback){
|
|
|
|
|
|
+ updateComponent(libId, oprtor, updateArr, callback) {
|
|
let parallelFucs = [];
|
|
let parallelFucs = [];
|
|
- for(let i = 0; i < updateArr.length; i++){
|
|
|
|
- parallelFucs.push((function(obj){
|
|
|
|
|
|
+ for (let i = 0; i < updateArr.length; i++) {
|
|
|
|
+ parallelFucs.push((function (obj) {
|
|
return function (cb) {
|
|
return function (cb) {
|
|
- if(typeof obj.component === 'undefined'){
|
|
|
|
|
|
+ if (typeof obj.component === 'undefined') {
|
|
obj.component = [];
|
|
obj.component = [];
|
|
}
|
|
}
|
|
- gljModel.update({repositoryId: libId, ID: obj.ID}, obj, function (err, result) {
|
|
|
|
- if(err){
|
|
|
|
|
|
+ gljModel.update({ repositoryId: libId, ID: obj.ID }, obj, function (err, result) {
|
|
|
|
+ if (err) {
|
|
cb(err);
|
|
cb(err);
|
|
}
|
|
}
|
|
- else{
|
|
|
|
|
|
+ else {
|
|
cb(null, obj);
|
|
cb(null, obj);
|
|
}
|
|
}
|
|
})
|
|
})
|
|
@@ -269,31 +287,31 @@ class GljDao extends OprDao{
|
|
}
|
|
}
|
|
parallelFucs.push((function () {
|
|
parallelFucs.push((function () {
|
|
return function (cb) {
|
|
return function (cb) {
|
|
- GljDao.updateOprArr({ID: libId}, oprtor, moment(Date.now()).format('YYYY-MM-DD HH:mm:ss'), function (err) {
|
|
|
|
- if(err){
|
|
|
|
|
|
+ GljDao.updateOprArr({ ID: libId }, oprtor, moment(Date.now()).format('YYYY-MM-DD HH:mm:ss'), function (err) {
|
|
|
|
+ if (err) {
|
|
cb(err);
|
|
cb(err);
|
|
}
|
|
}
|
|
- else{
|
|
|
|
|
|
+ else {
|
|
cb(null);
|
|
cb(null);
|
|
}
|
|
}
|
|
})
|
|
})
|
|
}
|
|
}
|
|
})());
|
|
})());
|
|
async.parallel(parallelFucs, function (err, result) {
|
|
async.parallel(parallelFucs, function (err, result) {
|
|
- if(err){
|
|
|
|
|
|
+ if (err) {
|
|
callback(err, '更新组成物错误!', null);
|
|
callback(err, '更新组成物错误!', null);
|
|
}
|
|
}
|
|
- else{
|
|
|
|
|
|
+ else {
|
|
callback(null, '成功!', result);
|
|
callback(null, '成功!', result);
|
|
}
|
|
}
|
|
});
|
|
});
|
|
}
|
|
}
|
|
|
|
|
|
- mixUpdateGljItems (repId, lastOpr, updateItems, addItems, rIds, callback) {
|
|
|
|
|
|
+ mixUpdateGljItems(repId, lastOpr, updateItems, addItems, rIds, callback) {
|
|
if (updateItems.length == 0 && rIds.length == 0) {
|
|
if (updateItems.length == 0 && rIds.length == 0) {
|
|
GljDao.addGljItems(repId, lastOpr, addItems, callback);
|
|
GljDao.addGljItems(repId, lastOpr, addItems, callback);
|
|
}
|
|
}
|
|
- else if(rIds.length > 0 && updateItems.length > 0){
|
|
|
|
|
|
+ else if (rIds.length > 0 && updateItems.length > 0) {
|
|
async.parallel([
|
|
async.parallel([
|
|
function (cb) {
|
|
function (cb) {
|
|
GljDao.removeGljItems(repId, lastOpr, rIds, cb);
|
|
GljDao.removeGljItems(repId, lastOpr, rIds, cb);
|
|
@@ -302,10 +320,10 @@ class GljDao extends OprDao{
|
|
GljDao.updateGljItems(repId, lastOpr, updateItems, cb);
|
|
GljDao.updateGljItems(repId, lastOpr, updateItems, cb);
|
|
}
|
|
}
|
|
], function (err) {
|
|
], function (err) {
|
|
- if(err){
|
|
|
|
|
|
+ if (err) {
|
|
callback(true, "Fail to update and delete", false)
|
|
callback(true, "Fail to update and delete", false)
|
|
}
|
|
}
|
|
- else{
|
|
|
|
|
|
+ else {
|
|
callback(false, "Save successfully", false);
|
|
callback(false, "Save successfully", false);
|
|
}
|
|
}
|
|
})
|
|
})
|
|
@@ -313,8 +331,8 @@ class GljDao extends OprDao{
|
|
else if (rIds.length > 0 && updateItems.length === 0) {
|
|
else if (rIds.length > 0 && updateItems.length === 0) {
|
|
GljDao.removeGljItems(repId, lastOpr, rIds, callback);
|
|
GljDao.removeGljItems(repId, lastOpr, rIds, callback);
|
|
}
|
|
}
|
|
- else if(updateItems.length > 0 || addItems.length > 0){
|
|
|
|
- GljDao.updateGljItems(repId, lastOpr, updateItems, function(err, results){
|
|
|
|
|
|
+ else if (updateItems.length > 0 || addItems.length > 0) {
|
|
|
|
+ GljDao.updateGljItems(repId, lastOpr, updateItems, function (err, results) {
|
|
if (err) {
|
|
if (err) {
|
|
callback(true, "Fail to update", false);
|
|
callback(true, "Fail to update", false);
|
|
} else {
|
|
} else {
|
|
@@ -349,17 +367,17 @@ class GljDao extends OprDao{
|
|
}
|
|
}
|
|
};*/
|
|
};*/
|
|
|
|
|
|
- static removeGljItems (repId, lastOpr, rIds, callback) {
|
|
|
|
|
|
+ static removeGljItems(repId, lastOpr, rIds, callback) {
|
|
if (rIds && rIds.length > 0) {
|
|
if (rIds && rIds.length > 0) {
|
|
- gljModel.collection.remove({ID: {$in: rIds}}, null, function(err, docs){
|
|
|
|
|
|
+ gljModel.collection.remove({ ID: { $in: rIds } }, null, function (err, docs) {
|
|
if (err) {
|
|
if (err) {
|
|
callback(true, "Fail to remove", false);
|
|
callback(true, "Fail to remove", false);
|
|
} else {
|
|
} else {
|
|
- GljDao.updateOprArr({ID: repId}, lastOpr, moment(Date.now()).format('YYYY-MM-DD HH:mm:ss'), function (err) {
|
|
|
|
- if(err){
|
|
|
|
|
|
+ GljDao.updateOprArr({ ID: repId }, lastOpr, moment(Date.now()).format('YYYY-MM-DD HH:mm:ss'), function (err) {
|
|
|
|
+ if (err) {
|
|
callback(true, "Fail to update operator", false);
|
|
callback(true, "Fail to update operator", false);
|
|
}
|
|
}
|
|
- else{
|
|
|
|
|
|
+ else {
|
|
callback(false, "Remove successfully", docs);
|
|
callback(false, "Remove successfully", docs);
|
|
}
|
|
}
|
|
});
|
|
});
|
|
@@ -370,11 +388,11 @@ class GljDao extends OprDao{
|
|
}
|
|
}
|
|
}
|
|
}
|
|
|
|
|
|
- static addGljItems (repId, lastOpr, items, callback) {
|
|
|
|
|
|
+ static addGljItems(repId, lastOpr, items, callback) {
|
|
if (items && items.length > 0) {
|
|
if (items && items.length > 0) {
|
|
const codes = [];
|
|
const codes = [];
|
|
items.forEach(item => codes.push(item.code));
|
|
items.forEach(item => codes.push(item.code));
|
|
- gljModel.find({repositoryId: repId, code: {$in: codes}}, '-_id code', {lean: true}, (err, codeData) => {
|
|
|
|
|
|
+ gljModel.find({ repositoryId: repId, code: { $in: codes } }, '-_id code', { lean: true }, (err, codeData) => {
|
|
if (err) {
|
|
if (err) {
|
|
callback(true, '判断编码唯一性失败', false);
|
|
callback(true, '判断编码唯一性失败', false);
|
|
return;
|
|
return;
|
|
@@ -390,7 +408,7 @@ class GljDao extends OprDao{
|
|
}
|
|
}
|
|
});
|
|
});
|
|
if (!insertData.length) {
|
|
if (!insertData.length) {
|
|
- callback(false, 'empty data', {insertData, failCode});
|
|
|
|
|
|
+ callback(false, 'empty data', { insertData, failCode });
|
|
return;
|
|
return;
|
|
}
|
|
}
|
|
counter.counterDAO.getIDAfterCount(counter.moduleName.GLJ, items.length, (counterErr, counterData) => {
|
|
counter.counterDAO.getIDAfterCount(counter.moduleName.GLJ, items.length, (counterErr, counterData) => {
|
|
@@ -406,7 +424,7 @@ class GljDao extends OprDao{
|
|
const task = [];
|
|
const task = [];
|
|
insertData.forEach(item => {
|
|
insertData.forEach(item => {
|
|
task.push({
|
|
task.push({
|
|
- insertOne: {document: item}
|
|
|
|
|
|
+ insertOne: { document: item }
|
|
});
|
|
});
|
|
});
|
|
});
|
|
gljModel.bulkWrite(task, (insertErr, rst) => {
|
|
gljModel.bulkWrite(task, (insertErr, rst) => {
|
|
@@ -414,11 +432,11 @@ class GljDao extends OprDao{
|
|
callback(true, '新增数据失败', false);
|
|
callback(true, '新增数据失败', false);
|
|
return;
|
|
return;
|
|
}
|
|
}
|
|
- GljDao.updateOprArr({ID: repId}, lastOpr, moment(Date.now()).format('YYYY-MM-DD HH:mm:ss'), function (err) {
|
|
|
|
- if(err){
|
|
|
|
|
|
+ GljDao.updateOprArr({ ID: repId }, lastOpr, moment(Date.now()).format('YYYY-MM-DD HH:mm:ss'), function (err) {
|
|
|
|
+ if (err) {
|
|
callback(true, "Fail to update Operator", false);
|
|
callback(true, "Fail to update Operator", false);
|
|
- } else{
|
|
|
|
- callback(false, "Add successfully", {insertData, failCode});
|
|
|
|
|
|
+ } else {
|
|
|
|
+ callback(false, "Add successfully", { insertData, failCode });
|
|
}
|
|
}
|
|
});
|
|
});
|
|
});
|
|
});
|
|
@@ -431,9 +449,9 @@ class GljDao extends OprDao{
|
|
|
|
|
|
static updateGljItems(repId, lastOpr, items, callback) {
|
|
static updateGljItems(repId, lastOpr, items, callback) {
|
|
var functions = [];
|
|
var functions = [];
|
|
- for (var i=0; i < items.length; i++) {
|
|
|
|
- functions.push((function(doc) {
|
|
|
|
- return function(cb) {
|
|
|
|
|
|
+ for (var i = 0; i < items.length; i++) {
|
|
|
|
+ functions.push((function (doc) {
|
|
|
|
+ return function (cb) {
|
|
var filter = {};
|
|
var filter = {};
|
|
if (doc.ID) {
|
|
if (doc.ID) {
|
|
filter.ID = doc.ID;
|
|
filter.ID = doc.ID;
|
|
@@ -447,33 +465,33 @@ class GljDao extends OprDao{
|
|
}
|
|
}
|
|
functions.push((function () {
|
|
functions.push((function () {
|
|
return function (cb) {
|
|
return function (cb) {
|
|
- GljDao.updateOprArr({ID: repId}, lastOpr, moment(Date.now()).format('YYYY-MM-DD HH:mm:ss'), function (err) {
|
|
|
|
- if(err){
|
|
|
|
|
|
+ GljDao.updateOprArr({ ID: repId }, lastOpr, moment(Date.now()).format('YYYY-MM-DD HH:mm:ss'), function (err) {
|
|
|
|
+ if (err) {
|
|
cb(err);
|
|
cb(err);
|
|
}
|
|
}
|
|
- else{
|
|
|
|
|
|
+ else {
|
|
cb(null);
|
|
cb(null);
|
|
}
|
|
}
|
|
})
|
|
})
|
|
}
|
|
}
|
|
})());
|
|
})());
|
|
- async.parallel(functions, function(err, results) {
|
|
|
|
|
|
+ async.parallel(functions, function (err, results) {
|
|
callback(err, results);
|
|
callback(err, results);
|
|
});
|
|
});
|
|
}
|
|
}
|
|
|
|
|
|
- getRationGljIds(rationLibs, callback){
|
|
|
|
|
|
+ getRationGljIds(rationLibs, callback) {
|
|
|
|
|
|
}
|
|
}
|
|
|
|
|
|
- updateNodes (updateData, lastOpr, callback) {
|
|
|
|
|
|
+ updateNodes(updateData, lastOpr, callback) {
|
|
let functions = [];
|
|
let functions = [];
|
|
for (let i = 0, len = updateData.length; i < len; i++) {
|
|
for (let i = 0, len = updateData.length; i < len; i++) {
|
|
- functions.push((function(doc) {
|
|
|
|
- return function(cb) {
|
|
|
|
- if(doc.updateType === 'update' && !doc.updateData.deleted){
|
|
|
|
- gljClassModel.update({repositoryId: doc.updateData.repositoryId, ID: doc.updateData.ID}, doc.updateData, function (err) {
|
|
|
|
- if(err){
|
|
|
|
|
|
+ functions.push((function (doc) {
|
|
|
|
+ return function (cb) {
|
|
|
|
+ if (doc.updateType === 'update' && !doc.updateData.deleted) {
|
|
|
|
+ gljClassModel.update({ repositoryId: doc.updateData.repositoryId, ID: doc.updateData.ID }, doc.updateData, function (err) {
|
|
|
|
+ if (err) {
|
|
cb(err);
|
|
cb(err);
|
|
}
|
|
}
|
|
else {
|
|
else {
|
|
@@ -481,26 +499,26 @@ class GljDao extends OprDao{
|
|
}
|
|
}
|
|
});
|
|
});
|
|
}
|
|
}
|
|
- else if(doc.updateType === 'update' && doc.updateData.deleted){
|
|
|
|
- gljClassModel.remove({repositoryId: doc.updateData.repositoryId, ID: doc.updateData.ID}, function (err) {
|
|
|
|
- if(err){
|
|
|
|
|
|
+ else if (doc.updateType === 'update' && doc.updateData.deleted) {
|
|
|
|
+ gljClassModel.remove({ repositoryId: doc.updateData.repositoryId, ID: doc.updateData.ID }, function (err) {
|
|
|
|
+ if (err) {
|
|
cb(err);
|
|
cb(err);
|
|
}
|
|
}
|
|
else {
|
|
else {
|
|
- gljModel.remove({repositoryId: doc.updateData.repositoryId, gljClass: doc.updateData.ID}, function (err) {
|
|
|
|
- if(err){
|
|
|
|
|
|
+ gljModel.remove({ repositoryId: doc.updateData.repositoryId, gljClass: doc.updateData.ID }, function (err) {
|
|
|
|
+ if (err) {
|
|
cb(err);
|
|
cb(err);
|
|
}
|
|
}
|
|
- else{
|
|
|
|
|
|
+ else {
|
|
cb(null);
|
|
cb(null);
|
|
}
|
|
}
|
|
});
|
|
});
|
|
}
|
|
}
|
|
});
|
|
});
|
|
}
|
|
}
|
|
- else if(doc.updateType === 'new'){
|
|
|
|
|
|
+ else if (doc.updateType === 'new') {
|
|
gljClassModel.create(doc.updateData, function (err) {
|
|
gljClassModel.create(doc.updateData, function (err) {
|
|
- if(err){
|
|
|
|
|
|
+ if (err) {
|
|
cb(err);
|
|
cb(err);
|
|
}
|
|
}
|
|
else {
|
|
else {
|
|
@@ -511,88 +529,88 @@ class GljDao extends OprDao{
|
|
};
|
|
};
|
|
})(updateData[i]));
|
|
})(updateData[i]));
|
|
}
|
|
}
|
|
- if(updateData.length > 0){
|
|
|
|
|
|
+ if (updateData.length > 0) {
|
|
functions.push((function () {
|
|
functions.push((function () {
|
|
return function (cb) {
|
|
return function (cb) {
|
|
- GljDao.updateOprArr({ID: updateData[0].updateData.rationRepId}, lastOpr, moment(Date.now()).format('YYYY-MM-DD HH:mm:ss'), function (err) {
|
|
|
|
- if(err){
|
|
|
|
|
|
+ GljDao.updateOprArr({ ID: updateData[0].updateData.rationRepId }, lastOpr, moment(Date.now()).format('YYYY-MM-DD HH:mm:ss'), function (err) {
|
|
|
|
+ if (err) {
|
|
cb(err);
|
|
cb(err);
|
|
}
|
|
}
|
|
- else{
|
|
|
|
|
|
+ else {
|
|
cb(null);
|
|
cb(null);
|
|
}
|
|
}
|
|
})
|
|
})
|
|
}
|
|
}
|
|
})());
|
|
})());
|
|
}
|
|
}
|
|
- async.parallel(functions, function(err, results) {
|
|
|
|
- if(!err){
|
|
|
|
|
|
+ async.parallel(functions, function (err, results) {
|
|
|
|
+ if (!err) {
|
|
err = 0;
|
|
err = 0;
|
|
}
|
|
}
|
|
callback(err, results);
|
|
callback(err, results);
|
|
});
|
|
});
|
|
}
|
|
}
|
|
|
|
|
|
- /* updateNodes (repId, lastOpr, nodes, callback) {
|
|
|
|
- var functions = [];
|
|
|
|
- for (var i=0; i < nodes.length; i++) {
|
|
|
|
- functions.push((function(doc) {
|
|
|
|
- return function(cb) {
|
|
|
|
- gljClassModel.update({ID: doc.ID}, doc, cb);
|
|
|
|
- };
|
|
|
|
- })(nodes[i]));
|
|
|
|
- }
|
|
|
|
- functions.push((function () {
|
|
|
|
- return function (cb) {
|
|
|
|
- GljDao.updateOprArr({ID: repId}, lastOpr, moment(Date.now()).format('YYYY-MM-DD HH:mm:ss'), function (err) {
|
|
|
|
- if(err){
|
|
|
|
- cb(err);
|
|
|
|
- }
|
|
|
|
- else{
|
|
|
|
- cb(null);
|
|
|
|
- }
|
|
|
|
- })
|
|
|
|
- }
|
|
|
|
- })());
|
|
|
|
- async.parallel(functions, function(err, results) {
|
|
|
|
- callback(err, results);
|
|
|
|
- });
|
|
|
|
- }*/
|
|
|
|
- removeNodes (repId, lastOpr, nodeIds, preNodeId, preNodeNextId, callback){
|
|
|
|
|
|
+ /* updateNodes (repId, lastOpr, nodes, callback) {
|
|
|
|
+ var functions = [];
|
|
|
|
+ for (var i=0; i < nodes.length; i++) {
|
|
|
|
+ functions.push((function(doc) {
|
|
|
|
+ return function(cb) {
|
|
|
|
+ gljClassModel.update({ID: doc.ID}, doc, cb);
|
|
|
|
+ };
|
|
|
|
+ })(nodes[i]));
|
|
|
|
+ }
|
|
|
|
+ functions.push((function () {
|
|
|
|
+ return function (cb) {
|
|
|
|
+ GljDao.updateOprArr({ID: repId}, lastOpr, moment(Date.now()).format('YYYY-MM-DD HH:mm:ss'), function (err) {
|
|
|
|
+ if(err){
|
|
|
|
+ cb(err);
|
|
|
|
+ }
|
|
|
|
+ else{
|
|
|
|
+ cb(null);
|
|
|
|
+ }
|
|
|
|
+ })
|
|
|
|
+ }
|
|
|
|
+ })());
|
|
|
|
+ async.parallel(functions, function(err, results) {
|
|
|
|
+ callback(err, results);
|
|
|
|
+ });
|
|
|
|
+ }*/
|
|
|
|
+ removeNodes(repId, lastOpr, nodeIds, preNodeId, preNodeNextId, callback) {
|
|
var functions = [];
|
|
var functions = [];
|
|
if (preNodeId != -1) {
|
|
if (preNodeId != -1) {
|
|
- functions.push((function(nodeId, nextId) {
|
|
|
|
- return function(cb) {
|
|
|
|
- gljClassModel.update({ID: nodeId}, {"NextSiblingID": nextId}, cb);
|
|
|
|
|
|
+ functions.push((function (nodeId, nextId) {
|
|
|
|
+ return function (cb) {
|
|
|
|
+ gljClassModel.update({ ID: nodeId }, { "NextSiblingID": nextId }, cb);
|
|
};
|
|
};
|
|
})(preNodeId, preNodeNextId));
|
|
})(preNodeId, preNodeNextId));
|
|
}
|
|
}
|
|
- for (var i=0; i < nodeIds.length; i++) {
|
|
|
|
- functions.push((function(nodeId) {
|
|
|
|
- return function(cb) {
|
|
|
|
- gljClassModel.update({ID: nodeId}, {"isDeleted": true}, cb);
|
|
|
|
|
|
+ for (var i = 0; i < nodeIds.length; i++) {
|
|
|
|
+ functions.push((function (nodeId) {
|
|
|
|
+ return function (cb) {
|
|
|
|
+ gljClassModel.update({ ID: nodeId }, { "isDeleted": true }, cb);
|
|
};
|
|
};
|
|
})(nodeIds[i]));
|
|
})(nodeIds[i]));
|
|
}
|
|
}
|
|
functions.push((function () {
|
|
functions.push((function () {
|
|
return function (cb) {
|
|
return function (cb) {
|
|
- GljDao.updateOprArr({ID: repId}, lastOpr, moment(Date.now()).format('YYYY-MM-DD HH:mm:ss'), function (err) {
|
|
|
|
- if(err){
|
|
|
|
|
|
+ GljDao.updateOprArr({ ID: repId }, lastOpr, moment(Date.now()).format('YYYY-MM-DD HH:mm:ss'), function (err) {
|
|
|
|
+ if (err) {
|
|
cb(err);
|
|
cb(err);
|
|
}
|
|
}
|
|
- else{
|
|
|
|
|
|
+ else {
|
|
cb(null);
|
|
cb(null);
|
|
}
|
|
}
|
|
})
|
|
})
|
|
}
|
|
}
|
|
})());
|
|
})());
|
|
- async.parallel(functions, function(err, results) {
|
|
|
|
|
|
+ async.parallel(functions, function (err, results) {
|
|
callback(err, results);
|
|
callback(err, results);
|
|
});
|
|
});
|
|
}
|
|
}
|
|
|
|
|
|
createNewNode(repId, lastOpr, lastNodeId, nodeData, callback) {
|
|
createNewNode(repId, lastOpr, lastNodeId, nodeData, callback) {
|
|
- return counter.counterDAO.getIDAfterCount(counter.moduleName.GLJ, 1, function(err, result){
|
|
|
|
|
|
+ return counter.counterDAO.getIDAfterCount(counter.moduleName.GLJ, 1, function (err, result) {
|
|
nodeData.repositoryId = repId;
|
|
nodeData.repositoryId = repId;
|
|
nodeData.ID = result.sequence_value;
|
|
nodeData.ID = result.sequence_value;
|
|
var node = new gljModel(nodeData);
|
|
var node = new gljModel(nodeData);
|
|
@@ -603,7 +621,7 @@ class GljDao extends OprDao{
|
|
cb("章节树ID错误!", false);
|
|
cb("章节树ID错误!", false);
|
|
} else {
|
|
} else {
|
|
if (lastNodeId > 0) {
|
|
if (lastNodeId > 0) {
|
|
- gljClassModel.update({ID: lastNodeId}, {"NextSiblingID": nodeData.ID}, function(err, rst){
|
|
|
|
|
|
+ gljClassModel.update({ ID: lastNodeId }, { "NextSiblingID": nodeData.ID }, function (err, rst) {
|
|
if (err) {
|
|
if (err) {
|
|
cb("章节树ID错误!", false);
|
|
cb("章节树ID错误!", false);
|
|
} else {
|
|
} else {
|
|
@@ -615,64 +633,64 @@ class GljDao extends OprDao{
|
|
});
|
|
});
|
|
},
|
|
},
|
|
function (cb) {
|
|
function (cb) {
|
|
- GljDao.updateOprArr({ID: repId}, lastOpr, moment(Date.now()).format('YYYY-MM-DD HH:mm:ss'), function (err) {
|
|
|
|
- if(err){
|
|
|
|
|
|
+ GljDao.updateOprArr({ ID: repId }, lastOpr, moment(Date.now()).format('YYYY-MM-DD HH:mm:ss'), function (err) {
|
|
|
|
+ if (err) {
|
|
cb(err);
|
|
cb(err);
|
|
}
|
|
}
|
|
- else{
|
|
|
|
|
|
+ else {
|
|
cb(null);
|
|
cb(null);
|
|
}
|
|
}
|
|
})
|
|
})
|
|
}
|
|
}
|
|
], function (err, result) {
|
|
], function (err, result) {
|
|
- if(err){
|
|
|
|
|
|
+ if (err) {
|
|
callback(true, "章节树错误!", false);
|
|
callback(true, "章节树错误!", false);
|
|
}
|
|
}
|
|
- else{
|
|
|
|
|
|
+ else {
|
|
callback(false, '', result[0]);
|
|
callback(false, '', result[0]);
|
|
}
|
|
}
|
|
})
|
|
})
|
|
});
|
|
});
|
|
}
|
|
}
|
|
|
|
|
|
- getGljItemsOccupied(repId, occupation, callback){
|
|
|
|
- gljModel.find({repositoryId: repId}, occupation, function (err, result) {
|
|
|
|
- if(err) callback(true, 'fail', null);
|
|
|
|
|
|
+ getGljItemsOccupied(repId, occupation, callback) {
|
|
|
|
+ gljModel.find({ repositoryId: repId }, occupation, function (err, result) {
|
|
|
|
+ if (err) callback(true, 'fail', null);
|
|
else callback(false, 'sc', result);
|
|
else callback(false, 'sc', result);
|
|
});
|
|
});
|
|
}
|
|
}
|
|
|
|
|
|
- async getGljItemsByRepId(repositoryId, returnFields = ''){
|
|
|
|
- return gljModel.find({"repositoryId": repositoryId}, returnFields);
|
|
|
|
|
|
+ async getGljItemsByRepId(repositoryId, returnFields = '') {
|
|
|
|
+ return gljModel.find({ "repositoryId": repositoryId }, returnFields);
|
|
}
|
|
}
|
|
|
|
|
|
- async batchUpdateGljPrice(gljLibId, sheetData){
|
|
|
|
- let gljLib = await gljMapModel.findOne({ID: gljLibId});
|
|
|
|
- if(!gljLib){
|
|
|
|
|
|
+ async batchUpdateGljPrice(gljLibId, sheetData) {
|
|
|
|
+ let gljLib = await gljMapModel.findOne({ ID: gljLibId });
|
|
|
|
+ if (!gljLib) {
|
|
throw '不存在此人材机库';
|
|
throw '不存在此人材机库';
|
|
}
|
|
}
|
|
- let compilation = await compilationModel.findOne({_id: mongoose.Types.ObjectId(gljLib.compilationId)});
|
|
|
|
- if(!compilation){
|
|
|
|
|
|
+ let compilation = await compilationModel.findOne({ _id: mongoose.Types.ObjectId(gljLib.compilationId) });
|
|
|
|
+ if (!compilation) {
|
|
throw '不存在此费用定额';
|
|
throw '不存在此费用定额';
|
|
}
|
|
}
|
|
let priceProperties = compilation.priceProperties ? compilation.priceProperties : [];
|
|
let priceProperties = compilation.priceProperties ? compilation.priceProperties : [];
|
|
//根据第一行数据,获取列下标与字段名映射
|
|
//根据第一行数据,获取列下标与字段名映射
|
|
let colMapping = {};
|
|
let colMapping = {};
|
|
- for(let col = 0; col < sheetData[0].length; col++){
|
|
|
|
|
|
+ for (let col = 0; col < sheetData[0].length; col++) {
|
|
let cData = sheetData[0][col];
|
|
let cData = sheetData[0][col];
|
|
- if(cData === '编码'){
|
|
|
|
|
|
+ if (cData === '编码') {
|
|
colMapping['code'] = col;
|
|
colMapping['code'] = col;
|
|
}
|
|
}
|
|
else {
|
|
else {
|
|
- if(priceProperties.length === 0){
|
|
|
|
- if(cData === '定额价'){
|
|
|
|
|
|
+ if (priceProperties.length === 0) {
|
|
|
|
+ if (cData === '定额价') {
|
|
colMapping['basePrice'] = col;
|
|
colMapping['basePrice'] = col;
|
|
break;
|
|
break;
|
|
}
|
|
}
|
|
}
|
|
}
|
|
else {
|
|
else {
|
|
- for(let priceProp of priceProperties){
|
|
|
|
- if(priceProp.price.dataName === cData){
|
|
|
|
|
|
+ for (let priceProp of priceProperties) {
|
|
|
|
+ if (priceProp.price.dataName === cData) {
|
|
colMapping[priceProp.price.dataCode] = col;
|
|
colMapping[priceProp.price.dataCode] = col;
|
|
break;
|
|
break;
|
|
}
|
|
}
|
|
@@ -681,7 +699,7 @@ class GljDao extends OprDao{
|
|
}
|
|
}
|
|
}
|
|
}
|
|
let colMappingKeys = Object.keys(colMapping);
|
|
let colMappingKeys = Object.keys(colMapping);
|
|
- if(colMappingKeys.length < 2){
|
|
|
|
|
|
+ if (colMappingKeys.length < 2) {
|
|
throw 'excel数据不正确'
|
|
throw 'excel数据不正确'
|
|
}
|
|
}
|
|
let updateBulk = [];
|
|
let updateBulk = [];
|
|
@@ -689,21 +707,21 @@ class GljDao extends OprDao{
|
|
let updateCodes = [];
|
|
let updateCodes = [];
|
|
//库中存在的人材机
|
|
//库中存在的人材机
|
|
let dateA = Date.now();
|
|
let dateA = Date.now();
|
|
- let existGljs = await gljModel.find({repositoryId: gljLibId}, '-_id code ID');
|
|
|
|
|
|
+ let existGljs = await gljModel.find({ repositoryId: gljLibId }, '-_id code ID');
|
|
let existMapping = {};
|
|
let existMapping = {};
|
|
for (let glj of existGljs) {
|
|
for (let glj of existGljs) {
|
|
existMapping[glj.code] = glj;
|
|
existMapping[glj.code] = glj;
|
|
}
|
|
}
|
|
- for(let row = 0; row < sheetData.length; row++){
|
|
|
|
- if(row === 0){
|
|
|
|
|
|
+ for (let row = 0; row < sheetData.length; row++) {
|
|
|
|
+ if (row === 0) {
|
|
continue;
|
|
continue;
|
|
}
|
|
}
|
|
let gljCode = sheetData[row][colMapping.code],
|
|
let gljCode = sheetData[row][colMapping.code],
|
|
existGlj = existMapping[gljCode];
|
|
existGlj = existMapping[gljCode];
|
|
//更新多单价、不覆盖priceProperty字段,覆盖priceProperty下的子字段'priceProperty.x'
|
|
//更新多单价、不覆盖priceProperty字段,覆盖priceProperty下的子字段'priceProperty.x'
|
|
- if(gljCode && gljCode !== '' && !updateCodes.includes(gljCode) && existGlj){
|
|
|
|
- if(priceProperties.length > 0){
|
|
|
|
- for(let priceProp of priceProperties){
|
|
|
|
|
|
+ if (gljCode && gljCode !== '' && !updateCodes.includes(gljCode) && existGlj) {
|
|
|
|
+ if (priceProperties.length > 0) {
|
|
|
|
+ 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]];
|
|
//Excel中没有这个单价则跳过
|
|
//Excel中没有这个单价则跳过
|
|
@@ -714,25 +732,25 @@ class GljDao extends OprDao{
|
|
updateSet['priceProperty.' + dataCode] = priceCellData && !isNaN(priceCellData) ?
|
|
updateSet['priceProperty.' + dataCode] = priceCellData && !isNaN(priceCellData) ?
|
|
scMathUtil.roundTo(parseFloat(priceCellData), -2) : 0;
|
|
scMathUtil.roundTo(parseFloat(priceCellData), -2) : 0;
|
|
updateBulk.push({
|
|
updateBulk.push({
|
|
- updateOne: {filter: {ID: existGlj.ID}, update: {$set: updateSet}}
|
|
|
|
|
|
+ updateOne: { filter: { ID: existGlj.ID }, update: { $set: updateSet } }
|
|
});
|
|
});
|
|
}
|
|
}
|
|
updateCodes.push(gljCode);
|
|
updateCodes.push(gljCode);
|
|
}
|
|
}
|
|
else {
|
|
else {
|
|
- if(colMapping.basePrice){
|
|
|
|
|
|
+ if (colMapping.basePrice) {
|
|
let priceCellData = sheetData[row][colMapping.basePrice];
|
|
let priceCellData = sheetData[row][colMapping.basePrice];
|
|
- let basePrice = priceCellData && !isNaN(priceCellData) ?
|
|
|
|
|
|
+ let basePrice = priceCellData && !isNaN(priceCellData) ?
|
|
scMathUtil.roundTo(priceCellData, -2) : 0;
|
|
scMathUtil.roundTo(priceCellData, -2) : 0;
|
|
updateCodes.push(gljCode);
|
|
updateCodes.push(gljCode);
|
|
updateBulk.push({
|
|
updateBulk.push({
|
|
- updateOne: {filter: {ID: existGlj.ID}, update: {$set: {basePrice: basePrice}}}
|
|
|
|
|
|
+ updateOne: { filter: { ID: existGlj.ID }, update: { $set: { basePrice: basePrice } } }
|
|
});
|
|
});
|
|
}
|
|
}
|
|
}
|
|
}
|
|
}
|
|
}
|
|
}
|
|
}
|
|
- if(updateBulk.length > 0){
|
|
|
|
|
|
+ if (updateBulk.length > 0) {
|
|
while (updateBulk.length > 0) {
|
|
while (updateBulk.length > 0) {
|
|
let sliceBulk = updateBulk.splice(0, 1000);
|
|
let sliceBulk = updateBulk.splice(0, 1000);
|
|
await gljModel.bulkWrite(sliceBulk);
|
|
await gljModel.bulkWrite(sliceBulk);
|
|
@@ -742,16 +760,16 @@ class GljDao extends OprDao{
|
|
}
|
|
}
|
|
|
|
|
|
async importComponents(gljLibId, sheetData) {
|
|
async importComponents(gljLibId, sheetData) {
|
|
- const gljLib = await gljMapModel.findOne({ID: gljLibId});
|
|
|
|
|
|
+ const gljLib = await gljMapModel.findOne({ ID: gljLibId });
|
|
if (!gljLib) {
|
|
if (!gljLib) {
|
|
throw '不存在此人材机库';
|
|
throw '不存在此人材机库';
|
|
}
|
|
}
|
|
- const compilation = await compilationModel.findOne({_id: mongoose.Types.ObjectId(gljLib.compilationId)});
|
|
|
|
|
|
+ const compilation = await compilationModel.findOne({ _id: mongoose.Types.ObjectId(gljLib.compilationId) });
|
|
if (!compilation) {
|
|
if (!compilation) {
|
|
throw '不存在此费用定额';
|
|
throw '不存在此费用定额';
|
|
}
|
|
}
|
|
// 将所有人材机进行编码映射
|
|
// 将所有人材机进行编码映射
|
|
- const allGLJs = await gljModel.find({repositoryId: gljLibId}, {ID: true, code: true}).lean();
|
|
|
|
|
|
+ const allGLJs = await gljModel.find({ repositoryId: gljLibId }, { ID: true, code: true }).lean();
|
|
const codeMapping = {};
|
|
const codeMapping = {};
|
|
allGLJs.forEach(glj => codeMapping[glj.code] = glj);
|
|
allGLJs.forEach(glj => codeMapping[glj.code] = glj);
|
|
// excel表格列号与字段的映射
|
|
// excel表格列号与字段的映射
|
|
@@ -790,7 +808,7 @@ class GljDao extends OprDao{
|
|
filter: {
|
|
filter: {
|
|
ID: glj.ID
|
|
ID: glj.ID
|
|
},
|
|
},
|
|
- update: {$set: {component: glj.component}}
|
|
|
|
|
|
+ update: { $set: { component: glj.component } }
|
|
}
|
|
}
|
|
});
|
|
});
|
|
});
|
|
});
|