限时交易(可以跨天设置)

主方法处理:
@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;

}

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包

打赏作者

damoneric_guo

你的鼓励将是我创作的最大动力

¥1 ¥2 ¥4 ¥6 ¥10 ¥20
扫码支付:¥1
获取中
扫码支付

您的余额不足,请更换扫码支付或充值

打赏作者

实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值