Browse Source

处理解析文件失败情况

master
luogw 2 weeks ago
parent
commit
c03146ddde
  1. 31
      src/main/java/com/project/information/application/impl/KnowledgePointApplicationServiceImpl.java

31
src/main/java/com/project/information/application/impl/KnowledgePointApplicationServiceImpl.java

@ -14,6 +14,7 @@ import com.project.information.domain.service.InformationBaseService;
import com.project.information.domain.service.KnowledgePointBaseService; import com.project.information.domain.service.KnowledgePointBaseService;
import lombok.extern.slf4j.Slf4j; import lombok.extern.slf4j.Slf4j;
import org.apache.commons.lang3.ObjectUtils; import org.apache.commons.lang3.ObjectUtils;
import org.apache.commons.lang3.StringUtils;
import org.springframework.beans.factory.annotation.Autowired; import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.beans.factory.annotation.Value; import org.springframework.beans.factory.annotation.Value;
import org.springframework.core.io.ByteArrayResource; import org.springframework.core.io.ByteArrayResource;
@ -66,6 +67,8 @@ public class KnowledgePointApplicationServiceImpl implements KnowledgePointAppli
uploadToPython(fileMap.get(id),id); uploadToPython(fileMap.get(id),id);
} catch (Exception e) { } catch (Exception e) {
log.error("文件解析失败:{}", fileMap.get(id).getOriginalFilename(), e); log.error("文件解析失败:{}", fileMap.get(id).getOriginalFilename(), e);
//更新资料状态
updateStatuInformation(null,InformationParseStatusEnum.Fail.getValue(),id);
} }
} }
} }
@ -95,17 +98,17 @@ public class KnowledgePointApplicationServiceImpl implements KnowledgePointAppli
ResponseEntity<String> response = ResponseEntity<String> response =
restTemplate.postForEntity("http://"+analysisHost+":"+analysisPort+analysisUrl, requestEntity, String.class); restTemplate.postForEntity("http://"+analysisHost+":"+analysisPort+analysisUrl, requestEntity, String.class);
log.info("文件 [{}] 解析完成,返回结果:{}", file.getOriginalFilename(), response.getBody()); log.info("文件 [{}] 解析请求成功,返回结果:{}", file.getOriginalFilename(), response.getBody());
List<KnowledgePointEntity> knowledgePointEntities = parseAnalysisResponse(response,id); List<KnowledgePointEntity> knowledgePointEntities = parseAnalysisResponse(response,id);
if(!CollectionUtils.isEmpty(knowledgePointEntities)){ if(!CollectionUtils.isEmpty(knowledgePointEntities)){
knowledgePointBaseService.saveBatch(knowledgePointEntities); knowledgePointBaseService.saveBatch(knowledgePointEntities);
//向资料中冗余pareName字段值 //更新状态
InformationEntity informationEntity = new InformationEntity(); updateStatuInformation(knowledgePointEntities.get(0).getParseName(),InformationParseStatusEnum.Success.getValue(),id);
informationEntity.setId(id); }else{
informationEntity.setParseStatus(InformationParseStatusEnum.Success.getValue()); log.error("获取知识点失败:{}", "不存在知识点");
informationEntity.setParseName(knowledgePointEntities.get(0).getParseName()); //更新状态
informationBaseService.updateById(informationEntity); updateStatuInformation(null,InformationParseStatusEnum.Fail.getValue(),id);
} }
} }
@ -132,7 +135,6 @@ public class KnowledgePointApplicationServiceImpl implements KnowledgePointAppli
if (dataObj instanceof List && ObjectUtils.isNotEmpty(dataObj)) { if (dataObj instanceof List && ObjectUtils.isNotEmpty(dataObj)) {
data = (List<Map<String, Object>>) dataObj; data = (List<Map<String, Object>>) dataObj;
}else{ }else{
log.error("文件解析失败");
return Collections.emptyList(); return Collections.emptyList();
} }
@ -172,4 +174,17 @@ public class KnowledgePointApplicationServiceImpl implements KnowledgePointAppli
return entity; return entity;
}).collect(Collectors.toList()); }).collect(Collectors.toList());
} }
/**
* 更新文件解析状态
*/
private void updateStatuInformation(String pareName,Integer status,Long id){
InformationEntity informationEntity = new InformationEntity();
informationEntity.setId(id);
if (StringUtils.isNotBlank(pareName)){
informationEntity.setParseName(pareName);
}
informationEntity.setParseStatus(status);
informationBaseService.updateById(informationEntity);
}
} }

Loading…
Cancel
Save