| | |
| | | package com.xinquan.user.controller.client; |
| | | |
| | | |
| | | import org.springframework.web.bind.annotation.RequestMapping; |
| | | 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 com.xinquan.course.api.domain.Course; |
| | | import com.xinquan.course.api.domain.CourseCategory; |
| | | import com.xinquan.system.api.domain.Prize; |
| | | import com.xinquan.system.api.domain.PrizeRedemptionRecord; |
| | | import com.xinquan.user.service.PrizeRedemptionRecordService; |
| | | import com.xinquan.user.service.PrizeService; |
| | | import io.swagger.annotations.ApiImplicitParam; |
| | | import io.swagger.annotations.ApiImplicitParams; |
| | | import io.swagger.annotations.ApiOperation; |
| | | import org.springframework.beans.factory.annotation.Autowired; |
| | | import org.springframework.web.bind.annotation.*; |
| | | |
| | | import org.springframework.web.bind.annotation.RestController; |
| | | import java.time.LocalDateTime; |
| | | import java.util.ArrayList; |
| | | import java.util.Arrays; |
| | | import java.util.List; |
| | | import java.util.stream.Collectors; |
| | | |
| | | /** |
| | | * <p> |
| | |
| | | @RestController |
| | | @RequestMapping("/client/prize") |
| | | public class ClientPrizeController { |
| | | @Autowired |
| | | private PrizeService prizeService; |
| | | @Autowired |
| | | private PrizeRedemptionRecordService prizeRedemptionRecordService; |
| | | |
| | | @PostMapping("/prizeManagementList") |
| | | @ApiOperation(value = "奖品列表-分页", tags = {"管理后台-奖品管理"}) |
| | | @ApiImplicitParams({ |
| | | @ApiImplicitParam(name = "pageCurr", value = "分页参数,当前页码", dataType = "Integer", required = true), |
| | | @ApiImplicitParam(name = "pageSize", value = "分页参数,每页数量", dataType = "Integer", required = true) |
| | | }) |
| | | public R<PageDTO<Prize>> prizeManagementList(@RequestParam(value = "pageCurr")Integer pageCurr, |
| | | @RequestParam(value = "pageSize")Integer pageSize) { |
| | | LambdaQueryWrapper<Prize> meditationLambdaQueryWrapper = new LambdaQueryWrapper<>(); |
| | | meditationLambdaQueryWrapper.orderByDesc(Prize::getSortNum); |
| | | Page<Prize> page = prizeService.page(new Page<>(pageCurr, pageSize), meditationLambdaQueryWrapper); |
| | | if (CollUtils.isEmpty(page.getRecords())) { |
| | | return R.ok(PageDTO.empty(page)); |
| | | } |
| | | for (Prize record : page.getRecords()) { |
| | | record.setUid(record.getId()+""); |
| | | long count = prizeRedemptionRecordService.count(new LambdaQueryWrapper<PrizeRedemptionRecord>() |
| | | .eq(PrizeRedemptionRecord::getPrizeId, record.getId())); |
| | | record.setReceiveCount(count); |
| | | } |
| | | return R.ok(PageDTO.of(page, Prize.class)); |
| | | } |
| | | |
| | | @PostMapping("/addPrize") |
| | | @ApiOperation(value = "新增奖品管理", tags = "管理后台-奖品管理") |
| | | public R addPrize(@RequestBody Prize homeBackgroundMusic) { |
| | | homeBackgroundMusic.setCreateBy(SecurityUtils.getUsername()); |
| | | homeBackgroundMusic.setCreateTime(LocalDateTime.now()); |
| | | return R.ok(prizeService.save(homeBackgroundMusic)); |
| | | } |
| | | @GetMapping("/detailPrize") |
| | | @ApiOperation(value = "查看详情奖品管理", tags = "管理后台-奖品管理") |
| | | public R<Prize> detailPrize(String uid) { |
| | | return R.ok(prizeService.getById(uid)); |
| | | } |
| | | @GetMapping("/updateState") |
| | | @ApiOperation(value = "修改奖品管理上下架状态", tags = "管理后台-奖品管理") |
| | | public R updateState(String uid) { |
| | | Prize byId = prizeService.getById(uid); |
| | | if (byId.getStatus() == 1){ |
| | | byId.setStatus(2); |
| | | }else { |
| | | byId.setStatus(1); |
| | | } |
| | | prizeService.updateById(byId); |
| | | return R.ok(); |
| | | } |
| | | @PostMapping("/updatePrize") |
| | | @ApiOperation(value = "修改奖品管理", tags = "管理后台-奖品管理") |
| | | public R updatePrize(@RequestBody Prize homeBackgroundMusic) { |
| | | homeBackgroundMusic.setUpdateBy(SecurityUtils.getUsername()); |
| | | homeBackgroundMusic.setUpdateTime(LocalDateTime.now()); |
| | | return R.ok(prizeService.updateById(homeBackgroundMusic)); |
| | | } |
| | | @PostMapping("/deletePrize") |
| | | @ApiOperation(value = "批量删除", tags = "管理后台-奖品管理") |
| | | public R deletePrize(String ids) { |
| | | List<Long> collect = Arrays.stream(ids.split(",")).map(Long::valueOf).collect(Collectors.toList()); |
| | | for (Long l : collect) { |
| | | List<PrizeRedemptionRecord> list = prizeRedemptionRecordService.lambdaQuery().eq(PrizeRedemptionRecord::getPrizeId, l).list(); |
| | | if (!list.isEmpty()){ |
| | | Prize byId = prizeService.getById(l); |
| | | return R.fail("奖品名称:"+byId.getName()+"存在兑换记录,不可删除"); |
| | | } |
| | | } |
| | | return R.ok(prizeService.removeBatchByIds(Arrays.asList(ids.split(",")).stream().map(Long::valueOf).collect(Collectors.toList()))); |
| | | } |
| | | } |
| | | |