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
import { default as BaseController } from "../baseController";
import { Post } from "egg-shell-decorators";
import * as sql from "mssql";
import { StorageAllocateEnter } from "../../entity/storage/allocate/storageAllocateEnter";
import { BasePosition } from "../../entity/basicInfo/base/basePosition";
import { StorageAllocateEnterList } from "../../entity/storage/allocate/storageAllocateEnterList";
import { StorageAllocateApply } from "../../entity/storage/allocate/storageAllocateApply";
import { StorageAllocateApplyList } from "../../entity/storage/allocate/storageAllocateApplyList";
export default class AllocateEnterController extends BaseController {
  //#region Auditing 审核
  @Post()
  public async auditing() {
    let { ctx } = this;
    let body = ctx.request.body;
    let userInfo = await ctx.helper.userInfo();
    let errorPositionName = "";
    try {
      let enterInfo = await this.dbRead.findOne(StorageAllocateEnter, {
        allocateEnter_Id: body.idValue
      });
 
      let enterListInfos = await this.dbRead.find(StorageAllocateEnterList, {
        allocateEnter_Id: body.idValue
      });
      // 明细数据
      let emptyPositions = enterListInfos.filter(row => !row.positionName).map(item => item.productCode);
      if (emptyPositions.length) {
        let msg = emptyPositions.join(",") + "货位不能为空";
        this.info.msg = msg;
        this.info.result = false;
        this.ctx.body = this.info;
        return;
      }
 
      //验证调入货位是否正确
      let groupByPositionInfos = enterListInfos.filter(row => row.positionName);
      // 对单据进行分组
      groupByPositionInfos = groupByPositionInfos.reduce(
        (all: Array<any>, next) => (all.some(item => item.positionName === next.positionName) ? all : [...all, next]),
        []
      );
      for (let positionInfo of groupByPositionInfos) {
        let positionInfos = await this.dbRead.find(BasePosition, {
          storage_Id: enterInfo.storage_Id_In,
          positionName: positionInfo.positionName
        });
        if (!positionInfos) {
          if (errorPositionName) errorPositionName += ",";
          errorPositionName += "'" + positionInfo.positionName + "'";
        }
      }
      if (errorPositionName) {
        this.info.result = false;
        this.info.msg = "货位:" + errorPositionName + "在仓库【" + enterInfo.storageName_In + "】中不存在,请更改后再审核!";
        ctx.body = this.info;
      }
      const connection: any = await this.dbWrite.connection;
      let request = new sql.Request(connection.driver.master);
      request.input("allocateEnter_Id", body.idValue);
      request.input("user_Id", userInfo.user_Id);
      request.input("userTrueName", userInfo.userTrueName);
      request.output("outMsg", sql.NVarChar(2000));
      let result = await request.execute("sp_Storage_AllocateEnter_Check");
      let outMsg = result.output.outMsg;
      if (outMsg) {
        this.info.msg = outMsg;
        this.info.result = false;
      } else {
        this.info.msg = "审核成功";
        this.info.result = true;
      }
      ctx.body = this.info;
    } catch (error) {
      this.info.msg = "审核失败" + error.message;
      this.info.result = false;
      ctx.body = this.info;
    }
  }
  //#endregion
  //#region getByCode
  /// <summary>
  /// 根据调拨申请单Code获取调拨申请单管理信息
  /// </summary>
  /// <param name="AllocateEnterCode">调拨申请单编号</param>
  /// <returns>调拨申请单对象</returns>
  @Post()
  public async getByCode() {
    let { ctx } = this;
    let body = ctx.request.body;
    let userInfo = await ctx.helper.userInfo();
    if (userInfo == null) {
      this.info.msg = "未找到用户信息";
      this.info.result = false;
      ctx.body = this.info;
    }
    try {
      let model = await this.dbRead.findOne(StorageAllocateApply, {
        allocateApplyCode: body.code,
        userProduct_Id: userInfo.userProduct_Id
      });
      //明细数据
      let detailList = await this.dbRead.find(StorageAllocateApplyList, {
        allocateApply_Id: model.allocateApply_Id
      });
      if (detailList) {
        this.info.msg = "获取信息成功";
        this.info.result = true;
        this.info.data = {
          consignor_Id: model.consignor_Id,
          consignorCode: model.consignorCode,
          consignorName: model.consignorName,
          storage_Id: model.storage_Id,
          storageName: model.storageName,
          storage_Id_In: model.storage_Id_In,
          storageName_In: model.storageName_In,
          storage_AllocateApplyList: detailList
        };
      }
    } catch (error) {
      this.info.msg = "未找到用户信息" + error.message;
      this.info.result = false;
      ctx.body = this.info;
    }
 
    ctx.body = this.info;
  }
  //#endregion
}