Commit 4a9301d0 by foutouren

虎哥E盾优化需求开发完成:

1、帐号数据授权仅保留车架号
2、大数据警情中心增加报警时长字段
1 parent ff9703c8
# Created by .ignore support plugin (hsz.mobi) qodana.yaml
.idea .mybatis/index.json
.vscode .trae/
target openspec/
ne-shield-trialdrive-admin.iml
doc/neshield数据库文档V1.9.0.html
...@@ -33,16 +33,40 @@ public class JudgmentController extends AbstractController { ...@@ -33,16 +33,40 @@ public class JudgmentController extends AbstractController {
@GetMapping("/search") @GetMapping("/search")
@ApiOperation(value = "查询大数据研判列表") @ApiOperation(value = "查询大数据研判列表")
public R findJudgmentList(JudgmentSearch judgmentSearch) { public R findJudgmentList(JudgmentSearch judgmentSearch) {
long t0 = System.currentTimeMillis();
boolean keywordsPresent = judgmentSearch != null && org.apache.commons.lang.StringUtils.isNotBlank(judgmentSearch.getKeywords());
log.info("judgment.search request: startTime={}, endTime={}, alarmType={}, alarmStatus={}, keywordsPresent={}",
judgmentSearch != null ? judgmentSearch.getStartTime() : null,
judgmentSearch != null ? judgmentSearch.getEndTime() : null,
judgmentSearch != null ? judgmentSearch.getAlarmType() : null,
judgmentSearch != null ? judgmentSearch.getAlarmStatus() : null,
keywordsPresent);
PageInfo pageInfo = judgmentService.findJudgmentList(judgmentSearch); PageInfo pageInfo = judgmentService.findJudgmentList(judgmentSearch);
log.info("judgment.search response: totalRecords={}, costMs={}",
pageInfo != null ? pageInfo.getTotal() : 0,
(System.currentTimeMillis() - t0));
return R.ok().putPageData(pageInfo); return R.ok().putPageData(pageInfo);
} }
@GetMapping("/export") @GetMapping("/export")
@ApiOperation(value = "导出大数据研判报表") @ApiOperation(value = "导出大数据研判报表")
public R<String> exportJudgmentList(JudgmentSearch judgmentSearch) { public R<String> exportJudgmentList(JudgmentSearch judgmentSearch) {
long t0 = System.currentTimeMillis();
boolean keywordsPresent = judgmentSearch != null && org.apache.commons.lang.StringUtils.isNotBlank(judgmentSearch.getKeywords());
log.info("judgment.export request: startTime={}, endTime={}, alarmType={}, alarmStatus={}, keywordsPresent={}",
judgmentSearch != null ? judgmentSearch.getStartTime() : null,
judgmentSearch != null ? judgmentSearch.getEndTime() : null,
judgmentSearch != null ? judgmentSearch.getAlarmType() : null,
judgmentSearch != null ? judgmentSearch.getAlarmStatus() : null,
keywordsPresent);
String fileName = StringUtil.getFileName("大数据研判报表"); String fileName = StringUtil.getFileName("大数据研判报表");
List<JudgmentExport> judgmentList = judgmentService.exportJudgmentList(judgmentSearch); List<JudgmentExport> judgmentList = judgmentService.exportJudgmentList(judgmentSearch);
String url = super.uploadExcel(fileName, judgmentList, JudgmentExport.class); String url = super.uploadExcel(fileName, judgmentList, JudgmentExport.class);
log.info("judgment.export generated: fileName={}, rows={}, urlSize={}, costMs={}",
fileName,
judgmentList != null ? judgmentList.size() : 0,
url != null ? url.length() : 0,
(System.currentTimeMillis() - t0));
return R.ok().data(url); return R.ok().data(url);
} }
} }
...@@ -119,4 +119,10 @@ public class JudgmentExport { ...@@ -119,4 +119,10 @@ public class JudgmentExport {
*/ */
@ExcelProperty("报警失效时间") @ExcelProperty("报警失效时间")
private String alarmEndTime; private String alarmEndTime;
/**
* 报警持续时间
*/
@ExcelProperty("报警持续时间")
private String alarmDuration;
} }
...@@ -79,24 +79,11 @@ public class VinWorkOrderNoImportListener extends AnalysisEventListener<VinWorkO ...@@ -79,24 +79,11 @@ public class VinWorkOrderNoImportListener extends AnalysisEventListener<VinWorkO
*/ */
@Override @Override
public void invokeHeadMap(Map<Integer, String> headMap, AnalysisContext context) { public void invokeHeadMap(Map<Integer, String> headMap, AnalysisContext context) {
// 通过反射获取 ExcelProperty 内容比较headMap
log.info(" 解析到一条头数据:{}", JSON.toJSONString(headMap)); log.info(" 解析到一条头数据:{}", JSON.toJSONString(headMap));
// 获取方法上的注解 String col0 = headMap.get(0);
Field[] fields = VinWorkOrderNoImport.class.getDeclaredFields(); if (!"车架号".equals(col0) && !"VIN".equalsIgnoreCase(col0)) {
for (Field field : fields) { log.error("表头不匹配,第一列表头应为 车架号/VIN,当前为:{}", col0);
ExcelProperty property = field.getAnnotation(ExcelProperty.class); throw new AdminException(ResultEnum.IMPORT_FAIL_FILE);
if (property == null) {
continue;
}
String excelPropertyName = property.value()[0];
if (excelPropertyName.equals("导入失败原因")) {
continue;
}
String excelColumnName = headMap.get(property.index());
if (!excelPropertyName.equals(excelColumnName)) {
log.error("存在表头ExcelProperty.{},ExcelColumn.{}不一致情况!", excelPropertyName, excelColumnName);
throw new AdminException(ResultEnum.IMPORT_FAIL_FILE);
}
} }
receiverVehicleIds = vehicleService.receiverVehicleIds(receiverId); receiverVehicleIds = vehicleService.receiverVehicleIds(receiverId);
} }
...@@ -124,10 +111,35 @@ public class VinWorkOrderNoImportListener extends AnalysisEventListener<VinWorkO ...@@ -124,10 +111,35 @@ public class VinWorkOrderNoImportListener extends AnalysisEventListener<VinWorkO
public void saveData() { public void saveData() {
List<VinWorkOrderNoImport> importList = new ArrayList<>(); List<VinWorkOrderNoImport> importList = new ArrayList<>();
list.forEach(woi -> { list.forEach(woi -> {
if (check(woi)) { if (!check(woi)) {
importList.add(woi);
} else {
failList.add(woi); failList.add(woi);
return;
}
List<Vehicle> vehicles = vehicleService.getVehiclesByVinInTenant(woi.getVin());
Map<Long, String> vehicleBizOrderMap = vehicleService.getBizOrderNoMapByVin(woi.getVin());
if (CollectionUtils.isEmpty(vehicles)) {
VinWorkOrderNoImport fail = copyFor(woi, null);
fail.setImportFailReason("当前租户未找到车辆");
failList.add(fail);
return;
}
for (Vehicle vehicle : vehicles) {
if (VehicleSettleFlagEnum.SETTLED.getCode().equals(vehicle.getSettleFlag())) {
VinWorkOrderNoImport fail = copyFor(woi, vehicleBizOrderMap.get(vehicle.getId()));
fail.setImportFailReason("车辆已结清");
failList.add(fail);
continue;
}
boolean accorderHasPermit = vehicleService.checkAccorderPermit(vehicle);
if (!accorderHasPermit) {
VinWorkOrderNoImport fail = copyFor(woi, vehicleBizOrderMap.get(vehicle.getId()));
fail.setImportFailReason("数据权限受限");
failList.add(fail);
continue;
}
VinWorkOrderNoImport ok = copyFor(woi, vehicleBizOrderMap.get(vehicle.getId()));
ok.setVehicleId(vehicle.getId());
importList.add(ok);
} }
}); });
List<VinWorkOrderNoImport> importFailList = vehicleService.batchAccorderVehicle(receiverId, importList, receiverVehicleIds); List<VinWorkOrderNoImport> importFailList = vehicleService.batchAccorderVehicle(receiverId, importList, receiverVehicleIds);
...@@ -144,45 +156,31 @@ public class VinWorkOrderNoImportListener extends AnalysisEventListener<VinWorkO ...@@ -144,45 +156,31 @@ public class VinWorkOrderNoImportListener extends AnalysisEventListener<VinWorkO
* @return * @return
*/ */
public boolean check(VinWorkOrderNoImport vwi) { public boolean check(VinWorkOrderNoImport vwi) {
if (StringUtils.isEmpty(vwi.getVin()) || StringUtils.isEmpty(vwi.getBizOrderNo())) { if (StringUtils.isNotEmpty(vwi.getVin())) {
vwi.setImportFailReason("车架号/业务工单号必填"); vwi.setVin(vwi.getVin().trim().toUpperCase());
}
if (StringUtils.isEmpty(vwi.getVin())) {
vwi.setImportFailReason("VIN 不能为空");
log.warn(vwi.toString()); log.warn(vwi.toString());
return false; return false;
} }
String vkey = vwi.getBizOrderNo() + "-" + vwi.getVin(); String vkey = vwi.getVin();
if (vehicleSet.contains(vkey)) { if (vehicleSet.contains(vkey)) {
vwi.setImportFailReason("重复导入数据"); vwi.setImportFailReason("重复 VIN");
//log.warn(vwi.toString());
return false; return false;
} }
vehicleSet.add(vkey); vehicleSet.add(vkey);
// 2022/3/14 校验数据唯一性
Vehicle vehicle = vehicleService.getBizWorkNoAndVin(vwi.getBizOrderNo(), vwi.getVin());
if (vehicle == null) {
vwi.setImportFailReason("工单车辆不存在");
log.warn(vwi.toString());
return false;
}
if (VehicleSettleFlagEnum.SETTLED.getCode().equals(vehicle.getSettleFlag())) {
vwi.setImportFailReason("工单车辆已结清");
log.warn(vwi.toString());
return false;
}
// 2022/3/14 校验当前用户数据权限
boolean accorderHasPermit = vehicleService.checkAccorderPermit(vehicle);
if (!accorderHasPermit) {
vwi.setImportFailReason("数据权限受限");
log.warn(vwi.toString());
return false;
}
vwi.setVehicleId(vehicle.getId());
return true; return true;
} }
private VinWorkOrderNoImport copyFor(VinWorkOrderNoImport src, String bizOrderNo) {
VinWorkOrderNoImport dst = new VinWorkOrderNoImport();
dst.setVin(src.getVin());
dst.setBizOrderNo(bizOrderNo);
return dst;
}
/** /**
* 最后执行导入 * 最后执行导入
* *
......
...@@ -8,6 +8,7 @@ import cn.com.glsx.admin.modules.remote.RemoteStuJudgeAlarmService; ...@@ -8,6 +8,7 @@ import cn.com.glsx.admin.modules.remote.RemoteStuJudgeAlarmService;
import cn.com.glsx.alarm.services.model.StuJudgeAlarmDto; import cn.com.glsx.alarm.services.model.StuJudgeAlarmDto;
import cn.hutool.core.collection.CollectionUtil; import cn.hutool.core.collection.CollectionUtil;
import cn.hutool.core.util.ObjectUtil; import cn.hutool.core.util.ObjectUtil;
import cn.hutool.core.date.DateUtil;
import com.alibaba.fastjson.JSON; import com.alibaba.fastjson.JSON;
import com.github.pagehelper.PageInfo; import com.github.pagehelper.PageInfo;
import com.glsx.plat.common.utils.StringUtils; import com.glsx.plat.common.utils.StringUtils;
...@@ -41,20 +42,36 @@ public class JudgmentService extends AbstractCommonService { ...@@ -41,20 +42,36 @@ public class JudgmentService extends AbstractCommonService {
* 查询大数据研判数据列表 * 查询大数据研判数据列表
* *
* @param search * @param search
*
* @return * @return
*/ */
public PageInfo findJudgmentList(JudgmentSearch search) { public PageInfo findJudgmentList(JudgmentSearch search) {
long allStart = System.currentTimeMillis();
injectOrgChecked(search); injectOrgChecked(search);
List<JudgmentExport> judgmentList = vehicleMapper.findJudgmentList(search); List<JudgmentExport> judgmentList = vehicleMapper.findJudgmentList(search);
if (CollectionUtil.isEmpty(judgmentList)) { if (CollectionUtil.isEmpty(judgmentList)) {
log.info("judgment.search early-return: baseListEmpty=true, costMs={}", (System.currentTimeMillis() - allStart));
return new PageInfo<>(); return new PageInfo<>();
} }
log.info("查询大数据研判数据列表的条数" + judgmentList.size()); log.info("judgment.search baseListSize={}", judgmentList.size());
List<String> snList = judgmentList.stream().map(JudgmentExport::getSn).collect(Collectors.toList()); List<String> snList = judgmentList.stream().map(JudgmentExport::getSn).collect(Collectors.toList());
PageInfo stuJudgeAlarmListByPage = remoteStuJudgeAlarmService.searchStuJudgeAlarmListByPage(snList, search); long remoteStart = System.currentTimeMillis();
PageInfo stuJudgeAlarmListByPage;
try {
stuJudgeAlarmListByPage = remoteStuJudgeAlarmService.searchStuJudgeAlarmListByPage(snList, search);
} catch (RuntimeException ex) {
log.error("judgment.search remote-call-failed: snSize={}, costMs={}, error={}",
snList != null ? snList.size() : 0, (System.currentTimeMillis() - remoteStart), ex.toString());
throw ex;
}
log.info("judgment.search remote-call-ok: snSize={}, remoteCount={}, costMs={}",
snList != null ? snList.size() : 0,
stuJudgeAlarmListByPage != null && stuJudgeAlarmListByPage.getList() != null ? stuJudgeAlarmListByPage.getList().size() : 0,
(System.currentTimeMillis() - remoteStart));
List<StuJudgeAlarmDto> stuJudgeAlarmList = JSON.parseArray(JSON.toJSONString(stuJudgeAlarmListByPage.getList()), StuJudgeAlarmDto.class); List<StuJudgeAlarmDto> stuJudgeAlarmList = JSON.parseArray(JSON.toJSONString(stuJudgeAlarmListByPage.getList()), StuJudgeAlarmDto.class);
if (CollectionUtil.isEmpty(stuJudgeAlarmList)) { if (CollectionUtil.isEmpty(stuJudgeAlarmList)) {
log.info("judgment.search early-return: remoteListEmpty=true, costMs={}", (System.currentTimeMillis() - allStart));
return new PageInfo<>(); return new PageInfo<>();
} }
...@@ -81,6 +98,32 @@ public class JudgmentService extends AbstractCommonService { ...@@ -81,6 +98,32 @@ public class JudgmentService extends AbstractCommonService {
// 如果警情为生效警情 则将失效时间设备为 -- // 如果警情为生效警情 则将失效时间设备为 --
judgmentExport.setAlarmEndTime("--"); judgmentExport.setAlarmEndTime("--");
} }
// 计算报警持续时间(驶出-进入):显示规则 <1天按小时;≥1天按X天Y小时;任一时间为"--"时显示"--"
if ("--".equals(judgmentExport.getAlarmBeginTime()) || "--".equals(judgmentExport.getAlarmEndTime())) {
judgmentExport.setAlarmDuration("--");
} else {
try {
java.util.Date begin = DateUtil.parse(judgmentExport.getAlarmBeginTime());
java.util.Date end = DateUtil.parse(judgmentExport.getAlarmEndTime());
long diffMs = end.getTime() - begin.getTime();
if (diffMs <= 0) {
judgmentExport.setAlarmDuration("0小时");
} else {
long hours = diffMs / (1000 * 60 * 60);
if (hours < 24) {
judgmentExport.setAlarmDuration(hours + "小时");
} else {
long days = hours / 24;
long remainHours = hours % 24;
judgmentExport.setAlarmDuration(days + "天" + remainHours + "小时");
}
}
} catch (Exception e) {
judgmentExport.setAlarmDuration("--");
}
}
judgmentExport.setAlarmLng(stuJudgeAlarm.getAlarmLng()); judgmentExport.setAlarmLng(stuJudgeAlarm.getAlarmLng());
judgmentExport.setAlarmLat(stuJudgeAlarm.getAlarmLat()); judgmentExport.setAlarmLat(stuJudgeAlarm.getAlarmLat());
judgmentExport.setAlarmAddress(stuJudgeAlarm.getAlarmAddress()); judgmentExport.setAlarmAddress(stuJudgeAlarm.getAlarmAddress());
...@@ -90,20 +133,42 @@ public class JudgmentService extends AbstractCommonService { ...@@ -90,20 +133,42 @@ public class JudgmentService extends AbstractCommonService {
} }
}); });
stuJudgeAlarmListByPage.setList(judgmentExportList); stuJudgeAlarmListByPage.setList(judgmentExportList);
if (log.isDebugEnabled() && CollectionUtil.isNotEmpty(judgmentExportList)) {
JudgmentExport s = judgmentExportList.get(0);
log.debug("judgment.search sample: sn={}, vin={}, alarmType={}, alarmStatus={}",
s.getSn(), s.getVin(), s.getAlarmType(), s.getAlarmStatus());
}
log.info("judgment.search assembledCount={}, totalCostMs={}",
judgmentExportList.size(), (System.currentTimeMillis() - allStart));
return stuJudgeAlarmListByPage; return stuJudgeAlarmListByPage;
} }
public List<JudgmentExport> exportJudgmentList(JudgmentSearch search) { public List<JudgmentExport> exportJudgmentList(JudgmentSearch search) {
long allStart = System.currentTimeMillis();
injectOrgChecked(search); injectOrgChecked(search);
List<JudgmentExport> judgmentList = vehicleMapper.findJudgmentList(search); List<JudgmentExport> judgmentList = vehicleMapper.findJudgmentList(search);
if (ObjectUtil.isNull(judgmentList)) { if (ObjectUtil.isNull(judgmentList)) {
log.info("judgment.export early-return: baseListNull=true, costMs={}", (System.currentTimeMillis() - allStart));
return null; return null;
} }
log.info("查询大数据研判数据列表的条数" + judgmentList.size()); log.info("judgment.export baseListSize={}", judgmentList.size());
List<String> snList = judgmentList.stream().map(JudgmentExport::getSn).collect(Collectors.toList()); List<String> snList = judgmentList.stream().map(JudgmentExport::getSn).collect(Collectors.toList());
List<StuJudgeAlarmDto> stuJudgeAlarmDtoList = remoteStuJudgeAlarmService.searchStuJudgeAlarmDataList(snList, search); long remoteStart = System.currentTimeMillis();
List<StuJudgeAlarmDto> stuJudgeAlarmDtoList;
try {
stuJudgeAlarmDtoList = remoteStuJudgeAlarmService.searchStuJudgeAlarmDataList(snList, search);
} catch (RuntimeException ex) {
log.error("judgment.export remote-call-failed: snSize={}, costMs={}, error={}",
snList != null ? snList.size() : 0, (System.currentTimeMillis() - remoteStart), ex.toString());
throw ex;
}
log.info("judgment.export remote-call-ok: snSize={}, remoteCount={}, costMs={}",
snList != null ? snList.size() : 0,
stuJudgeAlarmDtoList != null ? stuJudgeAlarmDtoList.size() : 0,
(System.currentTimeMillis() - remoteStart));
if (CollectionUtil.isEmpty(stuJudgeAlarmDtoList)) { if (CollectionUtil.isEmpty(stuJudgeAlarmDtoList)) {
log.info("judgment.export early-return: remoteListEmpty=true, costMs={}", (System.currentTimeMillis() - allStart));
return null; return null;
} }
...@@ -131,6 +196,32 @@ public class JudgmentService extends AbstractCommonService { ...@@ -131,6 +196,32 @@ public class JudgmentService extends AbstractCommonService {
// 如果警情为生效警情 则将失效时间设备为 -- // 如果警情为生效警情 则将失效时间设备为 --
judgmentExport.setAlarmEndTime("--"); judgmentExport.setAlarmEndTime("--");
} }
// 计算报警持续时间(驶出-进入):显示规则 <1天按小时;≥1天按X天Y小时;任一时间为"--"时显示"--"
if ("--".equals(judgmentExport.getAlarmBeginTime()) || "--".equals(judgmentExport.getAlarmEndTime())) {
judgmentExport.setAlarmDuration("--");
} else {
try {
java.util.Date begin = DateUtil.parse(judgmentExport.getAlarmBeginTime());
java.util.Date end = DateUtil.parse(judgmentExport.getAlarmEndTime());
long diffMs = end.getTime() - begin.getTime();
if (diffMs <= 0) {
judgmentExport.setAlarmDuration("0小时");
} else {
long hours = diffMs / (1000 * 60 * 60);
if (hours < 24) {
judgmentExport.setAlarmDuration(hours + "小时");
} else {
long days = hours / 24;
long remainHours = hours % 24;
judgmentExport.setAlarmDuration(days + "天" + remainHours + "小时");
}
}
} catch (Exception e) {
judgmentExport.setAlarmDuration("--");
}
}
judgmentExport.setAlarmLng(stuJudgeAlarm.getAlarmLng()); judgmentExport.setAlarmLng(stuJudgeAlarm.getAlarmLng());
judgmentExport.setAlarmLat(stuJudgeAlarm.getAlarmLat()); judgmentExport.setAlarmLat(stuJudgeAlarm.getAlarmLat());
judgmentExport.setAlarmAddress(stuJudgeAlarm.getAlarmAddress()); judgmentExport.setAlarmAddress(stuJudgeAlarm.getAlarmAddress());
...@@ -139,6 +230,13 @@ public class JudgmentService extends AbstractCommonService { ...@@ -139,6 +230,13 @@ public class JudgmentService extends AbstractCommonService {
judgmentExportList.add(judgmentExport); judgmentExportList.add(judgmentExport);
} }
}); });
if (log.isDebugEnabled() && CollectionUtil.isNotEmpty(judgmentExportList)) {
JudgmentExport s = judgmentExportList.get(0);
log.debug("judgment.export sample: sn={}, vin={}, alarmType={}, alarmStatus={}",
s.getSn(), s.getVin(), s.getAlarmType(), s.getAlarmStatus());
}
log.info("judgment.export assembledCount={}, totalCostMs={}",
judgmentExportList.size(), (System.currentTimeMillis() - allStart));
return judgmentExportList; return judgmentExportList;
} }
} }
...@@ -2412,6 +2412,50 @@ public class VehicleService extends AbstractCommonService { ...@@ -2412,6 +2412,50 @@ public class VehicleService extends AbstractCommonService {
} }
/** /**
* 按 VIN 在当前租户/可见范围内查询车辆列表(租户管理员限定本租户,超管不过滤)
*
* @param vin 车架号
* @return 匹配到的车辆列表
*/
public List<Vehicle> getVehiclesByVinInTenant(String vin) {
Long tenantId = null;
if (!ShieldContextHolder.isSuperAdmin()) {
tenantId = ShieldContextHolder.getTenantId();
}
return vehicleMapper.getVehicleListByVinAndTenantId(vin, tenantId);
}
/**
* 按 VIN 在当前租户/可见范围内查询单个车辆(若存在多条则返回首条)
*
* @param vin 车架号
* @return 匹配到的车辆(若存在多条则返回首条)
*/
public Vehicle getVehicleByVinInTenant(String vin) {
List<Vehicle> list = getVehiclesByVinInTenant(vin);
if (CollectionUtils.isEmpty(list)) {
return null;
}
return list.get(0);
}
/**
* 通过 VIN 获取车辆ID -> 业务工单号 映射(批量)
*
* @param vin 车架号
* @return 车辆ID到业务工单号的映射
*/
public Map<Long, String> getBizOrderNoMapByVin(String vin) {
List<LinkVehicleVO> links = workOrderMapper.getLinkVehicleListByVin(vin);
if (CollectionUtils.isEmpty(links)) {
return Collections.emptyMap();
}
return links.stream()
.filter(Objects::nonNull)
.collect(Collectors.toMap(LinkVehicleVO::getVehicleId, LinkVehicleVO::getBizOrderNo, (a, b) -> a));
}
/**
* 检验授权人是否有数据权限(可能页面没刷新导致可见和权限不一致) * 检验授权人是否有数据权限(可能页面没刷新导致可见和权限不一致)
* *
* @param vehicle * @param vehicle
......
  • @wangxw1
    commented
    Owner

    你好,我是资深 Java 开发工程师。针对你提交的关于“虎哥E盾优化需求”的代码变更,我进行了详细的审查。以下是本次代码审查中最关键的三个问题及优化建议:

    一、关键问题与优化建议(仅限 Top 3)

    1. 【性能与稳定性】循环内远程调用与 OOM 风险

      • 问题描述:在 VinWorkOrderNoImportListener.saveData() 方法中,对上传的每一行数据(list.forEach)都进行了 vehicleService.getVehiclesByVinInTenant(vin) 和 getBizOrderNoMapByVin(vin) 的数据库/逻辑查询。若导入文件包含数千条数据,将产生数千次数据库 IO,严重拖慢系统响应并增加数据库压力。此外,JudgmentService 在导出报表时,虽然有远程调用,但未对导出总量进行限制,大数据量下 stuJudgeAlarmDtoList 易引发 OOM。
      • 优化建议:导入逻辑应采用“批量查询 + 内存映射”的模式。先提取 list 中所有的 vin,一次性查询出相关的 Vehicle 和 BizOrderNo 并存储在 Map 中,随后在循环中进行内存匹配。
    2. 【代码规范与质量】重复代码与硬编码逻辑

      • 问题描述:JudgmentService 中的 findJudgmentList 和 exportJudgmentList 方法存在大量完全重复的逻辑,特别是计算“报警持续时间”的 try-catch 块(约 30 行代码),这严重违反了 DRY(Don't Repeat Yourself)原则。此外,计算逻辑中直接使用 1000 * 60 * 60 等魔法值,未利用 TimeUnit 或 Duration 等标准类库。
      • 优化建议:将计算报警时长的逻辑抽象为一个独立的方法(如 calculateAlarmDuration(String begin, String end)),并在两个业务方法中调用。使用 java.time 包处理时间计算,提高可读性。
    3. 【功能健壮性】异常处理与空值风险

      • 问题描述:在 VinWorkOrderNoImportListener.invokeHeadMap 中,代码仅校验了第一列是否为“车架号/VIN”,这种简化校验在用户上传模板列顺序错误或缺失其他必要列时无法及时发现,可能导致后续 invoke 方法解析数据错位。同时,JudgmentService 中对 stuJudgeAlarmListByPage.getList() 的处理依赖于 JSON.toJSONString 的二次转换,若远程接口返回结构变动,此处极易抛出解析异常。
      • 优化建议:恢复或增强对 Excel 表头的完整性校验,确保所有必要字段均存在且索引正确。对于远程返回的对象转换,建议直接使用强类型接收或使用更高效的 BeanUtil.copyToList。

    二、评分明细

    • 功能实现的正确性与健壮性:32/40 分(功能基本实现,但导入逻辑的表头校验弱化,且循环查询可能导致大文件处理超时)
    • 安全性与潜在风险:24/30 分(增加了租户权限校验,但缺乏对导出数据量的阈值控制,存在资源耗尽风险)
    • 最佳实践与可维护性:12/20 分(存在严重的代码重复,计算逻辑未封装,魔法数字较多)
    • 性能与资源利用:3/5 分(日志记录详尽利于排查,但循环 IO 是明显的性能瓶颈)
    • 提交信息质量:5/5 分(提交信息清晰,对应了需求变更点)

    总分:76分

Markdown is supported
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!