|
|
|
@ -1,8 +1,6 @@
|
|
|
|
|
package au.com.royalpay.payment.manage.apps.core.impls;
|
|
|
|
|
|
|
|
|
|
import java.math.BigDecimal;
|
|
|
|
|
import java.util.ArrayList;
|
|
|
|
|
import java.util.Date;
|
|
|
|
|
import java.util.List;
|
|
|
|
|
|
|
|
|
|
import javax.annotation.Resource;
|
|
|
|
@ -10,6 +8,10 @@ import javax.annotation.Resource;
|
|
|
|
|
import org.apache.commons.lang3.StringUtils;
|
|
|
|
|
import org.apache.commons.lang3.time.DateFormatUtils;
|
|
|
|
|
import org.joda.time.DateTime;
|
|
|
|
|
import org.slf4j.Logger;
|
|
|
|
|
import org.slf4j.LoggerFactory;
|
|
|
|
|
import org.springframework.data.redis.core.BoundListOperations;
|
|
|
|
|
import org.springframework.data.redis.core.StringRedisTemplate;
|
|
|
|
|
import org.springframework.stereotype.Service;
|
|
|
|
|
import org.springframework.transaction.annotation.Transactional;
|
|
|
|
|
import org.springframework.util.CollectionUtils;
|
|
|
|
@ -45,6 +47,9 @@ public class CustomerImpressionServiceImpl implements CustomerImpressionService
|
|
|
|
|
private CustomerRelationAlipayMapper customerRelationAlipayMapper;
|
|
|
|
|
@Resource
|
|
|
|
|
private CustomerMapper customerMapper;
|
|
|
|
|
@Resource
|
|
|
|
|
private StringRedisTemplate stringRedisTemplate;
|
|
|
|
|
Logger logger = LoggerFactory.getLogger(CustomerImpressionServiceImpl.class);
|
|
|
|
|
|
|
|
|
|
@Override
|
|
|
|
|
public JSONObject listPageble(CustomerImpressionQuery customerImpressionQuery) {
|
|
|
|
@ -91,66 +96,72 @@ public class CustomerImpressionServiceImpl implements CustomerImpressionService
|
|
|
|
|
return customer;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
// @Override
|
|
|
|
|
// @Transactional
|
|
|
|
|
// public void generate(int client_id) {
|
|
|
|
|
// JSONObject params = new JSONObject();
|
|
|
|
|
// params.put("client_id", client_id);
|
|
|
|
|
// params.put("include_success_status", 3);
|
|
|
|
|
// PageList<JSONObject> lastRecord = clientCustomersMapper.listCustomerInfo(params, new PageBounds(1, 1,
|
|
|
|
|
// Order.formString("update_time.desc")));
|
|
|
|
|
// if (!CollectionUtils.isEmpty(lastRecord)) {
|
|
|
|
|
// params.put("confirm_time", lastRecord.get(0).getDate("update_time"));
|
|
|
|
|
// }
|
|
|
|
|
// List<JSONObject> orders = orderMapper.listAnalysisClientCustomer(params);
|
|
|
|
|
// Date now = new Date();
|
|
|
|
|
// for (JSONObject order : orders) {
|
|
|
|
|
// if (StringUtils.isEmpty(order.getString("channel"))) {
|
|
|
|
|
// continue;
|
|
|
|
|
// }
|
|
|
|
|
// JSONObject userInfo = customerMapper.findCustomerByOpenId(order.getString("customer_id"));
|
|
|
|
|
// if (userInfo == null) {
|
|
|
|
|
// userInfo = customerRelationAlipayMapper.findCustomerByUserId(order.getString("customer_id"));
|
|
|
|
|
// }
|
|
|
|
|
//
|
|
|
|
|
// 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"));
|
|
|
|
|
// client_customer.put("tag", "不活跃用户");
|
|
|
|
|
// if (userInfo != null) {
|
|
|
|
|
// client_customer.put("headimg", userInfo.getString("headimg"));
|
|
|
|
|
// client_customer.put("nick_name", userInfo.getString("nickname"));
|
|
|
|
|
// }
|
|
|
|
|
// client_customer.put("payment_times", order.getIntValue("payment_times"));
|
|
|
|
|
// client_customer.put("total_amount", order.getBigDecimal("total_amount"));
|
|
|
|
|
// client_customer.put("update_time", now);
|
|
|
|
|
// client_customer.put("last_payment_time", order.getDate("confirm_time"));
|
|
|
|
|
// clientCustomersMapper.insert(client_customer);
|
|
|
|
|
// } else {
|
|
|
|
|
// clientCustomerInfo.put("payment_times", clientCustomerInfo.getIntValue("payment_times") +
|
|
|
|
|
// order.getIntValue("payment_times"));
|
|
|
|
|
// BigDecimal total_amount = clientCustomerInfo.getBigDecimal("total_amount");
|
|
|
|
|
// if (total_amount != null) {
|
|
|
|
|
// clientCustomerInfo.put("total_amount",
|
|
|
|
|
// clientCustomerInfo.getBigDecimal("total_amount").add(order.getBigDecimal("total_amount")));
|
|
|
|
|
// } else {
|
|
|
|
|
// clientCustomerInfo.put("total_amount", order.getBigDecimal("total_amount"));
|
|
|
|
|
// }
|
|
|
|
|
// if (userInfo != null) {
|
|
|
|
|
// clientCustomerInfo.put("headimg", userInfo.getString("headimg"));
|
|
|
|
|
// 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"));
|
|
|
|
|
// clientCustomersMapper.update(clientCustomerInfo);
|
|
|
|
|
// }
|
|
|
|
|
// }
|
|
|
|
|
// generateTag(client_id);
|
|
|
|
|
// }
|
|
|
|
|
|
|
|
|
|
@Override
|
|
|
|
|
@Transactional
|
|
|
|
|
public void generate(int client_id) {
|
|
|
|
|
JSONObject params = new JSONObject();
|
|
|
|
|
params.put("client_id", client_id);
|
|
|
|
|
params.put("include_success_status", 3);
|
|
|
|
|
PageList<JSONObject> lastRecord = clientCustomersMapper.listCustomerInfo(params, new PageBounds(1, 1, Order.formString("update_time.desc")));
|
|
|
|
|
if (!CollectionUtils.isEmpty(lastRecord)) {
|
|
|
|
|
params.put("confirm_time", lastRecord.get(0).getDate("update_time"));
|
|
|
|
|
}
|
|
|
|
|
List<JSONObject> orders = orderMapper.listAnalysisClientCustomer(params);
|
|
|
|
|
Date now = new Date();
|
|
|
|
|
for (JSONObject order : orders) {
|
|
|
|
|
if (StringUtils.isEmpty(order.getString("channel"))) {
|
|
|
|
|
continue;
|
|
|
|
|
}
|
|
|
|
|
JSONObject userInfo = customerMapper.findCustomerByOpenId(order.getString("customer_id"));
|
|
|
|
|
if (userInfo == null) {
|
|
|
|
|
userInfo = customerRelationAlipayMapper.findCustomerByUserId(order.getString("customer_id"));
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
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"));
|
|
|
|
|
client_customer.put("tag", "不活跃用户");
|
|
|
|
|
if (userInfo != null) {
|
|
|
|
|
client_customer.put("headimg", userInfo.getString("headimg"));
|
|
|
|
|
client_customer.put("nick_name", userInfo.getString("nickname"));
|
|
|
|
|
}
|
|
|
|
|
client_customer.put("payment_times", order.getIntValue("payment_times"));
|
|
|
|
|
client_customer.put("total_amount", order.getBigDecimal("total_amount"));
|
|
|
|
|
client_customer.put("update_time", now);
|
|
|
|
|
client_customer.put("last_payment_time", order.getDate("confirm_time"));
|
|
|
|
|
clientCustomersMapper.insert(client_customer);
|
|
|
|
|
} else {
|
|
|
|
|
clientCustomerInfo.put("payment_times", clientCustomerInfo.getIntValue("payment_times") + order.getIntValue("payment_times"));
|
|
|
|
|
BigDecimal total_amount = clientCustomerInfo.getBigDecimal("total_amount");
|
|
|
|
|
if (total_amount != null) {
|
|
|
|
|
clientCustomerInfo.put("total_amount", clientCustomerInfo.getBigDecimal("total_amount").add(order.getBigDecimal("total_amount")));
|
|
|
|
|
} else {
|
|
|
|
|
clientCustomerInfo.put("total_amount", order.getBigDecimal("total_amount"));
|
|
|
|
|
}
|
|
|
|
|
if (userInfo != null) {
|
|
|
|
|
clientCustomerInfo.put("headimg", userInfo.getString("headimg"));
|
|
|
|
|
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"));
|
|
|
|
|
clientCustomersMapper.update(clientCustomerInfo);
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
generateTag(client_id);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
private void generateTag(int client_id) {
|
|
|
|
|
public void generateTag(int client_id) {
|
|
|
|
|
JSONObject params = new JSONObject();
|
|
|
|
|
DateTime dt = new DateTime();
|
|
|
|
|
dt = dt.minusMonths(5);
|
|
|
|
@ -176,6 +187,53 @@ public class CustomerImpressionServiceImpl implements CustomerImpressionService
|
|
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
@Override
|
|
|
|
|
public void generateInfo() {
|
|
|
|
|
BoundListOperations<String, String> ops = stringRedisTemplate.boundListOps("customer_impression");
|
|
|
|
|
String redisValue = ops.leftPop();
|
|
|
|
|
|
|
|
|
|
while (!StringUtils.isEmpty(redisValue)) {
|
|
|
|
|
try {
|
|
|
|
|
JSONObject order = JSONObject.parseObject(redisValue);
|
|
|
|
|
redisValue = ops.leftPop();
|
|
|
|
|
if (StringUtils.isEmpty(order.getString("channel"))) {
|
|
|
|
|
continue;
|
|
|
|
|
}
|
|
|
|
|
JSONObject userInfo = customerMapper.findCustomerByOpenId(order.getString("customer_id"));
|
|
|
|
|
if (userInfo == null) {
|
|
|
|
|
userInfo = customerRelationAlipayMapper.findCustomerByUserId(order.getString("customer_id"));
|
|
|
|
|
}
|
|
|
|
|
JSONObject clientCustomerInfo = clientCustomersMapper.getClientCustomerWithNull(order.getIntValue("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"));
|
|
|
|
|
client_customer.put("tag", "不活跃用户");
|
|
|
|
|
if (userInfo != null) {
|
|
|
|
|
client_customer.put("headimg", userInfo.getString("headimg"));
|
|
|
|
|
client_customer.put("nick_name", userInfo.getString("nickname"));
|
|
|
|
|
}
|
|
|
|
|
client_customer.put("payment_times", 1);
|
|
|
|
|
client_customer.put("total_amount", order.getBigDecimal("total_amount"));
|
|
|
|
|
client_customer.put("last_payment_time", order.getDate("confirm_time"));
|
|
|
|
|
clientCustomersMapper.insert(client_customer);
|
|
|
|
|
} else {
|
|
|
|
|
clientCustomerInfo.put("payment_times", 1);
|
|
|
|
|
clientCustomerInfo.put("total_amount", order.getBigDecimal("total_amount"));
|
|
|
|
|
if (userInfo != null) {
|
|
|
|
|
clientCustomerInfo.put("headimg", userInfo.getString("headimg"));
|
|
|
|
|
clientCustomerInfo.put("nick_name", userInfo.getString("nickname"));
|
|
|
|
|
}
|
|
|
|
|
clientCustomerInfo.put("last_payment_time", order.getDate("confirm_time"));
|
|
|
|
|
clientCustomersMapper.updateAfterPaymentFinish(clientCustomerInfo);
|
|
|
|
|
}
|
|
|
|
|
} catch (Exception e) {
|
|
|
|
|
logger.debug("Reduce Customer Impression Error Redis Value =" + redisValue, e);
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
@Override
|
|
|
|
|
public void modifyNameRemark(int client_id, String customer_id, String name_remark) {
|
|
|
|
|
JSONObject clientCustomerInfo = clientCustomersMapper.getClientCustomer(client_id, customer_id);
|
|
|
|
|