Commit ca0b7775d9cbf96640fbf505b960de65e3b3db78

Authored by 娄高锋
1 parent 6286a676

场外加油:导入excel中驾驶员工号带有标点符号的提示错误(排除将加电导入加油的风险)

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.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 - 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 + System.out.println(jsy);
  523 + if(jsy != null && jsy.length() > 0 && !(jsy.equals(jsy.replaceAll("\\p{P}", "")))){
  524 + return "场外加油:驾驶员工号错误,请检查是否导入错误excel";
  525 + }
  526 +
  527 + List<Double> jzl_ = repository.import_queryBySame(gsbm, rq, nbbm);
  528 +//
  529 + if(jzl_.size() == 0){
  530 + repository.import_insertData(gsbm, rq, nbbm, jsy,
  531 + df.format(jzl), jyz, remarks, sd.format(new Date()));
  532 + }else{
  533 + repository.import_UpdateJzl(df.format(jzl), jsy, jyz, remarks, gsbm, rq, nbbm);
  534 + }
  535 + }
  536 +
  537 + /** 以下为测试导入ylxxb用 */
  538 +// Date date = new Date();
  539 +// SimpleDateFormat dateFormat = new SimpleDateFormat("yyyy-MM-dd HH:mm:ss");
  540 +// for(int i = 1; i < rowNum; i++){
  541 +// row = sheet.getRow(i);
  542 +// if (row == null){
  543 +// continue;
  544 +// }
  545 +// String text = "";
  546 +// for(int j = 0; j < cellNum; j++){
  547 +// cell = row.getCell(j);
  548 +// if(cell == null){
  549 +// text += ",";
  550 +// continue;
  551 +// }
  552 +// if(j == 1 && cell.getCellType() == Cell.CELL_TYPE_NUMERIC){
  553 +// text += dateFormat.format(cell.getDateCellValue()) + ",";
  554 +// } else if(j == 4 || j == 7){
  555 +// text += "0,";
  556 +//// } else if(j == 6 && String.valueOf(cell).contains("-")){
  557 +//// String str = String.valueOf(cell);
  558 +//// text += str.split("-")[1] + ",";
  559 +// } else {
  560 +// text += String.valueOf(cell) + ",";
  561 +// }
  562 +// }
  563 +// System.out.println(text);
  564 +// Ylxxb ylxxb = new Ylxxb();
  565 +// String[] split = text.split(",");
  566 +// ylxxb.setCreatetime(date);
  567 +// ylxxb.setYyrq(sdf.parse(split[0].trim()));
  568 +// ylxxb.setJlrq(dateFormat.parse(split[1]));
  569 +// ylxxb.setFromgsdm("22");
  570 +// ylxxb.setNbbm(split[2]);
  571 +// ylxxb.setJzl(Double.valueOf(split[3]));
  572 +// ylxxb.setNylx(Integer.valueOf(split[4]));
  573 +// ylxxb.setStationid(split[5]);
  574 +// if(split[6].contains("-")){
  575 +// ylxxb.setJsy(split[6].split("-")[1]);
  576 +// }
  577 +// ylxxb.setBz(split[6]);
  578 +// ylxxb.setJylx(Integer.valueOf(split[7]));
  579 +// ylxxbRepository.save(ylxxb);
  580 +// }
  581 + wb.close();
  582 + fs.close();
  583 + } catch (Exception e) {
  584 + // TODO Auto-generated catch block
  585 + e.printStackTrace();
  586 + return "文件导入失败";
  587 + } finally {
  588 + file.delete();
  589 + }
  590 + return "文件导入成功";
  591 + }
  592 +
  593 +
590 } 594 }
591 \ No newline at end of file 595 \ No newline at end of file