zhaops пре 6 година
родитељ
комит
5ab0bc2bfe

+ 3 - 5
diagbotman-service/src/main/java/com/diagbot/dto/ProductServiceDTO.java

@@ -1,7 +1,6 @@
 package com.diagbot.dto;
 
 import com.diagbot.entity.LantoneProduct;
-import com.diagbot.entity.OpenedProducts;
 import com.diagbot.entity.ProductService;
 import com.diagbot.entity.ServiceInfo;
 import com.diagbot.entity.ServiceToken;
@@ -9,16 +8,15 @@ import lombok.Getter;
 import lombok.Setter;
 
 /**
- * @Description:
+ * @Description:产品服务关联信息返回类
  * @author: zhaops
- * @time: 2018/9/19 15:11
+ * @time: 2018/9/18 19:58
  */
 @Getter
 @Setter
 public class ProductServiceDTO {
     private ProductService productService;
+    private ServiceToken serviceToken;
     private LantoneProduct lantoneProduct;
-    private OpenedProducts openedProducts;
     private ServiceInfo serviceInfo;
-    private ServiceToken serviceToken;
 }

+ 0 - 23
diagbotman-service/src/main/java/com/diagbot/dto/ProductServiceRespDTO.java

@@ -1,23 +0,0 @@
-package com.diagbot.dto;
-
-import com.diagbot.entity.LantoneProduct;
-import com.diagbot.entity.ProductService;
-import com.diagbot.entity.ServiceInfo;
-import com.diagbot.entity.ServiceToken;
-import lombok.Getter;
-import lombok.Setter;
-
-/**
- * @Description:
- * @author: zhaops
- * @time: 2018/9/18 19:58
- */
-@Getter
-@Setter
-public class ProductServiceRespDTO {
-    private ProductService productService;
-    private ServiceToken serviceToken;
-    private LantoneProduct lantoneProduct;
-    private ServiceInfo serviceInfo;
-    private String msg;
-}

+ 20 - 23
diagbotman-service/src/main/java/com/diagbot/facade/ProductServiceFacade.java

@@ -2,7 +2,7 @@ package com.diagbot.facade;
 
 import com.baomidou.mybatisplus.core.metadata.IPage;
 import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
-import com.diagbot.dto.ProductServiceRespDTO;
+import com.diagbot.dto.ProductServiceDTO;
 import com.diagbot.entity.LantoneProduct;
 import com.diagbot.entity.OpenedProducts;
 import com.diagbot.entity.ProductService;
@@ -10,6 +10,8 @@ import com.diagbot.entity.ServiceInfo;
 import com.diagbot.entity.ServiceToken;
 import com.diagbot.entity.wrapper.ProductServiceWrapper;
 import com.diagbot.enums.TokenTypeEnum;
+import com.diagbot.exception.CommonErrorCode;
+import com.diagbot.exception.CommonException;
 import com.diagbot.service.impl.ProductServiceServiceImpl;
 import com.diagbot.util.GuidUtil;
 import com.diagbot.util.UserUtils;
