ration_glj_facade.js 23 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726
  1. /**
  2. * Created by chen on 2017/6/29.
  3. */
  4. let mongoose = require('mongoose');
  5. const uuidV1 = require('uuid/v1');
  6. let consts = require('../../main/models/project_consts')
  7. let commonConsts = consts.commonConst;
  8. let _=require("lodash");
  9. let ration_glj = mongoose.model('ration_glj');
  10. import GLJListModel from '../../glj/models/glj_list_model';
  11. let std_glj_lib_gljList_model = mongoose.model('std_glj_lib_gljList');
  12. let async_n = require("async");
  13. let ration = mongoose.model('ration');
  14. let ration_coe_facade = require('./ration_coe_facade');
  15. let ration_coe = mongoose.model('ration_coe');
  16. let std_ration_lib_ration_items = mongoose.model('std_ration_lib_ration_items');
  17. let glj_calculate_facade = require('./glj_calculate_facade');
  18. let quantity_detail_facade = require('./quantity_detail_facade');
  19. let logger = require("../../../logs/log_helper").logger;
  20. import stdgljutil from "../../../public/cache/std_glj_type_util";
  21. import EngineeringLibModel from "../../users/models/engineering_lib_model";
  22. import GljDao from "../../complementary_glj_lib/models/gljModel";
  23. module.exports={
  24. save:save,
  25. getData:getData,
  26. deleteByRation:deleteByRation,
  27. getQuantityByProjectGLJ:getQuantityByProjectGLJ,
  28. getLibInfo:getLibInfo,
  29. getGLJData:getGLJData,
  30. addGLJ:addGLJ,
  31. replaceGLJ:replaceGLJ,
  32. mReplaceGLJ:mReplaceGLJ
  33. }
  34. let operationMap={
  35. 'ut_create':create_ration_glj,
  36. 'ut_update':update_ration_glj,
  37. 'ut_delete':delete_ration_glj
  38. };
  39. let updateFunctionMap = {
  40. 'normalUpdate':normalUpdate,
  41. 'marketPriceAdjustUpdate':marketPriceAdjustUpdate,
  42. 'customQuantityUpdate':customQuantityUpdate
  43. };
  44. /**
  45. * 根据项目工料机ID和项目ID取消耗量
  46. *
  47. * @param {object} condition
  48. * @return Array
  49. */
  50. async function getQuantityByProjectGLJ(condition) {
  51. let query ={
  52. $and:[
  53. {'projectID':condition.projectID},
  54. {'projectGLJID':{$in:condition.projectGLJIDList}}
  55. ]
  56. }
  57. let results = await ration_glj.find(query,['projectGLJID','quantity','rationID'],{sort: {projectGLJID: 1}});
  58. let rationList = _.uniq(_.map(results,'rationID'));
  59. let rationQuery={
  60. $and:[
  61. {'projectID':condition.projectID},
  62. {'ID':{$in:rationList}},
  63. {'deleteInfo': null}
  64. ]
  65. }
  66. let rations = await ration.find(rationQuery,['ID','quantity']);
  67. return combineQuantity(results,rations);
  68. }
  69. function combineQuantity(results,rations) {
  70. let resultList=[];
  71. _.forEach(results,function (data) {
  72. let tmp = {
  73. projectGLJID:data.projectGLJID,
  74. quantity: data.quantity
  75. }
  76. let ration=_.find(rations,{ID:data.rationID});
  77. if(ration){
  78. tmp.rationID=ration.ID;
  79. tmp.rationQuantity=ration.quantity?Number(ration.quantity):undefined;
  80. }
  81. resultList.push(tmp);
  82. /* if(resultMap.hasOwnProperty(data.projectGLJID)){
  83. resultMap[data.projectGLJID] += data.quantity;
  84. }else {
  85. resultMap[data.projectGLJID] = data.quantity;
  86. }*/
  87. });
  88. /* var resultList =[];
  89. for(let key in resultMap){
  90. let newObject = {
  91. 'projectGLJID':key,
  92. 'quantity':resultMap[key]
  93. }
  94. resultList.push(newObject)
  95. }*/
  96. return resultList;
  97. }
  98. function get_lib_glj_info(ration_glj) {
  99. return function (result,cb) {
  100. std_glj_lib_gljList_model.findOne({'ID':ration_glj.GLJID},(err,glj)=>{
  101. if(err){
  102. cb(err,'')
  103. }else if(glj){
  104. ration_glj.name = glj.name;
  105. ration_glj.code = glj.code;
  106. ration_glj.unit = glj.unit;
  107. ration_glj.specs = glj.specs;
  108. ration_glj.basePrice = glj.basePrice;
  109. ration_glj.shortName = glj.shortName;
  110. ration_glj.type = glj.gljType;
  111. ration_glj.repositoryId = glj.repositoryId;
  112. getInfoFromProjectGLJ(ration_glj).then(function (info) {
  113. if(info){
  114. let tem={};
  115. tem.newRecode=createNewRecord(info);
  116. tem.showData=info;
  117. result.datas.push(tem);
  118. cb(null,result);
  119. }else {
  120. cb(new Error('get project glj error'),null);
  121. }
  122. });
  123. }else {
  124. cb(null,null);
  125. }
  126. })
  127. }
  128. }
  129. function createNewRecord(ration_glj) {
  130. let newRecoed={};
  131. newRecoed.ID=ration_glj.ID;
  132. newRecoed.projectID=ration_glj.projectID;
  133. newRecoed.GLJID=ration_glj.GLJID;
  134. newRecoed.rationID=ration_glj.rationID;
  135. newRecoed.rationItemQuantity=ration_glj.rationItemQuantity;
  136. newRecoed.quantity=ration_glj.quantity;
  137. newRecoed.name = ration_glj.name;
  138. newRecoed.code = ration_glj.code;
  139. newRecoed.unit = ration_glj.unit;
  140. newRecoed.specs = ration_glj.specs;
  141. newRecoed.from=ration_glj.from?ration_glj.from:undefined;
  142. newRecoed.createType=ration_glj.createType?ration_glj.createType:undefined;
  143. newRecoed.shortName = ration_glj.shortName;
  144. newRecoed.billsItemID=ration_glj.billsItemID,
  145. newRecoed.type = ration_glj.type;
  146. newRecoed.repositoryId = ration_glj.repositoryId;
  147. newRecoed.projectGLJID=ration_glj.projectGLJID;
  148. return newRecoed
  149. }
  150. async function getInfoFromProjectGLJ(ration_glj) {
  151. let data = getGLJSearchInfo(ration_glj);
  152. try {
  153. let projectGljModel = new GLJListModel();
  154. let result = await projectGljModel.addList(data);
  155. ration_glj.marketPrice=result.unit_price.market_price;
  156. ration_glj.adjustPrice=result.unit_price.base_price;
  157. ration_glj.basePrice=result.unit_price.base_price;
  158. ration_glj.projectGLJID=result.id;
  159. ration_glj.isEstimate=result.is_evaluate;
  160. return ration_glj;
  161. } catch (err) {
  162. logger.err(err);
  163. return null;
  164. }
  165. }
  166. function create_ration_glj(user_id,datas) {
  167. return function (callback) {
  168. let ration_glj_list=datas.ration_glj_list;
  169. var tasks=[];
  170. tasks.push(startingTask("get glj info"))
  171. for(let i =0;i<ration_glj_list.length;i++){
  172. ration_glj_list[i].ID = uuidV1();
  173. tasks.push(get_lib_glj_info(ration_glj_list[i]))
  174. }
  175. async_n.waterfall(tasks,(err,results)=>{
  176. if(err){
  177. callback(err,results)
  178. }else {
  179. let newRecords =[];
  180. let showDatas=[];
  181. for (let r of results.datas){
  182. if(r){
  183. newRecords.push(r.newRecode);
  184. showDatas.push(r.showData);
  185. }
  186. }
  187. if(newRecords.length>0){
  188. ration_glj.insertMany(newRecords,(err,doc)=>{
  189. if(err){
  190. callback(err,null);
  191. }else {
  192. let returndata ={
  193. updateTpye:commonConsts.UT_CREATE,
  194. moduleName:'ration_glj',
  195. data:{
  196. newRecords:newRecords,
  197. showDatas:showDatas
  198. }
  199. }
  200. callback(null,returndata)
  201. }
  202. });
  203. }else {
  204. logger.info("can't find gljs")
  205. callback(null,null)
  206. }
  207. }
  208. })
  209. }
  210. }
  211. function update_ration_glj(user_id,datas) {
  212. if(datas.updateFunction){
  213. return updateFunctionMap[datas.updateFunction](user_id,datas);
  214. }else {
  215. return normalUpdate(user_id,datas);
  216. }
  217. }
  218. function normalUpdate(user_id,datas){
  219. return function(callback) {
  220. ration_glj.update(datas.query,datas.doc,(err,result)=>{
  221. if(err){
  222. callback(err,'');
  223. }else {
  224. let returndata ={
  225. moduleName:'ration_glj',
  226. data:{
  227. updateTpye:commonConsts.UT_UPDATE,
  228. query:datas.query,
  229. doc:datas.doc
  230. }
  231. }
  232. callback(null,returndata)
  233. }
  234. })
  235. }
  236. }
  237. function customQuantityUpdate(user_id,datas){
  238. return function(callback) {
  239. doCustomQuantityUpdate(datas).then((result)=>{
  240. if(result.err){
  241. callback(result.err,'');
  242. }else {
  243. let ration_glj_data ={
  244. moduleName:'ration_glj',
  245. data:{
  246. updateTpye:commonConsts.UT_UPDATE,
  247. quantityRefresh:true,
  248. glj_result:result.cal_result.glj_result
  249. }
  250. };
  251. let ration_data ={
  252. moduleName:'ration',
  253. data:{
  254. updateTpye:commonConsts.UT_UPDATE,
  255. stateRefresh:true,
  256. rationID:result.cal_result.rationID,
  257. adjustState:result.cal_result.adjustState
  258. }
  259. };
  260. callback(null,[ration_glj_data,ration_data]);
  261. }
  262. })
  263. }
  264. }
  265. async function doCustomQuantityUpdate(datas){
  266. let result = {
  267. err:null
  268. }
  269. try{
  270. await ration_glj.update(datas.query,datas.doc);
  271. let cal_result = await glj_calculate_facade.calculateQuantity({projectID:datas.query.projectID,rationID:datas.query.rationID});
  272. cal_result.glj_result.forEach(function (item) {
  273. if(!item.doc.hasOwnProperty('customQuantity')){
  274. item.doc.customQuantity=null;
  275. }
  276. });
  277. result.cal_result =cal_result;
  278. console.log(result);
  279. return result;
  280. }catch (err){
  281. result.err = err;
  282. console.log(err);
  283. return result;
  284. }
  285. }
  286. function marketPriceAdjustUpdate(user_id,datas) {
  287. return function (callback) {
  288. updateprojectGljAndRationGLJ(datas.query,datas.doc).then((result)=>{
  289. if(result.err){
  290. callback(result.err,'');
  291. }else {
  292. let returndata ={
  293. moduleName:'ration_glj',
  294. data:{
  295. updateTpye:commonConsts.UT_UPDATE,
  296. query:datas.query,
  297. doc:result.doc
  298. }
  299. };
  300. let ration_data ={
  301. moduleName:'ration',
  302. data:{
  303. updateTpye:commonConsts.UT_UPDATE,
  304. stateRefresh:true,
  305. rationID:datas.query.rationID,
  306. adjustState:result.adjustState
  307. }
  308. }
  309. callback(null,[returndata,ration_data]);
  310. }
  311. })
  312. }
  313. }
  314. async function updateprojectGljAndRationGLJ(query,doc) {
  315. let returnresult={};
  316. try {
  317. let gljListModel = new GLJListModel();
  318. let temp = doc.market_price;
  319. if(doc.market_price==null){
  320. doc.market_price = doc.base_price;
  321. }
  322. delete doc.base_price;
  323. let result = await gljListModel.modifyMarketPrice(doc);
  324. let updateDoc ={
  325. marketPrice:result.unit_price.market_price,
  326. marketPriceAdjust:temp,
  327. projectGLJID:result.id,
  328. isEstimate:result.is_evaluate,
  329. name : result.name,
  330. code:result.code
  331. };
  332. let updateresult = await ration_glj.findOneAndUpdate(query, updateDoc);
  333. let stateResult = await glj_calculate_facade.calculateQuantity({projectID:query.projectID,rationID:query.rationID},true);
  334. returnresult ={
  335. err:null,
  336. doc :updateDoc,
  337. adjustState:stateResult.adjustState
  338. }
  339. return returnresult;
  340. } catch (error) {
  341. returnresult.err = error;
  342. console.log(error);
  343. return returnresult
  344. }
  345. }
  346. function delete_ration_glj(user_id,datas) {
  347. return function (callback) {
  348. if(datas.deleteType=="RATION"){
  349. deleteByRation(datas,callback);
  350. }else if(datas.deleteType=="BILL"){
  351. deleteByBill(user_id,datas,callback);
  352. } else{
  353. deleteByID(datas,callback);
  354. }
  355. }
  356. }
  357. function deleteByRation(datas,callback) {
  358. let data = datas.updateData;
  359. let tasks=[];
  360. tasks.push(deleteGLJList(data));
  361. tasks.push(ration_coe_facade.delete_ration_coe(data));
  362. tasks.push(quantity_detail_facade.deleteByRation(data));
  363. async_n.parallel(tasks,function (err,result) {
  364. commonCallback(callback,result,err)
  365. })
  366. }
  367. function deleteGLJList(data) {
  368. return function (callback) {
  369. ration_glj.deleteMany({projectID: data.projectID, rationID: data.ID},(err,result)=>{
  370. commonCallback(callback,result,err)
  371. });
  372. }
  373. }
  374. function deleteByBill(user_id,datas,callback) {
  375. let tasks = [];
  376. tasks.push(startingTask("deleteByBill"));
  377. tasks.push(getRationsByBill(datas));
  378. tasks.push(deleteRationsbyBill(user_id,datas));
  379. tasks.push(deleteByMultiRations(datas));
  380. async_n.waterfall(tasks,function (err,results) {
  381. if(err){
  382. callback(err,'');
  383. }else {
  384. callback(null,results);
  385. }
  386. })
  387. }
  388. function deleteByID(datas,callback){
  389. deleteAndUpdateState(datas).then(function (result) {
  390. if(result.err){
  391. callback(result.err,'');
  392. }else {
  393. let returndata ={
  394. moduleName:'ration_glj',
  395. data:{
  396. updateTpye:commonConsts.UT_DELETE,
  397. query:datas.query,
  398. adjustState:result.adjustState
  399. }
  400. }
  401. callback(null,returndata)
  402. }
  403. })
  404. }
  405. async function deleteAndUpdateState(datas) {
  406. let result={
  407. err:null
  408. }
  409. try {
  410. await ration_glj.deleteOne(datas.query);
  411. let stateResult = await glj_calculate_facade.calculateQuantity({projectID:datas.query.projectID,rationID:datas.doc.rationID});
  412. result.adjustState=stateResult.adjustState;
  413. }catch (err){
  414. result.err=err;
  415. }
  416. return result;
  417. }
  418. function startingTask(processName){
  419. return function(asyncCallBack){
  420. var result = {
  421. processName : processName,
  422. datas:[]
  423. };
  424. asyncCallBack(null, result);
  425. };
  426. }
  427. function getRationsByBill(datas) {
  428. return function (results,callback) {
  429. ration.find({projectID:datas.updateData.projectID,billsItemID:datas.updateData.ID,deleteInfo: null},function (err,rations) {
  430. if(err){
  431. callback(err,'')
  432. }else {
  433. results.rations=rations;
  434. callback(null,results)
  435. }
  436. })
  437. }
  438. }
  439. function deleteRationsbyBill (user_id,datas){
  440. return function (results,callback) {
  441. let deleteInfo ={
  442. deleteInfo :{deleted: true, deleteDateTime: new Date(), deleteBy: user_id}
  443. };
  444. ration.update({projectID: datas.updateData.projectID, billsItemID:datas.updateData.ID},deleteInfo,{multi: true},(err,deleteresults)=>{
  445. if(err){
  446. callback(err,'');
  447. }else {
  448. callback(null,results);
  449. }
  450. });
  451. }
  452. }
  453. function deleteByMultiRations(datas) {
  454. return function (results,deleteCallBack) {
  455. var delete_tasks = [];
  456. var deleteOne=function (ration) {
  457. return function (callback) {
  458. ration_glj.deleteMany({projectID: ration.projectID, rationID: ration.ID},function (err,result) {
  459. commonCallback(callback,result,err)
  460. });
  461. }
  462. }
  463. let rations = results.rations;
  464. for(let i=0;i<rations.length;i++){
  465. delete_tasks.push(deleteOne(rations[i]._doc));
  466. delete_tasks.push(ration_coe_facade.delete_ration_coe(rations[i]._doc));
  467. delete_tasks.push(quantity_detail_facade.deleteByRation(rations[i]._doc));
  468. }
  469. delete_tasks.push(quantity_detail_facade.deleteByBill(datas.updateData));
  470. async_n.parallel(delete_tasks,(err,results)=>{
  471. if (err){
  472. deleteCallBack(err,'')
  473. }else {
  474. deleteCallBack(null,results)
  475. }
  476. })
  477. }
  478. }
  479. /*
  480. function deleteByRation(doc) {
  481. return function (callback){
  482. ration_glj.deleteMany({projectID: doc.updateData.projectID, rationID: doc.updateData.ID},callback);
  483. }
  484. }
  485. */
  486. function save (user_id, datas, callback) {
  487. let operations=[];
  488. if(_.isArray(datas)){
  489. for(let i=0;i<datas.length;i++){
  490. operations.push(operationMap[datas[i].updateType](user_id,datas[i]));
  491. }
  492. }else {
  493. operations.push(operationMap[datas.updateType](user_id,datas));
  494. }
  495. async_n.parallel(operations,function (err,results) {
  496. if(err){
  497. callback(err,'');
  498. }else {
  499. if(results.length==1){
  500. callback(null,results[0])
  501. }else {
  502. callback(null,results)
  503. }
  504. }
  505. })
  506. }
  507. async function getLibInfo(req){
  508. let gljLibId = null, engineeringId, sessionCompilation = req.session.sessionCompilation,
  509. rationValuation = sessionCompilation.ration_valuation,
  510. billValuation = sessionCompilation.bill_valuation,
  511. engineeringLibModel = new EngineeringLibModel();
  512. if(rationValuation[0]){
  513. let engineeringList = rationValuation[0].engineering_list;
  514. engineeringId = engineeringList.length > 0 ? engineeringList[0].engineering_id : null;
  515. let engineeringInfo = await engineeringLibModel.getEngineering(engineeringId);
  516. gljLibId = engineeringInfo.glj_lib.length > 0 && typeof engineeringInfo.glj_lib !== 'undefined' ? engineeringInfo.glj_lib[0].id : null;
  517. }
  518. else if(billValuation[0]){
  519. let engineeringList = billValuation[0].engineering_list;
  520. engineeringId = engineeringList.length > 0 ? engineeringList[0].engineering_id : null;
  521. let engineeringInfo = await engineeringLibModel.getEngineering(engineeringId);
  522. gljLibId = engineeringInfo.glj_lib.length > 0 && typeof engineeringInfo.glj_lib !== 'undefined' ? engineeringInfo.glj_lib[0].id : null;
  523. }
  524. let data = {
  525. userID: req.session.sessionUser.ssoId,
  526. gljLibId: gljLibId,
  527. compilationId: sessionCompilation._id
  528. };
  529. return data;
  530. }
  531. function getGLJData(info,callback) {
  532. let gljDao = new GljDao();
  533. let datas={};
  534. let gljDistTypeCache = stdgljutil.getStdGljTypeCacheObj().toArray();
  535. datas.distTypeTree=gljDistTypeCache;
  536. async_n.parallel([
  537. function (cb) {
  538. gljDao.getGljTypes(info.gljLibId,function (err,data) {
  539. if(err){
  540. cb(err);
  541. }else {
  542. datas.treeData=data;
  543. cb(null);
  544. }
  545. })
  546. },
  547. function (cb) {
  548. gljDao.getGljItems(info.gljLibId,info.userID,info.compilationId, function (err,data) {
  549. if(err){
  550. cb(err);
  551. }else {
  552. datas.stdGLJ=data.stdGljs;
  553. datas.complementaryGLJs=data.complementaryGljs;
  554. cb(null);
  555. }
  556. });
  557. }
  558. ], function (err) {
  559. if(err){
  560. callback(true, null);
  561. }
  562. else{
  563. callback(false, datas);
  564. }
  565. })
  566. }
  567. function getGLJSearchInfo(ration_glj) {
  568. let data = {
  569. glj_id: ration_glj.GLJID,
  570. project_id: ration_glj.projectID,
  571. code: ration_glj.code,
  572. name: ration_glj.name,
  573. shortName:ration_glj.shortName,
  574. specs: ration_glj.specs,
  575. unit: ration_glj.unit,
  576. type: ration_glj.type,
  577. type_of_work: ration_glj.type,
  578. base_price: ration_glj.basePrice,
  579. market_price: ration_glj.basePrice,
  580. repositoryId:ration_glj.repositoryId,
  581. from:ration_glj.from?ration_glj.from:'std'//std:标准工料机库, cpt:补充工料机库
  582. };
  583. return data;
  584. }
  585. async function addGLJ(rgList) {
  586. let newRecodes = [];
  587. for(let g of rgList){
  588. let projectGljModel = new GLJListModel();
  589. let result = await projectGljModel.addList(getGLJSearchInfo(g));
  590. g.marketPrice=result.unit_price.market_price;
  591. g.adjustPrice=result.unit_price.base_price;
  592. g.basePrice=result.unit_price.base_price;
  593. g.projectGLJID=result.id;
  594. g.isEstimate=result.is_evaluate;
  595. g.ID=uuidV1();
  596. newRecodes.push(createNewRecord(g));
  597. }
  598. await ration_glj.insertMany(newRecodes);
  599. let stateResult = await glj_calculate_facade.calculateQuantity({projectID:rgList[0].projectID,rationID:rgList[0].rationID});
  600. let result={
  601. newRecodes:newRecodes,
  602. showData:rgList,
  603. adjustState:stateResult.adjustState
  604. }
  605. return result;
  606. }
  607. async function replaceGLJ(data) {
  608. let rdata={};
  609. let projectGljModel = new GLJListModel();
  610. let result = await projectGljModel.addList(getGLJSearchInfo(data));
  611. data.marketPrice=result.unit_price.market_price;
  612. data.adjustPrice=result.unit_price.base_price;
  613. data.basePrice=result.unit_price.base_price;
  614. data.projectGLJID=result.id;
  615. data.isEstimate=result.is_evaluate;
  616. let updateResult=await ration_glj.findOneAndUpdate({ID:data.ID,projectID:data.projectID},data);
  617. let stateResult = await glj_calculate_facade.calculateQuantity({projectID:data.projectID,rationID:data.rationID});
  618. rdata.data=data;
  619. rdata.adjustState=stateResult.adjustState;
  620. return rdata;
  621. }
  622. async function mReplaceGLJ(data) {
  623. let mresult={};
  624. let projectGljModel = new GLJListModel();
  625. let result = await projectGljModel.addList(getGLJSearchInfo(data.doc));
  626. data.doc.marketPrice=result.unit_price.market_price;
  627. data.doc.adjustPrice=result.unit_price.base_price;
  628. data.doc.basePrice=result.unit_price.base_price;
  629. data.doc.projectGLJID=result.id;
  630. data.doc.isEstimate=result.is_evaluate;
  631. let rationList=await ration_glj.distinct('rationID',data.query);
  632. let updateResult=await ration_glj.update(data.query,data.doc,{multi: true});
  633. let stateList= await changAdjustState(data,rationList);
  634. mresult.data=data;
  635. mresult.stateList=stateList;
  636. return mresult
  637. }
  638. async function changAdjustState(data,rationList) {
  639. let stateList=[];
  640. for(let r of rationList){
  641. let stateResult = await glj_calculate_facade.calculateQuantity({projectID:data.query.projectID,rationID:r});
  642. stateList.push({rationID:r,adjustState:stateResult.adjustState});
  643. }
  644. return stateList;
  645. }
  646. async function testError() {
  647. throw new Error('test Error');
  648. }
  649. function getData(projectID, callback) {
  650. ration_glj.find({'projectID':projectID},(err,datas)=>{
  651. if(err){
  652. callback(1, '', null);
  653. }else {
  654. callback(0, consts.projectConst.RATION_GLJ, datas);
  655. }
  656. })
  657. }
  658. function commonCallback(callback,result,err) {
  659. if(err){
  660. callback(err,'');
  661. }else {
  662. callback(null,result);
  663. }
  664. }