上传关联

dev_no_inv
zane 9 months ago
parent c565b37b4f
commit 00ec6eca85

@ -39,19 +39,25 @@ public class RelCodeBatchService extends ServiceImpl<RelCodeBatchMapper, RelCode
*/
@Transactional(rollbackFor = Exception.class)
public void xmlUpload(MultipartFile file) {
String fileName = file.getOriginalFilename();
String suffix = FileUtil.getSuffix(fileName);
if(! "xml".equals(suffix)){
throw new JsonException("上传文件类型错误:"+suffix);
}
log.info(file.getSize()+"文件长度");
try {
String fileName = file.getOriginalFilename();
String suffix = FileUtil.getSuffix(fileName);
if(! "xml".equals(suffix)){
throw new JsonException("仅支持XML文件类型错误"+suffix);
}
log.info(file.getSize()+"文件长度");
if(file.getSize() > 5 * 1024 *1024){
throw new JsonException("上传文件超过5M");
}
List<RelCodeDetail> relCodeDetails = new ArrayList<>();
Document document = XmlUtil.readXML(file.getInputStream());
//获取根
Element rootElement = XmlUtil.getRootElement(document);
//截取Relation
NodeList relation = rootElement.getElementsByTagName("Relation");
if(relation == null){
throw new JsonException("XML文件解析错误");
}
Element relationE = (Element) relation.item(0);
String productCode = relationE.getAttribute("productCode");
String subTypeNo = relationE.getAttribute("subTypeNo");
@ -60,6 +66,9 @@ public class RelCodeBatchService extends ServiceImpl<RelCodeBatchMapper, RelCode
String comment = relationE.getAttribute("comment");
//截取Batch
NodeList batch = rootElement.getElementsByTagName("Batch");
if(batch == null){
throw new JsonException("XML文件解析错误");
}
for (int i = 0; i < batch.getLength(); i++) {
Node batchNode = batch.item(i);
RelCodeBatch relCodeBatch = new RelCodeBatch();

Loading…
Cancel
Save