schangxiang@126.com
2025-09-09 3d8966ba2c81e7e0365c8b123e861d18ee4f94f5
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
import { default as BaseController } from "../baseController";
import { Post } from "egg-shell-decorators";
import { SaleOrderList } from "../../entity/outbound/sale/saleOrderList";
import { vBaseProductPlaceHolder } from "../../entity/storage/storage/vBaseProductPlaceHolder";
import { BaseProductPosition } from "../../entity/storage/product/baseProductPosition";
import { BaseProductPlaceHolder } from "../../entity/storage/storage/baseProductPlaceHolder";
import { SaleOrder } from "../../entity/outbound/sale/saleOrder";
 
/**
 * 出库 - 扫描操作
 */
export default class OutScanController extends BaseController {
  //#region 保存扫描结果(完全打包)
  /**
   * 保存扫描结果(完全打包)
   */
  @Post()
  public async saveScan() {
    let { ctx } = this;
    let body = ctx.request.body;
    this.info = await ctx.service.outbound.outScanService.saveScan(body.batchCode, body.expressCode, body.wrapperBarcode, body.isNoScanBatchCode);
    ctx.body = this.info;
  }
  //#endregion
 
  //#region  保存扫描结果(部分打包)
  @Post()
  public async partialSaveScan() {
    let { ctx } = this;
    let body = ctx.request.body;
    this.info = await ctx.service.outbound.outScanService.partialSaveScan(
      body.batchCode,
      body.expressCode,
      body.wrapperBarcode,
      body.newExpressCode,
      body.list,
      body.isNoScanBatchCode
    );
    ctx.body = this.info;
  }
  //#endregion
 
  //#region 根据条码获取物料图片
 
  /**
   * 根据条码获取物料图片
   */
  @Post()
  public async getProductImg() {
    let { ctx } = this;
    let body = ctx.request.body;
    this.info = await ctx.service.outbound.outScanService.getProductImg(body.orderCode);
    ctx.body = this.info;
  }
  //#endregion
 
  //#region 获取快递单对应的销售订单的信息 GetData
  @Post()
  public async getData() {
    let { ctx } = this;
    let body = ctx.request.body;
    //也可以是 销售订单号,因为有可能生成波次以后,没有打印面单,所以扫描不了快递单号,
    //但是打印了捡配单,可以扫描销售单号
    let expressCode = body.expressCode;
    let batchCode = body.batchCode;
    let isNoScanBatchCode = true; //不需要波次
 
    try {
      this.info = await ctx.service.outbound.outScanService.getData(expressCode, batchCode, isNoScanBatchCode);
    } catch (error) {
      this.info.result = false;
      this.info.msg = "错误:" + error.message;
    }
 
    ctx.body = this.info;
  }
  //#endregion
 
  //#region  保存扫描结果(部分打包)
  /**
   * 部分打包
   */
  @Post()
  public async outPartialSaveScan() {
    let { ctx } = this;
    let body = ctx.request.body;
    let isNoScanBatchCode = true; //无波次号扫描
    let batchCode = null;
    let expressCode = body.expressCode;
    let wrapperBarcode = body.wrapperBarcode;
    let newExpressCode = body.newExpressCode;
    let weight = body.weight || 0;
 
    //每个订单明细的扫描数量
    let dynamicData = body.data; //[{"orderList_Id":"10459","scanCount":2}]
    let list: Array<any> = [];
 
    try {
      for (var model of dynamicData) {
        let orderlist_id = model.orderList_Id;
        let orderCode = model.orderCode;
        let order_Id = model.order_Id;
        let caseNumber = model.caseNumber;
        let scancount = model.scanCount;
        let weight = model.weight || 0;
        let totalWeight = model.totalWeight || 0;
 
        list.push({
          orderList_Id: orderlist_id,
          order_Id: order_Id,
          orderCode: orderCode,
          caseNumber: caseNumber,
          scanCount: scancount,
          weight: weight,
          totalWeight: totalWeight
        });
      }
      this.info = await ctx.service.outbound.outScanService.partialSaveScan(
        batchCode,
        expressCode,
        wrapperBarcode,
        newExpressCode,
        list,
        isNoScanBatchCode,
        0
      );
 
      //#region 扫描成功后的操作
      if (this.info.result) {
        //扫描成功生成揽收信息
        await ctx.service.tms.wayBillHelper.createWayBillReceive(expressCode, weight);
      }
      //#endregion
    } catch (error) {
      this.info.result = false;
      this.info.msg = "错误:" + error.message;
    }
 
    ctx.body = this.info;
  }
  //#endregion
 
  //#region 按订单扫描出库 GetOrderData
  @Post()
  public async getOrderData() {
    let { ctx } = this;
    let body = ctx.request.body;
    let expressCode = body.expressCode;
 
    try {
      this.info = await ctx.service.outbound.outScanService.getOrderData(expressCode);
    } catch (error) {
      this.info.result = false;
      this.info.msg = "错误:" + error.message;
    }
    ctx.body = this.info;
  }
  //#endregion
 
