Authored by mingdan.ge

cps三期

package com.yoho.unions.common.utils;
import org.apache.commons.lang.StringUtils;
import java.util.regex.Matcher;
import java.util.regex.Pattern;
/**
* Created by mingdan.ge on 2018/6/20.
*/
public class ChineseNameUtils {
public static boolean checkName(String name) {
if (StringUtils.isBlank(name)) {
return false;
}
String reg = "[\\u4e00-\\u9fa5]{2,4}";
Pattern pattern = Pattern.compile(reg);
Matcher matcher = pattern.matcher(name);
return matcher.matches();
}
}
... ...
package com.yoho.unions.common.utils;
/**
* Created by mingdan.ge on 2018/6/20.
*/
public class StringHideUtils {
/**
* 隐藏指定位数
* @param resourseStr 源字符串
* @param hideNum 最多隐藏位数
* @param reserveNum 保留尾部位数
* */
public static String hideString(String resourseStr,int hideNum,int reserveNum){
if (null == resourseStr || resourseStr.length() <= reserveNum) {
return resourseStr;
}
int startHideNo = resourseStr.length() - (hideNum + reserveNum);
StringBuilder sb = new StringBuilder(startHideNo>0?resourseStr.substring(0,startHideNo):"");
for (int i = startHideNo>0?startHideNo:0; i < resourseStr.length() - reserveNum; i++) {
sb.append("*");
}
sb.append(resourseStr.substring(resourseStr.length() - reserveNum));
return sb.toString();
}
/**
* 隐藏指定位数
* @param resourseStr 源字符串
* @param reserveNum 保留尾部位数
* */
public static String hideString(String resourseStr,int reserveNum){
if (null == resourseStr || resourseStr.length() <= reserveNum) {
return resourseStr;
}
StringBuilder sb = new StringBuilder();
for (int i = 0; i < resourseStr.length() - reserveNum; i++) {
sb.append("*");
}
sb.append(resourseStr.substring(resourseStr.length() - reserveNum));
return sb.toString();
}
/**
* 隐藏指定位数
* @param resourseStr 源字符串
* @param hideNum 隐藏位数
* */
public static String hideSubString(String resourseStr,int hideNum){
if (null == resourseStr) {
return resourseStr;
}
int reserveNum = resourseStr.length() - hideNum;
StringBuilder sb = new StringBuilder();
for (int i = 0; i < resourseStr.length() - (reserveNum>0?reserveNum:0); i++) {
sb.append("*");
}
if (reserveNum > 0) {
sb.append(resourseStr.substring(hideNum));
}
return sb.toString();
}
public static void main(String[] args) {
String name = "中国人";
String bankCardNo = "6013821200016974875";
System.out.println(StringHideUtils.hideString(name,1,1));
System.out.println(StringHideUtils.hideString("名字",1,1));
System.out.println(bankCardNo);
System.out.println(StringHideUtils.hideString(bankCardNo,3));
System.out.println(StringHideUtils.hideSubString(bankCardNo,11));
}
}
... ...
... ... @@ -91,6 +91,7 @@
<value>/UnionShareRest/bindBankCard</value>
<value>/UnionShareRest/getBankList</value>
<value>/UnionShareRest/getBankCard</value>
<value>/UnionShareRest/checkBankCard</value>
</list>
</property>
... ...
... ... @@ -117,6 +117,19 @@ public class UnionShareRest {
int result = unionShareService.bindBankCard(bo);
return new UnionResponse(200, "bindBankCard success",result>0?"Y":"N");
}
/**
* 校验银行卡信息
* @param bo
* @return
*/
@RequestMapping("/checkBankCard")
@ResponseBody
public UnionResponse checkBankCard(@RequestBody UnionShareUserBankBo bo){
log.info("UnionShareRest.checkBankCard req is {}", bo);
int result = unionShareService.checkAndBuildBankCard(bo);
return new UnionResponse(200, "checkBankCard success",result>0?"Y":"N");
}
/**
* 查询绑定的银行卡
* @param uid
... ...
... ... @@ -72,7 +72,14 @@ public interface IUnionShareService {
* @param bo
* @return
*/
int bindBankCard(UnionShareUserBankBo bo);
int bindBankCard(UnionShareUserBankBo bo);
/**
* 校验银行卡信息
* @param bo
* @return
*/
int checkAndBuildBankCard(UnionShareUserBankBo bo);
/**
* 用户前台获取个人推广近期订单(10个)
... ...
... ... @@ -18,10 +18,7 @@ import com.yoho.unions.common.enums.ShareOrdersStatusEnum;
import com.yoho.unions.common.redis.RedisHashCache;
import com.yoho.unions.common.redis.RedisValueCache;
import com.yoho.unions.common.service.IBusinessExportService;
import com.yoho.unions.common.utils.BankUtils;
import com.yoho.unions.common.utils.DateUtil;
import com.yoho.unions.common.utils.IDCardUtil;
import com.yoho.unions.common.utils.RandomUtil;
import com.yoho.unions.common.utils.*;
import com.yoho.unions.convert.BeanConvert;
import com.yoho.unions.convert.Convert;
import com.yoho.unions.dal.*;
... ... @@ -306,11 +303,19 @@ public class UnionShareServiceImpl implements IUnionShareService,IBusinessExport
*/
@Override
public int bindBankCard(UnionShareUserBankBo bo){
logger.info("bindBankCard,uid is {}",bo);
logger.info("bindBankCard,bo is {}",bo);
if (null == bo||bo.getUid()<0) {
return 0;
}
//信息格式校验
checkAndBuildBankCard(bo);
//查询该用户是否为特邀用户
int count = unionShareUserMapper.selectCountByUid(bo.getUid());
if (count == 0) {
//不是特邀用户
logger.info("bindBankCard end,can not find unionType,bo is {}",bo);
throw new ServiceException(ServiceError.USER_ID_ERROR);
}
UnionShareUserBank insertReq = new UnionShareUserBank();
BeanUtils.copyProperties(bo, insertReq);
insertReq.setStatus((byte)1);
... ... @@ -345,8 +350,8 @@ public class UnionShareServiceImpl implements IUnionShareService,IBusinessExport
return null;
}
UnionShareUserBankBo result = new UnionShareUserBankBo();
result.setName(list.get(0).getName());
result.setBankCardNo(list.get(0).getBankCardNo());
result.setName(StringHideUtils.hideString(list.get(0).getName(),1,1));
result.setBankCardNo(StringHideUtils.hideSubString(list.get(0).getBankCardNo(),11));
result.setBankName(list.get(0).getBankName());
result.setIdCardNo(list.get(0).getIdCardNo());
addToRedis(ShareOrdersKeyEnum.USER_SETTLEMENT,uid,result,USER_SETTLEMENT_BANKCARD);
... ... @@ -354,7 +359,13 @@ public class UnionShareServiceImpl implements IUnionShareService,IBusinessExport
return result;
}
private void checkAndBuildBankCard(UnionShareUserBankBo bo) {
@Override
public int checkAndBuildBankCard(UnionShareUserBankBo bo) {
// 校验姓名
if (!ChineseNameUtils.checkName(bo.getName())) {
throw new ServiceException(ServiceError.UNION_CHINESE_NAME_ERROR);
}
// 校验是否已绑定银行卡
if (hasBankCard(bo.getUid())) {
throw new ServiceException(ServiceError.UNION_HAS_AVAILABLE_CARD);
... ... @@ -372,6 +383,7 @@ public class UnionShareServiceImpl implements IUnionShareService,IBusinessExport
if (null == bo.getBankName()) {
throw new ServiceException(ServiceError.UNION_BANK_CODE_ERROR);
}
return 200;
}
private boolean checkIdCard(String idcard) {
... ...