| | |
| | | package com.xinquan.user.controller.client; |
| | | |
| | | |
| | | import com.alibaba.nacos.common.utils.StringUtils; |
| | | 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 com.xinquan.meditation.api.feign.RemoteMeditationService; |
| | | import com.xinquan.system.api.RemoteUserService; |
| | | import com.xinquan.system.api.domain.AppUser; |
| | | import com.xinquan.system.api.domain.Prize; |
| | | import com.xinquan.system.api.domain.PrizeRedemptionRecord; |
| | | import com.xinquan.system.api.domain.SysUser; |
| | | 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; |
| | |
| | | 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 = {"管理后台-兑换记录管理"}) |
| | |
| | | } |
| | | List<Long> longs = new ArrayList<>(); |
| | | LambdaQueryWrapper<PrizeRedemptionRecord> courseLambdaQueryWrapper = new LambdaQueryWrapper<>(); |
| | | courseLambdaQueryWrapper.between(PrizeRedemptionRecord::getCreateTime, startTime, endTime); |
| | | courseLambdaQueryWrapper.eq(courseDTO.getStatus()!=null,PrizeRedemptionRecord::getStatus, courseDTO.getStatus()); |
| | | 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() |
| | |
| | | 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()); |
| | |
| | | } |
| | | |
| | | @GetMapping("/detailPrizeRedemptionRecord") |
| | | @ApiOperation(value = "查看详情兑换记录管理", notes = "管理后台-兑换记录管理") |
| | | @ApiOperation(value = "查看详情兑换记录管理", tags = "管理后台-兑换记录管理") |
| | | public R<PrizeRedemptionRecord> detailPrizeRedemptionRecord(String uid) { |
| | | PrizeRedemptionRecord byId = prizeRedemptionRecordService.getById(uid); |
| | | Prize byId1 = prizeService.getById(byId.getPrizeId()); |
| | |
| | | } |
| | | return R.ok(); |
| | | } |
| | | @Autowired |
| | | private TokenService tokenService; |
| | | @GetMapping("/confirm") |
| | | @ApiOperation(value = "确认兑换", notes = "管理后台-兑换记录管理") |
| | | @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(SecurityUtils.getUserId() + "").getData(); |
| | | byId.setUpdateBy(SecurityUtils.getUsername()+data.getNickName()+"("+data.getUserName()+")"); |
| | | SysUser data = remoteUserService.getSysUserById(userId + "").getData(); |
| | | byId.setUpdateBy(data.getUserName()+data.getNickName()+"("+data.getUserName()+")"); |
| | | prizeRedemptionRecordService.updateById(byId); |
| | | } |
| | | return R.ok(); |