  //#region  按订单扫描出库 保存扫描结果(部分打包)
  /**
   * 部分打包
   */
  @Post()
  public async orderPartialSaveScan() {
    let { ctx } = this;
    let body = ctx.request.body;
    let expressCode = body.expressCode;
    let wrapperBarcode = body.wrapperBarcode;
    let newExpressCode = body.newExpressCode;
    let totalPackage = body.totalPackage;
    let totalVolume = body.totalVolume;
 
    try {
      //每个订单明细的扫描数量
      let data = body.data;
      if (!Array.isArray(data)) {
        this.info.result = false;
        this.info.msg = "扫描明细不能为空";
        ctx.body = this.info;
        return;
      }
 
      let list: Array<any> = [];
      for (var model of data) {
        let orderlist_id = model.orderList_Id;
        let orderCode = model.orderCode;
        let order_Id = model.order_Id;
        let caseNumber = model.caseNumber;
        let scancount = model.scanCount;
        let weight = model.weight || 0;
        let totalWeight = model.totalWeight;
        list.push({
          orderList_Id: orderlist_id,
          order_Id: order_Id,
          orderCode: orderCode,
          caseNumber: caseNumber,
          scanCount: scancount,
          weight: weight,
          totalWeight: totalWeight
        });
      }
      this.info = await ctx.service.outbound.outScanService.orderPartialSaveScan(
        totalPackage,
        totalVolume,
        expressCode,
        wrapperBarcode,
        newExpressCode,
        list
      );
    } catch (error) {
      this.info.result = false;
      this.info.msg = "错误:" + error.message;
      ctx.body = this.info;
    }
 
    ctx.body = this.info;
  }
  //#endregion
 
  //#region 扫描物流单出库 - 根据物流单获得出库单明细数据接口
  @Post()
  public async getSaleOuterExpress() {
    let { ctx } = this;
    let body = ctx.request.body;
    let expressCode = body.expressCode;
 
    try {
      this.info = await ctx.service.outbound.outScanService.getSaleOuterData(expressCode);
    } catch (error) {
      this.info.result = false;
      this.info.msg = "错误:" + error.message;
    }
    ctx.body = this.info;
  }
  //#endregion
 
  //#region 扫描物流单出库保存
  @Post()
  public async saveSaleOuterExpress() {
    let { ctx } = this;
    let body = ctx.request.body;
    let storage_Id = body.storage_Id; // 仓库ID
    let expressCode = body.expressCode; //出库单号
    try {
      this.info = await ctx.service.outbound.outScanService.saveSaleOrderCode(storage_Id, expressCode);
    } catch (error) {
      this, (this.info.result = false);
      this.info.msg = "错误:" + error.message;
    }
 
    ctx.body = this.info;
  }
  //#endregion
 
  //#region 妥投相关-获取妥投出库订单明细
  @Post()
  public async getSaleOrderList() {
    let { ctx } = this;
    let body = ctx.request.body;
    let orderCode = body.orderCode; //出库单号
    try {
      this.info = await ctx.service.outbound.outScanService.getSaleOrderDetaliList(orderCode);
    } catch (error) {
      this, (this.info.result = false);
      this.info.msg = "错误:" + error.message;
    }
 
    ctx.body = this.info;
  }
  //#endregion
 
  //#region 妥投相关-确认妥投
  @Post()
  public async saveSaleOrderTuotou() {
    let { ctx } = this;
    let body = ctx.request.body;
    let orderCode = body.orderCode; //出库单号
    let dataArray = body.orderList;
    try {
      this.info = await ctx.service.outbound.outScanService.saveSaleOrderTuotou(orderCode, dataArray);
    } catch (error) {
      this, (this.info.result = false);
      this.info.msg = "错误:" + error.message;
    }
 
    ctx.body = this.info;
  }
  //#endregion
 
  //#region 出库扫描EU-出库
  @Post()
  public async saveEuOut() {
    let { ctx } = this;
    let body = ctx.request.body;
    let order_Id = body.order_Id; //出库单id
    let orderInfoList = await this.dbRead
      .createQueryBuilder(SaleOrderList, "t")
      .where("order_Id=:order_Id", {
        order_Id: order_Id
      })
      .getMany();
    for (var orderInfo of orderInfoList) {
      // 查找明细所有占位
 
      let holdList = await this.dbRead
        .createQueryBuilder(vBaseProductPlaceHolder, "t")
        .where("mainID=:mainID and detailID=:detailID and className='销售订单'", {
          mainID: order_Id,
          detailID: orderInfo.orderList_Id
        })
        .getMany();
 
      for (var holdInfo of holdList) {
        // 库存数量削减
        holdInfo.productPosition_Id;
        var productPosition = await this.dbRead
          .createQueryBuilder(BaseProductPosition, "t")
          .where("productPosition_Id=:productPosition_Id", {
            productPosition_Id: holdInfo.productPosition_Id
          })
          .getOne();
        productPosition.productStorage = productPosition.productStorage - holdInfo.placeholderStorage;
        await this.dbWrite.save(productPosition);
 
        // 清除明细占位
        var hold = await this.dbRead
          .createQueryBuilder(BaseProductPlaceHolder, "t")
          .where("placeholder_Id=:placeholder_Id", {
            placeholder_Id: holdInfo.placeholder_Id
          })
          .getOne();
        hold.placeholderStorage = 0;
        await this.dbWrite.save(hold);
      }
 
      // 更新出库单状态
      let saleOrderInfo = await this.dbRead
        .createQueryBuilder(SaleOrder, "t")
        .where("order_Id=:order_Id", {
          order_Id: order_Id
        })
        .getOne();
      saleOrderInfo.statusText = "发运完成";
      saleOrderInfo.statusID = 12;
      await this.dbWrite.save(saleOrderInfo);
    }
 
    try {
    } catch (error) {
      this, (this.info.result = false);
      this.info.msg = "错误:" + error.message;
    }
 
    ctx.body = this.info;
  }
  //#endregion
}