Compare commits

..

2 Commits

Author SHA1 Message Date
f03d63b7d1 更新 mes_in_sct/app/action/GetBatteryInfo.php
Some checks failed
Run Unit Tests / test (pull_request) Failing after 9s
2025-06-15 15:01:23 +08:00
a856480ca0 更新 mes_in_sct/app/action/CheckBomInfo.php 2025-06-15 15:00:53 +08:00
4 changed files with 32 additions and 83 deletions

View File

@ -1,74 +1,26 @@
name: Run Unit Tests name: Run Unit Tests
on: on:
pull_request: push:
branches: branches:
- main - main
env: - develop
GITEA_TOKEN: ${{ secrets.GITEA_TOKEN }} pull_request:
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

@ -25,7 +25,7 @@ class CheckBomInfo
//2.判断工序单元、设备编码是存在? //2.判断工序单元、设备编码是存在?
$sql = "SELECT id FROM hf_mes_process_workingsubclass WHERE code='".$workingsubclass."'"; $sql = "SELECT id FROM hf_mes_process_workingsubclass WHERE code='".$workingsubclass."'";
$ret = Db::fetch($sql); $ret = Db::fetch($sql2);
if(empty($ret)){ if(empty($ret)){
throw new Exception("工序单元[$workingsubclass]不存在",4001); throw new Exception("工序单元[$workingsubclass]不存在",4001);
} }

View File

@ -34,7 +34,7 @@ class GetBatteryInfo
WHERE battery_id='%s' ORDER BY id DESC LIMIT 1;", WHERE battery_id='%s' ORDER BY id DESC LIMIT 1;",
$battery_id $battery_id
); );
$ret = Db::fetch($sql); $ret = Db::fetch($sql2);
list($tray, $lot, $batch, $subbatch) = [ list($tray, $lot, $batch, $subbatch) = [
$ret['tray'], $ret['tray'],

View File

@ -122,15 +122,11 @@ 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"); //获取原材料的正向追溯的uuid
$forward_tracing_uuid = []; $forward_tracing_uuid = 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'];
@ -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);