|
|
|
@ -10,6 +10,7 @@ import com.xydl.cac.service.ZsbService;
|
|
|
|
|
import lombok.extern.slf4j.Slf4j;
|
|
|
|
|
import org.springframework.stereotype.Service;
|
|
|
|
|
import org.springframework.transaction.annotation.Transactional;
|
|
|
|
|
import org.springframework.util.CollectionUtils;
|
|
|
|
|
|
|
|
|
|
import javax.annotation.Resource;
|
|
|
|
|
import java.util.List;
|
|
|
|
@ -28,11 +29,36 @@ public class ZsbServiceImpl implements ZsbService {
|
|
|
|
|
LxRepository lxRepository;
|
|
|
|
|
|
|
|
|
|
@Override
|
|
|
|
|
public List<Zsb> listAll(Integer jgid) {
|
|
|
|
|
public List<Zsb> listAll(Integer jgid) throws Exception {
|
|
|
|
|
if (jgid == null) {
|
|
|
|
|
return repository.findAll();
|
|
|
|
|
List<Zsb> result = repository.findAll();
|
|
|
|
|
this.fillJgBdzName(result);
|
|
|
|
|
return result;
|
|
|
|
|
} else {
|
|
|
|
|
return repository.findByJgid(jgid);
|
|
|
|
|
List<Zsb> result = repository.findByJgid(jgid);
|
|
|
|
|
Jg jg = jgService.detail(jgid);
|
|
|
|
|
if (!CollectionUtils.isEmpty(result)) {
|
|
|
|
|
for (Zsb zsb : result) {
|
|
|
|
|
zsb.setJgName(jg.getMc());
|
|
|
|
|
zsb.setBdzName(jg.getBdzName());
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
return result;
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
private void fillJgBdzName(List<Zsb> list) {
|
|
|
|
|
List<Jg> jgList = jgService.listAll(null);
|
|
|
|
|
if (!CollectionUtils.isEmpty(list) && !CollectionUtils.isEmpty(jgList)) {
|
|
|
|
|
for (Zsb zsb : list) {
|
|
|
|
|
for (Jg jg : jgList) {
|
|
|
|
|
if (jg.getId().equals(zsb.getJgid())) {
|
|
|
|
|
zsb.setBdzName(jg.getBdzName());
|
|
|
|
|
zsb.setJgName(jg.getMc());
|
|
|
|
|
break;
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
@ -41,8 +67,8 @@ public class ZsbServiceImpl implements ZsbService {
|
|
|
|
|
item.setId(null);
|
|
|
|
|
Jg jg = jgService.detail(item.getJgid());
|
|
|
|
|
item.setBdzid(jg.getBdzid());
|
|
|
|
|
Optional<Lx> optional = lxRepository.findById(item.getLxid());
|
|
|
|
|
if (!optional.isPresent()) {
|
|
|
|
|
Optional<Lx> optionalLx = lxRepository.findById(item.getLxid());
|
|
|
|
|
if (!optionalLx.isPresent()) {
|
|
|
|
|
throw new Exception("未找到该设备类型");
|
|
|
|
|
}
|
|
|
|
|
return repository.save(item);
|
|
|
|
@ -52,15 +78,28 @@ public class ZsbServiceImpl implements ZsbService {
|
|
|
|
|
public void update(Zsb item) throws Exception {
|
|
|
|
|
Jg jg = jgService.detail(item.getJgid());
|
|
|
|
|
item.setBdzid(jg.getBdzid());
|
|
|
|
|
Optional<Lx> optional = lxRepository.findById(item.getLxid());
|
|
|
|
|
if (!optional.isPresent()) {
|
|
|
|
|
Optional<Lx> optionalLx = lxRepository.findById(item.getLxid());
|
|
|
|
|
if (!optionalLx.isPresent()) {
|
|
|
|
|
throw new Exception("未找到该设备类型");
|
|
|
|
|
}
|
|
|
|
|
repository.save(item);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
@Override
|
|
|
|
|
public void delete(Integer id) {
|
|
|
|
|
public void delete(Integer id) throws Exception {
|
|
|
|
|
repository.deleteById(id);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
@Override
|
|
|
|
|
public Zsb detail(Integer id) throws Exception {
|
|
|
|
|
Optional<Zsb> optional = repository.findById(id);
|
|
|
|
|
if (!optional.isPresent()) {
|
|
|
|
|
throw new Exception("未找到该主设备");
|
|
|
|
|
}
|
|
|
|
|
Zsb zsb = optional.get();
|
|
|
|
|
Jg jg = jgService.detail(zsb.getJgid());
|
|
|
|
|
zsb.setBdzName(jg.getBdzName());
|
|
|
|
|
zsb.setJgName(jg.getMc());
|
|
|
|
|
return zsb;
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|