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);
} }
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;
}
} }
This diff is collapsed.
This diff is collapsed.
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