Merge remote-tracking branch 'origin/develop' into develop

master
james.zhao 6 years ago
commit 473aa0adf9

@ -78,4 +78,11 @@ public interface TransactionAnalysisMapper {
List<JSONObject> getAreaMerchantAmountByCycle(JSONObject params);
JSONObject getOrderClearAmount(@Param("order_id") String order_id);
/**
* cny_amount
* @param params
* @return
*/
BigDecimal getCnyAmount(JSONObject params);
}

@ -0,0 +1,35 @@
package au.com.royalpay.payment.manage.dataAnalysis.core;
import com.alibaba.fastjson.JSONObject;
/**
* @Author lvjian
* @Date 2018/6/28 18:40
*/
public interface DataAnalysisService {
/**
* 1
* @param params
* @param response
* @return
*/
JSONObject getDataAnalysis1(JSONObject params, JSONObject response);
/**
* 2
* @param params
* @param response
* @return
*/
JSONObject getDataAnalysis2(JSONObject params, JSONObject response);
/**
*
* cny_amount
* @param params
* @param response
* @return
*/
JSONObject getCnyAmount(JSONObject params, JSONObject response);
}

@ -0,0 +1,65 @@
package au.com.royalpay.payment.manage.dataAnalysis.core;
import au.com.royalpay.payment.manage.analysis.mappers.ClientAnalysisMapper;
import au.com.royalpay.payment.manage.analysis.mappers.TransactionAnalysisMapper;
import com.alibaba.fastjson.JSONObject;
import com.github.miemiedev.mybatis.paginator.domain.Order;
import com.github.miemiedev.mybatis.paginator.domain.PageBounds;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
import javax.annotation.Resource;
import java.util.List;
/**
* @Author lvjian
* @Date 2018/6/28 18:42
*/
@Service
public class DataAnalysisServiceImpl implements DataAnalysisService {
@Resource
private ClientAnalysisMapper clientAnalysisMapper;
@Resource
private TransactionAnalysisMapper transactionAnalysisMapper;
@Override
public JSONObject getDataAnalysis1(JSONObject params, JSONObject response) {
//新加的商户数
response.put("new_partners", clientAnalysisMapper.countNewClients(params));
//总商户数
response.put("total_partners", clientAnalysisMapper.countClients(params));
//产生交易的商户数
response.put("traded_partners", clientAnalysisMapper.countTradedPartners(params));
//交易总额
response.put("trade_amount", transactionAnalysisMapper.analysisTotalAmount(params));
return response;
}
@Override
public JSONObject getDataAnalysis2(JSONObject params, JSONObject response) {
//交易笔数
response.put("trade_count", transactionAnalysisMapper.analysisTotalCount(params));
List<JSONObject> topOrders = transactionAnalysisMapper.getTopOrders(params);
//最大交易额
if (!topOrders.isEmpty()) {
response.put("max_order", topOrders.get(0).get("aud_fee"));
} else {
response.put("max_order", 0);
}
//总消费人数
response.put("total_customers", transactionAnalysisMapper.countCustomers(params));
//老客户人数
response.put("old_customers", transactionAnalysisMapper.countOldCustomers(params));
return response;
}
@Override
public JSONObject getCnyAmount(JSONObject params, JSONObject response) {
response.put("cny_amount", transactionAnalysisMapper.getCnyAmount(params));
return response;
}
}

@ -0,0 +1,27 @@
package au.com.royalpay.payment.manage.dataAnalysis.util;
import java.util.Calendar;
import java.util.Date;
/**
* @Author lvjian
* @Date 2018/6/28 18:34
*/
public class MyUtil {
/**
*
* @param date
* @return
*/
public static Date getYMD(Date date) {
Calendar calendar = Calendar.getInstance();
calendar.setTime(date);
calendar.set(Calendar.HOUR_OF_DAY, 0);
calendar.set(Calendar.MINUTE, 0);
calendar.set(Calendar.SECOND, 0);
calendar.set(Calendar.MILLISECOND, 0);
return calendar.getTime();
}
}

@ -0,0 +1,54 @@
package au.com.royalpay.payment.manage.dataAnalysis.web;
import au.com.royalpay.payment.manage.dataAnalysis.core.DataAnalysisService;
import au.com.royalpay.payment.manage.dataAnalysis.util.MyUtil;
import com.alibaba.fastjson.JSONObject;
import org.apache.commons.lang3.time.DateUtils;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestParam;
import org.springframework.web.bind.annotation.RestController;
import java.text.DateFormat;
import java.text.ParseException;
import java.text.SimpleDateFormat;
import java.util.Date;
/**
* @Author lvjian
* @Date 2018/6/28 18:32
*/
@RestController
@RequestMapping(value = "/out")
public class DataAnalysisController {
@Autowired
private DataAnalysisService dataAnalysisService;
@RequestMapping(value = "/data_analysis")
public JSONObject dataAnalysis(@RequestParam(value = "begin", required = false) String begin,
@RequestParam(value = "offset", defaultValue = "1") Integer offset) throws ParseException {
JSONObject params = new JSONObject();
if (begin == null) {
Date beginInit = MyUtil.getYMD(new Date());
Date endInit = DateUtils.addDays(beginInit,offset);
params.put("begin",beginInit);
params.put("end",endInit);
} else {
DateFormat format = new SimpleDateFormat("yyyyMMdd");
if (offset < 0) {
params.put("end", format.parse(begin));
params.put("begin", DateUtils.addDays(format.parse(begin),offset));
} else {
params.put("begin", format.parse(begin));
params.put("end", DateUtils.addDays(format.parse(begin),offset));
}
}
JSONObject response = new JSONObject();
response = dataAnalysisService.getDataAnalysis1(params,response);
response = dataAnalysisService.getDataAnalysis2(params,response);
response = dataAnalysisService.getCnyAmount(params, response);
return response;
}
}

@ -35,6 +35,29 @@
</where>
</select>
<!--统计cny_amount-->
<select id="getCnyAmount" resultType="java.math.BigDecimal">
<![CDATA[
SELECT ifnull(sum(if(l.transaction_type = 'Credit',l.cny_amount,-l.cny_amount)), 0)
FROM pmt_transactions l
INNER JOIN pmt_orders o ON o.order_id = l.order_id AND o.create_time >= #{begin} AND
o.create_time <= #{end}
WHERE (l.transaction_type = 'Credit' or l.refund_id is not null)
]]>
<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>
<if test="org_id!=null and org_ids==null">and l.org_id=#{org_id}</if>
<if test="org_ids!=null">and l.org_id in
<foreach collection="org_ids" item="org_id" open="(" close=")" separator=",">#{org_id}</foreach></if>
</select>
<select id="analysisTotalAmount" resultType="java.math.BigDecimal">
<![CDATA[
SELECT ifnull(sum(if(l.transaction_type = 'Credit',l.clearing_amount,-l.clearing_amount)), 0)
@ -871,4 +894,6 @@
WHERE o.order_id = #{order_id}
LIMIT 1;
</select>
</mapper>
Loading…
Cancel
Save