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.

75 lines
2.3 KiB

2 months ago
2 months ago
2 months ago
2 months ago
2 months ago
2 months ago
2 months ago
2 months ago
2 months ago
2 months ago
2 months ago
2 months ago
  1. package com.example.demo.controller.coin;
  2. import com.example.demo.config.interfac.Log;
  3. import com.example.demo.domain.entity.Rate;
  4. import com.example.demo.domain.vo.coin.Page;
  5. import com.example.demo.domain.vo.coin.Result;
  6. import com.example.demo.service.coin.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.web.bind.annotation.*;
  12. import java.math.BigDecimal;
  13. import java.util.Map;
  14. @RestController
  15. @RequestMapping("/rate")
  16. @RequiredArgsConstructor
  17. @Slf4j
  18. @CrossOrigin
  19. public class RateController {
  20. @Autowired
  21. private RateService rateService;
  22. //货币汇率列表
  23. @Log("获取汇率列表")
  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. @Log("查询货币汇率")
  37. @PostMapping("/selectById")
  38. public Result selectById(@RequestBody Map<String, Object> requestBody) {
  39. Integer id = (Integer) requestBody.get("id");
  40. if (ObjectUtils.isEmpty(id)) {
  41. return Result.error("id 为空!");
  42. }
  43. Rate rate = rateService.selectById(id);
  44. return Result.success(rate);
  45. }
  46. // 编辑
  47. @Log("编辑货币汇率")
  48. @PostMapping("/update")
  49. public Result update(@RequestBody Rate rate) {
  50. if (ObjectUtils.isEmpty(rate.getId())) {
  51. return Result.error("id不能为空");
  52. }
  53. if (ObjectUtils.isEmpty(rate.getRateName())) {
  54. return Result.error("汇率名称不能为空");
  55. }
  56. if(rate.getNum()==null || rate.getNum().compareTo(BigDecimal.ZERO) <= 0){
  57. return Result.error(("汇率数值不能小于等于0"));
  58. }
  59. rateService.update(rate);
  60. if (rate.getNum() == null || rate.getNum().equals(BigDecimal.ZERO)) {
  61. return Result.error("汇率数值存在异常");
  62. }else
  63. return Result.success("编辑成功");
  64. }
  65. }