From 5589d83f0d1fc6580070d52d4564d3060fd09285 Mon Sep 17 00:00:00 2001 From: wangning <164851225@qq.com> Date: Tue, 13 Mar 2018 15:14:15 +0800 Subject: [PATCH] add exchange rate cache --- .../core/impls/DashboardServiceImpl.java | 50 ++++++++++--------- .../web/ClearingConfigController.java | 16 ++++-- .../mappers/system/ExchangeRateMapper.java | 29 +++++++++++ .../mappers/system/ExchangeRateMapper.xml | 19 +++++++ 4 files changed, 86 insertions(+), 28 deletions(-) create mode 100644 src/main/java/au/com/royalpay/payment/manage/mappers/system/ExchangeRateMapper.java create mode 100644 src/main/resources/au/com/royalpay/payment/manage/mappers/system/ExchangeRateMapper.xml diff --git a/src/main/java/au/com/royalpay/payment/manage/analysis/core/impls/DashboardServiceImpl.java b/src/main/java/au/com/royalpay/payment/manage/analysis/core/impls/DashboardServiceImpl.java index 67b3206ca..248197b91 100644 --- a/src/main/java/au/com/royalpay/payment/manage/analysis/core/impls/DashboardServiceImpl.java +++ b/src/main/java/au/com/royalpay/payment/manage/analysis/core/impls/DashboardServiceImpl.java @@ -1,5 +1,28 @@ 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.ParseException; import java.text.SimpleDateFormat; @@ -12,28 +35,6 @@ import java.util.TreeMap; 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. */ @@ -50,6 +51,8 @@ public class DashboardServiceImpl implements DashboardService,DashboardAnalysisT private ClientMapper clientMapper; @Resource private CustomerAndOrdersStatisticsMapper customerAndOrdersStatisticsMapper; + @Resource + private ExchangeRateMapper exchangeRateMapper; @Override public JSONObject getCommonAnalysis1(JSONObject params) { @@ -323,7 +326,8 @@ public class DashboardServiceImpl implements DashboardService,DashboardAnalysisT } public void channelsExchangeRate(Date beginDate,Date endDate,Map exchangeRateMap, String channel){ - List channelRates = transactionAnalysisMapper.listExchangeRates(beginDate, endDate,channel); + + List channelRates = exchangeRateMapper.listExchangeRates(beginDate, endDate,channel); for (JSONObject analysisItem:channelRates){ Date date = analysisItem.getDate("date"); JSONObject dataItem = exchangeRateMap.get(date); diff --git a/src/main/java/au/com/royalpay/payment/manage/management/clearing/web/ClearingConfigController.java b/src/main/java/au/com/royalpay/payment/manage/management/clearing/web/ClearingConfigController.java index fda50ec79..89a9e4a61 100644 --- a/src/main/java/au/com/royalpay/payment/manage/management/clearing/web/ClearingConfigController.java +++ b/src/main/java/au/com/royalpay/payment/manage/management/clearing/web/ClearingConfigController.java @@ -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.tools.permission.enums.ManagerRole; import au.com.royalpay.payment.tools.CommonConsts; + +import com.alibaba.fastjson.JSON; +import com.alibaba.fastjson.JSONArray; import com.alibaba.fastjson.JSONObject; + +import org.springframework.util.CollectionUtils; import org.springframework.web.bind.annotation.*; import javax.annotation.Resource; @@ -18,13 +23,14 @@ public class ClearingConfigController { @Resource private CleanService cleanService; - @ManagerMapping(value = "/rate_warnings",method = RequestMethod.GET,role = {ManagerRole.ADMIN,ManagerRole.OPERATOR, ManagerRole.FINANCIAL_STAFF}) - public JSONObject getRateWarnings(){ + @ManagerMapping(value = "/rate_warnings", method = RequestMethod.GET, role = { ManagerRole.ADMIN, ManagerRole.OPERATOR, ManagerRole.FINANCIAL_STAFF }) + public JSONObject getRateWarnings() { return cleanService.rateWarnings(); } - @ManagerMapping(value = "/clients/{clientMoniker}/auto_rate",method = RequestMethod.PUT,role = {ManagerRole.ADMIN,ManagerRole.OPERATOR}) - public JSONObject generateRateAutomatically(@PathVariable String clientMoniker, @ModelAttribute(CommonConsts.MANAGER_STATUS) JSONObject manager){ - return cleanService.autoGenerateRate(clientMoniker,manager); + @ManagerMapping(value = "/clients/{clientMoniker}/auto_rate", method = RequestMethod.PUT, role = { ManagerRole.ADMIN, ManagerRole.OPERATOR }) + public JSONObject generateRateAutomatically(@PathVariable String clientMoniker, @ModelAttribute(CommonConsts.MANAGER_STATUS) JSONObject manager) { + return cleanService.autoGenerateRate(clientMoniker, manager); } + } diff --git a/src/main/java/au/com/royalpay/payment/manage/mappers/system/ExchangeRateMapper.java b/src/main/java/au/com/royalpay/payment/manage/mappers/system/ExchangeRateMapper.java new file mode 100644 index 000000000..dc086e7d7 --- /dev/null +++ b/src/main/java/au/com/royalpay/payment/manage/mappers/system/ExchangeRateMapper.java @@ -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 listExchangeRates(@Param("begin") Date begin, @Param("end") Date end, @Param("channel") String channel); +} diff --git a/src/main/resources/au/com/royalpay/payment/manage/mappers/system/ExchangeRateMapper.xml b/src/main/resources/au/com/royalpay/payment/manage/mappers/system/ExchangeRateMapper.xml new file mode 100644 index 000000000..1c552bbf8 --- /dev/null +++ b/src/main/resources/au/com/royalpay/payment/manage/mappers/system/ExchangeRateMapper.xml @@ -0,0 +1,19 @@ + + + + + \ No newline at end of file