Commit 553e6438 by 阮思源

'【ID1002408】小睿提供个性化定制服务——阶段管理'

parent 57bf1fcb
......@@ -4,13 +4,15 @@ import com.alibaba.druid.pool.DruidDataSource;
import com.pcloud.book.mq.config.MQTopicConumer;
import com.pcloud.common.core.constant.MQQueueConstant;
import com.pcloud.common.core.constant.MQTopicProducer;
import com.pcloud.common.core.mq.MQExchangeConstants;
import com.pcloud.common.core.mq.MQQueueConstants;
import com.pcloud.common.core.mq.RabbitMQFactory;
import org.mybatis.spring.annotation.MapperScan;
import org.springframework.amqp.core.Binding;
import org.springframework.amqp.core.DirectExchange;
import org.springframework.amqp.core.BindingBuilder;
import org.springframework.amqp.core.CustomExchange;
import org.springframework.amqp.core.Queue;
import org.springframework.amqp.core.QueueBuilder;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.boot.SpringApplication;
import org.springframework.boot.autoconfigure.SpringBootApplication;
......@@ -35,8 +37,6 @@ import springfox.documentation.spi.DocumentationType;
import springfox.documentation.spring.web.plugins.Docket;
import springfox.documentation.swagger2.annotations.EnableSwagger2;
import static com.pcloud.book.guide.constant.DelayQueueConstant.*;
@SpringBootApplication
@ComponentScan("com.pcloud")
@EnableEurekaClient
......@@ -181,7 +181,7 @@ public class BookApplication {
}
@Bean
public Queue convert2BookQueue(){
public Queue convert2BookQueue() {
return RabbitMQFactory.queueBuilder(MQQueueConstant.CONVERT_TO_BOOK);
}
......@@ -209,33 +209,33 @@ public class BookApplication {
}
@Bean
public Queue wxGroupUserBindQueue(){
public Queue wxGroupUserBindQueue() {
return RabbitMQFactory.queueBuilder(MQTopicConumer.CONSUMER_WXGROUP_USER_BIND);
}
@Bean
public Binding wxGroupUserBindBind(){
public Binding wxGroupUserBindBind() {
return RabbitMQFactory.bindingExchange(wxGroupUserBindQueue(), MQTopicProducer.WXGROUP_USER_BIND);
}
@Bean
public Queue wxLiveBroadcastReminderBindQueue(){
public Queue wxLiveBroadcastReminderBindQueue() {
return RabbitMQFactory.queueBuilder(MQTopicConumer.WX_LIVE_BROADCAST_REMINDER);
}
@Bean
public Binding wxLiveBroadcastReminderBindBind(){
public Binding wxLiveBroadcastReminderBindBind() {
return RabbitMQFactory.bindingExchange(wxLiveBroadcastReminderBindQueue(), MQTopicProducer.WX_LIVE_BROADCAST_REMINDER);
}
@Bean
public Queue someUserScanBookGroupQueue(){
public Queue someUserScanBookGroupQueue() {
return RabbitMQFactory.queueBuilder(MQTopicConumer.CONSUMER_SOME_USER_SCAN_BOOK_GROUP);
}
@Bean
public Binding someUserScanBookGroupBind(){
public Binding someUserScanBookGroupBind() {
return RabbitMQFactory.bindingExchange(someUserScanBookGroupQueue(), MQTopicProducer.SOME_USER_SCAN_BOOK_GROUP);
}
......@@ -261,4 +261,37 @@ public class BookApplication {
public Binding wxGroupRealStatusBind() {
return RabbitMQFactory.bindingExchange(wxGroupRealStatusQueue(), MQTopicProducer.ROBOT_REAL_STATUS);
}
@Bean
public CustomExchange delayExchange() {
Map<String, Object> args = new HashMap<>();
args.put(RabbitMQFactory.X_DELAYED_TYPE, RabbitMQFactory.DIRECT);
return new CustomExchange(MQExchangeConstants.BOOK_DELAYED_EXCHANGE, RabbitMQFactory.X_DELAYED_MESSAGE, true, false, args);
}
/**
* 创建一个立即消费队列
*/
@Bean
public Queue immediateQueue() {
return new Queue(MQQueueConstants.BOOK_IMMEDIATE_QUEUE_FOR_DELAY, true);
}
/**
* 把立即消费的队列和延时消费的exchange绑定在一起
*/
@Bean
public Binding bindingNotify() {
return BindingBuilder.bind(immediateQueue()).to(delayExchange()).with(MQExchangeConstants.BOOK_DELAY_ROUTING_KEY).noargs();
}
@Bean
public Queue selfRobotSendTextQueue() {
return RabbitMQFactory.queueBuilder(MQTopicConumer.SELF_ROBOT_SEND_TEXT);
}
@Bean
public Binding selfRobotSendTextBind() {
return RabbitMQFactory.bindingExchange(selfRobotSendTextQueue(),MQTopicProducer.SELF_ROBOT_SEND_TEXT);
}
}
......@@ -25,4 +25,6 @@ public interface PcloudGuideBiz {
void copyGuideSetting(String fromRobotWxId, String toRobotWxId);
void add4Classify(Create4ClassifyVO create4ClassifyVO);
void stopPcloudGuidePush(String robotWxId, String userWxId);
}
......@@ -16,6 +16,7 @@ import com.pcloud.book.keywords.enums.ReplyTypeEnum;
import com.pcloud.common.page.PageBeanNew;
import com.pcloud.common.utils.BeanUtils;
import com.pcloud.common.utils.ListUtils;
import com.pcloud.common.utils.cache.redis.JedisClusterUtils;
import com.pcloud.common.utils.string.StringUtil;
import com.pcloud.contentcenter.resource.dto.ResourceDTO;
import org.springframework.beans.factory.annotation.Autowired;
......@@ -28,6 +29,8 @@ import java.util.List;
import java.util.Map;
import java.util.stream.Collectors;
import static com.pcloud.book.guide.constant.PcloudGuideRedisConstant.PCLOUD_GUIDE_SUFFIX;
@Component("pcloudGuideBiz")
public class PcloudGuideBizImpl implements PcloudGuideBiz {
......@@ -281,4 +284,9 @@ public class PcloudGuideBizImpl implements PcloudGuideBiz {
pcloudGuideMessageMapper.batchInsert(list);
}
}
@Override
public void stopPcloudGuidePush(String robotWxId, String userWxId) {
JedisClusterUtils.hdel(robotWxId + PCLOUD_GUIDE_SUFFIX, userWxId);
}
}
......@@ -56,6 +56,7 @@ import com.pcloud.book.keywords.vo.UpdateGuideVO;
import com.pcloud.book.pcloudkeyword.biz.PcloudRobotBiz;
import com.pcloud.book.pcloudkeyword.dao.PcloudRobotDao;
import com.pcloud.book.pcloudkeyword.entity.PcloudRobot;
import com.pcloud.book.personalstage.biz.PersonalStageBiz;
import com.pcloud.book.weixinclock.dao.WeixinClockGroupClassifyDao;
import com.pcloud.book.weixinclock.dto.WeixinClockDto;
import com.pcloud.channelcenter.wechat.dto.AccountSettingDto;
......@@ -141,6 +142,8 @@ public class BookGuideBizImpl implements BookGuideBiz {
private PcloudRobotDao pcloudRobotDao;
@Autowired
private PcloudGuideMapper pcloudGuideMapper;
@Autowired
private PersonalStageBiz personalStageBiz;
@Value("${wechat.group.link.prefix}")
private String wechatGroupLinkPrefix;
......@@ -162,6 +165,9 @@ public class BookGuideBizImpl implements BookGuideBiz {
pcloudRobotBiz.sendWelcomeReply(agreeAddUserDTO.getRobotWxId(), agreeAddUserDTO.getUserWxId(), agreeAddUserDTO.getIp());
//好友引导语
sendFriendGuide(null, agreeAddUserDTO);
if (personalStageBiz.isPersonalStageUser(agreeAddUserDTO.getRobotWxId())){
personalStageBiz.createAddUserStageUser(agreeAddUserDTO.getRobotWxId(),agreeAddUserDTO.getUserWxId(), agreeAddUserDTO.getIp());
}
return;
}
SendTextMessageVO vo = new SendTextMessageVO();
......
......@@ -86,6 +86,9 @@ import com.pcloud.book.pcloudkeyword.enums.KeywordTypeEnum;
import com.pcloud.book.pcloudkeyword.enums.MethodEnum;
import com.pcloud.book.pcloudkeyword.enums.RelevanceTypeEnum;
import com.pcloud.book.pcloudkeyword.set.PcloudRobotSet;
import com.pcloud.book.personalstage.biz.PersonalStageBiz;
import com.pcloud.book.personalstage.biz.PersonalStageJumpBiz;
import com.pcloud.book.personalstage.enums.JumpTypeEnum;
import com.pcloud.book.reading.biz.ReadingActivityBiz;
import com.pcloud.book.util.common.ThreadPoolUtils;
import com.pcloud.channelcenter.base.constants.ChannelEnum;
......@@ -244,6 +247,10 @@ public class BookKeywordBizImpl implements BookKeywordBiz {
private AdviserConsr adviserConsr;
@Autowired
private PcloudRobotSet pcloudRobotSet;
@Autowired
private PersonalStageBiz personalStageBiz;
@Autowired
private PersonalStageJumpBiz personalStageJumpBiz;
/**
* 字符串切割长度
......@@ -592,6 +599,10 @@ public class BookKeywordBizImpl implements BookKeywordBiz {
sendSearchBook(sendTextDTO);
return;
}
if (personalStageBiz.isPersonalStageUser(sendTextDTO.getWxId())){
personalStageBiz.userSendPersonalStage(sendTextDTO.getWechatUserId(), sendTextDTO.getIp(), sendTextDTO.getCode(), sendTextDTO.getWxId(), sendTextDTO.getTextContent());
return;
}
sendPcloudKeyword(sendTextDTO,pcloudRobot);
return;
}
......
......@@ -95,4 +95,8 @@ public class MQTopicConumer {
*/
public static final String WXGROUP_SEND_NOT_TEXT = PREFIX + MQTopicProducer.WXGROUP_SEND_NOT_TEXT;
/**
* 个人号发送文本消息
*/
public static final String SELF_ROBOT_SEND_TEXT = PREFIX + MQTopicProducer.SELF_ROBOT_SEND_TEXT;
}
package com.pcloud.book.mq.delay;
import com.pcloud.common.core.mq.DelayQueueDTO;
import com.pcloud.common.core.mq.MQExchangeConstants;
import org.springframework.amqp.rabbit.core.RabbitTemplate;
import org.springframework.stereotype.Component;
import javax.annotation.Resource;
import lombok.extern.slf4j.Slf4j;
/**
* 延时队列消息生产者
*/
@Slf4j
@Component
public class DelayMessageSender {
@Resource
private RabbitTemplate rabbitTemplate;
public void send(DelayQueueDTO dto) {
this.rabbitTemplate.convertAndSend(MQExchangeConstants.BOOK_DELAYED_EXCHANGE, MQExchangeConstants.BOOK_DELAY_ROUTING_KEY, dto, message -> {
message.getMessageProperties().setDelay(dto.getTimeout());
return message;
});
}
}
package com.pcloud.book.mq.delay;
import com.pcloud.book.personalstage.biz.PersonalStageBiz;
import com.pcloud.book.personalstage.constant.PersonalStageConstant;
import com.pcloud.common.core.mq.DelayQueueDTO;
import com.pcloud.common.core.mq.MQQueueConstants;
import org.springframework.amqp.rabbit.annotation.RabbitHandler;
import org.springframework.amqp.rabbit.annotation.RabbitListener;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Component;
import java.text.SimpleDateFormat;
import java.util.Date;
import lombok.extern.slf4j.Slf4j;
/**
* 监听延时队列
*/
@Slf4j
@Component
@RabbitListener(queues = MQQueueConstants.BOOK_IMMEDIATE_QUEUE_FOR_DELAY)
public class DelayReceiver {
@Autowired
private PersonalStageBiz personalStageBiz;
@RabbitHandler
public void onMessage(DelayQueueDTO dto) {
SimpleDateFormat sdf = new SimpleDateFormat("yyyy-MM-dd HH:mm:ss");
log.info("收到延时消息:{} 时间:{}", dto, sdf.format(new Date()) + " Delay sent.");
if (dto==null){
log.info("收到延时消息为空!");
return;
}
if (PersonalStageConstant.PERSONALSTAGE_DELAY_WAKEUP.equals(dto.getType())){
personalStageBiz.dealDelayWakeup(dto);
} else if (PersonalStageConstant.PERSONALSTAGE_DELAY_FUSING.equals(dto.getType())) {
personalStageBiz.dealDelayFusingFinish(dto);
}
}
}
package com.pcloud.book.mq.topic;
import com.pcloud.book.mq.config.MQTopicConumer;
import com.pcloud.book.personalstage.biz.PersonalStageJumpBiz;
import com.pcloud.book.personalstage.enums.JumpTypeEnum;
import com.pcloud.common.core.aspect.ParamLog;
import com.pcloud.common.exceptions.BizException;
import com.pcloud.common.utils.string.StringUtil;
import com.pcloud.wechatgroup.base.constants.WechatGroupConstant;
import com.pcloud.wechatgroup.message.dto.SendTextDTO;
import lombok.extern.slf4j.Slf4j;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.amqp.rabbit.annotation.RabbitHandler;
import org.springframework.amqp.rabbit.annotation.RabbitListener;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Component;
@Slf4j
@Component("selfRobotSendTextListener")
@RabbitListener(queues = MQTopicConumer.SELF_ROBOT_SEND_TEXT)
public class SelfRobotSendTextListener {
private static final Logger LOGGER = LoggerFactory.getLogger(SelfRobotSendTextListener.class);
@Autowired
private PersonalStageJumpBiz personalStageJumpBiz;
/**
* 接收个人号发送文本消息
*/
@ParamLog("接收个人号文本消息")
@RabbitHandler
public void onMessage(SendTextDTO sendTextDTO) throws BizException {
try {
LOGGER.info("接收到个人号发送文本消息,处理中:"+sendTextDTO.toString());
//TODO 处理个人号消息
if (!StringUtil.isEmpty(sendTextDTO.getTextContent()) && sendTextDTO.getTextContent().startsWith(WechatGroupConstant.SELF_ROBOT_CONTENT_KEYWORD)) {
personalStageJumpBiz.handlePersonalStageJump(sendTextDTO.getWechatGroupId(), sendTextDTO.getWxId(), sendTextDTO.getTextContent(), JumpTypeEnum.ROBOT_TRIGGER);
}
} catch (Exception e) {
LOGGER.error("接收用户发送文本消息失败" + e.getMessage(), e);
}
}
}
......@@ -8,6 +8,7 @@ import com.pcloud.book.pcloudkeyword.dao.PcloudRobotDao;
import com.pcloud.book.pcloudkeyword.entity.PcloudKeywordClassify;
import com.pcloud.book.pcloudkeyword.entity.PcloudRobot;
import com.pcloud.book.pcloudkeyword.entity.PcloudRobotClassify;
import com.pcloud.book.personalstage.biz.PersonalStageBiz;
import com.pcloud.common.core.aspect.ParamLog;
import com.pcloud.common.exceptions.BizException;
import com.pcloud.common.utils.cache.redis.JedisClusterUtils;
......@@ -36,6 +37,8 @@ public class WxGroupSendNotTextListener {
private PcloudRobotClassifyDao pcloudRobotClassifyDao;
@Autowired
private PcloudKeywordClassifyDao pcloudKeywordClassifyDao;
@Autowired
private PersonalStageBiz personalStageBiz;
@ParamLog("接收用户发送非文本消息")
@RabbitHandler
......@@ -52,6 +55,10 @@ public class WxGroupSendNotTextListener {
bookKeywordBiz.silenceProcess(userWxId, code, robotId);
// 机器人自动唤醒
bookKeywordBiz.robotWakeUp(userWxId, ip, code, robotId);
if (personalStageBiz.isPersonalStageUser(sendNotTextDTO.getWxId())){
personalStageBiz.userSendPersonalStage(userWxId,ip,code,robotId,null);
return;
}
//判断是否为平台端小号
PcloudRobot pcloudRobot = pcloudRobotDao.getByWxId(sendNotTextDTO.getWxId());
if (pcloudRobot!=null){
......
package com.pcloud.book.personalstage.biz;
import com.pcloud.book.personalstage.dto.PersonalStageDTO;
import com.pcloud.book.personalstage.entity.PersonalStage;
import com.pcloud.common.core.mq.DelayQueueDTO;
import com.pcloud.common.exceptions.BizException;
import com.pcloud.common.page.PageBean;
import com.pcloud.common.page.PageParam;
import java.util.List;
public interface PersonalStageBiz {
Long createPersonalStage(PersonalStage personalStage);
void updatePersonalStage(PersonalStage personalStage);
void deletePersonalStage(Long id);
PersonalStage getPersonalStage(Long id);
void updateSeqNum(PersonalStage personalStage);
/**
* 获取阶段列表
* @param robotClassifyId 分类ID
* @param pageParam 分页参数
* @return
* @throws BizException
*/
PageBean getPersonalStageList(Long robotClassifyId, PageParam pageParam) throws BizException;
/**
* 获取阶段列表
* @param robotClassifyId 分类ID
* @return
* @throws BizException
*/
List<PersonalStageDTO> getPersonalStageListNoPage(Long robotClassifyId) throws BizException;
void userSendPersonalStage(String userWxId, String ip, Integer code, String robotId, String content);
Boolean isPersonalStageUser(String robotId);
void createAddUserStageUser(String robotId, String userWxId, String ip);
void dealDelayWakeup(DelayQueueDTO dto);
void nextStageAddStageUserAndWakeupDelay(String robotId, String userWxId, String ip, Long personalStageId);
void sendNotKeywordReply(String robotId, String userWxId, String ip, Long personalStageId);
void sendNotKeywordFusingReply(String robotId, String userWxId, String ip, Long personalStageId);
void dealDelayFusingFinish(DelayQueueDTO dto);
}
package com.pcloud.book.personalstage.biz;
import com.pcloud.book.personalstage.dto.PersonalStageJumpDto;
import com.pcloud.book.personalstage.enums.JumpTypeEnum;
import com.pcloud.book.personalstage.vo.request.CreateStageJumpRequestVO;
import com.pcloud.book.personalstage.vo.request.UpdateStageJumpRequestVO;
import com.pcloud.common.page.PageBeanNew;
public interface PersonalStageJumpBiz {
/**
* 新建阶段跳转
* @param vo
*/
void createPersonalStageJump(CreateStageJumpRequestVO vo);
/**
* 修改阶段跳转
* @param vo
*/
void updatePersonalStageJump(UpdateStageJumpRequestVO vo);
PageBeanNew getJumpList(Long personalStageId, Integer currentPage, Integer numPerPage);
PersonalStageJumpDto getJump(Long jumpId);
void deleteJump(Long jumpId);
Long updateEmailStatus(Long jumpId, Integer openEmail);
/**
* 处理用户跳转逻辑
* 用户的消息状态
* @return false:未能跳转到下个阶段,需要后续的其它处理;
* true:命中关键字,已经跳转到下个阶段,无需后续处理;
*/
Boolean handlePersonalStageJump(String userWxId, String robotWxId, String content, JumpTypeEnum jumpTypeEnum);
}
package com.pcloud.book.personalstage.biz.impl;
import com.pcloud.book.base.exception.BookBizException;
import com.pcloud.book.keywords.enums.ReplyTypeEnum;
import com.pcloud.book.mq.delay.DelayMessageSender;
import com.pcloud.book.pcloudkeyword.dao.PcloudRobotClassifyDao;
import com.pcloud.book.pcloudkeyword.dao.PcloudRobotDao;
import com.pcloud.book.pcloudkeyword.entity.PcloudRobot;
import com.pcloud.book.pcloudkeyword.entity.PcloudRobotClassify;
import com.pcloud.book.personalstage.biz.PersonalStageBiz;
import com.pcloud.book.personalstage.biz.PersonalStageJumpBiz;
import com.pcloud.book.personalstage.check.PersonalStageCheck;
import com.pcloud.book.personalstage.constant.PersonalStageConstant;
import com.pcloud.book.personalstage.dao.PersonalStageDao;
import com.pcloud.book.personalstage.dao.PersonalStageJumpDao;
import com.pcloud.book.personalstage.dao.PersonalStageJumpKeywordDao;
import com.pcloud.book.personalstage.dao.PersonalStageReplyDao;
import com.pcloud.book.personalstage.dao.PersonalStageReplyItemDao;
import com.pcloud.book.personalstage.dao.PersonalStageUserDao;
import com.pcloud.book.personalstage.dao.PersonalStageWakeupDao;
import com.pcloud.book.personalstage.dto.FusingFinishDelayDTO;
import com.pcloud.book.personalstage.dto.PersonalStageDTO;
import com.pcloud.book.personalstage.dto.PersonalStageJumpKeywordDto;
import com.pcloud.book.personalstage.dto.WakeupDelayDTO;
import com.pcloud.book.personalstage.entity.PersonalStage;
import com.pcloud.book.personalstage.entity.PersonalStageReply;
import com.pcloud.book.personalstage.entity.PersonalStageReplyItem;
import com.pcloud.book.personalstage.entity.PersonalStageUser;
import com.pcloud.book.personalstage.entity.PersonalStageWakeup;
import com.pcloud.book.personalstage.enums.JumpTypeEnum;
import com.pcloud.book.personalstage.enums.PersonalStageUserStateEnum;
import com.pcloud.book.personalstage.enums.StageReplyRelevEnum;
import com.pcloud.common.core.aspect.ParamLog;
import com.pcloud.common.core.mq.DelayQueueDTO;
import com.pcloud.common.utils.ListUtils;
import com.pcloud.common.utils.cache.redis.JedisClusterUtils;
import com.pcloud.common.utils.string.StringUtil;
import com.sdk.wxgroup.SendMessageTypeEnum;
import com.sdk.wxgroup.SendPicMessageVO;
import com.sdk.wxgroup.SendTextMessageVO;
import com.sdk.wxgroup.WxGroupSDK;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.beans.factory.annotation.Autowired;
import com.pcloud.common.exceptions.BizException;
import com.pcloud.common.page.PageBean;
import com.pcloud.common.page.PageParam;
import org.springframework.stereotype.Component;
import org.springframework.transaction.annotation.Transactional;
import java.util.ArrayList;
import java.util.Arrays;
import java.util.List;
import java.util.HashMap;
import java.util.Map;
import java.util.Random;
import java.util.stream.Collectors;
@Component("personalStageBiz")
public class PersonalStageBizImpl implements PersonalStageBiz {
private static final Logger LOGGER = LoggerFactory.getLogger(PersonalStageBizImpl.class);
@Autowired
private PersonalStageDao personalStageDao;
@Autowired
private PersonalStageReplyDao personalStageReplyDao;
@Autowired
private PersonalStageReplyItemDao personalStageReplyItemDao;
@Autowired
private PersonalStageWakeupDao personalStageWakeupDao;
@Autowired
private PersonalStageCheck personalStageCheck;
@Autowired
private PersonalStageJumpDao personalStageJumpDao;
@Autowired
private PcloudRobotClassifyDao pcloudRobotClassifyDao;
@Autowired
private PcloudRobotDao pcloudRobotDao;
@Autowired
private PersonalStageUserDao personalStageUserDao;
@Autowired
private DelayMessageSender delayMessageSender;
@Autowired
private PersonalStageJumpKeywordDao personalStageJumpKeywordDao;
@Autowired
private PersonalStageJumpBiz personalStageJumpBiz;
@Transactional(rollbackFor = Exception.class)
@ParamLog("新增阶段")
@Override
public Long createPersonalStage(PersonalStage personalStage) {
personalStageCheck.createPersonalStageParamCheck(personalStage);
Integer maxSeqNum = personalStageDao.getMaxSeqNum();
personalStage.setSeqNum(maxSeqNum+1);
personalStageDao.insert(personalStage);
addWakeAndReply(personalStage);
return personalStage.getId();
}
@Transactional(rollbackFor = Exception.class)
@ParamLog("修改阶段")
@Override
public void updatePersonalStage(PersonalStage personalStage) {
personalStageCheck.updatePersonalStageParamCheck(personalStage);
personalStageDao.update(personalStage);
deleteAddWakeAndReply(personalStage.getId());
addWakeAndReply(personalStage);
}
@Transactional(rollbackFor = Exception.class)
@ParamLog("删除阶段")
@Override
public void deletePersonalStage(Long id) {
if (id==null){
throw new BookBizException(BookBizException.PARAM_IS_NULL,"id不能为空!");
}
//校验是否是某个阶段的下一个阶段
Integer count = personalStageJumpDao.getCountByPersonalStageId(id);
if (count>0){
throw new BookBizException(BookBizException.PARAM_IS_NULL,"该阶段为某个阶段的下一阶段,不能删除!");
}
personalStageDao.deleteById(id);
deleteAddWakeAndReply(id);
}
@ParamLog("获取定制化阶段")
@Override
public PersonalStage getPersonalStage(Long id) {
PersonalStage personalStage = personalStageDao.getById(id);
if (personalStage==null){
throw new BookBizException(BookBizException.ERROR,"没有该记录");
}
List<PersonalStageReply> replies = personalStageReplyDao.getListByPersonalStageId(id);
Map<Long,List<PersonalStageReply>> wakeupReplyMap=new HashMap<>();
if (!ListUtils.isEmpty(replies)){
List<Long> replyIds=replies.stream().map(PersonalStageReply::getId).collect(Collectors.toList());
List<PersonalStageReplyItem> replyItems = personalStageReplyItemDao.getListByReplyIds(replyIds);
if (!ListUtils.isEmpty(replyItems)){
Map<Long,List<PersonalStageReplyItem>> itemMap=replyItems.stream().collect(Collectors.groupingBy(PersonalStageReplyItem::getPersonalStageReplyId));
for (PersonalStageReply reply:replies){
reply.setPersonalStageReplyItems(itemMap.get(reply.getId()));
}
}
personalStage.setStageNotKeywordReplies(replies.stream().filter(s->StageReplyRelevEnum.STAGE_NOT_KEYWORD.value.equals(s.getRelevanceType())).collect(Collectors.toList()));
personalStage.setFusingNotKeywordReplies(replies.stream().filter(s->StageReplyRelevEnum.FUSING_NOT_KEYWORD.value.equals(s.getRelevanceType())).collect(Collectors.toList()));
List<PersonalStageReply> wakeupReplies=replies.stream().filter(s->StageReplyRelevEnum.WAKEUP.value.equals(s.getRelevanceType())).collect(Collectors.toList());
wakeupReplyMap=wakeupReplies.stream().collect(Collectors.groupingBy(PersonalStageReply::getRelevanceId));
}
List<PersonalStageWakeup> wakeups = personalStageWakeupDao.getListByPersonalStageId(id);
for (PersonalStageWakeup wakeup:wakeups){
wakeup.setWakeupReplies(wakeupReplyMap.get(wakeup.getId()));
}
personalStage.setPersonalStageWakeups(wakeups);
return personalStage;
}
@Transactional(rollbackFor = Exception.class)
@ParamLog("修改排序值")
@Override
public void updateSeqNum(PersonalStage personalStage) {
if (personalStage==null||personalStage.getId()==null||personalStage.getSeqNum()==null){
throw new BookBizException(BookBizException.PARAM_IS_NULL,"参数有误!");
}
personalStageDao.updateSeqNum(personalStage.getId(),personalStage.getSeqNum());
}
@ParamLog("删除唤醒和回复")
private void deleteAddWakeAndReply(Long personalStageId) {
List<Long> replyIds = personalStageReplyDao.getIdsByPersonalStageId(personalStageId);
personalStageReplyDao.deleteByIds(replyIds);
personalStageReplyItemDao.deleteByReplyIds(replyIds);
personalStageWakeupDao.deleteByPersonalStageId(personalStageId);
}
@ParamLog("新增唤醒和回复")
private void addWakeAndReply(PersonalStage personalStage) {
Long personalStageId = personalStage.getId();
List<PersonalStageReply> allReply=new ArrayList<>();
if (!ListUtils.isEmpty(personalStage.getPersonalStageWakeups())){
for (PersonalStageWakeup wakeup:personalStage.getPersonalStageWakeups()){
wakeup.setPersonalStageId(personalStageId);
}
personalStageWakeupDao.batchInsert(personalStage.getPersonalStageWakeups());
for (PersonalStageWakeup wakeup:personalStage.getPersonalStageWakeups()){
Long wakeupId=wakeup.getId();
for (PersonalStageReply reply:wakeup.getWakeupReplies()){
reply.setRelevanceType(StageReplyRelevEnum.WAKEUP.value);
reply.setRelevanceId(wakeupId);
reply.setPersonalStageId(personalStageId);
}
allReply.addAll(wakeup.getWakeupReplies());
}
}
for (PersonalStageReply reply:personalStage.getStageNotKeywordReplies()){
reply.setRelevanceType(StageReplyRelevEnum.STAGE_NOT_KEYWORD.value);
reply.setPersonalStageId(personalStageId);
reply.setRelevanceId(personalStageId);
}
allReply.addAll(personalStage.getStageNotKeywordReplies());
for (PersonalStageReply reply:personalStage.getFusingNotKeywordReplies()){
reply.setRelevanceType(StageReplyRelevEnum.FUSING_NOT_KEYWORD.value);
reply.setPersonalStageId(personalStageId);
reply.setRelevanceId(personalStageId);
}
allReply.addAll(personalStage.getFusingNotKeywordReplies());
personalStageReplyDao.batchInsert(allReply);
List<PersonalStageReplyItem> allItems=new ArrayList<>();
for (PersonalStageReply reply:allReply){
Long replyId=reply.getId();
for (PersonalStageReplyItem item:reply.getPersonalStageReplyItems()){
item.setPersonalStageReplyId(replyId);
}
allItems.addAll(reply.getPersonalStageReplyItems());
}
personalStageReplyItemDao.batchInsert(allItems);
}
/**
* 获取阶段列表
*/
@Override
public PageBean getPersonalStageList(Long robotClassifyId, PageParam pageParam) throws BizException {
Map<String, Object> paramMap = new HashMap<>();
paramMap.put("robotClassifyId", robotClassifyId);
return personalStageDao.listPage(pageParam, paramMap, "getPersonalStageList");
}
/**
* 获取阶段列表
*/
@Override
public List<PersonalStageDTO> getPersonalStageListNoPage(Long robotClassifyId) throws BizException {
return personalStageDao.getPersonalStageList(robotClassifyId);
}
@Transactional(rollbackFor = Exception.class)
@ParamLog("发送关键词时处理用户定制化阶段")
@Override
public void userSendPersonalStage(String userWxId,String ip,Integer code,String robotId, String content) {
Boolean hasRecord;
PersonalStageUser last = personalStageUserDao.getLast(userWxId, robotId, null);
PersonalStage personalStage;
if (last!=null){
hasRecord=true;
personalStage=personalStageDao.getById(last.getPersonalStageId());
}else {
hasRecord=false;
PcloudRobot pcloudRobot = pcloudRobotDao.getByWxId(robotId);
Long robotClassifyId=pcloudRobot.getRobotType().longValue();
personalStage = personalStageDao.getFirstStage(robotClassifyId);
}
Boolean iskeyword;
if (StringUtil.isEmpty(content)){
iskeyword=false;
}else {
//关键词库查询
PersonalStageJumpKeywordDto dto=personalStageJumpKeywordDao.getByKeyword(personalStage.getId(),content, JumpTypeEnum.READER_TRIGGER.key);
if (dto!=null){
iskeyword=true;
}else {
iskeyword=false;
}
}
//是关键词且有记录
if (iskeyword){
LOGGER.info("是关键词且有记录");
//调关键词处理逻辑
personalStageJumpBiz.handlePersonalStageJump(userWxId,robotId,content,JumpTypeEnum.READER_TRIGGER);
}
//不是关键词且有记录
if (!iskeyword&&hasRecord){
//判断是否已经达到熔断标准
if (personalStage!=null){
if ((last.getNotKeywordSendCount()!=null&&last.getNotKeywordSendCount()>=personalStage.getNotKeywordFusingCount())
||PersonalStageUserStateEnum.FUSING.value.equals(last.getState())){
// 走熔断
LOGGER.info("走熔断");
handleFusingReply(robotId,userWxId,ip,personalStage,last);
}else {
//走正常逻辑非关键词回复并且更新记录
if (PersonalStageUserStateEnum.NORMAL.value.equals(last.getState())
||PersonalStageUserStateEnum.WAKEUP.value.equals(last.getState())){
LOGGER.info("走正常逻辑非关键词回复并且更新记录");
//如果是正常状态或者唤醒状态才回复,并且更新状态为正常状态
sendNotKeywordReply(robotId,userWxId,ip,personalStage.getId());
last.setNotKeywordSendCount(last.getNotKeywordSendCount()+1);
last.setState(PersonalStageUserStateEnum.NORMAL.value);
personalStageUserDao.update(last);
}
}
}
}
//不是关键词且没有记录
if (!iskeyword&&!hasRecord){
//走正常非关键词回复并且新增记录
LOGGER.info("走正常非关键词回复并且新增记录");
sendNotKeywordReply(robotId,userWxId,ip,personalStage.getId());
PcloudRobot pcloudRobot = pcloudRobotDao.getByWxId(robotId);
Long robotClassifyId=pcloudRobot.getRobotType().longValue();
PersonalStage firstStage = personalStageDao.getFirstStage(robotClassifyId);
PersonalStageUser personalStageUser=new PersonalStageUser();
personalStageUser.setRobotId(robotId);
personalStageUser.setWxId(userWxId);
personalStageUser.setState(PersonalStageUserStateEnum.NORMAL.value);
personalStageUser.setNotKeywordSendCount(1);
personalStageUser.setRobotClassifyId(robotClassifyId);
personalStageUser.setPersonalStageId(firstStage.getId());
personalStageUserDao.insert(personalStageUser);
}
}
@Override
@ParamLog("判断是否是定制化用户")
public Boolean isPersonalStageUser(String robotId){
//判断是否是平台端配置的小号
try {
PcloudRobot pcloudRobot = pcloudRobotDao.getByWxId(robotId);
if (pcloudRobot!=null&&pcloudRobot.getRobotType()!=null){
//查询该分类下的定制化阶段
Long robotClassifyId=pcloudRobot.getRobotType().longValue();
PcloudRobotClassify robotClassify = pcloudRobotClassifyDao.getById(robotClassifyId);
if (robotClassify!=null){
//获取该分类下的阶段数量
Integer count=personalStageDao.getCountByRobotClassifyId(robotClassifyId);
if (count>0){
return true;
}
}
}
}catch (Exception e) {
LOGGER.error("判断是否是定制化用户失败" + e.getMessage(), e);
}
return false;
}
@ParamLog("加好友时插入初始状态")
@Override
public void createAddUserStageUser(String robotId, String userWxId, String ip) {
//查询第一个阶段
PcloudRobot pcloudRobot = pcloudRobotDao.getByWxId(robotId);
Long robotClassifyId=pcloudRobot.getRobotType().longValue();
PersonalStage firstStage = personalStageDao.getFirstStage(robotClassifyId);
if (firstStage==null){
return;
}
nextStageAddStageUserAndWakeupDelay (robotId, userWxId, ip, firstStage.getId());
}
@ParamLog("处理延时唤醒")
@Override
public void dealDelayWakeup(DelayQueueDTO dto) {
String wxId=dto.getKey();
WakeupDelayDTO wakeupDelayDTO=(WakeupDelayDTO) dto.getMsg();
//查询该用户最后的阶段
PersonalStageUser last = personalStageUserDao.getLast(wxId, wakeupDelayDTO.getRobotId(), null);
Long personalStageId = wakeupDelayDTO.getPersonalStageId();
//判断用户是否在插入唤醒延时队列的当时阶段且是唤醒状态
if (last==null||!PersonalStageUserStateEnum.WAKEUP.value.equals(last.getState())
||!last.getPersonalStageId().equals(personalStageId)){
LOGGER.info("用户已跳阶段或者不是唤醒状态"+wakeupDelayDTO.toString());
return;
}
PersonalStage personalStage=personalStageDao.getById(personalStageId);
if (personalStage==null){
LOGGER.info("未找到该阶段personalStageId="+personalStageId);
return;
}
Long currentWakeupId=wakeupDelayDTO.getPersonalStageWakeupId();
//发送唤醒内容
List<Long> replyIds=personalStageReplyDao.getIdsByRelevance(StageReplyRelevEnum.WAKEUP.value,currentWakeupId);
if (ListUtils.isEmpty(replyIds)){
LOGGER.info("没有回复currentWakeupId="+currentWakeupId);
return;
}
List<PersonalStageReplyItem> replyItems = personalStageReplyItemDao.getListByReplyIds(replyIds);
if (ListUtils.isEmpty(replyItems)){
LOGGER.info("没有回复项replyIds="+replyIds);
return;
}
String robotId=wakeupDelayDTO.getRobotId();
String userWxId=wakeupDelayDTO.getWxId();
String ip=wakeupDelayDTO.getIp();
sendReplyItems(replyItems,robotId,userWxId,ip);
//下一个延时
List<PersonalStageWakeup> wakeups = personalStageWakeupDao.getListByPersonalStageId(personalStageId);
int i=0;
for (PersonalStageWakeup wakeup:wakeups){
i=i+1;
if (currentWakeupId.equals(wakeup.getId())){
break;
}
}
if (i>0&&i<wakeups.size()){
PersonalStageWakeup nextWakeup=wakeups.get(i);
Integer time=nextWakeup.getToStageStartTime()*60*1000-dto.getTimeout();
WakeupDelayDTO wakeupDelayDTONew=new WakeupDelayDTO();
wakeupDelayDTONew.setPersonalStageWakeupId(nextWakeup.getId());
wakeupDelayDTONew.setRobotId(robotId);
wakeupDelayDTONew.setWxId(userWxId);
wakeupDelayDTONew.setIp(ip);
wakeupDelayDTONew.setPersonalStageId(personalStageId);
DelayQueueDTO delayQueueDTONew = DelayQueueDTO.builder().key(userWxId).type(PersonalStageConstant.PERSONALSTAGE_DELAY_WAKEUP).msg(wakeupDelayDTONew).timeout(time).build();
delayMessageSender.send(delayQueueDTONew);
LOGGER.info("下一个延时发送delayQueueDTONew="+delayQueueDTONew.toString());
}
}
@ParamLog("下一阶段新增定制化阶段用户记录和唤醒延时")
@Override
public void nextStageAddStageUserAndWakeupDelay(String robotId, String userWxId, String ip, Long personalStageId) {
PersonalStageWakeup wakeup = personalStageWakeupDao.getFirstWakeup(personalStageId);
PersonalStageUser personalStageUser=new PersonalStageUser();
personalStageUser.setRobotId(robotId);
personalStageUser.setWxId(userWxId);
if (wakeup==null){
//没有唤醒,设置状态为正常状态
personalStageUser.setState(PersonalStageUserStateEnum.NORMAL.value);
}else {
//有唤醒,设置状态为唤醒状态
personalStageUser.setState(PersonalStageUserStateEnum.WAKEUP.value);
}
personalStageUser.setNotKeywordSendCount(0);
//查询分类
PcloudRobot pcloudRobot = pcloudRobotDao.getByWxId(robotId);
Long robotClassifyId=pcloudRobot.getRobotType().longValue();
personalStageUser.setRobotClassifyId(robotClassifyId);
personalStageUser.setPersonalStageId(personalStageId);
personalStageUserDao.insert(personalStageUser);
//同时插入唤醒队列
//查询第一个唤醒时长
if (wakeup==null){
return;
}
Integer toStageStartTime=wakeup.getToStageStartTime();
WakeupDelayDTO wakeupDelayDTO=new WakeupDelayDTO();
wakeupDelayDTO.setPersonalStageWakeupId(wakeup.getId());
wakeupDelayDTO.setRobotId(robotId);
wakeupDelayDTO.setWxId(userWxId);
wakeupDelayDTO.setIp(ip);
wakeupDelayDTO.setPersonalStageId(personalStageId);
DelayQueueDTO delayQueueDTO = DelayQueueDTO.builder().key(userWxId).type(PersonalStageConstant.PERSONALSTAGE_DELAY_WAKEUP).msg(wakeupDelayDTO).timeout(toStageStartTime*60*1000).build();
delayMessageSender.send(delayQueueDTO);
}
@ParamLog("非关键词回复")
@Override
public void sendNotKeywordReply(String robotId, String userWxId, String ip, Long personalStageId) {
List<Long> ids = personalStageReplyDao.getIdsByRelevance(StageReplyRelevEnum.STAGE_NOT_KEYWORD.value, personalStageId);
if (ListUtils.isEmpty(ids)){
return;
}
Random random = new Random();
Long replyId=ids.get(random.nextInt(ids.size()));
List<PersonalStageReplyItem> items = personalStageReplyItemDao.getListByReplyIds(Arrays.asList(replyId));
if (ListUtils.isEmpty(items)){
return;
}
sendReplyItems(items,robotId,userWxId,ip);
}
@ParamLog("非关键词熔断回复")
@Override
public void sendNotKeywordFusingReply(String robotId, String userWxId, String ip, Long personalStageId) {
List<Long> ids = personalStageReplyDao.getIdsByRelevance(StageReplyRelevEnum.FUSING_NOT_KEYWORD.value, personalStageId);
if (ListUtils.isEmpty(ids)) {
return;
}
Random random = new Random();
Long replyId = ids.get(random.nextInt(ids.size()));
List<PersonalStageReplyItem> items = personalStageReplyItemDao.getListByReplyIds(Arrays.asList(replyId));
if (ListUtils.isEmpty(items)){
return;
}
sendReplyItems(items,robotId,userWxId,ip);
}
@ParamLog("发送回复")
private void sendReplyItems(List<PersonalStageReplyItem> replyItems,String robotId, String userWxId, String ip){
for (PersonalStageReplyItem item:replyItems){
Integer type=item.getReplyType();
if (ReplyTypeEnum.TEXT.value.equals(type)) {
SendTextMessageVO sendTextMessageVO = new SendTextMessageVO();
sendTextMessageVO.setContent(item.getContent());
sendTextMessageVO.setAltId(robotId);
sendTextMessageVO.setWxGroupId(userWxId);
sendTextMessageVO.setIp(ip);
sendTextMessageVO.setCode(SendMessageTypeEnum.SELF.getCode());
WxGroupSDK.sendTextMessage(sendTextMessageVO);
}
if (ReplyTypeEnum.IMAGE.value.equals(type)) {
SendPicMessageVO sendPicMessageVO = new SendPicMessageVO();
sendPicMessageVO.setWxGroupId(userWxId);
sendPicMessageVO.setAltId(robotId);
sendPicMessageVO.setPicUrl(item.getPicUrl());
sendPicMessageVO.setIp(ip);
sendPicMessageVO.setCode(SendMessageTypeEnum.SELF.getCode());
WxGroupSDK.sendPicMessage(sendPicMessageVO);
}
}
}
@ParamLog("处理熔断回复情况")
private void handleFusingReply(String robotId, String userWxId, String ip, PersonalStage personalStage, PersonalStageUser last) {
if (!PersonalStageUserStateEnum.FUSING.value.equals(last.getState())) {
// 置为熔断状态
PersonalStageUser user = new PersonalStageUser();
user.setId(last.getId());
user.setState(PersonalStageUserStateEnum.FUSING.value);
user.setNotKeywordSendCount(last.getNotKeywordSendCount()+1);
personalStageUserDao.update(user);
// 添加延迟队列
FusingFinishDelayDTO delayDTO = new FusingFinishDelayDTO();
delayDTO.setPersonalStageUserId(last.getId());
delayDTO.setPersonalStageId(personalStage.getId());
delayDTO.setRobotId(robotId);
delayDTO.setWxId(userWxId);
delayDTO.setIp(ip);
DelayQueueDTO delayQueueDTO = DelayQueueDTO.builder().key(userWxId).type(PersonalStageConstant.PERSONALSTAGE_DELAY_FUSING)
.msg(delayDTO).timeout(personalStage.getNotKeywordFusingTime().intValue() * 60 * 1000).build();
delayMessageSender.send(delayQueueDTO);
}
String key = "BOOK:PERSONAL_STAGE:FUSING:" + last.getId();
if (!JedisClusterUtils.exists(key)) {
// 发送熔断回复消息
sendNotKeywordFusingReply(robotId, userWxId, ip, personalStage.getId());
JedisClusterUtils.set(key, "true", 60);
}
}
@ParamLog("处理延时熔断结束")
@Override
public void dealDelayFusingFinish(DelayQueueDTO dto) {
String wxId = dto.getKey();
FusingFinishDelayDTO delayDTO = (FusingFinishDelayDTO) dto.getMsg();
//查询该用户在该阶段的状态
Long personalStageId = delayDTO.getPersonalStageId();
Long personalStageUserId = delayDTO.getPersonalStageUserId();
PersonalStageUser last = personalStageUserDao.getById(personalStageUserId);
if (last == null || !PersonalStageUserStateEnum.FUSING.value.equals(last.getState())){
return;
}
PersonalStage personalStage = personalStageDao.getById(personalStageId);
if (personalStage == null){
return;
}
// 将用户置为正常状态
PersonalStageUser user = new PersonalStageUser();
user.setId(personalStageUserId);
user.setState(PersonalStageUserStateEnum.NORMAL.value);
user.setNotKeywordSendCount(0);
personalStageUserDao.update(user);
}
}
package com.pcloud.book.personalstage.biz.impl;
import com.pcloud.book.base.exception.BookBizException;
import com.google.common.collect.Lists;
import com.google.common.collect.Maps;
import com.pcloud.book.consumer.wechatgroup.WechatGroupConsr;
import com.pcloud.book.group.biz.WeixinQrcodeBiz;
import com.pcloud.book.guide.biz.PcloudGuideBiz;
import com.pcloud.book.pcloudkeyword.dao.PcloudRobotClassifyDao;
import com.pcloud.book.pcloudkeyword.dao.PcloudRobotDao;
import com.pcloud.book.pcloudkeyword.entity.PcloudRobot;
import com.pcloud.book.pcloudkeyword.entity.PcloudRobotClassify;
import com.pcloud.book.personalstage.biz.PersonalStageBiz;
import com.pcloud.book.personalstage.biz.PersonalStageJumpBiz;
import com.pcloud.book.personalstage.dao.PersonalStageJumpDao;
import com.pcloud.book.personalstage.dao.PersonalStageJumpEmailDao;
import com.pcloud.book.personalstage.dao.PersonalStageJumpKeywordDao;
import com.pcloud.book.personalstage.dao.PersonalStageJumpLinkupDao;
import com.pcloud.book.personalstage.dao.PersonalStageUserDao;
import com.pcloud.book.personalstage.dto.PersonalStageJumpDto;
import com.pcloud.book.personalstage.dto.PersonalStageJumpKeywordDto;
import com.pcloud.book.personalstage.entity.PersonalStage;
import com.pcloud.book.personalstage.entity.PersonalStageJump;
import com.pcloud.book.personalstage.entity.PersonalStageJumpEmail;
import com.pcloud.book.personalstage.entity.PersonalStageJumpKeyword;
import com.pcloud.book.personalstage.entity.PersonalStageJumpLinkup;
import com.pcloud.book.personalstage.entity.PersonalStageUser;
import com.pcloud.book.personalstage.enums.JumpTypeEnum;
import com.pcloud.book.personalstage.enums.PersonalStageUserStateEnum;
import com.pcloud.book.personalstage.vo.request.BaseStageJumpRequestVO;
import com.pcloud.book.personalstage.vo.request.CreateStageJumpRequestVO;
import com.pcloud.book.personalstage.vo.request.UpdateStageJumpRequestVO;
import com.pcloud.book.util.common.YesOrNoEnums;
import com.pcloud.common.core.aspect.ParamLog;
import com.pcloud.common.core.biz.MessageBiz;
import com.pcloud.common.core.dto.SendEmailDto;
import com.pcloud.common.exceptions.BizException;
import com.pcloud.common.page.PageBeanNew;
import com.pcloud.common.page.PageParam;
import com.pcloud.common.utils.DateNewUtils;
import com.pcloud.common.utils.ListUtils;
import com.pcloud.common.utils.NumberUtil;
import com.pcloud.common.utils.string.StringUtil;
import com.pcloud.wechatgroup.group.dto.GroupRobotDTO;
import com.pcloud.wechatgroup.group.dto.GroupUserDTO;
import com.sdk.wxgroup.SendMessageTypeEnum;
import com.sdk.wxgroup.SendTextMessageVO;
import com.sdk.wxgroup.WxGroupSDK;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Component;
import org.springframework.transaction.annotation.Transactional;
import java.util.Date;
import java.util.List;
import java.util.stream.Collectors;
import java.util.HashMap;
import java.util.Map;
@Component("personalStageJumpBiz")
public class PersonalStageJumpBizImpl implements PersonalStageJumpBiz {
private static final Logger LOGGER = LoggerFactory.getLogger(PersonalStageJumpBizImpl.class);
@Autowired
private PersonalStageBiz personalStageBiz;
@Autowired
private PersonalStageJumpDao personalStageJumpDao;
@Autowired
private PersonalStageJumpKeywordDao personalStageJumpKeywordDao;
@Autowired
private PersonalStageJumpEmailDao personalStageJumpEmailDao;
@Autowired
private PersonalStageJumpLinkupDao personalStageJumpLinkupDao;
@Autowired
private PersonalStageUserDao personalStageUserDao;
@Autowired
private WechatGroupConsr wechatGroupConsr;
@Autowired
private WeixinQrcodeBiz weixinQrcodeBiz;
@Autowired
private PcloudRobotDao pcloudRobotDao;
@Autowired
private PcloudRobotClassifyDao pcloudRobotClassifyDao;
@Autowired
private MessageBiz messageBiz;
@Autowired
private PcloudGuideBiz pcloudGuideBiz;
@Override
@ParamLog("新增阶段跳转")
@Transactional(rollbackFor = Exception.class)
public void createPersonalStageJump(CreateStageJumpRequestVO vo) {
//校验关键词是否重复
if (!JumpTypeEnum.PAY_TRIGGER.key.equals(vo.getJumpType())){
this.checkKeywords(vo.getKeywords(), vo.getPersonalStageId(), null);
}
if (vo.getOpenEmail()){
this.checkEmail(vo.getEmails());
}
PersonalStageJump personalStageJump = CreateStageJumpRequestVO.valueToJumpEntity(vo);
personalStageJumpDao.insert(personalStageJump);
List<PersonalStageJumpKeyword> jumpKeywords = BaseStageJumpRequestVO.valueToJumpKeywords(vo, personalStageJump.getId());
if (!ListUtils.isEmpty(jumpKeywords)) {
personalStageJumpKeywordDao.batchInsert(jumpKeywords);
}
List<PersonalStageJumpEmail> jumpEmails = BaseStageJumpRequestVO.valueToJumpEmails(vo, personalStageJump.getId());
if (!ListUtils.isEmpty(jumpEmails)) {
personalStageJumpEmailDao.batchInsert(jumpEmails);
}
List<PersonalStageJumpLinkup> jumpLinkups = BaseStageJumpRequestVO.valueToJumpLinkups(vo, personalStageJump.getId());
if (!ListUtils.isEmpty(jumpLinkups)){
personalStageJumpLinkupDao.batchInsert(jumpLinkups);
}
}
@Override
@ParamLog("获取跳转设置列表")
public PageBeanNew getJumpList(Long personalStageId, Integer currentPage, Integer numPerPage) {
if(!NumberUtil.isNumber(personalStageId) || personalStageId <= 0){
throw new BizException(BizException.PARAM_IS_NULL.getCode(), "personalStageId 值不能为空");
}
HashMap<String, Object> map = Maps.newHashMap();
map.put("personalStageId", personalStageId);
PageBeanNew<PersonalStageJumpDto> pageBeanNew = personalStageJumpDao.listPageNew(new PageParam(currentPage, numPerPage), map, "getJumpList");
List<PersonalStageJumpDto> recordList = pageBeanNew.getRecordList();
if(ListUtils.isEmpty(recordList)){
return pageBeanNew;
}
this.fillJumpKeywords(recordList);
this.fillJumpEmails(recordList);
this.fillJumpLinkups(recordList);
return pageBeanNew;
}
@ParamLog("填充邮件")
private void fillJumpEmails(List<PersonalStageJumpDto> recordList) {
List<Long> jumpIds = recordList.stream().map(x -> x.getId()).collect(Collectors.toList());
HashMap<String, Object> map = Maps.newHashMap();
map.put("jumpIds", jumpIds);
List<PersonalStageJumpEmail> jumpEmails = personalStageJumpEmailDao.listBy(map);
if(ListUtils.isEmpty(jumpEmails)){
return;
}
Map<Long, List<PersonalStageJumpEmail>> mapJumpEmails = jumpEmails.stream().collect(Collectors.groupingBy(x -> x.getPersonalStageJumpId()));
for (PersonalStageJumpDto jumpDto : recordList){
jumpDto.setJumpEmails(mapJumpEmails.getOrDefault(jumpDto.getId(), Lists.newArrayList()));
}
}
@ParamLog("填充跳转衔接语")
private void fillJumpLinkups(List<PersonalStageJumpDto> recordList) {
List<Long> jumpIds = recordList.stream().map(x -> x.getId()).collect(Collectors.toList());
HashMap<String, Object> map = Maps.newHashMap();
map.put("jumpIds", jumpIds);
List<PersonalStageJumpLinkup> linkups = personalStageJumpLinkupDao.listBy(map);
if(ListUtils.isEmpty(linkups)){
return;
}
Map<Long, List<PersonalStageJumpLinkup>> mapJumpLinkups = linkups.stream().collect(Collectors.groupingBy(x -> x.getPersonalStageJumpId()));
for (PersonalStageJumpDto jumpDto : recordList){
jumpDto.setJumpLinkups(mapJumpLinkups.getOrDefault(jumpDto.getId(), Lists.newArrayList()));
}
}
@ParamLog("填充跳转关键字列表")
private void fillJumpKeywords(List<PersonalStageJumpDto> recordList) {
List<Long> jumpIds = recordList.stream().map(x -> x.getId()).collect(Collectors.toList());
HashMap<String, Object> map = Maps.newHashMap();
map.put("jumpIds", jumpIds);
List<PersonalStageJumpKeyword> keywords = personalStageJumpKeywordDao.listBy(map);
if(ListUtils.isEmpty(keywords)){
return;
}
Map<Long, List<PersonalStageJumpKeyword>> mapJumpKeyword = keywords.stream().collect(Collectors.groupingBy(x -> x.getPersonalStageJumpId()));
for (PersonalStageJumpDto jumpDto : recordList){
jumpDto.setJumpKeywords(mapJumpKeyword.getOrDefault(jumpDto.getId(), Lists.newArrayList()));
}
}
@Override
@ParamLog("修改跳转阶段")
public void updatePersonalStageJump(UpdateStageJumpRequestVO vo) {
//校验关键词是否重复
this.checkKeywords(vo.getKeywords(), vo.getPersonalStageId(), vo.getPersonalStageJumpId());
PersonalStageJump personalStageJump = UpdateStageJumpRequestVO.valueToJumpEntity(vo);
personalStageJumpDao.update(personalStageJump);
//删除原有的关键词
personalStageJumpKeywordDao.deleteByJumpId(vo.getPersonalStageJumpId());
//删除原有的邮件地址
personalStageJumpEmailDao.deleteByJumpId(vo.getPersonalStageJumpId());
//删除原有的衔接语
personalStageJumpLinkupDao.deleteByJumpId(vo.getPersonalStageJumpId());
List<PersonalStageJumpKeyword> jumpKeywords = BaseStageJumpRequestVO.valueToJumpKeywords(vo, personalStageJump.getId());
if (!ListUtils.isEmpty(jumpKeywords)){
personalStageJumpKeywordDao.batchInsert(jumpKeywords);
}
List<PersonalStageJumpEmail> jumpEmails = BaseStageJumpRequestVO.valueToJumpEmails(vo, personalStageJump.getId());
if (!ListUtils.isEmpty(jumpEmails)){
personalStageJumpEmailDao.batchInsert(jumpEmails);
}
List<PersonalStageJumpLinkup> jumpLinkups = BaseStageJumpRequestVO.valueToJumpLinkups(vo, personalStageJump.getId());
if (!ListUtils.isEmpty(jumpLinkups)){
personalStageJumpLinkupDao.batchInsert(jumpLinkups);
}
}
@ParamLog("校验跳转关键词")
private void checkKeywords(List<String> keywords, Long personalStageId, Long personalStageJumpId) {
if (ListUtils.isEmpty(keywords)){
throw new BookBizException(BookBizException.ERROR, "跳转关键词不能为空");
}
List<String> words = keywords.stream().distinct().collect(Collectors.toList());
if (keywords.size() != words.size()) {
throw new BookBizException(BookBizException.ERROR, "跳转关键词不能重复");
}
PersonalStageJumpKeyword personalStageJumpKeyword = personalStageJumpKeywordDao.getStageKeywordByKeywords(keywords, personalStageId);
if (null != personalStageJumpKeyword) {
if (null == personalStageJumpId
|| !personalStageJumpId.equals(personalStageJumpKeyword.getPersonalStageJumpId())) {
//如果personalStageJumpId为空,则为新增时校验,否则为修改时校验
throw new BookBizException(BookBizException.ERROR, "跳转关键词不能重复");
}
}
}
@ParamLog("校验邮件地址")
private void checkEmail(List<String> emails){
if (ListUtils.isEmpty(emails)){
throw new BookBizException(BookBizException.ERROR, "邮件地址不能为空");
}
List<String> fEmail = emails.stream().filter(e -> !StringUtil.isEmpty(e)).collect(Collectors.toList());
if (ListUtils.isEmpty(fEmail) || emails.size() != fEmail.size()){
throw new BookBizException(BookBizException.ERROR, "邮件地址不能为空");
}
}
@Override
@ParamLog("根据id获取跳转对象")
public PersonalStageJumpDto getJump(Long jumpId) {
if(!NumberUtil.isNumber(jumpId) || jumpId <= 0){
throw new BizException(BizException.PARAM_IS_NULL.getCode(), "jumpId 值不能为空");
}
PersonalStageJumpDto jumpDto = personalStageJumpDao.getDtoById(jumpId);
if(jumpDto == null){
jumpDto = new PersonalStageJumpDto();
jumpDto.setJumpKeywords(Lists.newArrayList());
jumpDto.setJumpLinkups(Lists.newArrayList());
return jumpDto;
}
this.fillJumpKeywords(Lists.newArrayList(jumpDto));
this.fillJumpEmails(Lists.newArrayList(jumpDto));
this.fillJumpLinkups(Lists.newArrayList(jumpDto));
return jumpDto;
}
@Override
@ParamLog("删除跳转")
public void deleteJump(Long jumpId) {
if(!NumberUtil.isNumber(jumpId) || jumpId <= 0){
throw new BizException(BizException.PARAM_IS_NULL.getCode(), "jumpId 值不能为空");
}
// 删除跳转
personalStageJumpDao.deleteById(jumpId);
// 删除关键字
personalStageJumpKeywordDao.deleteByJumpId(jumpId);
// 删除邮件
personalStageJumpEmailDao.deleteByJumpId(jumpId);
}
@Override
@ParamLog("开启关闭邮件提醒")
public Long updateEmailStatus(Long jumpId, Integer openEmail) {
if(!NumberUtil.isNumber(jumpId) || jumpId <= 0){
throw new BizException(BizException.PARAM_IS_NULL.getCode(), "jumpId 值不能为空");
}
PersonalStageJump jump = new PersonalStageJump();
jump.setId(jumpId);
jump.setOpenEmail(YesOrNoEnums.YES.getValue().equals(openEmail));
return personalStageJumpDao.update(jump);
}
/**
*
* @param userWxId
* @param robotWxId
* @param content
* @return false:未能跳转到下个阶段,需要后续的其它处理;
* true:命中关键字,已经跳转到下个阶段,无需后续处理;
*/
@Override
@ParamLog("处理用户阶段跳转逻辑")
@Transactional(rollbackFor = Exception.class)
public Boolean handlePersonalStageJump(String userWxId, String robotWxId, String content, JumpTypeEnum jumpTypeEnum) {
// 查询用户的当前状态信息
PersonalStageUser currentStageUser = personalStageUserDao.getLast(userWxId, robotWxId, null);
// 如果用户没有阶段状态,则不处理
if(currentStageUser == null || currentStageUser.getId() <= 0) {
return false;
}
// TODO 判断消息的阶段是否和用户当前阶段匹配,如果不匹配需要当做已处理状态返回,以免触发后续其它操作
// (此操作需要建立在用户的消息有阶段id的情况下)
// if(personalStageId != currentStageUser.getPersonalStageId()) { return true; }
// 查询命中关键字跳转下一阶段的id
PersonalStageJumpKeywordDto jumpKeywordDto = personalStageJumpKeywordDao.getByKeyword(currentStageUser.getPersonalStageId(), content, jumpTypeEnum.key);
if(null == jumpKeywordDto || StringUtil.isEmpty(jumpKeywordDto.getKeyword())){
// 未能命中关键词
return false;
}
// 如果下一个阶段是空,则已完成
if(null == jumpKeywordDto.getAfterPersonalStageId() || jumpKeywordDto.getAfterPersonalStageId() <=0){
// 更新到完成状态
updateStageToComplete(currentStageUser);
return true;
}
GroupRobotDTO groupRobotDTO = wechatGroupConsr.getGroupRobotByWxId(robotWxId);
String ip = weixinQrcodeBiz.getRobotIpByGeneration(groupRobotDTO.getVersion());
// 发送邮件
sendEmail(userWxId, robotWxId, content, jumpKeywordDto);
// 将用户置为下个阶段
personalStageBiz.nextStageAddStageUserAndWakeupDelay(robotWxId, userWxId, ip, jumpKeywordDto.getAfterPersonalStageId());
// 发送内容衔接语
sendJumpLinkups(userWxId, robotWxId, ip, jumpKeywordDto.getPersonalStageJumpId());
// 停止发送引导语
pcloudGuideBiz.stopPcloudGuidePush(robotWxId, userWxId);
return true;
}
@ParamLog("发送阶段跳转邮件")
private void sendEmail(String userWxId, String robotWxId, String content, PersonalStageJumpKeywordDto jumpKeywordDto) {
try {
List<PersonalStageJumpEmail> jumpEmails = personalStageJumpEmailDao.getByJumpId(jumpKeywordDto.getPersonalStageJumpId());
if(ListUtils.isEmpty(jumpEmails)){
return;
}
GroupUserDTO wxUserInfo = wechatGroupConsr.getWxUserInfoByWxUserId(userWxId);
if(wxUserInfo==null){
LOGGER.info("未找到用户信息,无法发送阶段跳转邮件");
}
PcloudRobot pcloudRobot = pcloudRobotDao.getByWxId(robotWxId);
PcloudRobotClassify robotClassify = pcloudRobotClassifyDao.getById(pcloudRobot.getRobotType().longValue());
if (robotClassify == null|| robotClassify.getKeywordClassifyId() == null){
LOGGER.info("小号分类id为空,无法发送阶段跳转邮件");
return;
}
PersonalStage personalStage = personalStageBiz.getPersonalStage(jumpKeywordDto.getAfterPersonalStageId());
if (personalStage == null || StringUtil.isEmpty(personalStage.getName())){
LOGGER.info("未找到阶段信息,无法发送阶段跳转邮件");
return;
}
for (PersonalStageJumpEmail email : jumpEmails){
sendStageChangeEmail(email.getEmail(), content, wxUserInfo.getNickName(), userWxId, robotClassify.getClassifyName(), pcloudRobot.getUniqueNumber(), robotWxId, personalStage.getName());
}
} catch (Exception e){
LOGGER.info("阶段跳转邮件发送失败:" + e.getMessage(), e);
}
}
/**
* 发送阶段流转邮件
* @param toEmail 接收人邮件
* @param customizedService 定制服务需求(即触发阶段流转的关键词)
* @param nickname 读者昵称
* @param wxUserId 读者ID
* @param robotClassifyName 小号分类名称
* @param robotNumber 小号编号
* @param robotId 小号ID
* @param afterStageName 流转后阶段名称
*/
public void sendStageChangeEmail(String toEmail, String customizedService, String nickname, String wxUserId,
String robotClassifyName, String robotNumber, String robotId, String afterStageName) {
try {
SendEmailDto sendEmailDto = new SendEmailDto();
sendEmailDto.setToEmail(toEmail);
sendEmailDto.setTypeCode("stage_change_notice");
Map<String, Object> content = new HashMap<>();
content.put("customizedService", customizedService);
content.put("nickname", nickname);
content.put("wxUserId", wxUserId);
content.put("robotClassifyName", robotClassifyName);
content.put("robotNumber", robotNumber);
content.put("robotId", robotId);
content.put("afterStageName", afterStageName);
content.put("time", DateNewUtils.getLongDateStr());
sendEmailDto.setContent(content);
messageBiz.sendEmail(sendEmailDto);
} catch (Exception e) {
LOGGER.error("发送阶段流转邮件出错:" + e.getMessage(), e);
}
}
@ParamLog("发送内容衔接语")
private void sendJumpLinkups(String userWxId, String robotWxId, String ip, Long jumpId) {
List<PersonalStageJumpLinkup> linkups = personalStageJumpLinkupDao.getByJumpId(jumpId);
if(ListUtils.isEmpty(linkups)){
return;
}
for (PersonalStageJumpLinkup jumpLinkup : linkups){
SendTextMessageVO sendTextMessageVO = new SendTextMessageVO();
sendTextMessageVO.setContent(jumpLinkup.getLinkupContent());
sendTextMessageVO.setAltId(robotWxId);
sendTextMessageVO.setWxGroupId(userWxId);
sendTextMessageVO.setIp(ip);
sendTextMessageVO.setCode(SendMessageTypeEnum.SELF.getCode());
WxGroupSDK.sendTextMessage(sendTextMessageVO);
}
}
@ParamLog("更新到完成状态")
private void updateStageToComplete(PersonalStageUser currentStageUser) {
PersonalStageUser updateStageUser = new PersonalStageUser();
updateStageUser.setId(currentStageUser.getId());
updateStageUser.setState(PersonalStageUserStateEnum.FINISH.value);
updateStageUser.setUpdateTime(new Date());
personalStageUserDao.update(updateStageUser);
}
}
package com.pcloud.book.personalstage.check;
import com.pcloud.book.base.exception.BookBizException;
import com.pcloud.book.keywords.enums.ReplyTypeEnum;
import com.pcloud.book.personalstage.entity.PersonalStage;
import com.pcloud.book.personalstage.entity.PersonalStageReply;
import com.pcloud.book.personalstage.entity.PersonalStageReplyItem;
import com.pcloud.book.personalstage.entity.PersonalStageWakeup;
import com.pcloud.common.core.aspect.ParamLog;
import com.pcloud.common.utils.ListUtils;
import com.pcloud.common.utils.string.StringUtil;
import org.springframework.stereotype.Component;
import java.util.List;
@Component("定制化参数校验")
public class PersonalStageCheck {
@ParamLog("新增定制化阶段参数校验")
public void createPersonalStageParamCheck(PersonalStage personalStage) {
if (personalStage==null){
throw new BookBizException(BookBizException.PARAM_IS_ERROR,"定制化阶段不能为空!");
}
if (personalStage.getRobotClassifyId()==null){
throw new BookBizException(BookBizException.PARAM_IS_ERROR,"关键词分类不能为空!");
}
if (StringUtil.isEmpty(personalStage.getName())){
throw new BookBizException(BookBizException.PARAM_IS_ERROR,"阶段名称不能为空!");
}
if (personalStage.getNotKeywordFusingCount()==null){
throw new BookBizException(BookBizException.PARAM_IS_ERROR,"发送阶段非关键词回复语次数不能为空!");
}
if (personalStage.getNotKeywordFusingTime()==null){
throw new BookBizException(BookBizException.PARAM_IS_ERROR,"触发熔断后几分钟恢复正常不能为空!");
}
if (ListUtils.isEmpty(personalStage.getStageNotKeywordReplies())){
throw new BookBizException(BookBizException.PARAM_IS_ERROR,"阶段非关键词回复集合不能为空!");
}
checkReplies(personalStage.getStageNotKeywordReplies());
if (ListUtils.isEmpty(personalStage.getFusingNotKeywordReplies())){
throw new BookBizException(BookBizException.PARAM_IS_ERROR,"熔断非关键词恢复集合不能为空!");
}
checkReplies(personalStage.getFusingNotKeywordReplies());
if (!ListUtils.isEmpty(personalStage.getPersonalStageWakeups())){
checkWakeups(personalStage.getPersonalStageWakeups());
}
}
@ParamLog("校验唤醒")
private void checkWakeups(List<PersonalStageWakeup> list) {
for (PersonalStageWakeup wakeup:list){
if (wakeup==null){
throw new BookBizException(BookBizException.PARAM_IS_ERROR,"唤醒不能为空!");
}
if (wakeup.getToStageStartTime()==null){
throw new BookBizException(BookBizException.PARAM_IS_ERROR,"距离进入阶段时间不能为空!");
}
if (ListUtils.isEmpty(wakeup.getWakeupReplies())){
throw new BookBizException(BookBizException.PARAM_IS_ERROR,"唤醒回复集合不能为空!");
}
checkReplies(wakeup.getWakeupReplies());
}
}
@ParamLog("校验回复")
private void checkReplies(List<PersonalStageReply> list) {
for (PersonalStageReply reply:list){
if (reply==null){
throw new BookBizException(BookBizException.PARAM_IS_ERROR,"回复不能为空!");
}
if (StringUtil.isEmpty(reply.getName())){
throw new BookBizException(BookBizException.PARAM_IS_ERROR,"回复名称不能为空!");
}
if (ListUtils.isEmpty(reply.getPersonalStageReplyItems())){
throw new BookBizException(BookBizException.PARAM_IS_ERROR,"回复项集合不能为空!");
}
checkReplayItems(reply.getPersonalStageReplyItems());
}
}
@ParamLog("校验回复项")
private void checkReplayItems(List<PersonalStageReplyItem> list) {
for (PersonalStageReplyItem item:list){
if (item==null){
throw new BookBizException(BookBizException.PARAM_IS_ERROR,"回复项不能为空!");
}
if (item.getReplyType()==null){
throw new BookBizException(BookBizException.PARAM_IS_ERROR,"回复项类型不能为空!");
}
if (ReplyTypeEnum.TEXT.value.equals(item.getReplyType())&&StringUtil.isEmpty(item.getContent())){
throw new BookBizException(BookBizException.PARAM_IS_ERROR,"回复项内容不能为空!");
}
if (ReplyTypeEnum.IMAGE.value.equals(item.getReplyType())&&StringUtil.isEmpty(item.getPicUrl())){
throw new BookBizException(BookBizException.PARAM_IS_ERROR,"回复项图片不能为空!");
}
}
}
@ParamLog("修改定制化阶段参数校验")
public void updatePersonalStageParamCheck(PersonalStage personalStage) {
if (personalStage==null){
throw new BookBizException(BookBizException.PARAM_IS_ERROR,"定制化阶段不能为空!");
}
if (personalStage.getId()==null){
throw new BookBizException(BookBizException.PARAM_IS_ERROR,"定制化阶段id不能为空!");
}
createPersonalStageParamCheck(personalStage);
}
}
package com.pcloud.book.personalstage.constant;
public class PersonalStageConstant {
public static final String PERSONALSTAGE_DELAY_WAKEUP="PERSONALSTAGE_DELAY_WAKEUP";
public static final String PERSONALSTAGE_DELAY_FUSING="PERSONALSTAGE_DELAY_FUSING";
}
package com.pcloud.book.personalstage.dao;
import com.pcloud.book.personalstage.dto.PersonalStageDTO;
import com.pcloud.book.personalstage.entity.PersonalStage;
import com.pcloud.common.core.dao.BaseDao;
import java.util.List;
public interface PersonalStageDao extends BaseDao<PersonalStage> {
void updateSeqNum(Long id, Integer seqNum);
Integer getMaxSeqNum();
Integer getCountByRobotClassifyId(Long robotClassifyId);
PersonalStage getFirstStage(Long robotClassifyId);
List<PersonalStageDTO> getPersonalStageList(Long robotClassifyId);
}
\ No newline at end of file
package com.pcloud.book.personalstage.dao;
import com.pcloud.book.personalstage.dto.PersonalStageJumpDto;
import com.pcloud.book.personalstage.entity.PersonalStageJump;
import com.pcloud.common.core.dao.BaseDao;
public interface PersonalStageJumpDao extends BaseDao<PersonalStageJump> {
Integer getCountByPersonalStageId(Long personalStageId);
PersonalStageJumpDto getDtoById(Long jumpId);
}
\ No newline at end of file
package com.pcloud.book.personalstage.dao;
import com.pcloud.book.personalstage.entity.PersonalStageJumpEmail;
import com.pcloud.common.core.dao.BaseDao;
import java.util.List;
public interface PersonalStageJumpEmailDao extends BaseDao<PersonalStageJumpEmail> {
/**
* 批量新增
* @param personalStageJumpEmails
*/
void batchInsert(List<PersonalStageJumpEmail> personalStageJumpEmails);
List<PersonalStageJumpEmail> getByJumpId(Long jumpId);
/**
* 根据阶段跳转id删除
* @param jumpId
*/
void deleteByJumpId(Long jumpId);
}
\ No newline at end of file
package com.pcloud.book.personalstage.dao;
import com.pcloud.book.personalstage.dto.PersonalStageJumpKeywordDto;
import com.pcloud.book.personalstage.entity.PersonalStageJumpKeyword;
import com.pcloud.common.core.dao.BaseDao;
import java.util.List;
public interface PersonalStageJumpKeywordDao extends BaseDao<PersonalStageJumpKeyword> {
/**
* 获取阶段内一个重复关键词
* @param keywords
* @return
*/
PersonalStageJumpKeyword getStageKeywordByKeywords(List<String> keywords, Long personalStageId);
/**
* 批量添加
* @param personalStageJumpKeywords
*/
void batchInsert(List<PersonalStageJumpKeyword> personalStageJumpKeywords);
/**
* 根据阶段跳转id删除
* @param jumpId
*/
void deleteByJumpId(Long jumpId);
/**
* 查询命中的关键字
* @param personalStageId
* @param content
* @param jumpType
* @return
*/
PersonalStageJumpKeywordDto getByKeyword(Long personalStageId, String content, Integer jumpType);
}
\ No newline at end of file
package com.pcloud.book.personalstage.dao;
import com.pcloud.book.personalstage.entity.PersonalStageJumpLinkup;
import com.pcloud.common.core.dao.BaseDao;
import java.util.List;
public interface PersonalStageJumpLinkupDao extends BaseDao<PersonalStageJumpLinkup> {
/**
* 批量新增
* @param personalStageJumpLinkups
*/
void batchInsert(List<PersonalStageJumpLinkup> personalStageJumpLinkups);
/**
* 根据阶段跳转id删除
* @param personalStageJumpId
*/
void deleteByJumpId(Long personalStageJumpId);
/**
* 根据跳转id查询衔接语列表
* @param jumpId
* @return
*/
List<PersonalStageJumpLinkup> getByJumpId(Long jumpId);
}
\ No newline at end of file
package com.pcloud.book.personalstage.dao;
import com.pcloud.book.personalstage.entity.PersonalStageReply;
import com.pcloud.common.core.dao.BaseDao;
import java.util.List;
public interface PersonalStageReplyDao extends BaseDao<PersonalStageReply> {
Integer batchInsert(List<PersonalStageReply> list);
List<Long> getIdsByPersonalStageId(Long personalStageId);
void deleteByIds(List<Long> list);
List<PersonalStageReply> getListByPersonalStageId(Long personalStageId);
List<Long> getIdsByRelevance(Integer relevanceType, Long relevanceId);
}
\ No newline at end of file
package com.pcloud.book.personalstage.dao;
import com.pcloud.book.personalstage.entity.PersonalStageReplyItem;
import com.pcloud.common.core.dao.BaseDao;
import java.util.List;
public interface PersonalStageReplyItemDao extends BaseDao<PersonalStageReplyItem> {
Integer batchInsert(List<PersonalStageReplyItem> list);
void deleteByReplyIds(List<Long> list);
List<PersonalStageReplyItem> getListByReplyIds(List<Long> list);
}
\ No newline at end of file
package com.pcloud.book.personalstage.dao;
import com.pcloud.book.personalstage.entity.PersonalStageUser;
import com.pcloud.common.core.dao.BaseDao;
public interface PersonalStageUserDao extends BaseDao<PersonalStageUser> {
PersonalStageUser getLast(String wxId, String robotId, Long personalStageId);
}
\ No newline at end of file
package com.pcloud.book.personalstage.dao;
import com.pcloud.book.personalstage.entity.PersonalStageWakeup;
import com.pcloud.common.core.dao.BaseDao;
import java.util.List;
public interface PersonalStageWakeupDao extends BaseDao<PersonalStageWakeup> {
Integer batchInsert(List<PersonalStageWakeup> list);
void deleteByPersonalStageId(Long personalStageId);
List<PersonalStageWakeup> getListByPersonalStageId(Long personalStageId);
PersonalStageWakeup getFirstWakeup(Long personalStageId);
}
\ No newline at end of file
package com.pcloud.book.personalstage.dao.impl;
import com.pcloud.book.personalstage.dao.PersonalStageDao;
import com.pcloud.book.personalstage.dto.PersonalStageDTO;
import com.pcloud.book.personalstage.entity.PersonalStage;
import com.pcloud.common.core.dao.BaseDaoImpl;
import org.springframework.stereotype.Component;
import java.util.HashMap;
import java.util.List;
import java.util.Map;
@Component("personalStage")
public class PersonalStageDaoImpl extends BaseDaoImpl<PersonalStage> implements PersonalStageDao {
@Override
public void updateSeqNum(Long id, Integer seqNum) {
Map<String,Object> map=new HashMap<>();
map.put("id",id);
map.put("seqNum",seqNum);
super.getSqlSession().update(getStatement("updateSeqNum"), map);
}
@Override
public Integer getMaxSeqNum() {
return super.getSqlSession().selectOne(getStatement("getMaxSeqNum"));
}
@Override
public Integer getCountByRobotClassifyId(Long robotClassifyId) {
return super.getSqlSession().selectOne(getStatement("getCountByRobotClassifyId"), robotClassifyId);
}
@Override
public PersonalStage getFirstStage(Long robotClassifyId) {
return super.getSqlSession().selectOne(getStatement("getFirstStage"), robotClassifyId);
}
@Override
public List<PersonalStageDTO> getPersonalStageList(Long robotClassifyId) {
Map<String, Object> paramMap = new HashMap<>();
paramMap.put("robotClassifyId", robotClassifyId);
return super.getSqlSession().selectList(getStatement("getPersonalStageList"), paramMap);
}
}
package com.pcloud.book.personalstage.dao.impl;
import com.pcloud.book.personalstage.dao.PersonalStageJumpDao;
import com.pcloud.book.personalstage.dto.PersonalStageJumpDto;
import com.pcloud.book.personalstage.entity.PersonalStageJump;
import com.pcloud.common.core.dao.BaseDaoImpl;
import org.springframework.stereotype.Component;
@Component("personalStageJump")
public class PersonalStageJumpDaoImpl extends BaseDaoImpl<PersonalStageJump> implements PersonalStageJumpDao {
@Override
public Integer getCountByPersonalStageId(Long personalStageId) {
return super.getSqlSession().selectOne(getStatement("getCountByPersonalStageId"), personalStageId);
}
@Override
public PersonalStageJumpDto getDtoById(Long jumpId) {
return super.getSqlSession().selectOne(getStatement("getDtoById"), jumpId);
}
}
package com.pcloud.book.personalstage.dao.impl;
import com.pcloud.book.personalstage.dao.PersonalStageJumpEmailDao;
import com.pcloud.book.personalstage.entity.PersonalStageJumpEmail;
import com.pcloud.common.core.dao.BaseDaoImpl;
import org.springframework.stereotype.Component;
import java.util.List;
@Component("personalStageJumpEmail")
public class PersonalStageJumpEmailDaoImpl extends BaseDaoImpl<PersonalStageJumpEmail> implements PersonalStageJumpEmailDao {
@Override
public void batchInsert(List<PersonalStageJumpEmail> personalStageJumpEmails) {
super.getSessionTemplate().insert(getStatement("batchInsert"), personalStageJumpEmails);
}
@Override
public List<PersonalStageJumpEmail> getByJumpId(Long jumpId) {
return super.getSqlSession().selectList(getStatement("getByJumpId"), jumpId);
}
@Override
public void deleteByJumpId(Long jumpId) {
super.getSqlSession().delete(getStatement("deleteByJumpId"), jumpId);
}
}
package com.pcloud.book.personalstage.dao.impl;
import com.pcloud.book.personalstage.dao.PersonalStageJumpKeywordDao;
import com.pcloud.book.personalstage.dto.PersonalStageJumpKeywordDto;
import com.pcloud.book.personalstage.entity.PersonalStageJumpKeyword;
import com.pcloud.common.core.dao.BaseDaoImpl;
import org.springframework.stereotype.Component;
import java.util.HashMap;
import java.util.List;
import java.util.Map;
@Component("personalStageJumpKeyword")
public class PersonalStageJumpKeywordDaoImpl extends BaseDaoImpl<PersonalStageJumpKeyword> implements PersonalStageJumpKeywordDao {
@Override
public PersonalStageJumpKeyword getStageKeywordByKeywords(List<String> keywords, Long personalStageId) {
Map<String, Object> paramMap = new HashMap<>();
paramMap.put("keywords", keywords);
paramMap.put("personalStageId", personalStageId);
return super.getSessionTemplate().selectOne(getStatement("getStageKeywordByKeywords"), paramMap);
}
@Override
public void batchInsert(List<PersonalStageJumpKeyword> personalStageJumpKeywords) {
super.getSessionTemplate().insert(getStatement("batchInsert"), personalStageJumpKeywords);
}
@Override
public void deleteByJumpId(Long jumpId) {
super.getSqlSession().delete(getStatement("deleteByJumpId"), jumpId);
}
@Override
public PersonalStageJumpKeywordDto getByKeyword(Long personalStageId, String keyword, Integer jumpType) {
Map<String, Object> paramMap = new HashMap<>();
paramMap.put("keyword", keyword);
paramMap.put("personalStageId", personalStageId);
paramMap.put("jumpType", jumpType);
return super.getSessionTemplate().selectOne(getStatement("getByKeyword"), paramMap);
}
}
package com.pcloud.book.personalstage.dao.impl;
import com.pcloud.book.personalstage.dao.PersonalStageJumpLinkupDao;
import com.pcloud.book.personalstage.entity.PersonalStageJumpLinkup;
import com.pcloud.common.core.dao.BaseDaoImpl;
import org.springframework.stereotype.Component;
import java.util.List;
@Component("personalStageJumpLinkup")
public class PersonalStageJumpLinkupDaoImpl extends BaseDaoImpl<PersonalStageJumpLinkup> implements PersonalStageJumpLinkupDao {
@Override
public void batchInsert(List<PersonalStageJumpLinkup> personalStageJumpLinkups) {
super.getSessionTemplate().insert(getStatement("batchInsert"), personalStageJumpLinkups);
}
@Override
public void deleteByJumpId(Long personalStageJumpId) {
super.sqlSessionTemplate.delete(getStatement("deleteByJumpId"), personalStageJumpId);
}
@Override
public List<PersonalStageJumpLinkup> getByJumpId(Long jumpId) {
return super.sqlSessionTemplate.selectList(getStatement("getByJumpId"), jumpId);
}
}
package com.pcloud.book.personalstage.dao.impl;
import com.pcloud.book.personalstage.dao.PersonalStageReplyDao;
import com.pcloud.book.personalstage.entity.PersonalStageReply;
import com.pcloud.common.core.dao.BaseDaoImpl;
import org.springframework.stereotype.Component;
import java.util.HashMap;
import java.util.List;
import java.util.Map;
@Component("personalStageReply")
public class PersonalStageReplyDaoImpl extends BaseDaoImpl<PersonalStageReply> implements PersonalStageReplyDao {
@Override
public Integer batchInsert(List<PersonalStageReply> list) {
return super.getSqlSession().insert(getStatement("batchInsert"), list);
}
@Override
public List<Long> getIdsByPersonalStageId(Long personalStageId) {
return super.getSqlSession().selectList(getStatement("getIdsByPersonalStageId"), personalStageId);
}
@Override
public void deleteByIds(List<Long> list) {
super.getSqlSession().delete(getStatement("deleteByIds"), list);
}
@Override
public List<PersonalStageReply> getListByPersonalStageId(Long personalStageId) {
return super.getSqlSession().selectList(getStatement("getListByPersonalStageId"), personalStageId);
}
@Override
public List<Long> getIdsByRelevance(Integer relevanceType, Long relevanceId) {
Map<String, Object> map = new HashMap<>();
map.put("relevanceType", relevanceType);
map.put("relevanceId", relevanceId);
return super.getSessionTemplate().selectList(getStatement("getIdsByRelevance"), map);
}
}
package com.pcloud.book.personalstage.dao.impl;
import com.pcloud.book.personalstage.dao.PersonalStageReplyItemDao;
import com.pcloud.book.personalstage.entity.PersonalStageReplyItem;
import com.pcloud.common.core.dao.BaseDaoImpl;
import org.springframework.stereotype.Component;
import java.util.List;
@Component("personalStageReplyItem")
public class PersonalStageReplyItemDaoImpl extends BaseDaoImpl<PersonalStageReplyItem> implements PersonalStageReplyItemDao {
@Override
public Integer batchInsert(List<PersonalStageReplyItem> list) {
return super.getSqlSession().insert(getStatement("batchInsert"), list);
}
@Override
public void deleteByReplyIds(List<Long> list) {
super.getSqlSession().delete(getStatement("deleteByReplyIds"), list);
}
@Override
public List<PersonalStageReplyItem> getListByReplyIds(List<Long> list) {
return super.getSqlSession().selectList(getStatement("getListByReplyIds"), list);
}
}
package com.pcloud.book.personalstage.dao.impl;
import com.pcloud.book.personalstage.dao.PersonalStageUserDao;
import com.pcloud.book.personalstage.entity.PersonalStageUser;
import com.pcloud.common.core.dao.BaseDaoImpl;
import org.springframework.stereotype.Component;
import java.util.HashMap;
import java.util.Map;
@Component("personalStageUser")
public class PersonalStageUserDaoImpl extends BaseDaoImpl<PersonalStageUser> implements PersonalStageUserDao {
@Override
public PersonalStageUser getLast(String wxId, String robotId, Long personalStageId) {
Map<String, Object> map = new HashMap<>();
map.put("wxId", wxId);
map.put("robotId", robotId);
map.put("personalStageId", personalStageId);
return super.getSessionTemplate().selectOne(getStatement("getLast"), map);
}
}
package com.pcloud.book.personalstage.dao.impl;
import com.pcloud.book.personalstage.dao.PersonalStageWakeupDao;
import com.pcloud.book.personalstage.entity.PersonalStageWakeup;
import com.pcloud.common.core.dao.BaseDaoImpl;
import org.springframework.stereotype.Component;
import java.util.List;
@Component("personalStageWakeup")
public class PersonalStageWakeupDaoImpl extends BaseDaoImpl<PersonalStageWakeup> implements PersonalStageWakeupDao {
@Override
public Integer batchInsert(List<PersonalStageWakeup> list) {
return super.getSqlSession().insert(getStatement("batchInsert"), list);
}
@Override
public void deleteByPersonalStageId(Long personalStageId) {
super.getSqlSession().delete(getStatement("deleteByPersonalStageId"), personalStageId);
}
@Override
public List<PersonalStageWakeup> getListByPersonalStageId(Long personalStageId) {
return super.getSqlSession().selectList(getStatement("getListByPersonalStageId"), personalStageId);
}
@Override
public PersonalStageWakeup getFirstWakeup(Long personalStageId) {
return super.getSqlSession().selectOne(getStatement("getFirstWakeup"), personalStageId);
}
}
package com.pcloud.book.personalstage.dto;
import io.swagger.annotations.ApiModel;
import io.swagger.annotations.ApiModelProperty;
import lombok.Data;
import java.io.Serializable;
/**
* 熔断结束延迟DTO
* @author PENG
* @date 2020年2月22日11:08:01
*/
@Data
@ApiModel("熔断结束延迟DTO")
public class FusingFinishDelayDTO implements Serializable {
private static final long serialVersionUID = 8383714211800627924L;
@ApiModelProperty("阶段用户id")
private Long personalStageUserId;
@ApiModelProperty("定制化阶段id")
private Long personalStageId;
@ApiModelProperty("机器人id")
private String robotId;
@ApiModelProperty("用户wxId")
private String wxId;
@ApiModelProperty("ip地址")
private String ip;
}
package com.pcloud.book.personalstage.dto;
import com.fasterxml.jackson.annotation.JsonFormat;
import com.pcloud.common.dto.BaseDto;
import com.pcloud.common.entity.BaseEntity;
import io.swagger.annotations.ApiModel;
import io.swagger.annotations.ApiModelProperty;
import lombok.Data;
import java.util.Date;
@ApiModel("定制化阶段")
@Data
public class PersonalStageDTO extends BaseDto {
private static final long serialVersionUID = -5560187538777872008L;
@ApiModelProperty("阶段id")
private Long id;
@ApiModelProperty("阶段名称")
private String name;
@ApiModelProperty("发送阶段非关键词回复语次数")
private Integer notKeywordFusingCount;
@ApiModelProperty("触发熔断后几分钟恢复正常")
private Long notKeywordFusingTime;
@ApiModelProperty("机器人分类id")
private Long robotClassifyId;
@ApiModelProperty("排序值")
private Integer seqNum;
@ApiModelProperty("非关键词回复条数")
private Integer notKeywordReplyCount;
@ApiModelProperty("非关键词熔断回复条数")
private Integer notKeywordFusingReplyCount;
@ApiModelProperty("创建时间")
@JsonFormat(pattern = "yyyy-MM-dd HH:mm:ss", timezone = "GMT+8")
private Date createTime;
}
\ No newline at end of file
package com.pcloud.book.personalstage.dto;
import com.pcloud.book.personalstage.entity.PersonalStage;
import com.pcloud.book.personalstage.entity.PersonalStageJumpEmail;
import com.pcloud.book.personalstage.entity.PersonalStageJumpKeyword;
import com.pcloud.book.personalstage.entity.PersonalStageJumpLinkup;
import io.swagger.annotations.ApiModelProperty;
import lombok.Data;
import java.io.Serializable;
import java.util.List;
/**
* 定制化阶段跳转(PersonalStageJump)实体类
*
* @author makejava
* @since 2020-02-20 14:06:05
*/
@Data
public class PersonalStageJumpDto implements Serializable {
@ApiModelProperty("跳转id")
private Long id;
@ApiModelProperty("定制化阶段id")
private Long personalStageId;
@ApiModelProperty("跳转类型:1读者输入关键词触发,2小睿发送关键词触发,3转账触发")
private Integer jumpType;
@ApiModelProperty("跳转后阶段id")
private Long afterPersonalStageId;
@ApiModelProperty("是否开启邮件提醒")
private Boolean openEmail;
@ApiModelProperty("转账说明")
private String transferMessage;
@ApiModelProperty("转账金额")
private Double transferMoney;
@ApiModelProperty("定制化阶段名称")
private String personalStageName;
@ApiModelProperty("跳转关键词文案列表")
private List<PersonalStageJumpKeyword> jumpKeywords;
@ApiModelProperty("邮件列表")
private List<PersonalStageJumpEmail> jumpEmails;
@ApiModelProperty("衔接语")
private List<PersonalStageJumpLinkup> jumpLinkups;
}
\ No newline at end of file
package com.pcloud.book.personalstage.dto;
import com.pcloud.common.entity.BaseEntity;
import io.swagger.annotations.ApiModel;
import io.swagger.annotations.ApiModelProperty;
import lombok.Data;
@ApiModel("定制化阶段跳转关键词")
@Data
public class PersonalStageJumpKeywordDto extends BaseEntity {
private Long id;
@ApiModelProperty("阶段id")
private Long personalStageId;
@ApiModelProperty("定制化阶段跳转id")
private Long personalStageJumpId;
@ApiModelProperty("关键词")
private String keyword;
@ApiModelProperty("跳转类型:1读者输入关键词触发,2小睿发送关键词触发,3转账触发")
private Integer jumpType;
@ApiModelProperty("跳转后阶段id")
private Long afterPersonalStageId;
}
\ No newline at end of file
package com.pcloud.book.personalstage.dto;
import io.swagger.annotations.ApiModel;
import io.swagger.annotations.ApiModelProperty;
import lombok.Data;
import java.io.Serializable;
@Data
@ApiModel("唤醒延时dto")
public class WakeupDelayDTO implements Serializable {
@ApiModelProperty("唤醒id")
private Long personalStageWakeupId;
@ApiModelProperty("定制化阶段id")
private Long personalStageId;
@ApiModelProperty("机器人id")
private String robotId;
@ApiModelProperty("用户wxId")
private String wxId;
@ApiModelProperty("ip地址")
private String ip;
}
package com.pcloud.book.personalstage.entity;
import com.pcloud.common.entity.BaseEntity;
import io.swagger.annotations.ApiModel;
import io.swagger.annotations.ApiModelProperty;
import lombok.Data;
import java.util.List;
@ApiModel("定制化阶段")
@Data
public class PersonalStage extends BaseEntity {
@ApiModelProperty("阶段名称")
private String name;
@ApiModelProperty("发送阶段非关键词回复语次数")
private Integer notKeywordFusingCount;
@ApiModelProperty("触发熔断后几分钟恢复正常")
private Long notKeywordFusingTime;
@ApiModelProperty("机器人分类id")
private Long robotClassifyId;
@ApiModelProperty("排序值")
private Integer seqNum;
@ApiModelProperty("阶段非关键词回复集合")
private List<PersonalStageReply> stageNotKeywordReplies;
@ApiModelProperty("熔断非关键词恢复集合")
private List<PersonalStageReply> fusingNotKeywordReplies;
@ApiModelProperty("唤醒设置集合")
private List<PersonalStageWakeup> personalStageWakeups;
}
\ No newline at end of file
package com.pcloud.book.personalstage.entity;
import com.pcloud.common.entity.BaseEntity;
import io.swagger.annotations.ApiModel;
import io.swagger.annotations.ApiModelProperty;
import lombok.Data;
@ApiModel("定制化阶段跳转")
@Data
public class PersonalStageJump extends BaseEntity {
@ApiModelProperty("定制化阶段id")
private Long personalStageId;
@ApiModelProperty("跳转类型:1读者输入关键词触发,2小睿发送关键词触发,3转账触发")
private Integer jumpType;
@ApiModelProperty("跳转后阶段id")
private Long afterPersonalStageId;
@ApiModelProperty("是否开启邮件提醒")
private Boolean openEmail;
@ApiModelProperty("转账说明")
private String transferMessage;
@ApiModelProperty("转账金额")
private Double transferMoney;
}
\ No newline at end of file
package com.pcloud.book.personalstage.entity;
import com.pcloud.common.entity.BaseEntity;
import io.swagger.annotations.ApiModel;
import io.swagger.annotations.ApiModelProperty;
import lombok.Data;
@ApiModel("定制化阶段跳转邮件")
@Data
public class PersonalStageJumpEmail extends BaseEntity {
@ApiModelProperty("定制化阶段跳转id")
private Long personalStageJumpId;
@ApiModelProperty("邮件")
private String email;
}
\ No newline at end of file
package com.pcloud.book.personalstage.entity;
import com.pcloud.common.entity.BaseEntity;
import io.swagger.annotations.ApiModel;
import io.swagger.annotations.ApiModelProperty;
import lombok.Data;
@ApiModel("定制化阶段跳转关键词")
@Data
public class PersonalStageJumpKeyword extends BaseEntity {
@ApiModelProperty("阶段id")
private Long personalStageId;
@ApiModelProperty("定制化阶段跳转id")
private Long personalStageJumpId;
@ApiModelProperty("关键词")
private String keyword;
}
\ No newline at end of file
package com.pcloud.book.personalstage.entity;
import com.pcloud.common.entity.BaseEntity;
import io.swagger.annotations.ApiModel;
import io.swagger.annotations.ApiModelProperty;
import lombok.Data;
@ApiModel("定制化阶段跳转衔接语")
@Data
public class PersonalStageJumpLinkup extends BaseEntity {
@ApiModelProperty("定制化阶段跳转id")
private Long personalStageJumpId;
@ApiModelProperty("衔接语")
private String linkupContent;
}
\ No newline at end of file
package com.pcloud.book.personalstage.entity;
import com.pcloud.common.entity.BaseEntity;
import io.swagger.annotations.ApiModel;
import io.swagger.annotations.ApiModelProperty;
import lombok.Data;
import java.util.List;
@ApiModel("定制化回复")
@Data
public class PersonalStageReply extends BaseEntity {
@ApiModelProperty("名称")
private String name;
@ApiModelProperty("定制化阶段id")
private Long personalStageId;
@ApiModelProperty("关联id")
private Long relevanceId;
@ApiModelProperty("关联类型:1阶段非关键词回复,2非关键词熔断回复,3唤醒")
private Integer relevanceType;
@ApiModelProperty("回复项集合")
private List<PersonalStageReplyItem> personalStageReplyItems;
}
\ No newline at end of file
package com.pcloud.book.personalstage.entity;
import com.pcloud.common.entity.BaseEntity;
import io.swagger.annotations.ApiModel;
import io.swagger.annotations.ApiModelProperty;
import lombok.Data;
@ApiModel("定制化阶段回复项")
@Data
public class PersonalStageReplyItem extends BaseEntity {
@ApiModelProperty("定制化阶段回复id")
private Long personalStageReplyId;
@ApiModelProperty("回复类型 1 文字 2 图片 3 链接 4应用 5素材")
private Integer replyType;
@ApiModelProperty("内容")
private String content;
@ApiModelProperty("图片地址")
private String picUrl;
}
\ No newline at end of file
package com.pcloud.book.personalstage.entity;
import com.pcloud.common.entity.BaseEntity;
import io.swagger.annotations.ApiModel;
import io.swagger.annotations.ApiModelProperty;
import lombok.Data;
import java.util.List;
@ApiModel("定制化阶段用户")
@Data
public class PersonalStageUser extends BaseEntity {
@ApiModelProperty("定制化阶段id")
private Long personalStageId;
@ApiModelProperty("微信用户id")
private String wxId;
@ApiModelProperty("小号id")
private String robotId;
@ApiModelProperty("机器人分类id")
private Long robotClassifyId;
@ApiModelProperty("状态:1正常,2唤醒,3熔断,4结束")
private Integer state;
@ApiModelProperty("用户非关键词发送次数")
private Integer notKeywordSendCount;
}
\ No newline at end of file
package com.pcloud.book.personalstage.entity;
import com.pcloud.common.entity.BaseEntity;
import io.swagger.annotations.ApiModel;
import io.swagger.annotations.ApiModelProperty;
import lombok.Data;
import java.util.List;
@ApiModel("定制化阶段唤醒")
@Data
public class PersonalStageWakeup extends BaseEntity {
@ApiModelProperty("定制化阶段id")
private Long personalStageId;
@ApiModelProperty("距离进入阶段时间")
private Integer toStageStartTime;
@ApiModelProperty("唤醒回复集合")
private List<PersonalStageReply> wakeupReplies;
}
\ No newline at end of file
package com.pcloud.book.personalstage.enums;
public enum JumpTypeEnum {
READER_TRIGGER(1,"读者输入关键词触发"),
ROBOT_TRIGGER(2,"小睿发送关键词触发"),
PAY_TRIGGER(3,"转账触发");
public final Integer key;
public final String desc;
JumpTypeEnum(Integer key, String desc){
this.key = key;
this.desc = desc;
}
}
package com.pcloud.book.personalstage.enums;
public enum PersonalStageUserStateEnum {
/**
* 正常
*/
NORMAL(1),
/**
* 唤醒
*/
WAKEUP(2),
/**
* 熔断
*/
FUSING(3),
/**
* 结束
*/
FINISH(4);
public final Integer value;
PersonalStageUserStateEnum(Integer value) {
this.value = value;
}
}
package com.pcloud.book.personalstage.enums;
public enum StageReplyRelevEnum {
/**
* 阶段非关键词回复
*/
STAGE_NOT_KEYWORD(1),
/**
* 非关键词熔断回复
*/
FUSING_NOT_KEYWORD(2),
/**
* 唤醒
*/
WAKEUP(3);
public final Integer value;
StageReplyRelevEnum(Integer value) {
this.value = value;
}
}
package com.pcloud.book.personalstage.facade;
import com.pcloud.book.personalstage.biz.PersonalStageBiz;
import com.pcloud.book.personalstage.entity.PersonalStage;
import com.pcloud.book.personalstage.enums.JumpTypeEnum;
import com.pcloud.book.personalstage.vo.request.CreateStageJumpRequestVO;
import com.pcloud.book.personalstage.vo.request.UpdateStageJumpRequestVO;
import com.pcloud.common.dto.ResponseDto;
import com.pcloud.common.exceptions.BizException;
import com.pcloud.common.permission.PermissionException;
import com.pcloud.common.utils.SessionUtil;
import com.pcloud.book.base.exception.BookBizException;
import com.pcloud.common.page.PageParam;
import com.pcloud.book.personalstage.biz.PersonalStageJumpBiz;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import io.swagger.annotations.ApiParam;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.validation.annotation.Validated;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestHeader;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestParam;
import org.springframework.web.bind.annotation.RestController;
import org.springframework.web.bind.annotation.*;
import java.util.Optional;
@Api("定制化阶段")
@RestController("personalStageFacade")
@RequestMapping("personalStage")
public class PersonalStageFacade {
@Autowired
private PersonalStageBiz personalStageBiz;
@Autowired
private PersonalStageJumpBiz personalStageJumpBiz;
@ApiOperation("新增定制化阶段")
@PostMapping("/createPersonalStage")
public ResponseDto<?> createPersonalStage(
@RequestHeader("token") @ApiParam("token信息") String token,
@RequestBody @ApiParam("定制化阶段") PersonalStage personalStage
) throws BizException, PermissionException {
SessionUtil.getVlaue(token, SessionUtil.PARTY_ID);
return new ResponseDto<>(personalStageBiz.createPersonalStage(personalStage));
}
@ApiOperation("修改定制化阶段")
@PostMapping("/updatePersonalStage")
public ResponseDto<?> updatePersonalStage(
@RequestHeader("token") @ApiParam("token信息") String token,
@RequestBody @ApiParam("定制化阶段") PersonalStage personalStage
) throws BizException, PermissionException {
SessionUtil.getVlaue(token, SessionUtil.PARTY_ID);
personalStageBiz.updatePersonalStage(personalStage);
return new ResponseDto<>();
}
@ApiOperation("删除定制化阶段")
@GetMapping("/deletePersonalStage")
public ResponseDto<?> deletePersonalStage(
@RequestHeader("token") @ApiParam("token信息") String token,
@RequestParam("id") @ApiParam("定制化阶段id") Long id
) throws BizException, PermissionException {
SessionUtil.getVlaue(token, SessionUtil.PARTY_ID);
personalStageBiz.deletePersonalStage(id);
return new ResponseDto<>();
}
@ApiOperation("获取定制化阶段")
@GetMapping("/getPersonalStage")
public ResponseDto<?> getPersonalStage(
@RequestHeader("token") @ApiParam("token信息") String token,
@RequestParam("id") @ApiParam("定制化阶段id") Long id
) throws BizException, PermissionException {
SessionUtil.getVlaue(token, SessionUtil.PARTY_ID);
return new ResponseDto<>(personalStageBiz.getPersonalStage(id));
}
@ApiOperation("修改排序值")
@PostMapping("/updateSeqNum")
public ResponseDto<?> updateSeqNum(
@RequestHeader("token") @ApiParam("token信息") String token,
@RequestBody @ApiParam("定制化阶段") PersonalStage personalStage
) throws BizException, PermissionException {
SessionUtil.getVlaue(token, SessionUtil.PARTY_ID);
personalStageBiz.updateSeqNum(personalStage);
return new ResponseDto<>();
}
@RequestMapping(value = "getPersonalStageList", method = RequestMethod.GET)
@ApiOperation(value = "获取阶段列表", httpMethod = "GET")
public ResponseDto<?> getPersonalStageList(@RequestHeader("token") String token, @RequestParam(value = "robotClassifyId", required = false) Long robotClassifyId,
@RequestParam(value = "currentPage", required = false) Integer currentPage,
@RequestParam(value = "numPerPage", required = false) Integer numPerPage)
throws PermissionException, BizException {
SessionUtil.getToken4Redis(token);
if (null == robotClassifyId) {
throw BookBizException.PARAM_DELETION;
}
if (currentPage == null || numPerPage == null || currentPage < 0 || numPerPage < 0) {
throw BookBizException.PAGE_PARAM_DELETION;
}
return new ResponseDto<>(personalStageBiz.getPersonalStageList(robotClassifyId, new PageParam(currentPage, numPerPage)));
}
@RequestMapping(value = "getPersonalStageListNoPage", method = RequestMethod.GET)
@ApiOperation(value = "获取阶段列表", httpMethod = "GET")
public ResponseDto<?> getPersonalStageListNoPage(@RequestHeader("token") String token, @RequestParam(value = "robotClassifyId", required = false) Long robotClassifyId)
throws PermissionException, BizException {
SessionUtil.getToken4Redis(token);
if (null == robotClassifyId) {
throw BookBizException.PARAM_DELETION;
}
return new ResponseDto<>(personalStageBiz.getPersonalStageListNoPage(robotClassifyId));
}
@ApiOperation("获取跳转列表")
@GetMapping("getJumpList")
public ResponseDto<?> getJumpList(@RequestHeader("token") String token, @RequestParam Long personalStageId, @RequestParam("currentPage") Integer currentPage, @RequestParam("numPerPage") Integer numPerPage) throws PermissionException {
SessionUtil.getVlaue(token, SessionUtil.PARTY_ID);
if (null == personalStageId) {
throw BookBizException.PARAM_DELETION;
}
if (currentPage == null || numPerPage == null || currentPage < 0 || numPerPage < 0) {
throw BookBizException.PAGE_PARAM_DELETION;
}
return new ResponseDto<>(personalStageJumpBiz.getJumpList(personalStageId, currentPage, numPerPage));
}
@ApiOperation("获取跳转详情")
@GetMapping("getJump")
public ResponseDto<?> getJump(@RequestHeader("token") String token, @RequestParam Long jumpId) throws BizException, PermissionException {
SessionUtil.getVlaue(token, SessionUtil.PARTY_ID);
if (null == jumpId) {
throw BookBizException.PARAM_DELETION;
}
return new ResponseDto<>(personalStageJumpBiz.getJump(jumpId));
}
@ApiOperation("删除跳转")
@GetMapping("deleteJump")
public ResponseDto<?> deleteJump(@RequestHeader("token") String token, @RequestParam Long jumpId) throws BizException, PermissionException {
SessionUtil.getVlaue(token, SessionUtil.PARTY_ID);
if (null == jumpId) {
throw BookBizException.PARAM_DELETION;
}
personalStageJumpBiz.deleteJump(jumpId);
return new ResponseDto<>();
}
@ApiOperation("打开关闭Email通知")
@GetMapping("updateEmailStatus")
public ResponseDto<?> updateEmailStatus(@RequestHeader("token") String token, @RequestParam Long jumpId,@RequestParam Integer openEmail) throws BizException, PermissionException {
SessionUtil.getVlaue(token, SessionUtil.PARTY_ID);
if (null == jumpId) {
throw BookBizException.PARAM_DELETION;
}
return new ResponseDto<>(personalStageJumpBiz.updateEmailStatus(jumpId, openEmail));
}
@ApiOperation("新建跳转")
@PostMapping("createPersonalStageJump")
public ResponseDto<?> createPersonalStageJump(@RequestHeader("token") String token, @Validated @RequestBody CreateStageJumpRequestVO vo) throws PermissionException, BizException{
Optional.ofNullable(vo).orElseThrow(() -> new BookBizException(BookBizException.ERROR, "参数为空"));
SessionUtil.getVlaue(token, SessionUtil.PARTY_ID);
personalStageJumpBiz.createPersonalStageJump(vo);
return new ResponseDto<>();
}
@ApiOperation("修改跳转")
@PostMapping("updatePersonalStageJump")
public ResponseDto<?> updatePersonalStageJump(@RequestHeader("token") String token, @Validated @RequestBody UpdateStageJumpRequestVO vo) throws PermissionException, BizException{
Optional.ofNullable(vo).orElseThrow(() -> new BookBizException(BookBizException.ERROR, "参数为空"));
SessionUtil.getVlaue(token, SessionUtil.PARTY_ID);
personalStageJumpBiz.updatePersonalStageJump(vo);
return new ResponseDto<>();
}
}
package com.pcloud.book.personalstage.vo.request;
import com.pcloud.book.personalstage.entity.PersonalStageJumpEmail;
import com.pcloud.book.personalstage.entity.PersonalStageJumpKeyword;
import com.pcloud.book.personalstage.entity.PersonalStageJumpLinkup;
import com.pcloud.common.entity.BaseRequestVO;
import com.pcloud.common.utils.ListUtils;
import lombok.Data;
import javax.validation.constraints.NotNull;
import javax.validation.constraints.Size;
import java.util.ArrayList;
import java.util.Date;
import java.util.List;
@Data
public abstract class BaseStageJumpRequestVO extends BaseRequestVO {
@NotNull(message = "阶段id不能为空")
private Long personalStageId;
@NotNull(message = "跳转类型不能为空")
private Integer jumpType;
private Long afterPersonalStageId;
@NotNull(message = "未设置是否开启邮件提醒")
private Boolean openEmail;
private String transferMessage;
private Double transferMoney;
@NotNull(message = "跳转关键词不能为空")
@Size(max = 5, message = "跳转关键词不能超过5个")
private List<String> keywords;
@Size(max = 5, message = "邮件地址不能超过5个")
private List<String> emails;
@Size(max = 5, message = "衔接语不能超过5个")
private List<String> linkupContents;
public static List<PersonalStageJumpKeyword> valueToJumpKeywords(BaseStageJumpRequestVO vo, Long personalStageJumpId){
List<String> keywords = vo.getKeywords();
if (ListUtils.isEmpty(keywords)){
return new ArrayList<>();
}
List<PersonalStageJumpKeyword> jumpKeywords = new ArrayList<>();
for (String keyword : keywords){
PersonalStageJumpKeyword jumpKeyword = new PersonalStageJumpKeyword();
jumpKeyword.setKeyword(keyword);
jumpKeyword.setPersonalStageId(vo.getPersonalStageId());
jumpKeyword.setPersonalStageJumpId(personalStageJumpId);
jumpKeywords.add(jumpKeyword);
}
return jumpKeywords;
}
public static List<PersonalStageJumpEmail> valueToJumpEmails(BaseStageJumpRequestVO vo, Long personalStageJumpId){
List<String> emails = vo.getEmails();
if (ListUtils.isEmpty(emails)){
return new ArrayList<>();
}
List<PersonalStageJumpEmail> jumpEmails = new ArrayList<>();
for (String email : emails){
PersonalStageJumpEmail jumpEmail = new PersonalStageJumpEmail();
jumpEmail.setEmail(email);
jumpEmail.setPersonalStageJumpId(personalStageJumpId);
jumpEmails.add(jumpEmail);
}
return jumpEmails;
}
public static List<PersonalStageJumpLinkup> valueToJumpLinkups(BaseStageJumpRequestVO vo, Long personalStageJumpId){
List<String> linkupContents = vo.getLinkupContents();
if (ListUtils.isEmpty(linkupContents)){
return new ArrayList<>();
}
List<PersonalStageJumpLinkup> jumpLinkups = new ArrayList<>();
for (String linkupContent : linkupContents){
PersonalStageJumpLinkup jumpLinkup = new PersonalStageJumpLinkup();
jumpLinkup.setLinkupContent(linkupContent);
jumpLinkup.setPersonalStageJumpId(personalStageJumpId);
jumpLinkups.add(jumpLinkup);
}
return jumpLinkups;
}
}
package com.pcloud.book.personalstage.vo.request;
import com.pcloud.book.personalstage.entity.PersonalStageJump;
import com.pcloud.common.utils.BeanUtils;
import lombok.Data;
import java.util.Date;
@Data
public class CreateStageJumpRequestVO extends BaseStageJumpRequestVO {
public static PersonalStageJump valueToJumpEntity(CreateStageJumpRequestVO vo){
PersonalStageJump personalStageJump = new PersonalStageJump();
BeanUtils.copyProperties(vo, personalStageJump);
personalStageJump.setCreateTime(new Date());
return personalStageJump;
}
}
package com.pcloud.book.personalstage.vo.request;
import com.pcloud.book.personalstage.entity.PersonalStageJump;
import com.pcloud.common.utils.BeanUtils;
import lombok.Data;
import javax.validation.constraints.NotNull;
import java.util.Date;
@Data
public class UpdateStageJumpRequestVO extends BaseStageJumpRequestVO {
@NotNull(message = "阶段跳转id不能为空")
private Long personalStageJumpId;
public static PersonalStageJump valueToJumpEntity(UpdateStageJumpRequestVO vo){
PersonalStageJump personalStageJump = new PersonalStageJump();
BeanUtils.copyProperties(vo, personalStageJump);
personalStageJump.setCreateTime(new Date());
personalStageJump.setId(vo.getPersonalStageJumpId());
return personalStageJump;
}
}
<?xml version="1.0" encoding="UTF-8" ?>
<!DOCTYPE mapper PUBLIC "-//mybatis.org//DTD Mapper 3.0//EN" "mybatis-3-mapper.dtd" >
<mapper namespace="com.pcloud.book.personalstage.dao.impl.PersonalStageDaoImpl">
<resultMap id="BaseResultMap" type="com.pcloud.book.personalstage.entity.PersonalStage">
<id property="id" column="id" jdbcType="BIGINT"/>
<result property="name" column="name" jdbcType="VARCHAR"/>
<result property="notKeywordFusingCount" column="not_keyword_fusing_count" jdbcType="INTEGER"/>
<result property="notKeywordFusingTime" column="not_keyword_fusing_time" jdbcType="BIGINT"/>
<result property="robotClassifyId" column="robot_classify_id" jdbcType="BIGINT"/>
<result property="seqNum" column="seq_num" jdbcType="INTEGER"/>
<result property="createTime" column="create_time" jdbcType="TIMESTAMP"/>
</resultMap>
<sql id="Base_Column_List">
id, name, not_keyword_fusing_count, not_keyword_fusing_time, robot_classify_id, seq_num, create_time
</sql>
<select id="getById" resultMap="BaseResultMap" parameterType="java.lang.Long">
select
<include refid="Base_Column_List"/>
from personal_stage
where id = #{id,jdbcType=BIGINT}
</select>
<delete id="deleteById" parameterType="long">
delete from personal_stage
where id = #{id,jdbcType=BIGINT}
</delete>
<insert id="insert" parameterType="com.pcloud.book.personalstage.entity.PersonalStage" useGeneratedKeys="true" keyProperty="id">
insert into personal_stage
<trim prefix="(" suffix=")" suffixOverrides=",">
name,
not_keyword_fusing_count,
not_keyword_fusing_time,
robot_classify_id,
seq_num,
create_time
</trim>
<trim prefix="values (" suffix=")" suffixOverrides=",">
#{name,jdbcType=VARCHAR},
#{notKeywordFusingCount,jdbcType=INTEGER},
#{notKeywordFusingTime,jdbcType=BIGINT},
#{robotClassifyId,jdbcType=BIGINT},
#{seqNum,jdbcType=INTEGER},
NOW()
</trim>
</insert>
<update id="update" parameterType="com.pcloud.book.personalstage.entity.PersonalStage">
update personal_stage
<set>
<if test="name != null">
name = #{name,jdbcType=VARCHAR},
</if>
<if test="notKeywordFusingCount != null">
not_keyword_fusing_count = #{notKeywordFusingCount,jdbcType=INTEGER},
</if>
<if test="notKeywordFusingTime != null">
not_keyword_fusing_time = #{notKeywordFusingTime,jdbcType=BIGINT},
</if>
<if test="robotClassifyId != null">
robot_classify_id = #{robotClassifyId,jdbcType=BIGINT},
</if>
<if test="seqNum != null">
seq_num = #{seqNum,jdbcType=INTEGER},
</if>
</set>
where id = #{id,jdbcType=BIGINT}
</update>
<update id="updateSeqNum" parameterType="map">
update personal_stage
set seq_num=#{seqNum}
where id=#{id}
</update>
<select id="getPersonalStageList" parameterType="map" resultType="com.pcloud.book.personalstage.dto.PersonalStageDTO">
SELECT
s.id,
s.`name`,
sum(IF(r.relevance_type = 1, 1, 0)) notKeywordReplyCount,
sum(IF(r.relevance_type = 2, 1, 0)) notKeywordFusingReplyCount,
s.seq_num seqNum,
s.create_time createTime
FROM
personal_stage s
LEFT JOIN personal_stage_reply r ON r.personal_stage_id = s.id
AND r.relevance_type != 3
WHERE
s.robot_classify_id = #{robotClassifyId}
GROUP BY
s.id
ORDER BY
s.seq_num ASC,
s.id ASC
</select>
<select id="getMaxSeqNum" resultType="integer">
select ifnull(max(seq_num),0) from personal_stage
</select>
<select id="getCountByRobotClassifyId" parameterType="long" resultType="integer">
select count(1) from personal_stage
where robot_classify_id = #{robotClassifyId}
</select>
<select id="getFirstStage" parameterType="long" resultMap="BaseResultMap">
select <include refid="Base_Column_List"/>
from personal_stage
where robot_classify_id = #{robotClassifyId}
order by seq_num, id
limit 1
</select>
</mapper>
\ No newline at end of file
<?xml version="1.0" encoding="UTF-8" ?>
<!DOCTYPE mapper PUBLIC "-//mybatis.org//DTD Mapper 3.0//EN" "mybatis-3-mapper.dtd" >
<mapper namespace="com.pcloud.book.personalstage.dao.impl.PersonalStageJumpDaoImpl">
<resultMap id="BaseResultMap" type="com.pcloud.book.personalstage.entity.PersonalStageJump">
<id property="id" column="id" jdbcType="BIGINT"/>
<result property="personalStageId" column="personal_stage_id" jdbcType="BIGINT"/>
<result property="jumpType" column="jump_type" jdbcType="INTEGER"/>
<result property="afterPersonalStageId" column="after_personal_stage_id" jdbcType="BIGINT"/>
<result property="openEmail" column="open_email" jdbcType="BOOLEAN"/>
<result property="transferMessage" column="transfer_message" jdbcType="VARCHAR"/>
<result property="transferMoney" column="transfer_money" jdbcType="DOUBLE"/>
<result property="createTime" column="create_time" jdbcType="TIMESTAMP"/>
</resultMap>
<sql id="Base_Column_List">
id, personal_stage_id, jump_type, after_personal_stage_id, open_email, transfer_message, transfer_money, create_time
</sql>
<select id="getById" resultMap="BaseResultMap" parameterType="java.lang.Long">
select
<include refid="Base_Column_List"/>
from personal_stage_jump
where id = #{id,jdbcType=BIGINT}
</select>
<select id="getDtoById" resultType="com.pcloud.book.personalstage.dto.PersonalStageJumpDto" parameterType="java.lang.Long">
SELECT
a.id,
a.personal_stage_id personalStageId,
a.jump_type jumpType,
a.after_personal_stage_id afterPersonalStageId,
a.open_email openEmail,
a.transfer_message transferMessage,
a.transfer_money transferMoney,
b.name personalStageName
FROM personal_stage_jump a, personal_stage b
WHERE a.after_personal_stage_id = b.id AND a.id = #{jumpId,jdbcType=BIGINT}
</select>
<select id="getJumpList" resultType="com.pcloud.book.personalstage.dto.PersonalStageJumpDto" parameterType="long">
SELECT
a.id,
a.personal_stage_id personalStageId,
a.jump_type jumpType,
a.after_personal_stage_id afterPersonalStageId,
a.open_email openEmail,
a.transfer_message transferMessage,
a.transfer_money transferMoney,
b.name personalStageName
FROM personal_stage_jump a LEFT JOIN personal_stage b ON a.after_personal_stage_id = b.id
WHERE a.personal_stage_id = #{personalStageId,jdbcType=BIGINT}
</select>
<delete id="deleteById" parameterType="long">
delete from personal_stage_jump
where id = #{id,jdbcType=BIGINT}
</delete>
<insert id="insert" parameterType="com.pcloud.book.personalstage.entity.PersonalStage" useGeneratedKeys="true" keyProperty="id">
insert into personal_stage_jump
<trim prefix="(" suffix=")" suffixOverrides=",">
personal_stage_id,
jump_type,
after_personal_stage_id,
open_email,
transfer_message,
transfer_money,
create_time
</trim>
<trim prefix="values (" suffix=")" suffixOverrides=",">
#{personalStageId,jdbcType=BIGINT},
#{jumpType,jdbcType=INTEGER},
#{afterPersonalStageId,jdbcType=BIGINT},
#{openEmail,jdbcType=BOOLEAN},
#{transferMessage,jdbcType=VARCHAR},
#{transferMoney,jdbcType=DOUBLE},
NOW()
</trim>
</insert>
<select id="getCountByPersonalStageId" parameterType="long" resultType="integer">
select count(1) from personal_stage_jump
where personal_stage_id=#{personalStageId}
</select>
<update id="update" parameterType="com.pcloud.book.personalstage.entity.PersonalStageJump">
UPDATE personal_stage_jump
<set>
<if test="personalStageId != null">
personal_stage_id = #{personalStageId},
</if>
<if test="jumpType != null">
jump_type = #{jumpType},
</if>
<if test="afterPersonalStageId != null">
after_personal_stage_id = #{afterPersonalStageId},
</if>
<if test="openEmail != null" >
open_email = #{openEmail,jdbcType=BOOLEAN},
</if>
<if test="transferMessage != null">
transfer_message = #{transferMessage},
</if>
<if test="transferMoney != null">
transfer_money = #{transferMoney},
</if>
</set>
where id = #{id,jdbcType=INTEGER}
</update>
</mapper>
\ No newline at end of file
<?xml version="1.0" encoding="UTF-8" ?>
<!DOCTYPE mapper PUBLIC "-//mybatis.org//DTD Mapper 3.0//EN" "mybatis-3-mapper.dtd" >
<mapper namespace="com.pcloud.book.personalstage.dao.impl.PersonalStageJumpEmailDaoImpl">
<resultMap id="BaseResultMap" type="com.pcloud.book.personalstage.entity.PersonalStageJumpEmail">
<id property="id" column="id" jdbcType="BIGINT"/>
<result property="personalStageJumpId" column="personal_stage_jump_id" jdbcType="BIGINT"/>
<result property="email" column="email" jdbcType="VARCHAR"/>
<result property="createTime" column="create_time" jdbcType="TIMESTAMP"/>
</resultMap>
<sql id="Base_Column_List">
id, personal_stage_jump_id, email, create_time
</sql>
<select id="getById" resultMap="BaseResultMap" parameterType="java.lang.Long">
select
<include refid="Base_Column_List"/>
from personal_stage_jump_email
where id = #{id,jdbcType=BIGINT}
</select>
<select id="listBy" resultMap="BaseResultMap" parameterType="map">
select
<include refid="Base_Column_List"/>
from personal_stage_jump_email
where personal_stage_jump_id IN
<foreach collection="jumpIds" item="jumpId" separator="," open="(" close=")">
${jumpId}
</foreach>
</select>
<select id="getByJumpId" resultMap="BaseResultMap" parameterType="java.lang.Long">
select
<include refid="Base_Column_List"/>
from personal_stage_jump_email
where personal_stage_jump_id = #{jumpId,jdbcType=BIGINT}
</select>
<delete id="deleteById" parameterType="long">
delete from personal_stage_jump_email
where id = #{id,jdbcType=BIGINT}
</delete>
<delete id="deleteByJumpId" parameterType="long">
delete from personal_stage_jump_email
where personal_stage_jump_id = #{jumpId,jdbcType=BIGINT}
</delete>
<insert id="insert" parameterType="com.pcloud.book.personalstage.entity.PersonalStageJumpEmail" useGeneratedKeys="true" keyProperty="id">
insert into personal_stage_jump_email
<trim prefix="(" suffix=")" suffixOverrides=",">
personal_stage_jump_id,
email,
create_time
</trim>
<trim prefix="values (" suffix=")" suffixOverrides=",">
#{personalStageJumpId,jdbcType=BIGINT},
#{email,jdbcType=VARCHAR},
NOW()
</trim>
</insert>
<insert id="batchInsert" parameterType="list" useGeneratedKeys="true" keyProperty="id">
insert into personal_stage_jump_email
<trim prefix="(" suffix=")" suffixOverrides=",">
personal_stage_jump_id,
email,
create_time
</trim>
values
<foreach collection="list" item="item" separator=",">
<trim prefix="(" suffix=")" suffixOverrides=",">
#{item.personalStageJumpId,jdbcType=BIGINT},
#{item.email,jdbcType=VARCHAR},
NOW()
</trim>
</foreach>
</insert>
</mapper>
\ No newline at end of file
<?xml version="1.0" encoding="UTF-8" ?>
<!DOCTYPE mapper PUBLIC "-//mybatis.org//DTD Mapper 3.0//EN" "mybatis-3-mapper.dtd" >
<mapper namespace="com.pcloud.book.personalstage.dao.impl.PersonalStageJumpKeywordDaoImpl">
<resultMap id="BaseResultMap" type="com.pcloud.book.personalstage.entity.PersonalStageJumpKeyword">
<id property="id" column="id" jdbcType="BIGINT"/>
<result property="personalStageId" column="personal_stage_id" jdbcType="BIGINT"/>
<result property="personalStageJumpId" column="personal_stage_jump_id" jdbcType="BIGINT"/>
<result property="keyword" column="keyword" jdbcType="VARCHAR"/>
<result property="createTime" column="create_time" jdbcType="TIMESTAMP"/>
</resultMap>
<sql id="Base_Column_List">
id, personal_stage_id, personal_stage_jump_id, keyword, create_time
</sql>
<select id="getById" resultMap="BaseResultMap" parameterType="java.lang.Long">
select
<include refid="Base_Column_List"/>
from personal_stage_jump_keyword
where id = #{id,jdbcType=BIGINT}
</select>
<select id="listBy" resultMap="BaseResultMap" parameterType="map">
select
<include refid="Base_Column_List"/>
from personal_stage_jump_keyword
where personal_stage_jump_id IN
<foreach collection="jumpIds" item="jumpId" separator="," open="(" close=")">
${jumpId}
</foreach>
</select>
<select id="getByKeyword" resultType="com.pcloud.book.personalstage.dto.PersonalStageJumpKeywordDto" parameterType="map">
SELECT
a.id, a.personal_stage_id personalStageId, a.personal_stage_jump_id personalStageJumpId,
a.keyword, b.jump_type jumpType, b.after_personal_stage_id afterPersonalStageId
FROM personal_stage_jump_keyword a,personal_stage_jump b
WHERE a.personal_stage_jump_id = b.id AND a.keyword = #{keyword,jdbcType=VARCHAR}
AND a.personal_stage_id = #{personalStageId,jdbcType=BIGINT}
AND b.jump_type = #{jumpType,jdbcType=INTEGER}
LIMIT 0,1
</select>
<delete id="deleteById" parameterType="long">
delete from personal_stage_jump_keyword
where id = #{id,jdbcType=BIGINT}
</delete>
<delete id="deleteByJumpId" parameterType="long">
delete from personal_stage_jump_keyword
where personal_stage_jump_id = #{jumpId,jdbcType=BIGINT}
</delete>
<insert id="insert" parameterType="com.pcloud.book.personalstage.entity.PersonalStageJumpKeyword" useGeneratedKeys="true" keyProperty="id">
insert into personal_stage_jump_keyword
<trim prefix="(" suffix=")" suffixOverrides=",">
personal_stage_id,
personal_stage_jump_id,
keyword,
create_time
</trim>
<trim prefix="values (" suffix=")" suffixOverrides=",">
#{personalStageId, jdbcType=BIGINT},
#{personalStageJumpId,jdbcType=BIGINT},
#{keyword,jdbcType=VARCHAR},
NOW()
</trim>
</insert>
<insert id="batchInsert" parameterType="list" useGeneratedKeys="true" keyProperty="id">
insert into personal_stage_jump_keyword
<trim prefix="(" suffix=")" suffixOverrides=",">
personal_stage_id,
personal_stage_jump_id,
keyword,
create_time
</trim>
values
<foreach collection="list" item="item" separator=",">
<trim prefix="(" suffix=")" suffixOverrides=",">
#{item.personalStageId, jdbcType=BIGINT},
#{item.personalStageJumpId,jdbcType=BIGINT},
#{item.keyword,jdbcType=VARCHAR},
NOW()
</trim>
</foreach>
</insert>
<select id="getStageKeywordByKeywords" parameterType="map" resultMap="BaseResultMap">
select <include refid="Base_Column_List"/> from personal_stage_jump_keyword
where personal_stage_id = #{personalStageId}
and keyword in
<foreach collection="keywords" item="item" open="(" close=")" separator=",">
'${item}'
</foreach>
limit 1
</select>
</mapper>
\ No newline at end of file
<?xml version="1.0" encoding="UTF-8" ?>
<!DOCTYPE mapper PUBLIC "-//mybatis.org//DTD Mapper 3.0//EN" "mybatis-3-mapper.dtd" >
<mapper namespace="com.pcloud.book.personalstage.dao.impl.PersonalStageJumpLinkupDaoImpl">
<resultMap id="BaseResultMap" type="com.pcloud.book.personalstage.entity.PersonalStageJumpLinkup">
<id property="id" column="id" jdbcType="BIGINT"/>
<result property="personalStageJumpId" column="personal_stage_jump_id" jdbcType="BIGINT"/>
<result property="linkupContent" column="linkup_content" jdbcType="VARCHAR"/>
</resultMap>
<sql id="Base_Column_List">
id, personal_stage_jump_id, linkup_content
</sql>
<select id="getById" resultMap="BaseResultMap" parameterType="java.lang.Long">
select
<include refid="Base_Column_List"/>
from personal_stage_jump_linkup
where id = #{id,jdbcType=BIGINT}
</select>
<select id="getByJumpId" resultMap="BaseResultMap" parameterType="java.lang.Long">
select
<include refid="Base_Column_List"/>
from personal_stage_jump_linkup
where personal_stage_jump_id = #{jumpId,jdbcType=BIGINT}
</select>
<select id="listBy" resultMap="BaseResultMap" parameterType="map">
select
<include refid="Base_Column_List"/>
from personal_stage_jump_linkup
where personal_stage_jump_id IN
<foreach collection="jumpIds" item="jumpId" separator="," open="(" close=")">
${jumpId}
</foreach>
</select>
<delete id="deleteById" parameterType="long">
delete from personal_stage_jump_linkup
where id = #{id,jdbcType=BIGINT}
</delete>
<delete id="deleteByJumpId" parameterType="long">
delete from personal_stage_jump_linkup
where personal_stage_jump_id = #{personalStageJumpId,jdbcType=BIGINT}
</delete>
<insert id="insert" parameterType="com.pcloud.book.personalstage.entity.PersonalStageJumpLinkup" useGeneratedKeys="true" keyProperty="id">
insert into personal_stage_jump_linkup
<trim prefix="(" suffix=")" suffixOverrides=",">
personal_stage_jump_id,
linkup_content
</trim>
<trim prefix="values (" suffix=")" suffixOverrides=",">
#{personalStageJumpId,jdbcType=BIGINT},
#{linkupContent,jdbcType=VARCHAR}
</trim>
</insert>
<insert id="batchInsert" parameterType="list" useGeneratedKeys="true" keyProperty="id">
insert into personal_stage_jump_linkup
<trim prefix="(" suffix=")" suffixOverrides=",">
personal_stage_jump_id,
linkup_content
</trim>
values
<foreach collection="list" item="item" separator=",">
<trim prefix="(" suffix=")" suffixOverrides=",">
#{item.personalStageJumpId,jdbcType=BIGINT},
#{item.linkupContent,jdbcType=VARCHAR}
</trim>
</foreach>
</insert>
</mapper>
\ No newline at end of file
<?xml version="1.0" encoding="UTF-8" ?>
<!DOCTYPE mapper PUBLIC "-//mybatis.org//DTD Mapper 3.0//EN" "mybatis-3-mapper.dtd" >
<mapper namespace="com.pcloud.book.personalstage.dao.impl.PersonalStageReplyDaoImpl">
<resultMap id="BaseResultMap" type="com.pcloud.book.personalstage.entity.PersonalStageReply">
<id property="id" column="id" jdbcType="BIGINT"/>
<result property="name" column="name" jdbcType="VARCHAR"/>
<result property="personalStageId" column="personal_stage_id" jdbcType="BIGINT"/>
<result property="relevanceId" column="relevance_id" jdbcType="BIGINT"/>
<result property="relevanceType" column="relevance_type" jdbcType="INTEGER"/>
<result property="createTime" column="create_time" jdbcType="TIMESTAMP"/>
</resultMap>
<sql id="Base_Column_List">
id, name, personal_stage_id, relevance_id, relevance_type, create_time
</sql>
<select id="getById" resultMap="BaseResultMap" parameterType="java.lang.Long">
select
<include refid="Base_Column_List"/>
from personal_stage_reply
where id = #{id,jdbcType=BIGINT}
</select>
<delete id="deleteById" parameterType="long">
delete from personal_stage_reply
where id = #{id,jdbcType=BIGINT}
</delete>
<insert id="insert" parameterType="com.pcloud.book.personalstage.entity.PersonalStageReply" useGeneratedKeys="true" keyProperty="id">
insert into personal_stage_reply
<trim prefix="(" suffix=")" suffixOverrides=",">
name,
personal_stage_id,
relevance_id,
relevance_type,
create_time
</trim>
<trim prefix="values (" suffix=")" suffixOverrides=",">
#{name,jdbcType=VARCHAR},
#{personalStageId,jdbcType=BIGINT},
#{relevanceId,jdbcType=BIGINT},
#{relevanceType,jdbcType=INTEGER},
NOW()
</trim>
</insert>
<insert id="batchInsert" parameterType="com.pcloud.book.personalstage.entity.PersonalStageReply" useGeneratedKeys="true" keyProperty="id">
insert into personal_stage_reply (
name,
personal_stage_id,
relevance_id,
relevance_type,
create_time
) values
<foreach collection="list" item="item" index="index" separator=",">
(
#{item.name,jdbcType=VARCHAR},
#{item.personalStageId,jdbcType=BIGINT},
#{item.relevanceId,jdbcType=BIGINT},
#{item.relevanceType,jdbcType=INTEGER},
NOW()
)
</foreach>
</insert>
<select id="getIdsByPersonalStageId" parameterType="long" resultType="long">
select id from personal_stage_reply
where personal_stage_id=#{personalStageId}
</select>
<delete id="deleteByIds" parameterType="long">
delete from personal_stage_reply
where id in
<foreach collection="list" item="item" open="(" separator="," close=")">
${item}
</foreach>
</delete>
<select id="getListByPersonalStageId" parameterType="long" resultMap="BaseResultMap">
select <include refid="Base_Column_List"/>
from personal_stage_reply
where personal_stage_id=#{personalStageId}
</select>
<select id="getIdsByRelevance" parameterType="map" resultType="long">
select id from personal_stage_reply
where relevance_id=#{relevanceId}
and relevance_type=#{relevanceType}
</select>
</mapper>
\ No newline at end of file
<?xml version="1.0" encoding="UTF-8" ?>
<!DOCTYPE mapper PUBLIC "-//mybatis.org//DTD Mapper 3.0//EN" "mybatis-3-mapper.dtd" >
<mapper namespace="com.pcloud.book.personalstage.dao.impl.PersonalStageReplyItemDaoImpl">
<resultMap id="BaseResultMap" type="com.pcloud.book.personalstage.entity.PersonalStageReplyItem">
<id property="id" column="id" jdbcType="BIGINT"/>
<result property="personalStageReplyId" column="personal_stage_reply_id" jdbcType="BIGINT"/>
<result property="replyType" column="reply_type" jdbcType="INTEGER"/>
<result property="content" column="content" jdbcType="VARCHAR"/>
<result property="picUrl" column="pic_url" jdbcType="VARCHAR"/>
<result property="createTime" column="create_time" jdbcType="TIMESTAMP"/>
</resultMap>
<sql id="Base_Column_List">
id, personal_stage_reply_id, reply_type, content, pic_url, create_time
</sql>
<select id="getById" resultMap="BaseResultMap" parameterType="java.lang.Long">
select
<include refid="Base_Column_List"/>
from personal_stage_reply_item
where id = #{id,jdbcType=BIGINT}
</select>
<delete id="deleteById" parameterType="long">
delete from personal_stage_reply_item
where id = #{id,jdbcType=BIGINT}
</delete>
<insert id="insert" parameterType="com.pcloud.book.personalstage.entity.PersonalStageReplyItem" useGeneratedKeys="true" keyProperty="id">
insert into personal_stage_reply_item
<trim prefix="(" suffix=")" suffixOverrides=",">
personal_stage_reply_id,
reply_type,
content,
pic_url,
create_time
</trim>
<trim prefix="values (" suffix=")" suffixOverrides=",">
#{personalStageReplyId,jdbcType=BIGINT},
#{replyType,jdbcType=INTEGER},
#{content,jdbcType=VARCHAR},
#{picUrl,jdbcType=VARCHAR},
NOW()
</trim>
</insert>
<insert id="batchInsert" parameterType="com.pcloud.book.personalstage.entity.PersonalStageReplyItem" useGeneratedKeys="true" keyProperty="id">
insert into personal_stage_reply_item (
personal_stage_reply_id,
reply_type,
content,
pic_url,
create_time
) values
<foreach collection="list" item="item" index="index" separator=",">
(
#{item.personalStageReplyId,jdbcType=BIGINT},
#{item.replyType,jdbcType=INTEGER},
#{item.content,jdbcType=VARCHAR},
#{item.picUrl,jdbcType=VARCHAR},
NOW()
)
</foreach>
</insert>
<delete id="deleteByReplyIds" parameterType="long">
delete from personal_stage_reply_item
where personal_stage_reply_id in
<foreach collection="list" item="item" open="(" separator="," close=")">
${item}
</foreach>
</delete>
<select id="getListByReplyIds" parameterType="long" resultMap="BaseResultMap">
select <include refid="Base_Column_List"/> from personal_stage_reply_item
where personal_stage_reply_id in
<foreach collection="list" item="item" open="(" separator="," close=")">
${item}
</foreach>
</select>
</mapper>
\ No newline at end of file
<?xml version="1.0" encoding="UTF-8" ?>
<!DOCTYPE mapper PUBLIC "-//mybatis.org//DTD Mapper 3.0//EN" "mybatis-3-mapper.dtd" >
<mapper namespace="com.pcloud.book.personalstage.dao.impl.PersonalStageUserDaoImpl">
<resultMap id="BaseResultMap" type="com.pcloud.book.personalstage.entity.PersonalStageUser">
<id property="id" column="id" jdbcType="BIGINT"/>
<result property="personalStageId" column="personal_stage_id" jdbcType="BIGINT"/>
<result property="wxId" column="wx_id" jdbcType="VARCHAR"/>
<result property="robotId" column="robot_id" jdbcType="VARCHAR"/>
<result property="robotClassifyId" column="robot_classify_id" jdbcType="BIGINT"/>
<result property="state" column="state" jdbcType="INTEGER"/>
<result property="notKeywordSendCount" column="not_keyword_send_count" jdbcType="INTEGER"/>
<result property="createTime" column="create_time" jdbcType="TIMESTAMP"/>
<result property="updateTime" column="update_time" jdbcType="TIMESTAMP"/>
</resultMap>
<sql id="Base_Column_List">
id, personal_stage_id, wx_id, robot_id, robot_classify_id, state, not_keyword_send_count, create_time,update_time
</sql>
<select id="getById" resultMap="BaseResultMap" parameterType="java.lang.Long">
select
<include refid="Base_Column_List"/>
from personal_stage_user
where id = #{id,jdbcType=BIGINT}
</select>
<delete id="deleteById" parameterType="long">
delete from personal_stage_user
where id = #{id,jdbcType=BIGINT}
</delete>
<insert id="insert" parameterType="com.pcloud.book.personalstage.entity.PersonalStageUser" useGeneratedKeys="true" keyProperty="id">
insert into personal_stage_user
<trim prefix="(" suffix=")" suffixOverrides=",">
personal_stage_id,
wx_id,
robot_id,
robot_classify_id,
state,
not_keyword_send_count,
create_time,
update_time
</trim>
<trim prefix="values (" suffix=")" suffixOverrides=",">
#{personalStageId,jdbcType=BIGINT},
#{wxId,jdbcType=VARCHAR},
#{robotId,jdbcType=VARCHAR},
#{robotClassifyId,jdbcType=BIGINT},
#{state,jdbcType=INTEGER},
#{notKeywordSendCount,jdbcType=INTEGER},
NOW(),
now()
</trim>
</insert>
<update id="update" parameterType="com.pcloud.book.personalstage.entity.PersonalStageUser">
update personal_stage_user
<set>
<if test="personalStageId != null">
personal_stage_id = #{personalStageId,jdbcType=BIGINT},
</if>
<if test="wxId != null">
wx_id = #{wxId,jdbcType=VARCHAR},
</if>
<if test="robotId != null">
robot_id = #{robotId,jdbcType=VARCHAR},
</if>
<if test="robotClassifyId != null">
robot_classify_id = #{robotClassifyId,jdbcType=BIGINT},
</if>
<if test="state != null">
state = #{state,jdbcType=INTEGER},
</if>
<if test="notKeywordSendCount != null">
not_keyword_send_count = #{notKeywordSendCount,jdbcType=INTEGER},
</if>
update_time=now()
</set>
where id = #{id,jdbcType=BIGINT}
</update>
<select id="getLast" parameterType="map" resultMap="BaseResultMap">
select <include refid="Base_Column_List"/>
from personal_stage_user
where 1=1
<if test="wxId!=null">
and wx_id=#{wxId}
</if>
<if test="robotId!=null">
and robot_id = #{robotId}
</if>
<if test="personalStageId!=null">
and personal_stage_id=#{personalStageId}
</if>
order by create_time desc
LIMIT 0,1
</select>
</mapper>
\ No newline at end of file
<?xml version="1.0" encoding="UTF-8" ?>
<!DOCTYPE mapper PUBLIC "-//mybatis.org//DTD Mapper 3.0//EN" "mybatis-3-mapper.dtd" >
<mapper namespace="com.pcloud.book.personalstage.dao.impl.PersonalStageWakeupDaoImpl">
<resultMap id="BaseResultMap" type="com.pcloud.book.personalstage.entity.PersonalStageWakeup">
<id property="id" column="id" jdbcType="BIGINT"/>
<result property="personalStageId" column="personal_stage_id" jdbcType="BIGINT"/>
<result property="toStageStartTime" column="to_stage_start_time" jdbcType="INTEGER"/>
<result property="createTime" column="create_time" jdbcType="TIMESTAMP"/>
</resultMap>
<sql id="Base_Column_List">
id, personal_stage_id, to_stage_start_time, create_time
</sql>
<select id="getById" resultMap="BaseResultMap" parameterType="java.lang.Long">
select
<include refid="Base_Column_List"/>
from personal_stage_wakeup
where id = #{id,jdbcType=BIGINT}
</select>
<delete id="deleteById" parameterType="long">
delete from personal_stage_wakeup
where id = #{id,jdbcType=BIGINT}
</delete>
<insert id="insert" parameterType="com.pcloud.book.personalstage.entity.PersonalStageWakeup" useGeneratedKeys="true" keyProperty="id">
insert into personal_stage_wakeup
<trim prefix="(" suffix=")" suffixOverrides=",">
personal_stage_id,
to_stage_start_time,
create_time
</trim>
<trim prefix="values (" suffix=")" suffixOverrides=",">
#{personalStageId,jdbcType=BIGINT},
#{toStageStartTime,jdbcType=INTEGER},
NOW()
</trim>
</insert>
<insert id="batchInsert" parameterType="com.pcloud.book.personalstage.entity.PersonalStageWakeup" useGeneratedKeys="true" keyProperty="id">
insert into personal_stage_wakeup (
personal_stage_id,
to_stage_start_time,
create_time
) values
<foreach collection="list" item="item" index="index" separator=",">
(
#{item.personalStageId,jdbcType=BIGINT},
#{item.toStageStartTime,jdbcType=INTEGER},
NOW()
)
</foreach>
</insert>
<delete id="deleteByPersonalStageId" parameterType="long">
delete from personal_stage_wakeup
where personal_stage_id =#{personalStageId}
</delete>
<select id="getListByPersonalStageId" parameterType="long" resultMap="BaseResultMap">
select <include refid="Base_Column_List"/>
from personal_stage_wakeup
where personal_stage_id=#{personalStageId}
order by to_stage_start_time
</select>
<select id="getFirstWakeup" parameterType="long" resultMap="BaseResultMap">
select <include refid="Base_Column_List"/>
from personal_stage_wakeup
where personal_stage_id=#{personalStageId}
order by to_stage_start_time
limit 1
</select>
</mapper>
\ No newline at end of file
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