package com.xinquan.user.controller.client; 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 javax.annotation.Resource; import java.time.LocalDate; import java.time.LocalDateTime; import java.time.LocalTime; import java.time.temporal.ChronoUnit; import java.util.ArrayList; import java.util.List; /** *

* 用户树苗表 前端控制器 *

* * @author mitao * @since 2024-08-21 */ @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 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 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 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 >= 3600) { 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); byId.setEnergyValue(byId.getEnergyValue() + 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); byId.setEnergyValue(byId.getEnergyValue() + 20); } appUserTree.setTaskOne(1); appUserTree.setTaskTwo(1); } else if (temp >= 1800) { 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); byId.setEnergyValue(byId.getEnergyValue() + 10); } appUserTree.setTaskOne(2); appUserTree.setTaskTwo(1); } 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 >= 3600) { 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); byId.setEnergyValue(byId.getEnergyValue() + 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.setTaskTwo(1); byId.setEnergyValue(byId.getEnergyValue() + 20); } } else if (temp >= 1800) { 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); byId.setEnergyValue(byId.getEnergyValue() + 10); } } 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 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()); appUserService.updateById(byId); return R.ok(one); } }else{ List 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); } } /** * 刷新用户观看和任务完成记录 * @return */ @PostMapping("/getUserEnergy/{id}") public R getUserEnergy(@PathVariable("id")Long id) { AppUser byId = appUserService.getById(id); byId.setIsFirst(2); appUserService.updateById(byId); // 查询用户今日观看疗愈多少秒 LocalDateTime now = LocalDateTime.now(); LocalDateTime startOfDay = now.toLocalDate().atStartOfDay(); LocalDateTime endOfDay = now.toLocalDate().atTime(LocalTime.MAX); List list = appUserViewingHistoryService .lambdaQuery().eq(AppUserViewingHistory::getAppUserId, id) .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, id) .eq(AppUserTree::getSowAgain, 2).one(); if (one == null) { AppUserTree appUserTree = new AppUserTree(); appUserTree.setTime(LocalDateTime.now()); appUserTree.setAppUserId(id); 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 >= 3600) { if (appUserTree.getTaskOne() == 2) { AppUserEnergyRecord appUserEnergyRecord = new AppUserEnergyRecord(); appUserEnergyRecord.setAppUserId(id); appUserEnergyRecord.setChangeType(1); appUserEnergyRecord.setEnergyValue(10); appUserEnergyRecord.setReason("完成【每日疗愈30分钟】任务"); appUserEnergyRecordService.save(appUserEnergyRecord); byId.setTotalEnergyValue(byId.getTotalEnergyValue() + 10); byId.setEnergyValue(byId.getEnergyValue() + 10); } if (appUserTree.getTaskTwo() == 2) { AppUserEnergyRecord appUserEnergyRecord = new AppUserEnergyRecord(); appUserEnergyRecord.setAppUserId(id); appUserEnergyRecord.setChangeType(1); appUserEnergyRecord.setEnergyValue(20); appUserEnergyRecord.setReason("完成【每日疗愈60分钟】任务"); appUserEnergyRecordService.save(appUserEnergyRecord); byId.setTotalEnergyValue(byId.getTotalEnergyValue() + 20); byId.setEnergyValue(byId.getEnergyValue() + 20); } appUserTree.setTaskOne(1); appUserTree.setTaskTwo(1); } else if (temp >= 1800) { if (appUserTree.getTaskOne() == 2) { AppUserEnergyRecord appUserEnergyRecord = new AppUserEnergyRecord(); appUserEnergyRecord.setAppUserId(id); appUserEnergyRecord.setChangeType(1); appUserEnergyRecord.setEnergyValue(10); appUserEnergyRecord.setReason("完成【每日疗愈30分钟】任务"); appUserEnergyRecordService.save(appUserEnergyRecord); byId.setTotalEnergyValue(byId.getTotalEnergyValue() + 10); byId.setEnergyValue(byId.getEnergyValue() + 10); } appUserTree.setTaskOne(2); appUserTree.setTaskTwo(1); } else { appUserTree.setTaskOne(2); appUserTree.setTaskTwo(2); } appUserTree.setEnergyValue(byId.getEnergyValue()); appUserTree.setNextLevel(1000); appUserTreeService.save(appUserTree); appUserTree.setTotalEnergyValue(byId.getTotalEnergyValue()); return R.ok(); } else { if (temp >= 3600) { if (one.getTaskOne() == 2) { AppUserEnergyRecord appUserEnergyRecord = new AppUserEnergyRecord(); appUserEnergyRecord.setAppUserId(id); appUserEnergyRecord.setChangeType(1); appUserEnergyRecord.setEnergyValue(10); appUserEnergyRecord.setReason("完成【每日疗愈30分钟】任务"); appUserEnergyRecordService.save(appUserEnergyRecord); byId.setTotalEnergyValue(byId.getTotalEnergyValue() + 10); one.setTaskOne(1); byId.setEnergyValue(byId.getEnergyValue() + 10); } if (one.getTaskTwo() == 2) { AppUserEnergyRecord appUserEnergyRecord = new AppUserEnergyRecord(); appUserEnergyRecord.setAppUserId(id); appUserEnergyRecord.setChangeType(1); appUserEnergyRecord.setEnergyValue(20); appUserEnergyRecord.setReason("完成【每日疗愈60分钟】任务"); appUserEnergyRecordService.save(appUserEnergyRecord); byId.setTotalEnergyValue(byId.getTotalEnergyValue() + 20); one.setTaskTwo(1); byId.setEnergyValue(byId.getEnergyValue() + 20); } } else if (temp >= 1800) { if (one.getTaskOne() == 2) { AppUserEnergyRecord appUserEnergyRecord = new AppUserEnergyRecord(); appUserEnergyRecord.setAppUserId(id); appUserEnergyRecord.setChangeType(1); appUserEnergyRecord.setEnergyValue(10); appUserEnergyRecord.setReason("完成【每日疗愈30分钟】任务"); appUserEnergyRecordService.save(appUserEnergyRecord); byId.setTotalEnergyValue(byId.getTotalEnergyValue() + 10); one.setTaskOne(1); byId.setEnergyValue(byId.getEnergyValue() + 10); } } 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 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()); appUserService.updateById(byId); return R.ok(); } } @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 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(); if (one.getTreeLevelType() == 10){ return R.fail("成长值已满,请重新播种"); } one.setStatus(2); one.setTotal(one.getTotal()+byId.getEnergyValue()); one.setTime(LocalDateTime.now()); appUserTreeService.updateById(one); byId.setEnergyValue(0); appUserService.updateById(byId); List 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); if (one.getTotal()>=data.get(9).getGrowthValue()){ // 本次浇水量 byId.setEnergyValue(one.getTotal()-data.get(9).getGrowthValue()); appUserService.updateById(byId); one.setTotal(data.get(9).getGrowthValue()); appUserTreeService.updateById(one); } wateringVO.setNextLevel(tem); wateringVO.setTreeLevelType(x); wateringVO.setGrowthValue(total1); wateringVO.setEnergyValue(byId.getEnergyValue()); 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); if (byId.getSignTime()!=null && byId.getSignTime().toLocalDate().equals(LocalDate.now())){ return R.fail("您今日已签到"); } 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> 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 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 page = appUserEnergyRecordService.page(new Page<>(dto.getPageCurr(), dto.getPageSize()), lambdaQueryWrapper); if (CollUtils.isEmpty(page.getRecords())){ PageDTO empty = PageDTO.empty(page); energyVO.setList(new ArrayList()); return R.ok(empty); } PageDTO 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> userExchangeRecordList(@RequestBody UserExchangeRecordDTO dto) { Page page = prizeRedemptionRecordService.lambdaQuery() .eq(PrizeRedemptionRecord::getAppUserId, dto.getUid()) .orderByDesc(BaseModel::getCreateTime).page(new Page<>(dto.getPageCurr(), dto.getPageSize())); if (CollUtils.isEmpty(page.getRecords())){ PageDTO empty = PageDTO.empty(page); return R.ok(empty); } PageDTO 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> 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 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 page = appUserEnergyRecordService.page(new Page<>(pageCurr, pageSize), lambdaQueryWrapper); if (CollUtils.isEmpty(page.getRecords())){ PageDTO empty = PageDTO.empty(page); energyVO.setList(new ArrayList()); return R.ok(new ArrayList<>()); } PageDTO 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> goodsList(Integer pageCurr,Integer pageSize) { LoginUser loginUser = tokenService.getLoginUser(); if (loginUser==null){ return R.tokenError("登录失效"); } Long userId = loginUser.getUserid(); Page page = prizeService.lambdaQuery() .eq(Prize::getStatus, 1) .orderByDesc(BaseModel::getCreateTime).page(new Page<>(pageCurr, pageSize)); if (CollUtils.isEmpty(page.getRecords())){ PageDTO 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 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()> exchangeRecordList(Integer pageCurr, Integer pageSize) { LoginUser loginUser = tokenService.getLoginUser(); if (loginUser==null){ return R.tokenError("登录失效"); } Long userId = loginUser.getUserid(); Page page = prizeRedemptionRecordService.lambdaQuery() .eq(PrizeRedemptionRecord::getAppUserId, userId) .orderByDesc(BaseModel::getCreateTime).page(new Page<>(pageCurr, pageSize)); if (CollUtils.isEmpty(page.getRecords())){ PageDTO empty = PageDTO.empty(page); return R.ok(new ArrayList()); } PageDTO 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()); } }