Commit 9dce97e6 authored by litengwei's avatar litengwei

中心检测问题处理

parent 2f8eb8c8
package com.yeejoin.equipmanage.common.utils;
import org.apache.tika.io.FilenameUtils;
import javax.xml.bind.JAXBContext;
import javax.xml.bind.Unmarshaller;
import java.io.Reader;
import java.io.StringReader;
/**
* @author keyong
......@@ -17,18 +12,6 @@ import java.io.StringReader;
*/
public class XmlBuilder {
public static Object xmlStrToObject(Class<?> clazz, String xmlStr) throws Exception {
Object obj = null;
StringReader reader = null;
JAXBContext context = JAXBContext.newInstance(clazz);
Unmarshaller un = context.createUnmarshaller();
un.setProperty("com.sun.xml.bind.v2.runtime.property.DisableExternalEntities", true); // 禁用外部实体解析
reader = new StringReader(FilenameUtils.normalize(xmlStr));
obj = un.unmarshal(reader);
if (null != reader) {
reader.close();
}
return obj;
}
}
......@@ -15,17 +15,17 @@ import java.util.List;
*/
public interface ICarLonAndLatDataService {
/**
* 获取经纬list
* @return
* @throws Exception
*/
List<LonAndLatEntityVo> listCarLonAndLat() throws Exception;
/**
* 获取车辆速度和路线
* @return
* @throws Exception
*/
List<SpeedAndTimeEntityVo> listCarSpeedAndGround() throws Exception;
// /**
// * 获取经纬list
// * @return
// * @throws Exception
// */
// List<LonAndLatEntityVo> listCarLonAndLat() throws Exception;
//
// /**
// * 获取车辆速度和路线
// * @return
// * @throws Exception
// */
// List<SpeedAndTimeEntityVo> listCarSpeedAndGround() throws Exception;
}
package com.yeejoin.equipmanage.service.impl;
import com.yeejoin.equipmanage.common.utils.XmlBuilder;
import com.yeejoin.equipmanage.common.vo.LonAndLatEntityVo;
import com.yeejoin.equipmanage.common.vo.LonAndLatList;
import com.yeejoin.equipmanage.common.vo.SpeedAndTimeEntityVo;
import com.yeejoin.equipmanage.common.vo.SpeedAndTimeList;
import com.yeejoin.equipmanage.service.ICarLonAndLatDataService;
import org.springframework.core.io.ClassPathResource;
import org.springframework.core.io.Resource;
......@@ -27,40 +23,5 @@ import java.util.List;
@Service
public class CarLonAndLatDataServiceImpl implements ICarLonAndLatDataService {
@Override
public List<LonAndLatEntityVo> listCarLonAndLat() throws Exception {
Resource resource = new ClassPathResource("car-history-track-data.xml");
try (InputStreamReader inputStreamReader = new InputStreamReader(resource.getInputStream());
BufferedReader br = new BufferedReader(inputStreamReader);) {
StringBuffer buffer = new StringBuffer();
String line = "";
while((line = br.readLine())!=null)
{
buffer.append(line);
}
LonAndLatList list = (LonAndLatList) XmlBuilder.xmlStrToObject(LonAndLatList.class, buffer.toString());
return list.getDataList();
} catch (Exception e) {
e.printStackTrace();
}
return new ArrayList<>();
}
@Override
public List<SpeedAndTimeEntityVo> listCarSpeedAndGround() throws Exception {
Resource resource = new ClassPathResource("car-history-trend-data.xml");
try (InputStreamReader inputStreamReader = new InputStreamReader(resource.getInputStream());
BufferedReader br = new BufferedReader(inputStreamReader);) {
StringBuffer buffer = new StringBuffer();
String line = "";
while ((line = br.readLine()) != null) {
buffer.append(line);
}
SpeedAndTimeList list = (SpeedAndTimeList) XmlBuilder.xmlStrToObject(SpeedAndTimeList.class, buffer.toString());
return list.getDataList();
} catch (Exception e) {
e.printStackTrace();
}
return new ArrayList<>();
}
}
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment