Browse Source

Merge remote-tracking branch 'origin/dev/one' into dev/one

zhaops 6 years ago
parent
commit
6a6b53b1d7

+ 34 - 0
diagbotman-service/src/main/java/com/diagbot/dto/GetConsoleOnTrialDTO.java

@@ -6,5 +6,39 @@ import lombok.Setter;
 @Getter
 @Setter
 public class GetConsoleOnTrialDTO {
+	
+	/**
+	 * 产品id
+	 */
+	private Long id;
+	
+	/**
+	 * 产品名
+	 */
+	private String name;
+	
+	/**
+	 * 接入模式
+	 */
+	private String accessType;
+	
+    /**
+     * 是否已试用
+     */
+    private String isUsed;
+	
+    /**
+     * 试用地址
+     */
+    private String trialUrl;
+    
+    /**
+     * 开通日期
+     */
+    private String startingDate;
 
+    /**
+     * 到期时间
+     */
+    private String expiringDate;
 }

+ 11 - 0
diagbotman-service/src/main/java/com/diagbot/dto/OpenUpOnTrialDTO.java

@@ -0,0 +1,11 @@
+package com.diagbot.dto;
+
+import lombok.Getter;
+import lombok.Setter;
+
+@Getter
+@Setter
+public class OpenUpOnTrialDTO {
+	
+
+}

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

@@ -1,13 +1,22 @@
 package com.diagbot.facade;
 
+import java.util.Date;
 import java.util.List;
+import java.util.Map;
 
+import org.springframework.beans.factory.annotation.Autowired;
 import org.springframework.stereotype.Component;
 
 import com.diagbot.dto.GetConsoleOnTrialDTO;
 import com.diagbot.dto.GetConsoleOpenedDTO;
+import com.diagbot.dto.OpenUpOnTrialDTO;
+import com.diagbot.entity.OpenedProducts;
+import com.diagbot.entity.ProductService;
+import com.diagbot.entity.ServiceInfo;
 import com.diagbot.service.impl.OpenedProductsServiceImpl;
 import com.diagbot.util.UserUtils;
+import com.diagbot.vo.OpenUpOnTrialVO;
+import com.diagbot.vo.ProductServiceSaveVO;
 
 /**
  * @Description:已开通产品业务层
@@ -16,16 +25,57 @@ import com.diagbot.util.UserUtils;
  */
 @Component
 public class OpenedProductsFacade extends OpenedProductsServiceImpl {
-	
-	
+	@Autowired
+	private ServiceInfoFacade serviceInfoFacade;
+	@Autowired
+	private ProductServiceFacade productServiceFacade;
+
+    public List<OpenedProducts> getByAppkeyAndSecretFac(Map map) {
+        return this.getByAppkeyAndSecret(map);
+    }
+
+
     public List<GetConsoleOpenedDTO> getConsoleOpened(){
     	Long userId = Long.parseLong(UserUtils.getCurrentPrincipleID());
         return baseMapper.getConsoleOpened(userId);
     }
-	
+
     public List<GetConsoleOnTrialDTO> getConsoleOnTrial(){
     	Long userId = Long.parseLong(UserUtils.getCurrentPrincipleID());
         return baseMapper.getConsoleOnTrial(userId);
     }
-	
+    
+    public OpenUpOnTrialDTO openUpOnTrial(OpenUpOnTrialVO openUpOnTrialVO){
+    	Long userId = Long.parseLong(UserUtils.getCurrentPrincipleID());
+    	String userName = UserUtils.getCurrentPrinciple();
+    	Date now = new Date();
+    	ServiceInfo serviceInfo = new ServiceInfo();
+    	serviceInfo.setType(2);
+    	serviceInfo.setUserId(userId);
+    	serviceInfo.setDescription("用户试用产品-虚拟服务");
+    	serviceInfo.setName("虚拟服务");
+    	serviceInfo.setCreator(userName);
+    	serviceInfo.setGmtCreate(now);
+    	serviceInfo.setIsDeleted("N");
+    	serviceInfoFacade.save(serviceInfo);
+    	
+    	ProductService productService = new ProductService();
+    	productService.setServiceId(serviceInfo.getId());
+    	productService.setProductId(openUpOnTrialVO.getProductId());
+    	productService.setCreator(userName);
+    	productService.setGmtCreate(now);
+    	productService.setIsDeleted("N");
+    	productServiceFacade.save(productService);
+    	
+    	ProductServiceSaveVO productServiceSaveVO = new ProductServiceSaveVO();
+    	productServiceSaveVO.setProductId(openUpOnTrialVO.getProductId());
+    	productServiceSaveVO.setServiceId(serviceInfo.getId());
+    	productServiceSaveVO.setType(3);
+    	productServiceFacade.genProductService(productServiceSaveVO);
+    	
+    	OpenUpOnTrialDTO openUpOnTrialDTO = new OpenUpOnTrialDTO();
+    	
+    	return openUpOnTrialDTO;	
+    }
+
 }

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

