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
import BaseService from "../baseService";
import { BasePosition } from "../../entity/basicInfo/base/basePosition";
import { BaseProductPosition } from "../../entity/storage/product/baseProductPosition";
import { In, MoreThan, Not } from "typeorm";
 
/**
 * 货位管理
 */
export default class PositionService extends BaseService {
  //#region 添加保存前事件
  /**
   * 添加保存前事件
   */
  public async onAddSaveBefore(t: BasePosition) {
    let userInfo = await this.userInfo;
    this.info.result = true;
 
    //判断条码是否重复
    let where = {
      positionName: t.positionName,
      storage_Id: t.storage_Id,
      userProduct_Id: userInfo.userProduct_Id,
      position_Id: Not(0)
    };
    if (t.position_Id > 0) {
      where.position_Id = Not(t.position_Id);
    }
 
    let count = await this.dbRead.count(BasePosition, where);
    if (count) {
      this.info.msg = "当前货位【" + t.positionName + "】已存在,不允许重复添加!";
      this.info.result = false;
    }
 
    return this.info;
  }
  //#endregion
 
  //#region 删除货位前事件
  public async onDeleteBefore(deletedIDs: Array<any>) {
    let userInfo = await this.userInfo;
    if (!Array.isArray(deletedIDs) || !deletedIDs.length) {
      this.info.result = false;
      this.info.msg = "参数不存在";
      return this.info;
    }
 
    let dataList = await this.dbRead.find(BasePosition, {
      position_Id: In(deletedIDs)
    });
    for (let dataInfo of dataList) {
      let ppInfo = await this.dbRead.findOne(BaseProductPosition, {
        select: ["productStorage"],
        where: {
          userProduct_Id: userInfo.userProduct_Id,
          storage_Id: dataInfo.storage_Id,
          positionName: dataInfo.positionName,
          productStorage: MoreThan(0)
        }
      });
      // 货位已存在库存不允许删除
      if (ppInfo) {
        this.info.result = false;
        this.info.msg = `货位【${dataInfo.positionName}】已存在库存,不允许删除`;
        return this.info;
      }
    }
 
    this.info.result = true;
    return this.info;
  }
}