//#region
|
import BaseController from "./baseController";
|
import { Get, Post } from "egg-shell-decorators";
|
import { tran, rgv, srm, transList, siemensApi } from "../public/webServiceHelper";
|
import { TaskQueue } from "../entity/basicInfo/base/taskQueue";
|
import { Not, In, LessThanOrEqual, MoreThan } from "typeorm";
|
import moment = require("moment");
|
import { BasePlate } from "../entity/basicInfo/base/basePlate";
|
import { SaleOrder } from "../entity/outbound/sale/saleOrder";
|
import { BaseProductPlaceHolder } from "../entity/storage/storage/baseProductPlaceHolder";
|
import { BasePlateType } from "../entity/basicInfo/base/basePlateType";
|
import { BaseEquipment } from "../entity/basicInfo/base/baseEquipment";
|
import { ResultInfo } from "../public/commonInterface";
|
import { BaseEmptyEquipmentReturnList } from "../entity/outbound/sale/baseEmptyEquipmentReturnList";
|
import { BaseProductPosition } from "../entity/storage/product/baseProductPosition";
|
import { PurchaseShelve } from "../entity/inbound/purchase/purchaseShelve";
|
// import { execFile } from "child_process";
|
let isRunning = false; // 正在运行
|
let isRunning_doStep = false; // 正在运行
|
let startDate = new Date(); // 开始时间
|
let startDate_doStep = new Date(); // 开始时间
|
//#endregion
|
|
export default class TaskController extends BaseController {
|
//#region 自动化作业,检测输送是否有货start
|
/**
|
* 自动化作业,检测输送是否有货
|
*/
|
@Get()
|
public async start() {
|
let info = this.getInfo();
|
let userInfo = await this.ctx.helper.userInfo();
|
let orderInfo = await this.dbRead.findOne(PurchaseShelve, {
|
userProduct_Id: userInfo.userProduct_Id,
|
onShelveStatus: "待上架",
|
orderType: In(["入库上架"])
|
});
|
if (!orderInfo) {
|
let returnInfo = await this.dbRead.findOne(BaseEmptyEquipmentReturnList, {
|
returnStatus: "新建"
|
});
|
if (!returnInfo) {
|
let msg = "WMS无可用入库单" + moment(new Date()).format("YYYY-MM-DD HH:mm:ss");
|
console.log(msg);
|
return;
|
}
|
}
|
// WCS中间件url地址
|
tran.domainUrl = this.app.config.domainUrl;
|
rgv.domainUrl = this.app.config.domainUrl;
|
srm.domainUrl = this.app.config.domainUrl;
|
siemensApi.domainUrl = this.app.config.domainUrl;
|
|
if (isRunning) {
|
let msg = "检测是否有货接口堵塞中";
|
await this.ctx.service.wcs.saveMongoLog("入口输送线", msg);
|
// 防呆滞,超过一分钟重新执行
|
let endDate = moment(new Date());
|
let span = endDate.diff(startDate, "minute");
|
if (span >= 1) {
|
isRunning = false;
|
startDate = new Date();
|
}
|
info.result = false;
|
info.msg = msg;
|
this.ctx.body = info;
|
return;
|
}
|
let { ctx } = this;
|
info.result = true;
|
|
// 检测是否有新货入库
|
try {
|
isRunning = true;
|
await this.ctx.service.wcs.saveMongoLog("入口输送线", "开始执行hasTranGoods");
|
let hasGoods: any = await tran.hasTranGoods();
|
if (!hasGoods || !hasGoods.HasTranGoodsResult) {
|
await this.ctx.service.wcs.saveMongoLog("入口输送线", "WCS未开启");
|
return;
|
}
|
// goods数据结构:["0","0","0","0","1","0"]
|
let goods = hasGoods.HasTranGoodsResult.int;
|
let transIndex = 1;
|
await this.ctx.service.wcs.saveMongoLog("入口输送线", "goods list=" + JSON.stringify(goods));
|
// 入库口ID和输送线编号对应关系
|
for (let hasId of goods) {
|
hasId = Number(hasId);
|
if (hasId === 1) {
|
let item = transList.find(item => item.id === transIndex);
|
// 创建任务单
|
let info: any = await this.ctx.service.wcs.createTask(item.transId);
|
let msg = "goodsId=" + hasId + ",item.transId=" + item.transId + "创建任务结果:" + info.result;
|
await this.ctx.service.wcs.saveMongoLog("入口输送线", msg);
|
|
if (info.result) {
|
let taskInfo = info.data.taskInfo;
|
// 更新任务状态为等待尺寸校验是否通过
|
await this.ctx.service.wcs.updateTaskStatus(taskInfo, "任务创建成功", info.msg);
|
// 清除入口无货
|
let clearResult = await tran.clearTranGoods({
|
transId: item.transId
|
});
|
let msg = "goodsId=" + hasId + ",item.transId=" + item.transId + "清除hasGoods结果:" + JSON.stringify(clearResult);
|
await this.ctx.service.wcs.saveMongoLog("入口输送线", msg);
|
} else {
|
info.msg = info.msg;
|
let msg = "goodsId=" + hasId + ",item.transId=" + item.transId + "清除hasGoods失败," + JSON.stringify(info.msg);
|
await this.ctx.service.wcs.saveMongoLog("入口输送线", msg);
|
}
|
|
await this.ctx.helper.sleep(2000); // 延迟执行
|
}
|
transIndex++;
|
}
|
isRunning = false;
|
let msg = "结束执行hasTranGoods";
|
await this.ctx.service.wcs.saveMongoLog("入口输送线", msg);
|
} catch (error) {
|
isRunning = false;
|
|
info.result = false;
|
info.msg = error.message;
|
let msg = "执行hasTranGoods出错:" + error.message;
|
await this.ctx.service.wcs.saveMongoLog("入口输送线", msg);
|
}
|
|
// 设备检测,每5分钟检测一次
|
// try {
|
// let minute = moment(new Date()).minutes();
|
// if (minute % 5 === 0) {
|
// await this.checkDevice();
|
// }
|
// } catch (error) {}
|
let msg = "start结束," + moment(new Date()).format("YYYY-MM-DD HH:mm:ss");
|
await this.ctx.service.wcs.saveMongoLog("入口输送线", msg);
|
info.msg = msg;
|
ctx.body = info;
|
}
|
//#endregion
|
// public get userInfo(): Promise<LoginInfo> {
|
// return this.ctx.helper.userInfo();
|
// }
|
//拆盘任务
|
@Post()
|
public async callContainer() {
|
siemensApi.domainUrl = this.app.config.domainUrl;
|
let params = this.ctx.body;
|
siemensApi.callContainer(params);
|
}
|
//分拣确认
|
@Post()
|
public async sorting() {
|
let { ctx } = this;
|
siemensApi.domainUrl = this.app.config.domainUrl;
|
let plateCode = this.body.plateCode;
|
let creator = this.body.creator;
|
let percentage = this.body.percentage;
|
let detailList = this.body.detailList;
|
let result: any;
|
result = await siemensApi.sortingTask({
|
creator:creator,
|
plateCode: plateCode,
|
percentage: percentage,
|
detailList: detailList
|
});
|
var resultInfo = JSON.parse(result);
|
this.info.result = resultInfo.result;
|
this.info.msg = resultInfo.msg;
|
ctx.body = this.info;
|
}
|
//获取库存盘点
|
@Post()
|
public async GetTakeStock() {
|
let { ctx } = this;
|
siemensApi.domainUrl = this.app.config.domainUrl;
|
var params = this.ctx.body;
|
var paramss = JSON.stringify(params);
|
let result: any;
|
result = await siemensApi.TakeStock({
|
paramss
|
});
|
var resultInfo = JSON.parse(result);
|
if (resultInfo.status == 200) {
|
this.info.data = resultInfo.date;
|
this.info.data2 = resultInfo.allDate;
|
//this.info.data2[0].MateralName="数据待更新";
|
this.info.result = true;
|
this.info.countPrint = resultInfo.total;
|
this.info.statusCode = resultInfo.status;
|
} else {
|
this.info.data = [];
|
this.info.result = false;
|
this.info.countPrint = 1;
|
this.info.statusCode = resultInfo.status;
|
}
|
ctx.body = this.info;
|
}
|
@Post()
|
public async getLackList() {
|
let { ctx } = this;
|
siemensApi.domainUrl = this.app.config.domainUrl;
|
var paramss = {
|
lackOrderId: this.ctx.body.lackOrderId
|
};
|
// var paramss = JSON.stringify(params);
|
let result: any;
|
|
result = await siemensApi.getLackList({
|
paramss
|
});
|
if (result === "false") {
|
return (this.info.result = false);
|
}
|
var resultInfo = JSON.parse(result);
|
|
this.info.data = resultInfo.dataList;
|
this.info.statusCode = resultInfo.lackname;
|
this.info.result = true;
|
ctx.body = this.info;
|
}
|
//获取库存数据
|
@Post()
|
public async productStockInfo() {
|
let { ctx } = this;
|
siemensApi.domainUrl = this.app.config.domainUrl;
|
var params = this.ctx.body;
|
if (params.positionTypeValue == "") params.positionTypeValue = "0";
|
var paramss = JSON.stringify(params);
|
let result: any;
|
|
result = await siemensApi.productStock({
|
paramss
|
});
|
var resultInfo = JSON.parse(result);
|
|
this.info.data = resultInfo.date;
|
this.info.data2 = resultInfo.allDate;
|
this.info.result = true;
|
this.info.countPrint = resultInfo.total;
|
this.info.statusCode = resultInfo.status;
|
this.info.msg = resultInfo.roleDelete + "-" + resultInfo.roleModifi;
|
this.info.buttonAuth=resultInfo.buttonAuth;
|
ctx.body = this.info;
|
}
|
//修改库存数据
|
@Post()
|
public async updateProductStock() {
|
let { ctx } = this;
|
siemensApi.domainUrl = this.app.config.domainUrl;
|
var params = this.ctx.body.taskForm;
|
|
var paramss = JSON.stringify(params);
|
let result: any;
|
|
result = await siemensApi.updateProductStock({
|
paramss
|
});
|
var resultInfo = JSON.parse(result);
|
if (resultInfo.status == 200) {
|
this.info.result = true;
|
} else {
|
this.info.result = false;
|
this.info.msg=resultInfo.msg
|
}
|
ctx.body = this.info;
|
}
|
|
//修改库存数据
|
@Post()
|
public async emtypContainerOUtandIN() {
|
let { ctx } = this;
|
siemensApi.domainUrl = this.app.config.domainUrl;
|
var paramss = JSON.stringify(this.ctx.body);
|
let result: any;
|
result = await siemensApi.emtypContainerOUtandIN({
|
paramss
|
});
|
var resultInfo = JSON.parse(result);
|
if (resultInfo.status == 200) {
|
this.info.result = true;
|
} else {
|
this.info.result = false;
|
this.info.msg = resultInfo.msg;
|
}
|
ctx.body = this.info;
|
}
|
//查询库存
|
@Post()
|
public async findProductStock() {
|
let { ctx } = this;
|
siemensApi.domainUrl = this.app.config.domainUrl;
|
let result: any;
|
var params = this.ctx.body;
|
var par = JSON.stringify(params);
|
result = await siemensApi.findProductStock({
|
par
|
});
|
var resultInfo = JSON.parse(result);
|
this.info.data = resultInfo.date;
|
this.info.data2 = resultInfo.allDate;
|
this.info.result = true;
|
this.info.countPrint = resultInfo.total;
|
this.info.statusCode = resultInfo.status;
|
ctx.body = this.info;
|
}
|
//查询过期库存预警
|
@Post()
|
public async findOldLibraryEarlyWarning() {
|
let { ctx } = this;
|
siemensApi.domainUrl = this.app.config.domainUrl;
|
let result: any;
|
var params = this.ctx.body;
|
var par = JSON.stringify(params);
|
result = await siemensApi.findOldLibraryEarlyWarning({
|
par
|
});
|
var resultInfo = JSON.parse(result);
|
this.info.data = resultInfo.date;
|
this.info.data2 = resultInfo.allDate;
|
this.info.result = true;
|
this.info.countPrint = resultInfo.total;
|
this.info.statusCode = resultInfo.status;
|
this.info.buttonAuth=resultInfo.buttonAuth;
|
ctx.body = this.info;
|
}
|
|
// ly 维护库存预警天数
|
@Post()
|
public async UpdateStoreWarningDays() {
|
let { ctx } = this;
|
siemensApi.domainUrl = this.app.config.domainUrl;
|
let result: any;
|
var params = this.ctx.body;
|
var par = JSON.stringify(params);
|
//debugger
|
result = await siemensApi.UpdateStoreWarningDays({
|
par
|
});
|
var resultInfo = JSON.parse(result);
|
this.info.result = resultInfo.result;
|
this.info.data = resultInfo.resData;
|
this.info.msg=resultInfo.resMsg;
|
ctx.body = this.info;
|
}
|
//ly 获取库存预警天数
|
@Post()
|
public async GetStoreWarningDays() {
|
let { ctx } = this;
|
siemensApi.domainUrl = this.app.config.domainUrl;
|
let result: any;
|
var params = this.ctx.body;
|
var par = JSON.stringify(params);
|
//debugger
|
result = await siemensApi.GetStoreWarningDays({
|
par
|
});
|
if(result){
|
var resultInfo = result;
|
if(typeof(result) == 'string'){
|
resultInfo = JSON.parse(result);
|
}
|
this.info.result = resultInfo.result;
|
this.info.data = resultInfo.resData;
|
this.info.msg=resultInfo.resMsg;
|
ctx.body = this.info;
|
}
|
}
|
|
|
|
//查询反馈给SAP数据的记录 【EditBy shaocx,2022-02-01】
|
@Post()
|
public async findSendToSapData() {
|
let { ctx } = this;
|
siemensApi.domainUrl = this.app.config.domainUrl;
|
let result: any;
|
var params = this.ctx.body;
|
var par = JSON.stringify(params);
|
result = await siemensApi.findSendToSapData({
|
par
|
});
|
var resultInfo = JSON.parse(result);
|
this.info.data = resultInfo.date;
|
this.info.data2 = resultInfo.allDate;
|
this.info.result = true;
|
this.info.countPrint = resultInfo.total;
|
this.info.statusCode = resultInfo.status;
|
ctx.body = this.info;
|
}
|
//查询反馈给SAP数据失败的记录 【EditBy shaocx,2022-02-01】
|
@Post()
|
public async findSendToSapFailData() {
|
let { ctx } = this;
|
siemensApi.domainUrl = this.app.config.domainUrl;
|
let result: any;
|
var params = this.ctx.body;
|
var par = JSON.stringify(params);
|
result = await siemensApi.findSendToSapFailData({
|
par
|
});
|
var resultInfo = JSON.parse(result);
|
this.info.data = resultInfo.date;
|
this.info.data2 = resultInfo.allDate;
|
this.info.result = true;
|
this.info.countPrint = resultInfo.total;
|
this.info.statusCode = resultInfo.status;
|
ctx.body = this.info;
|
}
|
|
//获取库位统计
|
|
@Post()
|
public async getPositionTotal() {
|
let { ctx } = this;
|
siemensApi.domainUrl = this.app.config.domainUrl;
|
let result: any;
|
var param = "";
|
result = await siemensApi.getPositionTotal({
|
param
|
});
|
var resultInfo = JSON.parse(result);
|
if (resultInfo.status == 200) {
|
this.info.statusCode = 200;
|
this.info.data = resultInfo.date;
|
} else {
|
this.info.statusCode = 400;
|
}
|
|
ctx.body = this.info;
|
}
|
|
//查询设备报警信息
|
@Post()
|
public async findDeviceAlarm() {
|
let { ctx } = this;
|
siemensApi.domainUrl = this.app.config.domainUrl;
|
let result: any;
|
var params = this.ctx.body;
|
var par = JSON.stringify(params);
|
result = await siemensApi.findDeviceAlarm({
|
par
|
});
|
var resultInfo = JSON.parse(result);
|
if (resultInfo.status == 200) {
|
this.info.data = resultInfo.date;
|
this.info.data2 = resultInfo.allDate;//增加 【EditBy shaocx,2022-03-07】
|
this.info.result = true;
|
this.info.countPrint = resultInfo.total;
|
this.info.statusCode = resultInfo.status;
|
} else {
|
this.info.result = false;
|
}
|
ctx.body = this.info;
|
}
|
//查询设备报警信息统计
|
@Post()
|
public async findDeviceAlarms() {
|
let { ctx } = this;
|
siemensApi.domainUrl = this.app.config.domainUrl;
|
let result: any;
|
var par = this.ctx.body.month;
|
result = await siemensApi.findDeviceAlarms({
|
par
|
});
|
var resultInfo = JSON.parse(result);
|
if (resultInfo.status == 200) {
|
this.info.data = resultInfo.date;
|
this.info.state = "200";
|
} else {
|
this.info.state = "200";
|
}
|
ctx.body = this.info;
|
}
|
//2d动画
|
@Post()
|
public async getPosition() {
|
let { ctx } = this;
|
siemensApi.domainUrl = this.app.config.domainUrl;
|
let result: any;
|
var par = "";
|
|
result = await siemensApi.getPosition({
|
par
|
});
|
//var resultInfo = JSON.parse(result);
|
this.info.data = result.int;
|
//this.info.data2 = resultInfo.allDate;
|
this.info.result = true;
|
//this.info.countPrint = resultInfo.total;
|
//this.info.statusCode = resultInfo.status;
|
ctx.body = this.info;
|
}
|
|
//删除库存数据
|
@Post()
|
public async deleteProductStock() {
|
let { ctx } = this;
|
siemensApi.domainUrl = this.app.config.domainUrl;
|
var _id = this.ctx.body.id;
|
var _userName= this.ctx.body.userName;
|
|
var params = {
|
id:_id,
|
userName:_userName
|
};
|
|
let result: any;
|
|
result = await siemensApi.deleteProductStock(
|
params
|
);
|
var resultInfo = JSON.parse(result);
|
if (resultInfo.status == 200) {
|
this.info.result = true;
|
} else {
|
this.info.result = false;
|
}
|
ctx.body = this.info;
|
}
|
//按单收货
|
@Post()
|
public async receiptConvert() {
|
let { ctx } = this;
|
siemensApi.domainUrl = this.app.config.domainUrl;
|
var param = this.ctx.body;
|
let result: any;
|
|
result = await siemensApi.receiptConvert({
|
param
|
});
|
var resultInfo = JSON.parse(result);
|
if (resultInfo.result === true) {
|
this.info.result = true;
|
} else {
|
this.info.result = false;
|
}
|
this.info.msg = resultInfo.msg;
|
ctx.body = this.info;
|
}
|
//组盘
|
@Post()
|
public async bindContiner() {
|
let { ctx } = this;
|
siemensApi.domainUrl = this.app.config.domainUrl;
|
var param = this.ctx.body;
|
let result: any;
|
|
result = await siemensApi.bindContiner({
|
param
|
});
|
var resultInfo = JSON.parse(result);
|
if (resultInfo.result === true) {
|
this.info.result = true;
|
} else {
|
this.info.result = false;
|
}
|
this.info.msg = resultInfo.msg;
|
ctx.body = this.info;
|
}
|
//通用验证方法
|
@Post()
|
public async validateDataCommon() {
|
let { ctx } = this;
|
siemensApi.domainUrl = this.app.config.domainUrl;
|
var param = this.ctx.body;
|
let result: any;
|
|
result = await siemensApi.validateDataCommon({
|
param
|
});
|
var resultInfo = JSON.parse(result);
|
if (resultInfo.result === true) {
|
this.info.result = true;
|
} else {
|
this.info.result = false;
|
}
|
this.info.msg = resultInfo.msg;
|
ctx.body = this.info;
|
}
|
//移库
|
@Post()
|
public async moveStock() {
|
let { ctx } = this;
|
siemensApi.domainUrl = this.app.config.domainUrl;
|
var par = this.ctx.body;
|
|
let result: any;
|
|
result = await siemensApi.moveStock({
|
par
|
});
|
var resultInfo = JSON.parse(result);
|
if (resultInfo.status == 200) {
|
this.info.result = true;
|
} else {
|
this.info.result = false;
|
}
|
ctx.body = this.info;
|
}
|
//分页查询 闲时移库 [EditBy shaocx,2022-09-13]
|
@Post()
|
public async QueryPageFreeTimeMoveLocationTask() {
|
|
let { ctx } = this;
|
siemensApi.domainUrl = this.app.config.domainUrl;
|
let result: any;
|
var params = this.ctx.body;
|
var par = JSON.stringify(params);
|
result = await siemensApi.QueryPageFreeTimeMoveLocationTask({
|
par
|
});
|
var resultInfo = JSON.parse(result);
|
|
if (resultInfo.status == 200) {
|
this.info.data = resultInfo.date;
|
this.info.data2 = resultInfo.allDate;//增加 【EditBy shaocx,2022-03-07】
|
this.info.result = true;
|
this.info.countPrint = resultInfo.total;
|
this.info.statusCode = resultInfo.status;
|
} else {
|
this.info.result = false;
|
}
|
ctx.body = this.info;
|
}
|
//分页查询 闲时移库明细 [EditBy shaocx,2022-09-13]
|
@Post()
|
public async QueryPageFreeTimeMoveLocationTaskDetails() {
|
|
let { ctx } = this;
|
siemensApi.domainUrl = this.app.config.domainUrl;
|
let result: any;
|
var params = this.ctx.body;
|
var par = JSON.stringify(params);
|
result = await siemensApi.QueryPageFreeTimeMoveLocationTaskDetails({
|
par
|
});
|
var resultInfo = JSON.parse(result);
|
|
if (resultInfo.status == 200) {
|
this.info.data = resultInfo.date;
|
//this.info.data2 = resultInfo.allDate;//增加 【EditBy shaocx,2022-03-07】
|
this.info.result = true;
|
this.info.countPrint = resultInfo.total;
|
this.info.statusCode = resultInfo.status;
|
} else {
|
this.info.result = false;
|
}
|
ctx.body = this.info;
|
}
|
//新增 闲时移库 [EditBy shaocx,2022-09-13]
|
@Post()
|
public async AddFreeTimeMoveLocationTask() {
|
let { ctx } = this;
|
siemensApi.domainUrl = this.app.config.domainUrl;
|
|
let result: any;
|
var params = this.ctx.body;
|
var par = JSON.stringify(params);
|
//debugger
|
|
result = await siemensApi.AddFreeTimeMoveLocationTask({
|
par
|
});
|
var resultInfo = JSON.parse(result);
|
this.info.result = resultInfo.result;
|
this.info.data = resultInfo.resData;
|
this.info.msg=resultInfo.resMsg;
|
ctx.body = this.info;
|
}
|
//编辑 闲时移库 [EditBy shaocx,2022-09-13]
|
@Post()
|
public async UpdateFreeTimeMoveLocationTask() {
|
let { ctx } = this;
|
siemensApi.domainUrl = this.app.config.domainUrl;
|
|
let result: any;
|
var params = this.ctx.body;
|
var par = JSON.stringify(params);
|
//debugger
|
result = await siemensApi.UpdateFreeTimeMoveLocationTask({
|
par
|
});
|
var resultInfo = JSON.parse(result);
|
this.info.result = resultInfo.result;
|
this.info.data = resultInfo.resData;
|
this.info.msg=resultInfo.resMsg;
|
ctx.body = this.info;
|
}
|
//执行 闲时移库 [EditBy shaocx,2022-09-13]
|
@Post()
|
public async ExcuteFreeTimeMoveLocationTask() {
|
let { ctx } = this;
|
siemensApi.domainUrl = this.app.config.domainUrl;
|
|
let result: any;
|
var params = this.ctx.body;
|
var par = JSON.stringify(params);
|
//debugger
|
|
result = await siemensApi.ExcuteFreeTimeMoveLocationTask({
|
par
|
});
|
var resultInfo = JSON.parse(result);
|
this.info.result = resultInfo.result;
|
this.info.data = resultInfo.resData;
|
this.info.msg=resultInfo.resMsg;
|
ctx.body = this.info;
|
}
|
//取消 闲时移库 [EditBy shaocx,2022-09-13]
|
@Post()
|
public async CancelFreeTimeMoveLocationTask() {
|
let { ctx } = this;
|
siemensApi.domainUrl = this.app.config.domainUrl;
|
|
let result: any;
|
var params = this.ctx.body;
|
var par = JSON.stringify(params);
|
//debugger
|
|
result = await siemensApi.CancelFreeTimeMoveLocationTask({
|
par
|
});
|
var resultInfo = JSON.parse(result);
|
this.info.result = resultInfo.result;
|
this.info.data = resultInfo.resData;
|
this.info.msg=resultInfo.resMsg;
|
ctx.body = this.info;
|
}
|
//人工结束 闲时移库 [EditBy shaocx,2022-09-13]
|
@Post()
|
public async PersonStopFreeTimeMoveLocationTask() {
|
let { ctx } = this;
|
siemensApi.domainUrl = this.app.config.domainUrl;
|
|
let result: any;
|
var params = this.ctx.body;
|
var par = JSON.stringify(params);
|
//debugger
|
result = await siemensApi.PersonStopFreeTimeMoveLocationTask({
|
par
|
});
|
var resultInfo = JSON.parse(result);
|
this.info.result = resultInfo.result;
|
this.info.data = resultInfo.resData;
|
this.info.msg=resultInfo.resMsg;
|
ctx.body = this.info;
|
}
|
//权限
|
//查询 按钮权限 [EditBy shaocx,2022-09-15]
|
@Post()
|
public async QueryButtonAuth() {
|
let { ctx } = this;
|
siemensApi.domainUrl = this.app.config.domainUrl;
|
|
let result: any;
|
var params = this.ctx.body;
|
var par = JSON.stringify(params);
|
//debugger
|
result = await siemensApi.QueryButtonAuth({
|
par
|
});
|
var resultInfo = JSON.parse(result);
|
this.info.result = resultInfo.result;
|
this.info.data = resultInfo.resData;
|
this.info.msg=resultInfo.resMsg;
|
ctx.body = this.info;
|
}
|
//重新打印标签 [EditBy shaocx,2022-09-13]
|
@Post()
|
public async RePrintBarCode() {
|
let { ctx } = this;
|
siemensApi.domainUrl = this.app.config.domainUrl;
|
|
let result: any;
|
var params = this.ctx.body;
|
var par = JSON.stringify(params);
|
//debugger
|
|
result = await siemensApi.RePrintBarCode({
|
par
|
});
|
var resultInfo = JSON.parse(result);
|
this.info.result = resultInfo.result;
|
this.info.data = resultInfo.resData;
|
this.info.msg=resultInfo.resMsg;
|
ctx.body = this.info;
|
}
|
|
//分页查询 按单出库记录 [EditBy shaocx,2022-09-13]
|
@Post()
|
public async QueryPageSale_Order_History() {
|
|
let { ctx } = this;
|
siemensApi.domainUrl = this.app.config.domainUrl;
|
let result: any;
|
var params = this.ctx.body;
|
var par = JSON.stringify(params);
|
result = await siemensApi.QueryPageSale_Order_History({
|
par
|
});
|
var resultInfo = JSON.parse(result);
|
|
if (resultInfo.status == 200) {
|
this.info.data = resultInfo.date;
|
this.info.data2 = resultInfo.allDate;//增加 【EditBy shaocx,2022-03-07】
|
this.info.result = true;
|
this.info.countPrint = resultInfo.total;
|
this.info.statusCode = resultInfo.status;
|
} else {
|
this.info.result = false;
|
}
|
ctx.body = this.info;
|
}
|
//分页查询 按单出库记录明细 [EditBy shaocx,2022-09-13]
|
@Post()
|
public async QueryPageSale_Order_HistoryDetails() {
|
|
let { ctx } = this;
|
siemensApi.domainUrl = this.app.config.domainUrl;
|
let result: any;
|
var params = this.ctx.body;
|
var par = JSON.stringify(params);
|
result = await siemensApi.QueryPageSale_Order_HistoryDetails({
|
par
|
});
|
var resultInfo = JSON.parse(result);
|
|
if (resultInfo.status == 200) {
|
this.info.data = resultInfo.date;
|
//this.info.data2 = resultInfo.allDate;//增加 【EditBy shaocx,2022-03-07】
|
this.info.result = true;
|
this.info.countPrint = resultInfo.total;
|
this.info.statusCode = resultInfo.status;
|
} else {
|
this.info.result = false;
|
}
|
ctx.body = this.info;
|
}
|
//获取出入库记录
|
@Post()
|
public async outInTaskList() {
|
let { ctx } = this;
|
siemensApi.domainUrl = this.app.config.domainUrl;
|
let result: any;
|
var params = this.ctx.body;
|
var par = JSON.stringify(params);
|
result = await siemensApi.outInTaskList({
|
par
|
});
|
var resultInfo = JSON.parse(result.outInTaskListResult);
|
this.info.data = resultInfo.date;
|
this.info.data2 = resultInfo.allDate;
|
this.info.result = true;
|
this.info.countPrint = resultInfo.total;
|
this.info.statusCode = resultInfo.status;
|
ctx.body = this.info;
|
}
|
|
//获取设备状态信息
|
@Post()
|
public async GetDeviceInfo() {
|
let { ctx } = this;
|
siemensApi.domainUrl = this.app.config.domainUrl;
|
var par = this.ctx.body;
|
let result: any;
|
result = await siemensApi.getDevice(par);
|
var resultInfo = JSON.parse(result);
|
this.info.data = resultInfo;
|
this.info.result = true;
|
ctx.body = this.info;
|
}
|
//获取出库任务单
|
@Post()
|
public async getOutTaskList() {
|
let { ctx } = this;
|
siemensApi.domainUrl = this.app.config.domainUrl;
|
let result: any;
|
result = await siemensApi.getOutTask();
|
var resultInfo = JSON.parse(result);
|
|
this.info.data = resultInfo;
|
// this.info.data2 = resultInfo.allDate;
|
this.info.result = true;
|
// this.info.countPrint = resultInfo.total;
|
|
ctx.body = this.info;
|
}
|
//获取入库任务表
|
@Post()
|
public async getEnterTaskList() {
|
let { ctx } = this;
|
siemensApi.domainUrl = this.app.config.domainUrl;
|
let result: any;
|
result = await siemensApi.getEnterTask();
|
var resultInfo = JSON.parse(result);
|
|
this.info.data = resultInfo;
|
// this.info.data2 = resultInfo.allDate;
|
this.info.result = true;
|
// this.info.countPrint = resultInfo.total;
|
|
ctx.body = this.info;
|
}
|
|
//复位拆叠盘设备状态,()
|
@Post()
|
public async resetDeviceStatus() {
|
let { ctx } = this;
|
siemensApi.domainUrl = this.app.config.domainUrl;
|
let result: any;
|
var params = {
|
voucher: this.ctx.body
|
};
|
result = await siemensApi.resetChaiDieDeviceStatus({
|
params
|
});
|
var resultInfo = result.resetChaiDieDeviceResult;
|
|
this.info.data = resultInfo;
|
if (resultInfo == "复位成功") {
|
this.info.result = true;
|
} else {
|
this.info.result = false;
|
}
|
// this.info.countPrint = resultInfo.total;
|
|
ctx.body = this.info;
|
}
|
///删除wcs任务
|
@Post()
|
public async deleteTask() {
|
let { ctx } = this;
|
siemensApi.domainUrl = this.app.config.domainUrl;
|
let result: any;
|
var params = {
|
voucher: this.ctx.body
|
};
|
result = await siemensApi.deleteTask({
|
params
|
});
|
var resultInfo = result.deleteTaskResult;
|
|
// this.info.data = resultInfo;
|
if (resultInfo == "删除成功") {
|
this.info.result = true;
|
this.info.msg = resultInfo;
|
} else {
|
this.info.result = false;
|
this.info.msg = resultInfo;
|
}
|
// this.info.countPrint = resultInfo.total;
|
|
ctx.body = this.info;
|
}
|
@Post()
|
//sap撤销
|
public async reverser() {
|
let { ctx } = this;
|
siemensApi.domainUrl = this.app.config.domainUrl;
|
let result: any;
|
|
var params = {
|
voucher: this.ctx.body
|
};
|
result = await siemensApi.sendReverser({
|
params
|
});
|
var resultInfo = result.reverserResult;
|
this.info.data = resultInfo;
|
// this.info.data2 = resultInfo.allDate;
|
this.info.result = true;
|
// this.info.countPrint = resultInfo.total;
|
|
ctx.body = this.info;
|
}
|
@Post()
|
//缺料表
|
public async lackAnalysis() {
|
let { ctx } = this;
|
siemensApi.domainUrl = this.app.config.domainUrl;
|
let result: any;
|
|
var params = {
|
voucher: this.ctx.body
|
};
|
result = await siemensApi.lackAnalysis({
|
params
|
});
|
var resultInfo = result.reverserResult;
|
this.info.data = resultInfo;
|
// this.info.data2 = resultInfo.allDate;
|
this.info.result = true;
|
// this.info.countPrint = resultInfo.total;
|
|
ctx.body = this.info;
|
}
|
@Post()
|
//清除库位信息和状态
|
public async stockDelete() {
|
let { ctx } = this;
|
siemensApi.domainUrl = this.app.config.domainUrl;
|
let result: any;
|
|
var params = this.ctx.body;
|
result = await siemensApi.stockDelete({
|
params
|
});
|
var resultInfo = result.unlockResult;
|
this.info.data = resultInfo;
|
// this.info.data2 = resultInfo.allDate;
|
if (resultInfo === "解锁成功") {
|
this.info.result = true;
|
} else {
|
this.info.result = false;
|
}
|
|
// this.info.countPrint = resultInfo.total;
|
|
ctx.body = this.info;
|
}
|
///
|
//获取库存数据
|
@Post()
|
public async findMaterial() {
|
let { ctx } = this;
|
siemensApi.domainUrl = this.app.config.domainUrl;
|
var paramss = JSON.stringify(this.ctx.body);
|
let result: any;
|
result = await siemensApi.findMaterial({
|
paramss
|
});
|
var resultInfo = JSON.parse(result);
|
this.info.data = resultInfo.date;
|
this.info.data2 = resultInfo.allDate;
|
this.info.result = true;
|
this.info.countPrint = resultInfo.total;
|
this.info.statusCode = resultInfo.status;
|
ctx.body = this.info;
|
}
|
|
//获取库存数据
|
@Post()
|
public async MaterialOperation() {
|
let { ctx } = this;
|
siemensApi.domainUrl = this.app.config.domainUrl;
|
|
var params = this.ctx.body;
|
if (params.OperationValue === 1) {
|
delete params.taskForm.Product_Id;
|
}
|
var paramss = JSON.stringify(params);
|
let result: any;
|
result = await siemensApi.MaterialOperation({
|
paramss
|
});
|
var resultInfo = JSON.parse(result);
|
this.info.msg = resultInfo.msg;
|
this.info.result = resultInfo.result;
|
ctx.body = this.info;
|
}
|
// 拼盘
|
@Post()
|
public async productSend() {
|
let { ctx } = this;
|
siemensApi.domainUrl = this.app.config.domainUrl;
|
let detailList = this.body.detailList;
|
let creator = this.body.creator;
|
// let postition = JSON.parse(this.body.detailList[0]);
|
let result: any;
|
result = await siemensApi.madeDish({
|
creator:creator,
|
detailList: detailList
|
});
|
debugger
|
var resultInfo = JSON.parse(result);
|
this.info.msg = resultInfo.msg;
|
this.info.result = resultInfo.result;
|
ctx.body = this.info;
|
}
|
|
//#region 步骤执行计划 doStep
|
/**
|
* 步骤执行计划 doStep
|
*/
|
@Get()
|
public async doStep() {
|
let info = this.getInfo();
|
let clear = this.ctx.query.clear;
|
// 手动清掉
|
if (clear) {
|
isRunning = false;
|
isRunning_doStep = false;
|
}
|
|
if (isRunning_doStep) {
|
let msg = "doStep服务堵塞中";
|
await this.ctx.service.wcs.saveMongoLog("执行任务", msg);
|
// 防呆滞,超过一分钟重新执行
|
let endDate = moment(new Date());
|
let span = endDate.diff(startDate_doStep, "minute");
|
if (span >= 1) {
|
isRunning_doStep = false;
|
startDate_doStep = new Date();
|
}
|
info.result = false;
|
info.msg = msg;
|
this.ctx.body = info;
|
return;
|
}
|
|
isRunning_doStep = true;
|
let { ctx } = this;
|
let taskList = await this.dbRead.find(TaskQueue, {
|
where: {
|
taskStatus: Not(In(["任务完成"])),
|
doCount: LessThanOrEqual(2000)
|
// isDoing: 0
|
},
|
take: 10,
|
order: {
|
doCount: "ASC"
|
}
|
});
|
let msg = "执行任务数:" + taskList.length;
|
await this.ctx.service.wcs.saveMongoLog("计划任务", msg);
|
let taskIndex = 0;
|
for (let taskInfo of taskList) {
|
await this.dbWrite.update(TaskQueue, taskInfo.task_Id, {
|
isDoing: 1
|
});
|
try {
|
if (taskIndex > 0) {
|
await this.ctx.helper.sleep(1000);
|
}
|
taskIndex++;
|
let statusList = ["任务创建成功", "任务下发失败", "分配货位失败", "目标货位未分配", "任务进行中", "等待移库任务完成", "未分配到库存"];
|
if (statusList.indexOf(taskInfo.taskStatus) >= 0) {
|
info = await this.sendTask(taskInfo);
|
let msg = `${taskInfo.billCode},sendTask任务发送结果:result=` + info.result + ",msg=" + info.msg;
|
await this.ctx.service.wcs.saveMongoLog("计划任务", msg, taskInfo);
|
// 记录任务执行次数,递增加一次
|
this.dbWrite.increment(
|
TaskQueue,
|
{
|
task_Id: taskInfo.task_Id
|
},
|
"doCount",
|
1
|
);
|
} else if (["任务下发成功", "任务完成失败", "任务完成中"].indexOf(taskInfo.taskStatus) >= 0) {
|
info = await this.taskFinish(taskInfo);
|
let msg = `${taskInfo.billCode},taskFinish任务发送结果:result=` + info.result + ",msg=" + info.msg;
|
await this.ctx.service.wcs.saveMongoLog("计划任务", msg, taskInfo);
|
// 记录任务执行次数,递增加一次
|
this.dbWrite.increment(
|
TaskQueue,
|
{
|
task_Id: taskInfo.task_Id
|
},
|
"doCount",
|
1
|
);
|
}
|
} catch (error) {
|
let msg = "执行doStep出错:" + error.message;
|
await this.ctx.service.wcs.saveMongoLog("计划任务", msg, taskInfo);
|
}
|
await this.dbWrite.update(TaskQueue, taskInfo.task_Id, {
|
isDoing: 0
|
});
|
}
|
isRunning_doStep = false;
|
ctx.body = info;
|
}
|
//#endregion
|
|
//#region 发送任务 sendTask
|
/**
|
* 发送任务 sendTask
|
*/
|
private async sendTask(taskInfo: TaskQueue) {
|
let info = this.getInfo();
|
try {
|
let msg = "开始执行任务:" + taskInfo.taskType + taskInfo.billCode;
|
await this.ctx.service.wcs.saveMongoLog("计划任务", msg, taskInfo);
|
if (["上架单", "空器具上架"].indexOf(taskInfo.taskType) >= 0) {
|
let spInfo: any = await this.ctx.service.wcs.sortPosition(taskInfo);
|
if (!spInfo.result) {
|
// 货位不存在
|
if (spInfo.statusCode === 330) {
|
await this.ctx.service.wcs.updateTaskStatus(taskInfo, "分配货位失败", null, spInfo.msg);
|
}
|
// 分配货位失败
|
await this.ctx.service.wcs.saveLog(taskInfo, spInfo.msg);
|
return spInfo;
|
}
|
} else if (taskInfo.taskType === "移库单") {
|
let spInfo: any = {
|
result: false
|
};
|
// 单实例
|
if (!this.ctx.service.wcs.isTransferSorting) {
|
this.ctx.service.wcs.isTransferSorting = true;
|
spInfo = await this.ctx.service.wcs.transferSortPosition(taskInfo);
|
this.ctx.service.wcs.isTransferSorting = false;
|
} else {
|
spInfo = {
|
result: false,
|
msg: "其他单据正在分配移库货位,请稍等..."
|
};
|
}
|
if (!spInfo.result) {
|
// 分配货位失败
|
await this.ctx.service.wcs.saveLog(taskInfo, spInfo.msg);
|
return spInfo;
|
}
|
}
|
let taskType = 1; // 默认值
|
let outType = 0;
|
let sourcePlace = null;
|
let toPlace = null;
|
let palletType = "";
|
if (["上架单", "空器具上架"].indexOf(taskInfo.taskType) >= 0) {
|
let plateTypeInfo = await this.dbRead.findOne(BasePlateType, {
|
plateType: taskInfo.plateType
|
});
|
palletType = plateTypeInfo.palletType;
|
taskType = 1;
|
outType = 0;
|
sourcePlace = taskInfo.tranCode; // 起始位置
|
toPlace = taskInfo.toPositionName; // 目标位置
|
if (!taskInfo.toPositionName) {
|
await this.ctx.service.wcs.updateTaskStatus(taskInfo, "目标货位未分配");
|
info.result = false;
|
info.msg = `${taskInfo.billCode}目标货位未分配${taskInfo.toPositionName}`;
|
return info;
|
}
|
// 校验目标货位是否存在库存,放置满入
|
let ppInfo = await this.dbRead.findOne(BaseProductPosition, {
|
positionName: taskInfo.toPositionName,
|
productStorage: MoreThan(0)
|
});
|
if (ppInfo) {
|
await this.ctx.service.wcs.updateTaskStatus(taskInfo, "目标货位存在库存");
|
info.result = false;
|
info.msg = `${taskInfo.billCode}目标货位存在库存${taskInfo.toPositionName}`;
|
return info;
|
}
|
// 判断货位是否已经重复分配
|
let existTask = await this.dbRead.findOne(TaskQueue, {
|
toPositionName: taskInfo.toPositionName,
|
task_Id: Not(taskInfo.task_Id),
|
taskStatus: Not("任务完成")
|
});
|
if (existTask) {
|
await this.ctx.service.wcs.updateTaskStatus(taskInfo, "目标货位重复分配");
|
info.result = false;
|
info.msg = `${taskInfo.billCode}目标货位重复分配${taskInfo.toPositionName}`;
|
// 清空当前目标货位,重新分配
|
await this.dbWrite.update(TaskQueue, taskInfo.task_Id, {
|
toPositionName: null
|
});
|
return info;
|
}
|
} else if (taskInfo.taskType === "出库单") {
|
// 如果存在移库任务,判断移库任务是否完成
|
if (taskInfo.relationTask_Id) {
|
let moveTaskInfo = await this.dbRead.findOne(TaskQueue, taskInfo.relationTask_Id);
|
if (moveTaskInfo.taskStatus != "任务完成") {
|
await this.ctx.service.wcs.updateTaskStatus(taskInfo, "等待移库任务完成");
|
info.result = false;
|
info.msg = "移库任务未完成";
|
return info;
|
}
|
}
|
let orderInfo = await this.dbRead.findOne(SaleOrder, taskInfo.bill_Id);
|
if (!orderInfo.plateCode) {
|
info.result = false;
|
info.msg = `${taskInfo.billCode}未分配到器具编号`;
|
return info;
|
}
|
let plateInfo = await this.dbRead.findOne(BasePlate, {
|
plateCode: orderInfo.plateCode
|
});
|
let plateTypeInfo = await this.dbRead.findOne(BasePlateType, {
|
plateType: plateInfo.plateType
|
});
|
palletType = plateTypeInfo.palletType;
|
// 校验库存知否存在
|
let holderInfo = await this.dbRead.findOne(BaseProductPlaceHolder, {
|
mainID: orderInfo.order_Id,
|
className: "销售订单"
|
});
|
if (!holderInfo) {
|
await this.ctx.service.wcs.updateTaskStatus(taskInfo, "未分配到库存");
|
info.result = false;
|
info.msg = `${taskInfo.billCode}未分配到库存`;
|
return info;
|
}
|
if (holderInfo.productPosition_Id !== taskInfo.productPosition_Id) {
|
await this.ctx.service.wcs.updateTaskStatus(taskInfo, "任务库存不正确");
|
info.result = false;
|
info.msg = `${taskInfo.billCode}库存分配不正确`;
|
return info;
|
}
|
// 再次核验任务中库存是否有库存
|
holderInfo = await this.dbRead.findOne(BaseProductPlaceHolder, {
|
productPosition_Id: taskInfo.productPosition_Id,
|
mainID: orderInfo.order_Id,
|
className: "销售订单"
|
});
|
if (!holderInfo) {
|
await this.ctx.service.wcs.updateTaskStatus(taskInfo, "库存分配不正确");
|
info.result = false;
|
info.msg = `${taskInfo.billCode}库存分配不正确`;
|
return info;
|
}
|
taskType = 2;
|
outType = Number(orderInfo.orderExit) || 0;
|
sourcePlace = holderInfo.positionName || "";
|
toPlace = orderInfo.outTransId || "";
|
} else if (taskInfo.taskType === "空器具下架") {
|
// 如果存在移库任务,判断移库任务是否完成
|
if (taskInfo.relationTask_Id) {
|
let moveTaskInfo = await this.dbRead.findOne(TaskQueue, taskInfo.relationTask_Id);
|
if (moveTaskInfo.taskStatus != "任务完成") {
|
await this.ctx.service.wcs.updateTaskStatus(taskInfo, "等待移库任务完成");
|
info.result = false;
|
info.msg = "移库任务未完成";
|
return info;
|
}
|
}
|
if (!taskInfo.plateCode) {
|
info.result = false;
|
info.msg = `${taskInfo.billCode}未分配到器具编号`;
|
return info;
|
}
|
let plateInfo = await this.dbRead.findOne(BasePlate, {
|
plateCode: taskInfo.plateCode
|
});
|
let plateTypeInfo = await this.dbRead.findOne(BasePlateType, {
|
plateType: plateInfo.plateType
|
});
|
palletType = plateTypeInfo.palletType;
|
taskType = 2;
|
outType = 0;
|
sourcePlace = taskInfo.fromPositionName || "";
|
toPlace = taskInfo.toPositionName || "";
|
} else if (taskInfo.taskType === "移库单") {
|
let orderInfo = await this.dbRead.findOne(SaleOrder, taskInfo.bill_Id);
|
let plateInfo = await this.dbRead.findOne(BasePlate, {
|
plateCode: orderInfo.plateCode
|
});
|
let plateTypeInfo = await this.dbRead.findOne(BasePlateType, {
|
plateType: plateInfo.plateType
|
});
|
palletType = plateTypeInfo.palletType;
|
taskType = 3;
|
outType = Number(orderInfo.orderExit) || 0;
|
sourcePlace = taskInfo.fromPositionName;
|
toPlace = taskInfo.toPositionName;
|
}
|
// WCS中间件url地址
|
srm.domainUrl = this.app.config.domainUrl;
|
let params = {
|
palletType: palletType, // 器具种类
|
sourcePlace: sourcePlace,
|
toPlace: toPlace,
|
taskId: taskInfo.task_Id,
|
taskType: taskType, //1=入库,2=出库,3=移库
|
outType: outType
|
};
|
let result: any;
|
// 模拟数据
|
if (this.app.config.isVirtual) {
|
result = {
|
SendTaskResult: {
|
result: true
|
}
|
};
|
} else {
|
result = await srm.sendTask(params);
|
}
|
|
if (result.result === false) {
|
info.result = false;
|
info.msg = result.msg;
|
return info;
|
}
|
|
try {
|
// 记录数据到mongodb日志中
|
let db = this.app.mongodb;
|
let collection = db.collection("apiWcsLog");
|
let mongoData = JSON.parse(JSON.stringify(result));
|
mongoData.bill_Id = taskInfo.bill_Id;
|
mongoData.billCode = taskInfo.billCode;
|
mongoData.taskInfo = taskInfo;
|
mongoData.params = params;
|
mongoData.createDate = new Date();
|
await collection.insert(mongoData);
|
} catch {}
|
|
if ("" + result.SendTaskResult.result === "true") {
|
// 更新任务状态
|
await this.ctx.service.wcs.updateTaskStatus(taskInfo, "任务下发成功");
|
info.result = true;
|
info.msg = `${taskInfo.billCode}任务下发成功`;
|
} else {
|
if (taskType === 2) {
|
// 出库单,更新目标输送线ID,给PDA查看
|
if (result.SendTaskResult.outTransId) {
|
await this.dbWrite.update(SaleOrder, taskInfo.bill_Id, {
|
outTransId: result.SendTaskResult.outTransId
|
});
|
}
|
}
|
let deviceType = "0";
|
let status = "任务下发失败";
|
let msg = `状态码${result.SendTaskResult.statusId}=`;
|
if (result.SendTaskResult.statusId === "1") {
|
msg += "非空闲";
|
} else if (result.SendTaskResult.statusId === "2") {
|
msg += "输送线故障中";
|
deviceType = "输送机";
|
} else if (result.SendTaskResult.statusId === "3") {
|
msg += "RGV故障";
|
deviceType = "RGV";
|
} else if (result.SendTaskResult.statusId === "4") {
|
msg += "码垛机故障";
|
deviceType = "堆垛机";
|
} else {
|
msg += "任务进行中";
|
status = "任务进行中";
|
}
|
if (result.SendTaskResult.deviceId) {
|
msg += `,故障设备ID:${result.SendTaskResult.deviceId}`;
|
// 更新设备不可用
|
await this.dbWrite.update(
|
BaseEquipment,
|
{
|
deviceCode: result.SendTaskResult.deviceId || "0",
|
deviceType: deviceType
|
},
|
{
|
enable: 0
|
}
|
);
|
}
|
// 更新任务状态
|
await this.ctx.service.wcs.updateTaskStatus(taskInfo, status, msg);
|
info.result = true;
|
info.msg = `${taskInfo.billCode}${msg}`;
|
}
|
msg = "下发任务:" + info.msg;
|
await this.ctx.service.wcs.saveMongoLog("计划任务", msg, taskInfo);
|
} catch (error) {
|
info.result = false;
|
info.msg = error.message;
|
let msg = "执行任务,有错:" + taskInfo.taskType + taskInfo.billCode + error.message;
|
await this.ctx.service.wcs.saveMongoLog("计划任务", msg, taskInfo);
|
}
|
return info;
|
}
|
//#endregion
|
|
//#region 检测任务完成 taskFinish
|
/**
|
* 任务完成 taskFinish
|
*/
|
private async taskFinish(taskInfo: TaskQueue) {
|
let info = this.getInfo();
|
let msg = `taskFinish开始:` + taskInfo.taskType + taskInfo.billCode;
|
await this.ctx.service.wcs.saveMongoLog("计划任务", msg, taskInfo);
|
// WCS中间件url地址
|
srm.domainUrl = this.app.config.domainUrl;
|
let params = {
|
taskId: taskInfo.task_Id
|
};
|
let result: any;
|
// 模拟数据
|
if (this.app.config.isVirtual) {
|
result = {
|
TaskFinishResult: {
|
result: true
|
}
|
};
|
} else {
|
result = await srm.taskFinish(params);
|
}
|
|
if (result.result === false) {
|
info.result = false;
|
info.msg = result.msg;
|
return info;
|
}
|
|
try {
|
// 记录数据到mongodb日志中
|
let db = this.app.mongodb;
|
let collection = db.collection("apiWcsLog");
|
let mongoData = JSON.parse(JSON.stringify(result));
|
mongoData.bill_Id = taskInfo.bill_Id;
|
mongoData.billCode = taskInfo.billCode;
|
mongoData.taskInfo = taskInfo;
|
mongoData.params = params;
|
mongoData.taskInfo = taskInfo;
|
mongoData.createDate = new Date();
|
await collection.insert(mongoData);
|
} catch {}
|
|
let wmsResult: ResultInfo = {
|
result: false
|
};
|
// 检测到任务完成,返回为true
|
if ("" + result.TaskFinishResult.result === "true") {
|
if (taskInfo.taskType === "上架单") {
|
// 入库操作
|
wmsResult = await this.ctx.service.wcs.checkEnterStorage(taskInfo);
|
} else if (taskInfo.taskType === "空器具上架") {
|
// 空器具上架操作
|
wmsResult = await this.ctx.service.wcs.checkEnterStorageEmpty(taskInfo);
|
} else if (taskInfo.taskType === "空器具下架") {
|
// 空器具下架操作
|
wmsResult = await this.ctx.service.wcs.checkOutStorageEmpty(taskInfo);
|
} else if (taskInfo.taskType === "移库单") {
|
// 移库操作
|
wmsResult = await this.ctx.service.wcs.checkTransferStorage(taskInfo);
|
} else if (taskInfo.taskType === "出库单") {
|
// 出库操作
|
wmsResult = await this.ctx.service.wcs.checkOutStorage(taskInfo);
|
}
|
let msg = `${taskInfo.billCode}完成任务结果:` + wmsResult.result + wmsResult.msg;
|
await this.ctx.service.wcs.saveMongoLog("计划任务", msg, taskInfo);
|
if (wmsResult.result) {
|
// 更新任务状态,任务完成
|
await this.ctx.service.wcs.updateTaskStatus(taskInfo, "任务完成");
|
info.result = true;
|
info.msg = `${taskInfo.billCode}任务完成`;
|
} else {
|
info.result = false;
|
info.msg = wmsResult.msg;
|
let msg = `${taskInfo.billCode}taskFinish失败` + info.msg;
|
await this.ctx.service.wcs.saveMongoLog("计划任务", msg, taskInfo);
|
}
|
} else {
|
let status = "任务完成失败";
|
let msg = `状态码${result.TaskFinishResult.statusId}=`;
|
if (result.TaskFinishResult.statusId === "1") {
|
msg += "卡在输送线";
|
} else if (result.TaskFinishResult.statusId === "2") {
|
msg += "卡在RGV";
|
} else if (result.TaskFinishResult.statusId === "3") {
|
msg += "卡在堆垛机";
|
} else {
|
msg += "任务完成中";
|
status = "任务完成中";
|
}
|
// 更新任务状态
|
await this.ctx.service.wcs.updateTaskStatus(taskInfo, status, msg);
|
info.result = true;
|
info.msg = `${taskInfo.billCode}${msg}`;
|
}
|
msg = "taskFinish结束:" + info.msg + taskInfo.taskType + taskInfo.billCode;
|
await this.ctx.service.wcs.saveMongoLog("计划任务", msg, taskInfo);
|
return info;
|
}
|
//#endregion
|
|
//#region 设备检测心跳 checkDevice
|
/**
|
* 设备检测心跳 checkDevice
|
*/
|
public async checkDevice() {
|
let info = this.getInfo();
|
// 输送线检测
|
let tranList = await this.dbRead.find(BaseEquipment, {
|
deviceType: "输送机",
|
enable: 0
|
});
|
for (let tranInfo of tranList) {
|
const result: any = await tran.getSrmConveyorStationInfo({
|
transPlaceId: tranInfo.deviceCode
|
});
|
if (result && result.GetSrmConveyorStationInfoResult) {
|
let data = result.GetSrmConveyorStationInfoResult;
|
if ("" + data.state === "1") {
|
// 更新设备可用
|
await this.dbWrite.update(
|
BaseEquipment,
|
{
|
equipment_Id: tranInfo.equipment_Id
|
},
|
{
|
enable: 1
|
}
|
);
|
}
|
}
|
}
|
|
// RGV检测
|
let rgvList = await this.dbRead.find(BaseEquipment, {
|
deviceType: "RGV",
|
enable: 0
|
});
|
for (let rgvInfo of rgvList) {
|
const result: any = await rgv.getRgvInfo({
|
transPlaceId: rgvInfo.deviceCode
|
});
|
if (result && result.GetRgvInfofoResult) {
|
let data = result.GetRgvInfofoResult;
|
if ("" + data.state === "1") {
|
// 更新设备可用
|
await this.dbWrite.update(
|
BaseEquipment,
|
{
|
equipment_Id: rgvInfo.equipment_Id
|
},
|
{
|
enable: 1
|
}
|
);
|
}
|
}
|
}
|
// 输送线检测
|
let srmList = await this.dbRead.find(BaseEquipment, {
|
deviceType: "堆垛机",
|
enable: 0
|
});
|
for (let srmInfo of srmList) {
|
const result: any = await srm.getSrmInfo({
|
rgvId: srmInfo.deviceCode
|
});
|
if (result && result.GetSrmInfoResult) {
|
let data = result.GetSrmInfoResult;
|
if ("" + data.state === "1") {
|
// 更新设备可用
|
await this.dbWrite.update(
|
BaseEquipment,
|
{
|
equipment_Id: srmInfo.equipment_Id
|
},
|
{
|
enable: 1
|
}
|
);
|
}
|
}
|
}
|
let msg = "设备完成:" + info.msg;
|
await this.ctx.service.wcs.saveMongoLog("计划任务", msg);
|
return info;
|
}
|
//#endregion
|
}
|