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