Merge remote-tracking branch 'origin/master'

# Conflicts:
#	src/db/modify.sql
#	src/main/ui/static/analysis/org/templates/analysis_org.html
master
eason.qian 7 years ago
commit d3d0419c31

@ -147,7 +147,6 @@ ALTER TABLE sys_org ADD COLUMN min_jd_rate DECIMAL(3,2) DEFAULT NULL COMMENT '
ALTER TABLE sys_org ADD COLUMN commission_type SMALLINT(1) DEFAULT '1' COMMENT '提成类型 1:渠道计算法 2:总交易额比例 3:收益比例';
--agent_commission
CREATE TABLE `financial_agent_commission` (
@ -185,9 +184,10 @@ CREATE TABLE `financial_agent_commission_detail` (
alter table financial_partner_commission add column commission_type smallint(1) DEFAULT 1 COMMENT '提成类型 1:渠道计算法 2:总交易额比例 3:收益比例';
alter table financial_partner_commission_detail add column commission_type smallint(1) DEFAULT 1 COMMENT '提成类型 1:渠道计算法 2:总交易额比例 3:收益比例';
INSERT INTO `royalpay_production`.`sys_configs`(`config_key` , `config_value`)
INSERT INTO `royalpay_production`.`sys_configs`(`config_key` , `config_value`)
VALUES
(
'android_version_content' ,

@ -13,7 +13,10 @@ public interface CustomerImpressionService {
JSONObject findOne(int client_id,String customer_id);
void generateTag(int client_id);
void generate(int client_id);
void generateInfo();
void modifyNameRemark(int client_id, String customer_id,String name_remark);
}

@ -10,6 +10,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;
@ -28,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.tools.exceptions.BadRequestException;
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;
/**
@ -45,6 +51,13 @@ public class CustomerImpressionServiceImpl implements CustomerImpressionService
private CustomerRelationAlipayMapper customerRelationAlipayMapper;
@Resource
private CustomerMapper customerMapper;
@Resource
private Locker locker;
@Resource
private StringRedisTemplate stringRedisTemplate;
private static String CUSTOMER_IMPRESSION_PREFIX = "Customer_impression_insert";
Logger logger = LoggerFactory.getLogger(CustomerImpressionServiceImpl.class);
@Override
public JSONObject listPageble(CustomerImpressionQuery customerImpressionQuery) {
@ -92,8 +105,12 @@ public class CustomerImpressionServiceImpl implements CustomerImpressionService
}
@Override
@Transactional
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();
params.put("client_id", client_id);
params.put("include_success_status", 3);
@ -102,58 +119,59 @@ public class CustomerImpressionServiceImpl implements CustomerImpressionService
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"));
String customer_id = order.getString("customer_id");
JSONObject userInfo = customerMapper.findCustomerByOpenId(customer_id);
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) {
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"));
locker.lock(CUSTOMER_IMPRESSION_PREFIX+customer_id, 30_000, 30_000);
try {
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);
} finally {
locker.unlock(customer_id);
}
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"));
}
clientCustomerInfo.put("payment_times", order.getIntValue("payment_times"));
clientCustomerInfo.put("client_id", order.getIntValue("client_id"));
clientCustomerInfo.put("customer_id", order.getString("customer_id"));
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);
clientCustomersMapper.updateAfterPaymentFinish(clientCustomerInfo);
}
}
generateTag(client_id);
}
private void generateTag(int client_id) {
@Override
@Transactional
public void generateTag(int client_id) {
JSONObject params = new JSONObject();
DateTime dt = new DateTime();
dt = dt.minusMonths(5);
dt = dt.minusMonths(1);
params.put("confirm_time", dt.toDate());
params.put("client_id", client_id);
List<JSONObject> orders = orderMapper.listAnalysisClientCustomer(params);
@ -176,6 +194,67 @@ public class CustomerImpressionServiceImpl implements CustomerImpressionService
}
@Override
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");
String redisValue = ops.leftPop();
while (!StringUtils.isEmpty(redisValue)) {
try {
JSONObject order = JSONObject.parseObject(redisValue);
redisValue = ops.leftPop();
if (StringUtils.isEmpty(order.getString("channel"))) {
continue;
}
String customer_id = order.getString("customer_id");
JSONObject userInfo = customerMapper.findCustomerByOpenId(customer_id);
if (userInfo == null) {
userInfo = customerRelationAlipayMapper.findCustomerByUserId(customer_id);
}
JSONObject clientCustomerInfo = clientCustomersMapper.getClientCustomerWithNull(order.getIntValue("client_id"), customer_id);
if (clientCustomerInfo == null) {
locker.lock(CUSTOMER_IMPRESSION_PREFIX+customer_id, 30_000, 30_000);
try {
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("update_time", now);
client_customer.put("total_amount", order.getBigDecimal("total_amount"));
client_customer.put("last_payment_time", order.getDate("confirm_time"));
clientCustomersMapper.insert(client_customer);
} finally {
locker.unlock(customer_id);
}
} else {
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"));
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);
@ -185,5 +264,4 @@ public class CustomerImpressionServiceImpl implements CustomerImpressionService
clientCustomerInfo.put("name_remak", name_remark);
clientCustomersMapper.update(clientCustomerInfo);
}
}

@ -0,0 +1,28 @@
package au.com.royalpay.payment.manage.apps.events.listeners;
import au.com.royalpay.payment.core.events.AfterPaymentFinishEvent;
import com.alibaba.fastjson.JSONObject;
import org.springframework.context.ApplicationListener;
import org.springframework.data.redis.core.BoundListOperations;
import org.springframework.data.redis.core.StringRedisTemplate;
import org.springframework.stereotype.Service;
import javax.annotation.Resource;
/**
* Created by wangning on 17/01/2018.
*/
@Service
public class AfterPaymentFinishListener implements ApplicationListener<AfterPaymentFinishEvent> {
@Resource
private StringRedisTemplate stringRedisTemplate;
@Override
public void onApplicationEvent(AfterPaymentFinishEvent event) {
JSONObject order = event.getFinishedEvent().getOrder();
BoundListOperations<String, String> ops = stringRedisTemplate.boundListOps("customer_impression");
ops.rightPush(order.toJSONString());
}
}

@ -0,0 +1,4 @@
/**
* Created by wangning on 17/01/2018.
*/
package au.com.royalpay.payment.manage.apps.events;

@ -41,10 +41,4 @@ public class CustomerImpressionController {
@ModelAttribute(CommonConsts.RETAIL_DEVICE) JSONObject app) {
customerImpressionService.modifyNameRemark(app.getIntValue("client_id"), customer_id, customerInfo.getString("name_remark"));
}
@RequestMapping(value = "/gengrate", method = RequestMethod.PUT)
@ResponseBody
public void generate(@ModelAttribute(CommonConsts.RETAIL_DEVICE) JSONObject app) {
customerImpressionService.generate(app.getIntValue("client_id"));
}
}

@ -26,6 +26,8 @@ public interface ClientCustomersMapper {
@AutoSql(type = SqlType.UPDATE)
public void update(JSONObject obj);
public void updateAfterPaymentFinish(JSONObject obj);
PageList<JSONObject> listCustomerInfo(JSONObject params, PageBounds pageBounds);
}

@ -30,6 +30,27 @@ public class CustomerImpressionTask {
private ThreadPoolExecutor generatePool = new ThreadPoolExecutor(10, 30, 5, TimeUnit.SECONDS, new LinkedBlockingQueue<Runnable>());
@Scheduled(cron = "0 0 3 * * ?")
public void generateTags() {
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.generateTag(p.getIntValue("client_id"));
});
generatePool.execute(task);
}
}
@Scheduled(cron = "0 0 3 * * ?")
public void generate() {
List<JSONObject> clients = clientMapper.listValidClient();
@ -50,4 +71,9 @@ public class CustomerImpressionTask {
generatePool.execute(task);
}
}
@Scheduled(cron = "0/1 * * * * ?")
public void generateInfo() {
customerImpressionService.generateInfo();
}
}

