汇率管理
This commit is contained in:
+163
@@ -0,0 +1,163 @@
|
||||
package com.ruoyi.web.controller.data;
|
||||
|
||||
import java.math.BigDecimal;
|
||||
import java.text.SimpleDateFormat;
|
||||
import java.util.Date;
|
||||
import java.util.List;
|
||||
import jakarta.servlet.http.HttpServletResponse;
|
||||
import org.springframework.beans.factory.annotation.Autowired;
|
||||
import org.springframework.security.access.prepost.PreAuthorize;
|
||||
import org.springframework.validation.annotation.Validated;
|
||||
import org.springframework.web.bind.annotation.DeleteMapping;
|
||||
import org.springframework.web.bind.annotation.GetMapping;
|
||||
import org.springframework.web.bind.annotation.PathVariable;
|
||||
import org.springframework.web.bind.annotation.PostMapping;
|
||||
import org.springframework.web.bind.annotation.PutMapping;
|
||||
import org.springframework.web.bind.annotation.RequestBody;
|
||||
import org.springframework.web.bind.annotation.RequestMapping;
|
||||
import org.springframework.web.bind.annotation.RequestParam;
|
||||
import org.springframework.web.bind.annotation.RestController;
|
||||
import com.ruoyi.common.annotation.Log;
|
||||
import com.ruoyi.common.core.controller.BaseController;
|
||||
import com.ruoyi.common.core.domain.AjaxResult;
|
||||
import com.ruoyi.common.core.page.TableDataInfo;
|
||||
import com.ruoyi.common.enums.BusinessType;
|
||||
import com.ruoyi.common.utils.poi.ExcelUtil;
|
||||
import com.ruoyi.system.domain.BmsExchangeRate;
|
||||
import com.ruoyi.system.domain.BmsExchangeRateConvertResult;
|
||||
import com.ruoyi.system.service.IBmsExchangeRateService;
|
||||
|
||||
/**
|
||||
* 汇率管理 信息操作处理
|
||||
*
|
||||
* @author ruoyi
|
||||
*/
|
||||
@RestController
|
||||
@RequestMapping("/data/exchangerate")
|
||||
public class BmsExchangeRateController extends BaseController
|
||||
{
|
||||
@Autowired
|
||||
private IBmsExchangeRateService exchangeRateService;
|
||||
|
||||
/**
|
||||
* 获取汇率列表
|
||||
*/
|
||||
@PreAuthorize("@ss.hasPermi('data:exchangerate:list')")
|
||||
@GetMapping("/list")
|
||||
public TableDataInfo list(BmsExchangeRate exchangeRate)
|
||||
{
|
||||
startPage();
|
||||
List<BmsExchangeRate> list = exchangeRateService.selectExchangeRateList(exchangeRate);
|
||||
return getDataTable(list);
|
||||
}
|
||||
|
||||
/**
|
||||
* 导出汇率列表
|
||||
*/
|
||||
@PreAuthorize("@ss.hasPermi('data:exchangerate:export')")
|
||||
@Log(title = "汇率管理", businessType = BusinessType.EXPORT)
|
||||
@PostMapping("/export")
|
||||
public void export(HttpServletResponse response, BmsExchangeRate exchangeRate)
|
||||
{
|
||||
List<BmsExchangeRate> list = exchangeRateService.selectExchangeRateList(exchangeRate);
|
||||
ExcelUtil<BmsExchangeRate> util = new ExcelUtil<BmsExchangeRate>(BmsExchangeRate.class);
|
||||
util.exportExcel(response, list, "汇率数据");
|
||||
}
|
||||
|
||||
/**
|
||||
* 获取汇率详细信息
|
||||
*/
|
||||
@PreAuthorize("@ss.hasPermi('data:exchangerate:query')")
|
||||
@GetMapping(value = "/{rateId}")
|
||||
public AjaxResult getInfo(@PathVariable Long rateId)
|
||||
{
|
||||
return success(exchangeRateService.selectExchangeRateById(rateId));
|
||||
}
|
||||
|
||||
/**
|
||||
* 新增汇率
|
||||
*/
|
||||
@PreAuthorize("@ss.hasPermi('data:exchangerate:add')")
|
||||
@Log(title = "汇率管理", businessType = BusinessType.INSERT)
|
||||
@PostMapping
|
||||
public AjaxResult add(@Validated @RequestBody BmsExchangeRate exchangeRate)
|
||||
{
|
||||
exchangeRate.setCreateBy(getUsername());
|
||||
return toAjax(exchangeRateService.insertExchangeRate(exchangeRate));
|
||||
}
|
||||
|
||||
/**
|
||||
* 修改汇率
|
||||
*/
|
||||
@PreAuthorize("@ss.hasPermi('data:exchangerate:edit')")
|
||||
@Log(title = "汇率管理", businessType = BusinessType.UPDATE)
|
||||
@PutMapping
|
||||
public AjaxResult edit(@Validated @RequestBody BmsExchangeRate exchangeRate)
|
||||
{
|
||||
return toAjax(exchangeRateService.updateExchangeRate(exchangeRate));
|
||||
}
|
||||
|
||||
/**
|
||||
* 删除汇率
|
||||
*/
|
||||
@PreAuthorize("@ss.hasPermi('data:exchangerate:remove')")
|
||||
@Log(title = "汇率管理", businessType = BusinessType.DELETE)
|
||||
@DeleteMapping("/{rateIds}")
|
||||
public AjaxResult remove(@PathVariable Long[] rateIds)
|
||||
{
|
||||
return toAjax(exchangeRateService.deleteExchangeRateByIds(rateIds));
|
||||
}
|
||||
|
||||
/**
|
||||
* 汇率换算(业务公共接口,登录即可调用,不单独设权限)
|
||||
*
|
||||
* @param amount 源金额
|
||||
* @param fromCurrency 源币种
|
||||
* @param toCurrency 目标币种
|
||||
* @param rateType 汇率类型(0即期 1月初 2月末 3固定),默认即期
|
||||
* @param bizDate 业务日期 yyyy-MM-dd,默认当天
|
||||
*/
|
||||
@GetMapping("/convert")
|
||||
public AjaxResult convert(@RequestParam BigDecimal amount,
|
||||
@RequestParam String fromCurrency,
|
||||
@RequestParam String toCurrency,
|
||||
@RequestParam(required = false) String rateType,
|
||||
@RequestParam(required = false) String bizDate)
|
||||
{
|
||||
Date date = parseDate(bizDate);
|
||||
BmsExchangeRateConvertResult result = exchangeRateService.convert(
|
||||
amount, fromCurrency, toCurrency, rateType, date);
|
||||
return success(result);
|
||||
}
|
||||
|
||||
/**
|
||||
* 本位币(CNY)折算:任意币种金额折算为人民币
|
||||
*/
|
||||
@GetMapping("/toBase")
|
||||
public AjaxResult toBase(@RequestParam BigDecimal amount,
|
||||
@RequestParam String currency,
|
||||
@RequestParam(required = false) String rateType,
|
||||
@RequestParam(required = false) String bizDate)
|
||||
{
|
||||
Date date = parseDate(bizDate);
|
||||
BmsExchangeRateConvertResult result = exchangeRateService.convert(
|
||||
amount, currency, BmsExchangeRate.BASE_CURRENCY, rateType, date);
|
||||
return success(result);
|
||||
}
|
||||
|
||||
private Date parseDate(String bizDate)
|
||||
{
|
||||
if (bizDate == null || bizDate.isEmpty())
|
||||
{
|
||||
return null;
|
||||
}
|
||||
try
|
||||
{
|
||||
return new SimpleDateFormat("yyyy-MM-dd").parse(bizDate);
|
||||
}
|
||||
catch (Exception e)
|
||||
{
|
||||
return null;
|
||||
}
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user