Sp_PLC_ScanInsertToERP.md 2.58 KB

Sp_PLC_ScanInsertToERP (procedure)

@author:zhucx @date:20210817 封存 @describe:PLC服务器调用

  • Type: PROCEDURE
  • Deterministic: NO
  • SQL data access: CONTAINS SQL

Parameters

# Mode Name Type
1 IN sBrId varchar(100)
2 IN sSuId varchar(100)
3 IN sPlcAddr longtext
4 IN sValues longtext

Body

Body is not pre-cached. To inspect: mysql --defaults-file=~/.my.cnf -e 'SHOW CREATE PROCEDURESpPLC_ScanInsertToERP'._

Narrative

Business context: 设备 / PLC 信号采集 — main entry called by the external PLC server to push a tick of raw signal data into ERP (proc COMMENT: "PLC服务器调用", dated 20210817 封存 / sealed). Decodes a pipe/comma-delimited address+value payload per 西门子 controller, reconciles it against the ERP-side state in plc_currentmachinevalue, and detects work-order/shift changes, alarm conditions, and production-count deltas to keep mftproductionplanslave / mftproductionreport in sync with the physical machines.

What it does: Outer loop splits sPlcAddr / sValues by | (one segment per controller); for each segment the first comma-separated token is iSemens, and the rest is address/value pairs. For each address, looks up viw_plc_machine (joining plc_currentmachinevalue to elemachine) to find the matching sPlcsStatusName slot, then updates plc_currentmachinevalue.sPlcsStatusValue. Branches on sPlcsStatusName: 合格数 sets ERP/PLC counters; 当前工单号 / 当前班组 compare PLC vs ERP value, set p_bBill/p_bShift flags, and look up the corresponding mftproductionplanslave row by sSrcNo+sMachineId; 当前设备状态 captures the device state; PH值 / 电导率 / 酒精 range-check against dMin/dMax and write 'ERP警报' codes 5/4/7 when out of range. The result is a partially reconciled snapshot that downstream procs use to drive production-report writes.

Invocation: Status: appears orphaned at the DB layer — no gdsmodule.sProcName binding, no form-master sSqlStr reference, no other-routine caller, no callable Java reference. The commented-out -- CALL Sp_PLC_ScanInsertToERP('','') lines inside many Sp_bd_*.sql / Sp_chart_*.sql source files in xly-src/script/标版/30100101/ are dead invocation hints, not live callers. The proc header marks it 封存 (sealed) and a customer override exists at xly-src/script/客户/亚明威/Sp_PLC_ScanInsertToERP.sql. The historical caller was an external PLC service hitting the DB directly — verify with operations before relying on it.