大屏接口

dev_0531
yechenhao 6 years ago
parent 199b0b3585
commit a38a41ca1d

@ -17,17 +17,26 @@ import com.kiisoo.ic.generalize.mapper.PoiCustomerContactDataStatMapper;
import com.kiisoo.ic.generalize.mapper.RetailCompanyMapper;
import com.kiisoo.ic.generalize.service.RetailCompanyService;
import com.kiisoo.ic.store.entity.PoiStore;
import com.kiisoo.ic.store.entity.PoiStoreStaff;
import com.kiisoo.ic.store.entity.PrivilageCpUserStoreDO;
import com.kiisoo.ic.store.mapper.PoiStoreDOMapper;
import com.kiisoo.ic.synchronous.entity.TurnBackDTO;
import com.kiisoo.ic.synchronous.entity.WxDataDTO;
import lombok.extern.slf4j.Slf4j;
import me.chanjar.weixin.common.error.WxErrorException;
import me.chanjar.weixin.cp.api.WxCpExternalContactService;
import me.chanjar.weixin.cp.api.WxCpService;
import me.chanjar.weixin.cp.bean.WxCpUserExternalContactInfo;
import org.apache.commons.collections.CollectionUtils;
import org.apache.commons.lang3.StringUtils;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
import java.text.SimpleDateFormat;
import java.util.*;
import java.util.concurrent.CountDownLatch;
import java.util.concurrent.ExecutorService;
import java.util.concurrent.Executors;
import java.util.concurrent.atomic.AtomicInteger;
import java.util.stream.Collectors;
@ -541,7 +550,10 @@ public class CustomerViewService {
return result;
}
public void syncAllCount() throws WxErrorException {
public void syncAllCount() throws WxErrorException, InterruptedException {
//初始化线程
ExecutorService newFixedThreadPool = Executors.newFixedThreadPool(8);
//查询现有企业微信账号
List<PrivilageCpUserDO> privilageCpUserDOS = privilageCpUserDOMapper.selectList(null);
Map<String,PrivilageCpUserDO> cpUserIdMap = new HashMap<>();
@ -552,7 +564,21 @@ public class CustomerViewService {
WxCpExternalContactService externalContactService = wxCpService.getExternalContactService();
//查询企业微信已配置联系我的用户
List<String> cpUserIds = externalContactService.listFollowUser();
for (String cpUserId : cpUserIds) {
if (CollectionUtils.isNotEmpty(cpUserIds)){
//分组
final List<List<String>> afterPageList = com.kiisoo.ic.utils.CollectionUtils.portListByQuantity(cpUserIds, 100);
//定义线程池长度
int threadPoolSize = afterPageList.size();
//定义countDownLatch
final CountDownLatch countDownLatch = new CountDownLatch(threadPoolSize);
for (int i = 0; i < afterPageList.size(); i++) {
List<String> ids = afterPageList.get(i);
newFixedThreadPool.execute(new Runnable() {
@Override
public void run() {
try {
for (String cpUserId : ids) {
List<String> customerStrs;
try {
//获取客户联系人
@ -586,6 +612,16 @@ public class CustomerViewService {
//移除已经请求过的数据库内账号
cpUserIdMap.remove(cpUserId);
}
} catch (Exception e) {
log.error("同步客户明细", e);
} finally {
//每次减去一,避免死锁
countDownLatch.countDown();
}
}
});
}
countDownLatch.await();
Set<String> removeCpUserIds = cpUserIdMap.keySet();
for (String cpUserId:removeCpUserIds){
PrivilageCpUserDO privilageCpUserDO = cpUserIdMap.get(cpUserId);
@ -595,16 +631,34 @@ public class CustomerViewService {
}
}
}
}
public void syncAliveCount() throws WxErrorException, InterruptedException {
//初始化线程
ExecutorService newFixedThreadPool = Executors.newFixedThreadPool(8);
public void syncAliveCount() throws WxErrorException {
//查询现有企业微信账号
QueryWrapper<PrivilageCpUserDO> qw = new QueryWrapper<>();
qw.ne("status",9);
List<PrivilageCpUserDO> privilageCpUserDOS = privilageCpUserDOMapper.selectList(null);
WxCpService wxCpService = WxCpConfiguration.getCpService(APPLICATIONID);
WxCpExternalContactService externalContactService = wxCpService.getExternalContactService();
if (CollectionUtils.isNotEmpty(privilageCpUserDOS)){
//分组
final List<List<PrivilageCpUserDO>> afterPageList = com.kiisoo.ic.utils.CollectionUtils.portListByQuantity(privilageCpUserDOS, 100);
//定义线程池长度
int threadPoolSize = afterPageList.size();
//定义countDownLatch
final CountDownLatch countDownLatch = new CountDownLatch(threadPoolSize);
for (int i = 0; i < afterPageList.size(); i++) {
List<PrivilageCpUserDO> cpUserDOS = afterPageList.get(i);
newFixedThreadPool.execute(new Runnable() {
@Override
public void run() {
try {
//查询企业微信已配置联系我的用户
for (PrivilageCpUserDO privilageCpUserDO : privilageCpUserDOS) {
for (PrivilageCpUserDO privilageCpUserDO : cpUserDOS) {
List<String> customerStrs;
try {
//获取客户联系人
@ -625,5 +679,16 @@ public class CustomerViewService {
}
}
}
} catch (Exception e) {
log.error("同步客户明细", e);
} finally {
//每次减去一,避免死锁
countDownLatch.countDown();
}
}
});
}
countDownLatch.await();
}
}
}

@ -22,6 +22,7 @@ import com.kiisoo.ic.store.mapper.PrivilageCpUserStoreDOMapper;
import com.kiisoo.ic.synchronous.entity.TurnBackDTO;
import com.kiisoo.ic.synchronous.entity.WxDataDTO;
import com.kiisoo.ic.wx.service.QWMailListManageService;
import lombok.extern.slf4j.Slf4j;
import me.chanjar.weixin.common.error.WxErrorException;
import me.chanjar.weixin.cp.bean.WxCpUser;
import me.chanjar.weixin.cp.bean.WxCpUserExternalContactInfo;
@ -43,6 +44,9 @@ import java.net.URLConnection;
import java.text.SimpleDateFormat;
import java.util.List;
import java.util.*;
import java.util.concurrent.CountDownLatch;
import java.util.concurrent.ExecutorService;
import java.util.concurrent.Executors;
import java.util.regex.Matcher;
import java.util.regex.Pattern;
import java.util.stream.Collectors;
@ -59,6 +63,7 @@ import static java.util.regex.Pattern.*;
* @Version: v1
*/
@Service
@Slf4j
public class EmployeeService {
@Autowired
@ -463,12 +468,28 @@ public class EmployeeService {
}
public void syncCustoemr() throws Exception {
//初始化线程
ExecutorService newFixedThreadPool = Executors.newFixedThreadPool(8);
SimpleDateFormat sdf = new SimpleDateFormat("yyyy-MM-dd HH:mm:ss");
//查询所有店长
List<PrivilageCpUserStoreDO> privilageCpUserStoreDOS = privilageCpUserStoreDOMapper.selectList(null);
if (CollectionUtils.isNotEmpty(privilageCpUserStoreDOS)){
for (PrivilageCpUserStoreDO privilageCpUserStoreDO:privilageCpUserStoreDOS){
String cpUserId = privilageCpUserStoreDOMapper.selectCpUserIdByStoreId(privilageCpUserStoreDO.getStoreId());
//分组
final List<List<PrivilageCpUserStoreDO>> afterPageList = com.kiisoo.ic.utils.CollectionUtils.portListByQuantity(privilageCpUserStoreDOS, 100);
//定义线程池长度
int threadPoolSize = afterPageList.size();
//定义countDownLatch
final CountDownLatch countDownLatch = new CountDownLatch(threadPoolSize);
for (int i = 0; i < afterPageList.size(); i++) {
List<PrivilageCpUserStoreDO> cpUserStoreDOS = afterPageList.get(i);
newFixedThreadPool.execute(new Runnable() {
@Override
public void run() {
try {
for (PrivilageCpUserStoreDO cpUserStoreDO : cpUserStoreDOS) {
String cpUserId = privilageCpUserStoreDOMapper.selectCpUserIdByStoreId(cpUserStoreDO.getStoreId());
if (StringUtils.isBlank(cpUserId)){
continue;
}
@ -499,11 +520,11 @@ public class EmployeeService {
}else if(tags != null && tags.length > 0){
//判断是否有打tag
//todo 根据tag获取导购码
for (int i = 0;i<tags.length;i++){
String groupName = tags[i].getGroupName();
for (int j = 0;j<tags.length;j++){
String groupName = tags[j].getGroupName();
if ("导购".equals(groupName)){
String tagName = tags[i].getTagName();
Long staffId = poiStoreStaffDOMapper.selectStaffIdByTag(privilageCpUserStoreDO.getStoreId(), tagName);
String tagName = tags[j].getTagName();
Long staffId = poiStoreStaffDOMapper.selectStaffIdByTag(cpUserStoreDO.getStoreId(), tagName);
if (staffId != null){
PoiStoreStaff poiStoreStaff = poiStoreStaffDOMapper.selectById(staffId);
if (poiStoreStaff!=null){
@ -537,6 +558,17 @@ public class EmployeeService {
}
}
}
} catch (Exception e) {
log.error("同步客户明细", e);
} finally {
//每次减去一,避免死锁
countDownLatch.countDown();
}
}
});
}
countDownLatch.await();
}
}

@ -0,0 +1,25 @@
package com.kiisoo.ic.utils;
import java.util.ArrayList;
import java.util.List;
public class CollectionUtils {
public static List portListByQuantity(List list, int quantity) {
if (list == null || list.size() == 0) {
return list;
}
if (quantity <= 0) {
new IllegalArgumentException("Wrong quantity.");
}
List wrapList = new ArrayList();
int count = 0;
while (count < list.size()) {
wrapList.add(list.subList(count, (count + quantity) > list.size() ? list.size() : count + quantity));
count += quantity;
}
return wrapList;
}
}
Loading…
Cancel
Save