|
@@ -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);
|
|
|
}
|