CwjyServiceImpl.java
7.47 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
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.Arrays;
import java.util.HashMap;
import java.util.List;
import java.util.Map;
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.bsth.common.ResponseCode;
import com.bsth.entity.oil.Cwjy;
import com.bsth.entity.oil.Ylxxb;
import com.bsth.repository.oil.CwjyRepository;
import com.bsth.repository.oil.YlxxbRepository;
import com.bsth.service.impl.BaseServiceImpl;
import com.bsth.service.oil.CwjyService;
import com.bsth.util.PageHelper;
import com.bsth.util.PageObject;
@Service
public class CwjyServiceImpl extends BaseServiceImpl<Cwjy,Integer> implements CwjyService
{
@Autowired
CwjyRepository repository;
@Autowired
YlxxbRepository ylxxbRepository;
@Autowired
JdbcTemplate jdbcTemplate;
@SuppressWarnings("unchecked")
public PageObject<Ylxxb> Pagequery(Map<String, Object> map) {
int page=Integer.parseInt(map.get("page").toString());
SimpleDateFormat sdf=new SimpleDateFormat("yyyy-MM-dd");
String rq=map.get("rq").toString();
String nbbm="";
if(map.get("nbbh")!=null){
nbbm=map.get("nbbh").toString();
}
Object gsdmIn=map.get("gsdm_in");
Object fgsdmIn=map.get("fgsdm_in");
String addSql="";
String gsdmLike="";
String fgsdmLike="";
//选择了公司
if(gsdmIn==null){
gsdmLike=map.get("gsdm_like").toString();
addSql += " and a.gsdm = '"+gsdmLike+ "' ";
//选择了分公司
if(fgsdmIn==null){
fgsdmLike=map.get("fgsdm_like").toString();;
addSql += " and a.fgsdm = '"+fgsdmLike+ "' ";
}else{
String fgsdmIns[]= fgsdmIn.toString().split(",");
addSql +=" and a.fgsdm in (";
for(int i=0;i<fgsdmIns.length;i++){
addSql +="'"+fgsdmIns[i]+"'";
if(i<fgsdmIns.length-1){
addSql +=",";
}
}
addSql +=")";
}
}else{
//没有选择公司 (分公司也没有选择)
String gsdmIns[]=gsdmIn.toString().split(",");
addSql += " and a.gsdm in (";
for(int i=0;i<gsdmIns.length;i++){
addSql +="'" +gsdmIns[i]+"'";
if(i<gsdmIns.length-1){
addSql+=",";
}
}
addSql +=")";
String fgsdmIns[]= fgsdmIn.toString().split(",");
addSql +=" and a.fgsdm in (";
for(int i=0;i<fgsdmIns.length;i++){
addSql +="'"+fgsdmIns[i]+"'";
if(i<fgsdmIns.length-1){
addSql +=",";
}
}
addSql +=")";
}
String countSql="SELECT ifnull(count(*),0) as countTs FROM bsth_c_cwjy a "+
" left join ( select * from bsth_c_ylxxb b where to_days(b.yyrq)=to_days('"+rq+"') and jylx=1) b " +
" on a.nbbm=b.nbbm left join (select nbbm,group_concat(jsy) as jsy "
+ "from bsth_c_ylb where to_days(rq)= to_days('"+rq+"' ) group by nbbm "+
" ) c on a.nbbm=c.nbbm where a.nbbm like '%"+nbbm+"%' " +addSql ;
int listsize=jdbcTemplate.queryForObject(countSql, Integer.class);
// TODO Auto-generated method stub
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,"
+ "b.nylx as nylx,b.yj as yj,b.bz as bz,c.jsy as ldgh FROM bsth_c_cwjy a "+
" left join ( select * from bsth_c_ylxxb b where to_days(b.yyrq)=to_days('"+rq+"') and jylx=1) b " +
" on a.nbbm=b.nbbm left join (select nbbm,group_concat(jsy) as jsy "
+ "from bsth_c_ylb where to_days(rq)= to_days('"+rq+"' ) group by nbbm "+
" ) c on a.nbbm=c.nbbm where a.nbbm like '%"+nbbm+"%' " +addSql+ " limit "+page*10+","+10;
List<Ylxxb> yList= jdbcTemplate.query(sql,
new RowMapper<Ylxxb>(){
@Override
public Ylxxb mapRow(ResultSet rs, int rowNum) throws SQLException {
Ylxxb t=new Ylxxb();
t.setGsdm(rs.getString("gsdm"));
t.setFgsdm(rs.getString("fgsdm"));
t.setNbbm(rs.getString("nbbm"));
t.setJsy(rs.getString("jsy"));
t.setJzl(rs.getDouble("jzl"));
t.setStationid(rs.getString("stationid"));
t.setNylx(rs.getInt("nylx"));
t.setYj(rs.getDouble("yj"));
t.setBz(rs.getString("bz"));
t.setLdgh(rs.getString("ldgh"));
return t;
}
});
/*List<Object[]> list=repository.obtainCwjycl(rq,nbbm);
for (int i = 0; i < list.size(); i++) {
Ylxxb y=new Ylxxb();
y.setGsdm(list.get(i)[0]==null?"":list.get(i)[0].toString());
y.setNbbm(list.get(i)[1]==null?"":list.get(i)[1].toString());
y.setJsy(list.get(i)[2]==null?"":list.get(i)[2].toString());
y.setJzl(list.get(i)[3]==null?0.0:Double.parseDouble(list.get(i)[3].toString()));
y.setStationid(list.get(i)[4]==null?"":list.get(i)[4].toString());
y.setNylx(list.get(i)[5]==null?0:Integer.parseInt(list.get(i)[5].toString()));
y.setYj(list.get(i)[6]==null?0.0:Double.parseDouble(list.get(i)[6].toString()));
y.setBz(list.get(i)[7]==null?"":list.get(i)[7].toString());
y.setLdgh(list.get(i)[8]==null?"":list.get(i)[8].toString());
try {
y.setYyrq(sdf.parse(rq));
} catch (ParseException e) {
// TODO Auto-generated catch block
e.printStackTrace();
}
yList.add(y);
}*/
PageHelper pageHelper = new PageHelper(listsize, map);
pageHelper.getMap();
PageObject<Ylxxb> pageObject=pageHelper.getPageObject();
pageObject.setDataList(yList);
return pageObject;
}
@Override
public Ylxxb bynbbm(Map<String, Object> map) {
// TODO Auto-generated method stub
// TODO Auto-generated method stub
SimpleDateFormat sdf = new SimpleDateFormat("yyyy-MM-dd");
String rq = map.get("rq").toString();
String nbbm = "";
if (map.get("nbbm") != null) {
nbbm = map.get("nbbm").toString();
}
List<Object[]> list = repository.obtainCwjycl(rq, nbbm);
Ylxxb y = new Ylxxb();
if (list.size() > 0) {
y.setGsdm(list.get(0)[0] == null ? "" : list.get(0)[0].toString());
y.setNbbm(list.get(0)[1] == null ? "" : list.get(0)[1].toString());
y.setJsy(list.get(0)[2] == null ? "" : list.get(0)[2].toString());
y.setJzl(list.get(0)[3] == null ? 0.0 : Double.parseDouble(list.get(0)[3].toString()));
y.setStationid(list.get(0)[4] == null ? "" : list.get(0)[4].toString());
y.setNylx(list.get(0)[5] == null ? 0 : Integer.parseInt(list.get(0)[5].toString()));
y.setYj(list.get(0)[6] == null ? 0.0 : Double.parseDouble(list.get(0)[6].toString()));
y.setBz(list.get(0)[7] == null ? "" : list.get(0)[7].toString());
y.setLdgh(list.get(0)[8] == null ? "" : list.get(0)[8].toString());
try {
y.setYyrq(sdf.parse(rq));
} catch (ParseException e) {
// TODO Auto-generated catch block
e.printStackTrace();
}
}
return y;
}
@Override
public Map<String, Object> savejzl(Ylxxb t) {
// TODO Auto-generated method stub
Map<String, Object> map=new HashMap<String,Object>();
try {
SimpleDateFormat sdf = new SimpleDateFormat("yyyy-MM-dd");
String rq = sdf.format(t.getYyrq());
String nbbm=t.getNbbm();
List<Ylxxb> yList=ylxxbRepository.obtainYlxx2(rq,nbbm);
if(yList.size()>0){
t.setId(yList.get(0).getId());
ylxxbRepository.save(t);
}else{
ylxxbRepository.save(t);
}
map.put("status", ResponseCode.SUCCESS);
} catch (Exception e) {
map.put("status", ResponseCode.ERROR);
e.printStackTrace();
// TODO: handle exception
}
return map;
}
}