Commit a4fe1446 authored by 王向伟's avatar 王向伟

用户综合查询

parent 9542e687
package cn.quantgroup.customer.model;
/**
* Created by Miraculous on 15/11/24.
*/
public class Tuple<K, V> {
private K key;
private V value;
public Tuple() {
}
public Tuple(K key, V value) {
this.key = key;
this.value = value;
}
public K getKey() {
return key;
}
public Tuple<K, V> setKey(K key) {
this.key = key;
return this;
}
public V getValue() {
return value;
}
public Tuple<K, V> setValue(V value) {
this.value = value;
return this;
}
}
package cn.quantgroup.customer.model.order;
import lombok.Data;
/**
* 申请订单
* @author Wang Xiangwei
* @version 2020/3/9
*/
@Data
public class ApplyOrder {
/**
* 序号
*/
private Long num;
private String channelNo;
private Long userId;
private String applyOrderNo;
private String applyStatus;
private String applyAt;
private String productDesc;
private String channelName;
private Long loanId;
private Boolean showBtn;
}
package cn.quantgroup.customer.model.order;
import lombok.Data;
import java.math.BigDecimal;
import java.util.List;
/**
* 提现订单详情
* @author Wang Xiangwei
* @version 2020/3/9
*/
@Data
public class LoanOrderDetail {
/**
*订单ID
*/
private Long orderId;
/**
*订单申请号
*/
private String orderNo;
/**
*借款订单号
*/
private Long loanId;
/**
*提现渠道号
*/
private String channelNo;
/**
*提现时间
*/
private String loanPaidAt;
/**
*资金方
*/
private String fund;
/**
*合同贷款金额
*/
private String contractAmount;
/**
*合同贷款期数
*/
private Integer contractTermNo;
/**
*担保费
*/
private BigDecimal guaranteeFee;
/**
*其他费用
*/
private BigDecimal otherFee;
/**
*一次性服务费
*/
private BigDecimal onceServiceFee;
/**
*月利率
*/
private BigDecimal monthlyInterestRate;
/**
*当前状态
*/
private String status;
/**
*推送资金方放款时间
*/
private String sendLoanPaidAt;
/**
*放款银行卡号
*/
private String cardNo;
/**
*放款银行卡户名
*/
private String cardHolderName;
/**
*放款银行名称
*/
private String bankName;
List<Repayment> repaymentList;
}
package cn.quantgroup.customer.model.order;
import lombok.Data;
import java.math.BigDecimal;
/**
* 还款计划信息
* @author Wang Xiangwei
* @version 2020/3/9
*/
@Data
public class Repayment {
/**
*还款期数
*/
private Integer termNo;
/**
*本金
*/
private BigDecimal principal;
/**
*利息
*/
private BigDecimal interest;
/**
*担保费
*/
private BigDecimal premium;
/**
*其他担保
*/
private BigDecimal otherFee;
/**
*罚息
*/
private BigDecimal overdueInterest;
/**
*逾期保费
*/
private BigDecimal overdueServiceFee;
/**
*当前减免
*/
private BigDecimal collectionRelief;
/**
*还款总额
*/
private BigDecimal actualRepayment;
/**
*应还总额
*/
private BigDecimal shouldAmount;
/**
*应还时间
*/
private String shouldAt;
/**
*还款时间
*/
private String repaidAt;
/**
*还款状态
*/
private String repaymentStatus;
/**
*还款方式
*/
private String repayType;
/**
*逾期天数
*/
private Integer overdueDays;
}
package cn.quantgroup.customer.model.xyqbuser;
import lombok.Data;
/**
* 信用钱包用户基本展示信息
* @author Wang Xiangwei
* @version 2020/3/9
*/
@Data
public class UserBasicInfo {
private Long userId;
private String name;
/**
* 男 女 未知
*/
private String gender;
/**
* 身份证号
*/
private String idNo;
/**
* 手机号
*/
private String phoneNo;
private String createAt;
/**
* 正常 封禁
*/
private String status;
}
package cn.quantgroup.customer.model.xyqbuser;
import cn.quantgroup.customer.model.order.ApplyOrder;
import lombok.Data;
import java.util.List;
/**
* @author Wang Xiangwei
* @version 2020/3/9
*/
@Data
public class UserCombination {
private UserBasicInfo userInfo;
private List<ApplyOrder> applyOrderList;
}
package cn.quantgroup.customer.rest;
import cn.quantgroup.customer.rest.vo.JsonResult;
import cn.quantgroup.customer.service.IXyqbService;
import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;
/**
* @author Wang Xiangwei
* @version 2020/3/9
*/
@Slf4j
@RestController
@RequestMapping("/order")
public class OrderRest {
@Autowired
private IXyqbService xyqbService;
@GetMapping("/loan/{loanId}")
public JsonResult getLoanOrderDetail(@PathVariable Long loanId){
return xyqbService.findLoanDetail(loanId);
}
}
...@@ -9,27 +9,26 @@ import cn.quantgroup.customer.rest.enums.phone.ModifyPhoneProcessingStatus; ...@@ -9,27 +9,26 @@ import cn.quantgroup.customer.rest.enums.phone.ModifyPhoneProcessingStatus;
import cn.quantgroup.customer.rest.param.phone.ModifyPhoneAudit; import cn.quantgroup.customer.rest.param.phone.ModifyPhoneAudit;
import cn.quantgroup.customer.rest.param.phone.ModifyPhoneFeedback; import cn.quantgroup.customer.rest.param.phone.ModifyPhoneFeedback;
import cn.quantgroup.customer.rest.param.phone.ModifyPhoneQuery; import cn.quantgroup.customer.rest.param.phone.ModifyPhoneQuery;
import cn.quantgroup.customer.rest.param.user.LoginParam; import cn.quantgroup.customer.rest.param.user.UserCombinationParam;
import cn.quantgroup.customer.rest.vo.JsonResult; import cn.quantgroup.customer.rest.vo.JsonResult;
import cn.quantgroup.customer.rest.vo.user.AuthUserVo;
import cn.quantgroup.customer.service.IUserService; import cn.quantgroup.customer.service.IUserService;
import cn.quantgroup.riskcontrol.model.AuthenticationUserDetail; import cn.quantgroup.customer.service.IXyqbService;
import lombok.extern.slf4j.Slf4j; import lombok.extern.slf4j.Slf4j;
import org.apache.commons.lang3.StringUtils; import org.apache.commons.lang3.StringUtils;
import org.springframework.beans.factory.annotation.Autowired; import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.security.authentication.AuthenticationManager; import org.springframework.security.authentication.AuthenticationManager;
import org.springframework.security.authentication.UsernamePasswordAuthenticationToken; import org.springframework.security.authentication.UsernamePasswordAuthenticationToken;
import org.springframework.security.core.Authentication; import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.security.core.context.SecurityContextHolder; import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.*; import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;
import javax.servlet.http.HttpServletRequest; import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpSession;
import javax.validation.Valid; import javax.validation.Valid;
import java.security.Principal; import java.security.Principal;
import java.time.LocalDate; import java.time.LocalDate;
import static cn.quantgroup.customer.constant.Constant.*; import static cn.quantgroup.customer.constant.Constant.GSON;
@Slf4j @Slf4j
@RestController @RestController
...@@ -38,11 +37,13 @@ public class UserRest { ...@@ -38,11 +37,13 @@ public class UserRest {
private final IUserService userService; private final IUserService userService;
private final AuthenticationManager authenticationManager; private final AuthenticationManager authenticationManager;
private final IXyqbService xyqbService;
@Autowired @Autowired
public UserRest(AuthenticationManager authenticationManager, IUserService userService) { public UserRest(AuthenticationManager authenticationManager, IUserService userService,IXyqbService xyqbService) {
this.authenticationManager = authenticationManager; this.authenticationManager = authenticationManager;
this.userService = userService; this.userService = userService;
this.xyqbService = xyqbService;
} }
@PostMapping(value = "/login") @PostMapping(value = "/login")
...@@ -124,4 +125,16 @@ public class UserRest { ...@@ -124,4 +125,16 @@ public class UserRest {
} }
/**
* 用户综合查询
* @param combinationParam
* @return
*/
@GetMapping(value = "/info")
public JsonResult findUserCombination(UserCombinationParam combinationParam){
return userService.findUserCombination(combinationParam);
}
} }
package cn.quantgroup.customer.rest.param.applyorder;
import lombok.Data;
/**
* @author Wang Xiangwei
* @version 2020/3/9
*/
@Data
public class ApplyOrderQuery {
private Long userId;
/**
* 申请订单号
*/
private String orderNo;
private Long loanId;
}
package cn.quantgroup.customer.rest.param.user;
import lombok.Data;
/**
* 用户综合查询参数
* @author Wang Xiangwei
* @version 2020/3/9
*/
@Data
public class UserCombinationParam {
/**
* 渠道订单号
*/
private String channelOrderNo;
/**
* 注册手机号
*/
private String phoneNo;
/**
* 用户注册身份证号
*/
private String idNo;
/**
* 申请订单号
*/
private String orderNo;
/**
* 借款订单号
*/
private Long loanId;
private Long userId;
private String uuid;
}
...@@ -7,7 +7,7 @@ import java.io.Serializable; ...@@ -7,7 +7,7 @@ import java.io.Serializable;
@Setter @Setter
@Getter @Getter
public class JsonResult implements Serializable { public class JsonResult<T> implements Serializable {
private static final Long API_INVOKE_UNEXPECTED_RESULT_CODE = 2L; private static final Long API_INVOKE_UNEXPECTED_RESULT_CODE = 2L;
private static final Long SUCCESS_CODE = 0L; private static final Long SUCCESS_CODE = 0L;
...@@ -22,43 +22,43 @@ public class JsonResult implements Serializable { ...@@ -22,43 +22,43 @@ public class JsonResult implements Serializable {
// 业务错误码 // 业务错误码
private String businessCode = "0000"; private String businessCode = "0000";
private Object data = null; private T data = null;
public JsonResult() { public JsonResult() {
} }
public JsonResult(String msg, Long code, Object data) { public JsonResult(String msg, Long code, T data) {
this.msg = msg; this.msg = msg;
this.code = String.format(ZERO_FILL_TEMPLATE, code); this.code = String.format(ZERO_FILL_TEMPLATE, code);
this.data = data; this.data = data;
} }
public JsonResult(String msg, Long code, Object data, Long businessCode) { public JsonResult(String msg, Long code, T data, Long businessCode) {
this.msg = msg; this.msg = msg;
this.code = String.format(ZERO_FILL_TEMPLATE, code); this.code = String.format(ZERO_FILL_TEMPLATE, code);
this.data = data; this.data = data;
this.businessCode = String.format(ZERO_FILL_TEMPLATE, businessCode); this.businessCode = String.format(ZERO_FILL_TEMPLATE, businessCode);
} }
public JsonResult(Object data) { public JsonResult(T data) {
this.data = data; this.data = data;
} }
public static JsonResult buildSuccessResult(String msg, Object data) { public static <T> JsonResult buildSuccessResult(String msg, T data) {
return new JsonResult(msg, SUCCESS_CODE, data, SUCCESS_BUSSINESS_CODE); return new JsonResult(msg, SUCCESS_CODE, data, SUCCESS_BUSSINESS_CODE);
} }
public static JsonResult buildSuccessResult(String msg, Object data, Long businessId) { public static <T> JsonResult buildSuccessResult(String msg, T data, Long businessId) {
return new JsonResult(msg, SUCCESS_CODE, data, businessId); return new JsonResult(msg, SUCCESS_CODE, data, businessId);
} }
public static JsonResult buildErrorStateResult(String msg, Object data) { public static <T> JsonResult buildErrorStateResult(String msg, T data) {
return new JsonResult(msg, ERROR_STATE_CODE, data, ERROR_BUSSINESS_CODE); return new JsonResult(msg, ERROR_STATE_CODE, data, ERROR_BUSSINESS_CODE);
} }
public static JsonResult buildErrorStateResult(String msg, Object data, Long businessId) { public static <T> JsonResult buildErrorStateResult(String msg, T data, Long businessId) {
return new JsonResult(msg, ERROR_STATE_CODE, data, businessId); return new JsonResult(msg, ERROR_STATE_CODE, data, businessId);
} }
...@@ -66,11 +66,11 @@ public class JsonResult implements Serializable { ...@@ -66,11 +66,11 @@ public class JsonResult implements Serializable {
return new JsonResult(msg, ERROR_STATE_CODE, null, businessId); return new JsonResult(msg, ERROR_STATE_CODE, null, businessId);
} }
public static JsonResult buildFatalErrorStateResult(String msg, Object data, Long businessId) { public static <T> JsonResult buildFatalErrorStateResult(String msg, T data, Long businessId) {
return new JsonResult(msg, ERROR_STATE_CODE, data, businessId); return new JsonResult(msg, ERROR_STATE_CODE, data, businessId);
} }
public static JsonResult buildApiInvokeUnexpectedResult(String msg, Object data) { public static <T> JsonResult buildApiInvokeUnexpectedResult(String msg, T data) {
return new JsonResult(msg, SUCCESS_CODE, data, API_INVOKE_UNEXPECTED_RESULT_CODE); return new JsonResult(msg, SUCCESS_CODE, data, API_INVOKE_UNEXPECTED_RESULT_CODE);
} }
......
package cn.quantgroup.customer.service; package cn.quantgroup.customer.service;
import cn.quantgroup.customer.model.xyqbuser.UserBasicInfo;
import cn.quantgroup.customer.rest.param.phone.ModifyPhoneAudit; import cn.quantgroup.customer.rest.param.phone.ModifyPhoneAudit;
import cn.quantgroup.customer.rest.param.phone.ModifyPhoneFeedback; import cn.quantgroup.customer.rest.param.phone.ModifyPhoneFeedback;
import cn.quantgroup.customer.rest.param.phone.ModifyPhoneQuery; import cn.quantgroup.customer.rest.param.phone.ModifyPhoneQuery;
import cn.quantgroup.customer.rest.param.user.UserCombinationParam;
import cn.quantgroup.customer.rest.vo.JsonResult;
import org.springframework.security.core.userdetails.UserDetailsService; import org.springframework.security.core.userdetails.UserDetailsService;
import org.springframework.stereotype.Service; import org.springframework.stereotype.Service;
...@@ -17,4 +20,17 @@ public interface IUserService extends UserDetailsService { ...@@ -17,4 +20,17 @@ public interface IUserService extends UserDetailsService {
String findUuidByIdNo(String idNo); String findUuidByIdNo(String idNo);
/**
* 用户基本信息
* @param userCombinationParam
* @return
*/
JsonResult findUserInfo(UserCombinationParam userCombinationParam);
JsonResult findUserCombination(UserCombinationParam userCombinationParam);
} }
package cn.quantgroup.customer.service; package cn.quantgroup.customer.service;
import cn.quantgroup.customer.rest.param.applyorder.ApplyOrderQuery;
import cn.quantgroup.customer.rest.param.repay.RepayOrderQuery; import cn.quantgroup.customer.rest.param.repay.RepayOrderQuery;
import cn.quantgroup.customer.rest.vo.JsonResult;
public interface IXyqbService { public interface IXyqbService {
String findRepayOrders(RepayOrderQuery repayOrderQuery); String findRepayOrders(RepayOrderQuery repayOrderQuery);
/**
* 申请订单列表查询
* @param applyOrderQuery
* @return
*/
JsonResult findApplyOrders(ApplyOrderQuery applyOrderQuery);
/**
* 流程日志查看
* @param orderNo 申请订单号
* @return
*/
JsonResult findFlowChart(String orderNo);
/**
* 提现订单查询
* @param loanId
* @return
*/
JsonResult findLoanDetail(Long loanId);
} }
...@@ -4,20 +4,33 @@ import cn.quantgroup.customer.common.adapter.LocalDateTypeAdapter; ...@@ -4,20 +4,33 @@ import cn.quantgroup.customer.common.adapter.LocalDateTypeAdapter;
import cn.quantgroup.customer.entity.User; import cn.quantgroup.customer.entity.User;
import cn.quantgroup.customer.enums.ErrorCodeEnum; import cn.quantgroup.customer.enums.ErrorCodeEnum;
import cn.quantgroup.customer.exception.BusinessException; import cn.quantgroup.customer.exception.BusinessException;
import cn.quantgroup.customer.model.Tuple;
import cn.quantgroup.customer.model.xyqbuser.UserBasicInfo;
import cn.quantgroup.customer.model.xyqbuser.UserCombination;
import cn.quantgroup.customer.repo.UserRepo; import cn.quantgroup.customer.repo.UserRepo;
import cn.quantgroup.customer.rest.param.applyorder.ApplyOrderQuery;
import cn.quantgroup.customer.rest.param.phone.ModifyPhoneAudit; import cn.quantgroup.customer.rest.param.phone.ModifyPhoneAudit;
import cn.quantgroup.customer.rest.param.phone.ModifyPhoneFeedback; import cn.quantgroup.customer.rest.param.phone.ModifyPhoneFeedback;
import cn.quantgroup.customer.rest.param.phone.ModifyPhoneQuery; import cn.quantgroup.customer.rest.param.phone.ModifyPhoneQuery;
import cn.quantgroup.customer.rest.param.user.UserCombinationParam;
import cn.quantgroup.customer.rest.vo.JsonResult; import cn.quantgroup.customer.rest.vo.JsonResult;
import cn.quantgroup.customer.service.IUserService; import cn.quantgroup.customer.service.IUserService;
import cn.quantgroup.customer.service.IXyqbService;
import cn.quantgroup.customer.service.http.IHttpService; import cn.quantgroup.customer.service.http.IHttpService;
import cn.quantgroup.customer.util.DateUtil;
import cn.quantgroup.customer.util.IdcardUtils;
import cn.quantgroup.customer.util.ValidationUtil;
import cn.quantgroup.riskcontrol.model.AuthenticationUserDetail; import cn.quantgroup.riskcontrol.model.AuthenticationUserDetail;
import cn.quantgroup.user.retbean.XUserDetail;
import cn.quantgroup.user.retbean.XUserFullInfo;
import cn.quantgroup.user.vo.UserSysResult;
import com.google.common.collect.Maps; import com.google.common.collect.Maps;
import com.google.gson.Gson; import com.google.gson.Gson;
import com.google.gson.GsonBuilder; import com.google.gson.GsonBuilder;
import lombok.extern.slf4j.Slf4j; import lombok.extern.slf4j.Slf4j;
import org.apache.commons.lang3.StringUtils; import org.apache.commons.lang3.StringUtils;
import org.apache.commons.lang3.exception.ExceptionUtils; import org.apache.commons.lang3.exception.ExceptionUtils;
import org.apache.commons.lang3.time.DateUtils;
import org.springframework.beans.factory.annotation.Autowired; import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.beans.factory.annotation.Value; import org.springframework.beans.factory.annotation.Value;
import org.springframework.security.core.userdetails.UserDetails; import org.springframework.security.core.userdetails.UserDetails;
...@@ -25,7 +38,9 @@ import org.springframework.security.core.userdetails.UsernameNotFoundException; ...@@ -25,7 +38,9 @@ import org.springframework.security.core.userdetails.UsernameNotFoundException;
import org.springframework.stereotype.Service; import org.springframework.stereotype.Service;
import java.time.LocalDate; import java.time.LocalDate;
import java.util.List;
import java.util.Map; import java.util.Map;
import java.util.Objects;
import static cn.quantgroup.customer.constant.Constant.GSON; import static cn.quantgroup.customer.constant.Constant.GSON;
...@@ -39,11 +54,16 @@ public class UserServiceImpl implements IUserService { ...@@ -39,11 +54,16 @@ public class UserServiceImpl implements IUserService {
private final UserRepo userRepo; private final UserRepo userRepo;
private final IHttpService httpService; private final IHttpService httpService;
private final UserSdkImpl userSdk;
private final IXyqbService xyqbService;
@Autowired @Autowired
public UserServiceImpl(UserRepo userRepo, IHttpService httpService) { public UserServiceImpl(UserRepo userRepo, IHttpService httpService, UserSdkImpl userSdk,IXyqbService xyqbService) {
this.userRepo = userRepo; this.userRepo = userRepo;
this.httpService = httpService; this.httpService = httpService;
this.userSdk = userSdk;
this.xyqbService =xyqbService;
} }
@Override @Override
...@@ -124,4 +144,222 @@ public class UserServiceImpl implements IUserService { ...@@ -124,4 +144,222 @@ public class UserServiceImpl implements IUserService {
} }
} }
@Override
public JsonResult findUserInfo(UserCombinationParam userCombinationParam) {
final String LOG_PRE = "UserServiceImpl.findUserInfo";
log.info("{} 查询用户信息 userCombinationParam={}",LOG_PRE,userCombinationParam);
Tuple<Boolean, String> tuple = validate(userCombinationParam);
if (!tuple.getKey()) {
log.error("{},参数验证失败,{}", LOG_PRE, tuple.getValue());
return JsonResult.buildErrorStateResult(tuple.getValue(), null);
}
//通过userId查询
if (!Objects.isNull(userCombinationParam.getUserId())){
log.info("{} 通过userId查询 userId={}",LOG_PRE,userCombinationParam.getUserId());
UserSysResult<XUserDetail> userDetailByUserId = userSdk.getService().findUserDetailByUserId(userCombinationParam.getUserId());
return getUserBasicInfoResult(userDetailByUserId);
}
if(StringUtils.isNotBlank(userCombinationParam.getPhoneNo())){
log.info("{} 通过phoneNo查询 phoneNo={}",LOG_PRE,userCombinationParam.getPhoneNo());
UserSysResult<XUserDetail> userDetailByPhone = userSdk.getService().findUserDetailByPhone(userCombinationParam.getPhoneNo());
return getUserBasicInfoResult(userDetailByPhone);
}
if(StringUtils.isNotBlank(userCombinationParam.getUuid())){
log.info("{} 通过uuid查询 uuid={}",LOG_PRE,userCombinationParam.getUuid());
UserSysResult<XUserFullInfo> userFullInfoByUuid = userSdk.getService().findUserFullInfoByUuid(userCombinationParam.getUuid());
Object jsonResultData = getJsonResultData(userFullInfoByUuid);
if(jsonResultData instanceof XUserFullInfo){
XUserFullInfo xUserFullInfo = (XUserFullInfo) jsonResultData;
UserSysResult<XUserDetail> userDetailByPhone = userSdk.getService().findUserDetailByPhone(xUserFullInfo.getPhoneNo());
return getUserBasicInfoResult(userDetailByPhone);
}else {
return (JsonResult) jsonResultData;
}
}
if(!Objects.isNull(userCombinationParam.getLoanId()) || StringUtils.isNotBlank(userCombinationParam.getChannelOrderNo()) || StringUtils.isNotBlank(userCombinationParam.getOrderNo())){
//通过ka获得userId然后通过userId查询
}
if(!Objects.isNull(userCombinationParam.getIdNo())){
//通过业务系统获得
return findUserDetailByIdNo(userCombinationParam.getIdNo());
}
return JsonResult.buildErrorStateResult("无有效查询参数",null);
}
private JsonResult findUserDetailByIdNo(String idNo){
String url = userSysUrl + "innerapi/user_detail/fuzzyQuery";
try {
Map<String, Object> param = Maps.newHashMap();
param.put("idNo", idNo);
String result = httpService.post(url, param);
log.info("[user][findUserDetailByIdNo ] 请求业务系统返回值:{}", result);
JsonResult jsonResult = GSON.fromJson(result, JsonResult.class);
if(!Objects.isNull(jsonResult) && jsonResult.isSuccess()){
Object data = jsonResult.getData();
if(data instanceof List){
List list = (List) data;
if(list.size() >1){
return JsonResult.buildErrorStateResult("身份证查询返回多条数据,请用其他参数查询",null);
}
if (list.size() ==0){
return JsonResult.buildErrorStateResult("不存在相关用户信息",null);
}
Object o = list.get(0);
XUserDetail userDetail = GSON.fromJson(o.toString(),XUserDetail.class);
UserBasicInfo userBasicInfo = new UserBasicInfo();
String createAt = DateUtil.format(userDetail.getCreatedAt(), DateUtil.DATE_FORMAT_1);
userBasicInfo.setCreateAt(createAt);
userBasicInfo.setGender(userDetail.getGender().getName());
userBasicInfo.setIdNo(userDetail.getIdNo());
userBasicInfo.setName(userDetail.getName());
userBasicInfo.setPhoneNo(userDetail.getPhoneNo());
userBasicInfo.setStatus(userDetail.getEnable()? "正常":"封禁");
return JsonResult.buildSuccessResult(null,userBasicInfo);
}
}
} catch (Exception e) {
log.error("[user][findUserDetailByIdNo ] 网络通讯异常,idNo:{},ex:{}", idNo, ExceptionUtils.getStackTrace(e));
throw new BusinessException(ErrorCodeEnum.NET_ERROR);
}
return JsonResult.buildErrorStateResult("查询用户信息错误",null);
}
private JsonResult getUserBasicInfoResult(UserSysResult userSysResult) {
Object data= getJsonResultData(userSysResult);
UserBasicInfo userBasicInfo = new UserBasicInfo();
if(data instanceof XUserDetail){
XUserDetail userDetail = (XUserDetail) data;
String createAt = DateUtil.format(userDetail.getCreatedAt(), DateUtil.DATE_FORMAT_1);
userBasicInfo.setCreateAt(createAt);
userBasicInfo.setGender(userDetail.getGender().getName());
userBasicInfo.setIdNo(userDetail.getIdNo());
userBasicInfo.setName(userDetail.getName());
userBasicInfo.setPhoneNo(userDetail.getPhoneNo());
userBasicInfo.setStatus(userDetail.getEnable()? "正常":"封禁");
}else {
return (JsonResult) data;
}
return JsonResult.buildSuccessResult(null,userBasicInfo);
}
private Object getJsonResultData(UserSysResult userSysResult) {
String logPre = "UserServiceImpl.getJsonResultData";
log.info("{} 转换为对象 userSysResult={}",logPre,userSysResult);
if(Objects.isNull(userSysResult)){
log.error("{} 转换参数为空 userSysResult={}",logPre,userSysResult);
return JsonResult.buildErrorStateResult("远程调用结果为空",null);
}
if(!userSysResult.isSuccess() || Objects.isNull(userSysResult.getData())){
log.error("{} 远程调用失败 userSysResult={}",logPre,userSysResult);
return JsonResult.buildErrorStateResult(userSysResult.getMsg(),userSysResult.getData());
}
return userSysResult.getData();
}
/**
* 验证参数不全为空且合法
*
* @param userCombinationParam
* @return
*/
private Tuple<Boolean, String> validate(UserCombinationParam userCombinationParam) {
Tuple<Boolean, String> result = new Tuple<>();
result.setKey(true);
if (Objects.isNull(userCombinationParam)) {
result.setKey(false);
result.setValue("对象为空");
return result;
}
if (StringUtils.isNotBlank(userCombinationParam.getChannelOrderNo())) {
return result;
}
if (StringUtils.isNotBlank(userCombinationParam.getIdNo())) {
if (IdcardUtils.validateIdCard18(userCombinationParam.getIdNo()) || IdcardUtils.validateIdCard15(userCombinationParam.getIdNo())) {
return result;
} else {
result.setKey(false);
result.setValue("身份证号格式有误");
return result;
}
}
if (StringUtils.isNotBlank(userCombinationParam.getOrderNo())) {
return result;
}
if (!Objects.isNull(userCombinationParam.getUserId())) {
return result;
}
if (StringUtils.isNotBlank(userCombinationParam.getPhoneNo())) {
if (ValidationUtil.validatePhoneNo(userCombinationParam.getPhoneNo())) {
return result;
} else {
result.setKey(false);
result.setValue("手机号格式错误");
return result;
}
}
if (StringUtils.isNotBlank(userCombinationParam.getUuid())) {
return result;
}
if (!Objects.isNull(userCombinationParam.getLoanId())) {
return result;
}
result.setKey(false);
result.setValue("字段全部为空");
return result;
}
@Override
public JsonResult findUserCombination(UserCombinationParam userCombinationParam) {
String logPre = "UserServiceImpl.findUserCombination";
log.info("{},综合查询 userCombinationParam={}",logPre,userCombinationParam);
JsonResult userInfo = this.findUserInfo(userCombinationParam);
if(!userInfo.isSuccess()){
return userInfo;
}
UserBasicInfo userBasicInfo = (UserBasicInfo) userInfo.getData();
ApplyOrderQuery applyOrderQuery = new ApplyOrderQuery();
applyOrderQuery.setLoanId(userCombinationParam.getLoanId());
applyOrderQuery.setOrderNo(userCombinationParam.getOrderNo());
applyOrderQuery.setUserId(userBasicInfo.getUserId());
JsonResult applyOrders = xyqbService.findApplyOrders(applyOrderQuery);
if(!applyOrders.isSuccess()){
return applyOrders;
}
List applyOrderList = (List)applyOrders.getData();
UserCombination userCombination = new UserCombination();
userCombination.setUserInfo(userBasicInfo);
userCombination.setApplyOrderList(applyOrderList);
return JsonResult.buildSuccessResult("",userCombination);
}
} }
package cn.quantgroup.customer.service.impl; package cn.quantgroup.customer.service.impl;
import cn.quantgroup.customer.model.order.ApplyOrder;
import cn.quantgroup.customer.rest.param.applyorder.ApplyOrderQuery;
import cn.quantgroup.customer.rest.param.repay.RepayOrderQuery; import cn.quantgroup.customer.rest.param.repay.RepayOrderQuery;
import cn.quantgroup.customer.rest.vo.JsonResult;
import cn.quantgroup.customer.service.IXyqbService; import cn.quantgroup.customer.service.IXyqbService;
import cn.quantgroup.customer.service.http.IHttpService; import cn.quantgroup.customer.service.http.IHttpService;
import com.google.common.collect.Maps; import com.google.common.collect.Maps;
...@@ -8,11 +11,16 @@ import lombok.extern.slf4j.Slf4j; ...@@ -8,11 +11,16 @@ import lombok.extern.slf4j.Slf4j;
import org.apache.commons.lang3.StringUtils; import org.apache.commons.lang3.StringUtils;
import org.springframework.beans.factory.annotation.Autowired; import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.beans.factory.annotation.Value; import org.springframework.beans.factory.annotation.Value;
import org.springframework.core.ParameterizedTypeReference;
import org.springframework.stereotype.Service; import org.springframework.stereotype.Service;
import java.util.ArrayList;
import java.util.List;
import java.util.Map; import java.util.Map;
import java.util.Objects; import java.util.Objects;
import static cn.quantgroup.customer.constant.Constant.GSON;
@Slf4j @Slf4j
@Service("xyqbService") @Service("xyqbService")
public class XyqbServiceImpl implements IXyqbService { public class XyqbServiceImpl implements IXyqbService {
...@@ -43,4 +51,88 @@ public class XyqbServiceImpl implements IXyqbService { ...@@ -43,4 +51,88 @@ public class XyqbServiceImpl implements IXyqbService {
log.info("[xyqb][query repay orders ] param:{},请求业务系统返回值:{}", param, response); log.info("[xyqb][query repay orders ] param:{},请求业务系统返回值:{}", param, response);
return response; return response;
} }
@Override
public JsonResult<List<ApplyOrder>> findApplyOrders(ApplyOrderQuery applyOrderQuery) {
String logPre="XyqbServiceImpl.findApplyOrders";
log.info("{} 申请订单查询 applyOrderQuery={}",logPre,applyOrderQuery);
String orderNo = applyOrderQuery.getOrderNo();
Long loanId = applyOrderQuery.getLoanId();
Long userId = applyOrderQuery.getUserId();
String url = xyqbSysUrl + "/ex/inside/customer_sys/query/applyOrder";
Map<String, Object> param = Maps.newHashMap();
if (StringUtils.isNotEmpty(orderNo)) {
param.put("orderNo", orderNo);
}
if (Objects.nonNull(userId)) {
param.put("userId", userId);
}
if (Objects.nonNull(loanId)) {
param.put("loanId", loanId);
}
Map<String, String> header = Maps.newHashMap();
header.put("Content-type", "application/x-www-form-urlencoded");
JsonResult jsonResult = httpService.post(url, header,param, JsonResult.class);
if(Objects.isNull(jsonResult) || jsonResult.isSuccess()){
log.error("{} 调用信用钱包失败 url={}, header={},param={},result={}",logPre,url, header,param,jsonResult);
return JsonResult.buildErrorStateResult("申请订单查询失败",null);
}
List<ApplyOrder> applyOrderList = new ArrayList<>();
List list = (List) jsonResult.getData();
list.forEach(e ->{
ApplyOrder applyOrder = GSON.fromJson(e.toString(), ApplyOrder.class);
applyOrderList.add(applyOrder);
});
jsonResult.setData(applyOrderList);
return jsonResult;
}
@Override
public JsonResult findFlowChart(String orderNo) {
String logPre="XyqbServiceImpl.findFlowChart";
log.info("{} 流程日志查询 orderNo={}",logPre,orderNo);
String url = xyqbSysUrl + "/ex/inside/customer_sys/query/applyOrder";
if (StringUtils.isEmpty(orderNo)) {
log.error("{} 申请订单号为空 orderNo={}",logPre,orderNo);
return JsonResult.buildErrorStateResult("申请订单号为空",null);
}
Map<String, Object> param = Maps.newHashMap();
param.put("orderNo", orderNo);
Map<String, String> header = Maps.newHashMap();
header.put("Content-type", "application/x-www-form-urlencoded");
JsonResult jsonResult = httpService.post(url, header,param, JsonResult.class);
if(Objects.isNull(jsonResult) || jsonResult.isSuccess()){
log.error("{} 调用信用钱包失败 url={}, header={},param={},result={}",logPre,url, header,param,jsonResult);
return JsonResult.buildErrorStateResult("流程日志查询失败",null);
}
return jsonResult;
}
@Override
public JsonResult findLoanDetail(Long loanId) {
String logPre="XyqbServiceImpl.findLoanDetail";
log.info("{} 提现订单详情 loanId={}",logPre,loanId);
String url = xyqbSysUrl + "/ex/inside/customer_sys/loan/detail";
if (Objects.isNull(loanId)) {
log.error("{} 借款订单号为空 orderNo={}",logPre,loanId);
return JsonResult.buildErrorStateResult("借款订单号为空",null);
}
Map<String, Object> param = Maps.newHashMap();
param.put("loanId", loanId);
Map<String, String> header = Maps.newHashMap();
header.put("Content-type", "application/x-www-form-urlencoded");
JsonResult jsonResult = httpService.post(url, header,param, JsonResult.class);
if(Objects.isNull(jsonResult) || jsonResult.isSuccess()){
log.error("{} 调用信用钱包失败 url={}, header={},param={},result={}",logPre,url, header,param,jsonResult);
return JsonResult.buildErrorStateResult("提现订单详情查询失败",null);
}
//data数据结构 LoanOrderDetail
return jsonResult;
}
} }
package cn.quantgroup.customer.util;
import lombok.extern.slf4j.Slf4j;
import org.apache.commons.lang3.StringUtils;
import org.apache.commons.lang3.exception.ExceptionUtils;
import org.apache.commons.lang3.time.DateUtils;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import java.sql.Timestamp;
import java.text.ParseException;
import java.text.SimpleDateFormat;
import java.time.*;
import java.time.format.DateTimeFormatter;
import java.util.Calendar;
import java.util.Date;
import java.util.Objects;
/**
* Created by conglin.liu on 2017/8/3.
*/
@Slf4j
public class DateUtil {
private static Logger logger = LoggerFactory.getLogger(DateUtil.class);
public final static String DATE_FORMAT_1 = "yyyy-MM-dd HH:mm:ss";
public final static String yyyyMMdd_HHmm = "yyyyMMdd_HHmm";
public final static String YYYYMMDD = "yyyyMMdd";
public final static String YYYYMMDDHHMMSS = "yyyyMMddHHmmss";
public final static String YYYYMMDD_HHMMSS = "yyyyMMdd HHmmss";
public final static String YYYY_MM_DD = "yyyy-MM-dd";
public final static DateTimeFormatter dateTimeFormatter_yyyy_MM_dd = DateTimeFormatter.ofPattern("yyyy-MM-dd");
public final static DateTimeFormatter dateTimeFormatter_yyyyMMdd = DateTimeFormatter.ofPattern("yyyyMMdd");
public final static String date_suffix = "235959";
public final static long THOUSAND = 1000L;
/**
* 某天零时零分零秒到23:59:59 的秒数
*/
public static final long SECOND_OF_DAY = 86399L;
/**
* 获得时间戳(10位,精确到秒)
* @return
*/
public static String getTenTimestamp() {
return String.valueOf(new Timestamp(System.currentTimeMillis()).getTime() / 1000);
}
/**
* 字符串(秒) 转为 Timestamp(10位)
* @param tsStr 2017-06-06 12:00:00 -> 1496721600
* @return
*/
public static Timestamp stringToTimestamp(String tsStr) {
Timestamp ts = new Timestamp(System.currentTimeMillis());
try {
ts = Timestamp.valueOf(tsStr);
} catch (Exception e) {
log.error("e={}", ExceptionUtils.getStackTrace(e));
}
return ts;
}
/**
* 字符串(秒) 转为 Timestamp(10位)
* @param tsStr 2017-06-06 12:00:00 -> 1496721600
* @return
*/
public static Date stringToDate(String tsStr) {
Date date = new Date();
try {
date = new Date(Long.valueOf(tsStr));
} catch (Exception e) {
log.error("e={}", ExceptionUtils.getStackTrace(e));
}
return date;
}
/**
* 数值 毫秒值 转时间
* @param times 时间的毫秒值
* @return
*/
public static Date getByLongTimes(Long times) {
Date date = null;
try {
date = new Date(times);
} catch (Exception e) {
log.error("e={}", ExceptionUtils.getStackTrace(e));
}
return date;
}
/**
* 数值 秒值 转时间
* @param times 时间的毫秒值
* @return
*/
public static Date getBy10LongTimes(Long times) {
return new Date(times * THOUSAND);
}
/**
* 数值 秒值 转时间
* @param times 时间的毫秒值
* @return
*/
public static Date getBy10LongTimes(String times) {
return new Date(Long.valueOf(times) * THOUSAND);
}
/**
* 字符毫秒值 转时间
* @param times 时间的毫秒值
* @return
*/
public static Date getByLongTimes(String times) {
Date date = null;
try {
if (ValidationUtil.isInteger(times)) {
date = new Date(Long.valueOf(times));
}
} catch (Exception e) {
log.error("e={}", ExceptionUtils.getStackTrace(e));
}
return date;
}
/**
* 使用参数Format格式化Date成字符串
*/
public static String format(Date date, String pattern) {
try {
return date == null ? "" : new SimpleDateFormat(pattern).format(date);
} catch (Exception e) {
log.error("[exception]date transfer error,date={},pattern={}",date,pattern);
return "";
}
}
/**
* Date 按格式化后转为Long13
*
* @param date
* @param pattern
* @return
*/
public static Long formatToLong(Date date, String pattern) {
try {
if (date == null) {
return null;
}
SimpleDateFormat format = new SimpleDateFormat(pattern);
String dated = format.format(date);
//转换为Date类
return format.parse(dated).getTime();
} catch (Exception e) {
log.error("[exception]date transfer error,date={},pattern={}",date,pattern);
return null;
}
}
/**
* 获得当天最晚时间戳
*
* @param time
* @return
*/
public static Long getEndOfDay(Long time) {
LocalDateTime localDateTime = LocalDateTime.ofInstant(Instant.ofEpochMilli(time), ZoneId.systemDefault());
LocalDateTime endOfDay = localDateTime.with(LocalTime.MAX);
return Date.from(endOfDay.atZone(ZoneId.systemDefault()).toInstant()).getTime();
}
/**
* 获得当天最开始时间戳
*
* @param time
* @return
*/
public static Long getStartOfDay(Long time) {
LocalDateTime localDateTime = LocalDateTime.ofInstant(Instant.ofEpochMilli(time), ZoneId.systemDefault());
LocalDateTime startOfDay = localDateTime.with(LocalTime.MIN);
return Date.from(startOfDay.atZone(ZoneId.systemDefault()).toInstant()).getTime();
}
/**
* 将yyyy-MM-dd 转成 yyyyMMdd+时分秒
* @param deadline
* @return yyyyMMddHHmmss
*/
public static String getDeadline(String deadline) {
try {
if (StringUtils.isNotBlank(deadline)) {
String date = deadline.replaceAll("-", "").replaceAll("/", "").substring(0, 8);
return date + date_suffix;
} else {
return LocalDateTime.now().format(dateTimeFormatter_yyyyMMdd) + date_suffix;
}
} catch (Exception e) {
return LocalDateTime.now().format(dateTimeFormatter_yyyyMMdd) + date_suffix;
}
}
/**
* 将yyyy-MM-dd 转成 yyyyMMdd+时分秒
* @param deadline
* @return yyyyMMddHHmmss
*/
public static String getDeadline(Date deadline) {
try {
if (deadline != null) {
String date = format(deadline, YYYYMMDD);
return date + date_suffix;
} else {
return LocalDateTime.now().format(dateTimeFormatter_yyyyMMdd) + date_suffix;
}
} catch (Exception e) {
return LocalDateTime.now().format(dateTimeFormatter_yyyyMMdd) + date_suffix;
}
}
/**
* 时间字符串 转换成时间
* @param dateStr 时间字符串
* @param parsePatterns 时间字符串 格式
* @return
*/
public static Date dateStr2Date(String dateStr, String parsePatterns) {
try {
return DateUtils.parseDate(dateStr, parsePatterns);
} catch (ParseException e) {
logger.error("时间转换出错,deadline={},parsePatterns={}", dateStr, parsePatterns, e);
return new Date();
}
}
/**
* 获取当前时间
* @return Timestamp
*/
public static Timestamp getCurrentTimestamp(){
return new Timestamp(System.currentTimeMillis());
}
/**
* 把时间字符串,源格式转换为 目标格式输出
* @param dateStr 时间字符串
* @param dateFormatSource : (source)格式
* @param dateFormatTarget (target)格式
* @return
*/
public static String parse(String dateStr, String dateFormatSource, String dateFormatTarget) {
String dateFormat;
try {
dateFormat = format(dateStr2Date(dateStr, dateFormatSource), dateFormatTarget);
if (StringUtils.isEmpty(dateFormat)) {
logger.error("时间为空,dateStr={},parsePatterns={}", dateStr, dateFormatSource + "2" + dateFormatTarget);
dateFormat = format(new Date(), dateFormatTarget);
}
} catch (Exception e) {
logger.error("时间转换出错,dateStr={},parsePatterns={}", dateStr, dateFormatSource + "2" + dateFormatTarget, e);
dateFormat = format(new Date(), dateFormatTarget);
}
return dateFormat;
}
public static Date monthLater() {
Calendar calendar = Calendar.getInstance();
calendar.setTime(new Date());
calendar.add(Calendar.MONTH, 1);
return new Date(calendar.getTime().getTime());
}
public static Date dayLater() {
Calendar calendar = Calendar.getInstance();
calendar.setTime(new Date());
calendar.add(Calendar.DAY_OF_MONTH, 1);
return new Date(calendar.getTime().getTime());
}
/**
* 根据时间 获取10位 时间戳
* @param updated
* @return
*/
public static Long get10LongTimeFromDate(Date updated) {
if (updated == null) {
return System.currentTimeMillis() / 1000;
} else {
return updated.getTime() / 1000;
}
}
/**
* 根据10位时间戳 获取13位时间戳
* @param dateTime
* @return
*/
public static Long get13LongTimeFormLong(Long dateTime) {
if (dateTime == null) {
return System.currentTimeMillis();
}
return dateTime * 1000;
}
/**
* 判断当前时间是否在[startTime, endTime]区间,注意时间格式要一致
*
* @param nowTime 当前时间
* @param startTime 开始时间
* @param endTime 结束时间
* @return true 在区间,false:不在区间
* @author suntao
*/
public static boolean isEffectiveDate(Date nowTime, Date startTime, Date endTime) {
if (nowTime.getTime() == startTime.getTime()
|| nowTime.getTime() == endTime.getTime()) {
return true;
}
Calendar date = Calendar.getInstance();
date.setTime(nowTime);
Calendar begin = Calendar.getInstance();
begin.setTime(startTime);
Calendar end = Calendar.getInstance();
end.setTime(endTime);
if (date.after(begin) && date.before(end)) {
return true;
} else {
return false;
}
}
/**
*
* @param fromDt 指定时间
* @param termUnit 时间类别 天 月 年
* @param count 时间
* @param beforeOrAfter beforeOrAfter true 往后 false 往前
* @return
*/
public static Date getNextDate(Date fromDt,int termUnit,int count,Boolean beforeOrAfter) {
try {
if (Objects.isNull(fromDt)) {
fromDt = new Date();
}
LocalDate localDate = fromDt.toInstant().atZone(ZoneId.systemDefault()).toLocalDate();
if (!beforeOrAfter) {
count = -count;
}
if (termUnit == Calendar.YEAR) {
return Date.from(localDate.plusYears(count).atStartOfDay(ZoneId.systemDefault()).toInstant());
} else if (termUnit == Calendar.MONTH) {
return Date.from(localDate.plusMonths(count).atStartOfDay(ZoneId.systemDefault()).toInstant());
} else {
return Date.from(localDate.plusDays(count).atStartOfDay(ZoneId.systemDefault()).toInstant());
}
} catch (Exception e) {
log.error("e={}", ExceptionUtils.getStackTrace(e));
return null;
}
}
/**
* 格式化时间转为时间戳
*
* @param strTime 格式化时间
* @param pattern 自定义格式化类型
* @return 13位时间戳
*/
public static Long timeOfStrToLong(String strTime, String pattern){
Long retTime = null;
try {
DateTimeFormatter ftf = DateTimeFormatter.ofPattern(pattern);
LocalDateTime parse = LocalDateTime.parse(strTime, ftf);
retTime = LocalDateTime.from(parse).atZone(ZoneId.systemDefault()).toInstant().toEpochMilli();
} catch (Exception e) {
log.error("e={}", ExceptionUtils.getStackTrace(e));
}
return retTime;
}
/**
* 格式化时间转为时间戳
* 格式为:yyyyMMddHHmmss
*
* @param strTime 格式化时间
* @return 13位时间戳
*/
public static Long timeOfStrToLong(String strTime){
return timeOfStrToLong(strTime, YYYYMMDDHHMMSS);
}
/**
* 获取当前时间字符串
*
* @param format
* @return
*/
public static String getCurrentTimeString(String format) {
// 如果为空,取默认值,如下
if (StringUtils.isEmpty(format)) {
format = YYYYMMDDHHMMSS;
}
DateTimeFormatter dateTimeFormatter = DateTimeFormatter.ofPattern(format);
LocalDateTime now = LocalDateTime.now();
return now.format(dateTimeFormatter);
}
public static void main(String[] args) {
Long dateLong = 1576944000000L;
System.out.println(DateUtil.getEndOfDay(dateLong));
System.out.println(DateUtil.getStartOfDay(1576548826000L));
}
}
package cn.quantgroup.customer.util;
import org.apache.commons.lang3.StringUtils;
import java.text.ParseException;
import java.text.SimpleDateFormat;
import java.util.Calendar;
import java.util.Date;
import java.util.HashMap;
import java.util.Map;
/**
* Created by springning on 15-8-24.
*/
public class IdcardUtils extends StringUtils {
/**
* 中国公民身份证号码最小长度。
*/
private static final int CHINA_ID_MIN_LENGTH = 15;
/**
* 中国公民身份证号码最大长度。
*/
private static final int CHINA_ID_MAX_LENGTH = 18;
/**
* 省、直辖市代码表
*/
private static final String[] CITY_CODE = {
"11", "12", "13", "14", "15", "21", "22", "23", "31", "32", "33", "34", "35", "36", "37", "41",
"42", "43", "44", "45", "46", "50", "51", "52", "53", "54", "61", "62", "63", "64", "65", "71",
"81", "82", "91"
};
/**
* 每位加权因子
*/
private static final int[] POWER = {
7, 9, 10, 5, 8, 4, 2, 1, 6, 3, 7, 9, 10, 5, 8, 4, 2
};
/**
* 第18位校检码
*/
private static final String[] VERIFY_CODE = {
"1", "0", "X", "9", "8", "7", "6", "5", "4", "3", "2"
};
/**
* 最低年限
*/
private static final int MIN = 1930;
private static final Map<String, String> cityCodes = new HashMap<String, String>();
/**
* 台湾身份首字母对应数字
*/
private static final Map<String, Integer> twFirstCode = new HashMap<String, Integer>();
/**
* 香港身份首字母对应数字
*/
private static final Map<String, Integer> hkFirstCode = new HashMap<String, Integer>();
static {
cityCodes.put("11", "北京");
cityCodes.put("12", "天津");
cityCodes.put("13", "河北");
cityCodes.put("14", "山西");
cityCodes.put("15", "内蒙古");
cityCodes.put("21", "辽宁");
cityCodes.put("22", "吉林");
cityCodes.put("23", "黑龙江");
cityCodes.put("31", "上海");
cityCodes.put("32", "江苏");
cityCodes.put("33", "浙江");
cityCodes.put("34", "安徽");
cityCodes.put("35", "福建");
cityCodes.put("36", "江西");
cityCodes.put("37", "山东");
cityCodes.put("41", "河南");
cityCodes.put("42", "湖北");
cityCodes.put("43", "湖南");
cityCodes.put("44", "广东");
cityCodes.put("45", "广西");
cityCodes.put("46", "海南");
cityCodes.put("50", "重庆");
cityCodes.put("51", "四川");
cityCodes.put("52", "贵州");
cityCodes.put("53", "云南");
cityCodes.put("54", "西藏");
cityCodes.put("61", "陕西");
cityCodes.put("62", "甘肃");
cityCodes.put("63", "青海");
cityCodes.put("64", "宁夏");
cityCodes.put("65", "新疆");
cityCodes.put("71", "台湾");
cityCodes.put("81", "香港");
cityCodes.put("82", "澳门");
cityCodes.put("91", "国外");
twFirstCode.put("A", 10);
twFirstCode.put("B", 11);
twFirstCode.put("C", 12);
twFirstCode.put("D", 13);
twFirstCode.put("E", 14);
twFirstCode.put("F", 15);
twFirstCode.put("G", 16);
twFirstCode.put("H", 17);
twFirstCode.put("J", 18);
twFirstCode.put("K", 19);
twFirstCode.put("L", 20);
twFirstCode.put("M", 21);
twFirstCode.put("N", 22);
twFirstCode.put("P", 23);
twFirstCode.put("Q", 24);
twFirstCode.put("R", 25);
twFirstCode.put("S", 26);
twFirstCode.put("T", 27);
twFirstCode.put("U", 28);
twFirstCode.put("V", 29);
twFirstCode.put("X", 30);
twFirstCode.put("Y", 31);
twFirstCode.put("W", 32);
twFirstCode.put("Z", 33);
twFirstCode.put("I", 34);
twFirstCode.put("O", 35);
hkFirstCode.put("A", 1);
hkFirstCode.put("B", 2);
hkFirstCode.put("C", 3);
hkFirstCode.put("R", 18);
hkFirstCode.put("U", 21);
hkFirstCode.put("Z", 26);
hkFirstCode.put("X", 24);
hkFirstCode.put("W", 23);
hkFirstCode.put("O", 15);
hkFirstCode.put("N", 14);
}
/**
* 将15位身份证号码转换为18位
*
* @param idCard 15位身份编码
* @return 18位身份编码
*/
public static String conver15CardTo18(String idCard) {
String idCard18 = "";
if (idCard.length() != CHINA_ID_MIN_LENGTH) {
return null;
}
if (isNum(idCard)) {
// 获取出生年月日
String birthday = idCard.substring(6, 12);
Date birthDate = null;
try {
birthDate = new SimpleDateFormat("yyMMdd").parse(birthday);
} catch (ParseException e) {
}
Calendar cal = Calendar.getInstance();
if (birthDate != null) {
cal.setTime(birthDate);
}
// 获取出生年(完全表现形式,如:2010)
String sYear = String.valueOf(cal.get(Calendar.YEAR));
idCard18 = idCard.substring(0, 6) + sYear + idCard.substring(8);
// 转换字符数组
char[] cArr = idCard18.toCharArray();
if (cArr != null) {
int[] iCard = converCharToInt(cArr);
int iSum17 = getPowerSum(iCard);
// 获取校验位
String sVal = getCheckCode18(iSum17);
if (sVal.length() > 0) {
idCard18 += sVal;
} else {
return null;
}
}
} else {
return null;
}
return idCard18;
}
/**
* 验证身份证是否合法
*/
public static boolean validateCard(String idCard) {
String card = idCard.trim();
if (validateIdCard18(card)) {
return true;
}
if (validateIdCard15(card)) {
return true;
}
String[] cardval = validateIdCard10(card);
if (cardval != null) {
String strTrueLine193 = "true";
int int2Line194 = 2;
if (cardval[int2Line194].equals(strTrueLine193)) {
return true;
}
}
return false;
}
/**
* 验证18位身份编码是否合法
*
* @param idCard 身份编码
* @return 是否合法
*/
public static boolean validateIdCard18(String idCard) {
boolean bTrue = false;
if (idCard.length() == CHINA_ID_MAX_LENGTH) {
// 前17位
String code17 = idCard.substring(0, 17);
// 第18位
String code18 = idCard.substring(17, CHINA_ID_MAX_LENGTH);
if (isNum(code17)) {
char[] cArr = code17.toCharArray();
if (cArr != null) {
int[] iCard = converCharToInt(cArr);
int iSum17 = getPowerSum(iCard);
// 获取校验位
String val = getCheckCode18(iSum17);
if (val.length() > 0) {
if (val.equalsIgnoreCase(code18)) {
bTrue = true;
}
}
}
}
}
return bTrue;
}
/**
* 验证15位身份编码是否合法
*
* @param idCard 身份编码
* @return 是否合法
*/
public static boolean validateIdCard15(String idCard) {
if (idCard.length() != CHINA_ID_MIN_LENGTH) {
return false;
}
if (isNum(idCard)) {
String proCode = idCard.substring(0, 2);
if (cityCodes.get(proCode) == null) {
return false;
}
String birthCode = idCard.substring(6, 12);
Date birthDate = null;
try {
birthDate = new SimpleDateFormat("yy").parse(birthCode.substring(0, 2));
} catch (ParseException e) {
}
Calendar cal = Calendar.getInstance();
if (birthDate != null) {
cal.setTime(birthDate);
}
int int4Line258 = 4;
int int2Line259 = 2;
if (!valiDate(cal.get(Calendar.YEAR), Integer.valueOf(birthCode.substring(int2Line259, int4Line258)),
Integer.valueOf(birthCode.substring(4, 6)))) {
return false;
}
} else {
return false;
}
return true;
}
/**
* 验证10位身份编码是否合法
*
* @param idCard 身份编码
* @return 身份证信息数组
* <p>
* [0] - 台湾、澳门、香港 [1] - 性别(男M,女F,未知N) [2] - 是否合法(合法true,不合法false)
* 若不是身份证件号码则返回null
* </p>
*/
public static String[] validateIdCard10(String idCard) {
String[] info = new String[3];
String reg1 = "[\\(|\\)]";
String card = idCard.replaceAll(reg1, "");
int int10Line284 = 10;
int int8Line285 = 8;
int int9Line286 = 9;
if (card.length() != int8Line285 && card.length() != int9Line286 && idCard.length() != int10Line284) {
return null;
}
String reg2 = "^[a-zA-Z][0-9]{9}$";
String reg3 = "^[1|5|7][0-9]{6}\\(?[0-9A-Z]\\)?$";
String reg4 = "^[A-Z]{1,2}[0-9]{6}\\(?[0-9A]\\)?$";
if (idCard.matches(reg2)) { // 台湾
info[0] = "台湾";
System.out.println("11111");
String char2 = idCard.substring(1, 2);
String str1Line297 = "1";
String str2Line301 = "2";
if (char2.equals(str1Line297)) {
info[1] = "M";
System.out.println("MMMMMMM");
} else if (char2.equals(str2Line301)) {
info[1] = "F";
System.out.println("FFFFFFF");
} else {
info[1] = "N";
info[2] = "false";
System.out.println("NNNN");
return info;
}
info[2] = validateTWCard(idCard) ? "true" : "false";
} else if (idCard.matches(reg3)) { // 澳门
info[0] = "澳门";
info[1] = "N";
// TODO
} else if (idCard.matches(reg4)) { // 香港
info[0] = "香港";
info[1] = "N";
info[2] = validateHKCard(idCard) ? "true" : "false";
} else {
return null;
}
return info;
}
/**
* 验证台湾身份证号码
*
* @param idCard 身份证号码
* @return 验证码是否符合
*/
public static boolean validateTWCard(String idCard) {
String start = idCard.substring(0, 1);
String mid = idCard.substring(1, 9);
String end = idCard.substring(9, 10);
Integer iStart = twFirstCode.get(start);
Integer sum = iStart / 10 + (iStart % 10) * 9;
char[] chars = mid.toCharArray();
Integer iflag = 8;
for (char c : chars) {
sum = sum + Integer.valueOf(c + "") * iflag;
iflag--;
}
return (sum % 10 == 0 ? 0 : (10 - sum % 10)) == Integer.valueOf(end) ? true : false;
}
/**
* 验证香港身份证号码(存在Bug,部份特殊身份证无法检查)
* <p>
* 身份证前2位为英文字符,如果只出现一个英文字符则表示第一位是空格,对应数字58 前2位英文字符A-Z分别对应数字10-35
* 最后一位校验码为0-9的数字加上字符"A","A"代表10
* </p>
* <p>
* 将身份证号码全部转换为数字,分别对应乘9-1相加的总和,整除11则证件号码有效
* </p>
*
* @param idCard 身份证号码
* @return 验证码是否符合
*/
public static boolean validateHKCard(String idCard) {
String card = idCard.replaceAll("[\\(|\\)]", "");
Integer sum = 0;
int int9Line363 = 9;
if (card.length() == int9Line363) {
sum = (Integer.valueOf(card.substring(0, 1).toUpperCase().toCharArray()[0]) - 55) * 9
+ (Integer.valueOf(card.substring(1, 2).toUpperCase().toCharArray()[0]) - 55) * 8;
card = card.substring(1, 9);
} else {
sum = 522 + (Integer.valueOf(card.substring(0, 1).toUpperCase().toCharArray()[0]) - 55) * 8;
}
String mid = card.substring(1, 7);
String end = card.substring(7, 8);
char[] chars = mid.toCharArray();
Integer iflag = 7;
for (char c : chars) {
sum = sum + Integer.valueOf(c + "") * iflag;
iflag--;
}
String strALine379 = "A";
if (end.toUpperCase().equals(strALine379)) {
sum = sum + 10;
} else {
sum = sum + Integer.valueOf(end);
}
return (sum % 11 == 0) ? true : false;
}
/**
* 将字符数组转换成数字数组
*
* @param ca 字符数组
* @return 数字数组
*/
public static int[] converCharToInt(char[] ca) {
int len = ca.length;
int[] iArr = new int[len];
try {
for (int i = 0; i < len; i++) {
iArr[i] = Integer.parseInt(String.valueOf(ca[i]));
}
} catch (NumberFormatException e) {
}
return iArr;
}
/**
* 将身份证的每位和对应位的加权因子相乘之后,再得到和值
*
* @param iArr
* @return 身份证编码。
*/
public static int getPowerSum(int[] iArr) {
int iSum = 0;
if (POWER.length == iArr.length) {
for (int i = 0; i < iArr.length; i++) {
for (int j = 0; j < POWER.length; j++) {
if (i == j) {
iSum = iSum + iArr[i] * POWER[j];
}
}
}
}
return iSum;
}
/**
* 将power和值与11取模获得余数进行校验码判断
*
* @param iSum
* @return 校验位
*/
public static String getCheckCode18(int iSum) {
String sCode = "";
switch (iSum % 11) {
case 10:
sCode = "2";
break;
case 9:
sCode = "3";
break;
case 8:
sCode = "4";
break;
case 7:
sCode = "5";
break;
case 6:
sCode = "6";
break;
case 5:
sCode = "7";
break;
case 4:
sCode = "8";
break;
case 3:
sCode = "9";
break;
case 2:
sCode = "x";
break;
case 1:
sCode = "0";
break;
case 0:
sCode = "1";
break;
default:
}
return sCode;
}
/**
* 根据身份编号获取年龄
*
* @param idCard 身份编号
* @return 年龄
*/
public static int getAgeByIdCard(String idCard) {
int iAge = 0;
if (StringUtils.isEmpty(idCard)) {
return iAge;
}
if (idCard.length() == CHINA_ID_MIN_LENGTH) {
idCard = conver15CardTo18(idCard);
}
if (StringUtils.isEmpty(idCard)) {
return iAge;
}
String year = idCard.substring(6, 10);
Calendar cal = Calendar.getInstance();
int iCurrYear = cal.get(Calendar.YEAR);
iAge = iCurrYear - Integer.valueOf(year);
return iAge;
}
/**
* 根据身份编号获取生日
*
* @param idCard 身份编号
* @return 生日(yyyyMMdd)
*/
public static String getBirthByIdCard(String idCard) {
String iAge = "0";
if (StringUtils.isEmpty(idCard)) {
return iAge;
}
Integer len = idCard.length();
if (len < CHINA_ID_MIN_LENGTH) {
return null;
} else if (len == CHINA_ID_MIN_LENGTH) {
idCard = conver15CardTo18(idCard);
}
if (StringUtils.isEmpty(idCard)) {
return iAge;
}
return idCard.substring(6, 14);
}
/**
* 根据身份编号获取生日年
*
* @param idCard 身份编号
* @return 生日(yyyy)
*/
public static Short getYearByIdCard(String idCard) {
Short s = Short.valueOf("0");
if (StringUtils.isEmpty(idCard)) {
return s;
}
Integer len = idCard.length();
if (len < CHINA_ID_MIN_LENGTH) {
return null;
} else if (len == CHINA_ID_MIN_LENGTH) {
idCard = conver15CardTo18(idCard);
}
if (StringUtils.isEmpty(idCard)) {
return s;
}
return Short.valueOf(idCard.substring(6, 10));
}
/**
* 根据身份编号获取生日月
*
* @param idCard 身份编号
* @return 生日(MM)
*/
public static Short getMonthByIdCard(String idCard) {
Short s = Short.valueOf("0");
if (StringUtils.isEmpty(idCard)) {
return s;
}
Integer len = idCard.length();
if (len < CHINA_ID_MIN_LENGTH) {
return null;
} else if (len == CHINA_ID_MIN_LENGTH) {
idCard = conver15CardTo18(idCard);
}
if (StringUtils.isEmpty(idCard)) {
return s;
}
return Short.valueOf(idCard.substring(10, 12));
}
/**
* 根据身份编号获取生日天
*
* @param idCard 身份编号
* @return 生日(dd)
*/
public static Short getDateByIdCard(String idCard) {
Short s = Short.valueOf("0");
if (StringUtils.isEmpty(idCard)) {
return s;
}
Integer len = idCard.length();
if (len < CHINA_ID_MIN_LENGTH) {
return null;
} else if (len == CHINA_ID_MIN_LENGTH) {
idCard = conver15CardTo18(idCard);
}
if (StringUtils.isEmpty(idCard)) {
return s;
}
return Short.valueOf(idCard.substring(12, 14));
}
/**
* 根据身份编号获取性别
*
* @param idCard 身份编号
* @return 性别(M-男,F-女,N-未知)
*/
public static String getGenderByIdCard(String idCard) {
String def = "N";
if (StringUtils.isEmpty(idCard)) {
return def;
}
String sGender = "N";
if (idCard.length() == CHINA_ID_MIN_LENGTH) {
idCard = conver15CardTo18(idCard);
}
if (StringUtils.isEmpty(idCard)) {
return def;
}
String sCardNum = idCard.substring(16, 17);
int int2Line607 = 2;
if (Integer.parseInt(sCardNum) % int2Line607 != 0) {
sGender = "M";
} else {
sGender = "F";
}
return sGender;
}
/**
* 根据身份编号获取户籍省份
*
* @param idCard 身份编码
* @return 省级编码。
*/
public static String getProvinceByIdCard(String idCard) {
int len = idCard.length();
String sProvince = null;
String sProvinNum = "";
if (len == CHINA_ID_MIN_LENGTH || len == CHINA_ID_MAX_LENGTH) {
sProvinNum = idCard.substring(0, 2);
}
sProvince = cityCodes.get(sProvinNum);
return sProvince;
}
/**
* 数字验证
*
* @param val
* @return 提取的数字。
*/
public static boolean isNum(String val) {
String reg = "^[0-9]*$";
return !(val == null || "".equals(val)) && val.matches(reg);
}
/**
* 验证小于当前日期 是否有效
*
* @param iYear 待验证日期(年)
* @param iMonth 待验证日期(月 1-12)
* @param iDate 待验证日期(日)
* @return 是否有效
*/
public static boolean valiDate(int iYear, int iMonth, int iDate) {
Calendar cal = Calendar.getInstance();
int year = cal.get(Calendar.YEAR);
int datePerMonth;
if (iYear < MIN || iYear >= year) {
return false;
}
int int12Line659 = 12;
if (iMonth < 1 || iMonth > int12Line659) {
return false;
}
switch (iMonth) {
case 4:
case 6:
case 9:
case 11:
datePerMonth = 30;
break;
case 2:
boolean dm = ((iYear % 4 == 0 && iYear % 100 != 0) || (iYear % 400 == 0))
&& (iYear > MIN && iYear < year);
datePerMonth = dm ? 29 : 28;
break;
default:
datePerMonth = 31;
}
return (iDate >= 1) && (iDate <= datePerMonth);
}
}
package cn.quantgroup.customer.util;
import org.apache.commons.lang3.StringUtils;
import org.springframework.beans.BeanWrapper;
import org.springframework.beans.BeanWrapperImpl;
import java.beans.PropertyDescriptor;
import java.lang.reflect.Field;
import java.util.*;
import java.util.regex.Matcher;
import java.util.regex.Pattern;
import static java.util.regex.Pattern.compile;
import static java.util.regex.Pattern.matches;
public class ValidationUtil {
public static boolean validatePhoneNo(String phoneNo) {
if (StringUtils.isEmpty(phoneNo)) {
return false;
}
String regExp = "^1\\d{10}$";
return matches(regExp, phoneNo);
}
public static boolean validateEmail(String email) {
String regexExpress = "\\b^[a-zA-Z0-9][a-zA-Z0-9_\\-\\.]{0,50}@(?:[a-zA-Z0-9\\-]+\\.)+[a-zA-Z]+$\\b";
Matcher matcher = compile(regexExpress).matcher(email);
return matcher.matches();
}
/**
* 校验实体对象属性是否全为null,注意:此方法仅考虑对象属性皆为String类型
* @param obj
* @return true : 全为null
* false : 不全为null
*/
public static boolean isALlNullByObjectField(Object obj, String... excludeFields) {
if (Objects.isNull(obj)) {
return true;
}
List<String> excludeFieldsList = Arrays.asList(excludeFields);
Class<? extends Object> objClass = obj.getClass();
Field[] objField = objClass.getDeclaredFields();
try {
for (int i = 0; i < objField.length; i++) {
Field field = objField[i];
if (excludeFieldsList.contains(field.getName())) {
continue;
}
field.setAccessible(true);
Object fieldValue = field.get(obj);
if (fieldValue != null) {
return false;
}
}
} catch (IllegalAccessException e) {
return false;
}
return true;
}
/**
* 校验实体对象属性是否全不为null,注意:此方法仅考虑对象属性皆为String类型
*
* @param obj
* @return
* true : 全部不为空;
* false : 有空存在
*/
public static boolean isALlNotNullByObjectField(Object obj) throws IllegalArgumentException, IllegalAccessException {
if (Objects.isNull(obj)) {
return false;
}
Class<? extends Object> objClass = obj.getClass();
Field[] objField = objClass.getDeclaredFields();
for (int i = 0; i < objField.length; i++) {
Field field = objField[i];
field.setAccessible(true);
Object fieldValue = field.get(obj);
if (fieldValue != null && fieldValue instanceof String && StringUtils.isNotEmpty((String) fieldValue)) {
} else if (fieldValue != null) {
/**
* 增加一个功能,判断非字符串类型的空判断,目前枚举测试过,没问题
* 如果要用到此功能,请先测试一下,或是进一步优化
*/
} else {
// 只要找到一个为空的字符串,即该对象至少有一个为null、""的属性,返回fasle
return false;
}
}
return true;
}
/**
* 指定字段之外的字段不为空
* @param obj
* @return
* true:全部不为空(exclude : fields)
* false:有空存在(exclude : fields)
*/
public static boolean isNotNullExclusionFields(Object obj, String[] fields) {
if (Objects.isNull(obj)) {
return false;
}
List<String> fieldsList = Arrays.asList(fields);
Class<? extends Object> objClass = obj.getClass();
Field[] objField = objClass.getDeclaredFields();
try {
for (int i = 0; i < objField.length; i++) {
Field field = objField[i];
if (fieldsList.contains(field.getName())) {
// fields 中的属性 不判断
continue;
}
field.setAccessible(true);
Object fieldValue = field.get(obj);
if (fieldValue != null && fieldValue instanceof String && StringUtils.isNotEmpty((String) fieldValue)) {
} else if (fieldValue != null) {
/**
* 增加一个功能,判断非字符串类型的空判断,目前枚举测试过,没问题
* 如果要用到此功能,请先测试一下,或是进一步优化
*/
} else {
// 只要找到一个为空的字符串,即该对象至少有一个为null、""的属性,返回fasle
return false;
}
}
} catch (IllegalAccessException e) {
return false;
}
return true;
}
/**
* 方法二:推荐,速度最快
* 判断是否为整数
*
* @param str 传入的字符串
* @return 是整数返回true, 否则返回false
*/
public static boolean isInteger(String str) {
Pattern pattern = compile("^[-\\+]?[\\d]*$");
return pattern.matcher(str).matches();
}
public static <T> boolean checkEmpty(T... objects) {
if (null == objects) {
return true;
}
for (T object : objects) {
if (object instanceof String && StringUtils.isEmpty((String) object)) {
return true;
}
if (null == object) {
return true;
}
}
return false;
}
/**
* @Title: getNullPropertyNames
* @Description: 获取值为空的属性名称
* @createdBy:byrc
*/
public static String[] getNullPropertyNames(Object source) {
BeanWrapper src = new BeanWrapperImpl(source);
PropertyDescriptor[] pds = src.getPropertyDescriptors();
Set<String> emptyNames = new HashSet<String>();
for (PropertyDescriptor pd : pds) {
Object srcValue = src.getPropertyValue(pd.getName());
if (srcValue == null) {
emptyNames.add(pd.getName());
}
if (srcValue instanceof String && StringUtils.isEmpty(String.valueOf(srcValue))) {
emptyNames.add(pd.getName());
}
}
String[] result = new String[emptyNames.size()];
return emptyNames.toArray(result);
}
}
\ No newline at end of file
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