222
schangxiang@126.com
2025-06-13 6a8393408d8cefcea02b7a598967de8dc1e565c2
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
import { srm, tran, rgv } from "../public/webServiceHelper";
import { Post } from "egg-shell-decorators";
import BaseController from "./baseController";
import * as mssql from "mssql";
import { PurchaseShelve } from "../entity/inbound/purchase/purchaseShelve";
 
export default class WcfController extends BaseController {
  //#region entry
  @Post()
  public async entry() {
    let { ctx } = this;
    let data: any;
    try {
      console.log("this.body.type =", this.body.type);
      console.log("this.body.method =", this.body.method);
      console.log("this.body.params =", this.body.params);
      if (this.body.type === "srm") {
        data = await srm[this.body.method](this.body.params);
        this.info.result = true;
        this.info.data = data;
        if (this.body.method === "isTaskFinish" && Number(data.IsTaskFinishResult) === 1) {
          // 码垛机上架完成执行入库操作
          await this.enterStorage();
        }
      } else if (this.body.type === "tran") {
        data = await tran[this.body.method](this.body.params);
        this.info.result = true;
        this.info.data = data;
        if (this.body.method === "isPassed" && "" + data.IsPassedResult === "true") {
          // 外形检测通过后,先分配空货位
          await this.sortPosition();
        }
      } else if (this.body.type === "rgv") {
        data = await rgv[this.body.method](this.body.params);
        this.info.result = true;
        this.info.data = data;
      } else {
        this.info.result = false;
        this.info.msg = "类型未定义";
      }
 
      ctx.body = this.info;
    } catch (error) {
      this.info.result = false;
      this.info.msg = error.message;
      ctx.body = this.info;
    }
  }
  //#endregion
 
  //#region 分配货位
  private async sortPosition() {
    try {
      let orderInfo = await this.dbRead.findOne(PurchaseShelve, 5930);
      orderInfo.positionName = "03-19-03";
      orderInfo.onShelveStatus = "在途中";
      await this.dbWrite.save(orderInfo);
      this.info.msg = "确认入库成功";
      this.info.result = true;
    } catch (error) {
      this.info.result = false;
      this.info.msg = "错误:" + error.message;
    }
  }
  //#endregion
 
  //#region 确认入库
  private async enterStorage() {
    try {
      const connection: any = await this.dbWrite.connection;
      let request = new mssql.Request(connection.driver.master);
      request.input("order_Id", 5930);
      request.input("user_Id", 1);
      request.input("userTrueName", "码垛机");
      request.output("outMsg", mssql.NVarChar(2000));
      let result = await request.execute("sp_Purchase_Order_OneKeyShelve");
      let outMsg = result.output.outMsg;
      if (outMsg != null && outMsg) {
        this.info.msg = outMsg;
        this.info.result = false;
      } else {
        this.info.msg = "确认入库成功";
        this.info.result = true;
      }
    } catch (error) {
      this.info.result = false;
      this.info.msg = "错误:" + error.message;
    }
  }
  //#endregion
}