import BaseService from "../baseService";
|
import { TMSWayBill } from "../../entity/express/tms/tmsWayBill";
|
import { TMSWayBillAbnormal } from "../../entity/express/tms/tmsWayBillAbnormal";
|
import { TMSPort } from "../../entity/express/tms/tmsPort";
|
import moment = require("moment");
|
import { TMSWayBillList } from "../../entity/express/tms/tmsWayBillList";
|
import { TMSAbnormal } from "../../entity/express/tms/tmsAbnormal";
|
import { TMSIdCard } from "../../entity/express/tms/tmsIdCard";
|
import { TMSWayBillReceive } from "../../entity/express/tms/tmsWayBillReceive";
|
|
export default class SortingHelperService extends BaseService {
|
public async checkRule(wayBillCode: string, type: string) {
|
let redis = await this.app.redis.clients.get("fenjianji");
|
try {
|
//#region 校验信息
|
if (!wayBillCode) {
|
this.info.result = false;
|
this.info.msg = "运单Id不能为空";
|
|
return this.info;
|
}
|
//#endregion
|
let waybill = await this.dbRead.findOne(TMSWayBill, {
|
wayBillCode: wayBillCode
|
});
|
this.info.result = true;
|
if (waybill) {
|
//单据数据验证,1、异常件维护校验
|
let abnormalList = await this.dbRead.find(TMSAbnormal, {
|
portName: waybill.portName,
|
panelType: "普通组板"
|
});
|
for (let abInfo of abnormalList) {
|
if (abInfo.dataType == "运单拦截") {
|
let abnormalData = abInfo.abnormalData;
|
let abnormalDataList = abnormalData.replace("\r", "").split(/;|,|,|\\n/g);
|
if (abnormalDataList.indexOf(waybill.wayBillCode) >= 0) {
|
let msg = abInfo.dataType + ":" + waybill.wayBillCode + "被强制拦截";
|
//#region
|
waybill.actualDropOffPort = "0";
|
waybill.groupBoard = "运单拦截";
|
waybill.orderStatus = "组板异常";
|
waybill.abnormalReason = msg;
|
this.info.data = waybill;
|
this.info.msg = msg;
|
this.info.result = false;
|
let abnormal = new TMSWayBillAbnormal();
|
abnormal.abnormal = waybill.abnormalReason;
|
abnormal.abnormalDate = new Date();
|
abnormal.abnormalStatus = waybill.groupBoard;
|
abnormal.wayBillCode = waybill.wayBillCode;
|
abnormal.wayBill_Id = waybill.wayBill_Id;
|
await this.dbWrite.save(abnormal);
|
|
await this.dbWrite.update(TMSWayBill, waybill.wayBill_Id, {
|
actualDropOffPort: waybill.actualDropOffPort,
|
groupBoard: waybill.groupBoard,
|
orderStatus: waybill.orderStatus,
|
abnormalReason: waybill.abnormalReason
|
});
|
|
return this.info;
|
//#endregion
|
}
|
}
|
}
|
|
if ("已组板,已退货,航空已发运,清关中,航班到达".indexOf(waybill.orderStatus) >= 0) {
|
let msg = waybill.orderStatus + "运单不可组板";
|
this.info.data = waybill;
|
this.info.msg = msg;
|
this.info.result = false;
|
let abnormal = new TMSWayBillAbnormal();
|
abnormal.abnormal = waybill.abnormalReason;
|
abnormal.abnormalDate = new Date();
|
abnormal.abnormalStatus = "组板失败";
|
abnormal.wayBillCode = waybill.wayBillCode;
|
abnormal.wayBill_Id = waybill.wayBill_Id;
|
await this.dbWrite.save(abnormal);
|
await this.dbWrite.update(TMSWayBill, waybill.wayBill_Id, {
|
actualDropOffPort: "0",
|
abnormalReason: waybill.abnormalReason
|
});
|
|
return this.info;
|
}
|
if (
|
!waybill.provinceName ||
|
!waybill.cityName ||
|
!waybill.consigneeName ||
|
!waybill.regionName ||
|
!waybill.consigneeAddress ||
|
waybill.consigneeAddress == waybill.provinceName + waybill.cityName + waybill.regionName
|
) {
|
waybill.actualDropOffPort = "2";
|
waybill.groupBoard = "组板失败";
|
waybill.abnormalReason = "收货地址信息不完善";
|
if (!waybill.consigneeName) {
|
waybill.abnormalReason = "收货人姓名信息不完善";
|
}
|
if (waybill.makeWay == "TMS录入") {
|
waybill.orderStatus = "录入异常";
|
} else {
|
waybill.orderStatus = "组板异常";
|
}
|
this.info.data = waybill;
|
this.info.msg = waybill.abnormalReason;
|
this.info.result = false;
|
let abnormal = new TMSWayBillAbnormal();
|
abnormal.abnormal = waybill.abnormalReason;
|
abnormal.abnormalDate = new Date();
|
abnormal.abnormalStatus = waybill.groupBoard;
|
abnormal.wayBillCode = waybill.wayBillCode;
|
abnormal.wayBill_Id = waybill.wayBill_Id;
|
|
await this.dbWrite.save(abnormal);
|
await this.dbWrite.update(TMSWayBill, waybill.wayBill_Id, {
|
actualDropOffPort: waybill.actualDropOffPort,
|
groupBoard: waybill.groupBoard,
|
orderStatus: waybill.orderStatus,
|
abnormalReason: waybill.abnormalReason
|
});
|
|
return this.info;
|
}
|
|
if (
|
waybill.orderStatus == "新建" ||
|
waybill.orderStatus == "面单已上传" ||
|
waybill.orderStatus == "已提交" ||
|
waybill.orderStatus == "终止"
|
) {
|
waybill.actualDropOffPort = "2";
|
waybill.groupBoard = "组板失败";
|
waybill.abnormalReason = "运单未审核不可组板";
|
this.info.data = waybill;
|
this.info.msg = "运单未审核不可组板";
|
this.info.result = false;
|
let abnormal = new TMSWayBillAbnormal();
|
abnormal.abnormal = waybill.abnormalReason;
|
abnormal.abnormalDate = new Date();
|
abnormal.abnormalStatus = waybill.groupBoard;
|
abnormal.wayBillCode = waybill.wayBillCode;
|
abnormal.wayBill_Id = waybill.wayBill_Id;
|
await this.dbWrite.save(abnormal);
|
await this.dbWrite.update(TMSWayBill, waybill.wayBill_Id, {
|
actualDropOffPort: waybill.actualDropOffPort,
|
groupBoard: waybill.groupBoard,
|
orderStatus: waybill.orderStatus,
|
abnormalReason: waybill.abnormalReason
|
});
|
|
return this.info;
|
}
|
|
//#region 计划口岸为空
|
if (!waybill.planDropOffPort) {
|
this.info.msg = "计划口岸为空,不可组板";
|
this.info.result = false;
|
|
return this.info;
|
}
|
//#endregion
|
|
//#region 验证口岸不能为空
|
if (waybill.portName == null) {
|
waybill.actualDropOffPort = "2";
|
waybill.groupBoard = "组板失败";
|
waybill.orderStatus = "组板异常";
|
waybill.abnormalReason = "口岸为空不可组板";
|
this.info.data = waybill;
|
this.info.msg = "口岸为空不可组板";
|
this.info.result = false;
|
let abnormal = new TMSWayBillAbnormal();
|
abnormal.abnormal = "口岸为空不可组板";
|
abnormal.abnormalDate = new Date();
|
abnormal.abnormalStatus = "组板失败";
|
abnormal.wayBillCode = waybill.wayBillCode;
|
abnormal.wayBill_Id = waybill.wayBill_Id;
|
await this.dbWrite.save(abnormal);
|
|
await this.dbWrite.update(TMSWayBill, waybill.wayBill_Id, {
|
actualDropOffPort: waybill.actualDropOffPort,
|
groupBoard: waybill.groupBoard,
|
orderStatus: waybill.orderStatus,
|
abnormalReason: waybill.abnormalReason
|
});
|
|
return this.info;
|
}
|
//#endregion
|
|
//#region 生成托盘号
|
let port = await this.dbRead.findOne(TMSPort, {
|
portName: waybill.portName
|
});
|
let rule = port.plateRule; //口岸组板规则
|
if (port) {
|
let Year = moment(new Date()).format("YYYY"); //获取年份
|
let month = moment(new Date()).format("MM"); //获取月份
|
let day = moment(new Date()).format("DD"); //获取月份
|
let hour = moment(new Date()).format("HH"); //获取小时 // 20
|
if (rule) {
|
if (rule.indexOf("[yyyy]") > -1) {
|
rule = rule.replace("[yyyy]", Year);
|
}
|
if (rule.indexOf("[MM]") > -1) {
|
rule = rule.replace("[MM]", month);
|
}
|
if (rule.indexOf("[dd]") > -1) {
|
rule = rule.replace("[dd]", day);
|
}
|
if (rule.indexOf("[hh]") > -1) {
|
rule = rule.replace("[hh]", hour);
|
}
|
}
|
}
|
//#endregion
|
|
//将数据写入redis
|
let key = `${rule}_${waybill.wayBillCode}_${waybill.consigneeMobile}_${waybill.consigneeIdcard}_${waybill.consigneeAddress}_${waybill.consigneeName}_`;
|
try {
|
this.info.state = key;
|
await redis.set(key, JSON.stringify(waybill));
|
await redis.expire(key, 60 * 60 * 8);
|
} catch (ex) {
|
console.log("扫描数据redis错误:" + ex.message);
|
}
|
|
//#region 校验明细
|
let detailList = await this.dbRead.find(TMSWayBillList, {
|
wayBill_Id: waybill.wayBill_Id
|
});
|
if (detailList.length == 0) {
|
//#region
|
waybill.actualDropOffPort = "2";
|
waybill.groupBoard = "组板失败";
|
if (waybill.makeWay == "TMS录入") {
|
waybill.orderStatus = "录入异常";
|
} else {
|
waybill.orderStatus = "组板异常";
|
}
|
waybill.abnormalReason = "无物料信息,物料(明细)信息不完整";
|
this.info.data = waybill;
|
this.info.msg = "无物料信息,物料(明细)信息不完整";
|
this.info.result = false;
|
let abnormal = new TMSWayBillAbnormal();
|
abnormal.abnormal = waybill.abnormalReason;
|
abnormal.abnormalDate = new Date();
|
abnormal.abnormalStatus = waybill.groupBoard;
|
abnormal.wayBillCode = waybill.wayBillCode;
|
abnormal.wayBill_Id = waybill.wayBill_Id;
|
await this.dbWrite.save(abnormal);
|
|
await this.dbWrite.update(TMSWayBill, waybill.wayBill_Id, {
|
actualDropOffPort: waybill.actualDropOffPort,
|
groupBoard: waybill.groupBoard,
|
orderStatus: waybill.orderStatus,
|
abnormalReason: waybill.abnormalReason
|
});
|
|
return this.info;
|
//#endregion
|
}
|
for (let item of detailList) {
|
if (!item.productCode || !item.productModel || !item.productName) {
|
//#region
|
waybill.actualDropOffPort = "2";
|
waybill.groupBoard = "组板失败";
|
if (waybill.makeWay == "TMS录入") {
|
waybill.orderStatus = "录入异常";
|
} else {
|
waybill.orderStatus = "组板异常";
|
}
|
waybill.abnormalReason = "物料明细信息不完整";
|
this.info.data = waybill;
|
this.info.msg = "物料明细信息不完整";
|
this.info.result = false;
|
let abnormal = new TMSWayBillAbnormal();
|
abnormal.abnormal = waybill.abnormalReason;
|
abnormal.abnormalDate = new Date();
|
abnormal.abnormalStatus = waybill.groupBoard;
|
abnormal.wayBillCode = waybill.wayBillCode;
|
abnormal.wayBill_Id = waybill.wayBill_Id;
|
await this.dbWrite.save(abnormal);
|
|
await this.dbWrite.update(TMSWayBill, waybill.wayBill_Id, {
|
actualDropOffPort: waybill.actualDropOffPort,
|
groupBoard: waybill.groupBoard,
|
orderStatus: waybill.orderStatus,
|
abnormalReason: waybill.abnormalReason
|
});
|
|
return this.info;
|
//#endregion
|
}
|
}
|
//#endregion
|
|
if (waybill.collectStatus != "已揽收") {
|
waybill.actualDropOffPort = "0";
|
waybill.abnormalReason = "运单未揽收,不可组板";
|
this.info.data = waybill;
|
this.info.msg = "运单未揽收,不可组板";
|
this.info.result = false;
|
let abnormal = new TMSWayBillAbnormal();
|
abnormal.abnormal = "运单未揽收,不可组板";
|
abnormal.abnormalDate = new Date();
|
abnormal.abnormalStatus = "组板失败";
|
abnormal.wayBillCode = waybill.wayBillCode;
|
abnormal.wayBill_Id = waybill.wayBill_Id;
|
await this.dbWrite.save(abnormal);
|
|
await this.dbWrite.update(TMSWayBill, waybill.wayBill_Id, {
|
actualDropOffPort: waybill.actualDropOffPort,
|
groupBoard: waybill.groupBoard,
|
orderStatus: waybill.orderStatus,
|
abnormalReason: waybill.abnormalReason
|
});
|
|
return this.info;
|
}
|
if (waybill.orderStatus == "录入异常") {
|
waybill.actualDropOffPort = "2";
|
waybill.abnormalReason = "录入异常,不可组板";
|
this.info.data = waybill;
|
this.info.msg = "录入异常,不可组板";
|
this.info.result = false;
|
let abnormal = new TMSWayBillAbnormal();
|
abnormal.abnormal = "录入异常,不可组板";
|
abnormal.abnormalDate = new Date();
|
abnormal.abnormalStatus = "组板失败";
|
abnormal.wayBillCode = waybill.wayBillCode;
|
abnormal.wayBill_Id = waybill.wayBill_Id;
|
await this.dbWrite.save(abnormal);
|
|
await this.dbWrite.update(TMSWayBill, waybill.wayBill_Id, {
|
actualDropOffPort: waybill.actualDropOffPort,
|
groupBoard: waybill.groupBoard,
|
orderStatus: waybill.orderStatus,
|
abnormalReason: waybill.abnormalReason
|
});
|
|
return this.info;
|
}
|
|
if (!waybill.expressCode) {
|
waybill.actualDropOffPort = "2";
|
waybill.abnormalReason = "国内快递单号不能为空";
|
this.info.data = waybill;
|
this.info.msg = "国内快递单号不能为空";
|
this.info.result = false;
|
let abnormal = new TMSWayBillAbnormal();
|
abnormal.abnormal = "国内快递单号不能为空";
|
abnormal.abnormalDate = new Date();
|
abnormal.abnormalStatus = "组板失败";
|
abnormal.wayBillCode = waybill.wayBillCode;
|
abnormal.wayBill_Id = waybill.wayBill_Id;
|
await this.dbWrite.save(abnormal);
|
|
await this.dbWrite.update(TMSWayBill, waybill.wayBill_Id, {
|
actualDropOffPort: waybill.actualDropOffPort,
|
groupBoard: waybill.groupBoard,
|
orderStatus: waybill.orderStatus,
|
abnormalReason: waybill.abnormalReason
|
});
|
|
return this.info;
|
}
|
if (!waybill.expressCorpName) {
|
waybill.actualDropOffPort = "2";
|
waybill.groupBoard = "组板失败";
|
waybill.orderStatus = "组板异常";
|
waybill.abnormalReason = "国内快递公司为空不可组板";
|
this.info.data = waybill;
|
this.info.msg = "国内快递公司为空不可组板";
|
this.info.result = false;
|
let abnormal = new TMSWayBillAbnormal();
|
abnormal.abnormal = "国内快递公司为空不可组板";
|
abnormal.abnormalDate = new Date();
|
abnormal.abnormalStatus = "组板失败";
|
abnormal.wayBillCode = waybill.wayBillCode;
|
abnormal.wayBill_Id = waybill.wayBill_Id;
|
await this.dbWrite.save(abnormal);
|
|
await this.dbWrite.update(TMSWayBill, waybill.wayBill_Id, {
|
actualDropOffPort: waybill.actualDropOffPort,
|
groupBoard: waybill.groupBoard,
|
orderStatus: waybill.orderStatus,
|
abnormalReason: waybill.abnormalReason
|
});
|
|
return this.info;
|
}
|
if (waybill.consigneeIdcard == null) {
|
waybill.actualDropOffPort = "3";
|
waybill.groupBoard = "组板失败";
|
waybill.orderStatus = "组板异常";
|
waybill.abnormalReason = "无身份证";
|
this.info.data = waybill;
|
this.info.msg = "无身份证";
|
this.info.result = false;
|
let abnormal = new TMSWayBillAbnormal();
|
abnormal.abnormal = "无身份证";
|
abnormal.abnormalDate = new Date();
|
abnormal.abnormalStatus = "组板失败";
|
abnormal.wayBillCode = waybill.wayBillCode;
|
abnormal.wayBill_Id = waybill.wayBill_Id;
|
await this.dbWrite.save(abnormal);
|
|
await this.dbWrite.update(TMSWayBill, waybill.wayBill_Id, {
|
actualDropOffPort: waybill.actualDropOffPort,
|
groupBoard: waybill.groupBoard,
|
orderStatus: waybill.orderStatus,
|
abnormalReason: waybill.abnormalReason
|
});
|
|
//#region 无身份证组板失败发送短信 不用了
|
try {
|
// 无身份证组板失败发送短信
|
//let msgInfo = new OA_CommonMessage();
|
//msgInfo.MsgType = "无身份证";
|
//msgInfo.ModuleName = "分拣机组板";
|
//msgInfo.CreateID = 1;
|
//msgInfo.Creator = "分拣机";
|
//msgInfo.MainInnerCode = waybill.consigneeMobile;
|
//msgInfo.message = waybill.wayBillCode;
|
//msgInfo.MainId = 2828614; //短信编码
|
//msgInfo.MsgStatus = "未发送";
|
//OA_CommonMessageRepository.Instance.Add(msgInfo);
|
//AoDeUcpaasHelper.SendYPZB(waybill.consigneeMobile, waybill.wayBillCode, 2828614);
|
} catch (ex) {}
|
//#endregion
|
|
return this.info;
|
}
|
//单据数据验证,1、异常件维护校验
|
for (let abInfo of abnormalList) {
|
if (abInfo.dataType == "身份证号") {
|
let abnormalData = abInfo.abnormalData;
|
let abnormalDataList = abnormalData.replace("\r", "").split(/;|,|,|\\n/g);
|
if (abnormalDataList.indexOf(waybill.consigneeIdcard) >= 0) {
|
//#region
|
waybill.actualDropOffPort = "2";
|
waybill.groupBoard = "组板失败";
|
waybill.orderStatus = "组板异常";
|
waybill.abnormalReason = abInfo.dataType + ":" + waybill.consigneeIdcard + "被" + abInfo.abnormalType;
|
this.info.data = waybill;
|
this.info.msg = abInfo.dataType + ":" + waybill.consigneeIdcard + "被" + abInfo.abnormalType;
|
this.info.result = false;
|
let abnormal = new TMSWayBillAbnormal();
|
abnormal.abnormal = waybill.abnormalReason;
|
abnormal.abnormalDate = new Date();
|
abnormal.abnormalStatus = waybill.groupBoard;
|
abnormal.wayBillCode = waybill.wayBillCode;
|
abnormal.wayBill_Id = waybill.wayBill_Id;
|
await this.dbWrite.save(abnormal);
|
|
await this.dbWrite.update(TMSWayBill, waybill.wayBill_Id, {
|
actualDropOffPort: waybill.actualDropOffPort,
|
groupBoard: waybill.groupBoard,
|
orderStatus: waybill.orderStatus,
|
abnormalReason: waybill.abnormalReason
|
});
|
|
return this.info;
|
//#endregion
|
}
|
}
|
if (abInfo.dataType == "物料条码") {
|
for (let item of detailList) {
|
let abnormalData = abInfo.abnormalData;
|
let abnormalDataList = abnormalData.replace("\r", "").split(/;|,|,|\\n/g);
|
if (abnormalDataList.indexOf(item.productModel) >= 0) {
|
//#region
|
waybill.actualDropOffPort = "2";
|
waybill.groupBoard = "组板失败";
|
waybill.orderStatus = "组板异常";
|
waybill.abnormalReason = abInfo.dataType + ":" + item.productModel + "被" + abInfo.abnormalType;
|
this.info.data = waybill;
|
this.info.msg = abInfo.dataType + ":" + item.productModel + "被" + abInfo.abnormalType;
|
this.info.result = false;
|
let abnormal = new TMSWayBillAbnormal();
|
abnormal.abnormal = waybill.abnormalReason;
|
abnormal.abnormalDate = new Date();
|
abnormal.abnormalStatus = waybill.groupBoard;
|
abnormal.wayBillCode = waybill.wayBillCode;
|
abnormal.wayBill_Id = waybill.wayBill_Id;
|
await this.dbWrite.save(abnormal);
|
|
await this.dbWrite.update(TMSWayBill, waybill.wayBill_Id, {
|
actualDropOffPort: waybill.actualDropOffPort,
|
groupBoard: waybill.groupBoard,
|
orderStatus: waybill.orderStatus,
|
abnormalReason: waybill.abnormalReason
|
});
|
|
return this.info;
|
//#endregion
|
}
|
}
|
}
|
}
|
|
//单据数据验证,2、异常件维护校验(综合组板)
|
let portName = waybill.portName || waybill.portName;
|
let storageName = waybill.storageName || waybill.storageName;
|
let expressCorpName = waybill.expressCorpName || waybill.expressCorpName;
|
let where = `portName='${portName}' and panelType='综合组板' And storageName='${storageName}' And expressCorpName='${expressCorpName}'
|
And (BeginTime IS NULL OR BeginTime<=getdate()) And (EndTime IS NULL OR EndTime>=getdate())`;
|
let colligateabnormalList = await this.dbRead.find(TMSAbnormal, {
|
where: where
|
});
|
for (let abInfo of colligateabnormalList) {
|
if (abInfo.dataType == "身份证号") {
|
if (abInfo.abnormalData && abInfo.abnormalData.indexOf(waybill.consigneeIdcard) >= 0) {
|
waybill.actualDropOffPort = "2";
|
waybill.groupBoard = "组板失败";
|
waybill.orderStatus = "组板异常";
|
waybill.abnormalReason = abInfo.dataType + ":" + waybill.consigneeIdcard + "被" + abInfo.abnormalType;
|
this.info.data = waybill;
|
this.info.msg = abInfo.dataType + ":" + waybill.consigneeIdcard + "被" + abInfo.abnormalType;
|
this.info.result = false;
|
let abnormal = new TMSWayBillAbnormal();
|
abnormal.abnormal = waybill.abnormalReason;
|
abnormal.abnormalDate = new Date();
|
abnormal.abnormalStatus = waybill.groupBoard;
|
abnormal.wayBillCode = waybill.wayBillCode;
|
abnormal.wayBill_Id = waybill.wayBill_Id;
|
await this.dbWrite.save(abnormal);
|
|
await this.dbWrite.update(TMSWayBill, waybill.wayBill_Id, {
|
actualDropOffPort: waybill.actualDropOffPort,
|
groupBoard: waybill.groupBoard,
|
orderStatus: waybill.orderStatus,
|
abnormalReason: waybill.abnormalReason
|
});
|
|
return this.info;
|
}
|
}
|
if (abInfo.addressee) {
|
// 是否包含,目前只有包含
|
let AddresseeContain = true; // abInfo.AddresseeContain == "1";
|
let addList = JSON.parse(abInfo.addressee);
|
for (let item of addList) {
|
let provinceName = "";
|
let cityName = "";
|
let regionName = "";
|
try {
|
provinceName = item.provinceName;
|
cityName = item.cityName;
|
regionName = item.regionName;
|
} catch {}
|
let isExist = false;
|
let msg = "";
|
if (waybill.provinceName == provinceName) {
|
if (cityName) {
|
if (regionName) {
|
isExist = waybill.cityName == cityName && waybill.regionName == regionName;
|
msg = provinceName + cityName + regionName + "在" + waybill.portName + "被禁止";
|
} else {
|
isExist = waybill.cityName == cityName;
|
msg = provinceName + cityName + "在" + waybill.portName + "被禁止";
|
}
|
} else {
|
isExist = true;
|
msg = provinceName + "在" + waybill.portName + "被禁止";
|
}
|
} else {
|
// 不包含
|
if (!AddresseeContain) {
|
isExist = true;
|
}
|
}
|
|
// (isExist && AddresseeContain)=为包含省市区禁止组板,标记为组板异常
|
// (!isExist && !AddresseeContain)=为不包含省市区禁止组板,标记为组板异常
|
if ((isExist && AddresseeContain) || (!isExist && !AddresseeContain)) {
|
waybill.actualDropOffPort = "2";
|
waybill.groupBoard = "组板失败";
|
waybill.orderStatus = "组板异常";
|
waybill.abnormalReason = msg;
|
this.info.data = waybill;
|
this.info.msg = msg;
|
this.info.result = false;
|
let abnormal = new TMSWayBillAbnormal();
|
abnormal.abnormal = waybill.abnormalReason;
|
abnormal.abnormalDate = new Date();
|
abnormal.abnormalStatus = waybill.groupBoard;
|
abnormal.wayBillCode = waybill.wayBillCode;
|
abnormal.wayBill_Id = waybill.wayBill_Id;
|
await this.dbWrite.save(abnormal);
|
|
await this.dbWrite.update(TMSWayBill, waybill.wayBill_Id, {
|
actualDropOffPort: waybill.actualDropOffPort,
|
groupBoard: waybill.groupBoard,
|
orderStatus: waybill.orderStatus,
|
abnormalReason: waybill.abnormalReason
|
});
|
|
return this.info;
|
}
|
}
|
}
|
}
|
|
//#region 口岸规则
|
if (port.portRule != "[]") {
|
let portRule = JSON.parse(port.portRule);
|
for (let item of portRule.checkRule) {
|
// ["相同托盘号下相同的信息存在", "单个包裹申报货值不差过", "单个包裹重量不超过"],
|
if (item == "相同托盘号下相同的信息存在") {
|
let existNumber = portRule.existNumber;
|
|
//根据预先生成的托盘号且主单为空的运单
|
for (let term of portRule.checkWhere) {
|
// ["手机号", "身份证号"]
|
if (term == "手机号") {
|
//先从Redis中获取数据验证
|
let keys = await redis.keys("*" + rule + "_*" + waybill.consigneeMobile + "_*");
|
let redisDataList = keys.filter(w => w.indexOf(waybill.wayBillCode) < 0);
|
if (redisDataList.length > existNumber) {
|
//#region
|
waybill.abnormalReason = "同一主单号下手机号已存在重复" + existNumber + "次限制(redis)";
|
waybill.actualDropOffPort = "3"; //异常口
|
waybill.groupBoard = "组板失败";
|
waybill.orderStatus = "组板异常";
|
this.info.msg = waybill.abnormalReason;
|
this.info.result = false;
|
this.info.data = waybill;
|
let abnormal = new TMSWayBillAbnormal();
|
abnormal.abnormal = waybill.abnormalReason;
|
abnormal.abnormalDate = new Date();
|
abnormal.abnormalStatus = waybill.groupBoard;
|
abnormal.wayBillCode = waybill.wayBillCode;
|
abnormal.wayBill_Id = waybill.wayBill_Id;
|
await this.dbWrite.save(abnormal);
|
|
await this.dbWrite.update(TMSWayBill, waybill.wayBill_Id, {
|
actualDropOffPort: waybill.actualDropOffPort,
|
groupBoard: waybill.groupBoard,
|
orderStatus: waybill.orderStatus,
|
abnormalReason: waybill.abnormalReason
|
});
|
|
return this.info;
|
//#endregion
|
}
|
|
//#region
|
let _wayBillList = await this.dbRead.find(TMSWayBill, {
|
select: ["wayBill_Id"],
|
where: {
|
orderStatus: "已组板",
|
plateCode: rule,
|
consigneeMobile: waybill.consigneeMobile
|
}
|
});
|
let cnt = _wayBillList.length;
|
if (cnt > existNumber) {
|
//#region
|
waybill.abnormalReason = "同一主单号下手机号已存在重复" + portRule.existNumber + "次限制";
|
waybill.actualDropOffPort = "3"; //异常口
|
waybill.groupBoard = "组板失败";
|
waybill.orderStatus = "组板异常";
|
this.info.msg = "同一主单号下手机号已存在重复" + portRule.existNumber + "次限制";
|
this.info.result = false;
|
this.info.data = waybill;
|
let abnormal = new TMSWayBillAbnormal();
|
abnormal.abnormal = waybill.abnormalReason;
|
abnormal.abnormalDate = new Date();
|
abnormal.abnormalStatus = waybill.groupBoard;
|
abnormal.wayBillCode = waybill.wayBillCode;
|
abnormal.wayBill_Id = waybill.wayBill_Id;
|
await this.dbWrite.save(abnormal);
|
|
await this.dbWrite.update(TMSWayBill, waybill.wayBill_Id, {
|
actualDropOffPort: waybill.actualDropOffPort,
|
groupBoard: waybill.groupBoard,
|
orderStatus: waybill.orderStatus,
|
abnormalReason: waybill.abnormalReason
|
});
|
|
return this.info;
|
//#endregion
|
}
|
//#endregion
|
}
|
if (term == "身份证号") {
|
//先从Redis中获取数据验证
|
let keys = await redis.keys("*" + rule + "_*" + waybill.consigneeIdcard + "_*");
|
let redisDataList = keys.filter(w => w.indexOf(waybill.wayBillCode) < 0);
|
if (redisDataList.length > existNumber) {
|
//#region
|
waybill.actualDropOffPort = "3"; //异常口
|
waybill.groupBoard = "组板失败";
|
waybill.orderStatus = "组板异常";
|
waybill.abnormalReason = "同一主单号下身份证已存在重复" + portRule.existNumber + "次限制(redis)";
|
this.info.result = false;
|
this.info.msg = waybill.abnormalReason;
|
this.info.data = waybill;
|
let abnormal = new TMSWayBillAbnormal();
|
abnormal.abnormal = waybill.abnormalReason;
|
abnormal.abnormalDate = new Date();
|
abnormal.abnormalStatus = waybill.groupBoard;
|
abnormal.wayBillCode = waybill.wayBillCode;
|
abnormal.wayBill_Id = waybill.wayBill_Id;
|
await this.dbWrite.save(abnormal);
|
|
await this.dbWrite.update(TMSWayBill, waybill.wayBill_Id, {
|
actualDropOffPort: waybill.actualDropOffPort,
|
groupBoard: waybill.groupBoard,
|
orderStatus: waybill.orderStatus,
|
abnormalReason: waybill.abnormalReason
|
});
|
|
return this.info;
|
//#endregion
|
}
|
|
//#region
|
let _wayBillList = await this.dbRead.find(TMSWayBill, {
|
select: ["wayBill_Id"],
|
where: {
|
orderStatus: "已组板",
|
plateCode: rule,
|
consigneeIdcard: waybill.consigneeIdcard
|
}
|
});
|
let cnt = _wayBillList.length;
|
if (cnt > existNumber) {
|
//#region
|
waybill.actualDropOffPort = "3"; //异常口
|
waybill.groupBoard = "组板失败";
|
waybill.orderStatus = "组板异常";
|
waybill.abnormalReason = "同一主单号下身份证已存在重复" + portRule.existNumber + "次限制";
|
this.info.result = false;
|
this.info.msg = "同一主单号下身份证已存在重复" + portRule.existNumber + "次限制";
|
this.info.data = waybill;
|
let abnormal = new TMSWayBillAbnormal();
|
abnormal.abnormal = waybill.abnormalReason;
|
abnormal.abnormalDate = new Date();
|
abnormal.abnormalStatus = waybill.groupBoard;
|
abnormal.wayBillCode = waybill.wayBillCode;
|
abnormal.wayBill_Id = waybill.wayBill_Id;
|
await this.dbWrite.save(abnormal);
|
|
await this.dbWrite.update(TMSWayBill, waybill.wayBill_Id, {
|
actualDropOffPort: waybill.actualDropOffPort,
|
groupBoard: waybill.groupBoard,
|
orderStatus: waybill.orderStatus,
|
abnormalReason: waybill.abnormalReason
|
});
|
|
return this.info;
|
//#endregion
|
}
|
//#endregion
|
}
|
if (term == "姓名") {
|
//#region
|
let _wayBillList = await this.dbRead.find(TMSWayBill, {
|
select: ["wayBill_Id"],
|
where: {
|
orderStatus: "已组板",
|
plateCode: rule,
|
consigneeName: waybill.consigneeName
|
}
|
});
|
let cnt = _wayBillList.length;
|
if (cnt > existNumber) {
|
//#region
|
waybill.actualDropOffPort = "3"; //异常口
|
waybill.groupBoard = "组板失败";
|
waybill.orderStatus = "组板异常";
|
waybill.abnormalReason = "同一主单号下姓名已存在重复" + portRule.existNumber + "次限制";
|
this.info.result = false;
|
this.info.msg = "同一主单号下姓名已存在重复" + portRule.existNumber + "次限制";
|
this.info.data = waybill;
|
let abnormal = new TMSWayBillAbnormal();
|
abnormal.abnormal = waybill.abnormalReason;
|
abnormal.abnormalDate = new Date();
|
abnormal.abnormalStatus = waybill.groupBoard;
|
abnormal.wayBillCode = waybill.wayBillCode;
|
abnormal.wayBill_Id = waybill.wayBill_Id;
|
await this.dbWrite.save(abnormal);
|
|
await this.dbWrite.update(TMSWayBill, waybill.wayBill_Id, {
|
actualDropOffPort: waybill.actualDropOffPort,
|
groupBoard: waybill.groupBoard,
|
orderStatus: waybill.orderStatus,
|
abnormalReason: waybill.abnormalReason
|
});
|
|
return this.info;
|
//#endregion
|
}
|
//#endregion
|
}
|
if (term == "地址") {
|
//先从Redis中获取数据验证
|
let keys = await redis.keys("*" + rule + "_*" + waybill.consigneeAddress + "_*");
|
let redisDataList = keys.filter(w => w.indexOf(waybill.wayBillCode) < 0);
|
if (redisDataList.length > existNumber) {
|
//#region
|
waybill.actualDropOffPort = "3"; //异常口
|
waybill.groupBoard = "组板失败";
|
waybill.orderStatus = "组板异常";
|
waybill.abnormalReason = "同一主单号下地址已存在重复" + portRule.existNumber + "次限制(redis)";
|
this.info.result = false;
|
this.info.msg = waybill.abnormalReason;
|
this.info.data = waybill;
|
let abnormal = new TMSWayBillAbnormal();
|
abnormal.abnormal = waybill.abnormalReason;
|
abnormal.abnormalDate = new Date();
|
abnormal.abnormalStatus = waybill.groupBoard;
|
abnormal.wayBillCode = waybill.wayBillCode;
|
abnormal.wayBill_Id = waybill.wayBill_Id;
|
await this.dbWrite.save(abnormal);
|
|
await this.dbWrite.update(TMSWayBill, waybill.wayBill_Id, {
|
actualDropOffPort: waybill.actualDropOffPort,
|
groupBoard: waybill.groupBoard,
|
orderStatus: waybill.orderStatus,
|
abnormalReason: waybill.abnormalReason
|
});
|
|
return this.info;
|
//#endregion
|
}
|
|
//#region
|
let _wayBillList = await this.dbRead.find(TMSWayBill, {
|
select: ["wayBill_Id"],
|
where: {
|
orderStatus: "已组板",
|
plateCode: rule,
|
consigneeAddress: waybill.consigneeAddress
|
}
|
});
|
let cnt = _wayBillList.length;
|
if (cnt > existNumber) {
|
//#region
|
waybill.actualDropOffPort = "3"; //异常口
|
waybill.groupBoard = "组板失败";
|
waybill.orderStatus = "组板异常";
|
waybill.abnormalReason = "同一主单号下地址已存在重复" + portRule.existNumber + "次限制";
|
this.info.result = false;
|
this.info.msg = "同一主单号下地址已存在重复" + portRule.existNumber + "次限制";
|
this.info.data = waybill;
|
let abnormal = new TMSWayBillAbnormal();
|
abnormal.abnormal = waybill.abnormalReason;
|
abnormal.abnormalDate = new Date();
|
abnormal.abnormalStatus = waybill.groupBoard;
|
abnormal.wayBillCode = waybill.wayBillCode;
|
abnormal.wayBill_Id = waybill.wayBill_Id;
|
await this.dbWrite.save(abnormal);
|
|
await this.dbWrite.update(TMSWayBill, waybill.wayBill_Id, {
|
actualDropOffPort: waybill.actualDropOffPort,
|
groupBoard: waybill.groupBoard,
|
orderStatus: waybill.orderStatus,
|
abnormalReason: waybill.abnormalReason
|
});
|
|
return this.info;
|
//#endregion
|
}
|
//#endregion
|
}
|
}
|
}
|
if (item == "单个包裹重量不超过") {
|
let existWeight = portRule.existWeight;
|
let weight = waybill.grossWeight || 0;
|
if (weight > existWeight) {
|
waybill.actualDropOffPort = "2";
|
waybill.groupBoard = "组板失败";
|
waybill.orderStatus = "组板异常";
|
waybill.abnormalReason = "单个包裹重量不超过" + existWeight;
|
this.info.data = waybill;
|
this.info.msg = "单个包裹重量不超过" + existWeight;
|
this.info.result = false;
|
let abnormal = new TMSWayBillAbnormal();
|
abnormal.abnormal = waybill.abnormalReason;
|
abnormal.abnormalDate = new Date();
|
abnormal.abnormalStatus = waybill.groupBoard;
|
abnormal.wayBillCode = waybill.wayBillCode;
|
abnormal.wayBill_Id = waybill.wayBill_Id;
|
await this.dbWrite.save(abnormal);
|
|
await this.dbWrite.update(TMSWayBill, waybill.wayBill_Id, {
|
actualDropOffPort: waybill.actualDropOffPort,
|
groupBoard: waybill.groupBoard,
|
orderStatus: waybill.orderStatus,
|
abnormalReason: waybill.abnormalReason
|
});
|
|
return this.info;
|
}
|
}
|
if (item == "单个包裹申报货值不差过") {
|
//let existMoney = portRule.ExistMoney;
|
//let Money
|
}
|
if (item == "需身份证正反面照片") {
|
let cardInfo = await this.dbRead.findOne(TMSIdCard, {
|
idCardCode: waybill.consigneeIdcard
|
});
|
if (!cardInfo || !cardInfo.positiveServerUrl || !cardInfo.negativeServerUrl) {
|
waybill.abnormalReason = "需身份证正反面照片";
|
waybill.actualDropOffPort = "3"; //异常口
|
waybill.groupBoard = "组板失败";
|
waybill.orderStatus = "组板异常";
|
|
this.info.data = waybill;
|
this.info.msg = waybill.wayBillCode + "需身份证正反面照片";
|
this.info.result = false;
|
let abnormal = new TMSWayBillAbnormal();
|
abnormal.abnormal = waybill.abnormalReason;
|
abnormal.abnormalDate = new Date();
|
abnormal.abnormalStatus = waybill.groupBoard;
|
abnormal.wayBillCode = waybill.wayBillCode;
|
abnormal.wayBill_Id = waybill.wayBill_Id;
|
await this.dbWrite.save(abnormal);
|
|
await this.dbWrite.update(TMSWayBill, waybill.wayBill_Id, {
|
actualDropOffPort: waybill.actualDropOffPort,
|
groupBoard: waybill.groupBoard,
|
orderStatus: waybill.orderStatus,
|
abnormalReason: waybill.abnormalReason
|
});
|
|
return this.info;
|
}
|
}
|
}
|
}
|
//#endregion
|
|
//#region 更新组板结果
|
if (this.info.result) {
|
waybill.actualDropOffPort = waybill.planDropOffPort;
|
waybill.groupBoard = "组板成功";
|
waybill.abnormalReason = null;
|
waybill.orderStatus = "已组板";
|
waybill.groupBoardDate = new Date();
|
waybill.panelWay = type;
|
// 已生成好的托盘规则
|
waybill.plateCode = rule;
|
//WayBillHelper.SetStatusHistory(waybill, "分拣机组板", "已组板", "出库扫描完毕,等待发往机场");
|
} else {
|
waybill.groupBoard = "组板失败";
|
if (waybill.orderStatus != "已提交") {
|
//状态已提交的不改变状态
|
waybill.orderStatus = "组板异常";
|
}
|
waybill.panelWay = type;
|
waybill.abnormalReason = this.info.msg;
|
//WayBillHelper.SetStatusHistory(waybill, "分拣机组板", "组板异常," + this.info.msg);
|
}
|
|
await this.dbWrite.update(TMSWayBill, waybill.wayBill_Id, {
|
actualDropOffPort: waybill.actualDropOffPort,
|
groupBoard: waybill.groupBoard,
|
orderStatus: waybill.orderStatus,
|
abnormalReason: waybill.abnormalReason
|
});
|
|
//#endregion
|
|
this.info.result = true;
|
this.info.data = waybill;
|
|
return this.info;
|
} else {
|
let wayReceiveInfo = await this.dbRead.findOne(TMSWayBillReceive, {
|
wayBillCode: wayBillCode
|
});
|
if (wayReceiveInfo) {
|
if (wayReceiveInfo.collectStatus == "已退货") {
|
//#region
|
let msg = "已退货运单不可组板";
|
waybill = new TMSWayBill();
|
waybill.wayBillCode = wayReceiveInfo.wayBillCode;
|
waybill.actualDropOffPort = "0";
|
waybill.abnormalReason = msg;
|
this.info.data = waybill;
|
this.info.msg = msg;
|
this.info.result = false;
|
let abnormal = new TMSWayBillAbnormal();
|
abnormal.abnormal = waybill.abnormalReason;
|
abnormal.abnormalDate = new Date();
|
abnormal.abnormalStatus = "组板失败";
|
abnormal.wayBillCode = waybill.wayBillCode;
|
abnormal.wayBill_Id = wayReceiveInfo.wayBillReceive_Id;
|
abnormal.abnormalRemark = msg;
|
await this.dbWrite.save(abnormal);
|
|
//WayBillHelper.SetStatusHistory(waybill, "分拣机组板", "组板异常");
|
|
return this.info;
|
//#endregion
|
} else if (wayReceiveInfo.collectStatus == "待揽收" || wayReceiveInfo.collectStatus == "未揽收") {
|
//#region
|
let msg = "未揽收运单不可组板";
|
waybill = new TMSWayBill();
|
waybill.wayBillCode = wayReceiveInfo.wayBillCode;
|
waybill.actualDropOffPort = "0";
|
waybill.abnormalReason = msg;
|
this.info.data = waybill;
|
this.info.msg = msg;
|
this.info.result = false;
|
let abnormal = new TMSWayBillAbnormal();
|
abnormal.abnormal = waybill.abnormalReason;
|
abnormal.abnormalDate = new Date();
|
abnormal.abnormalStatus = "组板失败";
|
abnormal.wayBillCode = waybill.wayBillCode;
|
abnormal.wayBill_Id = wayReceiveInfo.wayBillReceive_Id;
|
abnormal.abnormalRemark = msg;
|
await this.dbWrite.save(abnormal);
|
|
//WayBillHelper.SetStatusHistory(waybill, "分拣机组板", "组板异常");
|
|
return this.info;
|
//#endregion
|
} else if (wayReceiveInfo.collectStatus == "已揽收") {
|
//#region
|
let msg = "已揽收但未录入运单不可组板";
|
waybill = new TMSWayBill();
|
waybill.wayBillCode = wayReceiveInfo.wayBillCode;
|
waybill.actualDropOffPort = "2";
|
waybill.abnormalReason = msg;
|
this.info.data = waybill;
|
this.info.msg = msg;
|
this.info.result = false;
|
let abnormal = new TMSWayBillAbnormal();
|
abnormal.abnormal = waybill.abnormalReason;
|
abnormal.abnormalDate = new Date();
|
abnormal.abnormalStatus = "组板失败";
|
abnormal.wayBillCode = waybill.wayBillCode;
|
abnormal.wayBill_Id = wayReceiveInfo.wayBillReceive_Id;
|
abnormal.abnormalRemark = msg;
|
await this.dbWrite.save(abnormal);
|
|
//WayBillHelper.SetStatusHistory(waybill, "分拣机组板", "组板异常");
|
|
return this.info;
|
//#endregion
|
} else {
|
//#region
|
let msg = wayReceiveInfo.collectStatus + "运单不可组板";
|
waybill = new TMSWayBill();
|
waybill.wayBillCode = wayReceiveInfo.wayBillCode;
|
waybill.actualDropOffPort = "0";
|
waybill.abnormalReason = msg;
|
this.info.data = waybill;
|
this.info.msg = msg;
|
this.info.result = false;
|
let abnormal = new TMSWayBillAbnormal();
|
abnormal.abnormal = waybill.abnormalReason;
|
abnormal.abnormalDate = new Date();
|
abnormal.abnormalStatus = "组板失败";
|
abnormal.wayBillCode = waybill.wayBillCode;
|
abnormal.wayBill_Id = wayReceiveInfo.wayBillReceive_Id;
|
abnormal.abnormalRemark = msg;
|
await this.dbWrite.save(abnormal);
|
|
//WayBillHelper.SetStatusHistory(waybill, "分拣机组板", "组板异常");
|
|
return this.info;
|
//#endregion
|
}
|
} else {
|
this.info.result = false;
|
this.info.msg = "运单不存在";
|
|
return this.info;
|
}
|
}
|
} catch (ex) {
|
this.info.result = false;
|
this.info.msg = ex.message;
|
|
return this.info;
|
}
|
}
|
}
|