| | |
| | | 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.DesensitizedUtil; |
| | | import cn.hutool.core.util.PhoneUtil; |
| | | import cn.hutool.core.io.resource.ClassPathResource; |
| | | import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper; |
| | | import com.baomidou.mybatisplus.core.conditions.update.UpdateWrapper; |
| | | import com.xiaopeng.api.dto.account.UcUserInfo; |
| | | import com.xiaopeng.api.feignClient.account.SysGroupMenuClient; |
| | | import com.xiaopeng.api.feignClient.account.UserResourcesClient; |
| | | import com.xiaopeng.api.model.operation.XpInvitationCode; |
| | | import com.xiaopeng.api.model.operation.XpWhitelist; |
| | | import com.xiaopeng.api.vo.account.LoginUser; |
| | | import com.xiaopeng.common.core.domain.R; |
| | | import com.xiaopeng.common.core.exception.ServiceException; |
| | | import com.xiaopeng.common.core.utils.DateUtils; |
| | | import com.xiaopeng.common.core.utils.SensitiveDataCryptoUtil; |
| | | import com.xiaopeng.common.core.utils.WebUtils; |
| | | import com.xiaopeng.common.core.web.page.PageInfo; |
| | | import com.xiaopeng.common.log.annotation.AdminOperationLog; |
| | | import com.xiaopeng.common.log.enums.AdminBusinessType; |
| | | import com.xiaopeng.common.log.enums.AdminOperationType; |
| | | import com.xiaopeng.common.security.service.TokenService; |
| | | import com.xiaopeng.operation.constant.I18nKeyConstant; |
| | | import com.xiaopeng.operation.dto.InvitationAddDto; |
| | | import com.xiaopeng.operation.exportExcle.XpInvitationCodeExportExcel; |
| | |
| | | import io.swagger.annotations.*; |
| | | import lombok.extern.slf4j.Slf4j; |
| | | import org.apache.poi.ss.usermodel.Workbook; |
| | | import org.apache.shardingsphere.transaction.annotation.ShardingSphereTransactionType; |
| | | import org.apache.shardingsphere.transaction.core.TransactionType; |
| | | import org.springframework.beans.factory.annotation.Autowired; |
| | | import org.springframework.context.MessageSource; |
| | | import org.springframework.context.i18n.LocaleContextHolder; |
| | | import org.springframework.transaction.annotation.Transactional; |
| | |
| | | import java.util.*; |
| | | import java.util.stream.Collectors; |
| | | import java.util.regex.Pattern; |
| | | import com.xiaopeng.common.log.annotation.AdminOperationLog; |
| | | import com.xiaopeng.common.log.enums.AdminBusinessType; |
| | | import com.xiaopeng.common.log.enums.AdminOperationType; |
| | | |
| | | /** |
| | | * <p> |
| | |
| | | private IXpWhitelistService xpWhitelistService; |
| | | @Resource |
| | | private MessageSource messageSource; |
| | | @Resource |
| | | private SysGroupMenuClient groupMenuClient; |
| | | @Resource |
| | | private TokenService tokenService; |
| | | @Autowired |
| | | private UserResourcesClient userResourcesClient; |
| | | |
| | | private static final Pattern CHINESE_PATTERN = Pattern.compile("\\p{IsHan}"); |
| | | private static final long INVITATION_CODE_LIMIT = 500L; |
| | | |
| | | @ApiOperation(value = "邀请码管理分页列表",response = XpInvitationCode.class) |
| | | @ApiOperation(value = "邀请码管理分页列表", response = XpInvitationCode.class) |
| | | @PostMapping("/api/v1/invitation/pageList") |
| | | public R<PageInfo<XpInvitationCode>> pageList(@RequestBody InvitationPageListQuery query) { |
| | | LoginUser loginUser = tokenService.getLoginUser(); |
| | | PageInfo<XpInvitationCode> pageList = xpInvitationCodeService.pageList(query); |
| | | if(!loginUser.getPhoneDesensitizationExempt()){ |
| | | pageList.getRecords().forEach(s -> s.setBindAccount(DesensitizedUtil.mobilePhone(s.getBindAccount()))); |
| | | } |
| | | return R.ok(pageList); |
| | | } |
| | | |
| | | /** |
| | | * 生成邀请码 |
| | | */ |
| | | @PostMapping("/api/v1/invitation/add") |
| | | @ResponseBody |
| | | @ApiOperation(value = "生成邀请码") |
| | | @Transactional |
| | | @AdminOperationLog( |
| | | businessType = AdminBusinessType.INVITATION_CODE_MANAGEMENT, |
| | | operationType = AdminOperationType.ADD, |
| | | content = "生成邀请码", |
| | | appendRequestData = true |
| | | ) |
| | | 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()); |
| | | } |
| | | |
| | | /** |
| | | * 解绑 |
| | | */ |
| | |
| | | @ApiImplicitParams({ |
| | | @ApiImplicitParam(value = "id", name = "id", dataType = "Long", required = true) |
| | | }) |
| | | @AdminOperationLog( |
| | | businessType = AdminBusinessType.INVITATION_CODE_MANAGEMENT, |
| | | operationType = AdminOperationType.EDIT, |
| | | contentExpression = "'解绑邀请码,id=' + #p0", |
| | | appendRequestData = false |
| | | ) |
| | | public R unbind(@RequestParam("id") Long id){ |
| | | UpdateWrapper<XpInvitationCode> xpInvitationCodeUpdateWrapper = new UpdateWrapper<>(); |
| | | xpInvitationCodeUpdateWrapper.eq("id",id); |
| | | xpInvitationCodeUpdateWrapper.set("status",3); |
| | | xpInvitationCodeUpdateWrapper.eq("id", id); |
| | | xpInvitationCodeUpdateWrapper.set("status", 3); |
| | | xpInvitationCodeUpdateWrapper.set("bind_account", null); |
| | | xpInvitationCodeService.update(xpInvitationCodeUpdateWrapper); |
| | | return R.ok(); |
| | | } |
| | | |
| | | @ApiOperation(value = "邀请码导入模板下载") |
| | | @GetMapping("/api/v1/invitation/import-template") |
| | | public void importTemplate() { |
| | |
| | | } |
| | | } |
| | | } |
| | | |
| | | @ApiOperation(value = "邀请码导入") |
| | | @PostMapping("/base/v1/invitation/importExcel") |
| | | public R<String> importExcel(@RequestPart("file") MultipartFile file) { |
| | | @AdminOperationLog( |
| | | businessType = AdminBusinessType.INVITATION_CODE_MANAGEMENT, |
| | | operationType = AdminOperationType.IMPORT, |
| | | content = "导入邀请码", |
| | | appendRequestData = false |
| | | ) |
| | | public R<String> importExcel(@RequestParam("file") MultipartFile file) { |
| | | ImportParams params = new ImportParams(); |
| | | params.setHeadRows(1); //表头行数 |
| | | InputStream inputStream = null; |
| | |
| | | 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); |
| | | } |
| | | |
| | | // 批量校验:账号必须为手机号;邀请码不能为空且不能包含中文;同时校验文件内重复/数据库已存在 |
| | | List<String> errors = new ArrayList<>(); |
| | | Set<String> importCodes = new HashSet<>(); |
| | |
| | | |
| | | if (!StringUtils.hasLength(bindAccount)) { |
| | | errors.add(messageSource.getMessage(I18nKeyConstant.INVITATION_IMPORT_ACCOUNT_EMPTY, new Object[]{rowNum}, I18nKeyConstant.INVITATION_IMPORT_ACCOUNT_EMPTY, LocaleContextHolder.getLocale())); |
| | | } else if (!PhoneUtil.isPhone(bindAccount)) { |
| | | } else if (!PhoneUtil.isMobile(bindAccount)) { |
| | | errors.add(messageSource.getMessage(I18nKeyConstant.INVITATION_IMPORT_ACCOUNT_INVALID, new Object[]{rowNum, bindAccount}, I18nKeyConstant.INVITATION_IMPORT_ACCOUNT_INVALID, LocaleContextHolder.getLocale())); |
| | | } |
| | | |
| | |
| | | } |
| | | |
| | | if (!errors.isEmpty()) { |
| | | return R.fail(messageSource.getMessage(I18nKeyConstant.INVITATION_IMPORT_VALIDATE_FAIL, new Object[]{String.join("\n", errors)},I18nKeyConstant.INVITATION_IMPORT_VALIDATE_FAIL, LocaleContextHolder.getLocale())); |
| | | return R.fail(messageSource.getMessage(I18nKeyConstant.INVITATION_IMPORT_VALIDATE_FAIL, new Object[]{String.join("\n", errors)}, I18nKeyConstant.INVITATION_IMPORT_VALIDATE_FAIL, LocaleContextHolder.getLocale())); |
| | | } |
| | | |
| | | List<XpInvitationCode> addList = new ArrayList<>(); |
| | |
| | | XpInvitationCode xpInvitationCode = new XpInvitationCode(); |
| | | xpInvitationCode.setInvitationCode(locationExcel.getInvitationCode()); |
| | | xpInvitationCode.setBindAccount(locationExcel.getBindAccount()); |
| | | if (StringUtils.hasLength(locationExcel.getBindTime())){ |
| | | if (StringUtils.hasLength(locationExcel.getBindTime())) { |
| | | String replace = locationExcel.getBindTime().replace(".", "-"); |
| | | String res = replace.replace("/", "-"); |
| | | locationExcel.setBindTime(res); |
| | | } |
| | | |
| | | xpInvitationCode.setBindTime(DateUtils.stringToLocalDateTime(locationExcel.getBindTime())); |
| | | xpInvitationCode.setStatus(2); |
| | | UcUserInfo userByMobile = userResourcesClient.getUserByMobile(locationExcel.getBindAccount()); |
| | | if(null == userByMobile || StringUtils.isEmpty(userByMobile.getUid())){ |
| | | throw new ServiceException("手机号"+locationExcel.getBindAccount()+"查询用户失败"); |
| | | } |
| | | XpWhitelist xpWhitelist = new XpWhitelist(); |
| | | xpWhitelist.setAccount(locationExcel.getBindAccount()); |
| | | xpWhitelist.setAccount(SensitiveDataCryptoUtil.encrypt(locationExcel.getBindAccount())); |
| | | xpWhitelist.setNickName(userByMobile.getNickName()); |
| | | xpWhitelist.setAppUserId(userByMobile.getUid()); |
| | | xpWhitelist.setStatus(true); |
| | | xpWhitelist.setIsPriorityDispatch(false); |
| | | xpWhitelist.setWhitelistSource(2); |
| | |
| | | } |
| | | return CHINESE_PATTERN.matcher(value).find(); |
| | | } |
| | | |
| | | @ApiOperation(value = "邀请码导出") |
| | | @PostMapping(value = "/api/v1/invitation/exportExcel") |
| | | @AdminOperationLog( |
| | | businessType = AdminBusinessType.INVITATION_CODE_MANAGEMENT, |
| | | operationType = AdminOperationType.EXPORT, |
| | | content = "导出邀请码", |
| | | appendRequestData = true |
| | | ) |
| | | public void exportExcel(@RequestBody InvitationPageListQuery query) { |
| | | List<XpInvitationCode> list = xpInvitationCodeService.exportList(query); |
| | | List<XpInvitationCodeExportExcel> xpWhitelistExportExcels = new ArrayList<>(); |
| | |
| | | } |
| | | |
| | | } |
| | | |
| | | /** |
| | | * 批量删除 |
| | | */ |
| | | @GetMapping("/api/v1/invitation/deleteByIds") |
| | | @ResponseBody |
| | | @ApiOperation(value = "批量删除") |
| | | @AdminOperationLog( |
| | | businessType = AdminBusinessType.INVITATION_CODE_MANAGEMENT, |
| | | operationType = AdminOperationType.DELETE, |
| | | contentExpression = "'批量删除邀请码,ids=' + #p0", |
| | | appendRequestData = false |
| | | ) |
| | | public R deleteByIds(String ids){ |
| | | // 再转化为Long类型 |
| | | List<Long> longs = Arrays.stream(ids.split(",")).map(Long::parseLong).collect(Collectors.toList()); |
| | | List<XpInvitationCode> xpInvitationCodes = xpInvitationCodeService.listByIds(longs); |
| | | for (XpInvitationCode xpInvitationCode : xpInvitationCodes) { |
| | | XpWhitelist one = xpWhitelistService.getOne(new QueryWrapper<XpWhitelist>().eq("whitelist_source", 2) |
| | | .eq("status", 1).eq("is_deleted", 0) |
| | | .eq("account", SensitiveDataCryptoUtil.encrypt(xpInvitationCode.getBindAccount())).last(" limit 1")); |
| | | if(null != one){ |
| | | xpWhitelistService.removeById(one); |
| | | } |
| | | } |
| | | xpInvitationCodeService.removeBatchByIds(longs); |
| | | return R.ok(); |
| | | } |
| | | |
| | | |
| | | @ApiOperation(value = "校验生成邀请码的手机号是否合法") |
| | | @GetMapping("/api/v1/invitation/validateCode") |
| | | public R<List<String>> validateCode(@RequestParam String phone) { |
| | | List<String> phoneList = Arrays.asList(phone.split(",")); |
| | | List<String> existPhones = phoneList.stream().filter(item -> xpInvitationCodeService.lambdaQuery() |
| | | .in(XpInvitationCode::getBindAccount, item) |
| | | .count() > 0).collect(Collectors.toList()); |
| | | return R.ok(existPhones); |
| | | } |
| | | } |