新增监测装置类型表 修复禁止修改表名的bug

iec104
liuguijing 1 year ago
parent 6f7b457269
commit c9325d67d5

@ -6,6 +6,7 @@ import com.xydl.cac.service.ModevTypeService;
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,7 +29,7 @@ public class ModevTypeServiceImpl implements ModevTypeService {
public ModevType add(ModevType item) throws Exception {
item.setId(null);
List<ModevType> byMc = repository.findByMc(item.getMc());
if (!byMc.isEmpty()) {
if (!CollectionUtils.isEmpty(byMc)) {
throw new Exception("该监测装置类型已存在");
}
return repository.save(item);
@ -37,8 +38,12 @@ public class ModevTypeServiceImpl implements ModevTypeService {
@Override
public void update(ModevType item) throws Exception {
List<ModevType> byMc = repository.findByMc(item.getMc());
if (!byMc.isEmpty()) {
throw new Exception("该监测装置类型已存在");
if (!CollectionUtils.isEmpty(byMc)) {
for (ModevType it : byMc) {
if (it.getId() != item.getId()) {
throw new Exception("该监测装置类型已存在");
}
}
}
repository.save(item);
}

Loading…
Cancel
Save