@@ -1,16 +1,23 @@
 package com.diagbot.facade;
 
 import com.diagbot.dto.RespDTO;
+import com.diagbot.entity.OpenedProducts;
 import com.diagbot.entity.ProductService;
 import com.diagbot.entity.ServiceToken;
+import com.diagbot.enums.StatusEnum;
+import com.diagbot.enums.TokenTypeEnum;
 import com.diagbot.exception.CommonErrorCode;
 import com.diagbot.exception.CommonException;
 import com.diagbot.service.impl.ServiceTokenServiceImpl;
+import com.diagbot.util.ListUtil;
 import com.diagbot.vo.ServiceTokenVo;
 import org.springframework.beans.factory.annotation.Autowired;
 import org.springframework.stereotype.Component;
 
 import java.util.Date;
+import java.util.HashMap;
+import java.util.List;
+import java.util.Map;
 
 /**
  * @Description: 用户端token业务层
@@ -23,6 +30,8 @@ public class ServiceTokenFacade extends ServiceTokenServiceImpl {
 
     @Autowired
     ProductServiceFacade productServiceFacade;
+    @Autowired
+    OpenedProductsFacade openedProductsFacade;
 
     /**
      * @Description: 获取资源的url
@@ -32,20 +41,41 @@ public class ServiceTokenFacade extends ServiceTokenServiceImpl {
     public RespDTO<Boolean> hasPermission(ServiceTokenVo serviceTokenVo) {
         String appkey = serviceTokenVo.getAppkey();
         String secret = serviceTokenVo.getSecret();
-        ServiceToken st = this.getServiceToken(appkey, secret);
+        Map<String, Object> paramMap = new HashMap<>();
+        paramMap.put("appkey", appkey);
+        paramMap.put("secret", secret);
+        ServiceToken st = this.getServiceToken(paramMap);
         if(null == st) {
             throw new CommonException(CommonErrorCode.SERVER_IS_ERROR, "appkey或secret错误,appkey=【" + appkey + "】," + "secret=【" + secret + "】");
         }
-        ProductService ps = productServiceFacade.getById(st.getProductSeviceId());
-        if(ps == null) {
-            throw new CommonException(CommonErrorCode.SERVER_IS_ERROR, "无权限访问!");
-        }
-        if(!ps.getProductId().equals(serviceTokenVo.getProductId())) {
-            throw new CommonException(CommonErrorCode.SERVER_IS_ERROR, "无权限访问!");
-        }
-        Date date = new Date();
-        if(st.getExpiringDate().getTime() < date.getTime()) {
-            throw new CommonException(CommonErrorCode.SERVER_IS_ERROR, "访问权限已过期!");
+        if(TokenTypeEnum.Trial.getKey() == st.getType()) {
+            ProductService ps = productServiceFacade.getById(st.getProductSeviceId());
+            if (ps == null) {
+                throw new CommonException(CommonErrorCode.SERVER_IS_ERROR, "无权限访问!");
+            }
+            if (!ps.getProductId().equals(serviceTokenVo.getProductId())) {
+                throw new CommonException(CommonErrorCode.SERVER_IS_ERROR, "无权限访问!");
+            }
+            Date date = new Date();
+            if (st.getExpiringDate().getTime() < date.getTime()) {
+                throw new CommonException(CommonErrorCode.SERVER_IS_ERROR, "访问权限已过期!");
+            }
+        } else {
+            List<OpenedProducts> opList = openedProductsFacade.getByAppkeyAndSecret(paramMap);
+            if(ListUtil.isEmpty(opList)) {
+                throw new CommonException(CommonErrorCode.SERVER_IS_ERROR, "无权限访问!");
+            }
+            if(opList.size() != 1) {
+                throw new CommonException(CommonErrorCode.SERVER_IS_ERROR, "当前appkey和secret对应多条数据!");
+            }
+            OpenedProducts op = opList.get(0);// 正常只有一条数据
+            Date date = new Date();
+            if(!(StatusEnum.Enable.getKey() == op.getServiceStatus())) {
+                throw new CommonException(CommonErrorCode.SERVER_IS_ERROR, "当前服务已停用!");
+            }
+            if(op.getEndTime().getTime() < date.getTime()) {
+                throw new CommonException(CommonErrorCode.SERVER_IS_ERROR, "访问权限已过期!");
+            }
         }
         return RespDTO.onSuc(true);
     }

+ 11 - 2
diagbotman-service/src/main/java/com/diagbot/mapper/OpenedProductsMapper.java

@@ -34,14 +34,23 @@ public interface OpenedProductsMapper extends BaseMapper<OpenedProducts> {
      * @return
      */
     List<OpenedProducts> selectOpenedProducts(Map<String,Object>map);
