瀏覽代碼

删除产品,级联删除服务端关联和令牌

Zhaops 6 年之前
父節點
當前提交
2653f879a6

+ 9 - 4
diagbotman-service/src/main/java/com/diagbot/facade/ProductServiceFacade.java

@@ -1,6 +1,7 @@
 package com.diagbot.facade;
 
 import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
+import com.baomidou.mybatisplus.core.conditions.update.UpdateWrapper;
 import com.baomidou.mybatisplus.core.metadata.IPage;
 import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
 import com.diagbot.dto.ProductServiceDTO;
@@ -161,15 +162,19 @@ public class ProductServiceFacade extends ProductServiceServiceImpl {
         List<ProductService> productServiceList = this.list(queryWrapper);
         Map<Long, ProductService> map = EntityUtil.makeEntityMap(productServiceList, "id");
         //删除令牌
-        QueryWrapper<ServiceToken> serviceTokenQueryWrapper = new QueryWrapper<>();
-        serviceTokenQueryWrapper.in("product_service_id", map.keySet());
-        serviceTokenFacade.deleteByWrapper(serviceTokenQueryWrapper);
+        UpdateWrapper<ServiceToken> tokenUpdateWrapper = new UpdateWrapper<>();
+        tokenUpdateWrapper.in("product_service_id", map.keySet());
+        tokenUpdateWrapper.set("is_deleted", IsDeleteEnum.Y.getKey());
+        serviceTokenFacade.update(new ServiceToken(), tokenUpdateWrapper);
 
         //删除产品服务端关联
         for (ProductService productService : productServiceList) {
             productService.setIsDeleted(IsDeleteEnum.Y.getKey());
         }
-        this.updateBatchById(productServiceList);
+        UpdateWrapper<ProductService> productServiceUpdateWrapper = new UpdateWrapper<>();
+        productServiceUpdateWrapper.in("id", map.keySet());
+        productServiceUpdateWrapper.set("is_deleted", IsDeleteEnum.Y.getKey());
+        this.update(new ProductService(), productServiceUpdateWrapper);
         return true;
     }
 

+ 4 - 4
diagbotman-service/src/main/java/com/diagbot/facade/ServiceTokenFacade.java

@@ -65,11 +65,11 @@ public class ServiceTokenFacade extends ServiceTokenServiceImpl {
         //获取用户的id
         List<ServiceTokenWrapper> serviceTokenWrapperList = this.getByAppkeyAndSecretAndProductId(paramMap);
 
-        if(ListUtil.isEmpty(serviceTokenWrapperList)) {
+        if (ListUtil.isEmpty(serviceTokenWrapperList)) {
             throw new CommonException(CommonErrorCode.SERVER_IS_ERROR, "appkey或secret错误,appkey=【" + appkey + "】," + "secret=【" + secret + "】");
         }
         ServiceTokenWrapper st = serviceTokenWrapperList.get(0);
-        if(StatusEnum.Disable.getKey() == st.getServiceStatus()) {
+        if (StatusEnum.Disable.getKey() == st.getServiceStatus()) {
             throw new CommonException(CommonErrorCode.SERVER_IS_ERROR, "该产品已停用");
         }
         if (TokenTypeEnum.Trial.getKey() == st.getType()) {
@@ -83,7 +83,7 @@ public class ServiceTokenFacade extends ServiceTokenServiceImpl {
             queryWrapper.eq("user_id", st.getUserId());
             queryWrapper.eq("product_id", st.getProductId());
             OpenedProducts op = openedProductsFacade.getOne(queryWrapper);
-            if(op == null) {
+            if (op == null) {
                 throw new CommonException(CommonErrorCode.SERVER_IS_ERROR, "无权限访问");
             }
             Date date = new Date();
@@ -96,7 +96,7 @@ public class ServiceTokenFacade extends ServiceTokenServiceImpl {
         }
         hasPermissionDTO.setHasPermission(true);
         //获取用户的id
-        if(st.getUserId() != null) {
+        if (st.getUserId() != null) {
             hasPermissionDTO.setUserId(st.getUserId().toString());
         }
         return RespDTO.onSuc(hasPermissionDTO);