|
@@ -1,15 +1,20 @@
|
|
package com.diagbot.facade;
|
|
package com.diagbot.facade;
|
|
|
|
|
|
|
|
+import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
|
|
|
|
+import com.baomidou.mybatisplus.core.conditions.update.UpdateWrapper;
|
|
import com.diagbot.dto.RespDTO;
|
|
import com.diagbot.dto.RespDTO;
|
|
import com.diagbot.entity.OpenedProducts;
|
|
import com.diagbot.entity.OpenedProducts;
|
|
import com.diagbot.entity.ProductService;
|
|
import com.diagbot.entity.ProductService;
|
|
|
|
+import com.diagbot.entity.ServiceInfo;
|
|
import com.diagbot.entity.ServiceToken;
|
|
import com.diagbot.entity.ServiceToken;
|
|
|
|
+import com.diagbot.enums.IsDeleteEnum;
|
|
import com.diagbot.enums.StatusEnum;
|
|
import com.diagbot.enums.StatusEnum;
|
|
import com.diagbot.enums.TokenTypeEnum;
|
|
import com.diagbot.enums.TokenTypeEnum;
|
|
import com.diagbot.exception.CommonErrorCode;
|
|
import com.diagbot.exception.CommonErrorCode;
|
|
import com.diagbot.exception.CommonException;
|
|
import com.diagbot.exception.CommonException;
|
|
import com.diagbot.service.impl.ServiceTokenServiceImpl;
|
|
import com.diagbot.service.impl.ServiceTokenServiceImpl;
|
|
import com.diagbot.util.ListUtil;
|
|
import com.diagbot.util.ListUtil;
|
|
|
|
+import com.diagbot.util.UserUtils;
|
|
import com.diagbot.vo.ServiceTokenVo;
|
|
import com.diagbot.vo.ServiceTokenVo;
|
|
import org.springframework.beans.factory.annotation.Autowired;
|
|
import org.springframework.beans.factory.annotation.Autowired;
|
|
import org.springframework.stereotype.Component;
|
|
import org.springframework.stereotype.Component;
|
|
@@ -32,10 +37,13 @@ public class ServiceTokenFacade extends ServiceTokenServiceImpl {
|
|
ProductServiceFacade productServiceFacade;
|
|
ProductServiceFacade productServiceFacade;
|
|
@Autowired
|
|
@Autowired
|
|
OpenedProductsFacade openedProductsFacade;
|
|
OpenedProductsFacade openedProductsFacade;
|
|
|
|
+ @Autowired
|
|
|
|
+ ServiceInfoFacade serviceInfoFacade;
|
|
|
|
|
|
|
|
|
|
/**
|
|
/**
|
|
* 获取资源的url
|
|
* 获取资源的url
|
|
|
|
+ *
|
|
* @param serviceTokenVo 参数
|
|
* @param serviceTokenVo 参数
|
|
* @return 是否有权限
|
|
* @return 是否有权限
|
|
*/
|
|
*/
|
|
@@ -45,11 +53,15 @@ public class ServiceTokenFacade extends ServiceTokenServiceImpl {
|
|
Map<String, Object> paramMap = new HashMap<>();
|
|
Map<String, Object> paramMap = new HashMap<>();
|
|
paramMap.put("appkey", appkey);
|
|
paramMap.put("appkey", appkey);
|
|
paramMap.put("secret", secret);
|
|
paramMap.put("secret", secret);
|
|
- ServiceToken st = this.getServiceToken(paramMap);
|
|
|
|
- if(null == st) {
|
|
|
|
|
|
+ //ServiceToken st = this.getServiceToken(paramMap);
|
|
|
|
+ QueryWrapper<ServiceToken> qw = new QueryWrapper<>();
|
|
|
|
+ qw.eq("app_key_id", appkey);
|
|
|
|
+ qw.eq("app_key_secret", secret);
|
|
|
|
+ ServiceToken st = this.selectOneRecord(qw);
|
|
|
|
+ if (null == st) {
|
|
throw new CommonException(CommonErrorCode.SERVER_IS_ERROR, "appkey或secret错误,appkey=【" + appkey + "】," + "secret=【" + secret + "】");
|
|
throw new CommonException(CommonErrorCode.SERVER_IS_ERROR, "appkey或secret错误,appkey=【" + appkey + "】," + "secret=【" + secret + "】");
|
|
}
|
|
}
|
|
- if(TokenTypeEnum.Trial.getKey() == st.getType()) {
|
|
|
|
|
|
+ if (TokenTypeEnum.Trial.getKey() == st.getType()) {
|
|
ProductService ps = productServiceFacade.getById(st.getProductServiceId());
|
|
ProductService ps = productServiceFacade.getById(st.getProductServiceId());
|
|
if (ps == null) {
|
|
if (ps == null) {
|
|
throw new CommonException(CommonErrorCode.SERVER_IS_ERROR, "无权限访问!");
|
|
throw new CommonException(CommonErrorCode.SERVER_IS_ERROR, "无权限访问!");
|
|
@@ -63,21 +75,101 @@ public class ServiceTokenFacade extends ServiceTokenServiceImpl {
|
|
}
|
|
}
|
|
} else {
|
|
} else {
|
|
List<OpenedProducts> opList = openedProductsFacade.getByAppkeyAndSecret(paramMap);
|
|
List<OpenedProducts> opList = openedProductsFacade.getByAppkeyAndSecret(paramMap);
|
|
- if(ListUtil.isEmpty(opList)) {
|
|
|
|
|
|
+ if (ListUtil.isEmpty(opList)) {
|
|
throw new CommonException(CommonErrorCode.SERVER_IS_ERROR, "无权限访问!");
|
|
throw new CommonException(CommonErrorCode.SERVER_IS_ERROR, "无权限访问!");
|
|
}
|
|
}
|
|
- if(opList.size() != 1) {
|
|
|
|
|
|
+ if (opList.size() != 1) {
|
|
throw new CommonException(CommonErrorCode.SERVER_IS_ERROR, "当前appkey和secret对应多条数据!");
|
|
throw new CommonException(CommonErrorCode.SERVER_IS_ERROR, "当前appkey和secret对应多条数据!");
|
|
}
|
|
}
|
|
OpenedProducts op = opList.get(0);// 正常只有一条数据
|
|
OpenedProducts op = opList.get(0);// 正常只有一条数据
|
|
Date date = new Date();
|
|
Date date = new Date();
|
|
- if(!(StatusEnum.Enable.getKey() == op.getServiceStatus())) {
|
|
|
|
|
|
+ if (!(StatusEnum.Enable.getKey() == op.getServiceStatus())) {
|
|
throw new CommonException(CommonErrorCode.SERVER_IS_ERROR, "当前服务已停用!");
|
|
throw new CommonException(CommonErrorCode.SERVER_IS_ERROR, "当前服务已停用!");
|
|
}
|
|
}
|
|
- if(op.getEndTime().getTime() < date.getTime()) {
|
|
|
|
|
|
+ if (op.getEndTime().getTime() < date.getTime()) {
|
|
throw new CommonException(CommonErrorCode.SERVER_IS_ERROR, "访问权限已过期!");
|
|
throw new CommonException(CommonErrorCode.SERVER_IS_ERROR, "访问权限已过期!");
|
|
}
|
|
}
|
|
}
|
|
}
|
|
return RespDTO.onSuc(true);
|
|
return RespDTO.onSuc(true);
|
|
}
|
|
}
|
|
-}
|
|
|
|
|
|
+
|
|
|
|
+ /**
|
|
|
|
+ * 根据产品服务关联id获取令牌
|
|
|
|
+ *
|
|
|
|
+ * @param productServiceId
|
|
|
|
+ * @return
|
|
|
|
+ */
|
|
|
|
+ public ServiceToken getByProductServiceId(Long productServiceId) {
|
|
|
|
+ QueryWrapper<ServiceToken> qw = new QueryWrapper<>();
|
|
|
|
+ qw.eq("product_sevice_id", productServiceId);
|
|
|
|
+ return this.selectOneRecord(qw);
|
|
|
|
+ }
|
|
|
|
+
|
|
|
|
+ /**
|
|
|
|
+ * 根据产品服务关联id删除令牌
|
|
|
|
+ *
|
|
|
|
+ * @param productServiceId
|
|
|
|
+ * @return
|
|
|
|
+ */
|
|
|
|
+ public Integer deleteByProductServiceId(Long productServiceId) {
|
|
|
|
+ checkCurrentUser(productServiceId);
|
|
|
|
+ UpdateWrapper<ServiceToken> uw = new UpdateWrapper<>();
|
|
|
|
+ uw.eq("product_sevice_id", productServiceId);
|
|
|
|
+ ServiceToken serviceToken = new ServiceToken();
|
|
|
|
+ serviceToken.setIsDeleted(IsDeleteEnum.Y.getKey());
|
|
|
|
+ return this.updateRecord(serviceToken, uw);
|
|
|
|
+ }
|
|
|
|
+
|
|
|
|
+ /**
|
|
|
|
+ * 启用令牌
|
|
|
|
+ *
|
|
|
|
+ * @param productServiceId
|
|
|
|
+ * @return
|
|
|
|
+ */
|
|
|
|
+ public Integer enableToken(Long productServiceId) {
|
|
|
|
+ checkCurrentUser(productServiceId);
|
|
|
|
+ UpdateWrapper<ServiceToken> uw = new UpdateWrapper<>();
|
|
|
|
+ uw.eq("product_sevice_id", productServiceId);
|
|
|
|
+ uw.eq("type", TokenTypeEnum.Manual.getKey());
|
|
|
|
+ ServiceToken serviceToken = new ServiceToken();
|
|
|
|
+ serviceToken.setStatus(StatusEnum.Enable.getKey());
|
|
|
|
+ return this.updateRecord(serviceToken, uw);
|
|
|
|
+ }
|
|
|
|
+
|
|
|
|
+ /**
|
|
|
|
+ * 禁用令牌
|
|
|
|
+ *
|
|
|
|
+ * @param productServiceId
|
|
|
|
+ * @return
|
|
|
|
+ */
|
|
|
|
+ public Integer disableToken(Long productServiceId) {
|
|
|
|
+ checkCurrentUser(productServiceId);
|
|
|
|
+ UpdateWrapper<ServiceToken> uw = new UpdateWrapper<>();
|
|
|
|
+ uw.eq("product_sevice_id", productServiceId);
|
|
|
|
+ uw.eq("type", TokenTypeEnum.Manual.getKey());
|
|
|
|
+ ServiceToken serviceToken = new ServiceToken();
|
|
|
|
+ serviceToken.setStatus(StatusEnum.Disable.getKey());
|
|
|
|
+ return this.updateRecord(serviceToken, uw);
|
|
|
|
+ }
|
|
|
|
+
|
|
|
|
+ /**
|
|
|
|
+ * 校验令牌所属用户是否当前登录用户
|
|
|
|
+ *
|
|
|
|
+ * @param productServiceId
|
|
|
|
+ * @return
|
|
|
|
+ */
|
|
|
|
+ public Boolean checkCurrentUser(Long productServiceId) {
|
|
|
|
+ Long userId = Long.parseLong(UserUtils.getCurrentPrincipleID());
|
|
|
|
+ ProductService productService = productServiceFacade.getById(productServiceId);
|
|
|
|
+ if (productService == null) {
|
|
|
|
+ throw new CommonException(CommonErrorCode.NOT_EXISTS, "产品服务端关联不存在");
|
|
|
|
+ }
|
|
|
|
+ ServiceInfo serviceInfo = serviceInfoFacade.getById(productService.getServiceId());
|
|
|
|
+ if (serviceInfo == null) {
|
|
|
|
+ throw new CommonException(CommonErrorCode.NOT_EXISTS, "服务端不存在");
|
|
|
|
+ } else if (serviceInfo.getUserId() != userId) {
|
|
|
|
+ throw new CommonException(CommonErrorCode.NOT_EXISTS, "登录用户与令牌所属用户不一致");
|
|
|
|
+ }
|
|
|
|
+ return true;
|
|
|
|
+ }
|
|
|
|
+}
|