| 1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465 |
- package com.izouma.nineth.web;
- import com.izouma.nineth.domain.MetaBagAssetEffectConfig;
- import com.izouma.nineth.dto.PageQuery;
- import com.izouma.nineth.exception.BusinessException;
- import com.izouma.nineth.repo.MetaBagAssetEffectConfigRepo;
- import com.izouma.nineth.service.MetaBagAssetEffectConfigService;
- 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("/metaBagAssetEffectConfig")
- @AllArgsConstructor
- public class MetaBagAssetEffectConfigController extends BaseController {
- private MetaBagAssetEffectConfigService metaBagAssetEffectConfigService;
- private MetaBagAssetEffectConfigRepo metaBagAssetEffectConfigRepo;
- //@PreAuthorize("hasRole('ADMIN')")
- @PostMapping("/save")
- public MetaBagAssetEffectConfig save(@RequestBody MetaBagAssetEffectConfig record) {
- MetaBagAssetEffectConfig config = metaBagAssetEffectConfigRepo.findByNameAndDel(record.getName(), false);
- if (Objects.nonNull(config) && !Objects.equals(config.getId(), record.getId())) {
- throw new BusinessException("该名称特效已经配置!");
- }
- if (record.getId() != null) {
- MetaBagAssetEffectConfig orig = metaBagAssetEffectConfigRepo.findById(record.getId()).orElseThrow(new BusinessException("无记录"));
- ObjUtils.merge(orig, record);
- return metaBagAssetEffectConfigRepo.save(orig);
- }
- return metaBagAssetEffectConfigRepo.save(record);
- }
- //@PreAuthorize("hasRole('ADMIN')")
- @PostMapping("/all")
- public Page<MetaBagAssetEffectConfig> all(@RequestBody PageQuery pageQuery) {
- return metaBagAssetEffectConfigService.all(pageQuery);
- }
- @GetMapping("/get/{id}")
- public MetaBagAssetEffectConfig get(@PathVariable Long id) {
- return metaBagAssetEffectConfigRepo.findById(id).orElseThrow(new BusinessException("无记录"));
- }
- @PostMapping("/del/{id}")
- public void del(@PathVariable Long id) {
- metaBagAssetEffectConfigRepo.softDelete(id);
- }
- @GetMapping("/excel")
- @ResponseBody
- public void excel(HttpServletResponse response, PageQuery pageQuery) throws IOException {
- List<MetaBagAssetEffectConfig> data = all(pageQuery).getContent();
- ExcelUtils.export(response, data);
- }
- }
|