SchedulePlanInfoServiceImpl.java
12.1 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
package com.bsth.service.schedule.impl;
import com.bsth.common.ResponseCode;
import com.bsth.entity.schedule.SchedulePlanInfo;
import com.bsth.repository.schedule.SchedulePlanInfoRepository;
import com.bsth.service.schedule.SchedulePlanInfoService;
import com.bsth.util.ReportUtils;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.jdbc.core.JdbcTemplate;
import org.springframework.jdbc.core.RowCallbackHandler;
import org.springframework.jdbc.core.RowMapper;
import org.springframework.stereotype.Service;
import org.springframework.transaction.annotation.Transactional;
import java.sql.ResultSet;
import java.sql.SQLException;
import java.text.SimpleDateFormat;
import java.util.*;
/**
* Created by xu on 16/6/16.
*/
@Service
public class SchedulePlanInfoServiceImpl extends BServiceImpl<SchedulePlanInfo, Long> implements SchedulePlanInfoService {
@Autowired
private JdbcTemplate jdbcTemplate;
@Override
public SchedulePlanInfo save(SchedulePlanInfo schedulePlanInfo) {
// 生成计划不是save,使用的是spring batch插入的
// 这里是单独修改的时候,需要记录修改次数,用于标识被修改过
Integer currentModifyCount = schedulePlanInfo.getModifyCount();
schedulePlanInfo.setModifyCount(currentModifyCount == null ? 1 : ++ currentModifyCount);
return super.save(schedulePlanInfo);
}
@Override
public List<Date> findLastestPlanDate(Integer xlId) {
String sql = "select max(schedule_date) as sd from bsth_c_s_sp_info " +
"where xl = ?";
final List<Date> ld = new ArrayList<>();
jdbcTemplate.query(sql, new Object[]{xlId}, new RowCallbackHandler() {
@Override
public void processRow(ResultSet rs) throws SQLException {
if (rs != null && rs.getDate("sd") != null) {
ld.add(new Date(rs.getDate("sd").getTime()));
}
}
});
return ld;
}
@Override
public List<SchedulePlanGroupInfo> findSchedulePlanGroupInfo(Integer xlId, Date scheduleDate) {
String sql = SchedulePlanGroupInfo.generateSelectSql();
List<SchedulePlanGroupInfo> schedulePlanGroupInfos = jdbcTemplate.query(sql, new Object[]{xlId, scheduleDate}, new RowMapper<SchedulePlanGroupInfo>() {
@Override
public SchedulePlanGroupInfo mapRow(ResultSet resultSet, int i) throws SQLException {
SchedulePlanGroupInfo schedulePlanGroupInfo = new SchedulePlanGroupInfo();
schedulePlanGroupInfo.setFromResult(resultSet);
return schedulePlanGroupInfo;
}
});
// 排序
Collections.sort(schedulePlanGroupInfos);
return schedulePlanGroupInfos;
}
@Autowired
private SchedulePlanInfoRepository schedulePlanInfoRepository;
@Override
public List<GroupInfo> findGroupInfo(Integer xlid, Date scheduleDate) {
List<Object[]> groupInfos = schedulePlanInfoRepository.findGroupInfo(xlid, scheduleDate);
List<GroupInfo> groupInfoList = new ArrayList<>();
for (Object[] groupInfo : groupInfos) {
groupInfoList.add(new GroupInfo(groupInfo));
}
return groupInfoList;
}
@Override
@Transactional
public int updateGroupInfo(GroupInfoUpdate groupInfoUpdate) {
int type = groupInfoUpdate.getType();
int result = 0;
if (type == 1) {
// 换车
if (groupInfoUpdate.getUpdate().getClId() != groupInfoUpdate.getSrc().getClId()) {
result = this.schedulePlanInfoRepository.updateGroupInfo_type_1(
groupInfoUpdate.getUpdate().getClId(),
groupInfoUpdate.getUpdate().getClZbh(),
groupInfoUpdate.getSrc().getXlId(),
groupInfoUpdate.getSrc().getScheduleDate(),
groupInfoUpdate.getSrc().getLpName()
);
}
} else if (type == 2) {
// 更改出场班次1的时间
if (!groupInfoUpdate.getUpdate().getCcsj1().equals(groupInfoUpdate.getSrc().getCcsj1())) {
result = this.schedulePlanInfoRepository.updateGroupInfo_type_2_4(
groupInfoUpdate.getUpdate().getCcsj1(),
groupInfoUpdate.getSrc().getXlId(),
groupInfoUpdate.getUpdate().getScheduleDate(),
groupInfoUpdate.getSrc().getLpName(),
groupInfoUpdate.getSrc().getCcsj1(),
"out",
groupInfoUpdate.getSrc().getFcno1()
);
}
} else if (type == 3) {
// 更改驾驶员1
if (groupInfoUpdate.getUpdate().getJsy1Id() != groupInfoUpdate.getSrc().getJsy1Id()) {
result = this.schedulePlanInfoRepository.updateGroupInfo_type_3_5_jsy(
groupInfoUpdate.getUpdate().getJsy1Id(),
groupInfoUpdate.getUpdate().getJsy1Gh(),
groupInfoUpdate.getUpdate().getJsy1Name(),
groupInfoUpdate.getSrc().getXlId(),
groupInfoUpdate.getSrc().getScheduleDate(),
groupInfoUpdate.getSrc().getLpName(),
groupInfoUpdate.getSrc().getJsy1Id()
);
}
// 更改售票员1
if (groupInfoUpdate.getUpdate().getSpy1Id() != groupInfoUpdate.getSrc().getSpy1Id()) {
result = this.schedulePlanInfoRepository.updateGroupInfo_type_3_5_spy(
groupInfoUpdate.getUpdate().getSpy1Id(),
groupInfoUpdate.getUpdate().getSpy1Gh(),
groupInfoUpdate.getUpdate().getSpy1Name(),
groupInfoUpdate.getSrc().getXlId(),
groupInfoUpdate.getSrc().getScheduleDate(),
groupInfoUpdate.getSrc().getLpName(),
groupInfoUpdate.getSrc().getSpy1Id()
);
}
} else if (type == 4) {
// 更改出场班次2的时间
if (!groupInfoUpdate.getUpdate().getCcsj2().equals(groupInfoUpdate.getSrc().getCcsj2())) {
result = this.schedulePlanInfoRepository.updateGroupInfo_type_2_4(
groupInfoUpdate.getUpdate().getCcsj2(),
groupInfoUpdate.getSrc().getXlId(),
groupInfoUpdate.getUpdate().getScheduleDate(),
groupInfoUpdate.getSrc().getLpName(),
groupInfoUpdate.getSrc().getCcsj2(),
"out",
groupInfoUpdate.getSrc().getFcno2()
);
}
} else if (type == 5) {
// 更改驾驶员2
if (groupInfoUpdate.getUpdate().getJsy2Id() != groupInfoUpdate.getSrc().getJsy2Id()) {
result = this.schedulePlanInfoRepository.updateGroupInfo_type_3_5_jsy(
groupInfoUpdate.getUpdate().getJsy2Id(),
groupInfoUpdate.getUpdate().getJsy2Gh(),
groupInfoUpdate.getUpdate().getJsy2Name(),
groupInfoUpdate.getSrc().getXlId(),
groupInfoUpdate.getSrc().getScheduleDate(),
groupInfoUpdate.getSrc().getLpName(),
groupInfoUpdate.getSrc().getJsy2Id()
);
}
// 更改售票员2
if (groupInfoUpdate.getUpdate().getSpy2Id() != groupInfoUpdate.getSrc().getSpy2Id()) {
result = this.schedulePlanInfoRepository.updateGroupInfo_type_3_5_spy(
groupInfoUpdate.getUpdate().getSpy2Id(),
groupInfoUpdate.getUpdate().getSpy2Gh(),
groupInfoUpdate.getUpdate().getSpy2Name(),
groupInfoUpdate.getSrc().getXlId(),
groupInfoUpdate.getSrc().getScheduleDate(),
groupInfoUpdate.getSrc().getLpName(),
groupInfoUpdate.getSrc().getSpy2Id()
);
}
} else {
throw new RuntimeException("未知的更新类型,type=" + type);
}
return result;
}
public List<Map<String, Object>> infoexport(List<SchedulePlanInfoService.SchedulePlanGroupInfo> list){
List<Map<String, Object>> lMap = new ArrayList<Map<String, Object>>();
SimpleDateFormat sd = new SimpleDateFormat("yyyy-MM-dd");
try {
for (SchedulePlanInfoService.SchedulePlanGroupInfo t: list) {
Map<String, Object> m = new HashMap<String, Object>();
m.put("czr",t.getUpdateByName()+" \n"+"创建日期:"+sd.format(t.getCreateDate())+" \n"+"修改日期:"+sd.format(t.getUpdateDate()));
m.put("xl",t.getXlName());
m.put("rq",sd.format(t.getScheduleDate()));
m.put("lp",t.getLpName());
m.put("cl",exporttype(t.getClZbhs()));
m.put("jcsj",exporttype(t.getJcsjs()));
m.put("ccsj",exporttype(t.getCcsjs()));
m.put("jsy",exporttypety(t.getJsyNames(),t.getJsyGhs()));
m.put("spy",exporttypety(t.getSpyNames(),t.getSpyGhs()));
m.put("ttInfoName",t.getTtInfoName());
lMap.add(m);
}
SimpleDateFormat sdfMonth = new SimpleDateFormat("yyyy-MM-dd"),
sdfSimple = new SimpleDateFormat("yyyyMMdd");
List<Iterator<?>> listI = new ArrayList<Iterator<?>>();
Map<String, Object> m = new HashMap<String, Object>();
// String by=map.get("by").toString();
String xls="dailyreport.xls";
String xlName = null;
String dateTime = null;
if(list != null){
xlName = list.get(0).getXlName();
dateTime =sd.format(list.get(0).getScheduleDate());
}
ReportUtils ee = new ReportUtils();
try {
listI.add(lMap.iterator());
String path = this.getClass().getResource("/").getPath() + "static/pages/forms/";
ee.excelReplace(listI, new Object[]{m}, path + "mould/"+xls,
path + "export/"+dateTime+"-"+xlName+"-调度值勤日报.xls");
} catch (Exception e) {
// TODO: handle exception
e.printStackTrace();
}
}catch (Exception exp) {
exp.printStackTrace();
}
return lMap;
}
public String exporttype(List<String> t){
if(t.size() == 0) {
return "";
}else {
if (t.size() > 1) {
String y = "";
for(int i = 0 ; i< t.size();i++) {
if(i == 0) {
y = y + t.get(i);
}else {
y = y + " \n" + t.get(i);
}
}
return y;
} else {
return t.get(0);
}
}
}
public String exporttypety(List<String> x,List<String> y){
if(x.size() == 0 || y.size() == 0){
return "";
}else {
if(x.size() > 1 && y.size() >1){
String k ="";
for(int i = 0 ; i< x.size();i++) {
if(x.size() == y.size()){
if(x.size() -1 == i){
k = k + x.get(i) +" "+y.get(i);
}else {
k = k + x.get(i) +" "+y.get(i) + " \n";
}
}
}
return k;
}else {
return x.get(0) +" "+y.get(0);
}
}
}
}