lxw
2021-03-12 be51e2f3f6bfda8bc14dba03a178eaa708f457dc
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
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;
    }
}