Explorar el Código

feat: 信息价总表增加清除前后空格相关 (#GLY-4533)

vian hace 4 meses
padre
commit
29c6e4782a

+ 6 - 6
modules/price_info_lib/facade/index.js

@@ -176,12 +176,12 @@ async function importExcelData(libID, sheetData) {
     for (let row = 1; row < sheetData.length; row++) {
         const areaName = sheetData[row][colMap.area] || '';
         const className = sheetData[row][colMap.class] || '';
-        const code = sheetData[row][colMap.code] || '';
-        const name = sheetData[row][colMap.name] || '';
-        const specs = sheetData[row][colMap.specs] || '';
-        const unit = sheetData[row][colMap.unit] || '';
-        const noTaxPrice = sheetData[row][colMap.noTaxPrice] || '';
-        const taxPrice = sheetData[row][colMap.taxPrice] || '';
+        const code = sheetData[row][colMap.code] ? sheetData[row][colMap.code].trim() : '';
+        const name = sheetData[row][colMap.name] ? sheetData[row][colMap.name].trim() : '';
+        const specs = sheetData[row][colMap.specs] ? sheetData[row][colMap.specs].trim() : '';
+        const unit = sheetData[row][colMap.unit] ? sheetData[row][colMap.unit].trim() : '';
+        const noTaxPrice = sheetData[row][colMap.noTaxPrice] ? sheetData[row][colMap.noTaxPrice].trim() : '';
+        const taxPrice = sheetData[row][colMap.taxPrice] ? sheetData[row][colMap.taxPrice].trim() : '';
         if (!className && !code && !name && !specs && !noTaxPrice && !taxPrice) { // 认为是空数据
             continue;
         }

+ 11 - 0
modules/price_info_summary/controllers/index.js

@@ -60,6 +60,17 @@ class PriceInfoSummaryController extends BaseController {
         }
     }
 
+    // 清除前后空格
+    async trim(req, res) {
+        try {
+            await facade.trim();
+            res.json({ error: 0, message: 'trim success' });
+        } catch (err) {
+            console.log(err);
+            res.json({ error: 1, message: err.toString() });
+        }
+    }
+
     async aiMatch(req, res) {
         try {
             const { listA, listB } = JSON.parse(req.body.data);

+ 27 - 0
modules/price_info_summary/facade/index.js

@@ -96,6 +96,32 @@ async function exportExcelData() {
     return excelData;
 }
 
+// 清除前后空格
+async function trim() {
+    const bulks = [];
+    const items = await priceInfoSummaryModel.find({}, '-_id').lean();
+    items.forEach(item => {
+        const update = {};
+        let needUpdate = false;
+        ['code', 'classCode', 'expString', 'name', 'specs', 'unit'].forEach(key => {
+            const val = item[key];
+            if (val) {
+                const trimVal = val.trim();
+                if (trimVal !== val) {
+                    update[key] = trimVal;
+                    needUpdate = true;
+                }
+            }
+        });
+        if (needUpdate) {
+            bulks.push({ updateOne: { filter: { ID: item.ID }, update } });
+        }
+    });
+    if (bulks.length) {
+        await priceInfoSummaryModel.bulkWrite(bulks);
+    }
+}
+
 module.exports = {
     getData,
     getPagingData,
@@ -103,4 +129,5 @@ module.exports = {
     saveInSummary,
     exportExcelData,
     aiMatch,
+    trim,
 }

+ 1 - 0
modules/price_info_summary/routes/index.js

@@ -13,6 +13,7 @@ module.exports = function (app) {
     router.post("/editSummaryData", priceInfoSummaryController.auth, priceInfoSummaryController.init, priceInfoSummaryController.editSummaryData);
     router.post("/saveInSummary", priceInfoSummaryController.auth, priceInfoSummaryController.init, priceInfoSummaryController.saveInSummary);
     router.post("/aiMatch", priceInfoSummaryController.auth, priceInfoSummaryController.init, priceInfoSummaryController.aiMatch);
+    router.post("/trim", priceInfoSummaryController.auth, priceInfoSummaryController.init, priceInfoSummaryController.trim);
     router.get("/export", priceInfoSummaryController.auth, priceInfoSummaryController.init, priceInfoSummaryController.exportSummaryData);
 
     app.use("/priceInfoSummary", router);

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

@@ -256,12 +256,12 @@ const EMPTY_BOOK = (() => {
       removeIDs.push(item.ID);
       documents.push({
         ID: uuid.v1(),
-        code: item.code,
-        classCode: item.classCode,
-        expString: item.expString,
-        name: item.name,
-        specs: item.specs,
-        unit: item.unit,
+        code: item.code ? item.code.trim() : '',
+        classCode: item.classCode ? item.classCode.trim() : '',
+        expString: item.expString ? item.expString.trim() : '',
+        name: item.name ? item.name.trim() : '',
+        specs: item.specs ? item.specs.trim() : '',
+        unit: item.unit ? item.unit.trim() : '',
       });
     });
     if (!documents.length) {

+ 2 - 1
web/maintain/price_info_summary/html/main.html

@@ -18,7 +18,8 @@
             <span class="header-logo px-2">材料信息价总表</span>
             <a class="lock" data-locked="true" href="javascript:void(0);" title="解锁"><i
                 class="fa fa-unlock-alt"></i></a>
-                <a id="export" class="btn btn-success btn-sm" href="javascript:void(0);" title="导出" style="margin-left: 10px;"><i class="fa fa-sign-out fa-rotate-270"></i>导出</a>
+            <a id="export" class="btn btn-success btn-sm" href="javascript:void(0);" title="导出" style="margin-left: 10px;"><i class="fa fa-sign-out fa-rotate-270"></i>导出</a>
+            <a id="trim" class="btn btn-success btn-sm" href="javascript:void(0);" title="清除前后空格" style="margin-left: 10px;">清除前后空格</a>
         </nav>
     </div>
     <div class="search">

+ 3 - 0
web/maintain/price_info_summary/js/index.js

@@ -23,4 +23,7 @@ $(document).ready(() => {
     $('#export').click(() => {
         window.location.href = '/priceInfoSummary/export';
     });
+
+    // 清除前后空格
+    $('#trim').click(_.debounce(SUMMARY_BOOK.handleTrim, 200, { leading: true }));
 });

+ 17 - 0
web/maintain/price_info_summary/js/summarySheet.js

@@ -155,6 +155,22 @@ const SUMMARY_BOOK = (() => {
     loadPageData(0);
   }
 
+  // 清除前后空格
+  const handleTrim = async () => {
+    try {
+      $.bootstrapLoading.progressStart('清除前后空格', true);
+      $("#progress_modal_body").text('正在清除前后空格,请稍后...');
+      await ajaxPost('/priceInfoSummary/trim', {}, 1000 * 60 * 5);
+      setTimeout(() => {
+        $.bootstrapLoading.progressEnd();
+        window.location.reload()
+      }, 1000)
+    } catch (error) {
+      console.log(error);
+      $.bootstrapLoading.progressEnd();
+    }
+  }
+
 
   // 无限滚动加载
   const onTopRowChanged = (sender, args) => {
@@ -255,5 +271,6 @@ const SUMMARY_BOOK = (() => {
   return {
     sheet,
     handleSearch,
+    handleTrim,
   }
 })()