主方法处理:
@Resource(name = "dateLimit")
private DateLimit dateLimit;
public boolean preactRepaymentRdTx(final String flowCode, final BigDecimal serviceFee, final BigDecimal amount, final BigDecimal defaultAmount, final List payer, RepayChannelEnum channel) throws BusinessException {
Date now = new Date();
Date beforeDate = new Date();
try {
beforeDate = dateLimit.dealTimeBeforeLimit(now);
} catch (Exception e) {
}
Date afterDate = new Date();
try {
afterDate = dateLimit.dealTimeAfterLimit(now);
} catch (Exception e) {
}
// 0点前后5分钟停止交易
if (beforeDate.before(afterDate)) {
if ((now.after(beforeDate) || now.compareTo(beforeDate) == 0) && (now.before(afterDate) || now.compareTo(afterDate) == 0)) {
logger.error("限定时间内停止交易,禁止调用系统接口!");
throw new BusinessException("限定时间内停止交易,禁止调用系统接口!");
} else {
//逻辑处理
} else if (beforeDate.after(afterDate)) {
if (now.after(afterDate) && now.before(beforeDate)) {
//逻辑处理
} else {
logger.error("限定时间内停止交易,禁止调用系统接口!");
throw new BusinessException("限定时间内停止交易,禁止调用系统接口!");
}
} else {
return this.preactRepayment(flowCode, serviceFee, amount, defaultAmount, payer, channel);
}
}
调用的方法:
String getItemFinancialTimeLimit = 17:00:00-00:20:00 //跨天设置限制(
当天限时17:00:00到第二天
00:20:00
不能交易
)
String getItemFinancialTimeLimit = 17:00:00-18:20:00 //当天设置限制(当天限时17:00:00-18:20:00不能交易)
public Date dealTimeBeforeLimit(Date dealTime) throws Exception {
SimpleDateFormat sdf = new SimpleDateFormat("yyyy-MM-dd HH:mm:ss");
Calendar cal = Calendar.getInstance();
cal.setTime(dealTime);
int year = cal.get(Calendar.YEAR);// 获取年份
int month = cal.get(Calendar.MONTH) + 1;// 获取月份
int day = cal.get(Calendar.DATE);// 获取日
// "2012-1-13 23:55:00"
String timeBeforeLimitStr = sysConfig.getItemFinancialTimeLimit(); // "23:55:00";
String[] strs = timeBeforeLimitStr.split("-");
String str = strs[0];
str = year + "-" + month + "-" + day + " " + timeBeforeLimitStr; // 要跟上面sdf定义的格式一样
Date date = sdf.parse(str);
return date;
}
public Date dealTimeAfterLimit(Date dealTime) throws Exception {
SimpleDateFormat sdf = new SimpleDateFormat("yyyy-MM-dd HH:mm:ss");
Calendar cal = Calendar.getInstance();
cal.setTime(dealTime);
int year = cal.get(Calendar.YEAR);// 获取年份
int month = cal.get(Calendar.MONTH) + 1;// 获取月份
int day = cal.get(Calendar.DATE);// 获取日
// "2012-1-13 17:26:33"
String timeAfterLimitStr = sysConfig.getItemFinancialTimeLimit(); // "00:05:00";
String[] strs = timeAfterLimitStr.split("-");
String str2 = strs[1];
str2 = year + "-" + month + "-" + day + " " + str2; // 要跟上面sdf定义的格式一样
Date date2 = sdf.parse(str2);
// 判断参数平台配置是不是同一天段时间
return date2;
}