EmployeeConfigInfoServiceImpl.java
4.33 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
package com.bsth.service.schedule.impl;
import com.bsth.entity.schedule.EmployeeConfigInfo;
import com.bsth.entity.schedule.rule.ScheduleRule1Flat;
import com.bsth.service.schedule.EmployeeConfigInfoService;
import com.bsth.service.schedule.ScheduleException;
import com.bsth.service.schedule.ScheduleRule1FlatService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
import org.springframework.transaction.annotation.Transactional;
import org.springframework.util.CollectionUtils;
import java.util.*;
/**
* Created by xu on 16/5/10.
*/
@Service
public class EmployeeConfigInfoServiceImpl extends BServiceImpl<EmployeeConfigInfo, Long> implements EmployeeConfigInfoService {
@Autowired
private ScheduleRule1FlatService scheduleRule1FlatService;
@Transactional
@Override
public void validate_jsy(EmployeeConfigInfo employeeConfigInfo) throws ScheduleException {
// 驾驶员不能重复配置
Map<String, Object> param = new HashMap<>();
if (employeeConfigInfo.getId() != null) {
param.put("id_ne", employeeConfigInfo.getId());
}
if (employeeConfigInfo.getXl() == null ||
employeeConfigInfo.getXl().getId() == null ||
employeeConfigInfo.getXl().getName() == null) {
throw new ScheduleException("线路未选择");
} else {
if (employeeConfigInfo.getJsy() == null || employeeConfigInfo.getJsy().getId() == null) {
throw new ScheduleException("驾驶员未选择");
} else {
param.put("jsy.id_eq", employeeConfigInfo.getJsy().getId());
if (!CollectionUtils.isEmpty(list(param))) {
throw new ScheduleException("驾驶员已经配置在" + employeeConfigInfo.getXl().getName() + "线路中!");
}
}
}
}
@Transactional
@Override
public void validate_spy(EmployeeConfigInfo employeeConfigInfo) throws ScheduleException {
// 售票员不能重复配置
Map<String, Object> param = new HashMap<>();
if (employeeConfigInfo.getId() != null) {
param.put("id_ne", employeeConfigInfo.getId());
}
if (employeeConfigInfo.getXl() == null ||
employeeConfigInfo.getXl().getId() == null ||
employeeConfigInfo.getXl().getName() == null) {
throw new ScheduleException("线路未选择");
} else {
if (employeeConfigInfo.getSpy() == null || employeeConfigInfo.getSpy().getId() == null) {
throw new ScheduleException("售票员未选择");
} else {
param.put("spy.id_eq", employeeConfigInfo.getSpy().getId());
if (!CollectionUtils.isEmpty(list(param))) {
throw new ScheduleException("售票员已经配置在" + employeeConfigInfo.getXl().getName() + "线路中!");
}
}
}
}
@Transactional
@Override
public void delete(Long aLong) throws ScheduleException {
toggleCancel(aLong);
}
@Transactional
@Override
public void toggleCancel(Long id) throws ScheduleException {
EmployeeConfigInfo employeeConfigInfo = findById(id);
Map<String, Object> param = new HashMap<>();
if (employeeConfigInfo.getIsCancel()) {
validate_jsy(employeeConfigInfo);
validate_spy(employeeConfigInfo);
employeeConfigInfo.setIsCancel(false);
} else {
param.clear();
param.put("xl.id_eq", employeeConfigInfo.getXl().getId());
List<ScheduleRule1Flat> scheduleRule1Flats = (List<ScheduleRule1Flat>) scheduleRule1FlatService.list(param);
List<String> ryConfigIds = new ArrayList<>();
for (ScheduleRule1Flat scheduleRule1Flat : scheduleRule1Flats) {
ryConfigIds.addAll(Arrays.asList(scheduleRule1Flat.getRyConfigIds().split(",")));
}
if (ryConfigIds.contains(String.valueOf(id))) {
throw new ScheduleException("人员配置已被规则使用,不能作废,请先修改规则!");
} else {
employeeConfigInfo.setIsCancel(true);
}
}
}
}