pert: 增加主设备校验

dev
huangfeng 1 year ago
parent 09a420ef22
commit 59fd5ae5ba

@ -204,4 +204,12 @@ public class Zsb {
@Column(name = "sssj")
private String sssj;
@ApiModelProperty("变电站名称")
@Transient
private String bdzName;
@ApiModelProperty("区域名称")
@Transient
private String jgName;
}

@ -12,5 +12,5 @@ public interface BdzService {
void update(Bdz item);
void delete(Integer id);
void delete(Integer id) throws Exception;
}

@ -6,11 +6,13 @@ import java.util.List;
public interface ZsbService {
List<Zsb> listAll(Integer jgid);
List<Zsb> listAll(Integer jgid) throws Exception;
Zsb add(Zsb item) throws Exception;
void update(Zsb item) throws Exception;
void delete(Integer id);
void delete(Integer id) throws Exception;
Zsb detail(Integer id) throws Exception;
}

@ -1,11 +1,14 @@
package com.xydl.cac.service.impl;
import com.xydl.cac.entity.Bdz;
import com.xydl.cac.entity.Jg;
import com.xydl.cac.repository.BdzRepository;
import com.xydl.cac.repository.JgRepository;
import com.xydl.cac.service.BdzService;
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;
@ -17,6 +20,8 @@ public class BdzServiceImpl implements BdzService {
@Resource
BdzRepository repository;
@Resource
JgRepository jgRepository;
@Override
public List<Bdz> listAll() {
@ -35,7 +40,11 @@ public class BdzServiceImpl implements BdzService {
}
@Override
public void delete(Integer id) {
public void delete(Integer id) throws Exception {
List<Jg> jgList = jgRepository.findByBdzid(id);
if (!CollectionUtils.isEmpty(jgList)) {
throw new Exception("已被区域使用不能删除");
}
repository.deleteById(id);
}
}

@ -47,8 +47,8 @@ public class JgServiceImpl implements JgService {
}
private void fillBdzName(List<Jg> list) {
if (!CollectionUtils.isEmpty(list)) {
List<Bdz> bdzList = bdzRepository.findAll();
if (!CollectionUtils.isEmpty(list) && !CollectionUtils.isEmpty(bdzList)) {
for (Jg jg : list) {
for (Bdz bdz : bdzList) {
if (bdz.getId().equals(jg.getBdzid())) {

@ -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;
}
}

Loading…
Cancel
Save