@ -31,4 +31,16 @@
and customer_id = #{customer_id}
</select>
<update id="updateAfterPaymentFinish">
update sys_clients_customers
set total_amount = total_amount + #{total_amount},
payment_times = payment_times + #{payment_times},
last_payment_time = #{last_payment_time},
nick_name = #{nick_name},
headimg = #{headimg}
where client_id= #{client_id}
and customer_id = #{customer_id}
</update>
</mapper>

@ -2,16 +2,12 @@
<div class="row">
<div class="col-sm-12 analysis-nav">
<ul class="nav nav-pills">
<li ui-sref-active-eq="active" ng-if="('org_sale'|withModule)&&(currentUser.org_id==null||currentUser.org_id==1 ||('1000000000000'|withRole))">
<li ui-sref-active-eq="active" ng-if="('org_sale'|withModule)&&(currentUser.org_id==null||currentUser.org_id==1)">
<a ui-sref="analysis_org.organlasis"><i class="fa fa-hand-peace-o"></i>合伙人销售量|City Partner Sale</a>
</li>
<li ui-sref-active-eq="active" ng-if="('orgcommission'|withModule)">
<a ui-sref="analysis_org.orgcommission"><i class="fa fa-users"></i></i>合伙人提成|City Partner Commissions</a>
</li>
<li ui-sref-active-eq="active" ng-if="('org_sale'|withModule)&&(currentUser.org_id==null||currentUser.org_id==1)">
<a ui-sref="analysis_org.referrercommission"><i class="fa fa-users"></i></i>推荐人提成|Referrer Commissions</a>
<a ui-sref="analysis_org.commission"><i class="fa fa-users"></i></i>合伙人提成|City Partner Commissions</a>
</li>
</ul>
</div>
</div>

