import BaseService from "../baseService";
|
import { SysUser } from "../../entity/sys/core/sysUser";
|
import { LoginInfo } from "../../entity/sys/loginInfo";
|
import * as sql from "mssql";
|
import moment = require("moment");
|
import { StorageReplenishment } from "../../entity/storage/replenishment/storageReplenishment";
|
import { In } from "typeorm";
|
import { BaseProductPlaceHolder } from "../../entity/storage/storage/baseProductPlaceHolder";
|
/**
|
* 产品入库单Service
|
*/
|
export default class StorageReplenishmentService extends BaseService {
|
// #region 获取补货数据
|
/// <summary>
|
/// 获取补货数据
|
/// </summary>
|
/// <returns></returns>
|
public async getReplenishmentGroupData(replenishmentCode) {
|
let { ctx } = this;
|
let userInfo = await ctx.helper.userInfo();
|
let sql = "";
|
if (!replenishmentCode) {
|
this.info.result = false;
|
this.info.msg = "请扫描补货单号!";
|
return this.info;
|
}
|
sql = `SELECT S.product_Id, S.productCode, S.productModel, S.productName,ISNULL(S.ProductSpec,'') AS productSpec,
|
SUM(S.PlaceholderStorage) AS placeholderStorage,S. positionName, S.storageName,
|
ISNULL(S.BatchNumber,'') AS batchNumber,ISNULL( S.ProduceDate,'') AS produceDate,
|
ISNULL(S.PlateCode,'') AS plateCode, L.positionName AS targetPositionName,S.consignor_Id,
|
(SELECT TOP 1 manufacturer FROM dbo.vBase_ProductInfo_SKU nolock WHERE Product_Id=S.Product_Id) AS manufacturer
|
FROM Base_ProductPlaceHolder AS S INNER JOIN dbo.Storage_ReplenishmentList AS L
|
ON S.DetailID=L.ReplenishmentList_Id AND S.MainID=L.Replenishment_Id
|
WHERE ClassName='补货出库' AND S.PlaceholderStorage>0 AND
|
Replenishment_Id IN(SELECT TOP 1 Replenishment_Id FROM dbo.Storage_Replenishment WHERE ReplenishmentCode=@0 AND UserProduct_Id=@1)
|
AND S.UserProduct_Id=@1
|
GROUP BY S.Product_Id,S.ProductCode, S.ProductModel, S.ProductName,S.ProductSpec,S. PositionName,S.StorageName,
|
S.BatchNumber,S.ProduceDate,L.PositionName,S.PlateCode,S.Consignor_Id;`;
|
let orderList = await this.dbWrite.query(sql, [replenishmentCode, userInfo.userProduct_Id]);
|
if (!orderList || orderList.length <= 0) {
|
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 storageReplenishmentSave(replenishmentCode, productModelList: Array<any>, user_Id) {
|
let userInfo = new LoginInfo();
|
//#region 验证用户信息
|
let table = await this.dbRead.findOne(SysUser, {
|
user_Id: user_Id
|
});
|
if (table) {
|
userInfo.user_Id = table.user_Id;
|
userInfo.userName = table.userName;
|
userInfo.userTrueName = table.userTrueName;
|
}
|
|
if (!productModelList) {
|
this.info.msg = "没有确认补货出库数据";
|
this.info.result = false;
|
return this.info;
|
}
|
// #endregion
|
try {
|
var 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.DateTime);
|
excelDT.columns.add("plateCode", sql.NVarChar(50));
|
excelDT.columns.add("consignor_Id", sql.Int);
|
for (var dataItem of productModelList) {
|
excelDT.rows.add(
|
dataItem.product_Id,
|
dataItem.finishedQuantity,
|
dataItem.originalPositionName,
|
dataItem.targetPositionName,
|
dataItem.batchNumber,
|
moment(dataItem.produceDate).toDate(),
|
dataItem.plateCode,
|
dataItem.consignor_Id
|
);
|
}
|
const connection: any = await this.dbWrite.connection;
|
let request = new sql.Request(connection.driver.master);
|
request.input("replenishmentCode", replenishmentCode);
|
request.input("user_Id", user_Id);
|
request.input("execelDT", excelDT);
|
request.output("outMsg", sql.NVarChar(2000));
|
let result = await request.execute("sp_Storage_Replenishment_ConfirmOut");
|
let outMsg = result.output.outMsg;
|
if (outMsg) {
|
this.info.msg = outMsg;
|
this.info.result = false;
|
} else {
|
this.info.msg = "补货出库成功";
|
this.info.result = true;
|
}
|
return this.info;
|
} catch (ex) {
|
this.info.msg = "出库失败," + ex.message;
|
this.info.result = false;
|
return this.info;
|
}
|
}
|
//#endregion
|
|
//#region Stop
|
public async stop() {
|
// 删除占位
|
await this.dbRead.delete(BaseProductPlaceHolder, {
|
className: "补货出库",
|
mainID: In(this.body.idValues)
|
});
|
let stList = await this.dbRead.find(StorageReplenishment, {
|
replenishment_Id: In(this.body.idValues)
|
});
|
for (let sInfo of stList) {
|
await this.dbRead.update(StorageReplenishment, sInfo.replenishment_Id, {
|
billStatus: "终止"
|
});
|
}
|
this.info.result = true;
|
this.info.msg = "终止成功!";
|
|
return this.info;
|
}
|
//#endregion
|
|
//#region Open
|
public async open() {
|
let stList = await this.dbRead.find(StorageReplenishment, {
|
replenishment_Id: In(this.body.idValues)
|
});
|
for (let sInfo of stList) {
|
await this.dbRead.update(StorageReplenishment, sInfo.replenishment_Id, {
|
billStatus: "新建",
|
auditing: 0,
|
auditor: null,
|
auditDate: null,
|
sortingStatus: 1,
|
sortingDate: null
|
});
|
}
|
this.info.result = true;
|
this.info.msg = "开启成功!";
|
|
return this.info;
|
}
|
//#endregion
|
}
|