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
//#region import
import BaseService from "../baseService";
import { SaleOrderPrint } from "../../entity/outbound/manufacture/saleOrderPrint";
import { SaleOrder } from "../../entity/outbound/sale/saleOrder";
//#endregion
 
/**
 * 扫拍下架Service
 */
export default class PickingPaiScanService extends BaseService {
  //#region 根据波次单号获取拣货信息
  public async getData(orderPrintCode: string, userInfo) {
    let { ctx } = this;
    this.info.result = false;
    // 波次单主表
    let orderPrint = await this.dbRead
      .createQueryBuilder(SaleOrderPrint, "t")
      .where("orderPrintCode=:orderPrintCode and userProduct_Id=:userProduct_Id", {
        orderPrintCode: orderPrintCode,
        userProduct_Id: userInfo.userProduct_Id
      })
      .getOne();
 
    let model: any = {};
    model.orderPrint_Id = orderPrint.orderPrint_Id;
    model.orderPrintCode = orderPrint.orderPrintCode;
 
    if (orderPrint.pickingStatus !== "待拣货" && orderPrint.pickingStatus !== "拣货中") {
      this.info.result = false;
      this.info.msg = "波次单必须是[待拣货]或[拣货中],当前状态是[" + orderPrint.pickingStatus + "]";
      return this.info;
    }
    // 查询销售订单数据
    let orderList = await this.dbRead
      .createQueryBuilder(SaleOrder, "t")
      .where("orderPrint_Id=:orderPrint_Id AND statusText NOT IN('波次完成','拣货中', '审核成功', '改变物流')", {
        orderPrint_Id: orderPrint.orderPrint_Id
      })
      .getMany();
    if (orderList != null && orderList.length > 0) {
      // 销售单IDs
      let order_Ids = "0";
      for (var orderInfo of orderList) {
        order_Ids += ", " + orderInfo.order_Id;
      }
      let sql = `SELECT COUNT(DISTINCT OrderPrint_Id) cnt, OrderCode cnt FROM dbo.Sale_OrderPrintList 
                  WHERE Order_Id in(" + @0 + @")
                  GROUP BY OrderCode
                  HAVING COUNT(DISTINCT OrderPrint_Id)>1`;
      let table = await this.dbRead.query(sql, [order_Ids]);
      if (table <= 1) {
        // 一个订单没有生成多波次时提醒
        this.info.result = false;
        this.info.msg =
          "订单[" + orderList[0].orderCode + "]状态是[" + orderList[0].statusText + "],该波次不能拣货了!";
        return this.info;
      }
    }
    let sqlOne = `SELECT  l.productModel ,
                  l.productCode ,
                  MAX(l.productName) AS productName ,
                  SUM(l.quantityOrderOrign) AS quantityOrder ,
                  SUM(l.pickQuantity) as pickQuantity,
                  SUM(placeholderStorage) AS placeholderStorage,
                  MAX(v.salePrice) AS salePrice ,
                  MAX(v.remark) AS remark ,
                  0 AS orderList_Id ,
                  0 AS orderPrintList_Id ,
                  l.plateCode ,
                  l.positionName,
                  l.productSpec,
                  MAX(v.smallUnit) AS smallUnit,
                  v.relationCode, v.relationCode2, v.relationCode3, v.relationCode4, v.relationCode5,
                  v.middleBarcode, v.middleUnitConvert, v.bigBarcode, v.unitConvert,MAX(l.weight)AS weight,MAX(l.totalWeight) AS totalWeight
              FROM    dbo.Sale_OrderPrint m
                  INNER JOIN dbo.Sale_OrderPrintList l ON m.orderPrint_Id = l.orderPrint_Id
                  INNER JOIN vBase_ProductInfo_SKU v ON l.productCode = v.productCode
                  INNER JOIN dbo.Base_ProductPlaceHolder h ON l.placeholder_Id = h.placeholder_Id
              WHERE   m.orderPrint_Id = @0 AND ISNULL(quantityOrderOrign,0)>0
              GROUP BY 
                  l.productModel ,
                  l.productCode ,
                  l.plateCode ,
                  l.positionName,
                  l.productSpec,
                  v.relationCode, v.relationCode2, v.relationCode3, v.relationCode4, v.relationCode5,
                  v.middleBarcode, v.middleUnitConvert, v.bigBarcode, v.unitConvert
              ORDER BY l.positionName ,
                  l.productModel`;
    let tableList = await this.dbRead.query(sqlOne, [orderPrint.orderPrint_Id]);
    if (tableList.length == 0) {
      this.info.result = false;
      this.info.msg = "未找到对应的订单明细数据!";
      return this.info;
    } else {
      tableList = tableList.filter(item => item.quantityOrder > item.pickQuantity);
      this.info.result = true;
      model.dataList = tableList;
      model.isSupportPlate = false;
      //#region 波次所在仓库是否支持拍货
      let sqlTwo = `DECLARE @IsPlateManager INT=-1
                      SELECT @IsPlateManager=IsPlateManager FROM dbo.Base_Storage WHERE Storage_Id=(
                       SELECT TOP 1 Storage_Id FROM dbo.Sale_OrderPrint WHERE OrderPrintCode=@0
                      )
                    SELECT @IsPlateManager`;
      let isplatemanager = await this.dbRead.query(sqlTwo, [orderPrintCode]);
      if (isplatemanager == -1) {
        this.info.result = false;
        this.info.msg = "波次单号不存在!";
        return this.info;
      }
      //#endregion
 
      // 创建拣货记录
      await ctx.service.outbound.outScanService.pickingStart(orderPrintCode, orderPrint, tableList);
      //#region 获取入库收货位
      model.offPositionList = await ctx.service.outbound.outScanService.getOffPosition(orderPrint.storage_Id);
      //#endregion
 
      this.info.result = true;
      this.info.data = model;
    }
    return this.info;
  }
  //#endregion
 
  //#region 根据波次号和拍号获取数据
  public async getHoldingStorageByPlateCode(orderPrintCode: string, plateCode: string) {
    this.info.result = false;
    let sql = `SELECT p.productModel,p.productName,p.productCode,p.productSpec,h.placeholderStorage,p.remark,         h.positionName 
            FROM 
            dbo.Base_ProductPosition AS p INNER JOIN dbo.Base_ProductPlaceHolder h ON p.productPosition_Id=h.productPosition_Id
            INNER JOIN dbo.Sale_Order s ON h.MainID=s.order_Id
            WHERE orderPrintCode=@0 AND p.plateCode=@1 AND h.className='销售订单'`;
    let table = await this.dbRead.query(sql, [orderPrintCode, plateCode]);
    if (table.length > 0) {
      this.info.result = true;
      this.info.data = table;
      this.info.msg = "";
    } else {
      this.info.result = false;
      this.info.msg = "未搜索到明细数据!";
    }
    return this.info;
  }
  //#endregion
}