| | |
| | | package com.ruoyi.account.controller; |
| | | |
| | | |
| | | import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper; |
| | | import com.baomidou.mybatisplus.core.metadata.IPage; |
| | | import com.baomidou.mybatisplus.core.toolkit.Wrappers; |
| | | import com.baomidou.mybatisplus.extension.plugins.pagination.Page; |
| | | import com.ruoyi.account.api.dto.UnitListQueryDto; |
| | | import com.ruoyi.account.api.model.TAppUser; |
| | | import com.ruoyi.account.service.TAppUserService; |
| | | import com.ruoyi.account.api.dto.*; |
| | | import com.ruoyi.account.api.model.*; |
| | | import com.ruoyi.account.service.*; |
| | | import com.ruoyi.common.core.domain.R; |
| | | import com.ruoyi.common.core.utils.bean.BeanUtils; |
| | | import com.ruoyi.common.core.web.domain.BasePojo; |
| | | import com.ruoyi.common.security.annotation.RequiresPermissions; |
| | | import com.ruoyi.order.api.feignClient.ChargingOrderClient; |
| | | import com.ruoyi.order.api.feignClient.ExchangeOrderClient; |
| | | import com.ruoyi.order.api.model.TChargingOrder; |
| | | import com.ruoyi.order.api.model.TExchangeOrder; |
| | | import com.ruoyi.other.api.domain.TCompany; |
| | | import com.ruoyi.other.api.domain.TUserTag; |
| | | import com.ruoyi.other.api.feignClient.OtherClient; |
| | | import io.swagger.annotations.ApiImplicitParam; |
| | | import io.swagger.annotations.ApiImplicitParams; |
| | |
| | | import org.springframework.web.bind.annotation.*; |
| | | |
| | | import javax.annotation.Resource; |
| | | import java.time.Duration; |
| | | import java.time.LocalDateTime; |
| | | import java.util.ArrayList; |
| | | import java.util.Arrays; |
| | | import java.util.List; |
| | | import java.util.Map; |
| | | import java.util.stream.Collectors; |
| | | |
| | | /** |
| | | * <p> |
| | |
| | | private OtherClient otherClient; |
| | | @Resource |
| | | private TAppUserService appUserService; |
| | | @Resource |
| | | private TAppUserTagService appUserTagService; |
| | | |
| | | @Resource |
| | | private TAppUserVipDetailService tAppUserVipDetailService; |
| | | @Resource |
| | | private ChargingOrderClient chargingOrderClient; |
| | | |
| | | @Resource |
| | | private TAppUserCarService appUserCarService; |
| | | |
| | | @Resource |
| | | private TAppUserIntegralChangeService integralChangeService; |
| | | |
| | | @Resource |
| | | private ExchangeOrderClient exchangeOrderClient; |
| | | |
| | | @ApiOperation(value = "管理后台-根据手机号查询用户ids", tags = {"管理后台-活动费用统计"}) |
| | | @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())); |
| | | } |
| | | @ApiOperation(value = "单位管理列表", tags = {"用户管理-单位管理"}) |
| | | @PostMapping(value = "/unit/page") |
| | | public R<Page<TCompany>> unitPage(@RequestBody UnitListQueryDto unitListQueryDto) { |
| | |
| | | } |
| | | |
| | | |
| | | @ApiOperation(value = "用户列表", tags = {"用户管理-用户管理"}) |
| | | @ApiOperation(value = "用户列表", tags = {"用户管理-用户列表"}) |
| | | @PostMapping(value = "/user/page") |
| | | public R<Page<TCompany>> userPage(@RequestBody UnitListQueryDto unitListQueryDto) { |
| | | |
| | | //拿到标签tag |
| | | |
| | | //拿到会员map |
| | | |
| | | public R<Page<TAppUser>> userPage(@RequestBody UserListQueryDto userListQueryDto) { |
| | | List<Long> userIds = new ArrayList<>(); |
| | | //如果要筛选标签。用标签获取useids |
| | | if (userListQueryDto.getUserTagId() != null){ |
| | | userIds = appUserTagService.lambdaQuery().eq(TAppUserTag::getUserTagId, userListQueryDto.getUserTagId()).list().stream().map(TAppUserTag::getAppUserId).collect(Collectors.toList()); |
| | | } |
| | | //列表查询 |
| | | Page<TAppUser> page = appUserService.lambdaQuery() |
| | | .like(userListQueryDto.getUserPhone() != null && !"".equals(userListQueryDto.getUserPhone()), TAppUser::getPhone, userListQueryDto.getUserPhone()) |
| | | .eq(userListQueryDto.getCompanyId() != null, TAppUser::getCompanyId, userListQueryDto.getCompanyId()) |
| | | .eq(userListQueryDto.getCityCode() != null && !"".equals(userListQueryDto.getCityCode()), TAppUser::getCityCode, userListQueryDto.getCityCode()) |
| | | .eq(userListQueryDto.getStatus() != null, TAppUser::getStatus, userListQueryDto.getStatus()) |
| | | .eq(userListQueryDto.getVipTypeId() != null, TAppUser::getVipId, userListQueryDto.getVipTypeId()) |
| | | .in(!userIds.isEmpty(),TAppUser::getId,userIds) |
| | | .page(Page.of(userListQueryDto.getPageCurr(), userListQueryDto.getPageSize())); |
| | | if (page.getRecords().isEmpty()){ |
| | | return R.ok(page); |
| | | } |
| | | List<Integer> vipIds = new ArrayList<>(); |
| | | vipIds = page.getRecords().stream().map(TAppUser::getVipId).collect(Collectors.toList()); |
| | | //获取会员map |
| | | R<Map<Integer, String>> vipMap = otherClient.getVipMap(vipIds); |
| | | //循环处理 |
| | | for (TAppUser appUser : page.getRecords()) { |
| | | //拿到最新的tagId |
| | | TAppUserTag one = appUserTagService.lambdaQuery().eq(TAppUserTag::getAppUserId, appUser.getId()).orderByDesc(TAppUserTag::getCreateTime).last("limit 1").one(); |
| | | //设置最新的tagName |
| | | R<TUserTag> byIdTag = otherClient.getByIdTag(one.getUserTagId()); |
| | | if (byIdTag.getData()!=null) { |
| | | appUser.setTagName(byIdTag.getData().getName()); |
| | | } |
| | | //匹配vipMap的值 |
| | | appUser.setVipName(vipMap.getData().get(appUser.getVipId())); |
| | | //累计充电次数 |
| | | R<Long> useOrderCount = chargingOrderClient.useOrderCount(appUser.getId()); |
| | | appUser.setOrderCount(useOrderCount.getData()); |
| | | |
| | | } |
| | | return R.ok(page); |
| | | } |
| | | |
| | | @ApiOperation(tags = {"管理后台-优惠券管理"},value = "优惠券发放-选择人员") |
| | | @PostMapping("/choiceUser") |
| | | public R<Page<TAppUser>> choiceUser(@RequestBody ChoiceUserListQueryDto userListQueryDto) { |
| | | List<Long> userIds = new ArrayList<>(); |
| | | //如果要筛选标签。用标签获取useids |
| | | if (userListQueryDto.getUserTagId() != null){ |
| | | String[] split = userListQueryDto.getUserTagId().split(","); |
| | | userIds = appUserTagService.lambdaQuery().in(TAppUserTag::getUserTagId, Arrays.asList(split)).list().stream().map(TAppUserTag::getAppUserId).collect(Collectors.toList()); |
| | | } |
| | | //列表查询 |
| | | Page<TAppUser> page = appUserService.lambdaQuery() |
| | | .like(userListQueryDto.getUserPhone() != null && !"".equals(userListQueryDto.getUserPhone()), TAppUser::getPhone, userListQueryDto.getUserPhone()) |
| | | .eq(userListQueryDto.getCityCode() != null && !"".equals(userListQueryDto.getCityCode()), TAppUser::getCityCode, userListQueryDto.getCityCode()) |
| | | .eq(userListQueryDto.getProvinceCode() != null && !"".equals(userListQueryDto.getProvinceCode()), TAppUser::getProvinceCode, userListQueryDto.getProvinceCode()) |
| | | .in(!userIds.isEmpty(),TAppUser::getId,userIds) |
| | | .eq(TAppUser::getStatus,1) |
| | | .page(Page.of(userListQueryDto.getPageCurr(), userListQueryDto.getPageSize())); |
| | | if (page.getRecords().isEmpty()){ |
| | | return R.ok(page); |
| | | } |
| | | List<Integer> vipIds = new ArrayList<>(); |
| | | vipIds = page.getRecords().stream().map(TAppUser::getVipId).collect(Collectors.toList()); |
| | | //获取会员map |
| | | R<Map<Integer, String>> vipMap = otherClient.getVipMap(vipIds); |
| | | //循环处理 |
| | | for (TAppUser appUser : page.getRecords()) { |
| | | //拿到最新的tagId |
| | | TAppUserTag one = appUserTagService.lambdaQuery().eq(TAppUserTag::getAppUserId, appUser.getId()).orderByDesc(TAppUserTag::getCreateTime).last("limit 1").one(); |
| | | //设置最新的tagName |
| | | R<TUserTag> byIdTag = otherClient.getByIdTag(one.getUserTagId()); |
| | | if (byIdTag.getData()!=null) { |
| | | appUser.setTagName(byIdTag.getData().getName()); |
| | | } |
| | | //匹配vipMap的值 |
| | | appUser.setVipName(vipMap.getData().get(appUser.getVipId())); |
| | | //累计充电次数 |
| | | R<Long> useOrderCount = chargingOrderClient.useOrderCount(appUser.getId()); |
| | | appUser.setOrderCount(useOrderCount.getData()); |
| | | |
| | | } |
| | | return R.ok(page); |
| | | } |
| | | |
| | | |
| | | @ApiOperation(value = "用户添加编辑", tags = {"用户管理-用户列表"}) |
| | | @PostMapping(value = "/user/addOrUpdate") |
| | | public R addOrUpdate(@RequestBody TAppUser tAppUser) { |
| | | if (tAppUser.getId() != null){ |
| | | //为编辑操作,要进行vip的逻辑处理 |
| | | TAppUser nowUser = appUserService.getById(tAppUser.getId()); |
| | | //会员结束时间不为空 |
| | | if (tAppUser.getVipEndTime()!=null&&tAppUser.getVipEndTime()!=nowUser.getVipEndTime()){ |
| | | //计算改变后的结束时间和当前结束时间差距了多少时间 |
| | | Duration duration = Duration.between(tAppUser.getVipEndTime(), nowUser.getVipEndTime()); |
| | | List<TAppUserVipDetail> detailList = tAppUserVipDetailService.lambdaQuery().eq(TAppUserVipDetail::getAppUserId, tAppUser.getId()).gt(TAppUserVipDetail::getEndTime, LocalDateTime.now()).orderByAsc(TAppUserVipDetail::getStartTime).list(); |
| | | //如果是增加,则将明细表里当前会员的结束时间往后移,并将其余未开始会员的开始时间和结束时间往后移 |
| | | if (tAppUser.getVipEndTime().isAfter(nowUser.getVipEndTime())){ |
| | | for (int i = 0; i < detailList.size(); i++) { |
| | | TAppUserVipDetail tAppUserVipDetail = detailList.get(i); |
| | | if (i == 0 ){ |
| | | tAppUserVipDetail.setEndTime(tAppUser.getVipEndTime().plus(duration)); |
| | | }else { |
| | | tAppUserVipDetail.setStartTime(tAppUserVipDetail.getStartTime().plus(duration)); |
| | | tAppUserVipDetail.setEndTime(tAppUserVipDetail.getEndTime().plus(duration)); |
| | | } |
| | | } |
| | | }else { |
| | | //如果是减少,将当前会员结束时间减少,并将其余会员开始和结束时间都往前移动 |
| | | for (int i = 0; i < detailList.size(); i++) { |
| | | TAppUserVipDetail tAppUserVipDetail = detailList.get(i); |
| | | if (i == 0 ){ |
| | | tAppUserVipDetail.setEndTime(tAppUser.getVipEndTime().minus(duration)); |
| | | }else { |
| | | tAppUserVipDetail.setStartTime(tAppUserVipDetail.getStartTime().minus(duration)); |
| | | tAppUserVipDetail.setEndTime(tAppUserVipDetail.getEndTime().minus(duration)); |
| | | } |
| | | } |
| | | } |
| | | } |
| | | |
| | | } |
| | | appUserService.saveOrUpdate(tAppUser); |
| | | return R.ok(); |
| | | } |
| | | |
| | | @ApiOperation(value = "用户详情", tags = {"用户管理-用户列表"}) |
| | | @PostMapping(value = "/user/detail/{id}") |
| | | public R<UserDetailDto> userDetail(@PathVariable Long id) { |
| | | TAppUser user = appUserService.getById(id); |
| | | UserDetailDto userDetailDto = new UserDetailDto(); |
| | | BeanUtils.copyProperties(user,userDetailDto); |
| | | if (user.getVipId()!=null) { |
| | | R<Map<Integer, String>> vipMap = otherClient.getVipMap(Arrays.asList(user.getVipId())); |
| | | user.setVipName(vipMap.getData().get(user.getVipId())); |
| | | } |
| | | //获取累计充电数量 |
| | | R<Long> useOrderCount = chargingOrderClient.useOrderCount(user.getId()); |
| | | userDetailDto.setOrderCount(useOrderCount.getData()); |
| | | R<TCompany> tCompanyR = otherClient.unitDetail(user.getCompanyId()); |
| | | if (tCompanyR.getData()!=null){ |
| | | userDetailDto.setUnitName(tCompanyR.getData().getName()); |
| | | } |
| | | 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().toString()); |
| | | return R.ok(userDetailDto); |
| | | } |
| | | |
| | | @ApiOperation(value = "用户详情积分明细", tags = {"用户管理-用户列表"}) |
| | | @PostMapping(value = "/user/points/page") |
| | | public R<Page<TAppUserIntegralChange>> pointsDetail(@RequestBody PointsQueryDto pointsQueryDto) { |
| | | List<Integer> types = new ArrayList<>(); |
| | | if (pointsQueryDto.getType()!=null){ |
| | | types.add(1); |
| | | types.add(2); |
| | | types.add(3); |
| | | types.add(4); |
| | | types.add(5); |
| | | } |
| | | Page<TAppUserIntegralChange> page = integralChangeService.lambdaQuery() |
| | | .eq(TAppUserIntegralChange::getAppUserId, pointsQueryDto.getUserId()) |
| | | .orderByDesc(TAppUserIntegralChange::getCreateTime) |
| | | .eq(pointsQueryDto.getChangeType() != null, TAppUserIntegralChange::getChangeType, pointsQueryDto.getChangeType()) |
| | | .in(!types.isEmpty(), TAppUserIntegralChange::getChangeType, types).page(Page.of(pointsQueryDto.getPageCurr(), pointsQueryDto.getPageSize())); |
| | | |
| | | for (TAppUserIntegralChange record : page.getRecords()) { |
| | | if (record.getChangeType()==2){ |
| | | R<TChargingOrder> tChargingOrderR = chargingOrderClient.orderDetail(Long.valueOf(record.getExtension())); |
| | | if (tChargingOrderR.getData()!=null) { |
| | | record.setOrderNum(tChargingOrderR.getData().getCode()); |
| | | } |
| | | } |
| | | if (record.getChangeType()==6){ |
| | | R<TExchangeOrder> tExchangeOrderR = exchangeOrderClient.orderDetail(Long.valueOf(record.getExtension())); |
| | | if (tExchangeOrderR.getData()!=null){ |
| | | record.setOrderNum(tExchangeOrderR.getData().getCode()); |
| | | } |
| | | } |
| | | } |
| | | |
| | | return R.ok(page); |
| | | |
| | | } |
| | | |
| | | @ApiOperation(value = "用户详情积分明细", tags = {"用户管理-用户列表"}) |
| | | @PostMapping(value = "/user/status/change") |
| | | public R pointsDetail(@RequestBody UserChangeDto userChangeDto) { |
| | | TAppUser appUser = appUserService.getById(userChangeDto.getUserId()); |
| | | appUser.setStatus(userChangeDto.getStatus()); |
| | | appUserService.updateById(appUser); |
| | | return R.ok(); |
| | | } |
| | | |
| | | |
| | | @ApiOperation(value = "赠送会员", tags = {"用户管理-用户列表"}) |
| | | @PostMapping(value = "/user/give/vip") |
| | | public R giveVip(@RequestBody GiveVipDto giveVipDto) { |
| | | TAppUser nowUser = appUserService.getById(giveVipDto.getUserId()); |
| | | |
| | | |
| | | //如果vipEndTime为空或已过期,直接增加 |
| | | if (nowUser.getVipEndTime()==null||nowUser.getVipEndTime().isBefore(LocalDateTime.now())) { |
| | | if (giveVipDto.getType() == 1) { |
| | | nowUser.setVipEndTime(LocalDateTime.now().plusDays(31)); |
| | | //直接增加vipDetail |
| | | } else if (giveVipDto.getType() == 2) { |
| | | nowUser.setVipEndTime(LocalDateTime.now().plusDays(93)); |
| | | } else if (giveVipDto.getType() == 3) { |
| | | nowUser.setVipEndTime(LocalDateTime.now().plusDays(365)); |
| | | } |
| | | //直接赠送优惠卷 |
| | | }else { |
| | | if (giveVipDto.getType() == 1) { |
| | | nowUser.setVipEndTime(nowUser.getVipEndTime().plusDays(31)); |
| | | //如果有这个类型的vip,累加,没有的话,从entTime新增 |
| | | } else if (giveVipDto.getType() == 2) { |
| | | nowUser.setVipEndTime(nowUser.getVipEndTime().plusDays(93)); |
| | | } else if (giveVipDto.getType() == 3) { |
| | | nowUser.setVipEndTime(nowUser.getVipEndTime().plusDays(365)); |
| | | } |
| | | } |
| | | |
| | | |
| | | |
| | |
| | | return R.ok(); |
| | | } |
| | | |
| | | /** |
| | | * 根据用户id查询用户信息 |
| | | * @param appUserIds 用户id |
| | | * @return |
| | | */ |
| | | @PostMapping(value = "/user/getUserByIds") |
| | | public R<List<TAppUser>> getUserByIds(@RequestBody List<Long> appUserIds){ |
| | | return R.ok(appUserService.list(Wrappers.<TAppUser>lambdaQuery().in(TAppUser::getId,appUserIds))); |
| | | } |
| | | |
| | | } |
| | | |