Compare commits

..

1 Commits

Author SHA1 Message Date
hui
f53c742df0 feat(测试多文件异常):
Some checks failed
Run Unit Tests / test (pull_request) Failing after 3m41s
2025-06-16 11:07:44 +08:00
3 changed files with 87 additions and 133 deletions

View File

@ -1,74 +1,28 @@
name: Run Unit Tests name: Run Unit Tests
on: on:
push:
branches:
- main
- develop
pull_request: pull_request:
branches: branches:
- main - main
env:
GITEA_TOKEN: ${{ secrets.GITEA_TOKEN }}
jobs: jobs:
test: test:
runs-on: phpunit_test runs-on: phpunit_test
container: mirror.ccs.tencentyun.com/xeden3/ai-code-reviewer-gitea-runner:v1.4.1 container: docker.xuanyuan.me/xeden3/ai-code-reviewer-gitea-runner:v1.2
steps: steps:
- name: Checkout code - name: Checkout code
uses: http://119.91.43.128:3003/james/checkout@v4 uses: http://119.91.43.128:3003/james/checkout@v4
with:
- name: Get Pull Request Number fetch-depth: 2 # 至少获取最近两次提交
id: get_pr_number
run: |
# 提取 PR 编号(如 pull/14/head -> 14)
PULLS_ID=$(git branch | grep -o 'pull/[0-9]\+' | cut -d'/' -f2)
if [ -z "$PULLS_ID" ]; then
echo "❌ 无法提取 PR 编号"
exit 1
fi
echo "PR ID: $PULLS_ID"
# 写入 GITHUB_ENV(可选,兼容旧脚本)
echo "PULLS_ID=$PULLS_ID" >> $GITHUB_ENV
# 写入 outputs,供后续步骤使用
echo "pr_number=$PULLS_ID" >> $GITHUB_OUTPUT
- name: Run code review script - name: Run code review script
env: env:
# === 项目配置 ===
GIT_PROJECT_PATH: /workspace/hui/SCTMES_V5 # Gitea 的工作目录 GIT_PROJECT_PATH: /workspace/hui/SCTMES_V5 # Gitea 的工作目录
ALLOWED_PATHS: '["EdgeManager/**", "mes_in_sct/**", "mes_in_task/**", "webman/**"]' # 允许检测目录
IGNORED_PATHS: '["EdgeManager/vendor/**", "mes_in_sct/vendor/**", "mes_in_task/vendor/**", "webman/public/**", "webman/runtime/**", "webman/vendor/**"]' # 忽略检测目录
# === Gitea API 配置(传给 audit_code.sh)===
API_URL: "http://119.91.43.128:3003/api/v1/repos/hui/SCTMES_V5/issues/${{ steps.get_pr_number.outputs.pr_number }}/comments"
GITEA_TOKEN: ${{ secrets.GITEA_TOKEN }}
SYSTEM_PROMPT: |
你是一位资深的PHP软件开发工程师专注于代码的规范性、功能性、稳定性、运行效率。本次任务是对员工的代码进行审查具体要求如下
### 代码审查目标:
1. 功能实现的正确性与健壮性40分 确保代码逻辑正确,能够处理各种边界情况和异常输入。
2. 命名规范10分检查代码变量和函数命名是否规范类和函数使用驼峰命名变量使用小写字母+下横线命名。
3. 是否符合最佳实践20分评估代码是否遵循行业最佳实践包括代码结构、命名规范、注释清晰度等。
4. 性能与资源利用效率20分分析代码的性能表现评估是否存在资源浪费或性能瓶颈。
5. Commits信息的清晰性与准确性10分检查提交信息是否清晰、准确是否便于后续维护和协作。
6. 所有检查**不需要考虑类名称不需要考虑SQL语句**,数据库注入风险等数据库相关的风险,**不考虑SQL预处理sprintf处理不需要考虑返回值命名$ret的情况**。
### 输出格式:
请以Markdown格式输出代码审查报告并包含以下内容
1. 问题描述和优化建议(如果有):列出代码中存在的问题,简要说明其影响,并给出优化建议,**必要时候以代码段的形式指出具体的修改方案**。
2. 评分明细:为每个评分标准提供具体分数。
3. 总分:格式为“总分:XX分”例如总分:80分确保可通过正则表达式 r"总分[:]\s*(\d+)分?" 解析出总分。
### 特别说明:
整个评论要保持sarcastic风格
评论时请大胆使用讽刺性语言,但要确保技术指正准确。
评论时请:
1. 在技术点评中加入适当幽默元素
2. 合理使用相关Emoji但不要过度
- 🐛 表示bug
- 💥 表示严重问题
- 🎯 表示改进建议
- 🔍 表示需要仔细检查
run: | run: |
cd /workspace cd /workspace
./audit_code.sh ./audit_code.sh

