333
schangxiang@126.com
2025-09-19 18966e02fb573c7e2bb0c6426ed792b38b910940
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
import { default as BaseController } from "../baseController";
import { Post } from "egg-shell-decorators";
import { StorageAdjustList } from "../../entity/storage/adjust/storageAdjustList";
import * as sql from "mssql";
import * as XLSX from "xlsx";
import * as path from "path";
import { BaseProductInfo } from "../../entity/basicInfo/base/baseProductInfo";
import { isNumber } from "util";
import moment = require("moment");
import { StorageAdjust } from "../../entity/storage/adjust/storageAdjust";
import { BasePosition } from "../../entity/basicInfo/base/basePosition";
 
export default class StorageAdjustController extends BaseController {
  //#region GetData
  @Post()
  public async getData() {
    let { ctx } = this;
 
    let body = ctx.request.body;
    this.info = await ctx.service.storage.positionTransfer.getProductPositionGroupData(
      body.originalPositionName,
      body.targetPositionName,
      body.storage_Id
    );
    if (!this.info.result) {
      this.info.result = false;
      this.info.msg = this.info.msg;
    } else {
      this.info.result = true;
      this.info.dynamic = this.info.data;
    }
    ctx.body = this.info;
  }
  //#endregion
 
  //#region 审核
  @Post()
  public async auditing() {
    let { ctx } = this;
    let body = ctx.request.body;
    let userInfo = await ctx.helper.userInfo();
    let idValue = body.idValue;
    if (!idValue) {
      this.info.result = false;
      this.info.msg = "信息不存在";
      return;
    }
    try {
      let Adjustlist = await this.dbRead.find(StorageAdjustList, idValue);
      if (Adjustlist.length <= 0) {
        this.info.msg = "明细为空不能审核!";
        this.info.result = false;
        return;
      }
      if (body.auditing == 2) {
        const connection: any = await this.dbWrite.connection;
        let request = new sql.Request(connection.driver.master);
        request.input("User_Id", userInfo.user_Id);
        request.input("Adjust_Id", idValue);
        request.output("outMsg", sql.NVarChar(2000));
        // cmd.CommandTimeout = 60 * 10;
        let result = await request.execute("sp_Storage_Adjust_Sorting");
        let outMsg = result.output.outMsg;
 
        if (outMsg) {
          this.info.msg = outMsg;
          this.info.result = false;
          this.ctx.body = this.info;
          return;
        }
 
        //执行确认操作
        const connectiont: any = await this.dbWrite.connection;
        request = new sql.Request(connectiont.driver.master);
        request.input("modifier", userInfo.userTrueName);
        request.input("adjust_Id", idValue);
        request.output("outMsg", sql.NVarChar(2000));
        try {
          let result = await request.execute("sp_Storage_Adjust_Check");
 
          outMsg = result.output.outMsg;
        } catch (e) {
          this.info.msg = "执行错误:" + e.message;
          this.info.result = false;
          this.ctx.body = this.info;
          return;
        }
        if (outMsg) {
          this.info.msg = outMsg;
          this.info.result = false;
          ctx.body = this.info;
          return;
        }
        this.info.result = true;
        this.info.msg = "审核成功!";
      }
    } catch (ex) {
      this.info.result = false;
      this.info.msg = "错误信息:" + ex.message;
    }
    ctx.body = this.info;
  }
  //#endregion
 
