| 12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364 |
- package com.izouma.nineth.web;
- import com.izouma.nineth.domain.MetaSignAward;
- import com.izouma.nineth.dto.PageQuery;
- import com.izouma.nineth.exception.BusinessException;
- import com.izouma.nineth.repo.MetaSignAwardRepo;
- import com.izouma.nineth.service.MetaSignAwardService;
- import com.izouma.nineth.utils.ObjUtils;
- import com.izouma.nineth.utils.excel.ExcelUtils;
- import lombok.AllArgsConstructor;
- import org.springframework.data.domain.Page;
- import org.springframework.web.bind.annotation.*;
- import javax.servlet.http.HttpServletResponse;
- import java.io.IOException;
- import java.util.List;
- import java.util.Objects;
- @RestController
- @RequestMapping("/metaSignAward")
- @AllArgsConstructor
- public class MetaSignAwardController extends BaseController {
- private MetaSignAwardService metaSignAwardService;
- private MetaSignAwardRepo metaSignAwardRepo;
- //@PreAuthorize("hasRole('ADMIN')")
- @PostMapping("/save")
- public MetaSignAward save(@RequestBody MetaSignAward record) {
- MetaSignAward metaSignAward = metaSignAwardRepo.findByDateAndChannelIdAndSignNumAndDel(record.getDate(), record.getChannelId(), record.getSignNum(), false);
- if (Objects.nonNull(metaSignAward) && !Objects.equals(metaSignAward.getId(), record.getId())) {
- throw new BusinessException("已存在同一频道同一日期的累计签到天数的奖励配置!");
- }
- if (record.getId() != null) {
- MetaSignAward orig = metaSignAwardRepo.findById(record.getId()).orElseThrow(new BusinessException("无记录"));
- ObjUtils.merge(orig, record);
- return metaSignAwardRepo.save(orig);
- }
- return metaSignAwardRepo.save(record);
- }
- //@PreAuthorize("hasRole('ADMIN')")
- @PostMapping("/all")
- public Page<MetaSignAward> all(@RequestBody PageQuery pageQuery) {
- return metaSignAwardService.all(pageQuery);
- }
- @GetMapping("/get/{id}")
- public MetaSignAward get(@PathVariable Long id) {
- return metaSignAwardRepo.findById(id).orElseThrow(new BusinessException("无记录"));
- }
- @PostMapping("/del/{id}")
- public void del(@PathVariable Long id) {
- metaSignAwardRepo.softDelete(id);
- }
- @GetMapping("/excel")
- @ResponseBody
- public void excel(HttpServletResponse response, PageQuery pageQuery) throws IOException {
- List<MetaSignAward> data = all(pageQuery).getContent();
- ExcelUtils.export(response, data);
- }
- }
|