import BaseController from "../baseController";
|
import { Post } from "egg-shell-decorators";
|
import { TMSWayBill } from "../../entity/express/tms/tmsWayBill";
|
|
import { TMSVoyage } from "../../entity/express/tms/tmsVoyage";
|
import { TMSWayBillTracking } from "../../entity/express/tms/tmsWayBillTracking";
|
import { In } from "typeorm";
|
|
/**
|
* 菜单管理
|
*/
|
export default class VoyageController extends BaseController {
|
//#region 实际起飞时间
|
/**
|
* 实际起飞时间
|
*/
|
@Post()
|
public async upActualTakeOffTime() {
|
let { ctx } = this;
|
let body = ctx.request.body;
|
let userInfo = await ctx.helper.userInfo();
|
try {
|
//#region 校验数据
|
if (!body.voyageCode) {
|
this.info.result = false;
|
this.info.msg = "数据不存在";
|
ctx.body = this.info;
|
return;
|
}
|
//#endregion
|
this.info.result = true;
|
var voyageInfo = await this.dbRead.findOne(TMSVoyage, {
|
voyageCode: body.voyageCode
|
});
|
if (voyageInfo != null) {
|
await this.dbWrite.update(TMSVoyage, voyageInfo.voyage_Id, {
|
actualTakeOffTime: body.actualTakeOffTime
|
});
|
await this.dbWrite
|
.createQueryBuilder(TMSWayBill, "t")
|
.update()
|
.set({
|
orderStatus: "航空已发运"
|
})
|
.where(
|
`voyageCode=:voyageCode AND NOT EXISTS (SELECT 1 FROM TMS_WayBillTracking WHERE wayBillCode=TMS_WayBill.wayBillCode AND FromStatus='航空已发运')`,
|
{
|
voyageCode: body.voyageCode
|
}
|
)
|
.execute();
|
|
this.dbWrite
|
.createQueryBuilder(TMSWayBillTracking, "t")
|
.update()
|
.set({
|
createDate: body.actualTakeOffTime
|
})
|
.where(
|
`action='ATD录入' AND EXISTS (SELECT 1 FROM TMS_WayBill WHERE wayBillCode=TMS_WayBillTracking.wayBillCode AND voyageCode=:voyageCode)`,
|
{
|
voyageCode: body.voyageCode
|
}
|
)
|
.execute();
|
|
let sql = `
|
INSERT INTO TMS_WayBillTracking
|
(
|
Action, Remark, user_Id, userTrueName, CreateID, Creator, createDate,
|
PlatUser_Id, PlatUserCode, PlatUserName, PlatCorpName, UserProduct_Id, UserProductCode, UserProductAlias,
|
WayBill_Id, wayBillCode, FromStatus, ToStatus, Consignor_Id, ConsignorName, Storage_Id, StorageName,
|
clientDesc
|
)
|
SELECT 'ATD录入' AS Action, Remark, ${userInfo.user_Id}, '${userInfo.userTrueName}', ${userInfo.user_Id}, '${userInfo.userTrueName}', '${body.actualTakeOffTime}',
|
1 AS PlatUser_Id, PlatUserCode, PlatUserName, PlatCorpName, 1007 AS UserProduct_Id, UserProductCode, UserProductAlias,
|
WayBill_Id, wayBillCode, orderStatus AS FromStatus, '航空已发运' AS ToStatus, Consignor_Id, ConsignorName,
|
Storage_Id, StorageName, '航班起飞' AS clientDesc
|
FROM TMS_WayBill
|
WHERE voyageCode='${voyageInfo.voyageCode}' AND NOT EXISTS (SELECT 1 FROM TMS_WayBillTracking WHERE wayBillCode=TMS_WayBill.wayBillCode AND Action='ATD录入');`;
|
await this.dbWrite.query(sql);
|
} else {
|
this.info.result = false;
|
this.info.msg = "数据不存在";
|
}
|
} catch (ex) {
|
this.info.result = false;
|
this.info.msg = "错误信息:" + ex.message;
|
}
|
ctx.body = this.info;
|
}
|
//#endregion
|
|
//#region 实际落地时间
|
/**
|
* 实际落地时间
|
*/
|
@Post()
|
public async upActualLandingTime() {
|
let { ctx } = this;
|
let body = ctx.request.body;
|
let userInfo = await ctx.helper.userInfo();
|
try {
|
//#region 校验数据
|
if (!body.voyageCode) {
|
this.info.result = false;
|
this.info.msg = "数据不存在";
|
ctx.body = this.info;
|
return;
|
}
|
//#endregion
|
var voyageInfo = await this.dbRead.findOne(TMSVoyage, {
|
voyageCode: body.voyageCode
|
});
|
if (voyageInfo != null) {
|
await this.dbWrite.update(TMSVoyage, voyageInfo.voyage_Id, {
|
actualLandingTime: body.actualLandingTime
|
});
|
this.info.result = true;
|
|
this.dbWrite
|
.createQueryBuilder(TMSWayBillTracking, "t")
|
.update()
|
.set({
|
createDate: body.actualLandingTime
|
})
|
.where(
|
`action='实落ATA' AND EXISTS (SELECT 1 FROM TMS_WayBill WHERE wayBillCode=TMS_WayBillTracking.wayBillCode AND voyageCode=:voyageCode)`,
|
{
|
voyageCode: body.voyageCode
|
}
|
)
|
.execute();
|
|
let sql = `
|
INSERT INTO TMS_WayBillTracking
|
(
|
Action, Remark, user_Id, userTrueName, CreateID, Creator, createDate,
|
PlatUser_Id, PlatUserCode, PlatUserName, PlatCorpName, UserProduct_Id, UserProductCode, UserProductAlias,
|
WayBill_Id, wayBillCode, FromStatus, ToStatus, Consignor_Id, ConsignorName, Storage_Id, StorageName,
|
clientDesc
|
)
|
SELECT '实落ATA' AS Action, Remark, ${userInfo.user_Id}, '${userInfo.userTrueName}', ${userInfo.user_Id}, '${userInfo.userTrueName}', '${body.actualLandingTime}',
|
1 AS PlatUser_Id, PlatUserCode, PlatUserName, PlatCorpName, 1007 AS UserProduct_Id, UserProductCode, UserProductAlias,
|
WayBill_Id, wayBillCode, orderStatus AS FromStatus, '航班到达' AS ToStatus, Consignor_Id, ConsignorName,
|
Storage_Id, StorageName, '航班到达' AS clientDesc
|
FROM TMS_WayBill
|
WHERE voyageCode='${voyageInfo.voyageCode}' AND NOT EXISTS (SELECT 1 FROM TMS_WayBillTracking WHERE wayBillCode=TMS_WayBill.wayBillCode AND Action='实落ATA');`;
|
await this.dbWrite.query(sql);
|
|
await this.dbWrite
|
.createQueryBuilder(TMSWayBill, "t")
|
.update()
|
.set({
|
orderStatus: "航班到达",
|
modifyDate: new Date()
|
})
|
.where(
|
`voyageCode=:voyageCode AND NOT EXISTS (SELECT 1 FROM TMS_WayBillTracking WHERE wayBillCode=TMS_WayBill.wayBillCode AND FromStatus='航班到达')`,
|
{
|
voyageCode: body.voyageCode
|
}
|
)
|
.execute();
|
|
this.info.result = true;
|
} else {
|
this.info.result = false;
|
this.info.msg = "数据不存在";
|
}
|
} catch (ex) {
|
this.info.result = false;
|
this.info.msg = "错误信息:" + ex.message;
|
}
|
ctx.body = this.info;
|
return;
|
}
|
//#endregion
|
|
//#region 校验托盘号
|
/**
|
* 校验托盘号
|
*/
|
@Post()
|
public async checkPlateCode() {
|
let { ctx } = this;
|
let body = ctx.request.body;
|
try {
|
if (!body.voyageCode) {
|
this.info.result = true;
|
this.info.msg = "托盘号不能为空";
|
ctx.body = this.info;
|
return;
|
}
|
|
var waybill = await this.dbRead.findOne(TMSWayBill, {
|
plateCode: body.voyageCode
|
});
|
if (waybill != null) {
|
this.info.result = true;
|
} else {
|
this.info.result = false;
|
this.info.msg = "该托盘号不符合规则";
|
}
|
} catch (ex) {
|
this.info.msg = ex.message;
|
this.info.result = false;
|
}
|
ctx.body = this.info;
|
return;
|
}
|
//#endregion
|
|
//#region 航空发运
|
/**
|
* 航空发运
|
*/
|
@Post()
|
public async send() {
|
let { ctx } = this;
|
let body = ctx.request.body;
|
try {
|
if (!Array.isArray(body.ids) || !body.ids.length) {
|
this.info.result = true;
|
this.info.msg = "至少选择一项";
|
ctx.body = this.info;
|
return;
|
}
|
|
let voyageInfo = await this.dbRead.findOne(TMSVoyage, {
|
voyage_Id: In(body.ids)
|
});
|
|
if (voyageInfo) {
|
for (let plateCode of voyageInfo.plateCodes.split(",")) {
|
// 根据托盘号查询运单号
|
var wayInfo = await this.dbRead.findOne(TMSWayBill, {
|
plateCode: plateCode
|
});
|
if (wayInfo) {
|
// 修改运单中的航空主单号
|
await this.dbWrite.update(
|
TMSWayBill,
|
{
|
plateCode: plateCode
|
},
|
{
|
voyageCode: voyageInfo.voyageCode
|
}
|
);
|
}
|
}
|
}
|
|
await this.dbWrite.update(
|
TMSVoyage,
|
{
|
voyage_Id: In(body.ids)
|
},
|
{
|
voyageStatus: "已发运"
|
}
|
);
|
this.info.result = true;
|
this.info.msg = "发运成功";
|
} catch (ex) {
|
this.info.msg = ex.message;
|
this.info.result = false;
|
}
|
ctx.body = this.info;
|
return;
|
}
|
//#endregion
|
|
//#region 清关
|
/**
|
* 清关
|
*/
|
@Post()
|
public async clearance() {
|
let { ctx } = this;
|
let body = ctx.request.body;
|
try {
|
if (!Array.isArray(body.ids) || !body.ids.length) {
|
this.info.result = true;
|
this.info.msg = "至少选择一项";
|
ctx.body = this.info;
|
return;
|
}
|
await this.dbWrite.update(
|
TMSVoyage,
|
{
|
voyage_Id: In(body.ids)
|
},
|
{
|
voyageStatus: "清关中"
|
}
|
);
|
|
this.info.result = true;
|
this.info.msg = "已设置为清关中";
|
} catch (ex) {
|
this.info.msg = ex.message;
|
this.info.result = false;
|
}
|
ctx.body = this.info;
|
return;
|
}
|
//#endregion
|
|
//#region 清空运单表中的航空主单号
|
@Post()
|
public async deleteVoyageCode() {
|
if (!this.body.voyageCode) {
|
this.info.result = false;
|
this.info.msg = "未找到航空主单号";
|
this.ctx.body = this.info;
|
}
|
try {
|
for (let item of this.body.voyageCode) {
|
await this.dbWrite.update(
|
TMSWayBill,
|
{ voyageCode: item },
|
{
|
voyageCode: null
|
}
|
);
|
}
|
this.info.result = true;
|
this.info.msg = "清除运单表航空主单号成功";
|
this.ctx.body = this.info;
|
} catch (error) {
|
this.info.result = false;
|
this.info.msg = "未找到航空主单号" + error.message;
|
this.ctx.body = this.info;
|
}
|
}
|
|
//#endregion
|
}
|