package com.trafficaudit.llmintegration.service;
|
|
import com.trafficaudit.dataimport.entity.H2032EnterpriseMonthly;
|
import com.trafficaudit.dataimport.mapper.H2032EnterpriseMonthlyMapper;
|
import lombok.extern.slf4j.Slf4j;
|
import org.springframework.stereotype.Service;
|
|
import javax.annotation.Resource;
|
|
@Slf4j
|
@Service
|
public class AuditExplanationService {
|
|
@Resource
|
private LLMService llmService;
|
@Resource
|
private DesensitizeService desensitizeService;
|
@Resource
|
private H2032EnterpriseMonthlyMapper reportMapper;
|
|
public String analyze(String explanation, String ruleDesc, Long reportId) {
|
H2032EnterpriseMonthly report = reportMapper.selectById(reportId);
|
if (report == null) {
|
return "无法获取关联数据";
|
}
|
|
String maskedName = desensitizeService.maskEnterprise(report.getEnterpriseName());
|
|
String prompt = String.format(
|
"你是交通统计数据审核助手。请根据以下信息判断上报人的解释是否合理,并给出处置建议。\n\n" +
|
"审核规则: %s\n" +
|
"企业: %s\n" +
|
"车辆总数: %s, 吨位总数: %s\n" +
|
"货运量: %s, 周转量: %s\n" +
|
"上报人解释: %s\n\n" +
|
"请按以下格式回复:\n" +
|
"合理性判断: [合理/存疑/不合理]\n" +
|
"理由: [简要说明]\n" +
|
"处置建议: [具体建议]",
|
ruleDesc, maskedName,
|
report.getVehicleTotal(), report.getTonsTotal(),
|
report.getFreightTotal(), report.getTurnoverTotal(),
|
explanation);
|
|
String result = llmService.chat(prompt);
|
|
String unmasked = desensitizeService.unmaskEnterprise(maskedName);
|
if (result != null) {
|
result = result.replace(maskedName, unmasked);
|
}
|
|
return result != null ? result : "LLM分析失败,请人工判断";
|
}
|
}
|