| | |
| | | private static final Integer USE_RECORD_TYPE_EXCHANGE = 1; |
| | | private static final Integer USE_RECORD_TYPE_CONSUME = 2; |
| | | private static final Integer USE_RECORD_TYPE_REFUND = 3; |
| | | private static final String EXPIRE_INVALID_REASON = "领取截止日期已过期"; |
| | | private static final DateTimeFormatter BATCH_FORMATTER = DateTimeFormatter.ofPattern("yyyyMMddHHmmss"); |
| | | |
| | | @Resource |
| | |
| | | } |
| | | |
| | | @Override |
| | | public void updatePackageStatus(Long id, Integer status) { |
| | | if (id == null) { |
| | | throw new ServiceException("卡包ID不能为空"); |
| | | } |
| | | if (!STATUS_ENABLE.equals(status) && !STATUS_DISABLE.equals(status)) { |
| | | throw new ServiceException("启用状态不正确"); |
| | | } |
| | | TExchangeCodePackage old = this.getById(id); |
| | | if (old == null) { |
| | | throw new ServiceException("卡包不存在"); |
| | | } |
| | | TExchangeCodePackage entity = new TExchangeCodePackage(); |
| | | entity.setId(id); |
| | | entity.setStatus(status); |
| | | this.updateById(entity); |
| | | } |
| | | |
| | | @Override |
| | | public void refreshExpiredPackageCodes() { |
| | | List<TExchangeCodePackage> expiredPackages = this.list(new QueryWrapper<TExchangeCodePackage>() |
| | | .isNotNull("expire_time") |
| | | .lt("expire_time", LocalDateTime.now()) |
| | | .eq("del_flag", 0)); |
| | | for (TExchangeCodePackage exchangePackage : expiredPackages) { |
| | | refreshExpiredPackageCodes(exchangePackage.getId()); |
| | | } |
| | | } |
| | | |
| | | @Override |
| | | @Transactional(rollbackFor = Exception.class) |
| | | public void deletePackage(String ids) { |
| | | if (!StringUtils.hasText(ids)) { |
| | |
| | | if (entity == null) { |
| | | throw new ServiceException("卡包不存在"); |
| | | } |
| | | refreshExpiredPackageCodes(id); |
| | | refreshPackageStats(id); |
| | | entity = this.getById(id); |
| | | ExchangeCodePackageDetailVO detailVO = new ExchangeCodePackageDetailVO(); |
| | |
| | | |
| | | @Override |
| | | public PageInfo<ExchangeCodeDetailVO> codePage(ExchangeCodeDetailQuery query) { |
| | | refreshExpiredPackageCodes(query.getPackageId()); |
| | | PageInfo<ExchangeCodeDetailVO> pageInfo = new PageInfo<>(query.getPageCurr(), query.getPageSize()); |
| | | List<ExchangeCodeDetailVO> records = codeDetailMapper.pageList(pageInfo, query); |
| | | pageInfo.setRecords(records); |
| | |
| | | |
| | | @Override |
| | | public List<ExchangeCodeDetailVO> exportCodes(ExchangeCodeDetailQuery query) { |
| | | refreshExpiredPackageCodes(query.getPackageId()); |
| | | return codeDetailMapper.exportList(query); |
| | | } |
| | | |
| | |
| | | throw new ServiceException("卡包已下架"); |
| | | } |
| | | if (exchangePackage.getExpireTime() != null && exchangePackage.getExpireTime().isBefore(LocalDateTime.now())) { |
| | | refreshExpiredPackageCodes(exchangePackage.getId()); |
| | | throw new ServiceException("已失效"); |
| | | } |
| | | if (Objects.equals(detail.getStatus(), CODE_STATUS_INVALID)) { |
| | |
| | | this.baseMapper.updateById(entity); |
| | | } |
| | | |
| | | private void refreshExpiredPackageCodes(Long packageId) { |
| | | if (packageId == null) { |
| | | return; |
| | | } |
| | | TExchangeCodePackage exchangePackage = this.getById(packageId); |
| | | if (exchangePackage == null || exchangePackage.getExpireTime() == null |
| | | || !exchangePackage.getExpireTime().isBefore(LocalDateTime.now())) { |
| | | return; |
| | | } |
| | | TExchangeCodeDetail detail = new TExchangeCodeDetail(); |
| | | detail.setStatus(CODE_STATUS_INVALID); |
| | | detail.setInvalidTime(LocalDateTime.now()); |
| | | detail.setInvalidReason(EXPIRE_INVALID_REASON); |
| | | codeDetailMapper.update(detail, new QueryWrapper<TExchangeCodeDetail>() |
| | | .eq("package_id", packageId) |
| | | .eq("status", CODE_STATUS_UNBOUND) |
| | | .eq("del_flag", 0)); |
| | | refreshPackageStats(packageId); |
| | | } |
| | | |
| | | private String generateCode(Long packageId, int seq) { |
| | | return "CD" + packageId + LocalDateTime.now().format(DateTimeFormatter.ofPattern("yyMMddHHmmss")) + String.format("%03d", seq); |
| | | } |