| | |
| | | import cn.afterturn.easypoi.excel.entity.ExportParams; |
| | | import cn.afterturn.easypoi.excel.entity.ImportParams; |
| | | import cn.afterturn.easypoi.excel.entity.TemplateExportParams; |
| | | import cn.hutool.core.collection.CollUtil; |
| | | import cn.hutool.core.util.PhoneUtil; |
| | | import cn.hutool.core.io.resource.ClassPathResource; |
| | | import com.baomidou.mybatisplus.core.conditions.update.UpdateWrapper; |
| | |
| | | private MessageSource messageSource; |
| | | |
| | | private static final Pattern CHINESE_PATTERN = Pattern.compile("\\p{IsHan}"); |
| | | private static final long INVITATION_CODE_LIMIT = 500L; |
| | | |
| | | @ApiOperation(value = "邀请码管理分页列表",response = XpInvitationCode.class) |
| | | @PostMapping("/api/v1/invitation/pageList") |
| | |
| | | @ApiOperation(value = "生成邀请码") |
| | | @Transactional |
| | | public R add(@RequestBody InvitationAddDto dto){ |
| | | long existing = xpInvitationCodeService.count(); |
| | | long incoming = Arrays.stream(Optional.ofNullable(dto.getPhones()).orElse("").split(",")) |
| | | .map(String::trim) |
| | | .filter(StringUtils::hasLength) |
| | | .count(); |
| | | if (existing >= INVITATION_CODE_LIMIT || existing + incoming > INVITATION_CODE_LIMIT) { |
| | | String msg = messageSource.getMessage(I18nKeyConstant.INVITATION_LIMIT_EXCEEDED, |
| | | new Object[]{INVITATION_CODE_LIMIT, existing, incoming}, |
| | | I18nKeyConstant.INVITATION_LIMIT_EXCEEDED, |
| | | LocaleContextHolder.getLocale()); |
| | | return R.fail(msg); |
| | | } |
| | | return xpInvitationCodeService.add(dto.getPhones()); |
| | | } |
| | | /** |
| | |
| | | } |
| | | if (CollectionUtils.isEmpty(invitationCodeImportExcels)) { |
| | | return R.fail(messageSource.getMessage(I18nKeyConstant.INVITATION_IMPORT_DATA_EMPTY, null, I18nKeyConstant.INVITATION_IMPORT_DATA_EMPTY, LocaleContextHolder.getLocale())); |
| | | } |
| | | |
| | | long existing = xpInvitationCodeService.count(); |
| | | long incoming = invitationCodeImportExcels.size(); |
| | | if (existing >= INVITATION_CODE_LIMIT || existing + incoming > INVITATION_CODE_LIMIT) { |
| | | String msg = messageSource.getMessage(I18nKeyConstant.INVITATION_LIMIT_EXCEEDED, |
| | | new Object[]{INVITATION_CODE_LIMIT, existing, incoming}, |
| | | I18nKeyConstant.INVITATION_LIMIT_EXCEEDED, |
| | | LocaleContextHolder.getLocale()); |
| | | return R.fail(msg); |
| | | } |
| | | |
| | | // 批量校验:账号必须为手机号;邀请码不能为空且不能包含中文;同时校验文件内重复/数据库已存在 |
| | |
| | | xpInvitationCodeService.removeBatchByIds(longs); |
| | | return R.ok(); |
| | | } |
| | | |
| | | |
| | | @ApiOperation(value = "校验生成邀请码的手机号是否合法") |
| | | @PostMapping("/api/v1/invitation/validateCode") |
| | | public R<Boolean> validateCode(@RequestParam String phone){ |
| | | if (!PhoneUtil.isMobile(phone)){ |
| | | return R.ok(false); |
| | | } |
| | | List<XpInvitationCode> existsList = xpInvitationCodeService.lambdaQuery() |
| | | .in(XpInvitationCode::getBindAccount, phone) |
| | | .list(); |
| | | return R.ok(CollUtil.isEmpty(existsList)); |
| | | } |
| | | } |