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.

71 lines
2.2 KiB

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