import * as sql from "mssql";
|
import { Post } from "egg-shell-decorators";
|
import BaseController from "../baseController";
|
import { BasePosition } from "../../entity/basicInfo/base/basePosition";
|
|
/**
|
* 下架回拣
|
*/
|
export default class OrderPickingShelveController extends BaseController {
|
//#region 下架回拣 - 获取入库收货位
|
@Post()
|
public async getOffPosition() {
|
let { ctx } = this;
|
let body = ctx.request.body;
|
let storage_Id = body.storage_Id;
|
|
let outDateSet = await this.dbRead.find(BasePosition, {
|
select: ["positionName"],
|
where: {
|
storage_Id: storage_Id,
|
positionType: 5
|
}
|
});
|
if (!outDateSet.length) {
|
this.info.result = false;
|
this.info.msg = "理货位不存在";
|
ctx.body = this.info;
|
return;
|
} else {
|
this.info.result = true;
|
this.info.data = outDateSet;
|
ctx.body = this.info;
|
return;
|
}
|
}
|
//#endregion
|
|
//#region 下架回拣 - 获得理货位数据
|
@Post()
|
public async getOffPositionData() {
|
let { ctx } = this;
|
let body = ctx.request.body;
|
let storage_Id = body.storage_Id;
|
let positionName = body.positionName;
|
let productModel = body.productModel;
|
if (!positionName) {
|
this.info.result = false;
|
this.info.msg = "理货位不能为空!";
|
ctx.body = this.info;
|
return;
|
}
|
if (!productModel) {
|
this.info.result = false;
|
this.info.msg = "条码不能为空!";
|
ctx.body = this.info;
|
return;
|
}
|
|
let query = `
|
SELECT top 1 L.product_Id,L.productCode,L.productModel,0 AS finishedQuantity,L.productSpec, L.productName,
|
L.positionName, NULL AS shelvePosition, storage_Id, storageName, L.batchNumber,L.purchasePrice,
|
L.plateCode, CONVERT(varchar(100), L.produceDate, 120) AS produceDate, I.relationCode, I.relationCode2, I.relationCode3, I.relationCode4, I.relationCode5,
|
L.middleBarcode, I.middleUnitConvert, L.bigBarcode, I.unitConvert,L.validQty as validQty,L.consignor_Id,L.consignorCode,L.consignorName,L.weight,L.TotalWeight
|
FROM dbo.vBase_ProductPosition L INNER JOIN dbo.vBase_ProductInfo_SKU I ON L.product_Id=I.product_Id
|
WHERE L.positionName=@0
|
AND L.storage_Id=@1
|
AND L.productModel COLLATE Chinese_PRC_CS_AS=@2
|
AND L.PositionType=5
|
AND L.validQty>0
|
;`;
|
let orderList = await this.dbRead.query(query, [positionName, storage_Id, productModel]);
|
if (!orderList || orderList.length == 0) {
|
this.info.result = false;
|
this.info.msg = "未找到可上架理货位数据,请检查一下是否将理货位的库存释放占位了";
|
} else {
|
this.info.result = true;
|
this.info.data = orderList;
|
}
|
ctx.body = this.info;
|
return;
|
}
|
//#endregion
|
|
//#region 下架回拣 - 扫描保存
|
/// <summary>
|
/// 说明:扫描保存
|
/// </summary>
|
/// <returns></returns>
|
@Post()
|
public async shelveOffPositionSave() {
|
let { ctx } = this;
|
let body = ctx.request.body;
|
let userInfo = await ctx.helper.userInfo();
|
let productModelList = body.productDataList;
|
|
let menu_Id = 103;
|
if (!productModelList.length) {
|
this.info.result = false;
|
this.info.msg = "已扫描数量不能全部为零";
|
ctx.body = this.info;
|
return;
|
}
|
|
try {
|
let excelDT = new sql.Table();
|
excelDT.columns.add("storage_Id", sql.Int);
|
excelDT.columns.add("storageName", sql.NVarChar(50));
|
excelDT.columns.add("product_Id", sql.Int);
|
excelDT.columns.add("finishedQuantity", sql.Int);
|
excelDT.columns.add("productCode", sql.NVarChar(50));
|
excelDT.columns.add("productModel", sql.NVarChar(50));
|
excelDT.columns.add("positionName", sql.NVarChar(50));
|
excelDT.columns.add("shelvePosition", sql.NVarChar(50));
|
excelDT.columns.add("produceDate", sql.NVarChar(50));
|
|
excelDT.columns.add("purchasePrice", sql.Decimal(14, 4));
|
excelDT.columns.add("batchNumber", sql.NVarChar(50));
|
excelDT.columns.add("productSpec", sql.NVarChar(50));
|
excelDT.columns.add("plateCode", sql.NVarChar(50));
|
|
excelDT.columns.add("consignor_Id", sql.Int);
|
excelDT.columns.add("consignorCode", sql.NVarChar(50));
|
excelDT.columns.add("consignorName", sql.NVarChar(50));
|
|
excelDT.columns.add("weight", sql.Decimal(14, 4));
|
excelDT.columns.add("TotalWeight", sql.Decimal(14, 4));
|
|
for (var dataItem of productModelList) {
|
excelDT.rows.add(
|
dataItem.storage_Id,
|
dataItem.storageName,
|
dataItem.product_Id,
|
dataItem.finishedQuantity,
|
|
dataItem.productCode,
|
dataItem.productModel,
|
dataItem.positionName,
|
dataItem.shelvePosition,
|
dataItem.produceDate,
|
|
dataItem.purchasePrice,
|
dataItem.batchNumber,
|
dataItem.productSpec,
|
dataItem.plateCode,
|
|
dataItem.consignor_Id,
|
dataItem.consignorCode,
|
dataItem.consignorName,
|
dataItem.weight,
|
dataItem.TotalWeight
|
);
|
}
|
let shelveCode = await ctx.service.common.getCodeRegular(269);
|
const connection: any = await this.dbWrite.connection;
|
let request = new sql.Request(connection.driver.master);
|
request.input("shelveCode", shelveCode);
|
request.input("user_Id", userInfo.user_Id);
|
request.input("menu_Id", menu_Id);
|
request.input("excelDT", excelDT);
|
request.output("outMsg", sql.NVarChar(2000));
|
let result = await request.execute("sp_Sale_Shelve_OffPosition");
|
let outMsg = result.output.outMsg;
|
|
if (outMsg) {
|
this.info.msg = outMsg;
|
this.info.result = false;
|
} else {
|
this.info.msg = "确认上架成功!";
|
this.info.result = true;
|
}
|
} catch (error) {
|
this.info.msg = "错误:" + error.message;
|
this.info.result = false;
|
}
|
ctx.body = this.info;
|
return;
|
}
|
//#endregion
|
}
|