CarConfigInfoServiceImpl.java
3.87 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
package com.bsth.service.schedule.impl;
import com.bsth.entity.schedule.CarConfigInfo;
import com.bsth.entity.schedule.rule.ScheduleRule1Flat;
import com.bsth.service.schedule.CarConfigInfoService;
import com.bsth.service.schedule.ScheduleRule1FlatService;
import com.bsth.service.schedule.exception.ScheduleException;
import com.bsth.service.schedule.utils.DataToolsFile;
import com.bsth.service.schedule.utils.DataToolsService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.beans.factory.annotation.Qualifier;
import org.springframework.stereotype.Service;
import org.springframework.transaction.annotation.Transactional;
import org.springframework.util.CollectionUtils;
import java.io.File;
import java.util.HashMap;
import java.util.List;
import java.util.Map;
/**
* Created by xu on 16/5/9.
*/
@Service
public class CarConfigInfoServiceImpl extends BServiceImpl<CarConfigInfo, Long> implements CarConfigInfoService {
@Autowired
private ScheduleRule1FlatService scheduleRule1FlatService;
@Autowired
@Qualifier(value = "carConfig_dataTool")
private DataToolsService dataToolsService;
@Override
public DataToolsFile uploadFile(String filename, byte[] filedata) throws ScheduleException {
return dataToolsService.uploadFile(filename, filedata);
}
@Override
public void importData(File file, Map<String, Object> params) throws ScheduleException {
dataToolsService.importData(file, params);
}
@Override
public DataToolsFile exportData(Map<String, Object> params) throws ScheduleException {
return dataToolsService.exportData(params);
}
@Transactional
public void validate_cars(CarConfigInfo carConfigInfo) throws ScheduleException {
// 相同车辆不能同时配置
Map<String, Object> param = new HashMap<>();
if (carConfigInfo.getId() != null) {
param.put("id_ne", carConfigInfo.getId());
}
if (carConfigInfo.getXl() == null ||
carConfigInfo.getXl().getId() == null ||
carConfigInfo.getXl().getName() == null) {
throw new ScheduleException("线路未选择");
} else {
// param.put("xl.id_eq", carConfigInfo.getXl().getId());
param.put("isCancel_eq", false);
if (carConfigInfo.getCl() == null || carConfigInfo.getCl().getId() == null) {
throw new ScheduleException("车辆未选择");
} else {
param.put("cl.id_eq", carConfigInfo.getCl().getId());
List<CarConfigInfo> carConfigInfos = list(param);
if (!CollectionUtils.isEmpty(carConfigInfos)) {
throw new ScheduleException("车辆已经配置在" + carConfigInfos.get(0).getXl().getName() + "线路中!");
}
}
}
}
@Transactional
@Override
public void delete(Long aLong) throws ScheduleException {
toggleCancel(aLong);
}
@Transactional
public void toggleCancel(Long id) throws ScheduleException {
CarConfigInfo carConfigInfo = findById(id);
Map<String, Object> param = new HashMap<>();
if (carConfigInfo.getIsCancel()) {
validate_cars(carConfigInfo);
carConfigInfo.setIsCancel(false);
} else {
param.clear();
param.put("carConfigInfo.id_eq", carConfigInfo.getId());
List<ScheduleRule1Flat> scheduleRule1Flats = (List<ScheduleRule1Flat>) scheduleRule1FlatService.list(param);
if (CollectionUtils.isEmpty(scheduleRule1Flats)) {
carConfigInfo.setIsCancel(true);
} else {
throw new ScheduleException("车辆配置已被规则使用,不能作废,请先修改规则!");
}
}
}
}