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
import BaseService from "../baseService";
import { BasePosition } from "../../entity/basicInfo/base/basePosition";
import { BaseStorageArea } from "../../entity/basicInfo/base/baseStorageArea";
import { In, MoreThan } from "typeorm";
import { BaseProductPosition } from "../../entity/storage/product/baseProductPosition";
 
/**
 * 仓库信息Service
 */
export default class StorageAreaService extends BaseService {
  //#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 areaList = await this.dbRead.find(BaseStorageArea, {
      storageArea_Id: In(deletedIDs)
    });
 
    for (let dataInfo of areaList) {
      let ppInfo = await this.dbRead.findOne(BaseProductPosition, {
        select: ["productStorage"],
        where: {
          userProduct_Id: userInfo.userProduct_Id,
          storage_Id: dataInfo.storage_Id,
          areaCode: dataInfo.areaCode,
          productStorage: MoreThan(0)
        }
      });
      // 库区已存在库存不允许删除
      if (ppInfo) {
        this.info.result = false;
        this.info.msg = `库区【${dataInfo.areaCode}】已存在库存,不允许删除`;
        return this.info;
      }
    }
 
    // 删除对应货位
    for (let areaInfo of areaList) {
      await this.dbWrite.delete(BasePosition, {
        userProduct_Id: userInfo.userProduct_Id,
        storage_Id: areaInfo.storage_Id,
        areaCode: areaInfo.areaCode
      });
    }
    this.info.result = true;
    return this.info;
  }
  //#endregion
}