  //#region auditingAssemble
  @Post()
  public async auditingAssemble() {
    let { ctx } = this;
    let body = ctx.request.body;
    let userInfo = await ctx.helper.userInfo();
    let idValue = body.idValue;
 
    if (!idValue) {
      this.info.result = false;
      this.info.msg = "信息不存在";
      return;
    }
    try {
      let Adjustlist = await this.dbRead.find(StorageAdjustList, idValue);
      if (Adjustlist.length <= 0) {
        this.info.msg = "明细为空不能审核!";
        this.info.result = false;
        return;
      }
      if (body.auditing == 2) {
        const connection: any = await this.dbWrite.connection;
        let request = new sql.Request(connection.driver.master);
        request.input("User_Id", userInfo.user_Id);
        request.input("Assemble_Id", idValue);
        request.output("outMsg", sql.NVarChar(2000));
        // cmd.CommandTimeout = 60 * 10;
        let result = await request.execute("sp_Storage_Assemble_Sorting");
        let outMsg = result.output.outMsg;
 
        if (outMsg) {
          this.info.msg = outMsg;
          this.info.result = false;
          this.ctx.body = this.info;
          return;
        }
 
        //执行确认操作
        const connectiont: any = await this.dbWrite.connection;
        request = new sql.Request(connectiont.driver.master);
        request.input("User_Id", userInfo.user_Id);
        request.input("Assemble_Id", idValue);
        request.input("UserTrueName", userInfo.userTrueName);
        // request.output("outMsg", sql.NVarChar(2000));
        try {
          let result = await request.execute("sp_Storage_Assemble_Check");
          outMsg = result.output.outMsg;
        } catch (e) {
          this.info.msg = "执行错误:," + e.message;
          this.info.result = false;
          this.ctx.body = this.info;
          return;
        }
        if (outMsg) {
          this.info.msg = outMsg;
          this.info.result = false;
          return this.info;
        }
        this.info.result = true;
        this.info.msg = "审核成功!";
      }
    } catch (ex) {
      this.info.result = false;
      this.info.msg = "错误信息:" + ex.message;
    }
    ctx.body = this.info;
  }
  //#endregion
 
