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
import { default as BaseController } from "../../baseController";
import { Post } from "egg-shell-decorators";
export default class PositionShowController extends BaseController {
  //#region 货位总数量
  /**
   *货位总数量
   */
  @Post()
  public async getPostionNameSum() {
    let { ctx } = this;
    let body = ctx.body; // 接收前端发来的数据
    let userInfo = await ctx.helper.userInfo(); // 权限
    let userProduct_Id = userInfo.userProduct_Id; // 获取权限id
    try {
      // 总数量
      let sql = `SELECT COUNT(positionName) AS positionCount FROM Base_Position WHERE Enable = 1 AND AreaCode =${body.areaCode} AND UserProduct_Id=  ${userProduct_Id} AND Storage_Id=${body.storage_Id}`;
      let positionCount = await this.dbRead.query(sql);
      positionCount = positionCount[0].positionCount;
 
      // 有库存
      sql = `SELECT COUNT(positionName) AS hasStorageCount FROM Base_Position p WHERE Enable = 1 
      AND AreaCode =${body.areaCode} AND UserProduct_Id=  ${userProduct_Id} AND Storage_Id=${body.storage_Id}
      AND EXISTS(SELECT 1 FROM dbo.Base_ProductPosition pp WHERE pp.Storage_Id=p.Storage_Id AND pp.PositionName=p.PositionName AND pp.ProductStorage>0)
      `;
      let hasStorageCount = await this.dbRead.query(sql);
      hasStorageCount = hasStorageCount[0].hasStorageCount;
 
      // 物料总数量
      sql = `SELECT isnull(SUM(pp.ProductStorage),0) AS productStorage FROM dbo.vBase_ProductPosition pp WHERE pp.Storage_Id=${body.storage_Id}   AND pp.ProductStorage>0
      AND pp.AreaCode=${body.areaCode} 
      `;
      let productStorage = await this.dbRead.query(sql);
      productStorage = productStorage[0].productStorage;
 
      this.info.data = {
        positionCount: positionCount,
        hasStorageCount: hasStorageCount,
        noStorageCount: positionCount - hasStorageCount,
        productStorage: productStorage
      };
      this.info.result = true;
    } catch (error) {
      this.info.result = false;
      this.info.msg = "错误信息:" + error.message;
    }
    ctx.body = this.info;
  }
  //#endregion
}