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
import * as sql from "mssql";
import { Post } from "egg-shell-decorators";
import BaseController from "../baseController";
import { BasePosition } from "../../entity/basicInfo/base/basePosition";
 
/**
 * 下架回拣
 */
export default class OrderPickingShelveController extends BaseController {
  //#region 下架回拣 - 获取入库收货位
  @Post()
  public async getOffPosition() {
    let { ctx } = this;
    let body = ctx.request.body;
    let storage_Id = body.storage_Id;
 
    let outDateSet = await this.dbRead.find(BasePosition, {
      select: ["positionName"],
      where: {
        storage_Id: storage_Id,
        positionType: 5
      }
    });
    if (!outDateSet.length) {
      this.info.result = false;
      this.info.msg = "理货位不存在";
      ctx.body = this.info;
      return;
    } else {
      this.info.result = true;
      this.info.data = outDateSet;
      ctx.body = this.info;
      return;
    }
  }
  //#endregion
 
  //#region 下架回拣 - 获得理货位数据
  @Post()
  public async getOffPositionData() {
    let { ctx } = this;
    let body = ctx.request.body;
    let storage_Id = body.storage_Id;
    let positionName = body.positionName;
    let productModel = body.productModel;
    if (!positionName) {
      this.info.result = false;
      this.info.msg = "理货位不能为空!";
      ctx.body = this.info;
      return;
    }
    if (!productModel) {
      this.info.result = false;
      this.info.msg = "条码不能为空!";
      ctx.body = this.info;
      return;
    }
 
    let query = `
                SELECT top 1 L.product_Id,L.productCode,L.productModel,0 AS finishedQuantity,L.productSpec, L.productName,
                    L.positionName, NULL AS shelvePosition, storage_Id, storageName, L.batchNumber,L.purchasePrice,
                    L.plateCode, CONVERT(varchar(100), L.produceDate, 120) AS produceDate, I.relationCode, I.relationCode2, I.relationCode3, I.relationCode4, I.relationCode5,
                    L.middleBarcode, I.middleUnitConvert, L.bigBarcode, I.unitConvert,L.validQty as validQty,L.consignor_Id,L.consignorCode,L.consignorName,L.weight,L.TotalWeight
                FROM dbo.vBase_ProductPosition L INNER JOIN dbo.vBase_ProductInfo_SKU I ON L.product_Id=I.product_Id
                WHERE L.positionName=@0 
                    AND L.storage_Id=@1
                    AND L.productModel COLLATE Chinese_PRC_CS_AS=@2
                    AND L.PositionType=5
                    AND L.validQty>0
                ;`;
    let orderList = await this.dbRead.query(query, [positionName, storage_Id, productModel]);
    if (!orderList || orderList.length == 0) {
      this.info.result = false;
      this.info.msg = "未找到可上架理货位数据,请检查一下是否将理货位的库存释放占位了";
    } else {
      this.info.result = true;
      this.info.data = orderList;
    }
    ctx.body = this.info;
    return;
  }
  //#endregion
 
  //#region 下架回拣 - 扫描保存
  /// <summary>
  /// 说明:扫描保存
  /// </summary>
  /// <returns></returns>
  @Post()
  public async shelveOffPositionSave() {
    let { ctx } = this;
    let body = ctx.request.body;
    let userInfo = await ctx.helper.userInfo();
    let productModelList = body.productDataList;
 
    let menu_Id = 103;
    if (!productModelList.length) {
      this.info.result = false;
      this.info.msg = "已扫描数量不能全部为零";
      ctx.body = this.info;
      return;
    }
 
    try {
      let excelDT = new sql.Table();
      excelDT.columns.add("storage_Id", sql.Int);
      excelDT.columns.add("storageName", sql.NVarChar(50));
      excelDT.columns.add("product_Id", sql.Int);
      excelDT.columns.add("finishedQuantity", sql.Int);
      excelDT.columns.add("productCode", sql.NVarChar(50));
      excelDT.columns.add("productModel", sql.NVarChar(50));
      excelDT.columns.add("positionName", sql.NVarChar(50));
      excelDT.columns.add("shelvePosition", sql.NVarChar(50));
      excelDT.columns.add("produceDate", sql.NVarChar(50));
 
      excelDT.columns.add("purchasePrice", sql.Decimal(14, 4));
      excelDT.columns.add("batchNumber", sql.NVarChar(50));
      excelDT.columns.add("productSpec", sql.NVarChar(50));
      excelDT.columns.add("plateCode", sql.NVarChar(50));
 
      excelDT.columns.add("consignor_Id", sql.Int);
      excelDT.columns.add("consignorCode", sql.NVarChar(50));
      excelDT.columns.add("consignorName", sql.NVarChar(50));
 
      excelDT.columns.add("weight", sql.Decimal(14, 4));
      excelDT.columns.add("TotalWeight", sql.Decimal(14, 4));
 
      for (var dataItem of productModelList) {
        excelDT.rows.add(
          dataItem.storage_Id,
          dataItem.storageName,
          dataItem.product_Id,
          dataItem.finishedQuantity,
 
          dataItem.productCode,
          dataItem.productModel,
          dataItem.positionName,
          dataItem.shelvePosition,
          dataItem.produceDate,
 
          dataItem.purchasePrice,
          dataItem.batchNumber,
          dataItem.productSpec,
          dataItem.plateCode,
 
          dataItem.consignor_Id,
          dataItem.consignorCode,
          dataItem.consignorName,
          dataItem.weight,
          dataItem.TotalWeight
        );
      }
      let shelveCode = await ctx.service.common.getCodeRegular(269);
      const connection: any = await this.dbWrite.connection;
      let request = new sql.Request(connection.driver.master);
      request.input("shelveCode", shelveCode);
      request.input("user_Id", userInfo.user_Id);
      request.input("menu_Id", menu_Id);
      request.input("excelDT", excelDT);
      request.output("outMsg", sql.NVarChar(2000));
      let result = await request.execute("sp_Sale_Shelve_OffPosition");
      let outMsg = result.output.outMsg;
 
      if (outMsg) {
        this.info.msg = outMsg;
        this.info.result = false;
      } else {
        this.info.msg = "确认上架成功!";
        this.info.result = true;
      }
    } catch (error) {
      this.info.msg = "错误:" + error.message;
      this.info.result = false;
    }
    ctx.body = this.info;
    return;
  }
  //#endregion
}