Commit bd9f9aeb972a28cbdf69bc3f870694fb1b48507d

Authored by 娄高锋
1 parent 74d076bc

导入表数据的方法

src/main/java/com/bsth/service/oil/impl/CwjyServiceImpl.java
1 -package com.bsth.service.oil.impl;  
2 -  
3 -import java.io.File;  
4 -import java.io.FileInputStream;  
5 -import java.sql.ResultSet;  
6 -import java.sql.SQLException;  
7 -import java.text.DecimalFormat;  
8 -import java.text.ParseException;  
9 -import java.text.SimpleDateFormat;  
10 -import java.util.ArrayList;  
11 -import java.util.Arrays;  
12 -import java.util.Date;  
13 -import java.util.HashMap;  
14 -import java.util.List;  
15 -import java.util.Map;  
16 -  
17 -import javax.transaction.Transactional;  
18 -  
19 -import org.apache.commons.lang3.StringEscapeUtils;  
20 -import org.apache.poi.hssf.usermodel.HSSFCell;  
21 -import org.apache.poi.hssf.usermodel.HSSFRow;  
22 -import org.apache.poi.hssf.usermodel.HSSFSheet;  
23 -import org.apache.poi.hssf.usermodel.HSSFWorkbook;  
24 -import org.apache.poi.poifs.filesystem.POIFSFileSystem;  
25 -import org.slf4j.Logger;  
26 -import org.slf4j.LoggerFactory;  
27 -import org.springframework.beans.factory.annotation.Autowired;  
28 -import org.springframework.jdbc.core.JdbcTemplate;  
29 -import org.springframework.jdbc.core.RowMapper;  
30 -import org.springframework.stereotype.Service;  
31 -  
32 -import com.alibaba.fastjson.JSONArray;  
33 -import com.alibaba.fastjson.JSONObject;  
34 -import com.bsth.common.ResponseCode;  
35 -import com.bsth.data.BasicData;  
36 -import com.bsth.entity.oil.Cwjy;  
37 -import com.bsth.entity.oil.Cyl;  
38 -import com.bsth.entity.oil.Ylb;  
39 -import com.bsth.entity.oil.Ylxxb;  
40 -import com.bsth.repository.oil.CwjyRepository;  
41 -import com.bsth.repository.oil.YlxxbRepository;  
42 -import com.bsth.service.impl.BaseServiceImpl;  
43 -import com.bsth.service.oil.CwjyService;  
44 -import com.bsth.util.Arith;  
45 -import com.bsth.util.PageHelper;  
46 -import com.bsth.util.PageObject;  
47 -  
48 -@Service  
49 -public class CwjyServiceImpl extends BaseServiceImpl<Cwjy,Integer> implements CwjyService  
50 -{  
51 - @Autowired  
52 - CwjyRepository repository;  
53 - @Autowired  
54 - YlxxbRepository ylxxbRepository;  
55 -  
56 - @Autowired  
57 - JdbcTemplate jdbcTemplate;  
58 - Logger logger = LoggerFactory.getLogger(this.getClass());  
59 - /*@SuppressWarnings("unchecked")  
60 - public PageObject<Ylxxb> Pagequery(Map<String, Object> map) {  
61 - int page=Integer.parseInt(map.get("page").toString());  
62 - SimpleDateFormat sdf=new SimpleDateFormat("yyyy-MM-dd");  
63 -  
64 - String rq=map.get("rq").toString();  
65 - String nbbm="";  
66 - if(map.get("nbbh")!=null){  
67 - nbbm=map.get("nbbh").toString();  
68 - }  
69 -  
70 - Object gsdmIn=map.get("gsdm_in");  
71 - Object fgsdmIn=map.get("fgsdm_in");  
72 - String addSql="";  
73 - String gsdmLike="";  
74 - String fgsdmLike="";  
75 -  
76 - //选择了公司  
77 - if(gsdmIn==null){  
78 - gsdmLike=map.get("gsdm_like").toString();  
79 - addSql += " and a.gsdm = '"+gsdmLike+ "' ";  
80 -  
81 - //选择了分公司  
82 - if(fgsdmIn==null){  
83 - fgsdmLike=map.get("fgsdm_like").toString();;  
84 - addSql += " and a.fgsdm = '"+fgsdmLike+ "' ";  
85 - }else{  
86 - String fgsdmIns[]= fgsdmIn.toString().split(",");  
87 - addSql +=" and a.fgsdm in (";  
88 - for(int i=0;i<fgsdmIns.length;i++){  
89 - addSql +="'"+fgsdmIns[i]+"'";  
90 - if(i<fgsdmIns.length-1){  
91 - addSql +=",";  
92 - }  
93 - }  
94 - addSql +=")";  
95 - }  
96 - }else{  
97 - //没有选择公司 (分公司也没有选择)  
98 - String gsdmIns[]=gsdmIn.toString().split(",");  
99 - addSql += " and a.gsdm in (";  
100 - for(int i=0;i<gsdmIns.length;i++){  
101 - addSql +="'" +gsdmIns[i]+"'";  
102 - if(i<gsdmIns.length-1){  
103 - addSql+=",";  
104 - }  
105 - }  
106 - addSql +=")";  
107 - String fgsdmIns[]= fgsdmIn.toString().split(",");  
108 - addSql +=" and a.fgsdm in (";  
109 - for(int i=0;i<fgsdmIns.length;i++){  
110 - addSql +="'"+fgsdmIns[i]+"'";  
111 - if(i<fgsdmIns.length-1){  
112 - addSql +=",";  
113 - }  
114 - }  
115 - addSql +=")";  
116 -  
117 -  
118 - }  
119 - String countSql="SELECT ifnull(count(*),0) as countTs FROM bsth_c_cwjy a "+  
120 - " left join ( select * from bsth_c_ylxxb b where to_days(b.yyrq)=to_days('"+rq+"') and jylx=1) b " +  
121 - " on a.nbbm=b.nbbm left join (select nbbm,group_concat(jsy) as jsy "  
122 - + "from bsth_c_ylb where to_days(rq)= to_days('"+rq+"' ) group by nbbm "+  
123 - " ) c on a.nbbm=c.nbbm where a.nbbm like '%"+nbbm+"%' " +addSql ;  
124 - int listsize=jdbcTemplate.queryForObject(countSql, Integer.class);  
125 - // TODO Auto-generated method stub  
126 - String sql="SELECT a.gsdm as gsdm,a.fgsdm as fgsdm,a.nbbm as nbbm,b.jsy as jsy,b.jzl as jzl ,b.stationid as stationid,"  
127 - + "b.nylx as nylx,b.yj as yj,b.bz as bz,c.jsy as ldgh FROM bsth_c_cwjy a "+  
128 - " left join ( select * from bsth_c_ylxxb b where to_days(b.yyrq)=to_days('"+rq+"') and jylx=1) b " +  
129 - " on a.nbbm=b.nbbm left join (select nbbm,group_concat(jsy) as jsy "  
130 - + "from bsth_c_ylb where to_days(rq)= to_days('"+rq+"' ) group by nbbm "+  
131 - " ) c on a.nbbm=c.nbbm where a.nbbm like '%"+nbbm+"%' " +addSql+ " limit "+page*10+","+10;  
132 -  
133 -  
134 - List<Ylxxb> yList= jdbcTemplate.query(sql,  
135 - new RowMapper<Ylxxb>(){  
136 - @Override  
137 - public Ylxxb mapRow(ResultSet rs, int rowNum) throws SQLException {  
138 - Ylxxb t=new Ylxxb();  
139 - t.setGsdm(rs.getString("gsdm"));  
140 - t.setFgsdm(rs.getString("fgsdm"));  
141 - t.setNbbm(rs.getString("nbbm"));  
142 - t.setJsy(rs.getString("jsy"));  
143 - t.setJzl(rs.getDouble("jzl"));  
144 - t.setStationid(rs.getString("stationid"));  
145 - t.setNylx(rs.getInt("nylx"));  
146 - t.setYj(rs.getDouble("yj"));  
147 - t.setBz(rs.getString("bz"));  
148 - t.setLdgh(rs.getString("ldgh"));  
149 - return t;  
150 - }  
151 - });  
152 - List<Object[]> list=repository.obtainCwjycl(rq,nbbm);  
153 - for (int i = 0; i < list.size(); i++) {  
154 - Ylxxb y=new Ylxxb();  
155 - y.setGsdm(list.get(i)[0]==null?"":list.get(i)[0].toString());  
156 - y.setNbbm(list.get(i)[1]==null?"":list.get(i)[1].toString());  
157 - y.setJsy(list.get(i)[2]==null?"":list.get(i)[2].toString());  
158 - y.setJzl(list.get(i)[3]==null?0.0:Double.parseDouble(list.get(i)[3].toString()));  
159 - y.setStationid(list.get(i)[4]==null?"":list.get(i)[4].toString());  
160 - y.setNylx(list.get(i)[5]==null?0:Integer.parseInt(list.get(i)[5].toString()));  
161 - y.setYj(list.get(i)[6]==null?0.0:Double.parseDouble(list.get(i)[6].toString()));  
162 - y.setBz(list.get(i)[7]==null?"":list.get(i)[7].toString());  
163 - y.setLdgh(list.get(i)[8]==null?"":list.get(i)[8].toString());  
164 - try {  
165 - y.setYyrq(sdf.parse(rq));  
166 - } catch (ParseException e) {  
167 - // TODO Auto-generated catch block  
168 - e.printStackTrace();  
169 - }  
170 - yList.add(y);  
171 - }  
172 - PageHelper pageHelper = new PageHelper(listsize, map);  
173 - pageHelper.getMap();  
174 - PageObject<Ylxxb> pageObject=pageHelper.getPageObject();  
175 - pageObject.setDataList(yList);  
176 - return pageObject;  
177 - }*/  
178 -  
179 - @Override  
180 - public Ylxxb bynbbm(Map<String, Object> map) {  
181 - // TODO Auto-generated method stub  
182 - // TODO Auto-generated method stub  
183 - SimpleDateFormat sdf = new SimpleDateFormat("yyyy-MM-dd");  
184 - String rq = map.get("rq").toString();  
185 - String nbbm = "";  
186 - if (map.get("nbbm") != null) {  
187 - nbbm = map.get("nbbm").toString();  
188 - }  
189 - List<Object[]> list = repository.obtainCwjycl(rq, nbbm);  
190 - Ylxxb y = new Ylxxb();  
191 - if (list.size() > 0) {  
192 - y.setGsdm(list.get(0)[0] == null ? "" : list.get(0)[0].toString());  
193 - y.setNbbm(list.get(0)[1] == null ? "" : list.get(0)[1].toString());  
194 - y.setJsy(list.get(0)[2] == null ? "" : list.get(0)[2].toString());  
195 - y.setJzl(list.get(0)[3] == null ? 0.0 : Double.parseDouble(list.get(0)[3].toString()));  
196 - y.setStationid(list.get(0)[4] == null ? "" : list.get(0)[4].toString());  
197 - y.setNylx(list.get(0)[5] == null ? 0 : Integer.parseInt(list.get(0)[5].toString()));  
198 - y.setYj(list.get(0)[6] == null ? 0.0 : Double.parseDouble(list.get(0)[6].toString()));  
199 - y.setBz(list.get(0)[7] == null ? "" : list.get(0)[7].toString());  
200 - y.setLdgh(list.get(0)[8] == null ? "" : list.get(0)[8].toString());  
201 - try {  
202 - y.setYyrq(sdf.parse(rq));  
203 - } catch (ParseException e) {  
204 - // TODO Auto-generated catch block  
205 - e.printStackTrace();  
206 - }  
207 - }  
208 - return y;  
209 - }  
210 -  
211 - @Transactional  
212 - @Override  
213 - public Map<String, Object> savejzl(Map<String, Object> maps) throws Exception {  
214 - // TODO Auto-generated method stub  
215 - Map<String, Object> map=new HashMap<String,Object>();  
216 - try {  
217 - SimpleDateFormat sdf = new SimpleDateFormat("yyyy-MM-dd");  
218 -// String rq = sdf.format(t.getYyrq());  
219 -// String nbbm=t.getNbbm();  
220 -// List<Ylxxb> yList=ylxxbRepository.obtainYlxx2(rq,nbbm);  
221 -// if(yList.size()>0){  
222 -// t.setId(yList.get(0).getId());  
223 -// ylxxbRepository.save(t);  
224 -// }else{  
225 -// ylxxbRepository.save(t);  
226 -// }  
227 - String gsbm=maps.get("gsbm").toString();  
228 - String fgsbm=maps.get("fgsbm").toString();  
229 - String rq=maps.get("rq").toString();  
230 - Date date=sdf.parse(rq);  
231 - String json =StringEscapeUtils.unescapeHtml4(maps.get("ylbList").toString());  
232 - JSONArray jsonArray=JSONArray.parseArray(json);  
233 - JSONObject jsonObject;  
234 - // 获取车辆存油信息  
235 - for (int i = 0; i < jsonArray.size(); i++) {  
236 - jsonObject=jsonArray.getJSONObject(i);  
237 - Integer id =jsonObject.getInteger("id");  
238 - String jsy=jsonObject.getString("jsy");  
239 - double jzl=jsonObject.getDoubleValue("jzl");  
240 - String stationid=jsonObject.getString("stationid");  
241 - String nbbm=jsonObject.getString("nbbm");  
242 - int nylx=jsonObject.getIntValue("nylx");  
243 - String jyggh=jsonObject.getString("jyggh");  
244 - String bz=jsonObject.getString("bz");  
245 - Ylxxb y;  
246 - if(id>0){  
247 - y=ylxxbRepository.findById(id).get();  
248 - y.setJsy(jsy);  
249 - y.setJzl(jzl);  
250 - y.setStationid(stationid);  
251 - y.setJyggh(jyggh);  
252 - y.setBz(bz);  
253 - y.setCreatetime(new Date());  
254 - y.setYyrq(date);  
255 - ylxxbRepository.save(y);  
256 - }else{  
257 - if(jsy!="" && jzl>0){  
258 - y=new Ylxxb();  
259 - y.setGsdm(gsbm);  
260 - y.setJsy(jsy);  
261 - y.setNbbm(nbbm);  
262 - y.setJzl(jzl);  
263 - y.setStationid(stationid);  
264 - y.setJyggh(jyggh);  
265 - y.setBz(bz);  
266 - y.setCreatetime(new Date());  
267 - y.setYyrq(date);  
268 - y.setJylx(1);  
269 - y.setNylx(0);  
270 - ylxxbRepository.save(y);  
271 - }  
272 - }  
273 - }  
274 - map.put("status", ResponseCode.SUCCESS);  
275 -  
276 - } catch (Exception e) {  
277 - map.put("status", ResponseCode.ERROR);  
278 - logger.error("save erro.", e);  
279 - throw e;  
280 - // TODO: handle exception  
281 - }  
282 - return map;  
283 - }  
284 -  
285 -  
286 -  
287 - @Override  
288 - public List<Ylxxb> Pagequery(Map<String, Object> map) {  
289 - // TODO Auto-generated method stub  
290 - String rq=map.get("rq").toString();  
291 - String nbbm=map.get("nbbh").toString();  
292 - String gsdm=map.get("gsdm_like").toString();  
293 -  
294 - String fgsdm=map.get("fgsdm_like").toString();  
295 - String line =map.get("line_like").toString().trim();  
296 - /*String sql="SELECT a.gsdm as gsdm,a.fgsdm as fgsdm,a.nbbm as nbbm,"  
297 - + "b.jyggh as jyggh,b.jzl as jzl ,b.stationid as stationid,b.jsy as jsy,"  
298 - + "b.nylx as nylx,b.yj as yj,b.bz as bz,b.id as id ,c.jsy as ldgh FROM bsth_c_cwjy a "+  
299 - " left join ("  
300 - + " select * from bsth_c_ylxxb b "  
301 - + "where to_days(b.yyrq)=to_days('"+rq+"') and jylx=1 "  
302 - + " and gsdm = '"+gsdm+"') b " +  
303 - " on a.nbbm=b.nbbm "  
304 - + "left join (select nbbm,group_concat(jsy) as jsy "  
305 - + "from bsth_c_ylb where to_days(rq)= to_days('"+rq+"' ) "  
306 - + " and ssgsdm='"+gsdm+"' and fgsdm ='"+fgsdm+"' group by nbbm "+  
307 - " ) c on a.nbbm=c.nbbm "  
308 - + "where a.nbbm like '%"+nbbm+"%' and a.gsdm='"+gsdm+"' and a.fgsdm ='"+fgsdm+"'"  
309 - + " order by a.nbbm";*/  
310 - String sql= " select * from bsth_c_ylxxb b "  
311 - + "where to_days(b.yyrq)=to_days('"+rq+"') and jylx=1 "  
312 - + " and gsdm = '"+gsdm+"'";  
313 -  
314 - List<Ylxxb> yList= jdbcTemplate.query(sql,  
315 - new RowMapper<Ylxxb>(){  
316 - @Override  
317 - public Ylxxb mapRow(ResultSet rs, int rowNum) throws SQLException {  
318 - Ylxxb t=new Ylxxb();  
319 - t.setId(rs.getInt("id"));  
320 - t.setGsdm(rs.getString("gsdm"));  
321 - t.setFgsdm(rs.getString("fgsdm"));  
322 - t.setNbbm(rs.getString("nbbm"));  
323 - t.setJyggh(rs.getString("jyggh"));  
324 - t.setJsy(rs.getString("jsy"));  
325 - t.setJzl(rs.getDouble("jzl"));  
326 - t.setStationid(rs.getString("stationid"));  
327 - t.setNylx(rs.getInt("nylx"));  
328 - t.setYj(rs.getDouble("yj"));  
329 - t.setBz(rs.getString("bz"));  
330 - return t;  
331 - }  
332 - });  
333 - List<Cwjy> cwList=null;  
334 - if(line.equals("")){  
335 - cwList = repository.selectAll(nbbm, gsdm, fgsdm);  
336 - }else{  
337 - cwList = repository.selectAll_s(nbbm, gsdm, fgsdm, line);  
338 - }  
339 -  
340 - String sql_ylb="SELECT nbbm,group_concat(jsy) AS jsy FROM bsth_c_ylb WHERE "  
341 - + " rq = '"+rq+"' AND ssgsdm = '"+gsdm+"' AND "  
342 - + " fgsdm = '"+fgsdm+"' GROUP BY nbbm";  
343 -  
344 - List<Map<String, String>> ylbList= jdbcTemplate.query(sql_ylb,  
345 - new RowMapper<Map<String, String>>(){  
346 - @Override  
347 - public Map<String, String> mapRow(ResultSet rs, int rowNum) throws SQLException {  
348 - Map<String, String> maps =new HashMap<String, String>();  
349 - maps.put("nbbm", rs.getString("nbbm"));  
350 - maps.put("ldgh", rs.getString("jsy"));  
351 - return maps;  
352 - }  
353 - });  
354 -  
355 - List<Ylxxb> ylxxbList= new ArrayList<Ylxxb>();  
356 - Ylxxb y=null;  
357 - for (int i = 0; i < cwList.size(); i++) {  
358 - Cwjy cwjy=cwList.get(i);  
359 - y=new Ylxxb();  
360 - y.setNylx(0);  
361 - y.setId(0);  
362 - y.setJzl(0.0);  
363 - y.setGsdm(cwjy.getGsdm());  
364 - y.setFgsdm(cwjy.getFgsdm());  
365 - y.setNbbm(cwjy.getNbbm());  
366 - y.setLinename(cwjy.getLinename());  
367 - for (int j = 0; j < yList.size(); j++) {  
368 - Ylxxb ylxxb=yList.get(j);  
369 - if(y.getNbbm().equals(ylxxb.getNbbm())){  
370 - y.setId(ylxxb.getId());  
371 - y.setJyggh(ylxxb.getJyggh());  
372 - y.setJsy(ylxxb.getJsy());  
373 - y.setJzl(ylxxb.getJzl());  
374 - y.setStationid(ylxxb.getStationid());  
375 - y.setNylx(ylxxb.getNylx());  
376 - y.setYj(ylxxb.getYj());  
377 - y.setBz(ylxxb.getBz());  
378 - break;  
379 - }  
380 - }  
381 - for (int j = 0; j < ylbList.size(); j++) {  
382 - Map<String, String> m=ylbList.get(j);  
383 - if(m.get("nbbm").toString().equals(cwjy.getNbbm())){  
384 - y.setLdgh(m.get("ldgh").toString());  
385 - break;  
386 - }  
387 -  
388 - }  
389 -  
390 - ylxxbList.add(y);  
391 -  
392 - }  
393 -  
394 - return ylxxbList;  
395 - }  
396 -  
397 - @Override  
398 - public int checkNbbm(Cwjy t) {  
399 - // TODO Auto-generated method stub  
400 - String sql="select count(*) from bsth_c_cwjy where nbbm ='"+t.getNbbm()+"'"  
401 - + " and gsdm ='"+t.getFgsdm()+"' and fgsdm ='"+t.getFgsdm()+"'";  
402 - int cs=jdbcTemplate.queryForObject(sql, Integer.class);  
403 -  
404 - return cs;  
405 - }  
406 -  
407 - @Override  
408 - public List<Ylxxb> cwjyList(Map<String, Object> map) {  
409 - String rq=map.get("rq").toString();  
410 - String nbbm=map.get("nbbh").toString();  
411 - String gsdm=map.get("gsdm_like").toString();  
412 -  
413 - String fgsdm=map.get("fgsdm_like").toString();  
414 - String line =map.get("line_like").toString().trim();  
415 - boolean type=false;  
416 - if(map.get("type")!=null){  
417 - type=true;  
418 - }  
419 - String sql="select a.nbbm,a.gsdm,a.fgsdm,IFNULL(b.id,0) as id,IFNULL(b.jzl,0) as jzl,"  
420 - + " IFNULL(b.jyggh,0) as jyggh,IFNULL(b.jsy,0) as jsy,IFNULL(b.stationid,0) as stationid ,"  
421 - + " IFNULL(b.yj,0) as yj,IFNULL(b.nylx,0) as nylx,IFNULL(b.bz,'') as bz,IFNULL(c.jsy,'') as ldgh ,"  
422 - + " IFNULL(c.xlname,c.linename) as xlname from "  
423 - + " (select * from bsth_c_cwjy where gsdm='"+gsdm+"' and fgsdm='"+fgsdm+"') a "  
424 - + " left join (select * from bsth_c_ylxxb where yyrq='"+rq+"' and gsdm='"+gsdm+"' and jylx=1) b"  
425 - + " on a.nbbm=b.nbbm LEFT JOIN (select u.nbbm,u.jsy,v.linename,v.xlname,v.xlbm from(select a.nbbm,GROUP_CONCAT(a.jsy) as jsy "  
426 - + " from (select nbbm,jsy from bsth_c_ylb x where x.rq='"+rq+"' "  
427 - + " and x.ssgsdm='"+gsdm+"' and x.fgsdm='"+fgsdm+"' group by nbbm,jsy ) a group by a.nbbm) u"  
428 - + " LEFT JOIN(select o.nbbm,GROUP_CONCAT(o.xlbm) xlbm ,GROUP_CONCAT(o.linename) as xlname,"  
429 - + " GROUP_CONCAT(p.`name`) as linename from (select nbbm,xlbm,linename from bsth_c_ylb "  
430 - + " where rq='"+rq+"' and ssgsdm='"+gsdm+"' and fgsdm='"+fgsdm+"' group by nbbm,xlbm,linename) o "  
431 - + " LEFT JOIN bsth_c_line p on o.xlbm=p.line_code group by o.nbbm ) v on u.nbbm=v.nbbm) c "  
432 - + " on a.nbbm=c.nbbm where 1=1 ";  
433 - if(!nbbm.equals("")){  
434 - sql +=" and a.nbbm like '%"+nbbm+"%'";  
435 - }  
436 - if(!line.equals("")){  
437 - sql += " and c.xlbm ='"+line+"'";  
438 - }  
439 - if(type){  
440 - sql +=" and c.xlbm is not null";  
441 - }  
442 - sql +=" order by xlname desc";  
443 - List<Ylxxb> yList= jdbcTemplate.query(sql,  
444 - new RowMapper<Ylxxb>(){  
445 - @Override  
446 - public Ylxxb mapRow(ResultSet rs, int rowNum) throws SQLException {  
447 - Ylxxb t=new Ylxxb();  
448 - t.setId(rs.getInt("id"));  
449 - t.setGsdm(rs.getString("gsdm"));  
450 - t.setFgsdm(rs.getString("fgsdm"));  
451 - t.setNbbm(rs.getString("nbbm"));  
452 - t.setJyggh(rs.getString("jyggh"));  
453 - t.setJsy(rs.getString("jsy"));  
454 - t.setJzl(rs.getDouble("jzl"));  
455 - t.setStationid(rs.getString("stationid"));  
456 - t.setNylx(rs.getInt("nylx"));  
457 - t.setYj(rs.getDouble("yj"));  
458 - t.setBz(rs.getString("bz"));  
459 - t.setLdgh(rs.getString("ldgh"));  
460 - t.setLinename(rs.getString("xlname"));  
461 - return t;  
462 - }  
463 - });  
464 - return yList;  
465 - }  
466 -  
467 -  
468 - @Override  
469 - public String importExcel(File file, String gsbm, String gsName) {  
470 - SimpleDateFormat sdf = new SimpleDateFormat("yyyy-MM-dd");  
471 - SimpleDateFormat sd = new SimpleDateFormat("yyyy-MM-dd HH:mm:ss");  
472 - DecimalFormat df = new DecimalFormat("######0.00");  
473 - List<String> textList = new ArrayList<String>();  
474 - try {  
475 - POIFSFileSystem fs = new POIFSFileSystem(new FileInputStream(file));  
476 - HSSFWorkbook wb = new HSSFWorkbook(fs);  
477 - HSSFSheet sheet = wb.getSheetAt(0);  
478 - // 取得总行数  
479 - int rowNum = sheet.getLastRowNum() + 1;  
480 - // 取得总列数  
481 - int cellNum = sheet.getRow(0).getLastCellNum();  
482 - HSSFRow row = null;  
483 - HSSFCell cell = null;  
484 - for(int i = 2; i < rowNum; i++){  
485 - row = sheet.getRow(i);  
486 - if (row == null){  
487 - continue;  
488 - }  
489 - String text = "";  
490 - for(int j = 0; j < cellNum; j++){  
491 - cell = row.getCell(j);  
492 - if(cell == null){  
493 - text += ",";  
494 - continue;  
495 - }  
496 - text += String.valueOf(cell) + ",";  
497 - }  
498 - String[] split = (text+";").split(",");  
499 - String str = "";  
500 - for(int j = 0; j < split.length && j < 5; j++){  
501 - str += split[j];  
502 - }  
503 - if(str.trim().length() == 0){  
504 - continue;  
505 - }  
506 - textList.add(text + ";");  
507 - }  
508 - for(int i = 0; i < textList.size(); i++){  
509 - String text = textList.get(i);  
510 - System.out.println(text);  
511 - String[] split = text.split(",");  
512 - String rq = split[0].trim();  
513 - String nbbm = split[1].trim();  
514 - String jsy = split[2].trim();  
515 - double jzl = Double.valueOf(split[3].trim().length()!=0?split[3]:"0");  
516 - String jyz = split[4].trim();  
517 - String remarks = split[5].trim();  
518 - if(rq.trim().length() == 0){  
519 - rq = sdf.format(new Date());  
520 - }  
521 -  
522 - List<Double> jzl_ = repository.import_queryBySame(gsbm, rq, nbbm);  
523 -//  
524 - if(jzl_.size() == 0){  
525 - repository.import_insertData(gsbm, rq, nbbm, jsy,  
526 - df.format(jzl), jyz, remarks, sd.format(new Date()));  
527 - }else{  
528 - repository.import_UpdateJzl(df.format(jzl), jsy, jyz, remarks, gsbm, rq, nbbm);  
529 - }  
530 - }  
531 - wb.close();  
532 - fs.close();  
533 - } catch (Exception e) {  
534 - // TODO Auto-generated catch block  
535 - e.printStackTrace();  
536 - return "文件导入失败";  
537 - } finally {  
538 - file.delete();  
539 - }  
540 - return "文件导入成功";  
541 - }  
542 -  
543 -  
544 -} 1 +package com.bsth.service.oil.impl;
  2 +
  3 +import java.io.File;
  4 +import java.io.FileInputStream;
  5 +import java.sql.ResultSet;
  6 +import java.sql.SQLException;
  7 +import java.text.DecimalFormat;
  8 +import java.text.ParseException;
  9 +import java.text.SimpleDateFormat;
  10 +import java.util.ArrayList;
  11 +import java.util.Arrays;
  12 +import java.util.Date;
  13 +import java.util.HashMap;
  14 +import java.util.List;
  15 +import java.util.Map;
  16 +
  17 +import javax.transaction.Transactional;
  18 +
  19 +import org.apache.commons.lang3.StringEscapeUtils;
  20 +import org.apache.poi.hssf.usermodel.HSSFCell;
  21 +import org.apache.poi.hssf.usermodel.HSSFRow;
  22 +import org.apache.poi.hssf.usermodel.HSSFSheet;
  23 +import org.apache.poi.hssf.usermodel.HSSFWorkbook;
  24 +import org.apache.poi.poifs.filesystem.POIFSFileSystem;
  25 +import org.apache.poi.ss.usermodel.Cell;
  26 +import org.slf4j.Logger;
  27 +import org.slf4j.LoggerFactory;
  28 +import org.springframework.beans.factory.annotation.Autowired;
  29 +import org.springframework.jdbc.core.JdbcTemplate;
  30 +import org.springframework.jdbc.core.RowMapper;
  31 +import org.springframework.stereotype.Service;
  32 +
  33 +import com.alibaba.fastjson.JSONArray;
  34 +import com.alibaba.fastjson.JSONObject;
  35 +import com.bsth.common.ResponseCode;
  36 +import com.bsth.data.BasicData;
  37 +import com.bsth.entity.oil.Cwjy;
  38 +import com.bsth.entity.oil.Cyl;
  39 +import com.bsth.entity.oil.Ylb;
  40 +import com.bsth.entity.oil.Ylxxb;
  41 +import com.bsth.repository.oil.CwjyRepository;
  42 +import com.bsth.repository.oil.YlxxbRepository;
  43 +import com.bsth.service.impl.BaseServiceImpl;
  44 +import com.bsth.service.oil.CwjyService;
  45 +import com.bsth.util.Arith;
  46 +import com.bsth.util.PageHelper;
  47 +import com.bsth.util.PageObject;
  48 +
  49 +@Service
  50 +public class CwjyServiceImpl extends BaseServiceImpl<Cwjy,Integer> implements CwjyService
  51 +{
  52 + @Autowired
  53 + CwjyRepository repository;
  54 + @Autowired
  55 + YlxxbRepository ylxxbRepository;
  56 +
  57 + @Autowired
  58 + JdbcTemplate jdbcTemplate;
  59 + Logger logger = LoggerFactory.getLogger(this.getClass());
  60 + /*@SuppressWarnings("unchecked")
  61 + public PageObject<Ylxxb> Pagequery(Map<String, Object> map) {
  62 + int page=Integer.parseInt(map.get("page").toString());
  63 + SimpleDateFormat sdf=new SimpleDateFormat("yyyy-MM-dd");
  64 +
  65 + String rq=map.get("rq").toString();
  66 + String nbbm="";
  67 + if(map.get("nbbh")!=null){
  68 + nbbm=map.get("nbbh").toString();
  69 + }
  70 +
  71 + Object gsdmIn=map.get("gsdm_in");
  72 + Object fgsdmIn=map.get("fgsdm_in");
  73 + String addSql="";
  74 + String gsdmLike="";
  75 + String fgsdmLike="";
  76 +
  77 + //选择了公司
  78 + if(gsdmIn==null){
  79 + gsdmLike=map.get("gsdm_like").toString();
  80 + addSql += " and a.gsdm = '"+gsdmLike+ "' ";
  81 +
  82 + //选择了分公司
  83 + if(fgsdmIn==null){
  84 + fgsdmLike=map.get("fgsdm_like").toString();;
  85 + addSql += " and a.fgsdm = '"+fgsdmLike+ "' ";
  86 + }else{
  87 + String fgsdmIns[]= fgsdmIn.toString().split(",");
  88 + addSql +=" and a.fgsdm in (";
  89 + for(int i=0;i<fgsdmIns.length;i++){
  90 + addSql +="'"+fgsdmIns[i]+"'";
  91 + if(i<fgsdmIns.length-1){
  92 + addSql +=",";
  93 + }
  94 + }
  95 + addSql +=")";
  96 + }
  97 + }else{
  98 + //没有选择公司 (分公司也没有选择)
  99 + String gsdmIns[]=gsdmIn.toString().split(",");
  100 + addSql += " and a.gsdm in (";
  101 + for(int i=0;i<gsdmIns.length;i++){
  102 + addSql +="'" +gsdmIns[i]+"'";
  103 + if(i<gsdmIns.length-1){
  104 + addSql+=",";
  105 + }
  106 + }
  107 + addSql +=")";
  108 + String fgsdmIns[]= fgsdmIn.toString().split(",");
  109 + addSql +=" and a.fgsdm in (";
  110 + for(int i=0;i<fgsdmIns.length;i++){
  111 + addSql +="'"+fgsdmIns[i]+"'";
  112 + if(i<fgsdmIns.length-1){
  113 + addSql +=",";
  114 + }
  115 + }
  116 + addSql +=")";
  117 +
  118 +
  119 + }
  120 + String countSql="SELECT ifnull(count(*),0) as countTs FROM bsth_c_cwjy a "+
  121 + " left join ( select * from bsth_c_ylxxb b where to_days(b.yyrq)=to_days('"+rq+"') and jylx=1) b " +
  122 + " on a.nbbm=b.nbbm left join (select nbbm,group_concat(jsy) as jsy "
  123 + + "from bsth_c_ylb where to_days(rq)= to_days('"+rq+"' ) group by nbbm "+
  124 + " ) c on a.nbbm=c.nbbm where a.nbbm like '%"+nbbm+"%' " +addSql ;
  125 + int listsize=jdbcTemplate.queryForObject(countSql, Integer.class);
  126 + // TODO Auto-generated method stub
  127 + String sql="SELECT a.gsdm as gsdm,a.fgsdm as fgsdm,a.nbbm as nbbm,b.jsy as jsy,b.jzl as jzl ,b.stationid as stationid,"
  128 + + "b.nylx as nylx,b.yj as yj,b.bz as bz,c.jsy as ldgh FROM bsth_c_cwjy a "+
  129 + " left join ( select * from bsth_c_ylxxb b where to_days(b.yyrq)=to_days('"+rq+"') and jylx=1) b " +
  130 + " on a.nbbm=b.nbbm left join (select nbbm,group_concat(jsy) as jsy "
  131 + + "from bsth_c_ylb where to_days(rq)= to_days('"+rq+"' ) group by nbbm "+
  132 + " ) c on a.nbbm=c.nbbm where a.nbbm like '%"+nbbm+"%' " +addSql+ " limit "+page*10+","+10;
  133 +
  134 +
  135 + List<Ylxxb> yList= jdbcTemplate.query(sql,
  136 + new RowMapper<Ylxxb>(){
  137 + @Override
  138 + public Ylxxb mapRow(ResultSet rs, int rowNum) throws SQLException {
  139 + Ylxxb t=new Ylxxb();
  140 + t.setGsdm(rs.getString("gsdm"));
  141 + t.setFgsdm(rs.getString("fgsdm"));
  142 + t.setNbbm(rs.getString("nbbm"));
  143 + t.setJsy(rs.getString("jsy"));
  144 + t.setJzl(rs.getDouble("jzl"));
  145 + t.setStationid(rs.getString("stationid"));
  146 + t.setNylx(rs.getInt("nylx"));
  147 + t.setYj(rs.getDouble("yj"));
  148 + t.setBz(rs.getString("bz"));
  149 + t.setLdgh(rs.getString("ldgh"));
  150 + return t;
  151 + }
  152 + });
  153 + List<Object[]> list=repository.obtainCwjycl(rq,nbbm);
  154 + for (int i = 0; i < list.size(); i++) {
  155 + Ylxxb y=new Ylxxb();
  156 + y.setGsdm(list.get(i)[0]==null?"":list.get(i)[0].toString());
  157 + y.setNbbm(list.get(i)[1]==null?"":list.get(i)[1].toString());
  158 + y.setJsy(list.get(i)[2]==null?"":list.get(i)[2].toString());
  159 + y.setJzl(list.get(i)[3]==null?0.0:Double.parseDouble(list.get(i)[3].toString()));
  160 + y.setStationid(list.get(i)[4]==null?"":list.get(i)[4].toString());
  161 + y.setNylx(list.get(i)[5]==null?0:Integer.parseInt(list.get(i)[5].toString()));
  162 + y.setYj(list.get(i)[6]==null?0.0:Double.parseDouble(list.get(i)[6].toString()));
  163 + y.setBz(list.get(i)[7]==null?"":list.get(i)[7].toString());
  164 + y.setLdgh(list.get(i)[8]==null?"":list.get(i)[8].toString());
  165 + try {
  166 + y.setYyrq(sdf.parse(rq));
  167 + } catch (ParseException e) {
  168 + // TODO Auto-generated catch block
  169 + e.printStackTrace();
  170 + }
  171 + yList.add(y);
  172 + }
  173 + PageHelper pageHelper = new PageHelper(listsize, map);
  174 + pageHelper.getMap();
  175 + PageObject<Ylxxb> pageObject=pageHelper.getPageObject();
  176 + pageObject.setDataList(yList);
  177 + return pageObject;
  178 + }*/
  179 +
  180 + @Override
  181 + public Ylxxb bynbbm(Map<String, Object> map) {
  182 + // TODO Auto-generated method stub
  183 + // TODO Auto-generated method stub
  184 + SimpleDateFormat sdf = new SimpleDateFormat("yyyy-MM-dd");
  185 + String rq = map.get("rq").toString();
  186 + String nbbm = "";
  187 + if (map.get("nbbm") != null) {
  188 + nbbm = map.get("nbbm").toString();
  189 + }
  190 + List<Object[]> list = repository.obtainCwjycl(rq, nbbm);
  191 + Ylxxb y = new Ylxxb();
  192 + if (list.size() > 0) {
  193 + y.setGsdm(list.get(0)[0] == null ? "" : list.get(0)[0].toString());
  194 + y.setNbbm(list.get(0)[1] == null ? "" : list.get(0)[1].toString());
  195 + y.setJsy(list.get(0)[2] == null ? "" : list.get(0)[2].toString());
  196 + y.setJzl(list.get(0)[3] == null ? 0.0 : Double.parseDouble(list.get(0)[3].toString()));
  197 + y.setStationid(list.get(0)[4] == null ? "" : list.get(0)[4].toString());
  198 + y.setNylx(list.get(0)[5] == null ? 0 : Integer.parseInt(list.get(0)[5].toString()));
  199 + y.setYj(list.get(0)[6] == null ? 0.0 : Double.parseDouble(list.get(0)[6].toString()));
  200 + y.setBz(list.get(0)[7] == null ? "" : list.get(0)[7].toString());
  201 + y.setLdgh(list.get(0)[8] == null ? "" : list.get(0)[8].toString());
  202 + try {
  203 + y.setYyrq(sdf.parse(rq));
  204 + } catch (ParseException e) {
  205 + // TODO Auto-generated catch block
  206 + e.printStackTrace();
  207 + }
  208 + }
  209 + return y;
  210 + }
  211 +
  212 + @Transactional
  213 + @Override
  214 + public Map<String, Object> savejzl(Map<String, Object> maps) throws Exception {
  215 + // TODO Auto-generated method stub
  216 + Map<String, Object> map=new HashMap<String,Object>();
  217 + try {
  218 + SimpleDateFormat sdf = new SimpleDateFormat("yyyy-MM-dd");
  219 +// String rq = sdf.format(t.getYyrq());
  220 +// String nbbm=t.getNbbm();
  221 +// List<Ylxxb> yList=ylxxbRepository.obtainYlxx2(rq,nbbm);
  222 +// if(yList.size()>0){
  223 +// t.setId(yList.get(0).getId());
  224 +// ylxxbRepository.save(t);
  225 +// }else{
  226 +// ylxxbRepository.save(t);
  227 +// }
  228 + String gsbm=maps.get("gsbm").toString();
  229 + String fgsbm=maps.get("fgsbm").toString();
  230 + String rq=maps.get("rq").toString();
  231 + Date date=sdf.parse(rq);
  232 + String json =StringEscapeUtils.unescapeHtml4(maps.get("ylbList").toString());
  233 + JSONArray jsonArray=JSONArray.parseArray(json);
  234 + JSONObject jsonObject;
  235 + // 获取车辆存油信息
  236 + for (int i = 0; i < jsonArray.size(); i++) {
  237 + jsonObject=jsonArray.getJSONObject(i);
  238 + Integer id =jsonObject.getInteger("id");
  239 + String jsy=jsonObject.getString("jsy");
  240 + double jzl=jsonObject.getDoubleValue("jzl");
  241 + String stationid=jsonObject.getString("stationid");
  242 + String nbbm=jsonObject.getString("nbbm");
  243 + int nylx=jsonObject.getIntValue("nylx");
  244 + String jyggh=jsonObject.getString("jyggh");
  245 + String bz=jsonObject.getString("bz");
  246 + Ylxxb y;
  247 + if(id>0){
  248 + y=ylxxbRepository.findById(id).get();
  249 + y.setJsy(jsy);
  250 + y.setJzl(jzl);
  251 + y.setStationid(stationid);
  252 + y.setJyggh(jyggh);
  253 + y.setBz(bz);
  254 + y.setCreatetime(new Date());
  255 + y.setYyrq(date);
  256 + ylxxbRepository.save(y);
  257 + }else{
  258 + if(jsy!="" && jzl>0){
  259 + y=new Ylxxb();
  260 + y.setGsdm(gsbm);
  261 + y.setJsy(jsy);
  262 + y.setNbbm(nbbm);
  263 + y.setJzl(jzl);
  264 + y.setStationid(stationid);
  265 + y.setJyggh(jyggh);
  266 + y.setBz(bz);
  267 + y.setCreatetime(new Date());
  268 + y.setYyrq(date);
  269 + y.setJylx(1);
  270 + y.setNylx(0);
  271 + ylxxbRepository.save(y);
  272 + }
  273 + }
  274 + }
  275 + map.put("status", ResponseCode.SUCCESS);
  276 +
  277 + } catch (Exception e) {
  278 + map.put("status", ResponseCode.ERROR);
  279 + logger.error("save erro.", e);
  280 + throw e;
  281 + // TODO: handle exception
  282 + }
  283 + return map;
  284 + }
  285 +
  286 +
  287 +
  288 + @Override
  289 + public List<Ylxxb> Pagequery(Map<String, Object> map) {
  290 + // TODO Auto-generated method stub
  291 + String rq=map.get("rq").toString();
  292 + String nbbm=map.get("nbbh").toString();
  293 + String gsdm=map.get("gsdm_like").toString();
  294 +
  295 + String fgsdm=map.get("fgsdm_like").toString();
  296 + String line =map.get("line_like").toString().trim();
  297 + /*String sql="SELECT a.gsdm as gsdm,a.fgsdm as fgsdm,a.nbbm as nbbm,"
  298 + + "b.jyggh as jyggh,b.jzl as jzl ,b.stationid as stationid,b.jsy as jsy,"
  299 + + "b.nylx as nylx,b.yj as yj,b.bz as bz,b.id as id ,c.jsy as ldgh FROM bsth_c_cwjy a "+
  300 + " left join ("
  301 + + " select * from bsth_c_ylxxb b "
  302 + + "where to_days(b.yyrq)=to_days('"+rq+"') and jylx=1 "
  303 + + " and gsdm = '"+gsdm+"') b " +
  304 + " on a.nbbm=b.nbbm "
  305 + + "left join (select nbbm,group_concat(jsy) as jsy "
  306 + + "from bsth_c_ylb where to_days(rq)= to_days('"+rq+"' ) "
  307 + + " and ssgsdm='"+gsdm+"' and fgsdm ='"+fgsdm+"' group by nbbm "+
  308 + " ) c on a.nbbm=c.nbbm "
  309 + + "where a.nbbm like '%"+nbbm+"%' and a.gsdm='"+gsdm+"' and a.fgsdm ='"+fgsdm+"'"
  310 + + " order by a.nbbm";*/
  311 + String sql= " select * from bsth_c_ylxxb b "
  312 + + "where to_days(b.yyrq)=to_days('"+rq+"') and jylx=1 "
  313 + + " and gsdm = '"+gsdm+"'";
  314 +
  315 + List<Ylxxb> yList= jdbcTemplate.query(sql,
  316 + new RowMapper<Ylxxb>(){
  317 + @Override
  318 + public Ylxxb mapRow(ResultSet rs, int rowNum) throws SQLException {
  319 + Ylxxb t=new Ylxxb();
  320 + t.setId(rs.getInt("id"));
  321 + t.setGsdm(rs.getString("gsdm"));
  322 + t.setFgsdm(rs.getString("fgsdm"));
  323 + t.setNbbm(rs.getString("nbbm"));
  324 + t.setJyggh(rs.getString("jyggh"));
  325 + t.setJsy(rs.getString("jsy"));
  326 + t.setJzl(rs.getDouble("jzl"));
  327 + t.setStationid(rs.getString("stationid"));
  328 + t.setNylx(rs.getInt("nylx"));
  329 + t.setYj(rs.getDouble("yj"));
  330 + t.setBz(rs.getString("bz"));
  331 + return t;
  332 + }
  333 + });
  334 + List<Cwjy> cwList=null;
  335 + if(line.equals("")){
  336 + cwList = repository.selectAll(nbbm, gsdm, fgsdm);
  337 + }else{
  338 + cwList = repository.selectAll_s(nbbm, gsdm, fgsdm, line);
  339 + }
  340 +
  341 + String sql_ylb="SELECT nbbm,group_concat(jsy) AS jsy FROM bsth_c_ylb WHERE "
  342 + + " rq = '"+rq+"' AND ssgsdm = '"+gsdm+"' AND "
  343 + + " fgsdm = '"+fgsdm+"' GROUP BY nbbm";
  344 +
  345 + List<Map<String, String>> ylbList= jdbcTemplate.query(sql_ylb,
  346 + new RowMapper<Map<String, String>>(){
  347 + @Override
  348 + public Map<String, String> mapRow(ResultSet rs, int rowNum) throws SQLException {
  349 + Map<String, String> maps =new HashMap<String, String>();
  350 + maps.put("nbbm", rs.getString("nbbm"));
  351 + maps.put("ldgh", rs.getString("jsy"));
  352 + return maps;
  353 + }
  354 + });
  355 +
  356 + List<Ylxxb> ylxxbList= new ArrayList<Ylxxb>();
  357 + Ylxxb y=null;
  358 + for (int i = 0; i < cwList.size(); i++) {
  359 + Cwjy cwjy=cwList.get(i);
  360 + y=new Ylxxb();
  361 + y.setNylx(0);
  362 + y.setId(0);
  363 + y.setJzl(0.0);
  364 + y.setGsdm(cwjy.getGsdm());
  365 + y.setFgsdm(cwjy.getFgsdm());
  366 + y.setNbbm(cwjy.getNbbm());
  367 + y.setLinename(cwjy.getLinename());
  368 + for (int j = 0; j < yList.size(); j++) {
  369 + Ylxxb ylxxb=yList.get(j);
  370 + if(y.getNbbm().equals(ylxxb.getNbbm())){
  371 + y.setId(ylxxb.getId());
  372 + y.setJyggh(ylxxb.getJyggh());
  373 + y.setJsy(ylxxb.getJsy());
  374 + y.setJzl(ylxxb.getJzl());
  375 + y.setStationid(ylxxb.getStationid());
  376 + y.setNylx(ylxxb.getNylx());
  377 + y.setYj(ylxxb.getYj());
  378 + y.setBz(ylxxb.getBz());
  379 + break;
  380 + }
  381 + }
  382 + for (int j = 0; j < ylbList.size(); j++) {
  383 + Map<String, String> m=ylbList.get(j);
  384 + if(m.get("nbbm").toString().equals(cwjy.getNbbm())){
  385 + y.setLdgh(m.get("ldgh").toString());
  386 + break;
  387 + }
  388 +
  389 + }
  390 +
  391 + ylxxbList.add(y);
  392 +
  393 + }
  394 +
  395 + return ylxxbList;
  396 + }
  397 +
  398 + @Override
  399 + public int checkNbbm(Cwjy t) {
  400 + // TODO Auto-generated method stub
  401 + String sql="select count(*) from bsth_c_cwjy where nbbm ='"+t.getNbbm()+"'"
  402 + + " and gsdm ='"+t.getFgsdm()+"' and fgsdm ='"+t.getFgsdm()+"'";
  403 + int cs=jdbcTemplate.queryForObject(sql, Integer.class);
  404 +
  405 + return cs;
  406 + }
  407 +
  408 + @Override
  409 + public List<Ylxxb> cwjyList(Map<String, Object> map) {
  410 + String rq=map.get("rq").toString();
  411 + String nbbm=map.get("nbbh").toString();
  412 + String gsdm=map.get("gsdm_like").toString();
  413 +
  414 + String fgsdm=map.get("fgsdm_like").toString();
  415 + String line =map.get("line_like").toString().trim();
  416 + boolean type=false;
  417 + if(map.get("type")!=null){
  418 + type=true;
  419 + }
  420 + String sql="select a.nbbm,a.gsdm,a.fgsdm,IFNULL(b.id,0) as id,IFNULL(b.jzl,0) as jzl,"
  421 + + " IFNULL(b.jyggh,0) as jyggh,IFNULL(b.jsy,0) as jsy,IFNULL(b.stationid,0) as stationid ,"
  422 + + " IFNULL(b.yj,0) as yj,IFNULL(b.nylx,0) as nylx,IFNULL(b.bz,'') as bz,IFNULL(c.jsy,'') as ldgh ,"
  423 + + " IFNULL(c.xlname,c.linename) as xlname from "
  424 + + " (select * from bsth_c_cwjy where gsdm='"+gsdm+"' and fgsdm='"+fgsdm+"') a "
  425 + + " left join (select * from bsth_c_ylxxb where yyrq='"+rq+"' and gsdm='"+gsdm+"' and jylx=1) b"
  426 + + " on a.nbbm=b.nbbm LEFT JOIN (select u.nbbm,u.jsy,v.linename,v.xlname,v.xlbm from(select a.nbbm,GROUP_CONCAT(a.jsy) as jsy "
  427 + + " from (select nbbm,jsy from bsth_c_ylb x where x.rq='"+rq+"' "
  428 + + " and x.ssgsdm='"+gsdm+"' and x.fgsdm='"+fgsdm+"' group by nbbm,jsy ) a group by a.nbbm) u"
  429 + + " LEFT JOIN(select o.nbbm,GROUP_CONCAT(o.xlbm) xlbm ,GROUP_CONCAT(o.linename) as xlname,"
  430 + + " GROUP_CONCAT(p.`name`) as linename from (select nbbm,xlbm,linename from bsth_c_ylb "
  431 + + " where rq='"+rq+"' and ssgsdm='"+gsdm+"' and fgsdm='"+fgsdm+"' group by nbbm,xlbm,linename) o "
  432 + + " LEFT JOIN bsth_c_line p on o.xlbm=p.line_code group by o.nbbm ) v on u.nbbm=v.nbbm) c "
  433 + + " on a.nbbm=c.nbbm where 1=1 ";
  434 + if(!nbbm.equals("")){
  435 + sql +=" and a.nbbm like '%"+nbbm+"%'";
  436 + }
  437 + if(!line.equals("")){
  438 + sql += " and c.xlbm ='"+line+"'";
  439 + }
  440 + if(type){
  441 + sql +=" and c.xlbm is not null";
  442 + }
  443 + sql +=" order by xlname desc";
  444 + List<Ylxxb> yList= jdbcTemplate.query(sql,
  445 + new RowMapper<Ylxxb>(){
  446 + @Override
  447 + public Ylxxb mapRow(ResultSet rs, int rowNum) throws SQLException {
  448 + Ylxxb t=new Ylxxb();
  449 + t.setId(rs.getInt("id"));
  450 + t.setGsdm(rs.getString("gsdm"));
  451 + t.setFgsdm(rs.getString("fgsdm"));
  452 + t.setNbbm(rs.getString("nbbm"));
  453 + t.setJyggh(rs.getString("jyggh"));
  454 + t.setJsy(rs.getString("jsy"));
  455 + t.setJzl(rs.getDouble("jzl"));
  456 + t.setStationid(rs.getString("stationid"));
  457 + t.setNylx(rs.getInt("nylx"));
  458 + t.setYj(rs.getDouble("yj"));
  459 + t.setBz(rs.getString("bz"));
  460 + t.setLdgh(rs.getString("ldgh"));
  461 + t.setLinename(rs.getString("xlname"));
  462 + return t;
  463 + }
  464 + });
  465 + return yList;
  466 + }
  467 +
  468 +
  469 + @Override
  470 + public String importExcel(File file, String gsbm, String gsName) {
  471 + SimpleDateFormat sdf = new SimpleDateFormat("yyyy-MM-dd");
  472 + SimpleDateFormat sd = new SimpleDateFormat("yyyy-MM-dd HH:mm:ss");
  473 + DecimalFormat df = new DecimalFormat("######0.00");
  474 + List<String> textList = new ArrayList<String>();
  475 + try {
  476 + POIFSFileSystem fs = new POIFSFileSystem(new FileInputStream(file));
  477 + HSSFWorkbook wb = new HSSFWorkbook(fs);
  478 + HSSFSheet sheet = wb.getSheetAt(0);
  479 + // 取得总行数
  480 + int rowNum = sheet.getLastRowNum() + 1;
  481 + // 取得总列数
  482 + int cellNum = sheet.getRow(0).getLastCellNum();
  483 + HSSFRow row = null;
  484 + HSSFCell cell = null;
  485 + for(int i = 2; i < rowNum; i++){
  486 + row = sheet.getRow(i);
  487 + if (row == null){
  488 + continue;
  489 + }
  490 + String text = "";
  491 + for(int j = 0; j < cellNum; j++){
  492 + cell = row.getCell(j);
  493 + if(cell == null){
  494 + text += ",";
  495 + continue;
  496 + }
  497 + text += String.valueOf(cell) + ",";
  498 + }
  499 + String[] split = (text+";").split(",");
  500 + String str = "";
  501 + for(int j = 0; j < split.length && j < 5; j++){
  502 + str += split[j];
  503 + }
  504 + if(str.trim().length() == 0){
  505 + continue;
  506 + }
  507 + textList.add(text + ";");
  508 + }
  509 + for(int i = 0; i < textList.size(); i++){
  510 + String text = textList.get(i);
  511 + System.out.println(text);
  512 + String[] split = text.split(",");
  513 + String rq = split[0].trim();
  514 + String nbbm = split[1].trim();
  515 + String jsy = split[2].trim();
  516 + double jzl = Double.valueOf(split[3].trim().length()!=0?split[3]:"0");
  517 + String jyz = split[4].trim();
  518 + String remarks = split[5].trim();
  519 + if(rq.trim().length() == 0){
  520 + rq = sdf.format(new Date());
  521 + }
  522 +
  523 + List<Double> jzl_ = repository.import_queryBySame(gsbm, rq, nbbm);
  524 +//
  525 + if(jzl_.size() == 0){
  526 + repository.import_insertData(gsbm, rq, nbbm, jsy,
  527 + df.format(jzl), jyz, remarks, sd.format(new Date()));
  528 + }else{
  529 + repository.import_UpdateJzl(df.format(jzl), jsy, jyz, remarks, gsbm, rq, nbbm);
  530 + }
  531 + }
  532 +
  533 + /** 以下为测试导入ylxxb用 */
  534 +// Date date = new Date();
  535 +// SimpleDateFormat dateFormat = new SimpleDateFormat("yyyy-MM-dd HH:mm:ss");
  536 +// for(int i = 1; i < rowNum; i++){
  537 +// row = sheet.getRow(i);
  538 +// if (row == null){
  539 +// continue;
  540 +// }
  541 +// String text = "";
  542 +// for(int j = 0; j < cellNum; j++){
  543 +// cell = row.getCell(j);
  544 +// if(cell == null){
  545 +// text += ",";
  546 +// continue;
  547 +// }
  548 +// if(j == 1 && cell.getCellType() == Cell.CELL_TYPE_NUMERIC){
  549 +// text += dateFormat.format(cell.getDateCellValue()) + ",";
  550 +// } else if(j == 4 || j == 7){
  551 +// text += "0,";
  552 +//// } else if(j == 6 && String.valueOf(cell).contains("-")){
  553 +//// String str = String.valueOf(cell);
  554 +//// text += str.split("-")[1] + ",";
  555 +// } else {
  556 +// text += String.valueOf(cell) + ",";
  557 +// }
  558 +// }
  559 +// System.out.println(text);
  560 +// Ylxxb ylxxb = new Ylxxb();
  561 +// String[] split = text.split(",");
  562 +// ylxxb.setCreatetime(date);
  563 +// ylxxb.setYyrq(sdf.parse(split[0].trim()));
  564 +// ylxxb.setJlrq(dateFormat.parse(split[1]));
  565 +// ylxxb.setFromgsdm("22");
  566 +// ylxxb.setNbbm(split[2]);
  567 +// ylxxb.setJzl(Double.valueOf(split[3]));
  568 +// ylxxb.setNylx(Integer.valueOf(split[4]));
  569 +// ylxxb.setStationid(split[5]);
  570 +// if(split[6].contains("-")){
  571 +// ylxxb.setJsy(split[6].split("-")[1]);
  572 +// }
  573 +// ylxxb.setBz(split[6]);
  574 +// ylxxb.setJylx(Integer.valueOf(split[7]));
  575 +// ylxxbRepository.save(ylxxb);
  576 +// }
  577 + wb.close();
  578 + fs.close();
  579 + } catch (Exception e) {
  580 + // TODO Auto-generated catch block
  581 + e.printStackTrace();
  582 + return "文件导入失败";
  583 + } finally {
  584 + file.delete();
  585 + }
  586 + return "文件导入成功";
  587 + }
  588 +
  589 +
  590 +}