wangning 7 years ago
parent 9c567a6e98
commit 28537f5783

@ -14,6 +14,7 @@ public interface CustomerImpressionService {
JSONObject findOne(int client_id,String customer_id); JSONObject findOne(int client_id,String customer_id);
void generateTag(int client_id); void generateTag(int client_id);
void generate(int client_id);
void generateInfo(); void generateInfo();

@ -1,6 +1,8 @@
package au.com.royalpay.payment.manage.apps.core.impls; package au.com.royalpay.payment.manage.apps.core.impls;
import java.math.BigDecimal;
import java.util.ArrayList; import java.util.ArrayList;
import java.util.Date;
import java.util.List; import java.util.List;
import javax.annotation.Resource; import javax.annotation.Resource;
@ -96,68 +98,62 @@ public class CustomerImpressionServiceImpl implements CustomerImpressionService
return customer; return customer;
} }
// @Override @Override
// @Transactional public void generate(int client_id) {
// public void generate(int client_id) { 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); PageList<JSONObject> lastRecord = clientCustomersMapper.listCustomerInfo(params, new PageBounds(1, 1, Order.formString("update_time.desc")));
// PageList<JSONObject> lastRecord = clientCustomersMapper.listCustomerInfo(params, new PageBounds(1, 1, if (!CollectionUtils.isEmpty(lastRecord)) {
// Order.formString("update_time.desc"))); params.put("confirm_time", lastRecord.get(0).getDate("update_time"));
// if (!CollectionUtils.isEmpty(lastRecord)) { }
// params.put("confirm_time", lastRecord.get(0).getDate("update_time")); List<JSONObject> orders = orderMapper.listAnalysisClientCustomer(params);
// } Date now = new Date();
// List<JSONObject> orders = orderMapper.listAnalysisClientCustomer(params); for (JSONObject order : orders) {
// Date now = new Date(); if (StringUtils.isEmpty(order.getString("channel"))) {
// for (JSONObject order : orders) { continue;
// if (StringUtils.isEmpty(order.getString("channel"))) { }
// continue; JSONObject userInfo = customerMapper.findCustomerByOpenId(order.getString("customer_id"));
// } if (userInfo == null) {
// JSONObject userInfo = customerMapper.findCustomerByOpenId(order.getString("customer_id")); userInfo = customerRelationAlipayMapper.findCustomerByUserId(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 clientCustomerInfo = clientCustomersMapper.getClientCustomerWithNull(client_id, JSONObject client_customer = new JSONObject();
// order.getString("customer_id")); client_customer.put("client_id", order.getIntValue("client_id"));
// if (clientCustomerInfo == null) { client_customer.put("customer_id", order.getString("customer_id"));
// JSONObject client_customer = new JSONObject(); client_customer.put("channel", order.getString("channel"));
// client_customer.put("client_id", order.getIntValue("client_id")); client_customer.put("tag", "不活跃用户");
// client_customer.put("customer_id", order.getString("customer_id")); if (userInfo != null) {
// client_customer.put("channel", order.getString("channel")); client_customer.put("headimg", userInfo.getString("headimg"));
// client_customer.put("tag", "不活跃用户"); client_customer.put("nick_name", userInfo.getString("nickname"));
// if (userInfo != null) { }
// client_customer.put("headimg", userInfo.getString("headimg")); client_customer.put("payment_times", order.getIntValue("payment_times"));
// client_customer.put("nick_name", userInfo.getString("nickname")); client_customer.put("total_amount", order.getBigDecimal("total_amount"));
// } client_customer.put("update_time", now);
// client_customer.put("payment_times", order.getIntValue("payment_times")); client_customer.put("last_payment_time", order.getDate("confirm_time"));
// client_customer.put("total_amount", order.getBigDecimal("total_amount")); clientCustomersMapper.insert(client_customer);
// client_customer.put("update_time", now); } else {
// client_customer.put("last_payment_time", order.getDate("confirm_time")); clientCustomerInfo.put("payment_times", clientCustomerInfo.getIntValue("payment_times") + order.getIntValue("payment_times"));
// clientCustomersMapper.insert(client_customer); BigDecimal total_amount = clientCustomerInfo.getBigDecimal("total_amount");
// } else { if (total_amount != null) {
// clientCustomerInfo.put("payment_times", clientCustomerInfo.getIntValue("payment_times") + clientCustomerInfo.put("total_amount", clientCustomerInfo.getBigDecimal("total_amount").add(order.getBigDecimal("total_amount")));
// order.getIntValue("payment_times")); } else {
// BigDecimal total_amount = clientCustomerInfo.getBigDecimal("total_amount"); clientCustomerInfo.put("total_amount", order.getBigDecimal("total_amount"));
// if (total_amount != null) { }
// clientCustomerInfo.put("total_amount", if (userInfo != null) {
// clientCustomerInfo.getBigDecimal("total_amount").add(order.getBigDecimal("total_amount"))); clientCustomerInfo.put("headimg", userInfo.getString("headimg"));
// } else { clientCustomerInfo.put("nick_name", userInfo.getString("nickname"));
// clientCustomerInfo.put("total_amount", order.getBigDecimal("total_amount")); }
// } clientCustomerInfo.put("channel", order.getString("channel"));
// if (userInfo != null) { clientCustomerInfo.put("tag", "不活跃用户");
// clientCustomerInfo.put("headimg", userInfo.getString("headimg")); clientCustomerInfo.put("update_time", now);
// clientCustomerInfo.put("nick_name", userInfo.getString("nickname")); clientCustomerInfo.put("last_payment_time", order.getDate("confirm_time"));
// } clientCustomersMapper.update(clientCustomerInfo);
// 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 @Override
@Transactional @Transactional
@ -189,6 +185,11 @@ public class CustomerImpressionServiceImpl implements CustomerImpressionService
@Override @Override
public void generateInfo() { public void generateInfo() {
Date now = new Date();
DateTime dt = new DateTime(2018,1,19,3,0);
if(dt.toDate().compareTo(now)>0){
return;
}
BoundListOperations<String, String> ops = stringRedisTemplate.boundListOps("customer_impression"); BoundListOperations<String, String> ops = stringRedisTemplate.boundListOps("customer_impression");
String redisValue = ops.leftPop(); String redisValue = ops.leftPop();
@ -197,7 +198,7 @@ public class CustomerImpressionServiceImpl implements CustomerImpressionService
JSONObject order = JSONObject.parseObject(redisValue); JSONObject order = JSONObject.parseObject(redisValue);
redisValue = ops.leftPop(); redisValue = ops.leftPop();
if (StringUtils.isEmpty(order.getString("channel"))) { if (StringUtils.isEmpty(order.getString("channel"))) {
continue; continue;
} }
JSONObject userInfo = customerMapper.findCustomerByOpenId(order.getString("customer_id")); JSONObject userInfo = customerMapper.findCustomerByOpenId(order.getString("customer_id"));
if (userInfo == null) { if (userInfo == null) {

@ -51,6 +51,27 @@ public class CustomerImpressionTask {
} }
} }
@Scheduled(cron = "0 0 3 * * ?")
public void generate() {
List<JSONObject> clients = clientMapper.listValidClient();
List<List<JSONObject>> splitList = new ArrayList<>();
for (int i = 0; i < clients.size(); i+=200) {
if(i+200>clients.size()){
splitList.add(clients.subList(i,clients.size()));
}else {
splitList.add(clients.subList(i,i+200));
}
}
for (List<JSONObject> splitClients : splitList) {
Runnable task = () -> splitClients.forEach((p)->{
System.out.println("当前执行到"+p.getIntValue("client_id"));
customerImpressionService.generate(p.getIntValue("client_id"));
});
generatePool.execute(task);
}
}
@Scheduled(cron = "0/1 * * * * ?") @Scheduled(cron = "0/1 * * * * ?")
public void generateInfo() { public void generateInfo() {
customerImpressionService.generateInfo(); customerImpressionService.generateInfo();

Loading…
Cancel
Save