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