import BaseService from "../baseService";
|
import * as sql from "mssql";
|
import { ResultInfo } from "../../public/commonInterface";
|
import { StoragePositionTransfer } from "../../entity/storage/check/storagePositionTransfer";
|
import { In } from "typeorm";
|
export default class PositionTransferService extends BaseService {
|
//#region 获取货位数据
|
|
/// <summary>
|
/// 获取货位数据
|
/// </summary>
|
/// <returns></returns>
|
public async getProductPositionGroupData(originalPositionName: string, targetPositionName: string, storage_Id) {
|
let { ctx } = this;
|
let body = ctx.request.body;
|
let sql = "";
|
if (!originalPositionName) {
|
this.info.result = false;
|
this.info.msg = "原货位不能为空!";
|
return this.info;
|
}
|
if (storage_Id <= 0) {
|
this.info.result = false;
|
this.info.msg = "仓库不能为空!";
|
return this.info;
|
}
|
if (originalPositionName == targetPositionName) {
|
this.info.result = false;
|
this.info.msg = "原货位和目标货位不能相同!";
|
return this.info;
|
}
|
sql = `
|
SELECT PP.product_Id,PP.productCode,PP.productModel,PP.productName,ISNULL(PP.ProductSpec,'') AS productSpec,
|
PP.ValidQuantity as productStorage, PP.positionName,PP.storageName,ISNULL(PP.batchNumber,'') AS batchNumber,
|
PP.produceDate, PP.productAttribute, PP.storageStatus,
|
ISNULL(PP.PlateCode,'') AS plateCode, PP.consignor_Id, PP.consignorCode, PP.consignorName,
|
(SELECT TOP 1 ServerPath FROM dbo.Base_ProductInfo_Image WHERE product_Id=PP.product_Id) AS serverPath,
|
PI.relationCode, PI.relationCode2, PI.relationCode3, PI.relationCode4, PI.relationCode5,
|
PI.middleBarcode, PI.middleUnitConvert, PI.bigBarcode, PI.unitConvert,ISNULL(PP.Weight,0) as weight,PP.ValidQuantity*ISNULL(PP.Weight,0) as sumTotalWeight
|
FROM dbo.vBase_ProductInfo_SKU AS PI INNER JOIN
|
dbo.vBase_ProductPositionGroup AS PP ON PI.product_Id = PP.product_Id
|
WHERE PP.PositionName COLLATE Chinese_PRC_CS_AS=@0 AND storage_Id=@1
|
AND ValidQuantity>0 /*AND PositionType IN(1,2,4,5,6,8,12,13)*/`;
|
|
let orderList = await this.dbRead.query(sql, [body.originalPositionName, body.storage_Id]);
|
if (!orderList) {
|
this.info.result = false;
|
this.info.msg = "未找到对应的明细数据";
|
return this.info;
|
} else {
|
this.info.result = true;
|
this.info.msg = "";
|
this.info.data = orderList;
|
return this.info;
|
}
|
}
|
//#endregion
|
|
// #region ScanSvae 货位转移操作
|
/// <summary>
|
/// 货位转移操作
|
/// </summary>
|
/// <returns></returns>
|
public async storagePositionTransferSave(storage_Id, productModelList, user_Id) {
|
let { ctx } = this;
|
|
try {
|
// #region 验证用户信息
|
if (!productModelList.length) {
|
this.info.msg = "转移数据错误";
|
this.info.result = false;
|
return this.info;
|
}
|
// #endregion
|
|
// #region 创建一个DataTable
|
let excelDT = new sql.Table();
|
excelDT.columns.add("product_Id", sql.Int);
|
excelDT.columns.add("finishedQuantity", sql.Int);
|
excelDT.columns.add("originalPositionName", sql.NVarChar(50));
|
excelDT.columns.add("targetPositionName", sql.NVarChar(50));
|
excelDT.columns.add("batchNumber", sql.NVarChar(50));
|
excelDT.columns.add("produceDate", 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("ScanWeight", sql.Decimal(12, 4));
|
excelDT.columns.add("Weight", sql.Decimal(12, 4));
|
excelDT.columns.add("storageStatus", sql.NVarChar(50));
|
excelDT.columns.add("productAttribute", sql.NVarChar(50));
|
|
for (var dataItem of productModelList) {
|
if (!dataItem.targetPositionName) {
|
this.info.msg = "目标货位不能为空";
|
this.info.result = false;
|
return this.info;
|
}
|
excelDT.rows.add(
|
dataItem.product_Id,
|
dataItem.finishedQuantity,
|
dataItem.originalPositionName,
|
dataItem.targetPositionName,
|
dataItem.batchNumber,
|
dataItem.produceDate,
|
dataItem.productSpec,
|
dataItem.plateCode,
|
dataItem.consignor_Id,
|
dataItem.scanWeight,
|
dataItem.weight,
|
dataItem.storageStatus,
|
dataItem.productAttribute
|
);
|
}
|
// #endregion
|
let transferCode = await ctx.service.common.getCodeRegular(450);
|
const connection: any = await this.dbWrite.connection;
|
let request = new sql.Request(connection.driver.master);
|
request.input("transferCode", transferCode);
|
request.input("storage_Id", storage_Id);
|
request.input("user_Id", user_Id);
|
request.input("excelDT", excelDT);
|
request.output("outMsg", sql.NVarChar(2000));
|
let result = await request.execute("sp_Storage_PositionTransfer_Create");
|
let outMsg = result.output.outMsg;
|
if (outMsg) {
|
this.info.msg = outMsg;
|
this.info.result = false;
|
return this.info;
|
} else {
|
let where = { transferCode: transferCode };
|
let transfer = await this.dbRead.findOne(StoragePositionTransfer, where);
|
if (transfer != null) {
|
const connection: any = await this.dbWrite.connection;
|
let request = new sql.Request(connection.driver.master);
|
request.input("transfer_Id", transfer.transfer_Id);
|
request.input("user_Id", user_Id);
|
request.input("Menu_Id", 450);
|
request.output("outMsg", sql.NVarChar(2000));
|
let result = await request.execute("sp_Storage_PositionTransfer_Check");
|
let outMsgs = result.output.outMsg;
|
if (outMsgs) {
|
this.info.msg = outMsgs;
|
this.info.result = false;
|
return this.info;
|
} else {
|
this.info.msg = "确认转移成功";
|
this.info.result = true;
|
return this.info;
|
}
|
} else {
|
this.info.msg = "转移失败,单据创建成功";
|
this.info.result = false;
|
return this.info;
|
}
|
}
|
} catch (error) {
|
this.info.msg = "转移错误:" + error.message;
|
this.info.result = false;
|
return this.info;
|
}
|
}
|
//#endregion
|
|
// #region Stop
|
/// <summary>
|
/// 货位转移终止
|
/// </summary>
|
/// <param name="loadInfo"></param>
|
/// <returns></returns>
|
public async stop(): Promise<ResultInfo> {
|
let { ctx } = this;
|
let body = ctx.request.body;
|
|
try {
|
let transferInfo = await this.dbRead.find(StoragePositionTransfer, {
|
transfer_Id: In(this.body.idValues)
|
});
|
for (let item of transferInfo) {
|
await this.dbWrite.update(
|
body.tableName,
|
{
|
[body.idField]: item.transfer_Id
|
},
|
{
|
statusID: 3,
|
statusText: "终止",
|
sortingStatus: 1,
|
sortingDate: null
|
}
|
);
|
}
|
this.info.result = true;
|
this.info.msg = "终止成功!";
|
} catch (error) {
|
this.info.result = true;
|
this.info.msg = "终止失败!" + error.message;
|
}
|
return this.info;
|
}
|
//#endregion
|
|
// #region Open
|
/// <summary>
|
/// 货位转移开启
|
/// </summary>
|
/// <returns></returns>
|
public async open(): Promise<ResultInfo> {
|
let { ctx } = this;
|
let body = ctx.request.body;
|
try {
|
let transferInfo = await this.dbRead.find(StoragePositionTransfer, {
|
transfer_Id: In(this.body.idValues)
|
});
|
for (let item of transferInfo) {
|
if (item.statusText != "终止") {
|
this.info.result = false;
|
this.info.msg = "只有状态为终止, 才能开启!";
|
this.ctx.body = this.info;
|
return this.info;
|
}
|
await this.dbWrite.update(
|
body.tableName,
|
{
|
[body.idField]: item.transfer_Id
|
},
|
{
|
statusID: 1,
|
statusText: "新建",
|
sortingStatus: 1,
|
auditing: null,
|
sortingDate: null
|
}
|
);
|
}
|
this.info.result = true;
|
this.info.msg = "开启成功!";
|
} catch (error) {
|
this.info.result = false;
|
this.info.msg = "开启失败!" + error.message;
|
}
|
return this.info;
|
}
|
//#endregion
|
}
|