提交 d84f0ccf authored 作者: zgy's avatar zgy

完成汇率转换接口

上级 0bd9c725
......@@ -31,14 +31,16 @@ public class TbCfOrderController {
@ApiOperation("用户结算,返回订单")
@GetMapping("/settle")
public Result<TbCfOrderVo> settleAccount(@ApiParam("发放ID") @RequestParam(value = "toitableId",required = false) String toitableId) throws IOException, URISyntaxException, ExecutionException, InterruptedException, TimeoutException {
public Result<TbCfOrderVo> settleAccount(@ApiParam("发放ID") @RequestParam(value = "toitableId", required = false) String toitableId) throws IOException, URISyntaxException, ExecutionException, InterruptedException, TimeoutException {
return tbCfOrderService.settleAccount(toitableId);
}
@ApiOperation("用户确定下单")
@PostMapping("/place")
public Result placeOrder(@ApiParam("订单详情") @RequestBody TbCfOrderVo tbCfOrderVo,@ApiParam("发放ID") @RequestParam(value = "toitableId",required = false) String toitableId) throws IOException, URISyntaxException, ExecutionException, InterruptedException, TimeoutException {
return tbCfOrderService.placeOrder(tbCfOrderVo,toitableId);
public Result placeOrder(@ApiParam("订单详情") @RequestBody TbCfOrderVo tbCfOrderVo, @ApiParam("发放ID") @RequestParam(value = "toitableId", required = false) String toitableId) throws IOException, URISyntaxException, ExecutionException, InterruptedException, TimeoutException {
return tbCfOrderService.placeOrder(tbCfOrderVo, toitableId);
}
/**
* pageNum 页数
* pageSize 每页大小
......@@ -63,11 +65,13 @@ public class TbCfOrderController {
public Result payForOrder(@ApiParam("订单id") @PathVariable("orderId") String orderId, @ApiParam("支付token") @PathVariable("token") String token) {
return tbCfOrderService.payForOrder(orderId, token);
}
@ApiOperation("发起订单支付")
@PostMapping("/pay/{orderId}")
public Result rePayForOrder(@ApiParam("订单id") @PathVariable("orderId") String orderId) {
return tbCfOrderService.rePayForOrder(orderId);
}
@ApiOperation("根据订单id,查询物流详情")
@GetMapping("/express/{orderId}")
public Result queryOrderExpressInfo(@ApiParam("订单id") @PathVariable String orderId) throws IOException {
......@@ -81,11 +85,25 @@ public class TbCfOrderController {
}
/**
* 根据订单号获取详细订单数据
* 根据订单号获取详细订单数据
*/
@ApiOperation(value = "根据订单号获取详细订单数据")
@GetMapping(value = "/detail/{orderId}")
public Result getOrderDetail(@PathVariable("orderId") String orderId) {
return tbCfOrderService.getOrderDetail(orderId);
}
/**
* 汇率转换(美元转换成其他)
*
* @param price
* @param currency
* @return
*/
@ApiOperation("汇率转换")
@GetMapping("/currencyConversion")
public Result currencyConversion(@ApiParam("价格") @RequestParam("price") String price,
@ApiParam("兑换货币") @RequestParam("currency") String currency) {
return tbCfOrderService.currencyConversion(price, currency);
}
}
......@@ -17,27 +17,32 @@ public interface TbCfOrderDao extends BaseDao<TbCfOrderEntity> {
/**
* 获取用户订单数据
*
* @param userId
* @param orderStatus OrderStatusEnum
* @return
*/
List<TbCfOrderEntity> getUserOrderList(String userId,Integer orderStatus);
List<TbCfOrderEntity> getUserOrderList(String userId, Integer orderStatus);
/**
* 获取订单内商品
*
* @param orderId
* @return
*/
List<TbCfItemDetailEntity> getOrderItemList(String orderId);
/**
* 获取订单内商品
* 获取订单内商品
*
* @param orderId
* @return
*/
List<ItemEntity> getItemList(String orderId);
/**
* 获取付款订单
*
* @param beginDate
* @param endDate
* @return
......@@ -46,12 +51,14 @@ public interface TbCfOrderDao extends BaseDao<TbCfOrderEntity> {
/**
* 获取某段时间已发货订单数据
*
* @return
*/
List<TbCfItemShippedEntity> getDeliveryList(Date beginDate, Date endDate);
/**
* 根据订单id获取订单实体
*
* @param orderId
* @return
*/
......@@ -62,10 +69,19 @@ public interface TbCfOrderDao extends BaseDao<TbCfOrderEntity> {
/**
* 根据订单id和商品id查询订单记录id //后续根据此id 查询物流信息
*
* @param orderId
* @param itemId
* @return
*/
String getOrdersId(String orderId, String itemId);
/**
* 汇率转换
*
* @param currency
* @return
*/
TbCfExchangeEntity currencyConversion(String currency);
}
package com.diaoyun.zion.chinafrica.entity;
import java.io.Serializable;
import java.math.BigDecimal;
import java.util.Date;
/**
* 汇率管理实体
* 表名 tb_cf_exchange
*
* @author lipengjun
* @date 2019-12-10 15:29:22
*/
public class TbCfExchangeEntity implements Serializable {
private static final long serialVersionUID = 1L;
/**
* ID
*/
private String id;
/**
* 转换类型
*/
private String type;
/**
* 货币
*/
private String currency;
/**
* 兑换货币
*/
private String exchangeCurrency;
/**
* 汇率
*/
private BigDecimal exchangeRate;
/**
* 删除标志 0:正常 1:已删除
*/
private Integer delFlag;
/**
* 创建时间
*/
private Date createTime;
/**
* 更新时间
*/
private Date updateTime;
/**
* 设置:ID
*/
public void setId(String id) {
this.id = id;
}
/**
* 获取:ID
*/
public String getId() {
return id;
}
/**
* 设置:转换类型
*/
public void setType(String type) {
this.type = type;
}
/**
* 获取:转换类型
*/
public String getType() {
return type;
}
/**
* 设置:货币
*/
public void setCurrency(String currency) {
this.currency = currency;
}
/**
* 获取:货币
*/
public String getCurrency() {
return currency;
}
/**
* 设置:兑换货币
*/
public void setExchangeCurrency(String exchangeCurrency) {
this.exchangeCurrency = exchangeCurrency;
}
/**
* 获取:兑换货币
*/
public String getExchangeCurrency() {
return exchangeCurrency;
}
/**
* 设置:汇率
*/
public void setExchangeRate(BigDecimal exchangeRate) {
this.exchangeRate = exchangeRate;
}
/**
* 获取:汇率
*/
public BigDecimal getExchangeRate() {
return exchangeRate;
}
/**
* 设置:删除标志 0:正常 1:已删除
*/
public void setDelFlag(Integer delFlag) {
this.delFlag = delFlag;
}
/**
* 获取:删除标志 0:正常 1:已删除
*/
public Integer getDelFlag() {
return delFlag;
}
/**
* 设置:创建时间
*/
public void setCreateTime(Date createTime) {
this.createTime = createTime;
}
/**
* 获取:创建时间
*/
public Date getCreateTime() {
return createTime;
}
/**
* 设置:更新时间
*/
public void setUpdateTime(Date updateTime) {
this.updateTime = updateTime;
}
/**
* 获取:更新时间
*/
public Date getUpdateTime() {
return updateTime;
}
}
......@@ -3,6 +3,8 @@ package com.diaoyun.zion.chinafrica.service;
import com.diaoyun.zion.chinafrica.entity.TbCfOrderEntity;
import com.diaoyun.zion.chinafrica.vo.TbCfOrderVo;
import com.diaoyun.zion.master.base.Result;
import io.swagger.annotations.ApiParam;
import org.springframework.web.bind.annotation.RequestParam;
import java.io.IOException;
import java.net.URISyntaxException;
......@@ -173,4 +175,6 @@ public interface TbCfOrderService {
Result getDescriptionById(String descriptionId);
Result rePayForOrder(String orderId);
Result currencyConversion(String price, String currency);
}
......@@ -185,8 +185,8 @@ public class TbCfOrderServiceImpl implements TbCfOrderService {
} else {
//获取下单的订单数据
TbCfOrderVo definiteOrder = ensureOrder(tbCfUserInfoVo, pageOrder, tbCfCartItemDetailList, toitableId);
for( TbCfCartItemDetailVo itemList: tbCfCartItemDetailList ){
TbCfItemOrderREntity tbCfItemOrderREntity=new TbCfItemOrderREntity();
for (TbCfCartItemDetailVo itemList : tbCfCartItemDetailList) {
TbCfItemOrderREntity tbCfItemOrderREntity = new TbCfItemOrderREntity();
tbCfItemOrderREntity.setOrderItemId(IdUtil.createIdbyUUID());
tbCfItemOrderREntity.setOrderId(definiteOrder.getOrderId());
tbCfItemOrderREntity.setItemId(itemList.getItemId());
......@@ -353,6 +353,7 @@ public class TbCfOrderServiceImpl implements TbCfOrderService {
/**
* 获取某段时间的付款订单数据
*
* @return
*/
@Override
......@@ -370,8 +371,10 @@ public class TbCfOrderServiceImpl implements TbCfOrderService {
}
return result;
}
/**
* 获取某段时间已发货订单数据
*
* @return
*/
@Override
......@@ -385,7 +388,7 @@ public class TbCfOrderServiceImpl implements TbCfOrderService {
Date endDate = new Date(endTime * 1000);
List<TbCfItemShippedEntity> orderList = tbCfOrderDao.getDeliveryList(beginDate, endDate);
// TODO 暂设为赞比亚
for(TbCfItemShippedEntity list:orderList ){
for (TbCfItemShippedEntity list : orderList) {
list.setCountry("赞比亚");
}
PageInfo<TbCfItemShippedEntity> pageInfo = new PageInfo<>(orderList);
......@@ -393,8 +396,10 @@ public class TbCfOrderServiceImpl implements TbCfOrderService {
}
return result;
}
/**
* 根据订单号获取详细订单数据 给第三方的接口
*
* @param orderId
* @return
*/
......@@ -427,6 +432,7 @@ public class TbCfOrderServiceImpl implements TbCfOrderService {
result.setData(orderEntity);
return result;
}
@Override
public Result deleteOrder(String orderId) {
Result result = new Result();
......@@ -467,8 +473,8 @@ public class TbCfOrderServiceImpl implements TbCfOrderService {
@Override
public Result getDescriptionById(String descriptionId) {
Result<ExpressTemplateVo> result = new Result<>();
ExpressTemplateVo tbCfExpressTemplateEntity= new ExpressTemplateVo();
ExpressTemplateVo expressTemplate=tbCfExpressTemplateDao.getDescriptionById(descriptionId);
ExpressTemplateVo tbCfExpressTemplateEntity = new ExpressTemplateVo();
ExpressTemplateVo expressTemplate = tbCfExpressTemplateDao.getDescriptionById(descriptionId);
tbCfExpressTemplateEntity.setDescriptionId(expressTemplate.getDescriptionId());
tbCfExpressTemplateEntity.setDescriptionName(expressTemplate.getDescriptionName());
tbCfExpressTemplateEntity.setExpressFee(expressTemplate.getExpressFee());
......@@ -480,11 +486,37 @@ public class TbCfOrderServiceImpl implements TbCfOrderService {
@Override
public Result rePayForOrder(String orderId) {
Result result=new Result();
TbCfOrderEntity order=tbCfOrderDao.queryObject(orderId);
Result result = new Result();
TbCfOrderEntity order = tbCfOrderDao.queryObject(orderId);
return result.setData(order);
}
/**
* 汇率转换
*
* @param price
* @param currency
* @return
*/
@Override
public Result currencyConversion(String price, String currency) {
Result result = new Result();
try {
if (!StringUtils.isBlank(price) && !StringUtils.isBlank(currency)) {
TbCfExchangeEntity exchangeEntity = tbCfOrderDao.currencyConversion(currency.toUpperCase());
BigDecimal rate = exchangeEntity.getExchangeRate();
BigDecimal oldPrice = new BigDecimal(price);
BigDecimal resultPrice = oldPrice.multiply(rate);
result.setData(resultPrice).setMessage(ResultCodeEnum.SUCCESS.getDesc());
} else {
result.setCode(ResultCodeEnum.QUERY_ERROR.getCode()).setMessage(ResultCodeEnum.QUERY_ERROR.getDesc());
}
} catch (Exception e) {
result.setCode(ResultCodeEnum.QUERY_ERROR.getCode()).setMessage(e.getMessage());
}
return result;
}
/**
* 记录财务流水
......@@ -735,14 +767,14 @@ public class TbCfOrderServiceImpl implements TbCfOrderService {
itemsPrice = itemsPrice.add(itemSourcePrice.multiply(itemNum));
//计算运费
BigDecimal expressCost = getExpressTemplate(tbCfCartItemDetailVo.getItemCategory());
BigDecimal continuationFee=getContinuationFee(tbCfCartItemDetailVo.getItemCategory());
BigDecimal continuationFee = getContinuationFee(tbCfCartItemDetailVo.getItemCategory());
//expressCost = expressCost.multiply(itemNum);
if("1".equals(itemNum)){
if ("1".equals(itemNum)) {
expressCost = expressCost.multiply(itemNum);
}else{
BigDecimal a= BigDecimal.valueOf(1);
} else {
BigDecimal a = BigDecimal.valueOf(1);
BigDecimal dj = continuationFee.multiply(itemNum.subtract(a));
expressCost =dj.add(expressCost);
expressCost = dj.add(expressCost);
}
totalExpressCost = totalExpressCost.add(expressCost);
}
......@@ -771,6 +803,7 @@ public class TbCfOrderServiceImpl implements TbCfOrderService {
TbCfExpressTemplateEntity tbCfExpressTemplateEntity = tbCfExpressTemplateDao.queryObject(templateId);
return tbCfExpressTemplateEntity.getExpressFee();
}
/**
* 获取运费 TODO 运费模板可改为缓存
*
......
......@@ -39,12 +39,12 @@ spring:
type: com.alibaba.druid.pool.DruidDataSource
driver-class-name: com.mysql.cj.jdbc.Driver
# 测试环境
# url: jdbc:mysql://47.106.242.175:3306/chinafrica?useUnicode=true&characterEncoding=UTF-8&rewriteBatchedStatements=true&autoReconnect=true&failOverReadOnly=false&zeroDateTimeBehavior=convertToNull&useSSL=false
# username: root
# password: diaoyun666
url: jdbc:mysql://159.138.48.71:3306/chinafrica?useUnicode=true&characterEncoding=UTF-8&rewriteBatchedStatements=true&autoReconnect=true&failOverReadOnly=false&zeroDateTimeBehavior=convertToNull&useSSL=false
url: jdbc:mysql://47.106.242.175:3306/chinafrica?useUnicode=true&characterEncoding=UTF-8&rewriteBatchedStatements=true&autoReconnect=true&failOverReadOnly=false&zeroDateTimeBehavior=convertToNull&useSSL=false
username: root
password: Diaoyunnuli.8
password: diaoyun666
# url: jdbc:mysql://159.138.48.71:3306/chinafrica?useUnicode=true&characterEncoding=UTF-8&rewriteBatchedStatements=true&autoReconnect=true&failOverReadOnly=false&zeroDateTimeBehavior=convertToNull&useSSL=false
# username: root
# password: Diaoyunnuli.8
# 连接池配置
initial-size: 5
......
Markdown 格式
0%
您添加了 0 到此讨论。请谨慎行事。
请先完成此评论的编辑!
注册 或者 后发表评论