Showing
6 changed files
with
135 additions
and
9 deletions
1 | +package com.yoho.unions.common.utils; | ||
2 | + | ||
3 | +import org.apache.commons.lang.StringUtils; | ||
4 | + | ||
5 | +import java.util.regex.Matcher; | ||
6 | +import java.util.regex.Pattern; | ||
7 | + | ||
8 | +/** | ||
9 | + * Created by mingdan.ge on 2018/6/20. | ||
10 | + */ | ||
11 | +public class ChineseNameUtils { | ||
12 | + | ||
13 | + public static boolean checkName(String name) { | ||
14 | + if (StringUtils.isBlank(name)) { | ||
15 | + return false; | ||
16 | + } | ||
17 | + String reg = "[\\u4e00-\\u9fa5]{2,4}"; | ||
18 | + Pattern pattern = Pattern.compile(reg); | ||
19 | + Matcher matcher = pattern.matcher(name); | ||
20 | + return matcher.matches(); | ||
21 | + } | ||
22 | +} |
1 | +package com.yoho.unions.common.utils; | ||
2 | + | ||
3 | +/** | ||
4 | + * Created by mingdan.ge on 2018/6/20. | ||
5 | + */ | ||
6 | +public class StringHideUtils { | ||
7 | + | ||
8 | + /** | ||
9 | + * 隐藏指定位数 | ||
10 | + * @param resourseStr 源字符串 | ||
11 | + * @param hideNum 最多隐藏位数 | ||
12 | + * @param reserveNum 保留尾部位数 | ||
13 | + * */ | ||
14 | + public static String hideString(String resourseStr,int hideNum,int reserveNum){ | ||
15 | + if (null == resourseStr || resourseStr.length() <= reserveNum) { | ||
16 | + return resourseStr; | ||
17 | + } | ||
18 | + int startHideNo = resourseStr.length() - (hideNum + reserveNum); | ||
19 | + StringBuilder sb = new StringBuilder(startHideNo>0?resourseStr.substring(0,startHideNo):""); | ||
20 | + for (int i = startHideNo>0?startHideNo:0; i < resourseStr.length() - reserveNum; i++) { | ||
21 | + sb.append("*"); | ||
22 | + } | ||
23 | + sb.append(resourseStr.substring(resourseStr.length() - reserveNum)); | ||
24 | + return sb.toString(); | ||
25 | + } | ||
26 | + /** | ||
27 | + * 隐藏指定位数 | ||
28 | + * @param resourseStr 源字符串 | ||
29 | + * @param reserveNum 保留尾部位数 | ||
30 | + * */ | ||
31 | + public static String hideString(String resourseStr,int reserveNum){ | ||
32 | + if (null == resourseStr || resourseStr.length() <= reserveNum) { | ||
33 | + return resourseStr; | ||
34 | + } | ||
35 | + StringBuilder sb = new StringBuilder(); | ||
36 | + for (int i = 0; i < resourseStr.length() - reserveNum; i++) { | ||
37 | + sb.append("*"); | ||
38 | + } | ||
39 | + sb.append(resourseStr.substring(resourseStr.length() - reserveNum)); | ||
40 | + return sb.toString(); | ||
41 | + } | ||
42 | + /** | ||
43 | + * 隐藏指定位数 | ||
44 | + * @param resourseStr 源字符串 | ||
45 | + * @param hideNum 隐藏位数 | ||
46 | + * */ | ||
47 | + public static String hideSubString(String resourseStr,int hideNum){ | ||
48 | + if (null == resourseStr) { | ||
49 | + return resourseStr; | ||
50 | + } | ||
51 | + int reserveNum = resourseStr.length() - hideNum; | ||
52 | + StringBuilder sb = new StringBuilder(); | ||
53 | + for (int i = 0; i < resourseStr.length() - (reserveNum>0?reserveNum:0); i++) { | ||
54 | + sb.append("*"); | ||
55 | + } | ||
56 | + if (reserveNum > 0) { | ||
57 | + sb.append(resourseStr.substring(hideNum)); | ||
58 | + } | ||
59 | + return sb.toString(); | ||
60 | + } | ||
61 | + | ||
62 | + public static void main(String[] args) { | ||
63 | + String name = "中国人"; | ||
64 | + String bankCardNo = "6013821200016974875"; | ||
65 | + System.out.println(StringHideUtils.hideString(name,1,1)); | ||
66 | + System.out.println(StringHideUtils.hideString("名字",1,1)); | ||
67 | + System.out.println(bankCardNo); | ||
68 | + System.out.println(StringHideUtils.hideString(bankCardNo,3)); | ||
69 | + System.out.println(StringHideUtils.hideSubString(bankCardNo,11)); | ||
70 | + } | ||
71 | +} |
@@ -91,6 +91,7 @@ | @@ -91,6 +91,7 @@ | ||
91 | <value>/UnionShareRest/bindBankCard</value> | 91 | <value>/UnionShareRest/bindBankCard</value> |
92 | <value>/UnionShareRest/getBankList</value> | 92 | <value>/UnionShareRest/getBankList</value> |
93 | <value>/UnionShareRest/getBankCard</value> | 93 | <value>/UnionShareRest/getBankCard</value> |
94 | + <value>/UnionShareRest/checkBankCard</value> | ||
94 | 95 | ||
95 | </list> | 96 | </list> |
96 | </property> | 97 | </property> |
@@ -117,6 +117,19 @@ public class UnionShareRest { | @@ -117,6 +117,19 @@ public class UnionShareRest { | ||
117 | int result = unionShareService.bindBankCard(bo); | 117 | int result = unionShareService.bindBankCard(bo); |
118 | return new UnionResponse(200, "bindBankCard success",result>0?"Y":"N"); | 118 | return new UnionResponse(200, "bindBankCard success",result>0?"Y":"N"); |
119 | } | 119 | } |
120 | + | ||
121 | + /** | ||
122 | + * 校验银行卡信息 | ||
123 | + * @param bo | ||
124 | + * @return | ||
125 | + */ | ||
126 | + @RequestMapping("/checkBankCard") | ||
127 | + @ResponseBody | ||
128 | + public UnionResponse checkBankCard(@RequestBody UnionShareUserBankBo bo){ | ||
129 | + log.info("UnionShareRest.checkBankCard req is {}", bo); | ||
130 | + int result = unionShareService.checkAndBuildBankCard(bo); | ||
131 | + return new UnionResponse(200, "checkBankCard success",result>0?"Y":"N"); | ||
132 | + } | ||
120 | /** | 133 | /** |
121 | * 查询绑定的银行卡 | 134 | * 查询绑定的银行卡 |
122 | * @param uid | 135 | * @param uid |
@@ -72,7 +72,14 @@ public interface IUnionShareService { | @@ -72,7 +72,14 @@ public interface IUnionShareService { | ||
72 | * @param bo | 72 | * @param bo |
73 | * @return | 73 | * @return |
74 | */ | 74 | */ |
75 | - int bindBankCard(UnionShareUserBankBo bo); | 75 | + int bindBankCard(UnionShareUserBankBo bo); |
76 | + | ||
77 | + /** | ||
78 | + * 校验银行卡信息 | ||
79 | + * @param bo | ||
80 | + * @return | ||
81 | + */ | ||
82 | + int checkAndBuildBankCard(UnionShareUserBankBo bo); | ||
76 | 83 | ||
77 | /** | 84 | /** |
78 | * 用户前台获取个人推广近期订单(10个) | 85 | * 用户前台获取个人推广近期订单(10个) |
@@ -18,10 +18,7 @@ import com.yoho.unions.common.enums.ShareOrdersStatusEnum; | @@ -18,10 +18,7 @@ import com.yoho.unions.common.enums.ShareOrdersStatusEnum; | ||
18 | import com.yoho.unions.common.redis.RedisHashCache; | 18 | import com.yoho.unions.common.redis.RedisHashCache; |
19 | import com.yoho.unions.common.redis.RedisValueCache; | 19 | import com.yoho.unions.common.redis.RedisValueCache; |
20 | import com.yoho.unions.common.service.IBusinessExportService; | 20 | import com.yoho.unions.common.service.IBusinessExportService; |
21 | -import com.yoho.unions.common.utils.BankUtils; | ||
22 | -import com.yoho.unions.common.utils.DateUtil; | ||
23 | -import com.yoho.unions.common.utils.IDCardUtil; | ||
24 | -import com.yoho.unions.common.utils.RandomUtil; | 21 | +import com.yoho.unions.common.utils.*; |
25 | import com.yoho.unions.convert.BeanConvert; | 22 | import com.yoho.unions.convert.BeanConvert; |
26 | import com.yoho.unions.convert.Convert; | 23 | import com.yoho.unions.convert.Convert; |
27 | import com.yoho.unions.dal.*; | 24 | import com.yoho.unions.dal.*; |
@@ -306,11 +303,19 @@ public class UnionShareServiceImpl implements IUnionShareService,IBusinessExport | @@ -306,11 +303,19 @@ public class UnionShareServiceImpl implements IUnionShareService,IBusinessExport | ||
306 | */ | 303 | */ |
307 | @Override | 304 | @Override |
308 | public int bindBankCard(UnionShareUserBankBo bo){ | 305 | public int bindBankCard(UnionShareUserBankBo bo){ |
309 | - logger.info("bindBankCard,uid is {}",bo); | 306 | + logger.info("bindBankCard,bo is {}",bo); |
310 | if (null == bo||bo.getUid()<0) { | 307 | if (null == bo||bo.getUid()<0) { |
311 | return 0; | 308 | return 0; |
312 | } | 309 | } |
310 | + //信息格式校验 | ||
313 | checkAndBuildBankCard(bo); | 311 | checkAndBuildBankCard(bo); |
312 | + //查询该用户是否为特邀用户 | ||
313 | + int count = unionShareUserMapper.selectCountByUid(bo.getUid()); | ||
314 | + if (count == 0) { | ||
315 | + //不是特邀用户 | ||
316 | + logger.info("bindBankCard end,can not find unionType,bo is {}",bo); | ||
317 | + throw new ServiceException(ServiceError.USER_ID_ERROR); | ||
318 | + } | ||
314 | UnionShareUserBank insertReq = new UnionShareUserBank(); | 319 | UnionShareUserBank insertReq = new UnionShareUserBank(); |
315 | BeanUtils.copyProperties(bo, insertReq); | 320 | BeanUtils.copyProperties(bo, insertReq); |
316 | insertReq.setStatus((byte)1); | 321 | insertReq.setStatus((byte)1); |
@@ -345,8 +350,8 @@ public class UnionShareServiceImpl implements IUnionShareService,IBusinessExport | @@ -345,8 +350,8 @@ public class UnionShareServiceImpl implements IUnionShareService,IBusinessExport | ||
345 | return null; | 350 | return null; |
346 | } | 351 | } |
347 | UnionShareUserBankBo result = new UnionShareUserBankBo(); | 352 | UnionShareUserBankBo result = new UnionShareUserBankBo(); |
348 | - result.setName(list.get(0).getName()); | ||
349 | - result.setBankCardNo(list.get(0).getBankCardNo()); | 353 | + result.setName(StringHideUtils.hideString(list.get(0).getName(),1,1)); |
354 | + result.setBankCardNo(StringHideUtils.hideSubString(list.get(0).getBankCardNo(),11)); | ||
350 | result.setBankName(list.get(0).getBankName()); | 355 | result.setBankName(list.get(0).getBankName()); |
351 | result.setIdCardNo(list.get(0).getIdCardNo()); | 356 | result.setIdCardNo(list.get(0).getIdCardNo()); |
352 | addToRedis(ShareOrdersKeyEnum.USER_SETTLEMENT,uid,result,USER_SETTLEMENT_BANKCARD); | 357 | addToRedis(ShareOrdersKeyEnum.USER_SETTLEMENT,uid,result,USER_SETTLEMENT_BANKCARD); |
@@ -354,7 +359,13 @@ public class UnionShareServiceImpl implements IUnionShareService,IBusinessExport | @@ -354,7 +359,13 @@ public class UnionShareServiceImpl implements IUnionShareService,IBusinessExport | ||
354 | return result; | 359 | return result; |
355 | } | 360 | } |
356 | 361 | ||
357 | - private void checkAndBuildBankCard(UnionShareUserBankBo bo) { | 362 | + @Override |
363 | + public int checkAndBuildBankCard(UnionShareUserBankBo bo) { | ||
364 | + // 校验姓名 | ||
365 | + if (!ChineseNameUtils.checkName(bo.getName())) { | ||
366 | + throw new ServiceException(ServiceError.UNION_CHINESE_NAME_ERROR); | ||
367 | + } | ||
368 | + | ||
358 | // 校验是否已绑定银行卡 | 369 | // 校验是否已绑定银行卡 |
359 | if (hasBankCard(bo.getUid())) { | 370 | if (hasBankCard(bo.getUid())) { |
360 | throw new ServiceException(ServiceError.UNION_HAS_AVAILABLE_CARD); | 371 | throw new ServiceException(ServiceError.UNION_HAS_AVAILABLE_CARD); |
@@ -372,6 +383,7 @@ public class UnionShareServiceImpl implements IUnionShareService,IBusinessExport | @@ -372,6 +383,7 @@ public class UnionShareServiceImpl implements IUnionShareService,IBusinessExport | ||
372 | if (null == bo.getBankName()) { | 383 | if (null == bo.getBankName()) { |
373 | throw new ServiceException(ServiceError.UNION_BANK_CODE_ERROR); | 384 | throw new ServiceException(ServiceError.UNION_BANK_CODE_ERROR); |
374 | } | 385 | } |
386 | + return 200; | ||
375 | } | 387 | } |
376 | 388 | ||
377 | private boolean checkIdCard(String idcard) { | 389 | private boolean checkIdCard(String idcard) { |
-
Please register or login to post a comment