333
schangxiang@126.com
2025-09-19 18966e02fb573c7e2bb0c6426ed792b38b910940
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
import BaseController from "../baseController";
import { Post } from "egg-shell-decorators";
import { BaseExpressSpareCode } from "../../entity/express/spare/baseExpressSpareCode";
import { IsNull } from "typeorm";
 
export default class SpareCodeController extends BaseController {
  //#region GetCensusList 获得统计数据与剩余未分配单数据
  /// <summary>
  /// 获得统计数据与剩余未分配单数据
  /// </summary>
  /// <returns>返回列表集合</returns>
  ///
  @Post()
  public async getStatInfo() {
    let where = await this.ctx.service.common.getWhere();
    try {
      //统计总数据
      var dataInfo = await this.dbRead
        .createQueryBuilder(BaseExpressSpareCode, "t")
        .select("count(1)", "cnt")
        .where(where)
        .getRawOne();
 
      //统计未使用的数据
      where["orderCode"] = IsNull();
      var dataSurInfo = await this.dbRead
        .createQueryBuilder(BaseExpressSpareCode, "t")
        .select("count(1)", "cnt")
        .where(where)
        .getRawOne();
 
      this.info.result = true;
      this.info.data = {
        sumQuantity: dataInfo.cnt,
        surplusQuantity: dataSurInfo.cnt
      };
      this.ctx.body = this.info;
      return;
    } catch (ex) {
      let msg = "异常错误信息:" + ex.message;
      this.info.result = false;
      this.info.msg = msg;
      this.ctx.body = this.info;
      return;
    }
  }
  //#endregion
}