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

Commit

Permalink
fix(扫描结果): 修复扫描结果为空时状态报错问题
Browse files Browse the repository at this point in the history
  • Loading branch information
maguohao2017 committed Sep 29, 2021
1 parent ca3f14f commit 2c7dd88
Show file tree
Hide file tree
Showing 3 changed files with 23 additions and 19 deletions.
38 changes: 21 additions & 17 deletions backend/src/main/java/io/riskscanner/service/OrderService.java
Original file line number Diff line number Diff line change
Expand Up @@ -626,7 +626,7 @@ public Integer insertScanHistory (Account account) {
return scanHistoryMapper.insertSelective(history);
}

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

public void updateTaskHistory (Task task, ScanTaskHistoryExample example) {
TaskItemResourceExample taskItemResourceExample = new TaskItemResourceExample();
taskItemResourceExample.createCriteria().andTaskIdEqualTo(task.getId());
List<TaskItemResourceWithBLOBs> taskItemResources = taskItemResourceMapper.selectByExampleWithBLOBs(taskItemResourceExample);
JSONArray jsonArray = new JSONArray();
taskItemResources.stream().forEach(item ->{
ResourceWithBLOBs resource = resourceMapper.selectByPrimaryKey(item.getResourceId());
if(resource!=null) jsonArray.addAll(JSON.parseArray(resource.getResources()));
});
ScanTaskHistory history = new ScanTaskHistory();
history.setResourcesSum(task.getResourcesSum()!=null?task.getResourcesSum():0);
history.setReturnSum(task.getReturnSum()!=null?task.getReturnSum():0);
history.setScanScore(calculateScore(accountMapper.selectByPrimaryKey(task.getAccountId()), task));
history.setOperation("修改历史合规扫描");
history.setOutput(jsonArray.toJSONString());
scanTaskHistoryMapper.updateByExampleSelective(history, example);
public void updateTaskHistory (Task task, ScanTaskHistoryExample example) throws Exception {
try{
TaskItemResourceExample taskItemResourceExample = new TaskItemResourceExample();
taskItemResourceExample.createCriteria().andTaskIdEqualTo(task.getId());
List<TaskItemResourceWithBLOBs> taskItemResources = taskItemResourceMapper.selectByExampleWithBLOBs(taskItemResourceExample);
JSONArray jsonArray = new JSONArray();
taskItemResources.forEach(item ->{
ResourceWithBLOBs resource = resourceMapper.selectByPrimaryKey(item.getResourceId());
if(resource!=null) jsonArray.addAll(JSON.parseArray(!resource.getResources().isEmpty()?resource.getResources():"[]"));
});
ScanTaskHistory history = new ScanTaskHistory();
history.setResourcesSum(task.getResourcesSum()!=null?task.getResourcesSum():0);
history.setReturnSum(task.getReturnSum()!=null?task.getReturnSum():0);
history.setScanScore(calculateScore(accountMapper.selectByPrimaryKey(task.getAccountId()), task));
history.setOperation("修改历史合规扫描");
history.setOutput(jsonArray.toJSONString());
scanTaskHistoryMapper.updateByExampleSelective(history, example);
}catch (Exception e){
throw new Exception(e.getMessage());
}
}

public void createQuartzTask(String quartzTaskId) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -104,7 +104,7 @@ public void handleTasks() {
}
}

public void handleTask(Task task) {
public void handleTask(Task task) throws Exception {
String taskId = task.getId();
int i = orderService.updateTaskStatus(taskId, TaskConstants.TASK_STATUS.APPROVED.toString(), TaskConstants.TASK_STATUS.PROCESSING.toString());
if (i == 0) {
Expand Down
2 changes: 1 addition & 1 deletion frontend/src/business/components/resource/home/Result.vue
Original file line number Diff line number Diff line change
Expand Up @@ -130,7 +130,7 @@
<span :key="tag.tagKey" v-if="scope.row.ruleTags.indexOf(tag.tagKey) > -1"> {{ tag.tagName }}</span>
</span>
</template>
<span v-if="!!scope.row.resourceTypes && scope.row.resourceTypes.indexOf('.')===-1"> [{{ scope.row.resourceTypes }}]</span>
<span v-if="!!scope.row.resourceTypes && scope.row.resourceTypes.indexOf('.')===-1"> {{ scope.row.resourceTypes }}</span>
<span v-if="!!scope.row.resourceTypes && scope.row.resourceTypes.indexOf('.')>-1">
<template v-for="type in resourceTypes" >
<span :key="type.value" v-if="scope.row.resourceTypes">
Expand Down

0 comments on commit 2c7dd88

Please sign in to comment.