ration_glj_facade.js 22 KB

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