155 lines
7.4 KiB
PHP
155 lines
7.4 KiB
PHP
|
<?php
|
||
|
|
||
|
namespace app\action;
|
||
|
|
||
|
use Exception;
|
||
|
use libs\db\Db;
|
||
|
use libs\listener\Event;
|
||
|
|
||
|
class GetBatteryProcessRoute
|
||
|
{
|
||
|
public function execute($post)
|
||
|
{
|
||
|
// 验证数据
|
||
|
$param = check_valid($post['action'], [
|
||
|
['device_code', 'string', '设备编码'],
|
||
|
['battery_ids', 'array', '电池条码数组']
|
||
|
], $post['param']);
|
||
|
|
||
|
$battery_ids = $param['battery_ids'];
|
||
|
//校验是否重复条码
|
||
|
if (count($battery_ids) > 1) {
|
||
|
$duplicates = array_diff_assoc($battery_ids, array_unique($battery_ids)); // 获取重复的元素
|
||
|
if (!empty($duplicates)) {
|
||
|
// 存储重复电池条码及其位置
|
||
|
$duplicate_positions = [];
|
||
|
foreach ($battery_ids as $index => $battery_id) {
|
||
|
if (in_array($battery_id, $duplicates)) {
|
||
|
// 将重复条码和它的位置记录下来
|
||
|
$duplicate_positions[$battery_id][] = $index + 1;
|
||
|
}
|
||
|
}
|
||
|
|
||
|
// 如果有重复,抛出异常并返回重复条码和它们的位置
|
||
|
$duplicate_msg = "";
|
||
|
foreach ($duplicate_positions as $battery_id => $positions) {
|
||
|
$duplicate_msg .= "电池条码 {$battery_id} 存在重复,重复位置在: [" . implode(", ", $positions) . "]; ";
|
||
|
}
|
||
|
throw new Exception($duplicate_msg);
|
||
|
}
|
||
|
}
|
||
|
try {
|
||
|
$result = [];
|
||
|
|
||
|
foreach ($battery_ids as $k => $battery_id) {
|
||
|
// 判断电池是否为空
|
||
|
if (empty($battery_id)) {
|
||
|
throw new Exception("电池条码数组第[{$k}]位置的电池条码不能是:[0, '0', '', null, NAN]等,请上传电池条码");
|
||
|
}
|
||
|
|
||
|
$sql = sprintf(
|
||
|
"SELECT tray,lot,batch,subbatch
|
||
|
FROM hf_mes_production_battery_map
|
||
|
WHERE battery_id='%s' ORDER BY id DESC LIMIT 1;",
|
||
|
$battery_id
|
||
|
);
|
||
|
$ret = Db::fetch($sql);
|
||
|
if (is_null($ret)) {
|
||
|
throw new Exception("电池条码数组第[{$k}]位置的电池条码{$battery_id}不存在");
|
||
|
}
|
||
|
|
||
|
list($tray, $lot, $batch, $subbatch) = [
|
||
|
$ret['tray'],
|
||
|
$ret['lot'],
|
||
|
$ret['batch'],
|
||
|
$ret['subbatch']
|
||
|
];
|
||
|
|
||
|
$sql = sprintf(
|
||
|
"SELECT a.flow_id,c.code AS model
|
||
|
FROM hf_mes_production_planning_management_batch AS a
|
||
|
INNER JOIN hf_mes_technology_flow b ON b.id = a.flow_id
|
||
|
INNER JOIN hf_mes_product_model c ON c.id = b.product_model_id
|
||
|
WHERE batch='%s' LIMIT 1;",
|
||
|
$batch
|
||
|
);
|
||
|
$ret = Db::fetch($sql);
|
||
|
$model = $ret['model'];
|
||
|
|
||
|
$sql = sprintf(
|
||
|
"SELECT a.process_code,a.next_process_code, a.active,
|
||
|
d.code as last_workingsubclass,e.code as next_workingsubclass,
|
||
|
f.code as last_workstation,g.code as next_workstation
|
||
|
FROM \"%s\" AS a
|
||
|
INNER JOIN hf_mes_technology_process b ON b.code = a.process_code
|
||
|
INNER JOIN hf_mes_technology_process c ON c.code = a.next_process_code
|
||
|
INNER JOIN hf_mes_process_workingsubclass d ON d.id = b.workingsubclass_id
|
||
|
INNER JOIN hf_mes_process_workingsubclass e ON e.id = c.workingsubclass_id
|
||
|
INNER JOIN hf_mes_device_category f ON f.id = d.device_category_id
|
||
|
INNER JOIN hf_mes_device_category g ON g.id = e.device_category_id
|
||
|
WHERE battery_id='%s' AND tray='%s' AND lot='%s' LIMIT 1;",
|
||
|
config('app.bkv_prefix') . $subbatch,
|
||
|
$battery_id,
|
||
|
$tray,
|
||
|
$lot
|
||
|
);
|
||
|
$ret = Db::fetch($sql);
|
||
|
if (isset($param['batch']) && $param['batch'] != $batch) {
|
||
|
throw new Exception("电池条码数组第[{$k}]位置电池条码{$battery_id}的生产批次{$batch}与上传的生产批次" . $param['batch'] . "不相同");
|
||
|
}
|
||
|
// 判断电池是否没有激活
|
||
|
if ($ret['active'] != 1) {
|
||
|
throw new Exception("电池条码数组第[{$k}]位置电池条码{$battery_id}:是未激活电池");
|
||
|
}
|
||
|
|
||
|
if($k == 0){
|
||
|
//时间制程管控(同步)
|
||
|
|
||
|
$params = $param;
|
||
|
$params['process_code'] = $ret['next_process_code'];
|
||
|
$params['class_name'] = get_class($this);
|
||
|
$response = Event::emit('ExtScriptEvent.extScriptBegin', $params);
|
||
|
if($response['ext_script_code'] != 0){
|
||
|
throw new Exception($response['ext_script_msg']);
|
||
|
}
|
||
|
}
|
||
|
|
||
|
|
||
|
// 冻结解冻列表设置拦截工序调用该接口就会反馈给class和classname到设备
|
||
|
$freeze_data = Event::emit('FreezeInterceptionEvent.handle', [
|
||
|
'battery_id' => $battery_id,
|
||
|
'workingsubclass' => $ret['next_workingsubclass'],
|
||
|
'ropes_time' => date("Y-m-d H:i:s"),
|
||
|
]);
|
||
|
$h = $k + 1;
|
||
|
if (!empty($freeze_data)) {
|
||
|
// 检查 status 是否为 5 和 workingsubclass为ALLPROCESS
|
||
|
if ($freeze_data['status'] == 5 && $freeze_data['workingsubclass'] = 'ALLPROCESS') {
|
||
|
throw new Exception("(!!!紧急冻结全工序!!!)第[{$h}]位置电池条码{$battery_id}在工序[{$ret['next_workingsubclass']}]已被标记[{$freeze_data['classname']}]冻结,需要设备排出或人工取出!!!");
|
||
|
// 检查 status 是否为 1
|
||
|
} elseif($freeze_data['status'] == 1) {
|
||
|
throw new Exception("(!!!请先解冻再复投!!!)第[{$h}]位置电池条码{$battery_id}在工序[{$ret['next_workingsubclass']}]已被标记[{$freeze_data['classname']}]冻结,需要设备排出或人工取出!!!");
|
||
|
}
|
||
|
|
||
|
// 默认冻结报错逻辑
|
||
|
throw new Exception("第[{$h}]位置电池条码{$battery_id}在工序[{$ret['next_workingsubclass']}]已被标记[{$freeze_data['classname']}]冻结,需要设备排出或人工取出!!!");
|
||
|
}
|
||
|
|
||
|
// 返回数据
|
||
|
$result['battery_ids'][] = $battery_id;
|
||
|
$result['batch'][] = $batch;
|
||
|
$result['model'][] = $model;
|
||
|
$result['last_process_code'][] = $ret['process_code'];
|
||
|
$result['next_process_code'][] = $ret['next_process_code'];
|
||
|
$result['last_workingsubclass'][] = $ret['last_workingsubclass'];
|
||
|
$result['next_workingsubclass'][] = $ret['next_workingsubclass'];
|
||
|
$result['last_workstation'][] = $ret['last_workstation'];
|
||
|
$result['next_workstation'][] = $ret['next_workstation'];
|
||
|
}
|
||
|
} catch (Exception $e) {
|
||
|
throw new Exception($e->getMessage());
|
||
|
}
|
||
|
|
||
|
return $result;
|
||
|
}
|
||
|
}
|