MetaBagAssetEffectConfigController.java 2.5 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465
  1. package com.izouma.nineth.web;
  2. import com.izouma.nineth.domain.MetaBagAssetEffectConfig;
  3. import com.izouma.nineth.dto.PageQuery;
  4. import com.izouma.nineth.exception.BusinessException;
  5. import com.izouma.nineth.repo.MetaBagAssetEffectConfigRepo;
  6. import com.izouma.nineth.service.MetaBagAssetEffectConfigService;
  7. import com.izouma.nineth.utils.ObjUtils;
  8. import com.izouma.nineth.utils.excel.ExcelUtils;
  9. import lombok.AllArgsConstructor;
  10. import org.springframework.data.domain.Page;
  11. import org.springframework.web.bind.annotation.*;
  12. import javax.servlet.http.HttpServletResponse;
  13. import java.io.IOException;
  14. import java.util.List;
  15. import java.util.Objects;
  16. @RestController
  17. @RequestMapping("/metaBagAssetEffectConfig")
  18. @AllArgsConstructor
  19. public class MetaBagAssetEffectConfigController extends BaseController {
  20. private MetaBagAssetEffectConfigService metaBagAssetEffectConfigService;
  21. private MetaBagAssetEffectConfigRepo metaBagAssetEffectConfigRepo;
  22. //@PreAuthorize("hasRole('ADMIN')")
  23. @PostMapping("/save")
  24. public MetaBagAssetEffectConfig save(@RequestBody MetaBagAssetEffectConfig record) {
  25. MetaBagAssetEffectConfig config = metaBagAssetEffectConfigRepo.findByNameAndDel(record.getName(), false);
  26. if (Objects.nonNull(config) && !Objects.equals(config.getId(), record.getId())) {
  27. throw new BusinessException("该名称特效已经配置!");
  28. }
  29. if (record.getId() != null) {
  30. MetaBagAssetEffectConfig orig = metaBagAssetEffectConfigRepo.findById(record.getId()).orElseThrow(new BusinessException("无记录"));
  31. ObjUtils.merge(orig, record);
  32. return metaBagAssetEffectConfigRepo.save(orig);
  33. }
  34. return metaBagAssetEffectConfigRepo.save(record);
  35. }
  36. //@PreAuthorize("hasRole('ADMIN')")
  37. @PostMapping("/all")
  38. public Page<MetaBagAssetEffectConfig> all(@RequestBody PageQuery pageQuery) {
  39. return metaBagAssetEffectConfigService.all(pageQuery);
  40. }
  41. @GetMapping("/get/{id}")
  42. public MetaBagAssetEffectConfig get(@PathVariable Long id) {
  43. return metaBagAssetEffectConfigRepo.findById(id).orElseThrow(new BusinessException("无记录"));
  44. }
  45. @PostMapping("/del/{id}")
  46. public void del(@PathVariable Long id) {
  47. metaBagAssetEffectConfigRepo.softDelete(id);
  48. }
  49. @GetMapping("/excel")
  50. @ResponseBody
  51. public void excel(HttpServletResponse response, PageQuery pageQuery) throws IOException {
  52. List<MetaBagAssetEffectConfig> data = all(pageQuery).getContent();
  53. ExcelUtils.export(response, data);
  54. }
  55. }