package com.fgkj.Impl;
|
|
import java.io.BufferedReader;
|
import java.io.File;
|
import java.io.FileNotFoundException;
|
import java.io.FileReader;
|
import java.io.IOException;
|
import java.io.InputStreamReader;
|
import java.io.LineNumberReader;
|
import java.sql.ResultSet;
|
import java.util.ArrayList;
|
import java.util.List;
|
|
import javax.servlet.ServletContext;
|
|
import com.csvreader.CsvReader;
|
import com.fgkj.action.ActionUtil;
|
import com.fgkj.db.BaseDAO;
|
import com.fgkj.db.CallBack;
|
import com.fgkj.pojo.Dev_Vol;
|
import com.fgkj.service.Dev_VolService;
|
|
public class Dev_VolImpl implements BaseDAO,CallBack{
|
|
@Override
|
public List getResults(ResultSet rs) {
|
// TODO Auto-generated method stub
|
return null;
|
}
|
|
@Override
|
public boolean add(Object obj) {
|
// TODO Auto-generated method stub
|
return false;
|
}
|
|
@Override
|
public boolean update(Object obj) {
|
// TODO Auto-generated method stub
|
return false;
|
}
|
|
@Override
|
public boolean del(Object obj) {
|
// TODO Auto-generated method stub
|
return false;
|
}
|
//读取全图
|
@Override
|
public List searchAll() {
|
String filePath=getfilePath(1);
|
List list=new ArrayList();
|
try {
|
|
File csv=new File(filePath);
|
csv.setReadable(true);//设置可读
|
csv.setWritable(true);//设置可写
|
LineNumberReader br = new LineNumberReader(new FileReader(csv));
|
String line = "";
|
String everyLine = "";
|
try {
|
while ((line = br.readLine()) != null) // 读取到的内容给line变量
|
{ if(br.getLineNumber() >= 1500&&br.getLineNumber() <= 101500) {
|
everyLine = line;
|
list.add(changeStrToDev_Vol(everyLine,1));
|
}
|
}
|
System.out.println("csv表格中所有行数:" + list.size());
|
} catch (IOException e) {
|
e.printStackTrace();
|
}
|
} catch (Exception e) {
|
System.out.println(e);
|
}
|
return list;
|
}
|
//读取全图
|
@Override
|
public List serchByCondition(Object obj) {
|
Dev_Vol dv=(com.fgkj.pojo.Dev_Vol) obj;
|
String filePath=getfilePath(1);
|
List list=new ArrayList();
|
try {
|
|
File csv=new File(filePath);
|
csv.setReadable(true);//设置可读
|
csv.setWritable(true);//设置可写
|
LineNumberReader br = new LineNumberReader(new FileReader(csv));
|
String line = "";
|
String everyLine = "";
|
try {
|
while ((line = br.readLine()) != null) // 读取到的内容给line变量
|
{ if(br.getLineNumber() >= dv.getStartNum()&&br.getLineNumber() <= dv.getStopNum()) {
|
everyLine = line;
|
list.add(changeStrToDev_Vol(everyLine,1));
|
}
|
}
|
System.out.println("csv表格中所有行数:" + list.size());
|
} catch (IOException e) {
|
e.printStackTrace();
|
}
|
} catch (Exception e) {
|
System.out.println(e);
|
}
|
return list;
|
}
|
|
@Override
|
public List serchByInfo(Object obj) {
|
// TODO Auto-generated method stub
|
return null;
|
}
|
//读取缩略图
|
public List searchAbbreviation(){
|
String filePath=getfilePath(0);
|
List list=new ArrayList();
|
try {
|
/*
|
* // 创建CSV读对象 CsvReader csvReader = new CsvReader(filePath);
|
* System.out.println(5555); // 读表头 //csvReader.readHeaders(); int i=0;
|
* System.out.println(333); while (csvReader.readRecord()&&i<100){ // 读一整行
|
* //System.out.println(csvReader.getRawRecord()); // 读这行的某一列 //
|
* System.out.println(csvReader.get("Link")); Dev_Vol
|
* dv=changeStrToDev_Vol(csvReader.getRawRecord()); list.add(dv); i++; }
|
*/
|
File csv=new File(filePath);
|
csv.setReadable(true);//设置可读
|
csv.setWritable(true);//设置可写
|
// BufferedReader br = null;
|
// try {
|
// br = new BufferedReader(new FileReader(csv));
|
// } catch (FileNotFoundException e) {
|
// e.printStackTrace();
|
// }
|
LineNumberReader br = new LineNumberReader(new FileReader(csv));
|
String line = "";
|
String everyLine = "";
|
try {
|
while ((line = br.readLine()) != null) // 读取到的内容给line变量
|
{
|
everyLine = line;
|
list.add(changeStrToDev_Vol(everyLine,0));
|
}
|
System.out.println("csv表格中所有行数:" + list.size());
|
} catch (IOException e) {
|
e.printStackTrace();
|
}
|
} catch (Exception e) {
|
System.out.println(e);
|
}
|
return list;
|
}
|
//将字符串转换成对象
|
public static Dev_Vol changeStrToDev_Vol(String volStr,int flag) {
|
String[] vol=volStr.split(",");
|
Dev_Vol dv=new Dev_Vol();
|
if(flag==0) {
|
dv.setDateStr(vol[0]);
|
dv.setDev_vol(Double.valueOf(vol[1]));
|
dv.setNum((int)Double.parseDouble(vol[2]));
|
}else{
|
dv.setDateStr(vol[0]);
|
dv.setDev_vol(Double.valueOf(vol[1]));
|
}
|
|
return dv;
|
}
|
//读取文件路径
|
public static String getfilePath(int flag) {
|
//String path=this.getClass().getResource("/").getPath();
|
String loadpath =ActionUtil.getSession().getServletContext().getRealPath("/");
|
//String filePath = "D:/apache-tomcat-7.0.105/webapps/Dev_FastAcquisition/WEB-INF/电压2020_03_04_10_00_dgls.csv";
|
//String str = new File(loadpath).getAbsolutePath();
|
//System.out.println(str);
|
String str=loadpath.substring(0, loadpath.lastIndexOf("Dev_FastAcquisition"));
|
//System.out.println(str);
|
String filePath=null;
|
if(flag==0) {
|
filePath=str+File.separator+"csv"+File.separator+"电压2020_03_04_10_00_dgls.csv";
|
}else {
|
filePath=str+File.separator+"csv"+File.separator+"电压2020_03_04_10_00.csv";
|
}
|
return filePath;
|
}
|
}
|