Commit 0bf58b21 by 徐高华

log

parent d5cf96a6
package com.gic.haoban.manage.service.service.impl; package com.gic.haoban.manage.service.service.impl;
import java.util.ArrayList; import java.util.ArrayList;
import java.util.List; import java.util.List;
import java.util.Objects; import java.util.Objects;
import org.apache.commons.collections.CollectionUtils; import org.apache.commons.collections.CollectionUtils;
import org.apache.commons.lang3.StringUtils; import org.apache.commons.lang3.StringUtils;
import org.apache.logging.log4j.LogManager; import org.apache.logging.log4j.LogManager;
import org.apache.logging.log4j.Logger; import org.apache.logging.log4j.Logger;
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 com.alibaba.fastjson.JSON; import com.alibaba.fastjson.JSON;
import com.alibaba.fastjson.JSONObject; import com.alibaba.fastjson.JSONObject;
import com.gic.api.base.commons.JSONResponse; import com.gic.api.base.commons.JSONResponse;
import com.gic.clerk.api.dto.ClerkDTO; import com.gic.clerk.api.dto.ClerkDTO;
import com.gic.clerk.api.service.ClerkService; import com.gic.clerk.api.service.ClerkService;
import com.gic.commons.util.GICMQClientUtil; import com.gic.commons.util.GICMQClientUtil;
import com.gic.dubbo.entity.ProviderLocalTag; import com.gic.dubbo.entity.ProviderLocalTag;
import com.gic.enterprise.api.dto.QRcodeDTO; import com.gic.enterprise.api.dto.QRcodeDTO;
import com.gic.enterprise.api.service.ImageService; import com.gic.enterprise.api.service.ImageService;
import com.gic.haoban.manage.api.constants.Manage3Constants; import com.gic.haoban.manage.api.constants.Manage3Constants;
import com.gic.haoban.manage.api.dto.QwFrientNoticeDTO; import com.gic.haoban.manage.api.dto.QwFrientNoticeDTO;
import com.gic.haoban.manage.api.dto.QywxErrorLogDTO; import com.gic.haoban.manage.api.dto.QywxErrorLogDTO;
import com.gic.haoban.manage.api.dto.StaffClerkRelationDTO; import com.gic.haoban.manage.api.dto.StaffClerkRelationDTO;
import com.gic.haoban.manage.api.dto.WxEnterpriseQwDTO; import com.gic.haoban.manage.api.dto.WxEnterpriseQwDTO;
import com.gic.haoban.manage.api.dto.hm.HmClerkRelationDTO; import com.gic.haoban.manage.api.dto.hm.HmClerkRelationDTO;
import com.gic.haoban.manage.api.dto.hm.HmQrcodeDTO; import com.gic.haoban.manage.api.dto.hm.HmQrcodeDTO;
import com.gic.haoban.manage.api.enums.WelcomeMediaTypeEnum; import com.gic.haoban.manage.api.enums.WelcomeMediaTypeEnum;
import com.gic.haoban.manage.api.enums.hm.HmWelcomeReferType; import com.gic.haoban.manage.api.enums.hm.HmWelcomeReferType;
import com.gic.haoban.manage.api.service.hm.HmClerkRelationApiService; import com.gic.haoban.manage.api.service.hm.HmClerkRelationApiService;
import com.gic.haoban.manage.api.service.hm.HmQrcodeApiService; import com.gic.haoban.manage.api.service.hm.HmQrcodeApiService;
import com.gic.haoban.manage.service.config.Config; import com.gic.haoban.manage.service.config.Config;
import com.gic.haoban.manage.service.dao.mapper.StaffMapper; import com.gic.haoban.manage.service.dao.mapper.StaffMapper;
import com.gic.haoban.manage.service.entity.TabHaobanClerkMainStoreRelated; import com.gic.haoban.manage.service.entity.TabHaobanClerkMainStoreRelated;
import com.gic.haoban.manage.service.entity.TabHaobanStaff; import com.gic.haoban.manage.service.entity.TabHaobanStaff;
import com.gic.haoban.manage.service.entity.TabHaobanWxEnterprise; import com.gic.haoban.manage.service.entity.TabHaobanWxEnterprise;
import com.gic.haoban.manage.service.entity.TabMiniprogramSetting; import com.gic.haoban.manage.service.entity.TabMiniprogramSetting;
import com.gic.haoban.manage.service.pojo.bo.hm.KeyDataLinkBO; import com.gic.haoban.manage.service.pojo.bo.hm.KeyDataLinkBO;
import com.gic.haoban.manage.service.pojo.bo.welcome.WelcomeDetailBO; import com.gic.haoban.manage.service.pojo.bo.welcome.WelcomeDetailBO;
import com.gic.haoban.manage.service.pojo.bo.welcome.WelcomeMediaBO; import com.gic.haoban.manage.service.pojo.bo.welcome.WelcomeMediaBO;
import com.gic.haoban.manage.service.pojo.bo.welcome.WelcomeReferBO; import com.gic.haoban.manage.service.pojo.bo.welcome.WelcomeReferBO;
import com.gic.haoban.manage.service.service.ClerkMainStoreRelatedService; import com.gic.haoban.manage.service.service.ClerkMainStoreRelatedService;
import com.gic.haoban.manage.service.service.KeyDataService; import com.gic.haoban.manage.service.service.KeyDataService;
import com.gic.haoban.manage.service.service.MiniprogramSettingService; import com.gic.haoban.manage.service.service.MiniprogramSettingService;
import com.gic.haoban.manage.service.service.StaffClerkRelationService; import com.gic.haoban.manage.service.service.StaffClerkRelationService;
import com.gic.haoban.manage.service.service.WelcomeSendService; import com.gic.haoban.manage.service.service.WelcomeSendService;
import com.gic.haoban.manage.service.service.WelcomeService; import com.gic.haoban.manage.service.service.WelcomeService;
import com.gic.haoban.manage.service.service.WxEnterpriseService; import com.gic.haoban.manage.service.service.WxEnterpriseService;
import com.gic.haoban.manage.service.util.CommonUtil; import com.gic.haoban.manage.service.util.CommonUtil;
import com.gic.haoban.manage.service.util.EmojiFilterUtil; import com.gic.haoban.manage.service.util.EmojiFilterUtil;
import com.gic.mq.sdk.GicMQClient; import com.gic.mq.sdk.GicMQClient;
import com.gic.wechat.api.dto.qywx.welcome.QywxExternalMessageBaseDTO; import com.gic.wechat.api.dto.qywx.welcome.QywxExternalMessageBaseDTO;
import com.gic.wechat.api.dto.qywx.welcome.QywxFileExternalBaseDTO; import com.gic.wechat.api.dto.qywx.welcome.QywxFileExternalBaseDTO;
import com.gic.wechat.api.dto.qywx.welcome.QywxImageExternalBaseDTO; import com.gic.wechat.api.dto.qywx.welcome.QywxImageExternalBaseDTO;
import com.gic.wechat.api.dto.qywx.welcome.QywxLinkExternalBaseDTO; import com.gic.wechat.api.dto.qywx.welcome.QywxLinkExternalBaseDTO;
import com.gic.wechat.api.dto.qywx.welcome.QywxMiniprogramExternalBaseDTO; import com.gic.wechat.api.dto.qywx.welcome.QywxMiniprogramExternalBaseDTO;
import com.gic.wechat.api.dto.qywx.welcome.QywxVideoExternalBaseDTO; import com.gic.wechat.api.dto.qywx.welcome.QywxVideoExternalBaseDTO;
import com.gic.wechat.api.dto.qywx.welcome.QywxWelcomeMsgDTO; import com.gic.wechat.api.dto.qywx.welcome.QywxWelcomeMsgDTO;
import com.gic.wechat.api.enums.QywxMediaTypeEnum; import com.gic.wechat.api.enums.QywxMediaTypeEnum;
import com.gic.wechat.api.service.qywx.QywxSuiteApiService; import com.gic.wechat.api.service.qywx.QywxSuiteApiService;
import com.gic.wechat.api.service.qywx.QywxUserApiService; import com.gic.wechat.api.service.qywx.QywxUserApiService;
import cn.hutool.core.convert.Convert; import cn.hutool.core.convert.Convert;
import cn.hutool.crypto.SecureUtil; import cn.hutool.crypto.SecureUtil;
@Service @Service
public class WelcomeSendServiceImpl implements WelcomeSendService { public class WelcomeSendServiceImpl implements WelcomeSendService {
private static final Logger log = LogManager.getLogger(WelcomeSendServiceImpl.class); private static final Logger log = LogManager.getLogger(WelcomeSendServiceImpl.class);
@Autowired @Autowired
private QywxUserApiService qywxUserApiService; private QywxUserApiService qywxUserApiService;
@Autowired @Autowired
private WxEnterpriseService wxEnterpriseService; private WxEnterpriseService wxEnterpriseService;
@Autowired @Autowired
private ClerkService clerkService; private ClerkService clerkService;
@Autowired @Autowired
private ClerkMainStoreRelatedService clerkMainStoreRelatedService; private ClerkMainStoreRelatedService clerkMainStoreRelatedService;
@Autowired @Autowired
private Config config; private Config config;
@Autowired @Autowired
private QywxSuiteApiService qywxSuiteApiService; private QywxSuiteApiService qywxSuiteApiService;
@Autowired @Autowired
private StaffClerkRelationService staffClerkRelationService; private StaffClerkRelationService staffClerkRelationService;
@Autowired @Autowired
private MiniprogramSettingService miniprogramSettingService; private MiniprogramSettingService miniprogramSettingService;
@Autowired @Autowired
private WelcomeService welcomeService; private WelcomeService welcomeService;
@Autowired @Autowired
private ImageService imageService; private ImageService imageService;
@Autowired @Autowired
private HmQrcodeApiService hmQrcodeApiService; private HmQrcodeApiService hmQrcodeApiService;
@Autowired @Autowired
private KeyDataService keyDataService; private KeyDataService keyDataService;
@Autowired @Autowired
private HmClerkRelationApiService hmClerkRelationApiService; private HmClerkRelationApiService hmClerkRelationApiService;
@Autowired @Autowired
private StaffMapper staffMapper; private StaffMapper staffMapper;
private static GicMQClient clientInstance = GICMQClientUtil.getClientInstance(); private static GicMQClient clientInstance = GICMQClientUtil.getClientInstance();
@Override @Override
public void sendWelcome(String params) { public void sendWelcome(String params) {
log.info("发送欢迎语={}", params); log.info("新发送欢迎语={}", params);
QwFrientNoticeDTO dto = JSON.parseObject(params, QwFrientNoticeDTO.class); QwFrientNoticeDTO dto = JSON.parseObject(params, QwFrientNoticeDTO.class);
this.sendWelcome(dto.getCorpid(), dto.getExternalUserid(), dto.getWelcomeCode(), dto.getWxUserId(), this.sendWelcome(dto.getCorpid(), dto.getExternalUserid(), dto.getWelcomeCode(), dto.getWxUserId(),
dto.getState()); dto.getState());
} }
/** /**
* 发送欢迎语 * 发送欢迎语
* *
* @param dto * @param dto
* @param wxEnterpriseDTO * @param wxEnterpriseDTO
* @param enterpriseId * @param enterpriseId
* @param staffId * @param staffId
* {"data":{"welcomeCode":"J0GjdrsF-nZNac3Xc6V2K2p8OokQZcY4g0jxljdHc7A","wxUserId":"016903","suiteid":"selfSuiteId","corpid":"wxbde984c3488b837e","externalUserid":"wmSe9FEAAAy39F1NI6Z-THUUd9mkqOIw","changeType":"add_external_contact"},"type":1,"mqTraceId":"278473818-1-1679557069.126"} * {"data":{"welcomeCode":"J0GjdrsF-nZNac3Xc6V2K2p8OokQZcY4g0jxljdHc7A","wxUserId":"016903","suiteid":"selfSuiteId","corpid":"wxbde984c3488b837e","externalUserid":"wmSe9FEAAAy39F1NI6Z-THUUd9mkqOIw","changeType":"add_external_contact"},"type":1,"mqTraceId":"278473818-1-1679557069.126"}
*/ */
@Override @Override
public void sendWelcome(String corpid, String externalUserId, String welcomeCode, String wxUserId, String state) { public void sendWelcome(String corpid, String externalUserId, String welcomeCode, String wxUserId, String state) {
if (StringUtils.isEmpty(welcomeCode)) { if (StringUtils.isEmpty(welcomeCode)) {
log.error("welcomeCode为空,externalUserId={}", externalUserId); log.error("welcomeCode为空,externalUserId={}", externalUserId);
return; return;
} }
TabHaobanWxEnterprise wxEnterprise = this.wxEnterpriseService.getEnterpriseBycorpId(corpid); TabHaobanWxEnterprise wxEnterprise = this.wxEnterpriseService.getEnterpriseBycorpId(corpid);
if (wxEnterprise == null) { if (wxEnterprise == null) {
log.info("企业不存在,corpid={}", corpid); log.info("企业不存在,corpid={}", corpid);
return; return;
} }
String wxEnterpriseId = wxEnterprise.getWxEnterpriseId(); String wxEnterpriseId = wxEnterprise.getWxEnterpriseId();
WxEnterpriseQwDTO qwDTO = this.wxEnterpriseService.getQwInfo(wxEnterpriseId); WxEnterpriseQwDTO qwDTO = this.wxEnterpriseService.getQwInfo(wxEnterpriseId);
if (qwDTO == null) { if (qwDTO == null) {
log.info("企业不存在,wxEnterpriseId={}", wxEnterpriseId); log.info("企业不存在,wxEnterpriseId={}", wxEnterpriseId);
return; return;
} }
TabHaobanStaff staff = this.staffMapper.selectByUserIdAndEnterpriseId(wxUserId, wxEnterpriseId); TabHaobanStaff staff = this.staffMapper.selectByUserIdAndEnterpriseId(wxUserId, wxEnterpriseId);
if (null == staff) { if (null == staff) {
log.info("成员不存在,wxUserid={}", wxUserId); log.info("成员不存在,wxUserid={}", wxUserId);
return; return;
} }
String staffId = staff.getStaffId(); String staffId = staff.getStaffId();
log.info("发送欢迎语,state={}", state); log.info("发送欢迎语,state={}", state);
String relationKey = SecureUtil.md5(staffId + externalUserId); String relationKey = SecureUtil.md5(staffId + externalUserId);
WelcomeDetailBO welcomeBO = null; WelcomeDetailBO welcomeBO = null;
if (StringUtils.isNotBlank(state) if (StringUtils.isNotBlank(state)
&& (state.startsWith(Manage3Constants.HM) || state.startsWith(Manage3Constants.DT))) { && (state.startsWith(Manage3Constants.HM) || state.startsWith(Manage3Constants.DT))) {
WelcomeReferBO welcomeReferBo = getWelcomeReferBo(state); WelcomeReferBO welcomeReferBo = getWelcomeReferBo(state);
welcomeBO = welcomeService.getMatchWelcomeWithReferId(staffId, wxEnterpriseId, welcomeReferBo); welcomeBO = welcomeService.getMatchWelcomeWithReferId(staffId, wxEnterpriseId, welcomeReferBo);
} else { } else {
welcomeBO = welcomeService.getMatchWelcome(staffId, wxEnterpriseId); welcomeBO = welcomeService.getMatchWelcome(staffId, wxEnterpriseId);
} }
if (Objects.isNull(welcomeBO)) { if (Objects.isNull(welcomeBO)) {
log.info("欢迎语未配置wxEnterpriseId:{}", wxEnterpriseId); log.info("活码欢迎语未配置wxEnterpriseId:{}", wxEnterpriseId);
return; return;
} }
// 内容 // 内容
log.info("欢迎语发送{}={}", welcomeBO.getWelcomeId(), JSON.toJSONString(welcomeBO)); log.info("欢迎语发送{}={}", welcomeBO.getWelcomeId(), JSON.toJSONString(welcomeBO));
String content = welcomeBO.getWelcomeContent(); String content = welcomeBO.getWelcomeContent();
if (content.contains("<微信昵称>")) { if (content.contains("<微信昵称>")) {
String nickName = this.getExternalUserName(qwDTO, externalUserId); String nickName = this.getExternalUserName(qwDTO, externalUserId);
content = content.replaceAll("<微信昵称>", nickName); content = content.replaceAll("<微信昵称>", nickName);
} }
QywxWelcomeMsgDTO qywxWelcomeMsgDTO = new QywxWelcomeMsgDTO(); QywxWelcomeMsgDTO qywxWelcomeMsgDTO = new QywxWelcomeMsgDTO();
// 欢迎语内容 // 欢迎语内容
qywxWelcomeMsgDTO.setText(content); qywxWelcomeMsgDTO.setText(content);
// 欢迎语类型 // 欢迎语类型
List<QywxExternalMessageBaseDTO> attachments = new ArrayList<>(); List<QywxExternalMessageBaseDTO> attachments = new ArrayList<>();
// 开始设置欢迎语附件 // 开始设置欢迎语附件
List<WelcomeMediaBO> mediaList = welcomeBO.getWelcomeMediaList(); List<WelcomeMediaBO> mediaList = welcomeBO.getWelcomeMediaList();
mediaList.forEach(one -> { mediaList.forEach(one -> {
Integer mediaType = one.getMediaType(); Integer mediaType = one.getMediaType();
if (WelcomeMediaTypeEnum.IMAGE.getCode().equals(mediaType)) { if (WelcomeMediaTypeEnum.IMAGE.getCode().equals(mediaType)) {
attachmentAddImage(attachments, one, corpid); attachmentAddImage(attachments, one, corpid);
} }
if (WelcomeMediaTypeEnum.VIDEO.getCode().equals(mediaType)) { if (WelcomeMediaTypeEnum.VIDEO.getCode().equals(mediaType)) {
attachmentAddVideo(attachments, one, corpid); attachmentAddVideo(attachments, one, corpid);
} }
if (WelcomeMediaTypeEnum.FILE.getCode().equals(mediaType)) { if (WelcomeMediaTypeEnum.FILE.getCode().equals(mediaType)) {
attachmentAddFile(attachments, one, corpid); attachmentAddFile(attachments, one, corpid);
} }
if (WelcomeMediaTypeEnum.LINK.getCode().equals(mediaType)) { if (WelcomeMediaTypeEnum.LINK.getCode().equals(mediaType)) {
attachmentAddLink(attachments, one); attachmentAddLink(attachments, one);
} }
if (WelcomeMediaTypeEnum.PROGRAM.getCode().equals(mediaType)) { if (WelcomeMediaTypeEnum.PROGRAM.getCode().equals(mediaType)) {
attachmentAddProgram(attachments, one, wxEnterpriseId); attachmentAddProgram(attachments, one, wxEnterpriseId);
} }
if (WelcomeMediaTypeEnum.PARAM_PROGRAM.getCode().equals(mediaType) if (WelcomeMediaTypeEnum.PARAM_PROGRAM.getCode().equals(mediaType)
|| WelcomeMediaTypeEnum.PARAM_QRCODE.getCode().equals(mediaType)) { || WelcomeMediaTypeEnum.PARAM_QRCODE.getCode().equals(mediaType)) {
String clerkId = this.getClerkId(wxEnterpriseId, staffId, state); String clerkId = this.getClerkId(wxEnterpriseId, staffId, state);
String enterpriseId = null; String enterpriseId = null;
if (null != clerkId) { if (null != clerkId) {
ClerkDTO clerk = this.clerkService.getclerkById(clerkId); ClerkDTO clerk = this.clerkService.getclerkById(clerkId);
if (null != clerk) { if (null != clerk) {
enterpriseId = clerk.getEnterpriseId(); enterpriseId = clerk.getEnterpriseId();
} }
} }
if (WelcomeMediaTypeEnum.PARAM_QRCODE.getCode().equals(mediaType)) { if (WelcomeMediaTypeEnum.PARAM_QRCODE.getCode().equals(mediaType)) {
attachmentAddParamQrCode(attachments, enterpriseId, clerkId, corpid, relationKey); attachmentAddParamQrCode(attachments, enterpriseId, clerkId, corpid, relationKey);
} }
if (WelcomeMediaTypeEnum.PARAM_PROGRAM.getCode().equals(mediaType)) { if (WelcomeMediaTypeEnum.PARAM_PROGRAM.getCode().equals(mediaType)) {
attachmentAddParamProgram(attachments, enterpriseId, wxEnterpriseId, relationKey); attachmentAddParamProgram(attachments, enterpriseId, wxEnterpriseId, relationKey);
} }
} }
}); });
if (CollectionUtils.isNotEmpty(attachments)) { if (CollectionUtils.isNotEmpty(attachments)) {
qywxWelcomeMsgDTO.setAttachments(attachments); qywxWelcomeMsgDTO.setAttachments(attachments);
} }
qywxWelcomeMsgDTO.setWelcomeCode(welcomeCode); qywxWelcomeMsgDTO.setWelcomeCode(welcomeCode);
String result = this.qywxUserApiService.sendWelcomeMsgByExternal(corpid, config.getWxSuiteid(), String result = this.qywxUserApiService.sendWelcomeMsgByExternal(corpid, config.getWxSuiteid(),
qywxWelcomeMsgDTO); qywxWelcomeMsgDTO);
log.info("发送欢迎语 params:{},返回={}", JSON.toJSONString(qywxWelcomeMsgDTO), result); log.info("发送欢迎语 params:{},返回={}", JSON.toJSONString(qywxWelcomeMsgDTO), result);
if (StringUtils.isNotBlank(result)) { if (StringUtils.isNotBlank(result)) {
JSONObject json = JSON.parseObject(result); JSONObject json = JSON.parseObject(result);
int errcode = json.getIntValue("errcode"); int errcode = json.getIntValue("errcode");
if (0 != errcode) { if (0 != errcode) {
try { try {
QywxErrorLogDTO errLog = new QywxErrorLogDTO(); QywxErrorLogDTO errLog = new QywxErrorLogDTO();
errLog.setWxEnterpriseId(wxEnterpriseId); errLog.setWxEnterpriseId(wxEnterpriseId);
errLog.setExternalUserId(externalUserId); errLog.setExternalUserId(externalUserId);
errLog.setTraceId(ProviderLocalTag.tag.get().traceId); errLog.setTraceId(ProviderLocalTag.tag.get().traceId);
errLog.setQywxErrorType(1); errLog.setQywxErrorType(1);
errLog.setScenario("欢迎语"); errLog.setScenario("欢迎语");
errLog.setErrorContent(result); errLog.setErrorContent(result);
clientInstance.sendMessage(Manage3Constants.QYWX_ERROR_MSG, JSON.toJSONString(errLog)); clientInstance.sendMessage(Manage3Constants.QYWX_ERROR_MSG, JSON.toJSONString(errLog));
} catch (Exception e) { } catch (Exception e) {
log.error("发送消息失败:{}", e.getMessage(), e); log.error("发送消息失败:{}", e.getMessage(), e);
} }
} }
} }
} }
/** /**
* 获取链接或者活码id * 获取链接或者活码id
*/ */
private WelcomeReferBO getWelcomeReferBo(String state) { private WelcomeReferBO getWelcomeReferBo(String state) {
WelcomeReferBO welcomeReferBo = new WelcomeReferBO(); WelcomeReferBO welcomeReferBo = new WelcomeReferBO();
String id = state.substring(2); String id = state.substring(2);
if (state.contains(Manage3Constants.HM)) { if (state.contains(Manage3Constants.HM)) {
welcomeReferBo.setType(HmWelcomeReferType.HM.getCode()); welcomeReferBo.setType(HmWelcomeReferType.HM.getCode());
welcomeReferBo.setReferId(id); welcomeReferBo.setReferId(id);
} else if (state.contains(Manage3Constants.DT)) { } else if (state.contains(Manage3Constants.DT)) {
KeyDataLinkBO dataForHmLink = keyDataService.getDataForHmLink(id); KeyDataLinkBO dataForHmLink = keyDataService.getDataForHmLink(id);
if (dataForHmLink != null) { if (dataForHmLink != null) {
welcomeReferBo.setType(HmWelcomeReferType.LINK.getCode()); welcomeReferBo.setType(HmWelcomeReferType.LINK.getCode());
welcomeReferBo.setReferId(Convert.toStr(dataForHmLink.getLinkId())); welcomeReferBo.setReferId(Convert.toStr(dataForHmLink.getLinkId()));
} }
} }
return welcomeReferBo; return welcomeReferBo;
} }
private void attachmentAddImage(List<QywxExternalMessageBaseDTO> attachments, WelcomeMediaBO media, String corpid) { private void attachmentAddImage(List<QywxExternalMessageBaseDTO> attachments, WelcomeMediaBO media, String corpid) {
String mediaUrl = media.getMediaUrl(); String mediaUrl = media.getMediaUrl();
String[] arr = mediaUrl.split("/"); String[] arr = mediaUrl.split("/");
JSONResponse jp = qywxSuiteApiService.uploadMedia(corpid, config.getWxSuiteid(), JSONResponse jp = qywxSuiteApiService.uploadMedia(corpid, config.getWxSuiteid(),
CommonUtil.getFileByte(mediaUrl), arr[arr.length - 1], QywxMediaTypeEnum.IMAGE.getCode()); CommonUtil.getFileByte(mediaUrl), arr[arr.length - 1], QywxMediaTypeEnum.IMAGE.getCode());
log.info("欢迎语发送图片返回:{}", JSON.toJSONString(jp)); log.info("欢迎语发送图片返回:{}", JSON.toJSONString(jp));
if (jp.getErrorCode() == 0) { if (jp.getErrorCode() == 0) {
QywxImageExternalBaseDTO qywxImageExternalBaseDTO = new QywxImageExternalBaseDTO(); QywxImageExternalBaseDTO qywxImageExternalBaseDTO = new QywxImageExternalBaseDTO();
qywxImageExternalBaseDTO.setMediaId(jp.getResult().toString()); qywxImageExternalBaseDTO.setMediaId(jp.getResult().toString());
attachments.add(qywxImageExternalBaseDTO); attachments.add(qywxImageExternalBaseDTO);
} }
} }
private void attachmentAddVideo(List<QywxExternalMessageBaseDTO> attachments, WelcomeMediaBO media, String corpid) { private void attachmentAddVideo(List<QywxExternalMessageBaseDTO> attachments, WelcomeMediaBO media, String corpid) {
String mediaUrl = media.getMediaUrl(); String mediaUrl = media.getMediaUrl();
String[] arr = mediaUrl.split("/"); String[] arr = mediaUrl.split("/");
JSONResponse jp = qywxSuiteApiService.uploadMedia(corpid, config.getWxSuiteid(), JSONResponse jp = qywxSuiteApiService.uploadMedia(corpid, config.getWxSuiteid(),
CommonUtil.getFileByte(mediaUrl), arr[arr.length - 1], QywxMediaTypeEnum.VIDEO.getCode()); CommonUtil.getFileByte(mediaUrl), arr[arr.length - 1], QywxMediaTypeEnum.VIDEO.getCode());
log.info("欢迎语发送视频返回:{}", JSON.toJSONString(jp)); log.info("欢迎语发送视频返回:{}", JSON.toJSONString(jp));
if (jp.getErrorCode() == 0) { if (jp.getErrorCode() == 0) {
QywxVideoExternalBaseDTO qywxVideoExternalBaseDTO = new QywxVideoExternalBaseDTO(); QywxVideoExternalBaseDTO qywxVideoExternalBaseDTO = new QywxVideoExternalBaseDTO();
qywxVideoExternalBaseDTO.setMediaId(jp.getResult().toString()); qywxVideoExternalBaseDTO.setMediaId(jp.getResult().toString());
attachments.add(qywxVideoExternalBaseDTO); attachments.add(qywxVideoExternalBaseDTO);
} }
} }
private void attachmentAddFile(List<QywxExternalMessageBaseDTO> attachments, WelcomeMediaBO media, String corpid) { private void attachmentAddFile(List<QywxExternalMessageBaseDTO> attachments, WelcomeMediaBO media, String corpid) {
String mediaUrl = media.getMediaUrl(); String mediaUrl = media.getMediaUrl();
String[] arr = mediaUrl.split("/"); String[] arr = mediaUrl.split("/");
JSONResponse jp = qywxSuiteApiService.uploadMedia(corpid, config.getWxSuiteid(), JSONResponse jp = qywxSuiteApiService.uploadMedia(corpid, config.getWxSuiteid(),
CommonUtil.getFileByte(mediaUrl), arr[arr.length - 1], QywxMediaTypeEnum.FILE.getCode()); CommonUtil.getFileByte(mediaUrl), arr[arr.length - 1], QywxMediaTypeEnum.FILE.getCode());
log.info("欢迎语发送文件返回:{}", JSON.toJSONString(jp)); log.info("欢迎语发送文件返回:{}", JSON.toJSONString(jp));
if (jp.getErrorCode() == 0) { if (jp.getErrorCode() == 0) {
QywxFileExternalBaseDTO qywxFileExternalBaseDTO = new QywxFileExternalBaseDTO(); QywxFileExternalBaseDTO qywxFileExternalBaseDTO = new QywxFileExternalBaseDTO();
qywxFileExternalBaseDTO.setMediaId(jp.getResult().toString()); qywxFileExternalBaseDTO.setMediaId(jp.getResult().toString());
attachments.add(qywxFileExternalBaseDTO); attachments.add(qywxFileExternalBaseDTO);
} }
} }
private void attachmentAddLink(List<QywxExternalMessageBaseDTO> attachments, WelcomeMediaBO media) { private void attachmentAddLink(List<QywxExternalMessageBaseDTO> attachments, WelcomeMediaBO media) {
String mediaTitle = media.getMediaTitle(); String mediaTitle = media.getMediaTitle();
String mediaUrl = media.getMediaUrl(); String mediaUrl = media.getMediaUrl();
QywxLinkExternalBaseDTO qywxLinkExternalBaseDTO = new QywxLinkExternalBaseDTO(); QywxLinkExternalBaseDTO qywxLinkExternalBaseDTO = new QywxLinkExternalBaseDTO();
qywxLinkExternalBaseDTO.setTitle(mediaTitle); qywxLinkExternalBaseDTO.setTitle(mediaTitle);
qywxLinkExternalBaseDTO.setUrl(mediaUrl); qywxLinkExternalBaseDTO.setUrl(mediaUrl);
attachments.add(qywxLinkExternalBaseDTO); attachments.add(qywxLinkExternalBaseDTO);
} }
private void attachmentAddProgram(List<QywxExternalMessageBaseDTO> attachments, WelcomeMediaBO media, private void attachmentAddProgram(List<QywxExternalMessageBaseDTO> attachments, WelcomeMediaBO media,
String wxEnterpriseId) { String wxEnterpriseId) {
log.info("发送小程序:wxEnterpriseId:{}", wxEnterpriseId); log.info("发送小程序:wxEnterpriseId:{}", wxEnterpriseId);
String miniprogramSettingId = media.getMiniprogramSettingId(); String miniprogramSettingId = media.getMiniprogramSettingId();
TabMiniprogramSetting miniprogramSetting = miniprogramSettingService.getById(miniprogramSettingId); TabMiniprogramSetting miniprogramSetting = miniprogramSettingService.getById(miniprogramSettingId);
if (Objects.isNull(miniprogramSetting) || miniprogramSetting.getStatusFlag() == 0) { if (Objects.isNull(miniprogramSetting) || miniprogramSetting.getStatusFlag() == 0) {
log.info("小程序不存在或已被删除, miniprogramSettingId:{}", miniprogramSettingId); log.info("小程序不存在或已被删除, miniprogramSettingId:{}", miniprogramSettingId);
return; return;
} }
QywxMiniprogramExternalBaseDTO messageBaseDTO = new QywxMiniprogramExternalBaseDTO(); QywxMiniprogramExternalBaseDTO messageBaseDTO = new QywxMiniprogramExternalBaseDTO();
messageBaseDTO.setAppid(miniprogramSetting.getAppId()); messageBaseDTO.setAppid(miniprogramSetting.getAppId());
messageBaseDTO.setPicMediaId(miniprogramSetting.getMediaId()); messageBaseDTO.setPicMediaId(miniprogramSetting.getMediaId());
messageBaseDTO.setTitle(miniprogramSetting.getTitle()); messageBaseDTO.setTitle(miniprogramSetting.getTitle());
messageBaseDTO.setPage(media.getMiniProgramPage()); messageBaseDTO.setPage(media.getMiniProgramPage());
attachments.add(messageBaseDTO); attachments.add(messageBaseDTO);
} }
private void attachmentAddParamProgram(List<QywxExternalMessageBaseDTO> attachments, String enterpriseId, private void attachmentAddParamProgram(List<QywxExternalMessageBaseDTO> attachments, String enterpriseId,
String wxEnterpriseId, String relationKey) { String wxEnterpriseId, String relationKey) {
if (StringUtils.isEmpty(enterpriseId) || StringUtils.isEmpty(relationKey)) { if (StringUtils.isEmpty(enterpriseId) || StringUtils.isEmpty(relationKey)) {
log.info("带参二维码无法发送"); log.info("带参二维码无法发送");
return; return;
} }
log.info("发送带参小程序:wxEnterpriseId:{}", wxEnterpriseId); log.info("发送带参小程序:wxEnterpriseId:{}", wxEnterpriseId);
// 发送小程序 // 发送小程序
TabMiniprogramSetting miniprogramSetting = miniprogramSettingService.getMiniprogramSetting(wxEnterpriseId, TabMiniprogramSetting miniprogramSetting = miniprogramSettingService.getMiniprogramSetting(wxEnterpriseId,
enterpriseId); enterpriseId);
if (null == miniprogramSetting) { if (null == miniprogramSetting) {
log.info("需要配置小程序配置:wxEnterpriseId:{},enterpriseId:{}", wxEnterpriseId, enterpriseId); log.info("需要配置小程序配置:wxEnterpriseId:{},enterpriseId:{}", wxEnterpriseId, enterpriseId);
return; return;
} }
QywxMiniprogramExternalBaseDTO messageBaseDTO = new QywxMiniprogramExternalBaseDTO(); QywxMiniprogramExternalBaseDTO messageBaseDTO = new QywxMiniprogramExternalBaseDTO();
messageBaseDTO.setAppid(miniprogramSetting.getAppId()); messageBaseDTO.setAppid(miniprogramSetting.getAppId());
messageBaseDTO.setPicMediaId(miniprogramSetting.getMediaId()); messageBaseDTO.setPicMediaId(miniprogramSetting.getMediaId());
messageBaseDTO.setTitle(miniprogramSetting.getTitle()); messageBaseDTO.setTitle(miniprogramSetting.getTitle());
messageBaseDTO.setPage(config.getMemberOpenPage() + relationKey); messageBaseDTO.setPage(config.getMemberOpenPage() + relationKey);
attachments.add(messageBaseDTO); attachments.add(messageBaseDTO);
} }
private void attachmentAddParamQrCode(List<QywxExternalMessageBaseDTO> attachments, String enterpriseId, private void attachmentAddParamQrCode(List<QywxExternalMessageBaseDTO> attachments, String enterpriseId,
String clerkId, String corpid, String relationKey) { String clerkId, String corpid, String relationKey) {
if (StringUtils.isEmpty(enterpriseId) || StringUtils.isEmpty(clerkId)) { if (StringUtils.isEmpty(enterpriseId) || StringUtils.isEmpty(clerkId)) {
log.info("带参小程序无法发送"); log.info("带参小程序无法发送");
return; return;
} }
// 带参数的公众号二维码 // 带参数的公众号二维码
String sceneStr = "QWHY_" + relationKey + "_" + clerkId; String sceneStr = "QWHY_" + relationKey + "_" + clerkId;
// 30天失效 // 30天失效
QRcodeDTO qRcodePic = imageService.getQRcodePic(enterpriseId, sceneStr, 2592000); QRcodeDTO qRcodePic = imageService.getQRcodePic(enterpriseId, sceneStr, 2592000);
log.info("参数的公众号二维码返回:{}", JSON.toJSONString(qRcodePic)); log.info("参数的公众号二维码返回:{}", JSON.toJSONString(qRcodePic));
if (qRcodePic != null) { if (qRcodePic != null) {
String downloadUrl = qRcodePic.getPicUploadResDTO().downloadUrl; String downloadUrl = qRcodePic.getPicUploadResDTO().downloadUrl;
String[] arr = downloadUrl.split("/"); String[] arr = downloadUrl.split("/");
JSONResponse jp = qywxSuiteApiService.uploadMedia(corpid, config.getWxSuiteid(), JSONResponse jp = qywxSuiteApiService.uploadMedia(corpid, config.getWxSuiteid(),
CommonUtil.getFileByte(downloadUrl), arr[arr.length - 1], QywxMediaTypeEnum.IMAGE.getCode()); CommonUtil.getFileByte(downloadUrl), arr[arr.length - 1], QywxMediaTypeEnum.IMAGE.getCode());
log.info("欢迎语发送带参数的公众号企微二维码返回:{}", JSON.toJSONString(jp)); log.info("欢迎语发送带参数的公众号企微二维码返回:{}", JSON.toJSONString(jp));
if (jp.getErrorCode() == 0) { if (jp.getErrorCode() == 0) {
QywxImageExternalBaseDTO qywxImageExternalBaseDTO = new QywxImageExternalBaseDTO(); QywxImageExternalBaseDTO qywxImageExternalBaseDTO = new QywxImageExternalBaseDTO();
qywxImageExternalBaseDTO.setMediaId(jp.getResult().toString()); qywxImageExternalBaseDTO.setMediaId(jp.getResult().toString());
attachments.add(qywxImageExternalBaseDTO); attachments.add(qywxImageExternalBaseDTO);
} }
} }
} }
private String getExternalUserName(WxEnterpriseQwDTO qwDTO, String externalUserId) { private String getExternalUserName(WxEnterpriseQwDTO qwDTO, String externalUserId) {
log.info("查询好友详情,externalUserId={}", externalUserId); log.info("查询好友详情,externalUserId={}", externalUserId);
String userInfo = qywxUserApiService.getExternalUseridInfo(qwDTO.getThirdCorpid(), config.getWxSuiteid(), String userInfo = qywxUserApiService.getExternalUseridInfo(qwDTO.getThirdCorpid(), config.getWxSuiteid(),
externalUserId); externalUserId);
String name = ""; String name = "";
if (StringUtils.isBlank(userInfo)) { if (StringUtils.isBlank(userInfo)) {
log.info("好友不存在"); log.info("好友不存在");
return name; return name;
} }
if ("1".equals(userInfo)) { if ("1".equals(userInfo)) {
log.info("限制次数"); log.info("限制次数");
return name; return name;
} }
if (StringUtils.isNotBlank(userInfo)) { if (StringUtils.isNotBlank(userInfo)) {
JSONObject userJson = JSON.parseObject(userInfo); JSONObject userJson = JSON.parseObject(userInfo);
String external_contact = userJson.getString("external_contact"); String external_contact = userJson.getString("external_contact");
JSONObject jt = null; JSONObject jt = null;
if (StringUtils.isNotBlank(external_contact)) { if (StringUtils.isNotBlank(external_contact)) {
jt = JSON.parseObject(external_contact); jt = JSON.parseObject(external_contact);
name = EmojiFilterUtil.filterEmojiLast(jt.getString("name"), true); name = EmojiFilterUtil.filterEmojiLast(jt.getString("name"), true);
} }
} }
return name; return name;
} }
private String getClerkId(String wxEnterpriseId, String staffId, String state) { private String getClerkId(String wxEnterpriseId, String staffId, String state) {
String hyClerkId = null; String hyClerkId = null;
Long hmId = null; Long hmId = null;
if (StringUtils.isNotBlank(state) if (StringUtils.isNotBlank(state)
&& (state.startsWith(Manage3Constants.HM) || state.startsWith(Manage3Constants.DT))) { && (state.startsWith(Manage3Constants.HM) || state.startsWith(Manage3Constants.DT))) {
String id = state.substring(2); String id = state.substring(2);
if (state.startsWith(Manage3Constants.HM)) { if (state.startsWith(Manage3Constants.HM)) {
hmId = Convert.toLong(id); hmId = Convert.toLong(id);
} else if (state.startsWith(Manage3Constants.DT)) { } else if (state.startsWith(Manage3Constants.DT)) {
KeyDataLinkBO linkData = keyDataService.getDataForHmLink(id); KeyDataLinkBO linkData = keyDataService.getDataForHmLink(id);
if (null != linkData) { if (null != linkData) {
hmId = linkData.getHmId(); hmId = linkData.getHmId();
} }
} }
if (null != hmId) { if (null != hmId) {
HmQrcodeDTO hmDTO = hmQrcodeApiService.getSimpleById(hmId); HmQrcodeDTO hmDTO = hmQrcodeApiService.getSimpleById(hmId);
if (hmDTO != null) { if (hmDTO != null) {
hyClerkId = this.getHmClerk(hmDTO, wxEnterpriseId, staffId); hyClerkId = this.getHmClerk(hmDTO, wxEnterpriseId, staffId);
log.info("获取到活码导购={},hmId={}", hyClerkId, hmId); log.info("获取到活码导购={},hmId={}", hyClerkId, hmId);
} }
} }
} }
if (StringUtils.isEmpty(hyClerkId)) { if (StringUtils.isEmpty(hyClerkId)) {
TabHaobanClerkMainStoreRelated mainStoreRelated = clerkMainStoreRelatedService TabHaobanClerkMainStoreRelated mainStoreRelated = clerkMainStoreRelatedService
.getMainStoreByStaffId(staffId, wxEnterpriseId); .getMainStoreByStaffId(staffId, wxEnterpriseId);
if (mainStoreRelated != null) { if (mainStoreRelated != null) {
StaffClerkRelationDTO staffClerkRelationDTO = staffClerkRelationService.getOneBindByStoreId(staffId, StaffClerkRelationDTO staffClerkRelationDTO = staffClerkRelationService.getOneBindByStoreId(staffId,
mainStoreRelated.getStoreId()); mainStoreRelated.getStoreId());
if (null != staffClerkRelationDTO) { if (null != staffClerkRelationDTO) {
hyClerkId = staffClerkRelationDTO.getClerkId(); hyClerkId = staffClerkRelationDTO.getClerkId();
log.info("获取成员关联导购={}", hyClerkId); log.info("获取成员关联导购={}", hyClerkId);
} }
} }
} }
return hyClerkId; return hyClerkId;
} }
@Override @Override
public String getHmClerk(HmQrcodeDTO hmDTO, String wxEnterpriseId, String staffId) { public String getHmClerk(HmQrcodeDTO hmDTO, String wxEnterpriseId, String staffId) {
Long hmId = hmDTO.getHmId(); Long hmId = hmDTO.getHmId();
if (hmDTO.getHmType() == 1) { if (hmDTO.getHmType() == 1) {
return hmDTO.getClerkId(); return hmDTO.getClerkId();
} else if (hmDTO.getHmType() == 2) { } else if (hmDTO.getHmType() == 2) {
// 有主门店导购绑定主导购,没有主门店导购绑定第一个导购,其余随机 // 有主门店导购绑定主导购,没有主门店导购绑定第一个导购,其余随机
HmClerkRelationDTO hmClerkRelationDTO = null; HmClerkRelationDTO hmClerkRelationDTO = null;
TabHaobanClerkMainStoreRelated mainStoreRelated = clerkMainStoreRelatedService TabHaobanClerkMainStoreRelated mainStoreRelated = clerkMainStoreRelatedService
.getMainStoreByStaffId(staffId, wxEnterpriseId); .getMainStoreByStaffId(staffId, wxEnterpriseId);
if (mainStoreRelated != null) { if (mainStoreRelated != null) {
StaffClerkRelationDTO relationDTO = staffClerkRelationService.getOneBindByStoreId(staffId, StaffClerkRelationDTO relationDTO = staffClerkRelationService.getOneBindByStoreId(staffId,
mainStoreRelated.getStoreId()); mainStoreRelated.getStoreId());
hmClerkRelationDTO = hmClerkRelationApiService.getHmClerkByHmIdAndClerkId(hmId, hmClerkRelationDTO = hmClerkRelationApiService.getHmClerkByHmIdAndClerkId(hmId,
relationDTO.getClerkId()); relationDTO.getClerkId());
if (hmClerkRelationDTO == null) { if (hmClerkRelationDTO == null) {
hmClerkRelationDTO = hmClerkRelationApiService.getOneHmClerkByHmIdAndStaffId(hmId, staffId); hmClerkRelationDTO = hmClerkRelationApiService.getOneHmClerkByHmIdAndStaffId(hmId, staffId);
if (hmClerkRelationDTO == null) { if (hmClerkRelationDTO == null) {
hmClerkRelationDTO = hmClerkRelationApiService.getOneHmClerkByHmId(hmId); hmClerkRelationDTO = hmClerkRelationApiService.getOneHmClerkByHmId(hmId);
} }
} }
} else { } else {
hmClerkRelationDTO = hmClerkRelationApiService.getOneHmClerkByHmId(hmId); hmClerkRelationDTO = hmClerkRelationApiService.getOneHmClerkByHmId(hmId);
} }
return hmClerkRelationDTO.getClerkId(); return hmClerkRelationDTO.getClerkId();
} }
return null; return null;
} }
} }
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment