//#region import
|
import { default as BaseController } from "../baseController";
|
import { Post } from "egg-shell-decorators";
|
import { vSaleOrderPrintListGroup } from "../../entity/outbound/manufacture/vSaleOrderPrintListGroup";
|
import { In, Raw } from "typeorm";
|
import { SaleOrderPrint } from "../../entity/outbound/manufacture/saleOrderPrint";
|
import { SaleOrder } from "../../entity/outbound/sale/saleOrder";
|
import { BaseProductPlaceHolder } from "../../entity/storage/storage/baseProductPlaceHolder";
|
import { SaleOrderPrintList } from "../../entity/outbound/manufacture/saleOrderPrintList";
|
import moment = require("moment");
|
import { SaleOrderList } from "../../entity/outbound/sale/saleOrderList";
|
import { vSaleOrderPrintList } from "../../entity/outbound/manufacture/vSaleOrderPrintList";
|
import { vSaleOrderPickToLight } from "../../entity/outbound/manufacture/vSaleOrderPickToLight";
|
import { IDXPickToLight } from "../../entity/outbound/manufacture/iDXPickToLight";
|
import { SaleOrderPrintSub } from "../../entity/outbound/manufacture/saleOrderPrintSub";
|
//#endregion
|
|
/**
|
* 订单打印
|
*/
|
export default class OrderPrintController extends BaseController {
|
//#region 根据订单号、快递单号、波次单号、波次单ID获得出库单ID集合
|
/**
|
* 根据订单号、快递单号、波次单号、波次单ID获得出库单ID集合
|
*/
|
@Post()
|
public async getOrderIds() {
|
let { ctx } = this;
|
let body = ctx.request.body;
|
let type = body.type;
|
let userInfo = await this.userInfo;
|
|
try {
|
if (type === "order" || type === "express" || type === "orderprint") {
|
let where = {};
|
if (type === "order") {
|
where = {
|
userProduct_Id: userInfo.userProduct_Id,
|
orderCode: In(body.code)
|
};
|
} else if (type === "orderprint") {
|
let codes = "'" + body.code.join("','") + "'";
|
where = {
|
userProduct_Id: userInfo.userProduct_Id,
|
order_Id: Raw(() => {
|
return ` order_Id In(SELECT Order_Id FROM dbo.Sale_OrderPrint M INNER JOIN dbo.Sale_OrderPrintList L ON L.OrderPrint_Id = M.OrderPrint_Id
|
WHERE M.OrderPrintCode In(${codes}))`;
|
})
|
};
|
} else {
|
where = {
|
userProduct_Id: userInfo.userProduct_Id,
|
expressCode: In(body.code)
|
};
|
}
|
let orderPrintDetails = await this.dbRead.find(SaleOrder, {
|
select: ["order_Id"],
|
where: where
|
});
|
|
let idArr = orderPrintDetails
|
.reduce((all: Array<any>, next) => (all.some(item => item["order_Id"] == next["order_Id"]) ? all : [...all, next]), [])
|
.map(item => item.order_Id);
|
|
if (idArr.length) {
|
this.info.result = true;
|
this.info.data = idArr;
|
} else {
|
this.info.result = false;
|
this.info.msg = "未获得订单信息";
|
}
|
|
ctx.body = this.info;
|
} else {
|
let orderPrintDetails = await this.dbRead.find(vSaleOrderPrintListGroup, {
|
orderPrint_Id: In(body.ids)
|
});
|
|
let idArr = orderPrintDetails
|
.reduce((all: Array<any>, next) => (all.some(item => item["order_Id"] == next["order_Id"]) ? all : [...all, next]), [])
|
.map(item => item.order_Id);
|
|
if (idArr.length) {
|
this.info.result = true;
|
this.info.data = idArr;
|
} else {
|
this.info.result = false;
|
this.info.msg = "未获得订单信息";
|
}
|
ctx.body = this.info;
|
}
|
} catch (error) {
|
this.info.result = false;
|
this.info.msg = "未获得订单信息";
|
ctx.body = this.info;
|
}
|
}
|
//#endregion
|
|
//#region AddOrder 添加订单
|
@Post()
|
public async addOrder() {
|
let { ctx } = this;
|
let body = ctx.request.body;
|
let userInfo = await ctx.helper.userInfo();
|
|
let orderPrint_Id = body.orderPrint_Id;
|
let orderCode = body.orderCode;
|
let orderPrintInfo = await this.dbRead.findOne(SaleOrderPrint, orderPrint_Id);
|
|
let orderInfo = await this.dbRead.findOne(SaleOrder, {
|
orderCode: orderCode,
|
userProduct_Id: userInfo.userProduct_Id
|
});
|
if (orderInfo == null) {
|
this.info.result = false;
|
this.info.msg = orderCode + "订单号不存在!";
|
ctx.body = this.info;
|
return;
|
}
|
if (orderInfo.statusText != "审核成功") {
|
this.info.result = false;
|
this.info.msg = orderCode + "订单未审核成功,不允许添加!";
|
ctx.body = this.info;
|
return;
|
}
|
if (orderInfo.sortingStatus != 2) {
|
this.info.result = false;
|
this.info.msg = orderCode + "订单为分配成功 ,不允许添加!";
|
ctx.body = this.info;
|
return;
|
}
|
if (orderInfo.orderPrintCode) {
|
this.info.result = false;
|
this.info.msg = orderCode + "订单已经在" + orderInfo.orderPrintCode + "波次单下面,不允许添加!";
|
ctx.body = this.info;
|
return;
|
}
|
|
let holderList = await this.dbRead.find(BaseProductPlaceHolder, {
|
code: orderCode,
|
userProduct_Id: userInfo.userProduct_Id
|
});
|
let existsPrintDetail = await this.dbRead.findOne(SaleOrderPrintList, {
|
where: { orderPrint_Id: orderPrint_Id },
|
order: { allotPositionName: "DESC" }
|
});
|
let allotPositionName = existsPrintDetail.allotPositionName;
|
let allot = parseInt(allotPositionName) + 1;
|
allotPositionName = "" + (allot.toString().length == 1 ? "0" + allot : allot);
|
|
for (var item of holderList) {
|
let detailInfo = new SaleOrderPrintList();
|
detailInfo.allotPositionName = allotPositionName;
|
detailInfo.createDate = new Date();
|
detailInfo.createID = userInfo.user_Id;
|
detailInfo.creator = userInfo.userTrueName;
|
|
detailInfo.finishedQuanity = 0;
|
detailInfo.freezeQuanity = 0;
|
detailInfo.order_Id = item.mainID;
|
detailInfo.orderCode = item.code;
|
detailInfo.orderList_Id = item.detailID;
|
detailInfo.orderPrint_Id = orderPrint_Id;
|
|
detailInfo.pickQuantity = 0;
|
detailInfo.placeholder_Id = item.placeholder_Id;
|
detailInfo.plateCode = item.plateCode;
|
detailInfo.expressCorp_Id = orderInfo.expressCorp_Id;
|
detailInfo.expressCorpName = orderInfo.expressCorpName;
|
detailInfo.expressCode = orderInfo.expressCode;
|
|
detailInfo.positionName = item.positionName;
|
detailInfo.produceDate = item.produceDate ? moment(item.produceDate).format("YYYY-MM-DD") : null;
|
detailInfo.product_Id = item.product_Id;
|
detailInfo.productCode = item.productCode;
|
detailInfo.productModel = item.productModel;
|
detailInfo.productName = item.productName;
|
detailInfo.productSpec = item.productSpec;
|
|
let orderDetail = await this.dbRead.findOne(SaleOrderList, item.detailID);
|
detailInfo.weight = orderDetail.weight;
|
detailInfo.totalWeight = orderDetail.totalWeight;
|
detailInfo.quantityOrder = orderDetail.quantityOrder;
|
detailInfo.quantityOrderOrign = orderDetail.quantityOrder;
|
detailInfo.quantityOuter = 0;
|
detailInfo.storeOrderCode = item.storeOrderCode;
|
await this.dbWrite.save(detailInfo);
|
}
|
|
//更新订单波次号
|
await this.dbWrite.update(SaleOrder, orderInfo.order_Id, {
|
orderPrint_Id: orderPrintInfo.orderPrint_Id,
|
orderPrintCode: orderPrintInfo.orderPrintCode,
|
userProduct_Id: userInfo.userProduct_Id
|
});
|
|
let sql = `SET XACT_ABORT on;Begin Tran
|
Update Sale_Order Set StatusID=4, statusText='波次完成' Where orderCode='${orderCode}' and userProduct_Id=${userInfo.userProduct_Id};
|
Update Sale_OrderList set batchQuantity=quantityOrder WHERE Order_Id='${orderInfo.order_Id}'
|
Update Sale_OrderPrint set
|
TotalWeight=(SELECT SUM(totalWeight) FROM dbo.Sale_OrderPrintList WHERE orderPrint_Id=Sale_OrderPrint.orderPrint_Id AND ISNULL(Sale_OrderPrintList.QuantityOrder,0)>0),
|
OrderCount=(SELECT COUNT(DISTINCT order_Id) FROM dbo.Sale_OrderPrintList WHERE orderPrint_Id=Sale_OrderPrint.orderPrint_Id AND ISNULL(Sale_OrderPrintList.QuantityOrder,0)>0),
|
UnFinishedCount=(SELECT COUNT(DISTINCT order_Id) FROM dbo.Sale_OrderPrintList WHERE orderPrint_Id=Sale_OrderPrint.orderPrint_Id AND ISNULL(Sale_OrderPrintList.QuantityOrder,0)>0),
|
TotalQuanity=(SELECT SUM(quantityOrder) FROM dbo.Sale_OrderPrintList WHERE orderPrint_Id=Sale_OrderPrint.orderPrint_Id AND ISNULL(Sale_OrderPrintList.QuantityOrder,0)>0)
|
Where orderPrint_Id=${orderPrint_Id} and userProduct_Id=${userInfo.userProduct_Id}
|
If @@Error <> 0 RollBack Tran Else Commit Tran`;
|
|
await this.dbWrite.query(sql);
|
|
this.info.result = true;
|
this.info.msg = "添加成功!";
|
|
ctx.body = this.info;
|
}
|
//#endregion
|
|
//#region OnFrozenOrder 剔除订单
|
@Post()
|
public async onFrozenOrder() {
|
let { ctx } = this;
|
let body = ctx.request.body;
|
|
try {
|
let orderPrint_Id = body.orderPrint_Id;
|
let orderCode = body.orderCode;
|
let orderInfo = await this.dbRead.find(SaleOrderPrintList, {
|
orderPrint_Id: orderPrint_Id,
|
orderCode: orderCode
|
});
|
if (orderInfo == null || orderInfo.length == 0) {
|
this.info.result = false;
|
this.info.msg = orderCode + "订单号不存在当前波次单中!";
|
ctx.body = this.info;
|
return this.info;
|
}
|
if (orderInfo.filter(a => a.quantityOuter > 0).length) {
|
this.info.result = false;
|
this.info.msg = orderCode + "订单号已经存在出库明细,不允许剔除!";
|
ctx.body = this.info;
|
return this.info;
|
}
|
|
let sql = `SET XACT_ABORT on;Begin Tran
|
delete from Sale_OrderPrintList Where orderCode='${orderCode}' And orderPrint_Id=${orderPrint_Id};
|
Update Sale_OrderPrint set
|
OrderCount=(SELECT COUNT(DISTINCT order_Id) FROM dbo.Sale_OrderPrintList WHERE orderPrint_Id=Sale_OrderPrint.orderPrint_Id),
|
UnFinishedCount=(SELECT COUNT(DISTINCT order_Id) FROM dbo.Sale_OrderPrintList WHERE orderPrint_Id=Sale_OrderPrint.orderPrint_Id),
|
TotalQuanity=(SELECT SUM(quantityOrder) FROM dbo.Sale_OrderPrintList WHERE orderPrint_Id=Sale_OrderPrint.orderPrint_Id)
|
Where orderPrint_Id=${orderPrint_Id}
|
Update Sale_OrderPrint set
|
FreezeQuantity=
|
(
|
Select Sum(freezeQuanity) from Sale_OrderPrintList Where orderPrint_Id=${orderPrint_Id}
|
),
|
UnFinishedCount =
|
(
|
SELECT COUNT(DISTINCT order_Id)
|
FROM Sale_OrderPrintList L
|
WHERE orderPrint_Id = ${orderPrint_Id} AND L.quantityOrder>L.freezeQuanity
|
) Where orderPrint_Id=${orderPrint_Id};
|
|
--更新波次数量
|
UPDATE dbo.Sale_OrderList SET BatchQuantity=
|
ISNULL((
|
SELECT SUM(L.quantityOrder) FROM dbo.Sale_OrderPrintList L
|
WHERE orderList_Id=Sale_OrderList.orderList_Id
|
), 0)
|
Where order_Id IN (Select order_Id from Sale_Order Where orderPrint_Id=${orderPrint_Id});
|
--更新状态
|
Update Sale_Order Set StatusID=2, statusText='审核成功', orderPrint_Id=NULL, orderPrintCode=NULL Where orderCode='${orderCode}';
|
If @@Error <> 0 RollBack Tran Else Commit Tran`;
|
|
await this.dbWrite.query(sql);
|
|
this.info.result = true;
|
this.info.msg = "剔除订单成功!";
|
} catch (error) {
|
this.info.result = false;
|
this.info.msg = "剔除失败:" + error.message;
|
}
|
ctx.body = this.info;
|
}
|
//#endregion
|
|
//#region printPickBill2 打印拣配单
|
@Post()
|
public async printPickBill2() {
|
let userInfo = await this.userInfo;
|
let { ctx } = this;
|
let body = ctx.request.body;
|
|
try {
|
let dataList = [];
|
var orderPrints = await this.dbRead.find(SaleOrderPrint, {
|
orderPrint_Id: In(body.ids)
|
});
|
|
for (let printInfo of orderPrints) {
|
if (printInfo.subBatch) {
|
// 存在子波次
|
let subs = await this.dbRead.find(SaleOrderPrintSub, {
|
orderPrint_Id: printInfo.orderPrint_Id
|
});
|
let groupList = subs.reduce(
|
(all: Array<SaleOrderPrintSub>, next) => (all.some(item => item.areaCode == next.areaCode) ? all : [...all, next]),
|
[]
|
);
|
for (let subInfo of groupList) {
|
let ids = subs.filter(item => item.areaCode === subInfo.areaCode).map(item => item.orderPrintList_Id);
|
var orderPrintDetails = await this.dbRead.find(vSaleOrderPrintList, {
|
where: {
|
orderPrintList_Id: In(ids),
|
positionName: Raw(() => {
|
return `positionName NOT IN(SELECT positionName FROM base_position Where userProduct_Id=${userInfo.userProduct_Id} And positionType=5 And storage_Id=${printInfo.storage_Id})`;
|
})
|
},
|
order: { positionName: "ASC", productModel: "ASC" }
|
});
|
|
// 子波次号
|
printInfo.orderPrintCode = subInfo.subOrderPrintCode;
|
printInfo["areaCode"] = subInfo.areaCode;
|
|
let dataInfo = {
|
printInfo: this.ctx.helper.copyObject(printInfo),
|
details: orderPrintDetails
|
};
|
dataList.push(dataInfo);
|
}
|
} else {
|
// 常规波次
|
var orderPrintDetails = await this.dbRead.find(vSaleOrderPrintList, {
|
where: {
|
orderPrint_Id: printInfo.orderPrint_Id,
|
positionName: Raw(() => {
|
return `positionName NOT IN(SELECT positionName FROM base_position Where userProduct_Id=${userInfo.userProduct_Id} And positionType=5 And storage_Id=${printInfo.storage_Id})`;
|
})
|
},
|
order: { positionName: "ASC", productModel: "ASC" }
|
});
|
|
let dataInfo = {
|
printInfo: printInfo,
|
details: orderPrintDetails
|
};
|
dataList.push(dataInfo);
|
}
|
}
|
|
this.info.result = true;
|
this.info.data = dataList;
|
|
//#region 记录打印次数
|
await this.dbWrite.increment(
|
SaleOrderPrint,
|
{
|
orderPrint_Id: In(body.ids)
|
},
|
"pickingPrint",
|
1
|
);
|
//#endregion
|
} catch (ex) {
|
this.info.result = false;
|
this.info.msg = "加载数据失败:" + ex.message;
|
}
|
ctx.body = this.info;
|
}
|
//#endregion
|
|
//#region 更新打印次数
|
@Post()
|
public async updatePrintCount() {
|
try {
|
await this.dbWrite.increment(
|
SaleOrderPrint,
|
{
|
orderPrint_Id: In(this.body.ids)
|
},
|
this.body.type,
|
1
|
);
|
this.info.result = true;
|
this.info.msg = "打印次数更新成功";
|
} catch (error) {
|
this.info.result = false;
|
this.info.msg = "打印次数更新失败," + error.message;
|
}
|
|
this.ctx.body = this.info;
|
}
|
//#endregion
|
|
//#region LightPicking灯光拣选
|
@Post()
|
public async lightPicking() {
|
let userInfo = await this.userInfo;
|
try {
|
if (!this.body.orderPrintCode) {
|
this.info.result = false;
|
this.info.msg = "波次号不能为空";
|
this.ctx.body = this.info;
|
return;
|
}
|
let orderPrintInfo = await this.dbRead.findOne(SaleOrderPrint, {
|
orderPrintCode: this.body.orderPrintCode,
|
userProduct_Id: (await this.userInfo).userProduct_Id
|
});
|
if (!orderPrintInfo) {
|
this.info.result = false;
|
this.info.msg = "波次号不存在";
|
this.ctx.body = this.info;
|
return;
|
}
|
if (["波次完成", "拣货中"].indexOf(orderPrintInfo.statusText) < 0) {
|
this.info.result = false;
|
this.info.msg = "只有状态为“波次完成、拣货中”才允许转入灯光接口数据中";
|
this.ctx.body = this.info;
|
return;
|
}
|
let plList = await this.dbRead.find(vSaleOrderPickToLight, {
|
where: {
|
orderPrintCode: this.body.orderPrintCode,
|
userProduct_Id: userInfo.userProduct_Id
|
}
|
});
|
if (plList.length == 0) {
|
this.info.result = false;
|
this.info.msg = "没有对应波次单!";
|
this.ctx.body = this.info;
|
return;
|
}
|
|
for (var item of plList) {
|
let holderInfo = await this.dbRead.findOne(IDXPickToLight, {
|
placeholder_Id: item.placeholder_Id,
|
orderPrint_Id: item.orderPrint_Id
|
});
|
if (holderInfo) {
|
this.info.result = false;
|
this.info.msg = "已推送,不可重复推送";
|
this.ctx.body = this.info;
|
return;
|
}
|
|
let pl = new IDXPickToLight();
|
// pl.createDate = item.createDate;
|
// pl.fMLocation = item.fMLocation;
|
pl.isUpload = 0;
|
pl.orderCode = item.orderCode;
|
pl.orderList_Id = item.orderList_Id;
|
pl.orderPrintCode = item.orderPrintCode;
|
pl.orderPrintList_Id = item.orderPrintList_Id;
|
pl.orderPrint_Id = item.orderPrint_Id;
|
pl.order_Id = item.order_Id;
|
pl.placeholder_Id = item.placeholder_Id;
|
|
pl.positionName = item.positionName;
|
pl.productCode = item.productCode;
|
pl.productModel = item.productModel;
|
pl.productName = item.productName;
|
pl.productSpec = item.productSpec;
|
pl.product_Id = item.product_Id;
|
pl.quantityOrder = item.quantityOrder;
|
pl.orignHolderStorage = 0 + item.orignHolderStorage;
|
|
pl.smallUnit = item.smallUnit;
|
pl.bigUnit = item.bigUnit;
|
|
pl.taskProcess = item.taskProcess;
|
pl.taskType = item.taskType;
|
pl.userProduct_Id = item.userProduct_Id;
|
pl.storage_Id = item.storage_Id;
|
pl.storageName = item.storageName;
|
|
await this.dbWrite.save(pl);
|
}
|
// 更新备注
|
await this.dbWrite.update(SaleOrderPrint, orderPrintInfo.orderPrint_Id, {
|
remark: "已推送到灯光系统"
|
});
|
this.info.result = true;
|
this.info.msg = "灯光拣选成功";
|
} catch (ex) {
|
this.info.msg = ex.message;
|
this.info.result = false;
|
}
|
this.ctx.body = this.info;
|
}
|
//#endregion
|
}
|