|
|
@ -32,6 +32,8 @@ import au.com.royalpay.payment.manage.mappers.system.CustomerMapper;
|
|
|
|
import au.com.royalpay.payment.manage.mappers.system.CustomerRelationAlipayMapper;
|
|
|
|
import au.com.royalpay.payment.manage.mappers.system.CustomerRelationAlipayMapper;
|
|
|
|
import au.com.royalpay.payment.tools.exceptions.BadRequestException;
|
|
|
|
import au.com.royalpay.payment.tools.exceptions.BadRequestException;
|
|
|
|
import au.com.royalpay.payment.tools.exceptions.NotFoundException;
|
|
|
|
import au.com.royalpay.payment.tools.exceptions.NotFoundException;
|
|
|
|
|
|
|
|
import au.com.royalpay.payment.tools.lock.Locker;
|
|
|
|
|
|
|
|
import au.com.royalpay.payment.tools.lock.LockerRedisImpl;
|
|
|
|
import au.com.royalpay.payment.tools.utils.PageListUtils;
|
|
|
|
import au.com.royalpay.payment.tools.utils.PageListUtils;
|
|
|
|
|
|
|
|
|
|
|
|
/**
|
|
|
|
/**
|
|
|
@ -50,7 +52,11 @@ public class CustomerImpressionServiceImpl implements CustomerImpressionService
|
|
|
|
@Resource
|
|
|
|
@Resource
|
|
|
|
private CustomerMapper customerMapper;
|
|
|
|
private CustomerMapper customerMapper;
|
|
|
|
@Resource
|
|
|
|
@Resource
|
|
|
|
|
|
|
|
private Locker locker;
|
|
|
|
|
|
|
|
@Resource
|
|
|
|
private StringRedisTemplate stringRedisTemplate;
|
|
|
|
private StringRedisTemplate stringRedisTemplate;
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
private static String CUSTOMER_IMPRESSION_PREFIX = "Customer_impression_insert";
|
|
|
|
Logger logger = LoggerFactory.getLogger(CustomerImpressionServiceImpl.class);
|
|
|
|
Logger logger = LoggerFactory.getLogger(CustomerImpressionServiceImpl.class);
|
|
|
|
|
|
|
|
|
|
|
|
@Override
|
|
|
|
@Override
|
|
|
@ -100,6 +106,11 @@ public class CustomerImpressionServiceImpl implements CustomerImpressionService
|
|
|
|
|
|
|
|
|
|
|
|
@Override
|
|
|
|
@Override
|
|
|
|
public void generate(int client_id) {
|
|
|
|
public void generate(int client_id) {
|
|
|
|
|
|
|
|
Date now = new Date();
|
|
|
|
|
|
|
|
DateTime dt = new DateTime(2018, 1, 20, 0, 0);
|
|
|
|
|
|
|
|
if (now.compareTo(dt.toDate()) > 0) {
|
|
|
|
|
|
|
|
return;
|
|
|
|
|
|
|
|
}
|
|
|
|
JSONObject params = new JSONObject();
|
|
|
|
JSONObject params = new JSONObject();
|
|
|
|
params.put("client_id", client_id);
|
|
|
|
params.put("client_id", client_id);
|
|
|
|
params.put("include_success_status", 3);
|
|
|
|
params.put("include_success_status", 3);
|
|
|
@ -108,18 +119,20 @@ public class CustomerImpressionServiceImpl implements CustomerImpressionService
|
|
|
|
params.put("confirm_time", lastRecord.get(0).getDate("update_time"));
|
|
|
|
params.put("confirm_time", lastRecord.get(0).getDate("update_time"));
|
|
|
|
}
|
|
|
|
}
|
|
|
|
List<JSONObject> orders = orderMapper.listAnalysisClientCustomer(params);
|
|
|
|
List<JSONObject> orders = orderMapper.listAnalysisClientCustomer(params);
|
|
|
|
Date now = new Date();
|
|
|
|
|
|
|
|
for (JSONObject order : orders) {
|
|
|
|
for (JSONObject order : orders) {
|
|
|
|
if (StringUtils.isEmpty(order.getString("channel"))) {
|
|
|
|
if (StringUtils.isEmpty(order.getString("channel"))) {
|
|
|
|
continue;
|
|
|
|
continue;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
JSONObject userInfo = customerMapper.findCustomerByOpenId(order.getString("customer_id"));
|
|
|
|
String customer_id = order.getString("customer_id");
|
|
|
|
|
|
|
|
JSONObject userInfo = customerMapper.findCustomerByOpenId(customer_id);
|
|
|
|
if (userInfo == null) {
|
|
|
|
if (userInfo == null) {
|
|
|
|
userInfo = customerRelationAlipayMapper.findCustomerByUserId(order.getString("customer_id"));
|
|
|
|
userInfo = customerRelationAlipayMapper.findCustomerByUserId(customer_id);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
JSONObject clientCustomerInfo = clientCustomersMapper.getClientCustomerWithNull(client_id, order.getString("customer_id"));
|
|
|
|
JSONObject clientCustomerInfo = clientCustomersMapper.getClientCustomerWithNull(client_id, customer_id);
|
|
|
|
if (clientCustomerInfo == null) {
|
|
|
|
if (clientCustomerInfo == null) {
|
|
|
|
|
|
|
|
locker.lock(CUSTOMER_IMPRESSION_PREFIX+customer_id, 30_000, 30_000);
|
|
|
|
|
|
|
|
try {
|
|
|
|
JSONObject client_customer = new JSONObject();
|
|
|
|
JSONObject client_customer = new JSONObject();
|
|
|
|
client_customer.put("client_id", order.getIntValue("client_id"));
|
|
|
|
client_customer.put("client_id", order.getIntValue("client_id"));
|
|
|
|
client_customer.put("customer_id", order.getString("customer_id"));
|
|
|
|
client_customer.put("customer_id", order.getString("customer_id"));
|
|
|
@ -134,23 +147,21 @@ public class CustomerImpressionServiceImpl implements CustomerImpressionService
|
|
|
|
client_customer.put("update_time", now);
|
|
|
|
client_customer.put("update_time", now);
|
|
|
|
client_customer.put("last_payment_time", order.getDate("confirm_time"));
|
|
|
|
client_customer.put("last_payment_time", order.getDate("confirm_time"));
|
|
|
|
clientCustomersMapper.insert(client_customer);
|
|
|
|
clientCustomersMapper.insert(client_customer);
|
|
|
|
|
|
|
|
} finally {
|
|
|
|
|
|
|
|
locker.unlock(customer_id);
|
|
|
|
|
|
|
|
}
|
|
|
|
} else {
|
|
|
|
} else {
|
|
|
|
clientCustomerInfo.put("payment_times", clientCustomerInfo.getIntValue("payment_times") + order.getIntValue("payment_times"));
|
|
|
|
clientCustomerInfo.put("payment_times", clientCustomerInfo.getIntValue("payment_times") + order.getIntValue("payment_times"));
|
|
|
|
BigDecimal total_amount = clientCustomerInfo.getBigDecimal("total_amount");
|
|
|
|
clientCustomerInfo.put("payment_times", order.getIntValue("payment_times"));
|
|
|
|
if (total_amount != null) {
|
|
|
|
clientCustomerInfo.put("client_id", order.getIntValue("client_id"));
|
|
|
|
clientCustomerInfo.put("total_amount", clientCustomerInfo.getBigDecimal("total_amount").add(order.getBigDecimal("total_amount")));
|
|
|
|
clientCustomerInfo.put("customer_id", order.getString("customer_id"));
|
|
|
|
} else {
|
|
|
|
|
|
|
|
clientCustomerInfo.put("total_amount", order.getBigDecimal("total_amount"));
|
|
|
|
clientCustomerInfo.put("total_amount", order.getBigDecimal("total_amount"));
|
|
|
|
}
|
|
|
|
|
|
|
|
if (userInfo != null) {
|
|
|
|
if (userInfo != null) {
|
|
|
|
clientCustomerInfo.put("headimg", userInfo.getString("headimg"));
|
|
|
|
clientCustomerInfo.put("headimg", userInfo.getString("headimg"));
|
|
|
|
clientCustomerInfo.put("nick_name", userInfo.getString("nickname"));
|
|
|
|
clientCustomerInfo.put("nick_name", userInfo.getString("nickname"));
|
|
|
|
}
|
|
|
|
}
|
|
|
|
clientCustomerInfo.put("channel", order.getString("channel"));
|
|
|
|
|
|
|
|
clientCustomerInfo.put("tag", "不活跃用户");
|
|
|
|
|
|
|
|
clientCustomerInfo.put("update_time", now);
|
|
|
|
|
|
|
|
clientCustomerInfo.put("last_payment_time", order.getDate("confirm_time"));
|
|
|
|
clientCustomerInfo.put("last_payment_time", order.getDate("confirm_time"));
|
|
|
|
clientCustomersMapper.update(clientCustomerInfo);
|
|
|
|
clientCustomersMapper.updateAfterPaymentFinish(clientCustomerInfo);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
@ -160,7 +171,7 @@ public class CustomerImpressionServiceImpl implements CustomerImpressionService
|
|
|
|
public void generateTag(int client_id) {
|
|
|
|
public void generateTag(int client_id) {
|
|
|
|
JSONObject params = new JSONObject();
|
|
|
|
JSONObject params = new JSONObject();
|
|
|
|
DateTime dt = new DateTime();
|
|
|
|
DateTime dt = new DateTime();
|
|
|
|
dt = dt.minusMonths(5);
|
|
|
|
dt = dt.minusMonths(1);
|
|
|
|
params.put("confirm_time", dt.toDate());
|
|
|
|
params.put("confirm_time", dt.toDate());
|
|
|
|
params.put("client_id", client_id);
|
|
|
|
params.put("client_id", client_id);
|
|
|
|
List<JSONObject> orders = orderMapper.listAnalysisClientCustomer(params);
|
|
|
|
List<JSONObject> orders = orderMapper.listAnalysisClientCustomer(params);
|
|
|
@ -200,12 +211,15 @@ public class CustomerImpressionServiceImpl implements CustomerImpressionService
|
|
|
|
if (StringUtils.isEmpty(order.getString("channel"))) {
|
|
|
|
if (StringUtils.isEmpty(order.getString("channel"))) {
|
|
|
|
continue;
|
|
|
|
continue;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
JSONObject userInfo = customerMapper.findCustomerByOpenId(order.getString("customer_id"));
|
|
|
|
String customer_id = order.getString("customer_id");
|
|
|
|
|
|
|
|
JSONObject userInfo = customerMapper.findCustomerByOpenId(customer_id);
|
|
|
|
if (userInfo == null) {
|
|
|
|
if (userInfo == null) {
|
|
|
|
userInfo = customerRelationAlipayMapper.findCustomerByUserId(order.getString("customer_id"));
|
|
|
|
userInfo = customerRelationAlipayMapper.findCustomerByUserId(customer_id);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
JSONObject clientCustomerInfo = clientCustomersMapper.getClientCustomerWithNull(order.getIntValue("client_id"), order.getString("customer_id"));
|
|
|
|
JSONObject clientCustomerInfo = clientCustomersMapper.getClientCustomerWithNull(order.getIntValue("client_id"), customer_id);
|
|
|
|
if (clientCustomerInfo == null) {
|
|
|
|
if (clientCustomerInfo == null) {
|
|
|
|
|
|
|
|
locker.lock(CUSTOMER_IMPRESSION_PREFIX+customer_id, 30_000, 30_000);
|
|
|
|
|
|
|
|
try {
|
|
|
|
JSONObject client_customer = new JSONObject();
|
|
|
|
JSONObject client_customer = new JSONObject();
|
|
|
|
client_customer.put("client_id", order.getIntValue("client_id"));
|
|
|
|
client_customer.put("client_id", order.getIntValue("client_id"));
|
|
|
|
client_customer.put("customer_id", order.getString("customer_id"));
|
|
|
|
client_customer.put("customer_id", order.getString("customer_id"));
|
|
|
@ -219,8 +233,13 @@ public class CustomerImpressionServiceImpl implements CustomerImpressionService
|
|
|
|
client_customer.put("total_amount", order.getBigDecimal("total_amount"));
|
|
|
|
client_customer.put("total_amount", order.getBigDecimal("total_amount"));
|
|
|
|
client_customer.put("last_payment_time", order.getDate("confirm_time"));
|
|
|
|
client_customer.put("last_payment_time", order.getDate("confirm_time"));
|
|
|
|
clientCustomersMapper.insert(client_customer);
|
|
|
|
clientCustomersMapper.insert(client_customer);
|
|
|
|
|
|
|
|
} finally {
|
|
|
|
|
|
|
|
locker.unlock(customer_id);
|
|
|
|
|
|
|
|
}
|
|
|
|
} else {
|
|
|
|
} else {
|
|
|
|
clientCustomerInfo.put("payment_times", 1);
|
|
|
|
clientCustomerInfo.put("payment_times", 1);
|
|
|
|
|
|
|
|
clientCustomerInfo.put("client_id", order.getIntValue("client_id"));
|
|
|
|
|
|
|
|
clientCustomerInfo.put("customer_id", order.getString("customer_id"));
|
|
|
|
clientCustomerInfo.put("total_amount", order.getBigDecimal("total_amount"));
|
|
|
|
clientCustomerInfo.put("total_amount", order.getBigDecimal("total_amount"));
|
|
|
|
if (userInfo != null) {
|
|
|
|
if (userInfo != null) {
|
|
|
|
clientCustomerInfo.put("headimg", userInfo.getString("headimg"));
|
|
|
|
clientCustomerInfo.put("headimg", userInfo.getString("headimg"));
|
|
|
@ -244,5 +263,4 @@ public class CustomerImpressionServiceImpl implements CustomerImpressionService
|
|
|
|
clientCustomerInfo.put("name_remak", name_remark);
|
|
|
|
clientCustomerInfo.put("name_remak", name_remark);
|
|
|
|
clientCustomersMapper.update(clientCustomerInfo);
|
|
|
|
clientCustomersMapper.update(clientCustomerInfo);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
}
|
|
|
|
}
|