@ -14,18 +14,20 @@ var commissionTypeMap = [{
"value": "收益比例"
}
];
define(['angular','../../analysis/org/analysis-org'], function (angular) {
'use strict';
var app = angular.module('orgcommission', ['ui.router']);
app.config(['$stateProvider', function ($stateProvider) {
$stateProvider.state('analysis_org.orgcommission', {
$stateProvider.state('analysis_org.commission', {
url: '/org_commissions',
templateUrl: '/static/config/orgcommission/templates/org_commission_root.html',
controller: 'orgCommissionRootCtrl'
}).state('analysis_org.orgcommission.month', {
url: '/months/{monthStr}',
}).state('analysis_org.commission.month', {
url: '/commissionorg/months/{monthStr}',
templateUrl: '/static/config/orgcommission/templates/org_commission_month_root.html',
controller: 'commissionMonthRootCtrl'
}).state('analysis_org.commission.month.org', {
url: '/org',
templateUrl: '/static/config/orgcommission/templates/org_commission_month.html',
controller: 'orgCommissionMonthViewCtrl',
resolve: {
@ -33,7 +35,16 @@ define(['angular','../../analysis/org/analysis-org'], function (angular) {
return $http.get('/sys/citypartner_prizes/months/' + $stateParams.monthStr);
}]
}
}).state('analysis_org.orgcommission.month.orgdetail', {
}).state('analysis_org.commission.month.referrer', {
url: '/referrer',
templateUrl: '/static/config/referrercommission/templates/referrer_commission_month.html',
controller: 'referrerCommissionMonthViewCtrl',
resolve: {
monthData: ['$http', '$stateParams', function ($http, $stateParams) {
return $http.get('/sys/citypartner_prizes/referrer/months/' + $stateParams.monthStr);
}]
}
}).state('analysis_org.commission.month.org.orgdetail', {
url: '/citypartners/{orgId}',
templateUrl: '/static/config/orgcommission/templates/org_commission_detail.html',
controller: 'orgCommissionOrgDetailCtrl',
@ -42,13 +53,25 @@ define(['angular','../../analysis/org/analysis-org'], function (angular) {
return $http.get('/sys/citypartner_prizes/months/' + $stateParams.monthStr + '/orgs/' + $stateParams.orgId);
}]
}
}).state('analysis_org.commission.month.referrer.referrerdetail', {
url: '/referrer_commissions/{orgId}',
templateUrl: '/static/config/referrercommission/templates/referrer_commission_detail.html',
controller: 'referrerCommissionOrgDetailCtrl',
resolve: {
detail: ['$http', '$stateParams', function ($http, $stateParams) {
return $http.get('/sys/citypartner_prizes/referrer/months/' + $stateParams.monthStr + '/orgs/' + $stateParams.orgId);
}]
}
})
}]);
app.controller('commissionMonthRootCtrl', ['$scope', '$state', function ($scope, $state) {
if($state.is('analysis_org.commission.month')){
$state.go('.org');
}
}]);
app.controller('orgCommissionRootCtrl', ['$scope', '$http', '$filter', '$state', 'commonDialog',
function ($scope, $http, $filter, $state, commonDialog) {
$scope.generate = {};
$scope.generateOrgCommission = function () {
$scope.generate.status = {};
if (!$scope.generate.month) {
@ -63,7 +86,7 @@ define(['angular','../../analysis/org/analysis-org'], function (angular) {
}).then(function () {
var params = {month: $filter('date')($scope.generate.month, 'yyyy-MM')};
$http.post('/sys/citypartner_prizes/generate', params).then(function () {
$state.go('analysis_org.orgcommission.month', {monthStr: params.month})
$state.go('.org.month', {monthStr: params.month})
$scope.generate.status = null;
}, function (resp) {
commonDialog.alert({type: 'error', title: 'Error', content: resp.data.message});
@ -89,9 +112,14 @@ define(['angular','../../analysis/org/analysis-org'], function (angular) {
return has;
};
$scope.gotoMonth = function (mon) {
var monthStr = $scope.params.year.getFullYear() + '-' + (('0' + mon).substr(-2));
$state.go('analysis_org.orgcommission.month', {monthStr: monthStr})
if(mon){
$scope.params.month = mon;
}
var monthStr = $scope.params.year.getFullYear() + '-' + $scope.params.month;
$state.go('analysis_org.commission.month', {monthStr: monthStr})
};
}]);
app.controller('orgCommissionMonthViewCtrl', ['$scope', 'monthData','$filter', function ($scope, monthData) {
$scope.monthData = monthData.data;
@ -118,6 +146,29 @@ define(['angular','../../analysis/org/analysis-org'], function (angular) {
}
}]);
app.controller('referrerCommissionMonthViewCtrl', ['$scope', 'monthData', function ($scope, monthData) {
$scope.monthData = monthData.data;
$scope.ctrl = {};
$scope.active = function (log) {
if($scope.ctrl.activeLog && $scope.ctrl.activeLog.org_id==log.org_id){
$scope.ctrl.activeLog=null;
return;
}
$scope.ctrl.activeLog=log;
}
}]);
app.controller('referrerCommissionOrgDetailCtrl', ['$scope', 'detail', function ($scope, detail) {
$scope.detail = detail.data;
$scope.ctrl = {};
$scope.active = function (log) {
if($scope.ctrl.activeLog && $scope.ctrl.activeLog.client_moniker==log.client_moniker){
$scope.ctrl.activeLog=null;
return;
}
$scope.ctrl.activeLog=log;
}
}]);
app.filter('commission_type_filter', function () {
return function (sectorValue) {

@ -0,0 +1,13 @@
<div is-open="ctrl.viewyear">
<ul id="myTab" class="nav nav-tabs">
<li ui-sref-active="active">
<a ui-sref=".org" data-toggle="tab">
合伙人提成
</a>
</li>
<li ui-sref-active="active"><a ui-sref=".referrer" data-toggle="tab">推荐人提成</a></li>
</ul>
<div class="tab-content" ui-view>
</div>
</div>

@ -1,11 +1,4 @@
<!--<section class="content-header">-->
<!--<h1>City Partner Commissions</h1>-->
<!--<ol class="breadcrumb">-->
<!--<li><i class="fa fa-users"></i> Analysis</li>-->
<!--<li class="active">City Partner Commissions</li>-->
<!--</ol>-->
<!--</section>-->
<section class="content">
<div class="content">
<div class="box box-default">
<div class="box-body">
<div class="form-inline">
@ -13,7 +6,6 @@
<input type="text" class="form-control" uib-datepicker-popup="yyyy-MM" ng-model="generate.month"
is-open="ctrl.genmonth" datepicker-options="{minMode: 'month'}"
ng-click="ctrl.genmonth=true" placeholder="Select Month"/>
</div>
<button class="btn btn-primary" ng-click="generateOrgCommission()" ng-disabled="!generate.month">
Generate
@ -32,7 +24,7 @@
<div class="row">
<div class="col-md-3 col-sm-6 col-xs-12" ng-repeat="mon in availableMonths">
<div class="info-box">
<div class="info-box-icon bg-aqua" ng-bind="mon.month" ng-click="gotoMonth(mon.monthstr)" role="button">
<div class="info-box-icon bg-aqua" ng-bind="mon.month" ng-click="gotoMonth(mon.month)" role="button">
</div>
<div class="info-box-content">
<!--<div class="info-box-text text-bold text-red" ng-bind="r.charge_date"></div>-->
@ -54,7 +46,7 @@
</div>
</div>
</div>
</div>
<div ui-view></div>
</section>
</div>

@ -5,7 +5,6 @@
}
</style>
<div class="box box-warning" ng-if="detail">
<div class="box-header">Analysis</div>
<div class="box-body nowrap">

@ -34,7 +34,7 @@
<td ng-bind="log.gross_amount|currency:'AUD'"></td>
<td ng-bind="log.org_charge|currency:'AUD'"></td>
<td>
<a ui-sref=".orgdetail({orgId:log.org_id})">
<a ui-sref=".referrerdetail({orgId:log.org_id})">
<i class="fa fa-search"></i>
</a>
</td>

@ -1,68 +1,39 @@
package au.com.royalpay.payment.manage.apps.core.impls;
import java.util.ArrayList;
import java.util.List;
import java.util.concurrent.LinkedBlockingQueue;
import java.util.concurrent.ThreadPoolExecutor;
import java.util.concurrent.TimeUnit;
import javax.annotation.Resource;
import org.junit.Test;
import org.junit.runner.RunWith;
import org.springframework.boot.test.context.SpringBootTest;
import org.springframework.data.redis.core.BoundListOperations;
import org.springframework.data.redis.core.StringRedisTemplate;
import org.springframework.test.context.ActiveProfiles;
import org.springframework.test.context.junit4.SpringRunner;
import com.alibaba.fastjson.JSONObject;
import au.com.royalpay.payment.manage.apps.core.CustomerImpressionService;
import au.com.royalpay.payment.manage.mappers.system.ClientMapper;
import au.com.royalpay.payment.manage.mappers.payment.OrderMapper;
/**
* Created by wangning on 05/01/2018.
*/
@SpringBootTest
@ActiveProfiles({"production","alipay","wechat","jd","bestpay"})
@ActiveProfiles({ "local", "alipay", "wechat", "jd", "bestpay" })
@RunWith(SpringRunner.class)
public class CustomerImpressionImplTest {
@Resource
private CustomerImpressionService customerImpression;
@Resource
private ClientMapper clientMapper;
private ThreadPoolExecutor generatePool = new ThreadPoolExecutor(10, 30, 5, TimeUnit.SECONDS, new LinkedBlockingQueue<Runnable>());
private OrderMapper orderMapper;
@Test
public void generate() throws Exception {
customerImpression.generate(9);
}
@Resource
private StringRedisTemplate stringRedisTemplate;
@Test
public void generateAll(){
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));
}
public void redisQueue() {
BoundListOperations<String, String> ops = stringRedisTemplate.boundListOps("customer_impression");
JSONObject order = orderMapper.find("00009201711300930013961422");
for (int i = 0; i < 10000; i++) {
ops.rightPush(order.toJSONString());
}
for (List<JSONObject> splitClients : splitList) {
Runnable task = () -> splitClients.forEach((p)->{
System.out.println("当前执行到"+p.getIntValue("client_id"));
customerImpression.generate(p.getIntValue("client_id"));
});
generatePool.execute(task);
}
generatePool.shutdown();
try {
generatePool.awaitTermination(5, TimeUnit.HOURS);
} catch (InterruptedException e) {
e.printStackTrace();
}
}
}
Loading…
Cancel
Save