feat: 发起变更页 AI 接口全量接入(T02~T10)——预识别智能风险分析异步任务四段展示(DeepAnalysisPanel)+precheck.deep_analysis;风险页 aiOrganize/preInfo 下发/generateRiskCheck 后台编排(不弹抽屉);riskPre/hazop/fmea/riskCheck 四插件空实现与模拟 loading 全部替换为真实接口(hazop 节点/偏离推演、fmea 步骤/失效模式推演、全部偏离/失效模式顺序生成);培训/PSSR 传入真实风险记录+行动项+固定四组模板(group_type 优先匹配);等级评分按 dim 匹配+缺失维度人工补评提示;修复仅看是过滤丢数据;typecheck 基线持平/build 通过
This commit is contained in:
@@ -2,90 +2,33 @@
|
||||
import {onMounted, ref } from "vue";
|
||||
import { Icon } from '@iconify/vue'
|
||||
import { riskCheckDetailApi, riskCheckSaveApi } from '@/service/api/plugin'
|
||||
import { AiError, aiRiskCheck } from '@/service/api/ai'
|
||||
import { RISK_CHECKS_INIT } from './riskCheckTemplate'
|
||||
|
||||
const props = defineProps(['isAiOpen','currentId'])
|
||||
const props = defineProps(['isAiOpen','currentId','preInfo'])
|
||||
const emit = defineEmits(['close','toTable']);
|
||||
|
||||
// answer 1 是
|
||||
// answer 0 否
|
||||
// answer 2 NA
|
||||
|
||||
const RISK_CHECKS_INIT = [
|
||||
{
|
||||
group_id: 1,
|
||||
group_label: "安全健康",
|
||||
items: [
|
||||
{
|
||||
question_id: 1,
|
||||
answer: null,
|
||||
question: "是否存在任何可能导致安全问题的化学反应?检查化学反应禁忌表。",
|
||||
risk_desc: "",
|
||||
control_measure: "",
|
||||
},
|
||||
{
|
||||
question_id: 2,
|
||||
answer: null,
|
||||
question: "是否存在任何易燃易爆化学物质或粉尘?",
|
||||
risk_desc: "",
|
||||
control_measure: "",
|
||||
},
|
||||
{
|
||||
question_id: 3,
|
||||
answer: null,
|
||||
question: "是否存在任何有危险的原材料流速、成分或温度条件变更?",
|
||||
risk_desc: "",
|
||||
control_measure: "",
|
||||
},
|
||||
{
|
||||
question_id: 4,
|
||||
answer: null,
|
||||
question: "是否会因加热、冷却或精确的温度控制失控而导致安全问题?",
|
||||
risk_desc: "",
|
||||
control_measure: "",
|
||||
},
|
||||
{
|
||||
question_id: 5,
|
||||
answer: null,
|
||||
question: "是否具有为安全操作所必需的仪表、控制、紧急制动、开关或报警?",
|
||||
risk_desc: "",
|
||||
control_measure: " ",
|
||||
},
|
||||
],
|
||||
},
|
||||
{
|
||||
group_id: 2,
|
||||
group_label: "工艺与操作",
|
||||
items: [
|
||||
{
|
||||
question_id: 6,
|
||||
answer: null,
|
||||
question: "变更后是否需要对操作人员进行专门培训?",
|
||||
risk_desc: "",
|
||||
control_measure: "",
|
||||
},
|
||||
{
|
||||
question_id: 7,
|
||||
answer: null,
|
||||
question: "是否涉及应急预案或消防设施的调整?",
|
||||
risk_desc: "",
|
||||
control_measure: ""
|
||||
},
|
||||
],
|
||||
}
|
||||
];
|
||||
const loading = ref<boolean>(false);
|
||||
const riskGroups = ref<any[]>(RISK_CHECKS_INIT);
|
||||
// 深拷贝共享模板(避免直接修改共享常量)
|
||||
const cloneTemplate = () => JSON.parse(JSON.stringify(RISK_CHECKS_INIT));
|
||||
const riskGroups = ref<any[]>(cloneTemplate());
|
||||
// 全量数据副本:「仅看是」过滤只改显示视图,不丢已编辑/已加载内容
|
||||
const allGroups = ref<any[]>(cloneTemplate());
|
||||
const riskFilter = ref<number>(-1);
|
||||
const analyzing = ref<boolean>(false);
|
||||
|
||||
// 过滤风险项
|
||||
// 过滤风险项(基于全量副本,显示层过滤)
|
||||
const filterChange = (v: number) => {
|
||||
riskFilter.value = v;
|
||||
if(v===-1){
|
||||
riskGroups.value = RISK_CHECKS_INIT;
|
||||
riskGroups.value = allGroups.value;
|
||||
}else{
|
||||
const result = RISK_CHECKS_INIT.map(group => ({
|
||||
...group,
|
||||
const result = allGroups.value.map(group => ({
|
||||
...group,
|
||||
items: group.items.filter((item:any) => item.answer === 1)
|
||||
})).filter(group => group.items.length > 0);
|
||||
riskGroups.value = result;
|
||||
@@ -95,7 +38,7 @@ const filterChange = (v: number) => {
|
||||
const save = async () => {
|
||||
loading.value = true;
|
||||
const {error} = await riskCheckSaveApi(props.currentId,{
|
||||
groups: riskGroups.value
|
||||
groups: allGroups.value
|
||||
});
|
||||
if(!error){
|
||||
window.$message?.success("保存成功");
|
||||
@@ -126,14 +69,14 @@ const enterToTable = (type: string, groupIndex: number = -1, questionIndex: numb
|
||||
emit('toTable',type,newRow?[newRow]:[]);
|
||||
}
|
||||
if(type==='all'){
|
||||
const result = riskGroups.value.flatMap((group:any) =>
|
||||
group.items.map((item:any, index:number) => ({ group_id: group.group_id, group_label: group.group_label, index, item })).filter(({ item }:any) => !item.id)
|
||||
const result = allGroups.value.flatMap((group:any) =>
|
||||
group.items.map((item:any, index:number) => ({ group_id: group.group_id, group_label: group.group_label, index, item })).filter(({ item }:any) => !item.id)
|
||||
);
|
||||
if(result.length){
|
||||
return window.$message?.warning("请先保存再入表");
|
||||
}
|
||||
const enrichedRows:any[] = [];
|
||||
riskGroups.value.forEach((group:any) => {
|
||||
allGroups.value.forEach((group:any) => {
|
||||
group.items.forEach((row:any) => {
|
||||
enrichedRows.push({
|
||||
id: row.id || 0,
|
||||
@@ -153,12 +96,75 @@ const enterToTable = (type: string, groupIndex: number = -1, questionIndex: numb
|
||||
}
|
||||
}
|
||||
|
||||
// AI 自动分析工序
|
||||
const runAi = async () => {
|
||||
// AI 自动分析(/open/v1/moc/change/risk-check;当前 7 项模板为唯一权威,仅回填未判定项)
|
||||
// silent=true 为后台编排调用(申请单生成后):不弹交互提示、失败静默返回
|
||||
const runAi = async (silent = false) => {
|
||||
const description = (props.preInfo?.description ?? '').trim();
|
||||
if (!description) {
|
||||
if (!silent) window.$message?.warning('缺少变更描述(请先在「变更预识别」填写)');
|
||||
return;
|
||||
}
|
||||
if (analyzing.value) return;
|
||||
// 以当前全量 7 项为权威模板(含 question_id 与问题原文),旧 58/66 项不得覆盖
|
||||
const checkTemplate = {
|
||||
groups: allGroups.value.map((group: any) => ({
|
||||
group_id: group.group_id,
|
||||
group_label: group.group_label,
|
||||
items: (group.items ?? []).map((item: any) => ({ question_id: item.question_id, question: item.question }))
|
||||
}))
|
||||
};
|
||||
analyzing.value = true;
|
||||
setTimeout(() => {
|
||||
try {
|
||||
const rows = (props.preInfo?.compare_rows ?? []).map((r: any) => ({ item: r.item, before_text: r.before_text, after_text: r.after_text }));
|
||||
const res = await aiRiskCheck(description, rows, checkTemplate);
|
||||
const aiItems: any[] = res?.items ?? [];
|
||||
// 按 question_id 索引(no 字段为 question_id 原值),规范化问题原文兜底
|
||||
const byId = new Map<string, any>();
|
||||
const byQuestion = new Map<string, any>();
|
||||
aiItems.forEach((it: any) => {
|
||||
if (it?.no !== undefined && it.no !== '') byId.set(String(it.no), it);
|
||||
const q = String(it?.q ?? '').replace(/\s+/g, '').toLowerCase();
|
||||
if (q) byQuestion.set(q, it);
|
||||
});
|
||||
let filled = 0;
|
||||
let keptManual = 0;
|
||||
allGroups.value.forEach((group: any) => {
|
||||
(group.items ?? []).forEach((item: any) => {
|
||||
const qNorm = String(item.question ?? '').replace(/\s+/g, '').toLowerCase();
|
||||
const hit = byId.get(String(item.question_id)) ?? byQuestion.get(qNorm);
|
||||
if (!hit) return; // AI 缺失项:保留人工回答
|
||||
if (item.answer !== null && item.answer !== undefined) {
|
||||
keptManual += 1; // 已有人工判定不覆盖
|
||||
return;
|
||||
}
|
||||
const ans = hit.ans === '是' ? 1 : hit.ans === '否' ? 0 : hit.ans === 'NA' ? 2 : null;
|
||||
if (ans === null) return;
|
||||
item.answer = ans;
|
||||
if (ans === 1) {
|
||||
item.risk_desc = hit.risk ?? '';
|
||||
item.control_measure = hit.measure ?? '';
|
||||
} else {
|
||||
// 否/NA:两字段清空
|
||||
item.risk_desc = '';
|
||||
item.control_measure = '';
|
||||
}
|
||||
filled += 1;
|
||||
});
|
||||
});
|
||||
// 过滤视图下同步显示
|
||||
if (riskFilter.value !== -1) filterChange(riskFilter.value);
|
||||
if (!silent) {
|
||||
window.$message?.success(`AI 已判定 ${filled} 项${keptManual ? `(保留人工判定 ${keptManual} 项)` : ''},正在自动保存…`);
|
||||
}
|
||||
// 自动保存换取真实 ID(入表前置条件)
|
||||
await save();
|
||||
} catch (e: any) {
|
||||
// 后台失败静默(单项重试入口在插件内)
|
||||
if (e instanceof AiError) window.$message?.warning(`AI 自动分析失败:${e.message},可手动判定`);
|
||||
else window.$message?.warning('AI 自动分析失败,可手动判定');
|
||||
} finally {
|
||||
analyzing.value = false;
|
||||
}, 1000);
|
||||
}
|
||||
};
|
||||
|
||||
// 获取风险检查表详情
|
||||
@@ -167,16 +173,21 @@ const getRiskCheckDetail = async () => {
|
||||
const {data,error} = await riskCheckDetailApi(props.currentId);
|
||||
if(!error){
|
||||
if(data.length){
|
||||
riskGroups.value = data;
|
||||
allGroups.value = data;
|
||||
}else{
|
||||
riskGroups.value = RISK_CHECKS_INIT;
|
||||
allGroups.value = cloneTemplate();
|
||||
}
|
||||
// 详情刷新后保持当前过滤视图
|
||||
if (riskFilter.value !== -1) filterChange(riskFilter.value);
|
||||
else riskGroups.value = allGroups.value;
|
||||
}
|
||||
loading.value = false;
|
||||
}
|
||||
onMounted(() => {
|
||||
getRiskCheckDetail();
|
||||
})
|
||||
|
||||
defineExpose({ runAi })
|
||||
</script>
|
||||
|
||||
<template>
|
||||
@@ -199,7 +210,7 @@ onMounted(() => {
|
||||
<NButton size="small" ghost type="primary" class="text-xs" @click="enterToTable('all')">
|
||||
<Icon icon="carbon:document-import" class="size-14px mr-1" /> 全部整理入表
|
||||
</NButton>
|
||||
<NButton size="small" type="primary" class="text-xs" :disabled="analyzing" @click="runAi">
|
||||
<NButton size="small" type="primary" class="text-xs" :disabled="analyzing" @click="runAi()">
|
||||
<Icon v-if="analyzing" icon="ri:loader-4-fill" class="size-14px animate-spin" />
|
||||
<Icon v-else icon="lucide:sparkles" class="size-12px" />
|
||||
AI 自动分析
|
||||
|
||||
Reference in New Issue
Block a user