提交 117ec7ed 作者: gh

人群包读取,客服推送

上级 aeca1804
...@@ -12,7 +12,7 @@ import org.springframework.scheduling.annotation.EnableScheduling; ...@@ -12,7 +12,7 @@ import org.springframework.scheduling.annotation.EnableScheduling;
* @date 2022/9/15 18:13 * @date 2022/9/15 18:13
*/ */
@SpringBootApplication @SpringBootApplication
@EnableScheduling //@EnableScheduling
@MapperScan("com.yaoyaozw.customer.mapper") @MapperScan("com.yaoyaozw.customer.mapper")
@EnableFeignClients @EnableFeignClients
@EnableAsync @EnableAsync
......
...@@ -83,7 +83,7 @@ public class CustomerServiceCommonAsyncComponent { ...@@ -83,7 +83,7 @@ public class CustomerServiceCommonAsyncComponent {
LOCAL_LOG.info("人群包ID: {} 新增用户 {}个", packIdStr, userNotInPackageList.size()); LOCAL_LOG.info("人群包ID: {} 新增用户 {}个", packIdStr, userNotInPackageList.size());
if (needRemove) { if (needRemove) {
// 当前在人群包内的用户 // 当前在人群包内的用户
List<CrowdPackageUserVO> packCurrentUserList = userEntityService.getCurrentInPackUserList(packageId); List<CrowdPackageUserVO> packCurrentUserList = userEntityService.getCurrentInPackUserList(packageId,true);
if (CollectionUtil.isNotEmpty(packCurrentUserList)) { if (CollectionUtil.isNotEmpty(packCurrentUserList)) {
List<String> userOpenIdList = userList.stream().map(CrowdPackageUserVO::getOpenId).collect(Collectors.toList()); List<String> userOpenIdList = userList.stream().map(CrowdPackageUserVO::getOpenId).collect(Collectors.toList());
// 筛选出之前在人群包内,现在不在地用户列表 // 筛选出之前在人群包内,现在不在地用户列表
......
package com.yaoyaozw.customer.controller;
import com.yaoyaozw.customer.dto.integration.IntegrationRequestDTO;
import com.yaoyaozw.customer.service.CustomerGraphicsService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;
import java.util.Calendar;
/**
* @author wgh
* @date 2022/10/10 20:04
*/
@RestController
@RequestMapping("/customer-service/test")
public class TestController {
@Autowired
private CustomerGraphicsService customerGraphicsService;
@GetMapping("/CustomerTest")
public void test(){
Calendar calendar = Calendar.getInstance();
calendar.set(Calendar.AM_PM,0);
calendar.set(Calendar.HOUR,20);
calendar.set(Calendar.MINUTE,0);
calendar.set(Calendar.SECOND, 0);
calendar.set(Calendar.MILLISECOND, 0);
IntegrationRequestDTO integrationRequestDTO = new IntegrationRequestDTO();
integrationRequestDTO.setRequestDate(calendar.getTime());
customerGraphicsService.sendCustomerMessage(integrationRequestDTO);
}
}
...@@ -8,7 +8,7 @@ import lombok.Data; ...@@ -8,7 +8,7 @@ import lombok.Data;
import org.springframework.data.annotation.Id; import org.springframework.data.annotation.Id;
/** /**
* 客户图片 * 客服素材
* *
* @author Admin * @author Admin
* @date 2022/10/08 * @date 2022/10/08
...@@ -86,6 +86,9 @@ public class CustomerGraphics implements Serializable { ...@@ -86,6 +86,9 @@ public class CustomerGraphics implements Serializable {
@TableField(value = "gmt_modified") @TableField(value = "gmt_modified")
private Date gmtModified; private Date gmtModified;
@TableField(value = "referral_size")
private Integer referralSize;
/** /**
* 逻辑删除 * 逻辑删除
*/ */
......
...@@ -44,4 +44,11 @@ public interface RegisterUserEntityMapper extends BaseMapper<RegisterUserEntity> ...@@ -44,4 +44,11 @@ public interface RegisterUserEntityMapper extends BaseMapper<RegisterUserEntity>
*/ */
List<CrowdPackageUserVO> getCurrentInPackUserList(@Param("packageId") Long packageId); List<CrowdPackageUserVO> getCurrentInPackUserList(@Param("packageId") Long packageId);
/**
* 查询包中用户(不左连查询表)
* @param packageId
* @return
*/
List<CrowdPackageUserVO> getCurrentInPackUserListWithoutAccountId(@Param("packageId") Long packageId);
} }
\ No newline at end of file
package com.yaoyaozw.customer.scheduling; package com.yaoyaozw.customer.scheduling;
import com.yaoyaozw.customer.dto.integration.IntegrationRequestDTO; import com.yaoyaozw.customer.dto.integration.IntegrationRequestDTO;
import com.yaoyaozw.customer.service.AccountOrderService; import com.yaoyaozw.customer.entity.CustomerGraphics;
import com.yaoyaozw.customer.service.RegisterUserEntityService; import com.yaoyaozw.customer.service.*;
import org.springframework.beans.factory.annotation.Autowired; import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.scheduling.annotation.Scheduled; import org.springframework.scheduling.annotation.Scheduled;
import org.springframework.stereotype.Component; import org.springframework.stereotype.Component;
...@@ -16,7 +16,10 @@ public class SchedulingTask { ...@@ -16,7 +16,10 @@ public class SchedulingTask {
private AccountOrderService accountOrderService; private AccountOrderService accountOrderService;
@Autowired @Autowired
private RegisterUserEntityService registerUserEntityService; private CustomerGraphicsService customerGraphicsService;
@Autowired
private CustomerDelayPublishService customerDelayPublishService;
/** /**
...@@ -58,6 +61,16 @@ public class SchedulingTask { ...@@ -58,6 +61,16 @@ public class SchedulingTask {
*/ */
public void publishCustomerMessage(){ public void publishCustomerMessage(){
Calendar calendar = Calendar.getInstance();
calendar.set(Calendar.SECOND, 0);
calendar.set(Calendar.MILLISECOND, 0);
IntegrationRequestDTO integrationRequestDTO = new IntegrationRequestDTO();
customerGraphicsService.sendCustomerMessage(integrationRequestDTO);
} }
...@@ -67,6 +80,14 @@ public class SchedulingTask { ...@@ -67,6 +80,14 @@ public class SchedulingTask {
*/ */
public void publishDelayCustomerMessage(){ public void publishDelayCustomerMessage(){
Calendar calendar = Calendar.getInstance();
calendar.set(Calendar.SECOND, 0);
calendar.set(Calendar.MILLISECOND, 0);
IntegrationRequestDTO integrationRequestDTO = new IntegrationRequestDTO();
customerDelayPublishService.sendCustomerDelayMessage(integrationRequestDTO);
} }
} }
...@@ -67,6 +67,10 @@ public interface CustomerGraphicsService extends IService<CustomerGraphics> { ...@@ -67,6 +67,10 @@ public interface CustomerGraphicsService extends IService<CustomerGraphics> {
BaseResult setPack(Long id, Long packId); BaseResult setPack(Long id, Long packId);
/**
* 客服发送
* @param integrationRequestDTO 请求DTO
*/
void sendCustomerMessage(IntegrationRequestDTO integrationRequestDTO); void sendCustomerMessage(IntegrationRequestDTO integrationRequestDTO);
} }
......
...@@ -20,6 +20,10 @@ public interface ReferralEntityService extends IService<ReferralEntity> { ...@@ -20,6 +20,10 @@ public interface ReferralEntityService extends IService<ReferralEntity> {
*/ */
void ultimateDeleteReferrals(Long sourceId); void ultimateDeleteReferrals(Long sourceId);
/**
* 根据客服id找链接
* @param graphicsId 客服主体id
* @return
*/
List<ReferralEntityVo> findReferralByCustomerGraphicsId(Long graphicsId); List<ReferralEntityVo> findReferralByCustomerGraphicsId(Long graphicsId);
} }
...@@ -33,7 +33,7 @@ public interface RegisterUserEntityService extends IService<RegisterUserEntity>{ ...@@ -33,7 +33,7 @@ public interface RegisterUserEntityService extends IService<RegisterUserEntity>{
* @param packageId 包id * @param packageId 包id
* @return {@link List}<{@link CrowdPackageUserVO}> * @return {@link List}<{@link CrowdPackageUserVO}>
*/ */
List<CrowdPackageUserVO> getCurrentInPackUserList(Long packageId); List<CrowdPackageUserVO> getCurrentInPackUserList(Long packageId,Boolean isLeftJoin);
......
...@@ -7,6 +7,7 @@ import cn.hutool.core.util.ObjectUtil; ...@@ -7,6 +7,7 @@ import cn.hutool.core.util.ObjectUtil;
import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper; import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
import com.github.pagehelper.PageHelper; import com.github.pagehelper.PageHelper;
import com.github.pagehelper.PageInfo; import com.github.pagehelper.PageInfo;
import com.sun.xml.internal.bind.v2.TODO;
import com.yaoyaozw.customer.common.BaseResult; import com.yaoyaozw.customer.common.BaseResult;
import com.yaoyaozw.customer.common.GenericsResult; import com.yaoyaozw.customer.common.GenericsResult;
import com.yaoyaozw.customer.components.CustomerServiceCommonAsyncComponent; import com.yaoyaozw.customer.components.CustomerServiceCommonAsyncComponent;
...@@ -193,23 +194,17 @@ public class CustomerGraphicsServiceImpl extends ServiceImpl<CustomerGraphicsMap ...@@ -193,23 +194,17 @@ public class CustomerGraphicsServiceImpl extends ServiceImpl<CustomerGraphicsMap
public void sendCustomerMessage(IntegrationRequestDTO integrationRequestDTO) { public void sendCustomerMessage(IntegrationRequestDTO integrationRequestDTO) {
Date requestDate = integrationRequestDTO.getRequestDate(); Date requestDate = integrationRequestDTO.getRequestDate();
//todo:当前时刻发送的客服(需要加启用禁用)
//当前时刻发送的客服(需要加启用禁用)
List<CustomerGraphics> customerGraphicsList = list(new QueryWrapper<CustomerGraphics>().eq(CustomerGraphics.COL_POST_TIME, requestDate)); List<CustomerGraphics> customerGraphicsList = list(new QueryWrapper<CustomerGraphics>().eq(CustomerGraphics.COL_POST_TIME, requestDate));
for (CustomerGraphics customerGraphics : customerGraphicsList) { for (CustomerGraphics customerGraphics : customerGraphicsList) {
//人群包id
Long packId = customerGraphics.getPackId(); Long packId = customerGraphics.getPackId();
//根据人群包找人,并按appId分组
/* List<CrowdPackageUserVO> userList = registerUserEntityService.getCurrentInPackUserList(packId, false);
根据人群包找人
*/
List<CrowdPackageUserVO> userList=new ArrayList<>();
Map<String, List<CrowdPackageUserVO>> appidUserMap = userList.stream().collect(Collectors.groupingBy(CrowdPackageUserVO::getAppId)); Map<String, List<CrowdPackageUserVO>> appidUserMap = userList.stream().collect(Collectors.groupingBy(CrowdPackageUserVO::getAppId));
//根据客服id找不同公众号的链接,并按appId分组
//根据公众号找具体素材和链接
List<ReferralEntityVo> referralList = referralEntityService.findReferralByCustomerGraphicsId(customerGraphics.getId()); List<ReferralEntityVo> referralList = referralEntityService.findReferralByCustomerGraphicsId(customerGraphics.getId());
Map<String, List<ReferralEntityVo>> referralMap = referralList.stream().collect(Collectors.groupingBy(ReferralEntityVo::getAppid)); Map<String, List<ReferralEntityVo>> referralMap = referralList.stream().collect(Collectors.groupingBy(ReferralEntityVo::getAppid));
...@@ -228,7 +223,7 @@ public class CustomerGraphicsServiceImpl extends ServiceImpl<CustomerGraphicsMap ...@@ -228,7 +223,7 @@ public class CustomerGraphicsServiceImpl extends ServiceImpl<CustomerGraphicsMap
if (referralEntityVo!=null&&!referralEntityVo.isEmpty()){ if (referralEntityVo!=null&&!referralEntityVo.isEmpty()){
weChatService.sendCustomerMessage(appid,authorizerToken.getAuthorizerAccessToken(),customerGraphics,packageUserVo,referralEntityVo); weChatService.sendCustomerMessage(appid,authorizerToken,customerGraphics,packageUserVo,referralEntityVo);
} }
} }
} }
......
...@@ -39,11 +39,21 @@ public class RegisterUserEntityServiceImpl extends ServiceImpl<RegisterUserEntit ...@@ -39,11 +39,21 @@ public class RegisterUserEntityServiceImpl extends ServiceImpl<RegisterUserEntit
@Override @Override
public List<Long> getAccountIdListFromPackage(Long packageId) { public List<Long> getAccountIdListFromPackage(Long packageId) {
return baseMapper.getAuthListFromPackage(packageId); return baseMapper.getAuthListFromPackage(packageId);
} }
@Override @Override
public List<CrowdPackageUserVO> getCurrentInPackUserList(Long packageId) { public List<CrowdPackageUserVO> getCurrentInPackUserList(Long packageId,Boolean isLeftJoin) {
if (isLeftJoin!=null&&isLeftJoin){
return baseMapper.getCurrentInPackUserList(packageId); return baseMapper.getCurrentInPackUserList(packageId);
}else {
return baseMapper.getCurrentInPackUserListWithoutAccountId(packageId);
}
} }
} }
package com.yaoyaozw.customer.service.wechat.service; package com.yaoyaozw.customer.service.wechat.service;
import com.yaoyaozw.customer.entity.AuthorizerToken;
import com.yaoyaozw.customer.entity.CustomerDelayPublish; import com.yaoyaozw.customer.entity.CustomerDelayPublish;
import com.yaoyaozw.customer.entity.CustomerGraphics; import com.yaoyaozw.customer.entity.CustomerGraphics;
import com.yaoyaozw.customer.entity.RegisterUserEntity; import com.yaoyaozw.customer.entity.RegisterUserEntity;
...@@ -18,6 +19,6 @@ public interface WeChatService { ...@@ -18,6 +19,6 @@ public interface WeChatService {
*/ */
Future<CustomerDelayPublish> sendCustomerDelayMessage(String token, CustomerDelayPublish user, Map<Integer,CustomerDelayItemVO>delaySortMap); Future<CustomerDelayPublish> sendCustomerDelayMessage(String token, CustomerDelayPublish user, Map<Integer,CustomerDelayItemVO>delaySortMap);
void sendCustomerMessage(String appid,String token, CustomerGraphics customerGraphics, List<CrowdPackageUserVO>openidList,List<ReferralEntityVo> referralEntityVo); void sendCustomerMessage(String appid, AuthorizerToken authorizerToken, CustomerGraphics customerGraphics, List<CrowdPackageUserVO>openidList, List<ReferralEntityVo> referralEntityVo);
} }
package com.yaoyaozw.customer.service.wechat.service; package com.yaoyaozw.customer.service.wechat.service;
import com.yaoyaozw.customer.entity.AuthorizerToken;
import com.yaoyaozw.customer.entity.CustomerDelayPublish; import com.yaoyaozw.customer.entity.CustomerDelayPublish;
import com.yaoyaozw.customer.entity.CustomerGraphics; import com.yaoyaozw.customer.entity.CustomerGraphics;
import com.yaoyaozw.customer.service.ReferralEntityService; import com.yaoyaozw.customer.service.ReferralEntityService;
...@@ -23,17 +24,24 @@ import java.util.Date; ...@@ -23,17 +24,24 @@ import java.util.Date;
import java.util.List; import java.util.List;
import java.util.Map; import java.util.Map;
import java.util.concurrent.Future; import java.util.concurrent.Future;
import java.util.concurrent.LinkedBlockingQueue;
import java.util.concurrent.ThreadPoolExecutor;
import java.util.concurrent.TimeUnit;
import java.util.stream.Collectors; import java.util.stream.Collectors;
@Service @Service
public class WeChatServiceImpl implements WeChatService{ public class WeChatServiceImpl implements WeChatService{
private String customerPath=""; private String customerPath="https://api.weixin.qq.com/cgi-bin/message/custom/send";
private static final String CUSTOMER_TEXT="text"; private static final String CUSTOMER_TEXT="text";
private static final String CUSTOMER_NEWS="news"; private static final String CUSTOMER_NEWS="news";
private static final int THREAD_NUM=1000;
private static final ThreadPoolExecutor EXECUTOR = new ThreadPoolExecutor(20, 100, 60L, TimeUnit.SECONDS, new LinkedBlockingQueue<>(2),new ThreadPoolExecutor.CallerRunsPolicy());
@Autowired @Autowired
private WeChatRestService weChatRestService; private WeChatRestService weChatRestService;
...@@ -58,38 +66,72 @@ public class WeChatServiceImpl implements WeChatService{ ...@@ -58,38 +66,72 @@ public class WeChatServiceImpl implements WeChatService{
@Override @Override
public void sendCustomerMessage(String appid,String token, CustomerGraphics customerGraphics, List<CrowdPackageUserVO> openidList,List<ReferralEntityVo> referralEntityVo) { public void sendCustomerMessage(String appid, AuthorizerToken authorizerToken, CustomerGraphics customerGraphics, List<CrowdPackageUserVO> openidList, List<ReferralEntityVo> referralEntityVo) {
//根据公众号发送客服 //根据公众号发送客服
String fullPath=customerPath+"?"+token; String fullPath=customerPath+"?access_token="+authorizerToken.getAuthorizerAccessToken();
//构建请求参数(文本/图文) //构建请求参数(文本/图文)
WeChatCustomerRequestEntity customerRequest = buildCustomerRequest(customerGraphics,referralEntityVo); WeChatCustomerRequestEntity customerRequest = buildCustomerRequest(customerGraphics,referralEntityVo);
if (customerRequest!=null){
for (int i = 0; i < openidList.size(); i+=THREAD_NUM) {
List<CrowdPackageUserVO> subOpenidList = openidList.subList(i, Math.min(i + THREAD_NUM, openidList.size()));
//TODO:配置多线程+测试
EXECUTOR.execute(()->{
for (CrowdPackageUserVO crowdPackageUserVO : subOpenidList) {
//遍历人群包,每个用户一发
customerRequest.setTouser(crowdPackageUserVO.getOpenId());
try { try {
System.err.println(customerRequest.getTouser());
ResponseEntity<WeChatResponseEntity> response = weChatRestService.sendPostRequest(fullPath, WeChatResponseEntity.class, customerRequest); ResponseEntity<WeChatResponseEntity> response = weChatRestService.sendPostRequest(fullPath, WeChatResponseEntity.class, customerRequest);
WeChatResponseEntity body = response.getBody(); WeChatResponseEntity body = response.getBody();
System.err.println(body); System.err.println(body);
} catch (URISyntaxException e) { } catch (Exception e) {
e.printStackTrace(); e.printStackTrace();
} }
}
});
}
}
} }
private WeChatCustomerRequestEntity buildCustomerRequest(CustomerGraphics customerGraphics,List<ReferralEntityVo> urlList){ private WeChatCustomerRequestEntity buildCustomerRequest(CustomerGraphics customerGraphics,List<ReferralEntityVo> urlList){
//类型判断 //类型判断
if (CUSTOMER_TEXT.equals(customerGraphics.getType())){ if (CUSTOMER_TEXT.equals(customerGraphics.getType())){
//文本类客服,需要判断替换链接的个数
Map<Integer, String> sortReferral = urlList.stream().collect(Collectors.toMap(ReferralEntityVo::getSort, ReferralEntityVo::getReferral, (v1, v2) -> v2));
return new WeChatCustomerRequestEntity(CUSTOMER_TEXT,customerGraphics.getContent()); if (customerGraphics.getReferralSize()!=null&&customerGraphics.getReferralSize().equals(sortReferral.size())){
}else if (CUSTOMER_NEWS.equals(customerGraphics.getType())){ String content = customerGraphics.getContent();
//TODO:配置文本,多条链接替换进content
for (Map.Entry<Integer, String> replaceReferral : sortReferral.entrySet()) {
return new WeChatCustomerRequestEntity(CUSTOMER_NEWS,customerGraphics.getExtendTitle(),urlList.get(0).getReferral(),customerGraphics.getContent(),customerGraphics.getCoverUrl()); Integer sort = replaceReferral.getKey();
String url = replaceReferral.getValue();
//替换占位符
content=content.replace("占位符常量" + sort, url);
}
return new WeChatCustomerRequestEntity(CUSTOMER_TEXT,content);
}else{
return null;
} }
}else if (CUSTOMER_NEWS.equals(customerGraphics.getType())){
return new WeChatCustomerRequestEntity(CUSTOMER_NEWS,customerGraphics.getExtendTitle(),customerGraphics.getContent(),urlList.get(0).getReferral(),customerGraphics.getCoverUrl());
}
return null; return null;
} }
} }
...@@ -13,9 +13,13 @@ public class ReferralEntityVo implements Serializable { ...@@ -13,9 +13,13 @@ public class ReferralEntityVo implements Serializable {
private Long materialGraphicsId; private Long materialGraphicsId;
private Long accountId; private String accountId;
private String appid; private String appid;
private String referral; private String referral;
private Integer sort;
} }
...@@ -32,13 +32,13 @@ ...@@ -32,13 +32,13 @@
<select id="findByMaterialGraphicsId" resultType="com.yaoyaozw.customer.vo.referral.ReferralEntityVo"> <select id="findByMaterialGraphicsId" resultType="com.yaoyaozw.customer.vo.referral.ReferralEntityVo">
select material_graphics_id ,referral.account_id,authInfo.appid,referral.referral select material_graphics_id ,referral.account_id,authInfo.appid,referral.referral,referral.sort
from referral_entity referral left join authorizer_info authInfo from referral_entity referral left join authorizer_info authInfo
on referral.account_id=authInfo.account_id on referral.account_id=authInfo.account_id
where referral.material_graphics_id=#{graphicsId} and referral.is_deleted=0 where referral.material_graphics_id=#{graphicsId} and referral.is_deleted=0 and referral.account_id is not null
......
...@@ -85,4 +85,18 @@ ...@@ -85,4 +85,18 @@
</select> </select>
<select id="getCurrentInPackUserListWithoutAccountId" resultType="com.yaoyaozw.customer.vo.customer.CrowdPackageUserVO">
select
id,
setup_id,
open_id,
in_Package,
app_id
from register_user_entity
where find_in_set(#{packageId}, in_package)
</select>
</mapper> </mapper>
\ No newline at end of file
Markdown 格式
0%
您添加了 0 到此讨论。请谨慎行事。
请先完成此评论的编辑!
注册 或者 后发表评论