CarConfigInfoServiceImpl.java
1.97 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
package com.bsth.service.schedule;
import com.bsth.common.ResponseCode;
import com.bsth.entity.schedule.CarConfigInfo;
import com.bsth.entity.schedule.rule.ScheduleRule1Flat;
import com.bsth.repository.schedule.CarConfigInfoRepository;
import com.bsth.service.impl.BaseServiceImpl;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
import javax.transaction.Transactional;
import java.util.*;
/**
* Created by xu on 16/5/9.
*/
@Service
public class CarConfigInfoServiceImpl extends BaseServiceImpl<CarConfigInfo, Long> implements CarConfigInfoService {
@Autowired
private CarConfigInfoRepository carConfigInfoRepository;
@Autowired
private ScheduleRule1FlatService scheduleRule1FlatService;
@Override
@Transactional
public Map<String, Object> delete(Long aLong) {
// 获取待作废的车辆配置
CarConfigInfo carConfigInfo = carConfigInfoRepository.findOne(aLong);
// 查询有无规则使用过此车辆配置
Map<String, Object> param = new HashMap<>();
param.put("carConfigInfo.id_eq", carConfigInfo.getId());
Iterator<ScheduleRule1Flat> scheduleRule1FlatIterator =
scheduleRule1FlatService.list(param).iterator();
boolean isExist = false;
while (scheduleRule1FlatIterator.hasNext()) {
ScheduleRule1Flat scheduleRule1Flat = scheduleRule1FlatIterator.next();
if (scheduleRule1Flat.getCarConfigInfo().getId().equals(carConfigInfo.getId())) {
isExist = true;
break;
}
}
Map<String, Object> map = new HashMap<>();
if (isExist) {
throw new RuntimeException("车辆配置已被规则使用,不能删除,请先修改规则!");
} else {
carConfigInfo.setIsCancel(true);
map.put("status", ResponseCode.SUCCESS);
}
return map;
}
}