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.
|
|
package com.example.demo.controller.coin;
import com.example.demo.config.interfac.Log; import com.example.demo.domain.entity.Rate; import com.example.demo.domain.vo.coin.Page; import com.example.demo.domain.vo.coin.Result; import com.example.demo.service.coin.RateService; import lombok.RequiredArgsConstructor; import lombok.extern.slf4j.Slf4j; import org.springframework.beans.factory.annotation.Autowired; import org.springframework.util.ObjectUtils; import org.springframework.web.bind.annotation.*;
import java.math.BigDecimal; import java.util.Map;
@RestController @RequestMapping("/rate") @RequiredArgsConstructor @Slf4j @CrossOrigin public class RateController {
@Autowired private RateService rateService;
//货币汇率列表
@Log("获取汇率列表") @PostMapping("/selectAll") public Result selectAll(@RequestBody Page page){ if (ObjectUtils.isEmpty(page.getPageNum())) { return Result.error("页码数为空!"); } if (ObjectUtils.isEmpty(page.getPageSize())) { return Result.error("页大小为空!"); } else { return Result.success(rateService.selectAll(page.getPageNum(), page.getPageSize())); } }
//查询货币
@Log("查询货币汇率") @PostMapping("/selectById") public Result selectById(@RequestBody Map<String, Object> requestBody) { Integer id = (Integer) requestBody.get("id"); if (ObjectUtils.isEmpty(id)) { return Result.error("id 为空!"); } Rate rate = rateService.selectById(id); return Result.success(rate); }
// 编辑
@Log("编辑货币汇率") @PostMapping("/update") public Result update(@RequestBody Rate rate) { if (ObjectUtils.isEmpty(rate.getId())) { return Result.error("id不能为空"); } if (ObjectUtils.isEmpty(rate.getRateName())) { return Result.error("汇率名称不能为空"); } if(rate.getNum()==null || rate.getNum().compareTo(BigDecimal.ZERO) <= 0){ return Result.error(("汇率数值不能小于等于0")); } rateService.update(rate); if (rate.getNum() == null || rate.getNum().equals(BigDecimal.ZERO)) { return Result.error("汇率数值存在异常"); }else return Result.success("编辑成功"); }
}
|