CalcToolServiceImpl.java
11.9 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
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
package com.bsth.service.calc.impl;
import java.util.ArrayList;
import java.util.Date;
import java.util.HashMap;
import java.util.HashSet;
import java.util.List;
import java.util.Map;
import java.util.Set;
import com.bsth.entity.calc.CalcWaybill;
import com.bsth.entity.realcontrol.ChildTaskPlan;
import com.bsth.entity.realcontrol.ScheduleRealInfo;
import com.bsth.entity.sys.Interval;
import com.bsth.repository.calc.CalcIntervalRepository;
import com.bsth.repository.calc.CalcWaybillRepository;
import com.bsth.service.calc.CalcToolService;
import com.bsth.service.calc.CalcCulateMileageService;
import com.bsth.util.Arith;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.jdbc.core.JdbcTemplate;
import org.springframework.stereotype.Service;
/**
* Created by 17/11/16.
*/
@Service
public class CalcToolServiceImpl implements CalcToolService {
@Autowired
private CalcCulateMileageService culateMileageService;
@Autowired
JdbcTemplate jdbcTemplate;
Logger logger = LoggerFactory.getLogger(this.getClass());
@Override
public List<CalcWaybill> findAll(String rq, String lineCode, List<ScheduleRealInfo> list, List<Map<String, Object>> xlList, List<Interval> djgList) {
List<CalcWaybill> listCal=new ArrayList<CalcWaybill>();
List<Map<String, String>> listMap = new ArrayList<Map<String, String>>();
Set<String> tempSet = new HashSet<String>();
for(ScheduleRealInfo s : list){
String jGh = s.getjGh()!=null?s.getjGh().trim():"";
String sGh = s.getsGh()!=null?s.getsGh().trim():"";
String clZbh = s.getClZbh()!=null?s.getClZbh().trim():"";
String xlBm = s.getXlBm()!=null?s.getXlBm().trim():"";
String lpName = s.getLpName()!=null?s.getLpName().trim():"";
String key = jGh + sGh + clZbh + xlBm + lpName;
if(tempSet.add(key)){
Map<String, String> m = new HashMap<String, String>();
m.put("jGh", jGh);
m.put("sGh", sGh);
m.put("clZbh", clZbh);
m.put("xlBm", xlBm);
m.put("lpName", lpName);
listMap.add(m);
}
}
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);
s.setCreateDate(new Date());
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_, xlList, djgList));
}
}
while(true){
int i = 0, l = 0;
boolean flag = false;
for(; i < listCal.size(); i++){
CalcWaybill c1 = listCal.get(i);
String key = c1.getRqStr() +"-"+ c1.getXl() +"-"+ c1.getCl() +"-"+ c1.getjGh() +"-"+ c1.getsGh() +"-"+ c1.getLp();
for(l = 0; l < listCal.size(); l++){
if(l != i){
CalcWaybill c2 = listCal.get(l);
String key_ = c2.getRqStr() +"-"+ c2.getXl() +"-"+ c2.getCl() +"-"+ c2.getjGh() +"-"+ c2.getsGh() +"-"+ c2.getLp();
if(key_.equals(key)){
flag = true;
break;
}
}
}
if(flag){
break;
}
}
if(i != l){
CalcWaybill c1 = listCal.get(i);
CalcWaybill c2 = listCal.get(l);
listCal.remove(l);
} else {
break;
}
}
return listCal;
}
//list_ 全部班次 lists_执行了的班次(实到实发不为空)
private List<CalcWaybill> cul(List<ScheduleRealInfo> list_,List<ScheduleRealInfo> list_s, List<Map<String, Object>> xlList, List<Interval> djgList){
List<CalcWaybill> list=new ArrayList<CalcWaybill>();
List<CalcWaybill> list2=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(list_s, "");
int sjyybcZgf=culateMileageService.culateSjyybc(list_s, "zgf");
int sjyybcWgf=culateMileageService.culateSjyybc(list_s, "wgf");
double sjyylc=culateMileageService.culateSjyylc(list_s);//驾售共有
double sjyylc_j=culateMileageService.culateSjyylc_j(list_s);//无售
double sjfyylc=culateMileageService.culateSjfyylc(list_s);//驾售
double sjfyylc_j=culateMileageService.culateSjfyylc_j(list_s);//无售
int ljbc=culateMileageService.culateLjbc(list_s, "");
int ljbcZgf=culateMileageService.culateLjbc(list_s, "zgf");
int ljbcWgf=culateMileageService.culateLjbc(list_s, "wgf");
double ljyylc=culateMileageService.culateLjyylc(list_s);//驾售
double ljyylc_j=culateMileageService.culateLjyylc_j(list_s);//无售
double ljfyylc=culateMileageService.culateLjfyylc(list_s);//驾售
double ljfyylc_j=culateMileageService.culateLjfyylc_j(list_s);//无售
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_ljpm= 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(list_s, "major", "");//放站
int fzbcZgf=culateMileageService.culateDtfzbc(list_s, "major", "zgf");
int fzbcWgf=culateMileageService.culateDtfzbc(list_s, "major", "wgf");
int zfbc=culateMileageService.culateDtfzbc(list_s, "venting", "");//直放
int zfbcZgf=culateMileageService.culateDtfzbc(list_s, "venting", "zgf");
int zfbcWgf=culateMileageService.culateDtfzbc(list_s, "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.setLblcLjpm(ssgl_ljpm);
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);
list2.add(t_);
}
}
for(CalcWaybill c2 : list2){
boolean flag = true;
String key2 = c2.getjGh() + c2.getsGh()==null?"":c2.getsGh().trim()
+ c2.getCl() + c2.getXl() + c2.getLp();
for(CalcWaybill c : list){
String key = c.getjGh() + c.getsGh()==null?"":c.getsGh().trim()
+ c.getCl() + c.getXl() + c.getLp();
if(key2.equals(key)){
c.setSjyylc(Arith.add(c.getSjyylc(), c2.getSjyylc()));
c.setSjfyylc(Arith.add(c.getSjfyylc(), c2.getSjfyylc()));
c.setLjyylc(Arith.add(c.getLjyylc(), c2.getLjyylc()));
c.setLjfyylc(Arith.add(c.getLjfyylc(), c2.getLjfyylc()));
flag = false;
break;
}
}
if(flag)
list.add(c2);
}
return list;
}
}