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
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
// import * as sql from "mssql";
import { Post } from "egg-shell-decorators";
import BaseController from "../../baseController";
import { xStatStorageDay } from "../../../entity/stat/storage/xStatStorageDay";
import moment = require("moment");
import { StatStorageDay } from "../../../entity/stat/storage/statStorageDay";
import { StatStorageDayDetails } from "../../../entity/stat/storage/statStorageDayDetails";
 
/**
 * 库存统计
 */
export default class VpurchaseOrderController extends BaseController {
  // #region 获取库存总数量信息
  /**
        / 获取库存总数量信息
        */
  @Post()
  public async getStorageDayStatistics() {
    let { ctx } = this;
    let body = ctx.request.body;
    // let userInfo = await ctx.helper.userInfo();
    let storage_Id = body.storage_Id;
    let consignor_Id = body.consignor_Id;
    let userProduct_Id = body.userProduct_Id;
    let provider_Id = body.provider_Id;
    let beginTime = body.beginTime;
    let endTime = body.endTime;
    let where: any = {};
    where.userProduct_Id = userProduct_Id;
    if (storage_Id) {
      where.storage_Id = storage_Id;
    }
    if (provider_Id) {
      where.provider_Id = provider_Id;
    }
    if (consignor_Id) {
      where.consignor_Id = consignor_Id;
    }
    // if (beginTime) {
    //   where.storageDay = moment(beginTime).format("YYYY-MM-DD");
    // }
    // if (endTime) {
    //   where.storageDay = moment(endTime).format("YYYY-MM-DD");
    // }
    try {
      let quantityInfo;
      // 库存总量查询
      quantityInfo = await this.dbRead
        .createQueryBuilder(xStatStorageDay, "t")
        .select("MAX(productName)", "productName")
        .addSelect("sum(productStorage)", "sumproductStorage")
        .addSelect("sum(validStorage)", "sumvalidStorage")
        .where(where)
        .andWhere("storageDay>=:beginTime and  storageDay<=:endTime", {
          beginTime: beginTime,
          endTime: endTime
        })
        .getRawMany();
 
      this.info.result = true;
      this.info.msg = "获取成功";
      this.info.data = quantityInfo;
    } catch (ex) {
      this.info.result = false;
      this.info.msg = "获取数据时出错:" + ex.message;
    }
    ctx.body = this.info;
  }
  // #endregion
 
  // #region 获取每日库存总数量信息
  /**
        / 获取每日库存总数量信息
        */
  @Post()
  public async getProductStatistics() {
    let { ctx } = this;
    let body = ctx.request.body;
    // let userInfo = await ctx.helper.userInfo();
    let storage_Id = body.storage_Id;
    let consignor_Id = body.consignor_Id;
    let userProduct_Id = body.userProduct_Id;
    let provider_Id = body.provider_Id;
    let beginTime = body.beginTime;
    let type = body.type;
    let where: any = {};
    where.userProduct_Id = userProduct_Id;
    if (storage_Id) {
      where.storage_Id = storage_Id;
    }
    if (provider_Id) {
      where.provider_Id = provider_Id;
    }
    if (consignor_Id) {
      where.consignor_Id = consignor_Id;
    }
    if (beginTime) {
      where.storageDay = moment(beginTime).format("YYYY-MM-DD");
    }
    try {
      let quantityInfo;
      if (type === "每日库存主表") {
        // 每日物料库存总量查询
        quantityInfo = await this.dbRead
          .createQueryBuilder(StatStorageDay, "t")
          .select("MAX(productName)", "productName")
          .addSelect("sum(productStorage)", "sumproductStorage")
          .addSelect("sum(validStorage)", "sumvalidStorage")
          .where(where)
          .getRawMany();
      } else {
        // 每日物料明细库存总量查询
        quantityInfo = await this.dbRead
          .createQueryBuilder(StatStorageDayDetails, "t")
          .select("MAX(productName)", "productName")
          .addSelect("sum(productStorage)", "sumproductStorage")
          .addSelect("sum(validStorage)", "sumvalidStorage")
          .where(where)
          .getRawMany();
      }
 
      this.info.result = true;
      this.info.msg = "获取成功";
      this.info.data = quantityInfo;
    } catch (ex) {
      this.info.result = false;
      this.info.msg = "获取数据时出错:" + ex.message;
    }
    ctx.body = this.info;
  }
  // #endregion
}