View File

@ -122,16 +122,12 @@ class SetWipOutputByItemId
throw new Exception('工序单元[' . $workingsubclass . ']下设备编码[' . $device_code . ']找不到对应投入物料生产批次信息'); throw new Exception('工序单元[' . $workingsubclass . ']下设备编码[' . $device_code . ']找不到对应投入物料生产批次信息');
} }
$item_code_in_process_log = array_column($ret, "item_code"); $item_code_in_process_log = array_column($ret, "item_code");
//获取正向追溯的uuid
$forward_tracing_uuid_in_process_log = array_column($ret, "forward_tracing_uuid");
$forward_tracing_uuid = [];
foreach ($forward_tracing_uuid_in_process_log as $json_str) {
$decoded = json_decode($json_str, true); // 转成数组
if (is_array($decoded)) {
$forward_tracing_uuid = array_merge($forward_tracing_uuid, $decoded);
}
}
//获取原材料的正向追溯的uuid
$forward_tracing_uuid = array_unique(array_merge(...array_map(function ($json) {
return is_array($decoded = json_decode($json, true)) ? $decoded : [];
}, array_column($ret, "forward_tracing_uuid"))));
$bb = [sdfdf];
$batch = $ret[0]['batch']; $batch = $ret[0]['batch'];
//对比物料信息是否与process_log表的item_code是否相同 //对比物料信息是否与process_log表的item_code是否相同
@ -227,16 +223,14 @@ class SetWipOutputByItemId
} else { } else {
$sql_val_out_result_param[] = "'" . $param_out_val . "'"; $sql_val_out_result_param[] = "'" . $param_out_val . "'";
} }
$ng_code_val = 0;
// 判断NG是否存在 // 判断NG是否存在
if ($val['code'] == 'NG') { if ($val['code'] == 'NG') {
if ($param_out[$val['code']] != '') { if ($param_out[$val['code']] != '') {
$ng_code = $param_out[$val['code']]; $ng_code = $param_out[$val['code']];
} else {
$ng_code = 0;
} }
} }
$ng_code = $ng_code_val;
} }
// 8.获取设备投入物料信息为后续追加battery_map、bkv表做准备 // 8.获取设备投入物料信息为后续追加battery_map、bkv表做准备
@ -351,15 +345,17 @@ class SetWipOutputByItemId
} else { } else {
$uuid = json_encode(array_values(array_unique($uuid))); $uuid = json_encode(array_values(array_unique($uuid)));
} }
//保证每个正向追溯的uuid都是唯一的 //需要读取input_item_id的$forward_tracing_uuid进行拼接
$forward_tracing_uuid_only[] = generateUniqueId(); $sql = "SELECT forward_tracing_uuid FROM hf_mes_bkv_batch_process_log WHERE item_id = '" . $input_item_id . "' ORDER BY id DESC LIMIT 1";
$forward_tracing_uuid_only = json_encode($forward_tracing_uuid_only); $input_item_id_forward_tracing_uuid = Db::fetchAll($sql);
$decoded_uuid = json_decode($forward_tracing_uuid_only, true); if (!empty($input_item_id_forward_tracing_uuid)) {
if (is_array($decoded_uuid)) { $forward_tracing_uuid = array_unique(array_merge($forward_tracing_uuid, json_decode($input_item_id_forward_tracing_uuid[0]['forward_tracing_uuid'], true)));
$forward_tracing_uuid = array_merge($forward_tracing_uuid, $decoded_uuid);
} }
$forward_tracing_uuid = json_encode(array_unique($forward_tracing_uuid)); if ($input_item_id != $item_id) {
//保证每个正向追溯的uuid都是唯一的
$forward_tracing_uuid = array_unique(array_merge($forward_tracing_uuid, [generateUniqueId()]));
}
$forward_tracing_uuid = json_encode($forward_tracing_uuid);
$wip_uuid = json_encode(array_values(array_unique($wip_uuid))); $wip_uuid = json_encode(array_values(array_unique($wip_uuid)));
$now_date = date('Y-m-d H:i:s'); $now_date = date('Y-m-d H:i:s');
$start_time = isset($param_out['START_TIME']) ? $param_out['START_TIME'] : date('Y-m-d H:i:s'); $start_time = isset($param_out['START_TIME']) ? $param_out['START_TIME'] : date('Y-m-d H:i:s');
@ -368,9 +364,9 @@ class SetWipOutputByItemId
$battery_id = $item_id; $battery_id = $item_id;
// 新增数据到process_log表 // 新增数据到process_log表
$wip_process_log_sql_head = 'INSERT INTO "hf_mes_bkv_batch_process_log" (item_id, batch, subbatch, workingsubclass, process_code, device_code, status, start_time, finish_time, bom_source_id, item_batch, item_quantity, pid, uuid, bom_id, item_code, item_name, lot, tray, ng_code, device_category_id,last_status,forward_tracing_uuid) VALUES'; $wip_process_log_sql_head = 'INSERT INTO "hf_mes_bkv_batch_process_log" (item_id, batch, subbatch, workingsubclass, process_code, device_code, status, start_time, finish_time, bom_source_id, item_batch, item_quantity, pid, uuid, bom_id, item_code, item_name, lot, tray, ng_code, device_category_id,last_status,forward_tracing_uuid,input_finish_time) VALUES';
$wip_process_log_sql_val = sprintf( $wip_process_log_sql_val = sprintf(
"('%s', '%s', '%s', '%s', '%s', '%s', '%s', '%s', '%s', '%s', '%s', '%s', '%s', '%s', '%s', '%s', '%s', '%s', '%s', '%s', '%s', '%s', '%s')", "('%s', '%s', '%s', '%s', '%s', '%s', '%s', '%s', '%s', '%s', '%s', '%s', '%s', '%s', '%s', '%s', '%s', '%s', '%s', '%s', '%s', '%s', '%s', '%s')",
$battery_id, $battery_id,
$batch, $batch,
$subbatch, $subbatch,
@ -393,7 +389,8 @@ class SetWipOutputByItemId
$ng_code, $ng_code,
$device_category_id, $device_category_id,
1, 1,
$forward_tracing_uuid $forward_tracing_uuid,
$finish_time
); );
$sql = $wip_process_log_sql_head . $wip_process_log_sql_val; $sql = $wip_process_log_sql_head . $wip_process_log_sql_val;
$row = Db::query($sql); $row = Db::query($sql);

