Files
cut-abstractions/samples/moduleManager/module_checkBlocks.ts

77 lines
1.8 KiB
TypeScript
Raw Normal View History

2025-07-22 18:38:25 +08:00
import { Processor, ProcessorModule } from "../../src/device";
import { ErrorInfo } from "../../src/device";
/**
*
* input
*/
export const CheckBlocks: ProcessorModule<any, any> = {
moduleName: "CheckMaterial",
moduleVersion: '20250714',
config: {
minBlockWidth: 0,
minBlockThickness: 0,
},
setConfig(config) {
this.config = { ...this.config, ...config };
},
// 会在处理器自动执行
/**
*
* @param input
* @param next
* @param context
* @returns
*/
process(input, next, context) {
const { materialList, blockList } = input
const self = this;
let checkArr = checkBlocks(materialList, blockList)
if (checkArr.length > 0) {
const _errinfo: ErrorInfo = {
moduleName: this.moduleName,
moduleVersion: this.moduleVersion,
info: {
data: checkArr,
msg: '该订单内小板有异常'
}
}
this.onError(_errinfo)
}
function checkBlocks(materialList, blockList): any[] {
let allBlocks: any[] = []
for (let pm of materialList) {
let bList = blockList.filter(e => e.goodsId == pm.goodsId)
for (const pb of bList) {
if (pb.width < self.minBlockWidth) {
allBlocks.push(pb)
}
if (pb.thickness < self.minBlockThickness) {
allBlocks.push(pb)
}
}
}
return allBlocks
}
return next ? next(input) : input;
},
onError(error) {
console.error('出错了哦', error);
}
};