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