parent
4ceef6abb1
commit
1b48cd65f3
@ -0,0 +1,100 @@
|
||||
package au.com.royalpay.payment.manage.apps.bean;
|
||||
|
||||
import com.alibaba.fastjson.JSONObject;
|
||||
|
||||
import java.math.BigDecimal;
|
||||
|
||||
/**
|
||||
* Created by wangning on 2017/12/28.
|
||||
*/
|
||||
public class CustomerImpressionQuery {
|
||||
private int payment_times;
|
||||
private BigDecimal amount_begin;
|
||||
private BigDecimal amount_end;
|
||||
private String order;
|
||||
private int client_id;
|
||||
private int page = 1;
|
||||
private int limit = 10;
|
||||
|
||||
public JSONObject toParam(){
|
||||
JSONObject param = new JSONObject();
|
||||
param.put("payment_times",this.payment_times);
|
||||
param.put("amount_begin",this.amount_begin);
|
||||
param.put("amount_end",this.amount_end);
|
||||
param.put("order",this.order);
|
||||
param.put("client_id",this.client_id);
|
||||
return param;
|
||||
}
|
||||
public int getPayment_times() {
|
||||
return payment_times;
|
||||
}
|
||||
|
||||
public void setPayment_times(int payment_times) {
|
||||
this.payment_times = payment_times;
|
||||
}
|
||||
|
||||
public BigDecimal getamount_begin() {
|
||||
return amount_begin;
|
||||
}
|
||||
|
||||
public void setamount_begin(BigDecimal amount_begin) {
|
||||
this.amount_begin = amount_begin;
|
||||
}
|
||||
|
||||
public BigDecimal getamount_end() {
|
||||
return amount_end;
|
||||
}
|
||||
|
||||
public void setamount_end(BigDecimal amount_end) {
|
||||
this.amount_end = amount_end;
|
||||
}
|
||||
|
||||
public String getOrder() {
|
||||
return order;
|
||||
}
|
||||
|
||||
public void setOrder(String order) {
|
||||
this.order = order;
|
||||
}
|
||||
|
||||
public BigDecimal getAmount_begin() {
|
||||
return amount_begin;
|
||||
}
|
||||
|
||||
public void setAmount_begin(BigDecimal amount_begin) {
|
||||
this.amount_begin = amount_begin;
|
||||
}
|
||||
|
||||
public BigDecimal getAmount_end() {
|
||||
return amount_end;
|
||||
}
|
||||
|
||||
public void setAmount_end(BigDecimal amount_end) {
|
||||
this.amount_end = amount_end;
|
||||
}
|
||||
|
||||
public int getPage() {
|
||||
return page;
|
||||
}
|
||||
|
||||
public void setPage(int page) {
|
||||
this.page = page;
|
||||
}
|
||||
|
||||
public int getLimit() {
|
||||
return limit;
|
||||
}
|
||||
|
||||
public void setLimit(int limit) {
|
||||
this.limit = limit;
|
||||
}
|
||||
|
||||
public int getClient_id() {
|
||||
return client_id;
|
||||
}
|
||||
|
||||
public void setClient_id(int client_id) {
|
||||
this.client_id = client_id;
|
||||
}
|
||||
}
|
||||
|
@ -0,0 +1,17 @@
|
||||
package au.com.royalpay.payment.manage.apps.core;
|
||||
|
||||
import au.com.royalpay.payment.manage.apps.bean.CustomerImpressionQuery;
|
||||
|
||||
import com.alibaba.fastjson.JSONObject;
|
||||
|
||||
/**
|
||||
* Created by wangning on 2017/12/28.
|
||||
*/
|
||||
public interface CustomerImpression {
|
||||
|
||||
JSONObject listPageble(CustomerImpressionQuery customerImpressionQuery);
|
||||
|
||||
JSONObject findOne(int client_id,String customer_id);
|
||||
|
||||
void generate(int client_id);
|
||||
}
|
@ -0,0 +1,118 @@
|
||||
package au.com.royalpay.payment.manage.apps.core.impls;
|
||||
|
||||
import java.util.Date;
|
||||
import java.util.List;
|
||||
|
||||
import javax.annotation.Resource;
|
||||
|
||||
import org.apache.commons.lang.StringUtils;
|
||||
import org.apache.commons.lang.time.DateFormatUtils;
|
||||
import org.springframework.stereotype.Service;
|
||||
import org.springframework.transaction.annotation.Transactional;
|
||||
import org.springframework.util.CollectionUtils;
|
||||
|
||||
import com.alibaba.fastjson.JSONObject;
|
||||
import com.github.miemiedev.mybatis.paginator.domain.Order;
|
||||
import com.github.miemiedev.mybatis.paginator.domain.PageBounds;
|
||||
import com.github.miemiedev.mybatis.paginator.domain.PageList;
|
||||
import com.maxmind.geoip.LookupService;
|
||||
|
||||
import au.com.royalpay.payment.manage.apps.bean.CustomerImpressionQuery;
|
||||
import au.com.royalpay.payment.manage.apps.core.CustomerImpression;
|
||||
import au.com.royalpay.payment.manage.mappers.client.ClientCustomersMapper;
|
||||
import au.com.royalpay.payment.manage.mappers.payment.OrderMapper;
|
||||
import au.com.royalpay.payment.tools.exceptions.BadRequestException;
|
||||
import au.com.royalpay.payment.tools.utils.PageListUtils;
|
||||
|
||||
/**
|
||||
* Created by wangning on 2017/12/28.
|
||||
*/
|
||||
@Service
|
||||
public class CustomerImpressionImpl implements CustomerImpression {
|
||||
@Resource
|
||||
private ClientCustomersMapper clientCustomersMapper;
|
||||
@Resource
|
||||
private OrderMapper orderMapper;
|
||||
@Resource
|
||||
private LookupService lookupService;
|
||||
|
||||
@Override
|
||||
public JSONObject listPageble(CustomerImpressionQuery customerImpressionQuery) {
|
||||
PageList<JSONObject> logs = clientCustomersMapper.listCustomerInfo(customerImpressionQuery.toParam(),
|
||||
new PageBounds(customerImpressionQuery.getPage(), customerImpressionQuery.getLimit(), Order.formString(customerImpressionQuery.getOrder())));
|
||||
return PageListUtils.buildPageListResult(logs);
|
||||
}
|
||||
|
||||
@Override
|
||||
public JSONObject findOne(int client_id, String customer_id) {
|
||||
JSONObject customer = clientCustomersMapper.getClientCustomerWithNull(client_id, customer_id);
|
||||
if(customer==null){
|
||||
throw new BadRequestException("customer info not exist");
|
||||
}
|
||||
JSONObject params = new JSONObject();
|
||||
params.put("customer_id", customer_id);
|
||||
PageList<JSONObject> ordersLast = orderMapper.listOrderByCustomer(params, new PageBounds(1, 1, Order.formString("create_time.desc")));
|
||||
if (!CollectionUtils.isEmpty(ordersLast)) {
|
||||
JSONObject order = ordersLast.get(0);
|
||||
customer.put("last_pay_time", DateFormatUtils.format(order.getDate("create_time"), "yyyy-MM-dd HH:mm:ss"));
|
||||
customer.put("last_pay_location", lookupService.getLocation(order.getString("customer_ip")).city);
|
||||
}
|
||||
PageList<JSONObject> ordersFirst = orderMapper.listOrderByCustomer(params, new PageBounds(1, 1, Order.formString("create_time.asc")));
|
||||
if (!CollectionUtils.isEmpty(ordersFirst)) {
|
||||
JSONObject order = ordersFirst.get(0);
|
||||
customer.put("first_pay_time", DateFormatUtils.format(order.getDate("create_time"), "yyyy-MM-dd HH:mm:ss"));
|
||||
customer.put("first_pay_location", lookupService.getLocation(order.getString("customer_ip")).city);
|
||||
|
||||
}
|
||||
return customer;
|
||||
}
|
||||
|
||||
@Override
|
||||
@Transactional
|
||||
public void generate(int client_id) {
|
||||
JSONObject params = new JSONObject();
|
||||
params.put("client_id", client_id);
|
||||
PageList<JSONObject> lastRecord = clientCustomersMapper.listCustomerInfo(params, new PageBounds(1, 1, Order.formString("create_time.desc")));
|
||||
if (!CollectionUtils.isEmpty(lastRecord)) {
|
||||
params.put("confirm_time", lastRecord.get(0).getDate("creata_time"));
|
||||
}
|
||||
List<JSONObject> orders = orderMapper.listAnalysisClientCustomer(params);
|
||||
Date now = new Date();
|
||||
for (JSONObject order : orders) {
|
||||
if(StringUtils.isEmpty(order.getString("channel"))){
|
||||
continue;
|
||||
}
|
||||
JSONObject clientCustomerInfo = clientCustomersMapper.getClientCustomerWithNull(client_id, order.getString("customer_id"));
|
||||
if (clientCustomerInfo == null) {
|
||||
JSONObject client_customer = new JSONObject();
|
||||
client_customer.put("client_id", order.getIntValue("client_id"));
|
||||
client_customer.put("customer_id", order.getString("customer_id"));
|
||||
client_customer.put("channel", order.getString("channel"));
|
||||
if (order.getString("alipay_headimg") == null) {
|
||||
client_customer.put("headimg", order.getString("wechat_headimg"));
|
||||
client_customer.put("nick_name", order.getString("wechat_nickname"));
|
||||
} else {
|
||||
client_customer.put("headimg", order.getString("alipay_headimg"));
|
||||
client_customer.put("nick_name", order.getString("alipay_nickname"));
|
||||
}
|
||||
client_customer.put("payment_times", order.getIntValue("payment_times"));
|
||||
client_customer.put("total_amount", order.getBigDecimal("total_amount"));
|
||||
client_customer.put("create_time", now);
|
||||
clientCustomersMapper.insert(client_customer);
|
||||
} else {
|
||||
clientCustomerInfo.put("payment_times", clientCustomerInfo.getIntValue("payment_times") + order.getIntValue("payment_times"));
|
||||
clientCustomerInfo.put("total_amount", clientCustomerInfo.getBigDecimal("total_amount").add(order.getBigDecimal("total_amount")));
|
||||
if (order.getString("alipay_headimg") == null) {
|
||||
clientCustomerInfo.put("headimg", order.getString("wechat_headimg"));
|
||||
clientCustomerInfo.put("nick_name", order.getString("wechat_nickname"));
|
||||
} else {
|
||||
clientCustomerInfo.put("headimg", order.getString("alipay_headimg"));
|
||||
clientCustomerInfo.put("nick_name", order.getString("alipay_nickname"));
|
||||
}
|
||||
clientCustomerInfo.put("channel", order.getString("channel"));
|
||||
clientCustomersMapper.update(clientCustomerInfo);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
}
|
@ -0,0 +1,36 @@
|
||||
package au.com.royalpay.payment.manage.apps.web;
|
||||
|
||||
import au.com.royalpay.payment.manage.apps.bean.CustomerImpressionQuery;
|
||||
import au.com.royalpay.payment.manage.apps.core.CustomerImpression;
|
||||
|
||||
import com.alibaba.fastjson.JSONObject;
|
||||
|
||||
import org.springframework.web.bind.annotation.PathVariable;
|
||||
import org.springframework.web.bind.annotation.RequestMapping;
|
||||
import org.springframework.web.bind.annotation.RequestMethod;
|
||||
import org.springframework.web.bind.annotation.ResponseBody;
|
||||
import org.springframework.web.bind.annotation.RestController;
|
||||
|
||||
import javax.annotation.Resource;
|
||||
|
||||
@RestController
|
||||
@RequestMapping(value = "/customers/impression")
|
||||
public class CustomerImpressionController {
|
||||
@Resource
|
||||
private CustomerImpression customerImpression;
|
||||
|
||||
@RequestMapping(value = "/list", method = RequestMethod.GET)
|
||||
@ResponseBody
|
||||
public JSONObject checkPointsAfterPay(CustomerImpressionQuery customerImpressionQuery) {
|
||||
return customerImpression.listPageble(customerImpressionQuery);
|
||||
}
|
||||
|
||||
|
||||
@RequestMapping(value = "/{client_id}/{customer_id}", method = RequestMethod.GET)
|
||||
@ResponseBody
|
||||
public JSONObject checkPointsAfterPay(@PathVariable int client_id,@PathVariable String customer_id) {
|
||||
customerImpression.generate(9);
|
||||
// return customerImpression.findOne(client_id,customer_id);
|
||||
return null;
|
||||
}
|
||||
}
|
@ -0,0 +1,28 @@
|
||||
<?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.client.ClientCustomersMapper">
|
||||
<select id="listCustomerInfo" resultType="com.alibaba.fastjson.JSONObject">
|
||||
SELECT
|
||||
*
|
||||
FROM sys_clients_customers
|
||||
where
|
||||
client_id = #{client_id}
|
||||
<if test="payment_times >0">
|
||||
and payment_times = #{payment_times}
|
||||
</if>
|
||||
<if test="amount_begin != null">
|
||||
and total_amount > #{amount_begin}
|
||||
</if>
|
||||
<if test="amount_end != null">
|
||||
and total_amount <=#{amount_end}
|
||||
</if>
|
||||
</select>
|
||||
|
||||
<select id="getClientCustomerWithNull" resultType="com.alibaba.fastjson.JSONObject">
|
||||
select *
|
||||
FROM sys_clients_customers
|
||||
where client_id = #{client_id}
|
||||
and customer_id = #{customer_id}
|
||||
|
||||
</select>
|
||||
</mapper>
|
Loading…
Reference in new issue