SysConfigController.java 2.1 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364
  1. package com.izouma.nineth.web;
  2. import com.izouma.nineth.domain.SysConfig;
  3. import com.izouma.nineth.dto.PageQuery;
  4. import com.izouma.nineth.exception.BusinessException;
  5. import com.izouma.nineth.repo.SysConfigRepo;
  6. import com.izouma.nineth.service.SysConfigService;
  7. import com.izouma.nineth.utils.excel.ExcelUtils;
  8. import lombok.AllArgsConstructor;
  9. import org.springframework.cache.annotation.CacheEvict;
  10. import org.springframework.cache.annotation.Cacheable;
  11. import org.springframework.data.domain.Page;
  12. import org.springframework.security.access.prepost.PreAuthorize;
  13. import org.springframework.web.bind.annotation.*;
  14. import javax.servlet.http.HttpServletResponse;
  15. import java.io.IOException;
  16. import java.math.BigDecimal;
  17. import java.util.List;
  18. @RestController
  19. @RequestMapping("/sysConfig")
  20. @AllArgsConstructor
  21. public class SysConfigController extends BaseController {
  22. private SysConfigService sysConfigService;
  23. private SysConfigRepo sysConfigRepo;
  24. @PreAuthorize("hasRole('ADMIN')")
  25. @PostMapping("/save")
  26. @CacheEvict(value = {"SysConfigServiceGetBigDecimal", "SysConfigServiceGetTime", "SysConfigServiceGetBoolean", "SysConfigServiceGetInt"}, allEntries = true)
  27. public SysConfig save(@RequestBody SysConfig record) {
  28. return sysConfigRepo.save(record);
  29. }
  30. @PostMapping("/all")
  31. public Page<SysConfig> all(@RequestBody PageQuery pageQuery) {
  32. return sysConfigService.all(pageQuery);
  33. }
  34. @GetMapping("/get/{id}")
  35. public SysConfig get(@PathVariable String id) {
  36. return sysConfigRepo.findByName(id).orElseThrow(new BusinessException("无记录"));
  37. }
  38. @Cacheable("SysConfigServiceGetBigDecimal")
  39. @GetMapping("/getDecimal/{id}")
  40. public BigDecimal getDecimal(@PathVariable String id) {
  41. return sysConfigService.getBigDecimal(id);
  42. }
  43. @PostMapping("/del/{id}")
  44. public void del(@PathVariable String id) {
  45. sysConfigRepo.deleteById(id);
  46. }
  47. @GetMapping("/excel")
  48. @ResponseBody
  49. public void excel(HttpServletResponse response, PageQuery pageQuery) throws IOException {
  50. List<SysConfig> data = all(pageQuery).getContent();
  51. ExcelUtils.export(response, data);
  52. }
  53. }