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