|
|
@ -3,10 +3,13 @@ package com.kiisoo.ic.customer.service;
|
|
|
|
import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
|
|
|
|
import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
|
|
|
|
import com.github.pagehelper.Page;
|
|
|
|
import com.github.pagehelper.Page;
|
|
|
|
import com.github.pagehelper.PageHelper;
|
|
|
|
import com.github.pagehelper.PageHelper;
|
|
|
|
|
|
|
|
import com.kiisoo.ic.config.WxCpConfiguration;
|
|
|
|
import com.kiisoo.ic.customer.entity.*;
|
|
|
|
import com.kiisoo.ic.customer.entity.*;
|
|
|
|
import com.kiisoo.ic.customer.mapper.OpCustomerDOMapper;
|
|
|
|
import com.kiisoo.ic.customer.mapper.OpCustomerDOMapper;
|
|
|
|
import com.kiisoo.ic.customer.mapper.OpVipDOMapper;
|
|
|
|
import com.kiisoo.ic.customer.mapper.OpVipDOMapper;
|
|
|
|
import com.kiisoo.ic.domain.service.PrivilageDomainService;
|
|
|
|
import com.kiisoo.ic.domain.service.PrivilageDomainService;
|
|
|
|
|
|
|
|
import com.kiisoo.ic.employee.entity.CpUserCustomerRelationDO;
|
|
|
|
|
|
|
|
import com.kiisoo.ic.employee.entity.PrivilageCpUserDO;
|
|
|
|
import com.kiisoo.ic.employee.mapper.PrivilageCpUserDOMapper;
|
|
|
|
import com.kiisoo.ic.employee.mapper.PrivilageCpUserDOMapper;
|
|
|
|
import com.kiisoo.ic.generalize.entity.PoiCustomerContactDataStat;
|
|
|
|
import com.kiisoo.ic.generalize.entity.PoiCustomerContactDataStat;
|
|
|
|
import com.kiisoo.ic.generalize.entity.PrivilageOrganizational;
|
|
|
|
import com.kiisoo.ic.generalize.entity.PrivilageOrganizational;
|
|
|
@ -16,6 +19,9 @@ 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.mapper.PoiStoreDOMapper;
|
|
|
|
import com.kiisoo.ic.store.mapper.PoiStoreDOMapper;
|
|
|
|
import lombok.extern.slf4j.Slf4j;
|
|
|
|
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 org.apache.commons.collections.CollectionUtils;
|
|
|
|
import org.apache.commons.collections.CollectionUtils;
|
|
|
|
import org.springframework.beans.factory.annotation.Autowired;
|
|
|
|
import org.springframework.beans.factory.annotation.Autowired;
|
|
|
|
import org.springframework.stereotype.Service;
|
|
|
|
import org.springframework.stereotype.Service;
|
|
|
@ -25,6 +31,8 @@ import java.util.*;
|
|
|
|
import java.util.concurrent.atomic.AtomicInteger;
|
|
|
|
import java.util.concurrent.atomic.AtomicInteger;
|
|
|
|
import java.util.stream.Collectors;
|
|
|
|
import java.util.stream.Collectors;
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
import static com.kiisoo.ic.config.WxCpConfiguration.APPLICATIONID;
|
|
|
|
|
|
|
|
|
|
|
|
/**
|
|
|
|
/**
|
|
|
|
* @Description: 客户数据概览service
|
|
|
|
* @Description: 客户数据概览service
|
|
|
|
* @Author: wangyinjia
|
|
|
|
* @Author: wangyinjia
|
|
|
@ -499,7 +507,10 @@ public class CustomerViewService {
|
|
|
|
return shopIds;
|
|
|
|
return shopIds;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
/**
|
|
|
|
|
|
|
|
* 客户概览main
|
|
|
|
|
|
|
|
* @return 客户概览VO
|
|
|
|
|
|
|
|
*/
|
|
|
|
public CustomerViewVO getAllCount() {
|
|
|
|
public CustomerViewVO getAllCount() {
|
|
|
|
Long all = privilageCpUserDOMapper.selectAllCount();
|
|
|
|
Long all = privilageCpUserDOMapper.selectAllCount();
|
|
|
|
Long dis = privilageCpUserDOMapper.selectDistinctAllCount();
|
|
|
|
Long dis = privilageCpUserDOMapper.selectDistinctAllCount();
|
|
|
@ -508,4 +519,90 @@ public class CustomerViewService {
|
|
|
|
result.setAllValidCustomer(dis);
|
|
|
|
result.setAllValidCustomer(dis);
|
|
|
|
return result;
|
|
|
|
return result;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
public void syncAllCount() throws WxErrorException {
|
|
|
|
|
|
|
|
//查询现有企业微信账号
|
|
|
|
|
|
|
|
List<PrivilageCpUserDO> privilageCpUserDOS = privilageCpUserDOMapper.selectList(null);
|
|
|
|
|
|
|
|
Map<String,PrivilageCpUserDO> cpUserIdMap = new HashMap<>();
|
|
|
|
|
|
|
|
for (PrivilageCpUserDO privilageCpUserDO : privilageCpUserDOS) {
|
|
|
|
|
|
|
|
cpUserIdMap.put(privilageCpUserDO.getCpUserId(),privilageCpUserDO);
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
WxCpService wxCpService = WxCpConfiguration.getCpService(APPLICATIONID);
|
|
|
|
|
|
|
|
WxCpExternalContactService externalContactService = wxCpService.getExternalContactService();
|
|
|
|
|
|
|
|
//查询企业微信已配置联系我的用户
|
|
|
|
|
|
|
|
List<String> cpUserIds = externalContactService.listFollowUser();
|
|
|
|
|
|
|
|
for (String cpUserId : cpUserIds) {
|
|
|
|
|
|
|
|
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);
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
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 {
|
|
|
|
|
|
|
|
//查询现有企业微信账号
|
|
|
|
|
|
|
|
QueryWrapper<PrivilageCpUserDO> qw = new QueryWrapper<>();
|
|
|
|
|
|
|
|
qw.ne("status",9);
|
|
|
|
|
|
|
|
List<PrivilageCpUserDO> privilageCpUserDOS = privilageCpUserDOMapper.selectList(null);
|
|
|
|
|
|
|
|
WxCpService wxCpService = WxCpConfiguration.getCpService(APPLICATIONID);
|
|
|
|
|
|
|
|
WxCpExternalContactService externalContactService = wxCpService.getExternalContactService();
|
|
|
|
|
|
|
|
//查询企业微信已配置联系我的用户
|
|
|
|
|
|
|
|
for (PrivilageCpUserDO privilageCpUserDO : privilageCpUserDOS) {
|
|
|
|
|
|
|
|
List<String> customerStrs;
|
|
|
|
|
|
|
|
try {
|
|
|
|
|
|
|
|
//获取客户联系人
|
|
|
|
|
|
|
|
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());
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|