Bläddra i källkod

feat: 信息价库增加批量匹配总表

vian 11 månader sedan
förälder
incheckning
73bfe94504

+ 10 - 0
modules/price_info_lib/controllers/index.js

@@ -70,6 +70,16 @@ class PriceInfoController extends BaseController {
         res.render("maintain/price_info_lib/html/edit.html", renderData);
     }
 
+    async getAllLibs(req, res) {
+        try {
+            const data = await facade.getAllLibs();
+            res.json({ error: 0, message: 'getAreas success', data });
+        } catch (err) {
+            console.log(err);
+            res.json({ error: 1, message: err.toString() });
+        }
+    }
+
     async addLib(req, res) {
         try {
             const { name, period, compilationID } = req.body;

+ 14 - 0
modules/price_info_lib/facade/index.js

@@ -21,6 +21,19 @@ async function getLibs(query) {
     return await priceInfoLibModel.find(query).sort({ period: 1 }).lean();
 }
 
+// 获取费用定额的信息价库
+async function getAllLibs() {
+    const libs = await priceInfoLibModel.find({}, '-_id').lean();
+    const groupData = _.groupBy(libs, 'compilationID');
+    const rst = [];
+    Object.keys(groupData).forEach(key => {
+        const items = groupData[key];
+        items.sort((a, b) => a.period.localeCompare(b.period));
+        rst.push(...items);
+    });
+    return rst;
+}
+
 async function createLib(name, period, compilationID) {
     // 将2020-01变成2020年01月
     const reg = /(\d{4})-(\d{2})/;
@@ -769,4 +782,5 @@ module.exports = {
     handlePriceText,
     exportInfoPriceByLib,
     exportInfoPriceByCompilation,
+    getAllLibs,
 }

+ 2 - 1
modules/price_info_lib/routes/index.js

@@ -30,7 +30,8 @@ module.exports = function (app) {
     router.post("/getRecommendPriceSummaryData", priceInfoController.auth, priceInfoController.init, priceInfoController.getRecommendPriceSummaryData);
     router.get("/exportInfoPriceByLib", priceInfoController.auth, priceInfoController.init, priceInfoController.exportInfoPriceByLib);
     router.get("/exportInfoPriceByCompilation", priceInfoController.auth, priceInfoController.init, priceInfoController.exportInfoPriceByCompilation);
-    
+    router.post("/getAllLibs", priceInfoController.auth, priceInfoController.init, priceInfoController.getAllLibs);
+
     app.use("/priceInfo", router);
 };
 

+ 2 - 1
web/maintain/price_info_lib/html/edit.html

@@ -20,7 +20,8 @@
             <div class="navbar-text"><a href="/priceInfo/main">信息价库</a><i
                     class="fa fa-angle-right fa-fw"></i><%= libName  %>
                <button id="calc-price-index">计算指数</button>
-               <button id="match-summary">匹配总表</button> 
+               <button id="match-summary">匹配总表</button>
+               <button id="batch-match-summary">批量匹配总表</button> 
                <button id="show-empty">显示空数据</button> 
                <button id="check-repeat">检测重复别名编码</button> 
                <div class="form-check" id="match-all">

+ 39 - 2
web/maintain/price_info_lib/js/priceClass.js

@@ -1,4 +1,16 @@
 // 分类表
+function setTimeoutSync(handle, time) {
+  return new Promise(function (resolve, reject) {
+    setTimeout(function () {
+      if (handle && typeof handle === 'function') {
+        handle();
+      }
+      resolve();
+    }, time);
+  });
+}
+
+// 分类表
 const CLASS_BOOK = (() => {
   const setting = {
     header: [{ headerName: '分类', headerWidth: $('#area-spread').width(), dataCode: 'name', dataType: 'String', hAlign: 'left', vAlign: 'center' }],
@@ -104,6 +116,7 @@ const CLASS_BOOK = (() => {
   const $upMove = $('#tree-up-move');
   const $calcPriceIndex = $('#calc-price-index');
   const $matchSummary = $('#match-summary');
+  const $batchMatchSummary = $('#batch-match-summary');
   const $showEmpty = $('#show-empty');
 
   // 插入
@@ -457,6 +470,10 @@ const CLASS_BOOK = (() => {
 
   }, DEBOUNCE_TIME, { leading: true }));
 
+  const doMatchSummary = async (libID, compilationID, areaID) => {
+    await ajaxPost('/priceInfo/matchSummary', { libID, compilationID, areaID }, 1000 * 60 * 10);
+  }
+
   // 匹配总表
   $matchSummary.click(_.debounce(async () => {
     $.bootstrapLoading.progressStart('匹配总表', true);
@@ -464,11 +481,31 @@ const CLASS_BOOK = (() => {
     try {
       const matchAll = $('#match-all-input')[0].checked;
       const areaID = matchAll ? '' : AREA_BOOK.curArea?.ID;
-      debugger;
-      await ajaxPost('/priceInfo/matchSummary', { libID, compilationID, areaID }, 1000 * 60 * 10);
+      await doMatchSummary(libID, compilationID, areaID);
       setTimeout(() => {
         $.bootstrapLoading.progressEnd();
         window.location.reload()
+      }, 1000)
+    } catch (error) {
+      alert(error)
+      console.log(error);
+      $.bootstrapLoading.progressEnd();
+    }
+  }, DEBOUNCE_TIME, { leading: true }));
+
+  // 批量匹配总表
+  $batchMatchSummary.click(_.debounce(async () => {
+    $.bootstrapLoading.progressStart('批量匹配总表', true);
+    try {
+      const libs = await ajaxPost('/priceInfo/getAllLibs');
+      for (const lib of libs) {
+        $("#progress_modal_body").text(`${lib.name},正在匹配总表,请稍后(${libs.indexOf(lib) + 1}/${libs.length})...`);
+        await doMatchSummary(lib.ID, lib.compilationID, '');
+        await setTimeoutSync(() => { }, 100);
+      }
+      await setTimeoutSync(() => {
+        $.bootstrapLoading.progressEnd();
+        window.location.reload()
       }, 1000);
     } catch (error) {
       alert(error)