LoggerZnddServiceImpl.java
12.4 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
package com.bsth.service.zndd.impl;
import com.alibaba.fastjson.JSON;
import com.alibaba.fastjson.JSONObject;
import com.bsth.common.ResponseCode;
import com.bsth.controller.realcontrol.dto.DfsjChange;
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.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<String> nbbms=new ArrayList<>();
List<String> jghs=new ArrayList<>();
List<String> jNames=new ArrayList<>();
for (String lineCode : lines) {
Set<String> set = dayOfSchedule.findCarByLineCode(lineCode);
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));
int size =nbbms.size()>10?9:nbbms.size();
for (int i = 0; i < 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 || 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;
}
}