CarDeviceServiceImpl.java
2.18 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
package com.bsth.service.impl;
import com.bsth.common.ResponseCode;
import com.bsth.entity.CarDevice;
import com.bsth.entity.Cars;
import com.bsth.entity.schedule.rule.RerunRule;
import com.bsth.repository.CarDeviceRepository;
import com.bsth.repository.CarsRepository;
import com.bsth.service.CarDeviceService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
import javax.transaction.Transactional;
import java.util.HashMap;
import java.util.Map;
/**
* Created by xu on 16/6/15.
*/
@Service
public class CarDeviceServiceImpl extends BaseServiceImpl<CarDevice, Long> implements CarDeviceService {
@Autowired
private CarDeviceRepository carDeviceRepository;
@Autowired
private CarsRepository carsRepository;
@Transactional
@Override
public Map<String, Object> save(CarDevice carDevice) {
Map<String, Object> map = new HashMap<>();
try {
// 查找对应的车辆基础信息,更新设备编号数据
Cars cars = carsRepository.findOne(carDevice.getCl());
cars.setEquipmentCode(carDevice.getNewDeviceNo());
// 保存车辆设备信息
carDeviceRepository.save(carDevice);
map.put("status", ResponseCode.SUCCESS);
map.put("t", carDevice);
} catch(Exception e) {
map.put("status", ResponseCode.ERROR);
logger.error("save erro.", e);
}
return map;
}
@Transactional
@Override
public Map<String, Object> delete(Long aLong) {
// 获取作废数据
CarDevice carDevice = carDeviceRepository.findOne(aLong);
toogleIsCancel(carDevice);
Map<String, Object> map = new HashMap<>();
map.put("status", ResponseCode.SUCCESS);
return map;
}
/**
* 撤销/作废切换。
* @param rerunRule
*/
private void toogleIsCancel(CarDevice carDevice) {
boolean isCancel = carDevice.getIsCancel();
if (isCancel) {
carDevice.setIsCancel(false);
} else {
carDevice.setIsCancel(true);
}
}
}