| | |
| | | package com.xinquan.user.controller.client; |
| | | |
| | | |
| | | import org.springframework.web.bind.annotation.RequestMapping; |
| | | import com.alibaba.nacos.common.utils.StringUtils; |
| | | 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.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.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.user.api.domain.dto.PrizeRecordDTO; |
| | | 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.springframework.web.bind.annotation.*; |
| | | |
| | | import javax.annotation.Resource; |
| | | import java.time.LocalDateTime; |
| | | import java.util.ArrayList; |
| | | import java.util.Arrays; |
| | | import java.util.List; |
| | | import java.util.Objects; |
| | | import java.util.stream.Collectors; |
| | | |
| | | /** |
| | | * <p> |
| | |
| | | @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("/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<>(); |
| | | courseLambdaQueryWrapper.between(PrizeRedemptionRecord::getCreateTime, startTime, endTime); |
| | | courseLambdaQueryWrapper.eq(courseDTO.getStatus()!=null,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()) { |
| | | Prize byId = prizeService.getById(record.getPrizeId()); |
| | | if (Objects.nonNull(byId)){ |
| | | record.setName(byId.getName()); |
| | | record.setWorth(byId.getWorth()); |
| | | record.setEnergyValue(byId.getEnergyValue()); |
| | | } |
| | | 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 = "查看详情兑换记录管理", notes = "管理后台-兑换记录管理") |
| | | 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(); |
| | | } |
| | | @GetMapping("/confirm") |
| | | @ApiOperation(value = "确认兑换", notes = "管理后台-兑换记录管理") |
| | | public R updateState(String uid,String code) { |
| | | |
| | | 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()+")"); |
| | | prizeRedemptionRecordService.updateById(byId); |
| | | } |
| | | return R.ok(); |
| | | } |
| | | |
| | | |
| | | } |
| | | |