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
|
}
|