浏览代码

服务端管理

zhaops 6 年之前
父节点
当前提交
3fd654b273

+ 19 - 0
diagbotman-service/src/main/java/com/diagbot/dto/ProductServiceDTO.java

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

+ 5 - 3
diagbotman-service/src/main/java/com/diagbot/entity/ServiceToken.java

@@ -3,6 +3,8 @@ package com.diagbot.entity;
 import com.baomidou.mybatisplus.annotation.TableName;
 import com.baomidou.mybatisplus.annotation.IdType;
 import com.baomidou.mybatisplus.annotation.TableId;
+import io.swagger.models.auth.In;
+
 import java.util.Date;
 import java.io.Serializable;
 
@@ -70,7 +72,7 @@ public class ServiceToken implements Serializable {
     /**
      * 状态(0:禁用,1:启用)
      */
-    private String status;
+    private Integer status;
 
     /**
      * 开通日期
@@ -168,11 +170,11 @@ public class ServiceToken implements Serializable {
         this.type = type;
     }
 
-    public String getStatus() {
+    public Integer getStatus() {
         return status;
     }
 
-    public void setStatus(String status) {
+    public void setStatus(Integer status) {
         this.status = status;
     }
 

+ 50 - 0
diagbotman-service/src/main/java/com/diagbot/enums/StatusEnum.java

@@ -0,0 +1,50 @@
+package com.diagbot.enums;
+
+import com.diagbot.core.KeyedNamed;
+import lombok.Setter;
+
+/**
+ * @Description:
+ * @author: zhaops
+ * @time: 2018/9/19 10:05
+ */
+public enum StatusEnum implements KeyedNamed {
+    Disable(0, "禁用"),
+    Enable(1, "启用");
+
+    @Setter
+    private Integer key;
+
+    @Setter
+    private String name;
+
+    StatusEnum(Integer key, String name) {
+        this.key = key;
+        this.name = name;
+    }
+
+    public static StatusEnum getEnum(Integer key) {
+        for (StatusEnum item : StatusEnum.values()) {
+            if (item.key == key) {
+                return item;
+            }
+        }
+        return null;
+    }
+
+    public static String getName(Integer key) {
+        StatusEnum item = getEnum(key);
+        return item != null ? item.name : null;
+    }
+
+    @Override
+    public int getKey() {
+        return key;
+    }
+
+    @Override
+    public String getName() {
+        return name;
+    }
+}
+

+ 50 - 0
diagbotman-service/src/main/java/com/diagbot/enums/TokenTypeEnum.java

@@ -0,0 +1,50 @@
+package com.diagbot.enums;
+
+import com.diagbot.core.KeyedNamed;
+import lombok.Setter;
+
+/**
+ * @Description:
+ * @author: zhaops
+ * @time: 2018/9/18 18:59
+ */
+public enum TokenTypeEnum implements KeyedNamed {
+    Online(1, "线上生成"),
+    Manual(2, "手动生成"),
+    Trial(3, "试用");
+
+    @Setter
+    private Integer key;
+
+    @Setter
+    private String name;
+
+    TokenTypeEnum(Integer key, String name) {
+        this.key = key;
+        this.name = name;
+    }
+
+    public static TokenTypeEnum getEnum(Integer key) {
+        for (TokenTypeEnum item : TokenTypeEnum.values()) {
+            if (item.key == key) {
+                return item;
+            }
+        }
+        return null;
+    }
+
+    public static String getName(Integer key) {
+        TokenTypeEnum item = getEnum(key);
+        return item != null ? item.name : null;
+    }
+
+    @Override
+    public int getKey() {
+        return key;
+    }
+
+    @Override
+    public String getName() {
+        return name;
+    }
+}

+ 4 - 4
diagbotman-service/src/main/java/com/diagbot/mapper/ServiceTokenMapper.java

@@ -16,13 +16,13 @@ import java.util.Map;
 public interface ServiceTokenMapper extends BaseMapper<ServiceToken> {
 
 
-    public ServiceToken getServiceToken(Map map);
+    ServiceToken getServiceToken(Map map);
 
     ServiceToken getByProductServiceId(Long productServiceId);
 
-    ServiceToken deleteByProductServiceId(Long productServiceId);
+    Integer deleteByProductServiceId(Long productServiceId);
 
-    ServiceToken enableToken(Long productServiceId);
+    Integer enableToken(Long productServiceId);
 
-    ServiceToken disableToken(Long productServiceId);
+    Integer disableToken(Long productServiceId);
 }

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

@@ -18,13 +18,13 @@ public interface ServiceTokenService extends IService<ServiceToken> {
      * @Author: ztg
      * @Date: 2018/9/18 16:38
      */
-    public ServiceToken getServiceToken(String appkey, String secret);
+    ServiceToken getServiceToken(String appkey, String secret);
 
     ServiceToken getByProductServiceId(Long productServiceId);
 
-    ServiceToken deleteByProductServiceId(Long productServiceId);
+    Integer deleteByProductServiceId(Long productServiceId);
 
-    ServiceToken enableToken(Long productServiceId);
+    Integer enableToken(Long productServiceId);
 
-    ServiceToken disableToken(Long productServiceId);
+    Integer disableToken(Long productServiceId);
 }

+ 8 - 6
diagbotman-service/src/main/java/com/diagbot/service/impl/ServiceTokenServiceImpl.java

@@ -2,6 +2,8 @@ package com.diagbot.service.impl;
 
 import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
 import com.diagbot.entity.ServiceToken;
+import com.diagbot.enums.IsDeleteEnum;
+import com.diagbot.enums.StatusEnum;
 import com.diagbot.mapper.ServiceTokenMapper;
 import com.diagbot.service.ServiceTokenService;
 import org.springframework.beans.factory.annotation.Autowired;
@@ -26,25 +28,25 @@ public class ServiceTokenServiceImpl extends ServiceImpl<ServiceTokenMapper, Ser
 
     @Override
     public ServiceToken getServiceToken(String appkey, String secret) {
-        Map<String,Object> paramMap = new HashMap<>();
+        Map<String, Object> paramMap = new HashMap<>();
         paramMap.put("appkey", appkey);
         paramMap.put("secret", secret);
         return serviceTokenMapper.getServiceToken(paramMap);
     }
 
-    public ServiceToken getByProductServiceId(Long productServiceId){
-        return  baseMapper.getByProductServiceId(productServiceId);
+    public ServiceToken getByProductServiceId(Long productServiceId) {
+        return baseMapper.getByProductServiceId(productServiceId);
     }
 
-    public ServiceToken deleteByProductServiceId(Long productServiceId){
+    public Integer deleteByProductServiceId(Long productServiceId) {
         return baseMapper.deleteByProductServiceId(productServiceId);
     }
 
-    public ServiceToken enableToken(Long productServiceId){
+    public Integer enableToken(Long productServiceId) {
         return baseMapper.enableToken(productServiceId);
     }
 
-    public ServiceToken disableToken(Long productServiceId){
+    public Integer disableToken(Long productServiceId) {
         return baseMapper.disableToken(productServiceId);
     }
 }

+ 21 - 0
diagbotman-service/src/main/java/com/diagbot/vo/ProductServiceSaveVO.java

@@ -0,0 +1,21 @@
+package com.diagbot.vo;
+
+import lombok.Getter;
+import lombok.Setter;
+
+import javax.validation.constraints.NotBlank;
+
+/**
+ * @Description:
+ * @author: zhaops
+ * @time: 2018/9/18 18:53
+ */
+@Getter
+@Setter
+public class ProductServiceSaveVO {
+    @NotBlank(message = "请输入产品Id!")
+    private Long productId;
+    @NotBlank(message = "请输入服务Id!")
+    private Long serviceId;
+    private Integer type;
+}

+ 20 - 0
diagbotman-service/src/main/java/com/diagbot/vo/ServiceSaveVO.java

@@ -0,0 +1,20 @@
+package com.diagbot.vo;
+
+import lombok.Getter;
+import lombok.Setter;
+
+import javax.validation.constraints.NotBlank;
+
+/**
+ * @Description:
+ * @author: zhaops
+ * @time: 2018/9/18 16:48
+ */
+@Getter
+@Setter
+public class ServiceSaveVO {
+    @NotBlank(message = "请输入产品名称!")
+    private String name;
+    @NotBlank(message = "请输入产品介绍!")
+    private String description;
+}

+ 26 - 2
diagbotman-service/src/main/java/com/diagbot/web/ProductServiceController.java

@@ -1,9 +1,20 @@
 package com.diagbot.web;
 
 
+import com.diagbot.annotation.SysLogger;
+import com.diagbot.dto.ProductServiceDTO;
+import com.diagbot.dto.RespDTO;
+import com.diagbot.entity.ServiceInfo;
+import com.diagbot.facade.ProductServiceFacade;
+import com.diagbot.vo.ProductServiceSaveVO;
+import io.swagger.annotations.Api;
+import io.swagger.annotations.ApiOperation;
+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.stereotype.Controller;
+import org.springframework.web.bind.annotation.RestController;
 
 /**
  * <p>
@@ -13,9 +24,22 @@ import org.springframework.stereotype.Controller;
  * @author zhaops
  * @since 2018-09-17
  */
-@Controller
+@RestController
+@Api(value="产品服务端API", tags={"产品服务端API"})
 @RequestMapping("/productService")
 public class ProductServiceController {
+    @Autowired
+    private ProductServiceFacade productServiceFacade;
 
+    @ApiOperation(value = "服务端关联到产品接口",
+            notes = "productId:产品Id,必填<br>" +
+                    "serviceId:服务Id,必填<br> ")
+    @PostMapping("/genProductService")
+    @SysLogger("genProductService")
+    @Transactional
+    public RespDTO<ProductServiceDTO> genProductService(ProductServiceSaveVO productServiceSaveVO) {
+        ProductServiceDTO productServiceDTO = productServiceFacade.genProductService(productServiceSaveVO);
+        return RespDTO.onSuc(productServiceDTO);
+    }
 }
 

+ 50 - 1
diagbotman-service/src/main/java/com/diagbot/web/ServiceInfoController.java

@@ -1,9 +1,24 @@
 package com.diagbot.web;
 
 
+import com.diagbot.annotation.SysLogger;
+import com.diagbot.dto.RespDTO;
+import com.diagbot.entity.ServiceInfo;
+import com.diagbot.facade.ServiceInfoFacade;
+import com.diagbot.vo.ServiceSaveVO;
+import io.swagger.annotations.Api;
+import io.swagger.annotations.ApiOperation;
+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.RequestBody;
 import org.springframework.web.bind.annotation.RequestMapping;
 
 import org.springframework.stereotype.Controller;
+import org.springframework.web.bind.annotation.RestController;
+
+import javax.validation.Valid;
+import java.util.List;
 
 /**
  * <p>
@@ -13,9 +28,43 @@ import org.springframework.stereotype.Controller;
  * @author zhaops
  * @since 2018-09-17
  */
-@Controller
+@RestController
+@Api(value="用户服务API", tags={"用户服务API"})
 @RequestMapping("/serviceInfo")
 public class ServiceInfoController {
 
+    @Autowired
+    private ServiceInfoFacade serviceInfoFacade;
+
+    @ApiOperation(value = "新增服务",
+            notes = "name:产品名称,必填<br>" +
+                    "description:产品简介,必填<br> ")
+    @PostMapping("/createService")
+    @SysLogger("createService")
+    @Transactional
+    public RespDTO<ServiceInfo> createService(@RequestBody @Valid ServiceSaveVO serviceSaveVO) {
+        ServiceInfo serviceInfo = serviceInfoFacade.createService(serviceSaveVO);
+        return RespDTO.onSuc(serviceInfo);
+    }
+
+    @ApiOperation(value = "修改服务",
+            notes = "name:产品名称,必填<br>" +
+                    "description:产品简介,必填<br> ")
+    @PostMapping("/updateService")
+    @SysLogger("updateService")
+    @Transactional
+    public RespDTO<Boolean> updateService(@RequestBody @Valid ServiceSaveVO serviceSaveVO) {
+        Boolean isSuccess = serviceInfoFacade.updateService(serviceSaveVO);
+        return RespDTO.onSuc(isSuccess);
+    }
+
+    @ApiOperation(value = "获取当前登录用户的服务列表")
+    @PostMapping("/getServiceListByCurrentUser")
+    @SysLogger("getServiceListByCurrentUser")
+    @Transactional
+    public RespDTO<List<ServiceInfo>> getServiceListByCurrentUser() {
+        List<ServiceInfo> list = serviceInfoFacade.getServiceListByCurrentUser();
+        return RespDTO.onSuc(list);
+    }
 }
 

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

@@ -1,14 +1,24 @@
 package com.diagbot.web;
 
 
+import com.diagbot.annotation.SysLogger;
+import com.diagbot.dto.ProductServiceDTO;
 import com.diagbot.dto.RespDTO;
+import com.diagbot.facade.ProductServiceFacade;
 import com.diagbot.facade.ServiceTokenFacade;
+import com.diagbot.vo.ProductServiceSaveVO;
+import io.swagger.annotations.ApiOperation;
 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.RequestBody;
 import org.springframework.web.bind.annotation.RequestMapping;
+import org.springframework.web.bind.annotation.RequestParam;
 import org.springframework.web.bind.annotation.RestController;
 import springfox.documentation.annotations.ApiIgnore;
 
+import javax.validation.Valid;
+
 /**
  * <p>
  * 服务令牌表 前端控制器
@@ -23,6 +33,8 @@ public class ServiceTokenController {
 
     @Autowired
     ServiceTokenFacade serviceTokenFacade;
+    @Autowired
+    ProductServiceFacade productServiceFacade;
 
 
     @PostMapping("/hasPermission")
@@ -33,5 +45,45 @@ public class ServiceTokenController {
         //        return serviceTokenFacade.hasPermission(appkey, secret, productId);
     }
 
+    @ApiOperation(value = "生成令牌",
+            notes = "productId:产品Id,必填<br>" +
+                    "serviceId:服务Id,必填<br> ")
+    @PostMapping("/createServiceToken")
+    @SysLogger("createServiceToken")
+    @Transactional
+    public RespDTO<ProductServiceDTO> createServiceToken(@RequestBody @Valid ProductServiceSaveVO productServiceSaveVO) {
+        ProductServiceDTO productServiceDTO = productServiceFacade.genProductService(productServiceSaveVO);
+        return RespDTO.onSuc(productServiceDTO);
+    }
+
+    @ApiOperation(value = "令牌禁用",
+            notes = "productServiceId:产品服务id,必填<br>")
+    @PostMapping("/disableToken")
+    @SysLogger("disableToken")
+    @Transactional
+    public RespDTO<Integer> disableToken(@RequestParam Long productServiceId) {
+        Integer count = serviceTokenFacade.disableToken(productServiceId);
+        return RespDTO.onSuc(count);
+    }
+
+    @ApiOperation(value = "令牌启用",
+            notes = "productServiceId:产品服务id,必填<br>")
+    @PostMapping("/enableToken")
+    @SysLogger("enableToken")
+    @Transactional
+    public RespDTO<Integer> enableToken(@RequestParam Long productServiceId) {
+        Integer count = serviceTokenFacade.enableToken(productServiceId);
+        return RespDTO.onSuc(count);
+    }
+
+    @ApiOperation(value = "令牌删除",
+            notes = "productServiceId:产品服务id,必填<br>")
+    @PostMapping("/deleteTokenByProductServiceId")
+    @SysLogger("deleteTokenByProductServiceId")
+    @Transactional
+    public RespDTO<Integer> deleteTokenByProductServiceId(@RequestParam Long productServiceId) {
+        Integer count = serviceTokenFacade.deleteByProductServiceId(productServiceId);
+        return RespDTO.onSuc(count);
+    }
 }
 

+ 4 - 0
diagbotman-service/src/main/resources/mapper/ProductServiceMapper.xml

@@ -25,4 +25,8 @@
         where product_id = #{procuctId} and is_deleted = 'N'
     </select>
 
+    <update id="deleteById" parameterType="java.lang.Long">
+        update diag_product_service set is_deleted='Y'
+        where id = #{id} and is_deleted = 'N'
+    </update>
 </mapper>

+ 6 - 6
diagbotman-service/src/main/resources/mapper/ServiceTokenMapper.xml

@@ -30,19 +30,19 @@
         where product_sevice_id = #{productServiceId} and is_deleted = 'N'
     </select>
 
-    <select id="deleteByProductServiceId" resultMap="BaseResultMap" parameterType="java.lang.Long">
+    <update id="deleteByProductServiceId"  parameterType="java.lang.Long">
         update diag_service_token set is_deleted='Y'
         where product_sevice_id = #{productServiceId} and is_deleted = 'N'
-    </select>
+    </update>
 
-    <select id="enableToken" resultMap="BaseResultMap" parameterType="java.lang.Long">
+    <update id="enableToken" parameterType="java.lang.Long">
         update diag_service_token set status=1
         where product_sevice_id = #{productServiceId} and is_deleted = 'N'
-    </select>
+    </update>
 
-    <select id="disableToken" resultMap="BaseResultMap" parameterType="java.lang.Long">
+    <update id="disableToken" parameterType="java.lang.Long">
         update diag_service_token set status=0
         where product_sevice_id = #{productServiceId} and is_deleted = 'N'
-    </select>
+    </update>
 
 </mapper>