hotfix: 优化用户数查询

master
Yixian 3 years ago
parent b1c04352b6
commit ed58aae8ec

@ -39,7 +39,7 @@ import java.util.concurrent.TimeUnit;
* Created by davep on 2016-07-28.
*/
@Service
public class DashboardServiceImpl implements DashboardService,DashboardAnalysisTask {
public class DashboardServiceImpl implements DashboardService, DashboardAnalysisTask {
private Logger logger = LoggerFactory.getLogger(getClass());
@Resource
private ClientAnalysisMapper clientAnalysisMapper;
@ -64,25 +64,24 @@ public class DashboardServiceImpl implements DashboardService,DashboardAnalysisT
private MerchantInfoProvider merchantInfoProvider;
@Override
public JSONObject getCommonAnalysis1(JSONObject params) {
String jsonStr = stringRedisTemplate.boundValueOps("org_commonAnalysis1" + params.getString("org_id") + params.getString("begin")).get();
JSONObject commonAnalysis1 = JSON.parseObject(jsonStr);
if(commonAnalysis1 != null){
if (commonAnalysis1 != null) {
return commonAnalysis1;
}
JSONObject res = new JSONObject();
if(params.getDate("end").after(new Date())){
if(params.getDate("begin").compareTo(DateUtils.addDays(params.getDate("end"), -1))==0){
res = transactionAnalysisMapper.getClientTransaction(params);
}else {
if (params.getDate("end").after(new Date())) {
if (params.getDate("begin").compareTo(DateUtils.addDays(params.getDate("end"), -1)) == 0) {
res = transactionAnalysisMapper.getClientTransaction(params);
} else {
res = customerAndOrdersStatisticsMapper.getCommonCount(params);
}
}else {
res = customerAndOrdersStatisticsMapper.getCommonCount(params);
} else {
res = customerAndOrdersStatisticsMapper.getCommonCount(params);
}
stringRedisTemplate.boundValueOps("org_commonAnalysis1"+params.getString("org_id")+params.getString("begin")).set(res.toJSONString(), 5, TimeUnit.MINUTES);
stringRedisTemplate.boundValueOps("org_commonAnalysis1" + params.getString("org_id") + params.getString("begin")).set(res.toJSONString(), 5, TimeUnit.MINUTES);
return res;
}
@ -91,7 +90,7 @@ public class DashboardServiceImpl implements DashboardService,DashboardAnalysisT
public JSONObject getCommonAnalysis3(JSONObject params) {
String jsonStr = stringRedisTemplate.boundValueOps("org_commonAnalysis3" + params.getString("org_id") + params.getString("begin")).get();
JSONObject commonAnalysis3 = JSON.parseObject(jsonStr);
if(commonAnalysis3 != null){
if (commonAnalysis3 != null) {
return commonAnalysis3;
}
JSONObject res = new JSONObject();
@ -100,7 +99,7 @@ public class DashboardServiceImpl implements DashboardService,DashboardAnalysisT
//res.put("total_partners", clientAnalysisMapper.countClients(params));
// 统计所有的商户,包括禁用的
res.put("total_partners", clientAnalysisMapper.countClientsAll(params));
stringRedisTemplate.boundValueOps("org_commonAnalysis3"+params.getString("org_id")+params.getString("begin")).set(res.toJSONString(), 5, TimeUnit.MINUTES);
stringRedisTemplate.boundValueOps("org_commonAnalysis3" + params.getString("org_id") + params.getString("begin")).set(res.toJSONString(), 5, TimeUnit.MINUTES);
return res;
}
@ -108,25 +107,26 @@ public class DashboardServiceImpl implements DashboardService,DashboardAnalysisT
public JSONObject getCommonAnalysis2(JSONObject params) {
String jsonStr = stringRedisTemplate.boundValueOps("org_commonAnalysis2" + params.getString("org_id") + params.getString("begin")).get();
JSONObject commonAnalysis2 = JSON.parseObject(jsonStr);
if(commonAnalysis2 != null){
if (commonAnalysis2 != null) {
return commonAnalysis2;
}
JSONObject res = new JSONObject();
if(params.getDate("end").after(new Date())){
if(params.getDate("begin").compareTo(DateUtils.addDays(params.getDate("end"), -1))==0){
if (params.getDate("end").after(new Date())) {
if (params.getDate("begin").compareTo(DateUtils.addDays(params.getDate("end"), -1)) == 0) {
res.put("total_customers", transactionAnalysisMapper.countCustomers(params));
res.put("old_customers", transactionAnalysisMapper.countOldCustomers(params));
res.put("traded_partners", clientAnalysisMapper.countTradedPartners(params));
}else {
} else {
res = getYesOrLasMonth(params);
}
}else {
} else {
res = getYesOrLasMonth(params);
}
stringRedisTemplate.boundValueOps("org_commonAnalysis2"+params.getString("org_id")+params.getString("begin")).set(res.toJSONString(), 5, TimeUnit.MINUTES);
stringRedisTemplate.boundValueOps("org_commonAnalysis2" + params.getString("org_id") + params.getString("begin")).set(res.toJSONString(), 5, TimeUnit.MINUTES);
return res;
}
private JSONObject getYesOrLasMonth(JSONObject params){
private JSONObject getYesOrLasMonth(JSONObject params) {
JSONObject res = new JSONObject();
res.put("traded_partners", customerAndOrdersStatisticsMapper.countTradedClients(params));
res.put("total_customers", customerAndOrdersStatisticsMapper.countTotalCustomers(params));
@ -138,7 +138,7 @@ public class DashboardServiceImpl implements DashboardService,DashboardAnalysisT
public JSONObject getCommonAnalysis4(JSONObject params) {
String jsonStr = stringRedisTemplate.boundValueOps("org_commonAnalysis4" + params.getString("org_id") + params.getString("begin")).get();
JSONObject commonAnalysis4 = JSON.parseObject(jsonStr);
if(commonAnalysis4 != null){
if (commonAnalysis4 != null) {
return commonAnalysis4;
}
JSONObject res = new JSONObject();
@ -146,22 +146,22 @@ public class DashboardServiceImpl implements DashboardService,DashboardAnalysisT
if (!topOrders.isEmpty()) {
res.put("top_amount_order", topOrders.get(0));
}
stringRedisTemplate.boundValueOps("org_commonAnalysis4"+params.getString("org_id")+params.getString("begin")).set(res.toJSONString(), 5, TimeUnit.MINUTES);
stringRedisTemplate.boundValueOps("org_commonAnalysis4" + params.getString("org_id") + params.getString("begin")).set(res.toJSONString(), 5, TimeUnit.MINUTES);
return res;
}
@Override
public List<JSONObject> getTradeInTypes(JSONObject params) {
String jsonStr = stringRedisTemplate.boundValueOps("tradeInTypes"+params.getString("org_id")+ params.getString("begin")).get();
List<JSONObject> tradeInTypes = JSONObject.parseArray(jsonStr,JSONObject.class);
if(tradeInTypes != null){
String jsonStr = stringRedisTemplate.boundValueOps("tradeInTypes" + params.getString("org_id") + params.getString("begin")).get();
List<JSONObject> tradeInTypes = JSONObject.parseArray(jsonStr, JSONObject.class);
if (tradeInTypes != null) {
return tradeInTypes;
}
if (params.containsKey("client_id")) {
clientManager.queryModifyClientIds(params.getInteger("client_id"), params);
}
List<JSONObject> res = transactionAnalysisMapper.getTradeAmountInTypes(params);
stringRedisTemplate.boundValueOps("tradeInTypes"+params.getString("org_id")+ params.getString("begin")).set(res.toString(), 5, TimeUnit.MINUTES);
stringRedisTemplate.boundValueOps("tradeInTypes" + params.getString("org_id") + params.getString("begin")).set(res.toString(), 5, TimeUnit.MINUTES);
return res;
}
@ -175,14 +175,14 @@ public class DashboardServiceImpl implements DashboardService,DashboardAnalysisT
@Override
public List<JSONObject> getTopTradePartnersNew(JSONObject params) {
String jsonStr = stringRedisTemplate.boundValueOps("topTradePartnersNew"+params.getString("org_id")+ params.getString("begin")).get();
List<JSONObject> topTradePartnersNew = JSONObject.parseArray(jsonStr,JSONObject.class);
if(topTradePartnersNew != null){
String jsonStr = stringRedisTemplate.boundValueOps("topTradePartnersNew" + params.getString("org_id") + params.getString("begin")).get();
List<JSONObject> topTradePartnersNew = JSONObject.parseArray(jsonStr, JSONObject.class);
if (topTradePartnersNew != null) {
return topTradePartnersNew;
}
params.putIfAbsent("rankType", "aud_fee");
List<JSONObject> res = clientAnalysisMapper.listPartnersTradeAmountNew(params);
stringRedisTemplate.boundValueOps("topTradePartnersNew"+params.getString("org_id")+ params.getString("begin")).set(res.toString(), 5, TimeUnit.MINUTES);
stringRedisTemplate.boundValueOps("topTradePartnersNew" + params.getString("org_id") + params.getString("begin")).set(res.toString(), 5, TimeUnit.MINUTES);
return res;
}
@ -277,6 +277,7 @@ public class DashboardServiceImpl implements DashboardService,DashboardAnalysisT
analysis.add(wechatHtml5);
return analysis;
}
@Override
public List<JSONObject> getPartnerTradeAnalysisInDays(JSONObject params) {
int date_range = Integer.parseInt(DurationFormatUtils.formatPeriod(params.getDate("begin").getTime(), params.getDate("end").getTime(), "dd"));
@ -293,16 +294,16 @@ public class DashboardServiceImpl implements DashboardService,DashboardAnalysisT
@Override
public List<JSONObject> getTradeAnalysisInDays(JSONObject params) {
String jsonStr = stringRedisTemplate.boundValueOps("tradeAnalysisInDays"+params.getString("org_id")+ params.getString("begin")).get();
List<JSONObject> tradeAnalysisInDays = JSONObject.parseArray(jsonStr,JSONObject.class);
if(tradeAnalysisInDays != null){
String jsonStr = stringRedisTemplate.boundValueOps("tradeAnalysisInDays" + params.getString("org_id") + params.getString("begin")).get();
List<JSONObject> tradeAnalysisInDays = JSONObject.parseArray(jsonStr, JSONObject.class);
if (tradeAnalysisInDays != null) {
return tradeAnalysisInDays;
}
if (!params.containsKey("client_ids") && !params.containsKey("org_id")) {
params.put("client_id", 0);
}
List<JSONObject> res = customerAndOrdersStatisticsMapper.getSumCustomersAnalysis(params);
stringRedisTemplate.boundValueOps("tradeAnalysisInDays"+params.getString("org_id")+ params.getString("begin")).set(res.toString(), 5, TimeUnit.MINUTES);
stringRedisTemplate.boundValueOps("tradeAnalysisInDays" + params.getString("org_id") + params.getString("begin")).set(res.toString(), 5, TimeUnit.MINUTES);
return res;
}
@ -330,11 +331,11 @@ public class DashboardServiceImpl implements DashboardService,DashboardAnalysisT
params.put("client_id", partner.getIntValue("client_id"));
clientManager.queryModifyClientIds(partner.getIntValue("client_id"), params);
JSONObject today = getTransJSONO(params);
params.put("begin",DateUtils.addDays(params.getDate("begin"),-1));
params.put("end",DateUtils.addDays(params.getDate("end"),-1));
params.put("begin", DateUtils.addDays(params.getDate("begin"), -1));
params.put("end", DateUtils.addDays(params.getDate("end"), -1));
JSONObject yes = getTransJSONO(params);
res.put("today",today);
res.put("yes",yes);
res.put("today", today);
res.put("yes", yes);
// res.put("not_settled", new BigDecimal(transactionAnalysisMapper.analysisNotSettled(params)));
// params.put("channel", "system");
// res.put("sys_not_settled", new BigDecimal(transactionAnalysisMapper.analysisNotSettled(params)));
@ -342,18 +343,19 @@ public class DashboardServiceImpl implements DashboardService,DashboardAnalysisT
// res.put("rpaypmt_card_not_settled", new BigDecimal(transactionAnalysisMapper.analysisNotSettled(params)));
// params.put("channel", "rpaypmt_dd");
// res.put("rpaypmt_dd_not_settled", new BigDecimal(transactionAnalysisMapper.analysisNotSettled(params)));
res.put("trade_amount_rise",yes.getBigDecimal("trade_amount").compareTo(BigDecimal.ZERO)>0 ? (today.getBigDecimal("trade_amount").subtract(yes.getBigDecimal("trade_amount"))).divide(yes.getBigDecimal("trade_amount"), 4, RoundingMode.HALF_UP):BigDecimal.ZERO);
res.put("trade_amount_rise", yes.getBigDecimal("trade_amount").compareTo(BigDecimal.ZERO) > 0 ? (today.getBigDecimal("trade_amount").subtract(yes.getBigDecimal("trade_amount"))).divide(yes.getBigDecimal("trade_amount"), 4, RoundingMode.HALF_UP) : BigDecimal.ZERO);
res.put("trade_count_rise", yes.getIntValue("trade_count") > 0 ? (today.getBigDecimal("trade_count").subtract(yes.getBigDecimal("trade_count"))).divide(yes.getBigDecimal("trade_count"), 4, RoundingMode.HALF_UP) : 0);
res.put("customers_rise", yes.getIntValue("customers") > 0 ? (today.getBigDecimal("customers").subtract(yes.getBigDecimal("customers"))).divide(yes.getBigDecimal("customers"), 4, RoundingMode.HALF_UP) : 0);
params.remove("begin");
params.remove("end");
List<JSONObject> logs = transactionMapper.listSettlementLogTotal(params);
res.put("latest_settle",logs.isEmpty()?BigDecimal.ZERO:logs.get(0).getBigDecimal("income"));
res.put("latest_settle", logs.isEmpty() ? BigDecimal.ZERO : logs.get(0).getBigDecimal("income"));
return res;
}
/**
*
*
* @param partner
* @param partnerAnalysisBean
* @return
@ -374,16 +376,17 @@ public class DashboardServiceImpl implements DashboardService,DashboardAnalysisT
params.put("hide_sub_mch", mchConfig.getBooleanValue("hide_sub_mch"));
params.put("client_id", partner.getIntValue("client_id"));
clientManager.queryModifyClientIds(partner.getIntValue("client_id"), params);
params.put("begin",DateUtils.addDays(params.getDate("begin"),-1));
params.put("end",DateUtils.addDays(params.getDate("end"),-1));
String key="not_settled";
if(StringUtils.isNotEmpty(params.getString("channel"))){
key=params.getString("channel")+"_not_settled";
params.put("begin", DateUtils.addDays(params.getDate("begin"), -1));
params.put("end", DateUtils.addDays(params.getDate("end"), -1));
String key = "not_settled";
if (StringUtils.isNotEmpty(params.getString("channel"))) {
key = params.getString("channel") + "_not_settled";
}
res.put(key, new BigDecimal(transactionAnalysisMapper.analysisNotSettled(params)));
return res;
}
private JSONObject getTransJSONO(JSONObject params){
private JSONObject getTransJSONO(JSONObject params) {
JSONObject res = new JSONObject();
JSONObject object = transactionAnalysisMapper.getClientTransaction(params);
res.put("trade_amount", object.getBigDecimal("trade_amount"));
@ -391,6 +394,7 @@ public class DashboardServiceImpl implements DashboardService,DashboardAnalysisT
res.put("customers", transactionAnalysisMapper.countCustomers(params));
return res;
}
@Override
public List<JSONObject> getTradeAnalysisInHours(JSONObject partner, AnalysisBean partnerAnalysisBean) {
String timezone = partner.getJSONObject("client").getString("timezone");
@ -446,22 +450,22 @@ public class DashboardServiceImpl implements DashboardService,DashboardAnalysisT
throw new ParamInvalidException("end", "error.payment.valid.invalid_time");
}
List<JSONObject> listChannelRate = new ArrayList<>();
Map<Date,JSONObject> exchangeRateMap = new TreeMap<>();
String[] channels = {"Wechat","Alipay"};
for (String channel:channels){
Map<Date, JSONObject> exchangeRateMap = new TreeMap<>();
String[] channels = {"Wechat", "Alipay"};
for (String channel : channels) {
channelsExchangeRate(beginDate, endDate, exchangeRateMap, channel);
}
for (Date date:exchangeRateMap.keySet()){
for (Date date : exchangeRateMap.keySet()) {
JSONObject total = exchangeRateMap.get(date);
SimpleDateFormat sdf = new SimpleDateFormat("yyyy-MM-dd ");
String time = sdf.format(date);
total.put("date",time);
for (String channel:channels){
if(total.getJSONObject(channel)==null){
total.put("date", time);
for (String channel : channels) {
if (total.getJSONObject(channel) == null) {
JSONObject mockAnalysis = new JSONObject();
mockAnalysis.put("exchange_rate",0);
mockAnalysis.put("date",time);
total.put(channel,mockAnalysis);
mockAnalysis.put("exchange_rate", 0);
mockAnalysis.put("date", time);
total.put(channel, mockAnalysis);
}
}
listChannelRate.add(total);
@ -469,17 +473,17 @@ public class DashboardServiceImpl implements DashboardService,DashboardAnalysisT
return listChannelRate;
}
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 = exchangeRateMapper.listExchangeRates(beginDate, endDate,channel);
for (JSONObject analysisItem:channelRates){
List<JSONObject> channelRates = exchangeRateMapper.listExchangeRates(beginDate, endDate, channel);
for (JSONObject analysisItem : channelRates) {
Date date = analysisItem.getDate("date");
JSONObject dataItem = exchangeRateMap.get(date);
if(dataItem==null){
if (dataItem == null) {
dataItem = new JSONObject();
exchangeRateMap.put(date,dataItem);
exchangeRateMap.put(date, dataItem);
}
dataItem.put(channel,analysisItem);
dataItem.put(channel, analysisItem);
}
}
@ -502,16 +506,16 @@ public class DashboardServiceImpl implements DashboardService,DashboardAnalysisT
public JSONObject getNewRecord() {
String jsonStr = stringRedisTemplate.boundValueOps("newRecord").get();
JSONObject newRecord = JSON.parseObject(jsonStr);
if(newRecord != null){
if (newRecord != null) {
return newRecord;
}
JSONObject max_amount = customerAndOrdersStatisticsMapper.getMaxAmount(0);
JSONObject max_orders = customerAndOrdersStatisticsMapper.getMaxOrders(0);
JSONObject maxTransactionPartners = customerAndOrdersStatisticsMapper.getMaxTransactionPartners();
JSONObject res = new JSONObject();
res.put("max_amount",max_amount);
res.put("max_orders",max_orders);
res.put("max_transaction_partners",maxTransactionPartners);
res.put("max_amount", max_amount);
res.put("max_orders", max_orders);
res.put("max_transaction_partners", maxTransactionPartners);
stringRedisTemplate.boundValueOps("newRecord").set(res.toJSONString(), 5, TimeUnit.MINUTES);
return res;
}
@ -523,29 +527,31 @@ public class DashboardServiceImpl implements DashboardService,DashboardAnalysisT
}
@Override
public void generateCustomersAndOrdersStatistics(Date analysisDate){
public void generateCustomersAndOrdersStatistics(Date analysisDate) {
DateFormat format = new SimpleDateFormat("yyyyMMdd");
String date = format.format(analysisDate);
List<JSONObject> clients =clientMapper.listClients();
for (JSONObject client:clients){
List<JSONObject> clients = clientMapper.listClients();
for (JSONObject client : clients) {
generateData(format, date, client);
}
JSONObject totalObject = new JSONObject();
totalObject.put("client_id",0);
generateData(format,date,totalObject);
totalObject.put("client_id", 0);
generateData(format, date, totalObject);
logger.info("generate customer and orders statistics on {} done", date);
}
/**
*
*
* @param analysisDate
* @param clientId
*/
public void generateCustomersAndOrdersStatisticsByClientMoniker(Date analysisDate,String clientId){
public void generateCustomersAndOrdersStatisticsByClientMoniker(Date analysisDate, String clientId) {
DateFormat format = new SimpleDateFormat("yyyyMMdd");
String date = format.format(analysisDate);
List<JSONObject> clients =clientMapper.listClients();
for (JSONObject client:clients){
if(client.getString("client_id").equals(clientId)){
List<JSONObject> clients = clientMapper.listClients();
for (JSONObject client : clients) {
if (client.getString("client_id").equals(clientId)) {
generateData(format, date, client);
}
}
@ -553,8 +559,8 @@ public class DashboardServiceImpl implements DashboardService,DashboardAnalysisT
private void generateData(DateFormat format, String date, JSONObject client) {
JSONObject params = new JSONObject();
String timezone =client.getString("timezone");
if (timezone!=null){
String timezone = client.getString("timezone");
if (timezone != null) {
format.setTimeZone(TimeZone.getTimeZone(timezone));
}
try {
@ -563,17 +569,17 @@ public class DashboardServiceImpl implements DashboardService,DashboardAnalysisT
} catch (ParseException e) {
throw new ParamInvalidException("date", "error.payment.valid.invalid_date_format");
}
if (client.getIntValue("client_id")!=0){
params.put("client_id",client.getIntValue("client_id"));
if (client.getIntValue("client_id") != 0) {
params.put("client_id", client.getIntValue("client_id"));
}
List<JSONObject> records = transactionAnalysisMapper.getCustomersAndOrdersInDaysUseInScheduled(params);
if (!records.isEmpty()){
if (!records.isEmpty()) {
JSONObject deleteParams = new JSONObject();
deleteParams.put("begin",params.getDate("begin"));
deleteParams.put("end",params.getDate("end"));
deleteParams.put("client_id",params.getIntValue("client_id"));
deleteParams.put("begin", params.getDate("begin"));
deleteParams.put("end", params.getDate("end"));
deleteParams.put("client_id", params.getIntValue("client_id"));
customerAndOrdersStatisticsMapper.delete(deleteParams);
for (JSONObject record:records){
for (JSONObject record : records) {
String sdate = format.format(record.getDate("date"));
try {
params.put("begin", format.parse(sdate));
@ -581,17 +587,17 @@ public class DashboardServiceImpl implements DashboardService,DashboardAnalysisT
} catch (ParseException e) {
throw new ParamInvalidException("date", "error.payment.valid.invalid_date_format");
}
params.put("channel",record.getString("channel"));
params.put("channel", record.getString("channel"));
int newCustomers = 0;
int oldCustomers = transactionAnalysisMapper.countOldCustomers(params);
if (client.getIntValue("client_id")==0){
newCustomers = record.getIntValue("customers")-oldCustomers;
}else {
if (client.getIntValue("client_id") == 0) {
newCustomers = record.getIntValue("customers") - oldCustomers;
} else {
newCustomers = transactionAnalysisMapper.countNewCustomers(params);
}
record.put("new_customers",newCustomers);
record.put("old_customers",oldCustomers);
record.put("client_id",client.getIntValue("client_id"));
record.put("new_customers", newCustomers);
record.put("old_customers", oldCustomers);
record.put("client_id", client.getIntValue("client_id"));
if (StringUtils.equalsIgnoreCase("rpaypmt_card", record.getString("channel")) || StringUtils.equalsIgnoreCase("rpaypmt_dd", record.getString("channel"))) {
record.put("single_amount", record.getBigDecimal("total").divide(record.getBigDecimal("orders"), 2, RoundingMode.HALF_UP));
}
@ -599,37 +605,40 @@ public class DashboardServiceImpl implements DashboardService,DashboardAnalysisT
}
}
}
@Override
public JSONObject getPlatformAmount(JSONObject params) {
String jsonStr = stringRedisTemplate.boundValueOps("org_ChannelAnalysis" + params.getString("org_id") + params.getString("begin")).get();
JSONObject channelAnalysis = JSON.parseObject(jsonStr);
if(channelAnalysis != null){
if (channelAnalysis != null) {
return channelAnalysis;
}else {
} else {
JSONObject resp;
if(params.getDate("end").compareTo(new Date()) > 0){
if(params.getDate("begin").compareTo(DateUtils.addDays(params.getDate("end"), -1))==0){
if (params.getDate("end").compareTo(new Date()) > 0) {
if (params.getDate("begin").compareTo(DateUtils.addDays(params.getDate("end"), -1)) == 0) {
resp = getTodayChannelCount(params);
}else {
} else {
resp = customerAndOrdersStatisticsMapper.getChannelCommonCount(params);
}
}else {
} else {
resp = customerAndOrdersStatisticsMapper.getChannelCommonCount(params);
}
stringRedisTemplate.boundValueOps("org_ChannelAnalysis"+ params.getString("org_id")+params.getString("begin")).set(resp.toJSONString(), 5, TimeUnit.MINUTES);
stringRedisTemplate.boundValueOps("org_ChannelAnalysis" + params.getString("org_id") + params.getString("begin")).set(resp.toJSONString(), 5, TimeUnit.MINUTES);
return resp;
}
}
private JSONObject getTodayChannelCount(JSONObject params){
String[] channels = new String[]{"Wechat", "Alipay", "AlipayOnline", "Rpay", "rpaypmt_card", "rpaypmt_dd"};
private JSONObject getTodayChannelCount(JSONObject params) {
String[] channels = new String[]{"Wechat", "Alipay", "AlipayOnline", "Rpay", "rpaypmt_card", "rpaypmt_dd"};
JSONObject resp = new JSONObject();
for(String channel:channels) {
for (String channel : channels) {
params.put("channel", channel);
resp.put(channel.toLowerCase()+"amount", transactionAnalysisMapper.getPlatformAmount(params).getBigDecimal("amount"));
resp.put(channel.toLowerCase()+"_order_count", transactionAnalysisMapper.getPlatformAmount(params).getIntValue("order_count"));
resp.put(channel.toLowerCase() + "amount", transactionAnalysisMapper.getPlatformAmount(params).getBigDecimal("amount"));
resp.put(channel.toLowerCase() + "_order_count", transactionAnalysisMapper.getPlatformAmount(params).getIntValue("order_count"));
}
return resp;
}
@Override
public JSONObject getOrderAndCustomerPerDay(JSONObject partner, AnalysisBean partnerAnalysisBean) {
String timezone = partner.getJSONObject("client").getString("timezone");

@ -441,11 +441,9 @@
</select>
<select id="countOldCustomers" resultType="java.lang.Integer">
<![CDATA[
SELECT COUNT(DISTINCT customer_id) FROM (SELECT o.customer_id FROM pmt_transactions t
INNER JOIN pmt_orders o ON o.order_id = t.order_id
]]>
<![CDATA[
WHERE o.create_time >= #{begin} AND o.create_time < #{end}
SELECT COUNT(customer_id) FROM (
SELECT o.customer_id,min(o.create_time) first_pay,max(o.create_time) last_pay FROM pmt_orders o
WHERE o.create_time < #{end} and o.status>4
]]>
<if test="client_ids!=null">
AND o.client_id IN
@ -456,29 +454,15 @@
<if test="client_ids==null and client_id != null">
and o.client_id=#{client_id}
</if>
<if test="org_id!=null and org_ids==null">and t.org_id=#{org_id}</if>
<if test="org_ids!=null">and t.org_id in
<if test="org_id!=null and org_ids==null">and o.org_id=#{org_id}</if>
<if test="org_ids!=null">and o.org_id in
<foreach collection="org_ids" item="org_id" open="(" close=")" separator=",">#{org_id}</foreach>
</if>
<if test="channel !=null">and o.channel = #{channel}</if>
<![CDATA[
GROUP BY o.customer_id) p
where p.customer_id IN (SELECT o.customer_id FROM pmt_transactions t INNER JOIN pmt_orders o ON o.order_id = t.order_id
]]>
<![CDATA[
WHERE o.create_time < #{begin}
]]>
<if test="client_ids!=null">
AND o.client_id IN
<foreach collection="client_ids" open="(" close=")" separator="," item="client_id">
#{client_id}
</foreach>
</if>
<if test="client_ids==null and client_id != null">
and o.client_id=#{client_id}
</if>
<![CDATA[
)
GROUP BY o.customer_id
having first_pay<#{begin} and last_pay>=#{begin}
) p
]]>
</select>

Loading…
Cancel
Save