Преглед изворни кода

feat: 12定额库使用18定额库安装增加费数据相关

vian пре 2 година
родитељ
комит
e02ac68cfa
2 измењених фајлова са 356 додато и 242 уклоњено
  1. 40 28
      modules/ration_repository/models/installation.js
  2. 316 214
      modules/ration_repository/models/ration_item.js

+ 40 - 28
modules/ration_repository/models/installation.js

@@ -6,9 +6,15 @@ const rationItemModel = mongoose.model('std_ration_lib_ration_items');
 const installFeeItemModel = mongoose.model('std_ration_lib_installation');
 const installSectionModel = mongoose.model('std_ration_lib_installationSection');
 
-class InstallationDao{
-    async getInstallation(rationRepId, callback){
+class InstallationDao {
+    // 安装增加费库映射(12修缮定额需要直接用18定额的安装数据)
+    getInstLibID(libID) {
+        return +libID === 248 ? 214 : +libID;
+    }
+
+    async getInstallation(rationRepId, callback) {
         try {
+            rationRepId = this.getInstLibID(rationRepId);
             const feeItems = await installFeeItemModel.find({ rationRepId }).lean();
             const feeItemMap = {};
             const sectionIds = [];
@@ -17,7 +23,7 @@ class InstallationDao{
                 item.section.forEach(s => sectionIds.push(s.ID));
                 item.section = [];
             });
-            const sections = await installSectionModel.find({ID: {$in: sectionIds}});
+            const sections = await installSectionModel.find({ ID: { $in: sectionIds } });
             sections.forEach(section => {
                 const matchFeeItem = feeItemMap[section.feeItemId];
                 if (matchFeeItem) {
@@ -29,7 +35,7 @@ class InstallationDao{
             }
             callback(0, feeItems);
         }
-        catch(err){
+        catch (err) {
             if (!callback) {
                 return [];
             }
@@ -56,60 +62,66 @@ class InstallationDao{
         }
     }*/
 
-    async updateSection(updateData, libID, callback){
-        try{
+    async updateSection(updateData, libID, callback) {
+        try {
             const delIDs = [];
-            for(let data of updateData){
-                if(data.updateType === 'new'){
+            for (let data of updateData) {
+                if (data.updateData.rationRepId) {
+                    data.updateData.rationRepId = this.getInstLibID(data.updateData.rationRepId);
+                }
+                if (data.updateType === 'new') {
                     await installSectionModel.create(data.updateData);
                 }
-                else if(data.updateType === 'update' && !data.updateData.deleted){
-                    await installSectionModel.update({ID: data.updateData.ID}, data.updateData);
+                else if (data.updateType === 'update' && !data.updateData.deleted) {
+                    await installSectionModel.update({ ID: data.updateData.ID }, data.updateData);
                 }
                 else {
                     delIDs.push(data.updateData.ID);
-                    await installSectionModel.remove({ID: data.updateData.ID});
+                    await installSectionModel.remove({ ID: data.updateData.ID });
                 }
             }
             if (delIDs.length) {
-                await rationItemModel.updateMany({rationRepId: libID}, {$pull: { rationInstList: { sectionId: { $in: delIDs } } }});
+                await rationItemModel.updateMany({ rationRepId: libID }, { $pull: { rationInstList: { sectionId: { $in: delIDs } } } });
             }
             callback(0, null);
         }
-        catch(err){
+        catch (err) {
             callback(err, null);
         }
     }
 
-    async updateFeeItem(updateData, callback){
-        try{
-            for(let data of updateData){
-                if(data.updateType === 'new'){
+    async updateFeeItem(updateData, callback) {
+        try {
+            for (let data of updateData) {
+                if (data.updateData.rationRepId) {
+                    data.updateData.rationRepId = this.getInstLibID(data.updateData.rationRepId);
+                }
+                if (data.updateType === 'new') {
                     await installFeeItemModel.create(data.updateData);
                 }
-                else if(data.updateType === 'update' && !data.updateData.deleted){
-                    await installFeeItemModel.update({ID: data.updateData.ID}, data.updateData);
+                else if (data.updateType === 'update' && !data.updateData.deleted) {
+                    await installFeeItemModel.update({ ID: data.updateData.ID }, data.updateData);
                 }
-                else{
-                    await installFeeItemModel.remove({ID: data.updateData.ID});
+                else {
+                    await installFeeItemModel.remove({ ID: data.updateData.ID });
                 }
             }
             callback(0, null);
         }
-        catch(err){
+        catch (err) {
             callback(err, null);
         }
     }
 
-    async batchUpdateInst(rationSection, inst, callback){
-        try{
-            for(let sectionId of rationSection){
-                await rationItemModel.update({sectionId: sectionId, $or: [{isDeleted: null}, {isDeleted: false}]},
-                    {$addToSet: {rationInstList: {feeItemId: inst.feeItemId, sectionId: inst.sectionId}}}, {multi: true});
+    async batchUpdateInst(rationSection, inst, callback) {
+        try {
+            for (let sectionId of rationSection) {
+                await rationItemModel.update({ sectionId: sectionId, $or: [{ isDeleted: null }, { isDeleted: false }] },
+                    { $addToSet: { rationInstList: { feeItemId: inst.feeItemId, sectionId: inst.sectionId } } }, { multi: true });
             }
             callback(0, null);
         }
-        catch(err){
+        catch (err) {
             callback(err, null);
         }
     }

Разлика између датотеке није приказан због своје велике величине
+ 316 - 214
modules/ration_repository/models/ration_item.js