YlxxbServiceImpl.java
9.63 KB
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
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
package com.bsth.service.oil.impl;
import java.sql.ResultSet;
import java.sql.SQLException;
import java.text.ParseException;
import java.text.SimpleDateFormat;
import java.util.ArrayList;
import java.util.Date;
import java.util.HashMap;
import java.util.List;
import java.util.Map;
import javax.transaction.Transactional;
import org.apache.commons.lang3.StringEscapeUtils;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.jdbc.core.JdbcTemplate;
import org.springframework.jdbc.core.RowMapper;
import org.springframework.stereotype.Service;
import com.alibaba.fastjson.JSONArray;
import com.alibaba.fastjson.JSONObject;
import com.bsth.common.ResponseCode;
import com.bsth.entity.excep.Offline;
import com.bsth.entity.oil.Ylb;
import com.bsth.entity.oil.Ylxxb;
import com.bsth.entity.oil.YlxxbUpdate;
import com.bsth.entity.search.CustomerSpecs;
import com.bsth.repository.oil.YlbRepository;
import com.bsth.repository.oil.YlxxbRepository;
import com.bsth.repository.oil.YlxxbUpdateRepository;
import com.bsth.service.impl.BaseServiceImpl;
import com.bsth.service.oil.YlxxbService;
import com.bsth.util.PageHelper;
import com.bsth.util.PageObject;
@Service
public class YlxxbServiceImpl extends BaseServiceImpl<Ylxxb,Integer> implements YlxxbService
{
Logger logger = LoggerFactory.getLogger(this.getClass());
@Autowired
YlxxbRepository repository;
@Autowired
YlxxbUpdateRepository updateRepository;
@Autowired
YlbRepository ylbRepository;
@Autowired
JdbcTemplate jdbcTemplate;
@Override
public PageObject<Ylxxb> Pagequery(Map<String, Object> map) {
String rq=map.get("yyrq").toString();
String gsdm=map.get("gsdm_like").toString();
String fgsdm=map.get("fgsdm_like").toString();
String sql=" select * from ("
+ "select *,CONCAT(nbbm,jsy) as nj "
+ " from bsth_c_ylxxb where yyrq='"+rq+"' "
+ " and gsdm ='"+gsdm+"' and jylx !='1') x where x.nj not in ("
+ " select CONCAT(nbbm,jsy) from bsth_c_ylb "
+ " where rq='"+rq+"'"
+ " and ssgsdm='"+gsdm+"' and fgsdm ='"+fgsdm+"')"
+ " and x.nbbm in (select nbbm from bsth_c_ylb "
+ " where rq='"+rq+"'"
+ " and ssgsdm='"+gsdm+"' and fgsdm ='"+fgsdm+"') "
+ " and x.nbbm not in (select nbbm from bsth_c_ylxxb"
+ " where yyrq='"+rq+"' and gsdm ='"+gsdm+"' AND jylx !='0')";
/*String sql= "select v.*,u.jsy as ldgh from "
+ " ( select * from bsth_c_ylxxb x where "
+ " DATE_FORMAT(x.yyrq,'%Y-%m-%d')='"+rq+"' and x.gsdm='"+gsdm+"'"
+ " and x.jsy not in ("
+ " select jsy from bsth_c_ylb "
+ " where DATE_FORMAT(rq,'%Y-%m-%d')='"+rq+"' "
+ " and ssgsdm='"+gsdm+"' and fgsdm='"+fgsdm+"')"
+ " and x.nbbm in (select nbbm from bsth_c_ylb "
+ " where DATE_FORMAT(rq,'%Y-%m-%d')='"+rq+"' "
+ " and ssgsdm='"+gsdm+"' and fgsdm='"+fgsdm+"' )) v "
+ " left join (select * from bsth_c_ylb "
+ " where DATE_FORMAT(rq,'%Y-%m-%d')='"+rq+"'"
+ " and ssgsdm='"+gsdm+"' and fgsdm='"+fgsdm+"' ) u "
+ " on v.nbbm=u.nbbm ";*/
//根具条件查询指定日期Ylxxb的数据
// List<Ylxxb> iterator=repository.checkYlxx(rq,gsdm);
/*if(map.get("gsdm_in")!=null){
map.put("ssgsdm_in", map.get("gsdm_in"));
map.remove("gsdm_in");
}else{
map.put("ssgsdm_like", map.get("gsdm_like"));
map.remove("gsdm_like");
}*/
//根具条件查询指定日期Ylb的数据
// List<Ylb> ylbIterator=ylbRepository.checkYl(rq,gsdm,fgsdm);
List<Ylxxb> list=jdbcTemplate.query(sql,
new RowMapper<Ylxxb>(){
@Override
public Ylxxb mapRow(ResultSet rs, int rowNum) throws SQLException {
Ylxxb s = new Ylxxb();
s.setId(rs.getInt("id"));
s.setYyrq(rs.getDate("yyrq"));
s.setNbbm(rs.getString("nbbm"));
s.setGsdm(rs.getString("gsdm"));
s.setFgsdm(rs.getString("fgsdm"));
s.setJsy(rs.getString("jsy"));
s.setJzl(rs.getDouble("jzl"));
s.setStationid(rs.getString("stationid"));
s.setNylx(rs.getInt("nylx"));
s.setJyggh(rs.getString("jyggh"));
s.setYj(rs.getDouble("yj"));
// s.setLdgh(rs.getString("ldgh"));
s.setBz(rs.getString("bz"));
return s;
}
});
List<Ylb> listylb=ylbRepository.obtainYl(rq, gsdm, fgsdm, "", "", "nbbm");
for (int i = 0; i < list.size(); i++) {
String ldgh="";
for (int j = 0; j < listylb.size(); j++) {
Ylb ylb =listylb.get(j);
if(list.get(i).getNbbm().equals(ylb.getNbbm())){
if(ldgh.equals(""))
ldgh +=ylb.getJsy();
else
ldgh += ","+ylb.getJsy();
}
}
list.get(i).setLdgh(ldgh);
}
//正式使用用下面代码
// for (int i = 0; i < iterator.size(); i++) {
// Ylxxb y1=iterator.get(i);
// boolean fage=true;
// String ldgh="";
// for (int j = 0; j < ylbIterator.size(); j++) {
// Ylb y2 = ylbIterator.get(j);
// if(y1.getNbbm().equals(y2.getNbbm())){
// if(y1.getJsy().equals(y2.getJsy())){
// fage=false;
// }
// ldgh +=y2.getJsy()+"/";
// }
// }
// if(fage){
// y1.setLdgh(ldgh);
// list.add(y1);
// }
// }
PageHelper pageHelper = new PageHelper(list.size(), map);
pageHelper.getMap();
PageObject<Ylxxb> pageObject = pageHelper.getPageObject();
pageObject.setDataList(list);
return pageObject;
}
@Transactional
@Override
public Map<String, Object> checkJsy(Map<String, Object> map) throws Exception{
Map<String, Object> newMap=new HashMap<String,Object>();
// TODO Auto-generated method stub
try {
// int id=Integer.parseInt(map.get("id").toString());
// String jsy=map.get("jsy").toString();
// Ylxxb ylxxb=repository.findOne(id);
// ylxxb.setJsy(jsy);
// repository.save(ylxxb);
String json =StringEscapeUtils.unescapeHtml4(map.get("ylbList").toString());
JSONArray jsonArray=JSONArray.parseArray(json);
JSONObject jsonObject;
for (int x = 0; x < jsonArray.size(); x++) {
jsonObject=jsonArray.getJSONObject(x);
Integer id =jsonObject.getInteger("id");
String jsy =jsonObject.getString("jsy");
Ylxxb ylxxb=repository.findOne(id);
if(!ylxxb.getJsy().equals(jsy)){
ylxxb.setJsy(jsy);
ylxxb.setJylx(3);
repository.save(ylxxb);
}
}
newMap.put("status", ResponseCode.SUCCESS);
}catch(Exception e){
newMap.put("status", ResponseCode.ERROR);
logger.error("save erro.", e);
throw e;
}
return newMap;
}
@Override
public List<Ylxxb> Pagequery_nbbm(Map<String, Object> map) {
// TODO Auto-generated method stub
String rq=map.get("yyrq").toString();
String gsdm=map.get("gsdm_like").toString();
String nbbm=map.get("nbbm").toString();
String sql="select * from (select *,CONCAT(t.nbbm,'_',t.jsy,'_',t.jzl) as tj "
+ " from bsth_c_ylxxb t where t.yyrq='"+rq+"' and t.gsdm='"+gsdm+"' and "
+ " t.nylx=0 and t.jylx=0 and t.nbbm like '%"+nbbm+"%') y "
+ " where y.nbbm not in (select c.inside_code from bsth_c_cars c "
+ " where c.business_code ='05' and c.sfdc=0) and y.tj not in ("
+ " select x.tj from bsth_c_ylxxb_update x)";
//根具条件查询指定日期Ylb的数据
// List<Ylb> ylbIterator=ylbRepository.checkYl(rq,gsdm,fgsdm);
List<Ylxxb> list=jdbcTemplate.query(sql,
new RowMapper<Ylxxb>(){
@Override
public Ylxxb mapRow(ResultSet rs, int rowNum) throws SQLException {
Ylxxb s = new Ylxxb();
s.setId(rs.getInt("id"));
s.setYyrq(rs.getDate("yyrq"));
s.setNbbm(rs.getString("nbbm"));
s.setGsdm(rs.getString("gsdm"));
s.setJsy(rs.getString("jsy"));
s.setJzl(rs.getDouble("jzl"));
s.setStationid(rs.getString("stationid"));
s.setNylx(rs.getInt("nylx"));
s.setJyggh(rs.getString("jyggh"));
s.setYj(rs.getDouble("yj"));
// s.setLdgh(rs.getString("ldgh"));
s.setBz(rs.getString("bz"));
return s;
}
});
return list;
}
@Transactional
@Override
public Map<String, Object> checkNbbm(Map<String, Object> map) throws Exception{
Map<String, Object> newMap=new HashMap<String,Object>();
// TODO Auto-generated method stub
try {
// int id=Integer.parseInt(map.get("id").toString());
// String jsy=map.get("jsy").toString();
// Ylxxb ylxxb=repository.findOne(id);
// ylxxb.setJsy(jsy);
// repository.save(ylxxb);
String json =StringEscapeUtils.unescapeHtml4(map.get("ylbList").toString());
JSONArray jsonArray=JSONArray.parseArray(json);
JSONObject jsonObject;
for (int x = 0; x < jsonArray.size(); x++) {
jsonObject=jsonArray.getJSONObject(x);
Integer id =jsonObject.getInteger("id");
String nbbm =jsonObject.getString("nbbm").trim();
Ylxxb ylxxb=repository.findOne(id);
if(!ylxxb.getNbbm().equals(nbbm)){
ylxxb.setNbbm(nbbm);
ylxxb.setJylx(2);
repository.save(ylxxb);
YlxxbUpdate ylxxbUpdate=new YlxxbUpdate();
ylxxbUpdate.setGsdm(ylxxb.getGsdm());
ylxxbUpdate.setJsy(ylxxb.getJsy());
ylxxbUpdate.setJzl(ylxxb.getJzl());
ylxxbUpdate.setJlrq(ylxxb.getJlrq());
ylxxbUpdate.setNbbm(ylxxb.getNbbm());
ylxxbUpdate.setYyrq(ylxxb.getYyrq());
ylxxbUpdate.setCreatetime(new Date());
ylxxbUpdate.setTj(nbbm+"_"+ylxxb.getJsy()+"_"+ylxxb.getJzl());
updateRepository.save(ylxxbUpdate);
}
}
newMap.put("status", ResponseCode.SUCCESS);
}catch(Exception e){
newMap.put("status", ResponseCode.ERROR);
logger.error("save erro.", e);
throw e;
}
return newMap;
}
}