Commit 50c4bf3a authored by fangxinjiang's avatar fangxinjiang

小工具本地校验

parent a5a8f0d7
......@@ -98,5 +98,17 @@ public class TCheckBankNo extends BaseEntity {
@Schema(description ="银行卡类别 样例:借记卡")
private String cardCategory;
/**
* 姓名
*/
@Schema(description ="姓名")
private String name;
/**
* 身份证
*/
@Schema(description ="身份证")
private String idNum;
}
......@@ -120,7 +120,6 @@ public class TCheckBankNoController {
*/
@Operation(description = "银行卡号校验")
@SysLog("银行卡号校验" )
//@Inner
@GetMapping("/checkBankNo" )
public R<TCheckBankNo> checkBankNo(@RequestParam(value = "name",required = true)String name,
@RequestParam(value = "idNum",required = true)String idNum,
......@@ -128,4 +127,22 @@ public class TCheckBankNoController {
@RequestParam(value = "mobile",required = false) String mobile) {
return tCheckBankNoService.checkBankNo(name,idNum,cardNo,mobile);
}
/**
* 银行卡号校验
* @param name 姓名 是 [string]
* @param idNum 身份证号码,限单个 是 [string]
* @param cardNo 银行卡号,限单个 是 [string]
* @param mobile 银行预留手机号,仅支持国内11位号码
*/
@Operation(description = "银行卡号校验")
@SysLog("银行卡号校验" )
@Inner
@GetMapping("/inner/checkBankNo" )
public R<TCheckBankNo> checkBankNoInner(@RequestParam(value = "name",required = true)String name,
@RequestParam(value = "idNum",required = true)String idNum,
@RequestParam(value = "cardNo",required = true)String cardNo,
@RequestParam(value = "mobile",required = false) String mobile) {
return tCheckBankNoService.checkBankNo(name,idNum,cardNo,mobile);
}
}
......@@ -132,4 +132,19 @@ public class TCheckIdCardController {
public R<List<TCheckIdCard>> checkIdCard(@RequestBody List<TCheckIdCard> checkList) {
return tCheckIdCardService.checkIdCard(checkList);
}
/**
* @param checkList
* @Description: 校验姓名身份证
* @Author: fxj
* @Date: 2022-5-12 15:18:53
* @return: com.yifu.cloud.v1.common.core.util.R
**/
@Operation(description = "校验姓名身份证")
@SysLog("校验姓名身份证")
@Inner
@PostMapping("/inner/checkIdCard")
public R<List<TCheckIdCard>> checkIdCardInner(@RequestBody List<TCheckIdCard> checkList) {
return tCheckIdCardService.checkIdCard(checkList);
}
}
......@@ -32,6 +32,8 @@ import org.springframework.http.HttpHeaders;
import org.springframework.security.access.prepost.PreAuthorize;
import org.springframework.web.bind.annotation.*;
import java.util.Map;
/**
* 手机号码校验
......@@ -118,10 +120,22 @@ public class TCheckMobileController {
*/
@Operation(description = "检测手机号,多个手机号码用英文半角逗号隔开,仅支持国内号码")
@SysLog("检测手机号状态" )
//@Inner
@GetMapping("/checkMobiles" )
public R checkMobiles(String mobiles) {
return R.ok(tCheckMobileService.checkMobiles(mobiles));
public R<Map<String,TCheckMobile>> checkMobiles(String mobiles) {
return tCheckMobileService.checkMobiles(mobiles);
}
/**
* 手机号码状态校验
* @param mobiles 检测手机号,多个手机号码用英文半角逗号隔开,仅支持国内号码
* @return R
*/
@Operation(description = "检测手机号,多个手机号码用英文半角逗号隔开,仅支持国内号码")
@SysLog("检测手机号状态" )
@Inner
@GetMapping("/inner/checkMobiles" )
public R<Map<String,TCheckMobile>> checkMobilesInner(String mobiles) {
return tCheckMobileService.checkMobiles(mobiles);
}
}
......@@ -16,12 +16,14 @@
*/
package com.yifu.cloud.plus.v1.check.service.impl;
import com.baomidou.mybatisplus.core.toolkit.Wrappers;
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import com.yifu.cloud.plus.v1.check.entity.TCheckBankNo;
import com.yifu.cloud.plus.v1.check.mapper.TCheckBankNoMapper;
import com.yifu.cloud.plus.v1.check.service.TCanCheckService;
import com.yifu.cloud.plus.v1.check.service.TCheckBankNoService;
import com.yifu.cloud.plus.v1.check.utils.ChecksUtil;
import com.yifu.cloud.plus.v1.yifu.common.core.constant.CommonConstants;
import com.yifu.cloud.plus.v1.yifu.common.core.exception.ErrorCodes;
import com.yifu.cloud.plus.v1.yifu.common.core.util.Common;
import com.yifu.cloud.plus.v1.yifu.common.core.util.MsgUtils;
......@@ -40,11 +42,24 @@ import org.springframework.stereotype.Service;
public class TCheckBankNoServiceImpl extends ServiceImpl<TCheckBankNoMapper, TCheckBankNo> implements TCheckBankNoService {
private final TCanCheckService canCheckService;
@Override
public R<TCheckBankNo> checkBankNo(String name, String idNum, String cardNo, String mobile) {
if (Common.isEmpty(name) || Common.isEmpty(idNum) || Common.isEmpty(cardNo)){
return R.failed(MsgUtils.getMessage(ErrorCodes.CHECKS_BANK_NO_REQUEST_PARAM_ERROR));
}
return ChecksUtil.checkBankNo(name,idNum,cardNo,mobile,canCheckService.getCanCheck());
TCheckBankNo checkBankNo = baseMapper.selectOne(Wrappers.<TCheckBankNo>query().lambda()
.eq(TCheckBankNo::getBankNo,cardNo)
.eq(TCheckBankNo::getName,name)
.eq(TCheckBankNo::getIdNum,idNum)
.last(CommonConstants.LAST_ONE_SQL));
if (Common.isNotNull(checkBankNo)){
return R.ok(checkBankNo);
}
R<TCheckBankNo> res = ChecksUtil.checkBankNo(name,idNum,cardNo,mobile,canCheckService.getCanCheck());
if (Common.isNotNull(res) && Common.isNotNull(res.getData())){
baseMapper.insert(res.getData());
}
return res;
}
}
......@@ -16,6 +16,7 @@
*/
package com.yifu.cloud.plus.v1.check.service.impl;
import com.baomidou.mybatisplus.core.toolkit.Wrappers;
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import com.yifu.cloud.plus.v1.check.entity.TCheckMobile;
import com.yifu.cloud.plus.v1.check.mapper.TCheckMobileMapper;
......@@ -30,8 +31,10 @@ import com.yifu.cloud.plus.v1.yifu.common.core.util.R;
import lombok.RequiredArgsConstructor;
import org.springframework.stereotype.Service;
import java.util.HashMap;
import java.util.List;
import java.util.Map;
import java.util.stream.Collectors;
/**
* 手机号码校验
......@@ -44,6 +47,7 @@ import java.util.Map;
public class TCheckMobileServiceImpl extends ServiceImpl<TCheckMobileMapper, TCheckMobile> implements TCheckMobileService {
private final TCanCheckService canCheckService;
/**
* @Author fxj
* @Description 号码状态校验,单次请求上限100 多一个号码请以逗号分割
......@@ -53,12 +57,22 @@ public class TCheckMobileServiceImpl extends ServiceImpl<TCheckMobileMapper, TCh
public R<Map<String,TCheckMobile>> checkMobiles(String mobiles){
R<Map<String,TCheckMobile>> mobileMapR;
Map<String,TCheckMobile> checkMobileMap;
Map<String,TCheckMobile> existMap = new HashMap<>();
if (Common.isNotNull(mobiles)){
List<String> mobileList = Common.initStrToList(mobiles,CommonConstants.COMMA_STRING);
if (Common.isNotEmpty(mobileList) && mobileList.size() > CommonConstants.INTEGER_HUNDRED){
return R.failed(MsgUtils.getMessage(ErrorCodes.CHECKS_MOBILE_REQUEST_LIMIT_HUNDRED));
}
mobileMapR = ChecksUtil.checkMobile(mobiles,canCheckService.getCanCheck());
//1.先从本地库获取正常数据
List<TCheckMobile> checkMobiles = baseMapper.selectList(Wrappers.<TCheckMobile>query().lambda()
.in(TCheckMobile::getMobile,mobileList)
.eq(TCheckMobile::getStatus,CommonConstants.ONE_STRING));
if (Common.isNotNull(checkMobiles)){
checkMobiles.stream().collect(Collectors.toMap(TCheckMobile::getMobile,TCheckMobile -> TCheckMobile));
}
mobileList.removeAll(existMap.values());
//2.从远处端获取数据
mobileMapR = ChecksUtil.checkMobile(Common.ListToStr(mobileList,CommonConstants.COMMA_STRING),canCheckService.getCanCheck());
if (Common.isEmpty(mobileMapR) && Common.isEmpty(mobileMapR.getData())){
return R.failed(MsgUtils.getMessage(ErrorCodes.CHECKS_MOBILE_REQUEST_ERROR));
}
......@@ -78,7 +92,6 @@ public class TCheckMobileServiceImpl extends ServiceImpl<TCheckMobileMapper, TCh
checkMobileMap.put(mobile,checkMobile);
}
}
mobileMapR.setData(checkMobileMap);
}
}else {
return R.failed(MsgUtils.getMessage(ErrorCodes.PARAM_NOT_EMPTY));
......@@ -86,6 +99,8 @@ public class TCheckMobileServiceImpl extends ServiceImpl<TCheckMobileMapper, TCh
if (Common.isNotNull(checkMobileMap)){
this.saveBatch(checkMobileMap.values());
}
checkMobileMap.putAll(existMap);
mobileMapR.setData(checkMobileMap);
return mobileMapR;
}
......
......@@ -38,5 +38,7 @@
<result property="bankNo" column="bank_no"/>
<result property="cardType" column="card_type"/>
<result property="cardCategory" column="card_category"/>
<result property="name" column="name"/>
<result property="idNum" column="id_num"/>
</resultMap>
</mapper>
......@@ -4,6 +4,7 @@ import com.yifu.cloud.plus.v1.yifu.common.core.constant.CommonConstants;
import lombok.extern.slf4j.Slf4j;
import java.util.ArrayList;
import java.util.Collection;
import java.util.List;
import java.util.regex.Matcher;
import java.util.regex.Pattern;
......@@ -123,4 +124,34 @@ public class Common {
}
return result;
}
/**
* 将集合拼成串
*
* @param <T>
* @param str
* @param regex 分隔符默认,
* @return
*/
public static <T> String ListToStr(Collection<T> str, String regex) {
String result = "";
try {
if (isNotNull(str)) {
// 默认用,分割
if (!isNotNull(regex)) {
regex = ",";
}
for (Object strtemp : str) {
if ("".equals(result)) {
result = String.valueOf(strtemp);
} else {
result = result + regex + strtemp;
}
}
}
} catch (Exception e) {
// 数据异常
}
return result;
}
}
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