CarDeviceServiceImpl.java
2.57 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
package com.bsth.service.schedule.impl;
import com.bsth.entity.CarDevice;
import com.bsth.entity.Cars;
import com.bsth.service.CarsService;
import com.bsth.service.schedule.CarDeviceService;
import com.bsth.service.schedule.exception.ScheduleException;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
import org.springframework.transaction.annotation.Isolation;
import org.springframework.transaction.annotation.Propagation;
import org.springframework.transaction.annotation.Transactional;
import org.springframework.util.CollectionUtils;
import java.util.HashMap;
import java.util.Map;
/**
* Created by xu on 16/12/15.
*/
@Service(value = "carDeviceServiceImpl_sc")
public class CarDeviceServiceImpl extends BServiceImpl<CarDevice, Long> implements CarDeviceService {
@Autowired
private CarsService carsService;
@Transactional(propagation = Propagation.REQUIRED, isolation = Isolation.READ_COMMITTED)
@Override
public CarDevice save(CarDevice carDevice) {
// 查找对应的车辆基础信息,更新设备编号数据
Cars cars = carsService.findById(carDevice.getCl());
cars.setEquipmentCode(carDevice.getNewDeviceNo());
return super.save(carDevice);
}
@Transactional
@Override
public void validate_qyrq(CarDevice carDevice) throws ScheduleException {
if (carDevice.getXl() == null) {
throw new ScheduleException("线路未选择");
}
if (carDevice.getCl() == null) {
throw new ScheduleException("车辆未选择");
}
Map<String, Object> param = new HashMap<>();
if (carDevice.getId() != null) {
param.put("id_ne", carDevice.getId());
}
param.put("xl_eq", carDevice.getXl());
param.put("cl_eq", carDevice.getCl());
param.put("isCancel_eq", false); // 未标记作废删除的
param.put("qyrq_ge", carDevice.getQyrq());
if (!CollectionUtils.isEmpty(list(param))) {
throw new ScheduleException("启用日期必须比历史的启用日期大");
}
}
@Transactional
@Override
public void delete(Long aLong) throws ScheduleException {
toggleCancel(aLong);
}
@Transactional
public void toggleCancel(Long id) throws ScheduleException {
CarDevice carDevice = findById(id);
if (carDevice.getIsCancel()) {
carDevice.setIsCancel(false);
} else {
carDevice.setIsCancel(true);
}
}
}