LoggerZnddServiceImpl.java
7.78 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
package com.bsth.service.zndd.impl;
import com.bsth.controller.realcontrol.dto.DfsjChange;
import com.bsth.data.schedule.DayOfSchedule;
import com.bsth.data.schedule.ScheduleComparator;
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.impl.BaseServiceImpl;
import com.bsth.service.realcontrol.ScheduleRealInfoService;
import com.bsth.service.sys.RealControAuthorityService;
import com.bsth.service.zndd.LoggerZnddService;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.data.domain.Sort;
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
RealControAuthorityService realControAuthorityService;
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 sch=dayOfSchedule.get(ids);
Set<String> set = dayOfSchedule.findCarByLineCode(sch.getXlBm());
List<String> nbbms=new ArrayList<>();
List<String> jghs=new ArrayList<>();
List<String> jNames=new ArrayList<>();
LocalTime localTime=LocalTime.now().plusHours(1);
DateTimeFormatter dtf=DateTimeFormatter.ofPattern("HH:mm");
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);//最后一个班次
nbbms.add(s2.getClZbh());
jghs.add(s2.getjGh());
jNames.add(s2.getjName());
}
}else {//1小时内是否有待执行班次
LocalTime fcsj=LocalTime.parse(s.getFcsj(),dtf);
if(fcsj.isAfter(localTime)){
nbbms.add(s.getClZbh());
jghs.add(s.getjGh());
jNames.add(s.getjName());
}
}
}
StringBuffer sb=new StringBuffer();
String kscl="";
if(nbbms.size()>0){
sch.setClZbh(nbbms.get(0));
sch.setjGh(jghs.get(0));
sch.setjName(jNames.get(0));
for (int i = 0; i < nbbms.size(); i++) {
sb.append(nbbms.get(i)+"/");
sb.append(jNames.get(i)+",");
}
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){
xlNames += sc.getXlName()+",";
break;
}
}
}
return xlNames;
}
}