import * as sql from "mssql";
|
import { SaleOrderPrint } from "../../entity/outbound/manufacture/saleOrderPrint";
|
import { Post } from "egg-shell-decorators";
|
import BaseController from "../baseController";
|
import { SaleOrder } from "../../entity/outbound/sale/saleOrder";
|
import { SaleOrderPicking } from "../../entity/outbound/manufacture/saleOrderPicking";
|
import { SaleOrderMatching } from "../../entity/outbound/manufacture/saleOrderMatching";
|
|
/**
|
* 拣货下架
|
*/
|
export default class OrderMatchingController extends BaseController {
|
//#region 出库单配货
|
/**
|
/// 出库单配货
|
*/
|
@Post()
|
public async getOrderMatchingData() {
|
let { ctx } = this;
|
let body = ctx.request.body;
|
let userInfo = await ctx.helper.userInfo();
|
let orderPrintCode = body.orderPrintCode;
|
let subOrderPrintCode = orderPrintCode;
|
let scanMain = true; // 扫描主波次
|
|
// 转为主波次单和
|
if (orderPrintCode.indexOf("-") > 0) {
|
let arr = orderPrintCode.split("-");
|
orderPrintCode = arr[0];
|
scanMain = false;
|
}
|
|
var orderPrintInfo = await this.dbRead.findOne(SaleOrderPrint, {
|
orderPrintCode: orderPrintCode,
|
userProduct_Id: userInfo.userProduct_Id
|
});
|
if (orderPrintInfo == null) {
|
this.info.result = false;
|
this.info.msg = body.orderPrintCode + "波次号不存在!";
|
ctx.body = this.info;
|
return;
|
}
|
var reqInfo: any = {};
|
|
reqInfo.orderPrintCode = orderPrintCode;
|
reqInfo.user_Id = userInfo.user_Id;
|
reqInfo.userTrueName = userInfo.userTrueName;
|
reqInfo.storage_Id = orderPrintInfo.storage_Id || 0;
|
reqInfo.storageName = orderPrintInfo.storageName;
|
|
//#region 校验
|
if (reqInfo == null) {
|
this.info.msg = "请求参数不正确";
|
ctx.body = this.info;
|
return;
|
}
|
if (reqInfo.user_Id == 0) {
|
this.info.msg = "用户ID都不能为空!";
|
ctx.body = this.info;
|
return;
|
}
|
if (!reqInfo.orderPrintCode) {
|
this.info.msg = "波次单号不能为空";
|
ctx.body = this.info;
|
return;
|
}
|
|
// if (orderPrintInfo.statusText != "等待配货" && orderPrintInfo.statusText != "配货中") {
|
// this.info.result = false;
|
// this.info.msg = "波次单状态为[" + orderPrintInfo.statusText + "],不允许操作";
|
// ctx.body = this.info;
|
// return;
|
// }
|
|
let dataInfo: any = {};
|
dataInfo.orderPrint_Id = orderPrintInfo.orderPrint_Id;
|
dataInfo.orderPrintCode = orderPrintInfo.orderPrintCode;
|
|
let matchInfo = await this.dbRead.findOne(SaleOrderMatching, {
|
orderPrintCode: orderPrintInfo.orderPrintCode,
|
userProduct_Id: userInfo.userProduct_Id
|
});
|
if (matchInfo != null && matchInfo.matchStatus == "配货完成") {
|
this.info.result = false;
|
this.info.msg = "波次单" + orderPrintInfo.orderPrintCode + "已经配货完成!";
|
ctx.body = this.info;
|
return;
|
}
|
//#endregion
|
|
try {
|
//明细数据
|
let sql = `
|
SELECT T.*, I.relationCode, I.relationCode2, I.relationCode3, I.relationCode4, I.relationCode5,
|
middleBarcode, middleUnitConvert, bigBarcode, I.unitConvert
|
FROM
|
(
|
SELECT allotPositionName,orderCode,order_Id, product_Id, productCode,productModel,
|
max(productName) as productName,
|
SUM(quantityOrder) AS quantityOrder,
|
SUM(isnull(finishedQuanity,0)) as finishedQuanity,MAX(weight) AS weight,MAX(totalWeight) AS totalWeight
|
FROM dbo.Sale_OrderPrintList
|
WHERE orderPrint_Id=@0
|
${orderPrintInfo.subBatch && !scanMain ? ` And SubOrderPrintCode='${subOrderPrintCode}'` : ""}
|
GROUP BY allotPositionName,orderCode,order_Id,product_Id, productCode,productModel
|
HAVING SUM(quantityOrder) - sum(isnull(finishedQuanity,0))>0
|
) T INNER JOIN dbo.vBase_ProductInfo_SKU I ON T.product_Id=I.product_Id
|
ORDER BY allotPositionName
|
`;
|
|
var matchOrderInfoList = await this.dbRead.query(sql, [orderPrintInfo.orderPrint_Id]);
|
|
if (matchOrderInfoList != null && matchOrderInfoList.length > 0) {
|
if (matchInfo != null && (matchInfo.matchStatus == "部分配货" || matchInfo.matchStatus == "配货中")) {
|
this.info.result = true;
|
this.info.msg = "波次单" + orderPrintInfo.orderPrintCode + "正在配货!";
|
dataInfo.dataList = matchOrderInfoList;
|
this.info.data = dataInfo;
|
this.info.dynamic = orderPrintInfo.storage_Id + "," + orderPrintInfo.storageName;
|
|
// 更新配货状态
|
await this.dbWrite.update(SaleOrderMatching, matchInfo.orderMatching_Id, {
|
matchStatus: "配货中"
|
});
|
|
ctx.body = this.info;
|
return;
|
}
|
|
dataInfo.dataList = matchOrderInfoList;
|
this.info.result = true;
|
this.info.data = dataInfo;
|
this.info.msg = "已成功获取扫描数据!";
|
this.info.dynamic = orderPrintInfo.storage_Id + "," + orderPrintInfo.storageName;
|
} 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 saveOrderMatch() {
|
let { ctx } = this;
|
let body = ctx.request.body;
|
let userInfo = await ctx.helper.userInfo();
|
let orderPrintCode = body.orderPrintCode;
|
|
//#region 校验
|
if (!orderPrintCode) {
|
this.info.msg = "波次不能为空!";
|
ctx.body = this.info;
|
return;
|
}
|
|
if (!body.dataList || body.dataList.length == 0) {
|
this.info.msg = "请先扫描条码!";
|
ctx.body = this.info;
|
return;
|
}
|
|
// 转为主波次单和
|
if (orderPrintCode.indexOf("-") > 0) {
|
let arr = orderPrintCode.split("-");
|
orderPrintCode = arr[0];
|
}
|
|
let orderPrint = await this.dbRead.findOne(SaleOrderPrint, {
|
orderPrintCode: orderPrintCode
|
});
|
if (!orderPrint) {
|
this.info.msg = "波次不存在!";
|
ctx.body = this.info;
|
return;
|
}
|
|
let orderPicking = await this.dbRead.findOne(SaleOrderPicking, {
|
orderPrintCode: orderPrintCode,
|
userProduct_Id: userInfo.userProduct_Id
|
});
|
if (orderPicking == null) {
|
this.info.msg = "拣货记录不存在!";
|
ctx.body = this.info;
|
return;
|
}
|
|
//#endregion
|
|
//#region 存储过程
|
let data = new sql.Table();
|
data.columns.add("storage_Id", sql.Int);
|
data.columns.add("storageName", sql.NVarChar(50));
|
data.columns.add("product_Id", sql.BigInt);
|
data.columns.add("productCode", sql.NVarChar(50));
|
data.columns.add("quantityOrder", sql.Int);
|
data.columns.add("finishedQuantity", sql.Int);
|
data.columns.add("allotPositionName", sql.NVarChar(50));
|
data.columns.add("orderCode", sql.NVarChar(50));
|
data.columns.add("weight", sql.Decimal(14, 2));
|
data.columns.add("totalWeight", sql.Decimal(14, 2));
|
|
for (var _detail of body.dataList) {
|
data.rows.add(
|
orderPicking.storage_Id,
|
orderPicking.storageName,
|
_detail.product_Id,
|
_detail.productCode,
|
_detail.quantityOrder,
|
_detail.finishedQuantity,
|
_detail.allotPositionName,
|
_detail.orderCode,
|
_detail.weight,
|
_detail.totalWeight
|
);
|
}
|
const connection: any = await this.dbWrite.connection;
|
let request = new sql.Request(connection.driver.master);
|
request.input("orderPrintCode", orderPrintCode);
|
request.input("user_Id", userInfo.user_Id);
|
request.input("menu_Id", 250);
|
request.input("excelDT", data);
|
request.output("outMsg", sql.NVarChar(2000));
|
let result = await request.execute("sp_Sale_Order_Matching");
|
let outMsg = result.output.outMsg;
|
|
if (outMsg && outMsg != "部分配货" && outMsg != "配货完成") {
|
this.info.result = false;
|
this.info.msg = outMsg;
|
ctx.body = this.info;
|
return;
|
} else {
|
this.info.result = true;
|
this.info.msg = outMsg;
|
if (!outMsg) {
|
//#region 更新状态和插入记录
|
var orderList = await this.dbRead.find(SaleOrder, {
|
orderPrintCode: body.orderPrintCode
|
});
|
for (var orderInfo of orderList) {
|
ctx.service.outbound.orderHelper.setStatusHistory(orderInfo.order_Id, 6, 7, "订单状态", "订单配货");
|
}
|
//#endregion
|
}
|
}
|
//#endregion
|
|
ctx.body = this.info;
|
return;
|
}
|
|
//#endregion
|
}
|