|
@@ -15,6 +15,7 @@ const uuidV1 = require('uuid/v1');
|
|
|
let ration_model = mongoose.model('ration');
|
|
|
let bill_model=mongoose.model("bills");
|
|
|
const scMathUtil = require('../../../public/scMathUtil').getUtil();
|
|
|
+let decimal_facade = require('./decimal_facade');
|
|
|
|
|
|
module.exports={
|
|
|
save:save,
|
|
@@ -22,58 +23,143 @@ module.exports={
|
|
|
deleteByRation:deleteByRation,
|
|
|
deleteByBill:deleteByBill,
|
|
|
quantityEditChecking:quantityEditChecking,
|
|
|
+ saveQuantityDetail:saveQuantityDetail,
|
|
|
+ update:update,
|
|
|
+ updateRegex:updateRegex,
|
|
|
+ insertRecode:insertRecode,
|
|
|
+ deleteRecode:deleteRecode,
|
|
|
+ swapRow:swapRow
|
|
|
};
|
|
|
|
|
|
let operationMap={
|
|
|
- 'ut_create':create_quantity_detail,
|
|
|
'ut_update':update_quantity_detail,
|
|
|
- 'ut_delete':delete_quantity_detail
|
|
|
};
|
|
|
|
|
|
let updateFunctionMap = {
|
|
|
- 'normalUpdate':normalUpdate,
|
|
|
- 'updateQuantityRegex':updateQuantityRegex,
|
|
|
'insertRecode':insertRecode
|
|
|
}
|
|
|
|
|
|
-function create_quantity_detail(user_id,datas) {
|
|
|
- return function (callback) {
|
|
|
- let doc = datas.doc;
|
|
|
- doc.ID = uuidV1();
|
|
|
- if(doc.hasOwnProperty('regex')){
|
|
|
- insertRecodeWithReg(doc).then(function (resultObject) {
|
|
|
- if(resultObject.err){
|
|
|
- callback(null,{
|
|
|
- moduleName:consts.projectConst.QUANTITY_DETAIL,
|
|
|
- err:{
|
|
|
- message:result.err.message
|
|
|
- }
|
|
|
- });
|
|
|
- } else {
|
|
|
- callback(null,resultObject.return_list);
|
|
|
- }
|
|
|
- })
|
|
|
- }else {
|
|
|
- createNormalRecode(doc,callback)
|
|
|
- }
|
|
|
+async function saveQuantityDetail(datas) {
|
|
|
+ console.log(datas);
|
|
|
+ let doc = datas;
|
|
|
+ doc.ID = uuidV1();
|
|
|
+ if(doc.refreshQuantity==false){ //如果选择了不替换工程量,则清空
|
|
|
+ await cleanQuantityDetail(doc);
|
|
|
+ return
|
|
|
+ }
|
|
|
+ if(doc.hasOwnProperty('regex')){
|
|
|
+ return await insertRecodeWithReg(doc);
|
|
|
+ }else {
|
|
|
+ return await createNormalRecode(doc);
|
|
|
+ }
|
|
|
+}
|
|
|
|
|
|
+async function update(datas) {
|
|
|
+ let doc = datas.doc;
|
|
|
+ if(doc.hasOwnProperty('isSummation')){
|
|
|
+ return await doIsSummationUpdate(datas.query,doc);
|
|
|
+ }else {
|
|
|
+ await quantity_detail_model.update(datas.query,doc);
|
|
|
+ return datas;
|
|
|
}
|
|
|
}
|
|
|
|
|
|
-function insertRecode(user_id,datas) {
|
|
|
- return function (callback) {
|
|
|
- let doc = datas.doc;
|
|
|
- doc.ID = uuidV1();
|
|
|
- doInsertRecode(doc).then(function (result) {
|
|
|
- //console.log(result);
|
|
|
- if(result.err){
|
|
|
- callback(result.err,'')
|
|
|
- }else {
|
|
|
- callback(null,result.returndata)
|
|
|
- }
|
|
|
+async function swapRow(datas) {
|
|
|
+ for(let task of datas){
|
|
|
+ await update(task);
|
|
|
+ }
|
|
|
+ return {refreshList:datas};
|
|
|
+}
|
|
|
+
|
|
|
+async function updateRegex(datas) {
|
|
|
+ let resultObjec ={};
|
|
|
|
|
|
- })
|
|
|
+ let detailList = [];
|
|
|
+ let node ={};
|
|
|
+ let decimal =await decimal_facade.getProjectDecimal(datas.query.projectID);
|
|
|
+ if(datas.query.hasOwnProperty('rationID')){
|
|
|
+ detailList = await quantity_detail_model.find({'projectID':datas.query.projectID,'rationID':datas.query.rationID}).sort('seq').exec();
|
|
|
+ node.type = consts.projectConst.RATION;
|
|
|
+ node.ID = datas.query.rationID;
|
|
|
+ }else {
|
|
|
+ detailList = await quantity_detail_model.find({'projectID':datas.query.projectID,'billID':datas.query.billID}).sort('seq').exec();
|
|
|
+ node.type = consts.projectConst.BILLS;
|
|
|
+ node.ID=datas.query.billID;
|
|
|
}
|
|
|
+ let regex;
|
|
|
+ let result;
|
|
|
+ if(datas.doc.regex==null){
|
|
|
+ result=0;
|
|
|
+ datas.doc.referenceIndexs=[];
|
|
|
+ }else {
|
|
|
+ regex = datas.doc.regex.toUpperCase();
|
|
|
+ let referenceIndexs = datas.doc.referenceIndexs;
|
|
|
+ result = getEvalResult(referenceIndexs,detailList,regex,decimal);
|
|
|
+ }
|
|
|
+ detailList[datas.query.index].result =result;
|
|
|
+ detailList[datas.query.index].regex=datas.doc.regex;
|
|
|
+ detailList[datas.query.index].referenceIndexs =datas.doc.referenceIndexs;
|
|
|
+ let updateTasks =[];
|
|
|
+ datas.doc.result=result;
|
|
|
+ updateTasks.push({
|
|
|
+ query:{
|
|
|
+ ID:datas.query.ID,
|
|
|
+ projectID:datas.query.projectID
|
|
|
+ },
|
|
|
+ doc:datas.doc
|
|
|
+ })
|
|
|
+ updateReferenceRecode(datas.query.index+1,detailList,updateTasks);
|
|
|
+ await quantity_detail_model.bulkWrite(generateUpdateTaks(updateTasks));
|
|
|
+ resultObjec.refreshList=updateTasks;
|
|
|
+ if(datas.query.refreshQuantity==true){
|
|
|
+ let data = {};
|
|
|
+ data.quantity = await summateResults(datas.query,detailList,decimal);
|
|
|
+ data.isFromDetail = 1;
|
|
|
+ node.data = data;
|
|
|
+ resultObjec.node = node;
|
|
|
+ }
|
|
|
+ return resultObjec;
|
|
|
+
|
|
|
+}
|
|
|
+
|
|
|
+
|
|
|
+async function cleanQuantityDetail(doc) {
|
|
|
+ let query = {
|
|
|
+ projectID:doc.projectID
|
|
|
+ }
|
|
|
+ if(doc.hasOwnProperty('rationID')){
|
|
|
+ query.rationID = doc.rationID;
|
|
|
+ }else {
|
|
|
+ query.billID = doc.billID;
|
|
|
+ }
|
|
|
+ await quantity_detail_model.deleteMany(query);
|
|
|
+}
|
|
|
+
|
|
|
+
|
|
|
+async function insertRecode(doc){
|
|
|
+ let query = {
|
|
|
+ projectID:doc.projectID,
|
|
|
+ seq : { $gte: doc.seq }
|
|
|
+ }
|
|
|
+ if(doc.hasOwnProperty('rationID')){
|
|
|
+ query.rationID = doc.rationID;
|
|
|
+ }else {
|
|
|
+ query.billID = doc.billID;
|
|
|
+ }
|
|
|
+ let quantity_detail_List = await getDatailList(doc,{data:{}});
|
|
|
+ let update_task = getUpdateReferenceTask(quantity_detail_List,doc.seq,1);
|
|
|
+ await quantity_detail_model.update(query,{$inc:{seq:1}},{multi: true});
|
|
|
+ if(update_task.length>0){
|
|
|
+ await quantity_detail_model.bulkWrite(generateUpdateTaks(update_task));
|
|
|
+ }
|
|
|
+ doc.ID = uuidV1();
|
|
|
+ let newrecode = await quantity_detail_model.create(doc);
|
|
|
+ let data={
|
|
|
+ doc:newrecode,
|
|
|
+ resort:true,
|
|
|
+ update_task:update_task
|
|
|
+ }
|
|
|
+ return data;
|
|
|
}
|
|
|
|
|
|
async function doInsertRecode(doc) {
|
|
@@ -150,229 +236,78 @@ function getUpdateReferenceTask(quantity_detail_List,seq,re) {
|
|
|
}
|
|
|
|
|
|
|
|
|
-function createNormalRecode(doc,callback) {
|
|
|
- quantity_detail_model.create(doc,(err,result)=>{
|
|
|
- if(err){
|
|
|
- callback(err,null);
|
|
|
- }else {
|
|
|
- console.log(result);
|
|
|
- let returndata ={
|
|
|
- updateTpye:commonConsts.UT_CREATE,
|
|
|
- moduleName:consts.projectConst.QUANTITY_DETAIL,
|
|
|
- data:result
|
|
|
- }
|
|
|
- callback(null,returndata)
|
|
|
- }
|
|
|
- });
|
|
|
+async function createNormalRecode(doc) {
|
|
|
+ let result ={};
|
|
|
+ result.newRecord= await quantity_detail_model.create(doc);
|
|
|
+ return result;
|
|
|
}
|
|
|
|
|
|
|
|
|
async function insertRecodeWithReg (doc) {
|
|
|
- let returnObjec={
|
|
|
- err:null,
|
|
|
- return_list:[]
|
|
|
- }
|
|
|
+ let returnObjec={}
|
|
|
try {
|
|
|
- let returnData={
|
|
|
- moduleName:'',
|
|
|
- data:{
|
|
|
- updateTpye:commonConsts.UT_UPDATE,
|
|
|
- }
|
|
|
- }
|
|
|
+ let decimal =await decimal_facade.getProjectDecimal(doc.projectID);
|
|
|
let regex = doc.regex.toUpperCase();
|
|
|
let referenceIndexs = doc.referenceIndexs;
|
|
|
- let detailList = await getDatailList(doc,returnData);
|
|
|
- doc.result =getEvalResult(referenceIndexs,detailList,regex);
|
|
|
+ let detailList = await getDatailList(doc,returnObjec);
|
|
|
+ doc.result =getEvalResult(referenceIndexs,detailList,regex,decimal);
|
|
|
let refreshQuantity =false;
|
|
|
if(doc.refreshQuantity==true){
|
|
|
refreshQuantity = true;
|
|
|
}
|
|
|
delete doc.refreshQuantity;
|
|
|
- let newRecode = await quantity_detail_model.create(doc) ;
|
|
|
- detailList.push(newRecode);
|
|
|
+ let newRecord = await quantity_detail_model.create(doc) ;
|
|
|
+ detailList.push(newRecord);
|
|
|
if(refreshQuantity==true){
|
|
|
- returnData.data.quantity = await summateResuts(doc,detailList);
|
|
|
- returnData.data.quantityRefresh = true;
|
|
|
- returnObjec.return_list.push(returnData);
|
|
|
+ let data = {};
|
|
|
+ data.quantity = await summateResults(doc,detailList,decimal);
|
|
|
+ data.isFromDetail = 1;
|
|
|
+ returnObjec.node.data = data;
|
|
|
}
|
|
|
- returnObjec.return_list.push({
|
|
|
- updateTpye:commonConsts.UT_CREATE,
|
|
|
- moduleName:consts.projectConst.QUANTITY_DETAIL,
|
|
|
- data:newRecode
|
|
|
- });
|
|
|
+ returnObjec.newRecord = newRecord;
|
|
|
return returnObjec;
|
|
|
}catch (error){
|
|
|
- returnObjec.err = new Error('输入的表达式有误,请重新输入!');
|
|
|
- console.log(error)
|
|
|
- return returnObjec;
|
|
|
- }
|
|
|
-
|
|
|
-
|
|
|
-}
|
|
|
-
|
|
|
-
|
|
|
-
|
|
|
-function normalUpdate(user_id,datas) {
|
|
|
- return function(callback) {
|
|
|
- if(datas.doc.hasOwnProperty('isSummation')){
|
|
|
- doIsSummationUpdate(datas.query,datas.doc).then(function (sresult) {
|
|
|
- let returndata ={
|
|
|
- moduleName:consts.projectConst.QUANTITY_DETAIL,
|
|
|
- data:{
|
|
|
- updateTpye:commonConsts.UT_UPDATE,
|
|
|
- query:datas.query,
|
|
|
- doc:datas.doc
|
|
|
- }
|
|
|
- }
|
|
|
- let retrunArr = [];
|
|
|
- retrunArr.push(returndata);
|
|
|
- if(sresult){
|
|
|
- retrunArr.push(sresult);
|
|
|
- }
|
|
|
- callback(null,retrunArr);
|
|
|
- })
|
|
|
- }else {
|
|
|
- updateRecored(datas.query,datas.doc,callback);
|
|
|
- }
|
|
|
- }
|
|
|
-}
|
|
|
-function updateQuantityRegex(user_id,datas) {
|
|
|
- return function(callback){
|
|
|
- doRegexUpdate(datas).then(function (result) {
|
|
|
- if(result.err){
|
|
|
- callback(null,{
|
|
|
- moduleName:consts.projectConst.QUANTITY_DETAIL,
|
|
|
- err:{
|
|
|
- message:result.err.message
|
|
|
- }
|
|
|
- });
|
|
|
- }else {
|
|
|
- callback(null,result.rList);
|
|
|
- }
|
|
|
-
|
|
|
- })
|
|
|
+ console.log(error);
|
|
|
+ throw new Error('输入的表达式有误,请重新输入!');
|
|
|
}
|
|
|
}
|
|
|
|
|
|
async function doIsSummationUpdate(query,doc) {
|
|
|
- try {
|
|
|
- let returnData={
|
|
|
- moduleName:'',
|
|
|
- data:{
|
|
|
- updateTpye:commonConsts.UT_UPDATE,
|
|
|
- }
|
|
|
- }
|
|
|
- let refreshQuantity=false;
|
|
|
- if(query.refreshQuantity==true){
|
|
|
- refreshQuantity=true;
|
|
|
- }
|
|
|
- delete query.refreshQuantity;
|
|
|
- let updateDoc = await quantity_detail_model.update(query,doc);
|
|
|
- let detailList = await getDatailList(query,returnData);
|
|
|
- if(refreshQuantity==true){
|
|
|
- let quantity = await summateResuts(query,detailList);
|
|
|
- returnData.data.quantity = quantity;
|
|
|
- returnData.data.quantityRefresh = true;
|
|
|
- return returnData;
|
|
|
- }else {
|
|
|
- return null;
|
|
|
- }
|
|
|
- }catch (error){
|
|
|
- console.log(error)
|
|
|
+ let returnObjec={query:query,doc:doc};
|
|
|
+ let decimal =await decimal_facade.getProjectDecimal(query.projectID);
|
|
|
+ let refreshQuantity=false;
|
|
|
+ if(query.refreshQuantity==true){
|
|
|
+ refreshQuantity=true;
|
|
|
}
|
|
|
+ delete query.refreshQuantity;
|
|
|
+ await quantity_detail_model.update(query,doc);
|
|
|
+ let detailList = await getDatailList(query,returnObjec);
|
|
|
+ if(refreshQuantity==true){
|
|
|
+ let data = {};
|
|
|
+ data.quantity = await summateResults(query,detailList,decimal);
|
|
|
+ data.isFromDetail = 1;
|
|
|
+ returnObjec.node.data = data;
|
|
|
+ }
|
|
|
+ return returnObjec;
|
|
|
}
|
|
|
|
|
|
async function getDatailList(query,resultObject) {
|
|
|
let detailList = [];
|
|
|
+ let node={};
|
|
|
if(query.hasOwnProperty('rationID')){
|
|
|
detailList = await quantity_detail_model.find({'projectID':query.projectID,'rationID':query.rationID}).sort('seq').exec();
|
|
|
- resultObject.moduleName = consts.projectConst.RATION;
|
|
|
- resultObject.data.rationID=query.rationID;
|
|
|
-
|
|
|
+ node.type = consts.projectConst.RATION;
|
|
|
+ node.ID = query.rationID;
|
|
|
}else {
|
|
|
detailList = await quantity_detail_model.find({'projectID':query.projectID,'billID':query.billID}).sort('seq').exec();
|
|
|
- resultObject.moduleName = consts.projectConst.BILLS;
|
|
|
- resultObject.data.billID=query.billID;
|
|
|
+ node.type = consts.projectConst.BILLS;
|
|
|
+ node.ID=query.billID;
|
|
|
}
|
|
|
+ resultObject.node = node;
|
|
|
return detailList;
|
|
|
}
|
|
|
|
|
|
|
|
|
-async function doRegexUpdate(datas) {
|
|
|
- let resultObjec ={
|
|
|
- err:null,
|
|
|
- rList:[]
|
|
|
- }
|
|
|
- try {
|
|
|
- let detailList = [];
|
|
|
- let quantityResult ={
|
|
|
- moduleName:'',
|
|
|
- data:{
|
|
|
- updateTpye:commonConsts.UT_UPDATE,
|
|
|
- quantityRefresh:true
|
|
|
- }
|
|
|
- }
|
|
|
- if(datas.query.hasOwnProperty('rationID')){
|
|
|
- detailList = await quantity_detail_model.find({'projectID':datas.query.projectID,'rationID':datas.query.rationID}).sort('seq').exec();
|
|
|
- quantityResult.moduleName = consts.projectConst.RATION;
|
|
|
- quantityResult.data.rationID = datas.query.rationID;
|
|
|
- }else {
|
|
|
- detailList = await quantity_detail_model.find({'projectID':datas.query.projectID,'billID':datas.query.billID}).sort('seq').exec();
|
|
|
- quantityResult.data.billID = datas.query.billID;
|
|
|
- quantityResult.moduleName = consts.projectConst.BILLS;
|
|
|
- }
|
|
|
- let regex;
|
|
|
- let result;
|
|
|
- if(datas.doc.regex==null){
|
|
|
- result=0
|
|
|
- datas.doc.referenceIndexs=[];
|
|
|
- }else {
|
|
|
- regex = datas.doc.regex.toUpperCase();
|
|
|
- let referenceIndexs = datas.doc.referenceIndexs;
|
|
|
- result =getEvalResult(referenceIndexs,detailList,regex);
|
|
|
- }
|
|
|
- detailList[datas.query.index].result =result;
|
|
|
- detailList[datas.query.index].regex=datas.doc.regex;
|
|
|
- detailList[datas.query.index].referenceIndexs =datas.doc.referenceIndexs;
|
|
|
- let updateTasks =[];
|
|
|
- datas.doc.result=result;
|
|
|
- updateTasks.push({
|
|
|
- query:{
|
|
|
- ID:datas.query.ID,
|
|
|
- projectID:datas.query.projectID
|
|
|
- },
|
|
|
- doc:datas.doc
|
|
|
- })
|
|
|
- updateReferenceRecode(datas.query.index+1,detailList,updateTasks);
|
|
|
- let updateEdit = await quantity_detail_model.bulkWrite(generateUpdateTaks(updateTasks));
|
|
|
- resultObjec.rList.push(gernerateResultList(updateTasks));
|
|
|
- if(datas.query.refreshQuantity==true){
|
|
|
- quantityResult.data.quantity = await summateResuts(datas.query,detailList);
|
|
|
- resultObjec.rList.push(quantityResult);
|
|
|
- }
|
|
|
- return resultObjec;
|
|
|
- }catch (error){
|
|
|
- console.log(error);
|
|
|
- resultObjec.err=error;
|
|
|
- return resultObjec
|
|
|
-
|
|
|
- }
|
|
|
-}
|
|
|
-
|
|
|
-function gernerateResultList(updateTasks) {
|
|
|
- let returndata ={
|
|
|
- moduleName:consts.projectConst.QUANTITY_DETAIL,
|
|
|
- data:{
|
|
|
- updateTpye:commonConsts.UT_UPDATE,
|
|
|
- refreshList:updateTasks
|
|
|
- }
|
|
|
- }
|
|
|
- return returndata;
|
|
|
-
|
|
|
-}
|
|
|
-
|
|
|
-
|
|
|
-
|
|
|
function updateReferenceRecode(index,detailList,updateTasks) {
|
|
|
for(let d of detailList){
|
|
|
if(_.includes(d.referenceIndexs,index)){
|
|
@@ -394,34 +329,52 @@ function updateReferenceRecode(index,detailList,updateTasks) {
|
|
|
}
|
|
|
|
|
|
|
|
|
-async function summateResuts (query,detailList) {
|
|
|
+async function summateResults (query,detailList,decimal) {
|
|
|
let quantity = 0;
|
|
|
+ decimal = decimal?decimal:await decimal_facade.getProjectDecimal(query.projectID);
|
|
|
for(let d of detailList){
|
|
|
if(d.isSummation==1){
|
|
|
- let result = d.result==null||d.result==undefined?0:d.result
|
|
|
+ let result = d.result==null||d.result==undefined?0:d.result;
|
|
|
quantity+=result;
|
|
|
}
|
|
|
}
|
|
|
- quantity = quantity.toFixed(4);
|
|
|
if(query.hasOwnProperty('rationID')){
|
|
|
+ let ration = await ration_model.findOne({'ID':query.rationID,'projectID':query.projectID,deleteInfo: null});
|
|
|
+ quantity = getQuantityByUnit(quantity,ration.unit);
|
|
|
+ quantity = scMathUtil.roundTo(quantity, -decimal.ration.quantity);
|
|
|
await ration_model.update({'ID':query.rationID,'projectID':query.projectID,deleteInfo: null},{quantity:quantity,isFromDetail:1});
|
|
|
}else {
|
|
|
+ let bill = await bill_model.findOne({'ID':query.billID,'projectID':query.projectID,deleteInfo: null});
|
|
|
+ decimal = await decimal_facade.getBillsQuantityDecimal(query.projectID,bill.unit);
|
|
|
+ quantity = getQuantityByUnit(quantity,bill.unit);
|
|
|
+ quantity = scMathUtil.roundTo(quantity, -decimal);
|
|
|
await bill_model.update({'ID':query.billID,'projectID':query.projectID,deleteInfo: null},{quantity:quantity,isFromDetail:1});
|
|
|
}
|
|
|
return quantity
|
|
|
}
|
|
|
|
|
|
+function getQuantityByUnit(quantity,unit) {
|
|
|
+ if(unit){
|
|
|
+ let times = parseInt(unit);
|
|
|
+ if(isNaN(times)){
|
|
|
+ times = 1
|
|
|
+ }
|
|
|
+ quantity = quantity/times;
|
|
|
+ }
|
|
|
+ return quantity;
|
|
|
+}
|
|
|
|
|
|
|
|
|
-function getEvalResult(referenceIndexs,detailList,regex) {
|
|
|
+ function getEvalResult(referenceIndexs,detailList,regex,decimal={}) {
|
|
|
try {
|
|
|
+ decimal = decimal.quantity_detail?decimal.quantity_detail:4;
|
|
|
for(let i of referenceIndexs){
|
|
|
regex = replaceReference(i,detailList,regex)
|
|
|
}
|
|
|
console.log('replace all C reference -----'+regex);
|
|
|
regex =replaceSqr(regex);
|
|
|
console.log('replace all sqar reference -----'+regex);
|
|
|
- return scMathUtil.roundTo(eval(regex), -4);
|
|
|
+ return scMathUtil.roundTo(eval(regex), -decimal);
|
|
|
}catch (error){
|
|
|
console.log(error);
|
|
|
throw new Error('输入的表达式有误,请重新输入!');
|
|
@@ -492,26 +445,6 @@ function converSqrByArr (sqararr,text) {
|
|
|
return temp;
|
|
|
};
|
|
|
|
|
|
-
|
|
|
-function updateRecored(query,doc,callback) {
|
|
|
- quantity_detail_model.update(query,doc,(err,result)=>{
|
|
|
- if(err){
|
|
|
- callback(err,'');
|
|
|
- }else {
|
|
|
- let returndata ={
|
|
|
- moduleName:consts.projectConst.QUANTITY_DETAIL,
|
|
|
- data:{
|
|
|
- updateTpye:commonConsts.UT_UPDATE,
|
|
|
- query:query,
|
|
|
- doc:doc
|
|
|
- }
|
|
|
- }
|
|
|
- callback(null,returndata);
|
|
|
- }
|
|
|
- })
|
|
|
-}
|
|
|
-
|
|
|
-
|
|
|
function update_quantity_detail(user_id,datas) {
|
|
|
if(datas.updateFunction){
|
|
|
return updateFunctionMap[datas.updateFunction](user_id,datas);
|
|
@@ -520,57 +453,43 @@ function update_quantity_detail(user_id,datas) {
|
|
|
}
|
|
|
}
|
|
|
|
|
|
-function delete_quantity_detail(user_id,datas) {
|
|
|
- return function (callback) {
|
|
|
- doQuantityDelete(datas.doc).then(function (result) {
|
|
|
- if(result.err){
|
|
|
- callback(result.err,'')
|
|
|
- }else {
|
|
|
- callback(null,result.returndata)
|
|
|
- }
|
|
|
- });
|
|
|
- }
|
|
|
-}
|
|
|
|
|
|
-async function doQuantityDelete(doc) {;
|
|
|
- let result={
|
|
|
- err:null
|
|
|
+async function deleteRecode(doc) {
|
|
|
+ let resultObject = {};
|
|
|
+ let decimal =await decimal_facade.getProjectDecimal(doc.projectID);
|
|
|
+
|
|
|
+ let query = {
|
|
|
+ projectID:doc.projectID,
|
|
|
+ seq : { $gt: doc.seq }
|
|
|
}
|
|
|
- try{
|
|
|
- let query = {
|
|
|
- projectID:doc.projectID,
|
|
|
- seq : { $gt: doc.seq }
|
|
|
- }
|
|
|
- if(doc.hasOwnProperty('rationID')){
|
|
|
- query.rationID = doc.rationID;
|
|
|
- }else {
|
|
|
- query.billID = doc.billID;
|
|
|
- }
|
|
|
- let quantity_detail_List = await getDatailList(doc,{data:{}});
|
|
|
- let update_task = getUpdateReferenceTask(quantity_detail_List,doc.seq,-1);
|
|
|
- await quantity_detail_model.update(query,{$inc:{seq:-1}},{multi: true});
|
|
|
- if(update_task.length>0){
|
|
|
- await quantity_detail_model.bulkWrite(generateUpdateTaks(update_task));
|
|
|
- }
|
|
|
- await quantity_detail_model.deleteOne({ID:doc.ID,projectID:doc.projectID});
|
|
|
- let returndata ={
|
|
|
- moduleName:consts.projectConst.QUANTITY_DETAIL,
|
|
|
- data:{
|
|
|
- doc:doc,
|
|
|
- resort:true,
|
|
|
- update_task:update_task,
|
|
|
- updateTpye:commonConsts.UT_DELETE
|
|
|
- }
|
|
|
- };
|
|
|
- result.returndata =returndata
|
|
|
- return result;
|
|
|
- }catch (error){
|
|
|
- console.log(error)
|
|
|
- result.err;
|
|
|
- return result
|
|
|
+ if(doc.hasOwnProperty('rationID')){
|
|
|
+ query.rationID = doc.rationID;
|
|
|
+ }else {
|
|
|
+ query.billID = doc.billID;
|
|
|
}
|
|
|
+ let quantity_detail_List = await getDatailList(doc,resultObject);
|
|
|
+ let update_task = getUpdateReferenceTask(quantity_detail_List,doc.seq,-1);
|
|
|
+ await quantity_detail_model.update(query,{$inc:{seq:-1}},{multi: true});
|
|
|
+ if(update_task.length>0){
|
|
|
+ await quantity_detail_model.bulkWrite(generateUpdateTaks(update_task));
|
|
|
+ }
|
|
|
+ await quantity_detail_model.deleteOne({ID:doc.ID,projectID:doc.projectID});
|
|
|
+ _.remove(quantity_detail_List,{ID:doc.ID,projectID:doc.projectID});
|
|
|
+
|
|
|
+ let n_data = {};//更新节点信息
|
|
|
+ n_data.quantity = await summateResults(query,quantity_detail_List,decimal);
|
|
|
+ n_data.isFromDetail = 1;
|
|
|
+ resultObject.node.data = n_data;
|
|
|
+
|
|
|
+ let r_data ={
|
|
|
+ doc:doc,
|
|
|
+ resort:true,
|
|
|
+ update_task:update_task,
|
|
|
+ updateTpye:commonConsts.UT_DELETE
|
|
|
+ };
|
|
|
+ resultObject.data = r_data;
|
|
|
|
|
|
-
|
|
|
+ return resultObject;
|
|
|
}
|
|
|
|
|
|
|