Browse Source

修复调差工料order值重复bug

laiguoran 1 năm trước cách đây
mục cha
commit
b076fb36ba
2 tập tin đã thay đổi với 28 bổ sung0 xóa
  1. 24 0
      app/controller/material_controller.js
  2. 4 0
      app/service/material_bills.js

+ 24 - 0
app/controller/material_controller.js

@@ -382,6 +382,8 @@ module.exports = app => {
                 await this._setEditTaxPermission(ctx);
                 const renderData = await this._getDefaultRenderData(ctx);
                 renderData.materialBillsData = await this._getMaterialBillsData(ctx);
+                // 判断order是否重复,重复则重新排版并更新数据库
+                await this.checkBillsOrder(ctx, renderData.materialBillsData);
                 // 取对应期的截取上期的调差金额和应耗数量
                 if (ctx.material.highOrder !== ctx.material.order) {
                     for (const [mindex, mb] of renderData.materialBillsData.entries()) {
@@ -436,6 +438,28 @@ module.exports = app => {
             }
         }
 
+        // 判断order是否重复,重复则重新排版并更新数据库
+        async checkBillsOrder(ctx, billsList) {
+            if (billsList.length > 0) {
+                const needSet = ctx.helper._.uniq(ctx.helper._.map(billsList, 'order')).length !== billsList.length;
+                if (needSet) {
+                    let order = 1;
+                    const updateOrderList = [];
+                    for (const b of billsList) {
+                        if (b.order !== order) {
+                            b.order = order;
+                            updateOrderList.push({
+                                id: b.id,
+                                order,
+                            });
+                        }
+                        order = order + 1;
+                    }
+                    if (updateOrderList.length > 0) await ctx.service.materialBills.updateAllOrder(updateOrderList);
+                }
+            }
+        }
+
         /**
          * 调差清单页面 (Get)
          * @param {Object} ctx - egg全局变量

+ 4 - 0
app/service/material_bills.js

@@ -908,6 +908,10 @@ module.exports = app => {
                 }
             }
         }
+
+        async updateAllOrder(updateList) {
+            await this.db.updateRows(this.tableName, updateList);
+        }
     }
 
     return MaterialBills;