| | |
| | | import com.ruoyi.common.redis.service.RedisService; |
| | | import com.ruoyi.common.security.annotation.Logical; |
| | | import com.ruoyi.common.security.annotation.RequiresPermissions; |
| | | import com.ruoyi.common.security.annotation.InnerAuth; |
| | | import com.ruoyi.common.security.auth.AuthUtil; |
| | | import com.ruoyi.common.security.service.TokenService; |
| | | import com.ruoyi.common.security.utils.SecurityUtils; |
| | |
| | | private TAppUserWhitelistService appUserWhitelistService; |
| | | @Resource |
| | | private PartnerClient partnerClient; |
| | | @Resource |
| | | private PartnerAppUserAccessService partnerAppUserAccessService; |
| | | |
| | | @Autowired |
| | | private RedissonClient redissonClient; |
| | |
| | | } |
| | | |
| | | @ApiOperation(value = "管理后台-根据手机号查询用户ids", tags = {"管理后台-活动费用统计"}) |
| | | @RequiresPermissions(value = {"/appUser/select", "/appUser/list"}, logical = Logical.OR) |
| | | @PostMapping(value = "/user/getUserIdsByPhone") |
| | | public R<List<Long>> getUserIdsByPhone(@RequestParam("phone") String phone) { |
| | | return R.ok(appUserService.list(new QueryWrapper<TAppUser>().like("phone",phone)).stream().map(TAppUser::getId).collect(Collectors.toList())); |
| | |
| | | //如果要筛选标签。用标签获取useids |
| | | if (userListQueryDto.getUserTagId() != null){ |
| | | userIds = appUserTagService.lambdaQuery().eq(TAppUserTag::getUserTagId, userListQueryDto.getUserTagId()).list().stream().map(TAppUserTag::getAppUserId).collect(Collectors.toList()); |
| | | if (userIds.isEmpty()) { |
| | | userIds.add(-1L); |
| | | } |
| | | } |
| | | List<TAppUserWhitelist> whitelistList = new ArrayList<>(); |
| | | List<Long> whitelistUserIds = new ArrayList<>(); |
| | | List<String> whitelistPhones = new ArrayList<>(); |
| | | if (userListQueryDto.getWhitelistFlag() != null) { |
| | | whitelistList = appUserWhitelistService.lambdaQuery() |
| | | .eq(TAppUserWhitelist::getStatus, 1) |
| | | .eq(TAppUserWhitelist::getDelFlag, false) |
| | | .list(); |
| | | whitelistUserIds = whitelistList.stream() |
| | | .map(TAppUserWhitelist::getAppUserId) |
| | | .filter(Objects::nonNull) |
| | | .collect(Collectors.toList()); |
| | | whitelistPhones = whitelistList.stream() |
| | | .map(TAppUserWhitelist::getPhone) |
| | | .filter(StringUtils::isNotBlank) |
| | | .collect(Collectors.toList()); |
| | | } |
| | | //列表查询 |
| | | Page<TAppUser> page = appUserService.lambdaQuery() |
| | | LambdaQueryChainWrapper<TAppUser> query = appUserService.lambdaQuery() |
| | | .like(userListQueryDto.getUserPhone() != null && !"".equals(userListQueryDto.getUserPhone()), TAppUser::getPhone, userListQueryDto.getUserPhone()) |
| | | .eq(userListQueryDto.getCompanyId() != null, TAppUser::getCompanyId, userListQueryDto.getCompanyId()) |
| | | .eq(userListQueryDto.getProvinceCode() != null && !"".equals(userListQueryDto.getProvinceCode()), TAppUser::getProvinceCode, userListQueryDto.getProvinceCode()) |
| | |
| | | .eq(userListQueryDto.getStatus() != null, TAppUser::getStatus, userListQueryDto.getStatus()) |
| | | .eq(userListQueryDto.getVipTypeId() != null, TAppUser::getVipId, userListQueryDto.getVipTypeId()) |
| | | .in(!userIds.isEmpty(),TAppUser::getId,userIds) |
| | | .orderByDesc(BasePojo::getCreateTime) |
| | | .page(Page.of(userListQueryDto.getPageCurr(), userListQueryDto.getPageSize())); |
| | | .orderByDesc(BasePojo::getCreateTime); |
| | | List<Long> partnerVisibleUserIds = partnerAppUserAccessService.getVisibleUserIdsForCurrentPartner(); |
| | | if (partnerVisibleUserIds != null) { |
| | | query.in(TAppUser::getId, partnerVisibleUserIds); |
| | | } |
| | | if (Integer.valueOf(1).equals(userListQueryDto.getWhitelistFlag())) { |
| | | if (whitelistUserIds.isEmpty() && whitelistPhones.isEmpty()) { |
| | | query.eq(TAppUser::getId, -1L); |
| | | } else { |
| | | List<Long> finalWhitelistUserIds = whitelistUserIds; |
| | | List<String> finalWhitelistPhones = whitelistPhones; |
| | | query.and(wrapper -> { |
| | | if (!finalWhitelistUserIds.isEmpty()) { |
| | | wrapper.in(TAppUser::getId, finalWhitelistUserIds); |
| | | } |
| | | if (!finalWhitelistPhones.isEmpty()) { |
| | | if (!finalWhitelistUserIds.isEmpty()) { |
| | | wrapper.or(); |
| | | } |
| | | wrapper.in(TAppUser::getPhone, finalWhitelistPhones); |
| | | } |
| | | }); |
| | | } |
| | | } |
| | | if (Integer.valueOf(2).equals(userListQueryDto.getWhitelistFlag())) { |
| | | query.notIn(!whitelistUserIds.isEmpty(), TAppUser::getId, whitelistUserIds) |
| | | .notIn(!whitelistPhones.isEmpty(), TAppUser::getPhone, whitelistPhones); |
| | | } |
| | | Page<TAppUser> page = query.page(Page.of(userListQueryDto.getPageCurr(), userListQueryDto.getPageSize())); |
| | | if (page.getRecords().isEmpty()){ |
| | | return R.ok(page); |
| | | } |
| | | List<Long> pageUserIds = page.getRecords().stream().map(TAppUser::getId).collect(Collectors.toList()); |
| | | List<String> pageUserPhones = page.getRecords().stream() |
| | | .map(TAppUser::getPhone) |
| | | .filter(StringUtils::isNotBlank) |
| | | .map(String::trim) |
| | | .distinct() |
| | | .collect(Collectors.toList()); |
| | | LambdaQueryChainWrapper<TAppUserWhitelist> pageWhitelistQuery = appUserWhitelistService.lambdaQuery() |
| | | .eq(TAppUserWhitelist::getStatus, 1) |
| | | .eq(TAppUserWhitelist::getDelFlag, false) |
| | | .and(wrapper -> { |
| | | wrapper.in(TAppUserWhitelist::getAppUserId, pageUserIds); |
| | | if (!pageUserPhones.isEmpty()) { |
| | | wrapper.or().in(TAppUserWhitelist::getPhone, pageUserPhones); |
| | | } |
| | | }); |
| | | List<TAppUserWhitelist> pageWhitelistList = pageWhitelistQuery.list(); |
| | | Set<Long> activeWhitelistUserIds = pageWhitelistList.stream() |
| | | .map(TAppUserWhitelist::getAppUserId) |
| | | .filter(Objects::nonNull) |
| | | .collect(Collectors.toSet()); |
| | | Set<String> activeWhitelistPhones = pageWhitelistList.stream() |
| | | .map(TAppUserWhitelist::getPhone) |
| | | .filter(StringUtils::isNotBlank) |
| | | .map(String::trim) |
| | | .collect(Collectors.toSet()); |
| | | Map<Long, String> userTagNameMap = getUserTagNameMap(pageUserIds); |
| | | Map<Long, BigDecimal> exchangeCodeBalanceMap = otherClient.getExchangeCodeBalanceMap(pageUserIds).getData(); |
| | | if (exchangeCodeBalanceMap == null) { |
| | | exchangeCodeBalanceMap = new HashMap<>(); |
| | |
| | | //循环处理 |
| | | for (TAppUser appUser : page.getRecords()) { |
| | | appUser.setExchangeCodeBalance(exchangeCodeBalanceMap.getOrDefault(appUser.getId(), BigDecimal.ZERO)); |
| | | //拿到最新的tagId |
| | | TAppUserTag one = appUserTagService.lambdaQuery().eq(TAppUserTag::getAppUserId, appUser.getId()).orderByDesc(TAppUserTag::getCreateTime).last("limit 1").one(); |
| | | if (one!=null) { |
| | | //设置最新的tagName |
| | | R<TUserTag> byIdTag = otherClient.getByIdTag(one.getUserTagId()); |
| | | if (byIdTag.getData() != null) { |
| | | appUser.setTagName(byIdTag.getData().getName()); |
| | | } |
| | | } |
| | | appUser.setTagName(userTagNameMap.get(appUser.getId())); |
| | | boolean activeWhitelist = activeWhitelistUserIds.contains(appUser.getId()) |
| | | || (StringUtils.isNotBlank(appUser.getPhone()) && activeWhitelistPhones.contains(appUser.getPhone().trim())); |
| | | appUser.setWhitelistFlag(activeWhitelist ? 1 : 2); |
| | | if (appUser.getVipEndTime()!=null&&appUser.getVipEndTime().isAfter(LocalDateTime.now())) { |
| | | //匹配vipMap的值 |
| | | appUser.setVipName(vipMap.getData().get(appUser.getVipId())); |
| | |
| | | |
| | | } |
| | | return R.ok(page); |
| | | } |
| | | |
| | | private Map<Long, String> getUserTagNameMap(List<Long> userIds) { |
| | | if (userIds == null || userIds.isEmpty()) { |
| | | return new HashMap<>(); |
| | | } |
| | | List<TAppUserTag> userTags = appUserTagService.lambdaQuery() |
| | | .in(TAppUserTag::getAppUserId, userIds) |
| | | .orderByDesc(TAppUserTag::getCreateTime) |
| | | .list(); |
| | | if (userTags.isEmpty()) { |
| | | return new HashMap<>(); |
| | | } |
| | | List<Integer> tagIds = userTags.stream() |
| | | .map(TAppUserTag::getUserTagId) |
| | | .filter(Objects::nonNull) |
| | | .distinct() |
| | | .collect(Collectors.toList()); |
| | | R<Map<Integer, String>> tagMapResult = otherClient.getTagMap(tagIds); |
| | | Map<Integer, String> tagMap = tagMapResult == null || tagMapResult.getData() == null ? new HashMap<>() : tagMapResult.getData(); |
| | | Map<Long, LinkedHashSet<String>> userTagNames = new HashMap<>(); |
| | | for (TAppUserTag userTag : userTags) { |
| | | String tagName = tagMap.get(userTag.getUserTagId()); |
| | | if (StringUtils.isBlank(tagName)) { |
| | | continue; |
| | | } |
| | | userTagNames.computeIfAbsent(userTag.getAppUserId(), key -> new LinkedHashSet<>()).add(tagName); |
| | | } |
| | | Map<Long, String> result = new HashMap<>(); |
| | | userTagNames.forEach((userId, names) -> result.put(userId, String.join(",", names))); |
| | | return result; |
| | | } |
| | | |
| | | |
| | |
| | | @Log(title = "【用户列表】添加编辑用户", businessType = BusinessType.INSERT,operatorType = OperatorType.MANAGE) |
| | | public R addOrUpdate(@RequestBody TAppUser tAppUser) { |
| | | if (tAppUser.getId() != null){ |
| | | AuthUtil.checkPermi("/appUser/update"); |
| | | partnerAppUserAccessService.assertUserVisible(tAppUser.getId()); |
| | | //为编辑操作,要进行vip的逻辑处理 |
| | | TAppUser nowUser = appUserService.getById(tAppUser.getId()); |
| | | //会员结束时间不为空 |
| | |
| | | } |
| | | |
| | | }else { |
| | | AuthUtil.checkPermi("/appUser/add"); |
| | | List<TAppUser> list = appUserService.lambdaQuery().eq(TAppUser::getPhone, tAppUser.getPhone()).list(); |
| | | if (!list.isEmpty()){ |
| | | return R.fail("该手机号已注册"); |
| | |
| | | } |
| | | |
| | | |
| | | @RequiresPermissions(value = {"/appUser/select", "/vipList/select"}, logical = Logical.OR) |
| | | @RequiresPermissions(value = {"/appUser/list", "/appUser/select", "/vipList/select"}, logical = Logical.OR) |
| | | @ApiOperation(value = "用户详情", tags = {"用户管理-用户列表"}) |
| | | @GetMapping(value = "/user/detail/{id}") |
| | | public R<UserDetailDto> userDetail(@PathVariable Long id) { |
| | | partnerAppUserAccessService.assertUserVisible(id); |
| | | TAppUser user = appUserService.getById(id); |
| | | R<Map<Integer, String>> vipMap = otherClient.getVipMap(Collections.singletonList(user.getVipId())); |
| | | if (user.getVipEndTime()!=null&&user.getVipEndTime().isAfter(LocalDateTime.now())) { |
| | |
| | | |
| | | UserDetailDto userDetailDto = new UserDetailDto(); |
| | | BeanUtils.copyProperties(user,userDetailDto); |
| | | Map<Long, BigDecimal> exchangeCodeBalanceMap = otherClient |
| | | .getExchangeCodeBalanceMap(Collections.singletonList(id)) |
| | | .getData(); |
| | | userDetailDto.setExchangeCodeBalance(exchangeCodeBalanceMap == null |
| | | ? BigDecimal.ZERO |
| | | : exchangeCodeBalanceMap.getOrDefault(id, BigDecimal.ZERO)); |
| | | |
| | | //获取累计充电数量 |
| | | R<Long> useOrderCount = chargingOrderClient.useOrderCount(user.getId()); |
| | |
| | | List<TAppUserCar> carList = appUserCarService.lambdaQuery().eq(TAppUserCar::getAppUserId, id).orderByDesc(BasePojo::getCreateTime).list(); |
| | | userDetailDto.setCarList(carList); |
| | | |
| | | List<Integer> tagIds = appUserTagService.lambdaQuery().eq(TAppUserTag::getAppUserId, id).orderByDesc(TAppUserTag::getCreateTime).list().stream().map(TAppUserTag::getUserTagId).collect(Collectors.toList()); |
| | | R<Map<Integer, String>> tagMap = otherClient.getTagMap(tagIds); |
| | | userDetailDto.setTagName(tagMap.getData().values() |
| | | .stream() |
| | | .collect(Collectors.joining(","))); |
| | | userDetailDto.setTagName(getUserTagNameMap(Collections.singletonList(id)).get(id)); |
| | | |
| | | |
| | | |
| | | return R.ok(userDetailDto); |
| | | } |
| | | |
| | | @RequiresPermissions(value = {"/appUser/select", "/vipList/select"}, logical = Logical.OR) |
| | | @RequiresPermissions(value = {"/appUser/list", "/appUser/select", "/vipList/select"}, logical = Logical.OR) |
| | | @ApiOperation(value = "用户详情积分明细", tags = {"后台-用户管理-用户列表"}) |
| | | @PostMapping(value = "/user/points/page") |
| | | public R<Page<TAppUserIntegralChange>> pointsDetail(@RequestBody PointsQueryDto pointsQueryDto) { |
| | | if (pointsQueryDto.getUserId()==null){ |
| | | pointsQueryDto.setUserId(tokenService.getLoginUserApplet().getUserId()); |
| | | } |
| | | partnerAppUserAccessService.assertUserVisible(pointsQueryDto.getUserId()); |
| | | List<Integer> types = new ArrayList<>(); |
| | | if (pointsQueryDto.getType()==null){ |
| | | types.add(1); |
| | |
| | | @ApiOperation(value = "用户详情积分明细", tags = {"小程序-个人中心"}) |
| | | @PostMapping(value = "/user/points/page1") |
| | | public R<Page<TAppUserIntegralChange>> pointsDetail1(@RequestBody PointsQueryDto pointsQueryDto) { |
| | | if (pointsQueryDto.getUserId()==null){ |
| | | pointsQueryDto.setUserId(tokenService.getLoginUserApplet().getUserId()); |
| | | } |
| | | // 强制绑定当前登录用户,防止越权查询他人积分明细 |
| | | pointsQueryDto.setUserId(tokenService.getLoginUserApplet().getUserId()); |
| | | List<Integer> types = new ArrayList<>(); |
| | | if (pointsQueryDto.getType()==null){ |
| | | types.add(1); |
| | |
| | | |
| | | } |
| | | |
| | | @RequiresPermissions(value = {"/appUser/select", "/vipList/select"}, logical = Logical.OR) |
| | | @RequiresPermissions(value = {"/appUser/list", "/appUser/select", "/vipList/select"}, logical = Logical.OR) |
| | | @ApiOperation(value = "用户详情余额明细", tags = {"后台-用户管理-用户列表"}) |
| | | @PostMapping(value = "/user/balance/page") |
| | | public R<Page<TExchangeCodeUseRecord>> adminBalanceDetail(@RequestBody ExchangeCodeUseRecordQuery queryDto) { |
| | | partnerAppUserAccessService.assertUserVisible(queryDto.getUserId()); |
| | | return otherClient.exchangeCodeUseRecordPage(queryDto); |
| | | } |
| | | |
| | | @ApiOperation(value = "余额明细", tags = {"小程序-个人中心"}) |
| | | @PostMapping(value = "/user/balance/page1") |
| | | public R<Page<TExchangeCodeUseRecord>> balanceDetail(@RequestBody ExchangeCodeUseRecordQuery queryDto) { |
| | | if (queryDto.getUserId() == null) { |
| | | queryDto.setUserId(tokenService.getLoginUserApplet().getUserId()); |
| | | } |
| | | // 强制绑定当前登录用户,防止越权查询他人余额明细 |
| | | queryDto.setUserId(tokenService.getLoginUserApplet().getUserId()); |
| | | return otherClient.exchangeCodeUseRecordPage(queryDto); |
| | | } |
| | | |
| | |
| | | @PostMapping(value = "/user/status/change") |
| | | @Log(title = "【用户列表】冻结解冻用户", businessType = BusinessType.UPDATE,operatorType = OperatorType.MANAGE) |
| | | public R pointsDetail(@RequestBody UserChangeDto userChangeDto) { |
| | | partnerAppUserAccessService.assertUserVisible(userChangeDto.getUserId()); |
| | | TAppUser appUser = appUserService.getById(userChangeDto.getUserId()); |
| | | appUser.setStatus(userChangeDto.getStatus()); |
| | | appUser.setRemark(userChangeDto.getRemark()); |
| | |
| | | @PostMapping(value = "/user/unit/change") |
| | | @Log(title = "【用户列表】修改用户单位", businessType = BusinessType.UPDATE,operatorType = OperatorType.MANAGE) |
| | | public R unitChange(@RequestBody UnitChangeDto unitChangeDto) { |
| | | for (String s : unitChangeDto.getIds().split(",")) { |
| | | TAppUser byId = appUserService.getById(s); |
| | | List<Long> userIds = parseUserIds(unitChangeDto.getIds()); |
| | | partnerAppUserAccessService.assertUsersVisible(userIds); |
| | | for (Long userId : userIds) { |
| | | TAppUser byId = appUserService.getById(userId); |
| | | byId.setCompanyId(unitChangeDto.getUnitId()); |
| | | appUserService.updateById(byId); |
| | | } |
| | |
| | | @DeleteMapping(value = "/user/delete") |
| | | @Log(title = "【用户列表】删除用户", businessType = BusinessType.DELETE,operatorType = OperatorType.MANAGE) |
| | | public R userDelete(String ids) { |
| | | String[] split = ids.split(","); |
| | | for (String s : split) { |
| | | appUserService.removeById(s); |
| | | List<Long> userIds = parseUserIds(ids); |
| | | partnerAppUserAccessService.assertUsersVisible(userIds); |
| | | for (Long userId : userIds) { |
| | | appUserService.removeById(userId); |
| | | } |
| | | return R.ok(); |
| | | |
| | |
| | | @PostMapping(value = "/user/give/vip") |
| | | @Log(title = "【用户列表】赠送会员", businessType = BusinessType.OTHER,operatorType = OperatorType.MANAGE) |
| | | public R giveVip(@RequestBody GiveVipDto giveVipDto) { |
| | | String[] split = giveVipDto.getUserIds().split(","); |
| | | for (String s : split) { |
| | | TAppUser nowUser = appUserService.getById(s); |
| | | List<Long> userIds = parseUserIds(giveVipDto.getUserIds()); |
| | | partnerAppUserAccessService.assertUsersVisible(userIds); |
| | | for (Long userId : userIds) { |
| | | TAppUser nowUser = appUserService.getById(userId); |
| | | int plusDay = 0; |
| | | if (giveVipDto.getType() == 1) { |
| | | plusDay = 1; |
| | |
| | | } |
| | | return R.ok(); |
| | | } |
| | | |
| | | private List<Long> parseUserIds(String ids) { |
| | | if (StringUtils.isBlank(ids)) { |
| | | return Collections.emptyList(); |
| | | } |
| | | return Arrays.stream(ids.split(",")) |
| | | .map(String::trim) |
| | | .filter(StringUtils::isNotBlank) |
| | | .map(Long::valueOf) |
| | | .distinct() |
| | | .collect(Collectors.toList()); |
| | | } |
| | | |
| | | |
| | | |
| | | @RequiresPermissions(value = {"/appUser/giftVip", "/appUser/gift_vip"}, logical = Logical.OR) |
| | | @PostMapping(value = "/user/give/vip1") |
| | | public R giveVip1(@RequestBody GiveVipDto giveVipDto) { |
| | | String[] split = giveVipDto.getUserIds().split(","); |
| | |
| | | sendMessageDTO.getChargingCapacity(), sendMessageDTO.getChargingFee()); |
| | | String result4 = HttpUtils.post(MsgConstants.SEND_URL, reqStr4); |
| | | return R.ok(result4); |
| | | case 5: |
| | | String reqStr5 = MsgUtil.companyBalanceWarnMsg(sendMessageDTO.getPhone(), sendMessageDTO.getCompanyName(), |
| | | sendMessageDTO.getBalance(), sendMessageDTO.getWarnAmount()); |
| | | String result5 = HttpUtils.post(MsgConstants.SEND_URL, reqStr5); |
| | | return R.ok(result5); |
| | | case 6: |
| | | String reqStr6 = MsgUtil.subBalanceWarnMsg(sendMessageDTO.getPhone(), sendMessageDTO.getCompanyName(), |
| | | sendMessageDTO.getUserInfo(), sendMessageDTO.getBalance(), sendMessageDTO.getWarnAmount()); |
| | | String result6 = HttpUtils.post(MsgConstants.SEND_URL, reqStr6); |
| | | return R.ok(result6); |
| | | default: |
| | | String reqStr3 = MsgUtil.faultMsg(sendMessageDTO.getPhone(), sendMessageDTO.getSite(), sendMessageDTO.getChargeGun()); |
| | | String result3 = HttpUtils.post(MsgConstants.SEND_URL, reqStr3); |