Skip to content
This repository was archived by the owner on Apr 17, 2023. It is now read-only.

Commit 2c7dd88

Browse files
committed
fix(扫描结果): 修复扫描结果为空时状态报错问题
1 parent ca3f14f commit 2c7dd88

3 files changed

Lines changed: 23 additions & 19 deletions

File tree

backend/src/main/java/io/riskscanner/service/OrderService.java

Lines changed: 21 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -626,7 +626,7 @@ public Integer insertScanHistory (Account account) {
626626
return scanHistoryMapper.insertSelective(history);
627627
}
628628

629-
public void insertTaskHistory (Task task, Integer scanId) {
629+
public void insertTaskHistory (Task task, Integer scanId) throws Exception {
630630
ScanTaskHistoryExample example = new ScanTaskHistoryExample();
631631
example.createCriteria().andTaskIdEqualTo(task.getId()).andScanIdEqualTo(scanId);
632632
List<ScanTaskHistory> list = scanTaskHistoryMapper.selectByExample(example);
@@ -641,22 +641,26 @@ public void insertTaskHistory (Task task, Integer scanId) {
641641
}
642642
}
643643

644-
public void updateTaskHistory (Task task, ScanTaskHistoryExample example) {
645-
TaskItemResourceExample taskItemResourceExample = new TaskItemResourceExample();
646-
taskItemResourceExample.createCriteria().andTaskIdEqualTo(task.getId());
647-
List<TaskItemResourceWithBLOBs> taskItemResources = taskItemResourceMapper.selectByExampleWithBLOBs(taskItemResourceExample);
648-
JSONArray jsonArray = new JSONArray();
649-
taskItemResources.stream().forEach(item ->{
650-
ResourceWithBLOBs resource = resourceMapper.selectByPrimaryKey(item.getResourceId());
651-
if(resource!=null) jsonArray.addAll(JSON.parseArray(resource.getResources()));
652-
});
653-
ScanTaskHistory history = new ScanTaskHistory();
654-
history.setResourcesSum(task.getResourcesSum()!=null?task.getResourcesSum():0);
655-
history.setReturnSum(task.getReturnSum()!=null?task.getReturnSum():0);
656-
history.setScanScore(calculateScore(accountMapper.selectByPrimaryKey(task.getAccountId()), task));
657-
history.setOperation("修改历史合规扫描");
658-
history.setOutput(jsonArray.toJSONString());
659-
scanTaskHistoryMapper.updateByExampleSelective(history, example);
644+
public void updateTaskHistory (Task task, ScanTaskHistoryExample example) throws Exception {
645+
try{
646+
TaskItemResourceExample taskItemResourceExample = new TaskItemResourceExample();
647+
taskItemResourceExample.createCriteria().andTaskIdEqualTo(task.getId());
648+
List<TaskItemResourceWithBLOBs> taskItemResources = taskItemResourceMapper.selectByExampleWithBLOBs(taskItemResourceExample);
649+
JSONArray jsonArray = new JSONArray();
650+
taskItemResources.forEach(item ->{
651+
ResourceWithBLOBs resource = resourceMapper.selectByPrimaryKey(item.getResourceId());
652+
if(resource!=null) jsonArray.addAll(JSON.parseArray(!resource.getResources().isEmpty()?resource.getResources():"[]"));
653+
});
654+
ScanTaskHistory history = new ScanTaskHistory();
655+
history.setResourcesSum(task.getResourcesSum()!=null?task.getResourcesSum():0);
656+
history.setReturnSum(task.getReturnSum()!=null?task.getReturnSum():0);
657+
history.setScanScore(calculateScore(accountMapper.selectByPrimaryKey(task.getAccountId()), task));
658+
history.setOperation("修改历史合规扫描");
659+
history.setOutput(jsonArray.toJSONString());
660+
scanTaskHistoryMapper.updateByExampleSelective(history, example);
661+
}catch (Exception e){
662+
throw new Exception(e.getMessage());
663+
}
660664
}
661665

662666
public void createQuartzTask(String quartzTaskId) {

backend/src/main/java/io/riskscanner/service/ResourceCreateService.java

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -104,7 +104,7 @@ public void handleTasks() {
104104
}
105105
}
106106

107-
public void handleTask(Task task) {
107+
public void handleTask(Task task) throws Exception {
108108
String taskId = task.getId();
109109
int i = orderService.updateTaskStatus(taskId, TaskConstants.TASK_STATUS.APPROVED.toString(), TaskConstants.TASK_STATUS.PROCESSING.toString());
110110
if (i == 0) {

frontend/src/business/components/resource/home/Result.vue

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -130,7 +130,7 @@
130130
<span :key="tag.tagKey" v-if="scope.row.ruleTags.indexOf(tag.tagKey) > -1"> {{ tag.tagName }}</span>
131131
</span>
132132
</template>
133-
<span v-if="!!scope.row.resourceTypes && scope.row.resourceTypes.indexOf('.')===-1"> [{{ scope.row.resourceTypes }}]</span>
133+
<span v-if="!!scope.row.resourceTypes && scope.row.resourceTypes.indexOf('.')===-1"> {{ scope.row.resourceTypes }}</span>
134134
<span v-if="!!scope.row.resourceTypes && scope.row.resourceTypes.indexOf('.')>-1">
135135
<template v-for="type in resourceTypes" >
136136
<span :key="type.value" v-if="scope.row.resourceTypes">

0 commit comments

Comments
 (0)