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
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
import BaseController from "../baseController";
import { Post } from "egg-shell-decorators";
import { In } from "typeorm";
import { TMSWayBill } from "../../entity/express/tms/tmsWayBill";
import { TMSWayBillList } from "../../entity/express/tms/tmsWayBillList";
import { BasePrintTemplate } from "../../entity/sys/print/basePrintTemplate";
 
/**
 * 格口模板
 */
export default class PortTemplateController extends BaseController {
  //#region 获取模板信息
  /// <summary>
  /// 获取模板信息
  /// </summary>
  /// <param name="reqinfo">请求参数</param>
  /// <returns></returns>
  @Post()
  public async getTemplateInfo() {
    let userInfo = await this.userInfo;
    try {
      var where = `PrintTemplate_Id IN(
                    SELECT FaceBillTemplateID FROM TMS_PortTemplate WHERE portName=:portName AND expressCorp_Id=:expressCorp_Id
                ) And userProduct_Id=:userProduct_Id`;
      var tInfo = await this.dbRead
        .createQueryBuilder(BasePrintTemplate, "t")
        .where(where, {
          userProduct_Id: userInfo.userProduct_Id,
          portName: this.body.portName,
          expressCorp_Id: this.body.expressCorp_Id
        })
        .getOne();
 
      if (tInfo != null) {
        this.info.data = tInfo;
        this.info.result = true;
      } else {
        this.info.result = false;
        this.info.msg = "模板不存在!";
      }
    } catch (ex) {
      let msg = "异常错误信息:" + ex.message;
      this.info.result = false;
      this.info.msg = msg;
    }
    this.ctx.body = this.info;
  }
  //#endregion
 
  //#region 打印物流单 Print
  @Post()
  public async print() {
    try {
      var orderList = await this.dbRead.find(TMSWayBill, {
        wayBill_Id: In(this.body.ids)
      });
 
      var dataList = [];
      for (let printInfo of orderList) {
        //获得明细数据
        var orderDetails = await this.dbRead.find(TMSWayBillList, {
          wayBill_Id: printInfo.wayBill_Id
        });
 
        let groupList = orderDetails.reduce(
          (all: Array<any>, next) => (all.some(item => item.wayBill_Id == next.wayBill_Id) ? all : [...all, next]),
          []
        );
 
        //构建单据数据
        dataList.push({
          mainInfo: printInfo,
          detaiList: {
            total: orderDetails.length,
            rows: orderDetails,
            orderCount: groupList.length
          }
        });
        return true;
      }
      this.info.result = true;
      this.info.data = dataList;
    } catch (ex) {
      this.info.result = false;
      this.info.msg = "加载数据失败:" + ex.message;
    }
    this.ctx.body = this.info;
  }
  //#endregion
}