Commit 04497658 authored by 332784038@qq.com's avatar 332784038@qq.com

Merge branch 'refactor-currency-rate' into release

parents 8300fc7c bd7eeeb8
CREATE TABLE IF NOT EXISTS `ecw_currency_rate` (
`id` BIGINT AUTO_INCREMENT,
`source_id` BIGINT NOT NULL COMMENT '原币种',
`target_id` BIGINT NOT NULL COMMENT '支付币种',
`source_amount` DECIMAL(14, 4) NOT NULL COMMENT '原币种金额',
`target_amount` DECIMAL(14, 4) NOT NULL COMMENT '支付币种金额',
`countries` JSON NOT NULL COMMENT '国家',
`expiration` DATE NOT NULL COMMENT '有效日期',
`remarks` VARCHAR(255) NULL COMMENT '备注',
`creator` VARCHAR(32) NOT NULL COMMENT '创建者',
`create_time` DATETIME NOT NULL COMMENT '创建时间',
`updater` VARCHAR(32) NOT NULL COMMENT '更新者',
`update_time` DATETIME NOT NULL COMMENT '更新时间',
`deleted` BIT(1) NOT NULL DEFAULT b'0' COMMENT '是否删除',
PRIMARY KEY (`id`)
) COMMENT '币种汇率表';
CREATE TABLE IF NOT EXISTS `ecw_currency_rate_log` (
`id` BIGINT AUTO_INCREMENT,
`rate_id` BIGINT NOT NULL COMMENT '汇率编号',
`source_amount1` DECIMAL(14, 4) NOT NULL COMMENT '修改前原币种金额',
`source_amount2` DECIMAL(14, 4) NOT NULL COMMENT '修改后原币种金额',
`target_amount1` DECIMAL(14, 4) NOT NULL COMMENT '修改前支付币种金额',
`target_amount2` DECIMAL(14, 4) NOT NULL COMMENT '修改后支付币种金额',
`expiration1` DATE NOT NULL COMMENT '修改前有效期',
`expiration2` DATE NOT NULL COMMENT '修改后有效期',
`remarks` VARCHAR(255) NULL COMMENT '备注',
`creator` VARCHAR(32) NOT NULL COMMENT '创建者',
`create_time` DATETIME NOT NULL COMMENT '创建时间',
`updater` VARCHAR(32) NOT NULL COMMENT '更新者',
`update_time` DATETIME NOT NULL COMMENT '更新时间',
`deleted` BIT(1) NOT NULL DEFAULT b'0' COMMENT '是否删除',
PRIMARY KEY (`id`)
) COMMENT '币种汇率变更表';
BEGIN;
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');
SET @parent = 1244;
INSERT INTO `system_menu` (`name`, `permission`, `menu_type`, `sort`, `parent_id`, `path`, `icon`, `component`, `status`, `creator`, `create_time`, `updater`, `update_time`, `deleted`, `is_show_in_menu_bar`, `name_en`, `keepalive`, `redirect`)
VALUES ('货币汇率', 'ecw:currency:rate:query', 2, 3, @parent, 'currencyRate', 'money', 'ecw/currencyRate/index', 0, '115', '2023-07-09 16:02:32', '115', '2023-07-12 22:33:09', b'0', b'1', 'currency rate', b'0', NULL);
SET @parent = LAST_INSERT_ID();
INSERT INTO `system_menu`
(`name`, `permission`, `menu_type`, `sort`, `parent_id`, `path`, `icon`, `component`, `status`, `creator`, `create_time`, `updater`, `update_time`, `deleted`, `is_show_in_menu_bar`, `name_en`, `keepalive`, `redirect`)
VALUES
('货币汇率新增', 'ecw:currency:rate:create', 3, 1, @parent, '', '', '', 0, '115', '2023-07-09 16:02:32', '115', '2023-07-12 22:33:09', b'0', b'0', 'create', b'0', NULL),
('货币汇率编辑', 'ecw:currency:rate:update', 3, 2, @parent, '', '', '', 0, '115', '2023-07-09 16:02:32', '115', '2023-07-12 22:33:09', b'0', b'0', 'update', b'0', NULL),
('货币汇率删除', 'ecw:currency:rate:delete', 3, 3, @parent, '', '', '', 0, '115', '2023-07-09 16:02:32', '115', '2023-07-12 22:33:09', b'0', b'0', 'delete', b'0', NULL),
('货币汇率日志', 'ecw:currency:rate:history', 3, 4, @parent, '', '', '', 0, '115', '2023-07-09 16:02:32', '115', '2023-07-12 22:33:09', b'0', b'0', 'history', b'0', NULL);
COMMIT;
\ No newline at end of file
......@@ -3,6 +3,7 @@ package cn.iocoder.yudao.module.ecw.api.currency.dto;
import io.swagger.annotations.ApiModelProperty;
import lombok.Data;
import java.math.BigDecimal;
import java.util.Date;
@Data
......@@ -20,7 +21,14 @@ public class ExchangeRateRespDTO {
private String targetCurrencyCode;
@ApiModelProperty(value = "汇率")
private java.math.BigDecimal currencyRate;
private BigDecimal currencyRate;
@ApiModelProperty(value = "原币种基础兑换金额")
private BigDecimal sourceCurrencyAmount;
@ApiModelProperty(value = "目标币种基础兑换金额")
private BigDecimal targetCurrencyAmount;
@ApiModelProperty(value = "汇率有效期")
private Date expireDate;
}
......@@ -151,10 +151,13 @@ public interface ErrorCodeConstants {
ErrorCode CUSTOMER_CANNOT_DELAY_APPROVAL_WITH_NO_ENTER_OPEN_SEA_TIME = new ErrorCode(1004006028, "customer.cannot.delay.approval.with.no.enter.open.sea.time");
ErrorCode EXCHANGE_RATE_NOT_EXISTS = new ErrorCode(1004006029, "currency.rate.not.exists");
ErrorCode CURRENCY_RATE_NOT_EXISTS = new ErrorCode(1004006029, "currency.rate.not.exists");
ErrorCode EXCHANGE_RATE_LOG_NOT_EXISTS = new ErrorCode(1004006030, "汇率变更日志不存在");
ErrorCode EXCHANGE_RATE_EXISTS = new ErrorCode(1004006031, "currency.rate.exists");
ErrorCode CURRENCY_RATE_EXISTS = new ErrorCode(1004006031, "currency.rate.exists");
ErrorCode EXCHANGE_RATE_EXPIRE = new ErrorCode(1004006032, "currency.rate.disable");
ErrorCode CURRENCY_RATE_EXPIRED = new ErrorCode(1004006032, "currency.rate.disable");
ErrorCode EXCHANGE_RATE_NOT_EXISTS_PARAM = new ErrorCode(1004006033, "currency.rate.to.not.exists");
......@@ -191,6 +194,9 @@ public interface ErrorCodeConstants {
ErrorCode AREA_CODE_NOT_NULL = new ErrorCode(1004006044, "area.code.not.null");
ErrorCode CURRENCY_ID_NOT_NULL = new ErrorCode(1004006045, "currency.id.not.null");
ErrorCode CURRENCY_RATE_COUNTRIES_INVALID = new ErrorCode(1004006055, "currency.rate.countries.invalid");
ErrorCode CURRENCY_RATE_PAIR_INVALID = new ErrorCode(1004006056, "currency.rate.pair.invalid");
ErrorCode CURRENCY_RATE_AMOUNT_INVALID = new ErrorCode(1004006057, "currency.rate.amount.invalid");
ErrorCode CURRENCY_RATE_TOO_SMALL = new ErrorCode(1004006059, "currency.rate.too.small");
}
package cn.iocoder.yudao.module.ecw.controller.admin.currencyRate;
import cn.iocoder.yudao.framework.common.pojo.CommonResult;
import cn.iocoder.yudao.framework.common.pojo.PageParam;
import cn.iocoder.yudao.framework.common.pojo.PageResult;
import cn.iocoder.yudao.module.ecw.dal.dataobject.currencyRate.CurrencyRateDO;
import cn.iocoder.yudao.module.ecw.dal.dataobject.currencyRate.CurrencyRateLogDO;
import cn.iocoder.yudao.module.ecw.service.currencyRate.CurrencyRateService;
import cn.iocoder.yudao.module.ecw.vo.currencyRate.CurrencyRateCreateReqVO;
import cn.iocoder.yudao.module.ecw.vo.currencyRate.CurrencyRateQueryParamVO;
import cn.iocoder.yudao.module.ecw.vo.currencyRate.CurrencyRateUpdateReqVO;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiImplicitParam;
import io.swagger.annotations.ApiOperation;
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.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 javax.validation.Valid;
import static cn.iocoder.yudao.framework.common.pojo.CommonResult.success;
@Validated
@RestController
@Api(tags = "管理后台 - 货币汇率")
@RequestMapping("/ecw/currency-rate")
public class CurrencyRateController {
@Autowired
private CurrencyRateService service;
@PostMapping("/create")
@ApiOperation("创建汇率信息")
@PreAuthorize("@ss.hasPermission('ecw:currency:rate:create')")
public CommonResult<Boolean> create(@Valid @RequestBody CurrencyRateCreateReqVO req) {
service.create(req);
return success(true);
}
@PutMapping("/update")
@ApiOperation("更新汇率信息")
@PreAuthorize("@ss.hasPermission('ecw:currency:rate:update')")
@ApiImplicitParam(name = "id", value = "编号", required = true, example = "1024", dataTypeClass = Long.class)
public CommonResult<Boolean> update(@RequestParam("id") Long id, @Valid @RequestBody CurrencyRateUpdateReqVO req) {
service.update(id, req);
return success(true);
}
@DeleteMapping("/delete")
@ApiOperation("删除汇率信息")
@PreAuthorize("@ss.hasPermission('ecw:currency:rate:delete')")
@ApiImplicitParam(name = "id", value = "编号", required = true, example = "1024", dataTypeClass = Long.class)
public CommonResult<Boolean> delete(@RequestParam("id") Long id) {
service.delete(id);
return success(true);
}
@GetMapping("/page")
@ApiOperation("分页查询汇率信息")
@PreAuthorize("@ss.hasPermission('ecw:currency:rate:query')")
public CommonResult<PageResult<CurrencyRateDO>> page(@Valid CurrencyRateQueryParamVO param) {
return success(service.query(param));
}
@GetMapping("/get")
@ApiOperation("根据币种获取汇率信息")
@PreAuthorize("@ss.hasPermission('ecw:currency:rate:query')")
public CommonResult<CurrencyRateDO> get(@RequestParam("sourceId") Long sourceId, @RequestParam("targetId") Long targetId) {
return success(service.find(sourceId, targetId));
}
@GetMapping("/logs")
@ApiOperation("根据币种获取汇率根据货币符号")
@PreAuthorize("@ss.hasPermission('ecw:currency:rate:history')")
@ApiImplicitParam(name = "id", value = "编号", required = true, example = "1024", dataTypeClass = Long.class)
public CommonResult<PageResult<CurrencyRateLogDO>> logs(@RequestParam("id") Long id, PageParam page) {
return success(service.history(id, page));
}
}
package cn.iocoder.yudao.module.ecw.convert.currencyRate;
import cn.iocoder.yudao.module.ecw.dal.dataobject.currencyRate.CurrencyRateDO;
import cn.iocoder.yudao.module.ecw.vo.currencyRate.CurrencyRateCreateReqVO;
import cn.iocoder.yudao.module.ecw.vo.currencyRate.CurrencyRateUpdateReqVO;
import org.mapstruct.Mapper;
import org.mapstruct.MappingTarget;
import org.mapstruct.factory.Mappers;
@Mapper
public interface CurrencyRateConvert {
CurrencyRateConvert INSTANCE = Mappers.getMapper(CurrencyRateConvert.class);
CurrencyRateDO from(CurrencyRateCreateReqVO req);
void update(@MappingTarget CurrencyRateDO saved, CurrencyRateUpdateReqVO req);
}
package cn.iocoder.yudao.module.ecw.dal.dataobject.currencyRate;
import cn.iocoder.yudao.framework.mybatis.core.dataobject.BaseDO;
import cn.iocoder.yudao.framework.mybatis.core.type.JsonLongSetTypeHandler;
import com.baomidou.mybatisplus.annotation.TableField;
import com.baomidou.mybatisplus.annotation.TableId;
import com.baomidou.mybatisplus.annotation.TableName;
import lombok.AllArgsConstructor;
import lombok.Builder;
import lombok.Data;
import lombok.EqualsAndHashCode;
import lombok.NoArgsConstructor;
import lombok.ToString;
import java.math.BigDecimal;
import java.time.LocalDate;
import java.util.Set;
/**
* 货币汇率 DO
*/
@Data
@Builder
@NoArgsConstructor
@AllArgsConstructor
@TableName("ecw_currency_rate")
@EqualsAndHashCode(callSuper = true)
@ToString(callSuper = true)
public class CurrencyRateDO extends BaseDO {
/**
*
*/
@TableId
private Long id;
/**
* 原币种
*/
private Long sourceId;
/**
* 支付币种
*/
private Long targetId;
/**
* 原币种金额
*/
private BigDecimal sourceAmount;
/**
* 支付币种金额
*/
private BigDecimal targetAmount;
/**
* 国家
*/
@TableField(typeHandler = JsonLongSetTypeHandler.class)
private Set<Long> countries;
/**
* 有效期
*/
private LocalDate expiration;
/**
* 备注
*/
private String remarks;
}
package cn.iocoder.yudao.module.ecw.dal.dataobject.currencyRate;
import cn.iocoder.yudao.framework.mybatis.core.dataobject.BaseDO;
import com.baomidou.mybatisplus.annotation.TableId;
import com.baomidou.mybatisplus.annotation.TableName;
import lombok.AllArgsConstructor;
import lombok.Builder;
import lombok.Data;
import lombok.EqualsAndHashCode;
import lombok.NoArgsConstructor;
import lombok.ToString;
import java.math.BigDecimal;
import java.time.LocalDate;
/**
* 货币汇率变更历史 DO
*/
@Data
@Builder
@NoArgsConstructor
@AllArgsConstructor
@TableName("ecw_currency_rate_log")
@EqualsAndHashCode(callSuper = true)
@ToString(callSuper = true)
public class CurrencyRateLogDO extends BaseDO {
/**
*
*/
@TableId
private Long id;
/**
* 汇率编号
*/
private Long rateId;
/**
* 原币种变更前金额
*/
private BigDecimal sourceAmount1;
/**
* 原币种变更后金额
*/
private BigDecimal sourceAmount2;
/**
* 支付币种变更前金额
*/
private BigDecimal targetAmount1;
/**
* 支付币种变更后金额
*/
private BigDecimal targetAmount2;
/**
* 有效期
*/
private LocalDate expiration1;
/**
* 有效期
*/
private LocalDate expiration2;
/**
* 备注
*/
private String remarks;
}
package cn.iocoder.yudao.module.ecw.dal.mysql.currencyRate;
import cn.iocoder.yudao.framework.mybatis.core.mapper.AbstractMapper;
import cn.iocoder.yudao.module.ecw.dal.dataobject.currencyRate.CurrencyRateLogDO;
import org.apache.ibatis.annotations.Mapper;
@Mapper
public interface CurrencyRateLogMapper extends AbstractMapper<CurrencyRateLogDO> {
}
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.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 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
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);
}
}
package cn.iocoder.yudao.module.ecw.service.api;
import cn.hutool.core.date.DateUtil;
import cn.hutool.core.util.StrUtil;
import cn.iocoder.yudao.module.ecw.api.currency.CurrencyApi;
import cn.iocoder.yudao.module.ecw.api.currency.dto.CurrencyRespDTO;
import cn.iocoder.yudao.module.ecw.api.currency.dto.ExchangeRateRespDTO;
import cn.iocoder.yudao.module.ecw.convert.currency.CurrencyConvert;
import cn.iocoder.yudao.module.ecw.convert.exchangeRate.ExchangeRateConvert;
import cn.iocoder.yudao.module.ecw.dal.dataobject.currency.CurrencyDO;
import cn.iocoder.yudao.module.ecw.dal.dataobject.exchangeRate.ExchangeRateDO;
import cn.iocoder.yudao.module.ecw.dal.dataobject.currencyRate.CurrencyRateDO;
import cn.iocoder.yudao.module.ecw.service.currency.CurrencyService;
import cn.iocoder.yudao.module.ecw.service.exchangeRate.ExchangeRateService;
import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper;
import cn.iocoder.yudao.module.ecw.service.currencyRate.CurrencyRateService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
import javax.annotation.Resource;
import java.math.BigDecimal;
import java.util.ArrayList;
import java.util.Collection;
import java.util.List;
import java.util.Map;
import java.util.Optional;
import java.util.stream.Collectors;
import static cn.iocoder.yudao.framework.common.exception.util.ServiceExceptionUtil.exception;
import static cn.iocoder.yudao.module.ecw.enums.ErrorCodeConstants.EXCHANGE_RATE_EXPIRE;
import static cn.iocoder.yudao.module.ecw.enums.ErrorCodeConstants.EXCHANGE_RATE_NOT_EXISTS_PARAM;
@Service
public class CurrecyApiImpl implements CurrencyApi {
@Resource
CurrencyService currencyService;
@Resource
ExchangeRateService exchangeRateService;
@Autowired
private CurrencyRateService currencyRateService;
@Override
public Map<Integer, CurrencyRespDTO> getAllCurrency() {
......@@ -42,158 +36,77 @@ public class CurrecyApiImpl implements CurrencyApi {
@Override
public ExchangeRateRespDTO getCurrencyRate(Long sourceId, Long targetId) {
if (sourceId == targetId) {
ExchangeRateRespDTO dto = new ExchangeRateRespDTO();
dto.setCurrencyRate(new BigDecimal("1"));
dto.setSourceCurrencyId(sourceId);
dto.setTargetCurrencyId(targetId);
return dto;
}
LambdaQueryWrapper<ExchangeRateDO> lambdaQueryWrapper = new LambdaQueryWrapper<>();
lambdaQueryWrapper.eq(ExchangeRateDO::getSourceCurrencyId, sourceId);
lambdaQueryWrapper.eq(ExchangeRateDO::getTargetCurrencyId, targetId);
ExchangeRateDO rateDO = exchangeRateService.getOne(lambdaQueryWrapper);
CurrencyDO currencyDO1 = currencyService.getCurrency(sourceId.intValue());
CurrencyDO currencyDO2 = currencyService.getCurrency(targetId.intValue());
if (null != rateDO) {
//判断汇率有没有过期
if (null != rateDO.getExpireDate()) {
if (DateUtil.compare(rateDO.getExpireDate(), DateUtil.date()) == -1) {
if (null == currencyDO1 || null == currencyDO2) {
throw exception(EXCHANGE_RATE_EXPIRE, sourceId.toString(), targetId.toString());
} else {
throw exception(EXCHANGE_RATE_EXPIRE, currencyDO1.getTitleZh() + currencyDO1.getFuhao(), currencyDO2.getTitleZh() + currencyDO2.getFuhao());
}
}
} else {
if (null == currencyDO1 || null == currencyDO2) {
throw exception(EXCHANGE_RATE_EXPIRE, sourceId.toString(), targetId.toString());
} else {
throw exception(EXCHANGE_RATE_EXPIRE, currencyDO1.getTitleZh() + currencyDO1.getFuhao(), currencyDO2.getTitleZh() + currencyDO2.getFuhao());
}
}
return ExchangeRateConvert.INSTANCE.convert2(exchangeRateService.getOne(lambdaQueryWrapper));
ExchangeRateRespDTO dto = new ExchangeRateRespDTO();
dto.setSourceCurrencyId(sourceId);
dto.setTargetCurrencyId(targetId);
if (sourceId == null || targetId == null) {
dto.setCurrencyRate(BigDecimal.ZERO);
dto.setSourceCurrencyAmount(BigDecimal.ONE);// 除数默认值给1,避免计算错误
dto.setTargetCurrencyAmount(BigDecimal.ZERO);
} else {
if (null == currencyDO1 || null == currencyDO2) {
ExchangeRateRespDTO dto = new ExchangeRateRespDTO();
dto.setCurrencyRate(BigDecimal.ZERO);
dto.setSourceCurrencyId(sourceId);
dto.setTargetCurrencyId(targetId);
return dto;
} else {
throw exception(EXCHANGE_RATE_NOT_EXISTS_PARAM, currencyDO1.getTitleZh() + currencyDO1.getFuhao(), currencyDO2.getTitleZh() + currencyDO2.getFuhao());
if (sourceId.equals(targetId)){
dto.setSourceCurrencyAmount(BigDecimal.ONE);
dto.setTargetCurrencyAmount(BigDecimal.ONE);
dto.setCurrencyRate(BigDecimal.ONE);
}else {
CurrencyRateDO currencyRateDO = currencyRateService.exchangeBaseValue(sourceId, targetId);
dto.setSourceCurrencyAmount(currencyRateDO.getSourceAmount());
dto.setTargetCurrencyAmount(currencyRateDO.getTargetAmount());
dto.setCurrencyRate(currencyRateService.rate(currencyRateDO.getSourceAmount(), currencyRateDO.getTargetAmount()));
}
}
return dto;
}
@Override
public List<ExchangeRateRespDTO> getCurrencyRateList(Collection<Long> sourceIds, Long targetId) {
List<ExchangeRateRespDTO> exchangeRateRespDTOList = new ArrayList<>();
for (Long sourceId : sourceIds) {
if (sourceId == targetId) {
ExchangeRateRespDTO dto = new ExchangeRateRespDTO();
dto.setCurrencyRate(new BigDecimal("1"));
dto.setSourceCurrencyId(sourceId);
dto.setTargetCurrencyId(targetId);
exchangeRateRespDTOList.add(dto);
continue;
}
LambdaQueryWrapper<ExchangeRateDO> lambdaQueryWrapper = new LambdaQueryWrapper<>();
lambdaQueryWrapper.eq(ExchangeRateDO::getSourceCurrencyId, sourceId);
lambdaQueryWrapper.eq(ExchangeRateDO::getTargetCurrencyId, targetId);
ExchangeRateDO rateDO = exchangeRateService.getOne(lambdaQueryWrapper);
CurrencyDO currencyDO1 = currencyService.getCurrency(sourceId.intValue());
CurrencyDO currencyDO2 = currencyService.getCurrency(targetId.intValue());
if (null != rateDO) {
//判断汇率有没有过期
if (null != rateDO.getExpireDate()) {
if (DateUtil.compare(rateDO.getExpireDate(), DateUtil.date()) == -1) {
if (null == currencyDO1 || null == currencyDO2) {
throw exception(EXCHANGE_RATE_EXPIRE, sourceId.toString(), targetId.toString());
} else {
throw exception(EXCHANGE_RATE_EXPIRE, currencyDO1.getTitleZh() + currencyDO1.getFuhao(), currencyDO2.getTitleZh() + currencyDO2.getFuhao());
}
}
} else {
if (null == currencyDO1 || null == currencyDO2) {
throw exception(EXCHANGE_RATE_EXPIRE, sourceId.toString(), targetId.toString());
} else {
throw exception(EXCHANGE_RATE_EXPIRE, currencyDO1.getTitleZh() + currencyDO1.getFuhao(), currencyDO2.getTitleZh() + currencyDO2.getFuhao());
}
}
exchangeRateRespDTOList.add(ExchangeRateConvert.INSTANCE.convert2(rateDO));
} else {
if (null == currencyDO1 || null == currencyDO2) {
ExchangeRateRespDTO dto = new ExchangeRateRespDTO();
dto.setCurrencyRate(BigDecimal.ZERO);
dto.setSourceCurrencyId(sourceId);
dto.setTargetCurrencyId(targetId);
exchangeRateRespDTOList.add(dto);
} else {
throw exception(EXCHANGE_RATE_NOT_EXISTS_PARAM, currencyDO1.getTitleZh() + currencyDO1.getFuhao(), currencyDO2.getTitleZh() + currencyDO2.getFuhao());
}
}
}
return exchangeRateRespDTOList;
return sourceIds.stream()
.map(sourceId -> getCurrencyRate(sourceId, targetId))
.collect(Collectors.toList());
}
@Override
public ExchangeRateRespDTO getCurrencyRateByCode(String sourceCode, String targetCode) {
ExchangeRateRespDTO dto = new ExchangeRateRespDTO();
dto.setSourceCurrencyCode(sourceCode);
dto.setTargetCurrencyCode(targetCode);
if (StrUtil.equals(sourceCode, targetCode)) {
ExchangeRateRespDTO dto = new ExchangeRateRespDTO();
dto.setCurrencyRate(new BigDecimal("1"));
dto.setSourceCurrencyCode(sourceCode);
dto.setTargetCurrencyCode(targetCode);
dto.setSourceCurrencyAmount(BigDecimal.ONE);
dto.setTargetCurrencyAmount(BigDecimal.ONE);
dto.setCurrencyRate(BigDecimal.ONE);
return dto;
}
LambdaQueryWrapper<ExchangeRateDO> lambdaQueryWrapper = new LambdaQueryWrapper<>();
lambdaQueryWrapper.eq(ExchangeRateDO::getSourceCurrencyCode, sourceCode);
lambdaQueryWrapper.eq(ExchangeRateDO::getTargetCurrencyCode, targetCode);
ExchangeRateDO rateDO = exchangeRateService.getOne(lambdaQueryWrapper);
CurrencyDO currencyDO1 = currencyService.getCurrencyByCode(sourceCode);
CurrencyDO currencyDO2 = currencyService.getCurrencyByCode(targetCode);
if (null != rateDO) {
//判断汇率有没有过期
if (null != rateDO.getExpireDate()) {
if (DateUtil.compare(rateDO.getExpireDate(), DateUtil.date()) == -1) {
if (null == currencyDO1 || null == currencyDO2) {
throw exception(EXCHANGE_RATE_EXPIRE, sourceCode, targetCode);
} else {
throw exception(EXCHANGE_RATE_EXPIRE, currencyDO1.getTitleZh() + currencyDO1.getFuhao(), currencyDO2.getTitleZh() + currencyDO2.getFuhao());
}
}
} else {
if (null == currencyDO1 || null == currencyDO2) {
throw exception(EXCHANGE_RATE_EXPIRE, sourceCode, targetCode);
} else {
throw exception(EXCHANGE_RATE_EXPIRE, currencyDO1.getTitleZh() + currencyDO1.getFuhao(), currencyDO2.getTitleZh() + currencyDO2.getFuhao());
}
}
return ExchangeRateConvert.INSTANCE.convert2(exchangeRateService.getOne(lambdaQueryWrapper));
Integer sourceId = Optional.ofNullable(currencyService.getCurrencyByCode(sourceCode))
.map(CurrencyDO::getId)
.orElse(null);
Integer targetId = Optional.ofNullable(currencyService.getCurrencyByCode(targetCode))
.map(CurrencyDO::getId)
.orElse(null);
if (sourceId == null || targetId == null) {
dto.setCurrencyRate(BigDecimal.ZERO);
dto.setSourceCurrencyAmount(BigDecimal.ONE);// 除数默认值给1,避免计算错误
dto.setTargetCurrencyAmount(BigDecimal.ZERO);
} else {
if (null == currencyDO1 || null == currencyDO2) {
ExchangeRateRespDTO dto = new ExchangeRateRespDTO();
dto.setCurrencyRate(BigDecimal.ZERO);
dto.setSourceCurrencyCode(sourceCode);
dto.setTargetCurrencyCode(targetCode);
return dto;
} else {
throw exception(EXCHANGE_RATE_NOT_EXISTS_PARAM, currencyDO1.getTitleZh() + currencyDO1.getFuhao(), currencyDO2.getTitleZh() + currencyDO2.getFuhao());
if (sourceId.equals(targetId)){
dto.setSourceCurrencyAmount(BigDecimal.ONE);
dto.setTargetCurrencyAmount(BigDecimal.ONE);
dto.setCurrencyRate(BigDecimal.ONE);
}else {
CurrencyRateDO currencyRateDO = currencyRateService.exchangeBaseValue(sourceId, targetId);
dto.setSourceCurrencyAmount(currencyRateDO.getSourceAmount());
dto.setTargetCurrencyAmount(currencyRateDO.getTargetAmount());
dto.setCurrencyRate(currencyRateService.rate(currencyRateDO.getSourceAmount(), currencyRateDO.getTargetAmount()));
}
}
}
return dto;
}
@Override
......
package cn.iocoder.yudao.module.ecw.service.currencyRate;
import cn.iocoder.yudao.framework.common.exception.ServiceException;
import cn.iocoder.yudao.framework.common.pojo.PageParam;
import cn.iocoder.yudao.framework.common.pojo.PageResult;
import cn.iocoder.yudao.module.ecw.dal.dataobject.currencyRate.CurrencyRateDO;
import cn.iocoder.yudao.module.ecw.dal.dataobject.currencyRate.CurrencyRateLogDO;
import cn.iocoder.yudao.module.ecw.vo.currencyRate.CurrencyRateCreateReqVO;
import cn.iocoder.yudao.module.ecw.vo.currencyRate.CurrencyRateQueryParamVO;
import cn.iocoder.yudao.module.ecw.vo.currencyRate.CurrencyRateUpdateReqVO;
import java.math.BigDecimal;
import java.math.RoundingMode;
import java.time.LocalDate;
import java.util.Optional;
import static cn.iocoder.yudao.framework.common.exception.util.ServiceExceptionUtil.exception;
import static cn.iocoder.yudao.module.ecw.enums.ErrorCodeConstants.CURRENCY_RATE_AMOUNT_INVALID;
import static cn.iocoder.yudao.module.ecw.enums.ErrorCodeConstants.CURRENCY_RATE_EXPIRED;
import static cn.iocoder.yudao.module.ecw.enums.ErrorCodeConstants.CURRENCY_RATE_NOT_EXISTS;
import static cn.iocoder.yudao.module.ecw.enums.ErrorCodeConstants.CURRENCY_RATE_TOO_SMALL;
/**
* 货币汇率服务
*/
public interface CurrencyRateService {
/**
* 汇率精度。
*/
int RATE_SCALE = 8;
/**
* 汇率四舍五入。
*/
RoundingMode RATE_ROUNDING = RoundingMode.HALF_UP;
/**
* 计算两个金额的汇率。
*
* @param source 原金额
* @param target 目标金额
* @return 汇率
* @throws ServiceException 金额小于或等零,或者汇率小于精度下最小值
*/
default BigDecimal rate(BigDecimal source, BigDecimal target) throws ServiceException {
if (source.compareTo(BigDecimal.ZERO) <= 0 || target.compareTo(BigDecimal.ZERO) <= 0) {
throw exception(CURRENCY_RATE_AMOUNT_INVALID);
}
return Optional.of(target.divide(source, RATE_SCALE, RATE_ROUNDING))
.filter(it -> it.compareTo(BigDecimal.ZERO) > 0)
.orElseThrow(() -> exception(CURRENCY_RATE_TOO_SMALL));
}
/**
* 获得两个币种的兑换基础值。
*
* @param sourceId 原币种编号
* @param targetId 支付币种编号
* @return 获得两个币种的兑换基础值
* @throws ServiceException 汇率不存在或过期
*/
default CurrencyRateDO exchangeBaseValue(long sourceId, long targetId) throws ServiceException {
CurrencyRateDO entity = Optional.ofNullable(find(sourceId, targetId))
.orElseThrow(() -> exception(CURRENCY_RATE_NOT_EXISTS));
LocalDate now = LocalDate.now();
if (now.isAfter(entity.getExpiration())) {
throw exception(CURRENCY_RATE_EXPIRED, String.valueOf(sourceId), String.valueOf(targetId));
}
return entity;
}
/**
* 计算两个币种的汇率。
*
* @param sourceId 原币种编号
* @param targetId 支付币种编号
* @return 汇率比值,为空则表示汇率不存在
* @throws ServiceException 汇率不存在或过期
*/
default BigDecimal rate(long sourceId, long targetId) throws ServiceException {
CurrencyRateDO entity = Optional.ofNullable(find(sourceId, targetId))
.orElseThrow(() -> exception(CURRENCY_RATE_NOT_EXISTS));
LocalDate now = LocalDate.now();
if (now.isAfter(entity.getExpiration())) {
throw exception(CURRENCY_RATE_EXPIRED, String.valueOf(sourceId), String.valueOf(targetId));
}
return rate(entity.getSourceAmount(), entity.getTargetAmount());
}
/**
* 计算两个币种的汇率。
*
* @param sourceId 原币种编号
* @param targetId 支付币种编号
* @param tryOpposite 如果不存在则使用反向汇率计算
* @return 汇率比值,为空则表示汇率不存在
* @throws ServiceException 汇率不存在或过期或反向汇率过小
*/
default BigDecimal rate(long sourceId, long targetId, boolean tryOpposite) throws ServiceException {
try {
return rate(sourceId, targetId);
} catch (ServiceException e) {
if (!tryOpposite) {
throw e;
}
return BigDecimal.ONE.divide(rate(targetId, sourceId), RATE_SCALE, RATE_ROUNDING);
}
}
/**
* 创建新汇率。
*
* @param req 创建请求
* @throws ServiceException 汇率已存在或金额国家等参数不合法
*/
void create(CurrencyRateCreateReqVO req);
/**
* 获取汇率信息。
*
* @param sourceId 原币种编号
* @param targetId 支付币种编号
* @return 汇率信息,可能为空
*/
CurrencyRateDO find(long sourceId, long targetId);
/**
* 分页查询汇率。
*
* @param param 分页参数
* @return 分页结果
*/
PageResult<CurrencyRateDO> query(CurrencyRateQueryParamVO param);
/**
* 更新汇率信息。
*
* @param id 汇率信息编号
* @param req 更新请求
* @throws ServiceException 汇率不存在或金额等参数不合法
*/
void update(long id, CurrencyRateUpdateReqVO req);
/**
* 删除汇率信息。
*
* @param id 汇率信息编号
*/
void delete(long id);
/**
* 分页查询汇率变更历史。
*
* @param id 汇率信息编号
* @param param 分页参数
* @return 分页结果
*/
PageResult<CurrencyRateLogDO> history(long id, PageParam param);
}
package cn.iocoder.yudao.module.ecw.service.currencyRate;
import cn.iocoder.yudao.framework.common.pojo.PageParam;
import cn.iocoder.yudao.framework.common.pojo.PageResult;
import cn.iocoder.yudao.module.ecw.convert.currencyRate.CurrencyRateConvert;
import cn.iocoder.yudao.module.ecw.dal.dataobject.currencyRate.CurrencyRateDO;
import cn.iocoder.yudao.module.ecw.dal.dataobject.currencyRate.CurrencyRateLogDO;
import cn.iocoder.yudao.module.ecw.dal.mysql.currencyRate.CurrencyRateLogMapper;
import cn.iocoder.yudao.module.ecw.dal.mysql.currencyRate.CurrencyRateMapper;
import cn.iocoder.yudao.module.ecw.service.country.CountryService;
import cn.iocoder.yudao.module.ecw.service.currency.CurrencyService;
import cn.iocoder.yudao.module.ecw.vo.currencyRate.CurrencyRateCreateReqVO;
import cn.iocoder.yudao.module.ecw.vo.currencyRate.CurrencyRateQueryParamVO;
import cn.iocoder.yudao.module.ecw.vo.currencyRate.CurrencyRateUpdateReqVO;
import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper;
import com.baomidou.mybatisplus.core.toolkit.Wrappers;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
import java.util.Optional;
import java.util.Set;
import static cn.iocoder.yudao.framework.common.exception.util.ServiceExceptionUtil.exception;
import static cn.iocoder.yudao.module.ecw.enums.ErrorCodeConstants.CURRENCY_NOT_EXISTS;
import static cn.iocoder.yudao.module.ecw.enums.ErrorCodeConstants.CURRENCY_RATE_COUNTRIES_INVALID;
import static cn.iocoder.yudao.module.ecw.enums.ErrorCodeConstants.CURRENCY_RATE_EXISTS;
import static cn.iocoder.yudao.module.ecw.enums.ErrorCodeConstants.CURRENCY_RATE_NOT_EXISTS;
import static cn.iocoder.yudao.module.ecw.enums.ErrorCodeConstants.CURRENCY_RATE_PAIR_INVALID;
@Service
public class CurrencyRateServiceImpl implements CurrencyRateService {
@Autowired
private CountryService countryService;
@Autowired
private CurrencyService currencyService;
@Autowired
private CurrencyRateMapper mapper;
@Autowired
private CurrencyRateLogMapper logMapper;
// 检查指定币种是否存在
private void currency(long id) {
Optional.ofNullable(currencyService.getCurrency((int) id))
.orElseThrow(() -> exception(CURRENCY_NOT_EXISTS));
}
@Override
public void create(CurrencyRateCreateReqVO req) {
long sourceId = req.getSourceId();
long targetId = req.getTargetId();
Set<Long> countries = req.getCountries();
if (sourceId == targetId) {
throw exception(CURRENCY_RATE_PAIR_INVALID);
}
rate(req.getSourceAmount(), req.getTargetAmount()); // check rate
if (countries.isEmpty() || (countries.size() != countryService.getCountryList(countries).size())) {
throw exception(CURRENCY_RATE_COUNTRIES_INVALID);
}
// check if currencies exist
currency(sourceId);
currency(targetId);
if (find(sourceId, targetId) != null) {
throw exception(CURRENCY_RATE_EXISTS);
}
mapper.insert(CurrencyRateConvert.INSTANCE.from(req));
}
@Override
public CurrencyRateDO find(long sourceId, long targetId) {
LambdaQueryWrapper<CurrencyRateDO> wrapper = Wrappers.lambdaQuery(CurrencyRateDO.class)
.eq(CurrencyRateDO::getSourceId, sourceId)
.eq(CurrencyRateDO::getTargetId, targetId);
return mapper.selectOne(wrapper);
}
@Override
public PageResult<CurrencyRateDO> query(CurrencyRateQueryParamVO param) {
return mapper.selectPage(param);
}
@Override
public void update(long id, CurrencyRateUpdateReqVO req) {
rate(req.getSourceAmount(), req.getTargetAmount()); // check rate
CurrencyRateLogDO change = new CurrencyRateLogDO();
CurrencyRateDO saved = Optional.ofNullable(mapper.selectById(id))
.orElseThrow(() -> exception(CURRENCY_RATE_NOT_EXISTS));
// 修改前
change.setSourceAmount1(saved.getSourceAmount());
change.setTargetAmount1(saved.getTargetAmount());
change.setExpiration1(saved.getExpiration());
// 修改后
change.setSourceAmount2(req.getSourceAmount());
change.setTargetAmount2(req.getTargetAmount());
change.setExpiration2(req.getExpiration());
change.setRateId(id);
change.setRemarks(req.getRemarks());
logMapper.insert(change);
CurrencyRateConvert.INSTANCE.update(saved, req);
mapper.updateById(saved);
}
@Override
public void delete(long id) {
mapper.deleteById(id);
}
@Override
public PageResult<CurrencyRateLogDO> history(long id, PageParam param) {
LambdaQueryWrapper<CurrencyRateLogDO> wrapper = Wrappers.lambdaQuery(CurrencyRateLogDO.class)
.eq(CurrencyRateLogDO::getRateId, id)
.orderByDesc(CurrencyRateLogDO::getCreateTime);
return logMapper.selectPage(param, wrapper);
}
}
package cn.iocoder.yudao.module.ecw.vo.currencyRate;
import io.swagger.annotations.ApiModel;
import io.swagger.annotations.ApiModelProperty;
import lombok.Data;
import org.springframework.format.annotation.DateTimeFormat;
import javax.validation.constraints.Min;
import javax.validation.constraints.NotNull;
import java.math.BigDecimal;
import java.time.LocalDate;
import java.util.Set;
import static cn.iocoder.yudao.framework.common.util.date.DateUtils.FORMAT_YEAR_MONTH_DAY;
@Data
@ApiModel("管理后台 - 货币汇率创建 Request VO")
public class CurrencyRateCreateReqVO {
@ApiModelProperty(value = "原币种", required = true)
@NotNull(message = "原币种不能为空")
private Long sourceId;
@ApiModelProperty(value = "支付币种", required = true)
@NotNull(message = "支付币种不能为空")
private Long targetId;
@ApiModelProperty(value = "原币种金额", required = true)
@NotNull(message = "原币种不能为空")
@Min(0)
private BigDecimal sourceAmount;
@ApiModelProperty(value = "支付币种", required = true)
@NotNull(message = "支付币种不能为空")
@Min(0)
private BigDecimal targetAmount;
@ApiModelProperty(value = "国家", required = true)
@NotNull(message = "至少选择一个国家")
private Set<Long> countries;
@DateTimeFormat(pattern = FORMAT_YEAR_MONTH_DAY)
@ApiModelProperty(value = "汇率有效截止日期")
private LocalDate expiration;
@ApiModelProperty(value = "备注")
private String remarks;
}
package cn.iocoder.yudao.module.ecw.vo.currencyRate;
import cn.iocoder.yudao.framework.common.pojo.PageParam;
import io.swagger.annotations.ApiModel;
import io.swagger.annotations.ApiModelProperty;
import lombok.Data;
import org.hibernate.validator.constraints.Length;
import org.springframework.format.annotation.DateTimeFormat;
import java.time.LocalDate;
import java.util.Set;
import static cn.iocoder.yudao.framework.common.util.date.DateUtils.FORMAT_YEAR_MONTH_DAY;
@Data
@ApiModel("管理后台 - 货币汇率查询 VO")
public class CurrencyRateQueryParamVO extends PageParam {
@ApiModelProperty(value = "原币种")
private Long sourceId;
@ApiModelProperty(value = "支付币种")
private Long targetId;
@ApiModelProperty(value = "国家(最多五个)")
@Length(max = 5)
private Set<Long> countries;
@ApiModelProperty(value = "状态")
private Boolean expired;
@DateTimeFormat(pattern = FORMAT_YEAR_MONTH_DAY)
@ApiModelProperty(value = "有效期大于")
private LocalDate expirationAfter;
@DateTimeFormat(pattern = FORMAT_YEAR_MONTH_DAY)
@ApiModelProperty(value = "有效期小于")
private LocalDate expirationBefore;
}
package cn.iocoder.yudao.module.ecw.vo.currencyRate;
import io.swagger.annotations.ApiModel;
import io.swagger.annotations.ApiModelProperty;
import lombok.Data;
import org.springframework.format.annotation.DateTimeFormat;
import javax.validation.constraints.Min;
import javax.validation.constraints.NotNull;
import java.math.BigDecimal;
import java.time.LocalDate;
import static cn.iocoder.yudao.framework.common.util.date.DateUtils.FORMAT_YEAR_MONTH_DAY;
@Data
@ApiModel("管理后台 - 货币汇率更新 Request VO")
public class CurrencyRateUpdateReqVO {
@ApiModelProperty(value = "原币种金额", required = true)
@NotNull(message = "原币种不能为空")
@Min(0)
private BigDecimal sourceAmount;
@ApiModelProperty(value = "支付币种", required = true)
@NotNull(message = "支付币种不能为空")
@Min(0)
private BigDecimal targetAmount;
@DateTimeFormat(pattern = FORMAT_YEAR_MONTH_DAY)
@ApiModelProperty(value = "汇率有效截止日期")
private LocalDate expiration;
@ApiModelProperty(value = "备注")
private String remarks;
}
<?xml version="1.0" encoding="UTF-8"?>
<!DOCTYPE mapper PUBLIC "-//mybatis.org//DTD Mapper 3.0//EN" "http://mybatis.org/dtd/mybatis-3-mapper.dtd">
<mapper namespace="cn.iocoder.yudao.module.ecw.dal.mysql.ladingTemplate.LadingTemplateMapper">
<!--
一般情况下,尽可能使用 Mapper 进行 CRUD 增删改查即可。
无法满足的场景,例如说多表关联查询,才使用 XML 编写 SQL。
代码生成器暂时只生成 Mapper XML 文件本身,更多推荐 MybatisX 快速开发插件来生成查询。
文档可见:https://www.iocoder.cn/MyBatis/x-plugins/
-->
</mapper>
<?xml version="1.0" encoding="UTF-8"?>
<!DOCTYPE mapper PUBLIC "-//mybatis.org//DTD Mapper 3.0//EN" "http://mybatis.org/dtd/mybatis-3-mapper.dtd">
<mapper namespace="cn.iocoder.yudao.module.ecw.dal.mysql.warehouse.WarehouseMapper">
<!--
一般情况下,尽可能使用 Mapper 进行 CRUD 增删改查即可。
无法满足的场景,例如说多表关联查询,才使用 XML 编写 SQL。
代码生成器暂时只生成 Mapper XML 文件本身,更多推荐 MybatisX 快速开发插件来生成查询。
文档可见:https://www.iocoder.cn/MyBatis/x-plugins/
-->
</mapper>
<?xml version="1.0" encoding="UTF-8"?>
<!DOCTYPE mapper PUBLIC "-//mybatis.org//DTD Mapper 3.0//EN" "http://mybatis.org/dtd/mybatis-3-mapper.dtd">
<mapper namespace="cn.iocoder.yudao.module.ecw.dal.mysql.zhongPao.ZhongPaoMapper">
<!--
一般情况下,尽可能使用 Mapper 进行 CRUD 增删改查即可。
无法满足的场景,例如说多表关联查询,才使用 XML 编写 SQL。
代码生成器暂时只生成 Mapper XML 文件本身,更多推荐 MybatisX 快速开发插件来生成查询。
文档可见:https://www.iocoder.cn/MyBatis/x-plugins/
-->
</mapper>
......@@ -2528,8 +2528,9 @@ public class OrderBusinessServiceImpl extends AbstractService<OrderMapper, Order
if (Objects.isNull(exchangeRateRespDTO)) {
throw exception(EXCHANGE_RATE_NOT_EXISTS_PARAM, currencyRespDTOMap.get(feeDto.getCurrencyId()).getFuhao(), currencyRespDTOMap.get(1).getFuhao());
}
oldFreightAndClearanceFee =
oldFreightAndClearanceFee.add(feeDto.getAmount().multiply(exchangeRateRespDTO.getCurrencyRate()));
// oldFreightAndClearanceFee = oldFreightAndClearanceFee.add(feeDto.getAmount().multiply(exchangeRateRespDTO.getCurrencyRate()));
// 调整汇率计算为新的逻辑公式: 待计算原币种金额 * 目标支付币种金额基础值 / 原币种金额基础值(注:这里的币种金额基础值为后台设定的汇兑基础值) ,最终结果保留两位小数点四舍五入
oldFreightAndClearanceFee = oldFreightAndClearanceFee.add(feeDto.getAmount().multiply(exchangeRateRespDTO.getTargetCurrencyAmount()).divide(exchangeRateRespDTO.getSourceCurrencyAmount(), 2, RoundingMode.HALF_UP));
} else {
oldFreightAndClearanceFee =
oldFreightAndClearanceFee.add(feeDto.getAmount());
......@@ -2550,7 +2551,9 @@ public class OrderBusinessServiceImpl extends AbstractService<OrderMapper, Order
if (Objects.isNull(exchangeRateRespDTO)) {
throw exception(EXCHANGE_RATE_NOT_EXISTS_PARAM, currencyRespDTOMap.get(feeDto.getCurrencyId()).getFuhao(), currencyRespDTOMap.get(1).getFuhao());
}
newFreightAndClearanceFee = newFreightAndClearanceFee.add(feeDto.getAmount().multiply(exchangeRateRespDTO.getCurrencyRate()));
// newFreightAndClearanceFee = newFreightAndClearanceFee.add(feeDto.getAmount().multiply(exchangeRateRespDTO.getCurrencyRate()));
// 调整汇率计算为新的逻辑公式: 待计算原币种金额 * 目标支付币种金额基础值 / 原币种金额基础值(注:这里的币种金额基础值为后台设定的汇兑基础值) ,最终结果保留两位小数点四舍五入
newFreightAndClearanceFee = newFreightAndClearanceFee.add(feeDto.getAmount().multiply(exchangeRateRespDTO.getTargetCurrencyAmount()).divide(exchangeRateRespDTO.getSourceCurrencyAmount(), 2 ,RoundingMode.HALF_UP));
} else {
newFreightAndClearanceFee = newFreightAndClearanceFee.add(feeDto.getAmount());
}
......@@ -4072,12 +4075,14 @@ public class OrderBusinessServiceImpl extends AbstractService<OrderMapper, Order
BigDecimal totalOnePrice = BigDecimal.ZERO;
if (Objects.nonNull(param.getOneFreight()) && param.getOneFreight().compareTo(BigDecimal.ZERO) > 0) {
ExchangeRateRespDTO freightExchangeRate = currencyApi.getCurrencyRate(Long.valueOf(param.getFreightCurrency().toString()), targetId);
totalOnePrice = totalOnePrice.add(param.getOneFreight().multiply(freightExchangeRate.getCurrencyRate()).setScale(2, RoundingMode.HALF_UP));
// 调整汇率计算为新的逻辑公式: 待计算原币种金额 * 目标支付币种金额基础值 / 原币种金额基础值(注:这里的币种金额基础值为后台设定的汇兑基础值) ,最终结果保留两位小数点四舍五入
totalOnePrice = totalOnePrice.add(param.getOneFreight().multiply(freightExchangeRate.getTargetCurrencyAmount()).divide(freightExchangeRate.getSourceCurrencyAmount(), 2, RoundingMode.HALF_UP));
}
if (param.getCharging() == 0) {
if (Objects.nonNull(param.getOneClearanceFee()) && param.getOneClearanceFee().compareTo(BigDecimal.ZERO) > 0) {
ExchangeRateRespDTO clearanceExchangeRate = currencyApi.getCurrencyRate(Long.valueOf(param.getClearanceFeeCurrency().toString()), targetId);
totalOnePrice = totalOnePrice.add(param.getOneClearanceFee().multiply(clearanceExchangeRate.getCurrencyRate()).setScale(2, RoundingMode.HALF_UP));
// 调整汇率计算为新的逻辑公式: 待计算原币种金额 * 目标支付币种金额基础值 / 原币种金额基础值(注:这里的币种金额基础值为后台设定的汇兑基础值) ,最终结果保留两位小数点四舍五入
totalOnePrice = totalOnePrice.add(param.getOneClearanceFee().multiply(clearanceExchangeRate.getTargetCurrencyAmount()).divide(clearanceExchangeRate.getSourceCurrencyAmount(), 2, RoundingMode.HALF_UP));
}
}
orderItemDO.setTotalOnePrice(totalOnePrice);
......
......@@ -1305,12 +1305,13 @@ public class OrderQueryServiceImpl implements OrderQueryService {
//重新获取汇率-转成RMB
ExchangeRateRespDTO rateRespDTO = currencyApi.getCurrencyRateByCode(rate.getFuhao(), "¥");
if (null != rateRespDTO && null != rateRespDTO.getCurrencyRate()) {
totalAmount = totalAmount.add(receivableFee.multiply(rateRespDTO.getCurrencyRate()));
// 调整汇率计算为新的逻辑公式: 待计算原币种金额 * 目标支付币种金额基础值 / 原币种金额基础值(注:这里的币种金额基础值为后台设定的汇兑基础值) ,最终结果保留两位小数点四舍五入
totalAmount = totalAmount.add(receivableFee.multiply(rateRespDTO.getTargetCurrencyAmount()).divide(rateRespDTO.getSourceCurrencyAmount(), 2, RoundingMode.HALF_UP));
if (null != receivableBackVO.getFeeType() && receivableBackVO.getFeeType() == 1) {
totalYunfei = totalYunfei.add(receivableFee.multiply(rateRespDTO.getCurrencyRate()));
totalYunfei = totalYunfei.add(receivableFee.multiply(rateRespDTO.getTargetCurrencyAmount()).divide(rateRespDTO.getSourceCurrencyAmount(), 2, RoundingMode.HALF_UP));
}
if (null != receivableBackVO.getFeeType() && receivableBackVO.getFeeType() == 2) {
totalQingguanfei = totalQingguanfei.add(receivableFee.multiply(rateRespDTO.getCurrencyRate()));
totalQingguanfei = totalQingguanfei.add(receivableFee.multiply(rateRespDTO.getTargetCurrencyAmount()).divide(rateRespDTO.getSourceCurrencyAmount(), 2, RoundingMode.HALF_UP));
}
}
}
......@@ -1346,7 +1347,10 @@ public class OrderQueryServiceImpl implements OrderQueryService {
//重新获取汇率
ExchangeRateRespDTO rateRespDTO = currencyApi.getCurrencyRateByCode(rate.getFuhao(), "¥");
if (null != rateRespDTO && null != rateRespDTO.getCurrencyRate()) {
needTotalAmount = needTotalAmount.add(receivableFee.multiply(rateRespDTO.getCurrencyRate()).multiply(BigDecimal.valueOf(receiptDO.getWriteOffProportion().doubleValue() / 100)));
// 调整汇率计算为新的逻辑公式: 待计算原币种金额 * 目标支付币种金额基础值 / 原币种金额基础值(注:这里的币种金额基础值为后台设定的汇兑基础值) ,最终结果保留两位小数点四舍五入
needTotalAmount = needTotalAmount.add(receivableFee.multiply(rateRespDTO.getTargetCurrencyAmount().divide(rateRespDTO.getSourceCurrencyAmount(),2,RoundingMode.HALF_UP))
.divide(rateRespDTO.getSourceCurrencyAmount(), 2, RoundingMode.HALF_UP)
.multiply(BigDecimal.valueOf(receiptDO.getWriteOffProportion().doubleValue() / 100)));
}
}
......@@ -2404,7 +2408,8 @@ public class OrderQueryServiceImpl implements OrderQueryService {
receivableTotalFeeGroupDtoMap.put(freightCurrencyId, receivableSeaFreight.setScale(0, RoundingMode.HALF_UP));
}
// 总应收转换
receivableTotalFee = receivableTotalFee.add(receivableSeaFreight.multiply(freightTotalFeeRateRespDTO.getCurrencyRate()));
// 调整汇率计算为新的逻辑公式: 待计算原币种金额 * 目标支付币种金额基础值 / 原币种金额基础值(注:这里的币种金额基础值为后台设定的汇兑基础值) ,最终结果保留两位小数点四舍五入
receivableTotalFee = receivableTotalFee.add(receivableSeaFreight.multiply(freightTotalFeeRateRespDTO.getTargetCurrencyAmount()).divide(freightTotalFeeRateRespDTO.getSourceCurrencyAmount(), 2, RoundingMode.HALF_UP));
// 总实收金额
if (netReceiptsTotalFeeGroupDtoMap.containsKey(freightCurrencyId)) {
netReceiptsTotalFeeGroupDtoMap.put(freightCurrencyId, seaFreight.add(netReceiptsTotalFeeGroupDtoMap.get(freightCurrencyId)).setScale(0, RoundingMode.HALF_UP));
......@@ -2412,7 +2417,8 @@ public class OrderQueryServiceImpl implements OrderQueryService {
netReceiptsTotalFeeGroupDtoMap.put(freightCurrencyId, seaFreight.setScale(0, RoundingMode.HALF_UP));
}
// 总实收收转换
netReceiptsTotalFee = netReceiptsTotalFee.add(seaFreight.multiply(freightTotalFeeRateRespDTO.getCurrencyRate()));
// 调整汇率计算为新的逻辑公式: 待计算原币种金额 * 目标支付币种金额基础值 / 原币种金额基础值(注:这里的币种金额基础值为后台设定的汇兑基础值) ,最终结果保留两位小数点四舍五入
netReceiptsTotalFee = netReceiptsTotalFee.add(seaFreight.multiply(freightTotalFeeRateRespDTO.getTargetCurrencyAmount()).divide(freightTotalFeeRateRespDTO.getSourceCurrencyAmount(), 2, RoundingMode.HALF_UP));
// 总运费应收金额
if (totalReceivableFreightFeeGroupDtoMap.containsKey(freightCurrencyId)) {
totalReceivableFreightFeeGroupDtoMap.put(freightCurrencyId, receivableSeaFreight.add(totalReceivableFreightFeeGroupDtoMap.get(freightCurrencyId)).setScale(0, RoundingMode.HALF_UP));
......@@ -2427,8 +2433,9 @@ public class OrderQueryServiceImpl implements OrderQueryService {
totalNetReceiptsFreightFeeGroupDtoMap.put(freightCurrencyId, seaFreight.setScale(0, RoundingMode.HALF_UP));
}
// 运费的应收与实收根据目的地设置的进口运费货币汇率来转换计算
totalReceivableFreightFee = totalReceivableFreightFee.add(receivableSeaFreight.multiply(collectFreightRateRespDTO.getCurrencyRate()));
totalNetReceiptsFreightFee = totalNetReceiptsFreightFee.add(seaFreight.multiply(collectFreightRateRespDTO.getCurrencyRate()));
// 调整汇率计算为新的逻辑公式: 待计算原币种金额 * 目标支付币种金额基础值 / 原币种金额基础值(注:这里的币种金额基础值为后台设定的汇兑基础值) ,最终结果保留两位小数点四舍五入
totalReceivableFreightFee = totalReceivableFreightFee.add(receivableSeaFreight.multiply(collectFreightRateRespDTO.getTargetCurrencyAmount()).divide(collectFreightRateRespDTO.getSourceCurrencyAmount(), 2, RoundingMode.HALF_UP));
totalNetReceiptsFreightFee = totalNetReceiptsFreightFee.add(seaFreight.multiply(collectFreightRateRespDTO.getTargetCurrencyAmount()).divide(collectFreightRateRespDTO.getSourceCurrencyAmount(), 2, RoundingMode.HALF_UP));
if (orderItemDO.getCharging() == 0) {
Long clearanceCurrencyId = Long.parseLong(String.valueOf(orderItemDO.getClearanceFreightCurrency()));
......@@ -2442,7 +2449,8 @@ public class OrderQueryServiceImpl implements OrderQueryService {
receivableTotalFeeGroupDtoMap.put(clearanceCurrencyId, receivableClearanceFreight.setScale(0, RoundingMode.HALF_UP));
}
// 总应收转换
receivableTotalFee = receivableTotalFee.add(receivableClearanceFreight.multiply(clearanceTotalFeeRateRespDTO.getCurrencyRate()));
// 调整汇率计算为新的逻辑公式: 待计算原币种金额 * 目标支付币种金额基础值 / 原币种金额基础值(注:这里的币种金额基础值为后台设定的汇兑基础值) ,最终结果保留两位小数点四舍五入
receivableTotalFee = receivableTotalFee.add(receivableClearanceFreight.multiply(clearanceTotalFeeRateRespDTO.getTargetCurrencyAmount()).divide(clearanceTotalFeeRateRespDTO.getSourceCurrencyAmount(), 2, RoundingMode.HALF_UP));
// 总实收金额
if (netReceiptsTotalFeeGroupDtoMap.containsKey(clearanceCurrencyId)) {
netReceiptsTotalFeeGroupDtoMap.put(clearanceCurrencyId, clearanceFreight.add(netReceiptsTotalFeeGroupDtoMap.get(clearanceCurrencyId)).setScale(0, RoundingMode.HALF_UP));
......@@ -2450,7 +2458,8 @@ public class OrderQueryServiceImpl implements OrderQueryService {
netReceiptsTotalFeeGroupDtoMap.put(clearanceCurrencyId, clearanceFreight.setScale(0, RoundingMode.HALF_UP));
}
// 总实收收转换
netReceiptsTotalFee = netReceiptsTotalFee.add(clearanceFreight.multiply(clearanceTotalFeeRateRespDTO.getCurrencyRate()));
// 调整汇率计算为新的逻辑公式: 待计算原币种金额 * 目标支付币种金额基础值 / 原币种金额基础值(注:这里的币种金额基础值为后台设定的汇兑基础值) ,最终结果保留两位小数点四舍五入
netReceiptsTotalFee = netReceiptsTotalFee.add(clearanceFreight.multiply(clearanceTotalFeeRateRespDTO.getTargetCurrencyAmount()).divide(clearanceTotalFeeRateRespDTO.getSourceCurrencyAmount(), 2, RoundingMode.HALF_UP));
// 总清关费应收金额
if (totalReceivableClearanceFeeGroupDtoMap.containsKey(clearanceCurrencyId)) {
totalReceivableClearanceFeeGroupDtoMap.put(clearanceCurrencyId, receivableClearanceFreight.add(totalReceivableClearanceFeeGroupDtoMap.get(clearanceCurrencyId)).setScale(0, RoundingMode.HALF_UP));
......@@ -2464,8 +2473,9 @@ public class OrderQueryServiceImpl implements OrderQueryService {
totalNetReceiptsClearanceFeeGroupDtoMap.put(clearanceCurrencyId, clearanceFreight.setScale(0, RoundingMode.HALF_UP));
}
// 清关费的应收与实收转换
totalReceivableClearanceFee = totalReceivableClearanceFee.add(receivableClearanceFreight.multiply(collectClearanceRateRespDTO.getCurrencyRate()));
totalNetReceiptsClearanceFee = totalNetReceiptsClearanceFee.add(clearanceFreight.multiply(collectClearanceRateRespDTO.getCurrencyRate()));
// 调整汇率计算为新的逻辑公式: 待计算原币种金额 * 目标支付币种金额基础值 / 原币种金额基础值(注:这里的币种金额基础值为后台设定的汇兑基础值) ,最终结果保留两位小数点四舍五入
totalReceivableClearanceFee = totalReceivableClearanceFee.add(receivableClearanceFreight.multiply(collectClearanceRateRespDTO.getTargetCurrencyAmount()).divide(collectClearanceRateRespDTO.getSourceCurrencyAmount(),2,RoundingMode.HALF_UP));
totalNetReceiptsClearanceFee = totalNetReceiptsClearanceFee.add(clearanceFreight.multiply(collectClearanceRateRespDTO.getTargetCurrencyAmount()).divide(collectClearanceRateRespDTO.getSourceCurrencyAmount(),2,RoundingMode.HALF_UP));
}
}
}
......@@ -2493,7 +2503,8 @@ public class OrderQueryServiceImpl implements OrderQueryService {
} else {
netReceiptsTotalFeeGroupDtoMap.put(currencyId, discountFee.setScale(0, RoundingMode.HALF_UP).negate());
}
netReceiptsTotalFee = netReceiptsTotalFee.subtract(discountFee.multiply(totalFeeRateRespDTO.getCurrencyRate()));
// 调整汇率计算为新的逻辑公式: 待计算原币种金额 * 目标支付币种金额基础值 / 原币种金额基础值(注:这里的币种金额基础值为后台设定的汇兑基础值) ,最终结果保留两位小数点四舍五入
netReceiptsTotalFee = netReceiptsTotalFee.subtract(discountFee.multiply(totalFeeRateRespDTO.getTargetCurrencyAmount()).divide(totalFeeRateRespDTO.getSourceCurrencyAmount(),2,RoundingMode.HALF_UP));
if (receivableDO.getFeeType() == 1) {
ExchangeRateRespDTO collectFreightRateRespDTO = currencyApi.getCurrencyRate(currencyId, collectFreightFeeId);
// 总运费实收金额
......@@ -2502,7 +2513,8 @@ public class OrderQueryServiceImpl implements OrderQueryService {
} else {
totalNetReceiptsFreightFeeGroupDtoMap.put(currencyId, discountFee.setScale(0, RoundingMode.HALF_UP).negate());
}
totalNetReceiptsFreightFee = totalNetReceiptsFreightFee.subtract(discountFee.multiply(collectFreightRateRespDTO.getCurrencyRate()));
// 调整汇率计算为新的逻辑公式: 待计算原币种金额 * 目标支付币种金额基础值 / 原币种金额基础值(注:这里的币种金额基础值为后台设定的汇兑基础值) ,最终结果保留两位小数点四舍五入
totalNetReceiptsFreightFee = totalNetReceiptsFreightFee.subtract(discountFee.multiply(collectFreightRateRespDTO.getTargetCurrencyAmount()).divide(collectFreightRateRespDTO.getSourceCurrencyAmount(),2,RoundingMode.HALF_UP));
if (receivableDO.getState() == 2 && Objects.nonNull(receiptDO)) {
if (Objects.nonNull(isChina) && isChina) {
// 中国付
......@@ -2512,7 +2524,8 @@ public class OrderQueryServiceImpl implements OrderQueryService {
} else {
totalNetReceiptsAdvanceFreightFeeGroupDtoMap.put(currencyId, netReceiptsFee.setScale(0, RoundingMode.HALF_UP));
}
totalNetReceiptsAdvanceFreightFee = totalNetReceiptsAdvanceFreightFee.add(netReceiptsFee.multiply(collectFreightRateRespDTO.getCurrencyRate()));
// 调整汇率计算为新的逻辑公式: 待计算原币种金额 * 目标支付币种金额基础值 / 原币种金额基础值(注:这里的币种金额基础值为后台设定的汇兑基础值) ,最终结果保留两位小数点四舍五入
totalNetReceiptsAdvanceFreightFee = totalNetReceiptsAdvanceFreightFee.add(netReceiptsFee.multiply(collectFreightRateRespDTO.getTargetCurrencyAmount()).divide(collectFreightRateRespDTO.getSourceCurrencyAmount(),2,RoundingMode.HALF_UP));
} else {
// 国外付
// 总到付运费实收金额
......@@ -2521,7 +2534,8 @@ public class OrderQueryServiceImpl implements OrderQueryService {
} else {
totalNetReceiptsCollectFreightFeeGroupDtoMap.put(currencyId, netReceiptsFee.setScale(0, RoundingMode.HALF_UP));
}
totalNetReceiptsCollectFreightFee = totalNetReceiptsCollectFreightFee.add(netReceiptsFee.multiply(collectFreightRateRespDTO.getCurrencyRate()));
// 调整汇率计算为新的逻辑公式: 待计算原币种金额 * 目标支付币种金额基础值 / 原币种金额基础值(注:这里的币种金额基础值为后台设定的汇兑基础值) ,最终结果保留两位小数点四舍五入
totalNetReceiptsCollectFreightFee = totalNetReceiptsCollectFreightFee.add(netReceiptsFee.multiply(collectFreightRateRespDTO.getTargetCurrencyAmount()).divide(collectFreightRateRespDTO.getSourceCurrencyAmount(),2,RoundingMode.HALF_UP));
}
}
}
......@@ -2533,7 +2547,8 @@ public class OrderQueryServiceImpl implements OrderQueryService {
} else {
totalNetReceiptsClearanceFeeGroupDtoMap.put(currencyId, discountFee.setScale(0, RoundingMode.HALF_UP).negate());
}
totalNetReceiptsClearanceFee = totalNetReceiptsClearanceFee.subtract(discountFee.multiply(collectClearanceRateRespDTO.getCurrencyRate()));
// 调整汇率计算为新的逻辑公式: 待计算原币种金额 * 目标支付币种金额基础值 / 原币种金额基础值(注:这里的币种金额基础值为后台设定的汇兑基础值) ,最终结果保留两位小数点四舍五入
totalNetReceiptsClearanceFee = totalNetReceiptsClearanceFee.subtract(discountFee.multiply(collectClearanceRateRespDTO.getTargetCurrencyAmount()).divide(collectClearanceRateRespDTO.getSourceCurrencyAmount(),2,RoundingMode.HALF_UP));
if (receivableDO.getState() == 2) {
if (receivableDO.getState() == 2) {
if (Objects.nonNull(isChina) && isChina) {
......@@ -2544,7 +2559,8 @@ public class OrderQueryServiceImpl implements OrderQueryService {
} else {
totalNetReceiptsAdvanceClearanceFeeGroupDtoMap.put(currencyId, netReceiptsFee.setScale(0, RoundingMode.HALF_UP));
}
totalNetReceiptsAdvanceClearanceFee = totalNetReceiptsAdvanceClearanceFee.add(netReceiptsFee.multiply(collectClearanceRateRespDTO.getCurrencyRate()));
// 调整汇率计算为新的逻辑公式: 待计算原币种金额 * 目标支付币种金额基础值 / 原币种金额基础值(注:这里的币种金额基础值为后台设定的汇兑基础值) ,最终结果保留两位小数点四舍五入
totalNetReceiptsAdvanceClearanceFee = totalNetReceiptsAdvanceClearanceFee.add(netReceiptsFee.multiply(collectClearanceRateRespDTO.getTargetCurrencyAmount()).divide(collectClearanceRateRespDTO.getSourceCurrencyAmount(),2,RoundingMode.HALF_UP));
} else {
// 国外付
// 总到付清关费实收金额
......@@ -2553,7 +2569,8 @@ public class OrderQueryServiceImpl implements OrderQueryService {
} else {
totalNetReceiptsCollectClearanceFeeGroupDtoMap.put(currencyId, netReceiptsFee.setScale(0, RoundingMode.HALF_UP));
}
totalNetReceiptsCollectClearanceFee = totalNetReceiptsCollectClearanceFee.add(netReceiptsFee.multiply(collectClearanceRateRespDTO.getCurrencyRate()));
// 调整汇率计算为新的逻辑公式: 待计算原币种金额 * 目标支付币种金额基础值 / 原币种金额基础值(注:这里的币种金额基础值为后台设定的汇兑基础值) ,最终结果保留两位小数点四舍五入
totalNetReceiptsCollectClearanceFee = totalNetReceiptsCollectClearanceFee.add(netReceiptsFee.multiply(collectClearanceRateRespDTO.getTargetCurrencyAmount()).divide(collectClearanceRateRespDTO.getSourceCurrencyAmount(),2,RoundingMode.HALF_UP));
}
}
}
......@@ -2567,21 +2584,24 @@ public class OrderQueryServiceImpl implements OrderQueryService {
} else {
totalReceivableOtherFeeGroupDtoMap.put(currencyId, receivableFee.setScale(0, RoundingMode.HALF_UP));
}
totalReceivableOtherFee = totalReceivableOtherFee.add(receivableFee.multiply(collectOtherRateRespDTO.getCurrencyRate()));
// 调整汇率计算为新的逻辑公式: 待计算原币种金额 * 目标支付币种金额基础值 / 原币种金额基础值(注:这里的币种金额基础值为后台设定的汇兑基础值) ,最终结果保留两位小数点四舍五入
totalReceivableOtherFee = totalReceivableOtherFee.add(receivableFee.multiply(collectOtherRateRespDTO.getTargetCurrencyAmount()).divide(collectOtherRateRespDTO.getSourceCurrencyAmount(),2,RoundingMode.HALF_UP));
// 实收额外费用
if (totalNetReceiptsOtherFeeGroupDtoMap.containsKey(currencyId)) {
totalNetReceiptsOtherFeeGroupDtoMap.put(currencyId, netReceiptsFee.add(totalNetReceiptsOtherFeeGroupDtoMap.get(currencyId)).setScale(0, RoundingMode.HALF_UP));
} else {
totalNetReceiptsOtherFeeGroupDtoMap.put(currencyId, netReceiptsFee.setScale(0, RoundingMode.HALF_UP));
}
totalNetReceiptsOtherFee = totalNetReceiptsOtherFee.add(netReceiptsFee.multiply(collectOtherRateRespDTO.getCurrencyRate()));
// 调整汇率计算为新的逻辑公式: 待计算原币种金额 * 目标支付币种金额基础值 / 原币种金额基础值(注:这里的币种金额基础值为后台设定的汇兑基础值) ,最终结果保留两位小数点四舍五入
totalNetReceiptsOtherFee = totalNetReceiptsOtherFee.add(netReceiptsFee.multiply(collectOtherRateRespDTO.getTargetCurrencyAmount()).divide(collectOtherRateRespDTO.getSourceCurrencyAmount(),2,RoundingMode.HALF_UP));
// 总应收金额
if (receivableTotalFeeGroupDtoMap.containsKey(currencyId)) {
receivableTotalFeeGroupDtoMap.put(currencyId, receivableFee.add(receivableTotalFeeGroupDtoMap.get(currencyId)).setScale(0, RoundingMode.HALF_UP));
} else {
receivableTotalFeeGroupDtoMap.put(currencyId, receivableFee.setScale(0, RoundingMode.HALF_UP));
}
receivableTotalFee = receivableTotalFee.add(receivableFee.multiply(totalFeeRateRespDTO.getCurrencyRate()));
// 调整汇率计算为新的逻辑公式: 待计算原币种金额 * 目标支付币种金额基础值 / 原币种金额基础值(注:这里的币种金额基础值为后台设定的汇兑基础值) ,最终结果保留两位小数点四舍五入
receivableTotalFee = receivableTotalFee.add(receivableFee.multiply(totalFeeRateRespDTO.getTargetCurrencyAmount()).divide(totalFeeRateRespDTO.getSourceCurrencyAmount(),2,RoundingMode.HALF_UP));
// 总实收金额
if (netReceiptsTotalFeeGroupDtoMap.containsKey(currencyId)) {
netReceiptsTotalFeeGroupDtoMap.put(currencyId, netReceiptsFee.add(netReceiptsTotalFeeGroupDtoMap.get(currencyId)).setScale(0, RoundingMode.HALF_UP));
......@@ -2589,7 +2609,8 @@ public class OrderQueryServiceImpl implements OrderQueryService {
netReceiptsTotalFeeGroupDtoMap.put(currencyId, netReceiptsFee.setScale(0, RoundingMode.HALF_UP));
}
// 总实收收转换
netReceiptsTotalFee = netReceiptsTotalFee.add(netReceiptsFee.multiply(totalFeeRateRespDTO.getCurrencyRate()));
// 调整汇率计算为新的逻辑公式: 待计算原币种金额 * 目标支付币种金额基础值 / 原币种金额基础值(注:这里的币种金额基础值为后台设定的汇兑基础值) ,最终结果保留两位小数点四舍五入
netReceiptsTotalFee = netReceiptsTotalFee.add(netReceiptsFee.multiply(totalFeeRateRespDTO.getTargetCurrencyAmount()).divide(totalFeeRateRespDTO.getSourceCurrencyAmount(),2,RoundingMode.HALF_UP));
if (receivableDO.getState() == 2) {
if (Objects.nonNull(isChina) && isChina) {
// 中国付
......@@ -2602,13 +2623,15 @@ public class OrderQueryServiceImpl implements OrderQueryService {
}
if (!Objects.equals(currencyId, collectOtherFeeId)) {
ExchangeRateRespDTO otherRateRespDTO = currencyApi.getCurrencyRate(currencyId, collectOtherFeeId);
totalNetReceiptsAdvanceOtherFee = totalNetReceiptsAdvanceOtherFee.add(netReceiptsFee.multiply(otherRateRespDTO.getCurrencyRate()));
// 调整汇率计算为新的逻辑公式: 待计算原币种金额 * 目标支付币种金额基础值 / 原币种金额基础值(注:这里的币种金额基础值为后台设定的汇兑基础值) ,最终结果保留两位小数点四舍五入
totalNetReceiptsAdvanceOtherFee = totalNetReceiptsAdvanceOtherFee.add(netReceiptsFee.multiply(otherRateRespDTO.getTargetCurrencyAmount()).divide(otherRateRespDTO.getSourceCurrencyAmount(),2,RoundingMode.HALF_UP));
} else {
totalNetReceiptsAdvanceOtherFee = totalNetReceiptsAdvanceOtherFee.add(netReceiptsFee);
}
if (!Objects.equals(currencyId, collectAssistantOtherFeeId)) {
ExchangeRateRespDTO assistantOtherRateRespDTO = currencyApi.getCurrencyRate(currencyId, collectAssistantOtherFeeId);
totalNetReceiptsAdvanceAssistantOtherFee = totalNetReceiptsAdvanceAssistantOtherFee.add(netReceiptsFee.multiply(assistantOtherRateRespDTO.getCurrencyRate()));
// 调整汇率计算为新的逻辑公式: 待计算原币种金额 * 目标支付币种金额基础值 / 原币种金额基础值(注:这里的币种金额基础值为后台设定的汇兑基础值) ,最终结果保留两位小数点四舍五入
totalNetReceiptsAdvanceAssistantOtherFee = totalNetReceiptsAdvanceAssistantOtherFee.add(netReceiptsFee.multiply(assistantOtherRateRespDTO.getTargetCurrencyAmount()).divide(assistantOtherRateRespDTO.getSourceCurrencyAmount(),2,RoundingMode.HALF_UP));
} else {
totalNetReceiptsAdvanceAssistantOtherFee = totalNetReceiptsAdvanceAssistantOtherFee.add(netReceiptsFee);
}
......@@ -2622,13 +2645,15 @@ public class OrderQueryServiceImpl implements OrderQueryService {
}
if (!Objects.equals(currencyId, collectOtherFeeId)) {
ExchangeRateRespDTO otherRateRespDTO = currencyApi.getCurrencyRate(currencyId, collectOtherFeeId);
totalNetReceiptsCollectOtherFee = totalNetReceiptsCollectOtherFee.add(netReceiptsFee.multiply(otherRateRespDTO.getCurrencyRate()));
// 调整汇率计算为新的逻辑公式: 待计算原币种金额 * 目标支付币种金额基础值 / 原币种金额基础值(注:这里的币种金额基础值为后台设定的汇兑基础值) ,最终结果保留两位小数点四舍五入
totalNetReceiptsCollectOtherFee = totalNetReceiptsCollectOtherFee.add(netReceiptsFee.multiply(otherRateRespDTO.getTargetCurrencyAmount()).divide(otherRateRespDTO.getSourceCurrencyAmount(),2,RoundingMode.HALF_UP));
} else {
totalNetReceiptsCollectOtherFee = totalNetReceiptsCollectOtherFee.add(netReceiptsFee);
}
if (!Objects.equals(currencyId, collectAssistantOtherFeeId)) {
ExchangeRateRespDTO assistantOtherRateRespDTO = currencyApi.getCurrencyRate(currencyId, collectAssistantOtherFeeId);
totalNetReceiptsCollectAssistantOtherFee = totalNetReceiptsCollectAssistantOtherFee.add(netReceiptsFee.multiply(assistantOtherRateRespDTO.getCurrencyRate()));
// 调整汇率计算为新的逻辑公式: 待计算原币种金额 * 目标支付币种金额基础值 / 原币种金额基础值(注:这里的币种金额基础值为后台设定的汇兑基础值) ,最终结果保留两位小数点四舍五入
totalNetReceiptsCollectAssistantOtherFee = totalNetReceiptsCollectAssistantOtherFee.add(netReceiptsFee.multiply(assistantOtherRateRespDTO.getTargetCurrencyAmount()).divide(assistantOtherRateRespDTO.getSourceCurrencyAmount(),2,RoundingMode.HALF_UP));
} else {
totalNetReceiptsCollectAssistantOtherFee = totalNetReceiptsCollectAssistantOtherFee.add(netReceiptsFee);
}
......@@ -2673,17 +2698,13 @@ public class OrderQueryServiceImpl implements OrderQueryService {
// 订单总金额应收分组
StringBuilder receivableTotalFeeGroup = new StringBuilder();
List<FeeGroupDto> receivableTotalFeeGroupDtoList = new ArrayList<>();
this.
convertFeeGroup(currencyRespDTOMap, receivableTotalFeeGroupDtoMap, receivableTotalFeeGroupDtoList, receivableTotalFeeGroup);
this.convertFeeGroup(currencyRespDTOMap, receivableTotalFeeGroupDtoMap, receivableTotalFeeGroupDtoList, receivableTotalFeeGroup);
summaryDto.setReceivableTotalFeeGroupDtoList(receivableTotalFeeGroupDtoList);
summaryDto.setReceivableTotalFeeGroup(receivableTotalFeeGroup.toString());
// 订单总金额实收分组
StringBuilder netReceiptsTotalFeeGroup = new StringBuilder();
List<FeeGroupDto> netReceiptsTotalFeeGroupDtoList = new ArrayList<>();
this.
convertFeeGroup(currencyRespDTOMap, netReceiptsTotalFeeGroupDtoMap, netReceiptsTotalFeeGroupDtoList, netReceiptsTotalFeeGroup);
this.convertFeeGroup(currencyRespDTOMap, netReceiptsTotalFeeGroupDtoMap, netReceiptsTotalFeeGroupDtoList, netReceiptsTotalFeeGroup);
summaryDto.setNetReceiptsTotalFeeGroupDtoList(netReceiptsTotalFeeGroupDtoList);
summaryDto.setNetReceiptsTotalFeeGroup(netReceiptsTotalFeeGroup.toString());
// 订单总优惠分组
......@@ -2932,6 +2953,8 @@ public class OrderQueryServiceImpl implements OrderQueryService {
freightExchangeRateRespDTO.setTargetCurrencyId(1L);
freightExchangeRateRespDTO.setTargetCurrencyCode("$");
freightExchangeRateRespDTO.setCurrencyRate(new BigDecimal("1"));//美元兑美元,默认1:1
freightExchangeRateRespDTO.setSourceCurrencyAmount(new BigDecimal("1"));//美元兑美元,默认1:1
freightExchangeRateRespDTO.setTargetCurrencyAmount(new BigDecimal("1"));//美元兑美元,默认1:1
}
if (Objects.isNull(clearanceExchangeRateRespDTO)) {
clearanceExchangeRateRespDTO = new ExchangeRateRespDTO();
......@@ -2940,6 +2963,8 @@ public class OrderQueryServiceImpl implements OrderQueryService {
clearanceExchangeRateRespDTO.setTargetCurrencyId(1L);
clearanceExchangeRateRespDTO.setTargetCurrencyCode("$");
clearanceExchangeRateRespDTO.setCurrencyRate(new BigDecimal("1"));//美元兑美元,默认1:1
clearanceExchangeRateRespDTO.setSourceCurrencyAmount(new BigDecimal("1"));//美元兑美元,默认1:1
clearanceExchangeRateRespDTO.setTargetCurrencyAmount(new BigDecimal("1"));//美元兑美元,默认1:1
}
chargeVolume = chargeVolume.add(orderItemBackVO.getChargeVolume().compareTo(orderItemBackVO.getMinMeteringVolume()) < 0 ?
orderItemBackVO.getMinMeteringVolume() : orderItemBackVO.getChargeVolume());
......@@ -2973,10 +2998,10 @@ public class OrderQueryServiceImpl implements OrderQueryService {
if (allCurrencyIds.size() > 1) {
// 当所有费用的货币不统一时,总的优惠金额需要统一转换成美元来累加处理
// 该订单下清关费多种货币,需要统一转换成美元来累加处理
BigDecimal freightReceivableFee = receivableSeaFreight.multiply(freightExchangeRateRespDTO.getCurrencyRate()).setScale(0, RoundingMode.HALF_UP);
BigDecimal freightNetReceiptsFee = seaFreight.multiply(freightExchangeRateRespDTO.getCurrencyRate()).setScale(0, RoundingMode.HALF_UP);
BigDecimal clearanceReceivableFee = receivableClearanceFreight.multiply(clearanceExchangeRateRespDTO.getCurrencyRate()).setScale(0, RoundingMode.HALF_UP);
BigDecimal clearanceNetReceiptsFee = clearanceFreight.multiply(clearanceExchangeRateRespDTO.getCurrencyRate()).setScale(0, RoundingMode.HALF_UP);
BigDecimal freightReceivableFee = receivableSeaFreight.multiply(freightExchangeRateRespDTO.getTargetCurrencyAmount()).divide(freightExchangeRateRespDTO.getSourceCurrencyAmount(),0, RoundingMode.HALF_UP);
BigDecimal freightNetReceiptsFee = seaFreight.multiply(freightExchangeRateRespDTO.getTargetCurrencyAmount()).divide(freightExchangeRateRespDTO.getSourceCurrencyAmount(),0, RoundingMode.HALF_UP);
BigDecimal clearanceReceivableFee = receivableClearanceFreight.multiply(clearanceExchangeRateRespDTO.getTargetCurrencyAmount()).divide(clearanceExchangeRateRespDTO.getSourceCurrencyAmount(),0, RoundingMode.HALF_UP);
BigDecimal clearanceNetReceiptsFee = clearanceFreight.multiply(clearanceExchangeRateRespDTO.getTargetCurrencyAmount()).divide(clearanceExchangeRateRespDTO.getSourceCurrencyAmount(),0, RoundingMode.HALF_UP);
receivableTotalAmount = receivableTotalAmount.add(freightReceivableFee).add(clearanceReceivableFee);
netReceiptsTotalAmount = netReceiptsTotalAmount.add(freightNetReceiptsFee).add(clearanceNetReceiptsFee);
} else {
......@@ -3042,11 +3067,11 @@ public class OrderQueryServiceImpl implements OrderQueryService {
// 该订单下运费多种货币,需要统一转换成美元来累加处理
if (isWarehouseIn) {
// 入仓的品名才计算实收
BigDecimal receivableFee = orderItemBackVO.getReceivableSeaFreight().multiply(clearanceExchangeRateRespDTO.getCurrencyRate()).setScale(0, RoundingMode.HALF_UP);
BigDecimal receivableFee = orderItemBackVO.getReceivableSeaFreight().multiply(clearanceExchangeRateRespDTO.getTargetCurrencyAmount()).divide(clearanceExchangeRateRespDTO.getSourceCurrencyAmount(),0, RoundingMode.HALF_UP);
totalReceivableFreightFee = totalReceivableFreightFee.add(receivableFee).setScale(0, RoundingMode.HALF_UP);
BigDecimal fee = orderItemBackVO.getSeaFreight().multiply(clearanceExchangeRateRespDTO.getCurrencyRate()).setScale(0, RoundingMode.HALF_UP);
BigDecimal fee = orderItemBackVO.getSeaFreight().multiply(clearanceExchangeRateRespDTO.getTargetCurrencyAmount()).divide(clearanceExchangeRateRespDTO.getSourceCurrencyAmount(),0, RoundingMode.HALF_UP);
totalNetReceiptsFreightFee = totalNetReceiptsFreightFee.add(fee);
BigDecimal discountFee = orderItemBackVO.getDiscountFreightTotalPrice().multiply(freightExchangeRateRespDTO.getCurrencyRate()).setScale(0, RoundingMode.HALF_UP);
BigDecimal discountFee = orderItemBackVO.getDiscountFreightTotalPrice().multiply(freightExchangeRateRespDTO.getTargetCurrencyAmount()).divide(freightExchangeRateRespDTO.getSourceCurrencyAmount(),0, RoundingMode.HALF_UP);
totalDiscountFreightFee = totalDiscountFreightFee.add(discountFee).setScale(0, RoundingMode.HALF_UP);
}
......@@ -3065,11 +3090,11 @@ public class OrderQueryServiceImpl implements OrderQueryService {
// 该订单下清关费多种货币,需要统一转换成美元来累加处理
if (isWarehouseIn) {
// 入仓的品名才计算实收
BigDecimal receivableFee = orderItemBackVO.getReceivableClearanceFreight().multiply(clearanceExchangeRateRespDTO.getCurrencyRate()).setScale(0, RoundingMode.HALF_UP);
BigDecimal receivableFee = orderItemBackVO.getReceivableClearanceFreight().multiply(clearanceExchangeRateRespDTO.getTargetCurrencyAmount()).divide(clearanceExchangeRateRespDTO.getSourceCurrencyAmount(),0, RoundingMode.HALF_UP);
totalReceivableClearanceFee = totalReceivableClearanceFee.add(receivableFee).setScale(0, RoundingMode.HALF_UP);
BigDecimal fee = orderItemBackVO.getClearanceFreight().multiply(clearanceExchangeRateRespDTO.getCurrencyRate()).setScale(0, RoundingMode.HALF_UP);
BigDecimal fee = orderItemBackVO.getClearanceFreight().multiply(clearanceExchangeRateRespDTO.getTargetCurrencyAmount()).divide(clearanceExchangeRateRespDTO.getSourceCurrencyAmount(),0, RoundingMode.HALF_UP);
totalNetReceiptsClearanceFee = totalNetReceiptsClearanceFee.add(fee).setScale(0, RoundingMode.HALF_UP);
BigDecimal discountFee = orderItemBackVO.getDiscountClearanceFeeTotalPrice().multiply(clearanceExchangeRateRespDTO.getCurrencyRate()).setScale(0, RoundingMode.HALF_UP);
BigDecimal discountFee = orderItemBackVO.getDiscountClearanceFeeTotalPrice().multiply(clearanceExchangeRateRespDTO.getTargetCurrencyAmount()).divide(clearanceExchangeRateRespDTO.getSourceCurrencyAmount(),0, RoundingMode.HALF_UP);
totalDiscountClearanceFee = totalDiscountClearanceFee.add(discountFee).setScale(0, RoundingMode.HALF_UP);
}
} else {
......@@ -3136,11 +3161,13 @@ public class OrderQueryServiceImpl implements OrderQueryService {
exchangeRateRespDTO.setTargetCurrencyId(1L);
exchangeRateRespDTO.setTargetCurrencyCode("$");
exchangeRateRespDTO.setCurrencyRate(new BigDecimal("1"));//美元兑美元,默认1:1
exchangeRateRespDTO.setTargetCurrencyAmount(new BigDecimal("1"));//美元兑美元,默认1:1
exchangeRateRespDTO.setSourceCurrencyAmount(new BigDecimal("1"));//美元兑美元,默认1:1
}
if (allCurrencyIds.size() > 1) {
// 该订单下运费多种货币,需要统一转换成美元来累加处理
BigDecimal fee = netReceiptsFee.multiply(exchangeRateRespDTO.getCurrencyRate()).setScale(0, RoundingMode.HALF_UP);
BigDecimal fee = netReceiptsFee.multiply(exchangeRateRespDTO.getTargetCurrencyAmount()).divide(exchangeRateRespDTO.getSourceCurrencyAmount(),0, RoundingMode.HALF_UP);
if (receivableDO.getState() == 1) {
// 核销中的金额计算
writeOffAmount = writeOffAmount.add(fee.multiply(writeOffProportion));
......@@ -3151,11 +3178,11 @@ public class OrderQueryServiceImpl implements OrderQueryService {
// 所有费用的货币id不统一,则计算所有费用的数据时
if (receivableDO.getFeeSource() == 1 && (receivableDO.getFeeType() == 1 || receivableDO.getFeeType() == 2)) {
// 运费和清关费的应收只需要将总实收减去收款单可能的优惠
netReceiptsTotalAmount = netReceiptsTotalAmount.subtract(discountFee.multiply(exchangeRateRespDTO.getCurrencyRate()).setScale(0, RoundingMode.HALF_UP));
netReceiptsTotalAmount = netReceiptsTotalAmount.subtract(discountFee.multiply(exchangeRateRespDTO.getTargetCurrencyAmount()).divide(exchangeRateRespDTO.getSourceCurrencyAmount(),0, RoundingMode.HALF_UP));
} else {
// 额外费用的应收需要累加到总应收和实收中
receivableTotalAmount = receivableTotalAmount.add(receivableFee.multiply(exchangeRateRespDTO.getCurrencyRate()).setScale(0, RoundingMode.HALF_UP));
netReceiptsTotalAmount = netReceiptsTotalAmount.add(netReceiptsFee.multiply(exchangeRateRespDTO.getCurrencyRate()).setScale(0, RoundingMode.HALF_UP));
receivableTotalAmount = receivableTotalAmount.add(receivableFee.multiply(exchangeRateRespDTO.getTargetCurrencyAmount()).divide(exchangeRateRespDTO.getSourceCurrencyAmount(),0, RoundingMode.HALF_UP));
netReceiptsTotalAmount = netReceiptsTotalAmount.add(netReceiptsFee.multiply(exchangeRateRespDTO.getTargetCurrencyAmount()).divide(exchangeRateRespDTO.getSourceCurrencyAmount(),0, RoundingMode.HALF_UP));
}
} else {
// 该订单下费用单一货币,不需要转换汇率,直接累加
......@@ -3224,7 +3251,7 @@ public class OrderQueryServiceImpl implements OrderQueryService {
//}
if (seaFreightCurrencyIds.size() > 1) {
// 该订单下运费多种货币,需要统一转换成美元来累加处理,实收运费减去收款单的优惠金额
totalNetReceiptsFreightFee = totalNetReceiptsFreightFee.subtract(discountFee.multiply(exchangeRateRespDTO.getCurrencyRate()).setScale(0, RoundingMode.HALF_UP));
totalNetReceiptsFreightFee = totalNetReceiptsFreightFee.subtract(discountFee.multiply(exchangeRateRespDTO.getTargetCurrencyAmount()).divide(exchangeRateRespDTO.getSourceCurrencyAmount(),0, RoundingMode.HALF_UP));
} else {
// 该订单下运费单一货币,不需要转换汇率,实收运费减去收款单的优惠金额
totalNetReceiptsFreightFee = totalNetReceiptsFreightFee.subtract(discountFee);
......@@ -3269,7 +3296,7 @@ public class OrderQueryServiceImpl implements OrderQueryService {
// 清关费实收
if (clearanceFreightCurrencyIds.size() > 1) {
// 该订单下清关多种货币,需要统一转换成美元来累加处理,实收金额直接减去收款单优惠
totalNetReceiptsClearanceFee = totalNetReceiptsClearanceFee.subtract(discountFee.multiply(exchangeRateRespDTO.getCurrencyRate()).setScale(0, RoundingMode.HALF_UP));
totalNetReceiptsClearanceFee = totalNetReceiptsClearanceFee.subtract(discountFee.multiply(exchangeRateRespDTO.getTargetCurrencyAmount()).divide(exchangeRateRespDTO.getSourceCurrencyAmount(),0, RoundingMode.HALF_UP));
} else {
// 该订单下清关费单一货币,不需要转换汇率,实收金额直接减去收款单优惠
totalNetReceiptsClearanceFee = totalNetReceiptsClearanceFee.subtract(discountFee);
......@@ -3339,8 +3366,8 @@ public class OrderQueryServiceImpl implements OrderQueryService {
// TODO 额外费用的实收金额是否需要累加,这里的实收额外费用是不减收款单优惠的金额
if (otherCurrencyIds.size() > 1) {
// 该订单下其他费用多种货币,需要统一转换成美元来累加处理
totalReceivableOtherFee = totalReceivableOtherFee.add(receivableFee.multiply(exchangeRateRespDTO.getCurrencyRate()).setScale(0, RoundingMode.HALF_UP));
BigDecimal fee = netReceiptsFee.multiply(exchangeRateRespDTO.getCurrencyRate()).setScale(0, RoundingMode.HALF_UP);
totalReceivableOtherFee = totalReceivableOtherFee.add(receivableFee.multiply(exchangeRateRespDTO.getTargetCurrencyAmount()).divide(exchangeRateRespDTO.getSourceCurrencyAmount(),0, RoundingMode.HALF_UP));
BigDecimal fee = netReceiptsFee.multiply(exchangeRateRespDTO.getTargetCurrencyAmount()).divide(exchangeRateRespDTO.getSourceCurrencyAmount(),0, RoundingMode.HALF_UP);
totalNetReceiptsOtherFee = totalNetReceiptsOtherFee.add(fee);
} else {
// 该订单下其他费用单一货币,不需要转换汇率,直接累加
......
......@@ -471,7 +471,7 @@ public class ProdCostCalculation {
if (costDto.getTotalWorth().compareTo(BigDecimal.ZERO) > 0) {
// 因为货值为RMB计算,保价费应换算为目标货币(默认为美元)
BigDecimal insuranceFee = costDto.getTotalWorth().multiply(new BigDecimal("1.1"))
.multiply(new BigDecimal("0.002")).multiply(exchangeRateRespDTO.getCurrencyRate()).setScale(0, RoundingMode.HALF_UP);
.multiply(new BigDecimal("0.002")).multiply(exchangeRateRespDTO.getTargetCurrencyAmount()).divide(exchangeRateRespDTO.getSourceCurrencyAmount(),0, RoundingMode.HALF_UP);
costDto.setInsuranceFee(insuranceFee);
feeDto.setAmount(insuranceFee);
} else {
......@@ -1582,9 +1582,9 @@ public class ProdCostCalculation {
if (Objects.nonNull(priceStepDO)) {
BigDecimal productClearancePrice =
productExchangeRate.getCurrencyRate().
multiply(priceStepDO.getClearancePrice()).
setScale(2, BigDecimal.ROUND_HALF_UP);
priceStepDO.getClearancePrice().
multiply(productExchangeRate.getTargetCurrencyAmount()).
divide(productExchangeRate.getSourceCurrencyAmount(),2, BigDecimal.ROUND_HALF_UP);
if (lineClearanceBasePrice.getClearancePrice().
compareTo(BigDecimal.ZERO) > 0) {
......@@ -1634,9 +1634,9 @@ public class ProdCostCalculation {
clearanceBasePrice.getClearancePriceUnit(),
1L);
BigDecimal productClearancePrice =
productExchangeRate.getCurrencyRate().
multiply(clearanceBasePrice.getClearancePrice()).
setScale(2,
clearanceBasePrice.getClearancePrice().
multiply(productExchangeRate.getTargetCurrencyAmount()).
divide(productExchangeRate.getSourceCurrencyAmount(),2,
BigDecimal.ROUND_HALF_UP);
BigDecimal lineClearancePrice =
lineClearanceBasePrice.getProductClearanceAsExchangePrice();
......
......@@ -1196,11 +1196,13 @@ public class CouponServiceImpl extends AbstractService<CouponMapper, CouponDO> i
freightRateRespDTO.setSourceCurrencyId(dto.getReduceCurrencyId().longValue());
freightRateRespDTO.setTargetCurrencyId(rmbCurrency.longValue());
freightRateRespDTO.setCurrencyRate(new BigDecimal("1"));
freightRateRespDTO.setSourceCurrencyAmount(new BigDecimal("1"));
freightRateRespDTO.setTargetCurrencyAmount(new BigDecimal("1"));
}
}
BigDecimal freightRMBReduceAmount = dto.getReduceAmount().compareTo(BigDecimal.ZERO) > 0 && Objects.nonNull(dto.getReduceCurrencyId()) &&
Objects.nonNull(freightRateRespDTO.getCurrencyRate()) && freightRateRespDTO.getCurrencyRate().compareTo(BigDecimal.ZERO) > 0 ?
dto.getReduceAmount().multiply(freightRateRespDTO.getCurrencyRate()).setScale(2, RoundingMode.HALF_UP) : BigDecimal.ZERO;
dto.getReduceAmount().multiply(freightRateRespDTO.getTargetCurrencyAmount()).divide(freightRateRespDTO.getSourceCurrencyAmount(),2, RoundingMode.HALF_UP) : BigDecimal.ZERO;
ExchangeRateRespDTO clearanceFeeRateRespDTO = new ExchangeRateRespDTO();
if (Objects.nonNull(dto.getClearanceReduceCurrencyId())) {
clearanceFeeRateRespDTO = currencyApi.getCurrencyRate(dto.getClearanceReduceCurrencyId().longValue(), rmbCurrency.longValue());
......@@ -1210,11 +1212,13 @@ public class CouponServiceImpl extends AbstractService<CouponMapper, CouponDO> i
clearanceFeeRateRespDTO.setSourceCurrencyId(rmbCurrency.longValue());
clearanceFeeRateRespDTO.setTargetCurrencyId(rmbCurrency.longValue());
clearanceFeeRateRespDTO.setCurrencyRate(new BigDecimal("1"));
clearanceFeeRateRespDTO.setSourceCurrencyAmount(new BigDecimal("1"));
clearanceFeeRateRespDTO.setTargetCurrencyAmount(new BigDecimal("1"));
}
}
BigDecimal clearanceFeeRMBReduceAmount = dto.getClearanceReduceAmount().compareTo(BigDecimal.ZERO) > 0 && Objects.nonNull(dto.getClearanceReduceCurrencyId()) &&
Objects.nonNull(clearanceFeeRateRespDTO.getCurrencyRate()) && clearanceFeeRateRespDTO.getCurrencyRate().compareTo(BigDecimal.ZERO) > 0 ?
dto.getClearanceReduceAmount().multiply(clearanceFeeRateRespDTO.getCurrencyRate()).setScale(2, RoundingMode.HALF_UP) : BigDecimal.ZERO;
dto.getClearanceReduceAmount().multiply(clearanceFeeRateRespDTO.getTargetCurrencyAmount()).divide(clearanceFeeRateRespDTO.getSourceCurrencyAmount(),2, RoundingMode.HALF_UP) : BigDecimal.ZERO;
dto.setTotalRMBReduceAmount(freightRMBReduceAmount.add(clearanceFeeRMBReduceAmount));
// 封装优惠详情
CouponInfoVO infoVO = new CouponInfoVO();
......
......@@ -2369,9 +2369,9 @@ public class ProductPriceServiceImpl extends AbstractService<ProductPriceMapper,
int result = 0;
if (productPrice.getClearancePriceUnit() != channelPrice.getClearancePriceUnit()) {
ExchangeRateRespDTO productExchangeRate = currencyApi.getCurrencyRate(productPrice.getClearancePriceUnit(), 1L);
BigDecimal productClearancePrice = productExchangeRate.getCurrencyRate().multiply(productPrice.getClearancePrice()).setScale(2, BigDecimal.ROUND_HALF_UP);
BigDecimal productClearancePrice = productPrice.getClearancePrice().multiply(productExchangeRate.getTargetCurrencyAmount()).divide(productExchangeRate.getSourceCurrencyAmount(),2, BigDecimal.ROUND_HALF_UP);
ExchangeRateRespDTO channelExchangeRate = currencyApi.getCurrencyRate(channelPrice.getClearancePriceUnit(), 1L);
BigDecimal channelClearancePrice = channelExchangeRate.getCurrencyRate().multiply(channelPrice.getClearancePrice()).setScale(2, BigDecimal.ROUND_HALF_UP);
BigDecimal channelClearancePrice = channelPrice.getClearancePrice().multiply(channelExchangeRate.getTargetCurrencyAmount()).divide(channelExchangeRate.getSourceCurrencyAmount(),2, BigDecimal.ROUND_HALF_UP);
result = productClearancePrice.compareTo(channelClearancePrice);
} else {
result = productPrice.getClearancePrice().compareTo(channelPrice.getClearancePrice());
......
......@@ -522,7 +522,7 @@ public class AirBillReceivableExcelExportListener {
private BigDecimal changeAmountToDestCurrency(Long fromCurrencyId,Long toCurrencyId,BigDecimal fromAmount){
BigDecimal destAmount = BigDecimal.ZERO;
ExchangeRateRespDTO currencyRate = currencyApi.getCurrencyRate(fromCurrencyId, toCurrencyId);
destAmount = fromAmount.multiply(currencyRate.getCurrencyRate());
destAmount = fromAmount.multiply(currencyRate.getTargetCurrencyAmount()).divide(currencyRate.getSourceCurrencyAmount(),2,RoundingMode.HALF_UP);
return destAmount;
}
......
......@@ -631,7 +631,7 @@ public class ShipmentReceivableExcelExportListener2 {
BigDecimal fromAmount) {
BigDecimal destAmount = BigDecimal.ZERO;
ExchangeRateRespDTO currencyRate = currencyApi.getCurrencyRate(fromCurrencyId, toCurrencyId);
destAmount = fromAmount.multiply(currencyRate.getCurrencyRate());
destAmount = fromAmount.multiply(currencyRate.getTargetCurrencyAmount()).divide(currencyRate.getSourceCurrencyAmount(),2,RoundingMode.HALF_UP);
return destAmount;
}
......
......@@ -1338,7 +1338,7 @@ public class MakeBillOfLadingServiceImpl extends AbstractService<MakeBillOfLadin
private BigDecimal changeAmountToDestCurrency(Long fromCurrencyId, Long toCurrencyId, BigDecimal fromAmount) {
BigDecimal destAmount = BigDecimal.ZERO;
ExchangeRateRespDTO currencyRate = currencyApi.getCurrencyRate(fromCurrencyId, toCurrencyId);
destAmount = fromAmount.multiply(currencyRate.getCurrencyRate());
destAmount = fromAmount.multiply(currencyRate.getTargetCurrencyAmount()).divide(currencyRate.getSourceCurrencyAmount(),2,RoundingMode.HALF_UP);
return destAmount;
}
}
......@@ -53,6 +53,7 @@ import javax.servlet.ServletOutputStream;
import javax.servlet.http.HttpServletResponse;
import javax.validation.Valid;
import java.math.BigDecimal;
import java.math.RoundingMode;
import java.net.URLEncoder;
import java.util.Collection;
import java.util.HashMap;
......@@ -573,7 +574,7 @@ public class ReceiptController {
} else {
if (StrUtil.isNotBlank(currencyRespDTO.getFuhao())) {
ExchangeRateRespDTO exchangeRateRespDTO = currencyApi.getCurrencyRateByCode(currencyRespDTO.getFuhao(), "$");
usdTotal = usdTotal.add(receivableBackVO.getTotalAmount().multiply(exchangeRateRespDTO.getCurrencyRate()));
usdTotal = usdTotal.add(receivableBackVO.getTotalAmount().multiply(exchangeRateRespDTO.getTargetCurrencyAmount()).divide(exchangeRateRespDTO.getSourceCurrencyAmount(),2, RoundingMode.HALF_UP));
}
}
......@@ -606,7 +607,7 @@ public class ReceiptController {
if (StrUtil.isNotBlank(currencyRespDTO.getFuhao())) {
ExchangeRateRespDTO exchangeRateRespDTO = currencyApi.getCurrencyRateByCode(currencyRespDTO.getFuhao(), "$");
usdTotal = usdTotal.add(receivableBackVO.getTotalAmount().multiply(exchangeRateRespDTO.getCurrencyRate()));
usdTotal = usdTotal.add(receivableBackVO.getTotalAmount().multiply(exchangeRateRespDTO.getTargetCurrencyAmount()).divide(exchangeRateRespDTO.getSourceCurrencyAmount(),2,RoundingMode.HALF_UP));
}
}
......
......@@ -861,6 +861,10 @@ currency.rate.exists=currency rate exists
currency.rate.not.exists=currency rate not exists
currency.rate.disable=Currency {} Exchange rate for currency {} has expired, please reset
currency.rate.to.not.exists=Currency {} Exchange rate for currency {} not exists
currency.rate.too.small=currency rate too small
currency.rate.amount.invalid=currency amount must be greater than 0
currency.rate.countries.invalid=currency rate countries invalid
currency.rate.pair.invalid=currency rate parties must not be identical
not.find.dest.region=Destination information not found
dest.region.freight.currency.not.null=Destination [{}] cannot find freight related currency settings
......
......@@ -861,7 +861,10 @@ currency.rate.exists=Le taux de change existe
currency.rate.not.exists=Le taux de change introuvable
currency.rate.disable=Le taux de change de la devise {} vers {} est expir\u00E9, veuillez le r\u00E9initialiser
currency.rate.to.not.exists=Le taux de change de la devise {} vers {} est introuvable
currency.rate.too.small=Taux de change trop faible
currency.rate.amount.invalid=Le montant en devise doit être supérieur à 0
currency.rate.countries.invalid=Taux de change Pays Non valide
currency.rate.pair.invalid=Les parties du taux de change ne doivent pas être identiques
not.find.dest.region=Informations sur la destination introuvables
dest.region.freight.currency.not.null=Aucune configuration de devise pour les frais de transport \u00E0 la destination\u3010{}\u3011
dest.region.clearance.currency.not.null=Aucune configuration de devise pour les frais de d\u00E9douanement \u00E0 la destination\u3010{}\u3011
......
......@@ -598,6 +598,10 @@ currency.rate.exists=\u6C47\u7387\u5DF2\u5B58\u5728
currency.rate.not.exists=\u6C47\u7387\u4E0D\u5B58\u5728
currency.rate.disable=\u5E01\u79CD{}\u5BF9\u5E94\u5E01\u79CD{}\u6C47\u7387\u5DF2\u8FC7\u671F,\u8BF7\u91CD\u65B0\u8BBE\u7F6E
currency.rate.to.not.exists=\u5E01\u79CD{}\u5BF9\u5E94\u5E01\u79CD{}\u6C47\u7387\u4E0D\u5B58\u5728
currency.rate.too.small=\u6c47\u7387\u592a\u5c0f
currency.rate.amount.invalid=\u91d1\u989d\u5fc5\u987b\u5927\u5c0f\u0030
currency.rate.countries.invalid=\u56fd\u5bb6\u5217\u8868\u5fc5\u586b\u4e14\u4e3a\u6709\u6548\u503c
currency.rate.pair.invalid=\u6c47\u7387\u8d27\u5e01\u53cc\u65b9\u4e0d\u80fd\u76f8\u540c
product.price.not.exists=\u4EA7\u54C1\u4EF7\u683C\u4E0D\u5B58\u5728
shelf.not.exists=\u8D27\u67B6\u4E0D\u5B58\u5728
busi.pwd.not.exists=\u4E1A\u52A1\u5BC6\u7801\u4E0D\u5B58\u5728
......
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