import { default as BaseController } from "../baseController";
|
import { Post } from "egg-shell-decorators";
|
import * as sql from "mssql";
|
|
import { StorageValidAdjust } from "../../entity/storage/validadjust/storageValidAdjust";
|
import { StorageConsignorTransferList } from "../../entity/storage/consignor/storageConsignorTransferList";
|
import { StorageConsignorTransfer } from "../../entity/storage/consignor/storageConsignorTransfer";
|
import moment = require("moment");
|
|
export default class StorageConsignorTransferController extends BaseController {
|
//#region ConfirmAdjust 确认修改
|
@Post()
|
public async confirmAdjust() {
|
let { ctx } = this;
|
let body = ctx.request.body;
|
let userInfo = await ctx.helper.userInfo();
|
let id = body.id;
|
|
try {
|
if (!id) {
|
this.info.result = false;
|
this.info.msg = "未找到信息,id为0";
|
this.ctx.body = this.info;
|
return;
|
}
|
|
let adjustInfo = await this.dbRead.findOne(StorageValidAdjust, id);
|
|
const connection: any = await this.dbWrite.connection;
|
let request = new sql.Request(connection.driver.master);
|
request.input("ValidAdjust_Id", body.id);
|
request.input("User_Id", userInfo.user_Id);
|
request.output("outMsg", sql.NVarChar(2000));
|
let result = await request.execute("sp_Stoarge_ValidAdjust_Confirm");
|
let outMsg = result.output.outMsg;
|
if (outMsg) {
|
this.info.result = false;
|
this.info.msg = "【" + adjustInfo.validAdjustCode + "】调整失败";
|
} else {
|
this.info.result = true;
|
this.info.msg = "【" + adjustInfo.validAdjustCode + "】调整成功";
|
}
|
} catch (ex) {
|
this.info.result = false;
|
this.info.msg = "效期调整失败,原因:" + ex.message.ToString();
|
}
|
ctx.body = this.info;
|
}
|
//#endregion
|
|
//#region 审核
|
@Post()
|
public async auditing() {
|
let { ctx } = this;
|
let body = ctx.request.body;
|
let userInfo = await ctx.helper.userInfo();
|
let idValue = body.idValue;
|
try {
|
// 查询主表
|
for (let s_Id of idValue) {
|
// 明细校验
|
let transferListInfos = await this.dbRead.find(StorageConsignorTransferList, {
|
consignorTransfer_Id: s_Id
|
});
|
for (var item of transferListInfos) {
|
//目标货位不能为空
|
if (!item.positionName) {
|
this.info.result = false;
|
this.info.msg = "目标货位有空值,请查正后审核!";
|
this.ctx.body = this.info;
|
return;
|
}
|
//目标货主不能为空
|
if (!item.consignorName_Target) {
|
this.info.result = false;
|
this.info.msg = "目标货主有空值,请查正后审核!";
|
this.ctx.body = this.info;
|
return;
|
}
|
//转移数量不能为0 TransferQuantity = 1
|
if (!item.transferQuantity) {
|
this.info.result = false;
|
this.info.msg = "转移数量不能为0,请查正后审核!";
|
this.ctx.body = this.info;
|
return;
|
}
|
}
|
let Storage_ConsignorTransferInfo = await this.dbRead.findOne(StorageConsignorTransfer, s_Id);
|
if (Storage_ConsignorTransferInfo.statusText != "新建") {
|
this.info.result = false;
|
this.info.msg = "只有订单状态为新建才能审核!";
|
this.ctx.body = this.info;
|
return;
|
}
|
if (body.auditing == 2) {
|
await this.dbWrite.update(
|
StorageConsignorTransfer,
|
{
|
consignorTransfer_Id: s_Id
|
},
|
{
|
auditor: userInfo.userTrueName,
|
auditing: 2,
|
auditDate: new Date(),
|
remark: null,
|
statusID: 2,
|
statusText: "审核成功"
|
}
|
);
|
}
|
}
|
this.info.result = true;
|
this.info.msg = "审核成功!";
|
} catch (ex) {
|
this.info.result = false;
|
this.info.msg = "错误信息:" + ex.message;
|
}
|
ctx.body = this.info;
|
}
|
// #endregion
|
|
//#region 开始分拣
|
@Post()
|
public async startSorting() {
|
let { ctx } = this;
|
let body = ctx.request.body;
|
let id = body.id;
|
|
if (!id) {
|
this.info.result = false;
|
this.info.msg = "订单号不能为空!";
|
this.ctx.body = this.info;
|
return;
|
}
|
|
let Storage_ConsignorTransferInfo = await this.dbRead.findOne(StorageConsignorTransfer, id);
|
// Storage_ConsignorTransfer Storage_ConsignorTransferInfo = Storage_ConsignorTransferRepository.Instance.GetById(model.Id);
|
if (Storage_ConsignorTransferInfo.auditing != 2) {
|
this.info.result = false;
|
this.info.msg = "只有订单状态为审核成功才能分拣!";
|
this.ctx.body = this.info;
|
return;
|
}
|
|
this.info = await this.sortingMain(body.id);
|
ctx.body = this.info;
|
}
|
//#endregion
|
|
//#region 分拣入口 SortingMain
|
/// <summary>
|
/// 分拣入口
|
/// </summary>
|
@Post()
|
public async sortingMain(id) {
|
let { ctx } = this;
|
let body = ctx.request.body;
|
let userInfo = await ctx.helper.userInfo();
|
// let id = body.id;
|
let startDate = moment(Date.now());
|
|
//#region 正常分拣
|
let transferInfo = await this.dbRead.findOne(StorageConsignorTransfer, id);
|
|
const connection: any = await this.dbWrite.connection;
|
let request = new sql.Request(connection.driver.master);
|
request.input("ConsignorTransfer_Id", body.id);
|
request.input("User_Id", userInfo.user_Id);
|
request.output("outMsg", sql.NVarChar(2000));
|
let result = await request.execute("sp_Storage_ConsignorTransfer_Sorting");
|
let outMsg = result.output.outMsg;
|
let endDate = moment(Date.now());
|
let hour = endDate.diff(startDate, "hour");
|
let Minutes = endDate.diff(startDate, "minute");
|
let second = endDate.diff(startDate, "second");
|
|
this.info.result = outMsg.indexOf("成功") >= 0;
|
this.info.msg =
|
"单据【" +
|
transferInfo.consignorTransferCode +
|
"】" +
|
outMsg +
|
",数据分析完毕,共耗时" +
|
hour +
|
"小时" +
|
Minutes +
|
"分钟" +
|
second +
|
"秒。<br>";
|
|
//#endregion
|
return this.info;
|
}
|
//#endregion
|
|
//#region 确认过户
|
@Post()
|
public async transferConfirm() {
|
let { ctx } = this;
|
let body = ctx.request.body;
|
let userInfo = await ctx.helper.userInfo();
|
|
const connection: any = await this.dbWrite.connection;
|
let request = new sql.Request(connection.driver.master);
|
request.input("consignorTransfer_Id", body.id);
|
request.input("User_Id", userInfo.user_Id);
|
request.output("outMsg", sql.NVarChar(2000));
|
let result = await request.execute("sp_Storage_ConsignorTransfer_Confirm");
|
let outMsg = result.output.outMsg;
|
if (outMsg) {
|
this.info.result = false;
|
this.info.msg = "确认过户成功失败";
|
} else {
|
this.info.result = true;
|
this.info.msg = "确认过户成功";
|
}
|
ctx.body = this.info;
|
}
|
//#endregion
|
}
|