yaoyi 1 місяць тому
батько
коміт
3d7986b514

+ 1 - 1
src/main/java/com/hr/repository/jpa/IpInterfaceRepository.java

@@ -12,7 +12,7 @@ import java.util.List;
  */
 public interface IpInterfaceRepository extends JpaRepository<IpInterfacePO,Long> {
 
-    IpInterfacePO queryById(Long id);
+//    IpInterfacePO findById(Long id);
 
     IpInterfacePO findByInterfaceName(String interfaceName);
     IpInterfacePO findByInterfaceNo(String interfaceNo);

+ 14 - 7
src/main/java/com/hr/service/impl/IpInterfaceServiceImpl.java

@@ -15,6 +15,7 @@ import org.springframework.stereotype.Service;
 import java.time.LocalDateTime;
 import java.util.ArrayList;
 import java.util.List;
+import java.util.Optional;
 
 /**
  * 接口表;(ip_interface)表服务接口实现类
@@ -33,11 +34,15 @@ public class IpInterfaceServiceImpl implements IpInterfaceService {
      * @return 实例对象
      */
     public IpInterfaceVO queryById(Long id){
-        IpInterfacePO ipInterfacePO = ipInterfaceRepository.queryById(id);
-        IpInterfaceVO ipInterfaceVO = new IpInterfaceVO();
-        if(ipInterfacePO != null){
-            BeanUtils.copyProperties(ipInterfacePO, ipInterfaceVO);
-            return ipInterfaceVO;
+//        IpInterfacePO ipInterfacePO = ipInterfaceRepository.findById(id).get();
+        Optional<IpInterfacePO> optional = ipInterfaceRepository.findById(id);
+        if(optional.isPresent()) {
+            IpInterfacePO ipInterfacePO=optional.get();
+            IpInterfaceVO ipInterfaceVO = new IpInterfaceVO();
+            if (ipInterfacePO != null) {
+                BeanUtils.copyProperties(ipInterfacePO, ipInterfaceVO);
+                return ipInterfaceVO;
+            }
         }
         return null;
     }
@@ -86,10 +91,12 @@ public class IpInterfaceServiceImpl implements IpInterfaceService {
 
     @Override
     public Boolean switchStatus(SwitchStatusParam switchStatusParam) {
-        IpInterfacePO ipInterfacePO = ipInterfaceRepository.queryById(switchStatusParam.getId());
-        if(ipInterfacePO == null){
+        Optional<IpInterfacePO> optional = ipInterfaceRepository.findById(switchStatusParam.getId());
+        if(!optional.isPresent()){
             throw new RuntimeException("接口不存在");
         }
+        IpInterfacePO ipInterfacePO = optional.get();
+
         ipInterfacePO.setStatus(switchStatusParam.getStatus());
         ipInterfaceRepository.save(ipInterfacePO);
         return true;