Commit 147b9bb0 by danmo

重构回调通知

1 parent ed5d30ed
Showing 45 changed files with 640 additions and 275 deletions
package com.linkwechat.web.controller.wecom; package com.linkwechat.web.controller.wecom;
import com.alibaba.fastjson.JSONObject; import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper;
import com.linkwechat.common.utils.Threads; import com.linkwechat.common.core.domain.entity.WeCorpAccount;
import com.linkwechat.common.utils.wecom.WxCryptUtil; import com.linkwechat.common.utils.wecom.WxCryptUtil;
import com.linkwechat.web.controller.common.CommonController; import com.linkwechat.web.controller.common.CommonController;
import com.linkwechat.wecom.domain.vo.WxCpXmlMessageVO; import com.linkwechat.wecom.service.IWeCorpAccountService;
import com.linkwechat.wecom.factory.WeCallBackEventFactory; import com.linkwechat.wecom.service.event.WeEventPublisherService;
import com.linkwechat.wecom.factory.WeEventHandle;
import com.linkwechat.wecom.factory.impl.customer.WeCallBackAddExternalContactImpl;
import com.thoughtworks.xstream.XStream;
import com.thoughtworks.xstream.security.AnyTypePermission;
import io.swagger.annotations.Api; import io.swagger.annotations.Api;
import io.swagger.annotations.ApiModelProperty; import io.swagger.annotations.ApiModelProperty;
import lombok.extern.slf4j.Slf4j; import lombok.extern.slf4j.Slf4j;
import me.chanjar.weixin.common.util.xml.XStreamInitializer;
import me.chanjar.weixin.cp.bean.message.WxCpXmlMessage;
import org.springframework.beans.factory.annotation.Autowired; import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.beans.factory.annotation.Value; import org.springframework.beans.factory.annotation.Value;
import org.springframework.web.bind.annotation.*; import org.springframework.web.bind.annotation.*;
import javax.annotation.Resource;
import javax.servlet.http.HttpServletRequest; import javax.servlet.http.HttpServletRequest;
/** /**
...@@ -33,36 +26,20 @@ import javax.servlet.http.HttpServletRequest; ...@@ -33,36 +26,20 @@ import javax.servlet.http.HttpServletRequest;
@RequestMapping("/wecom/callback") @RequestMapping("/wecom/callback")
public class WeCallBackController extends CommonController { public class WeCallBackController extends CommonController {
@Autowired @Autowired
private WeEventHandle weEventHandle; private WeEventPublisherService weEventPublisherService;
@Value("${wecome.callBack.appIdOrCorpId}")
private String appIdOrCorpId;
@Value("${wecome.callBack.token}")
private String token;
@Value("${wecome.callBack.encodingAesKey}")
private String encodingAesKey;
@Autowired
private IWeCorpAccountService weCorpAccountService;
@ApiModelProperty("post数据接收") @ApiModelProperty("post数据接收")
@PostMapping(value = "/recive") @PostMapping(value = "/recive/{corpId}")
public String recive(@RequestBody String msg, @RequestParam(name = "msg_signature") String signature, public String recive(@RequestBody String msg, @RequestParam(name = "msg_signature") String signature,
String timestamp, String nonce) { String timestamp, String nonce,@PathVariable("corpId") String corpId) {
WxCryptUtil wxCryptUtil = new WxCryptUtil(token, encodingAesKey, appIdOrCorpId); WeCorpAccount corpAccount = weCorpAccountService.getCorpAccountByCorpId(corpId);
WxCryptUtil wxCryptUtil = new WxCryptUtil(corpAccount.getToken(), corpAccount.getEncodingAesKey(), corpId);
try { try {
String decrypt = wxCryptUtil.decrypt(signature, timestamp, nonce, msg); String decrypt = wxCryptUtil.decrypt(signature, timestamp, nonce, msg);
WxCpXmlMessageVO wxCpXmlMessage = StrXmlToBean(decrypt); weEventPublisherService.register(decrypt);
log.info("企微回调通知接口 wxCpXmlMessage:{}", JSONObject.toJSONString(wxCpXmlMessage));
try {
// ;
WeCallBackEventFactory factory = weEventHandle.factory(wxCpXmlMessage.getEvent());
if (factory !=null){
Threads.SINGLE_THREAD_POOL.submit(() -> factory.eventHandle(wxCpXmlMessage));
}
} catch (Exception e) {
e.printStackTrace();
}
return decrypt; return decrypt;
} catch (Exception e) { } catch (Exception e) {
e.printStackTrace();; e.printStackTrace();;
...@@ -72,8 +49,8 @@ public class WeCallBackController extends CommonController { ...@@ -72,8 +49,8 @@ public class WeCallBackController extends CommonController {
} }
@ApiModelProperty("get数据校验") @ApiModelProperty("get数据校验")
@GetMapping(value = "/recive") @GetMapping(value = "/recive/{corpId}")
public String recive(HttpServletRequest request) { public String recive(HttpServletRequest request,@PathVariable("corpId") String corpId) {
// 微信加密签名 // 微信加密签名
String sVerifyMsgSig = request.getParameter("msg_signature"); String sVerifyMsgSig = request.getParameter("msg_signature");
// 时间戳 // 时间戳
...@@ -83,25 +60,12 @@ public class WeCallBackController extends CommonController { ...@@ -83,25 +60,12 @@ public class WeCallBackController extends CommonController {
// 随机字符串 // 随机字符串
String sVerifyEchoStr = request.getParameter("echostr"); String sVerifyEchoStr = request.getParameter("echostr");
WxCryptUtil wxCryptUtil = new WxCryptUtil(token, encodingAesKey, appIdOrCorpId); WeCorpAccount corpAccount = weCorpAccountService.getCorpAccountByCorpId(corpId);
WxCryptUtil wxCryptUtil = new WxCryptUtil(corpAccount.getToken(), corpAccount.getEncodingAesKey(), corpId);
try { try {
return wxCryptUtil.verifyURL(sVerifyMsgSig, sVerifyTimeStamp, sVerifyNonce, sVerifyEchoStr); return wxCryptUtil.verifyURL(sVerifyMsgSig, sVerifyTimeStamp, sVerifyNonce, sVerifyEchoStr);
} catch (Exception e) { } catch (Exception e) {
return "error"; return "error";
} }
} }
private WxCpXmlMessageVO StrXmlToBean(String xmlStr){
XStream xstream = XStreamInitializer.getInstance();
xstream.addPermission(AnyTypePermission.ANY);
xstream.processAnnotations(WxCpXmlMessage.class);
xstream.processAnnotations(WxCpXmlMessageVO.class);
xstream.processAnnotations(WxCpXmlMessageVO.ScanCodeInfo.class);
xstream.processAnnotations(WxCpXmlMessageVO.SendPicsInfo.class);
xstream.processAnnotations(WxCpXmlMessageVO.SendPicsInfo.Item.class);
xstream.processAnnotations(WxCpXmlMessageVO.SendLocationInfo.class);
xstream.processAnnotations(WxCpXmlMessageVO.BatchJob.class);
WxCpXmlMessageVO wxCpXmlMessage = (WxCpXmlMessageVO)xstream.fromXML(xmlStr);
return wxCpXmlMessage;
}
} }
...@@ -281,23 +281,7 @@ public class WeConstans { ...@@ -281,23 +281,7 @@ public class WeConstans {
public static final String AppTicketKey = "ticket:AppGet"; public static final String AppTicketKey = "ticket:AppGet";
public static final String AgentTicketKey = "ticket:AgentGet"; public static final String AgentTicketKey = "ticket:AgentGet";
/** public static final String corpAccountKey = "we:corpAccount:{}";
* 企微回调事件类型路由
*/
public final static Map<String, String> eventRoute = new HashMap<String, String>() {
{
//成员事件
put("change_contact", "weEventChangeContactImpl");
//异步任务完成通知
put("batch_job_result", "weEventBatchJobResultImpl");
//外部联系人事件
put("change_external_contact", "weEventChangeExternalContactImpl");
//客户群事件
put("change_external_chat", "weEventChangeExternalChatImpl");
//客户标签事件
put("change_external_tag", "weEventChangeExternalTagImpl");
}
};
//性别,1表示男性,2表示女性 //性别,1表示男性,2表示女性
//表示所在部门是否为上级,0-否,1-是,顺序与Department字段的部门逐一对应 //表示所在部门是否为上级,0-否,1-是,顺序与Department字段的部门逐一对应
......
...@@ -110,7 +110,7 @@ public class WeCorpAccount extends BaseEntity ...@@ -110,7 +110,7 @@ public class WeCorpAccount extends BaseEntity
**********************************************/ **********************************************/
/**回调url*/ /**回调url*/
private String backOffUrl; //private String backOffUrl;
/**回调token*/ /**回调token*/
private String token; private String token;
......
package com.linkwechat.wecom.domain.callback;
import io.swagger.annotations.ApiModel;
import io.swagger.annotations.ApiModelProperty;
import lombok.Data;
/**
* @author danmo
* @description 异步任务完成通知
* @date 2021/11/20 13:14
**/
@ApiModel
@Data
public class WeBackAsynTaskVo extends WeBackBaseVo{
@ApiModelProperty("异步任务")
private BatchJobVo BatchJob;
@ApiModel
@Data
public class BatchJobVo{
@ApiModelProperty("异步任务id")
private String JobId;
@ApiModelProperty("操作类型 目前分别有:sync_user(增量更新成员)、 replace_user(全量覆盖成员)、invite_user(邀请成员关注)、replace_party(全量覆盖部门)")
private String JobType;
@ApiModelProperty("返回码")
private Integer ErrCode;
@ApiModelProperty("对返回码的文本描述内容")
private String ErrMsg;
}
}
package com.linkwechat.wecom.domain.callback;
import io.swagger.annotations.ApiModel;
import io.swagger.annotations.ApiModelProperty;
import lombok.Data;
/**
* @author danmo
* @description 回调验证XML对象
* @date 2021/11/19 18:39
**/
@ApiModel
@Data
public class WeBackBaseVo {
@ApiModelProperty("企业微信CorpID")
private String ToUserName;
@ApiModelProperty("此事件该值固定为sys")
private String FromUserName;
@ApiModelProperty("消息创建时间 (整型)")
private Long CreateTime;
@ApiModelProperty("消息的类型,此时固定为event")
private String MsgType;
@ApiModelProperty("事件的类型")
private String Event;
@ApiModelProperty("变更类型")
private String ChangeType;
@ApiModelProperty("token")
private String Token;
@ApiModelProperty("应用ID")
private String AgentID;
}
package com.linkwechat.wecom.domain.callback;
import io.swagger.annotations.ApiModel;
import io.swagger.annotations.ApiModelProperty;
import lombok.Data;
/**
* @author danmo
* @description 客户群变更通知
* @date 2021/11/20 13:14
**/
@ApiModel
@Data
public class WeBackCustomerGroupVo extends WeBackBaseVo {
@ApiModelProperty("群ID")
private String ChatId;
@ApiModelProperty("变更详情。add_member:成员入群 del_member:成员退群 change_owner:群主变更 change_name:群名变更 change_notice:群公告变更")
private String UpdateDetail;
@ApiModelProperty("当是成员入群时有值。表示成员的入群方式 0 - 由成员邀请入群(包括直接邀请入群和通过邀请链接入群) 3 - 通过扫描群二维码入群")
private Integer JoinScene;
@ApiModelProperty("当是成员退群时有值。表示成员的退群方式 0 - 自己退群 1 - 群主/群管理员移出")
private Integer QuitScene;
@ApiModelProperty("当是成员入群或退群时有值。表示成员变更数量")
private Integer MemChangeCnt;
}
package com.linkwechat.wecom.domain.callback;
import io.swagger.annotations.ApiModel;
import io.swagger.annotations.ApiModelProperty;
import lombok.Data;
/**
* @author danmo
* @description 企业客户标签变更通知
* @date 2021/11/20 13:14
**/
@ApiModel
@Data
public class WeBackCustomerTagVo extends WeBackBaseVo {
@ApiModelProperty("标签组的id")
private String Id;
@ApiModelProperty("删除标签时,此项为tag,删除标签组时,此项为tag_group")
private String TagType;
@ApiModelProperty("规则组id,如果修改了规则组标签的顺序,则回调时会带上此标签所属规则组的id")
private String StrategyId;
}
package com.linkwechat.wecom.domain.callback;
import io.swagger.annotations.ApiModel;
import io.swagger.annotations.ApiModelProperty;
import lombok.Data;
/**
* @author danmo
* @description 企业客户变更通知
* @date 2021/11/20 13:14
**/
@ApiModel
@Data
public class WeBackCustomerVo extends WeBackBaseVo{
@ApiModelProperty("企业服务人员的UserID")
private String UserID;
@ApiModelProperty("外部联系人的userid,注意不是企业成员的帐号")
private String ExternalUserID;
@ApiModelProperty("添加此用户的「联系我」方式配置的state参数,可用于识别添加此用户的渠道")
private String State;
@ApiModelProperty("欢迎语code")
private String WelcomeCode;
@ApiModelProperty("删除客户的操作来源,DELETE_BY_TRANSFER表示此客户是因在职继承自动被转接成员删除")
private String Source;
@ApiModelProperty("接替失败的原因, customer_refused-客户拒绝, customer_limit_exceed-接替成员的客户数达到上限")
private String FailReason;
}
package com.linkwechat.wecom.domain.callback;
import io.swagger.annotations.ApiModel;
import io.swagger.annotations.ApiModelProperty;
import lombok.Data;
/**
* @author danmo
* @description 部门变更通知
* @date 2021/11/20 13:14
**/
@ApiModel
@Data
public class WeBackDeptVo extends WeBackBaseVo{
@ApiModelProperty("部门Id")
private String Id;
@ApiModelProperty("部门名称")
private String Name;
@ApiModelProperty("父部门id")
private String ParentId;
@ApiModelProperty("部门排序")
private String Order;
}
package com.linkwechat.wecom.domain.callback;
import io.swagger.annotations.ApiModel;
import io.swagger.annotations.ApiModelProperty;
import lombok.Data;
/**
* @author danmo
* @description 标签成员变更通知
* @date 2021/11/20 13:14
**/
@ApiModel
@Data
public class WeBackUserTagVo extends WeBackBaseVo{
@ApiModelProperty("标签Id")
private String TagId;
@ApiModelProperty("标签中新增的成员userid列表,用逗号分隔")
private String AddUserItems;
@ApiModelProperty("标签中删除的成员userid列表,用逗号分隔")
private String DelUserItems;
@ApiModelProperty("标签中新增的部门id列表,用逗号分隔")
private String AddPartyItems;
@ApiModelProperty("标签中删除的部门id列表,用逗号分隔")
private String DelPartyItems;
}
package com.linkwechat.wecom.domain.callback;
import io.swagger.annotations.ApiModel;
import io.swagger.annotations.ApiModelProperty;
import lombok.Data;
/**
* @author danmo
* @description 成员变更通知
* @date 2021/11/20 13:02
**/
@ApiModel
@Data
public class WeBackUserVo extends WeBackBaseVo {
@ApiModelProperty("成员UserID")
private String UserID;
@ApiModelProperty("成员名称")
private String Name;
@ApiModelProperty("成员部门列表")
private String Department;
@ApiModelProperty("主部门")
private String MainDepartment;
@ApiModelProperty("表示所在部门是否为上级,0-否,1-是")
private String IsLeaderInDept;
@ApiModelProperty("手机号码")
private String Position;
@ApiModelProperty("职位信息")
private String Mobile;
@ApiModelProperty("性别")
private Integer Gender;
@ApiModelProperty("邮箱")
private String Email;
@ApiModelProperty("激活状态")
private Integer Status;
@ApiModelProperty("头像url")
private String Avatar;
@ApiModelProperty("成员别名")
private String Alias;
@ApiModelProperty("座机")
private String Telephone;
@ApiModelProperty("地址")
private String Address;
}
package com.linkwechat.wecom.domain.callback;
import org.springframework.context.ApplicationEvent;
/**
* @author danmo
* @description
* @date 2021/11/21 19:52
**/
public class WeCallBackEvent extends ApplicationEvent {
private String message;
public WeCallBackEvent(Object source,String message) {
super(source);
this.message = message;
}
public String getMessage() {
return message;
}
public void setMessage(String message) {
this.message = message;
}
}
...@@ -10,5 +10,5 @@ import org.springframework.stereotype.Service; ...@@ -10,5 +10,5 @@ import org.springframework.stereotype.Service;
**/ **/
@Service @Service
public interface WeCallBackEventFactory { public interface WeCallBackEventFactory {
public void eventHandle(WxCpXmlMessageVO message); public void eventHandle(String message);
} }
package com.linkwechat.wecom.factory;
import com.linkwechat.common.constant.WeConstans;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
import java.util.Map;
/**
* @author danmo
* @description 企微回调策略
* @date 2020/11/8 17:17
**/
@Service
public class WeEventHandle {
@Autowired
private Map<String, WeCallBackEventFactory> weCallBackEventFactoryMap;
public WeCallBackEventFactory factory(String eventType) {
if (!WeConstans.eventRoute.containsKey(eventType)) {
return null;
}
String resolveClass = WeConstans.eventRoute.get(eventType);
if (!weCallBackEventFactoryMap.containsKey(resolveClass)) {
return null;
}
return weCallBackEventFactoryMap.get(resolveClass);
}
}
package com.linkwechat.wecom.factory; package com.linkwechat.wecom.factory;
import com.linkwechat.wecom.domain.callback.WeBackBaseVo;
import com.linkwechat.wecom.domain.callback.WeBackDeptVo;
import com.linkwechat.wecom.domain.callback.WeBackUserVo;
import com.linkwechat.wecom.domain.WeDepartment; import com.linkwechat.wecom.domain.WeDepartment;
import com.linkwechat.wecom.domain.WeUser; import com.linkwechat.wecom.domain.WeUser;
import com.linkwechat.wecom.domain.vo.WxCpXmlMessageVO;
import java.util.Arrays;
import java.util.stream.Collectors;
/** /**
* @author danmo * @author danmo
...@@ -16,11 +15,11 @@ public abstract class WeEventStrategy { ...@@ -16,11 +15,11 @@ public abstract class WeEventStrategy {
protected final String tag = "tag"; protected final String tag = "tag";
protected final String tagGroup = "tag_group"; protected final String tagGroup = "tag_group";
public abstract void eventHandle(WxCpXmlMessageVO message); public abstract void eventHandle(WeBackBaseVo message);
//生成成员数据 //生成成员数据
public WeUser setWeUserData(WxCpXmlMessageVO message) { public WeUser setWeUserData(WeBackUserVo message) {
WeUser weUser = WeUser.builder().userId(message.getUserId()) WeUser weUser = WeUser.builder().userId(message.getUserID())
.email(message.getEmail()) .email(message.getEmail())
.name(message.getName()) .name(message.getName())
.alias(message.getAlias()) .alias(message.getAlias())
...@@ -32,23 +31,19 @@ public abstract class WeEventStrategy { ...@@ -32,23 +31,19 @@ public abstract class WeEventStrategy {
.position(message.getPosition()) .position(message.getPosition())
.build(); .build();
if (message.getStatus() != null) { if (message.getStatus() != null) {
weUser.setIsActivate(Integer.valueOf(message.getStatus())); weUser.setIsActivate(message.getStatus());
} }
if (message.getIsLeaderInDept() != null) { if (message.getIsLeaderInDept() != null) {
String isLeaderInDeptStr = Arrays.stream(message.getIsLeaderInDept()) weUser.setIsLeaderInDept(message.getIsLeaderInDept());
.map(String::valueOf).collect(Collectors.joining(","));
weUser.setIsLeaderInDept(isLeaderInDeptStr);
} }
if (message.getDepartments() != null) { if (message.getDepartment() != null) {
String departmentsStr = Arrays.stream(message.getDepartments()) weUser.setDepartment(message.getDepartment());
.map(String::valueOf).collect(Collectors.joining(","));
weUser.setDepartment(departmentsStr);
} }
return weUser; return weUser;
} }
//部门信息 //部门信息
public WeDepartment setWeDepartMent(WxCpXmlMessageVO message){ public WeDepartment setWeDepartMent(WeBackDeptVo message){
WeDepartment weDepartment = new WeDepartment(); WeDepartment weDepartment = new WeDepartment();
if (message.getId() != null) { if (message.getId() != null) {
weDepartment.setId(Long.parseLong(message.getId())); weDepartment.setId(Long.parseLong(message.getId()));
......
package com.linkwechat.wecom.factory; package com.linkwechat.wecom.factory;
import com.linkwechat.wecom.domain.vo.WxCpXmlMessageVO; import com.linkwechat.wecom.domain.callback.WeBackBaseVo;
import org.springframework.beans.factory.annotation.Autowired; import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service; import org.springframework.stereotype.Service;
...@@ -18,11 +18,10 @@ public class WeStrategyBeanFactory { ...@@ -18,11 +18,10 @@ public class WeStrategyBeanFactory {
private final Map<String, WeEventStrategy> eventStrategyMap = new ConcurrentHashMap<>(); private final Map<String, WeEventStrategy> eventStrategyMap = new ConcurrentHashMap<>();
public WeStrategyBeanFactory(Map<String, WeEventStrategy> strategyMap) { public WeStrategyBeanFactory(Map<String, WeEventStrategy> strategyMap) {
this.eventStrategyMap.clear(); this.eventStrategyMap.putAll(strategyMap);
strategyMap.forEach((k, v) -> this.eventStrategyMap.put(k, v));
} }
public void getResource(String type, WxCpXmlMessageVO message) { public void getResource(String type, WeBackBaseVo message) {
eventStrategyMap.get(type).eventHandle(message); eventStrategyMap.get(type).eventHandle(message);
} }
} }
package com.linkwechat.wecom.factory.impl; package com.linkwechat.wecom.factory.impl;
import com.linkwechat.wecom.domain.vo.WxCpXmlMessageVO; import cn.hutool.core.util.XmlUtil;
import com.linkwechat.wecom.domain.callback.WeBackAsynTaskVo;
import com.linkwechat.wecom.factory.WeCallBackEventFactory; import com.linkwechat.wecom.factory.WeCallBackEventFactory;
import lombok.extern.slf4j.Slf4j; import lombok.extern.slf4j.Slf4j;
import org.springframework.stereotype.Service; import org.springframework.stereotype.Service;
...@@ -15,8 +16,9 @@ import org.springframework.stereotype.Service; ...@@ -15,8 +16,9 @@ import org.springframework.stereotype.Service;
public class WeEventBatchJobResultImpl implements WeCallBackEventFactory { public class WeEventBatchJobResultImpl implements WeCallBackEventFactory {
@Override @Override
public void eventHandle(WxCpXmlMessageVO message) { public void eventHandle(String message) {
String jobType = message.getBatchJob().getJobType(); WeBackAsynTaskVo weBackAsynTaskVo = XmlUtil.xmlToBean(XmlUtil.parseXml(message).getFirstChild(), WeBackAsynTaskVo.class);
String jobType = weBackAsynTaskVo.getBatchJob().getJobType();
switch (jobType){ switch (jobType){
case "sync_user"://增量更新成员) case "sync_user"://增量更新成员)
break; break;
......
package com.linkwechat.wecom.factory.impl; package com.linkwechat.wecom.factory.impl;
import com.linkwechat.wecom.domain.vo.WxCpXmlMessageVO; import cn.hutool.core.util.XmlUtil;
import com.linkwechat.wecom.domain.callback.WeBackUserVo;
import com.linkwechat.wecom.factory.WeCallBackEventFactory; import com.linkwechat.wecom.factory.WeCallBackEventFactory;
import com.linkwechat.wecom.factory.WeStrategyBeanFactory; import com.linkwechat.wecom.factory.WeStrategyBeanFactory;
import lombok.extern.slf4j.Slf4j; import lombok.extern.slf4j.Slf4j;
...@@ -19,9 +20,10 @@ public class WeEventChangeContactImpl implements WeCallBackEventFactory { ...@@ -19,9 +20,10 @@ public class WeEventChangeContactImpl implements WeCallBackEventFactory {
private WeStrategyBeanFactory weStrategyBeanFactory; private WeStrategyBeanFactory weStrategyBeanFactory;
@Override @Override
public void eventHandle(WxCpXmlMessageVO message) { public void eventHandle(String message) {
//新增: create_user 更新: update_user 删除:delete_user //新增: create_user 更新: update_user 删除:delete_user
String changeType = message.getChangeType(); WeBackUserVo weBackUserVo = XmlUtil.xmlToBean(XmlUtil.parseXml(message).getFirstChild(), WeBackUserVo.class);
weStrategyBeanFactory.getResource(changeType, message); String changeType = weBackUserVo.getChangeType();
weStrategyBeanFactory.getResource(changeType, weBackUserVo);
} }
} }
package com.linkwechat.wecom.factory.impl; package com.linkwechat.wecom.factory.impl;
import com.linkwechat.wecom.domain.vo.WxCpXmlMessageVO; import cn.hutool.core.util.XmlUtil;
import com.linkwechat.wecom.domain.callback.WeBackCustomerGroupVo;
import com.linkwechat.wecom.factory.WeCallBackEventFactory; import com.linkwechat.wecom.factory.WeCallBackEventFactory;
import com.linkwechat.wecom.factory.WeStrategyBeanFactory; import com.linkwechat.wecom.factory.WeStrategyBeanFactory;
import lombok.extern.slf4j.Slf4j; import lombok.extern.slf4j.Slf4j;
...@@ -20,8 +21,9 @@ public class WeEventChangeExternalChatImpl implements WeCallBackEventFactory { ...@@ -20,8 +21,9 @@ public class WeEventChangeExternalChatImpl implements WeCallBackEventFactory {
private WeStrategyBeanFactory weStrategyBeanFactory; private WeStrategyBeanFactory weStrategyBeanFactory;
@Override @Override
public void eventHandle(WxCpXmlMessageVO message) { public void eventHandle(String message) {
String changeType = message.getChangeType(); WeBackCustomerGroupVo weBackCustomerGroupVo = XmlUtil.xmlToBean(XmlUtil.parseXml(message).getFirstChild(), WeBackCustomerGroupVo.class);
weStrategyBeanFactory.getResource(changeType,message); String changeType = weBackCustomerGroupVo.getChangeType();
weStrategyBeanFactory.getResource(changeType,weBackCustomerGroupVo);
} }
} }
package com.linkwechat.wecom.factory.impl; package com.linkwechat.wecom.factory.impl;
import com.linkwechat.wecom.domain.vo.WxCpXmlMessageVO; import cn.hutool.core.util.XmlUtil;
import com.linkwechat.wecom.domain.callback.WeBackCustomerVo;
import com.linkwechat.wecom.factory.WeCallBackEventFactory; import com.linkwechat.wecom.factory.WeCallBackEventFactory;
import com.linkwechat.wecom.factory.WeStrategyBeanFactory; import com.linkwechat.wecom.factory.WeStrategyBeanFactory;
import lombok.extern.slf4j.Slf4j; import lombok.extern.slf4j.Slf4j;
...@@ -19,8 +20,9 @@ public class WeEventChangeExternalContactImpl implements WeCallBackEventFactory ...@@ -19,8 +20,9 @@ public class WeEventChangeExternalContactImpl implements WeCallBackEventFactory
private WeStrategyBeanFactory weStrategyBeanFactory; private WeStrategyBeanFactory weStrategyBeanFactory;
@Override @Override
public void eventHandle(WxCpXmlMessageVO message) { public void eventHandle(String message) {
String changeType = message.getChangeType(); WeBackCustomerVo weBackCustomerVo = XmlUtil.xmlToBean(XmlUtil.parseXml(message).getFirstChild(), WeBackCustomerVo.class);
weStrategyBeanFactory.getResource(changeType,message); String changeType = weBackCustomerVo.getChangeType();
weStrategyBeanFactory.getResource(changeType, weBackCustomerVo);
} }
} }
package com.linkwechat.wecom.factory.impl; package com.linkwechat.wecom.factory.impl;
import cn.hutool.core.util.XmlUtil;
import com.linkwechat.wecom.domain.callback.WeBackCustomerGroupVo;
import com.linkwechat.wecom.domain.callback.WeBackCustomerTagVo;
import com.linkwechat.wecom.domain.callback.WeBackCustomerVo;
import com.linkwechat.wecom.domain.vo.WxCpXmlMessageVO; import com.linkwechat.wecom.domain.vo.WxCpXmlMessageVO;
import com.linkwechat.wecom.factory.WeCallBackEventFactory; import com.linkwechat.wecom.factory.WeCallBackEventFactory;
import com.linkwechat.wecom.factory.WeStrategyBeanFactory; import com.linkwechat.wecom.factory.WeStrategyBeanFactory;
...@@ -19,8 +23,9 @@ public class WeEventChangeExternalTagImpl implements WeCallBackEventFactory { ...@@ -19,8 +23,9 @@ public class WeEventChangeExternalTagImpl implements WeCallBackEventFactory {
private WeStrategyBeanFactory weStrategyBeanFactory; private WeStrategyBeanFactory weStrategyBeanFactory;
@Override @Override
public void eventHandle(WxCpXmlMessageVO message) { public void eventHandle(String message) {
String changeType = message.getChangeType()+"CustomerTag"; WeBackCustomerTagVo weBackCustomerTagVo = XmlUtil.xmlToBean(XmlUtil.parseXml(message).getFirstChild(), WeBackCustomerTagVo.class);
weStrategyBeanFactory.getResource(changeType,message); String changeType = weBackCustomerTagVo.getChangeType()+"CustomerTag";
weStrategyBeanFactory.getResource(changeType,weBackCustomerTagVo);
} }
} }
package com.linkwechat.wecom.factory.impl.customer; package com.linkwechat.wecom.factory.impl.customer;
import cn.hutool.core.collection.CollectionUtil;
import cn.hutool.core.io.FileUtil;
import com.alibaba.fastjson.JSONObject; import com.alibaba.fastjson.JSONObject;
import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper;
import com.linkwechat.common.constant.WeConstans; import com.linkwechat.common.constant.WeConstans;
import com.linkwechat.common.enums.MediaType; import com.linkwechat.common.enums.MediaType;
import com.linkwechat.common.utils.StringUtils; import com.linkwechat.wecom.domain.callback.WeBackBaseVo;
import com.linkwechat.wecom.client.WeCustomerClient; import com.linkwechat.wecom.domain.callback.WeBackCustomerVo;
import com.linkwechat.wecom.domain.*; import com.linkwechat.wecom.domain.*;
import com.linkwechat.wecom.domain.dto.WeEmpleCodeDto;
import com.linkwechat.wecom.domain.dto.WeMediaDto; import com.linkwechat.wecom.domain.dto.WeMediaDto;
import com.linkwechat.wecom.domain.dto.WeWelcomeMsg; import com.linkwechat.wecom.domain.dto.WeWelcomeMsg;
import com.linkwechat.wecom.domain.dto.customer.CutomerTagEdit;
import com.linkwechat.wecom.domain.vo.WxCpXmlMessageVO;
import com.linkwechat.wecom.factory.WeEventStrategy; import com.linkwechat.wecom.factory.WeEventStrategy;
import com.linkwechat.wecom.service.*; import com.linkwechat.wecom.service.*;
import com.linkwechat.wecom.service.event.WeEventPublisherService; import com.linkwechat.wecom.service.event.WeEventPublisherService;
import lombok.extern.slf4j.Slf4j; import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.factory.annotation.Autowired; import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Component; import org.springframework.stereotype.Component;
import java.util.ArrayList;
import java.util.Date; import java.util.Date;
import java.util.List; import java.util.List;
import java.util.Optional; import java.util.Optional;
...@@ -51,16 +45,17 @@ public class WeCallBackAddExternalContactImpl extends WeEventStrategy { ...@@ -51,16 +45,17 @@ public class WeCallBackAddExternalContactImpl extends WeEventStrategy {
@Override @Override
public void eventHandle(WxCpXmlMessageVO message) { public void eventHandle(WeBackBaseVo message) {
if (message.getExternalUserId() != null) { WeBackCustomerVo customerInfo = (WeBackCustomerVo) message;
weCustomerService.getCustomersInfoAndSynchWeCustomer(message.getExternalUserId(),message.getUserId()); if (customerInfo.getExternalUserID() != null) {
weCustomerService.getCustomersInfoAndSynchWeCustomer(customerInfo.getExternalUserID(),customerInfo.getUserID());
} }
if (message.getState() != null && message.getWelcomeCode() != null) { if (customerInfo.getState() != null && customerInfo.getWelcomeCode() != null) {
if (isFission(message.getState())) { if (isFission(customerInfo.getState())) {
taskFissionRecordHandle(message.getState(), message.getWelcomeCode(), message.getUserId(), message.getExternalUserId()); taskFissionRecordHandle(customerInfo.getState(), customerInfo.getWelcomeCode(), customerInfo.getUserID(), customerInfo.getExternalUserID());
} else { } else {
weEventPublisherService.register(message.getState(), message.getWelcomeCode(), message.getUserId(), message.getExternalUserId()); weEventPublisherService.register(customerInfo.getState(), customerInfo.getWelcomeCode(), customerInfo.getUserID(), customerInfo.getExternalUserID());
} }
} }
......
...@@ -2,12 +2,13 @@ package com.linkwechat.wecom.factory.impl.customer; ...@@ -2,12 +2,13 @@ package com.linkwechat.wecom.factory.impl.customer;
import com.alibaba.fastjson.JSONObject; import com.alibaba.fastjson.JSONObject;
import com.linkwechat.common.constant.WeConstans; import com.linkwechat.common.constant.WeConstans;
import com.linkwechat.wecom.domain.callback.WeBackBaseVo;
import com.linkwechat.wecom.domain.callback.WeBackCustomerVo;
import com.linkwechat.wecom.domain.WeFlowerCustomerRel; import com.linkwechat.wecom.domain.WeFlowerCustomerRel;
import com.linkwechat.wecom.domain.WeTaskFission; import com.linkwechat.wecom.domain.WeTaskFission;
import com.linkwechat.wecom.domain.WeTaskFissionRecord; import com.linkwechat.wecom.domain.WeTaskFissionRecord;
import com.linkwechat.wecom.domain.WeTaskFissionReward; import com.linkwechat.wecom.domain.WeTaskFissionReward;
import com.linkwechat.wecom.domain.dto.WeWelcomeMsg; import com.linkwechat.wecom.domain.dto.WeWelcomeMsg;
import com.linkwechat.wecom.domain.vo.WxCpXmlMessageVO;
import com.linkwechat.wecom.factory.WeEventStrategy; import com.linkwechat.wecom.factory.WeEventStrategy;
import com.linkwechat.wecom.service.IWeCustomerService; import com.linkwechat.wecom.service.IWeCustomerService;
import com.linkwechat.wecom.service.IWeTaskFissionRecordService; import com.linkwechat.wecom.service.IWeTaskFissionRecordService;
...@@ -47,16 +48,17 @@ public class WeCallBackAddHalfExternalContactImpl extends WeEventStrategy { ...@@ -47,16 +48,17 @@ public class WeCallBackAddHalfExternalContactImpl extends WeEventStrategy {
@Override @Override
public void eventHandle(WxCpXmlMessageVO message) { public void eventHandle(WeBackBaseVo message) {
if (message.getExternalUserId() != null) { WeBackCustomerVo customerInfo = (WeBackCustomerVo) message;
weCustomerService.getCustomersInfoAndSynchWeCustomer(message.getExternalUserId(),message.getUserId()); if (customerInfo.getExternalUserID() != null) {
weCustomerService.getCustomersInfoAndSynchWeCustomer(customerInfo.getExternalUserID(),customerInfo.getUserID());
} }
if (message.getState() != null && message.getWelcomeCode() != null) { if (customerInfo.getState() != null && customerInfo.getWelcomeCode() != null) {
if (isFission(message.getState())) { if (isFission(customerInfo.getState())) {
taskFissionRecordHandle(message.getState(), message.getWelcomeCode(), message.getUserId(), message.getExternalUserId()); taskFissionRecordHandle(customerInfo.getState(), customerInfo.getWelcomeCode(), customerInfo.getUserID(), customerInfo.getExternalUserID());
} else { } else {
weEventPublisherService.register(message.getExternalUserId(),message.getUserId(),message.getWelcomeCode(),message.getState()); weEventPublisherService.register(customerInfo.getExternalUserID(),customerInfo.getUserID(),customerInfo.getWelcomeCode(),customerInfo.getState());
} }
} }
} }
......
package com.linkwechat.wecom.factory.impl.customer; package com.linkwechat.wecom.factory.impl.customer;
import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper; import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper;
import com.linkwechat.wecom.domain.callback.WeBackBaseVo;
import com.linkwechat.wecom.domain.callback.WeBackCustomerVo;
import com.linkwechat.wecom.domain.WeCustomer; import com.linkwechat.wecom.domain.WeCustomer;
import com.linkwechat.wecom.domain.WeSensitiveAct; import com.linkwechat.wecom.domain.WeSensitiveAct;
import com.linkwechat.wecom.domain.WeSensitiveActHit; import com.linkwechat.wecom.domain.WeSensitiveActHit;
import com.linkwechat.wecom.domain.WeUser; import com.linkwechat.wecom.domain.WeUser;
import com.linkwechat.wecom.domain.vo.WxCpXmlMessageVO;
import com.linkwechat.wecom.factory.WeEventStrategy; import com.linkwechat.wecom.factory.WeEventStrategy;
import com.linkwechat.wecom.service.IWeCustomerService; import com.linkwechat.wecom.service.IWeCustomerService;
import com.linkwechat.wecom.service.IWeSensitiveActHitService; import com.linkwechat.wecom.service.IWeSensitiveActHitService;
...@@ -33,28 +34,29 @@ public class WeCallBackDelExternalContactImpl extends WeEventStrategy { ...@@ -33,28 +34,29 @@ public class WeCallBackDelExternalContactImpl extends WeEventStrategy {
private IWeUserService weUserService; private IWeUserService weUserService;
@Override @Override
public void eventHandle(WxCpXmlMessageVO message) { public void eventHandle(WeBackBaseVo message) {
if (message.getExternalUserId() != null) { WeBackCustomerVo customerInfo = (WeBackCustomerVo) message;
if (customerInfo.getExternalUserID() != null) {
//删除客户 //删除客户
if(weCustomerService.remove(new LambdaQueryWrapper<WeCustomer>() if(weCustomerService.remove(new LambdaQueryWrapper<WeCustomer>()
.eq(WeCustomer::getExternalUserid,message.getExternalUserId()) .eq(WeCustomer::getExternalUserid,customerInfo.getExternalUserID())
.eq(WeCustomer::getFirstUserId,message.getUserId()))){ .eq(WeCustomer::getFirstUserId,customerInfo.getUserID()))){
//增加敏感行为记录,员工删除客户 //增加敏感行为记录,员工删除客户
WeSensitiveAct weSensitiveAct = weSensitiveActHitService.getSensitiveActType("拉黑/删除好友"); WeSensitiveAct weSensitiveAct = weSensitiveActHitService.getSensitiveActType("拉黑/删除好友");
if (weSensitiveAct != null && weSensitiveAct.getEnableFlag() == 1) { if (weSensitiveAct != null && weSensitiveAct.getEnableFlag() == 1) {
WeSensitiveActHit weSensitiveActHit = new WeSensitiveActHit(); WeSensitiveActHit weSensitiveActHit = new WeSensitiveActHit();
weSensitiveActHit.setSensitiveActId(weSensitiveAct.getId()); weSensitiveActHit.setSensitiveActId(weSensitiveAct.getId());
weSensitiveActHit.setSensitiveAct(weSensitiveAct.getActName()); weSensitiveActHit.setSensitiveAct(weSensitiveAct.getActName());
weSensitiveActHit.setCreateTime(new Date(message.getCreateTime())); weSensitiveActHit.setCreateTime(new Date(customerInfo.getCreateTime()));
weSensitiveActHit.setCreateBy("admin"); weSensitiveActHit.setCreateBy("admin");
weSensitiveActHit.setOperatorId(message.getUserId()); weSensitiveActHit.setOperatorId(customerInfo.getUserID());
WeUser user = weUserService.getById(message.getUserId()); WeUser user = weUserService.getById(customerInfo.getUserID());
weSensitiveActHit.setOperator(user.getName()); weSensitiveActHit.setOperator(user.getName());
WeCustomer weCustomer = weCustomerService.getOne(new LambdaQueryWrapper<WeCustomer>() WeCustomer weCustomer = weCustomerService.getOne(new LambdaQueryWrapper<WeCustomer>()
.eq(WeCustomer::getExternalUserid,message.getExternalUserId()) .eq(WeCustomer::getExternalUserid,customerInfo.getExternalUserID())
.eq(WeCustomer::getFirstUserId,message.getUserId())); .eq(WeCustomer::getFirstUserId,customerInfo.getUserID()));
weSensitiveActHit.setOperateTargetId(weCustomer.getFirstUserId()); weSensitiveActHit.setOperateTargetId(weCustomer.getFirstUserId());
weSensitiveActHit.setOperateTarget(weCustomer.getCustomerName()); weSensitiveActHit.setOperateTarget(weCustomer.getCustomerName());
......
...@@ -5,13 +5,20 @@ import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper; ...@@ -5,13 +5,20 @@ import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper;
import com.linkwechat.common.constant.WeConstans; import com.linkwechat.common.constant.WeConstans;
import com.linkwechat.common.core.domain.entity.WeCorpAccount; import com.linkwechat.common.core.domain.entity.WeCorpAccount;
import com.linkwechat.common.enums.MessageType; import com.linkwechat.common.enums.MessageType;
import com.linkwechat.wecom.domain.callback.WeBackBaseVo;
import com.linkwechat.wecom.domain.callback.WeBackCustomerVo;
import com.linkwechat.wecom.client.WeMessagePushClient; import com.linkwechat.wecom.client.WeMessagePushClient;
import com.linkwechat.wecom.domain.*; import com.linkwechat.wecom.domain.WeCustomer;
import com.linkwechat.wecom.domain.WeSensitiveAct;
import com.linkwechat.wecom.domain.WeSensitiveActHit;
import com.linkwechat.wecom.domain.WeUser;
import com.linkwechat.wecom.domain.dto.WeMessagePushDto; import com.linkwechat.wecom.domain.dto.WeMessagePushDto;
import com.linkwechat.wecom.domain.dto.message.TextMessageDto; import com.linkwechat.wecom.domain.dto.message.TextMessageDto;
import com.linkwechat.wecom.domain.vo.WxCpXmlMessageVO;
import com.linkwechat.wecom.factory.WeEventStrategy; import com.linkwechat.wecom.factory.WeEventStrategy;
import com.linkwechat.wecom.service.*; import com.linkwechat.wecom.service.IWeCorpAccountService;
import com.linkwechat.wecom.service.IWeCustomerService;
import com.linkwechat.wecom.service.IWeSensitiveActHitService;
import com.linkwechat.wecom.service.IWeUserService;
import lombok.extern.slf4j.Slf4j; import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.factory.annotation.Autowired; import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Component; import org.springframework.stereotype.Component;
...@@ -39,27 +46,28 @@ public class WeCallBackDelFollowUserImpl extends WeEventStrategy { ...@@ -39,27 +46,28 @@ public class WeCallBackDelFollowUserImpl extends WeEventStrategy {
private IWeUserService weUserService; private IWeUserService weUserService;
@Override @Override
public void eventHandle(WxCpXmlMessageVO message) { public void eventHandle(WeBackBaseVo message) {
WeBackCustomerVo customerInfo = (WeBackCustomerVo) message;
try { try {
if (message.getUserId() != null && message.getExternalUserId() != null) { if (customerInfo.getUserID() != null && customerInfo.getExternalUserID() != null) {
if(weCustomerService.remove(new LambdaQueryWrapper<WeCustomer>() if(weCustomerService.remove(new LambdaQueryWrapper<WeCustomer>()
.eq(WeCustomer::getExternalUserid,message.getExternalUserId()) .eq(WeCustomer::getExternalUserid,customerInfo.getExternalUserID())
.eq(WeCustomer::getFirstUserId,message.getUserId()))){ .eq(WeCustomer::getFirstUserId,customerInfo.getUserID()))){
WeCorpAccount validWeCorpAccount = weCorpAccountService.findValidWeCorpAccount(); WeCorpAccount validWeCorpAccount = weCorpAccountService.findValidWeCorpAccount();
Optional.ofNullable(validWeCorpAccount).ifPresent(weCorpAccount -> { Optional.ofNullable(validWeCorpAccount).ifPresent(weCorpAccount -> {
String customerChurnNoticeSwitch = weCorpAccount.getCustomerChurnNoticeSwitch(); String customerChurnNoticeSwitch = weCorpAccount.getCustomerChurnNoticeSwitch();
if (WeConstans.DEL_FOLLOW_USER_SWITCH_OPEN.equals(customerChurnNoticeSwitch)) { if (WeConstans.DEL_FOLLOW_USER_SWITCH_OPEN.equals(customerChurnNoticeSwitch)) {
WeCustomer weCustomer = weCustomerService.getOne(new LambdaQueryWrapper<WeCustomer>().eq(WeCustomer::getFirstUserId,message.getUserId()) WeCustomer weCustomer = weCustomerService.getOne(new LambdaQueryWrapper<WeCustomer>().eq(WeCustomer::getFirstUserId,customerInfo.getUserID())
.eq(WeCustomer::getExternalUserid,message.getExternalUserId())); .eq(WeCustomer::getExternalUserid,customerInfo.getExternalUserID()));
String content = "您已经被客户@" + weCustomer.getCustomerName() + "删除!"; String content = "您已经被客户@" + weCustomer.getCustomerName() + "删除!";
TextMessageDto textMessageDto = new TextMessageDto(); TextMessageDto textMessageDto = new TextMessageDto();
textMessageDto.setContent(content); textMessageDto.setContent(content);
WeMessagePushDto weMessagePushDto = new WeMessagePushDto(); WeMessagePushDto weMessagePushDto = new WeMessagePushDto();
weMessagePushDto.setMsgtype(MessageType.TEXT.getMessageType()); weMessagePushDto.setMsgtype(MessageType.TEXT.getMessageType());
weMessagePushDto.setTouser(message.getUserId()); weMessagePushDto.setTouser(customerInfo.getUserID());
weMessagePushDto.setText(textMessageDto); weMessagePushDto.setText(textMessageDto);
Optional.ofNullable(validWeCorpAccount).map(WeCorpAccount::getAgentId).ifPresent(agentId -> { Optional.ofNullable(validWeCorpAccount).map(WeCorpAccount::getAgentId).ifPresent(agentId -> {
...@@ -76,7 +84,7 @@ public class WeCallBackDelFollowUserImpl extends WeEventStrategy { ...@@ -76,7 +84,7 @@ public class WeCallBackDelFollowUserImpl extends WeEventStrategy {
weSensitiveActHit.setSensitiveAct(weSensitiveAct.getActName()); weSensitiveActHit.setSensitiveAct(weSensitiveAct.getActName());
weSensitiveActHit.setCreateTime(new Date(message.getCreateTime())); weSensitiveActHit.setCreateTime(new Date(message.getCreateTime()));
weSensitiveActHit.setCreateBy("admin"); weSensitiveActHit.setCreateBy("admin");
WeUser user = weUserService.getById(message.getUserId()); WeUser user = weUserService.getById(customerInfo.getUserID());
weSensitiveActHit.setOperatorId(weCustomer.getFirstUserId()); weSensitiveActHit.setOperatorId(weCustomer.getFirstUserId());
weSensitiveActHit.setOperator(weCustomer.getCustomerName()); weSensitiveActHit.setOperator(weCustomer.getCustomerName());
weSensitiveActHit.setOperateTargetId(user.getUserId()); weSensitiveActHit.setOperateTargetId(user.getUserId());
......
package com.linkwechat.wecom.factory.impl.customer; package com.linkwechat.wecom.factory.impl.customer;
import com.linkwechat.wecom.domain.vo.WxCpXmlMessageVO; import com.linkwechat.wecom.domain.callback.WeBackBaseVo;
import com.linkwechat.wecom.domain.callback.WeBackCustomerVo;
import com.linkwechat.wecom.factory.WeEventStrategy; import com.linkwechat.wecom.factory.WeEventStrategy;
import com.linkwechat.wecom.service.IWeCustomerService; import com.linkwechat.wecom.service.IWeCustomerService;
import lombok.extern.slf4j.Slf4j; import lombok.extern.slf4j.Slf4j;
...@@ -19,9 +20,10 @@ public class WeCallBackEditExternalContactImpl extends WeEventStrategy { ...@@ -19,9 +20,10 @@ public class WeCallBackEditExternalContactImpl extends WeEventStrategy {
private IWeCustomerService weCustomerService; private IWeCustomerService weCustomerService;
@Override @Override
public void eventHandle(WxCpXmlMessageVO message) { public void eventHandle(WeBackBaseVo message) {
if (message.getExternalUserId() != null) { WeBackCustomerVo customerInfo = (WeBackCustomerVo) message;
weCustomerService.getCustomersInfoAndSynchWeCustomer(message.getExternalUserId(),message.getUserId()); if (customerInfo.getExternalUserID() != null) {
weCustomerService.getCustomersInfoAndSynchWeCustomer(customerInfo.getExternalUserID(),customerInfo.getUserID());
} }
} }
} }
package com.linkwechat.wecom.factory.impl.customer; package com.linkwechat.wecom.factory.impl.customer;
import com.linkwechat.wecom.domain.vo.WxCpXmlMessageVO; import com.linkwechat.wecom.domain.callback.WeBackBaseVo;
import com.linkwechat.wecom.domain.callback.WeBackCustomerVo;
import com.linkwechat.wecom.factory.WeEventStrategy; import com.linkwechat.wecom.factory.WeEventStrategy;
import com.linkwechat.wecom.service.IWeCustomerService; import com.linkwechat.wecom.service.IWeCustomerService;
import lombok.extern.slf4j.Slf4j; import lombok.extern.slf4j.Slf4j;
...@@ -20,9 +21,10 @@ public class WeCallBackMsgAuditApprovedImpl extends WeEventStrategy { ...@@ -20,9 +21,10 @@ public class WeCallBackMsgAuditApprovedImpl extends WeEventStrategy {
@Override @Override
public void eventHandle(WxCpXmlMessageVO message) { public void eventHandle(WeBackBaseVo message) {
String userId = message.getUserId(); WeBackCustomerVo customerInfo = (WeBackCustomerVo) message;
String externalUserId = message.getExternalUserId(); String userId = customerInfo.getUserID();
String externalUserId = customerInfo.getExternalUserID();
weCustomerService.updateCustomerChatStatus(externalUserId); weCustomerService.updateCustomerChatStatus(externalUserId);
} }
} }
\ No newline at end of file \ No newline at end of file
...@@ -2,8 +2,9 @@ package com.linkwechat.wecom.factory.impl.customer; ...@@ -2,8 +2,9 @@ package com.linkwechat.wecom.factory.impl.customer;
import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper; import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper;
import com.linkwechat.common.enums.TransferFailReason; import com.linkwechat.common.enums.TransferFailReason;
import com.linkwechat.wecom.domain.callback.WeBackBaseVo;
import com.linkwechat.wecom.domain.callback.WeBackCustomerVo;
import com.linkwechat.wecom.domain.WeAllocateCustomer; import com.linkwechat.wecom.domain.WeAllocateCustomer;
import com.linkwechat.wecom.domain.vo.WxCpXmlMessageVO;
import com.linkwechat.wecom.factory.WeEventStrategy; import com.linkwechat.wecom.factory.WeEventStrategy;
import com.linkwechat.wecom.service.IWeAllocateCustomerService; import com.linkwechat.wecom.service.IWeAllocateCustomerService;
import lombok.extern.slf4j.Slf4j; import lombok.extern.slf4j.Slf4j;
...@@ -23,10 +24,11 @@ public class WeCallbackTransferFailImpl extends WeEventStrategy { ...@@ -23,10 +24,11 @@ public class WeCallbackTransferFailImpl extends WeEventStrategy {
private IWeAllocateCustomerService iWeAllocateCustomerService; private IWeAllocateCustomerService iWeAllocateCustomerService;
@Override @Override
public void eventHandle(WxCpXmlMessageVO message) { public void eventHandle(WeBackBaseVo message) {
String userId = message.getUserId(); WeBackCustomerVo customerInfo = (WeBackCustomerVo) message;
String externalUserId = message.getExternalUserId(); String userId = customerInfo.getUserID();
String failReason = message.getFailReason(); String externalUserId = customerInfo.getExternalUserID();
String failReason = customerInfo.getFailReason();
WeAllocateCustomer weAllocateCustomer = WeAllocateCustomer.builder().failReason(TransferFailReason.getReason(failReason)) WeAllocateCustomer weAllocateCustomer = WeAllocateCustomer.builder().failReason(TransferFailReason.getReason(failReason))
.status(TransferFailReason.getNum(failReason)).build(); .status(TransferFailReason.getNum(failReason)).build();
iWeAllocateCustomerService.update(weAllocateCustomer,new LambdaQueryWrapper<WeAllocateCustomer>().eq(WeAllocateCustomer::getTakeoverUserid,userId) iWeAllocateCustomerService.update(weAllocateCustomer,new LambdaQueryWrapper<WeAllocateCustomer>().eq(WeAllocateCustomer::getTakeoverUserid,userId)
......
package com.linkwechat.wecom.factory.impl.customergroup; package com.linkwechat.wecom.factory.impl.customergroup;
import com.linkwechat.wecom.domain.vo.WxCpXmlMessageVO; import com.linkwechat.wecom.domain.callback.WeBackBaseVo;
import com.linkwechat.wecom.domain.callback.WeBackCustomerGroupVo;
import com.linkwechat.wecom.factory.WeEventStrategy; import com.linkwechat.wecom.factory.WeEventStrategy;
import com.linkwechat.wecom.service.IWeGroupService; import com.linkwechat.wecom.service.IWeGroupService;
import lombok.extern.slf4j.Slf4j; import lombok.extern.slf4j.Slf4j;
...@@ -20,12 +21,13 @@ public class WeCallBackCreateGroupImpl extends WeEventStrategy { ...@@ -20,12 +21,13 @@ public class WeCallBackCreateGroupImpl extends WeEventStrategy {
private IWeGroupService weGroupService; private IWeGroupService weGroupService;
@Override @Override
public void eventHandle(WxCpXmlMessageVO message) { public void eventHandle(WeBackBaseVo message) {
WeBackCustomerGroupVo customerGroupInfo = (WeBackCustomerGroupVo) message;
try { try {
weGroupService.createWeGroup(message.getChatId()); weGroupService.createWeGroup(customerGroupInfo.getChatId());
} catch (Exception e) { } catch (Exception e) {
e.printStackTrace(); e.printStackTrace();
log.error("create>>>>>>>>>param:{},ex:{}",message.getChatId(),e); log.error("create>>>>>>>>>param:{},ex:{}",customerGroupInfo.getChatId(),e);
} }
} }
} }
package com.linkwechat.wecom.factory.impl.customergroup; package com.linkwechat.wecom.factory.impl.customergroup;
import com.linkwechat.wecom.domain.vo.WxCpXmlMessageVO; import com.linkwechat.wecom.domain.callback.WeBackBaseVo;
import com.linkwechat.wecom.domain.callback.WeBackCustomerGroupVo;
import com.linkwechat.wecom.factory.WeEventStrategy; import com.linkwechat.wecom.factory.WeEventStrategy;
import com.linkwechat.wecom.service.IWeGroupService; import com.linkwechat.wecom.service.IWeGroupService;
import lombok.extern.slf4j.Slf4j; import lombok.extern.slf4j.Slf4j;
...@@ -20,12 +21,13 @@ public class WeCallBackDismissImpl extends WeEventStrategy { ...@@ -20,12 +21,13 @@ public class WeCallBackDismissImpl extends WeEventStrategy {
private IWeGroupService weGroupService; private IWeGroupService weGroupService;
@Override @Override
public void eventHandle(WxCpXmlMessageVO message) { public void eventHandle(WeBackBaseVo message) {
WeBackCustomerGroupVo customerGroupInfo = (WeBackCustomerGroupVo) message;
try { try {
weGroupService.deleteWeGroup(message.getChatId()); weGroupService.deleteWeGroup(customerGroupInfo.getChatId());
} catch (Exception e) { } catch (Exception e) {
e.printStackTrace(); e.printStackTrace();
log.error("dismiss>>>>>>>>>param:{},ex:{}",message.getChatId(),e); log.error("dismiss>>>>>>>>>param:{},ex:{}",customerGroupInfo.getChatId(),e);
} }
} }
} }
...@@ -3,8 +3,9 @@ package com.linkwechat.wecom.factory.impl.customergroup; ...@@ -3,8 +3,9 @@ package com.linkwechat.wecom.factory.impl.customergroup;
import cn.hutool.core.collection.CollectionUtil; import cn.hutool.core.collection.CollectionUtil;
import cn.hutool.core.thread.ThreadUtil; import cn.hutool.core.thread.ThreadUtil;
import com.linkwechat.common.enums.CallbackEventUpdateDetail; import com.linkwechat.common.enums.CallbackEventUpdateDetail;
import com.linkwechat.wecom.domain.callback.WeBackBaseVo;
import com.linkwechat.wecom.domain.callback.WeBackCustomerGroupVo;
import com.linkwechat.wecom.domain.*; import com.linkwechat.wecom.domain.*;
import com.linkwechat.wecom.domain.vo.WxCpXmlMessageVO;
import com.linkwechat.wecom.factory.WeEventStrategy; import com.linkwechat.wecom.factory.WeEventStrategy;
import com.linkwechat.wecom.service.*; import com.linkwechat.wecom.service.*;
import lombok.extern.slf4j.Slf4j; import lombok.extern.slf4j.Slf4j;
...@@ -41,20 +42,21 @@ public class WeCallBackUpdateGroupImpl extends WeEventStrategy { ...@@ -41,20 +42,21 @@ public class WeCallBackUpdateGroupImpl extends WeEventStrategy {
private IWeGroupMemberService groupMemberService; private IWeGroupMemberService groupMemberService;
@Override @Override
public void eventHandle(WxCpXmlMessageVO message) { public void eventHandle(WeBackBaseVo message) {
WeBackCustomerGroupVo customerGroupInfo = (WeBackCustomerGroupVo) message;
try { try {
weGroupService.updateWeGroup(message.getChatId()); weGroupService.updateWeGroup(customerGroupInfo.getChatId());
String updateDetail = message.getUpdateDetail(); String updateDetail = customerGroupInfo.getUpdateDetail();
if (updateDetail.equals(CallbackEventUpdateDetail.ADD_MEMBER.getType())) { if (updateDetail.equals(CallbackEventUpdateDetail.ADD_MEMBER.getType())) {
// 添加成员,该群的实际群活码扫码次数需要加1 // 添加成员,该群的实际群活码扫码次数需要加1
groupCodeActualService.updateScanTimesByChatId(message.getChatId()); groupCodeActualService.updateScanTimesByChatId(customerGroupInfo.getChatId());
ThreadUtil.execAsync(() ->{ ThreadUtil.execAsync(() ->{
groupFissionEnterCheck(message.getChatId()); groupFissionEnterCheck(customerGroupInfo.getChatId());
}); });
} }
} catch (Exception e) { } catch (Exception e) {
e.printStackTrace(); e.printStackTrace();
log.error("update>>>>>>>>>param:{},ex:{}",message.getChatId(),e); log.error("update>>>>>>>>>param:{},ex:{}",customerGroupInfo.getChatId(),e);
} }
} }
......
package com.linkwechat.wecom.factory.impl.party; package com.linkwechat.wecom.factory.impl.party;
import com.linkwechat.wecom.domain.WeDepartment; import com.linkwechat.wecom.domain.callback.WeBackBaseVo;
import com.linkwechat.wecom.domain.vo.WxCpXmlMessageVO; import com.linkwechat.wecom.domain.callback.WeBackDeptVo;
import com.linkwechat.wecom.factory.WeEventStrategy; import com.linkwechat.wecom.factory.WeEventStrategy;
import com.linkwechat.wecom.service.IWeDepartmentService; import com.linkwechat.wecom.service.IWeDepartmentService;
import lombok.extern.slf4j.Slf4j; import lombok.extern.slf4j.Slf4j;
...@@ -20,9 +20,10 @@ public class WeCallBackCreatePartyImpl extends WeEventStrategy { ...@@ -20,9 +20,10 @@ public class WeCallBackCreatePartyImpl extends WeEventStrategy {
private IWeDepartmentService weDepartmentService; private IWeDepartmentService weDepartmentService;
@Override @Override
public void eventHandle(WxCpXmlMessageVO message) { public void eventHandle(WeBackBaseVo message) {
WeBackDeptVo deptInfo = (WeBackDeptVo) message;
try { try {
weDepartmentService.insert2Data(setWeDepartMent(message)); weDepartmentService.insert2Data(setWeDepartMent(deptInfo));
} catch (Exception e) { } catch (Exception e) {
e.printStackTrace(); e.printStackTrace();
log.error(e.getMessage()); log.error(e.getMessage());
......
package com.linkwechat.wecom.factory.impl.party; package com.linkwechat.wecom.factory.impl.party;
import com.linkwechat.wecom.domain.vo.WxCpXmlMessageVO; import com.linkwechat.wecom.domain.callback.WeBackBaseVo;
import com.linkwechat.wecom.domain.callback.WeBackDeptVo;
import com.linkwechat.wecom.factory.WeEventStrategy; import com.linkwechat.wecom.factory.WeEventStrategy;
import com.linkwechat.wecom.service.IWeDepartmentService; import com.linkwechat.wecom.service.IWeDepartmentService;
import lombok.extern.slf4j.Slf4j; import lombok.extern.slf4j.Slf4j;
...@@ -19,9 +20,10 @@ public class WeCallBackDeletePartyImpl extends WeEventStrategy { ...@@ -19,9 +20,10 @@ public class WeCallBackDeletePartyImpl extends WeEventStrategy {
private IWeDepartmentService weDepartmentService; private IWeDepartmentService weDepartmentService;
@Override @Override
public void eventHandle(WxCpXmlMessageVO message) { public void eventHandle(WeBackBaseVo message) {
WeBackDeptVo deptInfo = (WeBackDeptVo) message;
try { try {
weDepartmentService.removeById(message.getId()); weDepartmentService.removeById(deptInfo.getId());
} catch (Exception e) { } catch (Exception e) {
e.printStackTrace(); e.printStackTrace();
log.error(e.getMessage()); log.error(e.getMessage());
......
package com.linkwechat.wecom.factory.impl.party; package com.linkwechat.wecom.factory.impl.party;
import com.linkwechat.wecom.domain.WeDepartment; import com.linkwechat.wecom.domain.callback.WeBackBaseVo;
import com.linkwechat.wecom.domain.vo.WxCpXmlMessageVO; import com.linkwechat.wecom.domain.callback.WeBackDeptVo;
import com.linkwechat.wecom.factory.WeEventStrategy; import com.linkwechat.wecom.factory.WeEventStrategy;
import com.linkwechat.wecom.service.IWeDepartmentService; import com.linkwechat.wecom.service.IWeDepartmentService;
import lombok.extern.slf4j.Slf4j; import lombok.extern.slf4j.Slf4j;
...@@ -20,9 +20,10 @@ public class WeCallBackUpdatePartyImpl extends WeEventStrategy { ...@@ -20,9 +20,10 @@ public class WeCallBackUpdatePartyImpl extends WeEventStrategy {
private IWeDepartmentService weDepartmentService; private IWeDepartmentService weDepartmentService;
@Override @Override
public void eventHandle(WxCpXmlMessageVO message) { public void eventHandle(WeBackBaseVo message) {
WeBackDeptVo deptInfo = (WeBackDeptVo) message;
try { try {
weDepartmentService.updateById(setWeDepartMent(message)); weDepartmentService.updateById(setWeDepartMent(deptInfo));
} catch (Exception e) { } catch (Exception e) {
e.printStackTrace(); e.printStackTrace();
log.error(e.getMessage()); log.error(e.getMessage());
......
package com.linkwechat.wecom.factory.impl.tag; package com.linkwechat.wecom.factory.impl.tag;
import com.linkwechat.wecom.domain.vo.WxCpXmlMessageVO; import com.linkwechat.wecom.domain.callback.WeBackBaseVo;
import com.linkwechat.wecom.domain.callback.WeBackCustomerTagVo;
import com.linkwechat.wecom.factory.WeEventStrategy; import com.linkwechat.wecom.factory.WeEventStrategy;
import com.linkwechat.wecom.service.IWeTagGroupService; import com.linkwechat.wecom.service.IWeTagGroupService;
import com.linkwechat.wecom.service.IWeTagService; import com.linkwechat.wecom.service.IWeTagService;
...@@ -22,21 +23,22 @@ public class WeCallBackCreateCustomerTagImpl extends WeEventStrategy { ...@@ -22,21 +23,22 @@ public class WeCallBackCreateCustomerTagImpl extends WeEventStrategy {
private IWeTagService weTagService; private IWeTagService weTagService;
@Override @Override
public void eventHandle(WxCpXmlMessageVO message) { public void eventHandle(WeBackBaseVo message) {
WeBackCustomerTagVo customerTagInfo = (WeBackCustomerTagVo) message;
try { try {
switch (message.getTagType()){ switch (customerTagInfo.getTagType()){
case tagGroup: case tagGroup:
weTagGroupService.createTagGroup(message.getId()); weTagGroupService.createTagGroup(customerTagInfo.getId());
break; break;
case tag: case tag:
weTagService.creatTag(message.getId()); weTagService.creatTag(customerTagInfo.getId());
break; break;
default: default:
break; break;
} }
} catch (Exception e) { } catch (Exception e) {
e.printStackTrace(); e.printStackTrace();
log.error("createCustomerTag>>>>>>>>>param:{},ex:{}",message.getId(),e); log.error("createCustomerTag>>>>>>>>>param:{},ex:{}",customerTagInfo.getId(),e);
} }
} }
} }
package com.linkwechat.wecom.factory.impl.tag; package com.linkwechat.wecom.factory.impl.tag;
import com.linkwechat.wecom.domain.vo.WxCpXmlMessageVO; import com.linkwechat.wecom.domain.callback.WeBackBaseVo;
import com.linkwechat.wecom.domain.callback.WeBackCustomerTagVo;
import com.linkwechat.wecom.factory.WeEventStrategy; import com.linkwechat.wecom.factory.WeEventStrategy;
import com.linkwechat.wecom.service.IWeTagGroupService; import com.linkwechat.wecom.service.IWeTagGroupService;
import com.linkwechat.wecom.service.IWeTagService; import com.linkwechat.wecom.service.IWeTagService;
...@@ -21,21 +22,22 @@ public class WeCallBackDeleteCustomerTagImpl extends WeEventStrategy { ...@@ -21,21 +22,22 @@ public class WeCallBackDeleteCustomerTagImpl extends WeEventStrategy {
@Autowired @Autowired
private IWeTagService weTagService; private IWeTagService weTagService;
@Override @Override
public void eventHandle(WxCpXmlMessageVO message) { public void eventHandle(WeBackBaseVo message) {
WeBackCustomerTagVo customerTagInfo = (WeBackCustomerTagVo) message;
try { try {
switch (message.getTagType()){ switch (customerTagInfo.getTagType()){
case tagGroup: case tagGroup:
weTagGroupService.deleteTagGroup(message.getId()); weTagGroupService.deleteTagGroup(customerTagInfo.getId());
break; break;
case tag: case tag:
weTagService.deleteTag(message.getId()); weTagService.deleteTag(customerTagInfo.getId());
break; break;
default: default:
break; break;
} }
} catch (Exception e) { } catch (Exception e) {
e.printStackTrace(); e.printStackTrace();
log.error("deleteCustomerTag>>>>>>>>>param:{},ex:{}",message.getId(),e); log.error("deleteCustomerTag>>>>>>>>>param:{},ex:{}",customerTagInfo.getId(),e);
} }
} }
} }
package com.linkwechat.wecom.factory.impl.tag; package com.linkwechat.wecom.factory.impl.tag;
import com.linkwechat.wecom.domain.vo.WxCpXmlMessageVO; import com.linkwechat.wecom.domain.callback.WeBackBaseVo;
import com.linkwechat.wecom.domain.callback.WeBackCustomerTagVo;
import com.linkwechat.wecom.factory.WeEventStrategy; import com.linkwechat.wecom.factory.WeEventStrategy;
import com.linkwechat.wecom.service.IWeTagGroupService; import com.linkwechat.wecom.service.IWeTagGroupService;
import com.linkwechat.wecom.service.IWeTagService; import com.linkwechat.wecom.service.IWeTagService;
...@@ -21,21 +22,22 @@ public class WeCallBackUpdateCustomerTagImpl extends WeEventStrategy { ...@@ -21,21 +22,22 @@ public class WeCallBackUpdateCustomerTagImpl extends WeEventStrategy {
@Autowired @Autowired
private IWeTagService weTagService; private IWeTagService weTagService;
@Override @Override
public void eventHandle(WxCpXmlMessageVO message) { public void eventHandle(WeBackBaseVo message) {
WeBackCustomerTagVo customerTagInfo = (WeBackCustomerTagVo) message;
try { try {
switch (message.getTagType()){ switch (customerTagInfo.getTagType()){
case tagGroup: case tagGroup:
weTagGroupService.updateTagGroup(message.getId()); weTagGroupService.updateTagGroup(customerTagInfo.getId());
break; break;
case tag: case tag:
weTagService.updateTag(message.getId()); weTagService.updateTag(customerTagInfo.getId());
break; break;
default: default:
break; break;
} }
} catch (Exception e) { } catch (Exception e) {
e.printStackTrace(); e.printStackTrace();
log.error("updateCustomerTag>>>>>>>>>param:{},ex:{}",message.getId(),e); log.error("updateCustomerTag>>>>>>>>>param:{},ex:{}",customerTagInfo.getId(),e);
} }
} }
} }
...@@ -2,9 +2,10 @@ package com.linkwechat.wecom.factory.impl.tag; ...@@ -2,9 +2,10 @@ package com.linkwechat.wecom.factory.impl.tag;
import cn.hutool.core.collection.CollectionUtil; import cn.hutool.core.collection.CollectionUtil;
import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper; import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper;
import com.linkwechat.wecom.domain.callback.WeBackBaseVo;
import com.linkwechat.wecom.domain.callback.WeBackUserTagVo;
import com.linkwechat.wecom.domain.WeCustomer; import com.linkwechat.wecom.domain.WeCustomer;
import com.linkwechat.wecom.domain.WeFlowerCustomerTagRel; import com.linkwechat.wecom.domain.WeFlowerCustomerTagRel;
import com.linkwechat.wecom.domain.vo.WxCpXmlMessageVO;
import com.linkwechat.wecom.factory.WeEventStrategy; import com.linkwechat.wecom.factory.WeEventStrategy;
import com.linkwechat.wecom.service.IWeCustomerService; import com.linkwechat.wecom.service.IWeCustomerService;
import com.linkwechat.wecom.service.IWeFlowerCustomerTagRelService; import com.linkwechat.wecom.service.IWeFlowerCustomerTagRelService;
...@@ -31,11 +32,12 @@ public class WeCallBackUpdateUserTagImpl extends WeEventStrategy { ...@@ -31,11 +32,12 @@ public class WeCallBackUpdateUserTagImpl extends WeEventStrategy {
@Override @Override
public void eventHandle(WxCpXmlMessageVO message) { public void eventHandle(WeBackBaseVo message) {
WeBackUserTagVo userTagInfo = (WeBackUserTagVo) message;
try { try {
String tagId = message.getTagId(); String tagId = userTagInfo.getTagId();
//标签中新增的成员userid列表,用逗号分隔 //标签中新增的成员userid列表,用逗号分隔
List<String> addUserItemsList = Arrays.stream(Optional.ofNullable(message.getAddUserItems()) List<String> addUserItemsList = Arrays.stream(Optional.ofNullable(userTagInfo.getAddUserItems())
.orElse("").split(",")).collect(Collectors.toList()); .orElse("").split(",")).collect(Collectors.toList());
if(CollectionUtil.isNotEmpty(addUserItemsList)){ if(CollectionUtil.isNotEmpty(addUserItemsList)){
...@@ -61,7 +63,7 @@ public class WeCallBackUpdateUserTagImpl extends WeEventStrategy { ...@@ -61,7 +63,7 @@ public class WeCallBackUpdateUserTagImpl extends WeEventStrategy {
//标签中删除的成员userid列表,用逗号分隔 //标签中删除的成员userid列表,用逗号分隔
List<String> delUserItemsList = Arrays.stream(Optional.ofNullable(message.getDelUserItems()) List<String> delUserItemsList = Arrays.stream(Optional.ofNullable(userTagInfo.getDelUserItems())
.orElse("").split(",")).collect(Collectors.toList()); .orElse("").split(",")).collect(Collectors.toList());
if(CollectionUtil.isNotEmpty(delUserItemsList)){ if(CollectionUtil.isNotEmpty(delUserItemsList)){
......
package com.linkwechat.wecom.factory.impl.user; package com.linkwechat.wecom.factory.impl.user;
import com.linkwechat.wecom.domain.vo.WxCpXmlMessageVO; import com.linkwechat.wecom.domain.callback.WeBackBaseVo;
import com.linkwechat.wecom.domain.callback.WeBackUserVo;
import com.linkwechat.wecom.factory.WeEventStrategy; import com.linkwechat.wecom.factory.WeEventStrategy;
import com.linkwechat.wecom.service.IWeUserService; import com.linkwechat.wecom.service.IWeUserService;
import lombok.extern.slf4j.Slf4j; import lombok.extern.slf4j.Slf4j;
...@@ -19,9 +20,10 @@ public class WeCallBackCreateUserImpl extends WeEventStrategy { ...@@ -19,9 +20,10 @@ public class WeCallBackCreateUserImpl extends WeEventStrategy {
private IWeUserService weUserService; private IWeUserService weUserService;
@Override @Override
public void eventHandle(WxCpXmlMessageVO message) { public void eventHandle(WeBackBaseVo message) {
WeBackUserVo userInfo = (WeBackUserVo) message;
try { try {
weUserService.insert2Data(setWeUserData(message)); weUserService.insert2Data(setWeUserData(userInfo));
} catch (Exception e) { } catch (Exception e) {
e.printStackTrace(); e.printStackTrace();
log.error(e.getMessage()); log.error(e.getMessage());
......
package com.linkwechat.wecom.factory.impl.user; package com.linkwechat.wecom.factory.impl.user;
import com.linkwechat.common.utils.StringUtils; import com.linkwechat.wecom.domain.callback.WeBackBaseVo;
import com.linkwechat.wecom.domain.vo.WxCpXmlMessageVO; import com.linkwechat.wecom.domain.callback.WeBackUserVo;
import com.linkwechat.wecom.factory.WeEventStrategy; import com.linkwechat.wecom.factory.WeEventStrategy;
import com.linkwechat.wecom.service.IWeUserService; import com.linkwechat.wecom.service.IWeUserService;
import lombok.extern.slf4j.Slf4j; import lombok.extern.slf4j.Slf4j;
...@@ -20,9 +20,10 @@ public class WeCallBackDeleteUserImpl extends WeEventStrategy { ...@@ -20,9 +20,10 @@ public class WeCallBackDeleteUserImpl extends WeEventStrategy {
private IWeUserService weUserService; private IWeUserService weUserService;
@Override @Override
public void eventHandle(WxCpXmlMessageVO message) { public void eventHandle(WeBackBaseVo message) {
WeBackUserVo userInfo = (WeBackUserVo) message;
try { try {
weUserService.deleteUserNoToWeCom(message.getUserId()); weUserService.deleteUserNoToWeCom(userInfo.getUserID());
} catch (Exception e) { } catch (Exception e) {
e.printStackTrace(); e.printStackTrace();
log.error(e.getMessage()); log.error(e.getMessage());
......
package com.linkwechat.wecom.factory.impl.user; package com.linkwechat.wecom.factory.impl.user;
import com.linkwechat.wecom.domain.vo.WxCpXmlMessageVO; import com.linkwechat.wecom.domain.callback.WeBackBaseVo;
import com.linkwechat.wecom.domain.callback.WeBackUserVo;
import com.linkwechat.wecom.factory.WeEventStrategy; import com.linkwechat.wecom.factory.WeEventStrategy;
import com.linkwechat.wecom.service.IWeUserService; import com.linkwechat.wecom.service.IWeUserService;
import lombok.extern.slf4j.Slf4j; import lombok.extern.slf4j.Slf4j;
...@@ -19,9 +20,10 @@ public class WeCallBackUpdateUserImpl extends WeEventStrategy { ...@@ -19,9 +20,10 @@ public class WeCallBackUpdateUserImpl extends WeEventStrategy {
private IWeUserService weUserService; private IWeUserService weUserService;
@Override @Override
public void eventHandle(WxCpXmlMessageVO message) { public void eventHandle(WeBackBaseVo message) {
WeBackUserVo userInfo = (WeBackUserVo) message;
try { try {
weUserService.update2Data(setWeUserData(message)); weUserService.update2Data(setWeUserData(userInfo));
} catch (Exception e) { } catch (Exception e) {
e.printStackTrace(); e.printStackTrace();
log.error(e.getMessage()); log.error(e.getMessage());
......
...@@ -9,14 +9,7 @@ import com.linkwechat.common.core.domain.entity.WeCorpAccount; ...@@ -9,14 +9,7 @@ import com.linkwechat.common.core.domain.entity.WeCorpAccount;
* @author ruoyi * @author ruoyi
* @date 2020-08-24 * @date 2020-08-24
*/ */
public interface IWeCorpAccountService extends IService<WeCorpAccount> public interface IWeCorpAccountService extends IService<WeCorpAccount> {
{
/** /**
* 获取有效的企业id * 获取有效的企业id
* *
...@@ -24,11 +17,9 @@ public interface IWeCorpAccountService extends IService<WeCorpAccount> ...@@ -24,11 +17,9 @@ public interface IWeCorpAccountService extends IService<WeCorpAccount>
*/ */
WeCorpAccount findValidWeCorpAccount(); WeCorpAccount findValidWeCorpAccount();
/** /**
* 客户流失通知开关 * 客户流失通知开关
*
* @param status 开关状态 * @param status 开关状态
* @return * @return
*/ */
...@@ -39,6 +30,11 @@ public interface IWeCorpAccountService extends IService<WeCorpAccount> ...@@ -39,6 +30,11 @@ public interface IWeCorpAccountService extends IService<WeCorpAccount>
*/ */
String getCustomerChurnNoticeSwitch(); String getCustomerChurnNoticeSwitch();
/**
* 通过企业id查询配置信息
*
* @param corpId 企业id
* @return
*/
WeCorpAccount getCorpAccountByCorpId(String corpId);
} }
package com.linkwechat.wecom.service.callback;
import cn.hutool.core.util.XmlUtil;
import com.alibaba.fastjson.JSONObject;
import com.linkwechat.wecom.domain.callback.WeBackBaseVo;
import com.linkwechat.wecom.domain.callback.WeCallBackEvent;
import com.linkwechat.wecom.factory.WeCallBackEventFactory;
import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.context.ApplicationListener;
import org.springframework.scheduling.annotation.Async;
import org.springframework.stereotype.Service;
import java.util.HashMap;
import java.util.Map;
import java.util.concurrent.ConcurrentHashMap;
/**
* @author danmo
* @description 回调通知处理
* @date 2021/11/21 19:57
**/
@Service
@Slf4j
public class WeCallBackEventService implements ApplicationListener<WeCallBackEvent> {
@Autowired
private Map<String, WeCallBackEventFactory> weCallBackEventFactoryMap = new ConcurrentHashMap<>();
/**
* 企微回调事件类型路由
*/
private final Map<String, String> eventRoute = new HashMap<String, String>() {
{
//成员事件
put("change_contact", "weEventChangeContactImpl");
//异步任务完成通知
put("batch_job_result", "weEventBatchJobResultImpl");
//外部联系人事件
put("change_external_contact", "weEventChangeExternalContactImpl");
//客户群事件
put("change_external_chat", "weEventChangeExternalChatImpl");
//客户标签事件
put("change_external_tag", "weEventChangeExternalTagImpl");
}
};
@Override
@Async
public void onApplicationEvent(WeCallBackEvent weCallBackEvent) {
String message = weCallBackEvent.getMessage();
WeBackBaseVo weBackBaseVo = XmlUtil.xmlToBean(XmlUtil.parseXml(message).getFirstChild(), WeBackBaseVo.class);
log.info("回调通知处理:weBackBaseVo:{}", JSONObject.toJSONString(weBackBaseVo));
WeCallBackEventFactory factory = factory(weBackBaseVo.getEvent());
if(factory != null){
factory.eventHandle(message);
}
}
private WeCallBackEventFactory factory(String eventType) {
if (!eventRoute.containsKey(eventType)) {
return null;
}
String resolveClass = eventRoute.get(eventType);
if (!weCallBackEventFactoryMap.containsKey(resolveClass)) {
return null;
}
return weCallBackEventFactoryMap.get(resolveClass);
}
}
package com.linkwechat.wecom.service.event; package com.linkwechat.wecom.service.event;
import com.linkwechat.wecom.domain.callback.WeCallBackEvent;
import com.linkwechat.wecom.domain.query.WeCustomerWelcomeQuery; import com.linkwechat.wecom.domain.query.WeCustomerWelcomeQuery;
import lombok.extern.slf4j.Slf4j; import lombok.extern.slf4j.Slf4j;
import org.springframework.context.ApplicationEventPublisher; import org.springframework.context.ApplicationEventPublisher;
...@@ -22,6 +23,15 @@ public class WeEventPublisherService implements ApplicationEventPublisherAware { ...@@ -22,6 +23,15 @@ public class WeEventPublisherService implements ApplicationEventPublisherAware {
this.applicationEventPublisher = applicationEventPublisher; this.applicationEventPublisher = applicationEventPublisher;
} }
/**
* 回调事件推送
*/
public void register(String message) {
log.info("回调事件推送:message:{}",message);
applicationEventPublisher.publishEvent(new WeCallBackEvent(this,message));
}
/** /**
* 发布欢迎语事件 * 发布欢迎语事件
*/ */
......
...@@ -5,10 +5,14 @@ import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl; ...@@ -5,10 +5,14 @@ import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import com.linkwechat.common.constant.Constants; import com.linkwechat.common.constant.Constants;
import com.linkwechat.common.constant.WeConstans; import com.linkwechat.common.constant.WeConstans;
import com.linkwechat.common.core.domain.entity.WeCorpAccount; import com.linkwechat.common.core.domain.entity.WeCorpAccount;
import com.linkwechat.common.core.redis.RedisCache;
import com.linkwechat.common.utils.StringUtils;
import com.linkwechat.wecom.mapper.WeCorpAccountMapper; import com.linkwechat.wecom.mapper.WeCorpAccountMapper;
import com.linkwechat.wecom.service.IWeCorpAccountService; import com.linkwechat.wecom.service.IWeCorpAccountService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service; import org.springframework.stereotype.Service;
import java.util.Optional; import java.util.Optional;
import java.util.concurrent.TimeUnit;
/** /**
* 企业id相关配置Service业务层处理 * 企业id相关配置Service业务层处理
...@@ -19,12 +23,8 @@ import java.util.Optional; ...@@ -19,12 +23,8 @@ import java.util.Optional;
@Service @Service
public class WeCorpAccountServiceImpl extends ServiceImpl<WeCorpAccountMapper,WeCorpAccount> implements IWeCorpAccountService { public class WeCorpAccountServiceImpl extends ServiceImpl<WeCorpAccountMapper,WeCorpAccount> implements IWeCorpAccountService {
@Autowired
private RedisCache redisCache;
public WeCorpAccountServiceImpl(){
System.out.println("nihaoya");
}
/** /**
* 获取有效的企业id * 获取有效的企业id
...@@ -58,6 +58,27 @@ public class WeCorpAccountServiceImpl extends ServiceImpl<WeCorpAccountMapper,We ...@@ -58,6 +58,27 @@ public class WeCorpAccountServiceImpl extends ServiceImpl<WeCorpAccountMapper,We
return noticeSwitch; return noticeSwitch;
} }
/**
* 通过企业id查询配置信息 ** 修改或者删除配置时记得删除缓存 **
*
* @param corpId 企业id
* @return
*/
@Override
public WeCorpAccount getCorpAccountByCorpId(String corpId) {
String key = StringUtils.format(WeConstans.corpAccountKey,corpId);
WeCorpAccount corpAccount = redisCache.getCacheObject(key);
if(corpAccount == null){
WeCorpAccount weCorpAccount = this.getOne(new LambdaQueryWrapper<WeCorpAccount>()
.eq(WeCorpAccount::getCorpId,corpId)
.eq(WeCorpAccount::getDelFlag, Constants.NORMAL_CODE).last("limit 1"));
if(weCorpAccount != null){
redisCache.setCacheObject(key,weCorpAccount,2 * 60 * 60, TimeUnit.SECONDS);
corpAccount = weCorpAccount;
}
}
return corpAccount;
}
} }
Markdown is supported
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!