-    
+
+
+    /**
+     * 查询已开通产品
+     * @param map 查询条件
+     * @return
+     */
+    List<OpenedProducts> getByAppkeyAndSecret(Map<String,Object> map);
+
+
     /**
      * 控制台已开通产品查询
      * @param userId
      * @return
      */
     List<GetConsoleOpenedDTO> getConsoleOpened(Long userId);
-    
+
     /**
      * 控制台已开通产品查询
      * @param userId

+ 9 - 0
diagbotman-service/src/main/java/com/diagbot/service/OpenedProductsService.java

@@ -30,4 +30,13 @@ public interface OpenedProductsService extends IService<OpenedProducts> {
      * @return
      */
     List<OpenedProducts> selectOpenedProducts(Map<String,Object> map);
+
+
+    /**
+     * @Description: 根据appkey和secret查询开通产品
+     * @Author: ztg
+     * @Date: 2018/9/20 15:23
+     */
+    List<OpenedProducts> getByAppkeyAndSecret(Map<String,Object> map);
+
 }

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

@@ -3,6 +3,8 @@ package com.diagbot.service;
 import com.baomidou.mybatisplus.extension.service.IService;
 import com.diagbot.entity.ServiceToken;
 
+import java.util.Map;
+
 /**
  * <p>
  * 服务令牌表 服务类
@@ -18,7 +20,7 @@ public interface ServiceTokenService extends IService<ServiceToken> {
      * @Author: ztg
      * @Date: 2018/9/18 16:38
      */
-    ServiceToken getServiceToken(String appkey, String secret);
+    ServiceToken getServiceToken(Map<String, Object> paramMap);
 
     ServiceToken getByProductServiceId(Long productServiceId);
 

+ 10 - 0
diagbotman-service/src/main/java/com/diagbot/service/impl/OpenedProductsServiceImpl.java

@@ -6,6 +6,7 @@ import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
 import com.diagbot.entity.OpenedProducts;
 import com.diagbot.mapper.OpenedProductsMapper;
 import com.diagbot.service.OpenedProductsService;
+import org.springframework.beans.factory.annotation.Autowired;
 import org.springframework.stereotype.Service;
 
 import java.util.List;
