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
import { default as BaseController } from "../baseController";
import { Post } from "egg-shell-decorators";
import * as sql from "mssql";
 
import { StorageValidAdjust } from "../../entity/storage/validadjust/storageValidAdjust";
import { StorageConsignorTransferList } from "../../entity/storage/consignor/storageConsignorTransferList";
import { StorageConsignorTransfer } from "../../entity/storage/consignor/storageConsignorTransfer";
import moment = require("moment");
 
export default class StorageConsignorTransferController extends BaseController {
  //#region ConfirmAdjust 确认修改
  @Post()
  public async confirmAdjust() {
    let { ctx } = this;
    let body = ctx.request.body;
    let userInfo = await ctx.helper.userInfo();
    let id = body.id;
 
    try {
      if (!id) {
        this.info.result = false;
        this.info.msg = "未找到信息,id为0";
        this.ctx.body = this.info;
        return;
      }
 
      let adjustInfo = await this.dbRead.findOne(StorageValidAdjust, id);
 
      const connection: any = await this.dbWrite.connection;
      let request = new sql.Request(connection.driver.master);
      request.input("ValidAdjust_Id", body.id);
      request.input("User_Id", userInfo.user_Id);
      request.output("outMsg", sql.NVarChar(2000));
      let result = await request.execute("sp_Stoarge_ValidAdjust_Confirm");
      let outMsg = result.output.outMsg;
      if (outMsg) {
        this.info.result = false;
        this.info.msg = "【" + adjustInfo.validAdjustCode + "】调整失败";
      } else {
        this.info.result = true;
        this.info.msg = "【" + adjustInfo.validAdjustCode + "】调整成功";
      }
    } catch (ex) {
      this.info.result = false;
      this.info.msg = "效期调整失败,原因:" + ex.message.ToString();
    }
    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;
    try {
      // 查询主表
      for (let s_Id of idValue) {
        // 明细校验
        let transferListInfos = await this.dbRead.find(StorageConsignorTransferList, {
          consignorTransfer_Id: s_Id
        });
        for (var item of transferListInfos) {
          //目标货位不能为空
          if (!item.positionName) {
            this.info.result = false;
            this.info.msg = "目标货位有空值,请查正后审核!";
            this.ctx.body = this.info;
            return;
          }
          //目标货主不能为空
          if (!item.consignorName_Target) {
            this.info.result = false;
            this.info.msg = "目标货主有空值,请查正后审核!";
            this.ctx.body = this.info;
            return;
          }
          //转移数量不能为0   TransferQuantity = 1
          if (!item.transferQuantity) {
            this.info.result = false;
            this.info.msg = "转移数量不能为0,请查正后审核!";
            this.ctx.body = this.info;
            return;
          }
        }
        let Storage_ConsignorTransferInfo = await this.dbRead.findOne(StorageConsignorTransfer, s_Id);
        if (Storage_ConsignorTransferInfo.statusText != "新建") {
          this.info.result = false;
          this.info.msg = "只有订单状态为新建才能审核!";
          this.ctx.body = this.info;
          return;
        }
        if (body.auditing == 2) {
          await this.dbWrite.update(
            StorageConsignorTransfer,
            {
              consignorTransfer_Id: s_Id
            },
            {
              auditor: userInfo.userTrueName,
              auditing: 2,
              auditDate: new Date(),
              remark: null,
              statusID: 2,
              statusText: "审核成功"
            }
          );
        }
      }
      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 startSorting() {
    let { ctx } = this;
    let body = ctx.request.body;
    let id = body.id;
 
    if (!id) {
      this.info.result = false;
      this.info.msg = "订单号不能为空!";
      this.ctx.body = this.info;
      return;
    }
 
    let Storage_ConsignorTransferInfo = await this.dbRead.findOne(StorageConsignorTransfer, id);
    // Storage_ConsignorTransfer Storage_ConsignorTransferInfo = Storage_ConsignorTransferRepository.Instance.GetById(model.Id);
    if (Storage_ConsignorTransferInfo.auditing != 2) {
      this.info.result = false;
      this.info.msg = "只有订单状态为审核成功才能分拣!";
      this.ctx.body = this.info;
      return;
    }
 
    this.info = await this.sortingMain(body.id);
    ctx.body = this.info;
  }
  //#endregion
 
  //#region 分拣入口 SortingMain
  /// <summary>
  /// 分拣入口
  /// </summary>
  @Post()
  public async sortingMain(id) {
    let { ctx } = this;
    let body = ctx.request.body;
    let userInfo = await ctx.helper.userInfo();
    // let id = body.id;
    let startDate = moment(Date.now());
 
    //#region 正常分拣
    let transferInfo = await this.dbRead.findOne(StorageConsignorTransfer, id);
 
    const connection: any = await this.dbWrite.connection;
    let request = new sql.Request(connection.driver.master);
    request.input("ConsignorTransfer_Id", body.id);
    request.input("User_Id", userInfo.user_Id);
    request.output("outMsg", sql.NVarChar(2000));
    let result = await request.execute("sp_Storage_ConsignorTransfer_Sorting");
    let outMsg = result.output.outMsg;
    let endDate = moment(Date.now());
    let hour = endDate.diff(startDate, "hour");
    let Minutes = endDate.diff(startDate, "minute");
    let second = endDate.diff(startDate, "second");
 
    this.info.result = outMsg.indexOf("成功") >= 0;
    this.info.msg =
      "单据【" +
      transferInfo.consignorTransferCode +
      "】" +
      outMsg +
      ",数据分析完毕,共耗时" +
      hour +
      "小时" +
      Minutes +
      "分钟" +
      second +
      "秒。<br>";
 
    //#endregion
    return this.info;
  }
  //#endregion
 
  //#region 确认过户
  @Post()
  public async transferConfirm() {
    let { ctx } = this;
    let body = ctx.request.body;
    let userInfo = await ctx.helper.userInfo();
 
    const connection: any = await this.dbWrite.connection;
    let request = new sql.Request(connection.driver.master);
    request.input("consignorTransfer_Id", body.id);
    request.input("User_Id", userInfo.user_Id);
    request.output("outMsg", sql.NVarChar(2000));
    let result = await request.execute("sp_Storage_ConsignorTransfer_Confirm");
    let outMsg = result.output.outMsg;
    if (outMsg) {
      this.info.result = false;
      this.info.msg = "确认过户成功失败";
    } else {
      this.info.result = true;
      this.info.msg = "确认过户成功";
    }
    ctx.body = this.info;
  }
  //#endregion
}