Commit de3f6621 by sunxiwang

修复新客拉群相关bug

1 parent 3a7a9343
......@@ -100,7 +100,7 @@ public class WeCommunityNewGroupController extends BaseController {
.map(e -> {
WeEmpleCode code = weEmpleCodeService.getById(e.getEmplCodeId());
Map<String, String> fileMap = new HashMap<>();
fileMap.put("fileName", code.getUseUserName() + "-" + code.getScenario()+".jpg");
fileMap.put("fileName", code.getScenario()+".jpg");
fileMap.put("url", code.getQrCode());
return fileMap;
})
......
......@@ -64,6 +64,10 @@ public class WeConstans {
* 活码前缀
*/
public static final String WE_QR_CODE_PREFIX = "we_qr";
/**
* 新客拉群
*/
public static final String WE_QR_XKLQ_PREFIX = "we_xklq";
/**
......
......@@ -16,6 +16,7 @@ import java.util.List;
import javax.validation.constraints.NotNull;
import javax.validation.constraints.Size;
import lombok.Builder;
import lombok.Data;
/**
......@@ -26,6 +27,7 @@ import lombok.Data;
*/
@ApiModel
@Data
@Builder
@SuppressWarnings("serial")
@TableName("we_qr_attachments")
public class WeQrAttachments extends BaseEntity implements Serializable {
......
package com.linkwechat.wecom.domain.vo;
import com.linkwechat.wecom.domain.vo.tag.WeTagVo;
import lombok.Data;
import java.util.List;
/**
* 社区运营 新客自动拉群
*/
@Data
public class WeCommunityWeComeMsgVo {
private Long id;
/**
* 群活码路径
*/
private String codeUrl;
/**
* 欢迎语
*/
private String welcomeMsg;
/**
* 客户标签列表
*/
private List<WeTagVo> tagList;
}
......@@ -3,6 +3,7 @@ package com.linkwechat.wecom.mapper;
import com.baomidou.mybatisplus.core.mapper.BaseMapper;
import com.linkwechat.wecom.domain.WeCommunityNewGroup;
import com.linkwechat.wecom.domain.vo.WeCommunityNewGroupVo;
import com.linkwechat.wecom.domain.vo.WeCommunityWeComeMsgVo;
import org.apache.ibatis.annotations.Mapper;
import org.apache.ibatis.annotations.Param;
import org.springframework.stereotype.Repository;
......@@ -22,10 +23,10 @@ public interface WeCommunityNewGroupMapper extends BaseMapper<WeCommunityNewGrou
/**
* 查询新客自动拉群列表
*
* @param emplCodeName 员工名称
* @param createBy 创建人
* @param beginTime 开始时间
* @param endTime 结束时间
* @param /emplCodeName 员工名称
* @param /createBy 创建人
* @param /beginTime 开始时间
* @param /endTime 结束时间
* @return {WeCommunityNewGroupVo}s 列表
*/
// List<WeCommunityNewGroupVo> selectWeCommunityNewGroupList(@Param("emplCodeName") String emplCodeName, @Param("createBy") String createBy
......@@ -61,4 +62,6 @@ public interface WeCommunityNewGroupMapper extends BaseMapper<WeCommunityNewGrou
* @return 结果
*/
int removeWeCommunityNewGroupByEmplCodeId(@Param("emplCodeId") Long emplCodeId);
WeCommunityWeComeMsgVo getWelcomeMsgByState(@Param("state") String state);
}
......@@ -4,6 +4,7 @@ import com.baomidou.mybatisplus.extension.service.IService;
import com.linkwechat.wecom.domain.WeCommunityNewGroup;
import com.linkwechat.wecom.domain.dto.WeCommunityNewGroupDto;
import com.linkwechat.wecom.domain.vo.WeCommunityNewGroupVo;
import com.linkwechat.wecom.domain.vo.WeCommunityWeComeMsgVo;
import java.util.List;
import java.util.Optional;
......@@ -73,4 +74,5 @@ public interface IWeCommunityNewGroupService extends IService<WeCommunityNewGrou
*/
List<WeCommunityNewGroupVo> selectWeCommunityNewGroupByIds(List<Long> ids);
WeCommunityWeComeMsgVo getWelcomeMsgByState(String state);
}
package com.linkwechat.wecom.service.impl;
import cn.hutool.core.collection.CollectionUtil;
import cn.hutool.core.lang.Snowflake;
import cn.hutool.core.util.IdUtil;
import cn.hutool.core.util.RandomUtil;
import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper;
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import com.linkwechat.common.constant.WeConstans;
import com.linkwechat.common.enums.WeEmpleCodeType;
import com.linkwechat.common.exception.wecom.WeComException;
import com.linkwechat.common.utils.SecurityUtils;
......@@ -12,6 +16,7 @@ import com.linkwechat.wecom.domain.*;
import com.linkwechat.wecom.domain.dto.WeCommunityNewGroupDto;
import com.linkwechat.wecom.domain.dto.WeExternalContactDto;
import com.linkwechat.wecom.domain.vo.WeCommunityNewGroupVo;
import com.linkwechat.wecom.domain.vo.WeCommunityWeComeMsgVo;
import com.linkwechat.wecom.domain.vo.WeGroupCodeVo;
import com.linkwechat.wecom.mapper.*;
import com.linkwechat.wecom.service.IWeCommunityNewGroupService;
......@@ -206,6 +211,11 @@ public class WeCommunityNewGroupServiceImpl extends ServiceImpl<WeCommunityNewGr
return weCommunityNewGroupMapper.selectWeCommunityNewGroupByIds(ids);
}
@Override
public WeCommunityWeComeMsgVo getWelcomeMsgByState(String state) {
return this.baseMapper.getWelcomeMsgByState(state);
}
/**
* 创建员工活码
*
......@@ -213,7 +223,7 @@ public class WeCommunityNewGroupServiceImpl extends ServiceImpl<WeCommunityNewGr
* @return 员工活码
*/
private WeEmpleCode getWeEmpleCode(WeCommunityNewGroupDto communityNewGroupDto) {
Snowflake snowflake = IdUtil.getSnowflake(RandomUtil.randomLong(6), RandomUtil.randomInt(6));
WeEmpleCode weEmpleCode = new WeEmpleCode();
weEmpleCode.setId(SnowFlakeUtil.nextId());
......@@ -227,7 +237,7 @@ public class WeCommunityNewGroupServiceImpl extends ServiceImpl<WeCommunityNewGr
// 欢迎语
weEmpleCode.setWelcomeMsg(communityNewGroupDto.getWelcomeMsg());
// state,用于区分客户具体是通过哪个「联系我」添加,最大30个字符。使用id作为值即可。
weEmpleCode.setState(weEmpleCode.getId().toString());
weEmpleCode.setState(WeConstans.WE_QR_XKLQ_PREFIX + snowflake.nextIdStr());
// 活动场景,使用键入的活码名称
weEmpleCode.setScenario(communityNewGroupDto.getCodeName());
......
......@@ -283,7 +283,7 @@ public class WeGroupMessageTemplateServiceImpl extends ServiceImpl<WeGroupMessag
throw new WeComException("暂无客户群可发送");
}
}
}else {
}else if(!query.getIsAll() && CollectionUtil.isEmpty(senderList)){
throw new WeComException("无指定接收消息的成员及对应客户列表");
}
}
......
......@@ -5,22 +5,23 @@ import cn.hutool.core.io.FileUtil;
import cn.hutool.core.util.ObjectUtil;
import com.alibaba.fastjson.JSONObject;
import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper;
import com.linkwechat.common.constant.WeConstans;
import com.linkwechat.common.enums.MessageType;
import com.linkwechat.wecom.client.WeCustomerClient;
import com.linkwechat.wecom.domain.WeCustomer;
import com.linkwechat.wecom.domain.WeQrAttachments;
import com.linkwechat.wecom.domain.WeQrCode;
import com.linkwechat.wecom.domain.WeTag;
import com.linkwechat.wecom.domain.dto.WeEmpleCodeDto;
import com.linkwechat.wecom.domain.dto.WeMediaDto;
import com.linkwechat.wecom.domain.dto.WeResultDto;
import com.linkwechat.wecom.domain.dto.WeWelcomeMsg;
import com.linkwechat.wecom.domain.query.WeCustomerWelcomeQuery;
import com.linkwechat.wecom.domain.vo.WeCommunityWeComeMsgVo;
import com.linkwechat.wecom.domain.vo.WeMakeCustomerTag;
import com.linkwechat.wecom.domain.vo.qr.WeQrCodeDetailVo;
import com.linkwechat.wecom.domain.vo.tag.WeTagVo;
import com.linkwechat.wecom.service.IWeCustomerService;
import com.linkwechat.wecom.service.IWeMaterialService;
import com.linkwechat.wecom.service.IWeQrCodeService;
import com.linkwechat.wecom.service.*;
import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.context.ApplicationListener;
......@@ -45,6 +46,9 @@ public class WelcomeService implements ApplicationListener<WeCustomerWelcomeQuer
private IWeQrCodeService weQrCodeService;
@Autowired
private IWeCommunityNewGroupService weCommunityNewGroupService;
@Autowired
private IWeCustomerService weCustomerService;
@Autowired
......@@ -57,17 +61,29 @@ public class WelcomeService implements ApplicationListener<WeCustomerWelcomeQuer
@Async
public void onApplicationEvent(WeCustomerWelcomeQuery query) {
log.info("开始发送欢迎语:query:{}", JSONObject.toJSONString(query));
WeQrCode weQrCode = weQrCodeService.getOne(new LambdaQueryWrapper<WeQrCode>()
.eq(WeQrCode::getState, query.getState())
.eq(WeQrCode::getDelFlag, 0).last("limit 1"));
List<WeQrAttachments> qrAttachments = new ArrayList<>();
if (weQrCode != null) {
WeQrCodeDetailVo qrDetail = weQrCodeService.getQrDetail(weQrCode.getId());
qrAttachments.addAll(qrDetail.getQrAttachments());
makeCustomerTag(query.getExternalUserId(), query.getUserId(), qrDetail.getQrTags());
} else {
log.info("未查询到对应活码信息");
if(query.getState().startsWith(WeConstans.WE_QR_CODE_PREFIX)){
WeQrCode weQrCode = weQrCodeService.getOne(new LambdaQueryWrapper<WeQrCode>()
.eq(WeQrCode::getState, query.getState())
.eq(WeQrCode::getDelFlag, 0).last("limit 1"));
if (weQrCode != null) {
WeQrCodeDetailVo qrDetail = weQrCodeService.getQrDetail(weQrCode.getId());
qrAttachments.addAll(qrDetail.getQrAttachments());
makeCustomerTag(query.getExternalUserId(), query.getUserId(), qrDetail.getQrTags());
} else {
log.warn("未查询到对应员工活码信息");
}
}else if(query.getState().startsWith(WeConstans.WE_QR_XKLQ_PREFIX)){
WeCommunityWeComeMsgVo welcomeMsgByState = weCommunityNewGroupService.getWelcomeMsgByState(query.getState());
if(welcomeMsgByState != null){
WeQrAttachments textAtt = WeQrAttachments.builder().msgType(MessageType.TEXT.getMessageType())
.content(welcomeMsgByState.getWelcomeMsg()).build();
WeQrAttachments imageAtt = WeQrAttachments.builder().msgType(MessageType.IMAGE.getMessageType())
.mediaId(welcomeMsgByState.getCodeUrl()).build();
qrAttachments.add(textAtt);
qrAttachments.add(imageAtt);
makeCustomerTag(query.getExternalUserId(), query.getUserId(), welcomeMsgByState.getTagList());
}
}
WeResultDto resultDto = sendWelcomeMsg(query, qrAttachments);
log.info("结束发送欢迎语:result:{}", JSONObject.toJSONString(resultDto));
......
......@@ -80,4 +80,24 @@
UPDATE we_community_new_group SET del_flag = 1 WHERE empl_code_id = #{emplCodeId}
</update>
<select id="getWelcomeMsgByState" parameterType="String" resultMap="WelcomeMsgResult">
select wec.id,wgc.code_url, wec.welcome_msg,wect.tag_id,wect.tag_name
from we_emple_code wec
left join we_emple_code_tag wect on wec.id = wect.emple_code_id and wect.del_flag = 0
left join we_community_new_group wcng on wec.id = wcng.empl_code_id
left join we_group_code wgc on wcng.group_code_id = wgc.id
where 1=1
and wec.state = #{state}
and wec.del_flag = 0
</select>
<resultMap type="WeCommunityWeComeMsgVo" id="WelcomeMsgResult">
<result property="id" column="id"/>
<result property="welcomeMsg" column="qr_code"/>
<result property="welcomeMsg" column="welcome_msg"/>
<collection property="tagList" ofType="com.linkwechat.wecom.domain.vo.tag.WeTagVo">
<result property="tagId" column="tag_id"/>
<result property="tagName" column="tag_name"/>
</collection>
</resultMap>
</mapper>
\ No newline at end of file
Markdown is supported
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!