View File

@ -79,9 +79,6 @@ class SetWipOutputByItemIds
if (empty($param["out"])) { if (empty($param["out"])) {
throw new Exception("缺少out参数"); throw new Exception("缺少out参数");
} }
if (empty($param["out"])) {
throw new Exception("缺少out参数");
}
$batch = ""; $batch = "";
$workingsubclass = $param["workingsubclass"]; $workingsubclass = $param["workingsubclass"];
@ -138,10 +135,10 @@ class SetWipOutputByItemIds
//查询对应的批次表看是否存在激活状态 //查询对应的批次表看是否存在激活状态
$subbatch = $item_id_ret['subbatch']; $subbatch = $item_id_ret['subbatch'];
$batch = $item_id_ret['batch']; $batch = $item_id_ret['batch'];
$sql = "SELECT id FROM \"hf_mes_tmp_bkv_" . $subbatch . "\" WHERE active = 1 AND battery_id='{$item_id}' "; $sql = "SELECT id FROM \"hf_mes_tmp_bkv_" . $subbatch . "\" WHERE active = 1 AND battery_id='{$item_ids[$i]}' ";
$item_id_info = Db::fetch($sql); $item_id_info = Db::fetch($sql);
if ($item_id_info) { if ($item_id_info) {
throw new Exception('电芯码[' . $item_id . ']已存在[' . $batch . ']批次', 4001); throw new Exception('电芯码[' . $item_ids[$i] . ']已存在[' . $batch . ']批次', 4001);
} }
} }
} }
@ -155,15 +152,11 @@ class SetWipOutputByItemIds
throw new Exception('工序单元[' . $workingsubclass . ']下设备编码[' . $device_code . ']找不到对应投入物料生产批次信息'); throw new Exception('工序单元[' . $workingsubclass . ']下设备编码[' . $device_code . ']找不到对应投入物料生产批次信息');
} }
$item_code_in_process_log = array_column($ret, "item_code"); $item_code_in_process_log = array_column($ret, "item_code");
//获取正向追溯的uuid
$forward_tracing_uuid_in_process_log = array_column($ret, "forward_tracing_uuid"); //获取原材料的正向追溯的uuid固定值不变
$forward_tracing_uuid = []; $forward_tracing_uuid_fixed = array_unique(array_merge(...array_map(function ($json) {
foreach ($forward_tracing_uuid_in_process_log as $json_str) { return is_array($decoded = json_decode($json, true)) ? $decoded : [];
$decoded = json_decode($json_str, true); // 转成数组 }, array_column($ret, "forward_tracing_uuid"))));
if (is_array($decoded)) {
$forward_tracing_uuid = array_merge($forward_tracing_uuid, $decoded);
}
}
$batch = $ret[0]['batch']; $batch = $ret[0]['batch'];
@ -266,15 +259,14 @@ class SetWipOutputByItemIds
} else { } else {
$sql_val_out_result_param[$i][] = "'" . $param_out_val . "'"; $sql_val_out_result_param[$i][] = "'" . $param_out_val . "'";
} }
$ng_code_val = 0;
// 判断NG是否存在 // 判断NG是否存在
if ($val['code'] == 'NG') { if ($val['code'] == 'NG') {
if ($param_out[$i][$val['code']] != '') { if ($param_out[$i][$val['code']] != '') {
$ng_code[] = $param_out[$i][$val['code']]; $ng_code_val = $param_out[$i][$val['code']];
} else {
$ng_code[] = 0;
} }
} }
$ng_code[] = $ng_code_val;
} }
} }
@ -350,7 +342,7 @@ class SetWipOutputByItemIds
); );
} }
} }
$bb = [sdfdf];
if (count($input_item_ids) > 0) { if (count($input_item_ids) > 0) {
$input_item_id = $input_item_ids[$i]; $input_item_id = $input_item_ids[$i];
//查询batch_process_log表中该裸电芯上一工序的uuid //查询batch_process_log表中该裸电芯上一工序的uuid
@ -374,7 +366,7 @@ class SetWipOutputByItemIds
Db::beginTrans(); Db::beginTrans();
try { try {
for ($i = 0; $i < count($item_ids); $i++) { for ($i = 0; $i < count(value: $item_ids); $i++) {
// 标记最后一条数据的状态 // 标记最后一条数据的状态
if (!empty($pid[$i])) { if (!empty($pid[$i])) {
Event::emit('SetProcessLogEvent.updateLastStatus', $pid[$i]); Event::emit('SetProcessLogEvent.updateLastStatus', $pid[$i]);
@ -405,14 +397,25 @@ class SetWipOutputByItemIds
} else { } else {
$uuid[$i] = json_encode(array_values(array_unique($uuid[$i]))); $uuid[$i] = json_encode(array_values(array_unique($uuid[$i])));
} }
//保证每个正向追溯的uuid都是唯一的
$forward_tracing_uuid_only[] = generateUniqueId(); $forward_tracing_uuid = $forward_tracing_uuid_fixed;
$forward_tracing_uuid_only = json_encode($forward_tracing_uuid_only); // 检查 $input_item_ids 是否非空 且当前索引存在
$decoded_uuid = json_decode($forward_tracing_uuid_only, true); if (count($input_item_ids) > 0) {
if (is_array($decoded_uuid)) { //需要读取input_item_id的$forward_tracing_uuid进行拼接
$forward_tracing_uuid = array_merge($forward_tracing_uuid, $decoded_uuid); $sql = "SELECT forward_tracing_uuid FROM hf_mes_bkv_batch_process_log WHERE item_id = '" . $input_item_ids[$i] . "' ORDER BY id DESC LIMIT 1";
$input_item_id_forward_tracing_uuid = Db::fetchAll($sql);
if (!empty($input_item_id_forward_tracing_uuid)) {
$forward_tracing_uuid = array_unique(array_merge($forward_tracing_uuid, json_decode($input_item_id_forward_tracing_uuid[0]['forward_tracing_uuid'], true)));
} }
$forward_tracing_uuid = json_encode(array_unique($forward_tracing_uuid)); if ($input_item_ids[$i] != $item_ids[$i]) {
//保证每个正向追溯的uuid都是唯一的
$forward_tracing_uuid = array_unique(array_merge($forward_tracing_uuid, [generateUniqueId()]));
}
} else {
$forward_tracing_uuid = array_unique(array_merge($forward_tracing_uuid, [generateUniqueId()]));
}
$forward_tracing_uuid = json_encode($forward_tracing_uuid);
$wip_uuid[$i] = json_encode(array_values(array_unique($wip_uuid[$i]))); $wip_uuid[$i] = json_encode(array_values(array_unique($wip_uuid[$i])));
$now_date = date('Y-m-d H:i:s'); $now_date = date('Y-m-d H:i:s');
@ -423,9 +426,9 @@ class SetWipOutputByItemIds
$battery_id = $item_ids[$i]; $battery_id = $item_ids[$i];
// 新增数据到process_log表 // 新增数据到process_log表
$wip_process_log_sql_head = 'INSERT INTO "hf_mes_bkv_batch_process_log" (item_id, batch, subbatch, workingsubclass, process_code, device_code, status, start_time, finish_time, bom_source_id, item_batch, item_quantity, pid, uuid, bom_id, item_code, item_name, lot, tray, ng_code, device_category_id,last_status,forward_tracing_uuid) VALUES'; $wip_process_log_sql_head = 'INSERT INTO "hf_mes_bkv_batch_process_log" (item_id, batch, subbatch, workingsubclass, process_code, device_code, status, start_time, finish_time, bom_source_id, item_batch, item_quantity, pid, uuid, bom_id, item_code, item_name, lot, tray, ng_code, device_category_id,last_status,forward_tracing_uuid,input_finish_time) VALUES';
$wip_process_log_sql_val = sprintf( $wip_process_log_sql_val = sprintf(
"('%s', '%s', '%s', '%s', '%s', '%s', '%s', '%s', '%s', '%s', '%s', '%s', '%s', '%s', '%s', '%s', '%s', '%s', '%s', '%s', '%s', '%s', '%s')", "('%s', '%s', '%s', '%s', '%s', '%s', '%s', '%s', '%s', '%s', '%s', '%s', '%s', '%s', '%s', '%s', '%s', '%s', '%s', '%s', '%s', '%s', '%s', '%s')",
$battery_id, $battery_id,
$batch, $batch,
$subbatch, $subbatch,
@ -448,14 +451,14 @@ class SetWipOutputByItemIds
$ng_code[$i], $ng_code[$i],
$device_category_id, $device_category_id,
1, 1,
$forward_tracing_uuid $forward_tracing_uuid,
$finish_time
); );
$sql = $wip_process_log_sql_head . $wip_process_log_sql_val; $sql = $wip_process_log_sql_head . $wip_process_log_sql_val;
$row = Db::query($sql); $row = Db::query($sql);
if ($row === NULL) { if ($row === NULL) {
throw new Exception('电芯 ' . $item_id . ' 半成品信息插入process_log表失败'); throw new Exception('电芯 ' . $item_id . ' 半成品信息插入process_log表失败');
} }
// 新增数据到battery_map表 // 新增数据到battery_map表
$battery_unique_value = "{$batch}_{$subbatch}_-1_{$lot}_{$battery_id}"; $battery_unique_value = "{$batch}_{$subbatch}_-1_{$lot}_{$battery_id}";
$wip_battery_map_sql_head = 'INSERT INTO "hf_mes_production_battery_map" (bom_source_id, battery_unique_value, battery_id, batch, subbatch, lot, tray, item_batch, pid, uuid, bom_id, workingsubclass, item_code,item_name) VALUES '; $wip_battery_map_sql_head = 'INSERT INTO "hf_mes_production_battery_map" (bom_source_id, battery_unique_value, battery_id, batch, subbatch, lot, tray, item_batch, pid, uuid, bom_id, workingsubclass, item_code,item_name) VALUES ';