Ver código fonte

feat: 信息价库的“批量匹配总表”按钮,新增弹窗二次确认;匹配所有按钮更改为仅匹配鼠标定位地区的相同省份 (#GLY-5749)

vian 1 mês atrás
pai
commit
7899278de7

+ 4 - 4
modules/price_info_lib/controllers/index.js

@@ -258,8 +258,8 @@ class PriceInfoController extends BaseController {
 
     async getPriceEmptyData(req, res) {
         try {
-            const { libID, compilationID, areaID } = JSON.parse(req.body.data);
-            const data = await facade.getPriceEmptyData(compilationID, libID, areaID);
+            const { libID, compilationID, areaID, matchAll } = JSON.parse(req.body.data);
+            const data = await facade.getPriceEmptyData(compilationID, libID, areaID, matchAll);
             res.json({ error: 0, message: 'getPriceEmptyData success', data });
         } catch (err) {
             console.log(err);
@@ -314,8 +314,8 @@ class PriceInfoController extends BaseController {
     // 匹配总表
     async matchSummary(req, res) {
         try {
-            const { compilationID, libID, areaID } = JSON.parse(req.body.data);
-            await facade.matchSummary(compilationID, libID, areaID);
+            const { compilationID, libID, areaID, matchAll } = JSON.parse(req.body.data);
+            await facade.matchSummary(compilationID, libID, areaID, matchAll);
             res.json({ error: 0, message: 'matchSummary success' });
         } catch (err) {
             console.log(err);

+ 41 - 21
modules/price_info_lib/facade/index.js

@@ -566,23 +566,33 @@ const getSummaryMap = (items) => {
 }
 
 // 匹配总表
-// 按规则匹配信息价的编码、别名编码、计算式(只匹配珠海建筑,要单独标记珠海地区);
+// 按规则匹配信息价的编码、别名编码
 // 匹配规则:名称+规格型号+单位,与总表一致则自动填入编码、别名编码、计算式(珠海建筑);
-const matchSummary = async (compilationID, libID, areaID) => {
-    const updateBulks = [];
-    const areaFilter = { compilationID };
-    if (areaID) {
-        areaFilter.ID = areaID;
+const matchSummary = async (compilationID, libID, areaID, matchAll) => {
+    if (!compilationID || !libID || !areaID) {
+        return;
     }
-    const areas = await priceInfoAreaModel.find(areaFilter, '-_id ID name').lean();
-    const areaNameMap = {};
-    areas.forEach(area => {
-        areaNameMap[area.ID] = area.name;
-    });
     const filter = { libID };
-    if (areaID) {
+    if (matchAll) {
+        const areas = await priceInfoAreaModel.find({ compilationID }, 'ID name').lean();
+        const area = areas.find(area => area.ID === areaID);
+        if (!area) {
+            return [];
+        }
+        const rootAreaName = area.name.split('-')[0];
+        const areaIDs = [];
+        areas.forEach(area => {
+            const name = area.name.split('-')[0];
+            if (name === rootAreaName) {
+                areaIDs.push(area.ID);
+            }
+        });
+        filter.areaID = { $in: areaIDs };
+    } else {
         filter.areaID = areaID;
     }
+
+    const updateBulks = [];
     const priceItems = await priceInfoItemModel.find(filter, '-_id ID compilationID name specs unit areaID period').lean();
     const summaryItems = await priceInfoSummaryModel.find({}, '-_id ID name specs unit code classCode expString').lean();
     const summaryMap = getSummaryMap(summaryItems);
@@ -594,12 +604,6 @@ const matchSummary = async (compilationID, libID, areaID) => {
                 code: matched.code,
                 classCode: matched.classCode,
             }
-            console.log(matched);
-            console.log(updateObj);
-            const areaName = areaNameMap[priceItem.areaID];
-            /* if (/珠海/.test(areaName)) {
-                updateObj.expString = matched.expString;
-            } */
             updateBulks.push({
                 updateOne: {
                     filter: { ID: priceItem.ID, compilationID: priceItem.compilationID, areaID: priceItem.areaID, period: priceItem.period },
@@ -615,13 +619,29 @@ const matchSummary = async (compilationID, libID, areaID) => {
 }
 
 // 获取空数据(没有别名编码)
-const getPriceEmptyData = async (compilationID, libID, areaID) => {
+const getPriceEmptyData = async (compilationID, libID, areaID, matchAll) => {
     const lib = await priceInfoLibModel.findOne({ ID: libID }).lean();
-    if (!lib) {
+    if (!lib || !areaID) {
         return [];
     }
     const filter = { compilationID, libID, period: lib.period };
-    if (areaID) {
+    if (matchAll) {
+        const areas = await priceInfoAreaModel.find({ compilationID }, 'ID name').lean();
+        const area = areas.find(area => area.ID === areaID);
+        console.log(area);
+        if (!area) {
+            return [];
+        }
+        const rootAreaName = area.name.split('-')[0];
+        const areaIDs = [];
+        areas.forEach(area => {
+            const name = area.name.split('-')[0];
+            if (name === rootAreaName) {
+                areaIDs.push(area.ID);
+            }
+        });
+        filter.areaID = { $in: areaIDs };
+    } else {
         filter.areaID = areaID;
     }
     const priceItems = await priceInfoItemModel.find(filter).lean();

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

@@ -27,13 +27,33 @@
                <div class="form-check" id="match-all">
                 <input class="form-check-input" type="checkbox" value="" id="match-all-input">
                 <label class="form-check-label" for="match-all-input" id="match-all-label">
-                  匹配所有
+                  匹配所有地区
                 </label>
               </div>
             </div>
 
         </nav>
     </div>
+
+    <div class="modal fade" id="batch-summary-dialog" data-backdrop="static" style="display: none;" aria-hidden="true">
+        <div class="modal-dialog" role="document">
+            <div class="modal-content">
+                <div class="modal-header">
+                    <h5 class="modal-title">批量匹配总表</h5>
+                    <button type="button" class="close" data-dismiss="modal" aria-label="Close">
+                        <span aria-hidden="true">×</span>
+                    </button>
+                </div>
+                <div class="modal-body">
+                    <h5 class="text-danger">当前操作影响选中同省地区全部月份的信息价,是否继续?</h5>
+                </div>
+                <div class="modal-footer">
+                    <a id="confirm-batch-summary" href="javascript:void(0);" class="btn btn-danger">确认</a>
+                    <button type="button" class="btn btn-secondary" data-dismiss="modal">取消</button>
+                </div>
+            </div>
+        </div>
+    </div>
     <div class="wrapper" style="overflow: hidden;">
         <div class="main">
             <div class="left">

+ 20 - 7
web/maintain/price_info_lib/js/priceClass.js

@@ -471,18 +471,22 @@ const CLASS_BOOK = (() => {
 
   }, DEBOUNCE_TIME, { leading: true }));
 
-  const doMatchSummary = async (libID, compilationID, areaID) => {
-    await ajaxPost('/priceInfo/matchSummary', { libID, compilationID, areaID }, 1000 * 60 * 10);
+  const doMatchSummary = async (libID, compilationID, areaID, matchAll) => {
+    await ajaxPost('/priceInfo/matchSummary', { libID, compilationID, areaID, matchAll }, 1000 * 60 * 10);
   }
 
   // 匹配总表
   $matchSummary.click(_.debounce(async () => {
+    const areaID = AREA_BOOK.curArea?.ID;
+    if (!areaID) {
+      alert('请选择地区');
+      return;
+    }
     $.bootstrapLoading.progressStart('匹配总表', true);
     $("#progress_modal_body").text('正在匹配总表,请稍后...');
     try {
-      const matchAll = $('#match-all-input')[0].checked;
-      const areaID = matchAll ? '' : AREA_BOOK.curArea?.ID;
-      await doMatchSummary(libID, compilationID, areaID);
+      const matchAll = Boolean($('#match-all-input')[0].checked);
+      await doMatchSummary(libID, compilationID, areaID, matchAll);
       setTimeout(() => {
         $.bootstrapLoading.progressEnd();
         window.location.reload()
@@ -495,13 +499,22 @@ const CLASS_BOOK = (() => {
   }, DEBOUNCE_TIME, { leading: true }));
 
   // 批量匹配总表
-  $batchMatchSummary.click(_.debounce(async () => {
+  $batchMatchSummary.click(() => {
+    $('#batch-summary-dialog').modal('show');
+  })
+  $('#confirm-batch-summary').click(_.debounce(async () => {
+    const areaID = AREA_BOOK.curArea?.ID;
+    if (!areaID) {
+      alert('请选择地区');
+      return;
+    }
+    $('#batch-summary-dialog').modal('hide');
     $.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 doMatchSummary(lib.ID, lib.compilationID, areaID, true);
         await setTimeoutSync(() => { }, 100);
       }
       await setTimeoutSync(() => {

+ 3 - 3
web/maintain/price_info_lib/js/priceEmpty.js

@@ -102,9 +102,9 @@ const EMPTY_BOOK = (() => {
     curRow = 0;
     $.bootstrapLoading.start();
     try {
-      const matchAll = $('#match-all-input')[0].checked;
-      const areaID = matchAll ? '' : AREA_BOOK.curArea?.ID;
-      totalData = await ajaxPost('/priceInfo/getPriceEmptyData', { libID, compilationID, areaID }, 1000 * 60 * 10);
+      const matchAll = Boolean($('#match-all-input')[0].checked);
+      const areaID = AREA_BOOK.curArea?.ID;
+      totalData = await ajaxPost('/priceInfo/getPriceEmptyData', { libID, compilationID, areaID, matchAll }, 1000 * 60 * 10);
       setTotalMap(totalData);
       const tableData = getTableData(totalData);
       cache.push(...tableData)