...
|
...
|
@@ -12,15 +12,13 @@ import javax.annotation.Resource; |
|
|
|
|
|
import org.apache.commons.collections.CollectionUtils;
|
|
|
import org.apache.commons.lang3.StringUtils;
|
|
|
import org.slf4j.Logger;
|
|
|
import org.slf4j.LoggerFactory;
|
|
|
import org.springframework.beans.factory.annotation.Autowired;
|
|
|
import org.springframework.stereotype.Service;
|
|
|
|
|
|
import com.yoho.core.config.ConfigReader;
|
|
|
import com.yoho.yhmessage.sms.filter.IFilterByCountService;
|
|
|
import com.yoho.yhmessage.filter.IFilterByCountService;
|
|
|
import com.yoho.yhmessage.filter.IObjectKeyTransfer;
|
|
|
import com.yoho.yhmessage.sms.filter.IFilterUserService;
|
|
|
import com.yoho.yhmessage.sms.filter.IObjectKeyTransfer;
|
|
|
import com.yoho.yhmessage.sms.util.CommonUtils;
|
|
|
|
|
|
/**
|
...
|
...
|
@@ -32,9 +30,8 @@ import com.yoho.yhmessage.sms.util.CommonUtils; |
|
|
* @taskId <br>
|
|
|
* @CreateDate 2016年12月8日 <br>
|
|
|
*/
|
|
|
@Service("filterUserService")
|
|
|
@Service
|
|
|
public class FilterUserServiceImpl implements IFilterUserService {
|
|
|
private static final Logger log = LoggerFactory.getLogger(FilterUserServiceImpl.class);
|
|
|
|
|
|
private static final DateFormat df = new SimpleDateFormat("yyyyMMdd");
|
|
|
private static final String FREQUENT_USER_KEY_FORMAT = "msgcenter_sms_user_count_%s";
|
...
|
...
|
@@ -42,24 +39,8 @@ public class FilterUserServiceImpl implements IFilterUserService { |
|
|
|
|
|
@Resource(name = "core-config-reader")
|
|
|
private ConfigReader configReader;
|
|
|
|
|
|
@Autowired
|
|
|
private IFilterByCountService filterByCountService;
|
|
|
/**
|
|
|
*
|
|
|
* Description: 过滤场景<br>
|
|
|
*
|
|
|
* @author amos.shan<br>
|
|
|
* @taskId <br>
|
|
|
* @return <br>
|
|
|
*/
|
|
|
public List<String> getIgnoreMobileCountKeyList() {
|
|
|
String ignoreMobileCountKeyList = "";
|
|
|
if (StringUtils.isBlank(ignoreMobileCountKeyList)) {
|
|
|
return new ArrayList<String>();
|
|
|
}
|
|
|
return Arrays.asList(ignoreMobileCountKeyList.split(","));
|
|
|
}
|
|
|
|
|
|
private IObjectKeyTransfer<String> getMobileTransfer() {
|
|
|
return new IObjectKeyTransfer<String>() {
|
...
|
...
|
@@ -95,6 +76,27 @@ public class FilterUserServiceImpl implements IFilterUserService { |
|
|
|
|
|
/**
|
|
|
*
|
|
|
* Description: 过滤累计发送超过五次的用户<br>
|
|
|
*
|
|
|
* @author amos.shan<br>
|
|
|
* @taskId <br>
|
|
|
* @param mobileList
|
|
|
* @return <br>
|
|
|
*/
|
|
|
public List<String> ignoreFrequentUsers(List<String> mobileList) {
|
|
|
if (CollectionUtils.isEmpty(mobileList)) {
|
|
|
return mobileList;
|
|
|
}
|
|
|
String redisKey = String.format(FREQUENT_USER_KEY_FORMAT, df.format(new Date()));
|
|
|
int mobileSendLimit = this.getMobileSendLimit();
|
|
|
List<String> mobileWhiteList = this.getMobileWhiteList();
|
|
|
List<String> filtedResults = filterByCountService.batchFilter(redisKey, mobileList, mobileWhiteList, this.getMobileTransfer(), mobileSendLimit, 24 * 60 * 60,
|
|
|
TimeUnit.SECONDS);
|
|
|
return filtedResults;
|
|
|
}
|
|
|
|
|
|
/**
|
|
|
*
|
|
|
* Description: 过滤mobile白名单<br>
|
|
|
*
|
|
|
* @author amos.shan<br>
|
...
|
...
|
@@ -111,34 +113,29 @@ public class FilterUserServiceImpl implements IFilterUserService { |
|
|
|
|
|
/**
|
|
|
*
|
|
|
* Description: 过滤累计发送超过五次的用户<br>
|
|
|
* Description: 发送次数限制<br>
|
|
|
*
|
|
|
* @author amos.shan<br>
|
|
|
* @taskId <br>
|
|
|
* @param mobileList
|
|
|
* @return <br>
|
|
|
*/
|
|
|
public List<String> ignoreFrequentUsers(List<String> mobileList) {
|
|
|
if (CollectionUtils.isEmpty(mobileList)) {
|
|
|
return mobileList;
|
|
|
}
|
|
|
String redisKey = String.format(FREQUENT_USER_KEY_FORMAT, df.format(new Date()));
|
|
|
int mobileSendLimit = this.getMobileSendLimit();
|
|
|
List<String> mobileWhiteList = this.getMobileWhiteList();
|
|
|
List<String> filtedResults = filterByCountService.batchFilter(redisKey, mobileList, mobileWhiteList, this.getMobileTransfer(), mobileSendLimit, 24 * 60 * 60,
|
|
|
TimeUnit.SECONDS);
|
|
|
return filtedResults;
|
|
|
private int getMobileSendLimit() {
|
|
|
return configReader.getInt("msgcenter.sms.degrade.userSendLimit", 50);
|
|
|
}
|
|
|
|
|
|
|
|
|
/**
|
|
|
*
|
|
|
* Description: 发送次数限制<br>
|
|
|
* Description: 过滤场景<br>
|
|
|
*
|
|
|
* @author amos.shan<br>
|
|
|
* @taskId <br>
|
|
|
* @return <br>
|
|
|
*/
|
|
|
private int getMobileSendLimit() {
|
|
|
return configReader.getInt("msgcenter.sms.degrade.userSendLimit", 5);
|
|
|
public List<String> getIgnoreMobileCountKeyList() {
|
|
|
String ignoreMobileCountKeyList = "";
|
|
|
if (StringUtils.isBlank(ignoreMobileCountKeyList)) {
|
|
|
return new ArrayList<String>();
|
|
|
}
|
|
|
return Arrays.asList(ignoreMobileCountKeyList.split(","));
|
|
|
}
|
|
|
} |
...
|
...
|
|