Commit 67f503bb by 徐高华

pendingid

parent fe67cf2a
......@@ -9,7 +9,10 @@ public enum HaoBanErrCode {
ERR_10012("10012","企业微信不存在"),
ERR_OTHER("9999","业务异常"),
ERR_100033("100033", "活码分组已经被关联,不可删除"),
ERR_2000("2000", "企微接口调用次数限制")
ERR_2000("2000", "企微接口调用次数限制-月"),
ERR_2001("2001", "企微接口调用次数限制-天"),
ERR_2002("2002", "企微接口调用次数限制-小时"),
ERR_2010("2010", "pending接口调用限制")
;
private String code;
......
......@@ -127,9 +127,9 @@ public class QwFriendApiServiceImpl implements QwFriendApiService {
WxEnterpriseQwDTO qwDTO = corpidResp.getResult();
String wxEnterpriseId = qwDTO.getWxEnterpriseId();
boolean isLimit = QwTimesUtils.isLimit(wxEnterpriseId, enterpriseId, QwInterfaceLimitEnum.GET_PENDING_ID);
if (isLimit) {
return ServiceResponse.failure(HaoBanErrCode.ERR_2000.getCode(), HaoBanErrCode.ERR_2000.getMsg());
HaoBanErrCode limitCode = QwTimesUtils.isLimit(wxEnterpriseId, enterpriseId, QwInterfaceLimitEnum.GET_PENDING_ID);
if (null != limitCode) {
return ServiceResponse.failure(limitCode.getCode(), limitCode.getMsg());
}
String corpid = qwDTO.getThirdCorpid();
ServiceResponse<PendingIdDTO> qwResp = this.qywxExternalUserService.unionidToExternalUserid(corpid, suiteid,
......@@ -209,28 +209,28 @@ public class QwFriendApiServiceImpl implements QwFriendApiService {
WxEnterpriseRelationBO enterpriseRelation = this.wxEnterpriseRelatedService.getHeadEnterprise(enterpriseId);
if (null == enterpriseRelation) {
// 非总部或不存在
return ServiceResponse.failure("2010", "请确认商户是否有效且是总部");
return ServiceResponse.failure(HaoBanErrCode.ERR_2010.getCode(), "请确认商户是否有效且是总部");
}
EnterpriseSettingDTO setting = this.enterpriseService.getEnterpriseSettingByEnterpriseId(enterpriseId) ;
String customSetting = setting.getCustomSetting() ;
if(StringUtils.isNotBlank(customSetting)) {
JSONObject json = JSON.parseObject(customSetting) ;
String qw = json.getString("qwPendingidFlag") ;
if(StringUtils.isNotBlank(qw) && "0".equals(qw)) {
String pendingidFlag = json.getString("qwPendingidFlag") ;
if(StringUtils.isBlank(pendingidFlag) || "0".equals(pendingidFlag)) {
log.info("未配置unionid查询企微外部联系人接口调用");
return ServiceResponse.failure("2010", "未配置unionid查询企微外部联系人接口调用");
return ServiceResponse.failure(HaoBanErrCode.ERR_2010.getCode(), "未配置unionid查询企微外部联系人接口调用");
}
}
Integer code = this.enterpriseUseForbidService.selectPermissionStatus(enterpriseId,
EnterpriseServiceEnum.HAO_BAN.getRightMenuCode());
log.info("好办是否到期停用={},{}", enterpriseId, code);
if (code != 0 && code != 1) {
return ServiceResponse.failure("2010", "商户已停用");
return ServiceResponse.failure(HaoBanErrCode.ERR_2010.getCode(), "商户已停用");
}
int memberOpenCardlag = enterpriseRelation.getMemberOpenCardFlag();
if (memberOpenCardlag != 0) {
// 不在同一开放平台
return ServiceResponse.failure("2010", "不在同一开放平台");
return ServiceResponse.failure(HaoBanErrCode.ERR_2010.getCode(), "不在同一开放平台");
}
String wxEnterpriseId = enterpriseRelation.getWxEnterpriseId();
WxEnterpriseQwDTO qwDTO = this.wxEnterpriseService.getQwInfo(wxEnterpriseId);
......
......@@ -19,6 +19,7 @@ import com.gic.enterprise.api.dto.EnterpriseDTO;
import com.gic.enterprise.api.service.EnterpriseService;
import com.gic.enterprise.service.CustomSettingApiService;
import com.gic.haoban.common.utils.DingUtils;
import com.gic.haoban.manage.service.errorcode.HaoBanErrCode;
import com.gic.haoban.manage.service.pojo.bo.QwLimitTimesBO;
import com.gic.redis.data.util.RedisUtil;
......@@ -60,7 +61,7 @@ public class QwTimesUtils {
return map ;
}
public static boolean isLimit(String wxEnterpriseId, String enterpriseId, QwInterfaceLimitEnum qwInterface) {
public static HaoBanErrCode isLimit(String wxEnterpriseId, String enterpriseId, QwInterfaceLimitEnum qwInterface) {
QwLimitTimesBO setTimeBO = getSettingTimes(wxEnterpriseId, qwInterface);
logger.info("获取配置次数={},wxEnterpriseId={},{}", JSON.toJSONString(setTimeBO), wxEnterpriseId,enterpriseId);
// 先判断月
......@@ -71,23 +72,23 @@ public class QwTimesUtils {
boolean monthResult = timesCheck(1, keyMonth, qwInterface, wxEnterpriseId, enterpriseId, now, setTimeBO);
if (monthResult) {
logger.info("月达到限制={},{}", keyMonth,enterpriseId);
return true;
return HaoBanErrCode.ERR_2000;
}
// 天
String keyDay = getCacheKey(wxEnterpriseId, interfaceName, dateStr.substring(0, 8));
boolean dayResult = timesCheck(2, keyDay, qwInterface, wxEnterpriseId, enterpriseId, now, setTimeBO);
if (dayResult) {
logger.info("天达到限制={},{}", keyDay,enterpriseId);
return true;
return HaoBanErrCode.ERR_2001;
}
// 小时
String keyHour = getCacheKey(wxEnterpriseId, interfaceName, dateStr.substring(0, 10));
boolean hourResult = timesCheck(3, keyHour, qwInterface, wxEnterpriseId, enterpriseId, now, setTimeBO);
if (hourResult) {
logger.info("小时达到限制={},{}", keyHour,enterpriseId);
return true;
return HaoBanErrCode.ERR_2002;
}
return false;
return null;
}
private static boolean timesCheck(int type, String cacheKey, QwInterfaceLimitEnum qwInterface,
......@@ -181,7 +182,11 @@ public class QwTimesUtils {
}
logger.info("告警key={},value={}",alertKey,RedisUtil.getCache(alertKey));
if (sendFlag && null == RedisUtil.getCache(alertKey)) {
RedisUtil.setCache(alertKey, 1 , 60*60*24L);
if(type==3) {
RedisUtil.setCache(alertKey, 1 , 60*59L);
}else {
RedisUtil.setCache(alertKey, 1 , 60*60*12L);
}
EnterpriseDTO enterpriseDTO = enterpriseService.getEnterpriseById(enterpriseId);
String brandName = enterpriseDTO.getBrandName();
// 达到上限时文案
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment