Commit 8d7ab65d by sunxiwang

客户流失提醒功能完善

1 parent 272e0a20
...@@ -83,8 +83,15 @@ public class WeCorpAccountController extends BaseController ...@@ -83,8 +83,15 @@ public class WeCorpAccountController extends BaseController
return toAjax(weCorpAccountService.startVailWeCorpAccount(corpId)); return toAjax(weCorpAccountService.startVailWeCorpAccount(corpId));
} }
/**
* 客户流失通知开关
*/
@PreAuthorize("@ss.hasPermi('wechat:corp:startCustomerChurnNoticeSwitch')")
@Log(title = "客户流失通知开关", businessType = BusinessType.UPDATE)
@PutMapping("/startCustomerChurnNoticeSwitch/{status}")
public AjaxResult startCustomerChurnNoticeSwitch(@PathVariable String status)
{
return toAjax(weCorpAccountService.startCustomerChurnNoticeSwitch(status));
}
} }
package com.linkwechat.common.constant; package com.linkwechat.common.constant;
import org.elasticsearch.common.xcontent.XContentBuilder;
import org.elasticsearch.common.xcontent.XContentFactory;
import java.io.IOException;
import java.util.HashMap; import java.util.HashMap;
import java.util.Map; import java.util.Map;
...@@ -200,6 +204,11 @@ public class WeConstans { ...@@ -200,6 +204,11 @@ public class WeConstans {
public static final Integer USE_SCOP_BUSINESSID_TYPE_ORG = 1; public static final Integer USE_SCOP_BUSINESSID_TYPE_ORG = 1;
/** /**
* 客户流失通知开关 0:关闭 1:开启
*/
public static final String DEL_FOLLOW_USER_SWITCH_CLOSE = "0";
public static final String DEL_FOLLOW_USER_SWITCH_OPEN = "1";
/**
* 企微回调事件类型路由 * 企微回调事件类型路由
*/ */
public final static Map<String, String> eventRoute = new HashMap<String, String>() { public final static Map<String, String> eventRoute = new HashMap<String, String>() {
...@@ -260,4 +269,38 @@ public class WeConstans { ...@@ -260,4 +269,38 @@ public class WeConstans {
} }
} }
public static XContentBuilder getFinanceTextMapping() throws IOException {
// 创建 会话文本Mapping
XContentBuilder xContentBuilder = XContentFactory.jsonBuilder()
.startObject()
.startObject("properties")
.startObject("msgid")
.field("type", "keyword")
.endObject()
.startObject("action")
.field("type", "keyword")
.endObject()
.startObject("from")
.field("type", "keyword")
.endObject()
.startObject("tolist")
.field("type", "text")
.endObject()
.startObject("roomid")
.field("type", "keyword")
.endObject()
.startObject("msgtime")
.field("type", "long")
.endObject()
.startObject("msgtype")
.field("type", "keyword")
.endObject()
.startObject("content")
.field("type", "text")
.endObject()
.endObject()
.endObject();
return xContentBuilder;
}
} }
...@@ -69,5 +69,6 @@ public class WeCorpAccount extends BaseEntity ...@@ -69,5 +69,6 @@ public class WeCorpAccount extends BaseEntity
@ApiModelProperty("企业微信扫码登陆回调地址") @ApiModelProperty("企业微信扫码登陆回调地址")
private String wxQrLoginRedirectUri; private String wxQrLoginRedirectUri;
@ApiModelProperty("客户流失通知开关 0:关闭 1:开启")
private String customerChurnNoticeSwitch = new String("0");
} }
package com.linkwechat.wecom.domain.dto; package com.linkwechat.wecom.domain.dto;
import com.linkwechat.wecom.domain.dto.message.ImageMessageDto;
import com.linkwechat.wecom.domain.dto.message.LinkMessageDto;
import com.linkwechat.wecom.domain.dto.message.MiniprogramMessageDto;
import com.linkwechat.wecom.domain.dto.message.TextMessageDto;
import lombok.Data; import lombok.Data;
import java.util.List; import java.util.List;
...@@ -9,19 +13,19 @@ import java.util.List; ...@@ -9,19 +13,19 @@ import java.util.List;
public class WeMessagePushDto { public class WeMessagePushDto {
/** /**
* 指定接收消息的成员,成员ID列表(多个接收者用‘|’分隔,最多支持1000个)。 * 指定接收消息的成员,成员ID列表(多个接收者用‘,’分隔,最多支持1000个)。
* 特殊情况:指定为”@all”,则向该企业应用的全部成员发送 * 特殊情况:指定为”@all”,则向该企业应用的全部成员发送
*/ */
private List<String> touser; private List<String> touser;
/** /**
* 指定接收消息的部门,部门ID列表,多个接收者用‘|’分隔,最多支持100个。 * 指定接收消息的部门,部门ID列表,多个接收者用‘,’分隔,最多支持100个。
* 当touser为”@all”时忽略本参数 * 当touser为”@all”时忽略本参数
*/ */
private List<String> toparty; private List<String> toparty;
/** /**
* 指定接收消息的标签,标签ID列表,多个接收者用‘|’分隔,最多支持100个。 * 指定接收消息的标签,标签ID列表,多个接收者用‘,’分隔,最多支持100个。
* 当touser为”@all”时忽略本参数 * 当touser为”@all”时忽略本参数
*/ */
private List<String> totag; private List<String> totag;
...@@ -61,5 +65,24 @@ public class WeMessagePushDto { ...@@ -61,5 +65,24 @@ public class WeMessagePushDto {
* 根据msgtype的值不同添加一个属性和对应的属性值 * 根据msgtype的值不同添加一个属性和对应的属性值
*/ */
/**
*文本消息
*/
private TextMessageDto text;
/**
* 图片消息
*/
private ImageMessageDto image;
/**
* 链接消息
*/
private LinkMessageDto link;
/**
* 小程序消息
*/
private MiniprogramMessageDto miniprogram;
} }
...@@ -2,31 +2,27 @@ package com.linkwechat.wecom.factory.impl; ...@@ -2,31 +2,27 @@ package com.linkwechat.wecom.factory.impl;
import com.alibaba.fastjson.JSONObject; import com.alibaba.fastjson.JSONObject;
import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper; import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper;
import com.linkwechat.common.constant.WeConstans;
import com.linkwechat.common.enums.MediaType; import com.linkwechat.common.enums.MediaType;
import com.linkwechat.common.enums.MessageType;
import com.linkwechat.common.utils.StringUtils; import com.linkwechat.common.utils.StringUtils;
import com.linkwechat.common.utils.Threads; import com.linkwechat.common.utils.Threads;
import com.linkwechat.wecom.domain.WeEmpleCodeTag; import com.linkwechat.wecom.client.WeMessagePushClient;
import com.linkwechat.wecom.domain.WeFlowerCustomerRel; import com.linkwechat.wecom.domain.*;
import com.linkwechat.wecom.domain.WeFlowerCustomerTagRel;
import com.linkwechat.wecom.domain.dto.WeEmpleCodeDto; 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.WeMessagePushDto;
import com.linkwechat.wecom.domain.dto.WeWelcomeMsg; import com.linkwechat.wecom.domain.dto.WeWelcomeMsg;
import com.linkwechat.wecom.domain.dto.message.TextMessageDto;
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.service.*; import com.linkwechat.wecom.service.*;
import lombok.extern.slf4j.Slf4j; import lombok.extern.slf4j.Slf4j;
import me.chanjar.weixin.cp.bean.external.msg.Image;
import me.chanjar.weixin.cp.bean.external.msg.Text;
import org.springframework.beans.factory.annotation.Autowired; import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.security.core.context.SecurityContext;
import org.springframework.security.core.context.SecurityContextHolder;
import org.springframework.stereotype.Service; import org.springframework.stereotype.Service;
import java.util.ArrayList; import java.util.*;
import java.util.Date; import java.util.stream.Collectors;
import java.util.List;
import java.util.Optional;
/** /**
* @author danmo * @author danmo
...@@ -48,6 +44,11 @@ public class WeEventChangeExternalContactImpl implements WeCallBackEventFactory ...@@ -48,6 +44,11 @@ public class WeEventChangeExternalContactImpl implements WeCallBackEventFactory
private IWeFlowerCustomerTagRelService weFlowerCustomerTagRelService; private IWeFlowerCustomerTagRelService weFlowerCustomerTagRelService;
@Autowired @Autowired
private IWeMaterialService weMaterialService; private IWeMaterialService weMaterialService;
@Autowired
private WeMessagePushClient weMessagePushClient;
@Autowired
private IWeCorpAccountService weCorpAccountService;
@Override @Override
public void eventHandle(WxCpXmlMessageVO message) { public void eventHandle(WxCpXmlMessageVO message) {
...@@ -88,9 +89,33 @@ public class WeEventChangeExternalContactImpl implements WeCallBackEventFactory ...@@ -88,9 +89,33 @@ public class WeEventChangeExternalContactImpl implements WeCallBackEventFactory
} }
private void delFollowUser(WxCpXmlMessageVO message) { private void delFollowUser(WxCpXmlMessageVO message) {
if (message.getUserId() != null && message.getExternalUserId() != null) { Threads.SINGLE_THREAD_POOL.execute(new Runnable() {
weFlowerCustomerRelService.deleteFollowUser(message.getUserId(), message.getExternalUserId()); @Override
} public void run() {
if (message.getUserId() != null && message.getExternalUserId() != null) {
weFlowerCustomerRelService.deleteFollowUser(message.getUserId(), message.getExternalUserId());
WeCorpAccount validWeCorpAccount = weCorpAccountService.findValidWeCorpAccount();
Optional.ofNullable(validWeCorpAccount).ifPresent(weCorpAccount -> {
String customerChurnNoticeSwitch = weCorpAccount.getCustomerChurnNoticeSwitch();
if (WeConstans.DEL_FOLLOW_USER_SWITCH_OPEN.equals(customerChurnNoticeSwitch)){
WeCustomer weCustomer = weCustomerService.getById(message.getExternalUserId());
String content = "您已经被客户@"+weCustomer.getName()+"删除!" ;
TextMessageDto textMessageDto = new TextMessageDto();
textMessageDto.setContent(content);
List<String> userIdList = Arrays.stream(message.getUserId().split(",")).collect(Collectors.toList());
WeMessagePushDto weMessagePushDto = new WeMessagePushDto();
weMessagePushDto.setMsgtype(MessageType.TEXT.getMessageType());
weMessagePushDto.setTouser(userIdList);
weMessagePushDto.setText(textMessageDto);
Optional.ofNullable(validWeCorpAccount).map(WeCorpAccount::getAgentId).ifPresent(agentId -> {
weMessagePushDto.setAgentid(Integer.valueOf(agentId));
});
weMessagePushClient.sendMessageToUser(weMessagePushDto);
}
});
}
}
});
} }
private void delExternalContact(WxCpXmlMessageVO message) { private void delExternalContact(WxCpXmlMessageVO message) {
......
...@@ -60,4 +60,10 @@ public interface IWeCorpAccountService ...@@ -60,4 +60,10 @@ public interface IWeCorpAccountService
*/ */
public int startVailWeCorpAccount(String corpId); public int startVailWeCorpAccount(String corpId);
/**
* 客户流失通知开关
* @param status 开关状态
* @return
*/
public int startCustomerChurnNoticeSwitch(String status);
} }
...@@ -95,7 +95,12 @@ public class WeCorpAccountServiceImpl implements IWeCorpAccountService { ...@@ -95,7 +95,12 @@ public class WeCorpAccountServiceImpl implements IWeCorpAccountService {
return weCorpAccountMapper.startVailWeCorpAccount(corpId); return weCorpAccountMapper.startVailWeCorpAccount(corpId);
} }
@Override
public int startCustomerChurnNoticeSwitch(String status) {
WeCorpAccount validWeCorpAccount = findValidWeCorpAccount();
validWeCorpAccount.setCustomerChurnNoticeSwitch(status);
return weCorpAccountMapper.updateWeCorpAccount(validWeCorpAccount);
}
} }
...@@ -18,10 +18,11 @@ PUBLIC "-//mybatis.org//DTD Mapper 3.0//EN" ...@@ -18,10 +18,11 @@ PUBLIC "-//mybatis.org//DTD Mapper 3.0//EN"
<result property="contactSecret" column="contact_secret" /> <result property="contactSecret" column="contact_secret" />
<result property="agentId" column="agent_id" /> <result property="agentId" column="agent_id" />
<result property="providerSecret" column="provider_secret" /> <result property="providerSecret" column="provider_secret" />
<result property="customerChurnNoticeSwitch" column="customer_churn_notice_switch" />
</resultMap> </resultMap>
<sql id="selectWeCorpAccountVo"> <sql id="selectWeCorpAccountVo">
select id,provider_secret,company_name, corp_id, corp_secret,agent_id ,status, del_flag, create_by, create_time, update_by, update_time,contact_secret from we_corp_account select id,provider_secret,company_name, corp_id, corp_secret,agent_id ,status, del_flag, create_by, create_time, update_by, update_time,contact_secret, customer_churn_notice_switch from we_corp_account
</sql> </sql>
<select id="selectWeCorpAccountList" parameterType="WeCorpAccount" resultMap="WeCorpAccountResult"> <select id="selectWeCorpAccountList" parameterType="WeCorpAccount" resultMap="WeCorpAccountResult">
...@@ -52,6 +53,7 @@ PUBLIC "-//mybatis.org//DTD Mapper 3.0//EN" ...@@ -52,6 +53,7 @@ PUBLIC "-//mybatis.org//DTD Mapper 3.0//EN"
<if test="updateBy != null">update_by,</if> <if test="updateBy != null">update_by,</if>
<if test="updateTime != null">update_time,</if> <if test="updateTime != null">update_time,</if>
<if test="contactSecret != null ">contact_secret,</if> <if test="contactSecret != null ">contact_secret,</if>
<if test="customerChurnNoticeSwitch != null ">customer_churn_notice_switch,</if>
</trim> </trim>
<trim prefix="values (" suffix=")" suffixOverrides=","> <trim prefix="values (" suffix=")" suffixOverrides=",">
<if test="companyName != null">#{companyName},</if> <if test="companyName != null">#{companyName},</if>
...@@ -64,6 +66,7 @@ PUBLIC "-//mybatis.org//DTD Mapper 3.0//EN" ...@@ -64,6 +66,7 @@ PUBLIC "-//mybatis.org//DTD Mapper 3.0//EN"
<if test="updateBy != null">#{updateBy},</if> <if test="updateBy != null">#{updateBy},</if>
<if test="updateTime != null">#{updateTime},</if> <if test="updateTime != null">#{updateTime},</if>
<if test="contactSecret != null ">#{contactSecret},</if> <if test="contactSecret != null ">#{contactSecret},</if>
<if test="customerChurnNoticeSwitch != null ">#{customer_churn_notice_switch},</if>
</trim> </trim>
</insert> </insert>
...@@ -80,6 +83,7 @@ PUBLIC "-//mybatis.org//DTD Mapper 3.0//EN" ...@@ -80,6 +83,7 @@ PUBLIC "-//mybatis.org//DTD Mapper 3.0//EN"
<if test="updateBy != null">update_by = #{updateBy},</if> <if test="updateBy != null">update_by = #{updateBy},</if>
<if test="updateTime != null">update_time = #{updateTime},</if> <if test="updateTime != null">update_time = #{updateTime},</if>
<if test="contactSecret != null ">contact_secret = #{contactSecret},</if> <if test="contactSecret != null ">contact_secret = #{contactSecret},</if>
<if test="customerChurnNoticeSwitch != null ">customer_churn_notice_switch = #{customerChurnNoticeSwitch},</if>
</trim> </trim>
where id = #{id} where id = #{id}
</update> </update>
......
Markdown is supported
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!