Browse Source

优化逻辑

longhu 1 month ago
parent
commit
0901778f97

+ 0 - 2
src/main/java/com/hr/controller/IpInterfaceController.java

@@ -68,14 +68,12 @@ public class IpInterfaceController {
 
     /**
      * 修改状态
-     *
      * @param switchStatusParam 主键
      * @return 是否成功
      */
     @Operation(summary = "修改状态")
     @PostMapping("/switchStatus")
     public BaseReturnDto<Boolean> switchStatus(@RequestBody SwitchStatusParam switchStatusParam){
-        System.out.println("switchStatusParam:"+switchStatusParam);
         return BaseReturnDto.success(ipInterfaceService.switchStatus(switchStatusParam));
     }
 

+ 4 - 2
src/main/java/com/hr/service/impl/IpAccountServiceImpl.java

@@ -18,6 +18,7 @@ import org.springframework.stereotype.Service;
 import java.time.LocalDateTime;
 import java.util.ArrayList;
 import java.util.List;
+import java.util.Optional;
 
 /**
  * 账户表;(ip_account)表服务接口实现类
@@ -89,10 +90,11 @@ public class IpAccountServiceImpl implements IpAccountService {
 
     @Override
     public Boolean switchStatus(SwitchStatusParam switchStatusParam) {
-        IpAccountPO ipAccountPO = ipAccountRepository.queryById(switchStatusParam.getId());
-        if(ipAccountPO == null){
+        Optional<IpAccountPO> optional = ipAccountRepository.findById(switchStatusParam.getId());
+        if(!optional.isPresent()){
             throw new RuntimeException("接口不存在");
         }
+        IpAccountPO ipAccountPO = optional.get();
         ipAccountPO.setStatus(switchStatusParam.getStatus());
         ipAccountRepository.save(ipAccountPO);
         return true;