glj_list_model.js 23 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638
  1. /**
  2. * 项目工料机列表数据模型
  3. *
  4. * @author CaiAoLin
  5. * @date 2017/6/22
  6. * @version
  7. */
  8. import BaseModel from "../../common/base/base_model";
  9. import {default as GLJSchemas, collectionName as gljCollectionName} from "./schemas/glj";
  10. import CounterModel from "./counter_model";
  11. import UnitPriceModel from "./unit_price_model";
  12. import UnitPriceFileModel from "./unit_price_file_model";
  13. import GLJTypeConst from "../../common/const/glj_type_const";
  14. import RationGLJFacade from "../../ration_glj/facade/ration_glj_facade";
  15. import STDGLJLibGLJListModel from "../../common/std/std_glj_lib_glj_list_model";
  16. import MixRatioModel from "./mix_ratio_model";
  17. import GljModel from "../../complementary_glj_lib/models/gljModel";
  18. const ProjectModel = require('../../pm/models/project_model').project;
  19. const scMathUtil = require('../../../public/scMathUtil').getUtil();
  20. class GLJListModel extends BaseModel {
  21. /**
  22. * 材料、主材、设备类型id
  23. *
  24. * @var {Array}
  25. */
  26. materialIdList = [GLJTypeConst.GENERAL_MATERIAL, GLJTypeConst.CONCRETE, GLJTypeConst.MORTAR, GLJTypeConst.MIX_RATIO,
  27. GLJTypeConst.COMMERCIAL_CONCRETE, GLJTypeConst.COMMERCIAL_MORTAR, GLJTypeConst.MAIN_MATERIAL,
  28. GLJTypeConst.EQUIPMENT];
  29. /**
  30. * 拥有组成物的工料机类型id
  31. *
  32. * @var {Array}
  33. */
  34. ownCompositionTypes = [GLJTypeConst.CONCRETE, GLJTypeConst.MORTAR, GLJTypeConst.MIX_RATIO,
  35. GLJTypeConst.COMMERCIAL_CONCRETE, GLJTypeConst.COMMERCIAL_MORTAR, GLJTypeConst.GENERAL_MACHINE];
  36. /**
  37. * 构造函数
  38. *
  39. * @return {void}
  40. */
  41. constructor() {
  42. let parent = super();
  43. parent.model = GLJSchemas;
  44. parent.init();
  45. }
  46. /**
  47. * 设置场景
  48. *
  49. * @param {string} scene
  50. * @return {void}
  51. */
  52. setScene(scene = '') {
  53. switch (scene) {
  54. // 新增数据的验证规则
  55. case 'add':
  56. this.model.schema.path('glj_id').required(true);
  57. this.model.schema.path('project_id').required(true);
  58. this.model.schema.path('code').required(true);
  59. // this.model.schema.path('name').required(true);
  60. break;
  61. }
  62. }
  63. /**
  64. * 根据标段对应项目工料机列表
  65. *
  66. * @param {Number} projectId
  67. * @param {Number} unitPriceFileId
  68. * @return {Promise}
  69. */
  70. async getListByProjectId(projectId, unitPriceFileId) {
  71. let gljData = null;
  72. let mixRatioConnectData = {};
  73. let mixRationMap={};
  74. try {
  75. // 首先获取对应标段下所有的项目工料机数据
  76. let condition = {project_id: projectId};
  77. let fields = {_id: 0};
  78. gljData = await this.db.find(condition, fields);
  79. // 没有数据则直接返回空
  80. if (gljData.length <= 0) {
  81. throw '无数据';
  82. }
  83. // 获取标段设置的单价文件数据
  84. let unitPriceModel = new UnitPriceModel();
  85. let unitPriceList = await unitPriceModel.getDataByFileId(unitPriceFileId);
  86. // 整理获取工料机ID list
  87. let gljIdList = [];
  88. for(let tmp of gljData) {
  89. gljIdList.push(tmp.id);
  90. }
  91. // 从定额工料机库中获取消耗量
  92. condition = {
  93. projectID: projectId,
  94. projectGLJIDList: gljIdList
  95. };
  96. let quantityData = await RationGLJFacade.getQuantityByProjectGLJ(condition);
  97. let quantityList = {};
  98. // 整理数据
  99. for (let tmp of quantityData) {
  100. let tmpNum = parseFloat(tmp.rationQuantity);
  101. tmpNum = isNaN(tmpNum) ? 1 : tmpNum;
  102. if (quantityList[tmp.projectGLJID] === undefined) {
  103. quantityList[tmp.projectGLJID] = tmp.quantity * tmpNum;
  104. } else {
  105. quantityList[tmp.projectGLJID] += tmp.quantity * tmpNum;
  106. }
  107. }
  108. // 整理获取有组成物的项目工料机编码
  109. let projectGLJCode = [];
  110. for(let tmp of gljData) {
  111. // 有组成物的类型且消耗量大于0才查找
  112. if (quantityList[tmp.id] !== undefined) {
  113. projectGLJCode.push(tmp.code);
  114. }
  115. }
  116. // 查找组成物的消耗量
  117. let totalComposition = {};
  118. let mixRatioData = {};
  119. if (projectGLJCode.length > 0) {
  120. let mixRatioModel = new MixRatioModel();
  121. condition = {connect_code: {"$in": projectGLJCode}, unit_price_file_id: unitPriceFileId};
  122. let mixRatioList = await mixRatioModel.findDataByCondition(condition, null, false);
  123. for (let tmp of mixRatioList) {
  124. totalComposition[tmp.connect_code] = totalComposition[tmp.connect_code] === undefined ? tmp.consumption :
  125. totalComposition[tmp.connect_code] + tmp.consumption;
  126. totalComposition[tmp.connect_code] = scMathUtil.roundTo(totalComposition[tmp.connect_code], -4);
  127. if (mixRatioData[tmp.glj_id] !== undefined) {
  128. mixRatioData[tmp.glj_id].push(tmp);
  129. } else {
  130. mixRatioData[tmp.glj_id] = [tmp];
  131. }
  132. if(mixRationMap[tmp.connect_code]!=undefined){
  133. mixRationMap[tmp.connect_code].push(tmp);
  134. }else {
  135. mixRationMap[tmp.connect_code]=[tmp];
  136. }
  137. if (mixRatioConnectData[tmp.glj_id] !== undefined) {
  138. mixRatioConnectData[tmp.glj_id].push(tmp.connect_code);
  139. } else {
  140. mixRatioConnectData[tmp.glj_id] = [tmp.connect_code];
  141. }
  142. }
  143. }
  144. // 组合单价数据
  145. gljData = this.combineData(gljData, unitPriceList, quantityList, mixRatioData, totalComposition);
  146. // 排序
  147. gljData.sort(function (a, b) {
  148. a.unit_price = a.unit_price === null ? 0 : a.unit_price;
  149. b.unit_price = b.unit_price === null ? 0 : b.unit_price;
  150. return a.unit_price.type - b.unit_price.type;
  151. });
  152. } catch (error) {
  153. console.log("glj_list_model:" + error);
  154. gljData = [];
  155. }
  156. return [gljData, mixRatioConnectData,mixRationMap];
  157. }
  158. /**
  159. * 组合工料机数据和单价文件数据
  160. *
  161. * @param {object} gljList
  162. * @param {object} unitPriceList
  163. * @param {object} quantityList
  164. * @param {object} mixRatioData 组合物明细数据
  165. * @param {object} totalComposition 组合物父工料机统计数据
  166. * @return {Array}
  167. */
  168. combineData(gljList, unitPriceList, quantityList = {}, mixRatioData = {}, totalComposition = {}) {
  169. // 整理组成物消耗量(只有在总列表显示的时候才需用到,获取单项项目工料机内容则忽略)
  170. let compositionConsumption = {};
  171. if (Object.keys(mixRatioData).length > 0 && Object.keys(totalComposition).length > 0) {
  172. for(let index in mixRatioData) {
  173. for(let tmp of mixRatioData[index]) {
  174. compositionConsumption[tmp.glj_id] = compositionConsumption[tmp.glj_id] === undefined ? tmp.consumption :
  175. compositionConsumption[tmp.glj_id] + tmp.consumption;
  176. }
  177. }
  178. }
  179. let result = [];
  180. // 循环组合数据
  181. for(let index in gljList) {
  182. let glj = gljList[index];
  183. if (glj.code === undefined) {
  184. continue;
  185. }
  186. glj.unit_price = unitPriceList !== null && unitPriceList[glj.code + glj.name] !== undefined ? unitPriceList[glj.code + glj.name] : null;
  187. if (glj.unit_price === null) {
  188. continue;
  189. }
  190. let gljId = glj.glj_id + '';
  191. let projectGljId = glj.id + '';
  192. // 消耗量赋值
  193. glj.quantity = quantityList[projectGljId] !== undefined ? quantityList[projectGljId] : 0;
  194. glj.quantity = totalComposition[glj.code] !== undefined ? totalComposition[glj.code] : glj.quantity;
  195. glj.quantity = compositionConsumption[gljId] !== undefined ? glj.quantity + compositionConsumption[gljId] : glj.quantity;
  196. glj.quantity = scMathUtil.roundTo(parseFloat(glj.quantity), -3);
  197. // 组成物数据
  198. gljList[index].ratio_data = mixRatioData[gljId] !== undefined ? mixRatioData[gljId] : [];
  199. glj.unit_price.base_price = scMathUtil.roundTo(parseFloat(glj.unit_price.base_price), -2);
  200. glj.unit_price.market_price = scMathUtil.roundTo(parseFloat(glj.unit_price.market_price), -2);
  201. // 计算调整基价
  202. switch (glj.unit_price.type + '') {
  203. // 人工: 调整基价=基价单价*调整系数
  204. case GLJTypeConst.LABOUR:
  205. glj.adjust_price = scMathUtil.roundTo(parseFloat(glj.adjustment * glj.unit_price.base_price), -2);
  206. break;
  207. // 机械类型的算法
  208. case GLJTypeConst.MACHINE:
  209. console.log('机械');
  210. break;
  211. // 材料、主材、设备
  212. default:
  213. glj.adjust_price = glj.unit_price.base_price;
  214. }
  215. result.push(glj);
  216. }
  217. return result;
  218. }
  219. /**
  220. * 新增项目工料机数据(包括新增单价文件) 定额工料机新增时调用
  221. *
  222. * @param {object} data
  223. * @return {Promise} 返回插入成功的数据id
  224. */
  225. async addList(data) {
  226. let result = null;
  227. try {
  228. if (Object.keys(data).length <= 0) {
  229. throw '新增数据为空';
  230. }
  231. // 首先查找是否有同编码同名称的工料机数据
  232. let projectGljData = await this.findDataByCondition({code: data.code, project_id: data.project_id});
  233. let isAddProjectGLJ = false;
  234. // 如果找不到数据则新增
  235. if (!projectGljData) {
  236. // 新增单条记录 (两个操作本来应该是事务操作,然而mongodb事务支持比较弱,就当作是都可以顺利执行)
  237. let gljInsertData = await this.add(data);
  238. if (!gljInsertData) {
  239. throw '新增项目工料机失败!';
  240. }
  241. isAddProjectGLJ = true;
  242. projectGljData = gljInsertData;
  243. }
  244. // 获取标段对应的单价文件id
  245. let unitPriceFileId = await ProjectModel.getUnitPriceFileId(data.project_id);
  246. if (unitPriceFileId <= 0) {
  247. throw '没有对应的单价文件';
  248. }
  249. // 判断类型,如果是混凝土、砂浆或者配合比则查找对应的组成物(前提是没有对应的项目工料机数据)
  250. if (isAddProjectGLJ && (data.type === GLJTypeConst.CONCRETE || data.type === GLJTypeConst.MORTAR ||
  251. data.type === GLJTypeConst.MIX_RATIO || data.type === GLJTypeConst.GENERAL_MACHINE)) {
  252. this.compositionInit(data, unitPriceFileId);
  253. }
  254. // 新增单价文件
  255. let unitPriceModel = new UnitPriceModel();
  256. let [unitPriceInsertData, isAdd] = await unitPriceModel.addUnitPrice(data, unitPriceFileId);
  257. if (!unitPriceInsertData) {
  258. throw '新增单价失败!';
  259. }
  260. projectGljData.unit_price = unitPriceInsertData;
  261. result = projectGljData;
  262. } catch (error) {
  263. console.log(error);
  264. result = null;
  265. }
  266. return result;
  267. }
  268. /**
  269. * 新增单条工料机数据
  270. *
  271. * @param {object} data
  272. * @return {Promise}
  273. */
  274. async add(data) {
  275. if (Object.keys(data).length <= 0) {
  276. throw '新增数据为空';
  277. }
  278. let counterModel = new CounterModel();
  279. if (data instanceof Array) {
  280. // 如果是批量新增
  281. for(let tmp in data) {
  282. data[tmp].id = await counterModel.getId(gljCollectionName);
  283. }
  284. } else {
  285. data.id = await counterModel.getId(gljCollectionName);
  286. }
  287. this.setScene('add');
  288. let result = await this.db.create(data);
  289. return result;
  290. }
  291. /**
  292. * 根据工料机id修改市场单价
  293. *
  294. * @param {Object} updateData
  295. * @return {Promise}
  296. */
  297. async modifyMarketPrice(updateData) {
  298. let result = {};
  299. try {
  300. if (updateData.code === undefined || updateData.market_price === undefined ||
  301. updateData.name === undefined || updateData.project_id === undefined) {
  302. throw '参数有误!';
  303. }
  304. // 先查是否有对应code的数据
  305. let gljListData = await this.findDataByCondition({code: updateData.code,
  306. project_id: updateData.project_id}, {_id: 0}, false);
  307. if (!gljListData) {
  308. throw '不存在对应code数据';
  309. }
  310. // 获取标段对应的单价文件id
  311. let unitPriceFileModel = new UnitPriceFileModel();
  312. let unitPriceFile = await unitPriceFileModel.getDataByProject(updateData.project_id);
  313. if (!unitPriceFile) {
  314. throw '没有对应的单价文件';
  315. }
  316. let unitPriceFileId = unitPriceFile.id;
  317. let unitPriceModel = new UnitPriceModel();
  318. let gljCount = gljListData.length;
  319. let [unitPriceData, isAdd] = await unitPriceModel.addUnitPrice(updateData, unitPriceFileId, gljCount);
  320. // 判断是否已存在对应数据
  321. let includeField = [
  322. {field: 'name', value: unitPriceData.name}
  323. ];
  324. let gljIndex = this.isIncluded(gljListData, includeField);
  325. let gljData = isAdd ? {} : gljListData[gljIndex];
  326. // 如果单价数据新增则工料机也需要新增
  327. if (isAdd) {
  328. // 如果没有对应的记录则新增一条工料机数据,并更改name
  329. let regular = /\(\d+\)/;
  330. let changeString = '(' + gljCount + ')';
  331. updateData.name = regular.test(updateData.name) ? updateData.name.replace(regular, changeString) :
  332. updateData.name + changeString;
  333. // 获取第一条数据作为数据源
  334. let originalData = gljListData[0];
  335. // 更改名称
  336. originalData.name = updateData.name;
  337. originalData = JSON.stringify(originalData);
  338. gljData = await this.add(JSON.parse(originalData));
  339. if (!gljData) {
  340. throw '新增工料机数据失败!';
  341. }
  342. }
  343. gljData.unit_price = unitPriceData;
  344. result = gljData;
  345. } catch (error) {
  346. console.log(error);
  347. result = {};
  348. }
  349. return result;
  350. }
  351. /**
  352. * 判断数据中是否包含某个数据
  353. *
  354. * @param {Array} data
  355. * @param {Array} includeField
  356. * @return {Number}
  357. */
  358. isIncluded(data, includeField) {
  359. let index = -1;
  360. if (data.length <= 0) {
  361. return index;
  362. }
  363. for(let tmp in data) {
  364. let counter = 0;
  365. for (let includeTmp of includeField) {
  366. if (data[tmp][includeTmp.field] === includeTmp.value) {
  367. counter++;
  368. }
  369. }
  370. if (counter === includeField.length) {
  371. index = tmp;
  372. break;
  373. }
  374. }
  375. return index;
  376. }
  377. /**
  378. * 工料机中组成物操作
  379. * 该方法只在确保没有对应项目工料机的时候才会调用
  380. *
  381. * @param {Object} data
  382. * @param {Number} projectId
  383. * @return {void}
  384. */
  385. async compositionInit(data, unitPriceFileId) {
  386. let gljId = data.glj_id === undefined ? 0 : data.glj_id;
  387. let projectId = data.project_id === undefined ? 0 : data.project_id;
  388. if (gljId === 0 || projectId === 0) {
  389. throw '参数错误';
  390. }
  391. let fromTable = data.from === undefined ? 'std' : data.from;
  392. // 查找对应组成物的项目工料机数据
  393. let [projectGljList, compositionGljList] = await this.getCompositionGLJList(gljId, projectId, 'name', fromTable);
  394. // 整理配合比待插入数据
  395. let mixRatioInsertData = [];
  396. for (let tmp of compositionGljList) {
  397. // 配合比数据插入
  398. let mixRatioData = {
  399. consumption: tmp.consumption,
  400. glj_id: tmp.ID,
  401. unit_price_file_id: unitPriceFileId,
  402. connect_code: tmp.connectCode,
  403. glj_type: tmp.gljType,
  404. code: tmp.code,
  405. };
  406. mixRatioInsertData.push(mixRatioData);
  407. }
  408. // 插入配合比表
  409. // 因为有可能项目工料机与单价数据已存在,但配合比数据不存在,所以先插入配合比,后续判断如果存在项目工料机则可以省下数据库操作
  410. let mixRatioModel = new MixRatioModel();
  411. let addMixRatioResult = await mixRatioModel.add(mixRatioInsertData);
  412. if (!addMixRatioResult) {
  413. throw '组成物插入单价数据失败!';
  414. }
  415. // 如果已经存在则后续操作停止
  416. if(projectGljList.length === compositionGljList.length) {
  417. return;
  418. }
  419. // 整理插入的数据
  420. let gljInsertData = [];
  421. let unitPriceInsertData = [];
  422. for(let tmp of compositionGljList) {
  423. if (projectGljList[tmp.name] !== undefined) {
  424. continue;
  425. }
  426. // 项目工料机插入的数据
  427. let gljData = {
  428. glj_id: tmp.ID,
  429. project_id: projectId,
  430. code: tmp.code,
  431. name: tmp.name,
  432. specs: tmp.specs,
  433. unit: tmp.unit === undefined ? '' : tmp.unit,
  434. };
  435. gljInsertData.push(gljData);
  436. // 单价文件插入的数据
  437. let unitPriceData = {
  438. base_price: tmp.basePrice,
  439. // 初始市场价=基价
  440. market_price: tmp.basePrice,
  441. code: tmp.code,
  442. name: tmp.name,
  443. unit_price_file_id: unitPriceFileId,
  444. type: tmp.gljType,
  445. short_name: tmp.shortName === undefined ? '' : tmp.shortName,
  446. glj_id: tmp.ID,
  447. };
  448. unitPriceInsertData.push(unitPriceData);
  449. }
  450. // 整理完后开始插入数据
  451. let addResult = await this.add(gljInsertData);
  452. if (!addResult) {
  453. throw '组成物插入项目工料机失败!';
  454. }
  455. // 插入单价数据表
  456. let unitPriceModel = new UnitPriceModel();
  457. let addUnitPriceResult = await unitPriceModel.add(unitPriceInsertData);
  458. if (!addUnitPriceResult) {
  459. throw '组成物插入单价数据失败!';
  460. }
  461. }
  462. /**
  463. * 获取组成物具体数据
  464. *
  465. * @param {Number} projectGLJId
  466. * @param {Number} unitPriceFileId
  467. * @return {Promise}
  468. */
  469. async getCompositionList(projectGLJId, unitPriceFileId) {
  470. let result = [];
  471. try {
  472. // 查找对应的项目工料机数据
  473. let projectGLJData = await this.getDataById(projectGLJId);
  474. let allowType = [GLJTypeConst.MIX_RATIO, GLJTypeConst.CONCRETE, GLJTypeConst.MORTAR,
  475. GLJTypeConst.GENERAL_MACHINE];
  476. if (projectGLJData.unit_price === null || allowType.indexOf(projectGLJData.unit_price.type) < 0) {
  477. throw '找不到相关项目工料机';
  478. }
  479. // 查找对应的项目工料机数据
  480. let [gljData, compositionList] = await this.getCompositionGLJList(projectGLJData.glj_id, projectGLJData.project_id);
  481. if (gljData.length <= 0) {
  482. throw '没有对应的组成物项目工料机';
  483. }
  484. // 整理出code和name查找相关单价数据
  485. let codeList = [];
  486. let nameList = [];
  487. let gljIdList = [];
  488. for(let tmp of gljData) {
  489. codeList.push(tmp.code);
  490. nameList.push(tmp.name);
  491. gljIdList.push(tmp.glj_id);
  492. }
  493. // 查找对应的单价数据
  494. let unitPriceModel = new UnitPriceModel();
  495. let condition = {code: {"$in": codeList}, name: {"$in": nameList}, unit_price_file_id: unitPriceFileId};
  496. let unitPriceList = await unitPriceModel.findDataByCondition(condition, {_id: 0}, false);
  497. // 查找对应的配合比数据
  498. let mixRatioModel = new MixRatioModel();
  499. condition = {glj_id: {"$in": gljIdList}, connect_code: projectGLJData.code, unit_price_file_id: unitPriceFileId};
  500. let mixRatioData = await mixRatioModel.findDataByCondition(condition, {_id: 0}, false, 'glj_id');
  501. // 整理数据
  502. let unitPriceData = {};
  503. for(let tmp of unitPriceList) {
  504. unitPriceData[tmp.code + tmp.name] = tmp;
  505. }
  506. gljData = this.combineData(gljData, unitPriceData, [], mixRatioData);
  507. // 排序
  508. gljData.sort(function (a, b) {
  509. return parseInt(a.code) - parseInt(b.code);
  510. });
  511. result = gljData;
  512. } catch (error) {
  513. console.log(error);
  514. result = [];
  515. }
  516. return result;
  517. }
  518. /**
  519. * 获取混凝土等有组成物相关工料机对应的组成物项目工料机数据
  520. *
  521. * @param {Number} gljId
  522. * @param {Number} projectId
  523. * @param {String} indexBy
  524. * @param {String} fromTable
  525. * @return {Promise} 返回组成物工料机数据和组成物列表数据
  526. */
  527. async getCompositionGLJList(gljId, projectId, indexBy = null, fromTable = 'std') {
  528. // 获取对应的组成物数据
  529. let gljListModel = fromTable === 'std' ? new STDGLJLibGLJListModel() : new GljModel();
  530. let componentGljList = await gljListModel.getComponent(gljId);
  531. if (componentGljList.length <= 0) {
  532. throw '不存在对应的组成物';
  533. }
  534. let codeList = [];
  535. let nameList = [];
  536. for(let tmp of componentGljList) {
  537. codeList.push(tmp.code);
  538. nameList.push(tmp.name);
  539. }
  540. // 查找对应的项目工料机数据
  541. let condition = {code: {"$in": codeList}, name: {"$in": nameList}, project_id: projectId};
  542. let gljData = await this.findDataByCondition(condition, {_id: 0}, false, indexBy);
  543. return [gljData, componentGljList];
  544. }
  545. /**
  546. * 根据条件获取对应项目工料机数据
  547. *
  548. * @param {Number} id
  549. * @return {Promise}
  550. */
  551. async getDataById(id) {
  552. // 查找对应的项目工料机数据
  553. let projectGLJData = await this.findDataByCondition({id: id});
  554. if (projectGLJData === null) {
  555. throw '没有找到对应数据';
  556. }
  557. // 查找对应的单价数据
  558. let unitPriceModel = new UnitPriceModel();
  559. let unitPrice = await unitPriceModel.findDataByCondition({code: projectGLJData.code, name: projectGLJData.name});
  560. projectGLJData.unit_price = unitPrice;
  561. return projectGLJData;
  562. }
  563. }
  564. export default GLJListModel;