@@ -44,22 +46,22 @@ public class ProductServiceFacade extends ProductServiceServiceImpl {
      * @author: zhaops
      * @time: 2018/9/18 16:33
      */
-    public ProductServiceRespDTO genProductService(ProductServiceSaveVO productServiceSaveVO) {
-        ProductServiceRespDTO productServiceRespDTO = new ProductServiceRespDTO();
+    public ProductServiceDTO genProductService(ProductServiceSaveVO productServiceSaveVO) {
+        ProductServiceDTO productServiceDTO = new ProductServiceDTO();
         Calendar calendar = Calendar.getInstance();
         Long userId = Long.parseLong(UserUtils.getCurrentPrincipleID());
         LantoneProduct lantoneProduct = lantoneProductFacade.getById(productServiceSaveVO.getProductId());
         if (lantoneProduct == null) {
-            productServiceRespDTO.setMsg("找不到产品【" + lantoneProduct.getName() + "】");
-            return productServiceRespDTO;
+            throw new CommonException(CommonErrorCode.NOT_EXISTS,
+                    "找不到产品【" + lantoneProduct.getName() + "】");
         }
         ServiceInfo serviceInfo = serviceInfoFacade.getById(productServiceSaveVO.getServiceId());
         if (serviceInfo == null) {
-            productServiceRespDTO.setMsg("找不到服务端【" + serviceInfo.getName() + "】");
-            return productServiceRespDTO;
+            throw new CommonException(CommonErrorCode.NOT_EXISTS,
+                    "找不到服务端【" + serviceInfo.getName() + "】");
         } else if (serviceInfo.getUserId() != userId) {
-            productServiceRespDTO.setMsg("当前登录用户没有关联服务端【" + serviceInfo.getName() + "】");
-            return productServiceRespDTO;
+            throw new CommonException(CommonErrorCode.SERVER_IS_ERROR,
+                    "当前登录用户没有关联服务端【" + serviceInfo.getName() + "】");
         }
 
         Map<String, Object> map = new HashMap<>();
@@ -99,8 +101,8 @@ public class ProductServiceFacade extends ProductServiceServiceImpl {
         if (old_serviceToken != null && old_serviceToken.getType().equals(TokenTypeEnum.Trial)) {
             //如果试用已过期,不允许再生成
             if (calendar.after(old_serviceToken.getExpiringDate())) {
-                productServiceRespDTO.setMsg("当前试用账号已过期,不允许再生成令牌");
-                return productServiceRespDTO;
+                throw new CommonException(CommonErrorCode.SERVER_IS_ERROR,
+                        "当前试用账号已过期,不允许再生成令牌");
             }
             serviceToken.setStartingDate(old_serviceToken.getStartingDate());
             serviceToken.setExpiringDate(old_serviceToken.getExpiringDate());
@@ -112,11 +114,10 @@ public class ProductServiceFacade extends ProductServiceServiceImpl {
             serviceToken.setExpiringDate(calendar.getTime());
         }
         serviceTokenFacade.save(serviceToken);
-        productServiceRespDTO.setServiceToken(serviceToken);
-        productServiceRespDTO.setMsg("令牌生成成功!");
+        productServiceDTO.setServiceToken(serviceToken);
 
-        productServiceRespDTO.setProductService(productService);
-        return productServiceRespDTO;
+        productServiceDTO.setProductService(productService);
+        return productServiceDTO;
     }
 
     /**
@@ -124,24 +125,20 @@ public class ProductServiceFacade extends ProductServiceServiceImpl {
      * @author: zhaops
      * @time: 2018/9/18 16:33
      */
-    public ProductServiceRespDTO deleteProductService(ProductServiceSaveVO productServiceSaveVO) {
-        ProductServiceRespDTO productServiceRespDTO = new ProductServiceRespDTO();
-        Calendar calendar = Calendar.getInstance();
-        Long userId = Long.parseLong(UserUtils.getCurrentPrincipleID());
+    public Boolean deleteProductService(ProductServiceSaveVO productServiceSaveVO) {
         Map<String, Object> map = new HashMap<>();
         map.put("productId", productServiceSaveVO.getProductId());
         map.put("serviceId", productServiceSaveVO.getServiceId());
         ProductService productService = this.findByProductIdAndServiceId(map);
         if (productService == null) {
-            productServiceRespDTO.setMsg("产品服务端不存在!");
-            return productServiceRespDTO;
+            throw new CommonException(CommonErrorCode.NOT_EXISTS,
+                    "找不到产品服务端");
         }
         //删除关联令牌
         serviceTokenFacade.deleteByProductServiceId(productService.getId());
         //删除产品服务端
         this.delById(productService.getId());
-        productServiceRespDTO.setMsg("删除成功!");
-        return productServiceRespDTO;
+        return true;
     }
 
     /**

+ 26 - 0
diagbotman-service/src/main/java/com/diagbot/facade/ServiceInfoFacade.java

@@ -6,6 +6,8 @@ import com.diagbot.entity.LantoneProduct;
 import com.diagbot.entity.ServiceInfo;
 import com.diagbot.entity.ServiceToken;
 import com.diagbot.entity.wrapper.ProductServiceWrapper;
+import com.diagbot.exception.CommonErrorCode;
+import com.diagbot.exception.CommonException;
 import com.diagbot.service.impl.ServiceInfoServiceImpl;
 import com.diagbot.util.UserUtils;
 import com.diagbot.vo.ServiceSaveVO;
@@ -20,6 +22,11 @@ import java.util.List;
  */
 @Component
 public class ServiceInfoFacade extends ServiceInfoServiceImpl {
+    /**
+     * @Description: 新建服务端
+     * @author: zhaops
+     * @time: 2018/9/18 16:31
+     */
     public ServiceInfo createService(ServiceSaveVO serviceSaveVO) {
         Long userId = Long.parseLong(UserUtils.getCurrentPrincipleID());
         ServiceInfo serviceInfo = new ServiceInfo();
@@ -33,20 +40,39 @@ public class ServiceInfoFacade extends ServiceInfoServiceImpl {
         return serviceInfo;
     }
 
+    /**
+     * @Description: 修改服务端
+     * @author: zhaops
+     * @time: 2018/9/18 16:31
+     */
     public Boolean updateService(ServiceInfo serviceInfo) {
         Long userId = Long.parseLong(UserUtils.getCurrentPrincipleID());
+        if (userId != serviceInfo.getUserId()) {
+            throw new CommonException(CommonErrorCode.UPDATE_INFO_FAIL,
+                    "服务端【" + serviceInfo.getName() + "】关联用户与当前登录用户不匹配");
+        }
         serviceInfo.setUserId(userId);
         serviceInfo.setModifier(userId.toString());
         serviceInfo.setGmtModified(new Date());
         return this.updateById(serviceInfo);
     }
 
+    /**
+     * @Description: 获取当前登录用户服务列表
+     * @author: zhaops
+     * @time: 2018/9/18 16:31
+     */
     public List<ServiceInfo> getServiceListByCurrentUser() {
         Long userId = Long.parseLong(UserUtils.getCurrentPrincipleID());
         List<ServiceInfo> list = this.getListByUserId(userId);
         return list;
     }
 
+    /**
+     * @Description: 获取当前登录用户服务分页列表
+     * @author: zhaops
+     * @time: 2018/9/19 14:05
+     */
     public IPage<ServiceInfo> getServiceListPageByCurrentUser(Page<ServiceInfo> page) {
         Long userId = Long.parseLong(UserUtils.getCurrentPrincipleID());
         ServiceInfo serviceInfoVO = new ServiceInfo();

+ 6 - 10
diagbotman-service/src/main/java/com/diagbot/web/ProductServiceController.java

@@ -5,9 +5,7 @@ import com.baomidou.mybatisplus.core.metadata.IPage;
 import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
 import com.diagbot.annotation.SysLogger;
 import com.diagbot.dto.ProductServiceDTO;
-import com.diagbot.dto.ProductServiceRespDTO;
 import com.diagbot.dto.RespDTO;
-import com.diagbot.entity.User;
 import com.diagbot.entity.wrapper.ProductServiceWrapper;
 import com.diagbot.facade.ProductServiceFacade;
 import com.diagbot.vo.ProductServiceSaveVO;
@@ -17,9 +15,7 @@ import org.springframework.beans.factory.annotation.Autowired;
 import org.springframework.transaction.annotation.Transactional;
 import org.springframework.web.bind.annotation.PostMapping;
 import org.springframework.web.bind.annotation.RequestMapping;
-
 import org.springframework.web.bind.annotation.RestController;
-import springfox.documentation.annotations.ApiIgnore;
 
 /**
  * <p>
@@ -43,9 +39,9 @@ public class ProductServiceController {
     @PostMapping("/genProductService")
     @SysLogger("genProductService")
     @Transactional
-    public RespDTO<ProductServiceRespDTO> genProductService(ProductServiceSaveVO productServiceSaveVO) {
-        ProductServiceRespDTO productServiceRespDTO = productServiceFacade.genProductService(productServiceSaveVO);
-        return RespDTO.onSuc(productServiceRespDTO);
+    public RespDTO<ProductServiceDTO> genProductService(ProductServiceSaveVO productServiceSaveVO) {
+        ProductServiceDTO productServiceDTO = productServiceFacade.genProductService(productServiceSaveVO);
+        return RespDTO.onSuc(productServiceDTO);
     }
 
     @ApiOperation(value = "删除产品服务端",
@@ -55,9 +51,9 @@ public class ProductServiceController {
     @PostMapping("/deleteProductService")
     @SysLogger("deleteProductService")
     @Transactional
-    public RespDTO<ProductServiceRespDTO> deleteProductService(ProductServiceSaveVO productServiceSaveVO) {
-        ProductServiceRespDTO productServiceRespDTO = productServiceFacade.deleteProductService(productServiceSaveVO);
-        return RespDTO.onSuc(productServiceRespDTO);
+    public RespDTO<Boolean> deleteProductService(ProductServiceSaveVO productServiceSaveVO) {
+        Boolean isSuccess = productServiceFacade.deleteProductService(productServiceSaveVO);
+        return RespDTO.onSuc(isSuccess);
     }
 
     @ApiOperation(value = "根据用户id获取产品服务关联信息", notes = "根据用户id获取产品服务关联信息")

+ 4 - 4
diagbotman-service/src/main/java/com/diagbot/web/ServiceTokenController.java

@@ -2,7 +2,7 @@ package com.diagbot.web;
 
 
 import com.diagbot.annotation.SysLogger;
-import com.diagbot.dto.ProductServiceRespDTO;
+import com.diagbot.dto.ProductServiceDTO;
 import com.diagbot.dto.RespDTO;
 import com.diagbot.facade.ProductServiceFacade;
 import com.diagbot.facade.ServiceTokenFacade;
@@ -50,9 +50,9 @@ public class ServiceTokenController {
     @PostMapping("/createServiceToken")
     @SysLogger("createServiceToken")
     @Transactional
-    public RespDTO<ProductServiceRespDTO> createServiceToken(@RequestBody @Valid ProductServiceSaveVO productServiceSaveVO) {
-        ProductServiceRespDTO productServiceRespDTO = productServiceFacade.genProductService(productServiceSaveVO);
-        return RespDTO.onSuc(productServiceRespDTO);
+    public RespDTO<ProductServiceDTO> createServiceToken(@RequestBody @Valid ProductServiceSaveVO productServiceSaveVO) {
+        ProductServiceDTO productServiceDTO = productServiceFacade.genProductService(productServiceSaveVO);
+        return RespDTO.onSuc(productServiceDTO);
     }
 
     @ApiOperation(value = "令牌禁用",