Commit cf9ae6b7 by 徐高华

Merge branch 'master_xgh_pendingid' into 'developer'

Master xgh pendingid

See merge request !283
parents 6b320e7d 1ec97747
package com.gic.haoban.manage.api.service;
import java.util.List;
import java.util.Map;
import com.gic.api.base.commons.ServiceResponse;
import com.gic.haoban.manage.api.dto.QwPendingIdDTO;
......@@ -17,6 +18,20 @@ public interface QwFriendApiService {
/**
*
* @Title: pendingCheck
* @Description: 校验商户能否获取pending
* @author xugh
* @param enterpriseId
* @param unionid
* @param openid
* @param wxaOpenid
* @return
* @throws
*/
public ServiceResponse<Map<String,String>> pendingIdCheck(String enterpriseId, String unionid, String openid, String wxaOpenid);
/**
*
* @Title: getPendingIdByUnionid
* @Description: 通过uniond获取好友id/pendingid
* @author xugh
......
......@@ -2,7 +2,9 @@ package com.gic.haoban.manage.service.service.out.impl;
import java.util.ArrayList;
import java.util.Arrays;
import java.util.HashMap;
import java.util.List;
import java.util.Map;
import org.apache.commons.collections.CollectionUtils;
import org.apache.logging.log4j.LogManager;
......@@ -44,24 +46,63 @@ public class QwFriendApiServiceImpl implements QwFriendApiService {
private Config config;
@Override
public ServiceResponse<QwPendingIdDTO> getPendingIdByUnionid(String enterpriseId, String unionid, String openid) {
public ServiceResponse<Map<String, String>> pendingIdCheck(String enterpriseId, String unionid, String openid,
String wxaOpenid) {
ServiceResponse<WxEnterpriseQwDTO> corpidResp = this.checkAndGetCorpid(enterpriseId);
if (!corpidResp.isSuccess()) {
return ServiceResponse.failure(corpidResp.getCode(), corpidResp.getMessage());
}
String suiteid = config.getWxSuiteid();
WxEnterpriseQwDTO qwDTO = corpidResp.getResult();
String corpid = qwDTO.getThirdCorpid();
ServiceResponse<PendingIdDTO> wxResp = this.qywxExternalUserService.unionidToExternalUserid(corpid, suiteid,
unionid, openid, 0);
Map<String, String> retMap = new HashMap<>();
StringBuilder sb = new StringBuilder();
String result = "";
String wxCode = "0";
String wxaCode = "0";
if (wxResp.isSuccess()) {
result = "ok";
} else {
result = wxResp.getCode();
wxCode = result;
}
retMap.put("wxCode", wxCode);
sb.append("服务号-").append(result).append(",");
ServiceResponse<PendingIdDTO> wxaResp = this.qywxExternalUserService.unionidToExternalUserid(corpid, suiteid,
unionid, wxaOpenid, 0);
if (wxaResp.isSuccess()) {
result = "ok";
} else {
result = wxResp.getCode();
wxaCode = result;
}
sb.append("小程序-").append(result);
retMap.put("remark", sb.toString());
retMap.put("wxaCode", wxaCode);
return ServiceResponse.success(retMap);
}
@Override
public ServiceResponse<QwPendingIdDTO> getPendingIdByUnionid(String enterpriseId, String unionid, String openid) {
ServiceResponse<WxEnterpriseQwDTO> corpidResp = this.checkAndGetCorpid(enterpriseId);
if (!corpidResp.isSuccess()) {
return ServiceResponse.failure(corpidResp.getCode(), corpidResp.getMessage());
}
String suiteid = config.getWxSuiteid();
WxEnterpriseQwDTO qwDTO = corpidResp.getResult();
String wxEnterpriseId = qwDTO.getWxEnterpriseId();
boolean isLimit = QwTimesUtils.isLimit(wxEnterpriseId, enterpriseId,QwInterfaceLimitEnum.GET_PENDING_ID);
boolean isLimit = QwTimesUtils.isLimit(wxEnterpriseId, enterpriseId, QwInterfaceLimitEnum.GET_PENDING_ID);
if (isLimit) {
return ServiceResponse.failure(HaoBanErrCode.ERR_2000.getCode(), HaoBanErrCode.ERR_2000.getMsg());
}
String corpid = qwDTO.getThirdCorpid();
ServiceResponse<PendingIdDTO> qwResp = this.qywxExternalUserService.unionidToExternalUserid(corpid, suiteid,
unionid, openid, 1);
unionid, openid, 0);
QwTimesUtils.addTimes(wxEnterpriseId, QwInterfaceLimitEnum.GET_PENDING_ID);
log.info("获取pendingid,参数={},返回={}", unionid, JSON.toJSONString(qwResp));
log.info("获取pendingid,参数={},{},返回={}", unionid, openid, JSON.toJSONString(qwResp));
if (!qwResp.isSuccess()) {
return ServiceResponse.failure(qwResp.getCode(), qwResp.getMessage());
}
......
......@@ -39,29 +39,29 @@ public class QwTimesUtils {
QwTimesUtils.enterpriseService = enterpriseService;
}
public static boolean isLimit(String wxEnterpriseId, String enterpriseId, QwInterfaceLimitEnum obj) {
QwLimitTimesBO setTimeBO = getSettingTimes(wxEnterpriseId, obj);
public static boolean isLimit(String wxEnterpriseId, String enterpriseId, QwInterfaceLimitEnum qwInterface) {
QwLimitTimesBO setTimeBO = getSettingTimes(wxEnterpriseId, qwInterface);
logger.info("获取配置次数={},wxEnterpriseId={}", JSON.toJSONString(setTimeBO), wxEnterpriseId);
// 先判断月
String interfaceName = obj.getName();
String interfaceName = qwInterface.getName();
Date now = new Date();
String dateStr = getDateStr(now);
String keyMonth = getCacheKey(wxEnterpriseId, interfaceName, dateStr.substring(0, 6));
boolean monthResult = timesCheck(1, keyMonth, obj, wxEnterpriseId, enterpriseId, now, setTimeBO);
boolean monthResult = timesCheck(1, keyMonth, qwInterface, wxEnterpriseId, enterpriseId, now, setTimeBO);
if (monthResult) {
logger.info("月达到限制={}", keyMonth);
return true;
}
// 天
String keyDay = getCacheKey(wxEnterpriseId, interfaceName, dateStr.substring(0, 8));
boolean dayResult = timesCheck(2, keyDay, obj, wxEnterpriseId, enterpriseId, now, setTimeBO);
boolean dayResult = timesCheck(2, keyDay, qwInterface, wxEnterpriseId, enterpriseId, now, setTimeBO);
if (dayResult) {
logger.info("天达到限制={}", keyDay);
return true;
}
// 小时
String keyHour = getCacheKey(wxEnterpriseId, interfaceName, dateStr.substring(0, 10));
boolean hourResult = timesCheck(3, keyHour, obj, wxEnterpriseId, enterpriseId, now, setTimeBO);
boolean hourResult = timesCheck(3, keyHour, qwInterface, wxEnterpriseId, enterpriseId, now, setTimeBO);
if (hourResult) {
logger.info("小时达到限制={}", keyHour);
return true;
......@@ -69,11 +69,11 @@ public class QwTimesUtils {
return false;
}
private static boolean timesCheck(int type, String cacheKey, QwInterfaceLimitEnum obj, String wxEnterpriseId,
String enterpriseId, Date now, QwLimitTimesBO setTimeBO) {
private static boolean timesCheck(int type, String cacheKey, QwInterfaceLimitEnum qwInterface,
String wxEnterpriseId, String enterpriseId, Date now, QwLimitTimesBO setTimeBO) {
Integer doneTimes = RedisUtil.getCache(cacheKey, Integer.class);
logger.info("获取已调次数={},cacheKey={}", doneTimes, cacheKey);
if (null == doneTimes) {
logger.info("type{}获取已调次数={},cacheKey={}", type, doneTimes == null ? 0 : doneTimes, cacheKey);
if (null == doneTimes || doneTimes == 0) {
return false;
}
int setTimes = 0;
......@@ -90,18 +90,18 @@ public class QwTimesUtils {
default:
break;
}
sendAlert(type, doneTimes, setTimes, obj, enterpriseId, now);
sendAlert(type, doneTimes, setTimes, qwInterface, enterpriseId, now);
if (doneTimes >= setTimes) {
return true;
}
return false;
}
private static QwLimitTimesBO getSettingTimes(String wxEnterpriseId, QwInterfaceLimitEnum obj) {
String key = String.format("%s_%s", obj.getName(), wxEnterpriseId);
private static QwLimitTimesBO getSettingTimes(String wxEnterpriseId, QwInterfaceLimitEnum qwInterface) {
String key = String.format("%s_%s", qwInterface.getName(), wxEnterpriseId);
QwLimitTimesBO times = getTimes(key);
if (null == times) {
return getTimes(obj.getName());
return getTimes(qwInterface.getName());
}
return times;
}
......@@ -112,16 +112,13 @@ public class QwTimesUtils {
ServiceResponse<Map<String, Object>> resp = customSettingApiService.getDetail("tab_gic_map",
searchParamMap.toJSONString());
if (resp.isSuccess() && null != resp.getResult()) {
QwLimitTimesBO times = new QwLimitTimesBO();
times = JSON.parseObject(resp.getResult().get("value").toString(), QwLimitTimesBO.class);
logger.info("获取默认配置次数={},{}", times, key);
return times;
return JSON.parseObject(resp.getResult().get("value").toString(), QwLimitTimesBO.class);
}
return null;
}
private static void sendAlert(int type, int doneTimes, int setTimes, QwInterfaceLimitEnum obj, String enterpriseId,
Date now) {
private static void sendAlert(int type, int doneTimes, int setTimes, QwInterfaceLimitEnum qwInterface,
String enterpriseId, Date now) {
// 调用次数达上线
String time = null;
String title = "已达上限";
......@@ -163,7 +160,7 @@ public class QwTimesUtils {
EnterpriseDTO enterpriseDTO = enterpriseService.getEnterpriseById(enterpriseId);
String brandName = enterpriseDTO.getBrandName();
// 达到上限时文案
String msg = String.format("告警【%s】%s调用在【%s】%s", brandName, obj.getRemark(), time, title);
String msg = String.format("告警【%s】%s调用在【%s】%s", brandName, qwInterface.getRemark(), time, title);
DingUtils.send(msg, false);
}
}
......
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