LoggerZnddServiceImpl.java
16.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
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
package com.bsth.service.zndd.impl;
import com.alibaba.fastjson.JSON;
import com.bsth.common.ResponseCode;
import com.bsth.controller.realcontrol.dto.DfsjChange;
import com.bsth.data.BasicData;
import com.bsth.data.schedule.DayOfSchedule;
import com.bsth.data.schedule.ScheduleComparator;
import com.bsth.data.schedule.edit_logs.service.dto.SchEditInfoDto;
import com.bsth.entity.Line;
import com.bsth.entity.realcontrol.ScheduleRealInfo;
import com.bsth.entity.sys.RealControAuthority;
import com.bsth.entity.zndd.LoggerZndd;
import com.bsth.repository.realcontrol.ScheduleRealInfoRepository;
import com.bsth.repository.zndd.LoggerZnddRepository;
import com.bsth.service.LineService;
import com.bsth.service.impl.BaseServiceImpl;
import com.bsth.service.realcontrol.ScheduleRealInfoService;
import com.bsth.service.report.ReportService;
import com.bsth.service.sys.RealControAuthorityService;
import com.bsth.service.zndd.LoggerZnddService;
import com.bsth.util.DateUtils;
import com.bsth.util.ReportUtils;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.data.domain.Sort;
import org.springframework.jdbc.core.BeanPropertyRowMapper;
import org.springframework.jdbc.core.JdbcTemplate;
import org.springframework.stereotype.Service;
import org.springframework.transaction.annotation.Transactional;
import org.springframework.web.bind.annotation.RequestParam;
import java.text.SimpleDateFormat;
import java.time.LocalTime;
import java.time.format.DateTimeFormatter;
import java.util.*;
@Service
public class LoggerZnddServiceImpl extends BaseServiceImpl<LoggerZndd, Integer> implements LoggerZnddService {
@Autowired
LoggerZnddRepository loggerZnddRepository;
@Autowired
DayOfSchedule dayOfSchedule;
@Autowired
ScheduleRealInfoService scheduleRealInfoService;
@Autowired
ScheduleRealInfoRepository scheduleRealInfoRepository;
@Autowired
LineService lineService;
@Autowired
ReportService reportService;
@Autowired
RealControAuthorityService realControAuthorityService;
@Autowired
JdbcTemplate jdbcTemplate;
Logger logger = LoggerFactory.getLogger(this.getClass());
private static SimpleDateFormat sdfMonth = new SimpleDateFormat("HH:mm");
private static SimpleDateFormat sdf = new SimpleDateFormat("yyyy-MM-dd HH:mm");
public List<Map<String, Object>> listAll(Map<String, Object> map){
loggerZnddRepository.findAll((Sort) map);
return null;
}
@Override
public ScheduleRealInfo schlist(String lineCode,Integer dir){
List<ScheduleRealInfo> list = dayOfSchedule.findByLineAndUpDown(lineCode,dir);
if (!list.isEmpty() ){
for (ScheduleRealInfo sr : list){
if(sr.getBcType().equals("normal")){
return sr;
}
}
}
return null;
};
@Override
@Transactional //发车间隔 误点
public Map<String, Object> znddConfig(Map<String, Object> map){
//查出离触发时间最近的一次路单 修改部分值
//包装好路单添加如临加班次
List<DfsjChange> dfsjcs = new ArrayList<>();//返回的数据
try {
String lineCode = map.get("lineCode") != null ? map.get("lineCode").toString() : null;
String xlDir = map.get("xlDir") != null ? map.get("xlDir").toString() : null;
String rq = map.get("rq") != null ? map.get("rq").toString() : null;
List<ScheduleRealInfo> upoldSchDateList = new ArrayList<>(), //上行
dnoldSchDateList = new ArrayList<>(); //下行
List<ScheduleRealInfo> listReal = new ArrayList<>();
Boolean typeReal = false;
//排班依次往后
List<ScheduleRealInfo> list = dayOfSchedule.findByLineCode(lineCode);
//区分上下行
for (ScheduleRealInfo t : list){
if (t.getXlDir().equals("0")){
upoldSchDateList.add(t);
}else {
dnoldSchDateList.add(t);
}
}
if (xlDir.equals("0")){
Collections.sort(upoldSchDateList, new ScheduleComparator.FCSJ());//排序
list = upoldSchDateList;
}else {
Collections.sort(upoldSchDateList, new ScheduleComparator.FCSJ());//排序
list = upoldSchDateList;
}
for (ScheduleRealInfo info : list) {
//从相等开始
if (info.getFcsjActual() != null && !info.getFcsjActual().equals("")) {
if (info.getFcsjActual().equals(rq))
typeReal = true;
continue;
}
if (typeReal && (info.getBcType().equals("normal")|| info.getBcType().equals("region")))
listReal.add(info);
if (listReal.size() >= 5) //或者不满5条结束 listReal.size()从1开始
break;
}
//处理listReal 5条数据或5条一下
for (int i = 0; i < listReal.size() ;i++){
DfsjChange cl = new DfsjChange();
Integer[] mis = {3,2,2,1,1}; //往后5个班次分别延后3 2 2 1 1
ScheduleRealInfo info = listReal.get(i);
int ms = mis[i];
//未发车时 才可改变
if (info.getFcsjActual() == null || info.getFcsjActual().equals("")){
String dfsj = sdfMonth.format(sdf.parse(info.getScheduleDateStr()+ " " + info.getDfsj()).getTime() - (ms * 60 * 1000)); //延后几分钟
cl.setSchId(info.getId());
cl.setOld_dfsj(info.getDfsj());
cl.setNew_dfsj(dfsj);
dfsjcs.add(cl);
}
}
return scheduleRealInfoService.multi_dftz(dfsjcs);
}catch (Exception e){
logger.info("--",e);
}
return null;
}
public ScheduleRealInfo thissch(Integer ids){
ScheduleRealInfo sch2=dayOfSchedule.get(ids);
ScheduleRealInfo sch= null;
try {
sch = sch2.clone();
} catch (CloneNotSupportedException e) {
e.printStackTrace();
}
Line line = lineService.findByLineCode(sch.getXlBm());
List<Map<String, Object>> lineList=reportService.lineList();
Set<String> lines = new HashSet<>();
for (Map<String, Object> map : lineList) {
if(line.getBrancheCompany().equals(map.get("fgsbm").toString())){
lines.add(map.get("xlbm").toString());
}
}
List<Map<String,String>> schs=new ArrayList<>();
LocalTime localTime=LocalTime.now().plusHours(1);
LocalTime now=LocalTime.now();
DateTimeFormatter dtf=DateTimeFormatter.ofPattern("HH:mm");
for (String lineCode : lines) {
Set<String> set = dayOfSchedule.findCarByLineCode(lineCode);
for (String nbbm : set) {
ScheduleRealInfo s=dayOfSchedule.executeCurr(nbbm);//当前执行班次
if(s==null){//当日班次执行完毕
List<ScheduleRealInfo> list=dayOfSchedule.findByNbbm(nbbm);
if(list.size()>0){
ScheduleRealInfo s2=list.get(list.size()-1);//最后一个班次\
if(s2.getZdsjActual()!=null && LocalTime.parse(s2.getZdsjActual(),dtf).isBefore(now)){
Map<String,String> schMap = new HashMap<>();
schMap.put("nbbm",s2.getClZbh());
schMap.put("jgh",s2.getjGh());
schMap.put("jName",s2.getjName());
schMap.put("zdsjActual",s2.getZdsjActual());
System.out.println(s2.getClZbh()+s2.getZdsjActual()+lineCode);
schs.add(schMap);
}
}
}else {//1小时内是否有待执行班次
LocalTime fcsj=LocalTime.parse(s.getFcsj(),dtf);
if(fcsj.isAfter(localTime)){
//查询上一个班次
ScheduleRealInfo s2=dayOfSchedule.prev(s);
if(s.getZdsjActual()!=null && LocalTime.parse(s2.getZdsjActual(),dtf).isBefore(now)){
Map<String,String> schMap = new HashMap<>();
schMap.put("nbbm",s2.getClZbh());
schMap.put("jgh",s2.getjGh());
schMap.put("jName",s2.getjName());
schMap.put("zdsjActual",s2.getZdsjActual());
System.out.println(s2.getClZbh()+s2.getZdsjActual()+lineCode);
schs.add(schMap);
}
}
}
}
}
Collections.sort(schs, new Comparator<Map<String, String>>(){
public int compare(Map<String, String> o1, Map<String, String> o2) {
String zdsjActual1 = o1.get("zdsjActual");
String zdsjActual2 = o2.get("zdsjActual");
return zdsjActual2.compareTo(zdsjActual1);
}
});
StringBuffer sb=new StringBuffer();
String kscl="";
List<Map<String, String>> schs2 = new ArrayList<>();
// 创建用于去重的 Set<Map>
Set<Map<String, String>> set = new HashSet<>();
// 遍历原始的 List<Map>
for (Map<String, String> map : schs) {
// 创建一个新的 Map 用于存储合并去重后的结果
Map<String, String> newMap = new HashMap<>(map);
// 如果新的 Map 成功添加到 Set 中,说明是一个新的 Map,将其添加到结果 List<Map> 中
if (set.add(newMap)) {
schs2.add(newMap);
}
}
if(schs2.size()>0){
sch.setClZbh(schs2.get(0).get("nbbm"));
sch.setjGh(schs2.get(0).get("jgh"));
sch.setjName(schs2.get(0).get("jName"));
int size =schs2.size()>8?8:schs2.size();
for (int i = 0; i < size; i++) {
sb.append(schs2.get(i).get("nbbm")+"/");
sb.append(schs2.get(i).get("jName")+"/");
sb.append(schs2.get(i).get("zdsjActual")+",");
}
kscl=sb.toString().substring(0,sb.length()-1);
}
sch.setKxcl(kscl);
return sch;
}
public String LineUserAll(@RequestParam Integer userId){
String xlNames ="";
RealControAuthority rcay = realControAuthorityService.findByUserId(userId);
String lineCodeStr = rcay.getLineCodeStr();
String[] lineArray = lineCodeStr.split(",");
for(String line : lineArray){
List<ScheduleRealInfo> schList = dayOfSchedule.findByLineCode(line);
for(ScheduleRealInfo sc : schList){
if (sc.getStatus() == 0 || sc.getStatus() == 1){
xlNames += sc.getXlName()+",";
break;
}
}
}
return xlNames;
}
public Map<String, Object> schTZSF(String line,String date,String endDate,String changType,String type){
Map<String, Object> rs = new HashMap();
try {
String cont = "";
if (line != null && !line.equals("")){
cont = " and line_code ="+line;
}
String bcType ="";
if (changType.equals("0")){
bcType = " and bc_type not in ('in','out','venting')";
}else {
bcType =" and bc_type in ('out')";
}
//拼接除rq、lineCode 外的其他where 条件
String sql = "select t1.*, t2.fcsj,t2.lp_name,t2.cl_zbh,t2.j_gh,t2.j_name,t2.xl_dir,t2.real_exec_date,t2.xl_name from (select * from logger_sch_modify where rq >=? and rq <=? and type in('SFTZ','FCXXWT') and remarks !='自动调度实发未发-车辆掉线'"+cont+" ) t1 INNER JOIN bsth_c_s_sp_info_real t2 on t1.sch_id=t2.id where 1=1 " +bcType;
List<SchEditInfoDto> list = jdbcTemplate.query(sql, new BeanPropertyRowMapper(SchEditInfoDto.class), date,endDate);
rs.put("status", ResponseCode.SUCCESS);
List<SchEditInfoDto> listnew = new ArrayList<>();
for(SchEditInfoDto item : list){
List<Map> lists = (List) JSON.parse(item.getJsonArray());
for(Map its : lists){
if (item.getType().equals("FCXXWT")) {
if (its.get("old") != null && its.get("title").equals("调整实发时间")) {
String text = "调整前:" + its.get("old") + ",调整后:" + its.get("now");
item.setText(text);
listnew.add(item);
break;
}
}else {
if(its.get("old") != null){
String text = "调整前:" + its.get("old") + ",调整后:" + its.get("now");
item.setText(text);
break;
}
}
};
};
rs.put("list", listnew);
if(type.equals("export")){
List<Iterator<?>> listI = new ArrayList<Iterator<?>>();
Map<String, Object> m = new HashMap<String, Object>();
ReportUtils ee = new ReportUtils();
List list1 = new ArrayList();
for(SchEditInfoDto sed : listnew){
Map map = JSON.parseObject(JSON.toJSONString(sed), Map.class);
list1.add(map);
}
try {
listI.add(list1.iterator());
String path = this.getClass().getResource("/").getPath() + "static/pages/forms/";
ee.excelReplace(listI, new Object[]{m}, path + "mould/" + "sch_tzsf.xls",
path + "export/"+date+"-"+endDate+"-异常调整实发.xls");
} catch (Exception e) {
// TODO: handle exception
e.printStackTrace();
}
}
}catch (Exception e){
logger.error("", e);
rs.put("status", ResponseCode.ERROR);
rs.put("msg", e.getMessage());
}
return rs;
}
public ScheduleRealInfo nextSch(Long id){
return dayOfSchedule.next(dayOfSchedule.get(id));
}
public Map schDeepSeep(String message){
Map m = new HashMap<>();
String xl = null; //线路编码
String xlName = null;
//获取所有线路
Map<String, String> lineMap = BasicData.lineCode2NameMap;
for (Map.Entry<String, String> t : lineMap.entrySet()){
if (message.contains(t.getValue())){
xl = t.getKey();
xlName = t.getValue();
}
}
if (xl != null){
//总班次、进场班次、出场班次、临加班次、正常班次、区间班次。0 未执行 1 正在执行 2 已执行 -1 已烂班
Integer inbcs = 0,outbcs = 0,ljbcs = 0,normalbcs = 0,regionbcs =0,wzxbcs = 0 ,zzxbcs = 0,yzxbcs = 0,lbbcs = 0;
List<ScheduleRealInfo> srList = dayOfSchedule.findByLineCode(xl);//当日所有班次
for(ScheduleRealInfo sc : srList) {
if (sc.getBcType().equals("in"))
inbcs = inbcs + 1;
if (sc.getBcType().equals("out"))
outbcs = outbcs + 1;
if (sc.isSflj())
ljbcs = ljbcs + 1;
if (sc.getBcType().equals("normal"))
normalbcs = normalbcs + 1;
if (sc.getBcType().equals("region"))
regionbcs = regionbcs + 1;
if (sc.getStatus() == 0)
wzxbcs = wzxbcs + 1;
if (sc.getStatus() == 1)
zzxbcs = zzxbcs + 1;
if (sc.getStatus() == 2)
yzxbcs = yzxbcs + 1;
if (sc.getStatus() == -1)
lbbcs = lbbcs + 1;
}
m.put("code","200");
m.put("inbcs",inbcs);
m.put("outbcs",outbcs);
m.put("ljbcs",ljbcs);
m.put("normalbcs",normalbcs);
m.put("regionbcs",regionbcs);
m.put("wzxbcs",wzxbcs);
m.put("zzxbcs",zzxbcs);
m.put("yzxbcs",yzxbcs);
m.put("lbbcs",lbbcs);
m.put("bcs",srList.size());
m.put("xlName",xlName);
}else {
m.put("code","100");
m.put("message","无法找到线路");
}
return m;
}
public List<ScheduleRealInfo> schQbc(String xl){
//获取前一天的班次
List<ScheduleRealInfo> list = scheduleRealInfoRepository.scheduleByDateAndLineTjrb(xl, DateUtils.qyt_date());
return list;
}
}