LocalDateTime运算案例,以及参考网站

@Override
    @Transactional(rollbackFor = RuntimeException.class)
    public Result<Object> fixedTicketAutoRecovery() {
        boolean isLock = redisLockService.lock(Const.FIXED_TICKET, 20);
        try {
            if (isLock) {
                LocalDateTime nowTime = LocalDateTime.now();
                // 将固定码表当中数据全部进行查出,然后比较该固定码是否已经过期
                QueryWrapper<FixedCode> fixedCodeQueryWrapper = new QueryWrapper<>();
                fixedCodeQueryWrapper.eq("status", STATUS);
                fixedCodeQueryWrapper.le("valid_end_time", nowTime);
                List<FixedCode> fixedCodes = fixedCodeDao.selectList(fixedCodeQueryWrapper);
                // 对过期固定码进行过滤筛选处理
                if (!fixedCodes.isEmpty()) {
                    for (FixedCode fixedCode : fixedCodes) {
                        // 联查判断该商户的优惠券过期处理是不是可以进行过期回收(0:回收、1:不回收)
                        ShopTicket shopTicketBean = shopTicketService.getById(fixedCode.getShopTicketId());
                        // 根据商户ID进行查询出相关的过期回收属性
                        Shop shopBean = shopService.getById(shopTicketBean.getShopId());
                        if (shopBean.getTicketOverdueProcessingWay() == 0) {
                            // 条件满足则该固定二维码已经过期
                            Integer total = fixedCode.getTotal();
                            Integer balance = fixedCode.getBalance();

                            // 对固定码数据进行过期处理
                            Integer updateTotal = total - balance;
                            fixedCode.setTotal(updateTotal);
                            fixedCode.setBalance(0);
                            fixedCode.setStatus(1);
                            fixedCodeDao.updateById(fixedCode);

                            // 对商户优惠券进行处理
                            ShopTicket shopTicket = shopTicketService.getById(fixedCode.getShopTicketId());
                            Integer updateBalance = shopTicket.getBalance() + balance;
                            shopTicket.setBalance(updateBalance);
                            shopTicketService.updateById(shopTicket);
                        }
                    }
                }
                return Result.modifyReturn(true, "固定码过期处理成功");
            }
            return Result.error();
        } finally {
            boolean unlock = redisLockService.unlock(Const.FIXED_TICKET);
            if (!unlock) {
                ExceptionUtils.sendRequestInfo("2.0固定码优惠券自动回收解锁失败", new StringBuilder());
            }
        }

// 这一行代码是新增优化的代码
DateTimeFormatter dateTimeFormatter1 = DateTimeFormatter.ofPattern(“yyyy-MM-dd HH:mm:ss”);

// 将两个参数从字符串转化为LocalDateTime类型
LocalDateTime parseStopStartDate = LocalDateTime.parse(param.getStopStartDate(), dateTimeFormatter1);
LocalDateTime parseStopEndtDate = LocalDateTime.parse(param.getStopEndDate(),dateTimeFormatter1);
Duration duration = Duration.between(parseStopStartDate, parseStopEndtDate);
long toDays = duration.toDays();
// 将到期时间往后推toDays天
LocalDateTime endTime = LocalDateTime.parse(param.getEndTime(), dateTimeFormatter1);
endTime.plusDays(toDays);
// 再将endTime转化为字符串然后存到param里面
String endTimeStr = dateTimeFormatter1.format(endTime);
param.setEndTime(endTimeStr);

LocalDateTime :算数操作参考

public class Main {
    public static void main(String[] args) {
        LocalDateTime dt = LocalDateTime.of(2019, 10, 26, 20, 30, 59);
        System.out.println(dt);
        // 加5天减3小时:
        LocalDateTime dt2 = dt.plusDays(5).minusHours(3);
        System.out.println(dt2); // 2019-10-31T17:30:59
        // 减1月:
        LocalDateTime dt3 = dt2.minusMonths(1);
        System.out.println(dt3); // 2019-09-30T17:30:59
    }
}

参考网站:
https://www.liaoxuefeng.com/wiki/1252599548343744/1303871087444002

  • 0
    点赞
  • 1
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

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

余额充值