From 0c51a577db337520452022d9d6a22b720ef858d4 Mon Sep 17 00:00:00 2001 From: 无关风月 <443237572@qq.com> Date: 星期二, 31 十二月 2024 14:13:01 +0800 Subject: [PATCH] 全部代码、数据库提交 --- xinquan-modules/xinquan-user/src/main/java/com/xinquan/user/controller/client/ClientPrizeRedemptionRecordController.java | 261 +++++++++++++++++++++++++++++++++++++++++++++++++++ 1 files changed, 259 insertions(+), 2 deletions(-) diff --git a/xinquan-modules/xinquan-user/src/main/java/com/xinquan/user/controller/client/ClientPrizeRedemptionRecordController.java b/xinquan-modules/xinquan-user/src/main/java/com/xinquan/user/controller/client/ClientPrizeRedemptionRecordController.java index 4fc6ba4..f5ce7b4 100644 --- a/xinquan-modules/xinquan-user/src/main/java/com/xinquan/user/controller/client/ClientPrizeRedemptionRecordController.java +++ b/xinquan-modules/xinquan-user/src/main/java/com/xinquan/user/controller/client/ClientPrizeRedemptionRecordController.java @@ -1,9 +1,46 @@ package com.xinquan.user.controller.client; -import org.springframework.web.bind.annotation.RequestMapping; +import cn.afterturn.easypoi.excel.ExcelExportUtil; +import cn.afterturn.easypoi.excel.entity.ExportParams; +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.WebUtils; +import com.xinquan.common.core.utils.page.CollUtils; +import com.xinquan.common.core.utils.page.PageDTO; +import com.xinquan.common.security.service.TokenService; +import com.xinquan.common.security.utils.SecurityUtils; -import org.springframework.web.bind.annotation.RestController; +import com.xinquan.meditation.api.feign.RemoteMeditationService; +import com.xinquan.system.api.RemoteUserService; +import com.xinquan.system.api.domain.*; +import com.xinquan.system.api.model.LoginUser; +import com.xinquan.user.api.domain.dto.OrderListDTO; +import com.xinquan.user.api.domain.dto.PrizeRecordDTO; +import com.xinquan.user.domain.export.PrizeExport; +import com.xinquan.user.domain.export.WithdrawExport; +import com.xinquan.user.service.AppUserService; +import com.xinquan.user.service.PrizeRedemptionRecordService; +import com.xinquan.user.service.PrizeService; +import io.swagger.annotations.ApiOperation; +import org.apache.poi.ss.usermodel.Workbook; +import org.springframework.beans.factory.annotation.Autowired; +import org.springframework.util.StringUtils; +import org.springframework.web.bind.annotation.*; + +import javax.annotation.Resource; +import javax.servlet.ServletOutputStream; +import javax.servlet.http.HttpServletResponse; +import java.io.IOException; +import java.net.URLEncoder; +import java.time.LocalDateTime; +import java.time.format.DateTimeFormatter; +import java.util.ArrayList; +import java.util.Arrays; +import java.util.List; +import java.util.Objects; +import java.util.stream.Collectors; /** * <p> @@ -16,6 +53,226 @@ @RestController @RequestMapping("/client/prize-redemption-record") public class ClientPrizeRedemptionRecordController { + @Resource + private PrizeService prizeService; + @Resource + private PrizeRedemptionRecordService prizeRedemptionRecordService; + @Resource + private AppUserService appUserService; + @Resource + private RemoteUserService remoteUserService; + @PostMapping("/getPrizeRecordCount") + public R<String> getPrizeRecordCount(){ + List<PrizeRedemptionRecord> list = prizeRedemptionRecordService.lambdaQuery() + .eq(PrizeRedemptionRecord::getStatus, 1).list(); + return R.ok(list.size()+""); + } + + @ApiOperation(value = "兑换记录管理导出", tags = {"管理后台-兑换记录管理"}) + @PutMapping("/export") + public void export(@RequestBody PrizeRecordDTO courseDTO){ + String startTime = null; + String endTime = null; + if (org.springframework.util.StringUtils.hasLength(courseDTO.getTime())){ + String[] split = courseDTO.getTime().split(" - "); + startTime = split[0]+" 00:00:00"; + endTime = split[1]+" 23:59:59"; + } + List<Long> longs = new ArrayList<>(); + LambdaQueryWrapper<PrizeRedemptionRecord> courseLambdaQueryWrapper = new LambdaQueryWrapper<>(); + if (StringUtils.hasLength(courseDTO.getIds())){ + courseLambdaQueryWrapper.in(PrizeRedemptionRecord::getId, Arrays.asList(courseDTO.getIds().split(","))); + } + if (startTime!=null){ + courseLambdaQueryWrapper.between(PrizeRedemptionRecord::getCreateTime, startTime, endTime); + } + if (courseDTO.getStatus()!=null){ + courseLambdaQueryWrapper.eq(PrizeRedemptionRecord::getStatus, courseDTO.getStatus()); + } + courseLambdaQueryWrapper.orderByDesc(PrizeRedemptionRecord::getCreateTime); + if (org.springframework.util.StringUtils.hasLength(courseDTO.getUserNameOrPhone())){ + List<Long> collect = appUserService.lambdaQuery().like(AppUser::getNickname, courseDTO.getUserNameOrPhone()).list() + .stream().map(AppUser::getId).collect(Collectors.toList()); + longs.addAll(collect); + List<Long> collect1 = appUserService.lambdaQuery().like(AppUser::getCellPhone, courseDTO.getUserNameOrPhone()).list() + .stream().map(AppUser::getId).collect(Collectors.toList()); + longs.addAll(collect1); + if (longs.isEmpty()){ + longs.add(-1L); + } + courseLambdaQueryWrapper.in(PrizeRedemptionRecord::getAppUserId, longs); + } + if (org.springframework.util.StringUtils.hasLength(courseDTO.getName())){ + List<Long> collect = prizeService.lambdaQuery().like(Prize::getName, courseDTO.getName()).list() + .stream().map(Prize::getId).collect(Collectors.toList()); + if (collect.isEmpty()){ + collect.add(-1L); + } + courseLambdaQueryWrapper.in(PrizeRedemptionRecord::getPrizeId, collect); + } + List<PrizeExport> prizeExports = new ArrayList<>(); + + List<PrizeRedemptionRecord> page = prizeRedemptionRecordService.list(courseLambdaQueryWrapper); + for (PrizeRedemptionRecord record : page) { + Prize byId = prizeService.getById(record.getPrizeId()); + + record.setUid(record.getId().toString()); + AppUser byId1 = appUserService.getById(record.getAppUserId()); + + PrizeExport prizeExport = new PrizeExport(); + DateTimeFormatter df = DateTimeFormatter.ofPattern("yyyy-MM-dd HH:mm:ss"); + String format = df.format(record.getCreateTime()); + prizeExport.setCreateTime(format); + if (Objects.nonNull(byId1)){ + record.setUserName(byId1.getNickname()); + record.setAvatar(byId1.getAvatar()); + record.setCellPhone(byId1.getCellPhone()); + prizeExport.setUserName(byId1.getNickname()); + prizeExport.setCellphone(byId1.getCellPhone()); + } + if (Objects.nonNull(byId)){ + record.setName(byId.getName()); + record.setWorth(byId.getWorth()); + record.setEnergyValue(byId.getEnergyValue()); + prizeExport.setPrizeName(byId.getName()); + prizeExport.setAmount(byId.getWorth()+""); + prizeExport.setEnergyValue(byId.getEnergyValue()+""); + } + prizeExport.setStatus(record.getStatus()+""); + prizeExports.add(prizeExport); + } + Workbook workbook = ExcelExportUtil.exportExcel(new ExportParams(), PrizeExport.class, prizeExports); + HttpServletResponse response = WebUtils.response(); + response.setContentType("application/vnd.ms-excel"); + response.setCharacterEncoding("utf-8"); + ServletOutputStream outputStream = null; + try { + String fileName = URLEncoder.encode("兑换记录管理导出.xls", "utf-8"); + response.setHeader("Content-Disposition", "attachment;filename=" + fileName); + response.setContentType("application/vnd.ms-excel;charset=UTF-8"); + response.setHeader("Pragma", "no-cache"); + response.setHeader("Cache-Control", "no-cache"); + outputStream = response.getOutputStream(); + workbook.write(outputStream); + } catch (IOException e) { + e.printStackTrace(); + } finally { + try { + outputStream.close(); + } catch (IOException e) { + e.printStackTrace(); + } + } + } + + + @PostMapping("/prizeRedemptionRecordList") + @ApiOperation(value = "兑换记录管理列表-分页", tags = {"管理后台-兑换记录管理"}) + + public R<PageDTO<PrizeRedemptionRecord>> prizeRedemptionRecordList(@RequestBody PrizeRecordDTO courseDTO) { + String startTime = null; + String endTime = null; + if (org.springframework.util.StringUtils.hasLength(courseDTO.getTime())){ + String[] split = courseDTO.getTime().split(" - "); + startTime = split[0]+" 00:00:00"; + endTime = split[1]+" 23:59:59"; + } + List<Long> longs = new ArrayList<>(); + LambdaQueryWrapper<PrizeRedemptionRecord> courseLambdaQueryWrapper = new LambdaQueryWrapper<>(); + if (startTime!=null){ + courseLambdaQueryWrapper.between(PrizeRedemptionRecord::getCreateTime, startTime, endTime); + } + if (courseDTO.getStatus()!=null){ + courseLambdaQueryWrapper.eq(PrizeRedemptionRecord::getStatus, courseDTO.getStatus()); + } + courseLambdaQueryWrapper.orderByDesc(PrizeRedemptionRecord::getCreateTime); + if (org.springframework.util.StringUtils.hasLength(courseDTO.getUserNameOrPhone())){ + List<Long> collect = appUserService.lambdaQuery().like(AppUser::getNickname, courseDTO.getUserNameOrPhone()).list() + .stream().map(AppUser::getId).collect(Collectors.toList()); + longs.addAll(collect); + List<Long> collect1 = appUserService.lambdaQuery().like(AppUser::getCellPhone, courseDTO.getUserNameOrPhone()).list() + .stream().map(AppUser::getId).collect(Collectors.toList()); + longs.addAll(collect1); + if (longs.isEmpty()){ + longs.add(-1L); + } + courseLambdaQueryWrapper.in(PrizeRedemptionRecord::getAppUserId, longs); + } + if (org.springframework.util.StringUtils.hasLength(courseDTO.getName())){ + List<Long> collect = prizeService.lambdaQuery().like(Prize::getName, courseDTO.getName()).list() + .stream().map(Prize::getId).collect(Collectors.toList()); + if (collect.isEmpty()){ + collect.add(-1L); + } + courseLambdaQueryWrapper.in(PrizeRedemptionRecord::getPrizeId, collect); + } + Page<PrizeRedemptionRecord> page = prizeRedemptionRecordService.page(new Page<>(courseDTO.getPageCurr(), courseDTO.getPageSize()), courseLambdaQueryWrapper); + if (CollUtils.isEmpty(page.getRecords())) { + return R.ok(PageDTO.empty(page)); + } + for (PrizeRedemptionRecord record : page.getRecords()) { + record.setUuid(record.getAppUserId()+""); + Prize byId = prizeService.getById(record.getPrizeId()); + if (Objects.nonNull(byId)){ + record.setName(byId.getName()); + record.setWorth(byId.getWorth()); + record.setEnergyValue(byId.getEnergyValue()); + record.setCoverUrl(byId.getCoverUrl()); + } + record.setUid(record.getId().toString()); + AppUser byId1 = appUserService.getById(record.getAppUserId()); + if (Objects.nonNull(byId1)){ + record.setUserName(byId1.getNickname()); + record.setAvatar(byId1.getAvatar()); + record.setCellPhone(byId1.getCellPhone()); + } + } + return R.ok(PageDTO.of(page, PrizeRedemptionRecord.class)); + } + + @GetMapping("/detailPrizeRedemptionRecord") + @ApiOperation(value = "查看详情兑换记录管理", tags = "管理后台-兑换记录管理") + public R<PrizeRedemptionRecord> detailPrizeRedemptionRecord(String uid) { + PrizeRedemptionRecord byId = prizeRedemptionRecordService.getById(uid); + Prize byId1 = prizeService.getById(byId.getPrizeId()); + if (Objects.nonNull(byId1)){ + byId.setName(byId1.getName()); + byId.setWorth(byId1.getWorth()); + byId.setEnergyValue(byId1.getEnergyValue()); + } + byId.setUid(byId.getId().toString()); + AppUser byId2 = appUserService.getById(byId.getAppUserId()); + if (Objects.nonNull(byId2)){ + byId.setUserName(byId2.getNickname()); + byId.setAvatar(byId2.getAvatar()); + byId.setCellPhone(byId2.getCellPhone()); + } + return R.ok(); + } + @Autowired + private TokenService tokenService; + @GetMapping("/confirm") + @ApiOperation(value = "确认兑换", tags = "管理后台-兑换记录管理") + public R updateState(String uid,String code) { + LoginUser loginUser = tokenService.getLoginUser(); + if (loginUser==null){ + return R.tokenError("登录失效"); + } + Long userId = loginUser.getUserid(); + PrizeRedemptionRecord byId = prizeRedemptionRecordService.getById(uid); + if (!byId.getCode().equals(code)){ + return R.fail("兑换码错误"); + }else{ + byId.setStatus(2); + byId.setUpdateTime(LocalDateTime.now()); + SysUser data = remoteUserService.getSysUserById(userId + "").getData(); + byId.setUpdateBy(data.getUserName()+data.getNickName()+"("+data.getUserName()+")"); + byId.setHandleName(data.getUserName()+data.getNickName()+"("+data.getUserName()+")"); + prizeRedemptionRecordService.updateById(byId); + } + return R.ok(); + } + } -- Gitblit v1.7.1