diff --git a/ruoyi-admin/src/main/java/com/ruoyi/system/controller/BaseExchangeRateController.java b/ruoyi-admin/src/main/java/com/ruoyi/system/controller/BaseExchangeRateController.java index a6ce83ad..25c30b36 100644 --- a/ruoyi-admin/src/main/java/com/ruoyi/system/controller/BaseExchangeRateController.java +++ b/ruoyi-admin/src/main/java/com/ruoyi/system/controller/BaseExchangeRateController.java @@ -1,15 +1,13 @@ package com.ruoyi.system.controller; +import java.math.BigDecimal; +import java.util.Date; import java.util.List; import org.apache.shiro.authz.annotation.RequiresPermissions; import org.springframework.beans.factory.annotation.Autowired; import org.springframework.stereotype.Controller; import org.springframework.ui.ModelMap; -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.RequestMapping; -import org.springframework.web.bind.annotation.ResponseBody; +import org.springframework.web.bind.annotation.*; import com.ruoyi.common.annotation.Log; import com.ruoyi.common.enums.BusinessType; import com.ruoyi.system.domain.BaseExchangeRate; @@ -148,4 +146,22 @@ public class BaseExchangeRateController extends BaseController } + /** + * + * 根据单据创建时间查询当前区间内的美元汇率 + * */ + @GetMapping("/getLatestUsdTax") + @ResponseBody + public AjaxResult getExchangeRateByDate(){ + + Date curDate = new Date(); + BaseExchangeRate baseExchangeRate = new BaseExchangeRate(); + baseExchangeRate.setCreateTime(curDate); + //查询当前时间属于哪个区间,开始时间和结束时间之间。已经设置区间不能交叉 + + BaseExchangeRate tempBaseExchangeRate = baseExchangeRateService.selectExchangeRateByTimeRange(baseExchangeRate); + BigDecimal exchangeRate = tempBaseExchangeRate.getExchangeRate(); + return AjaxResult.success(exchangeRate); + } + } diff --git a/ruoyi-admin/src/main/java/com/ruoyi/system/mapper/BaseExchangeRateMapper.java b/ruoyi-admin/src/main/java/com/ruoyi/system/mapper/BaseExchangeRateMapper.java index 1a369057..e276830d 100644 --- a/ruoyi-admin/src/main/java/com/ruoyi/system/mapper/BaseExchangeRateMapper.java +++ b/ruoyi-admin/src/main/java/com/ruoyi/system/mapper/BaseExchangeRateMapper.java @@ -27,6 +27,13 @@ public interface BaseExchangeRateMapper */ public List selectBaseExchangeRateList(BaseExchangeRate baseExchangeRate); + /** + * 查询所有基础资料汇率管理列表 + * + * @return 基础资料汇率管理集合 + */ + + public List selectAllBaseExchangeRate(); /** * 查询时间交叉 diff --git a/ruoyi-admin/src/main/java/com/ruoyi/system/service/IBaseExchangeRateService.java b/ruoyi-admin/src/main/java/com/ruoyi/system/service/IBaseExchangeRateService.java index 4974fd33..638b2152 100644 --- a/ruoyi-admin/src/main/java/com/ruoyi/system/service/IBaseExchangeRateService.java +++ b/ruoyi-admin/src/main/java/com/ruoyi/system/service/IBaseExchangeRateService.java @@ -72,4 +72,9 @@ public interface IBaseExchangeRateService * @return */ int restoreBaseExchangeRateById(Long exchangeRateId); + + /** + * 查找当前时间的汇率 + * */ + BaseExchangeRate selectExchangeRateByTimeRange(BaseExchangeRate baseExchangeRate); } diff --git a/ruoyi-admin/src/main/java/com/ruoyi/system/service/impl/BaseExchangeRateServiceImpl.java b/ruoyi-admin/src/main/java/com/ruoyi/system/service/impl/BaseExchangeRateServiceImpl.java index 9a5561f6..329114f2 100644 --- a/ruoyi-admin/src/main/java/com/ruoyi/system/service/impl/BaseExchangeRateServiceImpl.java +++ b/ruoyi-admin/src/main/java/com/ruoyi/system/service/impl/BaseExchangeRateServiceImpl.java @@ -1,5 +1,6 @@ package com.ruoyi.system.service.impl; +import java.util.Calendar; import java.util.Date; import java.util.List; @@ -183,4 +184,43 @@ public class BaseExchangeRateServiceImpl implements IBaseExchangeRateService { return baseExchangeRateMapper.restoreBaseExchangeRateById(exchangeRateId); } + + /** + * 查找当前时间的汇率 + * */ + @Override + public BaseExchangeRate selectExchangeRateByTimeRange(BaseExchangeRate baseExchangeRate) { + // 当前时间 + Date curDate = baseExchangeRate.getCreateTime(); + curDate = setToMidnight(curDate); + + // 查找所有数据 + List baseExchangeRates = baseExchangeRateMapper.selectAllBaseExchangeRate(); + + // 比对当前时间,属于所有数据中的哪一个区间,包含临界值,返回该条数据的汇率 + for (BaseExchangeRate tempBaseExchangeRate : baseExchangeRates) { + Date startTime = tempBaseExchangeRate.getStartTime(); + startTime = setToMidnight(startTime); + Date endTime = tempBaseExchangeRate.getEndTime(); + endTime = setToMidnight(endTime); + + if (curDate.equals(startTime) || curDate.equals(endTime) || + (curDate.after(startTime) && curDate.before(endTime))) { + return tempBaseExchangeRate; + } + } + return null; + } + + //因为时间都没有包含时分秒,所以对比的时候设置时分秒为 00:00:00 + private Date setToMidnight(Date date) { + Calendar calendar = Calendar.getInstance(); + calendar.setTime(date); + calendar.set(Calendar.HOUR_OF_DAY, 0); + calendar.set(Calendar.MINUTE, 0); + calendar.set(Calendar.SECOND, 0); + calendar.set(Calendar.MILLISECOND, 0); + return calendar.getTime(); + } + } diff --git a/ruoyi-admin/src/main/resources/mapper/system/BaseExchangeRateMapper.xml b/ruoyi-admin/src/main/resources/mapper/system/BaseExchangeRateMapper.xml index 54234d0a..fc2c8fed 100644 --- a/ruoyi-admin/src/main/resources/mapper/system/BaseExchangeRateMapper.xml +++ b/ruoyi-admin/src/main/resources/mapper/system/BaseExchangeRateMapper.xml @@ -35,6 +35,11 @@ PUBLIC "-//mybatis.org//DTD Mapper 3.0//EN" + + + + - - - - - - - - -
@@ -79,18 +70,6 @@
- - - - - - - - - - - -
@@ -176,7 +155,10 @@ var loginName = [[${@permission.getPrincipalProperty('loginName')}]]; var prefix = ctx + "system/customerQuote"; var commonCurrency = $("#commonCurrency_add option:selected").val(); - $("#form-customerQuote-add").validate({focusCleanup: true}); + $("#form-customerQuote-add").validate( + { + focusCleanup: true} + ); function submitHandler() { if ($.validate.form()) { var formData = $("#form-customerQuote-add").serializeArray(); @@ -245,6 +227,9 @@ $(document).ready(function() { // 初始化时默认加载客户编号列表 loadCustomerIds(); + + //初始化美元汇率 + loadLatestUsdTax(); }); // 假设的加载客户编号列表函数 function loadCustomerIds() { @@ -344,7 +329,7 @@ return $.table.selectDictLabel(sysUnitClassDatas, value); } }, - {title: '半成品类型',field: 'processMethod',align: 'center', + {title: '加工方式',field: 'processMethod',align: 'center', formatter: function(value, row, index) { return $.table.selectDictLabel(processMethodDatas, value); } @@ -376,8 +361,8 @@ } }, - {title: '国内税率',field: 'countTax',align: 'center',}, - { title: '美元汇率',field: 'usdTax', align: 'center',}, + // {title: '国内税率',field: 'countTax',align: 'center',}, + // { title: '美元汇率',field: 'usdTax', align: 'center',}, { title: '物料的不含税单价(RMB)', field: 'materialNoRmb', align: 'center', @@ -753,7 +738,7 @@ } if ($("#usdTax_add").val() == null || $("#usdTax_add").val() == '') { - $.modal.alertWarning("请输入美元汇率"); + $.modal.alertWarning("当前未配置美元汇率,请联系总经理"); return; } @@ -848,7 +833,19 @@ $.modal.open("最新报价历史", url); } - + //from的最新美元汇率 + function loadLatestUsdTax() { + var url = ctx + 'system/exchangeRate/getLatestUsdTax'; + $.ajax({ + type: 'GET', // 请求类型 + url: url, // 后端接口URL + dataType: 'json', // 预期服务器返回的数据类型 + success: function(data) { + console.log(data) + $("#usdTax_add").val(data.data); + } + }); + }