| | |
| | | package com.whyc.service; |
| | | |
| | | import com.whyc.dto.ActionUtil; |
| | | import com.whyc.dto.FileParamToXml; |
| | | import com.whyc.dto.Response; |
| | | import com.whyc.dto.XmlFileOpreate; |
| | | import com.whyc.dto.*; |
| | | import com.whyc.pojo.FileInfo; |
| | | import com.whyc.pojo.FileParam; |
| | | import org.springframework.stereotype.Service; |
| | |
| | | import java.io.File; |
| | | import java.lang.reflect.Field; |
| | | import java.text.ParseException; |
| | | import java.util.ArrayList; |
| | | import java.util.HashMap; |
| | | import java.util.List; |
| | | import java.util.Map; |
| | | |
| | | @Service |
| | |
| | | //解析xml文件 |
| | | public Response getXmlValue(String filePath) { |
| | | File file=new File(filePath); |
| | | List list=new ArrayList(); |
| | | if(file.exists()){ |
| | | if(file.isFile()){ |
| | | FileInfo fileInfo=XmlFileOpreate.readXml(filePath); |
| | | return new Response().setII(1,fileInfo!=null,fileInfo,"返回解析数据"); |
| | | fileInfo.setFileUrl(filePath); |
| | | list.add(fileInfo); |
| | | }else{ |
| | | //3.如果是文件夹:获取文件夹下所有的文件 |
| | | List<File> allFile= FileOpreate.getAllFile(filePath); |
| | | if(allFile!=null&&allFile.size()>0){ |
| | | for (File f:allFile){ |
| | | if(!f.getName().contains(".xml")){ |
| | | continue; |
| | | } |
| | | FileInfo fileInfo=XmlFileOpreate.readXml(f.getPath()); |
| | | fileInfo.setFileUrl(f.getPath()); |
| | | list.add(fileInfo); |
| | | } |
| | | } |
| | | } |
| | | return new Response().setII(1,list.size()>0,list,"返回解析数据"); |
| | | }else{ |
| | | return new Response().set(1,false,"文件路径不正确"); |
| | | } |