import { default as BaseController } from "../baseController";
|
import { Post } from "egg-shell-decorators";
|
import { TMSPDAPrint } from "../../entity/express/tms/tmsPDAPrint";
|
import { TMSWayBill } from "../../entity/express/tms/tmsWayBill";
|
import { TMSPortTemplate } from "../../entity/express/tms/tmsPortTemplate";
|
import { BasePrintTemplate } from "../../entity/sys/print/basePrintTemplate";
|
import { TMSWayBillList } from "../../entity/express/tms/tmsWayBillList";
|
import { ExpressYTOrder } from "../../entity/express/yuantong/expressYTOrder";
|
import { ExpressSFOrder } from "../../entity/express/sf/expressSFOrder";
|
|
/**
|
* 打印模板
|
*/
|
export default class PrintTemplateController extends BaseController {
|
//#region 获得打印机IP和端口
|
/// <summary>
|
/// 清关
|
/// </summary>
|
/// <param name="body"></param>
|
/// <returns></returns>
|
@Post()
|
public async getIP() {
|
let { ctx } = this;
|
let body = ctx.request.body;
|
try {
|
var printInfo = await this.dbRead.findOne(TMSPDAPrint, {
|
user_Id: body.user_Id
|
});
|
if (printInfo != null) {
|
let dataInfo: any = {
|
pdaPrintIP: printInfo.iP,
|
pdaPrintPort: printInfo.port || "8000"
|
};
|
this.info.result = true;
|
this.info.data = dataInfo;
|
} else {
|
this.info.result = false;
|
}
|
} catch (ex) {
|
this.info.msg = ex.message;
|
this.info.result = false;
|
}
|
ctx.body = this.info;
|
}
|
//#endregion
|
|
//#region 获取运单信息和打印机名称
|
@Post()
|
public async getWayBillPrinter() {
|
let { ctx } = this;
|
let body = ctx.request.body;
|
try {
|
console.log(body.Code + " 打印请求:" + JSON.stringify(body));
|
|
var wayInfo = await this.dbRead.findOne(TMSWayBill, {
|
wayBillCode: body.wayBillCode
|
});
|
if (wayInfo != null) {
|
if (!wayInfo.portName) {
|
this.info.result = false;
|
this.info.msg = "未设置口岸信息";
|
ctx.body = this.info;
|
}
|
|
//#region 获取快递模板Id
|
let template = new TMSPortTemplate();
|
var protTemplateName = body.protTemplateName; //定向口岸
|
if (protTemplateName && protTemplateName != "系统分配") {
|
template = await this.dbRead.findOne(TMSPortTemplate, {
|
protTemplateName: protTemplateName
|
});
|
} else {
|
template = await this.dbRead.findOne(TMSPortTemplate, {
|
portName: wayInfo.portName
|
});
|
}
|
if (template == null) {
|
this.info.result = false;
|
this.info.msg = "口岸未设置快递模板";
|
ctx.body = this.info;
|
}
|
|
let btemp = await this.dbRead.findOne(BasePrintTemplate, {
|
printTemplate_Id: template.faceBillTemplateID
|
});
|
if (btemp == null) {
|
this.info.result = false;
|
this.info.msg = "快递模板不存在";
|
ctx.body = this.info;
|
}
|
//#endregion
|
|
//#region 获得口岸信息
|
var printInfo = await this.dbRead.findOne(TMSPDAPrint, {
|
portName: wayInfo.portName
|
});
|
if (printInfo == null) {
|
this.info.result = false;
|
this.info.msg = wayInfo.wayBillCode + wayInfo.portName + "未设置打印机";
|
ctx.body = this.info;
|
}
|
//#endregion
|
|
// 获得模板VueData
|
var templateInfo = await this.dbRead.findOne(BasePrintTemplate, {
|
menu_Id: body.menu_Id
|
});
|
if (templateInfo == null) {
|
this.info.result = false;
|
this.info.msg = wayInfo.wayBillCode + "打印模板不存在";
|
ctx.body = this.info;
|
}
|
|
//#region 获得打印数据
|
//获得明细数据
|
// sql =
|
// SELECT L.ProductName, L.QuantityOrder, L.ProductSpec,
|
// (SELECT TOP 1 CIQNameCn FROM dbo.TMS_ProductInfo_Port WHERE Product_Id=L.Product_Id AND port_Id="
|
// + (wayInfo.port_Id ?? 0) + @") AS CIQNameCn
|
// FROM dbo.TMS_WayBillList L
|
// WHERE L.wayBill_Id=" + wayInfo.wayBill_Id;
|
var detailDataSet = await this.dbRead
|
.createQueryBuilder(TMSWayBillList, "t")
|
.addSelect(
|
`(SELECT TOP 1 CIQNameCn FROM dbo.TMS_ProductInfo_Port WHERE Product_Id=L.Product_Id AND port_Id=${wayInfo.port_Id ||
|
0})`,
|
"cIQNameCn"
|
)
|
.where("wayBill_Id=:wayBill_Id", {
|
wayBill_Id: wayInfo.wayBill_Id
|
});
|
|
var printDetails = await this.dbRead.find(TMSWayBillList, {
|
wayBill_Id: wayInfo.wayBill_Id
|
});
|
var otherData: any = {};
|
if (wayInfo.expressCorpType == "5") {
|
//圆通
|
var ytOrder = await this.dbRead.findOne(ExpressYTOrder, {
|
txLogisticID: wayInfo.wayBillCode
|
});
|
if (ytOrder != null) {
|
otherData["BigPen"] = ytOrder.bigPen;
|
}
|
}
|
|
if (wayInfo.expressCorpType == "19") {
|
//泉州顺丰
|
var QZSFOrder = await this.dbRead.findOne(ExpressSFOrder, {
|
orderCode: wayInfo.wayBillCode,
|
expressCorpName: "泉州顺丰"
|
});
|
if (QZSFOrder != null) {
|
otherData["codingMapping"] = QZSFOrder.codingMapping;
|
otherData["codingMappingOut"] = QZSFOrder.codingMappingOut;
|
otherData["abFlag"] = QZSFOrder.abFlag;
|
otherData["pro_code"] = QZSFOrder.pro_code;
|
}
|
}
|
|
let groupList = printDetails.reduce(
|
(all: Array<any>, next) =>
|
all.some(item => item["wayBill_Id"] == next["wayBill_Id"]) ? all : [...all, next],
|
[]
|
);
|
|
var billDataInfo = {
|
mainInfo: wayInfo,
|
detaiList: {
|
total: printDetails.length,
|
rows: detailDataSet,
|
orderCount: groupList.length
|
},
|
otherData: otherData
|
};
|
|
//#endregion
|
|
// 更新打印次数
|
try {
|
await this.dbWrite.update(TMSWayBill, wayInfo.wayBill_Id, {
|
printNum: (wayInfo.printNum || 0) + 1
|
});
|
await this.dbWrite.increment(TMSWayBill, wayInfo.wayBill_Id, "printNum", wayInfo.printNum || 0);
|
console.log(wayInfo.wayBillCode + " 更新打印次数:" + ((wayInfo.printNum || 0) + 1));
|
} catch (Exception) {}
|
|
this.info.result = true;
|
this.info.data = {
|
wayInfo: {
|
wayBill_Id: wayInfo.wayBill_Id,
|
wayBillCode: wayInfo.wayBillCode
|
},
|
printInfo: {
|
printerName: printInfo.printerName,
|
portName: printInfo.portName
|
},
|
// 模板ID
|
menu_Id: btemp.menu_Id,
|
// 打印模板VueData
|
vueData: templateInfo.vueData,
|
// 打印数据
|
billDataInfo: billDataInfo
|
};
|
} else {
|
this.info.result = false;
|
this.info.msg = "运单号不存在";
|
}
|
} catch (ex) {
|
this.info.msg = ex.message;
|
this.info.result = false;
|
}
|
ctx.body = this.info;
|
}
|
//#endregion
|
|
//#region 获取打印模板
|
@Post()
|
public async getPrintTemplate() {
|
let { ctx } = this;
|
let body = ctx.request.body;
|
try {
|
// 获得模板VueData
|
var templateInfo = await this.dbRead.findOne(BasePrintTemplate, {
|
menu_Id: body.menu_Id
|
});
|
if (!templateInfo) {
|
this.info.result = false;
|
//this.info.msg = "打印模板不存在";
|
ctx.body = this.info;
|
}
|
|
this.info.result = true;
|
this.info.data = JSON.parse(templateInfo.vueData);
|
} catch (ex) {
|
this.info.msg = ex.message;
|
this.info.result = false;
|
}
|
ctx.body = this.info;
|
}
|
//#endregion
|
|
//#region getTemplateList
|
/// <summary>
|
/// 新增项
|
/// </summary>
|
/// <param name="this.body">保存请求参数</param>
|
@Post()
|
public async getTemplateList() {
|
let userInfo = await this.userInfo;
|
try {
|
var where =
|
"userProduct_Id=:userProduct_Id And parentId in(Select printTemplate_Id From Base_PrintTemplate Where templateName=:templateName)";
|
var dataList = await this.dbRead
|
.createQueryBuilder(BasePrintTemplate, "t")
|
.select(["printTemplate_Id", "menu_Id", "templateName"])
|
.where(where, {
|
userProduct_Id: userInfo.userProduct_Id,
|
templateName: this.body.templateName
|
})
|
.getRawMany();
|
|
this.info.data = dataList;
|
this.info.result = true;
|
} catch (ex) {
|
this.info.result = false;
|
this.info.msg = "获取打印模板失败," + ex.message;
|
}
|
|
this.ctx.body = this.info;
|
}
|
//#endregion
|
|
//#region getPortList 获取口岸模板列表
|
@Post()
|
public async getPortList() {
|
let { ctx } = this;
|
try {
|
var portList = await this.dbRead.find(TMSPortTemplate);
|
|
this.info.result = true;
|
this.info.data = portList.map(s => {
|
return {
|
portTemplate_Id: s.portTemplate_Id,
|
protTemplateName: s.protTemplateName
|
};
|
});
|
} catch (ex) {
|
this.info.msg = ex.message;
|
this.info.result = false;
|
}
|
ctx.body = this.info;
|
}
|
//#endregion
|
|
//#region AddItem
|
/// <summary>
|
/// 新增项
|
/// </summary>
|
@Post()
|
public async addItem() {
|
try {
|
var tempInfo = new BasePrintTemplate();
|
tempInfo.templateName = this.body.templateName;
|
tempInfo.parentId = this.body.parentId;
|
tempInfo.vueData = `{"dataOptions":{
|
"menu_Id": 0,
|
"projectName": null,
|
"tableView": null,
|
"idField": null,
|
"router": null,
|
"title": "${this.body.value}",
|
"paddingTop": 30,
|
"paddingBottom": 30,
|
"paddingLeft": 30,
|
"paddingRight": 30,
|
"width": 830,
|
"height": 500
|
},"fields":[]}`;
|
await this.setAccountInfo(tempInfo);
|
await this.dbWrite.save(tempInfo);
|
|
this.info.result = true;
|
this.info.msg = "新增成功";
|
} catch (ex) {
|
this.info.result = false;
|
this.info.msg = "保存失败," + ex.message;
|
}
|
|
this.ctx.body = this.info;
|
}
|
//#endregion
|
|
//#region CopyItem
|
/// <summary>
|
/// 复制项
|
/// </summary>
|
@Post()
|
public async copyItem() {
|
try {
|
var tempInfo = await this.dbRead.findOne(BasePrintTemplate, this.body.id);
|
if (tempInfo != null) {
|
tempInfo.printTemplate_Id = 0;
|
tempInfo.templateName = this.body.value;
|
await this.dbWrite.insert(BasePrintTemplate, tempInfo);
|
this.info.result = true;
|
this.info.msg = "复制成功";
|
}
|
} catch (ex) {
|
this.info.result = false;
|
this.info.msg = "保存失败," + ex.message;
|
}
|
|
this.ctx.body = this.info;
|
}
|
//#endregion
|
|
//#region UpdateTitle
|
/// <summary>
|
/// 修改名称
|
/// </summary>
|
@Post()
|
public async updateTitle() {
|
try {
|
var tempInfo = await this.dbRead.findOne(BasePrintTemplate, this.body.id);
|
if (tempInfo != null) {
|
tempInfo.templateName = this.body.value;
|
await this.dbWrite.update(BasePrintTemplate, tempInfo.printTemplate_Id, {
|
templateName: this.body.value
|
});
|
}
|
|
this.info.result = true;
|
this.info.msg = "保存成功";
|
} catch (ex) {
|
this.info.result = false;
|
this.info.msg = "保存失败," + ex.message;
|
}
|
|
this.ctx.body = this.info;
|
}
|
//#endregion
|
|
//#region DeleteItem
|
/// <summary>
|
/// 上次项
|
/// </summary>
|
/// <param name="DeleteItem">保存请求参数</param>
|
@Post()
|
public async deleteItem() {
|
try {
|
var tempInfo = await this.dbRead.findOne(BasePrintTemplate, this.body.id);
|
if (tempInfo != null) {
|
tempInfo.templateName = this.body.value;
|
await this.dbWrite.delete(BasePrintTemplate, tempInfo.printTemplate_Id);
|
this.info.result = true;
|
this.info.msg = "删除成功";
|
}
|
} catch (ex) {
|
this.info.result = false;
|
this.info.msg = "保存失败," + ex.message;
|
}
|
|
this.ctx.body = this.info;
|
}
|
//#endregion
|
|
//#region MoveItem
|
/// <summary>
|
/// 移动项
|
/// </summary>
|
/// <param name="this.body">保存请求参数</param>
|
@Post()
|
public async moveItem() {
|
try {
|
var tempInfo = await this.dbRead.findOne(BasePrintTemplate, this.body.id);
|
if (tempInfo != null) {
|
var parentId = this.body.value;
|
if (this.body.id == this.body.value) {
|
parentId = 0;
|
}
|
await this.dbWrite.update(BasePrintTemplate, tempInfo.printTemplate_Id, {
|
parentId: parentId
|
});
|
this.info.result = true;
|
this.info.msg = "移动成功";
|
}
|
} catch (ex) {
|
this.info.result = false;
|
this.info.msg = "保存失败," + ex.message;
|
}
|
|
this.ctx.body = this.info;
|
}
|
//#endregion
|
|
//#region savePrintTemplate 创建BaseVue页面
|
/// <summary>
|
/// 创建Vue页面
|
/// </summary>
|
///
|
@Post()
|
public async savePrintTemplate() {
|
try {
|
var printInfo = await this.dbRead.findOne(BasePrintTemplate, this.body.printTemplate_Id);
|
if (printInfo != null) {
|
printInfo.vueData = this.body.vueData;
|
printInfo.templateName = this.body.templateName;
|
printInfo.templateType = this.body.templateType;
|
printInfo.menu_Id = this.body.menu_Id;
|
await this.dbWrite.save(BasePrintTemplate, printInfo);
|
} else {
|
printInfo = new BasePrintTemplate();
|
await this.setAccountInfo(printInfo);
|
|
printInfo.printTemplate_Id = this.body.printTemplate_Id;
|
printInfo.templateName = this.body.templateName;
|
printInfo.templateType = this.body.templateType;
|
printInfo.menu_Id = this.body.menu_Id;
|
printInfo.vueData = this.body.vueData;
|
await this.dbWrite.save(BasePrintTemplate, printInfo);
|
}
|
|
this.info.result = true;
|
this.info.msg = "保存成功";
|
|
this.ctx.body = this.info;
|
} catch (ex) {
|
let msg = "保存失败:" + ex.message;
|
this.info.result = false;
|
this.info.msg = msg;
|
this.ctx.body = this.info;
|
}
|
}
|
//#endregion
|
}
|