Authored by linlong

update

... ... @@ -6,6 +6,8 @@ import com.yoho.service.model.union.response.PageBlackListRspBO;
import com.yoho.service.model.union.response.PageChannelGroupRspBO;
import com.yoho.unions.channel.service.IChannelBlackListService;
import com.yoho.unions.common.ApiResponse;
import com.yoho.unions.common.utils.PhoneUtil;
import org.apache.commons.lang3.StringUtils;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.beans.factory.annotation.Autowired;
... ... @@ -44,6 +46,9 @@ public class ChannelBlackListRest {
@ResponseBody
public ApiResponse addBlack(@RequestBody ChannelBlackListRequestBO channelBlackListRequestBO) {
logger.info("enter addBlack. param channelBlackListRequestBO={}", channelBlackListRequestBO);
if(!PhoneUtil.areaMobileVerify("",channelBlackListRequestBO.getMobile())){
return new ApiResponse.ApiResponseBuilder().code(500).message("手机号格式不对!").build();
}
int count = channelBlackListService.addBlack(channelBlackListRequestBO);
if (count>0){
return new ApiResponse.ApiResponseBuilder().code(200).message("成功").build();
... ...
... ... @@ -42,10 +42,17 @@ public class ChannelBlackListServiceImpl implements IChannelBlackListService{
@Override
public int addBlack(ChannelBlackListRequestBO channelBlackListRequestBO) {
logger.info("enter addBlack. param channelBlackListRequestBO={}", channelBlackListRequestBO);
ChannelSmsBlack smsBlack = new ChannelSmsBlack();
smsBlack.setMobile(channelBlackListRequestBO.getMobile());
smsBlack.setCreateTime(DateUtils.getCurrentTimeSecond());
int count = channelSmsBlackDAO.insertSelective(smsBlack);
int count = 0;
ChannelSmsBlack smsBlack = channelSmsBlackDAO.selectByMobile(channelBlackListRequestBO.getMobile());
if(smsBlack==null){
smsBlack = new ChannelSmsBlack();
smsBlack.setCreateTime(DateUtils.getCurrentTimeSecond());
smsBlack.setMobile(channelBlackListRequestBO.getMobile());
count = channelSmsBlackDAO.insertSelective(smsBlack);
}else{
smsBlack.setCreateTime(DateUtils.getCurrentTimeSecond());
count = channelSmsBlackDAO.updateByPrimaryKeySelective(smsBlack);
}
return count;
}
... ...
package com.yoho.unions.common.utils;
import org.apache.commons.lang.StringUtils;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import java.util.HashMap;
import java.util.Map;
import java.util.regex.Matcher;
import java.util.regex.Pattern;
/**
* Created by yoho on 2016/11/23.
*/
public class PhoneUtil {
private static Map<String, String> areaPatternMap = new HashMap<String, String>();
private static Logger logger = LoggerFactory.getLogger(PhoneUtil.class);
private final static String CHINA_AREA_CODE = "86";
static{
//------区域码,以及区域码对应的号码的校验正则表达式
//中国
areaPatternMap.put("86", "^[1|9][3|4|5|8|7|9][0-9]{9}$");
//中国香港
areaPatternMap.put("852", "^[9|6|5][0-9]{7}$");
//中国澳门
areaPatternMap.put("853", "^[0-9]{8}$");
//中国台湾
areaPatternMap.put("886", "^[0-9]{10}$");
//新加坡
areaPatternMap.put("65", "^[9|8][0-9]{7}$");
//马来西亚
areaPatternMap.put("60", "^1[1|2|3|4|6|7|9][0-9]{7}$");
//加拿大&美国
areaPatternMap.put("1", "^[0-9]{10}$");
//韩国
areaPatternMap.put("82", "^01[0-9]{9}$");
//英国
areaPatternMap.put("44", "^7[7|8|9][0-9]{8}$");
//日本
areaPatternMap.put("81", "^0[9|8|7][0-9]{9}$");
//澳大利亚
areaPatternMap.put("61", "^[0-9]{11}$");
}
/**
* 根据区域码,对手机号码进行处理,如果不是中国手机号码,在号码之前加区域码
*
* @param area 区域码
* @param mobile 手机号码
* @return String 处理之后的手机号码
*/
public static String makePhone(String area, String mobile){
if(null == mobile || mobile.isEmpty()){
logger.info("makePhone: mobile is null. area is {}, mobile is {}", area, mobile);
return null;
}
if(null == area || area.isEmpty() || CHINA_AREA_CODE.equals(area)){
logger.debug("makePhone: mobile is {}, area is {}", mobile, area);
return mobile;
}
logger.debug("makePhone: mobile is {}, area is {}", mobile, area);
return area + "-" + mobile;
}
/**
* 根据区域码,校验各个国家和地区的号码格式是否正确
*
* @param area
* @param mobile
* @return
*/
public static boolean areaMobileVerify(String area, String mobile){
String[] arr = mobile.split("-");
if(StringUtils.isEmpty(area) && arr.length == 1) {
area = "86";
} else if (arr.length == 2) {
area = arr[0];
mobile = arr[1];
}
if (!"86".equals(area)) {
return mobile.matches("\\d+");
}
//根据国家或者地区码返回匹配模式
String reg = areaPatternMap.get(area);
if(null == reg){
return false;
}
Pattern p = Pattern.compile(reg);
Matcher m = p.matcher(mobile);
boolean ret = m.matches();
return ret;
}
}
... ...
... ... @@ -16,6 +16,8 @@ public interface IChannelSmsBlackDAO {
ChannelSmsBlack selectByPrimaryKey(Integer id);
ChannelSmsBlack selectByMobile(String mobile);
int updateByPrimaryKeySelective(ChannelSmsBlack record);
int updateByPrimaryKey(ChannelSmsBlack record);
... ...
... ... @@ -15,6 +15,12 @@
from channel_sms_black
where id = #{id,jdbcType=INTEGER}
</select>
<select id="selectByMobile" resultMap="BaseResultMap" parameterType="java.lang.String" >
select
<include refid="Base_Column_List" />
from channel_sms_black
where mobile= #{mobile,jdbcType=VARCHAR}
</select>
<select id="selectAll" resultType="java.lang.String">
select mobile
from channel_sms_black
... ...