|
@@ -20,6 +20,9 @@ const stdBillsJobsModel = mongoose.model('std_bills_lib_jobContent');
|
|
|
const stdRationModel = mongoose.model('std_ration_lib_ration_items');
|
|
|
const engLibModel = mongoose.model('engineering_lib');
|
|
|
const compilationModel = mongoose.model('compilation');
|
|
|
+const billMaterialModel = mongoose.model('std_billsGuidance_materials');
|
|
|
+const gljModel = mongoose.model('std_glj_lib_gljList');
|
|
|
+const gljLibModel = mongoose.model('std_glj_lib_map');
|
|
|
const _ = require('lodash');
|
|
|
const zhLibID = 'cf851660-3534-11ec-9641-2da8021b8e4e';
|
|
|
const cqLibID = '90c51220-a740-11e8-a354-ab5db7d42428';
|
|
@@ -32,6 +35,8 @@ module.exports = {
|
|
|
getLibWithBills,
|
|
|
getItemsBybills,
|
|
|
updateItems,
|
|
|
+ getBillMaterials,
|
|
|
+ editBillMaterials,
|
|
|
testItems
|
|
|
};
|
|
|
|
|
@@ -404,6 +409,40 @@ async function updateItems(updateDatas) {
|
|
|
}
|
|
|
}
|
|
|
|
|
|
+// 获取清单材料数据
|
|
|
+async function getBillMaterials(libID, billID) {
|
|
|
+ const billMaterial = await billMaterialModel.findOne({ libID, billID }).lean();
|
|
|
+ if (!billMaterial || !billMaterial.materials) {
|
|
|
+ return [];
|
|
|
+ }
|
|
|
+ const gljIDs = billMaterial.materials.map(m => m.gljID);
|
|
|
+ const gljList = await gljModel.find({ ID: { $in: gljIDs } }, '-_id ID code name specs').lean();
|
|
|
+ return gljList.map(glj => ({ gljID: glj.ID, code: glj.code, name: glj.name, specs: glj.specs }));
|
|
|
+}
|
|
|
+
|
|
|
+// 编辑清单材料数据,返回清单材料数据
|
|
|
+async function editBillMaterials(libID, billID, gljCodes, compilationID) {
|
|
|
+ const gljLib = await gljLibModel.findOne({ compilationId: compilationID }, '-_id ID').lean();
|
|
|
+ const gljList = await gljModel.find({ repositoryId: gljLib.ID, code: { $in: gljCodes }, }, '-_id ID code name specs').lean();
|
|
|
+ const gljMap = {};
|
|
|
+ const materials = [];
|
|
|
+ gljList.forEach(glj => {
|
|
|
+ materials.push({ gljID: glj.ID });
|
|
|
+ gljMap[glj.code] = 1;
|
|
|
+ });
|
|
|
+ const missCodes = gljCodes.filter(code => !gljMap[code]);
|
|
|
+ if (missCodes.length) {
|
|
|
+ throw new Error(`没有找到人材机:<br/>${missCodes.join('<br/>')}`);
|
|
|
+ }
|
|
|
+ const billMaterial = await billMaterialModel.findOne({ libID, billID }, '-_id ID').lean();
|
|
|
+ if (billMaterial) {
|
|
|
+ await billMaterialModel.update({ ID: billMaterial.ID }, { $set: { materials } });
|
|
|
+ } else {
|
|
|
+ await billMaterialModel.create({ libID, billID, ID: uuidV1(), materials });
|
|
|
+ }
|
|
|
+ return gljList.map(glj => ({ gljID: glj.ID, code: glj.code, name: glj.name, specs: glj.specs }));
|
|
|
+}
|
|
|
+
|
|
|
async function testItems(libID) {
|
|
|
let items = await billsGuideItemsModel.find({libID: libID});
|
|
|
//删除垃圾数据
|