Commit 5e3bd425 authored by wanghuazhou's avatar wanghuazhou Committed by wux

refactor: 货币汇率支持国家多选查询

parent acc4af3f
...@@ -31,4 +31,13 @@ CREATE TABLE IF NOT EXISTS `ecw_currency_rate_log` ( ...@@ -31,4 +31,13 @@ CREATE TABLE IF NOT EXISTS `ecw_currency_rate_log` (
`update_time` DATETIME NOT NULL COMMENT '更新时间', `update_time` DATETIME NOT NULL COMMENT '更新时间',
`deleted` BIT(1) NOT NULL DEFAULT b'0' COMMENT '是否删除', `deleted` BIT(1) NOT NULL DEFAULT b'0' COMMENT '是否删除',
PRIMARY KEY (`id`) PRIMARY KEY (`id`)
) COMMENT '币种汇率变更表'; ) COMMENT '币种汇率变更表';
\ No newline at end of file
INSERT INTO `system_dict_type` (`name`, `type`, `status`, `remark`, `creator`, `create_time`, `updater`, `update_time`, `deleted`)
VALUES ('货币汇率状态', 'currency_rate_status', 0, NULL, '1', '2022-05-23 23:29:07', '1', '2022-05-23 23:34:59', b'0');
INSERT INTO `system_dict_data`
(`sort`, `label`, `value`, `dict_type`, `status`, `color_type`, `css_class`, `remark`, `creator`, `create_time`, `updater`, `update_time`, `deleted`, `label_en`)
VALUES
(0, '已过期', '1', 'currency_rate_status', 0, 'warning', '', NULL, '1', '2022-11-18 00:18:34', '1', '2023-01-15 18:09:43', b'0', 'Expired'),
(1, '生效中', '0', 'currency_rate_status', 0, 'warning', '', NULL, '1', '2022-11-18 00:18:34', '1', '2023-01-15 18:09:43', b'0', 'Active');
...@@ -53,11 +53,6 @@ public class CurrencyRateDO extends BaseDO { ...@@ -53,11 +53,6 @@ public class CurrencyRateDO extends BaseDO {
*/ */
private BigDecimal targetAmount; private BigDecimal targetAmount;
/**
* 汇率值
*/
private BigDecimal rate;
/** /**
* 国家 * 国家
*/ */
......
package cn.iocoder.yudao.module.ecw.dal.mysql.currencyRate; package cn.iocoder.yudao.module.ecw.dal.mysql.currencyRate;
import cn.iocoder.yudao.framework.common.pojo.PageResult;
import cn.iocoder.yudao.framework.mybatis.core.mapper.AbstractMapper; import cn.iocoder.yudao.framework.mybatis.core.mapper.AbstractMapper;
import cn.iocoder.yudao.module.ecw.dal.dataobject.currencyRate.CurrencyRateDO; import cn.iocoder.yudao.module.ecw.dal.dataobject.currencyRate.CurrencyRateDO;
import cn.iocoder.yudao.module.ecw.vo.currencyRate.CurrencyRateQueryParamVO;
import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper;
import com.baomidou.mybatisplus.core.toolkit.Wrappers;
import org.apache.ibatis.annotations.Mapper; import org.apache.ibatis.annotations.Mapper;
import java.time.LocalDate;
import java.util.Arrays;
import java.util.Collections;
import java.util.Optional;
import java.util.Set;
import java.util.function.Consumer;
@Mapper @Mapper
public interface CurrencyRateMapper extends AbstractMapper<CurrencyRateDO> { public interface CurrencyRateMapper extends AbstractMapper<CurrencyRateDO> {
default PageResult<CurrencyRateDO> selectPage(CurrencyRateQueryParamVO param) {
LocalDate now = LocalDate.now();
Set<Long> countries = Optional.ofNullable(param.getCountries()).orElse(Collections.emptySet());
Consumer<LambdaQueryWrapper<CurrencyRateDO>> countriesQuery = it ->
countries.stream().limit(5).forEach(id ->
it.or().apply("json_contains(`countries`, {0})", String.valueOf(id)));
LambdaQueryWrapper<CurrencyRateDO> wrapper = Wrappers.lambdaQuery(CurrencyRateDO.class)
.eq(param.getSourceId() != null, CurrencyRateDO::getSourceId, param.getSourceId())
.eq(param.getTargetId() != null, CurrencyRateDO::getTargetId, param.getTargetId())
.and(!countries.isEmpty(), countriesQuery)
.gt(param.getExpired() == Boolean.FALSE, CurrencyRateDO::getExpiration, now)
.lt(param.getExpired() == Boolean.TRUE, CurrencyRateDO::getExpiration, now)
.gt(param.getExpirationAfter() != null, CurrencyRateDO::getExpiration, param.getExpirationAfter())
.lt(param.getExpirationBefore() != null, CurrencyRateDO::getExpiration, param.getExpirationBefore())
.orderByDesc(Arrays.asList(CurrencyRateDO::getUpdateTime, CurrencyRateDO::getExpiration));
return selectPage(param, wrapper);
}
} }
...@@ -17,8 +17,6 @@ import com.baomidou.mybatisplus.core.toolkit.Wrappers; ...@@ -17,8 +17,6 @@ import com.baomidou.mybatisplus.core.toolkit.Wrappers;
import org.springframework.beans.factory.annotation.Autowired; import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service; import org.springframework.stereotype.Service;
import java.time.LocalDate;
import java.util.Arrays;
import java.util.Optional; import java.util.Optional;
import java.util.Set; import java.util.Set;
...@@ -86,17 +84,7 @@ public class CurrencyRateServiceImpl implements CurrencyRateService { ...@@ -86,17 +84,7 @@ public class CurrencyRateServiceImpl implements CurrencyRateService {
@Override @Override
public PageResult<CurrencyRateDO> query(CurrencyRateQueryParamVO param) { public PageResult<CurrencyRateDO> query(CurrencyRateQueryParamVO param) {
LocalDate now = LocalDate.now(); return mapper.selectPage(param);
LambdaQueryWrapper<CurrencyRateDO> wrapper = Wrappers.lambdaQuery(CurrencyRateDO.class)
.eq(param.getSourceId() != null, CurrencyRateDO::getSourceId, param.getSourceId())
.eq(param.getTargetId() != null, CurrencyRateDO::getTargetId, param.getTargetId())
// TODO countries intersect
.gt(param.getExpired() == Boolean.FALSE, CurrencyRateDO::getExpiration, now)
.lt(param.getExpired() == Boolean.TRUE, CurrencyRateDO::getExpiration, now)
.gt(param.getExpirationAfter() != null, CurrencyRateDO::getExpiration, param.getExpirationAfter())
.lt(param.getExpirationBefore() != null, CurrencyRateDO::getExpiration, param.getExpirationBefore())
.orderByDesc(Arrays.asList(CurrencyRateDO::getUpdateTime, CurrencyRateDO::getExpiration));
return mapper.selectPage(param, wrapper);
} }
@Override @Override
......
...@@ -4,6 +4,7 @@ import cn.iocoder.yudao.framework.common.pojo.PageParam; ...@@ -4,6 +4,7 @@ import cn.iocoder.yudao.framework.common.pojo.PageParam;
import io.swagger.annotations.ApiModel; import io.swagger.annotations.ApiModel;
import io.swagger.annotations.ApiModelProperty; import io.swagger.annotations.ApiModelProperty;
import lombok.Data; import lombok.Data;
import org.hibernate.validator.constraints.Length;
import org.springframework.format.annotation.DateTimeFormat; import org.springframework.format.annotation.DateTimeFormat;
import java.time.LocalDate; import java.time.LocalDate;
...@@ -20,7 +21,8 @@ public class CurrencyRateQueryParamVO extends PageParam { ...@@ -20,7 +21,8 @@ public class CurrencyRateQueryParamVO extends PageParam {
@ApiModelProperty(value = "支付币种") @ApiModelProperty(value = "支付币种")
private Long targetId; private Long targetId;
@ApiModelProperty(value = "国家") @ApiModelProperty(value = "国家(最多五个)")
@Length(max = 5)
private Set<Long> countries; private Set<Long> countries;
@ApiModelProperty(value = "状态") @ApiModelProperty(value = "状态")
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment