瀏覽代碼

清单精灵相关

zhongzewei 6 年之前
父節點
當前提交
9eac0f7af4

+ 12 - 0
modules/std_billsGuidance_lib/controllers/libController.js

@@ -87,6 +87,18 @@ class BillsGuideLibController extends BaseController{
             callback(req, res, 1, err, null);
         }
     }
+
+    async testItems(req, res){
+        try{
+            let data = JSON.parse(req.body.data);
+            let rst = await billsGuidanceFacade.testItems(data.libID);
+            res.json({error: 0, data: rst, message: ''});
+        }
+        catch (error){
+            res.json({error: 1, data: null, message: error});
+
+        }
+    }
 }
 
 export default BillsGuideLibController;

+ 66 - 1
modules/std_billsGuidance_lib/facade/facades.js

@@ -28,7 +28,8 @@ module.exports = {
     updateBillsGuideLib,
     getLibWithBills,
     getItemsBybills,
-    updateItems
+    updateItems,
+    testItems
 };
 
 async function getCompilationList() {
@@ -238,4 +239,68 @@ async function updateItems(updateDatas) {
     if(bulkArr.length > 0){
         await billsGuideItemsModel.bulkWrite(bulkArr);
     }
+}
+
+async function testItems(libID) {
+    let items = await billsGuideItemsModel.find({libID: libID});
+    //删除垃圾数据
+    let delBulk = [];
+    let itemsMapping = {};
+    for(let item of items){
+        itemsMapping[item.ID] = true;
+    }
+    for(let item of items){
+        if(item.ParentID != -1 && !itemsMapping[item.ParentID]){
+            delBulk.push({
+                deleteOne: {
+                    filter: {ID: item.ID}
+                }
+            });
+        }
+    }
+    if(delBulk.length > 0){
+        console.log(`delBulk.length`);
+        console.log(delBulk.length);
+        await billsGuideItemsModel.bulkWrite(delBulk);
+    }
+ /*   //查找同层节点含有相同NextSiblingID的节点
+    let rst = [];
+    let billsGroup = {};
+    for(let item of items){
+        if(!billsGroup[item.billsID]){
+            billsGroup[item.billsID] = [item];
+        }
+        else {
+            billsGroup[item.billsID].push(item);
+        }
+    }
+    for(let bGroup in billsGroup){
+        let group = billsGroup[bGroup];
+        let parentGroup = {};
+        for(let gItem of group){
+            if(!parentGroup[gItem.ParentID]){
+                parentGroup[gItem.ParentID] = [gItem]
+            }
+            else {
+                parentGroup[gItem.ParentID].push(gItem);
+            }
+        }
+        for(let pGroup in parentGroup){
+            let pGroupData = parentGroup[pGroup];
+            let nextGroup = {};
+            for(let nItem of pGroupData){
+                let sameNext = _.filter(pGroupData, {NextSiblingID: nItem.NextSiblingID});
+                if(sameNext.length > 1){
+                    console.log(`sameNext`);
+                    console.log(sameNext);
+                    if(!nextGroup[nItem.ParentID + nItem.NextSiblingID]){
+                        rst.push({NextSiblingID: nItem.NextSiblingID, ParentID: nItem.ParentID});
+                        nextGroup[nItem.ParentID + nItem.NextSiblingID] = 1;
+                    }
+                }
+            }
+        }
+
+    }*/
+    return delBulk.length;
 }

+ 11 - 9
modules/std_billsGuidance_lib/routes/routes.js

@@ -15,15 +15,17 @@ const billsGuideLibController = new BillsGuideLibController();
 const viewsController = new ViewsController();
 
 module.exports = function (app) {
-  app.get('/billsGuidance/main', viewsController.auth, viewsController.init, viewsController.redirectMain);
-  app.get('/billsGuidance/guidance', viewsController.auth, viewsController.init, viewsController.redirectGuidance);
-  router.post('/getComBillsLibInfo', billsGuideLibController.auth, billsGuideLibController.init, billsGuideLibController.getComBillsLibInfo);
-  router.post('/getBillsGuideLibs', billsGuideLibController.auth, billsGuideLibController.init, billsGuideLibController.getBillsGuideLibs);
-  router.post('/updateBillsGuideLib', billsGuideLibController.auth, billsGuideLibController.init, billsGuideLibController.updateBillsGuideLib);
-  router.post('/getLibWithBills', billsGuideLibController.auth, billsGuideLibController.init, billsGuideLibController.getLibWithBills);
-  router.post('/getItemsByBills', billsGuideLibController.auth, billsGuideLibController.init, billsGuideLibController.getItemsByBills);
-  router.post('/updateItems', billsGuideLibController.auth, billsGuideLibController.init, billsGuideLibController.updateItems);
+    app.get('/billsGuidance/main', viewsController.auth, viewsController.init, viewsController.redirectMain);
+    app.get('/billsGuidance/guidance', viewsController.auth, viewsController.init, viewsController.redirectGuidance);
+    router.post('/getComBillsLibInfo', billsGuideLibController.auth, billsGuideLibController.init, billsGuideLibController.getComBillsLibInfo);
+    router.post('/getBillsGuideLibs', billsGuideLibController.auth, billsGuideLibController.init, billsGuideLibController.getBillsGuideLibs);
+    router.post('/updateBillsGuideLib', billsGuideLibController.auth, billsGuideLibController.init, billsGuideLibController.updateBillsGuideLib);
+    router.post('/getLibWithBills', billsGuideLibController.auth, billsGuideLibController.init, billsGuideLibController.getLibWithBills);
+    router.post('/getItemsByBills', billsGuideLibController.auth, billsGuideLibController.init, billsGuideLibController.getItemsByBills);
+    router.post('/updateItems', billsGuideLibController.auth, billsGuideLibController.init, billsGuideLibController.updateItems);
+    //test
+    router.post('/testItems', billsGuideLibController.auth, billsGuideLibController.init, billsGuideLibController.testItems);
 
 
-  app.use('/billsGuidance/api', router);
+    app.use('/billsGuidance/api', router);
 };

+ 1 - 1
public/web/common_ajax.js

@@ -39,7 +39,7 @@ var CommonAjax = {
             data: {'data': JSON.stringify(data)},
             dataType: 'json',
             cache: false,
-            timeout: 50000,
+            timeout: 150000,
             success: function(result){
                 if (result.error === 0) {
                     if (successCallback) {

+ 3 - 0
web/maintain/billsGuidance_lib/js/billsGuidance.js

@@ -1056,4 +1056,7 @@ const billsGuidance = (function () {
 
 $(document).ready(function () {
     billsGuidance.initViews();
+    CommonAjax.post('/billsGuidance/api/testItems', {libID: getQueryString('libID')}, function (rstData) {
+        console.log(rstData);
+    });
 });