ScheduleRealInfoServiceImpl.java
10.5 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
package com.bsth.service.impl;
import com.bsth.entity.ScheduleRealInfo;
import com.bsth.entity.result.CalcWaybill;
import com.bsth.repository.ScheduleRealInfoRepository;
import com.bsth.service.*;
import com.bsth.util.Arith;
import org.joda.time.format.DateTimeFormat;
import org.joda.time.format.DateTimeFormatter;
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 java.sql.ResultSet;
import java.sql.SQLException;
import java.util.ArrayList;
import java.util.Date;
import java.util.HashMap;
import java.util.List;
import java.util.Map;
import java.util.Set;
import com.bsth.entity.*;
/**
* Created by panzhao on 2017/7/27.
*/
@Service
public class ScheduleRealInfoServiceImpl implements ScheduleRealInfoService {
@Autowired
ScheduleRealInfoRepository scheduleRealInfoRepository;
@Autowired
CulateMileageService culateMileageService;
@Autowired
JdbcTemplate jdbcTemplate;
@Autowired
LineConfigService lineConfigService;
Logger logger = LoggerFactory.getLogger(this.getClass());
private static DateTimeFormatter fmtyyyyMMddHHmm = DateTimeFormat.forPattern("yyyy-MM-ddHH:mm"),
fmtyyyyMMdd = DateTimeFormat.forPattern("yyyy-MM-dd"),
fmtHHmm = DateTimeFormat.forPattern("HH:mm");
private final static long DAY_TIME = 1000 * 60 * 60 * 24L;
@Override
public List<CalcWaybill> findAll(String rq,String lineCode) {
List<CalcWaybill> listCal=new ArrayList<CalcWaybill>();
List<ScheduleRealInfo> list = scheduleRealInfoRepository.findAll(rq,lineCode);
String sql ="select r.j_gh ,r.s_gh,r.cl_zbh,r.xl_bm, r.lp_name FROM"
+ " bsth_c_s_sp_info_real r where "
+ " r.schedule_date_str='"+rq+"' and r.xl_bm = '"+lineCode+"'"
+ " GROUP BY r.j_gh,r.xl_bm,r.lp_name ";
List<Map<String, String>> listMap = jdbcTemplate.query(sql, new RowMapper<Map<String, String>>() {
@Override
public Map<String, String> mapRow(ResultSet arg0, int arg1) throws SQLException {
Map<String, String> c = new HashMap<String,String>();
c.put("jGh", arg0.getString("j_gh"));
c.put("sGh", arg0.getString("s_gh")==null?"":arg0.getString("s_gh"));
c.put("clZbh", arg0.getString("cl_zbh"));
c.put("xlBm", arg0.getString("xl_bm"));
c.put("lpName", arg0.getString("lp_name"));
return c;
}
});
for (int i = 0; i < listMap.size(); i++) {
Map<String, String> m=listMap.get(i);
String jGh=m.get("jGh");
String sGh=m.get("sGh");
String clZbh=m.get("clZbh");
String xlBm=m.get("xlBm");
String lpName=m.get("lpName");
//所有数据排班数据
List<ScheduleRealInfo> list_=new ArrayList<ScheduleRealInfo>();
//执行了的班次的排班数据
List<ScheduleRealInfo> lists_=new ArrayList<ScheduleRealInfo>();
for (int j = 0; j < list.size(); j++) {
ScheduleRealInfo s=list.get(j);
if(jGh.equals(s.getjGh())
&& sGh.equals(s.getsGh()==null?"":s.getsGh())
&& clZbh.equals(s.getClZbh())
&& xlBm.equals(s.getXlBm())
&& lpName.equals(s.getLpName())){
list_.add(s);
Set<ChildTaskPlan> cts = s.getcTasks();
if(cts != null && cts.size() > 0){
lists_.add(s);
}else{
if(s.getZdsjActual()!=null
&& s.getFcsjActual() !=null){
lists_.add(s);
}
}
}
}
//计算方法
if(list_.size()>0){
listCal.addAll(this.cul(list_, lists_));
}
}
return listCal;
}
//list_ 全部班次 lists_执行了的班次(实到实发不为空)
private List<CalcWaybill> cul(List<ScheduleRealInfo> list_,List<ScheduleRealInfo> lists_){
List<CalcWaybill> list=new ArrayList<CalcWaybill>();
if(list_.size()>0){
Date date=list_.get(0).getScheduleDate();
String dateStr=list_.get(0).getScheduleDateStr();
String gsdm=list_.get(0).getGsBm();
String gsname=list_.get(0).getGsName();
String fgsdm=list_.get(0).getFgsBm();
String fgsname=list_.get(0).getFgsName();
String xlbm=list_.get(0).getXlBm();
String xlname=list_.get(0).getXlName();
String lp=list_.get(0).getLpName();
String jgh=list_.get(0).getjGh();
String jname=list_.get(0).getjName();
String sgh=list_.get(0).getsGh();
String sname=list_.get(0).getsName();
String clzbh=list_.get(0).getClZbh();
int jhyybc=culateMileageService.culateJhyybc(list_, "");
int jhyybcZgf=culateMileageService.culateJhyybc(list_, "zgf");
int jhyybcWgf=culateMileageService.culateJhyybc(list_, "wgf");
double jhyylc=culateMileageService.culateJhyylc(list_);
double jhfyylc=culateMileageService.culateJhfyylc(list_);
int sjyybc=culateMileageService.culateSjyybc(lists_, "");
int sjyybcZgf=culateMileageService.culateSjyybc(lists_, "zgf");
int sjyybcWgf=culateMileageService.culateSjyybc(lists_, "wgf");
double sjyylc=culateMileageService.culateSjyylc(lists_);//驾售共有
double sjyylc_j=culateMileageService.culateSjyylc_j(lists_);//无售
double sjfyylc=culateMileageService.culateSjfyylc(lists_);//驾售
double sjfyylc_j=culateMileageService.culateSjfyylc_j(lists_);//无售
int ljbc=culateMileageService.culateLjbc(lists_, "");
int ljbcZgf=culateMileageService.culateLjbc(lists_, "zgf");
int ljbcWgf=culateMileageService.culateLjbc(lists_, "wgf");
double ljyylc=culateMileageService.culateLjyylc(lists_);//驾售
double ljyylc_j=culateMileageService.culateLjyylc(lists_);//无售
double ljfyylc=culateMileageService.culateLjfyylc(lists_);//驾售
double ljfyylc_j=culateMileageService.culateLjfyylc_j(lists_);//无售
int lbbc=culateMileageService.culateLbbc(list_);
double lblc=culateMileageService.culateLbgl(list_);
double ssgl_lz= culateMileageService.culateCJLC(list_, "路阻");
double ssgl_dm= culateMileageService.culateCJLC(list_, "吊慢");
double ssgl_gz= culateMileageService.culateCJLC(list_, "故障");
double ssgl_jf= culateMileageService.culateCJLC(list_, "纠纷");
double ssgl_zs= culateMileageService.culateCJLC(list_, "肇事");
double ssgl_qr= culateMileageService.culateCJLC(list_, "缺人");
double ssgl_qc= culateMileageService.culateCJLC(list_, "缺车");
double ssgl_kx= culateMileageService.culateCJLC(list_, "客稀");
double ssgl_qh= culateMileageService.culateCJLC(list_, "气候");
double ssgl_yw= culateMileageService.culateCJLC(list_, "援外");
double ssgl_pc=culateMileageService.culateCJLC(list_, "配车");
double ssgl_by=culateMileageService.culateCJLC(list_, "保养");
double ssgl_cj=culateMileageService.culateCJLC(list_, "抽减");
double ssgl_qt=culateMileageService.culateCJLC(list_, "其他");
double ssgl_qtz=Arith.add(Arith.add(ssgl_pc, ssgl_by), Arith.add(ssgl_cj,ssgl_qt));
int fzbc=culateMileageService.culateDtfzbc(lists_, "major", "");//放站
int fzbcZgf=culateMileageService.culateDtfzbc(lists_, "major", "zgf");
int fzbcWgf=culateMileageService.culateDtfzbc(lists_, "major", "wgf");
int zfbc=culateMileageService.culateDtfzbc(lists_, "venting", "");//直放
int zfbcZgf=culateMileageService.culateDtfzbc(lists_, "venting", "zgf");
int zfbcWgf=culateMileageService.culateDtfzbc(lists_, "venting", "wgf");
CalcWaybill t=new CalcWaybill();
t.setRq(date);
t.setRqStr(dateStr);
t.setGsdm(gsdm);
t.setGsname(gsname);
t.setFgsdm(fgsdm);
t.setFgsname(fgsname);
t.setXl(xlbm);
t.setXlName(xlname);
t.setLp(lp);
t.setCl(clzbh);
t.setjGh(jgh);
t.setjName(jname);
t.setsGh(sgh);
t.setsName(sname);
t.setJhyybc(jhyybc);
t.setJhyybczgf(jhyybcZgf);
t.setJhyybcwgf(jhyybcWgf);
t.setJhyylc(jhyylc);
t.setJhfyylc(jhfyylc);
t.setSjyybc(sjyybc);
t.setSjyybczgf(sjyybcZgf);
t.setSjyybcwgf(sjyybcWgf);
t.setSjyylc(sjyylc);
t.setSjfyylc(sjfyylc);
t.setLjbc(ljbc);
t.setLjbczgf(ljbcZgf);
t.setLjbcwgf(ljbcWgf);
t.setLjyylc(ljyylc);
t.setLjfyylc(ljfyylc);
t.setLbbc(lbbc);
t.setLblc(lblc);
t.setLblcLz(ssgl_lz);
t.setLblcDm(ssgl_dm);
t.setLblcGz(ssgl_gz);
t.setLblcJf(ssgl_jf);
t.setLblcZs(ssgl_zs);
t.setLblcQr(ssgl_qr);
t.setLblcQc(ssgl_qc);
t.setLblcKx(ssgl_kx);
t.setLblcQh(ssgl_qh);
t.setLblcYw(ssgl_yw);
t.setLblcQt(ssgl_qtz);
t.setFzbc(fzbc+zfbc);
t.setFzbczgf(fzbcZgf+zfbcZgf);
t.setFzbcwgf(fzbcWgf+zfbcWgf);
t.setDtbc(0);
t.setDtbczgf(0);
t.setDtbcwgf(0);
list.add(t);
//驾驶员单独行驶里程
if(sjyylc_j>0||sjfyylc_j>0||ljyylc_j>0||ljfyylc_j>0){
CalcWaybill t_=new CalcWaybill();
t_.setRq(date);
t_.setRqStr(dateStr);
t_.setGsdm(gsdm);
t_.setGsname(gsname);
t_.setFgsdm(fgsdm);
t_.setFgsname(fgsname);
t_.setXl(xlbm);
t_.setXlName(xlname);
t_.setLp(lp);
t_.setCl(clzbh);
t_.setjGh(jgh);
t_.setjName(jname);
t_.setSjyylc(sjyylc_j);
t_.setSjfyylc(sjfyylc_j);
t_.setLjyylc(ljyylc_j);
t_.setLjfyylc(ljfyylc_j);
t_.setsGh("");
t_.setsName("");
t_.setJhyybc(0);
t_.setJhyybczgf(0);
t_.setJhyybcwgf(0);
t_.setJhyylc(0.0);
t_.setJhfyylc(0.0);
t_.setSjyybc(0);
t_.setSjyybczgf(0);
t_.setSjyybcwgf(0);
t_.setLjbc(0);
t_.setLjbczgf(0);
t_.setLjbcwgf(0);
t_.setLbbc(0);
t_.setLblc(0.0);
t_.setLblcLz(0.0);
t_.setLblcDm(0.0);
t_.setLblcGz(0.0);
t_.setLblcJf(0.0);
t_.setLblcZs(0.0);
t_.setLblcQr(0.0);
t_.setLblcQc(0.0);
t_.setLblcKx(0.0);
t_.setLblcQh(0.0);
t_.setLblcYw(0.0);
t_.setLblcQt(0.0);
t_.setFzbc(0);
t_.setFzbczgf(0);
t_.setFzbcwgf(0);
t_.setDtbc(0);
t_.setDtbczgf(0);
t_.setDtbcwgf(0);
list.add(t_);
}
}
return list;
}
}