@@ -21,6 +22,10 @@ import java.util.Map;
  */
 @Service
 public class OpenedProductsServiceImpl extends ServiceImpl<OpenedProductsMapper, OpenedProducts> implements OpenedProductsService {
+
+    @Autowired
+    OpenedProductsMapper openedProductsMapper;
+
     @Override
     public IPage<OpenedProducts> selectOpendInfoByUserId(Page<OpenedProducts> page, int userId) {
         return baseMapper.selectOpendInfoByUserId(page,userId);
@@ -34,4 +39,9 @@ public class OpenedProductsServiceImpl extends ServiceImpl<OpenedProductsMapper,
     public List<OpenedProducts> selectOpenedProducts(Map<String,Object> map){
         return baseMapper.selectOpenedProducts(map);
     }
+
+    @Override
+    public List<OpenedProducts> getByAppkeyAndSecret(Map<String, Object> map) {
+        return openedProductsMapper.getByAppkeyAndSecret(map);
+    }
 }

+ 1 - 7
diagbotman-service/src/main/java/com/diagbot/service/impl/ServiceTokenServiceImpl.java

@@ -2,14 +2,11 @@ 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;
 import org.springframework.stereotype.Service;
 
-import java.util.HashMap;
 import java.util.Map;
 
 /**
@@ -27,10 +24,7 @@ public class ServiceTokenServiceImpl extends ServiceImpl<ServiceTokenMapper, Ser
     ServiceTokenMapper serviceTokenMapper;
 
     @Override
-    public ServiceToken getServiceToken(String appkey, String secret) {
-        Map<String, Object> paramMap = new HashMap<>();
-        paramMap.put("appkey", appkey);
-        paramMap.put("secret", secret);
+    public ServiceToken getServiceToken(Map<String, Object> paramMap) {
         return serviceTokenMapper.getServiceToken(paramMap);
     }
 

+ 15 - 0
diagbotman-service/src/main/java/com/diagbot/vo/OpenUpOnTrialVO.java

@@ -0,0 +1,15 @@
+package com.diagbot.vo;
+
+import javax.validation.constraints.NotNull;
+
+import lombok.Getter;
+import lombok.Setter;
+
+@Getter
+@Setter
+public class OpenUpOnTrialVO {
+	
+	@NotNull(message="产品id不能为空")
+	private Long productId;
+
+}

+ 9 - 0
diagbotman-service/src/main/java/com/diagbot/web/ProductOrderController.java

@@ -10,10 +10,12 @@ import org.springframework.web.bind.annotation.RestController;
 import com.diagbot.annotation.SysLogger;
 import com.diagbot.dto.GetConsoleOnTrialDTO;
 import com.diagbot.dto.GetConsoleOpenedDTO;
+import com.diagbot.dto.OpenUpOnTrialDTO;
 import com.diagbot.dto.ProductAuthProgressDTO;
 import com.diagbot.dto.RespDTO;
 import com.diagbot.facade.OpenedProductsFacade;
 import com.diagbot.facade.ProductOrderFacade;
+import com.diagbot.vo.OpenUpOnTrialVO;
 
 import io.swagger.annotations.Api;
 import io.swagger.annotations.ApiOperation;
@@ -53,5 +55,12 @@ public class ProductOrderController {
 	public RespDTO<List<GetConsoleOnTrialDTO>> getConsoleOnTrial() {
 		return RespDTO.onSuc(openedProductsFacade.getConsoleOnTrial());
 	}
+	
+	@ApiOperation(value = "控制台-产品立即试用接口",notes="控制台-产品立即试用接口")
+	@PostMapping("/openUpOnTrial")
+	@SysLogger("openUpOnTrial")
+	public RespDTO<OpenUpOnTrialDTO> openUpOnTrial(OpenUpOnTrialVO openUpOnTrialVO) {
+		return RespDTO.onSuc(openedProductsFacade.openUpOnTrial(openUpOnTrialVO));
+	}
 
 }

+ 33 - 4
diagbotman-service/src/main/resources/mapper/OpenedProductsMapper.xml

@@ -23,7 +23,7 @@
         SELECT opend.* FROM diag_opened_products opend WHERE user_id = #{userId}
     </select>
 
-    <select id="selectOpenedProducts" resultMap="BaseResultMap" parameterMap="java.util.Map">
+    <select id="selectOpenedProducts" resultMap="BaseResultMap" parameterType="java.util.Map">
         SELECT t.* FROM diag_opened_products t WHERE t.is_deleted='N'
         <if test="userId != null and userId != ''">
         and t.user_id = #{userId}
@@ -32,7 +32,15 @@
         and t.product_id=#{productId}
         </if>
     </select>
-    
+
+
+    <select id="getByAppkeyAndSecret" resultMap="BaseResultMap" parameterType="java.util.Map">
+        select os.* from diag_service_token st, diag_product_service ps, diag_service_info si, diag_opened_products os
+        where st.product_sevice_id = ps.id and ps.product_id = os.product_id and ps.service_id = si.id and si.user_id = os.user_id
+        and st.is_deleted = 'N' and ps.is_deleted = 'N' and si.is_deleted = 'N' AND os.is_deleted = 'N'
+        and st.app_key_id = #{appkey} and st.app_key_secret = #{secret}
+    </select>
+
  	<select id="getConsoleOpened" parameterType="long" resultType="com.diagbot.dto.GetConsoleOpenedDTO">
     	SELECT
 			a.id as openId,
@@ -44,6 +52,27 @@
 		from diag_opened_products a join diag_lantone_product b on a.product_id=b.id
 		where a.is_deleted='N' and b.is_deleted='N' and a.user_id=#{userId};
     </select>
-    
-    
+
+
+
+    <select id="getConsoleOnTrial" parameterType="long" resultType="com.diagbot.dto.GetConsoleOnTrialDTO">
+    	SELECT
+			a.id as id,
+			a.name as name,
+			a.access_type as accessType,
+			case when d.id is null then 'N' else 'Y' end as isUsed,
+			a.trial_url as trialUrl,
+			DATE_FORMAT(d.starting_date,'%Y-%m-%d') as startingDate,
+			DATE_FORMAT(d.expiring_date,'%Y-%m-%d') as expiringDate
+		FROM diag_lantone_product a LEFT JOIN diag_product_service b on a.id=b.product_id
+		JOIN diag_service_info c on b.service_id=c.id
+		JOIN diag_service_token d on b.id=d.product_sevice_id
+		where a.is_deleted='N' and b.is_deleted='N' and c.is_deleted='N' and d.is_deleted='N'
+		and a.trial_status=1
+		and c.type=2
+		and c.user_id=#{userId}
+		and a.id not in (SELECT product_id FROM diag_opened_products where user_id=#{userId})
+    </select>
+
+
 </mapper>

+ 19 - 15
user-service/src/main/java/com/diagbot/facade/UserFacade.java

@@ -1,19 +1,5 @@
 package com.diagbot.facade;
 
-import java.io.Serializable;
-import java.util.Date;
-import java.util.HashMap;
-import java.util.List;
-import java.util.Map;
-
-import org.springframework.beans.factory.annotation.Autowired;
-import org.springframework.cache.annotation.CacheEvict;
-import org.springframework.cache.annotation.CachePut;
-import org.springframework.cache.annotation.Cacheable;
-import org.springframework.security.crypto.factory.PasswordEncoderFactories;
-import org.springframework.security.crypto.password.PasswordEncoder;
-import org.springframework.stereotype.Component;
-
 import com.baomidou.mybatisplus.core.metadata.IPage;
 import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
 import com.diagbot.client.AuthServiceClient;
@@ -35,10 +21,24 @@ import com.diagbot.service.impl.UserServiceImpl;
 import com.diagbot.util.BeanUtil;
 import com.diagbot.util.EntityUtil;
 import com.diagbot.util.ListUtil;
+import com.diagbot.util.RegexValidateUtil;
 import com.diagbot.util.StringUtil;
 import com.diagbot.util.UserUtils;
 import com.diagbot.vo.ImgVerVerVO;
 import com.diagbot.vo.UserSaveVO;
+import org.springframework.beans.factory.annotation.Autowired;
+import org.springframework.cache.annotation.CacheEvict;
+import org.springframework.cache.annotation.CachePut;
+import org.springframework.cache.annotation.Cacheable;
+import org.springframework.security.crypto.factory.PasswordEncoderFactories;
+import org.springframework.security.crypto.password.PasswordEncoder;
+import org.springframework.stereotype.Component;
+
+import java.io.Serializable;
+import java.util.Date;
+import java.util.HashMap;
+import java.util.List;
+import java.util.Map;
 
 /**
  * @Description: 用户业务层
@@ -78,13 +78,17 @@ public class UserFacade extends UserServiceImpl {
         if(bean != null) {
             throw new CommonException(ServiceErrorCode.USER_EXIST);
         }
+        if(!RegexValidateUtil.checkMobileNumber(userSaveVO.getUsername())) {
+            throw new CommonException(CommonErrorCode.SERVER_IS_ERROR, "请输入正确的手机号!");
+        }
+
         //TODO 测试注释了图形验证和短信验证,后面要开启
 //        verFacade.verifyImgVerification(imgVerVerVO); //保存时再次校验图形验证码,主要是为了防止跳过前端校验直接调用接口
 
         PasswordEncoder passwordEncoder = PasswordEncoderFactories.createDelegatingPasswordEncoder();
         String entryPassword= passwordEncoder.encode(user.getPassword());
         user.setPassword(entryPassword);
-//        this.save(user);
+        this.save(user);
 
         // 机构相关业务
         doOrganization(userSaveVO, user);

+ 13 - 15
user-service/src/main/java/com/diagbot/web/UserController.java

@@ -1,19 +1,5 @@
 package com.diagbot.web;
 
-import java.util.List;
-import java.util.Map;
-
-import javax.validation.Valid;
-
-import org.springframework.beans.factory.annotation.Autowired;
-import org.springframework.transaction.annotation.Transactional;
-import org.springframework.web.bind.annotation.GetMapping;
-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 com.baomidou.mybatisplus.core.metadata.IPage;
 import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
 import com.diagbot.annotation.SysLogger;
@@ -26,11 +12,22 @@ import com.diagbot.entity.User;
 import com.diagbot.facade.PermissionFacade;
 import com.diagbot.facade.UserFacade;
 import com.diagbot.vo.UserSaveVO;
-
 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.GetMapping;
+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;
+import java.util.List;
+import java.util.Map;
+
 /**
  * @Description: 用户操作API
  * @author: gaodm
@@ -93,6 +90,7 @@ public class UserController {
     @PostMapping(value = "/getUserAndOrg")
     @SysLogger("getUserAndOrg")
     @ApiOperation(value = "获取用户和机构信息")
+    @ApiIgnore
     RespDTO<Map<Long,UserOrgDTO>> getUserAndOrg(@RequestBody List<Long> userIds) {
         Map<Long, UserOrgDTO> result = userFacade.getUserAndOrg(userIds);
         return RespDTO.onSuc(result);