提交 a8a134cb 作者: 卢宇

发送客服消息适配小程序

上级 8acace10
...@@ -226,6 +226,10 @@ public class ReferralEntity implements Serializable { ...@@ -226,6 +226,10 @@ public class ReferralEntity implements Serializable {
@ApiModelProperty("小程序跳转路径") @ApiModelProperty("小程序跳转路径")
private String mpPath; private String mpPath;
@TableField(value = "media_id")
@ApiModelProperty("图片公众号后台id")
private String mediaId;
@TableField(exist = false) @TableField(exist = false)
private String h5Content; private String h5Content;
......
...@@ -36,4 +36,6 @@ public interface ReferralEntityMapper extends BaseMapper<ReferralEntity> { ...@@ -36,4 +36,6 @@ public interface ReferralEntityMapper extends BaseMapper<ReferralEntity> {
* @param extraCondition 特殊条件表达式 * @param extraCondition 特殊条件表达式
*/ */
void ultimateDeleteReferralsBatch(@Param("sourceIdList") List<Long> sourceIdList, @Param("extraCondition") String extraCondition); void ultimateDeleteReferralsBatch(@Param("sourceIdList") List<Long> sourceIdList, @Param("extraCondition") String extraCondition);
List<ReferralEntityVo> findReferralMiniByCustomerGraphicsId(@Param("graphicsId")Long graphicsId);
} }
\ No newline at end of file
...@@ -35,4 +35,11 @@ public interface ReferralEntityService extends IService<ReferralEntity> { ...@@ -35,4 +35,11 @@ public interface ReferralEntityService extends IService<ReferralEntity> {
* @return * @return
*/ */
List<ReferralEntityVo> findReferralByCustomerGraphicsId(Long graphicsId); List<ReferralEntityVo> findReferralByCustomerGraphicsId(Long graphicsId);
/**
* 根据客服id找小程序链接
* @param graphicsId 客服主体id
* @return
*/
List<ReferralEntityVo> findReferralMiniByCustomerGraphicsId(Long graphicsId);
} }
package com.yaoyaozw.customer.service.impl; package com.yaoyaozw.customer.service.impl;
import cn.hutool.core.bean.BeanUtil; import cn.hutool.core.bean.BeanUtil;
import cn.hutool.core.collection.CollectionUtil;
import cn.hutool.core.util.ObjectUtil; import cn.hutool.core.util.ObjectUtil;
import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper; import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl; import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
...@@ -24,6 +25,8 @@ import org.springframework.beans.factory.annotation.Autowired; ...@@ -24,6 +25,8 @@ import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service; import org.springframework.stereotype.Service;
import org.springframework.transaction.annotation.Transactional; import org.springframework.transaction.annotation.Transactional;
import java.util.List;
@Service @Service
public class CustomerGraphicsMiniProgramServiceImpl extends ServiceImpl<CustomerGraphicsMapper, CustomerGraphics> implements CustomerGraphicsMiniProgramService { public class CustomerGraphicsMiniProgramServiceImpl extends ServiceImpl<CustomerGraphicsMapper, CustomerGraphics> implements CustomerGraphicsMiniProgramService {
...@@ -84,11 +87,13 @@ public class CustomerGraphicsMiniProgramServiceImpl extends ServiceImpl<Customer ...@@ -84,11 +87,13 @@ public class CustomerGraphicsMiniProgramServiceImpl extends ServiceImpl<Customer
miniProgramDTO.setPostTime(customerGraphics.getPostTimeStr()); miniProgramDTO.setPostTime(customerGraphics.getPostTimeStr());
// 获取链接数据 // 获取链接数据
ReferralEntity referralEntity = referralEntityService.getOne(new QueryWrapper<ReferralEntity>().eq("material_graphics_id", id).isNull("account_id")); List<ReferralEntity> referralEntityList = referralEntityService.list(new QueryWrapper<ReferralEntity>().eq("material_graphics_id", id).eq("is_deleted",0).
isNull("account_id"));
if (ObjectUtil.isNull(referralEntity)) { if (CollectionUtil.isEmpty(referralEntityList)) {
return new GenericsResult<>(false, "找不到链接数据"); return new GenericsResult<>(false, "找不到链接数据");
} }
ReferralEntity referralEntity = referralEntityList.get(0);
miniProgramDTO.setMpAppId(referralEntity.getMpAppId()); miniProgramDTO.setMpAppId(referralEntity.getMpAppId());
miniProgramDTO.setMpTitle(referralEntity.getMpTitle()); miniProgramDTO.setMpTitle(referralEntity.getMpTitle());
miniProgramDTO.setMpPath(referralEntity.getMpPath()); miniProgramDTO.setMpPath(referralEntity.getMpPath());
......
...@@ -42,6 +42,8 @@ import com.yaoyaozw.customer.service.CustomerGraphicsService; ...@@ -42,6 +42,8 @@ import com.yaoyaozw.customer.service.CustomerGraphicsService;
import org.springframework.transaction.annotation.Transactional; import org.springframework.transaction.annotation.Transactional;
import org.springframework.transaction.interceptor.TransactionAspectSupport; import org.springframework.transaction.interceptor.TransactionAspectSupport;
import static com.yaoyaozw.customer.constants.CustomerCommonConstant.CUSTOMER_TYPE_VALUE_MINI_PROGRAM;
import static com.yaoyaozw.customer.constants.CustomerMaterialConstant.TENCENT_MEDIA_TYPE_MINI_PROGRAM;
import static java.util.stream.Collectors.toCollection; import static java.util.stream.Collectors.toCollection;
/** /**
...@@ -260,21 +262,34 @@ public class CustomerGraphicsServiceImpl extends ServiceImpl<CustomerGraphicsMap ...@@ -260,21 +262,34 @@ public class CustomerGraphicsServiceImpl extends ServiceImpl<CustomerGraphicsMap
.collect(Collectors.groupingBy(CrowdPackageUserVO::getAppId, Collectors.collectingAndThen(toCollection(() -> new TreeSet<>(Comparator.comparing(CrowdPackageUserVO::getOpenId))), ArrayList::new))); .collect(Collectors.groupingBy(CrowdPackageUserVO::getAppId, Collectors.collectingAndThen(toCollection(() -> new TreeSet<>(Comparator.comparing(CrowdPackageUserVO::getOpenId))), ArrayList::new)));
//根据客服id找不同公众号的链接,并按appId分组 //根据客服id找不同公众号的链接,并按appId分组
List<ReferralEntityVo> referralList = referralEntityService.findReferralByCustomerGraphicsId(customerGraphics.getId());
Map<String, List<ReferralEntityVo>> referralMap = referralList.stream().filter(a->StringUtils.isNotBlank(a.getReferral())).collect(Collectors.groupingBy(ReferralEntityVo::getAppid)); List<ReferralEntityVo> referralList=new ArrayList<>();
Map<String, List<ReferralEntityVo>> referralMap=new HashMap<>();
if (customerGraphics.getType().equals(CUSTOMER_TYPE_VALUE_MINI_PROGRAM)){
referralList=referralEntityService.findReferralMiniByCustomerGraphicsId(customerGraphics.getId());
}else {
referralList = referralEntityService.findReferralByCustomerGraphicsId(customerGraphics.getId());
referralMap = referralList.stream().filter(a->StringUtils.isNotBlank(a.getReferral())).collect(Collectors.groupingBy(ReferralEntityVo::getAppid));
}
//循环该人群包下的所有素材 //循环该人群包下的所有素材
int singleUserCount = 0; int singleUserCount = 0;
for (Map.Entry<String, List<CrowdPackageUserVO>> usersEntry : appidUserMap.entrySet()) { for (Map.Entry<String, List<CrowdPackageUserVO>> usersEntry : appidUserMap.entrySet()) {
String appid = usersEntry.getKey(); String appid = usersEntry.getKey();
try { //获取该号的链接实体 try { //获取该号的链接实体
List<ReferralEntityVo> referralEntityVo = referralMap.get(appid); if (customerGraphics.getType().equals(CUSTOMER_TYPE_VALUE_MINI_PROGRAM)){
//获取该号的openid //获取该号的openid
List<CrowdPackageUserVO> packageUserVo = usersEntry.getValue(); List<CrowdPackageUserVO> packageUserVo = usersEntry.getValue();
singleUserCount += packageUserVo.size(); singleUserCount += packageUserVo.size();
weChatService.sendCustomerMessage(appid,customerGraphics,packageUserVo,referralEntityVo); weChatService.sendCustomerMessage(appid,customerGraphics,packageUserVo,referralList);
}else {
List<ReferralEntityVo> referralEntityVo = referralMap.get(appid);
//获取该号的openid
List<CrowdPackageUserVO> packageUserVo = usersEntry.getValue();
singleUserCount += packageUserVo.size();
weChatService.sendCustomerMessage(appid,customerGraphics,packageUserVo,referralEntityVo);
}
}catch (Exception e){ }catch (Exception e){
LOCAL_LOG.error("{} send CustomerMessage failed for {}",appid,e.getStackTrace()[0]); LOCAL_LOG.error("{} send CustomerMessage failed for {}",appid,e.getStackTrace()[0]);
} }
......
...@@ -9,6 +9,7 @@ import com.yaoyaozw.customer.service.ReferralEntityService; ...@@ -9,6 +9,7 @@ import com.yaoyaozw.customer.service.ReferralEntityService;
import com.yaoyaozw.customer.vo.referral.ReferralEntityVo; import com.yaoyaozw.customer.vo.referral.ReferralEntityVo;
import org.springframework.stereotype.Service; import org.springframework.stereotype.Service;
import java.util.Collections;
import java.util.List; import java.util.List;
/** /**
...@@ -39,4 +40,9 @@ public class ReferralEntityServiceImpl extends ServiceImpl<ReferralEntityMapper, ...@@ -39,4 +40,9 @@ public class ReferralEntityServiceImpl extends ServiceImpl<ReferralEntityMapper,
return baseMapper.findByMaterialGraphicsId(graphicsId); return baseMapper.findByMaterialGraphicsId(graphicsId);
} }
@Override
public List<ReferralEntityVo> findReferralMiniByCustomerGraphicsId(Long graphicsId) {
return baseMapper.findReferralMiniByCustomerGraphicsId(graphicsId);
}
} }
package com.yaoyaozw.customer.service.wechat.entity.customerRequest;
import lombok.AllArgsConstructor;
import lombok.Data;
import lombok.NoArgsConstructor;
@Data
@NoArgsConstructor
@AllArgsConstructor
public class CustomerMiniProgram {
private String title;
private String appId;
private String pagepath;
private String thumb_media_id;
}
...@@ -22,6 +22,8 @@ public class WeChatCustomerRequestEntity implements Serializable { ...@@ -22,6 +22,8 @@ public class WeChatCustomerRequestEntity implements Serializable {
private CustomerTextItem text; private CustomerTextItem text;
private CustomerMiniProgram miniprogrampage;
public WeChatCustomerRequestEntity( String msgtype, String title, String description, String url, String picurl) { public WeChatCustomerRequestEntity( String msgtype, String title, String description, String url, String picurl) {
this.msgtype = msgtype; this.msgtype = msgtype;
...@@ -34,6 +36,12 @@ public class WeChatCustomerRequestEntity implements Serializable { ...@@ -34,6 +36,12 @@ public class WeChatCustomerRequestEntity implements Serializable {
this.text = new CustomerTextItem(content); this.text = new CustomerTextItem(content);
} }
public WeChatCustomerRequestEntity(String msgtype, String mpTitle,String mpAppId,String mpPath,String mediaId,String id) {
this.msgtype = msgtype;
this.miniprogrampage = new CustomerMiniProgram(mpTitle,mpAppId,mpPath,mediaId);
}
public WeChatCustomerRequestEntity() { public WeChatCustomerRequestEntity() {
} }
......
...@@ -15,6 +15,8 @@ import com.yaoyaozw.customer.vo.customer.CrowdPackageUserVO; ...@@ -15,6 +15,8 @@ import com.yaoyaozw.customer.vo.customer.CrowdPackageUserVO;
import com.yaoyaozw.customer.vo.customer.CustomerDelayItemVO; import com.yaoyaozw.customer.vo.customer.CustomerDelayItemVO;
import com.yaoyaozw.customer.vo.referral.ReferralEntityVo; import com.yaoyaozw.customer.vo.referral.ReferralEntityVo;
import org.apache.commons.lang3.StringUtils; import org.apache.commons.lang3.StringUtils;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.amqp.rabbit.core.RabbitTemplate; import org.springframework.amqp.rabbit.core.RabbitTemplate;
import org.springframework.beans.factory.annotation.Autowired; import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.data.redis.core.RedisTemplate; import org.springframework.data.redis.core.RedisTemplate;
...@@ -35,6 +37,8 @@ public class WeChatServiceImpl implements WeChatService{ ...@@ -35,6 +37,8 @@ public class WeChatServiceImpl implements WeChatService{
private static final String CUSTOMER_NEWS="news"; private static final String CUSTOMER_NEWS="news";
private static final String MINI_PROGRAM="miniProgram";
private static final int THREAD_SIZE=1000; private static final int THREAD_SIZE=1000;
private static final Integer SUCCESS_CODE=0; private static final Integer SUCCESS_CODE=0;
...@@ -228,6 +232,10 @@ public class WeChatServiceImpl implements WeChatService{ ...@@ -228,6 +232,10 @@ public class WeChatServiceImpl implements WeChatService{
if (urlList!=null&&!urlList.isEmpty()){ if (urlList!=null&&!urlList.isEmpty()){
return new WeChatCustomerRequestEntity(CUSTOMER_NEWS,customerGraphics.getExtendTitle(),customerGraphics.getContent(),urlList.get(0).getReferral(),customerGraphics.getCoverUrl()); return new WeChatCustomerRequestEntity(CUSTOMER_NEWS,customerGraphics.getExtendTitle(),customerGraphics.getContent(),urlList.get(0).getReferral(),customerGraphics.getCoverUrl());
} }
}else if (MINI_PROGRAM.equals(customerGraphics.getType())){
if (urlList!=null&&!urlList.isEmpty()){
return new WeChatCustomerRequestEntity(MINI_PROGRAM,urlList.get(0).getMpTitle(),urlList.get(0).getMpAppId(),urlList.get(0).getMpPath(),urlList.get(0).getMediaId(),null);
}
} }
return null; return null;
} }
......
package com.yaoyaozw.customer.vo.referral; package com.yaoyaozw.customer.vo.referral;
import com.baomidou.mybatisplus.annotation.TableField;
import io.swagger.annotations.ApiModelProperty;
import lombok.Data; import lombok.Data;
import java.io.Serializable; import java.io.Serializable;
...@@ -21,5 +23,13 @@ public class ReferralEntityVo implements Serializable { ...@@ -21,5 +23,13 @@ public class ReferralEntityVo implements Serializable {
private Integer sort; private Integer sort;
private String mpTitle;
private String mpAppId;
private String mpPath;
private String mediaId;
} }
...@@ -48,6 +48,14 @@ ...@@ -48,6 +48,14 @@
</select> </select>
<select id="findReferralMiniByCustomerGraphicsId" resultType="com.yaoyaozw.customer.vo.referral.ReferralEntityVo">
select material_graphics_id ,referral.account_id,referral.referral,referral.sort,referral.mp_title,referral.mp_app_id,referral.mp_path,
referral.media_id
from referral_entity referral
where referral.material_graphics_id=#{graphicsId} and referral.is_deleted=0
</select>
<delete id="ultimateDeleteReferralsBatch"> <delete id="ultimateDeleteReferralsBatch">
delete from referral_entity delete from referral_entity
where material_graphics_id in where material_graphics_id in
......
Markdown 格式
0%
您添加了 0 到此讨论。请谨慎行事。
请先完成此评论的编辑!
注册 或者 后发表评论