Explorar o código

增加删除判断

longhu hai 5 días
pai
achega
700ac2593c

+ 9 - 0
.idea/setting.xml

@@ -0,0 +1,9 @@
+<?xml version="1.0" encoding="UTF-8"?>
+<project version="4">
+  <component name="arthas.idea.plugin">
+    <option name="redisAddress" value="" />
+    <option name="redisAuth" value="" />
+    <option name="redisCacheKey" value="" />
+    <option name="lastSelectAppJson" value="null" />
+  </component>
+</project>

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

@@ -71,7 +71,8 @@ public class IpInterfaceController {
     @Operation(summary = "通过主键删除数据")
     @DeleteMapping("/delete/{id}")
     public BaseReturnDto<Boolean> deleteById(@PathVariable Long id){
-        return BaseReturnDto.success(ipInterfaceService.deleteById(id));
+        LoginUser user = TokenUtil.getUser();
+        return BaseReturnDto.success(ipInterfaceService.deleteById(id,user));
     }
 
     /**

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

@@ -25,4 +25,7 @@ public interface IpInterfaceRepository extends JpaRepository<IpInterfacePO,Long>
 
     BasePageResult<IpInterfaceVO> queryPage(@Param("interfaceName") String interfaceName, @Param("statusList") List<String> statusList);
 
+    Integer countEnableInterfaceRef(@Param("iid") Long iid);
+
+    Integer countEnableAccountRef(@Param("id") Long id);
 }

+ 5 - 5
src/main/java/com/hr/service/IpInterfaceService.java

@@ -1,6 +1,5 @@
 package com.hr.service;
 
-import com.github.pagehelper.PageInfo;
 import com.hr.param.InterfaceConfigParam;
 import com.hr.param.IpInterfaceParam;
 import com.hr.param.SwitchStatusParam;
@@ -8,7 +7,7 @@ import com.hr.repository.domain.IpInterfacePO;
 import com.hr.vo.IpInterfaceVO;
 import com.hr.vo.NameValueVO;
 import com.yy.basedevelop.common.data.BasePageResult;
-import org.springframework.data.domain.Page;
+import com.yy.basedevelop.dto.LoginUser;
 
 import java.util.List;
 
@@ -50,13 +49,14 @@ public interface IpInterfaceService{
      * @return 实例对象
      */
     void update(IpInterfacePO IpInterfacePO);
-    /** 
+    /**
      * 通过主键删除数据
      *
-     * @param iid 主键
+     * @param iid  主键
+     * @param user
      * @return 是否成功
      */
-    boolean deleteById(Long iid);
+    boolean deleteById(Long iid, LoginUser user);
 
     void saveOrUpdate(IpInterfaceParam ipInterfaceParam, String username, Long userid);
 

+ 9 - 0
src/main/java/com/hr/service/impl/IpAccountServiceImpl.java

@@ -9,6 +9,7 @@ import com.hr.param.IpAccountParam;
 import com.hr.param.SwitchStatusParam;
 import com.hr.repository.domain.IpAccountPO;
 import com.hr.repository.jpa.IpAccountRepository;
+import com.hr.repository.jpa.IpInterfaceRepository;
 import com.hr.service.IpAccountService;
 import com.hr.util.SnowflakeIdWorker;
 import com.hr.vo.IpAccountVO;
@@ -35,6 +36,10 @@ public class IpAccountServiceImpl implements IpAccountService {
     @Autowired
     private IpAccountRepository ipAccountRepository;
 
+    @Autowired
+    private IpInterfaceRepository ipInterfaceRepository;
+
+
     private static final Cache<String, IpAccountVO> QUERY_CACHE = CacheBuilder.newBuilder()
             .expireAfterWrite(100, TimeUnit.SECONDS)
             .build();
@@ -155,6 +160,10 @@ public class IpAccountServiceImpl implements IpAccountService {
      */
     public boolean deleteById(Long id, LoginUser user){
         IpAccountPO ipAccountPO = ipAccountRepository.findById(id).get();
+        Integer countNum = ipInterfaceRepository.countEnableAccountRef(id);
+        if(countNum > 0){
+            throw new RuntimeException("存在激活的接口关联,请先停用关联的接口");
+        }
         ipAccountPO.setStatus("delete");
         ipAccountPO.setUpdateTime(new Date());
         ipAccountPO.setUpdateUserId(user.getUserid());

+ 17 - 4
src/main/java/com/hr/service/impl/IpInterfaceServiceImpl.java

@@ -1,7 +1,6 @@
 package com.hr.service.impl;
 
 import com.github.pagehelper.PageHelper;
-import com.github.pagehelper.PageInfo;
 import com.google.common.cache.Cache;
 import com.google.common.cache.CacheBuilder;
 import com.hr.param.InterfaceConfigParam;
@@ -14,6 +13,7 @@ import com.hr.util.SnowflakeIdWorker;
 import com.hr.vo.IpInterfaceVO;
 import com.hr.vo.NameValueVO;
 import com.yy.basedevelop.common.data.BasePageResult;
+import com.yy.basedevelop.dto.LoginUser;
 import org.apache.commons.lang3.StringUtils;
 import org.springframework.beans.BeanUtils;
 import org.springframework.beans.factory.annotation.Autowired;
@@ -174,11 +174,24 @@ public class IpInterfaceServiceImpl implements IpInterfaceService {
     /**
      * 通过主键删除数据
      *
-     * @param iid 主键
+     * @param iid  主键
+     * @param user
      * @return 是否成功
      */
-    public boolean deleteById(Long iid){
-        ipInterfaceRepository.deleteById(iid);
+    public boolean deleteById(Long iid, LoginUser user){
+        IpInterfacePO ipInterfacePO = ipInterfaceRepository.findById(iid).get();
+        if(ipInterfacePO == null){
+            return false;
+        }
+        Integer countNum = ipInterfaceRepository.countEnableInterfaceRef(iid);
+        if(countNum > 0){
+            throw new RuntimeException("存在激活的接口关联,请先停用关联的接口");
+        }
+        ipInterfacePO.setStatus("delete");
+        ipInterfacePO.setUpdateTime(new Date());
+        ipInterfacePO.setUpdateUserId(user.getUserid());
+        ipInterfacePO.setUpdateUserName(user.getUsername());
+        ipInterfaceRepository.save(ipInterfacePO);
         return true;
     }
 }

+ 6 - 4
src/main/java/com/hr/service/impl/IpTokenInterfaceServiceImpl.java

@@ -172,10 +172,12 @@ public class IpTokenInterfaceServiceImpl implements IpTokenInterfaceService {
             vo.setToken(ipTokenPO.getToken());
             vo.setRemark(ipTokenPO.getRemark());
             IpInterfacePO ipInterfacePO = interfaceMap.get(item.getIid());
-            vo.setInterfaceCode(ipInterfacePO.getInterfaceNo());
-            vo.setInterfaceName(ipInterfacePO.getInterfaceName());
-            vo.setInterfaceId(ipInterfacePO.getId());
-            vo.setManufacturer(ipInterfacePO.getManufacturer());
+            if(ipInterfacePO != null){
+                vo.setInterfaceCode(ipInterfacePO.getInterfaceNo());
+                vo.setInterfaceName(ipInterfacePO.getInterfaceName());
+                vo.setInterfaceId(ipInterfacePO.getId());
+                vo.setManufacturer(ipInterfacePO.getManufacturer());
+            }
             vo.setCallback(item.getIsCallback());
             vo.setCallbackUrl(item.getCallbackUrl());
             return vo;

+ 6 - 0
src/main/resources/mapper/IpInterfaceMapper.xml

@@ -23,4 +23,10 @@
     <select id="queryPage" resultType="com.hr.vo.IpInterfaceVO">
         select * from ip_interface where 1=1 and interface_name like '%'||:interfaceName||'%' and status in (:statusList)
     </select>
+    <select id="countEnableInterfaceRef" resultType="java.lang.Integer">
+        select count(*) from ip_token_interface where status = 'normal' and interface_id = :iid
+    </select>
+    <select id="countEnableAccountRef" resultType="java.lang.Integer">
+        select count(*) from ip_token_interface where status = 'normal' and aid = :id
+    </select>
 </mapper>