import { default as BaseController } from "../baseController";
|
import { Post } from "egg-shell-decorators";
|
import * as sql from "mssql";
|
import { StorageAllocateEnter } from "../../entity/storage/allocate/storageAllocateEnter";
|
import { BasePosition } from "../../entity/basicInfo/base/basePosition";
|
import { StorageAllocateEnterList } from "../../entity/storage/allocate/storageAllocateEnterList";
|
import { StorageAllocateApply } from "../../entity/storage/allocate/storageAllocateApply";
|
import { StorageAllocateApplyList } from "../../entity/storage/allocate/storageAllocateApplyList";
|
export default class AllocateEnterController extends BaseController {
|
//#region Auditing 审核
|
@Post()
|
public async auditing() {
|
let { ctx } = this;
|
let body = ctx.request.body;
|
let userInfo = await ctx.helper.userInfo();
|
let errorPositionName = "";
|
try {
|
let enterInfo = await this.dbRead.findOne(StorageAllocateEnter, {
|
allocateEnter_Id: body.idValue
|
});
|
|
let enterListInfos = await this.dbRead.find(StorageAllocateEnterList, {
|
allocateEnter_Id: body.idValue
|
});
|
// 明细数据
|
let emptyPositions = enterListInfos.filter(row => !row.positionName).map(item => item.productCode);
|
if (emptyPositions.length) {
|
let msg = emptyPositions.join(",") + "货位不能为空";
|
this.info.msg = msg;
|
this.info.result = false;
|
this.ctx.body = this.info;
|
return;
|
}
|
|
//验证调入货位是否正确
|
let groupByPositionInfos = enterListInfos.filter(row => row.positionName);
|
// 对单据进行分组
|
groupByPositionInfos = groupByPositionInfos.reduce(
|
(all: Array<any>, next) => (all.some(item => item.positionName === next.positionName) ? all : [...all, next]),
|
[]
|
);
|
for (let positionInfo of groupByPositionInfos) {
|
let positionInfos = await this.dbRead.find(BasePosition, {
|
storage_Id: enterInfo.storage_Id_In,
|
positionName: positionInfo.positionName
|
});
|
if (!positionInfos) {
|
if (errorPositionName) errorPositionName += ",";
|
errorPositionName += "'" + positionInfo.positionName + "'";
|
}
|
}
|
if (errorPositionName) {
|
this.info.result = false;
|
this.info.msg = "货位:" + errorPositionName + "在仓库【" + enterInfo.storageName_In + "】中不存在,请更改后再审核!";
|
ctx.body = this.info;
|
}
|
const connection: any = await this.dbWrite.connection;
|
let request = new sql.Request(connection.driver.master);
|
request.input("allocateEnter_Id", body.idValue);
|
request.input("user_Id", userInfo.user_Id);
|
request.input("userTrueName", userInfo.userTrueName);
|
request.output("outMsg", sql.NVarChar(2000));
|
let result = await request.execute("sp_Storage_AllocateEnter_Check");
|
let outMsg = result.output.outMsg;
|
if (outMsg) {
|
this.info.msg = outMsg;
|
this.info.result = false;
|
} else {
|
this.info.msg = "审核成功";
|
this.info.result = true;
|
}
|
ctx.body = this.info;
|
} catch (error) {
|
this.info.msg = "审核失败" + error.message;
|
this.info.result = false;
|
ctx.body = this.info;
|
}
|
}
|
//#endregion
|
//#region getByCode
|
/// <summary>
|
/// 根据调拨申请单Code获取调拨申请单管理信息
|
/// </summary>
|
/// <param name="AllocateEnterCode">调拨申请单编号</param>
|
/// <returns>调拨申请单对象</returns>
|
@Post()
|
public async getByCode() {
|
let { ctx } = this;
|
let body = ctx.request.body;
|
let userInfo = await ctx.helper.userInfo();
|
if (userInfo == null) {
|
this.info.msg = "未找到用户信息";
|
this.info.result = false;
|
ctx.body = this.info;
|
}
|
try {
|
let model = await this.dbRead.findOne(StorageAllocateApply, {
|
allocateApplyCode: body.code,
|
userProduct_Id: userInfo.userProduct_Id
|
});
|
//明细数据
|
let detailList = await this.dbRead.find(StorageAllocateApplyList, {
|
allocateApply_Id: model.allocateApply_Id
|
});
|
if (detailList) {
|
this.info.msg = "获取信息成功";
|
this.info.result = true;
|
this.info.data = {
|
consignor_Id: model.consignor_Id,
|
consignorCode: model.consignorCode,
|
consignorName: model.consignorName,
|
storage_Id: model.storage_Id,
|
storageName: model.storageName,
|
storage_Id_In: model.storage_Id_In,
|
storageName_In: model.storageName_In,
|
storage_AllocateApplyList: detailList
|
};
|
}
|
} catch (error) {
|
this.info.msg = "未找到用户信息" + error.message;
|
this.info.result = false;
|
ctx.body = this.info;
|
}
|
|
ctx.body = this.info;
|
}
|
//#endregion
|
}
|