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
import BaseService from "../baseService";
import { BaseStorage } from "../../entity/basicInfo/base/baseStorage";
import { BasePosition } from "../../entity/basicInfo/base/basePosition";
import { Not } from "typeorm";
 
/**
 * 仓库信息Service
 */
export default class StorageService extends BaseService {
  //#region 创建仓库时自动增加收货位和理货位
  public async onAddSaveAfter(dataInfo: BaseStorage, isAdd: boolean) {
    let userInfo = await this.userInfo;
    if (isAdd) {
      // 自动增加收货位
      let posInfo = new BasePosition();
      posInfo.storage_Id = dataInfo.storage_Id;
      posInfo.storageName = dataInfo.storageName;
      posInfo.parentId = 0;
      posInfo.positionName = "收货位";
      posInfo.positionType = 4;
      posInfo.isFreeze = 0;
      posInfo.isLocked = 0;
      posInfo.isMixProduct = 1;
      posInfo.enable = 1;
 
      posInfo.createDate = new Date();
      posInfo.createID = userInfo.user_Id;
      posInfo.creator = userInfo.userTrueName;
 
      posInfo.platCorpName = dataInfo.platCorpName;
      posInfo.platUserCode = dataInfo.platUserCode;
      posInfo.platUserName = dataInfo.platUserName;
      posInfo.platUser_Id = dataInfo.platUser_Id;
      posInfo.userProductAlias = dataInfo.userProductAlias;
      posInfo.userProductCode = dataInfo.userProductCode;
      posInfo.userProduct_Id = dataInfo.userProduct_Id;
      this.dbWrite.save(posInfo);
 
      // 自动增加下架理货位
      posInfo = new BasePosition();
      posInfo.storage_Id = dataInfo.storage_Id;
      posInfo.storageName = dataInfo.storageName;
      posInfo.parentId = 0;
      posInfo.positionName = "下架理货位";
      posInfo.positionType = 5;
      posInfo.isFreeze = 0;
      posInfo.isLocked = 0;
      posInfo.isMixProduct = 1;
      posInfo.enable = 1;
 
      posInfo.createDate = new Date();
      posInfo.createID = userInfo.user_Id;
      posInfo.creator = userInfo.userTrueName;
 
      posInfo.platCorpName = dataInfo.platCorpName;
      posInfo.platUserCode = dataInfo.platUserCode;
      posInfo.platUserName = dataInfo.platUserName;
      posInfo.platUser_Id = dataInfo.platUser_Id;
      posInfo.userProductAlias = dataInfo.userProductAlias;
      posInfo.userProductCode = dataInfo.userProductCode;
      posInfo.userProduct_Id = dataInfo.userProduct_Id;
      this.dbWrite.save(posInfo);
    }
  }
  //#endregion
  //#region 保存前时间
  public async onAddSaveBefore(t: BaseStorage, isAdd: boolean) {
    // let userInfo = await this.userInfo;
    this.info.result = true;
    let userInfo = await this.userInfo;
    //判断条码是否重复
    if (isAdd) {
      let contractInfo = await this.dbRead.findOne(BaseStorage, {
        userProduct_Id: userInfo.userProduct_Id,
        storageName: t.storageName,
      });
      if (contractInfo) {
        this.info.result = false;
        this.info.msg = `当前仓库名称${t.storageName}已存在不允许重复添加,无法添加!`;
      }
    } else {
      let contractInfo = await this.dbRead.findOne(BaseStorage, {
        userProduct_Id: t.userProduct_Id,
        storageName: t.storageName,
        storage_Id: Not(t.storage_Id),
      });
      if (contractInfo) {
        this.info.result = false;
        this.info.msg = `当前仓库名称${t.storageName}已存在不允许重复添加,无法添加!`;
      }
    }
    return this.info;
  }
  //#endregion
}