import * as sql from "mssql";
|
import BaseController from "../baseController";
|
import { Post } from "egg-shell-decorators";
|
import { SaleOrderPrint } from "../../entity/outbound/manufacture/saleOrderPrint";
|
import { SaleOrderPicking } from "../../entity/outbound/manufacture/saleOrderPicking";
|
import { SaleOrderPrintList } from "../../entity/outbound/manufacture/saleOrderPrintList";
|
/**
|
* 扫拍下架
|
*/
|
export default class OrderPickingController extends BaseController {
|
//#region app-根据波次单号获取下架理货位
|
@Post()
|
public async getPickingOrderInfo() {
|
let { ctx } = this;
|
let body = ctx.request.body;
|
let userInfo = await ctx.helper.userInfo();
|
let orderPrintCode = body.orderPrintCode; // 盘点单号
|
try {
|
if (!orderPrintCode) {
|
this.info.result = false;
|
this.info.msg = "波次单号不能为空!";
|
ctx.body = this.info;
|
return;
|
}
|
// 对主表数据进行检验
|
let dataInfo = await this.dbRead
|
.createQueryBuilder(SaleOrderPrint, "t")
|
.where("orderPrintCode=:orderPrintCode", {
|
orderPrintCode: orderPrintCode
|
})
|
.getOne();
|
if (!dataInfo) {
|
this.info.msg = "未找到波次数据!";
|
this.info.result = false;
|
ctx.body = this.info;
|
return;
|
}
|
if (dataInfo.user_Id != userInfo.user_Id) {
|
this.info.msg = "该波次单已被其他用户占有!";
|
this.info.result = false;
|
ctx.body = this.info;
|
return;
|
}
|
// 获取波次对应的明细信息
|
let info = await ctx.service.outbound.pickingPaiScanService.getData(orderPrintCode, userInfo);
|
if (info.result) {
|
// 更新这个波次单为当前用户所有
|
let sql = `UPDATE dbo.Sale_OrderPrint
|
SET User_Id=u.User_Id,UserTrueName=u.UserTrueName,PickingStatus='拣货中',StatusID=5,StatusText='拣货中'
|
FROM dbo.Sale_OrderPrint s,dbo.Sys_User u
|
WHERE s.OrderPrint_Id=@0 AND u.User_Id=@1`;
|
await this.dbRead.query(sql, [dataInfo.orderPrint_Id, userInfo.user_Id]);
|
let sqlOne = `UPDATE dbo.Sys_User SET PDAOperateDate=GETDATE() WHERE User_Id= @0`;
|
await this.dbRead.query(sqlOne, [userInfo.user_Id]);
|
}
|
this.info.msg = info.msg;
|
this.info.data = info.data;
|
this.info.result = info.result;
|
} catch (error) {
|
this, (this.info.result = false);
|
this.info.msg = "错误:" + error.message;
|
}
|
ctx.body = this.info;
|
}
|
//#endregion
|
|
//#region app-根据波次号和拍号获取数据
|
@Post()
|
public async getPlateStorage() {
|
let { ctx } = this;
|
let body = ctx.request.body;
|
let orderPrintCode = body.orderPrintCode; // 盘点单号
|
let plateCode = body.plateCode; // 拍号
|
try {
|
if (!orderPrintCode) {
|
this.info.result = false;
|
this.info.msg = "波次单号不能为空!";
|
ctx.body = this.info;
|
return;
|
}
|
if (!plateCode) {
|
this.info.result = false;
|
this.info.msg = "拍号不能为空!";
|
ctx.body = this.info;
|
return;
|
}
|
// 获取波次对应的明细信息
|
this.info = await ctx.service.outbound.pickingPaiScanService.getHoldingStorageByPlateCode(
|
orderPrintCode,
|
plateCode
|
);
|
} catch (error) {
|
this, (this.info.result = false);
|
this.info.msg = "错误:" + error.message;
|
}
|
ctx.body = this.info;
|
}
|
//#endregion
|
|
//#region 保存扫描结果
|
/**
|
* 接货完成
|
*/
|
@Post()
|
public async saveScan() {
|
let { ctx } = this;
|
let body = ctx.request.body;
|
let userInfo = await ctx.helper.userInfo();
|
try {
|
let batchCode = body.batchCode; //波次号
|
let cartCode = body.cartCode; //车号
|
let dataList = body.dataList;
|
let orderPrint: SaleOrderPrint = await this.dbRead.findOne(SaleOrderPrint, {
|
orderPrintCode: batchCode
|
});
|
|
let printListModel = await this.dbRead.find(SaleOrderPrintList, {
|
orderPrint_Id: orderPrint.orderPrint_Id
|
});
|
|
//#region 校验
|
|
if (!batchCode) {
|
this.info.msg = "波次不能为空!";
|
ctx.body = this.info;
|
return;
|
}
|
if (!dataList || dataList.length == 0) {
|
this.info.msg = "请先扫描条码!";
|
ctx.body = this.info;
|
return;
|
}
|
if (orderPrint == null) {
|
this.info.msg = "波次不存在!";
|
ctx.body = this.info;
|
return;
|
}
|
if (dataList.PickingStatus == "等待配货") {
|
this.info.msg = "波次单[" + dataList.orderPrintCode + "]已经完成拣货,不能再拣货!";
|
ctx.body = this.info;
|
return;
|
}
|
let orderPicking = await this.dbRead.find(SaleOrderPicking, {
|
orderPrintCode: batchCode,
|
user_Id: userInfo.user_Id
|
});
|
if (orderPicking == null) {
|
this.info.msg = "拣货记录不存在!";
|
ctx.body = this.info;
|
return;
|
}
|
|
//#endregion
|
|
//#region 存储过程
|
let data = new sql.Table();
|
data.columns.add("productModel", sql.NVarChar(50));
|
data.columns.add("productCode", sql.NVarChar(50));
|
data.columns.add("positionName", sql.NVarChar(50));
|
data.columns.add("offPosition", sql.NVarChar(50));
|
data.columns.add("plateCode", sql.NVarChar(50));
|
data.columns.add("scanCount", sql.BigInt);
|
data.columns.add("weight", sql.Decimal(14, 4));
|
data.columns.add("totalWeight", sql.Decimal(14, 4));
|
for (var _detail of dataList) {
|
data.rows.add(
|
_detail.productModel,
|
_detail.productCode,
|
_detail.positionName,
|
_detail.offPosition,
|
_detail.plateCode,
|
_detail.scanCount,
|
_detail.weight,
|
_detail.totalWeight
|
);
|
}
|
const connection: any = await this.dbWrite.connection;
|
let request = new sql.Request(connection.driver.master);
|
request.input("batchCode", batchCode);
|
request.input("cartCode", cartCode);
|
request.input("user_Id", userInfo.user_Id);
|
request.input("userProduct_Id", userInfo.userProduct_Id);
|
request.input("data", data);
|
request.output("msg", sql.NVarChar(2000));
|
let result = await request.execute("sp_ScanPickingSave");
|
let msg = result.output.msg;
|
|
if (msg && msg != "部分拣货") {
|
this.info.result = false;
|
this.info.msg = msg;
|
ctx.body = this.info;
|
return;
|
} else {
|
this.info.result = true;
|
}
|
//#endregion
|
|
if (msg == "部分拣货") {
|
this.info.result = true;
|
this.info.state = "部分下架";
|
this.info.msg = "提交成功,已部分下架成功!";
|
} else {
|
// 对单据进行分组
|
let groupData = printListModel.reduce(
|
(all: Array<any>, next) => (all.some(item => item["order_Id"] == next["order_Id"]) ? all : [...all, next]),
|
[]
|
);
|
|
for (var g of groupData) {
|
ctx.service.outbound.orderHelper.setStatusHistory(g.order_Id, 5, 6, "订单状态", "订单拣货");
|
}
|
}
|
|
ctx.body = this.info;
|
} catch (ex) {
|
this.info.result = false;
|
this.info.msg = "错误信息:" + ex.message;
|
}
|
ctx.body = this.info;
|
}
|
//#endregion
|
}
|