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
70 lines
2.1 KiB
package com.example.demo.controller;
|
|
|
|
|
|
import com.example.demo.domain.entity.Rate;
|
|
import com.example.demo.domain.vo.Page;
|
|
import com.example.demo.domain.vo.Result;
|
|
import com.example.demo.mapper.RateMapper;
|
|
import com.example.demo.service.RateService;
|
|
import lombok.RequiredArgsConstructor;
|
|
import lombok.extern.slf4j.Slf4j;
|
|
import org.springframework.beans.factory.annotation.Autowired;
|
|
import org.springframework.util.ObjectUtils;
|
|
import org.springframework.validation.BindingResult;
|
|
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;
|
|
|
|
//货币汇率列表
|
|
@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()));
|
|
}
|
|
}
|
|
|
|
//查询货币
|
|
@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);
|
|
}
|
|
|
|
// 编辑
|
|
@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);
|
|
return Result.success("编辑成功");
|
|
}
|
|
|
|
}
|