add exchange rate cache

master
wangning 7 years ago
parent 3358eb269c
commit 5589d83f0d

@ -1,5 +1,28 @@
package au.com.royalpay.payment.manage.analysis.core.impls; package au.com.royalpay.payment.manage.analysis.core.impls;
import au.com.royalpay.payment.core.exceptions.ParamInvalidException;
import au.com.royalpay.payment.manage.analysis.beans.AnalysisBean;
import au.com.royalpay.payment.manage.analysis.core.DashboardAnalysisTask;
import au.com.royalpay.payment.manage.analysis.core.DashboardService;
import au.com.royalpay.payment.manage.analysis.mappers.ClientAnalysisMapper;
import au.com.royalpay.payment.manage.analysis.mappers.CustomerAndOrdersStatisticsMapper;
import au.com.royalpay.payment.manage.analysis.mappers.TransactionAnalysisMapper;
import au.com.royalpay.payment.manage.mappers.system.ClientMapper;
import au.com.royalpay.payment.manage.mappers.system.ExchangeRateMapper;
import au.com.royalpay.payment.manage.merchants.core.ClientManager;
import au.com.royalpay.payment.tools.defines.TradeType;
import com.alibaba.fastjson.JSONObject;
import com.github.miemiedev.mybatis.paginator.domain.Order;
import com.github.miemiedev.mybatis.paginator.domain.PageBounds;
import org.apache.commons.lang3.time.DateUtils;
import org.apache.commons.lang3.time.DurationFormatUtils;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.cache.annotation.Cacheable;
import org.springframework.stereotype.Service;
import java.text.DateFormat; import java.text.DateFormat;
import java.text.ParseException; import java.text.ParseException;
import java.text.SimpleDateFormat; import java.text.SimpleDateFormat;
@ -12,28 +35,6 @@ import java.util.TreeMap;
import javax.annotation.Resource; import javax.annotation.Resource;
import org.apache.commons.lang3.time.DateUtils;
import org.apache.commons.lang3.time.DurationFormatUtils;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.cache.annotation.Cacheable;
import org.springframework.stereotype.Service;
import com.alibaba.fastjson.JSONObject;
import com.github.miemiedev.mybatis.paginator.domain.Order;
import com.github.miemiedev.mybatis.paginator.domain.PageBounds;
import au.com.royalpay.payment.core.exceptions.ParamInvalidException;
import au.com.royalpay.payment.manage.analysis.beans.AnalysisBean;
import au.com.royalpay.payment.manage.analysis.core.DashboardAnalysisTask;
import au.com.royalpay.payment.manage.analysis.core.DashboardService;
import au.com.royalpay.payment.manage.analysis.mappers.ClientAnalysisMapper;
import au.com.royalpay.payment.manage.analysis.mappers.CustomerAndOrdersStatisticsMapper;
import au.com.royalpay.payment.manage.analysis.mappers.TransactionAnalysisMapper;
import au.com.royalpay.payment.manage.mappers.system.ClientMapper;
import au.com.royalpay.payment.manage.merchants.core.ClientManager;
import au.com.royalpay.payment.tools.defines.TradeType;
/** /**
* Created by davep on 2016-07-28. * Created by davep on 2016-07-28.
*/ */
@ -50,6 +51,8 @@ public class DashboardServiceImpl implements DashboardService,DashboardAnalysisT
private ClientMapper clientMapper; private ClientMapper clientMapper;
@Resource @Resource
private CustomerAndOrdersStatisticsMapper customerAndOrdersStatisticsMapper; private CustomerAndOrdersStatisticsMapper customerAndOrdersStatisticsMapper;
@Resource
private ExchangeRateMapper exchangeRateMapper;
@Override @Override
public JSONObject getCommonAnalysis1(JSONObject params) { public JSONObject getCommonAnalysis1(JSONObject params) {
@ -323,7 +326,8 @@ public class DashboardServiceImpl implements DashboardService,DashboardAnalysisT
} }
public void channelsExchangeRate(Date beginDate,Date endDate,Map<Date, JSONObject> exchangeRateMap, String channel){ public void channelsExchangeRate(Date beginDate,Date endDate,Map<Date, JSONObject> exchangeRateMap, String channel){
List<JSONObject> channelRates = transactionAnalysisMapper.listExchangeRates(beginDate, endDate,channel);
List<JSONObject> channelRates = exchangeRateMapper.listExchangeRates(beginDate, endDate,channel);
for (JSONObject analysisItem:channelRates){ for (JSONObject analysisItem:channelRates){
Date date = analysisItem.getDate("date"); Date date = analysisItem.getDate("date");
JSONObject dataItem = exchangeRateMap.get(date); JSONObject dataItem = exchangeRateMap.get(date);

@ -4,7 +4,12 @@ import au.com.royalpay.payment.manage.management.clearing.core.CleanService;
import au.com.royalpay.payment.manage.permission.manager.ManagerMapping; import au.com.royalpay.payment.manage.permission.manager.ManagerMapping;
import au.com.royalpay.payment.tools.permission.enums.ManagerRole; import au.com.royalpay.payment.tools.permission.enums.ManagerRole;
import au.com.royalpay.payment.tools.CommonConsts; import au.com.royalpay.payment.tools.CommonConsts;
import com.alibaba.fastjson.JSON;
import com.alibaba.fastjson.JSONArray;
import com.alibaba.fastjson.JSONObject; import com.alibaba.fastjson.JSONObject;
import org.springframework.util.CollectionUtils;
import org.springframework.web.bind.annotation.*; import org.springframework.web.bind.annotation.*;
import javax.annotation.Resource; import javax.annotation.Resource;
@ -27,4 +32,5 @@ public class ClearingConfigController {
public JSONObject generateRateAutomatically(@PathVariable String clientMoniker, @ModelAttribute(CommonConsts.MANAGER_STATUS) JSONObject manager) { public JSONObject generateRateAutomatically(@PathVariable String clientMoniker, @ModelAttribute(CommonConsts.MANAGER_STATUS) JSONObject manager) {
return cleanService.autoGenerateRate(clientMoniker, manager); return cleanService.autoGenerateRate(clientMoniker, manager);
} }
} }

@ -0,0 +1,29 @@
package au.com.royalpay.payment.manage.mappers.system;
import java.util.Date;
import java.util.List;
import org.apache.ibatis.annotations.Param;
import com.alibaba.fastjson.JSONObject;
import cn.yixblog.support.mybatis.autosql.annotations.AdvanceSelect;
import cn.yixblog.support.mybatis.autosql.annotations.AutoMapper;
import cn.yixblog.support.mybatis.autosql.annotations.AutoSql;
import cn.yixblog.support.mybatis.autosql.annotations.SqlType;
/**
* Create by yixian at 2017-12-19 19:09
*/
@AutoMapper(tablename = "sys_exchange_rate", pkName = "id")
public interface ExchangeRateMapper {
@AutoSql(type = SqlType.SELECT)
@AdvanceSelect(addonWhereClause = "type = 1")
JSONObject findMaxRate(@Param("create_date") Date create_time);
@AutoSql(type = SqlType.SELECT)
@AdvanceSelect(addonWhereClause = "type = 2")
JSONObject findMinRate(@Param("create_date") Date create_time);
List<JSONObject> listExchangeRates(@Param("begin") Date begin, @Param("end") Date end, @Param("channel") String channel);
}

@ -0,0 +1,19 @@
<?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="au.com.royalpay.payment.manage.mappers.system.ExchangeRateMapper">
<select id="listExchangeRates" resultType="com.alibaba.fastjson.JSONObject">
<![CDATA[
SELECT
create_date mx ,
rate exchange_rate ,
create_date `date`
FROM sys_exchange_rate
WHERE create_date >= #{begin} And create_date <= #{end} AND channel = #{channel} and type = 1
GROUP BY
create_date
ORDER BY
`date` ASC
]]>
</select>
</mapper>
Loading…
Cancel
Save