| | |
| | | import cn.afterturn.easypoi.excel.ExcelImportUtil; |
| | | import cn.afterturn.easypoi.excel.entity.ExportParams; |
| | | import cn.afterturn.easypoi.excel.entity.ImportParams; |
| | | import cn.hutool.core.util.DesensitizedUtil; |
| | | import cn.hutool.core.util.PhoneUtil; |
| | | import cn.hutool.json.JSONObject; |
| | | import cn.hutool.core.util.PhoneUtil; |
| | | import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper; |
| | | import com.xiaopeng.api.feignClient.account.SysGroupMenuClient; |
| | | import com.xiaopeng.api.model.account.SysUser; |
| | | import com.xiaopeng.api.model.operation.XpWhitelist; |
| | | import com.xiaopeng.api.model.operation.XpWhitelistOperlog; |
| | | 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.SensitiveDataCryptoUtil; |
| | | import com.xiaopeng.common.core.utils.WebUtils; |
| | | import com.xiaopeng.common.core.utils.bean.BeanUtils; |
| | | import com.xiaopeng.common.core.utils.ip.IpUtils; |
| | |
| | | import com.xiaopeng.operation.query.WhitelistPageListQuery; |
| | | import com.xiaopeng.operation.service.IXpWhitelistOperlogService; |
| | | import com.xiaopeng.operation.service.IXpWhitelistService; |
| | | import com.xiaopeng.operation.vo.XpAgreementVo; |
| | | import com.xiaopeng.unifiedverification.interceptor.XpClientCheck; |
| | | import io.swagger.annotations.Api; |
| | | import io.swagger.annotations.ApiOperation; |
| | | import lombok.extern.slf4j.Slf4j; |
| | | import org.apache.poi.ss.usermodel.Workbook; |
| | | import org.springframework.transaction.annotation.Propagation; |
| | | import org.apache.shardingsphere.transaction.annotation.ShardingSphereTransactionType; |
| | | import org.apache.shardingsphere.transaction.core.TransactionType; |
| | | import org.springframework.transaction.annotation.Transactional; |
| | | import org.springframework.util.CollectionUtils; |
| | | import org.springframework.util.StringUtils; |
| | |
| | | |
| | | import javax.annotation.Resource; |
| | | import javax.servlet.ServletOutputStream; |
| | | import javax.servlet.http.HttpServletRequest; |
| | | import javax.servlet.http.HttpServletResponse; |
| | | import java.io.IOException; |
| | | import java.io.InputStream; |
| | | import java.net.URLEncoder; |
| | | import java.time.LocalDate; |
| | | import java.time.LocalDateTime; |
| | | import java.time.format.DateTimeFormatter; |
| | | import java.util.ArrayList; |
| | | import java.util.Arrays; |
| | | import java.util.Collections; |
| | | import java.util.Comparator; |
| | | import java.util.HashMap; |
| | | import java.util.HashSet; |
| | | import java.util.LinkedHashSet; |
| | | import java.util.List; |
| | | import java.util.Map; |
| | | import java.util.Set; |
| | | import java.util.*; |
| | | import java.util.stream.Collectors; |
| | | |
| | | /** |
| | |
| | | private IXpWhitelistOperlogService xpWhitelistOperlogService; |
| | | @Resource |
| | | private TokenService tokenService; |
| | | @Resource |
| | | private SysGroupMenuClient groupMenuClient; |
| | | |
| | | |
| | | |
| | |
| | | * 获取所有白名单手机号 |
| | | * @return |
| | | */ |
| | | @PostMapping("/api/v1/whitelist/inner/getAllWhiteList") |
| | | @PostMapping("/logan/api/v1/whitelist/inner/getAllWhiteList") |
| | | public R<List<String>> getAllWhiteList(){ |
| | | return R.ok(xpWhitelistService.getAllWhiteList()); |
| | | } |
| | | |
| | | |
| | | @ApiOperation(value = "白名单管理详情", tags = {"管理后台-白名单管理详情"}) |
| | | @GetMapping("/api/v1/whitelist/detail/{id}") |
| | | public R<XpWhitelist> detail(@PathVariable("id") Long id) { |
| | | LoginUser loginUser = tokenService.getLoginUser(); |
| | | XpWhitelist xpWhitelist = xpWhitelistService.getById(id); |
| | | xpWhitelist.setAccount(SensitiveDataCryptoUtil.decryptIfPossible(xpWhitelist.getAccount())); |
| | | if(!loginUser.getPhoneDesensitizationExempt()){ |
| | | xpWhitelist.setAccount(DesensitizedUtil.mobilePhone(xpWhitelist.getAccount())); |
| | | } |
| | | return R.ok(xpWhitelist); |
| | | } |
| | | |
| | | |
| | | @ApiOperation(value = "白名单管理分页列表", response = XpWhitelist.class) |
| | | @PostMapping("/api/v1/whitelist/pageList") |
| | | public R<PageInfo<XpWhitelist>> pageList(@RequestBody WhitelistPageListQuery query) { |
| | | LoginUser loginUser = tokenService.getLoginUser(); |
| | | PageInfo<XpWhitelist> pageList = xpWhitelistService.pageList(query); |
| | | if(!loginUser.getPhoneDesensitizationExempt()){ |
| | | pageList.getRecords().forEach(s->s.setAccount(DesensitizedUtil.mobilePhone(s.getAccount()))); |
| | | } |
| | | return R.ok(pageList); |
| | | } |
| | | |
| | |
| | | @PostMapping("/api/v1/whitelist/add") |
| | | @ResponseBody |
| | | @ApiOperation(value = "新增白名单") |
| | | @Transactional |
| | | public R add(@Validated @RequestBody WhitelistAddDto dto) { |
| | | if (!StringUtils.hasLength(dto.getAccount())) { |
| | | return R.fail("请输入账号"); |
| | |
| | | return R.fail("请输入账号"); |
| | | } |
| | | SysUser sysUser = tokenService.getLoginUser().getSysUser(); |
| | | XpWhitelist xpWhitelist = new XpWhitelist(); |
| | | BeanUtils.copyProperties(dto, xpWhitelist); |
| | | xpWhitelist.setUpdateBy(tokenService.getLoginUser().getSysUser().getNickName()); |
| | | |
| | | return xpWhitelistService.editWhitelist(xpWhitelist, sysUser); |
| | | if (dto.getExpireTime() != null && dto.getExpireTime().isBefore(LocalDate.now())) { |
| | | return R.fail("有效期不能早于当前日期"); |
| | | } |
| | | |
| | | return xpWhitelistService.editWhitelist(dto, sysUser); |
| | | } |
| | | |
| | | /** |
| | |
| | | } |
| | | } |
| | | |
| | | @Log(title = "白名单导入", businessType = BusinessType.IMPORT) |
| | | |
| | | |
| | | @Transactional |
| | | @ShardingSphereTransactionType(TransactionType.BASE) |
| | | @ApiOperation(value = "白名单导入") |
| | | @Transactional(rollbackFor = Exception.class, propagation = Propagation.REQUIRES_NEW) |
| | | @PostMapping("/base/v1/whitelist/importExcel") |
| | | public AjaxResult<String> importExcel(@RequestPart("file") MultipartFile file) { |
| | | public AjaxResult<String> importExcel(@RequestParam("file") MultipartFile file) { |
| | | |
| | | ImportParams params = new ImportParams(); |
| | | // params.setTitleRows(1); // 标题行数 |
| | |
| | | recordFail(reasonCountMap, reasonSampleMap, "账号为空", "第" + excelRowNumber + "行", sampleLimitPerReason); |
| | | continue; |
| | | } |
| | | if (!PhoneUtil.isPhone(account)) { |
| | | if (!PhoneUtil.isMobile(account)) { |
| | | recordFail(reasonCountMap, reasonSampleMap, "账号格式不正确", account, sampleLimitPerReason); |
| | | continue; |
| | | } |
| | |
| | | if (!CollectionUtils.isEmpty(candidateAccounts)) { |
| | | existsAccounts = xpWhitelistService.lambdaQuery() |
| | | .select(XpWhitelist::getAccount) |
| | | .in(XpWhitelist::getAccount, candidateAccounts) |
| | | .in(XpWhitelist::getAccount, buildAccountQueryValues(candidateAccounts)) |
| | | .list() |
| | | .stream() |
| | | .map(XpWhitelist::getAccount) |
| | | .map(SensitiveDataCryptoUtil::decryptIfPossible) |
| | | .filter(StringUtils::hasLength) |
| | | .collect(Collectors.toSet()); |
| | | } |
| | |
| | | } |
| | | XpWhitelist xpWhitelist = new XpWhitelist(); |
| | | xpWhitelist.setNickName(whitelistImportExcel.getNickName()); |
| | | xpWhitelist.setAccount(whitelistImportExcel.getAccount()); |
| | | xpWhitelist.setAccount(SensitiveDataCryptoUtil.encrypt(whitelistImportExcel.getAccount())); |
| | | xpWhitelist.setStatus(true); |
| | | xpWhitelist.setIsPriorityDispatch(true); |
| | | xpWhitelist.setWhitelistSource(1); |
| | |
| | | xpWhitelistOperlog.setCreateBy(sysUser.getNickName()); |
| | | xpWhitelistOperlogService.save(xpWhitelistOperlog); |
| | | |
| | | return AjaxResult.success(message, message); |
| | | return AjaxResult.success(opContent, opContent); |
| | | } |
| | | |
| | | private static String trimToNull(String value) { |
| | |
| | | return value.substring(0, maxLength); |
| | | } |
| | | |
| | | private static List<String> buildAccountQueryValues(Set<String> accounts) { |
| | | if (CollectionUtils.isEmpty(accounts)) { |
| | | return Collections.emptyList(); |
| | | } |
| | | return accounts.stream() |
| | | .filter(StringUtils::hasLength) |
| | | .flatMap(account -> SensitiveDataCryptoUtil.queryValues(account).stream()) |
| | | .distinct() |
| | | .collect(Collectors.toList()); |
| | | } |
| | | |
| | | @ApiOperation(value = "白名单导出") |
| | | @PostMapping(value = "/api/v1/whitelist/exportExcel") |
| | | public void exportExcel(@RequestBody WhitelistPageListQuery query) { |
| | | @PostMapping(value = "/api/v1/whitelist/exportExcels") |
| | | public void exportExcels(@RequestBody WhitelistPageListQuery query) { |
| | | List<XpWhitelist> exportList = xpWhitelistService.exportList(query); |
| | | List<XpWhitelistExportExcel> xpWhitelistExportExcels = new ArrayList<>(); |
| | | long sequence = 1L; |
| | | for (XpWhitelist xpWhitelist : exportList) { |
| | | XpWhitelistExportExcel xpWhitelistExportExcel = new XpWhitelistExportExcel(); |
| | | xpWhitelistExportExcel.setId(xpWhitelist.getId()); |
| | | xpWhitelistExportExcel.setId(sequence++); |
| | | xpWhitelistExportExcel.setAccount(xpWhitelist.getAccount()); |
| | | xpWhitelistExportExcel.setNickName(xpWhitelist.getNickName()); |
| | | xpWhitelistExportExcel.setStatus(xpWhitelist.getStatus()); |
| | | xpWhitelistExportExcel.setIsPriorityDispatch(xpWhitelist.getIsPriorityDispatch()); |
| | | xpWhitelistExportExcel.setExpireTime(xpWhitelist.getExpireTime().toString()); |
| | | xpWhitelistExportExcel.setMaxOrderNum(xpWhitelist.getMaxOrderNum()); |
| | | |
| | | xpWhitelistExportExcel.setCreateBy(xpWhitelist.getCreateBy()); |
| | | LocalDateTime createTime = xpWhitelist.getCreateTime(); |
| | | // 将LocalDateTime转化为yyyy-MM-dd HH:mm:ss格式字符串 |
| | |
| | | |
| | | } |
| | | |
| | | |
| | | |
| | | /** |
| | | * 根据名称模糊搜索 |
| | | * @param name |
| | | * @return |
| | | */ |
| | | @PostMapping("/logan/api/v1/whitelist/inner/getXpWhitelistByName") |
| | | public R<List<XpWhitelist>> getXpWhitelistByName(@RequestParam String name){ |
| | | List<XpWhitelist> list = xpWhitelistService.list(new QueryWrapper<XpWhitelist>().like("nick_name", name) |
| | | .eq("status", 1).eq("is_deleted", 0)); |
| | | return R.ok(list); |
| | | } |
| | | |
| | | |
| | | |
| | | /** |
| | | * 根据手机号查询 |
| | | * @param phone |
| | | * @return |
| | | */ |
| | | @PostMapping("/logan/api/v1/whitelist/inner/getXpWhitelistByPhone") |
| | | public R<List<XpWhitelist>> getXpWhitelistByPhone(@RequestParam String phone){ |
| | | if (!StringUtils.hasLength(phone)) { |
| | | return R.ok(Collections.emptyList()); |
| | | } |
| | | List<XpWhitelist> list = xpWhitelistService.list(new QueryWrapper<XpWhitelist>().in("account", SensitiveDataCryptoUtil.queryValues(phone)) |
| | | .eq("status", 1).eq("is_deleted", 0)); |
| | | list.forEach(item -> item.setAccount(SensitiveDataCryptoUtil.decryptIfPossible(item.getAccount()))); |
| | | return R.ok(list); |
| | | } |
| | | |
| | | |
| | | |
| | | /** |
| | | * 根据账号查询 |
| | | * @return |
| | | */ |
| | | @PostMapping("/logan/api/v1/whitelist/inner/getXpWhitelistByUid") |
| | | public R<XpWhitelist> getXpWhitelistByUid(@RequestParam Long uid){ |
| | | XpWhitelist one = xpWhitelistService.getOne(new QueryWrapper<XpWhitelist>().eq("app_user_id", uid).eq("is_deleted", 0)); |
| | | return R.ok(one); |
| | | } |
| | | |
| | | |
| | | |
| | | @ApiOperation(value = "获取白名单权限", tags = {"小程序-首页"}) |
| | | @GetMapping("/api/v1/mini-program/whitelist/getUserWhitelist") |
| | | @XpClientCheck(checkToken = false, checkOtpToken = true) |
| | | public R<Boolean> getUserWhitelist(HttpServletRequest request){ |
| | | String uid = request.getHeader("XP-Uid"); |
| | | long count = xpWhitelistService.count(new QueryWrapper<XpWhitelist>() |
| | | .eq("app_user_id", uid).eq("status", 1).eq("is_deleted", 0) |
| | | .last(" and (DATE(expire_time) > DATE(NOW()) or expire_time is null)")); |
| | | return R.ok(count > 0); |
| | | } |
| | | } |