  //#region  批量添加新库存物料
  @Post()
  public async batchAdd() {
    // let { ctx } = this;
    // let body = ctx.request.body;
    // let userInfo = await ctx.helper.userInfo();
    // let idField = body.idField;
    // let dataList = (body.data.trim('\r').Replace("\r", ""), "\n");
    // let index = 0;
    // let sql ="";
    // let msg ="";
    // let adjust = await this.dbRead.findOne(StorageAdjust, body.adjust_Id);
    // let productCodeList = "";
    // let dtNew = null;
    // let newdt = null;
    // let dataPurchase = null;
    // for (let item of dataList)
    // {
    //  let itemList = item.split("\t,, ");
    //   if (itemList.length == 1) continue;
    //   if (itemList.length < 3) {
    //     this.info.result = false;
    //     msg += "<br/>第" + (index + 1) + "行数据格式不正确!";
    //     index++;
    //     continue;
    //   }
    //   // let dt = await this.dbRead.find(BasePosition,{
    //   //   storage_Id: adjust.storage_Id,
    //   // })
    //   // ${ saleOuter.outer_Id }
    //   sql = `SELECT PositionName FROM dbo.Base_Position WHERE storage_Id='" +${adjust.storage_Id} + "' AND PositionName='" +${itemList[0]}  + @"'`;
    //   let dt= await this.dbWrite.query(sql);
    //   if (dt.Rows.Count != 1) {
    //     msg += "<br/>第" + (index + 1) + "行数据货位【" + itemList[0] + "】不存在!";
    //     index++;
    //     continue;
    //   }
    //   let dtSku = await this.dbRead.find(vBaseProductInfoSKU,{
    //     ProductCode: itemList[1]
    //   });
    //   if (dtSku.Rows.Count != 1) {
    //     msg += "<br/>第" + (index + 1) + "行数据物料编号【" + itemList[1] + "】不存在!";
    //     index++;
    //     continue;
    //   }
    //   let ProductCode = itemList[1];
    //   let checkQuantity = itemList[2];
    //   if (productCodeList) productCodeList += "','";
    //   productCodeList += ProductCode;
    //   sql = `SELECT SUM(productStorage) AS productStorage FROM Base_ProductPosition    WHERE ProductCode='" +${itemList[1]}  + "' AND PositionName='" + ${itemList[0]} + "' and storage_Id='" + ${adjust.storage_Id}  + "' and consignorCode='" +${adjust.consignorCode}  + "'  and provider_Id='" + ${adjust.provider_Id} +"'`;
    //   let newdt  = await this.dbRead.query(sql);
    //   if (newdt.Rows.Count != 1) {
    //     msg += "<br/>第" + (index + 1) + "行数据,在仓库此货位下货主为:" + adjust.consignorCode + ",供应商为:" + adjust.adjustCode + "的,物料编号为:【" + itemList[1] + "】不存在,请核对物料信息!";
    //     index++;
    //     continue;
    //   }
    //   sql = `SELECT purchasePrice, purchaseMoney FROM Base_ProductPosition    WHERE ProductCode='" + ${itemList[1]}  + "' AND PositionName='" + ${itemList[0]} + "' and storage_Id='" + ${adjust.storage_Id} + "' and consignorCode='" + ${adjust.consignorCode} + "'  and provider_Id='" + ${adjust.provider_Id} + "'`;
    //   let dataPurchase = await this.dbRead.query(sql);
    //   let purchaseMoney = 0;//账面成本额
    //   let  purchasePrice = 0;//进货价
    //   for (let moneyRow of dataPurchase)
    //   {
    //     purchaseMoney = moneyRow["purchaseMoney"];
    //     purchasePrice = moneyRow["purchasePrice"];
    //   }
    //   let productStorage = 0;
    //   for (let newRow of newdt)
    //   {
    //     productStorage = newRow["productStorage"].GetInt();
    //   }
    //   let ProfitQuantity = 0;
    //   let lossQuantity = 0;
    //   if (checkQuantity.length > productStorage)//盘点数量大于账面库存量
    //   {
    //     ProfitQuantity = checkQuantity.length - productStorage;
    //   }
    //   if (checkQuantity.length < productStorage)//盘点数量小于账面库存量
    //   {
    //     lossQuantity = productStorage - checkQuantity.length;
    //   }
    //   let profitMoney = 0;//盘盈金额
    //   let lossMoney = 0;//盘亏金额
    //   purchaseMoney = purchaseMoney * productStorage;
    //   profitMoney = ProfitQuantity * purchaseMoney;
    //   lossMoney = lossQuantity * purchaseMoney;
    //   sql =`
    //   SELECT     Product_Id, ProductCode, ProductName, ProductModel, ProductSpec, SmallUnit, BigUnit, " +${productStorage} + @" as productStorage, " + ${purchaseMoney} + @" as purchaseMoney,
    //     UnitConvert, UnitConvertText, '" +${itemList[0]} + @"' AS PositionName, " + ${purchasePrice} + @" as purchasePrice,
    //       " + ${checkQuantity} + @" AS checkQuantity,
    //         " + ${ProfitQuantity} + @" AS ProfitQuantity, " + ${lossQuantity} + @" AS lossQuantity, " + ${profitMoney} + @" as profitMoney,
    //           " + ${lossMoney} + @" as lossMoney
    //   FROM  dbo.vBase_ProductInfo_SKU
    //   WHERE ProductCode = '" + ${ProductCode} + "'`;
    //   dt = await this.dbRead.query(sql);
    //   if (dtNew == null) {
    //     dtNew = dt;
    //   }
    //   else {
    //     dtNew.Merge(dt);
    //   }
    //   index++;
    // }
    // if (index > 0) {
    //   sql = @"
    //   DECLARE @ProductCode NVARCHAR(max);
    //   SET @ProductCode='';
    //   SELECT @ProductCode=ProductCode + ',' FROM dbo.vBase_ProductInfo_SKU WHERE ProductCode IN('" + productCodeList + @"') AND provider_Id IS NULL;
    //   SELECT @ProductCode AS ProductCode; ";
    //   string noProvider = Storage_AdjustRepository.Instance.DataContext.ExecuteScalar(CommandType.Text, sql).GetString();
    //   if (noProvider.IsNotNullOrEmpty()) {
    //     msg += "<br/>物料编号为【" + noProvider.Trim(',') + "】供应商不存在,请在物料信息中设置供应商!";
    //   }
    //   if (msg.IsNotNullOrEmpty()) //校验存在错误
    //   {
    //     this.info.result = false;
    //     //info.Data = string.Empty;
    //     info.Msg = msg;
    //   }
    //   else {
    //     this.info.result = true;
    //     //info.Data = DataTableHelper.DataTableToJson(dtNew);
    //     info.Msg = "加载成功!";
    //     foreach(DataRow row in dtNew.Rows)
    //     {
    //       string PositionName = row["PositionName"].ToString();
    //       string checkQuantity = row["checkQuantity"].ToString();
    //       string ProductCode = row["ProductCode"].ToString();
    //       string purchasePrice = row["purchasePrice"].ToString();
    //       string lossQuantity = row["lossQuantity"].ToString();
    //       string ProfitQuantity = row["ProfitQuantity"].ToString();
    //       string profitMoney = row["profitMoney"].ToString();
    //       string lossMoney = row["lossMoney"].ToString();
    //       string productStorage = row["productStorage"].ToString();
    //       string purchaseMoney = row["purchaseMoney"].ToString();
    //       string SmallUnit = row["SmallUnit"].ToString();
    //       sql = @"
    //       INSERT INTO Storage_AdjustList
    //         (Adjust_Id, Product_Id, ProductCode, ProductName, ProductModel, ProductSpec, SmallUnit, purchasePrice,
    //           PositionName, productStorage, purchaseMoney, checkQuantity,
    //           ProfitQuantity, profitMoney, lossQuantity, lossMoney,
    //           CreateID, Creator, CreateDate)
    //       SELECT  " + reqInfo.Adjust_Id + @" AS Adjust_Id, Product_Id, ProductCode, ProductName, ProductModel, ProductSpec, '" + SmallUnit + @"', " + purchasePrice + @" as purchasePrice,
    //         '" + PositionName + @"' AS PositionName, " + productStorage + @" AS productStorage,
    //           " + purchaseMoney + @" AS purchaseMoney, " + checkQuantity + @" AS checkQuantity,
    //             " + ProfitQuantity + @" AS ProfitQuantity, " + profitMoney + @"  AS profitMoney, " + lossQuantity + @" as lossQuantity, " + lossMoney + @" as lossMoney,
    //               " + UserHelper.UserInfo.User_Id + " as CreateID, '" + UserHelper.UserInfo.UserTrueName + @"' as Creator, getdate() as CreateDate
    //       FROM  dbo.vBase_ProductInfo_SKU
    //       WHERE ProductCode = '" + ProductCode + @"'; ";
    //       Storage_AdjustlistRepository.Instance.ExeSql(sql);
    //     }
    //     //更新求和
    //     sql = @"
    //     UPDATE    Storage_Adjust
    //     SET TotalProductStorage = T.TotalProductStorage, TotalPurchaseMoney = T.TotalPurchaseMoney,
    //       TotalCheckQuantity = T.TotalCheckQuantity, TotalProfitQuantity = T.TotalProfitQuantity,
    //       TotalProfitMoney = T.TotalProfitMoney,
    //       TotalLossQuantity = T.TotalLossQuantity,
    //       TotalLossMoney = T.TotalLossMoney
    //     FROM(
    //       SELECT Adjust_Id, TotalProductStorage = SUM(productStorage), TotalPurchaseMoney = SUM(purchaseMoney), TotalCheckQuantity = SUM(checkQuantity),
    //       TotalProfitQuantity = SUM(ProfitQuantity), TotalProfitMoney = SUM(profitMoney),
    //       TotalLossQuantity = SUM(lossQuantity), TotalLossMoney = SUM(lossMoney)
    //                 FROM Storage_AdjustList
    //                 WHERE Adjust_Id = " + reqInfo.Adjust_Id + @"
    //                 GROUP BY Adjust_Id
    //     ) T, Storage_Adjust
    //     WHERE t.Adjust_Id = dbo.Storage_Adjust.Adjust_Id
    //     AND dbo.Storage_Adjust.Adjust_Id = " + reqInfo.Adjust_Id + @"
    //     ";
    //     Storage_AdjustlistRepository.Instance.ExeSql(sql);
    //   }
    // }
    // else {
    //   this.info.result = false;
    //   info.Msg = "加载失败!";
    // }
    // return info;
  }
  //#endregion
 
