From 3ec572e2cb7adf7d33d2018b24c003d9ef18906a Mon Sep 17 00:00:00 2001 From: 无关风月 <443237572@qq.com> Date: 星期二, 12 十一月 2024 13:32:51 +0800 Subject: [PATCH] 代码提交 --- xinquan-modules/xinquan-user/src/main/java/com/xinquan/user/controller/client/ClientAppUserTreeController.java | 666 +++++++++++++++++++++++++++++++++++++++++++++++++++++++ 1 files changed, 664 insertions(+), 2 deletions(-) diff --git a/xinquan-modules/xinquan-user/src/main/java/com/xinquan/user/controller/client/ClientAppUserTreeController.java b/xinquan-modules/xinquan-user/src/main/java/com/xinquan/user/controller/client/ClientAppUserTreeController.java index d3abb7d..6f2f983 100644 --- a/xinquan-modules/xinquan-user/src/main/java/com/xinquan/user/controller/client/ClientAppUserTreeController.java +++ b/xinquan-modules/xinquan-user/src/main/java/com/xinquan/user/controller/client/ClientAppUserTreeController.java @@ -1,9 +1,42 @@ package com.xinquan.user.controller.client; -import org.springframework.web.bind.annotation.RequestMapping; +import cn.afterturn.easypoi.cache.manager.IFileLoader; +import cn.hutool.core.util.RandomUtil; +import com.alibaba.fastjson2.util.UUIDUtils; +import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper; +import com.baomidou.mybatisplus.extension.plugins.pagination.Page; +import com.xinquan.common.core.domain.R; +import com.xinquan.common.core.utils.page.CollUtils; +import com.xinquan.common.core.utils.page.PageDTO; +import com.xinquan.common.core.web.domain.BaseModel; +import com.xinquan.common.security.service.TokenService; +import com.xinquan.common.security.utils.SecurityUtils; +import com.xinquan.system.api.RemoteUserService; +import com.xinquan.system.api.domain.*; +import com.xinquan.system.api.domain.vo.AppUserEnergyRecordVO; +import com.xinquan.system.api.domain.vo.WateringVO; +import com.xinquan.system.api.feignClient.SysUserClient; +import com.xinquan.system.api.model.LoginUser; +import com.xinquan.user.api.domain.dto.UserEnergyDTO; +import com.xinquan.user.api.domain.dto.UserExchangeRecordDTO; +import com.xinquan.user.domain.vo.EnergyVO; +import com.xinquan.user.domain.vo.ExchangeRecordVO; +import com.xinquan.user.service.*; +import io.swagger.annotations.ApiImplicitParam; +import io.swagger.annotations.ApiImplicitParams; +import io.swagger.annotations.ApiOperation; +import org.apache.poi.ss.formula.functions.T; +import org.springframework.beans.factory.annotation.Autowired; +import org.springframework.util.StringUtils; +import org.springframework.web.bind.annotation.*; -import org.springframework.web.bind.annotation.RestController; +import javax.annotation.Resource; +import java.time.LocalDateTime; +import java.time.LocalTime; +import java.time.temporal.ChronoUnit; +import java.util.ArrayList; +import java.util.List; /** * <p> @@ -16,6 +49,635 @@ @RestController @RequestMapping("/client/app-user-tree") public class ClientAppUserTreeController { + @Resource + private AppUserTreeService appUserTreeService; + @Resource + private AppUserViewingHistoryService appUserViewingHistoryService; + @Resource + private AppUserService appUserService; + @Resource + private AppUserEnergyRecordService appUserEnergyRecordService; + @Resource + private PrizeService prizeService; + @Resource + private PrizeRedemptionRecordService prizeRedemptionRecordService; + @Resource + private RemoteUserService remoteUserService; + @Resource + private SysUserClient sysUserClient; + @PostMapping("/testDelete") + @ApiOperation(value = "手动扣除成长值",tags = "手动扣除成长值") + public R testDelete() { + try { + LocalDateTime now = LocalDateTime.now(); + List<AppUserTree> list1 = appUserTreeService.lambdaQuery().eq(AppUserTree::getSowAgain, 2) + .list(); + for (AppUserTree appUserTree : list1) { + LocalDateTime time = appUserTree.getTime(); + // 计算两个now和time的天数差 + long between = ChronoUnit.DAYS.between(time, now); + if (between>7){ + double v = appUserTree.getTotal() * 0.02; + long roundedValue = Math.round(v); + if ((appUserTree.getTotal() - (int) roundedValue)>0){ + appUserTree.setTotal(appUserTree.getTotal() - (int) roundedValue); + }else{ + appUserTree.setTotal(0); + } + appUserTree.setStatus(1); + }else if (between>=1){ + // 计算两个now和time的小时差 + long betweenHours = ChronoUnit.HOURS.between(time, now); + if (betweenHours>=24){ + double v = appUserTree.getTotal() * 0.01; + long roundedValue = Math.round(v); + if ((appUserTree.getTotal() - (int) roundedValue)>0){ + if (appUserTree.getId().equals(1854054871051481089L)){ + System.err.println(appUserTree.getTotal() - (int) roundedValue); + } + appUserTree.setTotal(appUserTree.getTotal() - (int) roundedValue); + }else{ + appUserTree.setTotal(0); + } + } + } + appUserTreeService.updateById(appUserTree); + } + } catch (Exception e) { + e.printStackTrace(); + } + return R.ok(); + } + @PostMapping("/getUserTree") + @ApiOperation(value = "获取用户树苗",tags = "树苗打卡站") + public R<AppUserTree> getUserTree() { + + LoginUser loginUser = tokenService.getLoginUser(); + if (loginUser!=null) { + Long userId = loginUser.getUserid(); + AppUser byId = appUserService.getById(userId); + byId.setIsFirst(2); + appUserService.updateById(byId); + // 查询用户今日观看疗愈多少秒 + LocalDateTime now = LocalDateTime.now(); + LocalDateTime startOfDay = now.toLocalDate().atStartOfDay(); + LocalDateTime endOfDay = now.toLocalDate().atTime(LocalTime.MAX); + List<AppUserViewingHistory> list = appUserViewingHistoryService + .lambdaQuery().eq(AppUserViewingHistory::getAppUserId, userId) + .eq(AppUserViewingHistory::getViewingType, 1) + .eq(BaseModel::getDelFlag, 0) + .between(AppUserViewingHistory::getCreateTime, startOfDay, endOfDay).list(); + int temp = 0; + for (AppUserViewingHistory appUserViewingHistory : list) { + if (appUserViewingHistory.getTimeLook()!=null){ + temp += appUserViewingHistory.getTimeLook(); + + } + } + AppUserTree one = appUserTreeService.lambdaQuery().eq(AppUserTree::getAppUserId, userId) + .eq(AppUserTree::getSowAgain, 2).one(); + if (one == null) { + AppUserTree appUserTree = new AppUserTree(); + appUserTree.setTime(LocalDateTime.now()); + appUserTree.setAppUserId(userId); + appUserTree.setTreeLevelType(1); + appUserTree.setGrowthValue(0); + appUserTree.setSowAgain(2); + appUserTree.setCreateTime(LocalDateTime.now()); + // 如果用户的签到时间是今天 那么修改为已签到 + if (byId.getSignTime() != null && byId.getSignTime().toLocalDate().equals(LocalDateTime.now().toLocalDate())) { + appUserTree.setIsSign(1); + } else { + appUserTree.setIsSign(2); + } + if (temp >= 120) { + if (appUserTree.getTaskOne() == 2) { + AppUserEnergyRecord appUserEnergyRecord = new AppUserEnergyRecord(); + appUserEnergyRecord.setAppUserId(userId); + appUserEnergyRecord.setChangeType(1); + appUserEnergyRecord.setEnergyValue(10); + appUserEnergyRecord.setReason("完成【每日疗愈30分钟】任务"); + appUserEnergyRecordService.save(appUserEnergyRecord); + byId.setTotalEnergyValue(byId.getTotalEnergyValue() + 10); + } + if (appUserTree.getTaskTwo() == 2) { + AppUserEnergyRecord appUserEnergyRecord = new AppUserEnergyRecord(); + appUserEnergyRecord.setAppUserId(userId); + appUserEnergyRecord.setChangeType(1); + appUserEnergyRecord.setEnergyValue(20); + appUserEnergyRecord.setReason("完成【每日疗愈60分钟】任务"); + appUserEnergyRecordService.save(appUserEnergyRecord); + byId.setTotalEnergyValue(byId.getTotalEnergyValue() + 20); + + } + appUserTree.setTaskOne(1); + appUserTree.setTaskTwo(1); + } else if (temp >= 60) { + if (appUserTree.getTaskOne() == 2) { + AppUserEnergyRecord appUserEnergyRecord = new AppUserEnergyRecord(); + appUserEnergyRecord.setAppUserId(userId); + appUserEnergyRecord.setChangeType(1); + appUserEnergyRecord.setEnergyValue(10); + appUserEnergyRecord.setReason("完成【每日疗愈30分钟】任务"); + appUserEnergyRecordService.save(appUserEnergyRecord); + byId.setTotalEnergyValue(byId.getTotalEnergyValue() + 10); + } + appUserTree.setTaskOne(1); + appUserTree.setTaskTwo(2); + } else { + appUserTree.setTaskOne(2); + appUserTree.setTaskTwo(2); + } + appUserTree.setEnergyValue(byId.getEnergyValue()); + appUserTree.setNextLevel(1000); + appUserTreeService.save(appUserTree); + appUserTree.setTotalEnergyValue(byId.getTotalEnergyValue()); + return R.ok(appUserTree); + } else { + if (temp >= 120) { + if (one.getTaskOne() == 2) { + AppUserEnergyRecord appUserEnergyRecord = new AppUserEnergyRecord(); + appUserEnergyRecord.setAppUserId(userId); + appUserEnergyRecord.setChangeType(1); + appUserEnergyRecord.setEnergyValue(10); + appUserEnergyRecord.setReason("完成【每日疗愈30分钟】任务"); + appUserEnergyRecordService.save(appUserEnergyRecord); + byId.setTotalEnergyValue(byId.getTotalEnergyValue() + 10); + } + if (one.getTaskTwo() == 2) { + AppUserEnergyRecord appUserEnergyRecord = new AppUserEnergyRecord(); + appUserEnergyRecord.setAppUserId(userId); + appUserEnergyRecord.setChangeType(1); + appUserEnergyRecord.setEnergyValue(20); + appUserEnergyRecord.setReason("完成【每日疗愈60分钟】任务"); + appUserEnergyRecordService.save(appUserEnergyRecord); + byId.setTotalEnergyValue(byId.getTotalEnergyValue() + 20); + + } + one.setTaskOne(1); + one.setTaskTwo(1); + } else if (temp >= 60) { + if (one.getTaskOne() == 2) { + AppUserEnergyRecord appUserEnergyRecord = new AppUserEnergyRecord(); + appUserEnergyRecord.setAppUserId(userId); + appUserEnergyRecord.setChangeType(1); + appUserEnergyRecord.setEnergyValue(10); + appUserEnergyRecord.setReason("完成【每日疗愈30分钟】任务"); + appUserEnergyRecordService.save(appUserEnergyRecord); + byId.setTotalEnergyValue(byId.getTotalEnergyValue() + 10); + } + one.setTaskOne(1); + one.setTaskTwo(2); + } else { + one.setTaskOne(2); + one.setTaskTwo(2); + } + // 如果用户的签到时间是今天 那么修改为已签到 + if (byId.getSignTime() != null && byId.getSignTime().toLocalDate().equals(LocalDateTime.now().toLocalDate())) { + one.setIsSign(1); + } else { + one.setIsSign(2); + } + List<TreeLevelSetting> data = sysUserClient.getTreeGroup().getData(); + + Integer total1 = one.getTotal(); + // 根据总能量值 确定他在哪一等级 + int x = 1; + int tem = 0; + for (TreeLevelSetting datum : data) { + if (total1 == 0) { + Integer growthValue = data.get(1).getGrowthValue(); + tem = growthValue; + break; + } else if (total1 >= datum.getGrowthValue()) { + x = datum.getTreeLevelType(); + } + } + if (x == 10) { + // 如果等级为10那么成长阈值是10级减去9级 + int ten = 0; + int nine = 0; + for (TreeLevelSetting datum : data) { + if (datum.getTreeLevelType() == 10) { + ten = datum.getGrowthValue(); + } + if (datum.getTreeLevelType() == 9) { + nine = datum.getGrowthValue(); + } + } + tem = ten - nine; + total1 = tem; + } else { + // 根据当前所在等级查询成长值 + int a = data.get(x).getGrowthValue() - data.get(x - 1).getGrowthValue(); + tem = a; + total1 = Math.abs(total1 - data.get(x - 1).getGrowthValue()); + } + one.setNextLevel(tem); + one.setTreeLevelType(x); + // 将当前成长值更新 + one.setGrowthValue(total1); + one.setEnergyValue(byId.getEnergyValue()); + appUserTreeService.updateById(one); + one.setTotalEnergyValue(byId.getTotalEnergyValue()); + return R.ok(one); + } + }else{ + List<TreeLevelSetting> data = sysUserClient.getTreeGroup().getData(); + + AppUserTree appUserTree = new AppUserTree(); + appUserTree.setTreeLevelType(1); + appUserTree.setTotal(0); + appUserTree.setGrowthValue(0); + for (TreeLevelSetting datum : data) { + if (datum.getTreeLevelType()==2){ + appUserTree.setNextLevel(datum.getGrowthValue()); + } + } + appUserTree.setSowAgain(2); + appUserTree.setStatus(2); + appUserTree.setTaskOne(2); + appUserTree.setEnergyValue(0); + appUserTree.setTaskTwo(2); + appUserTree.setIsSign(2); + appUserTree.setTotalEnergyValue(0); + return R.ok(appUserTree); + } + } + @Autowired + private TokenService tokenService; + @PostMapping("/restart") + @ApiOperation(value = "重新播种",tags = "树苗打卡站") + public R restart() { + LoginUser loginUser = tokenService.getLoginUser(); + if (loginUser==null){ + return R.tokenError("登录失效"); + } + Long userId = loginUser.getUserid(); + if(userId ==null || userId == 0)return R.tokenError("登录失效"); + AppUserTree one = appUserTreeService.lambdaQuery().eq(AppUserTree::getAppUserId, userId) + .eq(AppUserTree::getSowAgain,2).one(); + one.setSowAgain(1); + appUserTreeService.updateById(one); + AppUserTree appUserTree = new AppUserTree(); + appUserTree.setAppUserId(userId); + appUserTree.setTreeLevelType(1); + appUserTree.setGrowthValue(0); + appUserTree.setSowAgain(2); + appUserTree.setCreateTime(LocalDateTime.now()); + appUserTreeService.save(appUserTree); + return R.ok(); + } + + @Resource + private NoticeRecordService noticeRecordService; + @PostMapping("/watering") + @ApiOperation(value = "浇水 返回值true证明升级了 false没升级",tags = "树苗打卡站") + public R<WateringVO> watering() { + + + + LoginUser loginUser = tokenService.getLoginUser(); + if (loginUser==null){ + return R.tokenError("登录失效"); + } + Long userId = loginUser.getUserid(); + AppUser byId = appUserService.getById(userId); + if (byId.getEnergyValue() == 0){ + return R.energyValueError("能量值不足"); + + } + WateringVO wateringVO = new WateringVO(); + + AppUserTree one = appUserTreeService.lambdaQuery().eq(AppUserTree::getAppUserId, userId) + .eq(AppUserTree::getSowAgain,2).one(); + one.setStatus(2); + one.setTotal(one.getTotal()+byId.getEnergyValue()); + one.setTime(LocalDateTime.now()); + appUserTreeService.updateById(one); + byId.setEnergyValue(0); + appUserService.updateById(byId); + List<TreeLevelSetting> data = sysUserClient.getTreeGroup().getData(); + int y = one.getTreeLevelType(); + Integer total1 = one.getTotal(); + // 根据总能量值 确定他在哪一等级 + int x = 1; + int tem = 0; + for (TreeLevelSetting datum : data) { + if (total1 == 0){ + Integer growthValue = data.get(1).getGrowthValue(); + tem = growthValue; + break; + }else if (total1>=datum.getGrowthValue()){ + x = datum.getTreeLevelType(); + } + } + if (x == 10){ + // 如果等级为10那么成长阈值是10级减去9级 + int ten=0; + int nine = 0; + for (TreeLevelSetting datum : data) { + if (datum.getTreeLevelType()==10){ + ten = datum.getGrowthValue(); + } + if (datum.getTreeLevelType()==9){ + nine = datum.getGrowthValue(); + } + } + tem = ten-nine; + total1 = tem; + }else{ + // 根据当前所在等级查询成长值 + int a = data.get(x).getGrowthValue()-data.get(x-1).getGrowthValue(); + tem = a; + total1 = Math.abs(total1-data.get(x-1).getGrowthValue()); + } + one.setNextLevel(tem); + one.setTreeLevelType(x); + // 将当前成长值更新 + one.setGrowthValue(total1); + one.setEnergyValue(byId.getEnergyValue()); + appUserTreeService.updateById(one); + wateringVO.setNextLevel(tem); + wateringVO.setTreeLevelType(x); + wateringVO.setGrowthValue(total1); + if (x>y){ + wateringVO.setIsNext(true); + NoticeRecord noticeRecord = new NoticeRecord(); + noticeRecord.setAppUserId(userId); + noticeRecord.setReadStatus(1); + noticeRecord.setNoticeType(1); + noticeRecord.setTitle("树苗升级通知"); + noticeRecord.setContent("恭喜,您的树苗已升至"+x+"级,"+"继续加油哦"); + noticeRecordService.save(noticeRecord); + } + return R.ok(wateringVO); + } + @PostMapping("/sign") + @ApiOperation(value = "签到",tags = "树苗打卡站") + public R sign() { + LoginUser loginUser = tokenService.getLoginUser(); + if (loginUser==null){ + return R.tokenError("登录失效"); + } + Long userId = loginUser.getUserid(); + // 给用户加10能量 + AppUser byId = appUserService.getById(userId); + byId.setEnergyValue(byId.getEnergyValue()+10); + byId.setSignTime(LocalDateTime.now()); + byId.setTotalEnergyValue(byId.getTotalEnergyValue()+10); + appUserService.updateById(byId); + AppUserEnergyRecord appUserEnergyRecord = new AppUserEnergyRecord(); + appUserEnergyRecord.setAppUserId(userId); + + appUserEnergyRecord.setChangeType(1); + appUserEnergyRecord.setEnergyValue(10); + appUserEnergyRecord.setReason("签到"); + appUserEnergyRecordService.save(appUserEnergyRecord); + return R.ok(); + } + + @PostMapping("/isFirst") + @ApiOperation(value = "是否首次进入 ",tags = "树苗打卡站") + public R isFirst() { + LoginUser loginUser = tokenService.getLoginUser(); + if (loginUser==null){ + return R.tokenError("登录失效"); + } + Long userId = loginUser.getUserid(); + if(userId ==null || userId == 0)return R.tokenError("登录失效"); + AppUser byId = appUserService.getById(userId); + System.err.println("调用是否弹窗"+byId.getIsFirst()); + if (byId.getIsFirst() == 1){ + byId.setIsFirst(2); + appUserService.updateById(byId); + return R.ok(true); + }else{ + return R.ok(false); + } + } + @PostMapping("/userEnergyDetail") + @ApiOperation(tags = "管理后台-用户管理",value = "用户详情-能量值明细 ") + public R<PageDTO<AppUserEnergyRecordVO>> userEnergyDetail(@RequestBody UserEnergyDTO dto) { + String startTime = null; + String endTime = null; + if (org.springframework.util.StringUtils.hasLength(dto.getTime())){ + String[] split = dto.getTime().split(" - "); + startTime = split[0]+" 00:00:00"; + endTime = split[1]+" 23:59:59"; + } + String userId = dto.getUid(); + EnergyVO energyVO = new EnergyVO(); + energyVO.setEnergyTotal(appUserService.getById(userId).getTotalEnergyValue()); + LambdaQueryWrapper<AppUserEnergyRecord> lambdaQueryWrapper = new LambdaQueryWrapper<>(); + if (dto.getChangeType()!=null){ + switch (dto.getChangeType()){ + case 1: + lambdaQueryWrapper.eq(AppUserEnergyRecord::getChangeType, 1); + break; + case 2: + lambdaQueryWrapper.eq(AppUserEnergyRecord::getChangeType, 2); + break; + } + } + lambdaQueryWrapper.like(StringUtils.hasLength(dto.getReason()),AppUserEnergyRecord::getReason,dto.getReason()); + lambdaQueryWrapper.between(startTime!=null,BaseModel::getCreateTime,startTime,endTime); + lambdaQueryWrapper.eq(AppUserEnergyRecord::getAppUserId, userId).orderByDesc(BaseModel::getCreateTime); + Page<AppUserEnergyRecord> page = appUserEnergyRecordService.page(new Page<>(dto.getPageCurr(), dto.getPageSize()), lambdaQueryWrapper); + if (CollUtils.isEmpty(page.getRecords())){ + PageDTO<AppUserEnergyRecordVO> empty = PageDTO.empty(page); + energyVO.setList(new ArrayList<AppUserEnergyRecordVO>()); + return R.ok(empty); + } + PageDTO<AppUserEnergyRecordVO> appUserEnergyRecordVOPageDTO = PageDTO.of(page, AppUserEnergyRecordVO.class); + for (AppUserEnergyRecordVO appUserEnergyRecordVO : appUserEnergyRecordVOPageDTO.getList()) { + AppUser byId = appUserService.getById(appUserEnergyRecordVO.getAppUserId()); + appUserEnergyRecordVO.setPhone(byId.getNickname()); + appUserEnergyRecordVO.setName(byId.getCellPhone()); + if (appUserEnergyRecordVO.getUpdateId()!=null){ + SysUser data = remoteUserService.getSysUserById(appUserEnergyRecordVO.getUpdateId() + "").getData(); + if (data!=null){ + appUserEnergyRecordVO.setPhone(data.getUserName()); + appUserEnergyRecordVO.setName(data.getNickName()); + } + + } + } + energyVO.setList(appUserEnergyRecordVOPageDTO.getList()); + return R.ok(appUserEnergyRecordVOPageDTO); + } + @PostMapping("/userExchangeRecordList") + @ApiOperation(value = "用户详情-兑换记录 ",tags = "管理后台-用户管理") + public R<PageDTO<ExchangeRecordVO>> userExchangeRecordList(@RequestBody UserExchangeRecordDTO dto) { + Page<PrizeRedemptionRecord> page = prizeRedemptionRecordService.lambdaQuery() + .eq(PrizeRedemptionRecord::getAppUserId, dto.getUid()) + .orderByDesc(BaseModel::getCreateTime).page(new Page<>(dto.getPageCurr(), dto.getPageSize())); + if (CollUtils.isEmpty(page.getRecords())){ + PageDTO<ExchangeRecordVO> empty = PageDTO.empty(page); + return R.ok(empty); + } + PageDTO<ExchangeRecordVO> res = PageDTO.of(page, ExchangeRecordVO.class); + for (ExchangeRecordVO record : res.getList()) { + Prize temp = prizeService.lambdaQuery() + .eq(Prize::getId, record.getPrizeId()).one(); + if (temp != null){ + record.setName(temp.getName()); + record.setCoverUrl(temp.getCoverUrl()); + record.setWorth(temp.getWorth()); + record.setEnergyValue(temp.getEnergyValue()); + } + } + return R.ok(res); + } + @PostMapping("/energyDetail") + @ApiOperation(value = "能量值明细 ",tags = "树苗打卡站") + @ApiImplicitParams({ + @ApiImplicitParam(name = "state", value = "状态1全部 2增加 3扣除", dataType = "int", required = false), + @ApiImplicitParam(name = "pageCurr", value = "分页参数,当前页码", dataType = "Integer", required = true), + @ApiImplicitParam(name = "pageSize", value = "分页参数,每页数量", dataType = "Integer", required = true) + }) + public R<List<AppUserEnergyRecordVO>> energyDetail(Integer state,Integer pageCurr,Integer pageSize) { + LoginUser loginUser = tokenService.getLoginUser(); + if (loginUser==null){ + return R.tokenError("登录失效"); + } + Long userId = loginUser.getUserid(); + EnergyVO energyVO = new EnergyVO(); + energyVO.setEnergyTotal(appUserService.getById(userId).getTotalEnergyValue()); + LambdaQueryWrapper<AppUserEnergyRecord> lambdaQueryWrapper = new LambdaQueryWrapper<>(); + if (state!=null){ + switch (state){ + case 2: + lambdaQueryWrapper.eq(AppUserEnergyRecord::getChangeType, 1); + break; + case 3: + lambdaQueryWrapper.eq(AppUserEnergyRecord::getChangeType, 2); + break; + } + } + lambdaQueryWrapper.eq(AppUserEnergyRecord::getAppUserId, userId).orderByDesc(BaseModel::getCreateTime); + Page<AppUserEnergyRecord> page = appUserEnergyRecordService.page(new Page<>(pageCurr, pageSize), lambdaQueryWrapper); + if (CollUtils.isEmpty(page.getRecords())){ + PageDTO<AppUserEnergyRecordVO> empty = PageDTO.empty(page); + energyVO.setList(new ArrayList<AppUserEnergyRecordVO>()); + return R.ok(new ArrayList<>()); + } + PageDTO<AppUserEnergyRecordVO> appUserEnergyRecordVOPageDTO = PageDTO.of(page, AppUserEnergyRecordVO.class); + energyVO.setList(appUserEnergyRecordVOPageDTO.getList()); + return R.ok(appUserEnergyRecordVOPageDTO.getList()); + } + @PostMapping("/goodsList") + @ApiOperation(value = "能量兑换礼物列表 ",tags = "树苗打卡站") + @ApiImplicitParams({ + @ApiImplicitParam(name = "pageCurr", value = "分页参数,当前页码", dataType = "Integer", required = true), + @ApiImplicitParam(name = "pageSize", value = "分页参数,每页数量", dataType = "Integer", required = true) + }) + public R<List<Prize>> goodsList(Integer pageCurr,Integer pageSize) { + LoginUser loginUser = tokenService.getLoginUser(); + if (loginUser==null){ + return R.tokenError("登录失效"); + } + Long userId = loginUser.getUserid(); + Page<Prize> page = prizeService.lambdaQuery() + .eq(Prize::getStatus, 1) + .orderByDesc(BaseModel::getCreateTime).page(new Page<>(pageCurr, pageSize)); + + if (CollUtils.isEmpty(page.getRecords())){ + PageDTO<Prize> empty = PageDTO.empty(page); + return R.ok(new ArrayList<>()); + } + for (Prize record : page.getRecords()) { + PrizeRedemptionRecord one = prizeRedemptionRecordService.lambdaQuery() + .eq(PrizeRedemptionRecord::getPrizeId, record.getId()) + .eq(PrizeRedemptionRecord::getAppUserId, userId).one(); + if (one == null){ + record.setReceiveStatus(2); + }else{ + record.setReceiveStatus(1); + } + } + PageDTO<Prize> res = PageDTO.of(page, Prize.class); + return R.ok(res.getList()); + } + @PostMapping("/exchange") + @ApiOperation(value = "兑换奖品 ",tags = "树苗打卡站") + @ApiImplicitParams({ + @ApiImplicitParam(name = "prizeId", value = "奖品id", dataType = "Long", required = true), + }) + public R exchange(Long prizeId) { + LoginUser loginUser = tokenService.getLoginUser(); + if (loginUser==null){ + return R.tokenError("登录失效"); + } + Long userId = loginUser.getUserid(); + AppUser byId1 = appUserService.getById(userId); + Prize byId = prizeService.getById(prizeId); + if (byId1.getTotalEnergyValue()<byId.getEnergyValue()){ + return R.fail("能量值不足"); + } + PrizeRedemptionRecord one = prizeRedemptionRecordService.lambdaQuery() + .eq(PrizeRedemptionRecord::getPrizeId, prizeId) + .eq(PrizeRedemptionRecord::getAppUserId, userId).one(); + if (one!=null){ + return R.fail("奖品已兑换"); + } + // 扣去能量值 + Integer totalEnergyValue = byId1.getTotalEnergyValue(); + byId1.setTotalEnergyValue(totalEnergyValue-byId.getEnergyValue()); + appUserService.updateById(byId1); + // 增加记录 + AppUserEnergyRecord appUserEnergyRecord = new AppUserEnergyRecord(); + appUserEnergyRecord.setAppUserId(userId); + appUserEnergyRecord.setChangeType(2); + appUserEnergyRecord.setEnergyValue(byId.getEnergyValue()); + appUserEnergyRecord.setReason("兑换礼品"); + appUserEnergyRecordService.save(appUserEnergyRecord); + + PrizeRedemptionRecord prizeRedemptionRecord = new PrizeRedemptionRecord(); + prizeRedemptionRecord.setStatus(1); + prizeRedemptionRecord.setEnergyValue(byId.getEnergyValue()); + prizeRedemptionRecord.setPrizeId(prizeId); + prizeRedemptionRecord.setAppUserId(userId); + prizeRedemptionRecord.setCreateTime(LocalDateTime.now()); + String code = RandomUtil.randomNumbers(6); + prizeRedemptionRecord.setCode(code); + prizeRedemptionRecordService.save(prizeRedemptionRecord); + // 随机生成6位纯数字验证码 + + return R.ok(code); + } + @PostMapping("/exchangeRecordList") + @ApiOperation(value = "兑换记录 ",tags = "树苗打卡站") + @ApiImplicitParams({ + @ApiImplicitParam(name = "pageCurr", value = "分页参数,当前页码", dataType = "Integer", required = true), + @ApiImplicitParam(name = "pageSize", value = "分页参数,每页数量", dataType = "Integer", required = true) + }) + public R<List<ExchangeRecordVO>> exchangeRecordList(Integer pageCurr, Integer pageSize) { + LoginUser loginUser = tokenService.getLoginUser(); + if (loginUser==null){ + return R.tokenError("登录失效"); + } + Long userId = loginUser.getUserid(); + Page<PrizeRedemptionRecord> page = prizeRedemptionRecordService.lambdaQuery() + .eq(PrizeRedemptionRecord::getAppUserId, userId) + .orderByDesc(BaseModel::getCreateTime).page(new Page<>(pageCurr, pageSize)); + if (CollUtils.isEmpty(page.getRecords())){ + PageDTO<ExchangeRecordVO> empty = PageDTO.empty(page); + return R.ok(new ArrayList<ExchangeRecordVO>()); + } + PageDTO<ExchangeRecordVO> res = PageDTO.of(page, ExchangeRecordVO.class); + for (ExchangeRecordVO record : res.getList()) { + Prize temp = prizeService.lambdaQuery() + .eq(Prize::getId, record.getPrizeId()).one(); + if (temp != null){ + record.setName(temp.getName()); + record.setCoverUrl(temp.getCoverUrl()); + record.setWorth(temp.getWorth()); + record.setEnergyValue(temp.getEnergyValue()); + } + } + return R.ok(res.getList()); + } } -- Gitblit v1.7.1