85 lines
2.8 KiB
PHP
85 lines
2.8 KiB
PHP
<?php
|
||
|
||
namespace app\event;
|
||
|
||
use Exception;
|
||
use libs\db\Db;
|
||
use libs\listener\Event;
|
||
|
||
class FreezeInterceptionEvent extends Event
|
||
{
|
||
public function handle($data)
|
||
{
|
||
if (count($data) <= 0) {
|
||
throw new Exception('写入数据为空,请检查!');
|
||
}
|
||
|
||
$battery_id = $data['battery_id'];
|
||
$workingsubclass = $data['workingsubclass'];
|
||
$ropes_time = $data['ropes_time'];
|
||
|
||
// 查找最新记录是否含有status = 1 ,class为NG的电池数据,有符合直接返回
|
||
$sql_latest = "SELECT id, battery_id, workingsubclass, freeze_classname, class, status
|
||
FROM hf_mes_battery_intercption
|
||
WHERE battery_id = '%s'
|
||
ORDER BY id DESC LIMIT 1";
|
||
|
||
$formatted_sql_latest = sprintf($sql_latest, $battery_id);
|
||
$latest_record = Db::fetch($formatted_sql_latest);
|
||
|
||
// 如果存在记录,且 status = 1 且 class = 'NG',有符合直接返回
|
||
if (!empty($latest_record) && $latest_record['status'] == 1 && $latest_record['class'] == 'NG') {
|
||
return [
|
||
'status' => 1,
|
||
'class' => 'NG',
|
||
'classname' => $latest_record['freeze_classname']
|
||
];
|
||
}
|
||
|
||
// 如果存在记录,且 status = 5 且 class = 'NG',直接返回
|
||
if (!empty($latest_record) && $latest_record['status'] == 5 && $latest_record['class'] == 'NG' && $latest_record['workingsubclass'] == 'ALLPROCESS' ) {
|
||
return [
|
||
'status' => 5,
|
||
'class' => 'NG',
|
||
'classname' => $latest_record['freeze_classname']
|
||
];
|
||
}
|
||
|
||
// 查询未冻结且状态为 0 的记录
|
||
$sql = "SELECT id, battery_id, workingsubclass, freeze_classname, status
|
||
FROM hf_mes_battery_intercption
|
||
WHERE battery_id = '%s'
|
||
AND workingsubclass = '%s'
|
||
AND status = 0";
|
||
|
||
$formatted_sql = sprintf($sql, $battery_id, $workingsubclass);
|
||
$intercption_ret = Db::fetch($formatted_sql);
|
||
|
||
if (!empty($intercption_ret)) {
|
||
$classname = $intercption_ret['freeze_classname'];
|
||
|
||
$sql_update = "UPDATE hf_mes_battery_intercption
|
||
SET status = %s, ropes_time = '%s', cancel_note = '%s' , class = '%s'
|
||
WHERE id = %s";
|
||
|
||
$formatted_sql_update = sprintf(
|
||
$sql_update,
|
||
1,
|
||
$ropes_time,
|
||
"本工序[{$workingsubclass}]的冻结标记[{$classname}]冻结成功",
|
||
'NG',
|
||
$intercption_ret['id']
|
||
);
|
||
|
||
Db::query($formatted_sql_update);
|
||
|
||
return [
|
||
'class' => 'NG',
|
||
'classname' => $classname
|
||
];
|
||
}
|
||
|
||
return [];
|
||
}
|
||
|
||
} |