  //#region 库存调整明细导出
  /// <summary>
  /// 库存调整明细导出
  /// </summary>
  /// <param name="body"></param>
  /// <returns></returns>
  @Post()
  public async exportList() {
    let { ctx } = this;
    let body = ctx.request.body;
 
    try {
      let sql = "";
      sql = `SELECT 
productCode AS '物料编号',productName AS '物料名称',productSpec AS '物料规格',productModel AS '物料条码',positionName AS '货位',
productStorage AS '账面库存量', placeholderStorage AS '占位数量',smallUnit AS '小单位',purchasePrice AS '进货价',
purchaseMoney AS '账面成本额',checkQuantity AS '盘点数量',profitQuantity AS '盘盈数量',profitMoney AS '盘盈金额',lossQuantity AS '盘亏数量',
lossMoney AS '盘亏金额',lackStorage AS '缺货数量',weight AS '单位重量',totalWeight AS '库存重量',sortingStatus AS '分拣状态',
productAttribute AS '物料属性',produceDate AS '生产日期',shelfLifeDay AS '保质期天数',plateCode AS '拍号',containerNo AS '集装箱号',originPlace AS '原产地',batchNumber AS '批次号',inStorageDate AS '入库日期',remark AS '备注'
FROM Storage_Adjustlist
WHERE Adjustlist_Id IN(select col from dbo.split(@0, ','))`;
 
      let transferList: Array<any> = await this.dbRead.query(sql, [body.ids]);
 
      let root = path.resolve();
      let url = "/download/库存调整明细数据.xlsx";
      let fileName = root + url.replace(/\//g, path.sep);
      let pathToCreate = fileName.substring(0, fileName.lastIndexOf(path.sep));
      ctx.helper.mkdir(pathToCreate);
 
      // wayBillList = wayBillList.splice(0, 0, {
      //   "分运单号":"xxxxxx"
      // }, {"申报类型": "xxxxsssss"}, {});
      let jsonWorkSheet = XLSX.utils.json_to_sheet(transferList);
      // 构造workBook
      let workBook = {
        SheetNames: ["数据"],
        Sheets: {
          数据: jsonWorkSheet
        }
      };
      XLSX.writeFile(workBook, fileName);
 
      this.info.result = true;
      this.info.data = {
        url: url
      };
      this.info.msg = "导出成功!";
    } catch (ex) {
      this.info.result = false;
      this.info.msg = "错误信息:" + ex.message;
    }
    ctx.body = this.info;
  }
  //#endregion
 
  //#region 导入库存调整Excel
  @Post()
  public async importExcel() {
    setTimeout(async () => {
      await this.importExcelWork();
    }, 0);
 
    this.info.result = true;
    this.info.msg = "开始导入...";
    this.ctx.body = this.info;
  }
  //#endregion
 
  //#region importExcelWork
  private async importExcelWork() {
    let { ctx } = this;
    let userInfo = await this.userInfo;
    let body = ctx.request.body;
    let redis = ctx.app.redis.clients.get("common"); // 将消息放入redis缓存
    let fileUrl = body.fileUrl;
    redis.expire(body.key, 5 * 60);
    if (!this.body.adjust_Id) {
      this.setMsg("请先保存后再进行导入操作", "red");
      this.setMsg("-1");
      return;
    }
    if (!fileUrl) {
      this.setMsg("上传文件不存在", "red");
      this.setMsg("-1");
      return;
    }
    if (!body.key) {
      this.setMsg("上传key不存在", "red");
      this.setMsg("-1");
      return;
    }
 
    try {
      let rootPath = path.resolve(); // 获得根目录
      let filePath = rootPath + path.sep + fileUrl.replace(/\//gi, path.sep); // 上传文件路径
      var workbook = XLSX.readFile(filePath); //整个 excel 文档
      var sheetNames = workbook.SheetNames; //获取所有工作薄名
      var sheet1 = workbook.Sheets[sheetNames[0]]; //根据工作薄名获取工作薄
      let dataList = XLSX.utils.sheet_to_json(sheet1); // 获得当前sheet表单数据转为json格式
 
      //#region 验证数据正确性
      this.info.result = true;
      if (!dataList.length) {
        this.setMsg("没有可导入的数据", "red");
        this.setMsg("-1");
        return;
      }
      //#endregion
 
      let adjust = await this.dbRead.findOne(StorageAdjust, {
        adjust_Id: this.body.adjust_Id
      });
      let i = 1;
      let dataRows = []; // 数据集合
      for (let row of dataList) {
        i++;
        let prodInfo = await this.dbRead.findOne(BaseProductInfo, {
          productCode: row["物料编号"],
          userProduct_Id: userInfo.userProduct_Id
        });
 
        if (!prodInfo) {
          this.setMsg(`第${i}行、${row["物料编号"]}在物料基础信息中不存在`, "red");
        }
        let positionName = row["货位名称"];
        let Position = await this.dbRead.find(BasePosition, {
          positionName: positionName,
          storageName: adjust.storageName
        });
        if (!Position) {
          this.setMsg(`第${i}行、${row["货位名称"]}在,${adjust.storageName}不存在`, "red");
        }
        let produceDate = row["生产日期"];
        if (produceDate) {
          if (!isNumber(produceDate)) {
            this.setMsg(`第${i}行、${produceDate}在生产日期格式不正确`, "red");
          } else {
            produceDate = moment(new Date(1900, 0, produceDate - 1));
            produceDate = produceDate.toDate();
            // data.produceDate = d.toDate();
          }
        }
 
        let inStorageDate = row["入库日期"];
        if (inStorageDate) {
          if (!isNumber(inStorageDate)) {
            this.setMsg(`第${i}行,${inStorageDate}在生产日期格式不正确`, "red");
          } else {
            inStorageDate = moment(new Date(1900, 0, inStorageDate - 1));
            inStorageDate = inStorageDate.toDate();
          }
        }
        let weight = row["单位重量"];
        let checkQuantity = row["盘点数量"];
        let totalWeight = row["库存重量"];
        if (!weight) {
          weight = checkQuantity ? totalWeight / checkQuantity : 0;
        }
        let data = {
          adjust_Id: body.adjust_Id,
          createID: userInfo.user_Id,
          creator: userInfo.userTrueName,
          positionName: row["货位名称"],
          product_Id: prodInfo.product_Id,
          productCode: row["物料编号"],
          productName: row["物料名称"],
          productModel: row["条形码"],
          productSpec: row["物料规格"],
          productStorage: row["账面库存量"],
          placeholderStorage: row["占位数量"],
          smallUnit: row["小单位"],
          purchasePrice: row["进货价"],
          purchaseMoney: row["账面成本额"],
          checkQuantity: checkQuantity,
          profitQuantity: row["盘盈数量"],
          profitMoney: row["盘盈金额"],
          lossQuantity: row["盘亏数量"],
          lossMoney: row["盘亏金额"],
          lackStorage: row["缺货数量"],
          weight: weight,
          totalWeight: totalWeight,
          sortingStatus: row["分拣状态"],
          productAttribute: row["物料属性"],
          produceDate: produceDate,
          shelfLifeDay: row["保质期天数"],
          plateCode: row["拍号"],
          containerNo: row["集装箱号"],
          originPlace: row["原产地"],
          batchNumber: row["批次号"],
          inStorageDate: inStorageDate,
          remark: row["备注"]
        };
        //#region  // 校验数据
        if (!data.productCode) {
          this.setMsg(`第${i}行、物料编号不能为空`, "red");
        }
        if (!data.productName) {
          this.setMsg(`第${i}行、物料名称不能为空`, "red");
        }
        if (!data.productModel) {
          this.setMsg(`第${i}行、条形码不能为空`, "red");
        }
        if (!data.positionName) {
          this.setMsg(`第${i}行、货位不能为空`, "red");
        }
        if (data.shelfLifeDay) {
          if (!isNumber(data.shelfLifeDay)) {
            this.setMsg(`第${i}行、保质期天数必须是数字`, "red");
          }
        }
        // if (!data.originPlace) {
        //   this.setMsg(`第${i}行,原产地值为空`, "red");
        // }
        dataRows.push(data);
      }
      //#endregion
 
      if (this.isMsgError) {
        this.setMsg(`导入数据有错误,请处理好重新导入`, "red");
        this.setMsg("-1");
        return;
      }
      i = 1;
      let successCount = 0;
      let updateCount = 0;
      let rows = []; // 准备更新或者新增的数据
      for (let data of dataRows) {
        i++;
        successCount++;
        rows.push(data);
        if (i % 100 === 0) {
          await this.dbWrite.save(StorageAdjustList, rows);
          rows = [];
        }
      }
      if (rows.length > 0) {
        await this.dbWrite.save(StorageAdjustList, rows);
        rows = [];
      }
      this.setMsg(`导入成功,新增${successCount}条,更新${updateCount}条`, "blue");
    } catch (ex) {
      this.setMsg("出现异常:" + ex.message, "red");
      this.info.result = false;
    }
    this.setMsg("-1");
  }
  //#endregion
}