You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

70 lines
2.1 KiB

2 months ago
1 month ago
2 months ago
1 month ago
2 months ago
  1. package com.example.demo.controller;
  2. import com.example.demo.domain.entity.Rate;
  3. import com.example.demo.domain.vo.Page;
  4. import com.example.demo.domain.vo.Result;
  5. import com.example.demo.mapper.RateMapper;
  6. import com.example.demo.service.RateService;
  7. import lombok.RequiredArgsConstructor;
  8. import lombok.extern.slf4j.Slf4j;
  9. import org.springframework.beans.factory.annotation.Autowired;
  10. import org.springframework.util.ObjectUtils;
  11. import org.springframework.validation.BindingResult;
  12. import org.springframework.web.bind.annotation.*;
  13. import java.math.BigDecimal;
  14. import java.util.Map;
  15. @RestController
  16. @RequestMapping("/rate")
  17. @RequiredArgsConstructor
  18. @Slf4j
  19. @CrossOrigin
  20. public class RateController {
  21. @Autowired
  22. private RateService rateService;
  23. //货币汇率列表
  24. @PostMapping("/selectAll")
  25. public Result selectAll(@RequestBody Page page){
  26. if (ObjectUtils.isEmpty(page.getPageNum())) {
  27. return Result.error("页码数为空!");
  28. }
  29. if (ObjectUtils.isEmpty(page.getPageSize())) {
  30. return Result.error("页大小为空!");
  31. } else {
  32. return Result.success(rateService.selectAll(page.getPageNum(), page.getPageSize()));
  33. }
  34. }
  35. //查询货币
  36. @PostMapping("/selectById")
  37. public Result selectById(@RequestBody Map<String, Object> requestBody) {
  38. Integer id = (Integer) requestBody.get("id");
  39. if (ObjectUtils.isEmpty(id)) {
  40. return Result.error("id 为空!");
  41. }
  42. Rate rate = rateService.selectById(id);
  43. return Result.success(rate);
  44. }
  45. // 编辑
  46. @PostMapping("/update")
  47. public Result update(@RequestBody Rate rate) {
  48. if (ObjectUtils.isEmpty(rate.getId())) {
  49. return Result.error("id不能为空");
  50. }
  51. if (ObjectUtils.isEmpty(rate.getRateName())) {
  52. return Result.error("汇率名称不能为空");
  53. }
  54. if(rate.getNum()==null || rate.getNum().compareTo(BigDecimal.ZERO) <= 0){
  55. return Result.error(("汇率数值不能小于等于0"));
  56. }
  57. rateService.update(rate);
  58. return Result.success("编辑成功");
  59. }
  60. }